From 4d8c442a79371de78c017eaf7e657bab4bd6c57e Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 4 Nov 2007 04:33:49 +0000 Subject: [PATCH] Applied comedi_indent script to all source files. --- comedi/comedi_fops.c | 1216 ++-- comedi/comedi_fops.h | 2 +- comedi/comedi_ksyms.c | 6 - comedi/drivers.c | 503 +- comedi/drivers/8253.h | 96 +- comedi/drivers/8255.c | 277 +- comedi/drivers/8255.h | 23 +- comedi/drivers/acl7225b.c | 143 +- comedi/drivers/addi-data/APCI1710_82x54.c | 1717 +++--- comedi/drivers/addi-data/APCI1710_82x54.h | 48 +- comedi/drivers/addi-data/APCI1710_Chrono.c | 2010 ++++--- comedi/drivers/addi-data/APCI1710_Chrono.h | 57 +- comedi/drivers/addi-data/APCI1710_Dig_io.c | 1014 ++-- comedi/drivers/addi-data/APCI1710_Dig_io.h | 27 +- comedi/drivers/addi-data/APCI1710_INCCPT.c | 5796 +++++++++---------- comedi/drivers/addi-data/APCI1710_INCCPT.h | 235 +- comedi/drivers/addi-data/APCI1710_Inp_cpt.c | 820 +-- comedi/drivers/addi-data/APCI1710_Inp_cpt.h | 31 +- comedi/drivers/addi-data/APCI1710_Pwm.c | 3852 +++++++----- comedi/drivers/addi-data/APCI1710_Pwm.h | 120 +- comedi/drivers/addi-data/APCI1710_Ssi.c | 894 +-- comedi/drivers/addi-data/APCI1710_Ssi.h | 22 +- comedi/drivers/addi-data/APCI1710_Tor.c | 2059 ++++--- comedi/drivers/addi-data/APCI1710_Tor.h | 41 +- comedi/drivers/addi-data/APCI1710_Ttl.c | 1070 ++-- comedi/drivers/addi-data/APCI1710_Ttl.h | 22 +- comedi/drivers/addi-data/addi_amcc_S5920.c | 256 +- comedi/drivers/addi-data/addi_amcc_S5920.h | 20 +- comedi/drivers/addi-data/addi_amcc_s5933.h | 306 +- comedi/drivers/addi-data/addi_common.c | 5488 +++++++++--------- comedi/drivers/addi-data/addi_common.h | 628 +- comedi/drivers/addi-data/addi_eeprom.c | 1002 ++-- comedi/drivers/addi-data/amcc_s5933_58.h | 306 +- comedi/drivers/addi-data/hwdrv_APCI1710.c | 1720 +++--- comedi/drivers/addi-data/hwdrv_APCI1710.h | 126 +- comedi/drivers/addi-data/hwdrv_apci035.c | 601 +- comedi/drivers/addi-data/hwdrv_apci035.h | 74 +- comedi/drivers/addi-data/hwdrv_apci1032.c | 240 +- comedi/drivers/addi-data/hwdrv_apci1032.h | 31 +- comedi/drivers/addi-data/hwdrv_apci1500.c | 4568 ++++++++------- comedi/drivers/addi-data/hwdrv_apci1500.h | 178 +- comedi/drivers/addi-data/hwdrv_apci1516.c | 579 +- comedi/drivers/addi-data/hwdrv_apci1516.h | 44 +- comedi/drivers/addi-data/hwdrv_apci1564.c | 1332 +++-- comedi/drivers/addi-data/hwdrv_apci1564.h | 52 +- comedi/drivers/addi-data/hwdrv_apci16xx.c | 965 ++- comedi/drivers/addi-data/hwdrv_apci16xx.h | 68 +- comedi/drivers/addi-data/hwdrv_apci2016.c | 469 +- comedi/drivers/addi-data/hwdrv_apci2016.h | 29 +- comedi/drivers/addi-data/hwdrv_apci2032.c | 691 ++- comedi/drivers/addi-data/hwdrv_apci2032.h | 36 +- comedi/drivers/addi-data/hwdrv_apci2200.c | 581 +- comedi/drivers/addi-data/hwdrv_apci2200.h | 42 +- comedi/drivers/addi-data/hwdrv_apci3120.c | 3050 +++++----- comedi/drivers/addi-data/hwdrv_apci3120.h | 201 +- comedi/drivers/addi-data/hwdrv_apci3200.c | 5049 ++++++++-------- comedi/drivers/addi-data/hwdrv_apci3200.h | 213 +- comedi/drivers/addi-data/hwdrv_apci3501.c | 811 +-- comedi/drivers/addi-data/hwdrv_apci3501.h | 48 +- comedi/drivers/addi-data/hwdrv_apci3xxx.c | 2094 ++++--- comedi/drivers/addi-data/hwdrv_apci3xxx.h | 61 +- comedi/drivers/addi_apci_035.c | 2 +- comedi/drivers/addi_apci_all.c | 2 +- comedi/drivers/adl_pci6208.c | 262 +- comedi/drivers/adl_pci7296.c | 94 +- comedi/drivers/adl_pci7432.c | 124 +- comedi/drivers/adl_pci8164.c | 450 +- comedi/drivers/adl_pci9111.c | 1424 +++-- comedi/drivers/adl_pci9118.c | 2036 ++++--- comedi/drivers/adv_pci1710.c | 1350 +++-- comedi/drivers/adv_pci_dio.c | 819 +-- comedi/drivers/aio_aio12_8.c | 106 +- comedi/drivers/aio_iiro_16.c | 95 +- comedi/drivers/am9513.h | 1 - comedi/drivers/amcc_s5933.h | 11 +- comedi/drivers/amplc_dio200.c | 473 +- comedi/drivers/amplc_pc236.c | 220 +- comedi/drivers/amplc_pc263.c | 130 +- comedi/drivers/amplc_pci224.c | 469 +- comedi/drivers/amplc_pci230.c | 984 ++-- comedi/drivers/c6xdigio.c | 563 +- comedi/drivers/cb_das16_cs.c | 662 ++- comedi/drivers/cb_pcidas.c | 1417 +++-- comedi/drivers/cb_pcidas64.c | 3580 ++++++------ comedi/drivers/cb_pcidda.c | 498 +- comedi/drivers/cb_pcidio.c | 146 +- comedi/drivers/cb_pcimdas.c | 303 +- comedi/drivers/cb_pcimdda.c | 293 +- comedi/drivers/comedi_bond.c | 478 +- comedi/drivers/comedi_counter_unstable.h | 7 +- comedi/drivers/comedi_fc.c | 55 +- comedi/drivers/comedi_fc.h | 50 +- comedi/drivers/comedi_parport.c | 245 +- comedi/drivers/comedi_rt_timer.c | 395 +- comedi/drivers/comedi_test.c | 298 +- comedi/drivers/contec_pci_dio.c | 141 +- comedi/drivers/daqboard2000.c | 888 +-- comedi/drivers/das08.c | 965 +-- comedi/drivers/das08.h | 66 +- comedi/drivers/das08_cs.c | 281 +- comedi/drivers/das16.c | 1481 +++-- comedi/drivers/das16m1.c | 416 +- comedi/drivers/das1800.c | 1500 +++-- comedi/drivers/das6402.c | 255 +- comedi/drivers/das800.c | 653 +-- comedi/drivers/dmm32at.c | 718 ++- comedi/drivers/dt2801.c | 591 +- comedi/drivers/dt2811.c | 300 +- comedi/drivers/dt2814.c | 277 +- comedi/drivers/dt2815.c | 242 +- comedi/drivers/dt2817.c | 150 +- comedi/drivers/dt282x.c | 1050 ++-- comedi/drivers/dt3000.c | 765 +-- comedi/drivers/dt9812.c | 1515 ++--- comedi/drivers/dt9812.h | 193 +- comedi/drivers/fl512.c | 242 +- comedi/drivers/gsc_hpdi.c | 793 +-- comedi/drivers/icp_multi.c | 600 +- comedi/drivers/icp_multi.h | 215 +- comedi/drivers/ii_pci20kc.c | 274 +- comedi/drivers/jr3_pci.c | 1548 ++--- comedi/drivers/jr3_pci.h | 934 ++- comedi/drivers/ke_counter.c | 293 +- comedi/drivers/me4000.c | 3617 ++++++------ comedi/drivers/me4000.h | 358 +- comedi/drivers/me_daq.c | 1163 ++-- comedi/drivers/mite.c | 390 +- comedi/drivers/mite.h | 321 +- comedi/drivers/mpc624.c | 438 +- comedi/drivers/mpc8260cpm.c | 95 +- comedi/drivers/multiq3.c | 321 +- comedi/drivers/ni_6527.c | 351 +- comedi/drivers/ni_65xx.c | 745 +-- comedi/drivers/ni_660x.c | 579 +- comedi/drivers/ni_670x.c | 285 +- comedi/drivers/ni_at_a2150.c | 513 +- comedi/drivers/ni_at_ao.c | 335 +- comedi/drivers/ni_atmio.c | 499 +- comedi/drivers/ni_atmio16d.c | 619 +- comedi/drivers/ni_daq_dio24.c | 536 +- comedi/drivers/ni_labpc.c | 1424 +++-- comedi/drivers/ni_labpc.h | 44 +- comedi/drivers/ni_labpc_cs.c | 433 +- comedi/drivers/ni_mio_common.c | 4190 +++++++------- comedi/drivers/ni_mio_cs.c | 405 +- comedi/drivers/ni_pcidio.c | 958 +-- comedi/drivers/ni_pcimio.c | 2185 +++---- comedi/drivers/ni_stc.h | 373 +- comedi/drivers/ni_tio.c | 1482 ++--- comedi/drivers/ni_tio.h | 58 +- comedi/drivers/pcl711.c | 281 +- comedi/drivers/pcl724.c | 172 +- comedi/drivers/pcl725.c | 94 +- comedi/drivers/pcl726.c | 312 +- comedi/drivers/pcl730.c | 150 +- comedi/drivers/pcl812.c | 1135 ++-- comedi/drivers/pcl816.c | 1436 ++--- comedi/drivers/pcl818.c | 1675 +++--- comedi/drivers/pcm3724.c | 196 +- comedi/drivers/pcm3730.c | 168 +- comedi/drivers/pcmad.c | 109 +- comedi/drivers/pcmda12.c | 229 +- comedi/drivers/pcmmio.c | 1565 ++--- comedi/drivers/pcmuio.c | 1186 ++-- comedi/drivers/plx9080.h | 399 +- comedi/drivers/poc.c | 179 +- comedi/drivers/quatech_daqp_cs.c | 783 +-- comedi/drivers/rtd520.c | 2829 +++++---- comedi/drivers/rtd520.h | 526 +- comedi/drivers/rti800.c | 241 +- comedi/drivers/rti802.c | 64 +- comedi/drivers/s526.c | 1037 ++-- comedi/drivers/s626.c | 4775 +++++++-------- comedi/drivers/s626.h | 334 +- comedi/drivers/serial2002.c | 1234 ++-- comedi/drivers/skel.c | 347 +- comedi/drivers/ssv_dnp.c | 366 +- comedi/drivers/unioxx5.c | 733 +-- comedi/drivers/usbdux.c | 1889 +++--- comedi/drivers/usbduxfast.c | 1579 +++-- comedi/kcomedilib/data.c | 49 +- comedi/kcomedilib/dio.c | 34 +- comedi/kcomedilib/get.c | 156 +- comedi/kcomedilib/kcomedilib_main.c | 302 +- comedi/kcomedilib/ksyms.c | 5 - comedi/proc.c | 55 +- comedi/range.c | 132 +- comedi/rt.c | 124 +- comedi/rt_pend_tq.c | 46 +- comedi/rt_pend_tq.h | 7 +- include/asm/div64.h | 15 +- include/asm/dma.h | 2 +- include/asm/page.h | 17 +- include/asm/pgtable.h | 1 - include/asm/semaphore.h | 1 - include/asm/types.h | 1 - include/asm/uaccess.h | 29 +- include/linux/comedi.h | 1048 ++-- include/linux/comedi_rt.h | 27 +- include/linux/comedidev.h | 276 +- include/linux/comedilib.h | 179 +- include/linux/compiler.h | 2 - include/linux/delay.h | 1 - include/linux/device.h | 16 +- include/linux/interrupt.h | 1 - include/linux/isapnp.h | 2 +- include/linux/kernel.h | 2 +- include/linux/kref.h | 41 +- include/linux/mm.h | 11 +- include/linux/mod_devicetable.h | 2 +- include/linux/module.h | 15 +- include/linux/moduleparam.h | 9 +- include/linux/pci.h | 4 - include/linux/pci_ids.h | 5 +- include/linux/pnp.h | 180 +- include/linux/sched.h | 1 - include/linux/slab.h | 1 - include/linux/stddef.h | 7 +- include/linux/time.h | 1 - include/linux/types.h | 1 - include/linux/usb.h | 8 +- include/linux/version.h | 1 - include/linux/wrapper.h | 1 - include/pcmcia/ds.h | 19 +- 224 files changed, 72193 insertions(+), 68832 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 29134bdc..f39deb66 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -59,29 +59,31 @@ module_param(comedi_debug, int, 0644); #endif comedi_device *comedi_devices; -spinlock_t big_comedi_lock; /* Dynamic initialization */ - -static int do_devconfig_ioctl(comedi_device *dev,comedi_devconfig *arg); -static int do_bufconfig_ioctl(comedi_device *dev,void *arg); -static int do_devinfo_ioctl(comedi_device *dev,comedi_devinfo *arg, struct file *file); -static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file); -static int do_chaninfo_ioctl(comedi_device *dev,comedi_chaninfo *arg); -static int do_bufinfo_ioctl(comedi_device *dev,void *arg); -static int do_cmd_ioctl(comedi_device *dev,void *arg,void *file); -static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file); -static int do_unlock_ioctl(comedi_device *dev,unsigned int arg,void * file); -static int do_cancel_ioctl(comedi_device *dev,unsigned int arg,void *file); -static int do_cmdtest_ioctl(comedi_device *dev,void *arg,void *file); -static int do_insnlist_ioctl(comedi_device *dev,void *arg,void *file); -static int do_insn_ioctl(comedi_device *dev,void *arg,void *file); -static int do_poll_ioctl(comedi_device *dev,unsigned int subd,void *file); - -void do_become_nonbusy(comedi_device *dev,comedi_subdevice *s); -static int do_cancel(comedi_device *dev,comedi_subdevice *s); - -static int comedi_fasync (int fd, struct file *file, int on); - -static int comedi_ioctl(struct inode * inode,struct file * file, +spinlock_t big_comedi_lock; /* Dynamic initialization */ + +static int do_devconfig_ioctl(comedi_device * dev, comedi_devconfig * arg); +static int do_bufconfig_ioctl(comedi_device * dev, void *arg); +static int do_devinfo_ioctl(comedi_device * dev, comedi_devinfo * arg, + struct file *file); +static int do_subdinfo_ioctl(comedi_device * dev, comedi_subdinfo * arg, + void *file); +static int do_chaninfo_ioctl(comedi_device * dev, comedi_chaninfo * arg); +static int do_bufinfo_ioctl(comedi_device * dev, void *arg); +static int do_cmd_ioctl(comedi_device * dev, void *arg, void *file); +static int do_lock_ioctl(comedi_device * dev, unsigned int arg, void *file); +static int do_unlock_ioctl(comedi_device * dev, unsigned int arg, void *file); +static int do_cancel_ioctl(comedi_device * dev, unsigned int arg, void *file); +static int do_cmdtest_ioctl(comedi_device * dev, void *arg, void *file); +static int do_insnlist_ioctl(comedi_device * dev, void *arg, void *file); +static int do_insn_ioctl(comedi_device * dev, void *arg, void *file); +static int do_poll_ioctl(comedi_device * dev, unsigned int subd, void *file); + +void do_become_nonbusy(comedi_device * dev, comedi_subdevice * s); +static int do_cancel(comedi_device * dev, comedi_subdevice * s); + +static int comedi_fasync(int fd, struct file *file, int on); + +static int comedi_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { const unsigned minor = iminor(inode); @@ -89,51 +91,49 @@ static int comedi_ioctl(struct inode * inode,struct file * file, /* Device config is special, because it must work on * an unconfigured device. */ - if(cmd==COMEDI_DEVCONFIG){ - return do_devconfig_ioctl(dev,(void *)arg); + if (cmd == COMEDI_DEVCONFIG) { + return do_devconfig_ioctl(dev, (void *)arg); } - if(!dev->attached){ + if (!dev->attached) { DPRINTK("no driver configured on /dev/comedi%i\n", dev->minor); return -ENODEV; } - switch(cmd) - { + switch (cmd) { case COMEDI_BUFCONFIG: - return do_bufconfig_ioctl(dev,(void*)arg); + return do_bufconfig_ioctl(dev, (void *)arg); case COMEDI_DEVINFO: - return do_devinfo_ioctl(dev,(void *)arg, file); + return do_devinfo_ioctl(dev, (void *)arg, file); case COMEDI_SUBDINFO: - return do_subdinfo_ioctl(dev,(void *)arg,file); + return do_subdinfo_ioctl(dev, (void *)arg, file); case COMEDI_CHANINFO: - return do_chaninfo_ioctl(dev,(void *)arg); + return do_chaninfo_ioctl(dev, (void *)arg); case COMEDI_RANGEINFO: - return do_rangeinfo_ioctl(dev,(void *)arg); + return do_rangeinfo_ioctl(dev, (void *)arg); case COMEDI_BUFINFO: - return do_bufinfo_ioctl(dev,(void*)arg); + return do_bufinfo_ioctl(dev, (void *)arg); case COMEDI_LOCK: - return do_lock_ioctl(dev,arg,file); + return do_lock_ioctl(dev, arg, file); case COMEDI_UNLOCK: - return do_unlock_ioctl(dev,arg,file); + return do_unlock_ioctl(dev, arg, file); case COMEDI_CANCEL: - return do_cancel_ioctl(dev,arg,file); + return do_cancel_ioctl(dev, arg, file); case COMEDI_CMD: - return do_cmd_ioctl(dev,(void *)arg,file); + return do_cmd_ioctl(dev, (void *)arg, file); case COMEDI_CMDTEST: - return do_cmdtest_ioctl(dev,(void *)arg,file); + return do_cmdtest_ioctl(dev, (void *)arg, file); case COMEDI_INSNLIST: - return do_insnlist_ioctl(dev,(void *)arg,file); + return do_insnlist_ioctl(dev, (void *)arg, file); case COMEDI_INSN: - return do_insn_ioctl(dev,(void *)arg,file); + return do_insn_ioctl(dev, (void *)arg, file); case COMEDI_POLL: - return do_poll_ioctl(dev,arg,file); + return do_poll_ioctl(dev, arg, file); default: return -ENOTTY; } } - /* COMEDI_DEVCONFIG device config ioctl @@ -147,51 +147,55 @@ static int comedi_ioctl(struct inode * inode,struct file * file, writes: none */ -static int do_devconfig_ioctl(comedi_device *dev, comedi_devconfig *arg) +static int do_devconfig_ioctl(comedi_device * dev, comedi_devconfig * arg) { comedi_devconfig it; int ret; unsigned char *aux_data = NULL; int aux_len; - if(!capable(CAP_SYS_ADMIN)) + if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if(arg==NULL){ + if (arg == NULL) { return comedi_device_detach(dev); } - if(copy_from_user(&it,arg,sizeof(comedi_devconfig))) + if (copy_from_user(&it, arg, sizeof(comedi_devconfig))) return -EFAULT; - it.board_name[COMEDI_NAMELEN-1]=0; + it.board_name[COMEDI_NAMELEN - 1] = 0; - if(comedi_aux_data(it.options, 0) && - it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]){ + if (comedi_aux_data(it.options, 0) && + it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { int bit_shift; aux_len = it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; - if(aux_len<0)return -EFAULT; + if (aux_len < 0) + return -EFAULT; aux_data = vmalloc(aux_len); - if(!aux_data) return -ENOMEM; + if (!aux_data) + return -ENOMEM; - if(copy_from_user(aux_data, - comedi_aux_data(it.options, 0), aux_len)){ + if (copy_from_user(aux_data, + comedi_aux_data(it.options, 0), aux_len)) { vfree(aux_data); return -EFAULT; } - it.options[COMEDI_DEVCONF_AUX_DATA_LO] = (unsigned long)aux_data; - if(sizeof(void*) > sizeof(int)) - { + it.options[COMEDI_DEVCONF_AUX_DATA_LO] = + (unsigned long)aux_data; + if (sizeof(void *) > sizeof(int)) { bit_shift = sizeof(int) * 8; - it.options[COMEDI_DEVCONF_AUX_DATA_HI] = ((unsigned long)aux_data) >> bit_shift; - }else + it.options[COMEDI_DEVCONF_AUX_DATA_HI] = + ((unsigned long)aux_data) >> bit_shift; + } else it.options[COMEDI_DEVCONF_AUX_DATA_HI] = 0; } - ret = comedi_device_attach(dev,&it); + ret = comedi_device_attach(dev, &it); - if(aux_data) vfree(aux_data); + if (aux_data) + vfree(aux_data); return ret; } @@ -210,50 +214,50 @@ static int do_devconfig_ioctl(comedi_device *dev, comedi_devconfig *arg) modified bufconfig at arg */ -static int do_bufconfig_ioctl(comedi_device *dev,void *arg) +static int do_bufconfig_ioctl(comedi_device * dev, void *arg) { comedi_bufconfig bc; comedi_async *async; comedi_subdevice *s; int ret = 0; - if(copy_from_user(&bc,arg,sizeof(comedi_bufconfig))) + if (copy_from_user(&bc, arg, sizeof(comedi_bufconfig))) return -EFAULT; - if(bc.subdevice>=dev->n_subdevices || bc.subdevice<0) + if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0) return -EINVAL; - s=dev->subdevices+bc.subdevice; - async=s->async; + s = dev->subdevices + bc.subdevice; + async = s->async; - if(!async){ + if (!async) { DPRINTK("subdevice does not have async capability\n"); bc.size = 0; bc.maximum_size = 0; goto copyback; } - if(bc.maximum_size){ - if(!capable(CAP_SYS_ADMIN))return -EPERM; + if (bc.maximum_size) { + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; async->max_bufsize = bc.maximum_size; } - if(bc.size){ - if(bc.size > async->max_bufsize) + if (bc.size) { + if (bc.size > async->max_bufsize) return -EPERM; - if(s->busy) - { + if (s->busy) { DPRINTK("subdevice is busy, cannot resize buffer\n"); return -EBUSY; } - if(async->mmap_count){ + if (async->mmap_count) { DPRINTK("subdevice is mmapped, cannot resize buffer\n"); return -EBUSY; } - if(!async->prealloc_buf) + if (!async->prealloc_buf) return -EINVAL; /* make sure buffer is an integral number of pages @@ -261,11 +265,13 @@ static int do_bufconfig_ioctl(comedi_device *dev,void *arg) bc.size = (bc.size + PAGE_SIZE - 1) & PAGE_MASK; ret = comedi_buf_alloc(dev, s, bc.size); - if(ret < 0) return ret; + if (ret < 0) + return ret; - if(s->buf_change){ - ret = s->buf_change(dev,s,bc.size); - if(ret < 0) return ret; + if (s->buf_change) { + ret = s->buf_change(dev, s, bc.size); + if (ret < 0) + return ret; } DPRINTK("comedi%i subd %d buffer resized to %i bytes\n", @@ -275,8 +281,8 @@ static int do_bufconfig_ioctl(comedi_device *dev,void *arg) bc.size = async->prealloc_bufsz; bc.maximum_size = async->max_bufsize; -copyback: - if(copy_to_user(arg,&bc,sizeof(comedi_bufconfig))) + copyback: + if (copy_to_user(arg, &bc, sizeof(comedi_bufconfig))) return -EFAULT; return 0; @@ -296,39 +302,39 @@ copyback: devinfo structure */ -static int do_devinfo_ioctl(comedi_device *dev, comedi_devinfo *arg, struct file *file) +static int do_devinfo_ioctl(comedi_device * dev, comedi_devinfo * arg, + struct file *file) { comedi_devinfo devinfo; const unsigned minor = iminor(file->f_dentry->d_inode); comedi_subdevice *read_subdev = comedi_get_read_subdevice(dev, minor); comedi_subdevice *write_subdev = comedi_get_write_subdevice(dev, minor); - memset(&devinfo,0,sizeof(devinfo)); + memset(&devinfo, 0, sizeof(devinfo)); /* fill devinfo structure */ - devinfo.version_code=COMEDI_VERSION_CODE; - devinfo.n_subdevs=dev->n_subdevices; - memcpy(devinfo.driver_name,dev->driver->driver_name,COMEDI_NAMELEN); - memcpy(devinfo.board_name,dev->board_name,COMEDI_NAMELEN); + devinfo.version_code = COMEDI_VERSION_CODE; + devinfo.n_subdevs = dev->n_subdevices; + memcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN); + memcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN); - if(read_subdev){ + if (read_subdev) { devinfo.read_subdevice = read_subdev - dev->subdevices; - }else{ + } else { devinfo.read_subdevice = -1; } - if(write_subdev){ + if (write_subdev) { devinfo.write_subdevice = write_subdev - dev->subdevices; - }else{ + } else { devinfo.write_subdevice = -1; } - if(copy_to_user(arg,&devinfo,sizeof(comedi_devinfo))) + if (copy_to_user(arg, &devinfo, sizeof(comedi_devinfo))) return -EFAULT; return 0; } - /* COMEDI_SUBDINFO subdevice info ioctl @@ -343,67 +349,69 @@ static int do_devinfo_ioctl(comedi_device *dev, comedi_devinfo *arg, struct file array of subdevice info structures at arg */ -static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file) +static int do_subdinfo_ioctl(comedi_device * dev, comedi_subdinfo * arg, + void *file) { - int ret,i; - comedi_subdinfo *tmp,*us; + int ret, i; + comedi_subdinfo *tmp, *us; comedi_subdevice *s; - - tmp=kcalloc(dev->n_subdevices,sizeof(comedi_subdinfo),GFP_KERNEL); - if(!tmp) + tmp = kcalloc(dev->n_subdevices, sizeof(comedi_subdinfo), GFP_KERNEL); + if (!tmp) return -ENOMEM; /* fill subdinfo structs */ - for(i=0;in_subdevices;i++){ - s=dev->subdevices+i; - us=tmp+i; - - us->type = s->type; - us->n_chan = s->n_chan; - us->subd_flags = s->subdev_flags; - if(comedi_get_subdevice_runflags(s) & SRF_RUNNING) + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; + us = tmp + i; + + us->type = s->type; + us->n_chan = s->n_chan; + us->subd_flags = s->subdev_flags; + if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) us->subd_flags |= SDF_RUNNING; -#define TIMER_nanosec 5 /* backwards compatibility */ - us->timer_type = TIMER_nanosec; - us->len_chanlist = s->len_chanlist; - us->maxdata = s->maxdata; - if(s->range_table){ - us->range_type = (dev->minor << 28) | (i << 24) | (0 << 16) | - (s->range_table->length); - }else{ - us->range_type = 0; /* XXX */ +#define TIMER_nanosec 5 /* backwards compatibility */ + us->timer_type = TIMER_nanosec; + us->len_chanlist = s->len_chanlist; + us->maxdata = s->maxdata; + if (s->range_table) { + us->range_type = + (dev-> + minor << 28) | (i << 24) | (0 << 16) | (s-> + range_table->length); + } else { + us->range_type = 0; /* XXX */ } - us->flags = s->flags; + us->flags = s->flags; - if(s->busy) + if (s->busy) us->subd_flags |= SDF_BUSY; - if(s->busy == file) + if (s->busy == file) us->subd_flags |= SDF_BUSY_OWNER; - if(s->lock) + if (s->lock) us->subd_flags |= SDF_LOCKED; - if(s->lock == file) + if (s->lock == file) us->subd_flags |= SDF_LOCK_OWNER; - if(!s->maxdata && s->maxdata_list) + if (!s->maxdata && s->maxdata_list) us->subd_flags |= SDF_MAXDATA; - if(s->flaglist) + if (s->flaglist) us->subd_flags |= SDF_FLAGS; - if(s->range_table_list) + if (s->range_table_list) us->subd_flags |= SDF_RANGETYPE; - if(s->do_cmd) + if (s->do_cmd) us->subd_flags |= SDF_CMD; us->settling_time_0 = s->settling_time_0; } - ret=copy_to_user(arg,tmp,dev->n_subdevices*sizeof(comedi_subdinfo)); + ret = copy_to_user(arg, tmp, + dev->n_subdevices * sizeof(comedi_subdinfo)); kfree(tmp); - return ret?-EFAULT:0; + return ret ? -EFAULT : 0; } - /* COMEDI_CHANINFO subdevice info ioctl @@ -418,79 +426,83 @@ static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file) arrays at elements of chaninfo structure */ -static int do_chaninfo_ioctl(comedi_device *dev,comedi_chaninfo *arg) +static int do_chaninfo_ioctl(comedi_device * dev, comedi_chaninfo * arg) { comedi_subdevice *s; comedi_chaninfo it; - if(copy_from_user(&it,arg,sizeof(comedi_chaninfo))) + if (copy_from_user(&it, arg, sizeof(comedi_chaninfo))) return -EFAULT; - if(it.subdev>=dev->n_subdevices) + if (it.subdev >= dev->n_subdevices) return -EINVAL; - s=dev->subdevices+it.subdev; + s = dev->subdevices + it.subdev; - if(it.maxdata_list){ - if(s->maxdata || !s->maxdata_list) + if (it.maxdata_list) { + if (s->maxdata || !s->maxdata_list) return -EINVAL; - if(copy_to_user(it.maxdata_list,s->maxdata_list,s->n_chan*sizeof(lsampl_t))) + if (copy_to_user(it.maxdata_list, s->maxdata_list, + s->n_chan * sizeof(lsampl_t))) return -EFAULT; } - if(it.flaglist){ - if(!s->flaglist)return -EINVAL; - if(copy_to_user(it.flaglist,s->flaglist,s->n_chan*sizeof(unsigned int))) + if (it.flaglist) { + if (!s->flaglist) + return -EINVAL; + if (copy_to_user(it.flaglist, s->flaglist, + s->n_chan * sizeof(unsigned int))) return -EFAULT; } - if(it.rangelist){ + if (it.rangelist) { int i; - if(!s->range_table_list)return -EINVAL; - for(i=0;in_chan;i++){ + if (!s->range_table_list) + return -EINVAL; + for (i = 0; i < s->n_chan; i++) { int x; - x=(dev->minor << 28) | (it.subdev << 24) | (i << 16) | + x = (dev->minor << 28) | (it.subdev << 24) | (i << 16) | (s->range_table_list[i]->length); - put_user(x,it.rangelist+i); + put_user(x, it.rangelist + i); } //if(copy_to_user(it.rangelist,s->range_type_list,s->n_chan*sizeof(unsigned int))) - // return -EFAULT; + // return -EFAULT; } return 0; } /* - COMEDI_BUFINFO - buffer information ioctl + COMEDI_BUFINFO + buffer information ioctl - arg: - pointer to bufinfo structure + arg: + pointer to bufinfo structure - reads: - bufinfo at arg + reads: + bufinfo at arg - writes: - modified bufinfo at arg + writes: + modified bufinfo at arg -*/ -static int do_bufinfo_ioctl(comedi_device *dev,void *arg) + */ +static int do_bufinfo_ioctl(comedi_device * dev, void *arg) { comedi_bufinfo bi; comedi_subdevice *s; comedi_async *async; - if(copy_from_user(&bi,arg, sizeof(comedi_bufinfo))) + if (copy_from_user(&bi, arg, sizeof(comedi_bufinfo))) return -EFAULT; - if(bi.subdevice >= dev->n_subdevices || bi.subdevice < 0) + if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0) return -EINVAL; s = dev->subdevices + bi.subdevice; async = s->async; - if(!async){ + if (!async) { DPRINTK("subdevice does not have async capability\n"); bi.buf_write_ptr = 0; bi.buf_read_ptr = 0; @@ -499,18 +511,20 @@ static int do_bufinfo_ioctl(comedi_device *dev,void *arg) goto copyback; } - if(bi.bytes_read && (s->subdev_flags & SDF_CMD_READ)){ + if (bi.bytes_read && (s->subdev_flags & SDF_CMD_READ)) { bi.bytes_read = comedi_buf_read_alloc(async, bi.bytes_read); comedi_buf_read_free(async, bi.bytes_read); - if(!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | SRF_RUNNING)) && - async->buf_write_count == async->buf_read_count){ - do_become_nonbusy(dev,s); + if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | + SRF_RUNNING)) + && async->buf_write_count == async->buf_read_count) { + do_become_nonbusy(dev, s); } } - if(bi.bytes_written && (s->subdev_flags & SDF_CMD_WRITE)){ - bi.bytes_written = comedi_buf_write_alloc( async, bi.bytes_written ); + if (bi.bytes_written && (s->subdev_flags & SDF_CMD_WRITE)) { + bi.bytes_written = + comedi_buf_write_alloc(async, bi.bytes_written); comedi_buf_write_free(async, bi.bytes_written); } @@ -519,15 +533,15 @@ static int do_bufinfo_ioctl(comedi_device *dev,void *arg) bi.buf_read_count = async->buf_read_count; bi.buf_read_ptr = async->buf_read_ptr; -copyback: - if(copy_to_user(arg, &bi, sizeof(comedi_bufinfo))) + copyback: + if (copy_to_user(arg, &bi, sizeof(comedi_bufinfo))) return -EFAULT; return 0; } - -static int parse_insn(comedi_device *dev,comedi_insn *insn,lsampl_t *data,void *file); +static int parse_insn(comedi_device * dev, comedi_insn * insn, lsampl_t * data, + void *file); /* * COMEDI_INSNLIST * synchronous instructions @@ -545,82 +559,87 @@ static int parse_insn(comedi_device *dev,comedi_insn *insn,lsampl_t *data,void * */ /* arbitrary limits */ #define MAX_SAMPLES 256 -static int do_insnlist_ioctl(comedi_device *dev,void *arg,void *file) +static int do_insnlist_ioctl(comedi_device * dev, void *arg, void *file) { comedi_insnlist insnlist; - comedi_insn *insns = NULL; - lsampl_t *data = NULL; + comedi_insn *insns = NULL; + lsampl_t *data = NULL; int i = 0; - int ret=0; + int ret = 0; - if(copy_from_user(&insnlist,arg,sizeof(comedi_insnlist))) + if (copy_from_user(&insnlist, arg, sizeof(comedi_insnlist))) return -EFAULT; - data=kmalloc(sizeof(lsampl_t)*MAX_SAMPLES,GFP_KERNEL); - if(!data){ + data = kmalloc(sizeof(lsampl_t) * MAX_SAMPLES, GFP_KERNEL); + if (!data) { DPRINTK("kmalloc failed\n"); ret = -ENOMEM; goto error; } - insns=kmalloc(sizeof(comedi_insn)*insnlist.n_insns,GFP_KERNEL); - if(!insns){ + insns = kmalloc(sizeof(comedi_insn) * insnlist.n_insns, GFP_KERNEL); + if (!insns) { DPRINTK("kmalloc failed\n"); ret = -ENOMEM; goto error; } - if(copy_from_user(insns,insnlist.insns,sizeof(comedi_insn)*insnlist.n_insns)){ + if (copy_from_user(insns, insnlist.insns, + sizeof(comedi_insn) * insnlist.n_insns)) { DPRINTK("copy_from_user failed\n"); - ret=-EFAULT; + ret = -EFAULT; goto error; } - for(i=0;iMAX_SAMPLES){ + for (i = 0; i < insnlist.n_insns; i++) { + if (insns[i].n > MAX_SAMPLES) { DPRINTK("number of samples too large\n"); - ret=-EINVAL; + ret = -EINVAL; goto error; } - if(insns[i].insn&INSN_MASK_WRITE){ - if(copy_from_user(data,insns[i].data, - insns[i].n*sizeof(lsampl_t))){ + if (insns[i].insn & INSN_MASK_WRITE) { + if (copy_from_user(data, insns[i].data, + insns[i].n * sizeof(lsampl_t))) { DPRINTK("copy_from_user failed\n"); - ret=-EFAULT; + ret = -EFAULT; goto error; } } - ret = parse_insn(dev,insns+i,data,file); - if(ret<0)goto error; - if(insns[i].insn&INSN_MASK_READ){ - if(copy_to_user(insns[i].data,data, - insns[i].n*sizeof(lsampl_t))){ + ret = parse_insn(dev, insns + i, data, file); + if (ret < 0) + goto error; + if (insns[i].insn & INSN_MASK_READ) { + if (copy_to_user(insns[i].data, data, + insns[i].n * sizeof(lsampl_t))) { DPRINTK("copy_to_user failed\n"); - ret=-EFAULT; + ret = -EFAULT; goto error; } } - if(need_resched()) + if (need_resched()) schedule(); } -error: - if(insns)kfree(insns); - if(data)kfree(data); + error: + if (insns) + kfree(insns); + if (data) + kfree(data); - if(ret<0)return ret; + if (ret < 0) + return ret; return i; } -static int check_insn_config_length(comedi_insn *insn, lsampl_t *data) +static int check_insn_config_length(comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: case INSN_CONFIG_DIO_INPUT: case INSN_CONFIG_DISARM: case INSN_CONFIG_RESET: - if(insn->n == 1) return 0; + if (insn->n == 1) + return 0; break; case INSN_CONFIG_ARM: case INSN_CONFIG_DIO_QUERY: @@ -633,7 +652,8 @@ static int check_insn_config_length(comedi_insn *insn, lsampl_t *data) case INSN_CONFIG_8254_READ_STATUS: case INSN_CONFIG_SET_ROUTING: case INSN_CONFIG_GET_ROUTING: - if(insn->n == 2) return 0; + if (insn->n == 2) + return 0; break; case INSN_CONFIG_SET_GATE_SRC: case INSN_CONFIG_GET_GATE_SRC: @@ -641,155 +661,161 @@ static int check_insn_config_length(comedi_insn *insn, lsampl_t *data) case INSN_CONFIG_GET_CLOCK_SRC: case INSN_CONFIG_SET_OTHER_SRC: case INSN_CONFIG_GET_COUNTER_STATUS: - if(insn->n == 3) return 0; + if (insn->n == 3) + return 0; break; case INSN_CONFIG_PWM_OUTPUT: case INSN_CONFIG_ANALOG_TRIG: - if(insn->n == 5) return 0; + if (insn->n == 5) + return 0; break; - //by default we allow the insn since we don't have checks for all possible cases yet + //by default we allow the insn since we don't have checks for all possible cases yet default: - rt_printk("comedi: no check for data length of config insn id %i is implemented.\n" + rt_printk + ("comedi: no check for data length of config insn id %i is implemented.\n" " Add a check to %s in %s.\n" - " Assuming n=%i is correct.\n", - data[0], __FUNCTION__, __FILE__, insn->n); + " Assuming n=%i is correct.\n", data[0], __FUNCTION__, + __FILE__, insn->n); return 0; break; } return -EINVAL; } -static int parse_insn(comedi_device *dev,comedi_insn *insn,lsampl_t *data,void *file) +static int parse_insn(comedi_device * dev, comedi_insn * insn, lsampl_t * data, + void *file) { comedi_subdevice *s; int ret = 0; int i; - if(insn->insn&INSN_MASK_SPECIAL){ + if (insn->insn & INSN_MASK_SPECIAL) { /* a non-subdevice instruction */ - switch(insn->insn){ + switch (insn->insn) { case INSN_GTOD: - { - struct timeval tv; + { + struct timeval tv; - if(insn->n!=2){ - ret=-EINVAL; - break; - } + if (insn->n != 2) { + ret = -EINVAL; + break; + } - do_gettimeofday(&tv); - data[0]=tv.tv_sec; - data[1]=tv.tv_usec; - ret=2; + do_gettimeofday(&tv); + data[0] = tv.tv_sec; + data[1] = tv.tv_usec; + ret = 2; - break; - } + break; + } case INSN_WAIT: - if(insn->n!=1 || data[0]>=100000){ - ret=-EINVAL; + if (insn->n != 1 || data[0] >= 100000) { + ret = -EINVAL; break; } - udelay(data[0]/1000); - ret=1; + udelay(data[0] / 1000); + ret = 1; break; case INSN_INTTRIG: - if(insn->n!=1){ - ret=-EINVAL; + if (insn->n != 1) { + ret = -EINVAL; break; } - if(insn->subdev>=dev->n_subdevices){ - DPRINTK("%d not usable subdevice\n",insn->subdev); - ret=-EINVAL; + if (insn->subdev >= dev->n_subdevices) { + DPRINTK("%d not usable subdevice\n", + insn->subdev); + ret = -EINVAL; break; } - s=dev->subdevices+insn->subdev; - if(!s->async){ + s = dev->subdevices + insn->subdev; + if (!s->async) { DPRINTK("no async\n"); - ret=-EINVAL; + ret = -EINVAL; break; } - if(!s->async->inttrig){ + if (!s->async->inttrig) { DPRINTK("no inttrig\n"); - ret=-EAGAIN; + ret = -EAGAIN; break; } - ret = s->async->inttrig(dev,s,insn->data[0]); - if(ret>=0)ret = 1; + ret = s->async->inttrig(dev, s, insn->data[0]); + if (ret >= 0) + ret = 1; break; default: DPRINTK("invalid insn\n"); - ret=-EINVAL; + ret = -EINVAL; break; } - }else{ + } else { /* a subdevice instruction */ - if(insn->subdev>=dev->n_subdevices){ - DPRINTK("subdevice %d out of range\n",insn->subdev); - ret=-EINVAL; + if (insn->subdev >= dev->n_subdevices) { + DPRINTK("subdevice %d out of range\n", insn->subdev); + ret = -EINVAL; goto out; } - s=dev->subdevices+insn->subdev; + s = dev->subdevices + insn->subdev; - if(s->type==COMEDI_SUBD_UNUSED){ - DPRINTK("%d not usable subdevice\n",insn->subdev); + if (s->type == COMEDI_SUBD_UNUSED) { + DPRINTK("%d not usable subdevice\n", insn->subdev); ret = -EIO; goto out; } /* are we locked? (ioctl lock) */ - if(s->lock && s->lock!=file){ + if (s->lock && s->lock != file) { DPRINTK("device locked\n"); ret = -EACCES; goto out; } - if((ret=check_chanlist(s,1,&insn->chanspec))<0){ - ret=-EINVAL; + if ((ret = check_chanlist(s, 1, &insn->chanspec)) < 0) { + ret = -EINVAL; DPRINTK("bad chanspec\n"); goto out; } - if(s->busy){ - ret=-EBUSY; + if (s->busy) { + ret = -EBUSY; goto out; } /* This looks arbitrary. It is. */ - s->busy=&parse_insn; - switch(insn->insn){ - case INSN_READ: - ret=s->insn_read(dev,s,insn,data); - break; - case INSN_WRITE: - for(i = 0; i < insn->n; ++i) - { - if(data[i] > s->maxdata) ret = -EINVAL; - } - if(ret == 0) - ret = s->insn_write(dev,s,insn,data); - break; - case INSN_BITS: - if(insn->n != 2) - { - ret=-EINVAL; - break; - } - ret=s->insn_bits(dev,s,insn,data); - break; - case INSN_CONFIG: - ret=check_insn_config_length(insn, data); - if(ret) break; - ret=s->insn_config(dev,s,insn,data); + s->busy = &parse_insn; + switch (insn->insn) { + case INSN_READ: + ret = s->insn_read(dev, s, insn, data); + break; + case INSN_WRITE: + for (i = 0; i < insn->n; ++i) { + if (data[i] > s->maxdata) + ret = -EINVAL; + } + if (ret == 0) + ret = s->insn_write(dev, s, insn, data); + break; + case INSN_BITS: + if (insn->n != 2) { + ret = -EINVAL; break; - default: - ret=-EINVAL; + } + ret = s->insn_bits(dev, s, insn, data); + break; + case INSN_CONFIG: + ret = check_insn_config_length(insn, data); + if (ret) break; + ret = s->insn_config(dev, s, insn, data); + break; + default: + ret = -EINVAL; + break; } - s->busy=NULL; + s->busy = NULL; } -out: + out: return ret; } @@ -807,43 +833,46 @@ out: * writes: * data (for reads) */ -static int do_insn_ioctl(comedi_device *dev,void *arg,void *file) +static int do_insn_ioctl(comedi_device * dev, void *arg, void *file) { - comedi_insn insn; - lsampl_t *data = NULL; - int ret=0; + comedi_insn insn; + lsampl_t *data = NULL; + int ret = 0; - data=kmalloc(sizeof(lsampl_t)*MAX_SAMPLES,GFP_KERNEL); - if(!data){ + data = kmalloc(sizeof(lsampl_t) * MAX_SAMPLES, GFP_KERNEL); + if (!data) { ret = -ENOMEM; goto error; } - if(copy_from_user(&insn,arg,sizeof(comedi_insn))){ - ret=-EFAULT; + if (copy_from_user(&insn, arg, sizeof(comedi_insn))) { + ret = -EFAULT; goto error; } /* This is where the behavior of insn and insnlist deviate. */ - if(insn.n>MAX_SAMPLES)insn.n=MAX_SAMPLES; - if(insn.insn&INSN_MASK_WRITE){ - if(copy_from_user(data,insn.data,insn.n*sizeof(lsampl_t))){ - ret=-EFAULT; + if (insn.n > MAX_SAMPLES) + insn.n = MAX_SAMPLES; + if (insn.insn & INSN_MASK_WRITE) { + if (copy_from_user(data, insn.data, insn.n * sizeof(lsampl_t))) { + ret = -EFAULT; goto error; } } - ret = parse_insn(dev,&insn,data,file); - if(ret<0)goto error; - if(insn.insn&INSN_MASK_READ){ - if(copy_to_user(insn.data,data,insn.n*sizeof(lsampl_t))){ - ret=-EFAULT; + ret = parse_insn(dev, &insn, data, file); + if (ret < 0) + goto error; + if (insn.insn & INSN_MASK_READ) { + if (copy_to_user(insn.data, data, insn.n * sizeof(lsampl_t))) { + ret = -EFAULT; goto error; } } ret = insn.n; -error: - if(data)kfree(data); + error: + if (data) + kfree(data); return ret; } @@ -863,92 +892,97 @@ error: modified cmd structure at arg */ -static int do_cmd_ioctl(comedi_device *dev,void *arg,void *file) +static int do_cmd_ioctl(comedi_device * dev, void *arg, void *file) { comedi_cmd user_cmd; comedi_subdevice *s; comedi_async *async; - int ret=0; - unsigned int *chanlist_saver=NULL; + int ret = 0; + unsigned int *chanlist_saver = NULL; - if(copy_from_user(&user_cmd,arg,sizeof(comedi_cmd))){ + if (copy_from_user(&user_cmd, arg, sizeof(comedi_cmd))) { DPRINTK("bad cmd address\n"); return -EFAULT; } - // save user's chanlist pointer so it can be restored later chanlist_saver = user_cmd.chanlist; - if(user_cmd.subdev>=dev->n_subdevices){ - DPRINTK("%d no such subdevice\n",user_cmd.subdev); + if (user_cmd.subdev >= dev->n_subdevices) { + DPRINTK("%d no such subdevice\n", user_cmd.subdev); return -ENODEV; } - s=dev->subdevices+user_cmd.subdev; + s = dev->subdevices + user_cmd.subdev; async = s->async; - if(s->type==COMEDI_SUBD_UNUSED){ - DPRINTK("%d not valid subdevice\n",user_cmd.subdev); + if (s->type == COMEDI_SUBD_UNUSED) { + DPRINTK("%d not valid subdevice\n", user_cmd.subdev); return -EIO; } - if(!s->do_cmd || !s->do_cmdtest || !s->async){ - DPRINTK("subdevice %i does not support commands\n", user_cmd.subdev); + if (!s->do_cmd || !s->do_cmdtest || !s->async) { + DPRINTK("subdevice %i does not support commands\n", + user_cmd.subdev); return -EIO; } /* are we locked? (ioctl lock) */ - if(s->lock && s->lock!=file){ + if (s->lock && s->lock != file) { DPRINTK("subdevice locked\n"); return -EACCES; } /* are we busy? */ - if(s->busy){ + if (s->busy) { DPRINTK("subdevice busy\n"); return -EBUSY; } - s->busy=file; + s->busy = file; /* make sure channel/gain list isn't too long */ - if(user_cmd.chanlist_len > s->len_chanlist){ - DPRINTK("channel/gain list too long %d > %d\n",user_cmd.chanlist_len,s->len_chanlist); + if (user_cmd.chanlist_len > s->len_chanlist) { + DPRINTK("channel/gain list too long %d > %d\n", + user_cmd.chanlist_len, s->len_chanlist); ret = -EINVAL; goto cleanup; } - if(async->cmd.chanlist) kfree(async->cmd.chanlist); - async->cmd=user_cmd; - async->cmd.data=NULL; + if (async->cmd.chanlist) + kfree(async->cmd.chanlist); + async->cmd = user_cmd; + async->cmd.data = NULL; /* load channel/gain list */ - async->cmd.chanlist=kmalloc(async->cmd.chanlist_len*sizeof(int),GFP_KERNEL); - if(!async->cmd.chanlist){ + async->cmd.chanlist = + kmalloc(async->cmd.chanlist_len * sizeof(int), GFP_KERNEL); + if (!async->cmd.chanlist) { DPRINTK("allocation failed\n"); ret = -ENOMEM; goto cleanup; } - if(copy_from_user(async->cmd.chanlist,user_cmd.chanlist,async->cmd.chanlist_len*sizeof(int))){ + if (copy_from_user(async->cmd.chanlist, user_cmd.chanlist, + async->cmd.chanlist_len * sizeof(int))) { DPRINTK("fault reading chanlist\n"); ret = -EFAULT; goto cleanup; } /* make sure each element in channel/gain list is valid */ - if((ret=check_chanlist(s,async->cmd.chanlist_len,async->cmd.chanlist))<0){ + if ((ret = check_chanlist(s, async->cmd.chanlist_len, + async->cmd.chanlist)) < 0) { DPRINTK("bad chanlist\n"); goto cleanup; } - ret=s->do_cmdtest(dev,s,&async->cmd); + ret = s->do_cmdtest(dev, s, &async->cmd); - if(async->cmd.flags&TRIG_BOGUS || ret){ - DPRINTK("test returned %d\n",ret); - user_cmd=async->cmd; + if (async->cmd.flags & TRIG_BOGUS || ret) { + DPRINTK("test returned %d\n", ret); + user_cmd = async->cmd; // restore chanlist pointer before copying back user_cmd.chanlist = chanlist_saver; user_cmd.data = NULL; - if(copy_to_user(arg,&user_cmd,sizeof(comedi_cmd))){ + if (copy_to_user(arg, &user_cmd, sizeof(comedi_cmd))) { DPRINTK("fault writing cmd\n"); ret = -EFAULT; goto cleanup; @@ -957,33 +991,36 @@ static int do_cmd_ioctl(comedi_device *dev,void *arg,void *file) goto cleanup; } - if(!async->prealloc_bufsz){ - ret=-ENOMEM; + if (!async->prealloc_bufsz) { + ret = -ENOMEM; DPRINTK("no buffer (?)\n"); goto cleanup; } - comedi_reset_async_buf( async ); + comedi_reset_async_buf(async); - async->cb_mask = COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW; - if(async->cmd.flags & TRIG_WAKE_EOS){ + async->cb_mask = + COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR | + COMEDI_CB_OVERFLOW; + if (async->cmd.flags & TRIG_WAKE_EOS) { async->cb_mask |= COMEDI_CB_EOS; } comedi_set_subdevice_runflags(s, ~0, SRF_USER | SRF_RUNNING); #ifdef CONFIG_COMEDI_RT - if(async->cmd.flags&TRIG_RT){ + if (async->cmd.flags & TRIG_RT) { comedi_switch_to_rt(dev); comedi_set_subdevice_runflags(s, SRF_RT, SRF_RT); } #endif - ret=s->do_cmd(dev,s); - if(ret==0)return 0; + ret = s->do_cmd(dev, s); + if (ret == 0) + return 0; -cleanup: - do_become_nonbusy(dev,s); + cleanup: + do_become_nonbusy(dev, s); return ret; } @@ -1003,81 +1040,86 @@ cleanup: modified cmd structure at arg */ -static int do_cmdtest_ioctl(comedi_device *dev,void *arg,void *file) +static int do_cmdtest_ioctl(comedi_device * dev, void *arg, void *file) { comedi_cmd user_cmd; comedi_subdevice *s; - int ret=0; - unsigned int *chanlist=NULL; - unsigned int *chanlist_saver=NULL; + int ret = 0; + unsigned int *chanlist = NULL; + unsigned int *chanlist_saver = NULL; - if(copy_from_user(&user_cmd,arg,sizeof(comedi_cmd))){ + if (copy_from_user(&user_cmd, arg, sizeof(comedi_cmd))) { DPRINTK("bad cmd address\n"); return -EFAULT; } - // save user's chanlist pointer so it can be restored later chanlist_saver = user_cmd.chanlist; - if(user_cmd.subdev>=dev->n_subdevices){ - DPRINTK("%d no such subdevice\n",user_cmd.subdev); + if (user_cmd.subdev >= dev->n_subdevices) { + DPRINTK("%d no such subdevice\n", user_cmd.subdev); return -ENODEV; } - s=dev->subdevices+user_cmd.subdev; - if(s->type==COMEDI_SUBD_UNUSED){ - DPRINTK("%d not valid subdevice\n",user_cmd.subdev); + s = dev->subdevices + user_cmd.subdev; + if (s->type == COMEDI_SUBD_UNUSED) { + DPRINTK("%d not valid subdevice\n", user_cmd.subdev); return -EIO; } - if(!s->do_cmd || !s->do_cmdtest){ - DPRINTK("subdevice %i does not support commands\n", user_cmd.subdev); + if (!s->do_cmd || !s->do_cmdtest) { + DPRINTK("subdevice %i does not support commands\n", + user_cmd.subdev); return -EIO; } /* make sure channel/gain list isn't too long */ - if(user_cmd.chanlist_len > s->len_chanlist){ - DPRINTK("channel/gain list too long %d > %d\n",user_cmd.chanlist_len,s->len_chanlist); + if (user_cmd.chanlist_len > s->len_chanlist) { + DPRINTK("channel/gain list too long %d > %d\n", + user_cmd.chanlist_len, s->len_chanlist); ret = -EINVAL; goto cleanup; } /* load channel/gain list */ - if(user_cmd.chanlist){ - chanlist=kmalloc(user_cmd.chanlist_len*sizeof(int),GFP_KERNEL); - if(!chanlist){ + if (user_cmd.chanlist) { + chanlist = + kmalloc(user_cmd.chanlist_len * sizeof(int), + GFP_KERNEL); + if (!chanlist) { DPRINTK("allocation failed\n"); ret = -ENOMEM; goto cleanup; } - if(copy_from_user(chanlist,user_cmd.chanlist,user_cmd.chanlist_len*sizeof(int))){ + if (copy_from_user(chanlist, user_cmd.chanlist, + user_cmd.chanlist_len * sizeof(int))) { DPRINTK("fault reading chanlist\n"); ret = -EFAULT; goto cleanup; } /* make sure each element in channel/gain list is valid */ - if((ret=check_chanlist(s,user_cmd.chanlist_len,chanlist))<0){ + if ((ret = check_chanlist(s, user_cmd.chanlist_len, + chanlist)) < 0) { DPRINTK("bad chanlist\n"); goto cleanup; } - user_cmd.chanlist=chanlist; + user_cmd.chanlist = chanlist; } - ret=s->do_cmdtest(dev,s,&user_cmd); + ret = s->do_cmdtest(dev, s, &user_cmd); // restore chanlist pointer before copying back user_cmd.chanlist = chanlist_saver; - if(copy_to_user(arg,&user_cmd,sizeof(comedi_cmd))){ + if (copy_to_user(arg, &user_cmd, sizeof(comedi_cmd))) { DPRINTK("bad cmd address\n"); - ret=-EFAULT; + ret = -EFAULT; goto cleanup; } -cleanup: - if(chanlist) + cleanup: + if (chanlist) kfree(chanlist); return ret; @@ -1098,41 +1140,39 @@ cleanup: */ -static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file) +static int do_lock_ioctl(comedi_device * dev, unsigned int arg, void *file) { - int ret=0; + int ret = 0; unsigned long flags; comedi_subdevice *s; - if(arg>=dev->n_subdevices) + if (arg >= dev->n_subdevices) return -EINVAL; - s=dev->subdevices+arg; + s = dev->subdevices + arg; comedi_spin_lock_irqsave(&big_comedi_lock, flags); - if(s->busy) - { + if (s->busy) { comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); return -EBUSY; } - if(s->lock){ - ret=-EBUSY; - }else{ - s->lock=file; + if (s->lock) { + ret = -EBUSY; + } else { + s->lock = file; } comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); - if(ret<0) + if (ret < 0) return ret; #if 0 - if(s->lock_f) - ret=s->lock_f(dev,s); + if (s->lock_f) + ret = s->lock_f(dev, s); #endif return ret; } - /* COMEDI_UNLOCK unlock subdevice @@ -1149,27 +1189,27 @@ static int do_lock_ioctl(comedi_device *dev,unsigned int arg,void * file) This function isn't protected by the semaphore, since we already own the lock. */ -static int do_unlock_ioctl(comedi_device *dev,unsigned int arg,void * file) +static int do_unlock_ioctl(comedi_device * dev, unsigned int arg, void *file) { comedi_subdevice *s; - if(arg>=dev->n_subdevices) + if (arg >= dev->n_subdevices) return -EINVAL; - s=dev->subdevices+arg; + s = dev->subdevices + arg; - if(s->busy) + if (s->busy) return -EBUSY; - if(s->lock && s->lock!=file) + if (s->lock && s->lock != file) return -EACCES; - if(s->lock==file){ + if (s->lock == file) { #if 0 - if(s->unlock) - s->unlock(dev,s); + if (s->unlock) + s->unlock(dev, s); #endif - s->lock=NULL; + s->lock = NULL; } return 0; @@ -1189,26 +1229,26 @@ static int do_unlock_ioctl(comedi_device *dev,unsigned int arg,void * file) nothing */ -static int do_cancel_ioctl(comedi_device *dev,unsigned int arg,void *file) +static int do_cancel_ioctl(comedi_device * dev, unsigned int arg, void *file) { comedi_subdevice *s; - if(arg>=dev->n_subdevices) + if (arg >= dev->n_subdevices) return -EINVAL; - s=dev->subdevices+arg; - if(s->async == NULL) + s = dev->subdevices + arg; + if (s->async == NULL) return -EINVAL; - if(s->lock && s->lock!=file) + if (s->lock && s->lock != file) return -EACCES; - if(!s->busy) + if (!s->busy) return 0; - if(s->busy!=file) + if (s->busy != file) return -EBUSY; - return do_cancel(dev,s); + return do_cancel(dev, s); } /* @@ -1225,41 +1265,41 @@ static int do_cancel_ioctl(comedi_device *dev,unsigned int arg,void *file) nothing */ -static int do_poll_ioctl(comedi_device *dev,unsigned int arg,void *file) +static int do_poll_ioctl(comedi_device * dev, unsigned int arg, void *file) { comedi_subdevice *s; - if(arg>=dev->n_subdevices) + if (arg >= dev->n_subdevices) return -EINVAL; - s=dev->subdevices+arg; + s = dev->subdevices + arg; - if(s->lock && s->lock!=file) + if (s->lock && s->lock != file) return -EACCES; - if(!s->busy) + if (!s->busy) return 0; - if(s->busy!=file) + if (s->busy != file) return -EBUSY; - if(s->poll)return s->poll(dev,s); + if (s->poll) + return s->poll(dev, s); return -EINVAL; } -static int do_cancel(comedi_device *dev,comedi_subdevice *s) +static int do_cancel(comedi_device * dev, comedi_subdevice * s) { - int ret=0; + int ret = 0; - if((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel) - ret=s->cancel(dev,s); + if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel) + ret = s->cancel(dev, s); - do_become_nonbusy(dev,s); + do_become_nonbusy(dev, s); return ret; } - void comedi_unmap(struct vm_area_struct *area) { comedi_async *async; @@ -1269,11 +1309,11 @@ void comedi_unmap(struct vm_area_struct *area) async->mmap_count--; } -static struct vm_operations_struct comedi_vm_ops={ - close: comedi_unmap, +static struct vm_operations_struct comedi_vm_ops = { + close:comedi_unmap, }; -static int comedi_mmap(struct file * file, struct vm_area_struct *vma) +static int comedi_mmap(struct file *file, struct vm_area_struct *vma) { const unsigned minor = iminor(file->f_dentry->d_inode); comedi_device *dev = comedi_get_device_by_minor(minor); @@ -1284,39 +1324,39 @@ static int comedi_mmap(struct file * file, struct vm_area_struct *vma) int i; comedi_subdevice *s; - if(!dev->attached) - { + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); return -ENODEV; } - if(vma->vm_flags & VM_WRITE) - { + if (vma->vm_flags & VM_WRITE) { s = comedi_get_write_subdevice(dev, minor); - }else - { + } else { s = comedi_get_read_subdevice(dev, minor); } - if(s == NULL) return -EINVAL; + if (s == NULL) + return -EINVAL; async = s->async; - if(async==NULL){ + if (async == NULL) { return -EINVAL; } - if(vma->vm_pgoff != 0){ + if (vma->vm_pgoff != 0) { DPRINTK("comedi: mmap() offset must be 0.\n"); return -EINVAL; } size = vma->vm_end - vma->vm_start; - if(size>async->prealloc_bufsz) + if (size > async->prealloc_bufsz) return -EFAULT; - if(size&(~PAGE_MASK)) + if (size & (~PAGE_MASK)) return -EFAULT; n_pages = size >> PAGE_SHIFT; - for(i = 0; i < n_pages; ++i){ - if(remap_pfn_range(vma, start, page_to_pfn(virt_to_page(async->buf_page_list[i].virt_addr)), - PAGE_SIZE, PAGE_SHARED)){ + for (i = 0; i < n_pages; ++i) { + if (remap_pfn_range(vma, start, + page_to_pfn(virt_to_page(async-> + buf_page_list[i].virt_addr)), + PAGE_SIZE, PAGE_SHARED)) { return -EAGAIN; } start += PAGE_SIZE; @@ -1330,7 +1370,6 @@ static int comedi_mmap(struct file * file, struct vm_area_struct *vma) return 0; } - static unsigned int comedi_poll(struct file *file, poll_table * wait) { unsigned int mask; @@ -1339,26 +1378,28 @@ static unsigned int comedi_poll(struct file *file, poll_table * wait) comedi_subdevice *read_subdev = comedi_get_read_subdevice(dev, minor); comedi_subdevice *write_subdev = comedi_get_write_subdevice(dev, minor); - if(!dev->attached) - { + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); return -ENODEV; } mask = 0; - if(read_subdev){ + if (read_subdev) { poll_wait(file, &read_subdev->async->wait_head, wait); - if(!read_subdev->busy + if (!read_subdev->busy || comedi_buf_read_n_available(read_subdev->async) > 0 - || !(comedi_get_subdevice_runflags(read_subdev) & SRF_RUNNING)){ + || !(comedi_get_subdevice_runflags(read_subdev) & + SRF_RUNNING)) { mask |= POLLIN | POLLRDNORM; } } - if(write_subdev){ + if (write_subdev) { poll_wait(file, &write_subdev->async->wait_head, wait); - if(!write_subdev->busy - || !(comedi_get_subdevice_runflags(write_subdev) & SRF_RUNNING) - || comedi_buf_write_n_available(write_subdev->async) > 0){ + if (!write_subdev->busy + || !(comedi_get_subdevice_runflags(write_subdev) & + SRF_RUNNING) + || comedi_buf_write_n_available(write_subdev->async) > + 0) { mask |= POLLOUT | POLLWRNORM; } } @@ -1366,69 +1407,70 @@ static unsigned int comedi_poll(struct file *file, poll_table * wait) return mask; } -static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff_t *offset) +static ssize_t comedi_write(struct file *file, const char *buf, size_t nbytes, + loff_t * offset) { comedi_device *dev; comedi_subdevice *s; comedi_async *async; - int n,m,count=0,retval=0; - DECLARE_WAITQUEUE(wait,current); + int n, m, count = 0, retval = 0; + DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); dev = comedi_get_device_by_minor(minor); - if(!dev->attached) - { + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); return -ENODEV; } s = comedi_get_write_subdevice(dev, minor); - if(s == NULL) + if (s == NULL) return -EIO; async = s->async; - if(!nbytes)return 0; + if (!nbytes) + return 0; - if(!s->busy) - { + if (!s->busy) { return 0; } - if(s->busy != file) + if (s->busy != file) return -EACCES; add_wait_queue(&async->wait_head, &wait); - while(nbytes>0 && !retval){ + while (nbytes > 0 && !retval) { set_current_state(TASK_INTERRUPTIBLE); - n=nbytes; + n = nbytes; m = n; - if(async->buf_write_ptr + m > async->prealloc_bufsz){ + if (async->buf_write_ptr + m > async->prealloc_bufsz) { m = async->prealloc_bufsz - async->buf_write_ptr; } comedi_buf_write_alloc(async, async->prealloc_bufsz); - if(m > comedi_buf_write_n_allocated(async)) - { + if (m > comedi_buf_write_n_allocated(async)) { m = comedi_buf_write_n_allocated(async); } - if(m < n) n = m; + if (m < n) + n = m; - if(n==0){ - if(file->f_flags&O_NONBLOCK){ - retval=-EAGAIN; + if (n == 0) { + if (file->f_flags & O_NONBLOCK) { + retval = -EAGAIN; break; } - if(!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)){ - if(comedi_get_subdevice_runflags(s) & SRF_ERROR){ + if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { + if (comedi_get_subdevice_runflags(s) & + SRF_ERROR) { retval = -EPIPE; - }else{ + } else { retval = 0; } - do_become_nonbusy(dev,s); + do_become_nonbusy(dev, s); break; } - if(signal_pending(current)){ - retval=-ERESTARTSYS; + if (signal_pending(current)) { + retval = -ERESTARTSYS; break; } schedule(); @@ -1437,17 +1479,17 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff m = copy_from_user(async->prealloc_buf + async->buf_write_ptr, buf, n); - if(m){ + if (m) { n -= m; retval = -EFAULT; } comedi_buf_write_free(async, n); - count+=n; - nbytes-=n; + count += n; + nbytes -= n; - buf+=n; - break; /* makes device work like a pipe */ + buf += n; + break; /* makes device work like a pipe */ } set_current_state(TASK_RUNNING); remove_wait_queue(&async->wait_head, &wait); @@ -1455,63 +1497,66 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff return (count ? count : retval); } - -static ssize_t comedi_read(struct file * file,char *buf,size_t nbytes,loff_t *offset) +static ssize_t comedi_read(struct file *file, char *buf, size_t nbytes, + loff_t * offset) { comedi_subdevice *s; comedi_async *async; - int n,m,count=0,retval=0; - DECLARE_WAITQUEUE(wait,current); + int n, m, count = 0, retval = 0; + DECLARE_WAITQUEUE(wait, current); const unsigned minor = iminor(file->f_dentry->d_inode); comedi_device *dev = comedi_get_device_by_minor(minor); - if(!dev->attached) - { + if (!dev->attached) { DPRINTK("no driver configured on comedi%i\n", dev->minor); return -ENODEV; } s = comedi_get_read_subdevice(dev, minor); - if(s == NULL) return -EIO; + if (s == NULL) + return -EIO; async = s->async; - if(!nbytes)return 0; + if (!nbytes) + return 0; - if(!s->busy) + if (!s->busy) return 0; - if(s->busy != file) + if (s->busy != file) return -EACCES; add_wait_queue(&async->wait_head, &wait); - while(nbytes>0 && !retval){ + while (nbytes > 0 && !retval) { set_current_state(TASK_INTERRUPTIBLE); - n=nbytes; + n = nbytes; m = comedi_buf_read_n_available(async); //printk("%d available\n",m); - if(async->buf_read_ptr + m > async->prealloc_bufsz){ + if (async->buf_read_ptr + m > async->prealloc_bufsz) { m = async->prealloc_bufsz - async->buf_read_ptr; } //printk("%d contiguous\n",m); - if(mf_flags&O_NONBLOCK){ - retval=-EAGAIN; + if (n == 0) { + if (file->f_flags & O_NONBLOCK) { + retval = -EAGAIN; break; } - if(!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)){ - do_become_nonbusy(dev,s); - if(comedi_get_subdevice_runflags(s) & SRF_ERROR){ + if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { + do_become_nonbusy(dev, s); + if (comedi_get_subdevice_runflags(s) & + SRF_ERROR) { retval = -EPIPE; - }else{ + } else { retval = 0; } break; } - if(signal_pending(current)){ - retval=-ERESTARTSYS; + if (signal_pending(current)) { + retval = -ERESTARTSYS; break; } schedule(); @@ -1519,7 +1564,7 @@ static ssize_t comedi_read(struct file * file,char *buf,size_t nbytes,loff_t *of } m = copy_to_user(buf, async->prealloc_buf + async->buf_read_ptr, n); - if(m){ + if (m) { n -= m; retval = -EFAULT; } @@ -1527,16 +1572,15 @@ static ssize_t comedi_read(struct file * file,char *buf,size_t nbytes,loff_t *of comedi_buf_read_alloc(async, n); comedi_buf_read_free(async, n); - count+=n; - nbytes-=n; + count += n; + nbytes -= n; - buf+=n; - break; /* makes device work like a pipe */ + buf += n; + break; /* makes device work like a pipe */ } - if(!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | SRF_RUNNING)) && - async->buf_read_count - async->buf_write_count == 0) - { - do_become_nonbusy(dev,s); + if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | SRF_RUNNING)) && + async->buf_read_count - async->buf_write_count == 0) { + do_become_nonbusy(dev, s); } set_current_state(TASK_RUNNING); remove_wait_queue(&async->wait_head, &wait); @@ -1547,25 +1591,25 @@ static ssize_t comedi_read(struct file * file,char *buf,size_t nbytes,loff_t *of /* This function restores a subdevice to an idle state. */ -void do_become_nonbusy(comedi_device *dev,comedi_subdevice *s) +void do_become_nonbusy(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_set_subdevice_runflags(s, SRF_RUNNING, 0); #ifdef CONFIG_COMEDI_RT - if(comedi_get_subdevice_runflags(s) & SRF_RT){ + if (comedi_get_subdevice_runflags(s) & SRF_RT) { comedi_switch_to_non_rt(dev); comedi_set_subdevice_runflags(s, SRF_RT, 0); } #endif - if(async){ - comedi_reset_async_buf( async ); + if (async) { + comedi_reset_async_buf(async); async->inttrig = NULL; - }else{ + } else { printk("BUG: (?) do_become_nonbusy called with async=0\n"); } - s->busy=NULL; + s->busy = NULL; } static int comedi_open(struct inode *inode, struct file *file) @@ -1573,8 +1617,7 @@ static int comedi_open(struct inode *inode, struct file *file) char mod[32]; const unsigned minor = iminor(inode); comedi_device *dev = comedi_get_device_by_minor(minor); - if(dev == NULL) - { + if (dev == NULL) { DPRINTK("invalid minor number\n"); return -ENODEV; } @@ -1592,37 +1635,37 @@ static int comedi_open(struct inode *inode, struct file *file) * The last could be changed to "-> ok", which would deny root * autoloading. */ - if(dev->attached) + if (dev->attached) goto ok; - if(!capable(CAP_SYS_MODULE) && dev->in_request_module){ + if (!capable(CAP_SYS_MODULE) && dev->in_request_module) { DPRINTK("in request module\n"); return -ENODEV; } - if(capable(CAP_SYS_MODULE) && dev->in_request_module) + if (capable(CAP_SYS_MODULE) && dev->in_request_module) goto ok; - dev->in_request_module=1; + dev->in_request_module = 1; - sprintf(mod,"char-major-%i-%i", COMEDI_MAJOR, dev->minor); + sprintf(mod, "char-major-%i-%i", COMEDI_MAJOR, dev->minor); #ifdef CONFIG_KMOD request_module(mod); #endif - dev->in_request_module=0; + dev->in_request_module = 0; - if(!dev->attached && !capable(CAP_SYS_MODULE)){ + if (!dev->attached && !capable(CAP_SYS_MODULE)) { DPRINTK("not attached and not CAP_SYS_MODULE\n"); return -ENODEV; } -ok: - if(!try_module_get(THIS_MODULE)) + ok: + if (!try_module_get(THIS_MODULE)) return -ENOSYS; - if(dev->attached){ - try_module_get( dev->driver->module ); + if (dev->attached) { + try_module_get(dev->driver->module); } - if(dev->attached && dev->use_count==0 && dev->open){ + if (dev->attached && dev->use_count == 0 && dev->open) { dev->open(dev); } @@ -1631,63 +1674,61 @@ ok: return 0; } -static int comedi_close(struct inode *inode,struct file *file) +static int comedi_close(struct inode *inode, struct file *file) { const unsigned minor = iminor(inode); comedi_device *dev = comedi_get_device_by_minor(minor); comedi_subdevice *s = NULL; int i; - if(dev->subdevices) - { - for(i=0;in_subdevices;i++){ - s=dev->subdevices+i; + if (dev->subdevices) { + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; - if(s->busy==file){ - do_cancel(dev,s); + if (s->busy == file) { + do_cancel(dev, s); } - if(s->lock==file){ - s->lock=NULL; + if (s->lock == file) { + s->lock = NULL; } } } - if(dev->attached && dev->use_count==1 && dev->close){ + if (dev->attached && dev->use_count == 1 && dev->close) { dev->close(dev); } module_put(THIS_MODULE); - if(dev->attached){ + if (dev->attached) { module_put(dev->driver->module); } dev->use_count--; - if(file->f_flags & FASYNC){ - comedi_fasync(-1,file,0); + if (file->f_flags & FASYNC) { + comedi_fasync(-1, file, 0); } return 0; } -static int comedi_fasync (int fd, struct file *file, int on) +static int comedi_fasync(int fd, struct file *file, int on) { const unsigned minor = iminor(file->f_dentry->d_inode); comedi_device *dev = comedi_get_device_by_minor(minor); - return fasync_helper(fd,file,on,&dev->async_queue); + return fasync_helper(fd, file, on, &dev->async_queue); } - -const struct file_operations comedi_fops={ - owner : THIS_MODULE, - ioctl : comedi_ioctl, - open : comedi_open, - release : comedi_close, - read : comedi_read, - write : comedi_write, - mmap : comedi_mmap, - poll : comedi_poll, - fasync : comedi_fasync, +const struct file_operations comedi_fops = { + owner:THIS_MODULE, + ioctl:comedi_ioctl, + open:comedi_open, + release:comedi_close, + read:comedi_read, + write:comedi_write, + mmap:comedi_mmap, + poll:comedi_poll, + fasync:comedi_fasync, }; struct class *comedi_class = NULL; @@ -1698,30 +1739,34 @@ static int __init comedi_init(void) int i; int retval; - printk("comedi: version " COMEDI_RELEASE " - David Schleef \n"); + printk("comedi: version " COMEDI_RELEASE + " - David Schleef \n"); spin_lock_init(&big_comedi_lock); - retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS, "comedi"); - if(retval) return -EIO; + retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS, "comedi"); + if (retval) + return -EIO; cdev_init(&comedi_cdev, &comedi_fops); comedi_cdev.owner = THIS_MODULE; kobject_set_name(&comedi_cdev.kobj, "comedi"); - if(cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) - { - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); + if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) { + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); return -EIO; } comedi_class = class_create(THIS_MODULE, "comedi"); - if(IS_ERR(comedi_class)) - { + if (IS_ERR(comedi_class)) { printk("comedi: failed to create class"); - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); cdev_del(&comedi_cdev); return PTR_ERR(comedi_class); } - comedi_devices=kcalloc(COMEDI_NDEVICES,sizeof(comedi_device),GFP_KERNEL); - if(!comedi_devices) - { - unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS); + comedi_devices = + kcalloc(COMEDI_NDEVICES, sizeof(comedi_device), GFP_KERNEL); + if (!comedi_devices) { + unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), + COMEDI_NUM_MINORS); cdev_del(&comedi_cdev); class_destroy(comedi_class); return -ENOMEM; @@ -1730,11 +1775,12 @@ static int __init comedi_init(void) /* XXX requires /proc interface */ comedi_proc_init(); - for(i=0;iattached) + if (dev->attached) comedi_device_detach(dev); } - for(i = 0; i < COMEDI_NDEVICES; i++){ + for (i = 0; i < COMEDI_NDEVICES; i++) { char name[20]; class_device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, i)); sprintf(name, "comedi%d", i); @@ -1778,12 +1824,13 @@ static void __exit comedi_cleanup(void) module_init(comedi_init); module_exit(comedi_cleanup); -void comedi_error(const comedi_device *dev,const char *s) +void comedi_error(const comedi_device * dev, const char *s) { - rt_printk("comedi%d: %s: %s\n", dev->minor, dev->driver->driver_name, s); + rt_printk("comedi%d: %s: %s\n", dev->minor, dev->driver->driver_name, + s); } -void comedi_event(comedi_device *dev, comedi_subdevice *s) +void comedi_event(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; unsigned runflags = 0; @@ -1791,45 +1838,49 @@ void comedi_event(comedi_device *dev, comedi_subdevice *s) //DPRINTK("comedi_event 0x%x\n",mask); - if((comedi_get_subdevice_runflags(s) & SRF_RUNNING) == 0) + if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) == 0) return; - if(s->async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)){ + if (s->async-> + events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) + { runflags_mask |= SRF_RUNNING; } /* remember if an error event has occured, so an error * can be returned the next time the user does a read() */ - if(s->async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)){ + if (s->async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) { runflags_mask |= SRF_ERROR; runflags |= SRF_ERROR; } - if(runflags_mask) - { + if (runflags_mask) { /*sets SRF_ERROR and SRF_RUNNING together atomically */ comedi_set_subdevice_runflags(s, runflags_mask, runflags); } - if(async->cb_mask & s->async->events){ - if(comedi_get_subdevice_runflags(s) & SRF_USER){ + if (async->cb_mask & s->async->events) { + if (comedi_get_subdevice_runflags(s) & SRF_USER) { - if(dev->rt){ + if (dev->rt) { #ifdef CONFIG_COMEDI_RT // pend wake up comedi_rt_pend_wakeup(&async->wait_head); #else printk("BUG: comedi_event() code unreachable\n"); #endif - }else{ + } else { wake_up_interruptible(&async->wait_head); - if(s->subdev_flags & SDF_CMD_READ){ - kill_fasync(&dev->async_queue, SIGIO, POLL_IN); + if (s->subdev_flags & SDF_CMD_READ) { + kill_fasync(&dev->async_queue, SIGIO, + POLL_IN); } - if(s->subdev_flags & SDF_CMD_WRITE){ - kill_fasync(&dev->async_queue, SIGIO, POLL_OUT); + if (s->subdev_flags & SDF_CMD_WRITE) { + kill_fasync(&dev->async_queue, SIGIO, + POLL_OUT); } } - }else{ - if(async->cb_func)async->cb_func(s->async->events, async->cb_arg); + } else { + if (async->cb_func) + async->cb_func(s->async->events, async->cb_arg); /* XXX bug here. If subdevice A is rt, and * subdevice B tries to callback to a normal * linux kernel function, it will be at the @@ -1840,7 +1891,8 @@ void comedi_event(comedi_device *dev, comedi_subdevice *s) s->async->events = 0; } -void comedi_set_subdevice_runflags(comedi_subdevice *s, unsigned mask, unsigned bits) +void comedi_set_subdevice_runflags(comedi_subdevice * s, unsigned mask, + unsigned bits) { unsigned long flags; @@ -1850,7 +1902,7 @@ void comedi_set_subdevice_runflags(comedi_subdevice *s, unsigned mask, unsigned comedi_spin_unlock_irqrestore(&s->runflags_lock, flags); } -unsigned comedi_get_subdevice_runflags(comedi_subdevice *s) +unsigned comedi_get_subdevice_runflags(comedi_subdevice * s) { unsigned long flags; unsigned runflags; diff --git a/comedi/comedi_fops.h b/comedi/comedi_fops.h index baf9bc57..08a57128 100644 --- a/comedi/comedi_fops.h +++ b/comedi/comedi_fops.h @@ -5,4 +5,4 @@ extern struct class *comedi_class; extern const struct file_operations comedi_fops; -#endif //_COMEDI_FOPS_H +#endif //_COMEDI_FOPS_H diff --git a/comedi/comedi_ksyms.c b/comedi/comedi_ksyms.c index f86bc701..bfdafed3 100644 --- a/comedi/comedi_ksyms.c +++ b/comedi/comedi_ksyms.c @@ -21,7 +21,6 @@ */ - #define __NO_VERSION__ #ifndef EXPORT_SYMTAB #define EXPORT_SYMTAB @@ -29,9 +28,6 @@ #include - - - /* for drivers */ EXPORT_SYMBOL(comedi_driver_register); EXPORT_SYMBOL(comedi_driver_unregister); @@ -78,5 +74,3 @@ EXPORT_SYMBOL(comedi_buf_read_alloc); EXPORT_SYMBOL(comedi_buf_memcpy_to); EXPORT_SYMBOL(comedi_buf_memcpy_from); EXPORT_SYMBOL(comedi_reset_async_buf); - - diff --git a/comedi/drivers.c b/comedi/drivers.c index 15b396c8..fabf89cc 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -37,7 +37,7 @@ #include #include #include -#include /* for SuSE brokenness */ +#include /* for SuSE brokenness */ #include #include #include @@ -45,14 +45,15 @@ #include #include -static int postconfig(comedi_device *dev); -static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int insn_inval(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static void *comedi_recognize(comedi_driver *driv, const char *name); -static void comedi_report_boards(comedi_driver *driv); -static int poll_invalid(comedi_device *dev,comedi_subdevice *s); -int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, +static int postconfig(comedi_device * dev); +static int insn_rw_emulate_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int insn_inval(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static void *comedi_recognize(comedi_driver * driv, const char *name); +static void comedi_report_boards(comedi_driver * driv); +static int poll_invalid(comedi_device * dev, comedi_subdevice * s); +int comedi_buf_alloc(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); comedi_driver *comedi_drivers; @@ -62,24 +63,22 @@ int comedi_modprobe(int minor) return -EINVAL; } -static void cleanup_device(comedi_device *dev) +static void cleanup_device(comedi_device * dev) { int i; comedi_subdevice *s; - if(dev->subdevices) - { - for(i = 0; i < dev->n_subdevices; i++) - { + if (dev->subdevices) { + for (i = 0; i < dev->n_subdevices; i++) { s = dev->subdevices + i; - if(s->class_dev) - { - unsigned minor = comedi_construct_minor_for_subdevice(dev, i); + if (s->class_dev) { + unsigned minor = + comedi_construct_minor_for_subdevice + (dev, i); dev_t devt = MKDEV(COMEDI_MAJOR, minor); class_device_destroy(comedi_class, devt); } - if(s->async) - { + if (s->async) { comedi_buf_alloc(dev, s, 0); kfree(s->async); } @@ -88,8 +87,7 @@ static void cleanup_device(comedi_device *dev) dev->subdevices = NULL; dev->n_subdevices = 0; } - if(dev->private) - { + if (dev->private) { kfree(dev->private); dev->private = NULL; } @@ -106,55 +104,54 @@ static void cleanup_device(comedi_device *dev) comedi_set_hw_dev(dev, NULL); } -static int __comedi_device_detach(comedi_device *dev) +static int __comedi_device_detach(comedi_device * dev) { dev->attached = 0; - if(dev->driver){ + if (dev->driver) { dev->driver->detach(dev); - }else{ + } else { printk("BUG: dev->driver=NULL in comedi_device_detach()\n"); } cleanup_device(dev); return 0; } -int comedi_device_detach(comedi_device *dev) +int comedi_device_detach(comedi_device * dev) { - if(!dev->attached) + if (!dev->attached) return 0; return __comedi_device_detach(dev); } -int comedi_device_attach(comedi_device *dev,comedi_devconfig *it) +int comedi_device_attach(comedi_device * dev, comedi_devconfig * it) { comedi_driver *driv; int ret; - if(dev->attached) + if (dev->attached) return -EBUSY; - for(driv=comedi_drivers;driv;driv=driv->next){ - if(!try_module_get( driv->module )) - { - printk( "comedi: failed to increment module count, skipping\n" ); + for (driv = comedi_drivers; driv; driv = driv->next) { + if (!try_module_get(driv->module)) { + printk("comedi: failed to increment module count, skipping\n"); continue; } - if(driv->num_names){ + if (driv->num_names) { dev->board_ptr = comedi_recognize(driv, it->board_name); - if(dev->board_ptr==NULL){ - module_put( driv->module ); + if (dev->board_ptr == NULL) { + module_put(driv->module); continue; } - }else{ - if(strcmp(driv->driver_name,it->board_name)){ - module_put( driv->module ); + } else { + if (strcmp(driv->driver_name, it->board_name)) { + module_put(driv->module); continue; } } //initialize dev->driver here so comedi_error() can be called from attach - dev->driver=driv; - ret=driv->attach(dev,it); - if(ret<0){ + dev->driver = driv; + ret = driv->attach(dev, it); + if (ret < 0) { __comedi_device_detach(dev); return ret; } @@ -163,111 +160,109 @@ int comedi_device_attach(comedi_device *dev,comedi_devconfig *it) // recognize has failed if we get here // report valid board names before returning error - for(driv=comedi_drivers;driv;driv=driv->next){ - if(!try_module_get( driv->module )) - { - printk( "comedi: failed to increment module count\n" ); + for (driv = comedi_drivers; driv; driv = driv->next) { + if (!try_module_get(driv->module)) { + printk("comedi: failed to increment module count\n"); continue; } comedi_report_boards(driv); - module_put( driv->module ); + module_put(driv->module); } return -EIO; -attached: + attached: /* do a little post-config cleanup */ ret = postconfig(dev); - if(ret < 0) - { + if (ret < 0) { __comedi_device_detach(dev); return ret; } - if(!dev->board_name){ - printk("BUG: dev->board_name=<%p>\n",dev->board_name); - dev->board_name="BUG"; + if (!dev->board_name) { + printk("BUG: dev->board_name=<%p>\n", dev->board_name); + dev->board_name = "BUG"; } smp_wmb(); - dev->attached=1; + dev->attached = 1; return 0; } -int comedi_driver_register(comedi_driver *driver) +int comedi_driver_register(comedi_driver * driver) { - driver->next=comedi_drivers; - comedi_drivers=driver; + driver->next = comedi_drivers; + comedi_drivers = driver; return 0; } -int comedi_driver_unregister(comedi_driver *driver) +int comedi_driver_unregister(comedi_driver * driver) { comedi_driver *prev; int i; /* check for devices using this driver */ - for(i=0;iattached && dev->driver==driver){ - if(dev->use_count) - printk("BUG! detaching device with use_count=%d\n",dev->use_count); + if (dev->attached && dev->driver == driver) { + if (dev->use_count) + printk("BUG! detaching device with use_count=%d\n", dev->use_count); comedi_device_detach(dev); } } - if(comedi_drivers==driver){ - comedi_drivers=driver->next; + if (comedi_drivers == driver) { + comedi_drivers = driver->next; return 0; } - for(prev=comedi_drivers;prev->next;prev=prev->next){ - if(prev->next==driver){ - prev->next=driver->next; + for (prev = comedi_drivers; prev->next; prev = prev->next) { + if (prev->next == driver) { + prev->next = driver->next; return 0; } } return -EINVAL; } -comedi_device *comedi_allocate_dev(comedi_driver *driver) +comedi_device *comedi_allocate_dev(comedi_driver * driver) { return NULL; } -void comedi_deallocate_dev(comedi_device *dev) +void comedi_deallocate_dev(comedi_device * dev) { } -static int postconfig(comedi_device *dev) +static int postconfig(comedi_device * dev) { int i; comedi_subdevice *s; comedi_async *async = NULL; int ret; - for(i=0;in_subdevices;i++){ - s=dev->subdevices+i; + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; - if(s->type==COMEDI_SUBD_UNUSED) + if (s->type == COMEDI_SUBD_UNUSED) continue; - if(s->len_chanlist==0) - s->len_chanlist=1; + if (s->len_chanlist == 0) + s->len_chanlist = 1; - if(s->do_cmd){ + if (s->do_cmd) { unsigned minor; dev_t devt; - BUG_ON((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0); + BUG_ON((s->subdev_flags & (SDF_CMD_READ | + SDF_CMD_WRITE)) == 0); BUG_ON(!s->do_cmdtest); async = kzalloc(sizeof(comedi_async), GFP_KERNEL); - if(async == NULL) - { + if (async == NULL) { printk("failed to allocate async struct\n"); return -ENOMEM; } @@ -282,91 +277,102 @@ static int postconfig(comedi_device *dev) async->prealloc_buf = NULL; async->prealloc_bufsz = 0; - if(comedi_buf_alloc(dev,s,DEFAULT_BUF_SIZE) < 0){ + if (comedi_buf_alloc(dev, s, DEFAULT_BUF_SIZE) < 0) { printk("Buffer allocation failed\n"); return -ENOMEM; } - if(s->buf_change){ - ret = s->buf_change(dev,s,DEFAULT_BUF_SIZE); - if(ret < 0)return ret; + if (s->buf_change) { + ret = s->buf_change(dev, s, DEFAULT_BUF_SIZE); + if (ret < 0) + return ret; } minor = comedi_construct_minor_for_subdevice(dev, i); devt = MKDEV(COMEDI_MAJOR, minor); - s->class_dev = COMEDI_CLASS_DEVICE_CREATE(comedi_class, dev->class_dev, - devt, NULL, "comedi%i_sub%i", dev->minor, i); + s->class_dev = + COMEDI_CLASS_DEVICE_CREATE(comedi_class, + dev->class_dev, devt, NULL, "comedi%i_sub%i", + dev->minor, i); } - if(!s->range_table && !s->range_table_list) - s->range_table=&range_unknown; + if (!s->range_table && !s->range_table_list) + s->range_table = &range_unknown; - if(!s->insn_read && s->insn_bits) + if (!s->insn_read && s->insn_bits) s->insn_read = insn_rw_emulate_bits; - if(!s->insn_write && s->insn_bits) + if (!s->insn_write && s->insn_bits) s->insn_write = insn_rw_emulate_bits; - if(!s->insn_read)s->insn_read = insn_inval; - if(!s->insn_write)s->insn_write = insn_inval; - if(!s->insn_bits)s->insn_bits = insn_inval; - if(!s->insn_config)s->insn_config = insn_inval; - - if(!s->poll)s->poll=poll_invalid; + if (!s->insn_read) + s->insn_read = insn_inval; + if (!s->insn_write) + s->insn_write = insn_inval; + if (!s->insn_bits) + s->insn_bits = insn_inval; + if (!s->insn_config) + s->insn_config = insn_inval; + + if (!s->poll) + s->poll = poll_invalid; } return 0; } // generic recognize function for drivers that register their supported board names -void *comedi_recognize(comedi_driver *driv, const char *name) +void *comedi_recognize(comedi_driver * driv, const char *name) { unsigned i; - const char * const *name_ptr = driv->board_name; - for(i = 0; i < driv->num_names; i++) - { - if(strcmp(*name_ptr, name) == 0) - return (void*)name_ptr; - name_ptr = (const char * const *)((const char *)name_ptr + driv->offset); + const char *const *name_ptr = driv->board_name; + for (i = 0; i < driv->num_names; i++) { + if (strcmp(*name_ptr, name) == 0) + return (void *)name_ptr; + name_ptr = + (const char *const *)((const char *)name_ptr + + driv->offset); } return NULL; } -void comedi_report_boards(comedi_driver *driv) +void comedi_report_boards(comedi_driver * driv) { unsigned int i; - const char * const *name_ptr; + const char *const *name_ptr; - printk("comedi: valid board names for %s driver are:\n", driv->driver_name); + printk("comedi: valid board names for %s driver are:\n", + driv->driver_name); name_ptr = driv->board_name; - for(i = 0; i < driv->num_names; i++) - { + for (i = 0; i < driv->num_names; i++) { printk(" %s\n", *name_ptr); name_ptr = (const char **)((char *)name_ptr + driv->offset); } - if(driv->num_names == 0) + if (driv->num_names == 0) printk(" %s\n", driv->driver_name); } -static int poll_invalid(comedi_device *dev,comedi_subdevice *s) +static int poll_invalid(comedi_device * dev, comedi_subdevice * s) { return -EINVAL; } -static int insn_inval(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int insn_inval(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { return -EINVAL; } -static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int insn_rw_emulate_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { comedi_insn new_insn; int ret; static const unsigned channels_per_bitfield = 32; unsigned chan = CR_CHAN(insn->chanspec); - const unsigned base_bitfield_channel = (chan < channels_per_bitfield) ? 0 : chan; + const unsigned base_bitfield_channel = + (chan < channels_per_bitfield) ? 0 : chan; lsampl_t new_data[2]; memset(new_data, 0, sizeof(new_data)); memset(&new_insn, 0, sizeof(new_insn)); @@ -376,40 +382,40 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, new_insn.data = new_data; new_insn.subdev = insn->subdev; - if(insn->insn == INSN_WRITE) - { - if(!(s->subdev_flags & SDF_WRITABLE)) + if (insn->insn == INSN_WRITE) { + if (!(s->subdev_flags & SDF_WRITABLE)) return -EINVAL; - new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */ - new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel)) : 0; /* bits */ + new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */ + new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel)) : 0; /* bits */ } - ret = s->insn_bits(dev,s,&new_insn,new_data); - if(ret < 0) return ret; + ret = s->insn_bits(dev, s, &new_insn, new_data); + if (ret < 0) + return ret; - if(insn->insn == INSN_READ){ + if (insn->insn == INSN_READ) { data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1; } return 1; } - -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) +static inline unsigned long uvirt_to_kva(pgd_t * pgd, unsigned long adr) { unsigned long ret = 0UL; pmd_t *pmd; pte_t *ptep, pte; pud_t *pud; - if(!pgd_none(*pgd)){ + if (!pgd_none(*pgd)) { pud = pud_offset(pgd, adr); pmd = pmd_offset(pud, adr); - if(!pmd_none(*pmd)){ + if (!pmd_none(*pmd)) { ptep = pte_offset_kernel(pmd, adr); pte = *ptep; - if(pte_present(pte)){ - ret = (unsigned long) page_address(pte_page(pte)); + if (pte_present(pte)) { + ret = (unsigned long) + page_address(pte_page(pte)); ret |= (adr & (PAGE_SIZE - 1)); } } @@ -427,8 +433,7 @@ static inline unsigned long kvirt_to_kva(unsigned long adr) return kva; } - -int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, +int comedi_buf_alloc(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { comedi_async *async = s->async; @@ -437,28 +442,31 @@ int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK; /* if no change is required, do nothing */ - if(async->prealloc_buf && async->prealloc_bufsz == new_size){ + if (async->prealloc_buf && async->prealloc_bufsz == new_size) { return 0; } // deallocate old buffer - if(async->prealloc_buf) - { + if (async->prealloc_buf) { vunmap(async->prealloc_buf); async->prealloc_buf = NULL; async->prealloc_bufsz = 0; } - if(async->buf_page_list) - { + if (async->buf_page_list) { unsigned i; - for(i = 0; i < async->n_buf_pages; ++i) - { - if(async->buf_page_list[i].virt_addr){ - mem_map_unreserve(virt_to_page(async->buf_page_list[i].virt_addr)); - if(s->async_dma_dir != DMA_NONE){ - dma_free_coherent(dev->hw_dev, PAGE_SIZE, - async->buf_page_list[i].virt_addr, async->buf_page_list[i].dma_addr); - }else{ - free_page((unsigned long)async->buf_page_list[i].virt_addr); + for (i = 0; i < async->n_buf_pages; ++i) { + if (async->buf_page_list[i].virt_addr) { + mem_map_unreserve(virt_to_page(async-> + buf_page_list[i].virt_addr)); + if (s->async_dma_dir != DMA_NONE) { + dma_free_coherent(dev->hw_dev, + PAGE_SIZE, + async->buf_page_list[i]. + virt_addr, + async->buf_page_list[i]. + dma_addr); + } else { + free_page((unsigned long)async-> + buf_page_list[i].virt_addr); } } } @@ -467,50 +475,72 @@ int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, async->n_buf_pages = 0; } // allocate new buffer - if(new_size){ + if (new_size) { unsigned i = 0; unsigned n_pages = new_size >> PAGE_SHIFT; - struct page** pages = NULL; - - async->buf_page_list = vmalloc(sizeof(struct comedi_buf_page) * n_pages); - if(async->buf_page_list){ - memset(async->buf_page_list, 0, sizeof(struct comedi_buf_page) * n_pages); - pages = vmalloc(sizeof(struct page*) * n_pages); + struct page **pages = NULL; + + async->buf_page_list = + vmalloc(sizeof(struct comedi_buf_page) * n_pages); + if (async->buf_page_list) { + memset(async->buf_page_list, 0, + sizeof(struct comedi_buf_page) * n_pages); + pages = vmalloc(sizeof(struct page *) * n_pages); } - if(pages){ - for(i = 0; i < n_pages; i++){ - if(s->async_dma_dir != DMA_NONE){ - async->buf_page_list[i].virt_addr = dma_alloc_coherent(dev->hw_dev, - PAGE_SIZE, &async->buf_page_list[i].dma_addr, GFP_KERNEL | __GFP_COMP); - }else{ - async->buf_page_list[i].virt_addr = (void*)get_zeroed_page(GFP_KERNEL); + if (pages) { + for (i = 0; i < n_pages; i++) { + if (s->async_dma_dir != DMA_NONE) { + async->buf_page_list[i].virt_addr = + dma_alloc_coherent(dev->hw_dev, + PAGE_SIZE, + &async->buf_page_list[i]. + dma_addr, + GFP_KERNEL | __GFP_COMP); + } else { + async->buf_page_list[i].virt_addr = + (void *) + get_zeroed_page(GFP_KERNEL); } - if(async->buf_page_list[i].virt_addr == NULL){ + if (async->buf_page_list[i].virt_addr == NULL) { break; } - mem_map_reserve(virt_to_page(async->buf_page_list[i].virt_addr)); - pages[i] = virt_to_page(async->buf_page_list[i].virt_addr); + mem_map_reserve(virt_to_page(async-> + buf_page_list[i].virt_addr)); + pages[i] = + virt_to_page(async->buf_page_list[i]. + virt_addr); } } - if(i == n_pages){ - async->prealloc_buf = vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE); + if (i == n_pages) { + async->prealloc_buf = + vmap(pages, n_pages, VM_MAP, + PAGE_KERNEL_NOCACHE); } - if(pages){ + if (pages) { vfree(pages); } - if(async->prealloc_buf == NULL){ + if (async->prealloc_buf == NULL) { /* Some allocation failed above. */ - if(async->buf_page_list){ - for(i = 0; i < n_pages; i++){ - if(async->buf_page_list[i].virt_addr == NULL){ + if (async->buf_page_list) { + for (i = 0; i < n_pages; i++) { + if (async->buf_page_list[i].virt_addr == + NULL) { break; } - mem_map_unreserve(virt_to_page(async->buf_page_list[i].virt_addr)); - if(s->async_dma_dir != DMA_NONE){ - dma_free_coherent(dev->hw_dev, PAGE_SIZE, - async->buf_page_list[i].virt_addr, async->buf_page_list[i].dma_addr); - }else{ - free_page((unsigned long)async->buf_page_list[i].virt_addr); + mem_map_unreserve(virt_to_page(async-> + buf_page_list[i]. + virt_addr)); + if (s->async_dma_dir != DMA_NONE) { + dma_free_coherent(dev->hw_dev, + PAGE_SIZE, + async->buf_page_list[i]. + virt_addr, + async->buf_page_list[i]. + dma_addr); + } else { + free_page((unsigned long)async-> + buf_page_list[i]. + virt_addr); } } vfree(async->buf_page_list); @@ -527,38 +557,37 @@ int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, /* munging is applied to data by core as it passes between user * and kernel space */ -unsigned int comedi_buf_munge(comedi_async *async, - unsigned int num_bytes) +unsigned int comedi_buf_munge(comedi_async * async, unsigned int num_bytes) { comedi_subdevice *s = async->subdevice; unsigned int count = 0; const unsigned num_sample_bytes = bytes_per_sample(s); - if( s->munge == NULL || ( async->cmd.flags & CMDF_RAWDATA ) ) - { + if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) { async->munge_count += num_bytes; - if((int)(async->munge_count - async->buf_write_count) > 0) BUG(); + if ((int)(async->munge_count - async->buf_write_count) > 0) + BUG(); return num_bytes; } /* don't munge partial samples */ num_bytes -= num_bytes % num_sample_bytes; - while( count < num_bytes ) - { + while (count < num_bytes) { int block_size; block_size = num_bytes - count; - if(block_size < 0) - { - rt_printk("%s: %s: bug! block_size is negative\n", __FILE__, __FUNCTION__); + if (block_size < 0) { + rt_printk("%s: %s: bug! block_size is negative\n", + __FILE__, __FUNCTION__); break; } - if( (int)(async->munge_ptr + block_size - async->prealloc_bufsz) > 0 ) + if ((int)(async->munge_ptr + block_size - + async->prealloc_bufsz) > 0) block_size = async->prealloc_bufsz - async->munge_ptr; s->munge(s->device, s, async->prealloc_buf + async->munge_ptr, - block_size, async->munge_chan ); + block_size, async->munge_chan); - smp_wmb(); //barrier insures data is munged in buffer before munge_count is incremented + smp_wmb(); //barrier insures data is munged in buffer before munge_count is incremented async->munge_chan += block_size / num_sample_bytes; async->munge_chan %= async->cmd.chanlist_len; @@ -567,98 +596,102 @@ unsigned int comedi_buf_munge(comedi_async *async, async->munge_ptr %= async->prealloc_bufsz; count += block_size; } - if((int)(async->munge_count - async->buf_write_count) > 0) BUG(); + if ((int)(async->munge_count - async->buf_write_count) > 0) + BUG(); return count; } -unsigned int comedi_buf_write_n_available(comedi_async *async) +unsigned int comedi_buf_write_n_available(comedi_async * async) { unsigned int free_end; unsigned int nbytes; - if(async == NULL) return 0; + if (async == NULL) + return 0; free_end = async->buf_read_count + async->prealloc_bufsz; nbytes = free_end - async->buf_write_alloc_count; nbytes -= nbytes % bytes_per_sample(async->subdevice); /* barrier insures the read of buf_read_count in this - query occurs before any following writes to the buffer which - might be based on the return value from this query. - */ + query occurs before any following writes to the buffer which + might be based on the return value from this query. + */ smp_mb(); return nbytes; } /* allocates chunk for the writer from free buffer space */ -unsigned int comedi_buf_write_alloc(comedi_async *async, unsigned int nbytes) +unsigned int comedi_buf_write_alloc(comedi_async * async, unsigned int nbytes) { unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - if((int)(async->buf_write_alloc_count + nbytes - free_end) > 0){ + if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) { nbytes = free_end - async->buf_write_alloc_count; } async->buf_write_alloc_count += nbytes; /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ + we write data to the write-alloc'ed buffer space */ smp_mb(); return nbytes; } /* allocates nothing unless it can completely fulfill the request */ -unsigned int comedi_buf_write_alloc_strict(comedi_async *async, +unsigned int comedi_buf_write_alloc_strict(comedi_async * async, unsigned int nbytes) { unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - if((int)(async->buf_write_alloc_count + nbytes - free_end) > 0){ + if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) { nbytes = 0; } async->buf_write_alloc_count += nbytes; /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ + we write data to the write-alloc'ed buffer space */ smp_mb(); return nbytes; } /* transfers a chunk from writer to filled buffer space */ -unsigned comedi_buf_write_free(comedi_async *async, unsigned int nbytes) +unsigned comedi_buf_write_free(comedi_async * async, unsigned int nbytes) { - if((int)(async->buf_write_count + nbytes - async->buf_write_alloc_count) > 0) - { - rt_printk("comedi: attempted to write-free more bytes than have been write-allocated.\n"); + if ((int)(async->buf_write_count + nbytes - + async->buf_write_alloc_count) > 0) { + rt_printk + ("comedi: attempted to write-free more bytes than have been write-allocated.\n"); nbytes = async->buf_write_alloc_count - async->buf_write_count; } async->buf_write_count += nbytes; async->buf_write_ptr += nbytes; comedi_buf_munge(async, async->buf_write_count - async->munge_count); - if(async->buf_write_ptr >= async->prealloc_bufsz){ + if (async->buf_write_ptr >= async->prealloc_bufsz) { async->buf_write_ptr %= async->prealloc_bufsz; } return nbytes; } /* allocates a chunk for the reader from filled (and munged) buffer space */ -unsigned comedi_buf_read_alloc(comedi_async *async, unsigned nbytes) +unsigned comedi_buf_read_alloc(comedi_async * async, unsigned nbytes) { - if((int)(async->buf_read_alloc_count + nbytes - async->munge_count) > 0) - { + if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) > + 0) { nbytes = async->munge_count - async->buf_read_alloc_count; } async->buf_read_alloc_count += nbytes; /* barrier insures read of munge_count occurs before we actually read - data out of buffer */ + data out of buffer */ smp_rmb(); return nbytes; } /* transfers control of a chunk from reader to free buffer space */ -unsigned comedi_buf_read_free(comedi_async *async, unsigned int nbytes) +unsigned comedi_buf_read_free(comedi_async * async, unsigned int nbytes) { // barrier insures data has been read out of buffer before read count is incremented smp_mb(); - if((int)(async->buf_read_count + nbytes - async->buf_read_alloc_count) > 0) - { - rt_printk("comedi: attempted to read-free more bytes than have been read-allocated.\n"); + if ((int)(async->buf_read_count + nbytes - + async->buf_read_alloc_count) > 0) { + rt_printk + ("comedi: attempted to read-free more bytes than have been read-allocated.\n"); nbytes = async->buf_read_alloc_count - async->buf_read_count; } async->buf_read_count += nbytes; @@ -667,24 +700,23 @@ unsigned comedi_buf_read_free(comedi_async *async, unsigned int nbytes) return nbytes; } -void comedi_buf_memcpy_to( comedi_async *async, unsigned int offset, const void *data, - unsigned int num_bytes ) +void comedi_buf_memcpy_to(comedi_async * async, unsigned int offset, + const void *data, unsigned int num_bytes) { unsigned int write_ptr = async->buf_write_ptr + offset; - if( write_ptr >= async->prealloc_bufsz ) + if (write_ptr >= async->prealloc_bufsz) write_ptr %= async->prealloc_bufsz; - while( num_bytes ) - { + while (num_bytes) { unsigned int block_size; - if( write_ptr + num_bytes > async->prealloc_bufsz) + if (write_ptr + num_bytes > async->prealloc_bufsz) block_size = async->prealloc_bufsz - write_ptr; else block_size = num_bytes; - memcpy( async->prealloc_buf + write_ptr, data, block_size ); + memcpy(async->prealloc_buf + write_ptr, data, block_size); data += block_size; num_bytes -= block_size; @@ -693,73 +725,73 @@ void comedi_buf_memcpy_to( comedi_async *async, unsigned int offset, const void } } -void comedi_buf_memcpy_from(comedi_async *async, unsigned int offset, +void comedi_buf_memcpy_from(comedi_async * async, unsigned int offset, void *dest, unsigned int nbytes) { void *src; unsigned int read_ptr = async->buf_read_ptr + offset; - if( read_ptr >= async->prealloc_bufsz ) + if (read_ptr >= async->prealloc_bufsz) read_ptr %= async->prealloc_bufsz; - while( nbytes ) - { + while (nbytes) { unsigned int block_size; src = async->prealloc_buf + read_ptr; - if( nbytes >= async->prealloc_bufsz - read_ptr ) + if (nbytes >= async->prealloc_bufsz - read_ptr) block_size = async->prealloc_bufsz - read_ptr; else block_size = nbytes; - memcpy(dest, src, block_size ); + memcpy(dest, src, block_size); nbytes -= block_size; dest += block_size; read_ptr = 0; } } -unsigned int comedi_buf_read_n_available(comedi_async *async) +unsigned int comedi_buf_read_n_available(comedi_async * async) { unsigned num_bytes; - if(async == NULL) + if (async == NULL) return 0; num_bytes = async->munge_count - async->buf_read_count; /* barrier insures the read of munge_count in this - query occurs before any following reads of the buffer which - might be based on the return value from this query. - */ + query occurs before any following reads of the buffer which + might be based on the return value from this query. + */ smp_rmb(); return num_bytes; } -int comedi_buf_get(comedi_async *async, sampl_t *x) +int comedi_buf_get(comedi_async * async, sampl_t * x) { unsigned int n = comedi_buf_read_n_available(async); - if(n < sizeof(sampl_t)) return 0; + if (n < sizeof(sampl_t)) + return 0; comedi_buf_read_alloc(async, sizeof(sampl_t)); - *x = *(sampl_t *)(async->prealloc_buf + async->buf_read_ptr); + *x = *(sampl_t *) (async->prealloc_buf + async->buf_read_ptr); comedi_buf_read_free(async, sizeof(sampl_t)); return 1; } -int comedi_buf_put(comedi_async *async, sampl_t x) +int comedi_buf_put(comedi_async * async, sampl_t x) { unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(sampl_t)); - if(nevents |= COMEDI_CB_ERROR; return 0; } - *(sampl_t *)(async->prealloc_buf + async->buf_write_ptr) = x; + *(sampl_t *) (async->prealloc_buf + async->buf_write_ptr) = x; comedi_buf_write_free(async, sizeof(sampl_t)); return 1; } -void comedi_reset_async_buf(comedi_async *async) +void comedi_reset_async_buf(comedi_async * async) { async->buf_write_alloc_count = 0; async->buf_write_count = 0; @@ -777,4 +809,3 @@ void comedi_reset_async_buf(comedi_async *async) async->events = 0; } - diff --git a/comedi/drivers/8253.h b/comedi/drivers/8253.h index f4f0bcb1..3cd04e42 100644 --- a/comedi/drivers/8253.h +++ b/comedi/drivers/8253.h @@ -32,7 +32,9 @@ #define i8253_cascade_ns_to_timer i8253_cascade_ns_to_timer_2div -static inline void i8253_cascade_ns_to_timer_2div_old(int i8253_osc_base, unsigned int *d1, unsigned int *d2, unsigned int *nanosec, int round_mode) +static inline void i8253_cascade_ns_to_timer_2div_old(int i8253_osc_base, + unsigned int *d1, unsigned int *d2, unsigned int *nanosec, + int round_mode) { int divider; int div1, div2; @@ -79,7 +81,9 @@ static inline void i8253_cascade_ns_to_timer_2div_old(int i8253_osc_base, unsign return; } -static inline void i8253_cascade_ns_to_timer_power(int i8253_osc_base, unsigned int *d1, unsigned int *d2, unsigned int *nanosec, int round_mode) +static inline void i8253_cascade_ns_to_timer_power(int i8253_osc_base, + unsigned int *d1, unsigned int *d2, unsigned int *nanosec, + int round_mode) { int div1, div2; int base; @@ -99,7 +103,8 @@ static inline void i8253_cascade_ns_to_timer_power(int i8253_osc_base, unsigned div2 = (*nanosec + base - 1) / base; break; } - if (div2 < 2) div2 = 2; + if (div2 < 2) + div2 = 2; if (div2 <= 65536) { *nanosec = div2 * base; *d1 = div1 & 0xffff; @@ -117,7 +122,8 @@ static inline void i8253_cascade_ns_to_timer_power(int i8253_osc_base, unsigned } static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, - unsigned int *d1, unsigned int *d2, unsigned int *nanosec, int round_mode) + unsigned int *d1, unsigned int *d2, unsigned int *nanosec, + int round_mode) { unsigned int divider; unsigned int div1, div2; @@ -133,14 +139,13 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, div1 = *d1 ? *d1 : max_count; div2 = *d2 ? *d2 : max_count; divider = div1 * div2; - if(div1 * div2 * i8253_osc_base == *nanosec && + if (div1 * div2 * i8253_osc_base == *nanosec && div1 > 1 && div1 <= max_count && div2 > 1 && div2 <= max_count && /* check for overflow */ divider > div1 && divider > div2 && divider * i8253_osc_base > divider && - divider * i8253_osc_base > i8253_osc_base) - { + divider * i8253_osc_base > i8253_osc_base) { return; } @@ -154,9 +159,13 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, div2 = max_count; start = divider / div2; - if(start < 2) start = 2; - for (div1 = start; div1 <= divider / div1 + 1 && div1 <= max_count; div1++) { - for(div2 = divider / div1; div1 * div2 <= divider + div1 + 1 && div2 <= max_count; div2++) { + if (start < 2) + start = 2; + for (div1 = start; div1 <= divider / div1 + 1 && div1 <= max_count; + div1++) { + for (div2 = divider / div1; + div1 * div2 <= divider + div1 + 1 && div2 <= max_count; + div2++) { ns = i8253_osc_base * div1 * div2; if (ns <= *nanosec && ns > ns_glb) { ns_glb = ns; @@ -177,7 +186,7 @@ static inline void i8253_cascade_ns_to_timer_2div(int i8253_osc_base, default: ns_high = div1_lub * div2_lub * i8253_osc_base; ns_low = div1_glb * div2_glb * i8253_osc_base; - if( ns_high - *nanosec < *nanosec - ns_low) { + if (ns_high - *nanosec < *nanosec - ns_low) { div1 = div1_lub; div2 = div2_lub; } else { @@ -228,13 +237,17 @@ static inline int i8254_load(unsigned long base_address, unsigned int regshift, { unsigned int byte; - if(counter_number > 2) return -1; - if(count > 0xffff) return -1; - if(mode > 5) return -1; - if((mode == 2 || mode == 3) && count == 1) return -1; + if (counter_number > 2) + return -1; + if (count > 0xffff) + return -1; + if (mode > 5) + return -1; + if ((mode == 2 || mode == 3) && count == 1) + return -1; byte = counter_number << 6; - byte |= 0x30; // load low then high byte + byte |= 0x30; // load low then high byte byte |= (mode << 1); // set counter mode outb(byte, base_address + (i8254_control_reg << regshift)); byte = count & 0xff; // lsb of counter value @@ -250,13 +263,17 @@ static inline int i8254_mm_load(void *base_address, unsigned int regshift, { unsigned int byte; - if(counter_number > 2) return -1; - if(count > 0xffff) return -1; - if(mode > 5) return -1; - if((mode == 2 || mode == 3) && count == 1) return -1; + if (counter_number > 2) + return -1; + if (count > 0xffff) + return -1; + if (mode > 5) + return -1; + if ((mode == 2 || mode == 3) && count == 1) + return -1; byte = counter_number << 6; - byte |= 0x30; // load low then high byte + byte |= 0x30; // load low then high byte byte |= (mode << 1); // set counter mode writeb(byte, base_address + (i8254_control_reg << regshift)); byte = count & 0xff; // lsb of counter value @@ -274,7 +291,8 @@ static inline int i8254_read(unsigned long base_address, unsigned int regshift, unsigned int byte; int ret; - if(counter_number > 2) return -1; + if (counter_number > 2) + return -1; // latch counter byte = counter_number << 6; @@ -294,7 +312,8 @@ static inline int i8254_mm_read(void *base_address, unsigned int regshift, unsigned int byte; int ret; - if(counter_number > 2) return -1; + if (counter_number > 2) + return -1; // latch counter byte = counter_number << 6; @@ -314,7 +333,8 @@ static inline void i8254_write(unsigned long base_address, { unsigned int byte; - if(counter_number > 2) return; + if (counter_number > 2) + return; byte = count & 0xff; // lsb of counter value outb(byte, base_address + (counter_number << regshift)); @@ -327,7 +347,8 @@ static inline void i8254_mm_write(void *base_address, { unsigned int byte; - if(counter_number > 2) return; + if (counter_number > 2) + return; byte = count & 0xff; // lsb of counter value writeb(byte, base_address + (counter_number << regshift)); @@ -347,12 +368,14 @@ static inline int i8254_set_mode(unsigned long base_address, { unsigned int byte; - if(counter_number > 2) return -1; - if(mode > (I8254_MODE5 | I8254_BINARY)) return -1; + if (counter_number > 2) + return -1; + if (mode > (I8254_MODE5 | I8254_BINARY)) + return -1; byte = counter_number << 6; - byte |= 0x30; // load low then high byte - byte |= mode; // set counter mode and BCD|binary + byte |= 0x30; // load low then high byte + byte |= mode; // set counter mode and BCD|binary outb(byte, base_address + (i8254_control_reg << regshift)); return 0; @@ -363,12 +386,14 @@ static inline int i8254_mm_set_mode(void *base_address, { unsigned int byte; - if(counter_number > 2) return -1; - if(mode > (I8254_MODE5 | I8254_BINARY)) return -1; + if (counter_number > 2) + return -1; + if (mode > (I8254_MODE5 | I8254_BINARY)) + return -1; byte = counter_number << 6; - byte |= 0x30; // load low then high byte - byte |= mode; // set counter mode and BCD|binary + byte |= 0x30; // load low then high byte + byte |= mode; // set counter mode and BCD|binary writeb(byte, base_address + (i8254_control_reg << regshift)); return 0; @@ -378,7 +403,7 @@ static inline int i8254_status(unsigned long base_address, unsigned int regshift, unsigned int counter_number) { outb(0xE0 | (2 << counter_number), - base_address + (i8254_control_reg << regshift)); + base_address + (i8254_control_reg << regshift)); return inb(base_address + (counter_number << regshift)); } @@ -386,11 +411,10 @@ static inline int i8254_mm_status(void *base_address, unsigned int regshift, unsigned int counter_number) { writeb(0xE0 | (2 << counter_number), - base_address + (i8254_control_reg << regshift)); + base_address + (i8254_control_reg << regshift)); return readb(base_address + (counter_number << regshift)); } #endif #endif - diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index 48e564c6..ba7770dd 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -82,8 +82,6 @@ I/O port base address can be found in the output of 'lspci -v'. #include - - #define _8255_SIZE 4 #define _8255_DATA 0 @@ -97,9 +95,9 @@ I/O port base address can be found in the output of 'lspci -v'. #define CR_A_MODE(a) ((a)<<5) #define CR_CW 0x80 -struct subdev_8255_struct{ +struct subdev_8255_struct { unsigned long cb_arg; - int (*cb_func)(int,int,int,unsigned long); + int (*cb_func) (int, int, int, unsigned long); int have_irq; }; @@ -109,22 +107,23 @@ struct subdev_8255_struct{ static int dev_8255_attach(comedi_device * dev, comedi_devconfig * it); static int dev_8255_detach(comedi_device * dev); -static comedi_driver driver_8255={ - driver_name: "8255", - module: THIS_MODULE, - attach: dev_8255_attach, - detach: dev_8255_detach, +static comedi_driver driver_8255 = { + driver_name:"8255", + module:THIS_MODULE, + attach:dev_8255_attach, + detach:dev_8255_detach, }; + COMEDI_INITCLEANUP(driver_8255); -static void do_config(comedi_device *dev,comedi_subdevice *s); +static void do_config(comedi_device * dev, comedi_subdevice * s); -void subdev_8255_interrupt(comedi_device *dev, comedi_subdevice *s) +void subdev_8255_interrupt(comedi_device * dev, comedi_subdevice * s) { sampl_t d; - d = CALLBACK_FUNC(0,_8255_DATA,0,CALLBACK_ARG); - d |= (CALLBACK_FUNC(0,_8255_DATA+1,0,CALLBACK_ARG)<<8); + d = CALLBACK_FUNC(0, _8255_DATA, 0, CALLBACK_ARG); + d |= (CALLBACK_FUNC(0, _8255_DATA + 1, 0, CALLBACK_ARG) << 8); comedi_buf_put(s->async, d); s->async->events |= COMEDI_CB_EOS; @@ -132,63 +131,66 @@ void subdev_8255_interrupt(comedi_device *dev, comedi_subdevice *s) comedi_event(dev, s); } -static int subdev_8255_cb(int dir,int port,int data,unsigned long arg) +static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) { - unsigned long iobase=arg; + unsigned long iobase = arg; - if(dir){ - outb(data,iobase+port); + if (dir) { + outb(data, iobase + port); return 0; - }else{ - return inb(iobase+port); + } else { + return inb(iobase + port); } } -static int subdev_8255_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int subdev_8255_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - - if(data[0]&0xff) - CALLBACK_FUNC(1,_8255_DATA,s->state&0xff,CALLBACK_ARG); - if(data[0]&0xff00) - CALLBACK_FUNC(1,_8255_DATA+1,(s->state>>8)&0xff,CALLBACK_ARG); - if(data[0]&0xff0000) - CALLBACK_FUNC(1,_8255_DATA+2,(s->state>>16)&0xff,CALLBACK_ARG); + s->state |= (data[0] & data[1]); + + if (data[0] & 0xff) + CALLBACK_FUNC(1, _8255_DATA, s->state & 0xff, + CALLBACK_ARG); + if (data[0] & 0xff00) + CALLBACK_FUNC(1, _8255_DATA + 1, (s->state >> 8) & 0xff, + CALLBACK_ARG); + if (data[0] & 0xff0000) + CALLBACK_FUNC(1, _8255_DATA + 2, + (s->state >> 16) & 0xff, CALLBACK_ARG); } - data[1]=CALLBACK_FUNC(0,_8255_DATA,0,CALLBACK_ARG); - data[1]|=(CALLBACK_FUNC(0,_8255_DATA+1,0,CALLBACK_ARG)<<8); - data[1]|=(CALLBACK_FUNC(0,_8255_DATA+2,0,CALLBACK_ARG)<<16); + data[1] = CALLBACK_FUNC(0, _8255_DATA, 0, CALLBACK_ARG); + data[1] |= (CALLBACK_FUNC(0, _8255_DATA + 1, 0, CALLBACK_ARG) << 8); + data[1] |= (CALLBACK_FUNC(0, _8255_DATA + 2, 0, CALLBACK_ARG) << 16); return 2; } -static int subdev_8255_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int subdev_8255_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int mask; unsigned int bits; - mask=1<chanspec); - if(mask&0x0000ff){ - bits=0x0000ff; - }else if(mask&0x00ff00){ - bits=0x00ff00; - }else if(mask&0x0f0000){ - bits=0x0f0000; - }else{ - bits=0xf00000; + mask = 1 << CR_CHAN(insn->chanspec); + if (mask & 0x0000ff) { + bits = 0x0000ff; + } else if (mask & 0x00ff00) { + bits = 0x00ff00; + } else if (mask & 0x0f0000) { + bits = 0x0f0000; + } else { + bits = 0xf00000; } - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_DIO_INPUT: - s->io_bits&=~bits; + s->io_bits &= ~bits; break; case INSN_CONFIG_DIO_OUTPUT: - s->io_bits|=bits; + s->io_bits |= bits; break; case INSN_CONFIG_DIO_QUERY: data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT; @@ -198,30 +200,30 @@ static int subdev_8255_insn_config(comedi_device *dev,comedi_subdevice *s, return -EINVAL; } - do_config(dev,s); + do_config(dev, s); return 1; } -static void do_config(comedi_device *dev,comedi_subdevice *s) +static void do_config(comedi_device * dev, comedi_subdevice * s) { int config; - config=CR_CW; + config = CR_CW; /* 1 in io_bits indicates output, 1 in config indicates input */ - if(!(s->io_bits&0x0000ff)) - config|=CR_A_IO; - if(!(s->io_bits&0x00ff00)) - config|=CR_B_IO; - if(!(s->io_bits&0x0f0000)) - config|=CR_C_LO_IO; - if(!(s->io_bits&0xf00000)) - config|=CR_C_HI_IO; - CALLBACK_FUNC(1,_8255_CR,config,CALLBACK_ARG); + if (!(s->io_bits & 0x0000ff)) + config |= CR_A_IO; + if (!(s->io_bits & 0x00ff00)) + config |= CR_B_IO; + if (!(s->io_bits & 0x0f0000)) + config |= CR_C_LO_IO; + if (!(s->io_bits & 0xf00000)) + config |= CR_C_HI_IO; + CALLBACK_FUNC(1, _8255_CR, config, CALLBACK_ARG); } -static int subdev_8255_cmdtest(comedi_device *dev, comedi_subdevice *s, - comedi_cmd *cmd) +static int subdev_8255_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; unsigned int tmp; @@ -230,110 +232,122 @@ static int subdev_8255_cmdtest(comedi_device *dev, comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_FOLLOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2 */ - if(err) return 2; + if (err) + return 2; /* step 3 */ - if(cmd->start_arg != 0){ + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg != 1){ + if (cmd->scan_end_arg != 1) { cmd->scan_end_arg = 1; err++; } - if(cmd->stop_arg!= 0){ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } - if(err)return 3; + if (err) + return 3; /* step 4 */ - if(err)return 4; + if (err) + return 4; return 0; } -static int subdev_8255_cmd(comedi_device *dev, comedi_subdevice *s) +static int subdev_8255_cmd(comedi_device * dev, comedi_subdevice * s) { /* FIXME */ return 0; } -static int subdev_8255_cancel(comedi_device *dev, comedi_subdevice *s) +static int subdev_8255_cancel(comedi_device * dev, comedi_subdevice * s) { /* FIXME */ return 0; } -int subdev_8255_init(comedi_device *dev,comedi_subdevice *s,int (*cb)(int,int,int,unsigned long),unsigned long arg) +int subdev_8255_init(comedi_device * dev, comedi_subdevice * s, int (*cb) (int, + int, int, unsigned long), unsigned long arg) { - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=24; - s->range_table=&range_digital; - s->maxdata=1; - - s->private=kmalloc(sizeof(struct subdev_8255_struct),GFP_KERNEL); - if(!s->private)return -ENOMEM; - - CALLBACK_ARG=arg; - if(cb==NULL){ - CALLBACK_FUNC=subdev_8255_cb; - }else{ - CALLBACK_FUNC=cb; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 24; + s->range_table = &range_digital; + s->maxdata = 1; + + s->private = kmalloc(sizeof(struct subdev_8255_struct), GFP_KERNEL); + if (!s->private) + return -ENOMEM; + + CALLBACK_ARG = arg; + if (cb == NULL) { + CALLBACK_FUNC = subdev_8255_cb; + } else { + CALLBACK_FUNC = cb; } s->insn_bits = subdev_8255_insn; s->insn_config = subdev_8255_insn_config; - s->state=0; - s->io_bits=0; - do_config(dev,s); + s->state = 0; + s->io_bits = 0; + do_config(dev, s); return 0; } -int subdev_8255_init_irq(comedi_device *dev,comedi_subdevice *s, - int (*cb)(int,int,int,unsigned long),unsigned long arg) +int subdev_8255_init_irq(comedi_device * dev, comedi_subdevice * s, + int (*cb) (int, int, int, unsigned long), unsigned long arg) { int ret; - ret = subdev_8255_init(dev,s,cb,arg); - if(ret<0)return ret; + ret = subdev_8255_init(dev, s, cb, arg); + if (ret < 0) + return ret; s->do_cmdtest = subdev_8255_cmdtest; s->do_cmd = subdev_8255_cmd; @@ -344,10 +358,11 @@ int subdev_8255_init_irq(comedi_device *dev,comedi_subdevice *s, return 0; } -void subdev_8255_cleanup(comedi_device *dev,comedi_subdevice *s) +void subdev_8255_cleanup(comedi_device * dev, comedi_subdevice * s) { - if(s->private){ - if(subdevpriv->have_irq){} + if (s->private) { + if (subdevpriv->have_irq) { + } kfree(s->private); } @@ -359,38 +374,40 @@ void subdev_8255_cleanup(comedi_device *dev,comedi_subdevice *s) */ -static int dev_8255_attach(comedi_device *dev,comedi_devconfig *it) +static int dev_8255_attach(comedi_device * dev, comedi_devconfig * it) { int ret; unsigned long iobase; int i; - printk("comedi%d: 8255:",dev->minor); + printk("comedi%d: 8255:", dev->minor); - dev->board_name="8255"; + dev->board_name = "8255"; - for(i=0;ioptions[i]; - if(!iobase)break; + for (i = 0; i < COMEDI_NDEVCONFOPTS; i++) { + iobase = it->options[i]; + if (!iobase) + break; } - if(i==0){ + if (i == 0) { printk(" no devices specified\n"); return -EINVAL; } - if((ret=alloc_subdevices(dev, i))<0) + if ((ret = alloc_subdevices(dev, i)) < 0) return ret; - for(i=0;in_subdevices;i++){ - iobase=it->options[i]; + for (i = 0; i < dev->n_subdevices; i++) { + iobase = it->options[i]; - printk(" 0x%04lx",iobase); - if(!request_region(iobase,_8255_SIZE,"8255")){ + printk(" 0x%04lx", iobase); + if (!request_region(iobase, _8255_SIZE, "8255")) { printk(" (I/O port conflict)"); - dev->subdevices[i].type=COMEDI_SUBD_UNUSED; - }else{ - subdev_8255_init(dev,dev->subdevices+i,NULL,iobase); + dev->subdevices[i].type = COMEDI_SUBD_UNUSED; + } else { + subdev_8255_init(dev, dev->subdevices + i, NULL, + iobase); } } @@ -399,29 +416,27 @@ static int dev_8255_attach(comedi_device *dev,comedi_devconfig *it) return 0; } -static int dev_8255_detach(comedi_device *dev) +static int dev_8255_detach(comedi_device * dev) { int i; unsigned long iobase; comedi_subdevice *s; - printk("comedi%d: 8255: remove\n",dev->minor); + printk("comedi%d: 8255: remove\n", dev->minor); - for(i=0;in_subdevices;i++){ - s=dev->subdevices+i; - if(s->type!=COMEDI_SUBD_UNUSED){ - iobase=CALLBACK_ARG; - release_region(iobase,_8255_SIZE); + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; + if (s->type != COMEDI_SUBD_UNUSED) { + iobase = CALLBACK_ARG; + release_region(iobase, _8255_SIZE); } - subdev_8255_cleanup(dev,s); + subdev_8255_cleanup(dev, s); } return 0; } - EXPORT_SYMBOL(subdev_8255_init); EXPORT_SYMBOL(subdev_8255_init_irq); EXPORT_SYMBOL(subdev_8255_cleanup); EXPORT_SYMBOL(subdev_8255_interrupt); - diff --git a/comedi/drivers/8255.h b/comedi/drivers/8255.h index 287892b7..b0328112 100644 --- a/comedi/drivers/8255.h +++ b/comedi/drivers/8255.h @@ -28,27 +28,30 @@ #if defined(CONFIG_COMEDI_8255) || defined(CONFIG_COMEDI_8255_MODULE) -int subdev_8255_init(comedi_device *dev,comedi_subdevice *s, - int (*cb)(int,int,int,unsigned long),unsigned long arg); -int subdev_8255_init_irq(comedi_device *dev,comedi_subdevice *s, - int (*cb)(int,int,int,unsigned long),unsigned long arg); -void subdev_8255_cleanup(comedi_device *dev,comedi_subdevice *s); -void subdev_8255_interrupt(comedi_device *dev,comedi_subdevice *s); +int subdev_8255_init(comedi_device * dev, comedi_subdevice * s, + int (*cb) (int, int, int, unsigned long), unsigned long arg); +int subdev_8255_init_irq(comedi_device * dev, comedi_subdevice * s, + int (*cb) (int, int, int, unsigned long), unsigned long arg); +void subdev_8255_cleanup(comedi_device * dev, comedi_subdevice * s); +void subdev_8255_interrupt(comedi_device * dev, comedi_subdevice * s); #else -static inline int subdev_8255_init(comedi_device *dev,comedi_subdevice *s,void *x,unsigned long y) +static inline int subdev_8255_init(comedi_device * dev, comedi_subdevice * s, + void *x, unsigned long y) { printk("8255 support not configured -- disabling subdevice\n"); - s->type=COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; return 0; } -static inline void subdev_8255_cleanup(comedi_device *dev,comedi_subdevice *s){} +static inline void subdev_8255_cleanup(comedi_device * dev, + comedi_subdevice * s) +{ +} #endif #endif - diff --git a/comedi/drivers/acl7225b.c b/comedi/drivers/acl7225b.c index 58256c6e..1bd92f02 100644 --- a/comedi/drivers/acl7225b.c +++ b/comedi/drivers/acl7225b.c @@ -15,134 +15,135 @@ Devices: [Adlink] ACL-7225b (acl7225b), [ICP] P16R16DIO (p16r16dio) #include -#define ACL7225_SIZE 8 /* Requires 8 ioports, but only 4 are used */ +#define ACL7225_SIZE 8 /* Requires 8 ioports, but only 4 are used */ #define P16R16DIO_SIZE 4 -#define ACL7225_RIO_LO 0 /* Relays input/output low byte (R0-R7) */ -#define ACL7225_RIO_HI 1 /* Relays input/output high byte (R8-R15) */ -#define ACL7225_DI_LO 2 /* Digital input low byte (DI0-DI7) */ -#define ACL7225_DI_HI 3 /* Digital input high byte (DI8-DI15) */ +#define ACL7225_RIO_LO 0 /* Relays input/output low byte (R0-R7) */ +#define ACL7225_RIO_HI 1 /* Relays input/output high byte (R8-R15) */ +#define ACL7225_DI_LO 2 /* Digital input low byte (DI0-DI7) */ +#define ACL7225_DI_HI 3 /* Digital input high byte (DI8-DI15) */ -static int acl7225b_attach(comedi_device *dev,comedi_devconfig *it); -static int acl7225b_detach(comedi_device *dev); +static int acl7225b_attach(comedi_device * dev, comedi_devconfig * it); +static int acl7225b_detach(comedi_device * dev); typedef struct { - const char *name; // driver name - int io_range; // len of I/O space + const char *name; // driver name + int io_range; // len of I/O space } boardtype; -static const boardtype boardtypes[] = -{ - { "acl7225b", ACL7225_SIZE, }, - { "p16r16dio", P16R16DIO_SIZE, }, +static const boardtype boardtypes[] = { + {"acl7225b", ACL7225_SIZE,}, + {"p16r16dio", P16R16DIO_SIZE,}, }; + #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) static comedi_driver driver_acl7225b = { - driver_name: "acl7225b", - module: THIS_MODULE, - attach: acl7225b_attach, - detach: acl7225b_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), + driver_name:"acl7225b", + module:THIS_MODULE, + attach:acl7225b_attach, + detach:acl7225b_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_acl7225b); -static int acl7225b_do_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int acl7225b_do_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if( insn->n != 2 ) - return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]) - { + if (data[0]) { s->state &= ~data[0]; s->state |= (data[0] & data[1]); } - if( data[0] & 0x00ff ) - outb(s->state & 0xff, dev->iobase+(unsigned long)s->private); - if( data[0] & 0xff00 ) - outb((s->state >> 8), dev->iobase+(unsigned long)s->private+1); + if (data[0] & 0x00ff) + outb(s->state & 0xff, dev->iobase + (unsigned long)s->private); + if (data[0] & 0xff00) + outb((s->state >> 8), + dev->iobase + (unsigned long)s->private + 1); - data[1]=s->state; + data[1] = s->state; return 2; } -static int acl7225b_di_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int acl7225b_di_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if( insn->n != 2 ) - return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1]=inb(dev->iobase + (unsigned long)s->private) | - (inb(dev->iobase + (unsigned long)s->private+1) << 8); + data[1] = inb(dev->iobase + (unsigned long)s->private) | + (inb(dev->iobase + (unsigned long)s->private + 1) << 8); return 2; } -static int acl7225b_attach(comedi_device *dev,comedi_devconfig *it) +static int acl7225b_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int iobase, iorange; - iobase=it->options[0]; - iorange=this_board->io_range; + iobase = it->options[0]; + iorange = this_board->io_range; printk("comedi%d: acl7225b: board=%s 0x%04x ", dev->minor, - this_board->name, iobase); - if( !request_region(iobase, iorange, "acl7225b") ) { + this_board->name, iobase); + if (!request_region(iobase, iorange, "acl7225b")) { printk("I/O port conflict\n"); return -EIO; } - dev->board_name=this_board->name; - dev->iobase=iobase; - dev->irq=0; + dev->board_name = this_board->name; + dev->iobase = iobase; + dev->irq = 0; - if( alloc_subdevices(dev, 3) < 0 ) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* Relays outputs */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = acl7225b_do_insn; - s->range_table=&range_digital; - s->private=(void *)ACL7225_RIO_LO; + s->range_table = &range_digital; + s->private = (void *)ACL7225_RIO_LO; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* Relays status */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = acl7225b_di_insn; - s->range_table=&range_digital; - s->private=(void *)ACL7225_RIO_LO; + s->range_table = &range_digital; + s->private = (void *)ACL7225_RIO_LO; - s=dev->subdevices+2; + s = dev->subdevices + 2; /* Isolated digital inputs */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = acl7225b_di_insn; - s->range_table=&range_digital; - s->private=(void *)ACL7225_DI_LO; + s->range_table = &range_digital; + s->private = (void *)ACL7225_DI_LO; printk("\n"); return 0; } -static int acl7225b_detach(comedi_device *dev) +static int acl7225b_detach(comedi_device * dev) { - printk("comedi%d: acl7225b: remove\n",dev->minor); + printk("comedi%d: acl7225b: remove\n", dev->minor); - if(dev->iobase) - release_region(dev->iobase, this_board->io_range); + if (dev->iobase) + release_region(dev->iobase, this_board->io_range); return 0; } diff --git a/comedi/drivers/addi-data/APCI1710_82x54.c b/comedi/drivers/addi-data/APCI1710_82x54.c index 7d1f04da..ceedc23b 100644 --- a/comedi/drivers/addi-data/APCI1710_82x54.c +++ b/comedi/drivers/addi-data/APCI1710_82x54.c @@ -58,7 +58,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - #include "APCI1710_82x54.h" /* @@ -260,328 +259,354 @@ INT i_InsnConfig_InitTimer(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnConfigInitTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ -INT i_APCI1710_InsnConfigInitTimer(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - - INT i_ReturnValue = 0; - BYTE b_ModulNbr; - BYTE b_TimerNbr; - BYTE b_TimerMode; - ULONG ul_ReloadValue; - BYTE b_InputClockSelection; - BYTE b_InputClockLevel; - BYTE b_OutputLevel; - BYTE b_HardwareGateLevel; - - //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz + INT i_ReturnValue = 0; + BYTE b_ModulNbr; + BYTE b_TimerNbr; + BYTE b_TimerMode; + ULONG ul_ReloadValue; + BYTE b_InputClockSelection; + BYTE b_InputClockLevel; + BYTE b_OutputLevel; + BYTE b_HardwareGateLevel; + + //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz DWORD dw_Test = 0; //END JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz - i_ReturnValue=insn->n; - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_TimerNbr = (BYTE) CR_CHAN(insn->chanspec); - b_TimerMode = (BYTE) data[0]; - ul_ReloadValue = (ULONG) data[1]; - b_InputClockSelection =(BYTE) data[2]; - b_InputClockLevel =(BYTE) data[3]; - b_OutputLevel =(BYTE) data[4]; - b_HardwareGateLevel =(BYTE) data[5]; - + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_TimerNbr = (BYTE) CR_CHAN(insn->chanspec); + b_TimerMode = (BYTE) data[0]; + ul_ReloadValue = (ULONG) data[1]; + b_InputClockSelection = (BYTE) data[2]; + b_InputClockLevel = (BYTE) data[3]; + b_OutputLevel = (BYTE) data[4]; + b_HardwareGateLevel = (BYTE) data[5]; /**************************/ /* Test the module number */ /**************************/ - - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /***********************/ - /* Test the timer mode */ + /* Test the timer mode */ /***********************/ - if (b_TimerMode <= 5) - { - //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz + if (b_TimerMode <= 5) { + //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz /*********************************/ - /* Test te imput clock selection */ + /* Test te imput clock selection */ /*********************************/ - /* - if (((b_TimerNbr == 0) && (b_InputClockSelection == 0)) || - ((b_TimerNbr != 0) && ((b_InputClockSelection == 0) || (b_InputClockSelection == 1)))) - */ - - if (((b_TimerNbr == 0) && (b_InputClockSelection == APCI1710_PCI_BUS_CLOCK)) || - ((b_TimerNbr == 0) && (b_InputClockSelection == APCI1710_10MHZ)) || - ((b_TimerNbr != 0) && ((b_InputClockSelection == APCI1710_PCI_BUS_CLOCK) - || (b_InputClockSelection == APCI1710_FRONT_CONNECTOR_INPUT) - || (b_InputClockSelection == APCI1710_10MHZ)))) - //END JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz - { - //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz - if (((b_InputClockSelection == APCI1710_10MHZ) && - ((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0x0000FFFFUL) >= 0x3131)) || - (b_InputClockSelection != APCI1710_10MHZ)) - { - //END JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz - /****************************************/ - /* Test the input clock level selection */ - /****************************************/ - - if ((b_InputClockLevel == 0) || (b_InputClockLevel == 1)) - { + /* + if (((b_TimerNbr == 0) && (b_InputClockSelection == 0)) || + ((b_TimerNbr != 0) && ((b_InputClockSelection == 0) || (b_InputClockSelection == 1)))) + */ + + if (((b_TimerNbr == 0) + && + (b_InputClockSelection + == + APCI1710_PCI_BUS_CLOCK)) + || ((b_TimerNbr == 0) + && + (b_InputClockSelection + == + APCI1710_10MHZ)) + || ((b_TimerNbr != 0) + && + ((b_InputClockSelection + == + APCI1710_PCI_BUS_CLOCK) + || + (b_InputClockSelection + == + APCI1710_FRONT_CONNECTOR_INPUT) + || + (b_InputClockSelection + == + APCI1710_10MHZ)))) + //END JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz + { + //BEGIN JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz + if (((b_InputClockSelection == + APCI1710_10MHZ) + && ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0x0000FFFFUL) >= 0x3131)) || (b_InputClockSelection != APCI1710_10MHZ)) { + //END JK 27.10.2003 : Add the possibility to use a 40 Mhz quartz + /****************************************/ + /* Test the input clock level selection */ + /****************************************/ + + if ((b_InputClockLevel + == 0) + || + (b_InputClockLevel + == 1)) { /*****************************************/ - /* Test the output clock level selection */ + /* Test the output clock level selection */ /*****************************************/ - if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) - { - /******************************************/ - /* Test the hardware gate level selection */ - /******************************************/ + if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) { + /******************************************/ + /* Test the hardware gate level selection */ + /******************************************/ - if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) - { - //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) { + //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + /*****************************************************/ + /* Test if version > 1.1 and clock selection = 10MHz */ /*****************************************************/ - /* Test if version > 1.1 and clock selection = 10MHz */ - /*****************************************************/ - if ((b_InputClockSelection == APCI1710_10MHZ) && - ((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0x0000FFFFUL) > 0x3131)) - { + if ((b_InputClockSelection == APCI1710_10MHZ) && ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0x0000FFFFUL) > 0x3131)) { /*********************************/ - /* Test if 40MHz quartz on board */ + /* Test if 40MHz quartz on board */ /*********************************/ - dw_Test = inl (devpriv->s_BoardInfos.ui_Address + (16 + (b_TimerNbr * 4) + (64 * b_ModulNbr))); + dw_Test = inl(devpriv->s_BoardInfos.ui_Address + (16 + (b_TimerNbr * 4) + (64 * b_ModulNbr))); - dw_Test = (dw_Test >> 16) & 1; - } - else - { - dw_Test = 1; - } + dw_Test = (dw_Test >> 16) & 1; + } else { + dw_Test = 1; + } /************************/ - /* Test if detection OK */ + /* Test if detection OK */ /************************/ - if (dw_Test == 1) - { - //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + if (dw_Test == 1) { + //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz /*********************/ - /* Initialisation OK */ + /* Initialisation OK */ /*********************/ - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init = 1; - + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + b_82X54Init + = + 1; + /**********************************/ - /* Save the input clock selection */ + /* Save the input clock selection */ /**********************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_InputClockSelection = b_InputClockSelection; - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + b_InputClockSelection + = + b_InputClockSelection; + /******************************/ - /* Save the input clock level */ + /* Save the input clock level */ /******************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_InputClockLevel = ~b_InputClockLevel & 1; - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + b_InputClockLevel + = + ~b_InputClockLevel + & + 1; + /*************************/ - /* Save the output level */ + /* Save the output level */ /*************************/ - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_OutputLevel = ~b_OutputLevel & 1; - + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + b_OutputLevel + = + ~b_OutputLevel + & + 1; + /***********************/ - /* Save the gate level */ + /* Save the gate level */ /***********************/ - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_HardwareGateLevel = b_HardwareGateLevel; - + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + b_HardwareGateLevel + = + b_HardwareGateLevel; + /****************************************************/ - /* Set the configuration word and disable the timer */ + /* Set the configuration word and disable the timer */ /****************************************************/ - //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz - /* - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord = (DWORD) (((b_HardwareGateLevel << 0) & 0x1) | - ((b_InputClockLevel << 1) & 0x2) | - (((~b_OutputLevel & 1) << 2) & 0x4) | - ((b_InputClockSelection << 4) & 0x10)); - */ - /**************************/ - /* Test if 10MHz selected */ - /**************************/ - - if (b_InputClockSelection == APCI1710_10MHZ) - { - b_InputClockSelection = 2; - } - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord = (DWORD) (((b_HardwareGateLevel << 0) & 0x1) | - ((b_InputClockLevel << 1) & 0x2) | - (((~b_OutputLevel & 1) << 2) & 0x4) | - ((b_InputClockSelection << 4) & 0x30)); - //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo.s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord, devpriv->s_BoardInfos. - ui_Address + 32 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + /* + devpriv->s_ModuleInfo [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo [b_TimerNbr]. + dw_ConfigurationWord = (DWORD) (((b_HardwareGateLevel << 0) & 0x1) | + ((b_InputClockLevel << 1) & 0x2) | + (((~b_OutputLevel & 1) << 2) & 0x4) | + ((b_InputClockSelection << 4) & 0x10)); + */ + /**************************/ + /* Test if 10MHz selected */ + /**************************/ + + if (b_InputClockSelection == APCI1710_10MHZ) { + b_InputClockSelection + = + 2; + } + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + = + (DWORD) + ( + ((b_HardwareGateLevel << 0) & 0x1) | ((b_InputClockLevel << 1) & 0x2) | (((~b_OutputLevel & 1) << 2) & 0x4) | ((b_InputClockSelection << 4) & 0x30)); + //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + outl(devpriv->s_ModuleInfo[b_ModulNbr].s_82X54ModuleInfo.s_82X54TimerInfo[b_TimerNbr].dw_ConfigurationWord, devpriv->s_BoardInfos.ui_Address + 32 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); /******************************/ - /* Initialise the 82X54 Timer */ + /* Initialise the 82X54 Timer */ /******************************/ - - outl((DWORD) b_TimerMode,devpriv->s_BoardInfos. - ui_Address + 16 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - + outl((DWORD) b_TimerMode, devpriv->s_BoardInfos.ui_Address + 16 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + /**************************/ - /* Write the reload value */ + /* Write the reload value */ /**************************/ - - - outl(ul_ReloadValue,devpriv->s_BoardInfos. - ui_Address + 0 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz - } // if (dw_Test == 1) - else - { + + outl(ul_ReloadValue, devpriv->s_BoardInfos.ui_Address + 0 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + //BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + } // if (dw_Test == 1) + else { /****************************************/ - /* Input timer clock selection is wrong */ + /* Input timer clock selection is wrong */ /****************************************/ - i_ReturnValue = -6; - } // if (dw_Test == 1) - //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz - } // if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) - else - { + i_ReturnValue + = + -6; + } // if (dw_Test == 1) + //END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz + } // if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) + else { /***********************************************/ - /* Selection from hardware gate level is wrong */ + /* Selection from hardware gate level is wrong */ /***********************************************/ - DPRINTK("Selection from hardware gate level is wrong\n"); - i_ReturnValue = -9; - } // if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) - } // if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) - else - { + DPRINTK("Selection from hardware gate level is wrong\n"); + i_ReturnValue + = + -9; + } // if ((b_HardwareGateLevel == 0) || (b_HardwareGateLevel == 1)) + } // if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) + else { /**********************************************/ - /* Selection from output clock level is wrong */ + /* Selection from output clock level is wrong */ /**********************************************/ - DPRINTK("Selection from output clock level is wrong\n"); - i_ReturnValue = -8; - } // if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) - } // if ((b_InputClockLevel == 0) || (b_InputClockLevel == 1)) - else - { + DPRINTK("Selection from output clock level is wrong\n"); + i_ReturnValue + = + -8; + } // if ((b_OutputLevel == 0) || (b_OutputLevel == 1)) + } // if ((b_InputClockLevel == 0) || (b_InputClockLevel == 1)) + else { /*********************************************/ - /* Selection from input clock level is wrong */ + /* Selection from input clock level is wrong */ /*********************************************/ - DPRINTK("Selection from input clock level is wrong\n"); - i_ReturnValue = -7; - } // if ((b_InputClockLevel == 0) || (b_InputClockLevel == 1)) - } - else - { + DPRINTK("Selection from input clock level is wrong\n"); + i_ReturnValue = + -7; + } // if ((b_InputClockLevel == 0) || (b_InputClockLevel == 1)) + } else { /****************************************/ - /* Input timer clock selection is wrong */ + /* Input timer clock selection is wrong */ /****************************************/ - DPRINTK("Input timer clock selection is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Input timer clock selection is wrong\n"); + i_ReturnValue = -6; + } + } else { /****************************************/ - /* Input timer clock selection is wrong */ + /* Input timer clock selection is wrong */ /****************************************/ - DPRINTK("Input timer clock selection is wrong\n"); - i_ReturnValue = -6; - } - } // if ((b_TimerMode >= 0) && (b_TimerMode <= 5)) - else - { + DPRINTK("Input timer clock selection is wrong\n"); + i_ReturnValue = -6; + } + } // if ((b_TimerMode >= 0) && (b_TimerMode <= 5)) + else { /*********************************/ - /* Timer mode selection is wrong */ + /* Timer mode selection is wrong */ /*********************************/ - DPRINTK("Timer mode selection is wrong\n"); - i_ReturnValue = -5; - } // if ((b_TimerMode >= 0) && (b_TimerMode <= 5)) - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - else - { - /*************************/ - /* Timer selection wrong */ - /*************************/ - - DPRINTK("Timer selection wrong\n"); - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + DPRINTK("Timer mode selection is wrong\n"); + i_ReturnValue = -5; + } // if ((b_TimerMode >= 0) && (b_TimerMode <= 5)) + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + else { + /*************************/ + /* Timer selection wrong */ + /*************************/ + + DPRINTK("Timer selection wrong\n"); + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -632,248 +657,325 @@ i_ReturnValue=insn->n; +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnWriteEnableDisableTimer(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_DummyRead; - BYTE b_ModulNbr; - BYTE b_TimerNbr; - BYTE b_ActionType; - BYTE b_InterruptEnable; - - i_ReturnValue=insn->n; - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_TimerNbr = (BYTE) CR_CHAN(insn->chanspec); - b_ActionType = (BYTE) data[0]; // enable disable +INT i_APCI1710_InsnWriteEnableDisableTimer(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_DummyRead; + BYTE b_ModulNbr; + BYTE b_TimerNbr; + BYTE b_ActionType; + BYTE b_InterruptEnable; + + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_TimerNbr = (BYTE) CR_CHAN(insn->chanspec); + b_ActionType = (BYTE) data[0]; // enable disable /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /*****************************/ - /* Test if timer initialised */ + /* Test if timer initialised */ /*****************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_82X54Init == 1) { - switch(b_ActionType) - { - case APCI1710_ENABLE: + switch (b_ActionType) { + case APCI1710_ENABLE: - b_InterruptEnable = (BYTE) data[1]; + b_InterruptEnable = + (BYTE) data[1]; /********************************/ - /* Test the interrupt selection */ + /* Test the interrupt selection */ /********************************/ - if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - { - if (b_InterruptEnable == APCI1710_ENABLE) - { - - dw_DummyRead=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + if ((b_InterruptEnable == + APCI1710_ENABLE) + || (b_InterruptEnable == + APCI1710_DISABLE)) + { + if (b_InterruptEnable == + APCI1710_ENABLE) + { + + dw_DummyRead = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + 12 + + (b_TimerNbr + * + 4) + + + (64 * b_ModulNbr)); /************************/ - /* Enable the interrupt */ + /* Enable the interrupt */ /************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord | 0x8; - - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord,devpriv->s_BoardInfos. - ui_Address + 32 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - devpriv->tsk_Current=current; // Save the current process task structure - - - } // if (b_InterruptEnable == APCI1710_ENABLE) - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + | 0x8; + + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord, + devpriv-> + s_BoardInfos. + ui_Address + + 32 + + (b_TimerNbr + * + 4) + + + (64 * b_ModulNbr)); + devpriv->tsk_Current = current; // Save the current process task structure + + } // if (b_InterruptEnable == APCI1710_ENABLE) + else { /*************************/ - /* Disable the interrupt */ + /* Disable the interrupt */ /*************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord & 0xF7; - - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord,devpriv->s_BoardInfos. - ui_Address + 32 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + & 0xF7; + + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord, + devpriv-> + s_BoardInfos. + ui_Address + + 32 + + (b_TimerNbr + * + 4) + + + (64 * b_ModulNbr)); /***************************/ - /* Save the interrupt flag */ + /* Save the interrupt flag */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask & (0xFF - (1 << b_TimerNbr)); - } // if (b_InterruptEnable == APCI1710_ENABLE) + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + & (0xFF + - + (1 << b_TimerNbr)); + } // if (b_InterruptEnable == APCI1710_ENABLE) /***********************/ - /* Test if error occur */ + /* Test if error occur */ /***********************/ - if (i_ReturnValue >= 0) - { + if (i_ReturnValue >= 0) { /***************************/ - /* Save the interrupt flag */ + /* Save the interrupt flag */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask | ((1 & b_InterruptEnable) << b_TimerNbr); - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + | ((1 & b_InterruptEnable) << b_TimerNbr); /********************/ - /* Enable the timer */ + /* Enable the timer */ /********************/ - - outl(1,devpriv->s_BoardInfos. - ui_Address + 44 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - } - } - else - { + outl(1, devpriv->s_BoardInfos.ui_Address + 44 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + } + } else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("\n"); - i_ReturnValue = -6; - } - break; - case APCI1710_DISABLE: + DPRINTK("\n"); + i_ReturnValue = -6; + } + break; + case APCI1710_DISABLE: /***************************/ - /* Test the interrupt flag */ + /* Test the interrupt flag */ /***************************/ - if (((devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask >> b_TimerNbr) & 1) == 1) - { + if (((devpriv->s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + >> + b_TimerNbr) + & 1) == 1) { /*************************/ - /* Disable the interrupt */ + /* Disable the interrupt */ /*************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord & 0xF7; - - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - dw_ConfigurationWord,devpriv->s_BoardInfos. - ui_Address + 32 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord + & 0xF7; + + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo + [b_TimerNbr]. + dw_ConfigurationWord, + devpriv-> + s_BoardInfos. + ui_Address + + 32 + + (b_TimerNbr * + 4) + + (64 * b_ModulNbr)); /***************************/ - /* Save the interrupt flag */ + /* Save the interrupt flag */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - b_InterruptMask = devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo.b_InterruptMask & (0xFF - (1 << b_TimerNbr)); - } + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + b_InterruptMask + & (0xFF - + (1 << b_TimerNbr)); + } /*********************/ - /* Disable the timer */ + /* Disable the timer */ /*********************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 44 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - break; - }// Switch end - } - else - { + outl(0, devpriv->s_BoardInfos. + ui_Address + 44 + + (b_TimerNbr * 4) + + (64 * b_ModulNbr)); + break; + } // Switch end + } else { /**************************************/ - /* Timer not initialised see function */ + /* Timer not initialised see function */ /**************************************/ - DPRINTK("Timer not initialised see function\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timer not initialised see function\n"); + i_ReturnValue = -5; + } + } else { /*************************/ - /* Timer selection wrong */ + /* Timer selection wrong */ /*************************/ - DPRINTK("Timer selection wrong\n"); - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + DPRINTK("Timer selection wrong\n"); + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_ReadAllTimerValue | @@ -909,179 +1011,165 @@ INT i_APCI1710_InsnReadAllTimerValue(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadAllTimerValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { +INT i_APCI1710_InsnReadAllTimerValue(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ INT i_ReturnValue = 0; - BYTE b_ModulNbr,b_ReadType; - PULONG pul_TimerValueArray; + BYTE b_ModulNbr, b_ReadType; + PULONG pul_TimerValueArray; + + b_ModulNbr = CR_AREF(insn->chanspec); + b_ReadType = CR_CHAN(insn->chanspec); + pul_TimerValueArray = (PULONG) data; + i_ReturnValue = insn->n; + + switch (b_ReadType) { + case APCI1710_TIMER_READINTERRUPT: + + data[0] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; - b_ModulNbr=CR_AREF(insn->chanspec); - b_ReadType=CR_CHAN(insn->chanspec); - pul_TimerValueArray=(PULONG) data; - i_ReturnValue=insn->n; - - switch(b_ReadType) - { - case APCI1710_TIMER_READINTERRUPT: - - - data[0]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - /**************************/ - /* Increment the read FIFO */ + /* Increment the read FIFO */ /***************************/ - devpriv-> - s_InterruptParameters. - ui_Read = (devpriv-> - s_InterruptParameters. - ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Read = (devpriv-> + s_InterruptParameters. + ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - break; + break; - - case APCI1710_TIMER_READALLTIMER: + case APCI1710_TIMER_READALLTIMER: /**************************/ - /* Test the module number */ + /* Test the module number */ /**************************/ - - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /********************************/ - /* Test if timer 0 iniutialised */ + /* Test if timer 0 iniutialised */ /********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [0]. - b_82X54Init == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[0].b_82X54Init == 1) { /********************************/ - /* Test if timer 1 iniutialised */ + /* Test if timer 1 iniutialised */ /********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [1]. - b_82X54Init == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[1]. + b_82X54Init == 1) { /********************************/ - /* Test if timer 2 iniutialised */ + /* Test if timer 2 iniutialised */ /********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [2]. - b_82X54Init == 1) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[2]. + b_82X54Init == 1) { /*********************/ - /* Latch all counter */ + /* Latch all counter */ /*********************/ - - outl(0x17,devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); + outl(0x17, + devpriv-> + s_BoardInfos. + ui_Address + + 12 + + (64 * b_ModulNbr)); /**************************/ - /* Read the timer 0 value */ + /* Read the timer 0 value */ /**************************/ - - pul_TimerValueArray [0]=inl(devpriv->s_BoardInfos. - ui_Address + 0 + (64 * b_ModulNbr)); + pul_TimerValueArray[0] = + inl(devpriv-> + s_BoardInfos. + ui_Address + 0 + + (64 * b_ModulNbr)); /**************************/ - /* Read the timer 1 value */ + /* Read the timer 1 value */ /**************************/ - - pul_TimerValueArray [1]=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); + pul_TimerValueArray[1] = + inl(devpriv-> + s_BoardInfos. + ui_Address + 4 + + (64 * b_ModulNbr)); /**************************/ - /* Read the timer 2 value */ + /* Read the timer 2 value */ /**************************/ - - pul_TimerValueArray [2]=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (64 * b_ModulNbr)); - } - else - { + pul_TimerValueArray[2] = + inl(devpriv-> + s_BoardInfos. + ui_Address + 8 + + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Timer 2 not initialised see function */ + /* Timer 2 not initialised see function */ /****************************************/ - DPRINTK("Timer 2 not initialised see function\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Timer 2 not initialised see function\n"); + i_ReturnValue = -6; + } + } else { /****************************************/ - /* Timer 1 not initialised see function */ + /* Timer 1 not initialised see function */ /****************************************/ - DPRINTK("Timer 1 not initialised see function\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timer 1 not initialised see function\n"); + i_ReturnValue = -5; + } + } else { /****************************************/ - /* Timer 0 not initialised see function */ + /* Timer 0 not initialised see function */ /****************************************/ - DPRINTK("Timer 0 not initialised see function\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Timer 0 not initialised see function\n"); + i_ReturnValue = -4; + } + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } - }// End of Switch + } // End of Switch return (i_ReturnValue); - } - - +} /* +----------------------------------------------------------------------------+ @@ -1098,56 +1186,51 @@ comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnBitsTimer(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnBitsTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { BYTE b_BitsType; - INT i_ReturnValue=0; - b_BitsType=data[0]; + INT i_ReturnValue = 0; + b_BitsType = data[0]; + + printk("\n82X54"); - printk ("\n82X54"); - - switch(b_BitsType) - { + switch (b_BitsType) { case APCI1710_TIMER_READVALUE: - i_ReturnValue=i_APCI1710_ReadTimerValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_CHAN(insn->chanspec), - (PULONG) &data[0]); + i_ReturnValue = i_APCI1710_ReadTimerValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_CHAN(insn->chanspec), (PULONG) & data[0]); break; case APCI1710_TIMER_GETOUTPUTLEVEL: - i_ReturnValue=i_APCI1710_GetTimerOutputLevel (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_CHAN(insn->chanspec), - (PBYTE) &data[0]); + i_ReturnValue = i_APCI1710_GetTimerOutputLevel(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_CHAN(insn->chanspec), (PBYTE) & data[0]); break; case APCI1710_TIMER_GETPROGRESSSTATUS: - i_ReturnValue=i_APCI1710_GetTimerProgressStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_CHAN(insn->chanspec), - (PBYTE) &data[0]); + i_ReturnValue = i_APCI1710_GetTimerProgressStatus(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_CHAN(insn->chanspec), (PBYTE) & data[0]); break; case APCI1710_TIMER_WRITEVALUE: - i_ReturnValue=i_APCI1710_WriteTimerValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_CHAN(insn->chanspec), - (ULONG) data[1]); - + i_ReturnValue = i_APCI1710_WriteTimerValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_CHAN(insn->chanspec), (ULONG) data[1]); + break; default: printk("Bits Config Parameter Wrong\n"); - i_ReturnValue=-1; + i_ReturnValue = -1; } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_ReadTimerValue | @@ -1178,229 +1261,208 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ReadTimerValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PULONG pul_TimerValue) - { +INT i_APCI1710_ReadTimerValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PULONG pul_TimerValue) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /*****************************/ - /* Test if timer initialised */ + /* Test if timer initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_82X54Init == 1) { /*************************/ - /* Latch the timer value */ + /* Latch the timer value */ /*************************/ - - outl((2 << b_TimerNbr) | 0xD0,devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); + outl((2 << b_TimerNbr) | 0xD0, + devpriv->s_BoardInfos. + ui_Address + 12 + + (64 * b_ModulNbr)); /**************************/ - /* Read the counter value */ + /* Read the counter value */ /**************************/ - - *pul_TimerValue=inl(devpriv->s_BoardInfos. - ui_Address + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - } - else - { + *pul_TimerValue = + inl(devpriv->s_BoardInfos. + ui_Address + (b_TimerNbr * 4) + + (64 * b_ModulNbr)); + } else { /**************************************/ - /* Timer not initialised see function */ + /* Timer not initialised see function */ /**************************************/ - DPRINTK("Timer not initialised see function\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timer not initialised see function\n"); + i_ReturnValue = -5; + } + } else { /*************************/ - /* Timer selection wrong */ + /* Timer selection wrong */ /*************************/ - DPRINTK("Timer selection wrong\n"); - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + DPRINTK("Timer selection wrong\n"); + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* -+----------------------------------------------------------------------------+ -| Function Name : _INT_ i_APCI1710_GetTimerOutputLevel | -| (BYTE_ b_BoardHandle, | -| BYTE_ b_ModulNbr, | -| BYTE_ b_TimerNbr, | -| PBYTE_ pb_OutputLevel) | -+----------------------------------------------------------------------------+ -| Task : Return the output signal level (pb_OutputLevel) from | -| selected digital timer (b_TimerNbr) from selected timer| -| module (b_ModulNbr). | -+----------------------------------------------------------------------------+ -| Input Parameters : BYTE_ b_BoardHandle : Handle of board | -| APCI-1710 | -| BYTE_ b_ModulNbr : Selected module number | -| (0 to 3) | -| BYTE_ b_TimerNbr : Timer number to test | -| (0 to 2) | -+----------------------------------------------------------------------------+ -| Output Parameters : PBYTE_ pb_OutputLevel : Output signal level | -| 0 : The output is low | -| 1 : The output is high | -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -1: The handle parameter of the board is wrong | -| -2: Module selection wrong | -| -3: Timer selection wrong | -| -4: The module is not a TIMER module | -| -5: Timer not initialised see function | -| "i_APCI1710_InitTimer" | -+----------------------------------------------------------------------------+ -*/ - -INT i_APCI1710_GetTimerOutputLevel (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PBYTE pb_OutputLevel) - { - INT i_ReturnValue = 0; + +----------------------------------------------------------------------------+ + | Function Name : _INT_ i_APCI1710_GetTimerOutputLevel | + | (BYTE_ b_BoardHandle, | + | BYTE_ b_ModulNbr, | + | BYTE_ b_TimerNbr, | + | PBYTE_ pb_OutputLevel) | + +----------------------------------------------------------------------------+ + | Task : Return the output signal level (pb_OutputLevel) from | + | selected digital timer (b_TimerNbr) from selected timer| + | module (b_ModulNbr). | + +----------------------------------------------------------------------------+ + | Input Parameters : BYTE_ b_BoardHandle : Handle of board | + | APCI-1710 | + | BYTE_ b_ModulNbr : Selected module number | + | (0 to 3) | + | BYTE_ b_TimerNbr : Timer number to test | + | (0 to 2) | + +----------------------------------------------------------------------------+ + | Output Parameters : PBYTE_ pb_OutputLevel : Output signal level | + | 0 : The output is low | + | 1 : The output is high | + +----------------------------------------------------------------------------+ + | Return Value : 0: No error | + | -1: The handle parameter of the board is wrong | + | -2: Module selection wrong | + | -3: Timer selection wrong | + | -4: The module is not a TIMER module | + | -5: Timer not initialised see function | + | "i_APCI1710_InitTimer" | + +----------------------------------------------------------------------------+ + */ + +INT i_APCI1710_GetTimerOutputLevel(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PBYTE pb_OutputLevel) +{ + INT i_ReturnValue = 0; DWORD dw_TimerStatus; - - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /*****************************/ - /* Test if timer initialised */ + /* Test if timer initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_82X54Init == 1) { /*************************/ - /* Latch the timer value */ + /* Latch the timer value */ /*************************/ - outl((2 << b_TimerNbr) | 0xE0,devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); + outl((2 << b_TimerNbr) | 0xE0, + devpriv->s_BoardInfos. + ui_Address + 12 + + (64 * b_ModulNbr)); /*************************/ - /* Read the timer status */ + /* Read the timer status */ /*************************/ - - dw_TimerStatus=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - - *pb_OutputLevel = (BYTE) (((dw_TimerStatus >> 7) & 1) ^ devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_OutputLevel); - } - else - { + dw_TimerStatus = + inl(devpriv->s_BoardInfos. + ui_Address + 16 + + (b_TimerNbr * 4) + + (64 * b_ModulNbr)); + + *pb_OutputLevel = + (BYTE) (((dw_TimerStatus >> 7) & + 1) ^ devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_OutputLevel); + } else { /**************************************/ - /* Timer not initialised see function */ + /* Timer not initialised see function */ /**************************************/ - DPRINTK("Timer not initialised see function\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timer not initialised see function\n"); + i_ReturnValue = -5; + } + } else { /*************************/ - /* Timer selection wrong */ + /* Timer selection wrong */ /*************************/ - DPRINTK("Timer selection wrong\n"); - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + DPRINTK("Timer selection wrong\n"); + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -1435,102 +1497,93 @@ INT i_APCI1710_GetTimerOutputLevel (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetTimerProgressStatus (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PBYTE pb_TimerStatus) - { - INT i_ReturnValue = 0; +INT i_APCI1710_GetTimerProgressStatus(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PBYTE pb_TimerStatus) +{ + INT i_ReturnValue = 0; DWORD dw_TimerStatus; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /*****************************/ - /* Test if timer initialised */ + /* Test if timer initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_82X54Init == 1) { /*************************/ - /* Latch the timer value */ + /* Latch the timer value */ /*************************/ - - outl((2 << b_TimerNbr) | 0xE0,devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); + outl((2 << b_TimerNbr) | 0xE0, + devpriv->s_BoardInfos. + ui_Address + 12 + + (64 * b_ModulNbr)); /*************************/ - /* Read the timer status */ + /* Read the timer status */ /*************************/ - - dw_TimerStatus=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - - *pb_TimerStatus = (BYTE) ((dw_TimerStatus) >> 8) & 1; - printk("ProgressStatus : %d",*pb_TimerStatus); - } - else - { + dw_TimerStatus = + inl(devpriv->s_BoardInfos. + ui_Address + 16 + + (b_TimerNbr * 4) + + (64 * b_ModulNbr)); + + *pb_TimerStatus = + (BYTE) ((dw_TimerStatus) >> 8) & + 1; + printk("ProgressStatus : %d", + *pb_TimerStatus); + } else { /**************************************/ - /* Timer not initialised see function */ + /* Timer not initialised see function */ /**************************************/ - i_ReturnValue = -5; - } - } - else - { + i_ReturnValue = -5; + } + } else { /*************************/ - /* Timer selection wrong */ + /* Timer selection wrong */ /*************************/ - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - i_ReturnValue = -4; - } - } - else - { + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - i_ReturnValue = -2; - } - - return (i_ReturnValue); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1565,91 +1618,73 @@ INT i_APCI1710_GetTimerProgressStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ - INT i_APCI1710_WriteTimerValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - ULONG ul_WriteValue) - { - INT i_ReturnValue = 0; - +INT i_APCI1710_WriteTimerValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, ULONG ul_WriteValue) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if 82X54 timer */ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { /*************************/ - /* Test the timer number */ + /* Test the timer number */ /*************************/ - if (b_TimerNbr <= 2) - { + if (b_TimerNbr <= 2) { /*****************************/ - /* Test if timer initialised */ + /* Test if timer initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_82X54ModuleInfo. - s_82X54TimerInfo [b_TimerNbr]. - b_82X54Init == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_82X54ModuleInfo. + s_82X54TimerInfo[b_TimerNbr]. + b_82X54Init == 1) { /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - - outl(ul_WriteValue,devpriv->s_BoardInfos. - ui_Address + (b_TimerNbr * 4) + (64 * b_ModulNbr)); - } - else - { + outl(ul_WriteValue, + devpriv->s_BoardInfos. + ui_Address + (b_TimerNbr * 4) + + (64 * b_ModulNbr)); + } else { /**************************************/ - /* Timer not initialised see function */ + /* Timer not initialised see function */ /**************************************/ - DPRINTK("Timer not initialised see function\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timer not initialised see function\n"); + i_ReturnValue = -5; + } + } else { /*************************/ - /* Timer selection wrong */ + /* Timer selection wrong */ /*************************/ - DPRINTK("Timer selection wrong\n"); - i_ReturnValue = -3; - } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) - } - else - { + DPRINTK("Timer selection wrong\n"); + i_ReturnValue = -3; + } // if ((b_TimerNbr >= 0) && (b_TimerNbr <= 2)) + } else { /************************************/ - /* The module is not a TIMER module */ + /* The module is not a TIMER module */ /************************************/ - DPRINTK("The module is not a TIMER module\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The module is not a TIMER module\n"); + i_ReturnValue = -4; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - - + return (i_ReturnValue); +} diff --git a/comedi/drivers/addi-data/APCI1710_82x54.h b/comedi/drivers/addi-data/APCI1710_82x54.h index 6e4e2bdd..3c54a9d0 100644 --- a/comedi/drivers/addi-data/APCI1710_82x54.h +++ b/comedi/drivers/addi-data/APCI1710_82x54.h @@ -21,7 +21,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - #define APCI1710_PCI_BUS_CLOCK 0 #define APCI1710_FRONT_CONNECTOR_INPUT 1 @@ -35,7 +34,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc // BEGIN JK 27.10.03 : Add the possibility to use a 40 Mhz quartz #ifndef APCI1710_10MHZ - #define APCI1710_10MHZ 10 +#define APCI1710_10MHZ 10 #endif // END JK 27.10.03 : Add the possibility to use a 40 Mhz quartz @@ -45,54 +44,41 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnConfigInitTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); - -INT i_APCI1710_InsnConfigInitTimer(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - - -INT i_APCI1710_InsnWriteEnableDisableTimer(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnWriteEnableDisableTimer(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | 82X54 READ FUNCTION | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadAllTimerValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - +INT i_APCI1710_InsnReadAllTimerValue(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -INT i_APCI1710_InsnBitsTimer(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnBitsTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | 82X54 READ & WRITE FUNCTION | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ReadTimerValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PULONG pul_TimerValue); +INT i_APCI1710_ReadTimerValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PULONG pul_TimerValue); -INT i_APCI1710_GetTimerOutputLevel (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PBYTE pb_OutputLevel); +INT i_APCI1710_GetTimerOutputLevel(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PBYTE pb_OutputLevel); -INT i_APCI1710_GetTimerProgressStatus (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - PBYTE pb_TimerStatus); +INT i_APCI1710_GetTimerProgressStatus(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, PBYTE pb_TimerStatus); /* +----------------------------------------------------------------------------+ | 82X54 WRITE FUNCTION | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_WriteTimerValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_TimerNbr, - ULONG ul_WriteValue); +INT i_APCI1710_WriteTimerValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_TimerNbr, ULONG ul_WriteValue); diff --git a/comedi/drivers/addi-data/APCI1710_Chrono.c b/comedi/drivers/addi-data/APCI1710_Chrono.c index 89916fad..c2232696 100644 --- a/comedi/drivers/addi-data/APCI1710_Chrono.c +++ b/comedi/drivers/addi-data/APCI1710_Chrono.c @@ -131,469 +131,657 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - - -INT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - ULONG ul_TimerValue = 0; - ULONG ul_TimingInterval = 0; +INT i_APCI1710_InsnConfigInitChrono(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + ULONG ul_TimerValue = 0; + ULONG ul_TimingInterval = 0; ULONG ul_RealTimingInterval = 0; double d_RealTimingInterval = 0; - DWORD dw_ModeArray [8] = {0x01, 0x05, 0x00, 0x04, 0x02, 0x0E, 0x0A, 0x06}; - BYTE b_ModulNbr,b_ChronoMode,b_PCIInputClock,b_TimingUnit; + DWORD dw_ModeArray[8] = + { 0x01, 0x05, 0x00, 0x04, 0x02, 0x0E, 0x0A, 0x06 }; + BYTE b_ModulNbr, b_ChronoMode, b_PCIInputClock, b_TimingUnit; - b_ModulNbr = CR_AREF(insn->chanspec); - b_ChronoMode = (BYTE) data[0]; - b_PCIInputClock = (BYTE) data[1]; - b_TimingUnit = (BYTE) data[2]; - ul_TimingInterval = (ULONG) data[3]; - i_ReturnValue = insn->n; + b_ModulNbr = CR_AREF(insn->chanspec); + b_ChronoMode = (BYTE) data[0]; + b_PCIInputClock = (BYTE) data[1]; + b_TimingUnit = (BYTE) data[2]; + ul_TimingInterval = (ULONG) data[3]; + i_ReturnValue = insn->n; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /*****************************/ - /* Test the chronometer mode */ + /* Test the chronometer mode */ /*****************************/ - if (b_ChronoMode <= 7) - { + if (b_ChronoMode <= 7) { /**************************/ - /* Test the PCI bus clock */ + /* Test the PCI bus clock */ /**************************/ - if ((b_PCIInputClock == APCI1710_30MHZ) || - (b_PCIInputClock == APCI1710_33MHZ) || - (b_PCIInputClock == APCI1710_40MHZ)) - { + if ((b_PCIInputClock == APCI1710_30MHZ) || + (b_PCIInputClock == APCI1710_33MHZ) || + (b_PCIInputClock == APCI1710_40MHZ)) { /*************************/ - /* Test the timing unity */ + /* Test the timing unity */ /*************************/ - if (b_TimingUnit <= 4) - { + if (b_TimingUnit <= 4) { /**********************************/ - /* Test the base timing selection */ + /* Test the base timing selection */ /**********************************/ - if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 66) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165576UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 60) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150240UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 50) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374182UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 1UL))) - { + if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 66) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165576UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 60) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150240UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 50) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374182UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 1UL))) { /**************************/ - /* Test the board version */ + /* Test the board version */ /**************************/ - if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos. - b_BoardVersion > 0)) || - (b_PCIInputClock != APCI1710_40MHZ)) - { + if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos.b_BoardVersion > 0)) || (b_PCIInputClock != APCI1710_40MHZ)) { /************************/ - /* Test the TOR version */ + /* Test the TOR version */ /************************/ - if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)) || - (b_PCIInputClock != APCI1710_40MHZ)) - { - fpu_begin (); - + if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3131)) || (b_PCIInputClock != APCI1710_40MHZ)) { + fpu_begin + (); + /****************************************/ - /* Calculate the timer 0 division fator */ + /* Calculate the timer 0 division fator */ /****************************************/ - switch (b_TimingUnit) - { + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (0.001 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (0.001 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (0.001 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (0.001 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.001 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (0.001 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); - } - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (0.001 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (0.001 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (0.001 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 0.99392); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (1.0 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (1.0 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (1.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (1.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / ((double) 1.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (1.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (1.0 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + ( + (double) + 1.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (1.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 0.99392); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = ul_TimingInterval * (1000 * b_PCIInputClock); + ul_TimerValue + = + ul_TimingInterval + * + (1000 + * + b_PCIInputClock); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (1000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (1000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (1000.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (1000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); - } - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (1000.0 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (1000.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (1000.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 0.99392); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: - + case 3: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (1000000.0 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (1000000.0 + * + b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (1000000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (1000000.0 + * + (double) + b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (1000000.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (1000000.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 0.99392); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (1000000.0 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + ( + (ul_TimingInterval + * + 60) + * + (1000000.0 + * + b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_TimingInterval * 60.0) * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)(ul_TimingInterval * 60.0) * (1000000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60; - d_RealTimingInterval = ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) / 60.0; - - if ((double) (((double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60.0) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (1000000.0 + * + (double) + b_PCIInputClock)) + / + 60; + d_RealTimingInterval + = + ( + (double) + ul_TimerValue + / + (0.001 * (double)b_PCIInputClock)) / 60.0; + + if ((double)(((double)ul_TimerValue / (1000000.0 * (double)b_PCIInputClock)) / 60.0) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 0.99392); + } + + break; + } + + fpu_end(); - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); - } - - - break; - } - - fpu_end (); - /****************************/ - /* Save the PCI input clock */ + /* Save the PCI input clock */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_PCIInputClock = b_PCIInputClock; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_PCIInputClock + = + b_PCIInputClock; /*************************/ - /* Save the timing unity */ + /* Save the timing unity */ /*************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_TimingUnit = b_TimingUnit; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_TimingUnit + = + b_TimingUnit; /************************/ - /* Save the base timing */ + /* Save the base timing */ /************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - d_TimingInterval = d_RealTimingInterval; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + d_TimingInterval + = + d_RealTimingInterval; /****************************/ - /* Set the chronometer mode */ + /* Set the chronometer mode */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg = dw_ModeArray [b_ChronoMode]; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg + = + dw_ModeArray + [b_ChronoMode]; /***********************/ - /* Test if 40 MHz used */ + /* Test if 40 MHz used */ /***********************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg | 0x80; - } - - outl(devpriv->s_ModuleInfo [b_ModulNbr].s_ChronoModuleInfo. - dw_ConfigReg,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); + if (b_PCIInputClock == APCI1710_40MHZ) { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg + | + 0x80; + } + + outl(devpriv->s_ModuleInfo[b_ModulNbr].s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr)); /***********************/ - /* Write timer 0 value */ + /* Write timer 0 value */ /***********************/ - - outl(ul_TimerValue,devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); + outl(ul_TimerValue, devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); /*********************/ - /* Chronometer init. */ + /* Chronometer init. */ /*********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit = 1; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_ChronoInit + = + 1; + } else { /***********************************************/ - /* TOR version error for 40MHz clock selection */ + /* TOR version error for 40MHz clock selection */ /***********************************************/ - DPRINTK("TOR version error for 40MHz clock selection\n"); - i_ReturnValue = -9; - } - } - else - { + DPRINTK("TOR version error for 40MHz clock selection\n"); + i_ReturnValue + = + -9; + } + } else { /**************************************************************/ - /* You can not used the 40MHz clock selection wich this board */ + /* You can not used the 40MHz clock selection wich this board */ /**************************************************************/ - DPRINTK("You can not used the 40MHz clock selection wich this board\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("You can not used the 40MHz clock selection wich this board\n"); + i_ReturnValue = + -8; + } + } else { /**********************************/ - /* Base timing selection is wrong */ + /* Base timing selection is wrong */ /**********************************/ - DPRINTK("Base timing selection is wrong\n"); - i_ReturnValue = -7; - } - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - else - { + DPRINTK("Base timing selection is wrong\n"); + i_ReturnValue = -7; + } + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + else { /***********************************/ - /* Timing unity selection is wrong */ + /* Timing unity selection is wrong */ /***********************************/ - DPRINTK("Timing unity selection is wrong\n"); - i_ReturnValue = -6; - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) - else - { + DPRINTK("Timing unity selection is wrong\n"); + i_ReturnValue = -6; + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) + else { /*****************************************/ - /* The selected PCI input clock is wrong */ + /* The selected PCI input clock is wrong */ /*****************************************/ - DPRINTK("The selected PCI input clock is wrong\n"); - i_ReturnValue = -5; - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) - } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7) - else - { + DPRINTK("The selected PCI input clock is wrong\n"); + i_ReturnValue = -5; + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) + } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7) + else { /***************************************/ - /* Chronometer mode selection is wrong */ + /* Chronometer mode selection is wrong */ /***************************************/ - -DPRINTK("Chronometer mode selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7) - } - else - { + + DPRINTK("Chronometer mode selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7) + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - data[0] = ul_RealTimingInterval; - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - + data[0] = ul_RealTimingInterval; + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -652,221 +840,240 @@ comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { +INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ INT i_ReturnValue = 0; - BYTE b_ModulNbr,b_CycleMode,b_InterruptEnable,b_Action; - b_ModulNbr = CR_AREF(insn->chanspec); - b_Action =(BYTE) data[0]; - b_CycleMode =(BYTE) data[1]; - b_InterruptEnable =(BYTE) data[2]; - i_ReturnValue = insn->n; - - - + BYTE b_ModulNbr, b_CycleMode, b_InterruptEnable, b_Action; + b_ModulNbr = CR_AREF(insn->chanspec); + b_Action = (BYTE) data[0]; + b_CycleMode = (BYTE) data[1]; + b_InterruptEnable = (BYTE) data[2]; + i_ReturnValue = insn->n; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /***********************************/ - /* Test if chronometer initialised */ + /* Test if chronometer initialised */ /***********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_ChronoInit == 1) { + switch (b_Action) { + + case APCI1710_ENABLE: - switch(b_Action) - { - - case APCI1710_ENABLE : - /*********************************/ - /* Test the cycle mode parameter */ + /* Test the cycle mode parameter */ /*********************************/ - if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - { + if ((b_CycleMode == APCI1710_SINGLE) + || (b_CycleMode == + APCI1710_CONTINUOUS)) { /***************************/ - /* Test the interrupt flag */ + /* Test the interrupt flag */ /***************************/ - if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - { - - + if ((b_InterruptEnable == + APCI1710_ENABLE) + || (b_InterruptEnable == + APCI1710_DISABLE)) + { + /***************************/ - /* Save the interrupt flag */ + /* Save the interrupt flag */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_InterruptMask = b_InterruptEnable; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_InterruptMask + = + b_InterruptEnable; /***********************/ - /* Save the cycle mode */ + /* Save the cycle mode */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_CycleMode = b_CycleMode; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_CycleMode = + b_CycleMode; - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg = (devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg & 0x8F) | - ((1 & b_InterruptEnable) << 5) | - ((1 & b_CycleMode) << 6) | - 0x10 ; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg & + 0x8F) | ((1 & + b_InterruptEnable) + << 5) | ((1 & + b_CycleMode) + << 6) | 0x10; /*****************************/ - /* Test if interrupt enabled */ + /* Test if interrupt enabled */ /*****************************/ - if (b_InterruptEnable == APCI1710_ENABLE) - { + if (b_InterruptEnable == + APCI1710_ENABLE) + { /****************************/ - /* Clear the interrupt flag */ + /* Clear the interrupt flag */ /****************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos. - ui_Address + 32 + (64 * b_ModulNbr)); - devpriv->tsk_Current=current; // Save the current process task structure - } + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg, + devpriv-> + s_BoardInfos. + ui_Address + + 32 + + (64 * b_ModulNbr)); + devpriv->tsk_Current = current; // Save the current process task structure + } /***********************************/ - /* Enable or disable the interrupt */ - /* Enable the chronometer */ + /* Enable or disable the interrupt */ + /* Enable the chronometer */ /***********************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo.dw_ConfigReg,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); + + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg, + devpriv-> + s_BoardInfos. + ui_Address + + 16 + + (64 * b_ModulNbr)); /*************************/ - /* Clear status register */ + /* Clear status register */ /*************************/ - - outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr)); - - } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - else - { + outl(0, devpriv-> + s_BoardInfos. + ui_Address + + 36 + + (64 * b_ModulNbr)); + + } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) + else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("Interrupt parameter is wrong\n"); - i_ReturnValue = -6; - } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - else - { + DPRINTK("Interrupt parameter is wrong\n"); + i_ReturnValue = -6; + } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) + } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) + else { /***********************************************/ - /* Chronometer acquisition mode cycle is wrong */ + /* Chronometer acquisition mode cycle is wrong */ /***********************************************/ - DPRINTK("Chronometer acquisition mode cycle is wrong\n"); - i_ReturnValue = -5; - } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - break; + DPRINTK("Chronometer acquisition mode cycle is wrong\n"); + i_ReturnValue = -5; + } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) + break; - case APCI1710_DISABLE : + case APCI1710_DISABLE: - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_InterruptMask = 0; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo. + b_InterruptMask = 0; - devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - dw_ConfigReg & 0x2F; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg = + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo. + dw_ConfigReg & 0x2F; /***************************/ - /* Disable the interrupt */ - /* Disable the chronometer */ + /* Disable the interrupt */ + /* Disable the chronometer */ /***************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.dw_ConfigReg, + devpriv->s_BoardInfos. + ui_Address + 16 + + (64 * b_ModulNbr)); /***************************/ - /* Test if continuous mode */ + /* Test if continuous mode */ /***************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo.b_CycleMode == APCI1710_CONTINUOUS) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo. + b_CycleMode == + APCI1710_CONTINUOUS) { /*************************/ - /* Clear status register */ + /* Clear status register */ /*************************/ - - outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr)); - } - break; - - default: - DPRINTK("Inputs wrong! Enable or Disable chrono\n"); - i_ReturnValue = -8; - } // switch ENABLE/DISABLE - } - else - { + outl(0, devpriv->s_BoardInfos. + ui_Address + 36 + + (64 * b_ModulNbr)); + } + break; + + default: + DPRINTK("Inputs wrong! Enable or Disable chrono\n"); + i_ReturnValue = -8; + } // switch ENABLE/DISABLE + } else { /*******************************/ - /* Chronometer not initialised */ + /* Chronometer not initialised */ /*******************************/ - DPRINTK("Chronometer not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Chronometer not initialised\n"); + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -883,81 +1090,72 @@ comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnReadChrono(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { BYTE b_ReadType; - INT i_ReturnValue=insn->n; - - b_ReadType=CR_CHAN(insn->chanspec); + INT i_ReturnValue = insn->n; + + b_ReadType = CR_CHAN(insn->chanspec); - switch(b_ReadType) - { + switch (b_ReadType) { case APCI1710_CHRONO_PROGRESS_STATUS: - i_ReturnValue=i_APCI1710_GetChronoProgressStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; + i_ReturnValue = i_APCI1710_GetChronoProgressStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; case APCI1710_CHRONO_READVALUE: - i_ReturnValue=i_APCI1710_ReadChronoValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (UINT) insn->unused[0], - (PBYTE) &data[0], - (PULONG) &data[1]); - break; + i_ReturnValue = i_APCI1710_ReadChronoValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (UINT) insn->unused[0], + (PBYTE) & data[0], (PULONG) & data[1]); + break; case APCI1710_CHRONO_CONVERTVALUE: - i_ReturnValue=i_APCI1710_ConvertChronoValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (ULONG) insn->unused[0], - (PULONG) &data[0], - (PBYTE) &data[1], - (PBYTE) &data[2], - (PUINT) &data[3], - (PUINT) &data[4], - (PUINT) &data[5]); - break; - - case APCI1710_CHRONO_READINTERRUPT: - printk("In Chrono Read Interrupt\n"); - - data[0]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - + i_ReturnValue = i_APCI1710_ConvertChronoValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (ULONG) insn->unused[0], + (PULONG) & data[0], + (PBYTE) & data[1], + (PBYTE) & data[2], + (PUINT) & data[3], + (PUINT) & data[4], (PUINT) & data[5]); + break; + + case APCI1710_CHRONO_READINTERRUPT: + printk("In Chrono Read Interrupt\n"); + + data[0] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; + /**************************/ - /* Increment the read FIFO */ + /* Increment the read FIFO */ /***************************/ - devpriv-> - s_InterruptParameters. - ui_Read = (devpriv-> - s_InterruptParameters. - ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - break; - + devpriv-> + s_InterruptParameters. + ui_Read = (devpriv-> + s_InterruptParameters. + ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + break; + default: printk("ReadType Parameter wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; - return (i_ReturnValue); + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; + return (i_ReturnValue); } - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_GetChronoProgressStatus | @@ -996,121 +1194,103 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetChronoProgressStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_ChronoStatus) - { - INT i_ReturnValue = 0; +INT i_APCI1710_GetChronoProgressStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_ChronoStatus) +{ + INT i_ReturnValue = 0; DWORD dw_Status; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /***********************************/ - /* Test if chronometer initialised */ + /* Test if chronometer initialised */ /***********************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit == 1) - { - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (64 * b_ModulNbr)); + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_ChronoInit == 1) { + + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 8 + (64 * b_ModulNbr)); /********************/ - /* Test if overflow */ + /* Test if overflow */ /********************/ - if ((dw_Status & 8) == 8) - { + if ((dw_Status & 8) == 8) { /******************/ - /* Overflow occur */ + /* Overflow occur */ /******************/ - *pb_ChronoStatus = 3; - } // if ((dw_Status & 8) == 8) - else - { + *pb_ChronoStatus = 3; + } // if ((dw_Status & 8) == 8) + else { /*******************************/ - /* Test if measurement stopped */ + /* Test if measurement stopped */ /*******************************/ - if ((dw_Status & 2) == 2) - { + if ((dw_Status & 2) == 2) { /***********************/ - /* A stop signal occur */ + /* A stop signal occur */ /***********************/ - *pb_ChronoStatus = 2; - } // if ((dw_Status & 2) == 2) - else - { + *pb_ChronoStatus = 2; + } // if ((dw_Status & 2) == 2) + else { /*******************************/ - /* Test if measurement started */ + /* Test if measurement started */ /*******************************/ - if ((dw_Status & 1) == 1) - { + if ((dw_Status & 1) == 1) { /************************/ - /* A start signal occur */ + /* A start signal occur */ /************************/ - *pb_ChronoStatus = 1; - } // if ((dw_Status & 1) == 1) - else - { + *pb_ChronoStatus = 1; + } // if ((dw_Status & 1) == 1) + else { /***************************/ - /* Measurement not started */ + /* Measurement not started */ /***************************/ - *pb_ChronoStatus = 0; - } // if ((dw_Status & 1) == 1) - } // if ((dw_Status & 2) == 2) - } // if ((dw_Status & 8) == 8) - } - else - { + *pb_ChronoStatus = 0; + } // if ((dw_Status & 1) == 1) + } // if ((dw_Status & 2) == 2) + } // if ((dw_Status & 8) == 8) + } else { /*******************************/ - /* Chronometer not initialised */ + /* Chronometer not initialised */ /*******************************/ - DPRINTK("Chronometer not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Chronometer not initialised\n"); + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1175,241 +1355,228 @@ INT i_APCI1710_GetChronoProgressStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ReadChronoValue (comedi_device *dev, - BYTE b_ModulNbr, - UINT ui_TimeOut, - PBYTE pb_ChronoStatus, - PULONG pul_ChronoValue) - { - INT i_ReturnValue = 0; +INT i_APCI1710_ReadChronoValue(comedi_device * dev, + BYTE b_ModulNbr, + UINT ui_TimeOut, PBYTE pb_ChronoStatus, PULONG pul_ChronoValue) +{ + INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_TimeOut = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /***********************************/ - /* Test if chronometer initialised */ + /* Test if chronometer initialised */ /***********************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_ChronoInit == 1) { /*****************************/ - /* Test the timout parameter */ + /* Test the timout parameter */ /*****************************/ - if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL)) - { - - for (;;) - { + if ((ui_TimeOut >= 0) + && (ui_TimeOut <= 65535UL)) { + + for (;;) { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (64 * b_ModulNbr)); - + dw_Status = + inl(devpriv-> + s_BoardInfos. + ui_Address + 8 + + (64 * b_ModulNbr)); /********************/ - /* Test if overflow */ + /* Test if overflow */ /********************/ - if ((dw_Status & 8) == 8) - { + if ((dw_Status & 8) == 8) { /******************/ - /* Overflow occur */ + /* Overflow occur */ /******************/ - *pb_ChronoStatus = 3; + *pb_ChronoStatus = 3; /***************************/ - /* Test if continuous mode */ + /* Test if continuous mode */ /***************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_CycleMode == APCI1710_CONTINUOUS) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_CycleMode == + APCI1710_CONTINUOUS) + { /*************************/ - /* Clear status register */ + /* Clear status register */ /*************************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 36 + (64 * b_ModulNbr)); - } + outl(0, devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr)); + } - break; - } // if ((dw_Status & 8) == 8) - else - { + break; + } // if ((dw_Status & 8) == 8) + else { /*******************************/ - /* Test if measurement stopped */ + /* Test if measurement stopped */ /*******************************/ - if ((dw_Status & 2) == 2) - { + if ((dw_Status & 2) == + 2) { /***********************/ - /* A stop signal occur */ + /* A stop signal occur */ /***********************/ - *pb_ChronoStatus = 2; + *pb_ChronoStatus + = 2; /***************************/ - /* Test if continnous mode */ + /* Test if continnous mode */ /***************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_CycleMode == APCI1710_CONTINUOUS) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_ChronoModuleInfo. + b_CycleMode + == + APCI1710_CONTINUOUS) + { /*************************/ - /* Clear status register */ + /* Clear status register */ /*************************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 36 + (64 * b_ModulNbr)); - } - break; - } // if ((dw_Status & 2) == 2) - else - { + outl(0, devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr)); + } + break; + } // if ((dw_Status & 2) == 2) + else { /*******************************/ - /* Test if measurement started */ + /* Test if measurement started */ /*******************************/ - if ((dw_Status & 1) == 1) - { + if ((dw_Status & 1) == 1) { /************************/ - /* A start signal occur */ + /* A start signal occur */ /************************/ - *pb_ChronoStatus = 1; - } // if ((dw_Status & 1) == 1) - else - { + *pb_ChronoStatus + = + 1; + } // if ((dw_Status & 1) == 1) + else { /***************************/ - /* Measurement not started */ + /* Measurement not started */ /***************************/ - *pb_ChronoStatus = 0; - } // if ((dw_Status & 1) == 1) - } // if ((dw_Status & 2) == 2) - } // if ((dw_Status & 8) == 8) + *pb_ChronoStatus + = + 0; + } // if ((dw_Status & 1) == 1) + } // if ((dw_Status & 2) == 2) + } // if ((dw_Status & 8) == 8) - if (dw_TimeOut == ui_TimeOut) - { + if (dw_TimeOut == ui_TimeOut) { /*****************/ - /* Timeout occur */ + /* Timeout occur */ /*****************/ - break; - } - else - { + break; + } else { /*************************/ - /* Increment the timeout */ + /* Increment the timeout */ /*************************/ - dw_TimeOut = dw_TimeOut + 1; - mdelay(1000); - - } - } // for (;;) + dw_TimeOut = + dw_TimeOut + 1; + mdelay(1000); + + } + } // for (;;) /*****************************/ - /* Test if stop signal occur */ + /* Test if stop signal occur */ /*****************************/ - if (*pb_ChronoStatus == 2) - { + if (*pb_ChronoStatus == 2) { /**********************************/ - /* Read the measured timing value */ + /* Read the measured timing value */ /**********************************/ - - *pul_ChronoValue= inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); - - if (*pul_ChronoValue != 0) - { - *pul_ChronoValue = *pul_ChronoValue - 1; - } - } - else - { + *pul_ChronoValue = + inl(devpriv-> + s_BoardInfos. + ui_Address + 4 + + (64 * b_ModulNbr)); + + if (*pul_ChronoValue != 0) { + *pul_ChronoValue = + *pul_ChronoValue + - 1; + } + } else { /*************************/ - /* Test if timeout occur */ + /* Test if timeout occur */ /*************************/ - if ((*pb_ChronoStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0)) - { + if ((*pb_ChronoStatus != 3) + && (dw_TimeOut == + ui_TimeOut) + && (ui_TimeOut != 0)) { /*****************/ - /* Timeout occur */ + /* Timeout occur */ /*****************/ - *pb_ChronoStatus = 4; - } - } - - } - else - { + *pb_ChronoStatus = 4; + } + } + + } else { /******************************/ - /* Timeout parameter is wrong */ + /* Timeout parameter is wrong */ /******************************/ - DPRINTK("Timeout parameter is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timeout parameter is wrong\n"); + i_ReturnValue = -5; + } + } else { /*******************************/ - /* Chronometer not initialised */ + /* Chronometer not initialised */ /*******************************/ - DPRINTK("Chronometer not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Chronometer not initialised\n"); + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -1452,154 +1619,141 @@ INT i_APCI1710_ReadChronoValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ConvertChronoValue (comedi_device *dev, - BYTE b_ModulNbr, - ULONG ul_ChronoValue, - PULONG pul_Hour, - PBYTE pb_Minute, - PBYTE pb_Second, - PUINT pui_MilliSecond, - PUINT pui_MicroSecond, - PUINT pui_NanoSecond) - { - INT i_ReturnValue = 0; +INT i_APCI1710_ConvertChronoValue(comedi_device * dev, + BYTE b_ModulNbr, + ULONG ul_ChronoValue, + PULONG pul_Hour, + PBYTE pb_Minute, + PBYTE pb_Second, + PUINT pui_MilliSecond, PUINT pui_MicroSecond, PUINT pui_NanoSecond) +{ + INT i_ReturnValue = 0; double d_Hour; double d_Minute; double d_Second; double d_MilliSecond; double d_MicroSecond; double d_NanoSecond; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /***********************************/ - /* Test if chronometer initialised */ + /* Test if chronometer initialised */ /***********************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit == 1) - { - fpu_begin (); - - d_Hour = (double) ul_ChronoValue * (double) devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - d_TimingInterval; + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_ChronoInit == 1) { + fpu_begin(); - switch (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_TimingUnit) - { - case 0: - d_Hour = d_Hour / (double) 1000.0; + d_Hour = (double)ul_ChronoValue *(double) + devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.d_TimingInterval; - case 1: - d_Hour = d_Hour / (double) 1000.0; + switch (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_TimingUnit) { + case 0: + d_Hour = d_Hour / (double)1000.0; - case 2: - d_Hour = d_Hour / (double) 1000.0; + case 1: + d_Hour = d_Hour / (double)1000.0; - case 3: - d_Hour = d_Hour / (double) 60.0; + case 2: + d_Hour = d_Hour / (double)1000.0; - case 4: + case 3: + d_Hour = d_Hour / (double)60.0; + + case 4: /**********************/ - /* Calculate the hour */ + /* Calculate the hour */ /**********************/ - d_Hour = d_Hour / (double) 60.0; - *pul_Hour = (ULONG) d_Hour; + d_Hour = d_Hour / (double)60.0; + *pul_Hour = (ULONG) d_Hour; /************************/ - /* Calculate the minute */ + /* Calculate the minute */ /************************/ - d_Minute = d_Hour - *pul_Hour; - d_Minute = d_Minute * 60; - *pb_Minute = (BYTE) d_Minute; + d_Minute = d_Hour - *pul_Hour; + d_Minute = d_Minute * 60; + *pb_Minute = (BYTE) d_Minute; /************************/ - /* Calculate the second */ + /* Calculate the second */ /************************/ - d_Second = d_Minute - *pb_Minute; - d_Second = d_Second * 60; - *pb_Second = (BYTE) d_Second; + d_Second = d_Minute - *pb_Minute; + d_Second = d_Second * 60; + *pb_Second = (BYTE) d_Second; /*****************************/ - /* Calculate the mini second */ + /* Calculate the mini second */ /*****************************/ - d_MilliSecond = d_Second - *pb_Second; - d_MilliSecond = d_MilliSecond * 1000; - *pui_MilliSecond = (UINT) d_MilliSecond; + d_MilliSecond = d_Second - *pb_Second; + d_MilliSecond = d_MilliSecond * 1000; + *pui_MilliSecond = (UINT) d_MilliSecond; /******************************/ - /* Calculate the micro second */ + /* Calculate the micro second */ /******************************/ - d_MicroSecond = d_MilliSecond - *pui_MilliSecond; - d_MicroSecond = d_MicroSecond * 1000; - *pui_MicroSecond = (UINT) d_MicroSecond; + d_MicroSecond = + d_MilliSecond - + *pui_MilliSecond; + d_MicroSecond = d_MicroSecond * 1000; + *pui_MicroSecond = (UINT) d_MicroSecond; /******************************/ - /* Calculate the micro second */ + /* Calculate the micro second */ /******************************/ - d_NanoSecond = d_MicroSecond - *pui_MicroSecond; - d_NanoSecond = d_NanoSecond * 1000; - *pui_NanoSecond = (UINT) d_NanoSecond; - break; - } - - fpu_end (); - } - else - { + d_NanoSecond = + d_MicroSecond - + *pui_MicroSecond; + d_NanoSecond = d_NanoSecond * 1000; + *pui_NanoSecond = (UINT) d_NanoSecond; + break; + } + + fpu_end(); + } else { /*******************************/ - /* Chronometer not initialised */ + /* Chronometer not initialised */ /*******************************/ - DPRINTK("Chronometer not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Chronometer not initialised\n"); + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1722,159 +1876,157 @@ INT i_APCI1710_ConvertChronoValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - BYTE b_ModulNbr,b_OutputChannel,b_InputChannel,b_IOType; +INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + BYTE b_ModulNbr, b_OutputChannel, b_InputChannel, b_IOType; DWORD dw_Status; PBYTE pb_ChannelStatus; PBYTE pb_PortValue; - - b_ModulNbr = CR_AREF(insn->chanspec); - i_ReturnValue = insn->n; - b_IOType = (BYTE) data[0]; - - + b_ModulNbr = CR_AREF(insn->chanspec); + i_ReturnValue = insn->n; + b_IOType = (BYTE) data[0]; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /***********************************/ - /* Test if chronometer initialised */ + /* Test if chronometer initialised */ /***********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_ChronoModuleInfo. - b_ChronoInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_ChronoModuleInfo.b_ChronoInit == 1) { /***********************************/ - /* Test the digital output channel */ + /* Test the digital output channel */ /***********************************/ - switch(b_IOType) - { - - case APCI1710_CHRONO_SET_CHANNELOFF: - - b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec); - if (b_OutputChannel <= 2) - { - - outl(0,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr)); - } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) - else - { + switch (b_IOType) { + + case APCI1710_CHRONO_SET_CHANNELOFF: + + b_OutputChannel = + (BYTE) CR_CHAN(insn->chanspec); + if (b_OutputChannel <= 2) { + + outl(0, devpriv->s_BoardInfos. + ui_Address + 20 + + (b_OutputChannel * 4) + + (64 * b_ModulNbr)); + } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) + else { /****************************************/ - /* The selected digital output is wrong */ + /* The selected digital output is wrong */ /****************************************/ - DPRINTK("The selected digital output is wrong\n"); - i_ReturnValue = -4; + DPRINTK("The selected digital output is wrong\n"); + i_ReturnValue = -4; + + } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) - } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) + break; - break; + case APCI1710_CHRONO_SET_CHANNELON: - case APCI1710_CHRONO_SET_CHANNELON: + b_OutputChannel = + (BYTE) CR_CHAN(insn->chanspec); + if (b_OutputChannel <= 2) { - b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec); - if (b_OutputChannel <= 2) - { - - outl(1,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr)); - } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) - else - { + outl(1, devpriv->s_BoardInfos. + ui_Address + 20 + + (b_OutputChannel * 4) + + (64 * b_ModulNbr)); + } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) + else { /****************************************/ - /* The selected digital output is wrong */ + /* The selected digital output is wrong */ /****************************************/ - DPRINTK("The selected digital output is wrong\n"); - i_ReturnValue = -4; + DPRINTK("The selected digital output is wrong\n"); + i_ReturnValue = -4; - } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) + } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2)) - break; - - case APCI1710_CHRONO_READ_CHANNEL : + break; + + case APCI1710_CHRONO_READ_CHANNEL: /**********************************/ - /* Test the digital input channel */ + /* Test the digital input channel */ /**********************************/ - pb_ChannelStatus = (PBYTE) &data[0]; - b_InputChannel = (BYTE) CR_CHAN(insn->chanspec); - - if (b_InputChannel <= 2) - { - - dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr)); - - *pb_ChannelStatus = (BYTE) (((dw_Status >> b_InputChannel) & 1) ^ 1); - } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2)) - else - { + pb_ChannelStatus = (PBYTE) & data[0]; + b_InputChannel = + (BYTE) CR_CHAN(insn->chanspec); + + if (b_InputChannel <= 2) { + + dw_Status = + inl(devpriv-> + s_BoardInfos. + ui_Address + 12 + + (64 * b_ModulNbr)); + + *pb_ChannelStatus = + (BYTE) (((dw_Status >> + b_InputChannel) + & 1) ^ 1); + } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2)) + else { /***************************************/ - /* The selected digital input is wrong */ + /* The selected digital input is wrong */ /***************************************/ - DPRINTK("The selected digital input is wrong\n"); - i_ReturnValue = -4; - } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2)) + DPRINTK("The selected digital input is wrong\n"); + i_ReturnValue = -4; + } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2)) - break; + break; - case APCI1710_CHRONO_READ_PORT : + case APCI1710_CHRONO_READ_PORT: - pb_PortValue = (PBYTE) &data[0]; + pb_PortValue = (PBYTE) & data[0]; - - dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr)); + dw_Status = + inl(devpriv->s_BoardInfos. + ui_Address + 12 + + (64 * b_ModulNbr)); - *pb_PortValue = (BYTE) ((dw_Status & 0x7) ^ 7); - break; - } - } - else - { + *pb_PortValue = + (BYTE) ((dw_Status & 0x7) ^ 7); + break; + } + } else { /*******************************/ - /* Chronometer not initialised */ + /* Chronometer not initialised */ /*******************************/ - DPRINTK("Chronometer not initialised\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Chronometer not initialised\n"); + i_ReturnValue = -5; + } + } else { /******************************************/ - /* The module is not a Chronometer module */ + /* The module is not a Chronometer module */ /******************************************/ - DPRINTK("The module is not a Chronometer module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a Chronometer module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); } - diff --git a/comedi/drivers/addi-data/APCI1710_Chrono.h b/comedi/drivers/addi-data/APCI1710_Chrono.h index 9ea05701..a12c0e73 100644 --- a/comedi/drivers/addi-data/APCI1710_Chrono.h +++ b/comedi/drivers/addi-data/APCI1710_Chrono.h @@ -22,17 +22,13 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - #define APCI1710_30MHZ 30 #define APCI1710_33MHZ 33 #define APCI1710_40MHZ 40 - #define APCI1710_SINGLE 0 #define APCI1710_CONTINUOUS 1 - #define APCI1710_CHRONO_PROGRESS_STATUS 0 #define APCI1710_CHRONO_READVALUE 1 #define APCI1710_CHRONO_CONVERTVALUE 2 @@ -49,12 +45,11 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnConfigInitChrono(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ @@ -62,33 +57,23 @@ INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); - - -INT i_APCI1710_GetChronoProgressStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_ChronoStatus); - -INT i_APCI1710_ReadChronoValue (comedi_device *dev, - BYTE b_ModulNbr, - UINT ui_TimeOut, - PBYTE pb_ChronoStatus, - PULONG pul_ChronoValue); - -INT i_APCI1710_ConvertChronoValue (comedi_device *dev, - BYTE b_ModulNbr, - ULONG ul_ChronoValue, - PULONG pul_Hour, - PBYTE pb_Minute, - PBYTE pb_Second, - PUINT pui_MilliSecond, - PUINT pui_MicroSecond, - PUINT pui_NanoSecond); - +INT i_APCI1710_InsnReadChrono(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_GetChronoProgressStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_ChronoStatus); +INT i_APCI1710_ReadChronoValue(comedi_device * dev, + BYTE b_ModulNbr, + UINT ui_TimeOut, PBYTE pb_ChronoStatus, PULONG pul_ChronoValue); +INT i_APCI1710_ConvertChronoValue(comedi_device * dev, + BYTE b_ModulNbr, + ULONG ul_ChronoValue, + PULONG pul_Hour, + PBYTE pb_Minute, + PBYTE pb_Second, + PUINT pui_MilliSecond, PUINT pui_MicroSecond, PUINT pui_NanoSecond); /* +----------------------------------------------------------------------------+ @@ -96,7 +81,5 @@ INT i_APCI1710_ConvertChronoValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - +INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_Dig_io.c b/comedi/drivers/addi-data/APCI1710_Dig_io.c index 141eb575..7ec64228 100644 --- a/comedi/drivers/addi-data/APCI1710_Dig_io.c +++ b/comedi/drivers/addi-data/APCI1710_Dig_io.c @@ -59,7 +59,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "APCI1710_Dig_io.h" - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev, | @@ -100,153 +99,143 @@ Activates and deactivates the digital output memory. +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - BYTE b_ModulNbr,b_ChannelAMode,b_ChannelBMode ; - BYTE b_MemoryOnOff,b_ConfigType; - INT i_ReturnValue = 0; - DWORD dw_WriteConfig = 0; - - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_ConfigType - = (BYTE) data[0];// Memory or Init - b_ChannelAMode = (BYTE) data[1]; - b_ChannelBMode = (BYTE) data[2]; - b_MemoryOnOff = (BYTE) data[1]; // if memory operation - i_ReturnValue = insn->n; +INT i_APCI1710_InsnConfigDigitalIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + BYTE b_ModulNbr, b_ChannelAMode, b_ChannelBMode; + BYTE b_MemoryOnOff, b_ConfigType; + INT i_ReturnValue = 0; + DWORD dw_WriteConfig = 0; + + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_ConfigType = (BYTE) data[0]; // Memory or Init + b_ChannelAMode = (BYTE) data[1]; + b_ChannelBMode = (BYTE) data[2]; + b_MemoryOnOff = (BYTE) data[1]; // if memory operation + i_ReturnValue = insn->n; - /**************************/ - /* Test the module number */ + /* Test the module number */ /**************************/ - if (b_ModulNbr >= 4) - { - DPRINTK("Module Number invalid\n"); - i_ReturnValue = -2; - return i_ReturnValue; - } - switch(b_ConfigType) - { - case APCI1710_DIGIO_MEMORYONOFF: + if (b_ModulNbr >= 4) { + DPRINTK("Module Number invalid\n"); + i_ReturnValue = -2; + return i_ReturnValue; + } + switch (b_ConfigType) { + case APCI1710_DIGIO_MEMORYONOFF: - if(b_MemoryOnOff) // If Memory ON + if (b_MemoryOnOff) // If Memory ON { /****************************/ - /* Set the output memory on */ + /* Set the output memory on */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_OutputMemoryEnabled = 1; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_OutputMemoryEnabled = 1; /***************************/ - /* Clear the output memory */ + /* Clear the output memory */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory = 0; - } - else // If memory off + devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.dw_OutputMemory = 0; + } else // If memory off { /*****************************/ - /* Set the output memory off */ + /* Set the output memory off */ /*****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_OutputMemoryEnabled = 0; - } - break; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_OutputMemoryEnabled = 0; + } + break; + + case APCI1710_DIGIO_INIT: - case APCI1710_DIGIO_INIT: - /*******************************/ - /* Test if digital I/O counter */ + /* Test if digital I/O counter */ /*******************************/ - if((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_DIGITAL_IO) { /***************************************************/ - /* Test the bi-directional channel A configuration */ + /* Test the bi-directional channel A configuration */ /***************************************************/ - - if ((b_ChannelAMode == 0) || (b_ChannelAMode == 1)) - { + + if ((b_ChannelAMode == 0) || (b_ChannelAMode == 1)) { /***************************************************/ - /* Test the bi-directional channel B configuration */ + /* Test the bi-directional channel B configuration */ /***************************************************/ - if ((b_ChannelBMode == 0) || (b_ChannelBMode == 1)) - { - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_DigitalInit = 1; + if ((b_ChannelBMode == 0) + || (b_ChannelBMode == 1)) { + devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_DigitalInit = + 1; /********************************/ - /* Save channel A configuration */ + /* Save channel A configuration */ /********************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. + devpriv->s_ModuleInfo[b_ModulNbr]. s_DigitalIOInfo. b_ChannelAMode = b_ChannelAMode; /********************************/ - /* Save channel B configuration */ + /* Save channel B configuration */ /********************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. + devpriv->s_ModuleInfo[b_ModulNbr]. s_DigitalIOInfo. b_ChannelBMode = b_ChannelBMode; /*****************************************/ - /* Set the channel A and B configuration */ + /* Set the channel A and B configuration */ /*****************************************/ - - dw_WriteConfig = (DWORD) (b_ChannelAMode | (b_ChannelBMode * 2)); + dw_WriteConfig = + (DWORD) (b_ChannelAMode | + (b_ChannelBMode * 2)); /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(dw_WriteConfig,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr)); + outl(dw_WriteConfig, + devpriv->s_BoardInfos. + ui_Address + 4 + + (64 * b_ModulNbr)); - } - else - { + } else { /************************************************/ - /* Bi-directional channel B configuration error */ - /************************************************/ - DPRINTK("Bi-directional channel B configuration error\n"); - i_ReturnValue = -5; - } + /* Bi-directional channel B configuration error */ + /************************************************/ + DPRINTK("Bi-directional channel B configuration error\n"); + i_ReturnValue = -5; + } - } - else - { + } else { /************************************************/ - /* Bi-directional channel A configuration error */ + /* Bi-directional channel A configuration error */ /************************************************/ - DPRINTK("Bi-directional channel A configuration error\n"); - i_ReturnValue = -4; - - } + DPRINTK("Bi-directional channel A configuration error\n"); + i_ReturnValue = -4; - } - else - { + } + + } else { /******************************************/ - /* The module is not a digital I/O module */ + /* The module is not a digital I/O module */ /******************************************/ - DPRINTK("The module is not a digital I/O module\n"); + DPRINTK("The module is not a digital I/O module\n"); i_ReturnValue = -3; - } - } // end of Switch - printk("Return Value %d\n",i_ReturnValue); - return i_ReturnValue; + } + } // end of Switch + printk("Return Value %d\n", i_ReturnValue); + return i_ReturnValue; } /* @@ -300,150 +289,153 @@ INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s, */ //_INT_ i_APCI1710_ReadDigitalIOChlValue (BYTE_ b_BoardHandle, -// BYTE_ b_ModulNbr, -// BYTE_ b_InputChannel, +// BYTE_ b_ModulNbr, +// BYTE_ b_InputChannel, // -// PBYTE_ pb_ChannelStatus) -INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +// PBYTE_ pb_ChannelStatus) +INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - INT i_ReturnValue = 0; + INT i_ReturnValue = 0; DWORD dw_StatusReg; - BYTE b_ModulNbr,b_InputChannel; - PBYTE pb_ChannelStatus; - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_InputChannel = (BYTE) CR_CHAN(insn->chanspec); - data[0]=0; - pb_ChannelStatus= (PBYTE) &data[0]; - i_ReturnValue = insn->n; - + BYTE b_ModulNbr, b_InputChannel; + PBYTE pb_ChannelStatus; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_InputChannel = (BYTE) CR_CHAN(insn->chanspec); + data[0] = 0; + pb_ChannelStatus = (PBYTE) & data[0]; + i_ReturnValue = insn->n; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if digital I/O counter */ + /* Test if digital I/O counter */ /*******************************/ - if ((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_DIGITAL_IO) { /******************************************/ - /* Test the digital imnput channel number */ + /* Test the digital imnput channel number */ /******************************************/ - if (b_InputChannel <= 6) - { + if (b_InputChannel <= 6) { /**********************************************/ - /* Test if the digital I/O module initialised */ + /* Test if the digital I/O module initialised */ /**********************************************/ - if (devpriv->s_ModuleInfo[b_ModulNbr].s_DigitalIOInfo.b_DigitalInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_DigitalInit == 1) { /**********************************/ - /* Test if channel A or channel B */ + /* Test if channel A or channel B */ /**********************************/ - if (b_InputChannel > 4) - { + if (b_InputChannel > 4) { /*********************/ - /* Test if channel A */ + /* Test if channel A */ /*********************/ - if (b_InputChannel == 5) - { + if (b_InputChannel == 5) { /***************************/ - /* Test the channel A mode */ + /* Test the channel A mode */ /***************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelAMode != 0) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelAMode + != 0) { /********************************************/ - /* The digital channel A is used for output */ + /* The digital channel A is used for output */ /********************************************/ - i_ReturnValue = -6; - } - } // if (b_InputChannel == 5) - else - { + i_ReturnValue = + -6; + } + } // if (b_InputChannel == 5) + else { /***************************/ - /* Test the channel B mode */ + /* Test the channel B mode */ /***************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelBMode != 0) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelBMode + != 0) { /********************************************/ - /* The digital channel B is used for output */ + /* The digital channel B is used for output */ /********************************************/ - i_ReturnValue = -7; - } - } // if (b_InputChannel == 5) - } // if (b_InputChannel > 4) + i_ReturnValue = + -7; + } + } // if (b_InputChannel == 5) + } // if (b_InputChannel > 4) /***********************/ - /* Test if error occur */ + /* Test if error occur */ /***********************/ - if (i_ReturnValue >= 0) - { + if (i_ReturnValue >= 0) { /**************************/ - /* Read all digital input */ + /* Read all digital input */ /**************************/ - //INPDW (ps_APCI1710Variable-> - // s_Board [b_BoardHandle]. - // s_BoardInfos. - // ui_Address + (64 * b_ModulNbr), - // &dw_StatusReg); - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - - *pb_ChannelStatus = (BYTE) ((dw_StatusReg ^ 0x1C) >> b_InputChannel) & 1; - - } // if (i_ReturnValue == 0) - } - else - { + //INPDW (ps_APCI1710Variable-> + // s_Board [b_BoardHandle]. + // s_BoardInfos. + // ui_Address + (64 * b_ModulNbr), + // &dw_StatusReg); + + dw_StatusReg = + inl(devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + + *pb_ChannelStatus = + (BYTE) ((dw_StatusReg ^ + 0x1C) >> + b_InputChannel) & 1; + + } // if (i_ReturnValue == 0) + } else { /*******************************/ - /* Digital I/O not initialised */ + /* Digital I/O not initialised */ /*******************************/ - DPRINTK("Digital I/O not initialised\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Digital I/O not initialised\n"); + i_ReturnValue = -5; + } + } else { /********************************/ - /* Selected digital input error */ + /* Selected digital input error */ /********************************/ - DPRINTK("Selected digital input error\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Selected digital input error\n"); + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a digital I/O module */ + /* The module is not a digital I/O module */ /******************************************/ - DPRINTK("The module is not a digital I/O module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a digital I/O module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -451,8 +443,6 @@ INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ - - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device @@ -489,196 +479,199 @@ INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s, */ //_INT_ i_APCI1710_SetDigitalIOChlOn (BYTE_ b_BoardHandle, -// BYTE_ b_ModulNbr, -// BYTE_ b_OutputChannel) -INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_WriteValue = 0; - BYTE b_ModulNbr,b_OutputChannel; - i_ReturnValue = insn->n; - b_ModulNbr = CR_AREF(insn->chanspec); - b_OutputChannel = CR_CHAN(insn->chanspec); - - +// BYTE_ b_ModulNbr, +// BYTE_ b_OutputChannel) +INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_WriteValue = 0; + BYTE b_ModulNbr, b_OutputChannel; + i_ReturnValue = insn->n; + b_ModulNbr = CR_AREF(insn->chanspec); + b_OutputChannel = CR_CHAN(insn->chanspec); /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if digital I/O counter */ + /* Test if digital I/O counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_DIGITAL_IO) { /**********************************************/ - /* Test if the digital I/O module initialised */ + /* Test if the digital I/O module initialised */ /**********************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_DigitalInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_DigitalInit == 1) { /******************************************/ - /* Test the digital output channel number */ + /* Test the digital output channel number */ /******************************************/ - switch (b_OutputChannel) - { + switch (b_OutputChannel) { /*************/ - /* Channel H */ + /* Channel H */ /*************/ - case 0: - break; + case 0: + break; /*************/ - /* Channel A */ + /* Channel A */ /*************/ - case 1: - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_ChannelAMode != 1) - { + case 1: + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelAMode != 1) { /*******************************************/ - /* The digital channel A is used for input */ + /* The digital channel A is used for input */ /*******************************************/ - i_ReturnValue = -6; - } - break; + i_ReturnValue = -6; + } + break; /*************/ - /* Channel B */ + /* Channel B */ /*************/ - case 2: - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_ChannelBMode != 1) - { + case 2: + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelBMode != 1) { /*******************************************/ - /* The digital channel B is used for input */ + /* The digital channel B is used for input */ /*******************************************/ - i_ReturnValue = -7; - } - break; + i_ReturnValue = -7; + } + break; - default : + default: /****************************************/ - /* The selected digital output is wrong */ + /* The selected digital output is wrong */ /****************************************/ - i_ReturnValue = -4; - break; - } + i_ReturnValue = -4; + break; + } /***********************/ - /* Test if error occur */ + /* Test if error occur */ /***********************/ - if (i_ReturnValue >= 0) - { - - + if (i_ReturnValue >= 0) { + /*********************************/ - /* Test if set channel ON */ - /*********************************/ - if(data[0]) - { + /* Test if set channel ON */ /*********************************/ - /* Test if output memory enabled */ + if (data[0]) { + /*********************************/ + /* Test if output memory enabled */ /*********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_OutputMemoryEnabled == 1) - { - dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory | (1 << b_OutputChannel); - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory = dw_WriteValue; - } - else - { - dw_WriteValue = 1 << b_OutputChannel; - } - } // set channel off - else - { - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_OutputMemoryEnabled == 1) - { - dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory & (0xFFFFFFFFUL - (1 << b_OutputChannel)); - - devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue; - } - else - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_OutputMemoryEnabled == + 1) { + dw_WriteValue = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + | (1 << + b_OutputChannel); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + = dw_WriteValue; + } else { + dw_WriteValue = + 1 << + b_OutputChannel; + } + } // set channel off + else { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_OutputMemoryEnabled == + 1) { + dw_WriteValue = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + & (0xFFFFFFFFUL + - + (1 << b_OutputChannel)); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + = dw_WriteValue; + } else { /*****************************/ - /* Digital Output Memory OFF */ + /* Digital Output Memory OFF */ /*****************************/ - // +Use previously the function "i_APCI1710_SetDigitalIOMemoryOn" - i_ReturnValue = -8; - } + // +Use previously the function "i_APCI1710_SetDigitalIOMemoryOn" + i_ReturnValue = -8; + } - } + } /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - //OUTPDW (ps_APCI1710Variable-> - // s_Board [b_BoardHandle]. - // s_BoardInfos. - // ui_Address + (64 * b_ModulNbr), - // dw_WriteValue); - outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - } - } - else - { + //OUTPDW (ps_APCI1710Variable-> + // s_Board [b_BoardHandle]. + // s_BoardInfos. + // ui_Address + (64 * b_ModulNbr), + // dw_WriteValue); + outl(dw_WriteValue, + devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); + } + } else { /*******************************/ - /* Digital I/O not initialised */ + /* Digital I/O not initialised */ /*******************************/ - i_ReturnValue = -5; - } - } - else - { + i_ReturnValue = -5; + } + } else { /******************************************/ - /* The module is not a digital I/O module */ + /* The module is not a digital I/O module */ /******************************************/ - i_ReturnValue = -3; - } - } - else - { + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - i_ReturnValue = -2; - } - - return (i_ReturnValue); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -733,284 +726,295 @@ INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s */ //_INT_ i_APCI1710_SetDigitalIOPortOn (BYTE_ b_BoardHandle, -// BYTE_ b_ModulNbr, -// BYTE_ b_PortValue) -INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +// BYTE_ b_ModulNbr, +// BYTE_ b_PortValue) +INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_WriteValue = 0; DWORD dw_StatusReg; - BYTE b_ModulNbr,b_PortValue; - BYTE b_PortOperation,b_PortOnOFF; - - PBYTE pb_PortValue; - - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_PortOperation = (BYTE) data[0];// Input or output - b_PortOnOFF = (BYTE) data[1];// if output then On or Off - b_PortValue = (BYTE) data[2];// if out put then Value - i_ReturnValue = insn->n; - pb_PortValue = (PBYTE) &data[0]; -// if input then read value - + BYTE b_ModulNbr, b_PortValue; + BYTE b_PortOperation, b_PortOnOFF; + + PBYTE pb_PortValue; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_PortOperation = (BYTE) data[0]; // Input or output + b_PortOnOFF = (BYTE) data[1]; // if output then On or Off + b_PortValue = (BYTE) data[2]; // if out put then Value + i_ReturnValue = insn->n; + pb_PortValue = (PBYTE) & data[0]; +// if input then read value - switch(b_PortOperation) - { - case APCI1710_INPUT : + switch (b_PortOperation) { + case APCI1710_INPUT: /**************************/ - /* Test the module number */ + /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if digital I/O counter */ + /* Test if digital I/O counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_DIGITAL_IO) { /**********************************************/ - /* Test if the digital I/O module initialised */ + /* Test if the digital I/O module initialised */ /**********************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo.b_DigitalInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_DigitalInit == 1) { /**************************/ - /* Read all digital input */ + /* Read all digital input */ /**************************/ - //INPDW (ps_APCI1710Variable-> - // s_Board [b_BoardHandle]. - // s_BoardInfos. - // ui_Address + (64 * b_ModulNbr), - // &dw_StatusReg); - - dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - *pb_PortValue = (BYTE) (dw_StatusReg ^ 0x1C); - - } - else - { + //INPDW (ps_APCI1710Variable-> + // s_Board [b_BoardHandle]. + // s_BoardInfos. + // ui_Address + (64 * b_ModulNbr), + // &dw_StatusReg); + + dw_StatusReg = + inl(devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); + *pb_PortValue = + (BYTE) (dw_StatusReg ^ 0x1C); + + } else { /*******************************/ - /* Digital I/O not initialised */ + /* Digital I/O not initialised */ /*******************************/ - i_ReturnValue = -4; - } - } - else - { + i_ReturnValue = -4; + } + } else { /******************************************/ - /* The module is not a digital I/O module */ + /* The module is not a digital I/O module */ /******************************************/ - i_ReturnValue = -3; - } - } - else - { + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - i_ReturnValue = -2; - } - - break; + i_ReturnValue = -2; + } + + break; - case APCI1710_OUTPUT : + case APCI1710_OUTPUT: /**************************/ - /* Test the module number */ + /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if digital I/O counter */ + /* Test if digital I/O counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_DIGITAL_IO) { /**********************************************/ - /* Test if the digital I/O module initialised */ + /* Test if the digital I/O module initialised */ /**********************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_DigitalInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_DigitalIOInfo.b_DigitalInit == 1) { /***********************/ - /* Test the port value */ + /* Test the port value */ /***********************/ - if (b_PortValue <= 7) - { + if (b_PortValue <= 7) { /***********************************/ - /* Test the digital output channel */ + /* Test the digital output channel */ /***********************************/ /**************************/ - /* Test if channel A used */ + /* Test if channel A used */ /**************************/ - if ((b_PortValue & 2) == 2) - { - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_ChannelAMode != 1) - { + if ((b_PortValue & 2) == 2) { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelAMode + != 1) { /*******************************************/ - /* The digital channel A is used for input */ + /* The digital channel A is used for input */ /*******************************************/ - i_ReturnValue = -6; - } - } // if ((b_PortValue & 2) == 2) + i_ReturnValue = + -6; + } + } // if ((b_PortValue & 2) == 2) /**************************/ - /* Test if channel B used */ + /* Test if channel B used */ /**************************/ - if ((b_PortValue & 4) == 4) - { - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_ChannelBMode != 1) - { + if ((b_PortValue & 4) == 4) { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_ChannelBMode + != 1) { /*******************************************/ - /* The digital channel B is used for input */ + /* The digital channel B is used for input */ /*******************************************/ - i_ReturnValue = -7; - } - } // if ((b_PortValue & 4) == 4) + i_ReturnValue = + -7; + } + } // if ((b_PortValue & 4) == 4) /***********************/ - /* Test if error occur */ + /* Test if error occur */ /***********************/ - if (i_ReturnValue >= 0) - { - - //if(data[1]) - //{ - switch(b_PortOnOFF) - { + if (i_ReturnValue >= 0) { + + //if(data[1]) + //{ + switch (b_PortOnOFF) { /*********************************/ - /* Test if set Port ON */ + /* Test if set Port ON */ /*********************************/ - case APCI1710_ON : + case APCI1710_ON: /*********************************/ - /* Test if output memory enabled */ + /* Test if output memory enabled */ /*********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - b_OutputMemoryEnabled == 1) - { - dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory | b_PortValue; - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue; - } - else - { - dw_WriteValue = b_PortValue; - } - break; - - // If Set PORT OFF - case APCI1710_OFF: - + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_OutputMemoryEnabled + == 1) { + dw_WriteValue + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + | + b_PortValue; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + = + dw_WriteValue; + } else { + dw_WriteValue + = + b_PortValue; + } + break; + + // If Set PORT OFF + case APCI1710_OFF: + /*********************************/ - /* Test if output memory enabled */ + /* Test if output memory enabled */ /*********************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo.b_OutputMemoryEnabled == 1) - { - dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory & (0xFFFFFFFFUL - b_PortValue); - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_DigitalIOInfo. - dw_OutputMemory = dw_WriteValue; - } - else - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + b_OutputMemoryEnabled + == 1) { + dw_WriteValue + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + & + (0xFFFFFFFFUL + - + b_PortValue); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_DigitalIOInfo. + dw_OutputMemory + = + dw_WriteValue; + } else { /*****************************/ - /* Digital Output Memory OFF */ + /* Digital Output Memory OFF */ /*****************************/ - i_ReturnValue = -8; - } - } // switch + i_ReturnValue + = + -8; + } + } // switch /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - // OUTPDW (ps_APCI1710Variable-> - // s_Board [b_BoardHandle]. - // s_BoardInfos. - // ui_Address + (64 * b_ModulNbr), - // dw_WriteValue); - outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - } - } - else - { + // OUTPDW (ps_APCI1710Variable-> + // s_Board [b_BoardHandle]. + // s_BoardInfos. + // ui_Address + (64 * b_ModulNbr), + // dw_WriteValue); + outl(dw_WriteValue, + devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + } + } else { /**********************/ - /* Output value wrong */ + /* Output value wrong */ /**********************/ - i_ReturnValue = -4; - } - } - else - { + i_ReturnValue = -4; + } + } else { /*******************************/ - /* Digital I/O not initialised */ + /* Digital I/O not initialised */ /*******************************/ - i_ReturnValue = -5; - } - } - else - { + i_ReturnValue = -5; + } + } else { /******************************************/ - /* The module is not a digital I/O module */ + /* The module is not a digital I/O module */ /******************************************/ - i_ReturnValue = -3; - } - } - else - { + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - i_ReturnValue = -2; - } - break; + i_ReturnValue = -2; + } + break; default: i_ReturnValue = -9; DPRINTK("NO INPUT/OUTPUT specified\n"); - } //switch INPUT / OUTPUT + } //switch INPUT / OUTPUT return (i_ReturnValue); } - - - diff --git a/comedi/drivers/addi-data/APCI1710_Dig_io.h b/comedi/drivers/addi-data/APCI1710_Dig_io.h index 9aed5739..828a2488 100644 --- a/comedi/drivers/addi-data/APCI1710_Dig_io.h +++ b/comedi/drivers/addi-data/APCI1710_Dig_io.h @@ -22,39 +22,34 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - -#define APCI1710_ON 1 // Digital Output ON or OFF +#define APCI1710_ON 1 // Digital Output ON or OFF #define APCI1710_OFF 0 - -#define APCI1710_INPUT 0 // Digital I/O +#define APCI1710_INPUT 0 // Digital I/O #define APCI1710_OUTPUT 1 -#define APCI1710_DIGIO_MEMORYONOFF 0x10 // +#define APCI1710_DIGIO_MEMORYONOFF 0x10 // #define APCI1710_DIGIO_INIT 0x11 - /* +----------------------------------------------------------------------------+ | DIGITAL I/O INISIALISATION FUNCTION | +----------------------------------------------------------------------------+ */ - - INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnConfigDigitalIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | INPUT OUTPUT FUNCTIONS | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_INCCPT.c b/comedi/drivers/addi-data/APCI1710_INCCPT.c index 9136f51e..1a4b5dac 100644 --- a/comedi/drivers/addi-data/APCI1710_INCCPT.c +++ b/comedi/drivers/addi-data/APCI1710_INCCPT.c @@ -57,7 +57,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - #include "APCI1710_INCCPT.h" /* @@ -76,81 +75,70 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnConfigINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_ConfigType; + INT i_ReturnValue = 0; + ui_ConfigType = CR_CHAN(insn->chanspec); + + printk("\nINC_CPT"); + + devpriv->tsk_Current = current; // Save the current process task structure + switch (ui_ConfigType) { + case APCI1710_INCCPT_INITCOUNTER: + i_ReturnValue = i_APCI1710_InitCounter(dev, + CR_AREF(insn->chanspec), + (BYTE) data[0], + (BYTE) data[1], + (BYTE) data[2], (BYTE) data[3], (BYTE) data[4]); + break; + + case APCI1710_INCCPT_COUNTERAUTOTEST: + i_ReturnValue = i_APCI1710_CounterAutoTest(dev, + (PBYTE) & data[0]); + break; -INT i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) -{ - UINT ui_ConfigType; - INT i_ReturnValue = 0; - ui_ConfigType=CR_CHAN(insn->chanspec); - - printk ("\nINC_CPT"); - - devpriv->tsk_Current=current; // Save the current process task structure - switch(ui_ConfigType) - { - case APCI1710_INCCPT_INITCOUNTER : - i_ReturnValue =i_APCI1710_InitCounter (dev, - CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1], - (BYTE) data[2], - (BYTE) data[3], - (BYTE) data[4]); - break; - - case APCI1710_INCCPT_COUNTERAUTOTEST: - i_ReturnValue =i_APCI1710_CounterAutoTest (dev, - (PBYTE) &data[0]); - break; - - case APCI1710_INCCPT_INITINDEX: - i_ReturnValue =i_APCI1710_InitIndex (dev, - CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1], - (BYTE) data[2], - (BYTE) data[3]); - break; - - case APCI1710_INCCPT_INITREFERENCE: - i_ReturnValue =i_APCI1710_InitReference (dev, - CR_AREF(insn->chanspec), - (BYTE) data[0]); - break; - - case APCI1710_INCCPT_INITEXTERNALSTROBE: - i_ReturnValue =i_APCI1710_InitExternalStrobe (dev, - CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1]); - break; - - case APCI1710_INCCPT_INITCOMPARELOGIC: - i_ReturnValue =i_APCI1710_InitCompareLogic (dev, - CR_AREF(insn->chanspec), - (UINT) data[0]); - break; - - case APCI1710_INCCPT_INITFREQUENCYMEASUREMENT: - i_ReturnValue =i_APCI1710_InitFrequencyMeasurement (dev, - CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1], - (ULONG) data[2], - (PULONG) &data[0]); - break; - - default: - printk("Insn Config : Config Parameter Wrong\n"); + case APCI1710_INCCPT_INITINDEX: + i_ReturnValue = i_APCI1710_InitIndex(dev, + CR_AREF(insn->chanspec), + (BYTE) data[0], + (BYTE) data[1], (BYTE) data[2], (BYTE) data[3]); + break; + + case APCI1710_INCCPT_INITREFERENCE: + i_ReturnValue = i_APCI1710_InitReference(dev, + CR_AREF(insn->chanspec), (BYTE) data[0]); + break; + + case APCI1710_INCCPT_INITEXTERNALSTROBE: + i_ReturnValue = i_APCI1710_InitExternalStrobe(dev, + CR_AREF(insn->chanspec), + (BYTE) data[0], (BYTE) data[1]); + break; + + case APCI1710_INCCPT_INITCOMPARELOGIC: + i_ReturnValue = i_APCI1710_InitCompareLogic(dev, + CR_AREF(insn->chanspec), (UINT) data[0]); + break; + + case APCI1710_INCCPT_INITFREQUENCYMEASUREMENT: + i_ReturnValue = i_APCI1710_InitFrequencyMeasurement(dev, + CR_AREF(insn->chanspec), + (BYTE) data[0], + (BYTE) data[1], (ULONG) data[2], (PULONG) & data[0]); + break; + + default: + printk("Insn Config : Config Parameter Wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_InitCounter | @@ -311,221 +299,211 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InitCounter(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_CounterRange, + BYTE b_FirstCounterModus, + BYTE b_FirstCounterOption, + BYTE b_SecondCounterModus, BYTE b_SecondCounterOption) +{ + INT i_ReturnValue = 0; - - - -INT i_APCI1710_InitCounter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_CounterRange, - BYTE b_FirstCounterModus, - BYTE b_FirstCounterOption, - BYTE b_SecondCounterModus, - BYTE b_SecondCounterOption) - { - INT i_ReturnValue = 0; - /*******************************/ /* Test if incremental counter */ /*******************************/ if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER) { /**************************/ - /* Test the counter range */ + /* Test the counter range */ /**************************/ - if (b_CounterRange == APCI1710_16BIT_COUNTER || b_CounterRange == APCI1710_32BIT_COUNTER) - { + if (b_CounterRange == APCI1710_16BIT_COUNTER + || b_CounterRange == APCI1710_32BIT_COUNTER) { /********************************/ - /* Test the first counter modus */ + /* Test the first counter modus */ /********************************/ - if (b_FirstCounterModus == APCI1710_QUADRUPLE_MODE || - b_FirstCounterModus == APCI1710_DOUBLE_MODE || - b_FirstCounterModus == APCI1710_SIMPLE_MODE || - b_FirstCounterModus == APCI1710_DIRECT_MODE) - { + if (b_FirstCounterModus == APCI1710_QUADRUPLE_MODE || + b_FirstCounterModus == APCI1710_DOUBLE_MODE || + b_FirstCounterModus == APCI1710_SIMPLE_MODE || + b_FirstCounterModus == APCI1710_DIRECT_MODE) { /*********************************/ - /* Test the first counter option */ + /* Test the first counter option */ /*********************************/ - if ((b_FirstCounterModus == APCI1710_DIRECT_MODE && - (b_FirstCounterOption == APCI1710_INCREMENT || - b_FirstCounterOption == APCI1710_DECREMENT)) || - (b_FirstCounterModus != APCI1710_DIRECT_MODE && - (b_FirstCounterOption == APCI1710_HYSTERESIS_ON || - b_FirstCounterOption == APCI1710_HYSTERESIS_OFF))) - { + if ((b_FirstCounterModus == APCI1710_DIRECT_MODE + && (b_FirstCounterOption == + APCI1710_INCREMENT + || b_FirstCounterOption + == APCI1710_DECREMENT)) + || (b_FirstCounterModus != + APCI1710_DIRECT_MODE + && (b_FirstCounterOption == + APCI1710_HYSTERESIS_ON + || b_FirstCounterOption + == + APCI1710_HYSTERESIS_OFF))) + { /**************************/ - /* Test if 16-bit counter */ + /* Test if 16-bit counter */ /**************************/ - if (b_CounterRange == APCI1710_16BIT_COUNTER) - { + if (b_CounterRange == + APCI1710_16BIT_COUNTER) { /*********************************/ - /* Test the second counter modus */ + /* Test the second counter modus */ /*********************************/ - if ((b_FirstCounterModus != APCI1710_DIRECT_MODE && - (b_SecondCounterModus == APCI1710_QUADRUPLE_MODE || - b_SecondCounterModus == APCI1710_DOUBLE_MODE || - b_SecondCounterModus == APCI1710_SIMPLE_MODE)) || - (b_FirstCounterModus == APCI1710_DIRECT_MODE && - b_SecondCounterModus == APCI1710_DIRECT_MODE)) - { + if ((b_FirstCounterModus != + APCI1710_DIRECT_MODE + && + (b_SecondCounterModus + == + APCI1710_QUADRUPLE_MODE + || + b_SecondCounterModus + == + APCI1710_DOUBLE_MODE + || + b_SecondCounterModus + == + APCI1710_SIMPLE_MODE)) + || (b_FirstCounterModus + == + APCI1710_DIRECT_MODE + && + b_SecondCounterModus + == + APCI1710_DIRECT_MODE)) + { /**********************************/ - /* Test the second counter option */ + /* Test the second counter option */ /**********************************/ - if ((b_SecondCounterModus == APCI1710_DIRECT_MODE && - (b_SecondCounterOption == APCI1710_INCREMENT || - b_SecondCounterOption == APCI1710_DECREMENT)) || - (b_SecondCounterModus != APCI1710_DIRECT_MODE && - (b_SecondCounterOption == APCI1710_HYSTERESIS_ON || - b_SecondCounterOption == APCI1710_HYSTERESIS_OFF))) - { - i_ReturnValue = 0; - } - else - { + if ((b_SecondCounterModus == APCI1710_DIRECT_MODE && (b_SecondCounterOption == APCI1710_INCREMENT || b_SecondCounterOption == APCI1710_DECREMENT)) || (b_SecondCounterModus != APCI1710_DIRECT_MODE && (b_SecondCounterOption == APCI1710_HYSTERESIS_ON || b_SecondCounterOption == APCI1710_HYSTERESIS_OFF))) { + i_ReturnValue = + 0; + } else { /*********************************************************/ - /* The selected second counter operating option is wrong */ + /* The selected second counter operating option is wrong */ /*********************************************************/ - DPRINTK("The selected second counter operating option is wrong\n"); - i_ReturnValue = -7; - } - } - else - { + DPRINTK("The selected second counter operating option is wrong\n"); + i_ReturnValue = + -7; + } + } else { /*******************************************************/ - /* The selected second counter operating mode is wrong */ + /* The selected second counter operating mode is wrong */ /*******************************************************/ - DPRINTK("The selected second counter operating mode is wrong\n"); - i_ReturnValue = -6; - } - } - } - else - { + DPRINTK("The selected second counter operating mode is wrong\n"); + i_ReturnValue = -6; + } + } + } else { /********************************************************/ - /* The selected first counter operating option is wrong */ + /* The selected first counter operating option is wrong */ /********************************************************/ - DPRINTK("The selected first counter operating option is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("The selected first counter operating option is wrong\n"); + i_ReturnValue = -5; + } + } else { /******************************************************/ - /* The selected first counter operating mode is wrong */ + /* The selected first counter operating mode is wrong */ /******************************************************/ - DPRINTK("The selected first counter operating mode is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected first counter operating mode is wrong\n"); + i_ReturnValue = -4; + } + } else { /***************************************/ - /* The selected counter range is wrong */ + /* The selected counter range is wrong */ /***************************************/ - DPRINTK("The selected counter range is wrong\n"); - i_ReturnValue = -3; - } + DPRINTK("The selected counter range is wrong\n"); + i_ReturnValue = -3; + } /*************************/ - /* Test if a error occur */ + /* Test if a error occur */ /*************************/ - if (i_ReturnValue == 0) - { + if (i_ReturnValue == 0) { /**************************/ - /* Test if 16-Bit counter */ + /* Test if 16-Bit counter */ /**************************/ - if (b_CounterRange == APCI1710_32BIT_COUNTER) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 = b_CounterRange | - b_FirstCounterModus | - b_FirstCounterOption; - } - else - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 = b_CounterRange | - (b_FirstCounterModus & 0x5) | - (b_FirstCounterOption & 0x20) | - (b_SecondCounterModus & 0xA) | - (b_SecondCounterOption & 0x40); + if (b_CounterRange == APCI1710_32BIT_COUNTER) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 = b_CounterRange | + b_FirstCounterModus | + b_FirstCounterOption; + } else { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 = b_CounterRange | + (b_FirstCounterModus & 0x5) | + (b_FirstCounterOption & 0x20) | + (b_SecondCounterModus & 0xA) | + (b_SecondCounterOption & 0x40); /***********************/ - /* Test if direct mode */ + /* Test if direct mode */ /***********************/ - if (b_FirstCounterModus == APCI1710_DIRECT_MODE) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 | APCI1710_DIRECT_MODE; - } - } + if (b_FirstCounterModus == APCI1710_DIRECT_MODE) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 | + APCI1710_DIRECT_MODE; + } + } /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4, - devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit = 1; - } - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos. + ui_Address + 20 + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_CounterInit = 1; + } + } else { /**************************************/ - /* The module is not a counter module */ + /* The module is not a counter module */ /**************************************/ - DPRINTK("The module is not a counter module\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The module is not a counter module\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -567,96 +545,90 @@ INT i_APCI1710_InitCounter (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_CounterAutoTest (comedi_device *dev,PBYTE pb_TestStatus) - { - BYTE b_ModulCpt = 0; - INT i_ReturnValue = 0; +INT i_APCI1710_CounterAutoTest(comedi_device * dev, PBYTE pb_TestStatus) +{ + BYTE b_ModulCpt = 0; + INT i_ReturnValue = 0; DWORD dw_LathchValue; - - + *pb_TestStatus = 0; /********************************/ /* Test if counter module found */ /********************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER || - (devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER || - (devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER|| - (devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { - for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[0] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[1] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[2] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[3] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER) { + for (b_ModulCpt = 0; b_ModulCpt < 4; b_ModulCpt++) { /*******************************/ - /* Test if incremental counter */ + /* Test if incremental counter */ /*******************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulCpt] & + 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER) { /******************/ - /* Start the test */ + /* Start the test */ /******************/ - - outl(3,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulCpt)); + outl(3, devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModulCpt)); /*********************/ - /* Tatch the counter */ + /* Tatch the counter */ /*********************/ - - outl(1,devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulCpt)); + outl(1, devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulCpt)); /************************/ - /* Read the latch value */ + /* Read the latch value */ /************************/ - - dw_LathchValue=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulCpt)); - - if ((dw_LathchValue & 0xFF) != ((dw_LathchValue >> 8) & 0xFF) && - (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 16) & 0xFF) && - (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 24) & 0xFF)) - { - *pb_TestStatus = *pb_TestStatus | (1 << b_ModulCpt); - } + dw_LathchValue = inl(devpriv->s_BoardInfos. + ui_Address + 4 + (64 * b_ModulCpt)); + + if ((dw_LathchValue & 0xFF) != + ((dw_LathchValue >> 8) & 0xFF) + && (dw_LathchValue & 0xFF) != + ((dw_LathchValue >> 16) & 0xFF) + && (dw_LathchValue & 0xFF) != + ((dw_LathchValue >> 24) & 0xFF)) { + *pb_TestStatus = + *pb_TestStatus | (1 << + b_ModulCpt); + } /*****************/ - /* Stop the test */ + /* Stop the test */ /*****************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulCpt)); - } - } - } - else - { + outl(0, devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModulCpt)); + } + } + } else { /***************************/ - /* No counter module found */ + /* No counter module found */ /***************************/ - DPRINTK("No counter module found\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("No counter module found\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -736,355 +708,413 @@ INT i_APCI1710_CounterAutoTest (comedi_device *dev,PBYTE pb_TestStatus) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InitIndex (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ReferenceAction, - BYTE b_IndexOperation, - BYTE b_AutoMode, - BYTE b_InterruptEnable) - { - INT i_ReturnValue = 0; - +INT i_APCI1710_InitIndex(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_ReferenceAction, + BYTE b_IndexOperation, BYTE b_AutoMode, BYTE b_InterruptEnable) +{ + INT i_ReturnValue = 0; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /********************************/ - /* Test the reference parameter */ + /* Test the reference parameter */ /********************************/ - if (b_ReferenceAction == APCI1710_ENABLE || - b_ReferenceAction == APCI1710_DISABLE) - { + if (b_ReferenceAction == APCI1710_ENABLE || + b_ReferenceAction == APCI1710_DISABLE) { /****************************/ - /* Test the index parameter */ + /* Test the index parameter */ /****************************/ - if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER || - b_IndexOperation == APCI1710_HIGH_EDGE_CLEAR_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER || - b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) - { + if (b_IndexOperation == + APCI1710_HIGH_EDGE_LATCH_COUNTER + || b_IndexOperation == + APCI1710_LOW_EDGE_LATCH_COUNTER + || b_IndexOperation == + APCI1710_HIGH_EDGE_CLEAR_COUNTER + || b_IndexOperation == + APCI1710_LOW_EDGE_CLEAR_COUNTER + || b_IndexOperation == + APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER + || b_IndexOperation == + APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) + { /********************************/ - /* Test the auto mode parameter */ + /* Test the auto mode parameter */ /********************************/ - if (b_AutoMode == APCI1710_ENABLE || - b_AutoMode == APCI1710_DISABLE) - { + if (b_AutoMode == APCI1710_ENABLE || + b_AutoMode == APCI1710_DISABLE) + { /***************************/ - /* Test the interrupt mode */ + /* Test the interrupt mode */ /***************************/ - if (b_InterruptEnable == APCI1710_ENABLE || - b_InterruptEnable == APCI1710_DISABLE) - { - + if (b_InterruptEnable == + APCI1710_ENABLE + || b_InterruptEnable == + APCI1710_DISABLE) { + /************************************/ - /* Makte the configuration commando */ + /* Makte the configuration commando */ /************************************/ - if (b_ReferenceAction == APCI1710_ENABLE) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_ENABLE_INDEX_ACTION; - } - else - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & APCI1710_DISABLE_INDEX_ACTION; - } + if (b_ReferenceAction == + APCI1710_ENABLE) + { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + | + APCI1710_ENABLE_INDEX_ACTION; + } else { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + & + APCI1710_DISABLE_INDEX_ACTION; + } /****************************************/ - /* Test if low level latch or/and clear */ + /* Test if low level latch or/and clear */ /****************************************/ - if (b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) - { + if (b_IndexOperation == + APCI1710_LOW_EDGE_LATCH_COUNTER + || + b_IndexOperation + == + APCI1710_LOW_EDGE_CLEAR_COUNTER + || + b_IndexOperation + == + APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) + { /*************************************/ - /* Set the index level to low (DQ26) */ + /* Set the index level to low (DQ26) */ /*************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 | APCI1710_SET_LOW_INDEX_LEVEL; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + | + APCI1710_SET_LOW_INDEX_LEVEL; + } else { /**************************************/ - /* Set the index level to high (DQ26) */ + /* Set the index level to high (DQ26) */ /**************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & APCI1710_SET_HIGH_INDEX_LEVEL; - } + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + & + APCI1710_SET_HIGH_INDEX_LEVEL; + } /***********************************/ - /* Test if latch and clear counter */ + /* Test if latch and clear counter */ /***********************************/ - if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) - { + if (b_IndexOperation == + APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER + || + b_IndexOperation + == + APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) + { /***************************************/ - /* Set the latch and clear flag (DQ27) */ + /* Set the latch and clear flag (DQ27) */ /***************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 | APCI1710_ENABLE_LATCH_AND_CLEAR; - } // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + | + APCI1710_ENABLE_LATCH_AND_CLEAR; + } // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) + else { /*****************************************/ - /* Clear the latch and clear flag (DQ27) */ + /* Clear the latch and clear flag (DQ27) */ /*****************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & APCI1710_DISABLE_LATCH_AND_CLEAR; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + & + APCI1710_DISABLE_LATCH_AND_CLEAR; /*************************/ - /* Test if latch counter */ + /* Test if latch counter */ /*************************/ - if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER || - b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER) - { + if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER) { /*********************************/ - /* Enable the latch from counter */ + /* Enable the latch from counter */ /*********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_INDEX_LATCH_COUNTER; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + | + APCI1710_INDEX_LATCH_COUNTER; + } else { /*********************************/ - /* Enable the clear from counter */ + /* Enable the clear from counter */ /*********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & (~APCI1710_INDEX_LATCH_COUNTER); - } - } // // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) - - - if (b_AutoMode == APCI1710_DISABLE) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_INDEX_AUTO_MODE; - } - else - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & (~APCI1710_INDEX_AUTO_MODE); - } - - if (b_InterruptEnable == APCI1710_ENABLE) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 | APCI1710_ENABLE_INDEX_INT; - } - else - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_DISABLE_INDEX_INT; - } - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInit = 1; - - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + & + (~APCI1710_INDEX_LATCH_COUNTER); + } + } // // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER) + + if (b_AutoMode == + APCI1710_DISABLE) + { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + | + APCI1710_INDEX_AUTO_MODE; + } else { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 + & + (~APCI1710_INDEX_AUTO_MODE); + } + + if (b_InterruptEnable == + APCI1710_ENABLE) + { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + | + APCI1710_ENABLE_INDEX_INT; + } else { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + & + APCI1710_DISABLE_INDEX_INT; + } + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag. + b_IndexInit = 1; + + } else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("Interrupt parameter is wrong\n"); - i_ReturnValue = -7; - } - } - else - { + DPRINTK("Interrupt parameter is wrong\n"); + i_ReturnValue = -7; + } + } else { /************************************/ - /* The auto mode parameter is wrong */ + /* The auto mode parameter is wrong */ /************************************/ - DPRINTK("The auto mode parameter is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("The auto mode parameter is wrong\n"); + i_ReturnValue = -6; + } + } else { /***********************************************/ - /* The index operating mode parameter is wrong */ + /* The index operating mode parameter is wrong */ /***********************************************/ - DPRINTK("The index operating mode parameter is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("The index operating mode parameter is wrong\n"); + i_ReturnValue = -5; + } + } else { /*******************************************/ - /* The reference action parameter is wrong */ + /* The reference action parameter is wrong */ /*******************************************/ - DPRINTK("The reference action parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The reference action parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1122,115 +1152,96 @@ INT i_APCI1710_InitIndex (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InitReference (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ReferenceLevel) - { +INT i_APCI1710_InitReference(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_ReferenceLevel) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /**************************************/ - /* Test the reference level parameter */ + /* Test the reference level parameter */ /**************************************/ - if (b_ReferenceLevel == 0 || - b_ReferenceLevel == 1) - { - if (b_ReferenceLevel == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_REFERENCE_HIGH; - } - else - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & APCI1710_REFERENCE_LOW; - } - - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_ReferenceInit = 1; - } - else - { + if (b_ReferenceLevel == 0 || b_ReferenceLevel == 1) { + if (b_ReferenceLevel == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 | + APCI1710_REFERENCE_HIGH; + } else { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 & + APCI1710_REFERENCE_LOW; + } + + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_ReferenceInit = 1; + } else { /**************************************/ - /* Reference level parameter is wrong */ + /* Reference level parameter is wrong */ /**************************************/ - DPRINTK("Reference level parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Reference level parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_InitExternalStrobe | @@ -1266,190 +1277,165 @@ INT i_APCI1710_InitReference (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InitExternalStrobe (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ExternalStrobe, - BYTE b_ExternalStrobeLevel) - { - INT i_ReturnValue = 0; - - +INT i_APCI1710_InitExternalStrobe(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_ExternalStrobe, BYTE b_ExternalStrobeLevel) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + /**************************************/ + /* Test the external strobe selection */ /**************************************/ - /* Test the external strobe selection */ - /**************************************/ - if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) - { + if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) { /******************/ - /* Test the level */ + /* Test the level */ /******************/ - if ((b_ExternalStrobeLevel == APCI1710_HIGH) || - ((b_ExternalStrobeLevel == APCI1710_LOW && (devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135))) - { + if ((b_ExternalStrobeLevel == APCI1710_HIGH) || + ((b_ExternalStrobeLevel == APCI1710_LOW + && (devpriv-> + s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) >= + 0x3135))) { /*****************/ - /* Set the level */ + /* Set the level */ /*****************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & (0xFF - (0x10 << b_ExternalStrobe))) | - ((b_ExternalStrobeLevel^1) << (4 + b_ExternalStrobe)); - } - else - { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 = (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 & (0xFF - + (0x10 << b_ExternalStrobe))) | ((b_ExternalStrobeLevel ^ 1) << (4 + b_ExternalStrobe)); + } else { /********************************************/ - /* External strobe level parameter is wrong */ + /* External strobe level parameter is wrong */ /********************************************/ - DPRINTK("External strobe level parameter is wrong\n"); - i_ReturnValue = -5; - } - } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) - else - { + DPRINTK("External strobe level parameter is wrong\n"); + i_ReturnValue = -5; + } + } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) + else { /**************************************/ - /* External strobe selection is wrong */ + /* External strobe selection is wrong */ /**************************************/ - DPRINTK("External strobe selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) - } - else - { + DPRINTK("External strobe selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1) + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* -+----------------------------------------------------------------------------+ -| Function Name : _INT_ i_APCI1710_InitCompareLogic | -| (BYTE_ b_BoardHandle, | -| BYTE_ b_ModulNbr, | -| UINT_ ui_CompareValue) | -+----------------------------------------------------------------------------+ -| Task : Set the 32-Bit compare value. At that moment that the | -| incremental counter arrive to the compare value | -| (ui_CompareValue) a interrupt is generated. | -+----------------------------------------------------------------------------+ -| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | -| BYTE_ b_ModulNbr : Module number to configure | -| (0 to 3) | -| UINT_ ui_CompareValue : 32-Bit compare value | -+----------------------------------------------------------------------------+ -| Output Parameters : - -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -1: The handle parameter of the board is wrong | -| -2: No counter module found | -| -3: Counter not initialised see function | -| "i_APCI1710_InitCounter" | -+----------------------------------------------------------------------------+ -*/ - -INT i_APCI1710_InitCompareLogic (comedi_device *dev, - BYTE b_ModulNbr, - UINT ui_CompareValue) - { - INT i_ReturnValue = 0; - + +----------------------------------------------------------------------------+ + | Function Name : _INT_ i_APCI1710_InitCompareLogic | + | (BYTE_ b_BoardHandle, | + | BYTE_ b_ModulNbr, | + | UINT_ ui_CompareValue) | + +----------------------------------------------------------------------------+ + | Task : Set the 32-Bit compare value. At that moment that the | + | incremental counter arrive to the compare value | + | (ui_CompareValue) a interrupt is generated. | + +----------------------------------------------------------------------------+ + | Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | + | BYTE_ b_ModulNbr : Module number to configure | + | (0 to 3) | + | UINT_ ui_CompareValue : 32-Bit compare value | + +----------------------------------------------------------------------------+ + | Output Parameters : - + +----------------------------------------------------------------------------+ + | Return Value : 0: No error | + | -1: The handle parameter of the board is wrong | + | -2: No counter module found | + | -3: Counter not initialised see function | + | "i_APCI1710_InitCounter" | + +----------------------------------------------------------------------------+ + */ + +INT i_APCI1710_InitCompareLogic(comedi_device * dev, + BYTE b_ModulNbr, UINT ui_CompareValue) +{ + INT i_ReturnValue = 0; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - - outl(ui_CompareValue,devpriv->s_BoardInfos. - ui_Address + 28 + (64 * b_ModulNbr)); - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CompareLogicInit = 1; - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + + outl(ui_CompareValue, devpriv->s_BoardInfos. + ui_Address + 28 + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_CompareLogicInit = 1; + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1501,376 +1487,513 @@ INT i_APCI1710_InitCompareLogic (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InitFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PCIInputClock, - BYTE b_TimingUnity, - ULONG ul_TimingInterval, - PULONG pul_RealTimingInterval) - { - INT i_ReturnValue = 0; - ULONG ul_TimerValue = 0; +INT i_APCI1710_InitFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PCIInputClock, + BYTE b_TimingUnity, + ULONG ul_TimingInterval, PULONG pul_RealTimingInterval) +{ + INT i_ReturnValue = 0; + ULONG ul_TimerValue = 0; double d_RealTimingInterval; - DWORD dw_Status = 0; - + DWORD dw_Status = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /**************************/ - /* Test the PCI bus clock */ + /* Test the PCI bus clock */ /**************************/ - if ((b_PCIInputClock == APCI1710_30MHZ) || - (b_PCIInputClock == APCI1710_33MHZ) || - (b_PCIInputClock == APCI1710_40MHZ)) - { + if ((b_PCIInputClock == APCI1710_30MHZ) || + (b_PCIInputClock == APCI1710_33MHZ) || + (b_PCIInputClock == APCI1710_40MHZ)) { /************************/ - /* Test the timing unit */ + /* Test the timing unit */ /************************/ - if (b_TimingUnity <= 2) - { + if (b_TimingUnity <= 2) { /**********************************/ - /* Test the base timing selection */ + /* Test the base timing selection */ /**********************************/ - if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 266) && (ul_TimingInterval <= 8738133UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 8738UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 8UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 242) && (ul_TimingInterval <= 7943757UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 7943UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 7UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 200) && (ul_TimingInterval <= 6553500UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 6553UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 6UL))) - { + if (((b_PCIInputClock == APCI1710_30MHZ) + && (b_TimingUnity == 0) + && (ul_TimingInterval >= + 266) + && (ul_TimingInterval <= + 8738133UL)) + || ((b_PCIInputClock == + APCI1710_30MHZ) + && (b_TimingUnity == 1) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 8738UL)) + || ((b_PCIInputClock == + APCI1710_30MHZ) + && (b_TimingUnity == 2) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 8UL)) + || ((b_PCIInputClock == + APCI1710_33MHZ) + && (b_TimingUnity == 0) + && (ul_TimingInterval >= + 242) + && (ul_TimingInterval <= + 7943757UL)) + || ((b_PCIInputClock == + APCI1710_33MHZ) + && (b_TimingUnity == 1) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 7943UL)) + || ((b_PCIInputClock == + APCI1710_33MHZ) + && (b_TimingUnity == 2) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 7UL)) + || ((b_PCIInputClock == + APCI1710_40MHZ) + && (b_TimingUnity == 0) + && (ul_TimingInterval >= + 200) + && (ul_TimingInterval <= + 6553500UL)) + || ((b_PCIInputClock == + APCI1710_40MHZ) + && (b_TimingUnity == 1) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 6553UL)) + || ((b_PCIInputClock == + APCI1710_40MHZ) + && (b_TimingUnity == 2) + && (ul_TimingInterval >= + 1) + && (ul_TimingInterval <= + 6UL))) { /**********************/ - /* Test if 40MHz used */ + /* Test if 40MHz used */ /**********************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { + if (b_PCIInputClock == + APCI1710_40MHZ) { /******************************/ - /* Test if firmware >= Rev1.5 */ + /* Test if firmware >= Rev1.5 */ /******************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135) - { + if ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3135) { /*********************************/ - /* Test if 40MHz quartz on board */ + /* Test if 40MHz quartz on board */ /*********************************/ - /*INPDW (ps_APCI1710Variable-> - s_Board [b_BoardHandle]. - s_BoardInfos. - ui_Address + 36 + (64 * b_ModulNbr), &dw_Status);*/ - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 36 + (64 * b_ModulNbr)); + /*INPDW (ps_APCI1710Variable-> + s_Board [b_BoardHandle]. + s_BoardInfos. + ui_Address + 36 + (64 * b_ModulNbr), &dw_Status); */ + dw_Status = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + 36 + + (64 * b_ModulNbr)); /******************************/ - /* Test the quartz flag (DQ0) */ + /* Test the quartz flag (DQ0) */ /******************************/ - if ((dw_Status & 1) != 1) - { + if ((dw_Status & 1) != 1) { /*****************************/ - /* 40MHz quartz not on board */ + /* 40MHz quartz not on board */ /*****************************/ - DPRINTK("40MHz quartz not on board\n"); - i_ReturnValue = -7; - } - } - else - { + DPRINTK("40MHz quartz not on board\n"); + i_ReturnValue + = + -7; + } + } else { /*****************************/ - /* 40MHz quartz not on board */ + /* 40MHz quartz not on board */ /*****************************/ - DPRINTK("40MHz quartz not on board\n"); - i_ReturnValue = -7; - } - } // if (b_PCIInputClock == APCI1710_40MHZ) + DPRINTK("40MHz quartz not on board\n"); + i_ReturnValue = + -7; + } + } // if (b_PCIInputClock == APCI1710_40MHZ) /***************************/ - /* Test if not error occur */ + /* Test if not error occur */ /***************************/ - if (i_ReturnValue == 0) - { + if (i_ReturnValue == 0) { /****************************/ - /* Test the INC_CPT version */ + /* Test the INC_CPT version */ /****************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131) - { - + if ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3131) { + /**********************/ - /* Test if 40MHz used */ + /* Test if 40MHz used */ /**********************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { + if (b_PCIInputClock == APCI1710_40MHZ) { /*********************************/ - /* Enable the 40MHz quarz (DQ30) */ + /* Enable the 40MHz quarz (DQ30) */ /*********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FREQUENCY; - } // if (b_PCIInputClock == APCI1710_40MHZ) - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + | + APCI1710_ENABLE_40MHZ_FREQUENCY; + } // if (b_PCIInputClock == APCI1710_40MHZ) + else { /**********************************/ - /* Disable the 40MHz quarz (DQ30) */ + /* Disable the 40MHz quarz (DQ30) */ /**********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FREQUENCY; - - } // if (b_PCIInputClock == APCI1710_40MHZ) - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + & + APCI1710_DISABLE_40MHZ_FREQUENCY; + + } // if (b_PCIInputClock == APCI1710_40MHZ) /********************************/ - /* Calculate the division fator */ + /* Calculate the division fator */ /********************************/ - fpu_begin (); - switch (b_TimingUnity) - { + fpu_begin(); + switch (b_TimingUnity) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (0.00025 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (0.00025 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (0.00025 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (0.00025 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.00025 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5)) - { - *pul_RealTimingInterval = *pul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - break; + *pul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (0.00025 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (0.00025 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (0.00025 * (double)b_PCIInputClock)) >= (double)((double)*pul_RealTimingInterval + 0.5)) { + *pul_RealTimingInterval + = + *pul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (0.25 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (0.25 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (0.25 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (0.25 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.25 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / ((double) 0.25 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (0.25 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5)) - { - *pul_RealTimingInterval = *pul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - - break; + *pul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (0.25 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + ( + (double) + 0.25 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (0.25 * (double)b_PCIInputClock)) >= (double)((double)*pul_RealTimingInterval + 0.5)) { + *pul_RealTimingInterval + = + *pul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = ul_TimingInterval * (250.0 * b_PCIInputClock); + ul_TimerValue + = + ul_TimingInterval + * + (250.0 + * + b_PCIInputClock); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (250.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (250.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (250.0 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5)) - { - *pul_RealTimingInterval = *pul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - break; - } - - fpu_end (); + *pul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (250.0 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (250.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (250.0 * (double)b_PCIInputClock)) >= (double)((double)*pul_RealTimingInterval + 0.5)) { + *pul_RealTimingInterval + = + *pul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + break; + } + + fpu_end(); /*************************/ - /* Write the timer value */ + /* Write the timer value */ /*************************/ - - outl(ul_TimerValue,devpriv->s_BoardInfos. - ui_Address + 32 + (64 * b_ModulNbr)); + outl(ul_TimerValue, devpriv->s_BoardInfos.ui_Address + 32 + (64 * b_ModulNbr)); /*******************************/ - /* Set the initialisation flag */ + /* Set the initialisation flag */ /*******************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementInit = 1; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag. + b_FrequencyMeasurementInit + = 1; + } else { /***************************/ - /* Counter not initialised */ + /* Counter not initialised */ /***************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } // if (i_ReturnValue == 0) - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = + -3; + } + } // if (i_ReturnValue == 0) + } else { /**********************************/ - /* Base timing selection is wrong */ + /* Base timing selection is wrong */ /**********************************/ - DPRINTK("Base timing selection is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Base timing selection is wrong\n"); + i_ReturnValue = -6; + } + } else { /***********************************/ - /* Timing unity selection is wrong */ + /* Timing unity selection is wrong */ /***********************************/ - DPRINTK("Timing unity selection is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Timing unity selection is wrong\n"); + i_ReturnValue = -5; + } + } else { /*****************************************/ - /* The selected PCI input clock is wrong */ + /* The selected PCI input clock is wrong */ /*****************************************/ - DPRINTK("The selected PCI input clock is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected PCI input clock is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /*########################################################################### */ @@ -1892,64 +2015,59 @@ comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnBitsINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { UINT ui_BitsType; - INT i_ReturnValue=0; - ui_BitsType=CR_CHAN(insn->chanspec); - devpriv->tsk_Current=current; // Save the current process task structure + INT i_ReturnValue = 0; + ui_BitsType = CR_CHAN(insn->chanspec); + devpriv->tsk_Current = current; // Save the current process task structure - switch(ui_BitsType) - { + switch (ui_BitsType) { case APCI1710_INCCPT_CLEARCOUNTERVALUE: - i_ReturnValue=i_APCI1710_ClearCounterValue (dev, - (BYTE) CR_AREF(insn->chanspec)); + i_ReturnValue = i_APCI1710_ClearCounterValue(dev, + (BYTE) CR_AREF(insn->chanspec)); break; case APCI1710_INCCPT_CLEARALLCOUNTERVALUE: - i_ReturnValue=i_APCI1710_ClearAllCounterValue (dev); + i_ReturnValue = i_APCI1710_ClearAllCounterValue(dev); break; case APCI1710_INCCPT_SETINPUTFILTER: - i_ReturnValue=i_APCI1710_SetInputFilter (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1]); + i_ReturnValue = i_APCI1710_SetInputFilter(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) data[0], (BYTE) data[1]); break; case APCI1710_INCCPT_LATCHCOUNTER: - i_ReturnValue=i_APCI1710_LatchCounter (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0]); + i_ReturnValue = i_APCI1710_LatchCounter(dev, + (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0]); break; case APCI1710_INCCPT_SETINDEXANDREFERENCESOURCE: - i_ReturnValue=i_APCI1710_SetIndexAndReferenceSource (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0]); + i_ReturnValue = i_APCI1710_SetIndexAndReferenceSource(dev, + (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0]); break; case APCI1710_INCCPT_SETDIGITALCHLON: - i_ReturnValue=i_APCI1710_SetDigitalChlOn (dev, - (BYTE) CR_AREF(insn->chanspec)); + i_ReturnValue = i_APCI1710_SetDigitalChlOn(dev, + (BYTE) CR_AREF(insn->chanspec)); break; case APCI1710_INCCPT_SETDIGITALCHLOFF: - i_ReturnValue=i_APCI1710_SetDigitalChlOff (dev, - (BYTE) CR_AREF(insn->chanspec)); + i_ReturnValue = i_APCI1710_SetDigitalChlOff(dev, + (BYTE) CR_AREF(insn->chanspec)); break; default: printk("Bits Config Parameter Wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_ClearCounterValue | @@ -1973,60 +2091,48 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ClearCounterValue (comedi_device *dev, - BYTE b_ModulNbr) - { +INT i_APCI1710_ClearCounterValue(comedi_device * dev, BYTE b_ModulNbr) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*********************/ - /* Clear the counter */ + /* Clear the counter */ /*********************/ - - outl(1,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); - } - else - { + outl(1, devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -2045,59 +2151,55 @@ INT i_APCI1710_ClearCounterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ClearAllCounterValue (comedi_device *dev) - { - BYTE b_ModulCpt = 0; - INT i_ReturnValue = 0; - +INT i_APCI1710_ClearAllCounterValue(comedi_device * dev) +{ + BYTE b_ModulCpt = 0; + INT i_ReturnValue = 0; /********************************/ /* Test if counter module found */ /********************************/ if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER || - (devpriv->s_BoardInfos. - dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER || - (devpriv->s_BoardInfos. - dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER || - (devpriv->s_BoardInfos. - dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { - for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++) - { + dw_MolduleConfiguration[0] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[1] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[2] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER + || (devpriv->s_BoardInfos. + dw_MolduleConfiguration[3] & 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER) { + for (b_ModulCpt = 0; b_ModulCpt < 4; b_ModulCpt++) { /*******************************/ - /* Test if incremental counter */ + /* Test if incremental counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulCpt] & + 0xFFFF0000UL) == + APCI1710_INCREMENTAL_COUNTER) { /*********************/ - /* Clear the counter */ + /* Clear the counter */ /*********************/ - - outl(1,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulCpt)); - } - } - } - else - { + outl(1, devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModulCpt)); + } + } + } else { /***************************/ - /* No counter module found */ + /* No counter module found */ /***************************/ - DPRINTK("No counter module found\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("No counter module found\n"); + i_ReturnValue = -2; } - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -2195,216 +2297,241 @@ INT i_APCI1710_ClearAllCounterValue (comedi_device *dev) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_SetInputFilter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PCIInputClock, - BYTE b_Filter) - { - INT i_ReturnValue = 0; - DWORD dw_Status = 0; - +INT i_APCI1710_SetInputFilter(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_PCIInputClock, BYTE b_Filter) +{ + INT i_ReturnValue = 0; + DWORD dw_Status = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if incremental counter */ + /* Test if incremental counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) { /******************************/ - /* Test if firmware >= Rev1.5 */ + /* Test if firmware >= Rev1.5 */ /******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF) >= 0x3135) { /**************************/ - /* Test the PCI bus clock */ + /* Test the PCI bus clock */ /**************************/ - if ((b_PCIInputClock == APCI1710_30MHZ) || - (b_PCIInputClock == APCI1710_33MHZ) || - (b_PCIInputClock == APCI1710_40MHZ)) - { + if ((b_PCIInputClock == APCI1710_30MHZ) || + (b_PCIInputClock == APCI1710_33MHZ) || + (b_PCIInputClock == APCI1710_40MHZ)) { /*************************/ - /* Test the filter value */ + /* Test the filter value */ /*************************/ - if (b_Filter < 16) - { + if (b_Filter < 16) { /**********************/ - /* Test if 40MHz used */ + /* Test if 40MHz used */ /**********************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { + if (b_PCIInputClock == + APCI1710_40MHZ) { /*********************************/ - /* Test if 40MHz quartz on board */ + /* Test if 40MHz quartz on board */ /*********************************/ - - dw_Status= inl(devpriv->s_BoardInfos. - ui_Address + 36 + (64 * b_ModulNbr)); + dw_Status = + inl(devpriv-> + s_BoardInfos. + ui_Address + + 36 + + (64 * b_ModulNbr)); /******************************/ - /* Test the quartz flag (DQ0) */ + /* Test the quartz flag (DQ0) */ /******************************/ - if ((dw_Status & 1) != 1) - { + if ((dw_Status & 1) != + 1) { /*****************************/ - /* 40MHz quartz not on board */ + /* 40MHz quartz not on board */ /*****************************/ - DPRINTK("40MHz quartz not on board\n"); - i_ReturnValue = -6; - } - } // if (b_PCIInputClock == APCI1710_40MHZ) + DPRINTK("40MHz quartz not on board\n"); + i_ReturnValue = + -6; + } + } // if (b_PCIInputClock == APCI1710_40MHZ) /***************************/ - /* Test if error not occur */ + /* Test if error not occur */ /***************************/ - if (i_ReturnValue == 0) - { + if (i_ReturnValue == 0) { /**********************/ - /* Test if 40MHz used */ + /* Test if 40MHz used */ /**********************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { + if (b_PCIInputClock == + APCI1710_40MHZ) + { /*********************************/ - /* Enable the 40MHz quarz (DQ31) */ + /* Enable the 40MHz quarz (DQ31) */ /*********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FILTER; - - } // if (b_PCIInputClock == APCI1710_40MHZ) - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + | + APCI1710_ENABLE_40MHZ_FILTER; + + } // if (b_PCIInputClock == APCI1710_40MHZ) + else { /**********************************/ - /* Disable the 40MHz quarz (DQ31) */ + /* Disable the 40MHz quarz (DQ31) */ /**********************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FILTER; - - } // if (b_PCIInputClock == APCI1710_40MHZ) + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + & + APCI1710_DISABLE_40MHZ_FILTER; + + } // if (b_PCIInputClock == APCI1710_40MHZ) /************************/ - /* Set the filter value */ + /* Set the filter value */ /************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = (devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & 0x1F) | ((b_Filter & 0x7) << 5); - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & 0xFE) | ((b_Filter & 0x8) >> 3); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 + & 0x1F) | + ((b_Filter & + 0x7) << + 5); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 + & 0xFE) | + ((b_Filter & + 0x8) >> + 3); /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } // if (i_ReturnValue == 0) - } // if (b_Filter < 16) - else - { + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv-> + s_BoardInfos. + ui_Address + + 20 + + (64 * b_ModulNbr)); + } // if (i_ReturnValue == 0) + } // if (b_Filter < 16) + else { /**************************************/ - /* The selected filter value is wrong */ + /* The selected filter value is wrong */ /**************************************/ - DPRINTK("The selected filter value is wrong\n"); - i_ReturnValue = -5; - } // if (b_Filter < 16) - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ)) - else - { + DPRINTK("The selected filter value is wrong\n"); + i_ReturnValue = -5; + } // if (b_Filter < 16) + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ)) + else { /*****************************************/ - /* The selected PCI input clock is wrong */ + /* The selected PCI input clock is wrong */ /*****************************************/ - DPRINTK("The selected PCI input clock is wrong\n"); - i_ReturnValue = 4; - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ)) - } - else - { + DPRINTK("The selected PCI input clock is wrong\n"); + i_ReturnValue = 4; + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ)) + } else { /**************************************/ - /* The module is not a counter module */ + /* The module is not a counter module */ /**************************************/ - DPRINTK("The module is not a counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a counter module\n"); + i_ReturnValue = -3; + } + } else { /**************************************/ - /* The module is not a counter module */ + /* The module is not a counter module */ /**************************************/ - DPRINTK("The module is not a counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a counter module\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -2434,76 +2561,63 @@ INT i_APCI1710_SetInputFilter (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_LatchCounter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg) - { +INT i_APCI1710_LatchCounter(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg) +{ INT i_ReturnValue = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************************/ - /* Test the latch register parameter */ + /* Test the latch register parameter */ /*************************************/ - if (b_LatchReg < 2) - { + if (b_LatchReg < 2) { /*********************/ - /* Tatch the counter */ + /* Tatch the counter */ /*********************/ - outl(1 << (b_LatchReg * 4),devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); - } - else - { + outl(1 << (b_LatchReg * 4), + devpriv->s_BoardInfos.ui_Address + + (64 * b_ModulNbr)); + } else { /**************************************************/ - /* The selected latch register parameter is wrong */ + /* The selected latch register parameter is wrong */ /**************************************************/ - DPRINTK("The selected latch register parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected latch register parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -2544,121 +2658,119 @@ INT i_APCI1710_LatchCounter (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_SetIndexAndReferenceSource (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SourceSelection) - { - INT i_ReturnValue = 0; - - +INT i_APCI1710_SetIndexAndReferenceSource(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SourceSelection) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if incremental counter */ + /* Test if incremental counter */ /*******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) { /******************************/ - /* Test if firmware >= Rev1.5 */ + /* Test if firmware >= Rev1.5 */ /******************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF) >= 0x3135) { /*****************************/ - /* Test the source selection */ + /* Test the source selection */ /*****************************/ - if (b_SourceSelection == APCI1710_SOURCE_0 || - b_SourceSelection == APCI1710_SOURCE_1) - { + if (b_SourceSelection == APCI1710_SOURCE_0 || + b_SourceSelection == APCI1710_SOURCE_1) + { /******************************************/ - /* Test if invert the index and reference */ + /* Test if invert the index and reference */ /******************************************/ - if (b_SourceSelection == APCI1710_SOURCE_1) - { + if (b_SourceSelection == + APCI1710_SOURCE_1) { /********************************************/ - /* Invert index and reference source (DQ25) */ + /* Invert index and reference source (DQ25) */ /********************************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 | APCI1710_INVERT_INDEX_RFERENCE; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 | + APCI1710_INVERT_INDEX_RFERENCE; + } else { /****************************************/ - /* Set the default configuration (DQ25) */ + /* Set the default configuration (DQ25) */ /****************************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister4 & APCI1710_DEFAULT_INDEX_RFERENCE; - } - } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1) - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister4 & + APCI1710_DEFAULT_INDEX_RFERENCE; + } + } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1) + else { /*********************************/ - /* The source selection is wrong */ - /*********************************/ - - DPRINTK("The source selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1) - } - else - { + /* The source selection is wrong */ + /*********************************/ + + DPRINTK("The source selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1) + } else { /**************************************/ - /* The module is not a counter module */ + /* The module is not a counter module */ /**************************************/ - DPRINTK("The module is not a counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a counter module\n"); + i_ReturnValue = -3; + } + } else { /**************************************/ - /* The module is not a counter module */ + /* The module is not a counter module */ /**************************************/ - DPRINTK("The module is not a counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a counter module\n"); + i_ReturnValue = -3; + } + } else { /***************************************/ - /* The selected module number is wrong */ + /* The selected module number is wrong */ /***************************************/ - DPRINTK("The selected module number is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -2683,72 +2795,62 @@ INT i_APCI1710_SetIndexAndReferenceSource (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_SetDigitalChlOn (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; - +INT i_APCI1710_SetDigitalChlOn(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. s_SiemensCounterInfo. s_ModeRegister. s_ByteModeRegister. - b_ModeRegister3 | 0x10; + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister.b_ModeRegister3 | 0x10; /*********************/ - /* Set the output On */ + /* Set the output On */ /*********************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, devpriv->s_BoardInfos. + ui_Address + 20 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -2773,73 +2875,62 @@ INT i_APCI1710_SetDigitalChlOn (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_SetDigitalChlOff (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; - +INT i_APCI1710_SetDigitalChlOff(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. s_SiemensCounterInfo. s_ModeRegister. s_ByteModeRegister. - b_ModeRegister3 & 0xEF; + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister.b_ModeRegister3 & 0xEF; /**********************/ - /* Set the output Off */ + /* Set the output Off */ /**********************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, devpriv->s_BoardInfos. + ui_Address + 20 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /*########################################################################### */ @@ -2860,81 +2951,76 @@ comedi_insn *insn,lsampl_t *data) | | Return Value : +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnWriteINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { UINT ui_WriteType; - INT i_ReturnValue=0; - - ui_WriteType=CR_CHAN(insn->chanspec); - devpriv->tsk_Current=current; // Save the current process task structure - - switch(ui_WriteType) - { - case APCI1710_INCCPT_ENABLELATCHINTERRUPT: - i_ReturnValue = i_APCI1710_EnableLatchInterrupt (dev, - (BYTE) CR_AREF(insn->chanspec)); + INT i_ReturnValue = 0; + + ui_WriteType = CR_CHAN(insn->chanspec); + devpriv->tsk_Current = current; // Save the current process task structure + + switch (ui_WriteType) { + case APCI1710_INCCPT_ENABLELATCHINTERRUPT: + i_ReturnValue = i_APCI1710_EnableLatchInterrupt(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_DISABLELATCHINTERRUPT: - i_ReturnValue = i_APCI1710_DisableLatchInterrupt (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_DISABLELATCHINTERRUPT: + i_ReturnValue = i_APCI1710_DisableLatchInterrupt(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_WRITE16BITCOUNTERVALUE: - i_ReturnValue = i_APCI1710_Write16BitCounterValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0], - (UINT) data[1]); + case APCI1710_INCCPT_WRITE16BITCOUNTERVALUE: + i_ReturnValue = i_APCI1710_Write16BitCounterValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) data[0], (UINT) data[1]); break; - case APCI1710_INCCPT_WRITE32BITCOUNTERVALUE: - i_ReturnValue = i_APCI1710_Write32BitCounterValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (ULONG) data[0]); + case APCI1710_INCCPT_WRITE32BITCOUNTERVALUE: + i_ReturnValue = i_APCI1710_Write32BitCounterValue(dev, + (BYTE) CR_AREF(insn->chanspec), (ULONG) data[0]); break; - case APCI1710_INCCPT_ENABLEINDEX: - i_APCI1710_EnableIndex (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_ENABLEINDEX: + i_APCI1710_EnableIndex(dev, (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_DISABLEINDEX: - i_ReturnValue = i_APCI1710_DisableIndex (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_DISABLEINDEX: + i_ReturnValue = i_APCI1710_DisableIndex(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_ENABLECOMPARELOGIC: - i_ReturnValue = i_APCI1710_EnableCompareLogic (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_ENABLECOMPARELOGIC: + i_ReturnValue = i_APCI1710_EnableCompareLogic(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_DISABLECOMPARELOGIC: - i_ReturnValue = i_APCI1710_DisableCompareLogic (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_DISABLECOMPARELOGIC: + i_ReturnValue = i_APCI1710_DisableCompareLogic(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - case APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT: - i_ReturnValue = i_APCI1710_EnableFrequencyMeasurement (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0]); + case APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT: + i_ReturnValue = i_APCI1710_EnableFrequencyMeasurement(dev, + (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0]); break; - case APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT: - i_ReturnValue = i_APCI1710_DisableFrequencyMeasurement (dev, - (BYTE) CR_AREF(insn->chanspec)); + case APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT: + i_ReturnValue = i_APCI1710_DisableFrequencyMeasurement(dev, + (BYTE) CR_AREF(insn->chanspec)); break; - default: - printk("Write Config Parameter Wrong\n"); + default: + printk("Write Config Parameter Wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_EnableLatchInterrupt | @@ -2961,76 +3047,66 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_EnableLatchInterrupt (comedi_device *dev, - BYTE b_ModulNbr) - { +INT i_APCI1710_EnableLatchInterrupt(comedi_device * dev, BYTE b_ModulNbr) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /********************/ - /* Enable interrupt */ + /* Enable interrupt */ /********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_ENABLE_LATCH_INT; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 | APCI1710_ENABLE_LATCH_INT; /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, devpriv->s_BoardInfos. + ui_Address + 20 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -3057,80 +3133,73 @@ INT i_APCI1710_EnableLatchInterrupt (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_DisableLatchInterrupt (comedi_device *dev, - BYTE b_ModulNbr) - { +INT i_APCI1710_DisableLatchInterrupt(comedi_device * dev, BYTE b_ModulNbr) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4 & ((APCI1710_DISABLE_LATCH_INT << 8) | 0xFF),devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4 & + ((APCI1710_DISABLE_LATCH_INT << 8) | 0xFF), + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); - mdelay(1000); + mdelay(1000); /*********************/ - /* Disable interrupt */ + /* Disable interrupt */ /*********************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & APCI1710_DISABLE_LATCH_INT; - - } - else - { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 & APCI1710_DISABLE_LATCH_INT; + + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -3162,76 +3231,65 @@ INT i_APCI1710_DisableLatchInterrupt (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_Write16BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SelectedCounter, - UINT ui_WriteValue) - { +INT i_APCI1710_Write16BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SelectedCounter, UINT ui_WriteValue) +{ INT i_ReturnValue = 0; - - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /******************************/ - /* Test the counter selection */ + /* Test the counter selection */ /******************************/ - if (b_SelectedCounter < 2) - { + if (b_SelectedCounter < 2) { /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - outl((ULONG) ((ULONG) (ui_WriteValue) << (16 * b_SelectedCounter)),devpriv->s_BoardInfos. - ui_Address + 8 + (b_SelectedCounter * 4) + (64 * b_ModulNbr)); - } - else - { + outl((ULONG) ((ULONG) (ui_WriteValue) << (16 * + b_SelectedCounter)), + devpriv->s_BoardInfos.ui_Address + 8 + + (b_SelectedCounter * 4) + + (64 * b_ModulNbr)); + } else { /**************************************************/ - /* The selected 16-Bit counter parameter is wrong */ + /* The selected 16-Bit counter parameter is wrong */ /**************************************************/ - DPRINTK("The selected 16-Bit counter parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected 16-Bit counter parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -3258,60 +3316,49 @@ INT i_APCI1710_Write16BitCounterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_Write32BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - ULONG ul_WriteValue) - { +INT i_APCI1710_Write32BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, ULONG ul_WriteValue) +{ INT i_ReturnValue = 0; - - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - outl(ul_WriteValue,devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); - } - else - { + outl(ul_WriteValue, devpriv->s_BoardInfos. + ui_Address + 4 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -3336,94 +3383,80 @@ INT i_APCI1710_Write32BitCounterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_EnableIndex (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; +INT i_APCI1710_EnableIndex(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; ULONG ul_InterruptLatchReg; - - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*****************************/ - /* Test if index initialised */ + /* Test if index initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInit) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 | APCI1710_ENABLE_INDEX; - - ul_InterruptLatchReg=inl(devpriv->s_BoardInfos. - ui_Address + 24 + (64 * b_ModulNbr)); - - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_IndexInit) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 | APCI1710_ENABLE_INDEX; + + ul_InterruptLatchReg = + inl(devpriv->s_BoardInfos.ui_Address + + 24 + (64 * b_ModulNbr)); + + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + } else { /*************************************************************/ - /* Index not initialised see function "i_APCI1710_InitIndex" */ + /* Index not initialised see function "i_APCI1710_InitIndex" */ /*************************************************************/ - DPRINTK("Index not initialised \n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Index not initialised \n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -3448,90 +3481,76 @@ INT i_APCI1710_EnableIndex (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_DisableIndex (comedi_device *dev, - BYTE b_ModulNbr) - { +INT i_APCI1710_DisableIndex(comedi_device * dev, BYTE b_ModulNbr) +{ INT i_ReturnValue = 0; - - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*****************************/ - /* Test if index initialised */ + /* Test if index initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInit) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & APCI1710_DISABLE_INDEX; - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_IndexInit) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 & + APCI1710_DISABLE_INDEX; + + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + } else { /*************************************************************/ - /* Index not initialised see function "i_APCI1710_InitIndex" */ + /* Index not initialised see function "i_APCI1710_InitIndex" */ /*************************************************************/ - DPRINTK("Index not initialised \n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Index not initialised \n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -3561,93 +3580,81 @@ INT i_APCI1710_DisableIndex (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_EnableCompareLogic (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; - - +INT i_APCI1710_EnableCompareLogic(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************************/ - /* Test if compare logic initialised */ + /* Test if compare logic initialised */ /*************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CompareLogicInit == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 | APCI1710_ENABLE_COMPARE_INT; + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_CompareLogicInit == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 | + APCI1710_ENABLE_COMPARE_INT; /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + } else { /*********************************/ - /* Compare logic not initialised */ + /* Compare logic not initialised */ /*********************************/ - DPRINTK("Compare logic not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Compare logic not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -3673,387 +3680,354 @@ INT i_APCI1710_EnableCompareLogic (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_DisableCompareLogic (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; - +INT i_APCI1710_DisableCompareLogic(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************************/ - /* Test if compare logic initialised */ + /* Test if compare logic initialised */ /*************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CompareLogicInit == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_DISABLE_COMPARE_INT; + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_CompareLogicInit == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 & + APCI1710_DISABLE_COMPARE_INT; /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + } else { /*********************************/ - /* Compare logic not initialised */ + /* Compare logic not initialised */ /*********************************/ - DPRINTK("Compare logic not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Compare logic not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* -+----------------------------------------------------------------------------+ -| Function Name : _INT_ i_APCI1710_EnableFrequencyMeasurement | -| (BYTE_ b_BoardHandle, | -| BYTE_ b_ModulNbr, | -| BYTE_ b_InterruptEnable) | -+----------------------------------------------------------------------------+ -| Task : Enables the frequency measurement function | -+----------------------------------------------------------------------------+ -| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | -| BYTE_ b_ModulNbr : Number of the module to be | -| configured (0 to 3) | -| BYTE_ b_InterruptEnable: Enable or disable the | -| interrupt. | -| APCI1710_ENABLE: | -| Enable the interrupt | -| APCI1710_DISABLE: | -| Disable the interrupt | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -1: The handle parameter of the board is wrong | -| -2: The selected module number is wrong | -| -3: Counter not initialised see function | -| "i_APCI1710_InitCounter" | -| -4: Frequency measurement logic not initialised. | -| See function "i_APCI1710_InitFrequencyMeasurement" | -| -5: Interrupt parameter is wrong | -| -6: Interrupt function not initialised. | -+----------------------------------------------------------------------------+ -*/ + +----------------------------------------------------------------------------+ + | Function Name : _INT_ i_APCI1710_EnableFrequencyMeasurement | + | (BYTE_ b_BoardHandle, | + | BYTE_ b_ModulNbr, | + | BYTE_ b_InterruptEnable) | + +----------------------------------------------------------------------------+ + | Task : Enables the frequency measurement function | + +----------------------------------------------------------------------------+ + | Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | + | BYTE_ b_ModulNbr : Number of the module to be | + | configured (0 to 3) | + | BYTE_ b_InterruptEnable: Enable or disable the | + | interrupt. | + | APCI1710_ENABLE: | + | Enable the interrupt | + | APCI1710_DISABLE: | + | Disable the interrupt | + +----------------------------------------------------------------------------+ + | Output Parameters : - | + +----------------------------------------------------------------------------+ + | Return Value : 0: No error | + | -1: The handle parameter of the board is wrong | + | -2: The selected module number is wrong | + | -3: Counter not initialised see function | + | "i_APCI1710_InitCounter" | + | -4: Frequency measurement logic not initialised. | + | See function "i_APCI1710_InitFrequencyMeasurement" | + | -5: Interrupt parameter is wrong | + | -6: Interrupt function not initialised. | + +----------------------------------------------------------------------------+ + */ + +INT i_APCI1710_EnableFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_InterruptEnable) +{ + INT i_ReturnValue = 0; -INT i_APCI1710_EnableFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_InterruptEnable) - { - INT i_ReturnValue = 0; - - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /********************************************/ - /* Test if frequency mesurement initialised */ + /* Test if frequency mesurement initialised */ /********************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_FrequencyMeasurementInit == 1) { /***************************/ - /* Test the interrupt mode */ + /* Test the interrupt mode */ /***************************/ - if ((b_InterruptEnable == APCI1710_DISABLE) || - (b_InterruptEnable == APCI1710_ENABLE)) - { + if ((b_InterruptEnable == APCI1710_DISABLE) || + (b_InterruptEnable == APCI1710_ENABLE)) + { /************************************/ - /* Enable the frequency measurement */ + /* Enable the frequency measurement */ /************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 | APCI1710_ENABLE_FREQUENCY; + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 | + APCI1710_ENABLE_FREQUENCY; /*********************************************/ - /* Disable or enable the frequency interrupt */ + /* Disable or enable the frequency interrupt */ /*********************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY_INT) | (b_InterruptEnable << 3); + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 = (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 & + APCI1710_DISABLE_FREQUENCY_INT) + | (b_InterruptEnable << 3); /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementEnable = 1; - } - else - { + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos. + ui_Address + 20 + + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag. + b_FrequencyMeasurementEnable = + 1; + } else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("Interrupt parameter is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Interrupt parameter is wrong\n"); + i_ReturnValue = -5; + } + } else { /***********************************************/ - /* Frequency measurement logic not initialised */ + /* Frequency measurement logic not initialised */ /***********************************************/ - DPRINTK("Frequency measurement logic not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Frequency measurement logic not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* -+----------------------------------------------------------------------------+ -| Function Name : _INT_ i_APCI1710_DisableFrequencyMeasurement | -| (BYTE_ b_BoardHandle, | -| BYTE_ b_ModulNbr) | -+----------------------------------------------------------------------------+ -| Task : Disables the frequency measurement function | -+----------------------------------------------------------------------------+ -| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | -| BYTE_ b_ModulNbr : Number of the module to be | -| configured (0 to 3) | -+----------------------------------------------------------------------------+ -| Output Parameters : - | -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -1: The handle parameter of the board is wrong | -| -2: The selected module number is wrong | -| -3: Counter not initialised see function | -| "i_APCI1710_InitCounter" | -| -4: Frequency measurement logic not initialised. | -| See function "i_APCI1710_InitFrequencyMeasurement" | -+----------------------------------------------------------------------------+ -*/ + +----------------------------------------------------------------------------+ + | Function Name : _INT_ i_APCI1710_DisableFrequencyMeasurement | + | (BYTE_ b_BoardHandle, | + | BYTE_ b_ModulNbr) | + +----------------------------------------------------------------------------+ + | Task : Disables the frequency measurement function | + +----------------------------------------------------------------------------+ + | Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | + | BYTE_ b_ModulNbr : Number of the module to be | + | configured (0 to 3) | + +----------------------------------------------------------------------------+ + | Output Parameters : - | + +----------------------------------------------------------------------------+ + | Return Value : 0: No error | + | -1: The handle parameter of the board is wrong | + | -2: The selected module number is wrong | + | -3: Counter not initialised see function | + | "i_APCI1710_InitCounter" | + | -4: Frequency measurement logic not initialised. | + | See function "i_APCI1710_InitFrequencyMeasurement" | + +----------------------------------------------------------------------------+ + */ + +INT i_APCI1710_DisableFrequencyMeasurement(comedi_device * dev, BYTE b_ModulNbr) +{ + INT i_ReturnValue = 0; -INT i_APCI1710_DisableFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr) - { - INT i_ReturnValue = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /********************************************/ - /* Test if frequency mesurement initialised */ + /* Test if frequency mesurement initialised */ /********************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_FrequencyMeasurementInit == 1) { /*************************************/ - /* Disable the frequency measurement */ + /* Disable the frequency measurement */ /*************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY - // Begin CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared - & APCI1710_DISABLE_FREQUENCY_INT; - // End CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 & + APCI1710_DISABLE_FREQUENCY + // Begin CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared + & APCI1710_DISABLE_FREQUENCY_INT; + // End CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); /*************************************/ - /* Disable the frequency measurement */ + /* Disable the frequency measurement */ /*************************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementEnable = 0; - } - else - { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag. + b_FrequencyMeasurementEnable = 0; + } else { /***********************************************/ - /* Frequency measurement logic not initialised */ + /* Frequency measurement logic not initialised */ /***********************************************/ - DPRINTK("Frequency measurement logic not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Frequency measurement logic not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /*########################################################################### */ @@ -4061,9 +4035,6 @@ INT i_APCI1710_DisableFrequencyMeasurement (comedi_device *dev, /*########################################################################### */ - - - /* +----------------------------------------------------------------------------+ | Function Name :INT i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s, @@ -4078,135 +4049,116 @@ comedi_insn *insn,lsampl_t *data) | | Return Value : +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnReadINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { UINT ui_ReadType; - INT i_ReturnValue=0; - - ui_ReadType=CR_CHAN(insn->chanspec); + INT i_ReturnValue = 0; - devpriv->tsk_Current=current; // Save the current process task structure - switch(ui_ReadType) - { + ui_ReadType = CR_CHAN(insn->chanspec); + + devpriv->tsk_Current = current; // Save the current process task structure + switch (ui_ReadType) { case APCI1710_INCCPT_READLATCHREGISTERSTATUS: - i_ReturnValue=i_APCI1710_ReadLatchRegisterStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_RANGE(insn->chanspec), - (PBYTE) &data[0]); - break; + i_ReturnValue = i_APCI1710_ReadLatchRegisterStatus(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_RANGE(insn->chanspec), (PBYTE) & data[0]); + break; case APCI1710_INCCPT_READLATCHREGISTERVALUE: - i_ReturnValue=i_APCI1710_ReadLatchRegisterValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_RANGE(insn->chanspec), - (PULONG) &data[0]); - printk("Latch Register Value %d\n",data[0]); - break; + i_ReturnValue = i_APCI1710_ReadLatchRegisterValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_RANGE(insn->chanspec), (PULONG) & data[0]); + printk("Latch Register Value %d\n", data[0]); + break; case APCI1710_INCCPT_READ16BITCOUNTERVALUE: - i_ReturnValue=i_APCI1710_Read16BitCounterValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) CR_RANGE(insn->chanspec), - (PUINT) &data[0]); - break; - + i_ReturnValue = i_APCI1710_Read16BitCounterValue(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) CR_RANGE(insn->chanspec), (PUINT) & data[0]); + break; + case APCI1710_INCCPT_READ32BITCOUNTERVALUE: - i_ReturnValue=i_APCI1710_Read32BitCounterValue (dev, - (BYTE) CR_AREF(insn->chanspec), - (PULONG) &data[0]); - break; - + i_ReturnValue = i_APCI1710_Read32BitCounterValue(dev, + (BYTE) CR_AREF(insn->chanspec), (PULONG) & data[0]); + break; + case APCI1710_INCCPT_GETINDEXSTATUS: - i_ReturnValue=i_APCI1710_GetIndexStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; - + i_ReturnValue = i_APCI1710_GetIndexStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; + case APCI1710_INCCPT_GETREFERENCESTATUS: - i_ReturnValue=i_APCI1710_GetReferenceStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; - + i_ReturnValue = i_APCI1710_GetReferenceStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; + case APCI1710_INCCPT_GETUASSTATUS: - i_ReturnValue=i_APCI1710_GetUASStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; - + i_ReturnValue = i_APCI1710_GetUASStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; + case APCI1710_INCCPT_GETCBSTATUS: - i_ReturnValue=i_APCI1710_GetCBStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; - + i_ReturnValue = i_APCI1710_GetCBStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; + case APCI1710_INCCPT_GET16BITCBSTATUS: - i_ReturnValue=i_APCI1710_Get16BitCBStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0], - (PBYTE) &data[1]); - break; - + i_ReturnValue = i_APCI1710_Get16BitCBStatus(dev, + (BYTE) CR_AREF(insn->chanspec), + (PBYTE) & data[0], (PBYTE) & data[1]); + break; + case APCI1710_INCCPT_GETUDSTATUS: - i_ReturnValue=i_APCI1710_GetUDStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - - break; - + i_ReturnValue = i_APCI1710_GetUDStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + + break; + case APCI1710_INCCPT_GETINTERRUPTUDLATCHEDSTATUS: - i_ReturnValue=i_APCI1710_GetInterruptUDLatchedStatus (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0]); - break; - + i_ReturnValue = i_APCI1710_GetInterruptUDLatchedStatus(dev, + (BYTE) CR_AREF(insn->chanspec), (PBYTE) & data[0]); + break; + case APCI1710_INCCPT_READFREQUENCYMEASUREMENT: - i_ReturnValue=i_APCI1710_ReadFrequencyMeasurement (dev, - (BYTE) CR_AREF(insn->chanspec), - (PBYTE) &data[0], - (PBYTE) &data[1], - (PULONG) &data[2]); - break; - - case APCI1710_INCCPT_READINTERRUPT: - data[0]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - + i_ReturnValue = i_APCI1710_ReadFrequencyMeasurement(dev, + (BYTE) CR_AREF(insn->chanspec), + (PBYTE) & data[0], + (PBYTE) & data[1], (PULONG) & data[2]); + break; + + case APCI1710_INCCPT_READINTERRUPT: + data[0] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; + /**************************/ /* Increment the read FIFO */ /***************************/ devpriv-> - s_InterruptParameters. - ui_Read = (devpriv->s_InterruptParameters. - ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - - - break; - + s_InterruptParameters. + ui_Read = (devpriv->s_InterruptParameters. + ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + + break; + default: printk("ReadType Parameter wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; - return (i_ReturnValue); + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; + return (i_ReturnValue); } - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_ReadLatchRegisterStatus | @@ -4241,76 +4193,63 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ReadLatchRegisterStatus (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg, - PBYTE pb_LatchStatus) - { - INT i_ReturnValue = 0; +INT i_APCI1710_ReadLatchRegisterStatus(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg, PBYTE pb_LatchStatus) +{ + INT i_ReturnValue = 0; DWORD dw_LatchReg; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************************/ - /* Test the latch register parameter */ + /* Test the latch register parameter */ /*************************************/ - if (b_LatchReg < 2) - { - dw_LatchReg=inl(devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); + if (b_LatchReg < 2) { + dw_LatchReg = inl(devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); - *pb_LatchStatus = (BYTE) ((dw_LatchReg >> (b_LatchReg * 4)) & 0x3); - } - else - { + *pb_LatchStatus = + (BYTE) ((dw_LatchReg >> (b_LatchReg * + 4)) & 0x3); + } else { /**************************************************/ - /* The selected latch register parameter is wrong */ + /* The selected latch register parameter is wrong */ /**************************************************/ - DPRINTK("The selected latch register parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected latch register parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -4341,73 +4280,60 @@ INT i_APCI1710_ReadLatchRegisterStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_ReadLatchRegisterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg, - PULONG pul_LatchValue) - { +INT i_APCI1710_ReadLatchRegisterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg, PULONG pul_LatchValue) +{ INT i_ReturnValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************************/ - /* Test the latch register parameter */ + /* Test the latch register parameter */ /*************************************/ - if (b_LatchReg < 2) - { - *pul_LatchValue=inl(devpriv->s_BoardInfos. - ui_Address + ((b_LatchReg + 1) * 4) + (64 * b_ModulNbr)); - - } - else - { + if (b_LatchReg < 2) { + *pul_LatchValue = inl(devpriv->s_BoardInfos. + ui_Address + ((b_LatchReg + 1) * 4) + + (64 * b_ModulNbr)); + + } else { /**************************************************/ - /* The selected latch register parameter is wrong */ + /* The selected latch register parameter is wrong */ /**************************************************/ - DPRINTK("The selected latch register parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected latch register parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -4438,85 +4364,75 @@ INT i_APCI1710_ReadLatchRegisterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_Read16BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SelectedCounter, - PUINT pui_CounterValue) - { - INT i_ReturnValue = 0; +INT i_APCI1710_Read16BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SelectedCounter, PUINT pui_CounterValue) +{ + INT i_ReturnValue = 0; DWORD dw_LathchValue = 0; - + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /******************************/ - /* Test the counter selection */ + /* Test the counter selection */ /******************************/ - if (b_SelectedCounter < 2) - { + if (b_SelectedCounter < 2) { /*********************/ - /* Latch the counter */ + /* Latch the counter */ /*********************/ - outl(1,devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); + outl(1, devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); /************************/ - /* Read the latch value */ + /* Read the latch value */ /************************/ - dw_LathchValue=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); + dw_LathchValue = inl(devpriv->s_BoardInfos. + ui_Address + 4 + (64 * b_ModulNbr)); - *pui_CounterValue = (UINT) ((dw_LathchValue >> (16 * b_SelectedCounter)) & 0xFFFFU); - } - else - { + *pui_CounterValue = + (UINT) ((dw_LathchValue >> (16 * + b_SelectedCounter)) & + 0xFFFFU); + } else { /**************************************************/ - /* The selected 16-Bit counter parameter is wrong */ + /* The selected 16-Bit counter parameter is wrong */ /**************************************************/ - DPRINTK("The selected 16-Bit counter parameter is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected 16-Bit counter parameter is wrong\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -4543,67 +4459,56 @@ INT i_APCI1710_Read16BitCounterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_Read32BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - PULONG pul_CounterValue) - { - INT i_ReturnValue = 0; - - +INT i_APCI1710_Read32BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, PULONG pul_CounterValue) +{ + INT i_ReturnValue = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*********************/ - /* Tatch the counter */ + /* Tatch the counter */ /*********************/ - outl(1,devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); + outl(1, devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); /************************/ - /* Read the latch value */ + /* Read the latch value */ /************************/ - *pul_CounterValue=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); - } - else - { + *pul_CounterValue = inl(devpriv->s_BoardInfos. + ui_Address + 4 + (64 * b_ModulNbr)); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -4630,77 +4535,63 @@ INT i_APCI1710_Read32BitCounterValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetIndexStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_IndexStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - +INT i_APCI1710_GetIndexStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_IndexStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*****************************/ - /* Test if index initialised */ + /* Test if index initialised */ /*****************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInit) - { - dw_StatusReg= inl(devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); - - *pb_IndexStatus = (BYTE) (dw_StatusReg & 1); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_IndexInit) { + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (64 * b_ModulNbr)); + + *pb_IndexStatus = (BYTE) (dw_StatusReg & 1); + } else { /*************************************************************/ - /* Index not initialised see function "i_APCI1710_InitIndex" */ + /* Index not initialised see function "i_APCI1710_InitIndex" */ /*************************************************************/ - DPRINTK("Index not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Index not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -4728,79 +4619,65 @@ INT i_APCI1710_GetIndexStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetReferenceStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_ReferenceStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - +INT i_APCI1710_GetReferenceStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_ReferenceStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*********************************/ - /* Test if reference initialised */ + /* Test if reference initialised */ /*********************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_ReferenceInit) - { - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 24 + (64 * b_ModulNbr)); - - *pb_ReferenceStatus = (BYTE) (~dw_StatusReg & 1); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_ReferenceInit) { + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 24 + (64 * b_ModulNbr)); + + *pb_ReferenceStatus = + (BYTE) (~dw_StatusReg & 1); + } else { /*********************************************************************/ - /* Reference not initialised see function "i_APCI1710_InitReference" */ + /* Reference not initialised see function "i_APCI1710_InitReference" */ /*********************************************************************/ - DPRINTK("Reference not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Reference not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -4826,60 +4703,50 @@ INT i_APCI1710_GetReferenceStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetUASStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UASStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - - +INT i_APCI1710_GetUASStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UASStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 24 + (64 * b_ModulNbr)); - - *pb_UASStatus = (BYTE) ((dw_StatusReg >> 1) & 1); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 24 + (64 * b_ModulNbr)); + + *pb_UASStatus = (BYTE) ((dw_StatusReg >> 1) & 1); + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; - return (i_ReturnValue); } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_GetCBStatus | @@ -4904,61 +4771,49 @@ INT i_APCI1710_GetUASStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetCBStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_CBStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - +INT i_APCI1710_GetCBStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_CBStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); - - *pb_CBStatus = (BYTE) (dw_StatusReg & 1); - - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModulNbr)); + + *pb_CBStatus = (BYTE) (dw_StatusReg & 1); + + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -4998,102 +4853,92 @@ INT i_APCI1710_GetCBStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_Get16BitCBStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_CBStatusCounter0, - PBYTE pb_CBStatusCounter1) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - +INT i_APCI1710_Get16BitCBStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_CBStatusCounter0, PBYTE pb_CBStatusCounter1) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*************************/ - /* Test if 2*16-Bit mode */ + /* Test if 2*16-Bit mode */ /*************************/ - if ((devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 & 0x10) == 0x10) - { + if ((devpriv->s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 & 0x10) == 0x10) { /*****************************/ - /* Test the Firmware version */ + /* Test the Firmware version */ /*****************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136) - { - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); - - *pb_CBStatusCounter1 = (BYTE) ((dw_StatusReg >> 0) & 1); - *pb_CBStatusCounter0 = (BYTE) ((dw_StatusReg >> 1) & 1); - } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136) - else - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & 0xFFFF) >= + 0x3136) { + dw_StatusReg = + inl(devpriv->s_BoardInfos. + ui_Address + 16 + + (64 * b_ModulNbr)); + + *pb_CBStatusCounter1 = + (BYTE) ((dw_StatusReg >> 0) & + 1); + *pb_CBStatusCounter0 = + (BYTE) ((dw_StatusReg >> 1) & + 1); + } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136) + else { /****************************/ - /* Firmware revision error */ + /* Firmware revision error */ /****************************/ - i_ReturnValue = -5; - } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136) - } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10) - else - { + i_ReturnValue = -5; + } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136) + } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10) + else { /********************************************/ - /* Counter not initialised to 2*16-bit mode */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised to 2*16-bit mode */ + /* "i_APCI1710_InitCounter" */ /********************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -4; - } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10) - } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -4; + } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10) + } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) + else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) - } // if (b_ModulNbr < 4) - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) + } // if (b_ModulNbr < 4) + else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } // if (b_ModulNbr < 4) + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } // if (b_ModulNbr < 4) return (i_ReturnValue); - } - - +} /* +----------------------------------------------------------------------------+ @@ -5121,59 +4966,49 @@ INT i_APCI1710_Get16BitCBStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetUDStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UDStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - - +INT i_APCI1710_GetUDStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UDStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 24 + (64 * b_ModulNbr)); - - *pb_UDStatus = (BYTE) ((dw_StatusReg >> 2) & 1); - - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 24 + (64 * b_ModulNbr)); + + *pb_UDStatus = (BYTE) ((dw_StatusReg >> 2) & 1); + + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -5205,313 +5040,324 @@ INT i_APCI1710_GetUDStatus (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetInterruptUDLatchedStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UDStatus) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; - +INT i_APCI1710_GetInterruptUDLatchedStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UDStatus) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /*********************************/ - /* Test if index interrupt occur */ + /* Test if index interrupt occur */ /*********************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInterruptOccur == 1) - { - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInterruptOccur = 0; - - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModulNbr)); - - *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 1); - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_IndexInterruptOccur == 1) { + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_IndexInterruptOccur = 0; + + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (64 * b_ModulNbr)); + + *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 1); + } else { /****************************/ - /* No index interrupt occur */ + /* No index interrupt occur */ /****************************/ - *pb_UDStatus = 2; - } - } - else - { + *pb_UDStatus = 2; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* -+----------------------------------------------------------------------------+ -| Function Name : _INT_ i_APCI1710_ReadFrequencyMeasurement | -| (BYTE_ b_BoardHandle, | -| BYTE_ b_ModulNbr, | -| PBYTE_ pb_Status, | -| PULONG_ pul_ReadValue) | -+----------------------------------------------------------------------------+ -| Task : Returns the status (pb_Status) and the number of | -| increments in the set time. | -| See function " i_APCI1710_InitFrequencyMeasurement " | -+----------------------------------------------------------------------------+ -| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | -| BYTE_ b_ModulNbr : Number of the module to be | -| configured (0 to 3) | -+----------------------------------------------------------------------------+ -| Output Parameters : PBYTE_ pb_Status : Returns the frequency | -| measurement status | -| 0 : Counting cycle not | -| started. | -| 1 : Counting cycle started. | -| 2 : Counting cycle stopped. | -| The measurement cycle is | -| completed. | -| PBYTE_ pb_UDStatus : 0 : Counter progress in the | -| selected mode down | -| 1 : Counter progress in the | -| selected mode up | -| PULONG_ pul_ReadValue : Return the number of | -| increments in the defined | -| time base. | -+----------------------------------------------------------------------------+ -| Return Value : 0: No error | -| -1: The handle parameter of the board is wrong | -| -2: The selected module number is wrong | -| -3: Counter not initialised see function | -| "i_APCI1710_InitCounter" | -| -4: Frequency measurement logic not initialised. | -| See function "i_APCI1710_InitFrequencyMeasurement" | -+----------------------------------------------------------------------------+ -*/ - -INT i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_Status, - PBYTE pb_UDStatus, - PULONG pul_ReadValue) - { - INT i_ReturnValue = 0; - UINT ui_16BitValue; + +----------------------------------------------------------------------------+ + | Function Name : _INT_ i_APCI1710_ReadFrequencyMeasurement | + | (BYTE_ b_BoardHandle, | + | BYTE_ b_ModulNbr, | + | PBYTE_ pb_Status, | + | PULONG_ pul_ReadValue) | + +----------------------------------------------------------------------------+ + | Task : Returns the status (pb_Status) and the number of | + | increments in the set time. | + | See function " i_APCI1710_InitFrequencyMeasurement " | + +----------------------------------------------------------------------------+ + | Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 | + | BYTE_ b_ModulNbr : Number of the module to be | + | configured (0 to 3) | + +----------------------------------------------------------------------------+ + | Output Parameters : PBYTE_ pb_Status : Returns the frequency | + | measurement status | + | 0 : Counting cycle not | + | started. | + | 1 : Counting cycle started. | + | 2 : Counting cycle stopped. | + | The measurement cycle is | + | completed. | + | PBYTE_ pb_UDStatus : 0 : Counter progress in the | + | selected mode down | + | 1 : Counter progress in the | + | selected mode up | + | PULONG_ pul_ReadValue : Return the number of | + | increments in the defined | + | time base. | + +----------------------------------------------------------------------------+ + | Return Value : 0: No error | + | -1: The handle parameter of the board is wrong | + | -2: The selected module number is wrong | + | -3: Counter not initialised see function | + | "i_APCI1710_InitCounter" | + | -4: Frequency measurement logic not initialised. | + | See function "i_APCI1710_InitFrequencyMeasurement" | + +----------------------------------------------------------------------------+ + */ + +INT i_APCI1710_ReadFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, + PBYTE pb_Status, PBYTE pb_UDStatus, PULONG pul_ReadValue) +{ + INT i_ReturnValue = 0; + UINT ui_16BitValue; DWORD dw_StatusReg; - - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_CounterInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1) { /********************************************/ - /* Test if frequency mesurement initialised */ + /* Test if frequency mesurement initialised */ /********************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag.b_FrequencyMeasurementInit == 1) { /******************/ - /* Test if enable */ + /* Test if enable */ /******************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_InitFlag. - b_FrequencyMeasurementEnable == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SiemensCounterInfo. + s_InitFlag. + b_FrequencyMeasurementEnable == 1) { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + 32 + (64 * b_ModulNbr)); + dw_StatusReg = + inl(devpriv->s_BoardInfos. + ui_Address + 32 + + (64 * b_ModulNbr)); /**************************/ - /* Test if frequency stop */ + /* Test if frequency stop */ /**************************/ - if (dw_StatusReg & 1) - { - *pb_Status = 2; - *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 3); + if (dw_StatusReg & 1) { + *pb_Status = 2; + *pb_UDStatus = + (BYTE) ((dw_StatusReg >> + 1) & 3); /******************/ - /* Read the value */ + /* Read the value */ /******************/ - *pul_ReadValue=inl(devpriv->s_BoardInfos. - ui_Address + 28 + (64 * b_ModulNbr)); - + *pul_ReadValue = + inl(devpriv-> + s_BoardInfos. + ui_Address + 28 + + (64 * b_ModulNbr)); - if (*pb_UDStatus == 0) - { + if (*pb_UDStatus == 0) { /*************************/ - /* Test the counter mode */ + /* Test the counter mode */ /*************************/ - if ((devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER) - { + if ((devpriv->s_ModuleInfo[b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER) { /****************************************/ - /* Test if 16-bit counter 1 pulse occur */ + /* Test if 16-bit counter 1 pulse occur */ /****************************************/ - if ((*pul_ReadValue & 0xFFFFU) != 0) - { - ui_16BitValue = (UINT) *pul_ReadValue & 0xFFFFU; - *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue); - } + if ((*pul_ReadValue & 0xFFFFU) != 0) { + ui_16BitValue + = + (UINT) + * + pul_ReadValue + & + 0xFFFFU; + *pul_ReadValue + = + (*pul_ReadValue + & + 0xFFFF0000UL) + | + (0xFFFFU + - + ui_16BitValue); + } /****************************************/ - /* Test if 16-bit counter 2 pulse occur */ + /* Test if 16-bit counter 2 pulse occur */ /****************************************/ - if ((*pul_ReadValue & 0xFFFF0000UL) != 0) - { - ui_16BitValue = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU); - *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16); - } - } - else - { - if (*pul_ReadValue != 0) - { - *pul_ReadValue = 0xFFFFFFFFUL - *pul_ReadValue; - } - } - } - else - { - if (*pb_UDStatus == 1) - { + if ((*pul_ReadValue & 0xFFFF0000UL) != 0) { + ui_16BitValue + = + (UINT) + ( + (*pul_ReadValue + >> + 16) + & + 0xFFFFU); + *pul_ReadValue + = + (*pul_ReadValue + & + 0xFFFFUL) + | + ( + (0xFFFFU - ui_16BitValue) << 16); + } + } else { + if (*pul_ReadValue != 0) { + *pul_ReadValue + = + 0xFFFFFFFFUL + - + *pul_ReadValue; + } + } + } else { + if (*pb_UDStatus == 1) { /****************************************/ - /* Test if 16-bit counter 2 pulse occur */ + /* Test if 16-bit counter 2 pulse occur */ /****************************************/ - if ((*pul_ReadValue & 0xFFFF0000UL) != 0) - { - ui_16BitValue = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU); - *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16); - } - } - else - { - if (*pb_UDStatus == 2) - { + if ((*pul_ReadValue & 0xFFFF0000UL) != 0) { + ui_16BitValue + = + (UINT) + ( + (*pul_ReadValue + >> + 16) + & + 0xFFFFU); + *pul_ReadValue + = + (*pul_ReadValue + & + 0xFFFFUL) + | + ( + (0xFFFFU - ui_16BitValue) << 16); + } + } else { + if (*pb_UDStatus + == 2) { /****************************************/ - /* Test if 16-bit counter 1 pulse occur */ + /* Test if 16-bit counter 1 pulse occur */ /****************************************/ - if ((*pul_ReadValue & 0xFFFFU) != 0) - { - ui_16BitValue = (UINT) *pul_ReadValue & 0xFFFFU; - *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue); - } + if ((*pul_ReadValue & 0xFFFFU) != 0) { + ui_16BitValue + = + (UINT) + * + pul_ReadValue + & + 0xFFFFU; + *pul_ReadValue + = + (*pul_ReadValue + & + 0xFFFF0000UL) + | + (0xFFFFU + - + ui_16BitValue); + } + } + } + } + } else { + *pb_Status = 1; + *pb_UDStatus = 0; + } + } else { + *pb_Status = 0; + *pb_UDStatus = 0; } - } - } - } - else - { - *pb_Status = 1; - *pb_UDStatus = 0; - } - } - else - { - *pb_Status = 0; - *pb_UDStatus = 0; - } - } - else - { + } else { /***********************************************/ - /* Frequency measurement logic not initialised */ + /* Frequency measurement logic not initialised */ /***********************************************/ - DPRINTK("Frequency measurement logic not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Frequency measurement logic not initialised\n"); + i_ReturnValue = -4; + } + } else { /****************************************/ - /* Counter not initialised see function */ - /* "i_APCI1710_InitCounter" */ + /* Counter not initialised see function */ + /* "i_APCI1710_InitCounter" */ /****************************************/ - DPRINTK("Counter not initialised\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Counter not initialised\n"); + i_ReturnValue = -3; + } + } else { /*************************************************/ - /* The selected module number parameter is wrong */ + /* The selected module number parameter is wrong */ /*************************************************/ - DPRINTK("The selected module number parameter is wrong\n"); - i_ReturnValue = -2; - } + DPRINTK("The selected module number parameter is wrong\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} diff --git a/comedi/drivers/addi-data/APCI1710_INCCPT.h b/comedi/drivers/addi-data/APCI1710_INCCPT.h index cdb8d0e1..09fb0b7f 100644 --- a/comedi/drivers/addi-data/APCI1710_INCCPT.h +++ b/comedi/drivers/addi-data/APCI1710_INCCPT.h @@ -22,7 +22,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - #define APCI1710_16BIT_COUNTER 0x10 #define APCI1710_32BIT_COUNTER 0x0 #define APCI1710_QUADRUPLE_MODE 0x0 @@ -51,13 +50,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1710_SOURCE_0 0x0 #define APCI1710_SOURCE_1 0x1 - - #define APCI1710_30MHZ 30 #define APCI1710_33MHZ 33 #define APCI1710_40MHZ 40 - #define APCI1710_ENABLE_LATCH_INT 0x80 #define APCI1710_DISABLE_LATCH_INT (~APCI1710_ENABLE_LATCH_INT) @@ -95,12 +91,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1710_REFERENCE_HIGH 0x40 #define APCI1710_REFERENCE_LOW (~APCI1710_REFERENCE_HIGH) +#define APCI1710_TOR_GATE_LOW 0x40 +#define APCI1710_TOR_GATE_HIGH (~APCI1710_TOR_GATE_LOW) - #define APCI1710_TOR_GATE_LOW 0x40 - #define APCI1710_TOR_GATE_HIGH (~APCI1710_TOR_GATE_LOW) - - -// INSN CONFIG +// INSN CONFIG #define APCI1710_INCCPT_INITCOUNTER 100 #define APCI1710_INCCPT_COUNTERAUTOTEST 101 #define APCI1710_INCCPT_INITINDEX 102 @@ -110,9 +104,9 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1710_INCCPT_INITFREQUENCYMEASUREMENT 106 // INSN READ -#define APCI1710_INCCPT_READLATCHREGISTERSTATUS 200 +#define APCI1710_INCCPT_READLATCHREGISTERSTATUS 200 #define APCI1710_INCCPT_READLATCHREGISTERVALUE 201 -#define APCI1710_INCCPT_READ16BITCOUNTERVALUE 202 +#define APCI1710_INCCPT_READ16BITCOUNTERVALUE 202 #define APCI1710_INCCPT_READ32BITCOUNTERVALUE 203 #define APCI1710_INCCPT_GETINDEXSTATUS 204 #define APCI1710_INCCPT_GETREFERENCESTATUS 205 @@ -138,193 +132,138 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1710_INCCPT_DISABLELATCHINTERRUPT 401 #define APCI1710_INCCPT_WRITE16BITCOUNTERVALUE 402 #define APCI1710_INCCPT_WRITE32BITCOUNTERVALUE 403 -#define APCI1710_INCCPT_ENABLEINDEX 404 +#define APCI1710_INCCPT_ENABLEINDEX 404 #define APCI1710_INCCPT_DISABLEINDEX 405 -#define APCI1710_INCCPT_ENABLECOMPARELOGIC 406 +#define APCI1710_INCCPT_ENABLECOMPARELOGIC 406 #define APCI1710_INCCPT_DISABLECOMPARELOGIC 407 #define APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT 408 #define APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT 409 +/************ Main Functions *************/ +INT i_APCI1710_InsnConfigINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -/************ Main Functions *************/ -INT i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnBitsINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -INT i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnWriteINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -INT i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnReadINCCPT(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /*********** Supplementary Functions********/ - // INSN CONFIG -INT i_APCI1710_InitCounter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_CounterRange, - BYTE b_FirstCounterModus, - BYTE b_FirstCounterOption, - BYTE b_SecondCounterModus, - BYTE b_SecondCounterOption); +INT i_APCI1710_InitCounter(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_CounterRange, + BYTE b_FirstCounterModus, + BYTE b_FirstCounterOption, + BYTE b_SecondCounterModus, BYTE b_SecondCounterOption); -INT i_APCI1710_CounterAutoTest (comedi_device *dev,PBYTE pb_TestStatus); +INT i_APCI1710_CounterAutoTest(comedi_device * dev, PBYTE pb_TestStatus); -INT i_APCI1710_InitIndex (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ReferenceAction, - BYTE b_IndexOperation, - BYTE b_AutoMode, - BYTE b_InterruptEnable); +INT i_APCI1710_InitIndex(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_ReferenceAction, + BYTE b_IndexOperation, BYTE b_AutoMode, BYTE b_InterruptEnable); -INT i_APCI1710_InitReference (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ReferenceLevel); +INT i_APCI1710_InitReference(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_ReferenceLevel); -INT i_APCI1710_InitExternalStrobe (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_ExternalStrobe, - BYTE b_ExternalStrobeLevel); +INT i_APCI1710_InitExternalStrobe(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_ExternalStrobe, BYTE b_ExternalStrobeLevel); -INT i_APCI1710_InitCompareLogic (comedi_device *dev, - BYTE b_ModulNbr, - UINT ui_CompareValue); - -INT i_APCI1710_InitFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PCIInputClock, - BYTE b_TimingUnity, - ULONG ul_TimingInterval, - PULONG pul_RealTimingInterval); +INT i_APCI1710_InitCompareLogic(comedi_device * dev, + BYTE b_ModulNbr, UINT ui_CompareValue); +INT i_APCI1710_InitFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PCIInputClock, + BYTE b_TimingUnity, + ULONG ul_TimingInterval, PULONG pul_RealTimingInterval); //INSN BITS -INT i_APCI1710_ClearCounterValue (comedi_device *dev, - BYTE b_ModulNbr); - -INT i_APCI1710_ClearAllCounterValue (comedi_device *dev); +INT i_APCI1710_ClearCounterValue(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_SetInputFilter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PCIInputClock, - BYTE b_Filter); +INT i_APCI1710_ClearAllCounterValue(comedi_device * dev); -INT i_APCI1710_LatchCounter (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg); +INT i_APCI1710_SetInputFilter(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_PCIInputClock, BYTE b_Filter); -INT i_APCI1710_SetIndexAndReferenceSource (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SourceSelection); +INT i_APCI1710_LatchCounter(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg); -INT i_APCI1710_SetDigitalChlOn (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_SetIndexAndReferenceSource(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SourceSelection); -INT i_APCI1710_SetDigitalChlOff (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_SetDigitalChlOn(comedi_device * dev, BYTE b_ModulNbr); +INT i_APCI1710_SetDigitalChlOff(comedi_device * dev, BYTE b_ModulNbr); // INSN WRITE -INT i_APCI1710_EnableLatchInterrupt (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_EnableLatchInterrupt(comedi_device * dev, BYTE b_ModulNbr); +INT i_APCI1710_DisableLatchInterrupt(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_DisableLatchInterrupt (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_Write16BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SelectedCounter, UINT ui_WriteValue); -INT i_APCI1710_Write16BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SelectedCounter, - UINT ui_WriteValue); +INT i_APCI1710_Write32BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, ULONG ul_WriteValue); -INT i_APCI1710_Write32BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - ULONG ul_WriteValue); +INT i_APCI1710_EnableIndex(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_EnableIndex (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_DisableIndex(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_DisableIndex (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_EnableCompareLogic(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_EnableCompareLogic (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_DisableCompareLogic(comedi_device * dev, BYTE b_ModulNbr); -INT i_APCI1710_DisableCompareLogic (comedi_device *dev, - BYTE b_ModulNbr); - -INT i_APCI1710_EnableFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_InterruptEnable); - -INT i_APCI1710_DisableFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr); +INT i_APCI1710_EnableFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_InterruptEnable); +INT i_APCI1710_DisableFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr); // INSN READ -INT i_APCI1710_ReadLatchRegisterStatus (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg, - PBYTE pb_LatchStatus); - -INT i_APCI1710_ReadLatchRegisterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_LatchReg, - PULONG pul_LatchValue); - -INT i_APCI1710_Read16BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_SelectedCounter, - PUINT pui_CounterValue); - -INT i_APCI1710_Read32BitCounterValue (comedi_device *dev, - BYTE b_ModulNbr, - PULONG pul_CounterValue); - -INT i_APCI1710_GetIndexStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_IndexStatus); - -INT i_APCI1710_GetReferenceStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_ReferenceStatus); - -INT i_APCI1710_GetUASStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UASStatus); - -INT i_APCI1710_GetCBStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_CBStatus); +INT i_APCI1710_ReadLatchRegisterStatus(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg, PBYTE pb_LatchStatus); -INT i_APCI1710_Get16BitCBStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_CBStatusCounter0, - PBYTE pb_CBStatusCounter1); +INT i_APCI1710_ReadLatchRegisterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_LatchReg, PULONG pul_LatchValue); -INT i_APCI1710_GetUDStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UDStatus); +INT i_APCI1710_Read16BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, BYTE b_SelectedCounter, PUINT pui_CounterValue); -INT i_APCI1710_GetInterruptUDLatchedStatus (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_UDStatus); +INT i_APCI1710_Read32BitCounterValue(comedi_device * dev, + BYTE b_ModulNbr, PULONG pul_CounterValue); -INT i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev, - BYTE b_ModulNbr, - PBYTE pb_Status, - PBYTE pb_UDStatus, - PULONG pul_ReadValue); +INT i_APCI1710_GetIndexStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_IndexStatus); +INT i_APCI1710_GetReferenceStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_ReferenceStatus); +INT i_APCI1710_GetUASStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UASStatus); +INT i_APCI1710_GetCBStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_CBStatus); +INT i_APCI1710_Get16BitCBStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_CBStatusCounter0, PBYTE pb_CBStatusCounter1); +INT i_APCI1710_GetUDStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UDStatus); +INT i_APCI1710_GetInterruptUDLatchedStatus(comedi_device * dev, + BYTE b_ModulNbr, PBYTE pb_UDStatus); +INT i_APCI1710_ReadFrequencyMeasurement(comedi_device * dev, + BYTE b_ModulNbr, + PBYTE pb_Status, PBYTE pb_UDStatus, PULONG pul_ReadValue); diff --git a/comedi/drivers/addi-data/APCI1710_Inp_cpt.c b/comedi/drivers/addi-data/APCI1710_Inp_cpt.c index e9f11c25..965f172b 100644 --- a/comedi/drivers/addi-data/APCI1710_Inp_cpt.c +++ b/comedi/drivers/addi-data/APCI1710_Inp_cpt.c @@ -123,198 +123,231 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_IntRegister; - - BYTE b_ModulNbr; - BYTE b_PulseEncoderNbr; - BYTE b_InputLevelSelection; - BYTE b_TriggerOutputAction; - ULONG ul_StartValue; - - b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); - b_PulseEncoderNbr =(BYTE) data[0]; - b_InputLevelSelection =(BYTE) data[1]; - b_TriggerOutputAction =(BYTE) data[2]; - ul_StartValue =(ULONG) data[3]; - i_ReturnValue =insn->n; - + BYTE b_ModulNbr; + BYTE b_PulseEncoderNbr; + BYTE b_InputLevelSelection; + BYTE b_TriggerOutputAction; + ULONG ul_StartValue; + + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_PulseEncoderNbr = (BYTE) data[0]; + b_InputLevelSelection = (BYTE) data[1]; + b_TriggerOutputAction = (BYTE) data[2]; + ul_StartValue = (ULONG) data[3]; + + i_ReturnValue = insn->n; /***********************************/ /* Test the selected module number */ /***********************************/ - if (b_ModulNbr <= 3) - { + if (b_ModulNbr <= 3) { /*************************/ - /* Test if pulse encoder */ + /* Test if pulse encoder */ /*************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & APCI1710_PULSE_ENCODER) == APCI1710_PULSE_ENCODER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + APCI1710_PULSE_ENCODER) == + APCI1710_PULSE_ENCODER) { /******************************************/ - /* Test the selected pulse encoder number */ + /* Test the selected pulse encoder number */ /******************************************/ - if (b_PulseEncoderNbr <= 3) - { + if (b_PulseEncoderNbr <= 3) { /************************/ - /* Test the input level */ + /* Test the input level */ /************************/ - if ((b_InputLevelSelection == 0) || (b_InputLevelSelection == 1)) - { + if ((b_InputLevelSelection == 0) + || (b_InputLevelSelection == 1)) { /*******************************************/ - /* Test the ouput TRIGGER action selection */ + /* Test the ouput TRIGGER action selection */ /*******************************************/ - if ((b_TriggerOutputAction <= 2) || (b_PulseEncoderNbr > 0)) - { - if (ul_StartValue > 1) - { - - dw_IntRegister= inl(devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr)); + if ((b_TriggerOutputAction <= 2) + || (b_PulseEncoderNbr > 0)) { + if (ul_StartValue > 1) { + + dw_IntRegister = + inl(devpriv-> + s_BoardInfos. + ui_Address + + 20 + + (64 * b_ModulNbr)); /***********************/ - /* Set the start value */ + /* Set the start value */ /***********************/ - - outl(ul_StartValue,devpriv->s_BoardInfos.ui_Address + (b_PulseEncoderNbr * 4) + (64 * b_ModulNbr)); + outl(ul_StartValue, + devpriv-> + s_BoardInfos. + ui_Address + + (b_PulseEncoderNbr + * 4) + + (64 * b_ModulNbr)); /***********************/ - /* Set the input level */ + /* Set the input level */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister & (0xFFFFFFFFUL - (1UL << (8 + b_PulseEncoderNbr)))) | - ((1UL & (~b_InputLevelSelection)) << (8 + b_PulseEncoderNbr)); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister & + (0xFFFFFFFFUL - + (1UL << (8 + b_PulseEncoderNbr)))) | ((1UL & (~b_InputLevelSelection)) << (8 + b_PulseEncoderNbr)); /*******************************/ - /* Test if output trigger used */ + /* Test if output trigger used */ /*******************************/ - if ((b_TriggerOutputAction > 0) && (b_PulseEncoderNbr > 1)) - { + if ((b_TriggerOutputAction > 0) && (b_PulseEncoderNbr > 1)) { /****************************/ - /* Enable the output action */ + /* Enable the output action */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister | - (1UL << (4 + b_PulseEncoderNbr)); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + | (1UL + << (4 + b_PulseEncoderNbr)); /*********************************/ - /* Set the output TRIGGER action */ + /* Set the output TRIGGER action */ /*********************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister & (0xFFFFFFFFUL - (1UL << (12 + b_PulseEncoderNbr)))) | - ((1UL & (b_TriggerOutputAction - 1)) << (12 + b_PulseEncoderNbr)); - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + & + (0xFFFFFFFFUL + - + (1UL << (12 + b_PulseEncoderNbr)))) | ((1UL & (b_TriggerOutputAction - 1)) << (12 + b_PulseEncoderNbr)); + } else { /*****************************/ - /* Disable the output action */ + /* Disable the output action */ /*****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister & (0xFFFFFFFFUL - (1UL << (4 + b_PulseEncoderNbr))); - } + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + & + (0xFFFFFFFFUL + - + (1UL << (4 + b_PulseEncoderNbr))); + } /*************************/ - /* Set the configuration */ + /* Set the configuration */ /*************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo.dw_SetRegister,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - s_PulseEncoderInfo [b_PulseEncoderNbr]. - b_PulseEncoderInit = 1; - } - else - { + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister, + devpriv-> + s_BoardInfos. + ui_Address + + 20 + + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + s_PulseEncoderInfo + [b_PulseEncoderNbr]. + b_PulseEncoderInit + = 1; + } else { /**************************************/ - /* Pulse encoder start value is wrong */ + /* Pulse encoder start value is wrong */ /**************************************/ - DPRINTK("Pulse encoder start value is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Pulse encoder start value is wrong\n"); + i_ReturnValue = -6; + } + } else { /****************************************************/ - /* Digital TRIGGER output action selection is wrong */ + /* Digital TRIGGER output action selection is wrong */ /****************************************************/ - DPRINTK("Digital TRIGGER output action selection is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Digital TRIGGER output action selection is wrong\n"); + i_ReturnValue = -5; + } + } else { /**********************************/ - /* Input level selection is wrong */ + /* Input level selection is wrong */ /**********************************/ - DPRINTK("Input level selection is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Input level selection is wrong\n"); + i_ReturnValue = -4; + } + } else { /************************************/ - /* Pulse encoder selection is wrong */ + /* Pulse encoder selection is wrong */ /************************************/ - DPRINTK("Pulse encoder selection is wrong\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Pulse encoder selection is wrong\n"); + i_ReturnValue = -3; + } + } else { /********************************************/ - /* The module is not a pulse encoder module */ + /* The module is not a pulse encoder module */ /********************************************/ - DPRINTK("The module is not a pulse encoder module\n"); - i_ReturnValue = -2; - } - } - else - { + DPRINTK("The module is not a pulse encoder module\n"); + i_ReturnValue = -2; + } + } else { /********************************************/ - /* The module is not a pulse encoder module */ + /* The module is not a pulse encoder module */ /********************************************/ - DPRINTK("The module is not a pulse encoder module\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("The module is not a pulse encoder module\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -381,216 +414,250 @@ INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice * +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + BYTE b_ModulNbr; + BYTE b_PulseEncoderNbr; + BYTE b_CycleSelection; + BYTE b_InterruptHandling; + BYTE b_Action; + + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_Action = (BYTE) data[0]; + b_PulseEncoderNbr = (BYTE) data[1]; + b_CycleSelection = (BYTE) data[2]; + b_InterruptHandling = (BYTE) data[3]; - INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - BYTE b_ModulNbr; - BYTE b_PulseEncoderNbr ; - BYTE b_CycleSelection ; - BYTE b_InterruptHandling; - BYTE b_Action; - - i_ReturnValue =insn->n; - b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); - b_Action =(BYTE) data[0]; - b_PulseEncoderNbr =(BYTE) data[1]; - b_CycleSelection =(BYTE) data[2]; - b_InterruptHandling =(BYTE) data[3]; - - - /***********************************/ /* Test the selected module number */ /***********************************/ - if (b_ModulNbr <= 3) - { + if (b_ModulNbr <= 3) { /******************************************/ - /* Test the selected pulse encoder number */ + /* Test the selected pulse encoder number */ /******************************************/ - if (b_PulseEncoderNbr <= 3) - { + if (b_PulseEncoderNbr <= 3) { /*************************************/ - /* Test if pulse encoder initialised */ + /* Test if pulse encoder initialised */ /*************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - s_PulseEncoderInfo [b_PulseEncoderNbr]. - b_PulseEncoderInit == 1) - { - switch(b_Action) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + s_PulseEncoderInfo[b_PulseEncoderNbr]. + b_PulseEncoderInit == 1) { + switch (b_Action) { - case APCI1710_ENABLE: + case APCI1710_ENABLE: /****************************/ - /* Test the cycle selection */ + /* Test the cycle selection */ /****************************/ - if (b_CycleSelection == APCI1710_CONTINUOUS || b_CycleSelection == APCI1710_SINGLE) - { + if (b_CycleSelection == + APCI1710_CONTINUOUS + || b_CycleSelection == + APCI1710_SINGLE) { /*******************************/ - /* Test the interrupt handling */ + /* Test the interrupt handling */ /*******************************/ - if (b_InterruptHandling == APCI1710_ENABLE || b_InterruptHandling == APCI1710_DISABLE) - { + if (b_InterruptHandling == + APCI1710_ENABLE + || b_InterruptHandling + == APCI1710_DISABLE) { /******************************/ - /* Test if interrupt not used */ + /* Test if interrupt not used */ /******************************/ - if (b_InterruptHandling == APCI1710_DISABLE) - { + if (b_InterruptHandling + == + APCI1710_DISABLE) + { /*************************/ - /* Disable the interrupt */ + /* Disable the interrupt */ /*************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr)); - } - else - { - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + & + (0xFFFFFFFFUL + - + (1UL << b_PulseEncoderNbr)); + } else { + /************************/ - /* Enable the interrupt */ + /* Enable the interrupt */ /************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister | (1UL << b_PulseEncoderNbr); - devpriv->tsk_Current=current; // Save the current process task structure - - - } - - if (i_ReturnValue>=0) - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister + | (1UL + << + b_PulseEncoderNbr); + devpriv->tsk_Current = current; // Save the current process task structure + + } + + if (i_ReturnValue >= 0) { /***********************************/ - /* Enable or disable the interrupt */ + /* Enable or disable the interrupt */ /***********************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_SetRegister,devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_SetRegister, + devpriv-> + s_BoardInfos. + ui_Address + + 20 + + (64 * b_ModulNbr)); /****************************/ - /* Enable the pulse encoder */ + /* Enable the pulse encoder */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister | (1UL << b_PulseEncoderNbr); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister + = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister + | (1UL + << + b_PulseEncoderNbr); /**********************/ - /* Set the cycle mode */ + /* Set the cycle mode */ /**********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister = (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister & (0xFFFFFFFFUL - (1 << (b_PulseEncoderNbr + 4)))) | - ((b_CycleSelection & 1UL) << (4 + b_PulseEncoderNbr)); + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister + = + (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister + & + (0xFFFFFFFFUL + - + (1 << (b_PulseEncoderNbr + 4)))) | ((b_CycleSelection & 1UL) << (4 + b_PulseEncoderNbr)); /****************************/ - /* Enable the pulse encoder */ + /* Enable the pulse encoder */ /****************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); - } - } - else - { + outl(devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister, + devpriv-> + s_BoardInfos. + ui_Address + + 16 + + (64 * b_ModulNbr)); + } + } else { /************************************/ - /* Interrupt handling mode is wrong */ + /* Interrupt handling mode is wrong */ /************************************/ - DPRINTK("Interrupt handling mode is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Interrupt handling mode is wrong\n"); + i_ReturnValue = -6; + } + } else { /*********************************/ - /* Cycle selection mode is wrong */ + /* Cycle selection mode is wrong */ /*********************************/ - DPRINTK("Cycle selection mode is wrong\n"); - i_ReturnValue = -5; - } - break; + DPRINTK("Cycle selection mode is wrong\n"); + i_ReturnValue = -5; + } + break; - case APCI1710_DISABLE: - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr)); + case APCI1710_DISABLE: + devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister = + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister & + (0xFFFFFFFFUL - + (1UL << b_PulseEncoderNbr)); /*****************************/ - /* Disable the pulse encoder */ + /* Disable the pulse encoder */ /*****************************/ - - outl(devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_ControlRegister,devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); + outl(devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_ControlRegister, + devpriv->s_BoardInfos. + ui_Address + 16 + + (64 * b_ModulNbr)); - break; - }// switch End + break; + } // switch End - } - else - { + } else { /*********************************/ - /* Pulse encoder not initialised */ + /* Pulse encoder not initialised */ /*********************************/ - DPRINTK("Pulse encoder not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Pulse encoder not initialised\n"); + i_ReturnValue = -4; + } + } else { /************************************/ - /* Pulse encoder selection is wrong */ + /* Pulse encoder selection is wrong */ /************************************/ - DPRINTK("Pulse encoder selection is wrong\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Pulse encoder selection is wrong\n"); + i_ReturnValue = -3; + } + } else { /*****************************/ - /* Module selection is wrong */ + /* Module selection is wrong */ /*****************************/ - DPRINTK("Module selection is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module selection is wrong\n"); + i_ReturnValue = -2; } - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -635,167 +702,160 @@ INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice * +----------------------------------------------------------------------------+ */ - /*_INT_ i_APCI1710_ReadPulseEncoderStatus (BYTE_ b_BoardHandle, BYTE_ b_ModulNbr, BYTE_ b_PulseEncoderNbr, PBYTE_ pb_Status) */ -INT i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_StatusRegister; - BYTE b_ModulNbr; - BYTE b_PulseEncoderNbr; - PBYTE pb_Status; - BYTE b_Type; + BYTE b_ModulNbr; + BYTE b_PulseEncoderNbr; + PBYTE pb_Status; + BYTE b_Type; PULONG pul_ReadValue; - ULONG ul_WriteValue ; - - i_ReturnValue=insn->n; - b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); - b_Type =(BYTE) data[0] ; - b_PulseEncoderNbr=(BYTE) data[1]; - pb_Status =(PBYTE) &data[0]; - pul_ReadValue =(PULONG) &data[1]; - + ULONG ul_WriteValue; + + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_Type = (BYTE) data[0]; + b_PulseEncoderNbr = (BYTE) data[1]; + pb_Status = (PBYTE) & data[0]; + pul_ReadValue = (PULONG) & data[1]; + /***********************************/ /* Test the selected module number */ /***********************************/ - if (b_ModulNbr <= 3) - { + if (b_ModulNbr <= 3) { /******************************************/ - /* Test the selected pulse encoder number */ + /* Test the selected pulse encoder number */ /******************************************/ - if (b_PulseEncoderNbr <= 3) - { + if (b_PulseEncoderNbr <= 3) { /*************************************/ - /* Test if pulse encoder initialised */ + /* Test if pulse encoder initialised */ /*************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - s_PulseEncoderInfo [b_PulseEncoderNbr]. - b_PulseEncoderInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + s_PulseEncoderInfo[b_PulseEncoderNbr]. + b_PulseEncoderInit == 1) { - switch(b_Type) - { - case APCI1710_PULSEENCODER_READ: + switch (b_Type) { + case APCI1710_PULSEENCODER_READ: /****************************/ - /* Read the status register */ + /* Read the status register */ /****************************/ - - dw_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModulNbr)); + dw_StatusRegister = + inl(devpriv->s_BoardInfos. + ui_Address + 16 + + (64 * b_ModulNbr)); - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_StatusRegister = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_StatusRegister | dw_StatusRegister; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_StatusRegister = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_StatusRegister | + dw_StatusRegister; - *pb_Status = (BYTE) (devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_StatusRegister >> (1 + b_PulseEncoderNbr)) & 1; + *pb_Status = + (BYTE) (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_StatusRegister >> (1 + + b_PulseEncoderNbr)) & 1; - devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_StatusRegister = devpriv->s_ModuleInfo [b_ModulNbr]. - s_PulseEncoderModuleInfo. - dw_StatusRegister & (0xFFFFFFFFUL - (1 << (1 + b_PulseEncoderNbr))); + devpriv->s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_StatusRegister = + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PulseEncoderModuleInfo. + dw_StatusRegister & + (0xFFFFFFFFUL - (1 << (1 + + b_PulseEncoderNbr))); /******************/ - /* Read the value */ + /* Read the value */ /******************/ - - *pul_ReadValue=inl(devpriv->s_BoardInfos. - ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr)); - break; + *pul_ReadValue = + inl(devpriv->s_BoardInfos. + ui_Address + + (4 * b_PulseEncoderNbr) + + (64 * b_ModulNbr)); + break; - case APCI1710_PULSEENCODER_WRITE: - ul_WriteValue = (ULONG) data[2]; + case APCI1710_PULSEENCODER_WRITE: + ul_WriteValue = (ULONG) data[2]; /*******************/ - /* Write the value */ + /* Write the value */ /*******************/ - - outl(ul_WriteValue,devpriv->s_BoardInfos. - ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr)); + outl(ul_WriteValue, + devpriv->s_BoardInfos. + ui_Address + + (4 * b_PulseEncoderNbr) + + (64 * b_ModulNbr)); - }//end of switch - } - else - { + } //end of switch + } else { /*********************************/ - /* Pulse encoder not initialised */ + /* Pulse encoder not initialised */ /*********************************/ - DPRINTK("Pulse encoder not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Pulse encoder not initialised\n"); + i_ReturnValue = -4; + } + } else { /************************************/ - /* Pulse encoder selection is wrong */ + /* Pulse encoder selection is wrong */ /************************************/ - DPRINTK("Pulse encoder selection is wrong\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("Pulse encoder selection is wrong\n"); + i_ReturnValue = -3; + } + } else { /*****************************/ - /* Module selection is wrong */ + /* Module selection is wrong */ /*****************************/ - DPRINTK("Module selection is wrong\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module selection is wrong\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} -INT i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1] = devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2] = devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; + /***************************/ /* Increment the read FIFO */ /***************************/ devpriv->s_InterruptParameters. - ui_Read = (devpriv-> - s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - - return insn->n; + ui_Read = (devpriv-> + s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + return insn->n; } - - - diff --git a/comedi/drivers/addi-data/APCI1710_Inp_cpt.h b/comedi/drivers/addi-data/APCI1710_Inp_cpt.h index 5edd3ad5..89e52577 100644 --- a/comedi/drivers/addi-data/APCI1710_Inp_cpt.h +++ b/comedi/drivers/addi-data/APCI1710_Inp_cpt.h @@ -22,32 +22,25 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ +#define APCI1710_SINGLE 0 +#define APCI1710_CONTINUOUS 1 - - #define APCI1710_SINGLE 0 - #define APCI1710_CONTINUOUS 1 - - -#define APCI1710_PULSEENCODER_READ 0 +#define APCI1710_PULSEENCODER_READ 0 #define APCI1710_PULSEENCODER_WRITE 1 +INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - - - -INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | READ PULSE ENCODER FUNCTIONS | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ @@ -55,7 +48,5 @@ INT i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevi +----------------------------------------------------------------------------+ */ - INT i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - +INT i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_Pwm.c b/comedi/drivers/addi-data/APCI1710_Pwm.c index 8cf1f28f..80a44696 100644 --- a/comedi/drivers/addi-data/APCI1710_Pwm.c +++ b/comedi/drivers/addi-data/APCI1710_Pwm.c @@ -53,11 +53,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - #include "APCI1710_Pwm.h" - - /* +----------------------------------------------------------------------------+ | Function Name :INT i_APCI1710_InsnConfigPWM(comedi_device *dev, @@ -73,55 +70,50 @@ comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnConfigPWM(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { BYTE b_ConfigType; - INT i_ReturnValue=0; - b_ConfigType=CR_CHAN(insn->chanspec); - - - switch(b_ConfigType) - { - case APCI1710_PWM_INIT : - i_ReturnValue=i_APCI1710_InitPWM (dev, - (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr - (BYTE) data[0], //b_PWM - (BYTE) data[1], // b_ClockSelection - (BYTE) data[2], // b_TimingUnit - (ULONG)data[3], //ul_LowTiming - (ULONG)data[4], //ul_HighTiming - (PULONG)&data[0], //pul_RealLowTiming - (PULONG)&data[1] //pul_RealHighTiming - ); + INT i_ReturnValue = 0; + b_ConfigType = CR_CHAN(insn->chanspec); + + switch (b_ConfigType) { + case APCI1710_PWM_INIT: + i_ReturnValue = i_APCI1710_InitPWM(dev, (BYTE) CR_AREF(insn->chanspec), // b_ModulNbr + (BYTE) data[0], //b_PWM + (BYTE) data[1], // b_ClockSelection + (BYTE) data[2], // b_TimingUnit + (ULONG) data[3], //ul_LowTiming + (ULONG) data[4], //ul_HighTiming + (PULONG) & data[0], //pul_RealLowTiming + (PULONG) & data[1] //pul_RealHighTiming + ); break; - case APCI1710_PWM_GETINITDATA : - i_ReturnValue=i_APCI1710_GetPWMInitialisation (dev, - (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr - (BYTE) data[0], //b_PWM - (PBYTE)&data[0], //pb_TimingUnit - (PULONG)&data[1], //pul_LowTiming - (PULONG)&data[2], //pul_HighTiming - (PBYTE) &data[3], // pb_StartLevel - (PBYTE) &data[4], // pb_StopMode - (PBYTE) &data[5], // pb_StopLevel - (PBYTE) &data[6], // pb_ExternGate - (PBYTE) &data[7], // pb_InterruptEnable - (PBYTE) &data[8] // pb_Enable - ); + case APCI1710_PWM_GETINITDATA: + i_ReturnValue = i_APCI1710_GetPWMInitialisation(dev, (BYTE) CR_AREF(insn->chanspec), // b_ModulNbr + (BYTE) data[0], //b_PWM + (PBYTE) & data[0], //pb_TimingUnit + (PULONG) & data[1], //pul_LowTiming + (PULONG) & data[2], //pul_HighTiming + (PBYTE) & data[3], // pb_StartLevel + (PBYTE) & data[4], // pb_StopMode + (PBYTE) & data[5], // pb_StopLevel + (PBYTE) & data[6], // pb_ExternGate + (PBYTE) & data[7], // pb_InterruptEnable + (PBYTE) & data[8] // pb_Enable + ); break; default: printk(" Config Parameter Wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_InitPWM | @@ -187,733 +179,1265 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InitPWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_ClockSelection, - BYTE b_TimingUnit, - ULONG ul_LowTiming, - ULONG ul_HighTiming, - PULONG pul_RealLowTiming, - PULONG pul_RealHighTiming) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InitPWM(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + BYTE b_ClockSelection, + BYTE b_TimingUnit, + ULONG ul_LowTiming, + ULONG ul_HighTiming, + PULONG pul_RealLowTiming, PULONG pul_RealHighTiming) +{ + INT i_ReturnValue = 0; ULONG ul_LowTimerValue = 0; ULONG ul_HighTimerValue = 0; DWORD dw_Command; double d_RealLowTiming = 0; double d_RealHighTiming = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /******************/ - /* Test the clock */ + /* Test the clock */ /******************/ - if ((b_ClockSelection == APCI1710_30MHZ) || - (b_ClockSelection == APCI1710_33MHZ) || - (b_ClockSelection == APCI1710_40MHZ)) - { + if ((b_ClockSelection == APCI1710_30MHZ) || + (b_ClockSelection == APCI1710_33MHZ) || + (b_ClockSelection == APCI1710_40MHZ)) { /************************/ - /* Test the timing unit */ + /* Test the timing unit */ /************************/ - if (b_TimingUnit <= 4) - { + if (b_TimingUnit <= 4) { /*********************************/ - /* Test the low timing selection */ + /* Test the low timing selection */ /*********************************/ - if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230650UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 9UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691043UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 520UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 8UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496729UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 7UL))) - { + if (((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 266) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571230650UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571230UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= 9UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 242) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 519691043UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 519691UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 520UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= 8UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 200) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429496729UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429496UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 7UL))) { /**********************************/ - /* Test the High timing selection */ + /* Test the High timing selection */ /**********************************/ - if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) - { + if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) { /**************************/ - /* Test the board version */ + /* Test the board version */ /**************************/ - if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv-> - s_BoardInfos. - b_BoardVersion > 0)) || - (b_ClockSelection != APCI1710_40MHZ)) - { + if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv->s_BoardInfos.b_BoardVersion > 0)) || (b_ClockSelection != APCI1710_40MHZ)) { /************************************/ - /* Calculate the low division fator */ + /* Calculate the low division fator */ /************************************/ - fpu_begin (); - - switch (b_TimingUnit) - { + fpu_begin + (); + + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (0.00025 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5)) - { - *pul_RealLowTiming = *pul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - - break; + *pul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (0.00025 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (0.00025 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) { + *pul_RealLowTiming + = + *pul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (0.25 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5)) - { - *pul_RealLowTiming = *pul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - - break; + *pul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (0.25 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + ( + (double) + 0.25 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) { + *pul_RealLowTiming + = + *pul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection); + ul_LowTimerValue + = + ul_LowTiming + * + (250.0 + * + b_ClockSelection); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5)) - { - *pul_RealLowTiming = *pul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; + *pul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250.0 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (250.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) { + *pul_RealLowTiming + = + *pul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: + case 3: /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5)) - { - *pul_RealLowTiming = *pul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - - break; + *pul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealLowTiming + 0.5)) { + *pul_RealLowTiming + = + *pul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + ( + (ul_LowTiming + * + 60) + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)(ul_LowTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60; - d_RealLowTiming = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0; - - if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealLowTiming + 0.5)) - { - *pul_RealLowTiming = *pul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; - } + *pul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60; + d_RealLowTiming + = + ( + (double) + ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60.0; + + if ((double)(((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)*pul_RealLowTiming + 0.5)) { + *pul_RealLowTiming + = + *pul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; + } /*************************************/ - /* Calculate the high division fator */ + /* Calculate the high division fator */ /*************************************/ - switch (b_TimingUnit) - { + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (0.00025 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5)) - { - *pul_RealHighTiming = *pul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - - break; + *pul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (0.00025 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (0.00025 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) { + *pul_RealHighTiming + = + *pul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (0.25 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5)) - { - *pul_RealHighTiming = *pul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - - break; + *pul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (0.25 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + ( + (double) + 0.25 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) { + *pul_RealHighTiming + = + *pul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection); + ul_HighTimerValue + = + ul_HighTiming + * + (250.0 + * + b_ClockSelection); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5)) - { - *pul_RealHighTiming = *pul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - - break; + *pul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250.0 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (250.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) { + *pul_RealHighTiming + = + *pul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: - + case 3: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5)) - { - *pul_RealHighTiming = *pul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - - break; + *pul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)*pul_RealHighTiming + 0.5)) { + *pul_RealHighTiming + = + *pul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + ( + (ul_HighTiming + * + 60) + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)(ul_HighTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60; - d_RealHighTiming = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0; - - if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealHighTiming + 0.5)) - { - *pul_RealHighTiming = *pul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - break; - } - - fpu_end (); + *pul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60; + d_RealHighTiming + = + ( + (double) + ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60.0; + + if ((double)(((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)*pul_RealHighTiming + 0.5)) { + *pul_RealHighTiming + = + *pul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; + } + + fpu_end(); /****************************/ - /* Save the clock selection */ + /* Save the clock selection */ /****************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - b_ClockSelection = b_ClockSelection; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + b_ClockSelection + = + b_ClockSelection; /************************/ - /* Save the timing unit */ + /* Save the timing unit */ /************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - b_TimingUnit = b_TimingUnit; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + b_TimingUnit + = + b_TimingUnit; /****************************/ - /* Save the low base timing */ + /* Save the low base timing */ /****************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - d_LowTiming = d_RealLowTiming; - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - ul_RealLowTiming = *pul_RealLowTiming; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + d_LowTiming + = + d_RealLowTiming; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + ul_RealLowTiming + = + *pul_RealLowTiming; /****************************/ - /* Save the high base timing */ + /* Save the high base timing */ /****************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - d_HighTiming = d_RealHighTiming; - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - ul_RealHighTiming = *pul_RealHighTiming; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + d_HighTiming + = + d_RealHighTiming; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + ul_RealHighTiming + = + *pul_RealHighTiming; /************************/ - /* Write the low timing */ + /* Write the low timing */ /************************/ - outl(ul_LowTimerValue,devpriv->s_BoardInfos. - ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(ul_LowTimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); /*************************/ - /* Write the high timing */ + /* Write the high timing */ /*************************/ - outl(ul_HighTimerValue,devpriv->s_BoardInfos. - ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(ul_HighTimerValue, devpriv->s_BoardInfos.ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); /***************************/ - /* Set the clock selection */ + /* Set the clock selection */ /***************************/ - dw_Command=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); - - dw_Command = dw_Command & 0x7F; - - if (b_ClockSelection == APCI1710_40MHZ) - { - dw_Command = dw_Command | 0x80; - } + dw_Command + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 8 + + + (20 * b_PWM) + (64 * b_ModulNbr)); + + dw_Command + = + dw_Command + & + 0x7F; + + if (b_ClockSelection == APCI1710_40MHZ) { + dw_Command + = + dw_Command + | + 0x80; + } /***************************/ - /* Set the clock selection */ + /* Set the clock selection */ /***************************/ - outl(dw_Command,devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); /*************/ - /* PWM init. */ + /* PWM init. */ /*************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - b_PWMInit = 1; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + b_PWMInit + = + 1; + } else { /***************************************************/ - /* You can not used the 40MHz clock selection with */ - /* this board */ + /* You can not used the 40MHz clock selection with */ + /* this board */ /***************************************************/ - DPRINTK("You can not used the 40MHz clock selection with this board\n"); - i_ReturnValue = -9; - } - } - else - { + DPRINTK("You can not used the 40MHz clock selection with this board\n"); + i_ReturnValue + = + -9; + } + } else { /***************************************/ - /* High base timing selection is wrong */ + /* High base timing selection is wrong */ /***************************************/ - DPRINTK("High base timing selection is wrong\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("High base timing selection is wrong\n"); + i_ReturnValue = + -8; + } + } else { /**************************************/ - /* Low base timing selection is wrong */ + /* Low base timing selection is wrong */ /**************************************/ - DPRINTK("Low base timing selection is wrong\n"); - i_ReturnValue = -7; - } - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - else - { + DPRINTK("Low base timing selection is wrong\n"); + i_ReturnValue = -7; + } + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + else { /**********************************/ - /* Timing unit selection is wrong */ + /* Timing unit selection is wrong */ /**********************************/ - DPRINTK("Timing unit selection is wrong\n"); - i_ReturnValue = -6; - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) - else - { + DPRINTK("Timing unit selection is wrong\n"); + i_ReturnValue = -6; + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) + else { /*******************************/ - /* The selected clock is wrong */ + /* The selected clock is wrong */ /*******************************/ - DPRINTK("The selected clock is wrong\n"); - i_ReturnValue = -5; - } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK("The selected clock is wrong\n"); + i_ReturnValue = -5; + } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1010,143 +1534,139 @@ INT i_APCI1710_InitPWM (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_GetPWMInitialisation (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - PBYTE pb_TimingUnit, - PULONG pul_LowTiming, - PULONG pul_HighTiming, - PBYTE pb_StartLevel, - PBYTE pb_StopMode, - PBYTE pb_StopLevel, - PBYTE pb_ExternGate, - PBYTE pb_InterruptEnable, - PBYTE pb_Enable) - { - INT i_ReturnValue = 0; +INT i_APCI1710_GetPWMInitialisation(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + PBYTE pb_TimingUnit, + PULONG pul_LowTiming, + PULONG pul_HighTiming, + PBYTE pb_StartLevel, + PBYTE pb_StopMode, + PBYTE pb_StopLevel, + PBYTE pb_ExternGate, PBYTE pb_InterruptEnable, PBYTE pb_Enable) +{ + INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_Command; - - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /***************************/ - /* Test if PWM initialised */ + /* Test if PWM initialised */ /***************************/ - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (20 * b_PWM) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /***********************/ - /* Read the low timing */ + /* Read the low timing */ /***********************/ - *pul_LowTiming = inl(devpriv->s_BoardInfos. - ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); + *pul_LowTiming = + inl(devpriv->s_BoardInfos. + ui_Address + 0 + (20 * b_PWM) + + (64 * b_ModulNbr)); /************************/ - /* Read the high timing */ + /* Read the high timing */ /************************/ - *pul_HighTiming= inl(devpriv->s_BoardInfos. - ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); + *pul_HighTiming = + inl(devpriv->s_BoardInfos. + ui_Address + 4 + (20 * b_PWM) + + (64 * b_ModulNbr)); /********************/ - /* Read the command */ + /* Read the command */ /********************/ - dw_Command = inl(devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); - - *pb_StartLevel = (BYTE) ((dw_Command >> 5) & 1); - *pb_StopMode = (BYTE) ((dw_Command >> 0) & 1); - *pb_StopLevel = (BYTE) ((dw_Command >> 1) & 1); - *pb_ExternGate = (BYTE) ((dw_Command >> 4) & 1); - *pb_InterruptEnable = (BYTE) ((dw_Command >> 3) & 1); - - if (*pb_StopLevel) - { - *pb_StopLevel = *pb_StopLevel + (BYTE) ((dw_Command >> 2) & 1); - } + dw_Command = inl(devpriv->s_BoardInfos. + ui_Address + 8 + (20 * b_PWM) + + (64 * b_ModulNbr)); + + *pb_StartLevel = + (BYTE) ((dw_Command >> 5) & 1); + *pb_StopMode = + (BYTE) ((dw_Command >> 0) & 1); + *pb_StopLevel = + (BYTE) ((dw_Command >> 1) & 1); + *pb_ExternGate = + (BYTE) ((dw_Command >> 4) & 1); + *pb_InterruptEnable = + (BYTE) ((dw_Command >> 3) & 1); + + if (*pb_StopLevel) { + *pb_StopLevel = + *pb_StopLevel + + (BYTE) ((dw_Command >> + 2) & 1); + } /********************/ - /* Read the command */ + /* Read the command */ /********************/ - dw_Command=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Command = inl(devpriv->s_BoardInfos. + ui_Address + 8 + (20 * b_PWM) + + (64 * b_ModulNbr)); - *pb_Enable = (BYTE) ((dw_Command >> 0) & 1); + *pb_Enable = + (BYTE) ((dw_Command >> 0) & 1); - *pb_TimingUnit = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - b_TimingUnit; - } // if (dw_Status & 0x10) - else - { + *pb_TimingUnit = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo[b_PWM].b_TimingUnit; + } // if (dw_Status & 0x10) + else { /***********************/ - /* PWM not initialised */ + /* PWM not initialised */ /***********************/ - DPRINTK("PWM not initialised\n"); - i_ReturnValue = -5; - } // if (dw_Status & 0x10) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK("PWM not initialised\n"); + i_ReturnValue = -5; + } // if (dw_Status & 0x10) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1163,55 +1683,44 @@ comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) +INT i_APCI1710_InsnWritePWM(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { BYTE b_WriteType; - INT i_ReturnValue=0; - b_WriteType=CR_CHAN(insn->chanspec); - - - switch(b_WriteType) - { - case APCI1710_PWM_ENABLE : - i_ReturnValue=i_APCI1710_EnablePWM (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1], - (BYTE) data[2], - (BYTE) data[3], - (BYTE) data[4], - (BYTE) data[5]); + INT i_ReturnValue = 0; + b_WriteType = CR_CHAN(insn->chanspec); + + switch (b_WriteType) { + case APCI1710_PWM_ENABLE: + i_ReturnValue = i_APCI1710_EnablePWM(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) data[0], + (BYTE) data[1], + (BYTE) data[2], + (BYTE) data[3], (BYTE) data[4], (BYTE) data[5]); break; - case APCI1710_PWM_DISABLE : - i_ReturnValue=i_APCI1710_DisablePWM (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0]); + case APCI1710_PWM_DISABLE: + i_ReturnValue = i_APCI1710_DisablePWM(dev, + (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0]); break; case APCI1710_PWM_NEWTIMING: - i_ReturnValue=i_APCI1710_SetNewPWMTiming (dev, - (BYTE) CR_AREF(insn->chanspec), - (BYTE) data[0], - (BYTE) data[1], - (ULONG) data[2], - (ULONG) data[3]); + i_ReturnValue = i_APCI1710_SetNewPWMTiming(dev, + (BYTE) CR_AREF(insn->chanspec), + (BYTE) data[0], + (BYTE) data[1], (ULONG) data[2], (ULONG) data[3]); break; - default: printk("Write Config Parameter Wrong\n"); } - if(i_ReturnValue>=0) i_ReturnValue =insn->n; + if (i_ReturnValue >= 0) + i_ReturnValue = insn->n; return (i_ReturnValue); } - - - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_EnablePWM | @@ -1297,212 +1806,231 @@ comedi_insn *insn,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI1710_EnablePWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_StartLevel, - BYTE b_StopMode, - BYTE b_StopLevel, - BYTE b_ExternGate, - BYTE b_InterruptEnable) - { - INT i_ReturnValue = 0; +INT i_APCI1710_EnablePWM(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + BYTE b_StartLevel, + BYTE b_StopMode, + BYTE b_StopLevel, BYTE b_ExternGate, BYTE b_InterruptEnable) +{ + INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_Command; - - devpriv->tsk_Current=current; // Save the current process task structure + devpriv->tsk_Current = current; // Save the current process task structure /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /***************************/ - /* Test if PWM initialised */ + /* Test if PWM initialised */ /***************************/ - dw_Status= inl(devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (20 * b_PWM) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /**********************************/ - /* Test the start level selection */ + /* Test the start level selection */ /**********************************/ - if (b_StartLevel <= 1) - { + if (b_StartLevel <= 1) { /**********************/ - /* Test the stop mode */ + /* Test the stop mode */ /**********************/ - if (b_StopMode <= 1) - { + if (b_StopMode <= 1) { /***********************/ - /* Test the stop level */ + /* Test the stop level */ /***********************/ - if (b_StopLevel <= 2) - { + if (b_StopLevel <= 2) { /*****************************/ - /* Test the extern gate mode */ + /* Test the extern gate mode */ /*****************************/ - if (b_ExternGate <= 1) - { + if (b_ExternGate + <= 1) { /*****************************/ - /* Test the interrupt action */ + /* Test the interrupt action */ /*****************************/ - if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) - { + if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) { /******************************************/ - /* Test if interrupt function initialised */ + /* Test if interrupt function initialised */ /******************************************/ /********************/ - /* Read the command */ + /* Read the command */ /********************/ - dw_Command=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); - - dw_Command = dw_Command & 0x80; + dw_Command + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 8 + + + (20 * b_PWM) + (64 * b_ModulNbr)); + + dw_Command + = + dw_Command + & + 0x80; /********************/ - /* Make the command */ + /* Make the command */ /********************/ - dw_Command = dw_Command | b_StopMode | (b_InterruptEnable << 3) | (b_ExternGate << 4) | (b_StartLevel << 5); - - if (b_StopLevel & 3) - { - dw_Command = dw_Command | 2; - - if (b_StopLevel & 2) - { - dw_Command = dw_Command | 4; - } - } - - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - b_InterruptEnable = b_InterruptEnable; + dw_Command + = + dw_Command + | + b_StopMode + | + (b_InterruptEnable + << + 3) + | + (b_ExternGate + << + 4) + | + (b_StartLevel + << + 5); + + if (b_StopLevel & 3) { + dw_Command + = + dw_Command + | + 2; + + if (b_StopLevel & 2) { + dw_Command + = + dw_Command + | + 4; + } + } + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + b_InterruptEnable + = + b_InterruptEnable; /*******************/ - /* Set the command */ + /* Set the command */ /*******************/ - outl(dw_Command,devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); /******************/ - /* Enable the PWM */ + /* Enable the PWM */ /******************/ - outl(1,devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); - } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) - else - { + outl(1, devpriv->s_BoardInfos.ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) + else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("Interrupt parameter is wrong\n"); - i_ReturnValue = -10; - } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) - } // if (b_ExternGate >= 0 && b_ExternGate <= 1) - else - { + DPRINTK("Interrupt parameter is wrong\n"); + i_ReturnValue + = + -10; + } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE) + } // if (b_ExternGate >= 0 && b_ExternGate <= 1) + else { /*****************************************/ - /* Extern gate signal selection is wrong */ + /* Extern gate signal selection is wrong */ /*****************************************/ - DPRINTK("Extern gate signal selection is wrong\n"); - i_ReturnValue = -9; - } // if (b_ExternGate >= 0 && b_ExternGate <= 1) - } // if (b_StopLevel >= 0 && b_StopLevel <= 2) - else - { + DPRINTK("Extern gate signal selection is wrong\n"); + i_ReturnValue + = + -9; + } // if (b_ExternGate >= 0 && b_ExternGate <= 1) + } // if (b_StopLevel >= 0 && b_StopLevel <= 2) + else { /*************************************/ - /* PWM stop level selection is wrong */ + /* PWM stop level selection is wrong */ /*************************************/ - DPRINTK("PWM stop level selection is wrong\n"); - i_ReturnValue = -8; - } // if (b_StopLevel >= 0 && b_StopLevel <= 2) - } // if (b_StopMode >= 0 && b_StopMode <= 1) - else - { + DPRINTK("PWM stop level selection is wrong\n"); + i_ReturnValue = + -8; + } // if (b_StopLevel >= 0 && b_StopLevel <= 2) + } // if (b_StopMode >= 0 && b_StopMode <= 1) + else { /************************************/ - /* PWM stop mode selection is wrong */ + /* PWM stop mode selection is wrong */ /************************************/ - DPRINTK("PWM stop mode selection is wrong\n"); - i_ReturnValue = -7; - } // if (b_StopMode >= 0 && b_StopMode <= 1) - } // if (b_StartLevel >= 0 && b_StartLevel <= 1) - else - { + DPRINTK("PWM stop mode selection is wrong\n"); + i_ReturnValue = -7; + } // if (b_StopMode >= 0 && b_StopMode <= 1) + } // if (b_StartLevel >= 0 && b_StartLevel <= 1) + else { /**************************************/ - /* PWM start level selection is wrong */ + /* PWM start level selection is wrong */ /**************************************/ - DPRINTK("PWM start level selection is wrong\n"); - i_ReturnValue = -6; - } // if (b_StartLevel >= 0 && b_StartLevel <= 1) - } // if (dw_Status & 0x10) - else - { + DPRINTK("PWM start level selection is wrong\n"); + i_ReturnValue = -6; + } // if (b_StartLevel >= 0 && b_StartLevel <= 1) + } // if (dw_Status & 0x10) + else { /***********************/ - /* PWM not initialised */ + /* PWM not initialised */ /***********************/ - DPRINTK("PWM not initialised\n"); - i_ReturnValue = -5; - } // if (dw_Status & 0x10) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK("PWM not initialised\n"); + i_ReturnValue = -5; + } // if (dw_Status & 0x10) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -1534,100 +2062,90 @@ INT i_APCI1710_EnablePWM (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_DisablePWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM) - { - INT i_ReturnValue = 0; +INT i_APCI1710_DisablePWM(comedi_device * dev, BYTE b_ModulNbr, BYTE b_PWM) +{ + INT i_ReturnValue = 0; DWORD dw_Status; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /***************************/ - /* Test if PWM initialised */ + /* Test if PWM initialised */ /***************************/ - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (20 * b_PWM) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /***********************/ - /* Test if PWM enabled */ + /* Test if PWM enabled */ /***********************/ - if (dw_Status & 0x1) - { + if (dw_Status & 0x1) { /*******************/ - /* Disable the PWM */ + /* Disable the PWM */ /*******************/ - outl(0,devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); - } // if (dw_Status & 0x1) - else - { + outl(0, devpriv->s_BoardInfos. + ui_Address + 12 + + (20 * b_PWM) + + (64 * b_ModulNbr)); + } // if (dw_Status & 0x1) + else { /*******************/ - /* PWM not enabled */ + /* PWM not enabled */ /*******************/ - DPRINTK("PWM not enabled\n"); - i_ReturnValue = -6; - } // if (dw_Status & 0x1) - } // if (dw_Status & 0x10) - else - { + DPRINTK("PWM not enabled\n"); + i_ReturnValue = -6; + } // if (dw_Status & 0x1) + } // if (dw_Status & 0x10) + else { /***********************/ - /* PWM not initialised */ + /* PWM not initialised */ /***********************/ - DPRINTK(" PWM not initialised\n"); - i_ReturnValue = -5; - } // if (dw_Status & 0x10) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK(" PWM not initialised\n"); + i_ReturnValue = -5; + } // if (dw_Status & 0x10) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -1671,15 +2189,12 @@ INT i_APCI1710_DisablePWM (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_SetNewPWMTiming (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_TimingUnit, - ULONG ul_LowTiming, - ULONG ul_HighTiming) - { - BYTE b_ClockSelection; - INT i_ReturnValue = 0; +INT i_APCI1710_SetNewPWMTiming(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, BYTE b_TimingUnit, ULONG ul_LowTiming, ULONG ul_HighTiming) +{ + BYTE b_ClockSelection; + INT i_ReturnValue = 0; ULONG ul_LowTimerValue = 0; ULONG ul_HighTimerValue = 0; ULONG ul_RealLowTiming = 0; @@ -1688,682 +2203,1216 @@ INT i_APCI1710_SetNewPWMTiming (comedi_device *dev, DWORD dw_Command; double d_RealLowTiming = 0; double d_RealHighTiming = 0; - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /***************************/ - /* Test if PWM initialised */ + /* Test if PWM initialised */ /***************************/ - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (20 * b_PWM) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { - b_ClockSelection = devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - b_ClockSelection; + if (dw_Status & 0x10) { + b_ClockSelection = devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_PWMModuleInfo. + b_ClockSelection; /************************/ - /* Test the timing unit */ + /* Test the timing unit */ /************************/ - if (b_TimingUnit <= 4) - { + if (b_TimingUnit <= 4) { /*********************************/ - /* Test the low timing selection */ + /* Test the low timing selection */ /*********************************/ - if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230650UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 9UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691043UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 520UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 8UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496729UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 7UL))) - { + if (((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 266) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571230650UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571230UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 571UL)) + || ((b_ClockSelection == + APCI1710_30MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= 9UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 242) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 519691043UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 519691UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 520UL)) + || ((b_ClockSelection == + APCI1710_33MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= 8UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 0) + && (ul_LowTiming + >= 200) + && (ul_LowTiming + <= + 0xFFFFFFFFUL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 1) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429496729UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 2) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429496UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 3) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 429UL)) + || ((b_ClockSelection == + APCI1710_40MHZ) + && (b_TimingUnit + == 4) + && (ul_LowTiming + >= 1) + && (ul_LowTiming + <= + 7UL))) { /**********************************/ - /* Test the High timing selection */ + /* Test the High timing selection */ /**********************************/ - if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || - ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || - ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || - ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) - { + if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) { /************************************/ - /* Calculate the low division fator */ + /* Calculate the low division fator */ /************************************/ - fpu_begin (); - switch (b_TimingUnit) - { + fpu_begin(); + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (0.00025 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5)) - { - ul_RealLowTiming = ul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - - break; + ul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (0.00025 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (0.00025 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) { + ul_RealLowTiming + = + ul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (0.25 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5)) - { - ul_RealLowTiming = ul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; + ul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (0.25 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + ( + (double) + 0.25 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) { + ul_RealLowTiming + = + ul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection); + ul_LowTimerValue + = + ul_LowTiming + * + (250.0 + * + b_ClockSelection); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5)) - { - ul_RealLowTiming = ul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; + ul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250.0 * (double)b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (250.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) { + ul_RealLowTiming + = + ul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: - + case 3: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + (ul_LowTiming + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)ul_LowTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)); - d_RealLowTiming = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5)) - { - ul_RealLowTiming = ul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; + ul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)); + d_RealLowTiming + = + (double) + ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealLowTiming + 0.5)) { + ul_RealLowTiming + = + ul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection)); + ul_LowTimerValue + = + (ULONG) + ( + (ul_LowTiming + * + 60) + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) - { - ul_LowTimerValue = ul_LowTimerValue + 1; - } + if ((double)((double)(ul_LowTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_LowTimerValue + 0.5))) { + ul_LowTimerValue + = + ul_LowTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60; - d_RealLowTiming = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0; - - if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealLowTiming + 0.5)) - { - ul_RealLowTiming = ul_RealLowTiming + 1; - } - - ul_LowTiming = ul_LowTiming - 1; - ul_LowTimerValue = ul_LowTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288); - } - - break; - } + ul_RealLowTiming + = + (ULONG) + (ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60; + d_RealLowTiming + = + ( + (double) + ul_LowTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60.0; + + if ((double)(((double)ul_LowTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)ul_RealLowTiming + 0.5)) { + ul_RealLowTiming + = + ul_RealLowTiming + + + 1; + } + + ul_LowTiming + = + ul_LowTiming + - + 1; + ul_LowTimerValue + = + ul_LowTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_LowTimerValue + = + (ULONG) + ( + (double) + (ul_LowTimerValue) + * + 1.007752288); + } + + break; + } /*************************************/ - /* Calculate the high division fator */ + /* Calculate the high division fator */ /*************************************/ - switch (b_TimingUnit) - { + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (0.00025 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (0.00025 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5)) - { - ul_RealHighTiming = ul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - - break; + ul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (0.00025 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (0.00025 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (0.00025 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) { + ul_RealHighTiming + = + ul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (0.25 * b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (0.25 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5)) - { - ul_RealHighTiming = ul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - break; + ul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (0.25 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + ( + (double) + 0.25 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (0.25 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) { + ul_RealHighTiming + = + ul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection); + ul_HighTimerValue + = + ul_HighTiming + * + (250.0 + * + b_ClockSelection); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (250.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5)) - { - ul_RealHighTiming = ul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - break; + ul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250.0 * (double)b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (250.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (250.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) { + ul_RealHighTiming + = + ul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: - + case 3: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + (ul_HighTiming + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)ul_HighTiming * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)); - d_RealHighTiming = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection); - - if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5)) - { - ul_RealHighTiming = ul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - break; + ul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)); + d_RealHighTiming + = + (double) + ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection); + + if ((double)((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) >= (double)((double)ul_RealHighTiming + 0.5)) { + ul_RealHighTiming + = + ul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection)); + ul_HighTimerValue + = + (ULONG) + ( + (ul_HighTiming + * + 60) + * + (250000.0 + * + b_ClockSelection)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5))) - { - ul_HighTimerValue = ul_HighTimerValue + 1; - } + if ((double)((double)(ul_HighTiming * 60.0) * (250000.0 * (double)b_ClockSelection)) >= ((double)((double)ul_HighTimerValue + 0.5))) { + ul_HighTimerValue + = + ul_HighTimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60; - d_RealHighTiming = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0; - - if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealHighTiming + 0.5)) - { - ul_RealHighTiming = ul_RealHighTiming + 1; - } - - ul_HighTiming = ul_HighTiming - 1; - ul_HighTimerValue = ul_HighTimerValue - 2; - - if (b_ClockSelection != APCI1710_40MHZ) - { - ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288); - } - - break; - } - - fpu_end (); - + ul_RealHighTiming + = + (ULONG) + (ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60; + d_RealHighTiming + = + ( + (double) + ul_HighTimerValue + / + (250000.0 + * + (double) + b_ClockSelection)) + / + 60.0; + + if ((double)(((double)ul_HighTimerValue / (250000.0 * (double)b_ClockSelection)) / 60.0) >= (double)((double)ul_RealHighTiming + 0.5)) { + ul_RealHighTiming + = + ul_RealHighTiming + + + 1; + } + + ul_HighTiming + = + ul_HighTiming + - + 1; + ul_HighTimerValue + = + ul_HighTimerValue + - + 2; + + if (b_ClockSelection != APCI1710_40MHZ) { + ul_HighTimerValue + = + (ULONG) + ( + (double) + (ul_HighTimerValue) + * + 1.007752288); + } + + break; + } + + fpu_end(); + /************************/ - /* Save the timing unit */ + /* Save the timing unit */ /************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - b_TimingUnit = b_TimingUnit; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + b_TimingUnit + = + b_TimingUnit; /****************************/ - /* Save the low base timing */ + /* Save the low base timing */ /****************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - d_LowTiming = d_RealLowTiming; - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - ul_RealLowTiming = ul_RealLowTiming; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + d_LowTiming + = + d_RealLowTiming; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + ul_RealLowTiming + = + ul_RealLowTiming; /****************************/ - /* Save the high base timing */ + /* Save the high base timing */ /****************************/ - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - d_HighTiming = d_RealHighTiming; - - devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_PWMModuleInfo. - s_PWMInfo [b_PWM]. - ul_RealHighTiming = ul_RealHighTiming; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + d_HighTiming + = + d_RealHighTiming; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_PWMModuleInfo. + s_PWMInfo + [b_PWM]. + ul_RealHighTiming + = + ul_RealHighTiming; /************************/ - /* Write the low timing */ + /* Write the low timing */ /************************/ - outl(ul_LowTimerValue,devpriv->s_BoardInfos. - ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(ul_LowTimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); /*************************/ - /* Write the high timing */ + /* Write the high timing */ /*************************/ - outl(ul_HighTimerValue,devpriv->s_BoardInfos. - ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); + outl(ul_HighTimerValue, devpriv->s_BoardInfos.ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); /***************************/ - /* Set the clock selection */ + /* Set the clock selection */ /***************************/ - dw_Command=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); - - dw_Command = dw_Command & 0x7F; - - if (b_ClockSelection == APCI1710_40MHZ) - { - dw_Command = dw_Command | 0x80; - } + dw_Command = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + 8 + + (20 * b_PWM) + (64 * b_ModulNbr)); + + dw_Command = + dw_Command + & 0x7F; + + if (b_ClockSelection == APCI1710_40MHZ) { + dw_Command + = + dw_Command + | + 0x80; + } /***************************/ - /* Set the clock selection */ + /* Set the clock selection */ /***************************/ - outl(dw_Command,devpriv->s_BoardInfos. - ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); - } - else - { + outl(dw_Command, + devpriv-> + s_BoardInfos. + ui_Address + + 8 + + (20 * b_PWM) + (64 * b_ModulNbr)); + } else { /***************************************/ - /* High base timing selection is wrong */ + /* High base timing selection is wrong */ /***************************************/ - DPRINTK("High base timing selection is wrong\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("High base timing selection is wrong\n"); + i_ReturnValue = + -8; + } + } else { /**************************************/ - /* Low base timing selection is wrong */ + /* Low base timing selection is wrong */ /**************************************/ - DPRINTK("Low base timing selection is wrong\n"); - i_ReturnValue = -7; - } - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - else - { + DPRINTK("Low base timing selection is wrong\n"); + i_ReturnValue = -7; + } + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + else { /**********************************/ - /* Timing unit selection is wrong */ + /* Timing unit selection is wrong */ /**********************************/ - DPRINTK("Timing unit selection is wrong\n"); - i_ReturnValue = -6; - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - } // if (dw_Status & 0x10) - else - { + DPRINTK("Timing unit selection is wrong\n"); + i_ReturnValue = -6; + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + } // if (dw_Status & 0x10) + else { /***********************/ - /* PWM not initialised */ + /* PWM not initialised */ /***********************/ - DPRINTK("PWM not initialised\n"); - i_ReturnValue = -5; - } // if (dw_Status & 0x10) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK("PWM not initialised\n"); + i_ReturnValue = -5; + } // if (dw_Status & 0x10) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -2411,142 +3460,129 @@ INT i_APCI1710_SetNewPWMTiming (comedi_device *dev, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_Status; +INT i_APCI1710_InsnReadGetPWMStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_Status; + + BYTE b_ModulNbr; + BYTE b_PWM; + PBYTE pb_PWMOutputStatus; + PBYTE pb_ExternGateStatus; - BYTE b_ModulNbr; - BYTE b_PWM; - PBYTE pb_PWMOutputStatus; - PBYTE pb_ExternGateStatus; - - i_ReturnValue = insn->n; - b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); - b_PWM =(BYTE) CR_CHAN(insn->chanspec); - pb_PWMOutputStatus =(PBYTE) &data[0]; - pb_ExternGateStatus =(PBYTE) &data[1]; + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_PWM = (BYTE) CR_CHAN(insn->chanspec); + pb_PWMOutputStatus = (PBYTE) & data[0]; + pb_ExternGateStatus = (PBYTE) & data[1]; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***************/ - /* Test if PWM */ + /* Test if PWM */ /***************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ - /* Test the PWM selection */ + /* Test the PWM selection */ /**************************/ - if (b_PWM <= 1) - { + if (b_PWM <= 1) { /***************************/ - /* Test if PWM initialised */ + /* Test if PWM initialised */ /***************************/ - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (20 * b_PWM) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /***********************/ - /* Test if PWM enabled */ + /* Test if PWM enabled */ /***********************/ - if (dw_Status & 0x1) - { - *pb_PWMOutputStatus = (BYTE) ((dw_Status >> 7) & 1); - *pb_ExternGateStatus = (BYTE) ((dw_Status >> 6) & 1); - } // if (dw_Status & 0x1) - else - { + if (dw_Status & 0x1) { + *pb_PWMOutputStatus = + (BYTE) ((dw_Status >> 7) + & 1); + *pb_ExternGateStatus = + (BYTE) ((dw_Status >> 6) + & 1); + } // if (dw_Status & 0x1) + else { /*******************/ - /* PWM not enabled */ + /* PWM not enabled */ /*******************/ - DPRINTK("PWM not enabled \n"); - i_ReturnValue = -6; - } // if (dw_Status & 0x1) - } // if (dw_Status & 0x10) - else - { + DPRINTK("PWM not enabled \n"); + i_ReturnValue = -6; + } // if (dw_Status & 0x1) + } // if (dw_Status & 0x10) + else { /***********************/ - /* PWM not initialised */ + /* PWM not initialised */ /***********************/ - DPRINTK("PWM not initialised\n"); - i_ReturnValue = -5; - } // if (dw_Status & 0x10) - } // if (b_PWM >= 0 && b_PWM <= 1) - else - { + DPRINTK("PWM not initialised\n"); + i_ReturnValue = -5; + } // if (dw_Status & 0x10) + } // if (b_PWM >= 0 && b_PWM <= 1) + else { /******************************/ - /* Tor PWM selection is wrong */ + /* Tor PWM selection is wrong */ /******************************/ - DPRINTK("Tor PWM selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_PWM >= 0 && b_PWM <= 1) - } - else - { + DPRINTK("Tor PWM selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_PWM >= 0 && b_PWM <= 1) + } else { /**********************************/ - /* The module is not a PWM module */ + /* The module is not a PWM module */ /**********************************/ - DPRINTK("The module is not a PWM module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a PWM module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} -INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - +INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - data[0]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - + data[0] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; + /**************************/ - /* Increment the read FIFO */ + /* Increment the read FIFO */ /***************************/ - devpriv-> - s_InterruptParameters. - ui_Read = (devpriv-> - s_InterruptParameters. - ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Read = (devpriv-> + s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - return insn->n; + return insn->n; } diff --git a/comedi/drivers/addi-data/APCI1710_Pwm.h b/comedi/drivers/addi-data/APCI1710_Pwm.h index afd28d30..4836f8a8 100644 --- a/comedi/drivers/addi-data/APCI1710_Pwm.h +++ b/comedi/drivers/addi-data/APCI1710_Pwm.h @@ -22,80 +22,58 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - - - - #define APCI1710_30MHZ 30 - #define APCI1710_33MHZ 33 - #define APCI1710_40MHZ 40 - +#define APCI1710_30MHZ 30 +#define APCI1710_33MHZ 33 +#define APCI1710_40MHZ 40 #define APCI1710_PWM_INIT 0 #define APCI1710_PWM_GETINITDATA 1 #define APCI1710_PWM_DISABLE 0 #define APCI1710_PWM_ENABLE 1 -#define APCI1710_PWM_NEWTIMING 2 - - - - -INT i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_InitPWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_ClockSelection, - BYTE b_TimingUnit, - ULONG ul_LowTiming, - ULONG ul_HighTiming, - PULONG pul_RealLowTiming, - PULONG pul_RealHighTiming); - -INT i_APCI1710_GetPWMInitialisation (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - PBYTE pb_TimingUnit, - PULONG pul_LowTiming, - PULONG pul_HighTiming, - PBYTE pb_StartLevel, - PBYTE pb_StopMode, - PBYTE pb_StopLevel, - PBYTE pb_ExternGate, - PBYTE pb_InterruptEnable, - PBYTE pb_Enable); - - - - -INT i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_EnablePWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_StartLevel, - BYTE b_StopMode, - BYTE b_StopLevel, - BYTE b_ExternGate, - BYTE b_InterruptEnable); - -INT i_APCI1710_SetNewPWMTiming (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM, - BYTE b_TimingUnit, - ULONG ul_LowTiming, - ULONG ul_HighTiming); - -INT i_APCI1710_DisablePWM (comedi_device *dev, - BYTE b_ModulNbr, - BYTE b_PWM); - -INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - -INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - +#define APCI1710_PWM_NEWTIMING 2 + +INT i_APCI1710_InsnConfigPWM(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +INT i_APCI1710_InitPWM(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + BYTE b_ClockSelection, + BYTE b_TimingUnit, + ULONG ul_LowTiming, + ULONG ul_HighTiming, + PULONG pul_RealLowTiming, PULONG pul_RealHighTiming); + +INT i_APCI1710_GetPWMInitialisation(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + PBYTE pb_TimingUnit, + PULONG pul_LowTiming, + PULONG pul_HighTiming, + PBYTE pb_StartLevel, + PBYTE pb_StopMode, + PBYTE pb_StopLevel, + PBYTE pb_ExternGate, PBYTE pb_InterruptEnable, PBYTE pb_Enable); + +INT i_APCI1710_InsnWritePWM(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +INT i_APCI1710_EnablePWM(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, + BYTE b_StartLevel, + BYTE b_StopMode, + BYTE b_StopLevel, BYTE b_ExternGate, BYTE b_InterruptEnable); + +INT i_APCI1710_SetNewPWMTiming(comedi_device * dev, + BYTE b_ModulNbr, + BYTE b_PWM, BYTE b_TimingUnit, ULONG ul_LowTiming, ULONG ul_HighTiming); + +INT i_APCI1710_DisablePWM(comedi_device * dev, BYTE b_ModulNbr, BYTE b_PWM); + +INT i_APCI1710_InsnReadGetPWMStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_Ssi.c b/comedi/drivers/addi-data/APCI1710_Ssi.c index 0a639b1d..bdce4bc6 100644 --- a/comedi/drivers/addi-data/APCI1710_Ssi.c +++ b/comedi/drivers/addi-data/APCI1710_Ssi.c @@ -60,7 +60,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - #include "APCI1710_Ssi.h" /* @@ -134,227 +133,226 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnConfigInitSSI(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + UINT ui_TimerValue; + BYTE b_ModulNbr, b_SSIProfile, b_PositionTurnLength, b_TurnCptLength, + b_PCIInputClock, b_SSICountingMode; + ULONG ul_SSIOutputClock; + + b_ModulNbr = CR_AREF(insn->chanspec); + b_SSIProfile = (BYTE) data[0]; + b_PositionTurnLength = (BYTE) data[1]; + b_TurnCptLength = (BYTE) data[2]; + b_PCIInputClock = (BYTE) data[3]; + ul_SSIOutputClock = (ULONG) data[4]; + b_SSICountingMode = (BYTE) data[5]; -INT i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - UINT ui_TimerValue; - BYTE b_ModulNbr,b_SSIProfile,b_PositionTurnLength,b_TurnCptLength,b_PCIInputClock,b_SSICountingMode; - ULONG ul_SSIOutputClock; - - b_ModulNbr = CR_AREF(insn->chanspec); - b_SSIProfile = (BYTE) data[0]; - b_PositionTurnLength= (BYTE) data[1]; - b_TurnCptLength = (BYTE) data[2]; - b_PCIInputClock = (BYTE) data[3]; - ul_SSIOutputClock = (ULONG) data[4]; - b_SSICountingMode = (BYTE) data[5]; - - i_ReturnValue = insn->n; + i_ReturnValue = insn->n; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if SSI counter */ + /* Test if SSI counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_SSI_COUNTER) { /*******************************/ - /* Test the SSI profile length */ + /* Test the SSI profile length */ /*******************************/ - // CG 22/03/00 b_SSIProfile >= 2 anstatt b_SSIProfile > 2 - if (b_SSIProfile >= 2 && b_SSIProfile < 33) - { + // CG 22/03/00 b_SSIProfile >= 2 anstatt b_SSIProfile > 2 + if (b_SSIProfile >= 2 && b_SSIProfile < 33) { /*************************************/ - /* Test the SSI position data length */ + /* Test the SSI position data length */ /*************************************/ - if (b_PositionTurnLength > 0 && b_PositionTurnLength < 32) - { + if (b_PositionTurnLength > 0 + && b_PositionTurnLength < 32) { /*****************************************/ - /* Test the SSI turn counter data length */ + /* Test the SSI turn counter data length */ /*****************************************/ - if (b_TurnCptLength > 0 && b_TurnCptLength < 32) - { + if (b_TurnCptLength > 0 + && b_TurnCptLength < 32) { /***************************/ - /* Test the profile length */ + /* Test the profile length */ /***************************/ - if ((b_TurnCptLength + b_PositionTurnLength) <= b_SSIProfile) - { + if ((b_TurnCptLength + + b_PositionTurnLength) + <= b_SSIProfile) { /****************************/ - /* Test the PCI input clock */ + /* Test the PCI input clock */ /****************************/ - if (b_PCIInputClock == APCI1710_30MHZ || b_PCIInputClock == APCI1710_33MHZ) - { + if (b_PCIInputClock == + APCI1710_30MHZ + || + b_PCIInputClock + == + APCI1710_33MHZ) + { /*************************/ - /* Test the output clock */ + /* Test the output clock */ /*************************/ - if ((b_PCIInputClock == APCI1710_30MHZ && - (ul_SSIOutputClock > 228 && ul_SSIOutputClock <= 5000000UL)) || - (b_PCIInputClock == APCI1710_33MHZ && - (ul_SSIOutputClock > 251 && ul_SSIOutputClock <= 5000000UL))) - { - if (b_SSICountingMode == APCI1710_BINARY_MODE || - b_SSICountingMode == APCI1710_GRAY_MODE) - { + if ((b_PCIInputClock == APCI1710_30MHZ && (ul_SSIOutputClock > 228 && ul_SSIOutputClock <= 5000000UL)) || (b_PCIInputClock == APCI1710_33MHZ && (ul_SSIOutputClock > 251 && ul_SSIOutputClock <= 5000000UL))) { + if (b_SSICountingMode == APCI1710_BINARY_MODE || b_SSICountingMode == APCI1710_GRAY_MODE) { /**********************/ - /* Save configuration */ + /* Save configuration */ /**********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_SSIProfile = b_SSIProfile; - - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_PositionTurnLength = b_PositionTurnLength; - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_TurnCptLength = b_TurnCptLength; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIProfile + = + b_SSIProfile; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_PositionTurnLength + = + b_PositionTurnLength; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_TurnCptLength + = + b_TurnCptLength; /*********************************/ - /* Initialise the profile length */ + /* Initialise the profile length */ /*********************************/ - if (b_SSICountingMode == APCI1710_BINARY_MODE) - { - - outl(b_SSIProfile + 1,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr)); - } - else - { - - outl(b_SSIProfile,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr)); - } + if (b_SSICountingMode == APCI1710_BINARY_MODE) { + + outl(b_SSIProfile + 1, devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr)); + } else { + + outl(b_SSIProfile, devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr)); + } /******************************/ - /* Calculate the output clock */ + /* Calculate the output clock */ /******************************/ - ui_TimerValue = (UINT) (((ULONG) (b_PCIInputClock) * 500000UL) / ul_SSIOutputClock); + ui_TimerValue + = + (UINT) + ( + ((ULONG) (b_PCIInputClock) * 500000UL) / ul_SSIOutputClock); /************************/ - /* Initialise the timer */ + /* Initialise the timer */ /************************/ - - outl(ui_TimerValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - + outl(ui_TimerValue, devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); /********************************/ - /* Initialise the counting mode */ + /* Initialise the counting mode */ /********************************/ - - outl(7 * b_SSICountingMode,devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr)); - - devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIInit = 1; - } - else - { + + outl(7 * b_SSICountingMode, devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr)); + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIInit + = + 1; + } else { /*****************************************************/ - /* The selected SSI counting mode parameter is wrong */ + /* The selected SSI counting mode parameter is wrong */ /*****************************************************/ - DPRINTK("The selected SSI counting mode parameter is wrong\n"); - i_ReturnValue = -9; - } - } - else - { + DPRINTK("The selected SSI counting mode parameter is wrong\n"); + i_ReturnValue + = + -9; + } + } else { /******************************************/ - /* The selected SSI output clock is wrong */ + /* The selected SSI output clock is wrong */ /******************************************/ - DPRINTK("The selected SSI output clock is wrong\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("The selected SSI output clock is wrong\n"); + i_ReturnValue + = + -8; + } + } else { /*****************************************/ - /* The selected PCI input clock is wrong */ + /* The selected PCI input clock is wrong */ /*****************************************/ - DPRINTK("The selected PCI input clock is wrong\n"); - i_ReturnValue = -7; - } - } - else - { + DPRINTK("The selected PCI input clock is wrong\n"); + i_ReturnValue = + -7; + } + } else { /********************************************/ - /* The selected SSI profile length is wrong */ + /* The selected SSI profile length is wrong */ /********************************************/ - DPRINTK("The selected SSI profile length is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected SSI profile length is wrong\n"); + i_ReturnValue = -4; + } + } else { /******************************************************/ - /* The selected SSI turn counter data length is wrong */ + /* The selected SSI turn counter data length is wrong */ /******************************************************/ - DPRINTK("The selected SSI turn counter data length is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("The selected SSI turn counter data length is wrong\n"); + i_ReturnValue = -6; + } + } else { /**************************************************/ - /* The selected SSI position data length is wrong */ + /* The selected SSI position data length is wrong */ /**************************************************/ - DPRINTK("The selected SSI position data length is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("The selected SSI position data length is wrong\n"); + i_ReturnValue = -5; + } + } else { /********************************************/ - /* The selected SSI profile length is wrong */ + /* The selected SSI profile length is wrong */ /********************************************/ - DPRINTK("The selected SSI profile length is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected SSI profile length is wrong\n"); + i_ReturnValue = -4; + } + } else { /**********************************/ - /* The module is not a SSI module */ + /* The module is not a SSI module */ /**********************************/ - DPRINTK("The module is not a SSI module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a SSI module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -402,256 +400,303 @@ pul_Position = (PULONG) &data[0]; +----------------------------------------------------------------------------+ */ - INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - BYTE b_Cpt; - BYTE b_Length; - BYTE b_Schift; - BYTE b_SSICpt; +INT i_APCI1710_InsnReadSSIValue(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + BYTE b_Cpt; + BYTE b_Length; + BYTE b_Schift; + BYTE b_SSICpt; DWORD dw_And; DWORD dw_And1; DWORD dw_And2; DWORD dw_StatusReg; DWORD dw_CounterValue; - BYTE b_ModulNbr; - BYTE b_SelectedSSI; - BYTE b_ReadType; + BYTE b_ModulNbr; + BYTE b_SelectedSSI; + BYTE b_ReadType; PULONG pul_Position; PULONG pul_TurnCpt; PULONG pul_Position1; PULONG pul_TurnCpt1; - - i_ReturnValue = insn->n; - pul_Position1 = (PULONG) &data[0]; + i_ReturnValue = insn->n; + pul_Position1 = (PULONG) & data[0]; // For Read1 - pul_TurnCpt1 = (PULONG) &data[1]; + pul_TurnCpt1 = (PULONG) & data[1]; // For Read all - pul_Position = (PULONG) &data[0];//0-2 - pul_TurnCpt = (PULONG) &data[3];//3-5 - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_SelectedSSI = (BYTE) CR_CHAN(insn->chanspec); - b_ReadType = (BYTE) CR_RANGE(insn->chanspec); + pul_Position = (PULONG) & data[0]; //0-2 + pul_TurnCpt = (PULONG) & data[3]; //3-5 + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_SelectedSSI = (BYTE) CR_CHAN(insn->chanspec); + b_ReadType = (BYTE) CR_RANGE(insn->chanspec); /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if SSI counter */ + /* Test if SSI counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_SSI_COUNTER) { /***************************/ - /* Test if SSI initialised */ + /* Test if SSI initialised */ /***************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_SSIInit == 1) - { - - switch(b_ReadType) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_SSICounterInfo.b_SSIInit == 1) { + + switch (b_ReadType) { - case APCI1710_SSI_READ1VALUE : + case APCI1710_SSI_READ1VALUE: /****************************************/ - /* Test the selected SSI counter number */ + /* Test the selected SSI counter number */ /****************************************/ - if (b_SelectedSSI < 3) - { + if (b_SelectedSSI < 3) { /************************/ - /* Start the conversion */ + /* Start the conversion */ /************************/ + outl(0, devpriv->s_BoardInfos. + ui_Address + 8 + + (64 * b_ModulNbr)); - outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr)); - - - do - { + do { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - } - while ((dw_StatusReg & 0x1) != 0); + + dw_StatusReg = + inl(devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + } + while ((dw_StatusReg & 0x1) != + 0); /******************************/ - /* Read the SSI counter value */ + /* Read the SSI counter value */ /******************************/ - - dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SelectedSSI * 4) + (64 * b_ModulNbr)); - - b_Length = devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile / 2; - - if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile) - { - b_Length ++; - } - - b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_PositionTurnLength; - - - *pul_Position1 = dw_CounterValue >> b_Schift; - - dw_And = 1; - - for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_PositionTurnLength; b_Cpt ++) - { - dw_And = dw_And * 2; - } - *pul_Position1 = *pul_Position1 & ((dw_And) - 1); - - *pul_TurnCpt1 = dw_CounterValue >> b_Length; - - dw_And = 1; - - for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_TurnCptLength; b_Cpt ++) - { - dw_And = dw_And * 2; - } - - *pul_TurnCpt1 = *pul_TurnCpt1 & ((dw_And) - 1); - } - else - { + dw_CounterValue = + inl(devpriv-> + s_BoardInfos. + ui_Address + 4 + + (b_SelectedSSI * 4) + + (64 * b_ModulNbr)); + + b_Length = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIProfile / 2; + + if ((b_Length * 2) != + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIProfile) { + b_Length++; + } + + b_Schift = + b_Length - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_PositionTurnLength; + + *pul_Position1 = + dw_CounterValue >> + b_Schift; + + dw_And = 1; + + for (b_Cpt = 0; + b_Cpt < + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_PositionTurnLength; + b_Cpt++) { + dw_And = dw_And * 2; + } + + *pul_Position1 = + *pul_Position1 & + ((dw_And) - 1); + + *pul_TurnCpt1 = + dw_CounterValue >> + b_Length; + + dw_And = 1; + + for (b_Cpt = 0; + b_Cpt < + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_TurnCptLength; + b_Cpt++) { + dw_And = dw_And * 2; + } + + *pul_TurnCpt1 = + *pul_TurnCpt1 & + ((dw_And) - 1); + } else { /*****************************/ - /* The selected SSI is wrong */ + /* The selected SSI is wrong */ /*****************************/ - DPRINTK("The selected SSI is wrong\n"); - i_ReturnValue = -5; - } - break; - - case APCI1710_SSI_READALLVALUE : - dw_And1 = 1; - - for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_PositionTurnLength; b_Cpt ++) - { - dw_And1 = dw_And1 * 2; - } - - dw_And2 = 1; + DPRINTK("The selected SSI is wrong\n"); + i_ReturnValue = -5; + } + break; - for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_TurnCptLength; b_Cpt ++) - { - dw_And2 = dw_And2 * 2; - } + case APCI1710_SSI_READALLVALUE: + dw_And1 = 1; + + for (b_Cpt = 0; + b_Cpt < + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SSICounterInfo. + b_PositionTurnLength; b_Cpt++) { + dw_And1 = dw_And1 * 2; + } + + dw_And2 = 1; + + for (b_Cpt = 0; + b_Cpt < + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_SSICounterInfo. + b_TurnCptLength; b_Cpt++) { + dw_And2 = dw_And2 * 2; + } /************************/ - /* Start the conversion */ + /* Start the conversion */ /************************/ - - outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr)); - do - { + outl(0, devpriv->s_BoardInfos. + ui_Address + 8 + + (64 * b_ModulNbr)); + + do { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - } - while ((dw_StatusReg & 0x1) != 0); - for (b_SSICpt = 0; b_SSICpt < 3; b_SSICpt ++) - { + dw_StatusReg = + inl(devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + } + while ((dw_StatusReg & 0x1) != 0); + + for (b_SSICpt = 0; b_SSICpt < 3; + b_SSICpt++) { /******************************/ - /* Read the SSI counter value */ + /* Read the SSI counter value */ /******************************/ - - dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SSICpt * 4) + (64 * b_ModulNbr)); - - b_Length = devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_SSIProfile / 2; - - if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_SSIProfile) - { - b_Length ++; - } - - b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr]. - s_SSICounterInfo. - b_PositionTurnLength; - - - pul_Position [b_SSICpt] = dw_CounterValue >> b_Schift; - pul_Position [b_SSICpt] = pul_Position [b_SSICpt] & ((dw_And1) - 1); - - pul_TurnCpt [b_SSICpt] = dw_CounterValue >> b_Length; - pul_TurnCpt [b_SSICpt] = pul_TurnCpt [b_SSICpt] & ((dw_And2) - 1); - } - break; + dw_CounterValue = + inl(devpriv-> + s_BoardInfos. + ui_Address + 4 + + (b_SSICpt * 4) + + (64 * b_ModulNbr)); + + b_Length = + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIProfile / 2; + + if ((b_Length * 2) != + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_SSIProfile) { + b_Length++; + } + + b_Schift = + b_Length - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_SSICounterInfo. + b_PositionTurnLength; + + pul_Position[b_SSICpt] = + dw_CounterValue >> + b_Schift; + pul_Position[b_SSICpt] = + pul_Position[b_SSICpt] & + ((dw_And1) - 1); + + pul_TurnCpt[b_SSICpt] = + dw_CounterValue >> + b_Length; + pul_TurnCpt[b_SSICpt] = + pul_TurnCpt[b_SSICpt] & + ((dw_And2) - 1); + } + break; - default : - printk("Read Type Inputs Wrong\n"); + default: + printk("Read Type Inputs Wrong\n"); - } // switch ending + } // switch ending - } - else - { + } else { /***********************/ - /* SSI not initialised */ + /* SSI not initialised */ /***********************/ - DPRINTK("SSI not initialised\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("SSI not initialised\n"); + i_ReturnValue = -4; + } + } else { /**********************************/ - /* The module is not a SSI module */ + /* The module is not a SSI module */ /**********************************/ - DPRINTK("The module is not a SSI module\n"); - i_ReturnValue = -3; - - } - } - else - { + DPRINTK("The module is not a SSI module\n"); + i_ReturnValue = -3; + + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -690,121 +735,114 @@ pul_Position = (PULONG) &data[0]; +----------------------------------------------------------------------------+ */ - - -INT i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, -lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg; - BYTE b_ModulNbr; - BYTE b_InputChannel; - PBYTE pb_ChannelStatus; - PBYTE pb_InputStatus; - BYTE b_IOType; +INT i_APCI1710_InsnBitsSSIDigitalIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg; + BYTE b_ModulNbr; + BYTE b_InputChannel; + PBYTE pb_ChannelStatus; + PBYTE pb_InputStatus; + BYTE b_IOType; i_ReturnValue = insn->n; - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_IOType = (BYTE) data[0]; - + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_IOType = (BYTE) data[0]; + /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if SSI counter */ + /* Test if SSI counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER) - { - switch(b_IOType) - { - case APCI1710_SSI_SET_CHANNELON : + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_SSI_COUNTER) { + switch (b_IOType) { + case APCI1710_SSI_SET_CHANNELON: /*****************************/ - /* Set the digital output ON */ + /* Set the digital output ON */ /*****************************/ - - outl(1,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr)); - break ; + outl(1, devpriv->s_BoardInfos.ui_Address + 16 + + (64 * b_ModulNbr)); + break; - case APCI1710_SSI_SET_CHANNELOFF : + case APCI1710_SSI_SET_CHANNELOFF: /******************************/ - /* Set the digital output OFF */ + /* Set the digital output OFF */ /******************************/ - - outl(0,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr)); - break ; - - - - case APCI1710_SSI_READ_1CHANNEL: - /******************************************/ - /* Test the digital imnput channel number */ - /******************************************/ - - b_InputChannel = (BYTE) CR_CHAN(insn->chanspec); - pb_ChannelStatus = (PBYTE) &data[0]; - - if (b_InputChannel <= 2) - { - /**************************/ - /* Read all digital input */ - /**************************/ - - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - *pb_ChannelStatus = (BYTE) (((~dw_StatusReg) >> (4 + b_InputChannel)) & 1); - } - else - { - /********************************/ - /* Selected digital input error */ - /********************************/ - - DPRINTK("Selected digital input error\n"); - i_ReturnValue = -4; - } - break; + outl(0, devpriv->s_BoardInfos.ui_Address + 16 + + (64 * b_ModulNbr)); + break; + + case APCI1710_SSI_READ_1CHANNEL: + /******************************************/ + /* Test the digital imnput channel number */ + /******************************************/ + + b_InputChannel = (BYTE) CR_CHAN(insn->chanspec); + pb_ChannelStatus = (PBYTE) & data[0]; + + if (b_InputChannel <= 2) { + /**************************/ + /* Read all digital input */ + /**************************/ + + dw_StatusReg = + inl(devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); + *pb_ChannelStatus = + (BYTE) (((~dw_StatusReg) >> (4 + + b_InputChannel)) + & 1); + } else { + /********************************/ + /* Selected digital input error */ + /********************************/ + + DPRINTK("Selected digital input error\n"); + i_ReturnValue = -4; + } + break; case APCI1710_SSI_READ_ALLCHANNEL: - /**************************/ - /* Read all digital input */ - /**************************/ - pb_InputStatus = (PBYTE) &data[0]; - - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - *pb_InputStatus = (BYTE) (((~dw_StatusReg) >> 4) & 7); - break; - - default : - printk("IO type wrong\n"); - - } //switch end - } - else - { + /**************************/ + /* Read all digital input */ + /**************************/ + pb_InputStatus = (PBYTE) & data[0]; + + dw_StatusReg = + inl(devpriv->s_BoardInfos.ui_Address + + (64 * b_ModulNbr)); + *pb_InputStatus = + (BYTE) (((~dw_StatusReg) >> 4) & 7); + break; + + default: + printk("IO type wrong\n"); + + } //switch end + } else { /**********************************/ - /* The module is not a SSI module */ + /* The module is not a SSI module */ /**********************************/ - DPRINTK("The module is not a SSI module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a SSI module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} diff --git a/comedi/drivers/addi-data/APCI1710_Ssi.h b/comedi/drivers/addi-data/APCI1710_Ssi.h index 513e60bb..ee59687d 100644 --- a/comedi/drivers/addi-data/APCI1710_Ssi.h +++ b/comedi/drivers/addi-data/APCI1710_Ssi.h @@ -22,20 +22,16 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - #define APCI1710_30MHZ 30 #define APCI1710_33MHZ 33 #define APCI1710_40MHZ 40 - #define APCI1710_BINARY_MODE 0x1 #define APCI1710_GRAY_MODE 0x0 #define APCI1710_SSI_READ1VALUE 1 #define APCI1710_SSI_READALLVALUE 2 - #define APCI1710_SSI_SET_CHANNELON 0 #define APCI1710_SSI_SET_CHANNELOFF 1 #define APCI1710_SSI_READ_1CHANNEL 2 @@ -46,17 +42,11 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc | SSI INISIALISATION FUNCTION | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - -INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - - -INT i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, -lsampl_t *data); - +INT i_APCI1710_InsnConfigInitSSI(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnReadSSIValue(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnBitsSSIDigitalIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_Tor.c b/comedi/drivers/addi-data/APCI1710_Tor.c index f02d2eb4..85ea9250 100644 --- a/comedi/drivers/addi-data/APCI1710_Tor.c +++ b/comedi/drivers/addi-data/APCI1710_Tor.c @@ -58,12 +58,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - #include "APCI1710_Tor.h" - - - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_InitTorCounter | @@ -134,527 +130,736 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - - -INT i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - ULONG ul_TimerValue = 0; +INT i_APCI1710_InsnConfigInitTorCounter(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + ULONG ul_TimerValue = 0; DWORD dw_Command; double d_RealTimingInterval = 0; - BYTE b_ModulNbr; - BYTE b_TorCounter; - BYTE b_PCIInputClock; - BYTE b_TimingUnit; - ULONG ul_TimingInterval; - ULONG ul_RealTimingInterval = 0; - - i_ReturnValue = insn->n; - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - - b_TorCounter = (BYTE) data[0]; - b_PCIInputClock = (BYTE) data[1]; - b_TimingUnit = (BYTE) data[2]; - ul_TimingInterval = (ULONG) data[3]; - printk("INPUT clock %d\n",b_PCIInputClock); - + BYTE b_ModulNbr; + BYTE b_TorCounter; + BYTE b_PCIInputClock; + BYTE b_TimingUnit; + ULONG ul_TimingInterval; + ULONG ul_RealTimingInterval = 0; + + i_ReturnValue = insn->n; + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + + b_TorCounter = (BYTE) data[0]; + b_PCIInputClock = (BYTE) data[1]; + b_TimingUnit = (BYTE) data[2]; + ul_TimingInterval = (ULONG) data[3]; + printk("INPUT clock %d\n", b_PCIInputClock); + /**************************/ - /* Test the module number */ + /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ /* Test if tor counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TOR_COUNTER) { /**********************************/ - /* Test the tor counter selection */ + /* Test the tor counter selection */ /**********************************/ - if (b_TorCounter <= 1) - { + if (b_TorCounter <= 1) { /**************************/ - /* Test the PCI bus clock */ + /* Test the PCI bus clock */ /**************************/ - if ((b_PCIInputClock == APCI1710_30MHZ) || - (b_PCIInputClock == APCI1710_33MHZ) || - (b_PCIInputClock == APCI1710_40MHZ) || - (b_PCIInputClock == APCI1710_GATE_INPUT)) - { + if ((b_PCIInputClock == APCI1710_30MHZ) || + (b_PCIInputClock == APCI1710_33MHZ) || + (b_PCIInputClock == APCI1710_40MHZ) || + (b_PCIInputClock == + APCI1710_GATE_INPUT)) { /************************/ - /* Test the timing unit */ + /* Test the timing unit */ /************************/ - if ((b_TimingUnit <= 4) || (b_PCIInputClock == APCI1710_GATE_INPUT)) - { + if ((b_TimingUnit <= 4) + || (b_PCIInputClock == + APCI1710_GATE_INPUT)) { /**********************************/ - /* Test the base timing selection */ + /* Test the base timing selection */ /**********************************/ - if(((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 133) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571230650UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571230UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571UL)) || - ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 9UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 121) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 519691043UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 519691UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 520UL)) || - ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 8UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 100) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429496729UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429496UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429UL)) || - ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 7UL)) || - ((b_PCIInputClock == APCI1710_GATE_INPUT) && (ul_TimingInterval >= 2))) - { + if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 133) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571230650UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571230UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 571UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 9UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 121) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 519691043UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 519691UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 520UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 8UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 100) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429496729UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429496UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 429UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 7UL)) || ((b_PCIInputClock == APCI1710_GATE_INPUT) && (ul_TimingInterval >= 2))) { /**************************/ - /* Test the board version */ + /* Test the board version */ /**************************/ - if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos. - b_BoardVersion > 0)) || - (b_PCIInputClock != APCI1710_40MHZ)) - { + if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos.b_BoardVersion > 0)) || (b_PCIInputClock != APCI1710_40MHZ)) { /************************/ - /* Test the TOR version */ + /* Test the TOR version */ /************************/ - if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)) || - ((b_PCIInputClock == APCI1710_GATE_INPUT) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3132)) || - (b_PCIInputClock == APCI1710_30MHZ) || - (b_PCIInputClock == APCI1710_33MHZ)) - { + if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3131)) || ((b_PCIInputClock == APCI1710_GATE_INPUT) && ((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3132)) || (b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) { /*********************************/ - /* Test if not extern clock used */ + /* Test if not extern clock used */ /*********************************/ - if (b_PCIInputClock != APCI1710_GATE_INPUT) - { - fpu_begin (); + if (b_PCIInputClock != APCI1710_GATE_INPUT) { + fpu_begin + (); /****************************************/ - /* Calculate the timer 0 division fator */ + /* Calculate the timer 0 division fator */ /****************************************/ - switch (b_TimingUnit) - { + switch (b_TimingUnit) { /******/ - /* ns */ + /* ns */ /******/ - case 0: - + case 0: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (0.00025 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (0.00025 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (0.00025 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (0.00025 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.00025 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 1.007752288); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (0.00025 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (0.00025 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (0.00025 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 1.007752288); + } + + break; /******/ - /* æs */ + /* æs */ /******/ - case 1: - + case 1: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (0.25 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (0.25 * b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (0.25 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (0.25 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.25 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / ((double) 0.25 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (0.25 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 1.007752288); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (0.25 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + ( + (double) + 0.25 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (0.25 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 1.007752288); + } + + break; /******/ - /* ms */ + /* ms */ /******/ - case 2: - + case 2: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = ul_TimingInterval * (250.0 * b_PCIInputClock); + ul_TimerValue + = + ul_TimingInterval + * + (250.0 + * + b_PCIInputClock); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (250.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (250.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (250.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 1.007752288); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (250.0 * (double)b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (250.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (250.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 1.007752288); + } + + break; /*****/ - /* s */ + /* s */ /*****/ - case 3: - + case 3: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) (ul_TimingInterval * (250000.0 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + (ul_TimingInterval + * + (250000.0 + * + b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) ul_TimingInterval * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)ul_TimingInterval * (250000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock)); - d_RealTimingInterval = (double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock); - - if ((double) ((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 1.007752288); - } - - - break; + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (250000.0 + * + (double) + b_PCIInputClock)); + d_RealTimingInterval + = + (double) + ul_TimerValue + / + (250000.0 + * + (double) + b_PCIInputClock); + + if ((double)((double)ul_TimerValue / (250000.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 1.007752288); + } + + break; /******/ - /* mn */ + /* mn */ /******/ - case 4: - + case 4: + /******************/ - /* Timer 0 factor */ + /* Timer 0 factor */ /******************/ - ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (250000.0 * b_PCIInputClock)); + ul_TimerValue + = + (ULONG) + ( + (ul_TimingInterval + * + 60) + * + (250000.0 + * + b_PCIInputClock)); /*******************/ - /* Round the value */ + /* Round the value */ /*******************/ - if ((double) ((double) (ul_TimingInterval * 60.0) * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) - { - ul_TimerValue = ul_TimerValue + 1; - } + if ((double)((double)(ul_TimingInterval * 60.0) * (250000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) { + ul_TimerValue + = + ul_TimerValue + + + 1; + } /*****************************/ - /* Calculate the real timing */ + /* Calculate the real timing */ /*****************************/ - ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60; - d_RealTimingInterval = ((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0; - - if ((double) (((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0) >= (double) ((double) ul_RealTimingInterval + 0.5)) - { - ul_RealTimingInterval = ul_RealTimingInterval + 1; - } - - ul_TimingInterval = ul_TimingInterval - 1; - ul_TimerValue = ul_TimerValue - 2; - - if (b_PCIInputClock != APCI1710_40MHZ) - { - ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 1.007752288); - } - - break; - } - - fpu_end (); - } // if (b_PCIInputClock != APCI1710_GATE_INPUT) - else - { + ul_RealTimingInterval + = + (ULONG) + (ul_TimerValue + / + (250000.0 + * + (double) + b_PCIInputClock)) + / + 60; + d_RealTimingInterval + = + ( + (double) + ul_TimerValue + / + (250000.0 + * + (double) + b_PCIInputClock)) + / + 60.0; + + if ((double)(((double)ul_TimerValue / (250000.0 * (double)b_PCIInputClock)) / 60.0) >= (double)((double)ul_RealTimingInterval + 0.5)) { + ul_RealTimingInterval + = + ul_RealTimingInterval + + + 1; + } + + ul_TimingInterval + = + ul_TimingInterval + - + 1; + ul_TimerValue + = + ul_TimerValue + - + 2; + + if (b_PCIInputClock != APCI1710_40MHZ) { + ul_TimerValue + = + (ULONG) + ( + (double) + (ul_TimerValue) + * + 1.007752288); + } + + break; + } + + fpu_end(); + } // if (b_PCIInputClock != APCI1710_GATE_INPUT) + else { /*************************************************************/ - /* 2 Clock used for the overflow and the reload from counter */ + /* 2 Clock used for the overflow and the reload from counter */ /*************************************************************/ - ul_TimerValue = ul_TimingInterval - 2; - } // if (b_PCIInputClock != APCI1710_GATE_INPUT) + ul_TimerValue + = + ul_TimingInterval + - + 2; + } // if (b_PCIInputClock != APCI1710_GATE_INPUT) /****************************/ - /* Save the PCI input clock */ + /* Save the PCI input clock */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - b_PCIInputClock = b_PCIInputClock; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + b_PCIInputClock + = + b_PCIInputClock; /************************/ - /* Save the timing unit */ + /* Save the timing unit */ /************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - b_TimingUnit = b_TimingUnit; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + b_TimingUnit + = + b_TimingUnit; /************************/ - /* Save the base timing */ + /* Save the base timing */ /************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - d_TimingInterval = d_RealTimingInterval; - - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - ul_RealTimingInterval = ul_RealTimingInterval; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + d_TimingInterval + = + d_RealTimingInterval; + + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + ul_RealTimingInterval + = + ul_RealTimingInterval; /*******************/ - /* Get the command */ + /* Get the command */ /*******************/ - - dw_Command = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - - dw_Command = (dw_Command >> 4) & 0xF; + dw_Command + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 4 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + dw_Command + = + (dw_Command + >> + 4) + & + 0xF; /******************/ - /* Test if 40 MHz */ + /* Test if 40 MHz */ /******************/ - if (b_PCIInputClock == APCI1710_40MHZ) - { + if (b_PCIInputClock == APCI1710_40MHZ) { /****************************/ - /* Set the 40 MHz selection */ + /* Set the 40 MHz selection */ /****************************/ - dw_Command = dw_Command | 0x10; - } + dw_Command + = + dw_Command + | + 0x10; + } /*****************************/ - /* Test if extern clock used */ + /* Test if extern clock used */ /*****************************/ - if (b_PCIInputClock == APCI1710_GATE_INPUT) - { + if (b_PCIInputClock == APCI1710_GATE_INPUT) { /****************************/ - /* Set the 40 MHz selection */ + /* Set the 40 MHz selection */ /****************************/ - dw_Command = dw_Command | 0x20; - } + dw_Command + = + dw_Command + | + 0x20; + } /*************************/ - /* Write the new command */ + /* Write the new command */ /*************************/ - - outl(dw_Command,devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - + outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + /*******************/ - /* Disable the tor */ + /* Disable the tor */ /*******************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + outl(0, devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); /*************************/ - /* Set the timer 1 value */ + /* Set the timer 1 value */ /*************************/ - - outl(ul_TimerValue,devpriv->s_BoardInfos.ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + outl(ul_TimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr)); /*********************/ - /* Tor counter init. */ + /* Tor counter init. */ /*********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - b_TorCounterInit = 1; - } - else - { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + b_TorCounterInit + = + 1; + } else { /***********************************************/ - /* TOR version error for 40MHz clock selection */ + /* TOR version error for 40MHz clock selection */ /***********************************************/ - DPRINTK("TOR version error for 40MHz clock selection\n"); - i_ReturnValue = -9; - } - } - else - { + DPRINTK("TOR version error for 40MHz clock selection\n"); + i_ReturnValue + = + -9; + } + } else { /**************************************************************/ - /* You can not used the 40MHz clock selection wich this board */ + /* You can not used the 40MHz clock selection wich this board */ /**************************************************************/ - DPRINTK("You can not used the 40MHz clock selection wich this board\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("You can not used the 40MHz clock selection wich this board\n"); + i_ReturnValue = + -8; + } + } else { /**********************************/ - /* Base timing selection is wrong */ + /* Base timing selection is wrong */ /**********************************/ - DPRINTK("Base timing selection is wrong\n"); - i_ReturnValue = -7; - } - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - else - { + DPRINTK("Base timing selection is wrong\n"); + i_ReturnValue = -7; + } + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + else { /**********************************/ - /* Timing unit selection is wrong */ + /* Timing unit selection is wrong */ /**********************************/ - DPRINTK("Timing unit selection is wrong\n"); - i_ReturnValue = -6; - } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) - else - { + DPRINTK("Timing unit selection is wrong\n"); + i_ReturnValue = -6; + } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4)) + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) + else { /*****************************************/ - /* The selected PCI input clock is wrong */ + /* The selected PCI input clock is wrong */ /*****************************************/ - DPRINTK("The selected PCI input clock is wrong\n"); - i_ReturnValue = -5; - } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) - } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7) - else - { + DPRINTK("The selected PCI input clock is wrong\n"); + i_ReturnValue = -5; + } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ)) + } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7) + else { /**********************************/ - /* Tor Counter selection is wrong */ + /* Tor Counter selection is wrong */ /**********************************/ - DPRINTK("Tor Counter selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7) - } - else - { + DPRINTK("Tor Counter selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7) + } else { /******************************************/ - /* The module is not a tor counter module */ + /* The module is not a tor counter module */ /******************************************/ - DPRINTK("The module is not a tor counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a tor counter module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - data[0] = (UINT) ul_RealTimingInterval; - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - - + data[0] = (UINT) ul_RealTimingInterval; + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -782,345 +987,396 @@ INT i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s +----------------------------------------------------------------------------+ */ - - -INT i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnWriteEnableDisableTorCounter(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_DummyRead; DWORD dw_ConfigReg; - BYTE b_ModulNbr,b_Action; + BYTE b_ModulNbr, b_Action; BYTE b_TorCounter; BYTE b_InputMode; BYTE b_ExternGate; BYTE b_CycleMode; BYTE b_InterruptEnable; - b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); - b_Action =(BYTE) data[0]; // enable or disable - b_TorCounter =(BYTE) data[1]; - b_InputMode =(BYTE) data[2] ; - b_ExternGate =(BYTE) data[3] ; - b_CycleMode =(BYTE) data[4] ; - b_InterruptEnable =(BYTE) data[5] ; - i_ReturnValue = insn->n; ; - devpriv->tsk_Current=current; // Save the current process task structure + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_Action = (BYTE) data[0]; // enable or disable + b_TorCounter = (BYTE) data[1]; + b_InputMode = (BYTE) data[2]; + b_ExternGate = (BYTE) data[3]; + b_CycleMode = (BYTE) data[4]; + b_InterruptEnable = (BYTE) data[5]; + i_ReturnValue = insn->n;; + devpriv->tsk_Current = current; // Save the current process task structure /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if tor counter */ + /* Test if tor counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TOR_COUNTER) { /**********************************/ - /* Test the tor counter selection */ + /* Test the tor counter selection */ /**********************************/ - if (b_TorCounter <= 1) - { - switch(b_Action)// Enable or Disable - { - case APCI1710_ENABLE : + if (b_TorCounter <= 1) { + switch (b_Action) // Enable or Disable + { + case APCI1710_ENABLE: /***********************************/ - /* Test if tor counter initialised */ + /* Test if tor counter initialised */ /***********************************/ - + dw_Status = + inl(devpriv->s_BoardInfos. + ui_Address + 8 + + (16 * b_TorCounter) + + (64 * b_ModulNbr)); - dw_Status =inl(devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /******************************/ - /* Test the input signal mode */ + /* Test the input signal mode */ /******************************/ - if (b_InputMode == 0 || - b_InputMode == 1 || - b_InputMode == APCI1710_TOR_SIMPLE_MODE || - b_InputMode == APCI1710_TOR_DOUBLE_MODE || - b_InputMode == APCI1710_TOR_QUADRUPLE_MODE) - { + if (b_InputMode == 0 || + b_InputMode == 1 || + b_InputMode == + APCI1710_TOR_SIMPLE_MODE + || b_InputMode == + APCI1710_TOR_DOUBLE_MODE + || b_InputMode == + APCI1710_TOR_QUADRUPLE_MODE) + { /************************************/ - /* Test the extern gate signal mode */ + /* Test the extern gate signal mode */ /************************************/ - if (b_ExternGate == 0 || b_ExternGate == 1 || b_InputMode > 1) - { + if (b_ExternGate == 0 + || b_ExternGate + == 1 + || b_InputMode > + 1) { /*********************************/ - /* Test the cycle mode parameter */ + /* Test the cycle mode parameter */ /*********************************/ - if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - { + if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) { /***************************/ - /* Test the interrupt flag */ + /* Test the interrupt flag */ /***************************/ - if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - { + if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) { - - /***************************/ - /* Save the interrupt mode */ + /* Save the interrupt mode */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - b_InterruptEnable = b_InterruptEnable; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + b_InterruptEnable + = + b_InterruptEnable; /*******************/ - /* Get the command */ + /* Get the command */ /*******************/ - - dw_ConfigReg = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - - dw_ConfigReg = (dw_ConfigReg >> 4) & 0x30; + dw_ConfigReg + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 4 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + dw_ConfigReg + = + (dw_ConfigReg + >> + 4) + & + 0x30; /********************************/ - /* Test if not direct mode used */ + /* Test if not direct mode used */ /********************************/ - if (b_InputMode > 1) - { + if (b_InputMode > 1) { /*******************************/ - /* Extern gate can not be used */ + /* Extern gate can not be used */ /*******************************/ - b_ExternGate = 0; + b_ExternGate + = + 0; /*******************************************/ - /* Enable the extern gate for the Signal B */ + /* Enable the extern gate for the Signal B */ /*******************************************/ - dw_ConfigReg = dw_ConfigReg | 0x40; + dw_ConfigReg + = + dw_ConfigReg + | + 0x40; /***********************/ - /* Test if simple mode */ + /* Test if simple mode */ /***********************/ - if (b_InputMode == APCI1710_TOR_SIMPLE_MODE) - { + if (b_InputMode == APCI1710_TOR_SIMPLE_MODE) { /**************************/ - /* Enable the sinple mode */ + /* Enable the sinple mode */ /**************************/ - dw_ConfigReg = dw_ConfigReg | 0x780; + dw_ConfigReg + = + dw_ConfigReg + | + 0x780; - } // if (b_InputMode == APCI1710_TOR_SIMPLE_MODE) + } // if (b_InputMode == APCI1710_TOR_SIMPLE_MODE) /***********************/ - /* Test if double mode */ + /* Test if double mode */ /***********************/ - if (b_InputMode == APCI1710_TOR_DOUBLE_MODE) - { + if (b_InputMode == APCI1710_TOR_DOUBLE_MODE) { /**************************/ - /* Enable the double mode */ + /* Enable the double mode */ /**************************/ - dw_ConfigReg = dw_ConfigReg | 0x180; + dw_ConfigReg + = + dw_ConfigReg + | + 0x180; - } // if (b_InputMode == APCI1710_TOR_DOUBLE_MODE) + } // if (b_InputMode == APCI1710_TOR_DOUBLE_MODE) - b_InputMode = 0; - } // if (b_InputMode > 1) + b_InputMode + = + 0; + } // if (b_InputMode > 1) /*******************/ - /* Set the command */ + /* Set the command */ /*******************/ - dw_ConfigReg = dw_ConfigReg | b_CycleMode | (b_InterruptEnable * 2) | (b_InputMode * 4) | (b_ExternGate * 8); + dw_ConfigReg + = + dw_ConfigReg + | + b_CycleMode + | + (b_InterruptEnable + * + 2) + | + (b_InputMode + * + 4) + | + (b_ExternGate + * + 8); /*****************************/ - /* Clear the status register */ + /* Clear the status register */ /*****************************/ - - dw_DummyRead = inl(devpriv->s_BoardInfos. - ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + dw_DummyRead + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 0 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); /***************************************/ - /* Clear the interrupt status register */ + /* Clear the interrupt status register */ /***************************************/ - - dw_DummyRead=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + dw_DummyRead + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 12 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); /********************/ - /* Set the commando */ + /* Set the commando */ /********************/ - - outl(dw_ConfigReg,devpriv->s_BoardInfos. - ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + outl(dw_ConfigReg, devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); /****************/ - /* Set the gate */ + /* Set the gate */ /****************/ - - outl(1,devpriv->s_BoardInfos. - ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - - } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - else - { + outl(1, devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) + else { /********************************/ - /* Interrupt parameter is wrong */ + /* Interrupt parameter is wrong */ /********************************/ - DPRINTK("Interrupt parameter is wrong\n"); - i_ReturnValue = -9; - } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) - } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - else - { + DPRINTK("Interrupt parameter is wrong\n"); + i_ReturnValue + = + -9; + } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) + } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) + else { /***********************************************/ - /* Tor counter acquisition mode cycle is wrong */ + /* Tor counter acquisition mode cycle is wrong */ /***********************************************/ - DPRINTK("Tor counter acquisition mode cycle is wrong\n"); - i_ReturnValue = -8; - } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) - } // if (b_ExternGate >= 0 && b_ExternGate <= 1) - else - { + DPRINTK("Tor counter acquisition mode cycle is wrong\n"); + i_ReturnValue + = + -8; + } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) + } // if (b_ExternGate >= 0 && b_ExternGate <= 1) + else { /***********************************/ - /* Extern gate input mode is wrong */ + /* Extern gate input mode is wrong */ /***********************************/ - DPRINTK("Extern gate input mode is wrong\n"); - i_ReturnValue = -7; - } // if (b_ExternGate >= 0 && b_ExternGate <= 1) - } // if (b_InputMode >= 0 && b_InputMode <= 1) - else - { + DPRINTK("Extern gate input mode is wrong\n"); + i_ReturnValue = + -7; + } // if (b_ExternGate >= 0 && b_ExternGate <= 1) + } // if (b_InputMode >= 0 && b_InputMode <= 1) + else { /***************************************/ - /* Tor input signal selection is wrong */ + /* Tor input signal selection is wrong */ /***************************************/ - DPRINTK("Tor input signal selection is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Tor input signal selection is wrong\n"); + i_ReturnValue = -6; + } + } else { /*******************************/ - /* Tor counter not initialised */ + /* Tor counter not initialised */ /*******************************/ - DPRINTK("Tor counter not initialised\n"); - i_ReturnValue = -5; - } - break; + DPRINTK("Tor counter not initialised\n"); + i_ReturnValue = -5; + } + break; - case APCI1710_DISABLE : + case APCI1710_DISABLE: /***********************************/ - /* Test if tor counter initialised */ + /* Test if tor counter initialised */ /***********************************/ - - dw_Status = inl(devpriv->s_BoardInfos. - ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 8 + + (16 * b_TorCounter) + + (64 * b_ModulNbr)); /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /***************************/ - /* Test if counter enabled */ + /* Test if counter enabled */ /***************************/ - if (dw_Status & 0x1) - { + if (dw_Status & 0x1) { /****************************/ - /* Clear the interrupt mode */ + /* Clear the interrupt mode */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - b_InterruptEnable = APCI1710_DISABLE; - + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo + [b_TorCounter]. + b_InterruptEnable + = + APCI1710_DISABLE; /******************/ - /* Clear the gate */ + /* Clear the gate */ /******************/ - - outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - } // if (dw_Status & 0x1) - else - { + + outl(0, devpriv-> + s_BoardInfos. + ui_Address + 8 + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + } // if (dw_Status & 0x1) + else { /***************************/ - /* Tor counter not enabled */ + /* Tor counter not enabled */ /***************************/ - DPRINTK("Tor counter not enabled \n"); - i_ReturnValue = -6; - } // if (dw_Status & 0x1) - } // if (dw_Status & 0x10) - else - { + DPRINTK("Tor counter not enabled \n"); + i_ReturnValue = -6; + } // if (dw_Status & 0x1) + } // if (dw_Status & 0x10) + else { /*******************************/ - /* Tor counter not initialised */ + /* Tor counter not initialised */ /*******************************/ - DPRINTK("Tor counter not initialised\n"); - i_ReturnValue = -5; - } // // if (dw_Status & 0x10) - - + DPRINTK("Tor counter not initialised\n"); + i_ReturnValue = -5; + } // // if (dw_Status & 0x10) - } // switch - } // if (b_TorCounter <= 1) - else - { + } // switch + } // if (b_TorCounter <= 1) + else { /**********************************/ - /* Tor counter selection is wrong */ + /* Tor counter selection is wrong */ /**********************************/ - DPRINTK("Tor counter selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_TorCounter <= 1) - } - else - { + DPRINTK("Tor counter selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_TorCounter <= 1) + } else { /******************************************/ - /* The module is not a tor counter module */ + /* The module is not a tor counter module */ /******************************************/ - DPRINTK("The module is not a tor counter module \n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a tor counter module \n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error \n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error \n"); + i_ReturnValue = -2; } - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1204,191 +1460,185 @@ INT i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subd +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_Status; - BYTE b_ModulNbr; - BYTE b_TorCounter; - PBYTE pb_TimingUnit; + BYTE b_ModulNbr; + BYTE b_TorCounter; + PBYTE pb_TimingUnit; PULONG pul_TimingInterval; - PBYTE pb_InputMode; - PBYTE pb_ExternGate; - PBYTE pb_CycleMode; - PBYTE pb_Enable; - PBYTE pb_InterruptEnable ; - - i_ReturnValue = insn->n; - b_ModulNbr = CR_AREF(insn->chanspec); - b_TorCounter = CR_CHAN(insn->chanspec); + PBYTE pb_InputMode; + PBYTE pb_ExternGate; + PBYTE pb_CycleMode; + PBYTE pb_Enable; + PBYTE pb_InterruptEnable; - pb_TimingUnit = (PBYTE) &data[0]; - pul_TimingInterval = (PULONG) &data[1]; - pb_InputMode = (PBYTE) &data[2]; - pb_ExternGate = (PBYTE) &data[3]; - pb_CycleMode = (PBYTE) &data[4]; - pb_Enable = (PBYTE) &data[5]; - pb_InterruptEnable = (PBYTE) &data[6]; + i_ReturnValue = insn->n; + b_ModulNbr = CR_AREF(insn->chanspec); + b_TorCounter = CR_CHAN(insn->chanspec); + + pb_TimingUnit = (PBYTE) & data[0]; + pul_TimingInterval = (PULONG) & data[1]; + pb_InputMode = (PBYTE) & data[2]; + pb_ExternGate = (PBYTE) & data[3]; + pb_CycleMode = (PBYTE) & data[4]; + pb_Enable = (PBYTE) & data[5]; + pb_InterruptEnable = (PBYTE) & data[6]; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /***********************/ - /* Test if tor counter */ + /* Test if tor counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TOR_COUNTER) { /**********************************/ - /* Test the tor counter selection */ + /* Test the tor counter selection */ /**********************************/ - if (b_TorCounter <= 1) - { - - + if (b_TorCounter <= 1) { + /***********************************/ - /* Test if tor counter initialised */ + /* Test if tor counter initialised */ /***********************************/ - - dw_Status = inl(devpriv->s_BoardInfos. - ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 8 + (16 * b_TorCounter) + + (64 * b_ModulNbr)); - if (dw_Status & 0x10) - { - *pb_Enable = dw_Status & 1; + if (dw_Status & 0x10) { + *pb_Enable = dw_Status & 1; /********************/ - /* Get the commando */ + /* Get the commando */ /********************/ - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 4 + + (16 * b_TorCounter) + + (64 * b_ModulNbr)); - *pb_CycleMode = (BYTE) ((dw_Status >> 4) & 1); - *pb_InterruptEnable = (BYTE) ((dw_Status >> 5) & 1); + *pb_CycleMode = + (BYTE) ((dw_Status >> 4) & 1); + *pb_InterruptEnable = + (BYTE) ((dw_Status >> 5) & 1); /******************************************************/ - /* Test if extern gate used for clock or for signal B */ + /* Test if extern gate used for clock or for signal B */ /******************************************************/ - if (dw_Status & 0x600) - { + if (dw_Status & 0x600) { /*****************************************/ - /* Test if extern gate used for signal B */ + /* Test if extern gate used for signal B */ /*****************************************/ - if (dw_Status & 0x400) - { + if (dw_Status & 0x400) { /***********************/ - /* Test if simple mode */ + /* Test if simple mode */ /***********************/ - if ((dw_Status & 0x7800) == 0x7800) - { - *pb_InputMode = APCI1710_TOR_SIMPLE_MODE; - } + if ((dw_Status & 0x7800) + == 0x7800) { + *pb_InputMode = + APCI1710_TOR_SIMPLE_MODE; + } /***********************/ - /* Test if double mode */ + /* Test if double mode */ /***********************/ - if ((dw_Status & 0x7800) == 0x1800) - { - *pb_InputMode = APCI1710_TOR_DOUBLE_MODE; - } + if ((dw_Status & 0x7800) + == 0x1800) { + *pb_InputMode = + APCI1710_TOR_DOUBLE_MODE; + } /**************************/ - /* Test if quadruple mode */ + /* Test if quadruple mode */ /**************************/ - if ((dw_Status & 0x7800) == 0x0000) - { - *pb_InputMode = APCI1710_TOR_QUADRUPLE_MODE; - } - } // if (dw_Status & 0x400) - else - { - *pb_InputMode = 1; - } // // if (dw_Status & 0x400) + if ((dw_Status & 0x7800) + == 0x0000) { + *pb_InputMode = + APCI1710_TOR_QUADRUPLE_MODE; + } + } // if (dw_Status & 0x400) + else { + *pb_InputMode = 1; + } // // if (dw_Status & 0x400) /************************/ - /* Extern gate not used */ + /* Extern gate not used */ /************************/ - *pb_ExternGate = 0; - } // if (dw_Status & 0x600) - else - { - *pb_InputMode = (BYTE) ((dw_Status >> 6) & 1); - *pb_ExternGate = (BYTE) ((dw_Status >> 7) & 1); - } // if (dw_Status & 0x600) - - *pb_TimingUnit = devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - b_TimingUnit; - - *pul_TimingInterval = devpriv->s_ModuleInfo [b_ModulNbr]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounter]. - ul_RealTimingInterval; - } - else - { + *pb_ExternGate = 0; + } // if (dw_Status & 0x600) + else { + *pb_InputMode = + (BYTE) ((dw_Status >> 6) + & 1); + *pb_ExternGate = + (BYTE) ((dw_Status >> 7) + & 1); + } // if (dw_Status & 0x600) + + *pb_TimingUnit = + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo[b_TorCounter]. + b_TimingUnit; + + *pul_TimingInterval = + devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TorCounterModuleInfo. + s_TorCounterInfo[b_TorCounter]. + ul_RealTimingInterval; + } else { /*******************************/ - /* Tor counter not initialised */ + /* Tor counter not initialised */ /*******************************/ - DPRINTK("Tor counter not initialised\n"); - i_ReturnValue = -5; - } - - } // if (b_TorCounter <= 1) - else - { + DPRINTK("Tor counter not initialised\n"); + i_ReturnValue = -5; + } + + } // if (b_TorCounter <= 1) + else { /**********************************/ - /* Tor counter selection is wrong */ + /* Tor counter selection is wrong */ /**********************************/ - DPRINTK("Tor counter selection is wrong \n"); - i_ReturnValue = -4; - } // if (b_TorCounter <= 1) - } - else - { + DPRINTK("Tor counter selection is wrong \n"); + i_ReturnValue = -4; + } // if (b_TorCounter <= 1) + } else { /******************************************/ - /* The module is not a tor counter module */ + /* The module is not a tor counter module */ /******************************************/ - DPRINTK("The module is not a tor counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a tor counter module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1450,345 +1700,350 @@ INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_sub +----------------------------------------------------------------------------+ */ +INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_Status; + DWORD dw_TimeOut = 0; -INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_Status; - DWORD dw_TimeOut = 0; - - BYTE b_ModulNbr; - BYTE b_TorCounter; - BYTE b_ReadType; - UINT ui_TimeOut; - PBYTE pb_TorCounterStatus; - PULONG pul_TorCounterValue; + BYTE b_ModulNbr; + BYTE b_TorCounter; + BYTE b_ReadType; + UINT ui_TimeOut; + PBYTE pb_TorCounterStatus; + PULONG pul_TorCounterValue; i_ReturnValue = insn->n; - b_ModulNbr = CR_AREF(insn->chanspec); - b_ReadType = (BYTE) data[0]; - b_TorCounter = (BYTE) data[1]; - ui_TimeOut = (UINT) data[2]; - pb_TorCounterStatus=(PBYTE) &data[0]; - pul_TorCounterValue=(PULONG) &data[1]; - + b_ModulNbr = CR_AREF(insn->chanspec); + b_ReadType = (BYTE) data[0]; + b_TorCounter = (BYTE) data[1]; + ui_TimeOut = (UINT) data[2]; + pb_TorCounterStatus = (PBYTE) & data[0]; + pul_TorCounterValue = (PULONG) & data[1]; + /**************************/ /* Test the module number */ /**************************/ + if (b_ReadType == APCI1710_TOR_READINTERRUPT) { + + data[0] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].b_OldModuleMask; + data[1] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldInterruptMask; + data[2] = devpriv->s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters.ui_Read].ul_OldCounterLatchValue; - if(b_ReadType==APCI1710_TOR_READINTERRUPT) - { - - data[0]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].b_OldModuleMask; - data[1]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldInterruptMask; - data[2]=devpriv->s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Read].ul_OldCounterLatchValue; - - /**************************/ - /* Increment the read FIFO */ + /* Increment the read FIFO */ /***************************/ - devpriv-> - s_InterruptParameters. - ui_Read = (devpriv-> - s_InterruptParameters. - ui_Read + 1) % APCI1710_SAVE_INTERRUPT; - - return insn->n; - } - - if (b_ModulNbr < 4) - { + devpriv-> + s_InterruptParameters. + ui_Read = (devpriv-> + s_InterruptParameters. + ui_Read + 1) % APCI1710_SAVE_INTERRUPT; + + return insn->n; + } + + if (b_ModulNbr < 4) { /***********************/ - /* Test if tor counter */ + /* Test if tor counter */ /***********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TOR_COUNTER) { /**********************************/ - /* Test the tor counter selection */ + /* Test the tor counter selection */ /**********************************/ - if (b_TorCounter <= 1) - { + if (b_TorCounter <= 1) { /***********************************/ - /* Test if tor counter initialised */ + /* Test if tor counter initialised */ /***********************************/ - - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + dw_Status = inl(devpriv->s_BoardInfos. + ui_Address + 8 + (16 * b_TorCounter) + + (64 * b_ModulNbr)); /*******************************/ - /* Test if counter initialised */ + /* Test if counter initialised */ /*******************************/ - if (dw_Status & 0x10) - { + if (dw_Status & 0x10) { /***************************/ - /* Test if counter enabled */ + /* Test if counter enabled */ /***************************/ - if (dw_Status & 0x1) - { - - switch(b_ReadType) - { + if (dw_Status & 0x1) { - case APCI1710_TOR_GETPROGRESSSTATUS: - /*******************/ - /* Read the status */ + switch (b_ReadType) { + + case APCI1710_TOR_GETPROGRESSSTATUS: + /*******************/ + /* Read the status */ /*******************/ - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - dw_Status = dw_Status & 0xF; + dw_Status = + inl(devpriv-> + s_BoardInfos. + ui_Address + 4 + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + dw_Status = + dw_Status & 0xF; /*****************/ - /* Test if start */ + /* Test if start */ /*****************/ - if (dw_Status & 1) - { - if (dw_Status & 2) - { - if (dw_Status & 4) - { + if (dw_Status & 1) { + if (dw_Status & + 2) { + if (dw_Status & 4) { /************************/ - /* Tor counter owerflow */ + /* Tor counter owerflow */ /************************/ - *pb_TorCounterStatus = 3; - } - else - { + *pb_TorCounterStatus + = + 3; + } else { /***********************/ - /* Tor counter started */ + /* Tor counter started */ /***********************/ - *pb_TorCounterStatus = 2; - } - } - else - { + *pb_TorCounterStatus + = + 2; + } + } else { /***********************/ - /* Tor counter started */ + /* Tor counter started */ /***********************/ - *pb_TorCounterStatus = 1; - } - } - else - { + *pb_TorCounterStatus + = + 1; + } + } else { /***************************/ - /* Tor counter not started */ + /* Tor counter not started */ /***************************/ - *pb_TorCounterStatus = 0; - } - break; + *pb_TorCounterStatus + = 0; + } + break; + + case APCI1710_TOR_GETCOUNTERVALUE: - case APCI1710_TOR_GETCOUNTERVALUE : - /*****************************/ - /* Test the timout parameter */ + /* Test the timout parameter */ /*****************************/ - if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL)) - { - for (;;) - { + if ((ui_TimeOut >= 0) + && (ui_TimeOut + <= + 65535UL)) + { + for (;;) { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - - dw_Status=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + dw_Status + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 4 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); /********************/ - /* Test if overflow */ + /* Test if overflow */ /********************/ - if ((dw_Status & 4) == 4) - { + if ((dw_Status & 4) == 4) { /******************/ - /* Overflow occur */ + /* Overflow occur */ /******************/ - *pb_TorCounterStatus = 3; + *pb_TorCounterStatus + = + 3; /******************/ - /* Read the value */ + /* Read the value */ /******************/ - - *pul_TorCounterValue=inl(devpriv->s_BoardInfos. - ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - break; - } // if ((dw_Status & 4) == 4) - else - { + *pul_TorCounterValue + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 0 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + break; + } // if ((dw_Status & 4) == 4) + else { /*******************************/ - /* Test if measurement stopped */ + /* Test if measurement stopped */ /*******************************/ - if ((dw_Status & 2) == 2) - { + if ((dw_Status & 2) == 2) { /***********************/ - /* A stop signal occur */ + /* A stop signal occur */ /***********************/ - *pb_TorCounterStatus = 2; + *pb_TorCounterStatus + = + 2; /******************/ - /* Read the value */ + /* Read the value */ /******************/ - - *pul_TorCounterValue=inl(devpriv->s_BoardInfos. - ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr)); - - break; - } // if ((dw_Status & 2) == 2) - else - { + *pul_TorCounterValue + = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + 0 + + + (16 * b_TorCounter) + (64 * b_ModulNbr)); + + break; + } // if ((dw_Status & 2) == 2) + else { /*******************************/ - /* Test if measurement started */ + /* Test if measurement started */ /*******************************/ - if ((dw_Status & 1) == 1) - { + if ((dw_Status & 1) == 1) { /************************/ - /* A start signal occur */ + /* A start signal occur */ /************************/ - *pb_TorCounterStatus = 1; - } // if ((dw_Status & 1) == 1) - else - { + *pb_TorCounterStatus + = + 1; + } // if ((dw_Status & 1) == 1) + else { /***************************/ - /* Measurement not started */ + /* Measurement not started */ /***************************/ - *pb_TorCounterStatus = 0; - } // if ((dw_Status & 1) == 1) - } // if ((dw_Status & 2) == 2) - } // if ((dw_Status & 8) == 8) + *pb_TorCounterStatus + = + 0; + } // if ((dw_Status & 1) == 1) + } // if ((dw_Status & 2) == 2) + } // if ((dw_Status & 8) == 8) - if (dw_TimeOut == ui_TimeOut) - { + if (dw_TimeOut == ui_TimeOut) { /*****************/ - /* Timeout occur */ + /* Timeout occur */ /*****************/ - break; - } - else - { + break; + } else { /*************************/ - /* Increment the timeout */ + /* Increment the timeout */ /*************************/ - dw_TimeOut = dw_TimeOut + 1; - - mdelay(1000); - } - } // for (;;) + dw_TimeOut + = + dw_TimeOut + + + 1; + + mdelay(1000); + } + } // for (;;) /*************************/ - /* Test if timeout occur */ + /* Test if timeout occur */ /*************************/ - if ((*pb_TorCounterStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0)) - { + if ((*pb_TorCounterStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0)) { /*****************/ - /* Timeout occur */ + /* Timeout occur */ /*****************/ - *pb_TorCounterStatus = 4; - } - } - else - { + *pb_TorCounterStatus + = + 4; + } + } else { /******************************/ - /* Timeout parameter is wrong */ + /* Timeout parameter is wrong */ /******************************/ - DPRINTK("Timeout parameter is wrong\n"); - i_ReturnValue = -7; - } - break; - - - default: - printk("Inputs wrong\n"); - } // switch end - } // if (dw_Status & 0x1) - else - { + DPRINTK("Timeout parameter is wrong\n"); + i_ReturnValue = + -7; + } + break; + + default: + printk("Inputs wrong\n"); + } // switch end + } // if (dw_Status & 0x1) + else { /***************************/ - /* Tor counter not enabled */ + /* Tor counter not enabled */ /***************************/ - DPRINTK("Tor counter not enabled\n"); - i_ReturnValue = -6; - } // if (dw_Status & 0x1) - } - else - { + DPRINTK("Tor counter not enabled\n"); + i_ReturnValue = -6; + } // if (dw_Status & 0x1) + } else { /*******************************/ - /* Tor counter not initialised */ + /* Tor counter not initialised */ /*******************************/ - DPRINTK("Tor counter not initialised\n"); - i_ReturnValue = -5; - } - } // if (b_TorCounter <= 1) - else - { + DPRINTK("Tor counter not initialised\n"); + i_ReturnValue = -5; + } + } // if (b_TorCounter <= 1) + else { /**********************************/ - /* Tor counter selection is wrong */ + /* Tor counter selection is wrong */ /**********************************/ - DPRINTK("Tor counter selection is wrong\n"); - i_ReturnValue = -4; - } // if (b_TorCounter <= 1) - } - else - { + DPRINTK("Tor counter selection is wrong\n"); + i_ReturnValue = -4; + } // if (b_TorCounter <= 1) + } else { /******************************************/ - /* The module is not a tor counter module */ + /* The module is not a tor counter module */ /******************************************/ - DPRINTK("The module is not a tor counter module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a tor counter module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} diff --git a/comedi/drivers/addi-data/APCI1710_Tor.h b/comedi/drivers/addi-data/APCI1710_Tor.h index 4ef23c16..9ebc5c10 100644 --- a/comedi/drivers/addi-data/APCI1710_Tor.h +++ b/comedi/drivers/addi-data/APCI1710_Tor.h @@ -22,59 +22,42 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ +#define APCI1710_30MHZ 30 +#define APCI1710_33MHZ 33 +#define APCI1710_40MHZ 40 - - - #define APCI1710_30MHZ 30 - #define APCI1710_33MHZ 33 - #define APCI1710_40MHZ 40 - - - - #define APCI1710_GATE_INPUT 10 - +#define APCI1710_GATE_INPUT 10 #define APCI1710_TOR_SIMPLE_MODE 2 #define APCI1710_TOR_DOUBLE_MODE 3 #define APCI1710_TOR_QUADRUPLE_MODE 4 - #define APCI1710_SINGLE 0 #define APCI1710_CONTINUOUS 1 - #define APCI1710_TOR_GETPROGRESSSTATUS 0 #define APCI1710_TOR_GETCOUNTERVALUE 1 #define APCI1710_TOR_READINTERRUPT 2 - /* +----------------------------------------------------------------------------+ | TOR_COUNTER INISIALISATION FUNCTION | +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnConfigInitTorCounter(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnWriteEnableDisableTorCounter(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); - - - - -INT i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - - -INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | TOR_COUNTER READ FUNCTION | +----------------------------------------------------------------------------+ */ - - -INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/APCI1710_Ttl.c b/comedi/drivers/addi-data/APCI1710_Ttl.c index 91d3bf90..e090bb33 100644 --- a/comedi/drivers/addi-data/APCI1710_Ttl.c +++ b/comedi/drivers/addi-data/APCI1710_Ttl.c @@ -60,7 +60,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #include "APCI1710_Ttl.h" - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_InitTTLIODirection | @@ -101,246 +100,248 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - BYTE b_ModulNbr; - BYTE b_InitType; - BYTE b_PortAMode; - BYTE b_PortBMode; - BYTE b_PortCMode; - BYTE b_PortDMode; - - b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); - b_InitType = (BYTE) data[0]; - i_ReturnValue = insn->n; +INT i_APCI1710_InsnConfigInitTTLIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + BYTE b_ModulNbr; + BYTE b_InitType; + BYTE b_PortAMode; + BYTE b_PortBMode; + BYTE b_PortCMode; + BYTE b_PortDMode; + + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + b_InitType = (BYTE) data[0]; + i_ReturnValue = insn->n; /**************************/ /* Test the module number */ /**************************/ - - if (b_ModulNbr < 4) - { + + if (b_ModulNbr < 4) { /**************************/ - /* Test if TTL I/O module */ + /* Test if TTL I/O module */ /**************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO) - { - switch(b_InitType) - { - case APCI1710_TTL_INIT : + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TTL_IO) { + switch (b_InitType) { + case APCI1710_TTL_INIT: - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo.b_TTLInit = 1; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_TTLInit = 1; /***************************/ - /* Set TTL port A to input */ + /* Set TTL port A to input */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [0] = 0; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_PortConfiguration[0] = 0; /***************************/ - /* Set TTL port B to input */ + /* Set TTL port B to input */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [1] = 0; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_PortConfiguration[1] = 0; /***************************/ - /* Set TTL port C to input */ + /* Set TTL port C to input */ /***************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [2] = 0; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_PortConfiguration[2] = 0; /****************************/ - /* Set TTL port D to output */ + /* Set TTL port D to output */ /****************************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [3] = 1; + devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_PortConfiguration[3] = 1; /*************************/ - /* Set the configuration */ + /* Set the configuration */ /*************************/ - - outl(0x8,devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr)); - break; + outl(0x8, + devpriv->s_BoardInfos.ui_Address + 20 + + (64 * b_ModulNbr)); + break; - case APCI1710_TTL_INITDIRECTION : + case APCI1710_TTL_INITDIRECTION: - b_PortAMode = (BYTE) data[1]; - b_PortBMode = (BYTE) data[2]; - b_PortCMode = (BYTE) data[3]; - b_PortDMode = (BYTE) data[4]; + b_PortAMode = (BYTE) data[1]; + b_PortBMode = (BYTE) data[2]; + b_PortCMode = (BYTE) data[3]; + b_PortDMode = (BYTE) data[4]; /********************/ - /* Test the version */ + /* Test the version */ /********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & 0xFFFF) >= + 0x3230) { /************************/ - /* Test the port A mode */ + /* Test the port A mode */ /************************/ - if ((b_PortAMode == 0) || (b_PortAMode == 1)) - { + if ((b_PortAMode == 0) + || (b_PortAMode == 1)) { /************************/ - /* Test the port B mode */ + /* Test the port B mode */ /************************/ - if ((b_PortBMode == 0) || (b_PortBMode == 1)) - { + if ((b_PortBMode == 0) + || (b_PortBMode == 1)) { /************************/ - /* Test the port C mode */ + /* Test the port C mode */ /************************/ - if ((b_PortCMode == 0) || (b_PortCMode == 1)) - { + if ((b_PortCMode == 0) + || (b_PortCMode + == 1)) { /************************/ - /* Test the port D mode */ + /* Test the port D mode */ /************************/ - if ((b_PortDMode == 0) || (b_PortDMode == 1)) - { - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_TTLInit = 1; + if ((b_PortDMode == 0) || (b_PortDMode == 1)) { + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_TTLInit + = + 1; /***********************/ - /* Set TTL port A mode */ + /* Set TTL port A mode */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [0] = b_PortAMode; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [0] + = + b_PortAMode; /***********************/ - /* Set TTL port B mode */ + /* Set TTL port B mode */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [1] = b_PortBMode; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [1] + = + b_PortBMode; /***********************/ - /* Set TTL port C mode */ + /* Set TTL port C mode */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [2] = b_PortCMode; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [2] + = + b_PortCMode; /***********************/ - /* Set TTL port D mode */ + /* Set TTL port D mode */ /***********************/ - devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [3] = b_PortDMode; + devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [3] + = + b_PortDMode; /*************************/ - /* Set the configuration */ + /* Set the configuration */ /*************************/ - - outl((b_PortAMode << 0) | - (b_PortBMode << 1) | - (b_PortCMode << 2) | - (b_PortDMode << 3),devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModulNbr)); - } - else - { + outl((b_PortAMode << 0) | (b_PortBMode << 1) | (b_PortCMode << 2) | (b_PortDMode << 3), devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr)); + } else { /**********************************/ - /* Port D mode selection is wrong */ + /* Port D mode selection is wrong */ /**********************************/ - DPRINTK("Port D mode selection is wrong\n"); - i_ReturnValue = -8; - } - } - else - { + DPRINTK("Port D mode selection is wrong\n"); + i_ReturnValue + = + -8; + } + } else { /**********************************/ - /* Port C mode selection is wrong */ + /* Port C mode selection is wrong */ /**********************************/ - DPRINTK("Port C mode selection is wrong\n"); - i_ReturnValue = -7; - } - } - else - { + DPRINTK("Port C mode selection is wrong\n"); + i_ReturnValue = + -7; + } + } else { /**********************************/ - /* Port B mode selection is wrong */ + /* Port B mode selection is wrong */ /**********************************/ - DPRINTK("Port B mode selection is wrong\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("Port B mode selection is wrong\n"); + i_ReturnValue = -6; + } + } else { /**********************************/ - /* Port A mode selection is wrong */ + /* Port A mode selection is wrong */ /**********************************/ - DPRINTK("Port A mode selection is wrong\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Port A mode selection is wrong\n"); + i_ReturnValue = -5; + } + } else { /*******************************************/ - /* Function not available for this version */ + /* Function not available for this version */ /*******************************************/ - DPRINTK("Function not available for this version\n"); - i_ReturnValue = -4; - } - break; - - DPRINTK("\n"); - default: - printk("Bad Config Type\n"); - }// switch end - } - else - { + DPRINTK("Function not available for this version\n"); + i_ReturnValue = -4; + } + break; + + DPRINTK("\n"); + default: + printk("Bad Config Type\n"); + } // switch end + } else { /**********************************/ - /* The module is not a TTL module */ + /* The module is not a TTL module */ /**********************************/ - DPRINTK("The module is not a TTL module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a TTL module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -348,7 +349,6 @@ INT i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function Name : _INT_ i_APCI1710_ReadTTLIOChannelValue | @@ -406,232 +406,230 @@ APCI1710_TTL_READCHANNEL +----------------------------------------------------------------------------+ */ - -INT i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnBitsReadTTLIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_StatusReg; - BYTE b_ModulNbr; - BYTE b_SelectedPort; - BYTE b_InputChannel; - BYTE b_ReadType; - PBYTE pb_ChannelStatus; - PBYTE pb_PortValue; - - + BYTE b_ModulNbr; + BYTE b_SelectedPort; + BYTE b_InputChannel; + BYTE b_ReadType; + PBYTE pb_ChannelStatus; + PBYTE pb_PortValue; + i_ReturnValue = insn->n; - b_ReadType = (BYTE) data[0]; - b_ModulNbr = CR_AREF(insn->chanspec); - b_SelectedPort= CR_RANGE(insn->chanspec); - b_InputChannel= CR_CHAN(insn->chanspec); + b_ReadType = (BYTE) data[0]; + b_ModulNbr = CR_AREF(insn->chanspec); + b_SelectedPort = CR_RANGE(insn->chanspec); + b_InputChannel = CR_CHAN(insn->chanspec); - - - /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /**************************/ - /* Test if TTL I/O module */ + /* Test if TTL I/O module */ /**************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO) - { - switch(b_ReadType) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TTL_IO) { + switch (b_ReadType) { - case APCI1710_TTL_READCHANNEL: - pb_ChannelStatus = (PBYTE) &data[0]; + case APCI1710_TTL_READCHANNEL: + pb_ChannelStatus = (PBYTE) & data[0]; /********************************/ - /* Test the TTL I/O port number */ + /* Test the TTL I/O port number */ /********************************/ - if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) || - ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230))) - { + if (((b_SelectedPort <= 2) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) == + 0x3130)) + || ((b_SelectedPort <= 3) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) >= + 0x3230))) { /******************************************/ - /* Test the digital imnput channel number */ + /* Test the digital imnput channel number */ /******************************************/ - if (((b_InputChannel <= 7) && (b_SelectedPort < 3)) || - ((b_InputChannel <= 1) && (b_SelectedPort == 3))) - { + if (((b_InputChannel <= 7) + && (b_SelectedPort < 3)) + || ((b_InputChannel <= 1) + && (b_SelectedPort == + 3))) { /******************************************/ - /* Test if the TTL I/O module initialised */ + /* Test if the TTL I/O module initialised */ /******************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_TTLInit == 1) - { + if (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo.b_TTLInit == + 1) { /***********************************/ - /* Test if TTL port used for input */ + /* Test if TTL port used for input */ /***********************************/ - if (((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) || - (((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) && - (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [b_SelectedPort] == 0))) - { + if (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) == 0x3130) || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) { /**************************/ - /* Read all digital input */ + /* Read all digital input */ /**************************/ - - dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - - *pb_ChannelStatus = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) >> - b_InputChannel) & 1; - } - else - { + + dw_StatusReg = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + (64 * b_ModulNbr)); + + *pb_ChannelStatus + = + (BYTE) ( + (dw_StatusReg + >> + (8 * b_SelectedPort)) >> b_InputChannel) & 1; + } else { /*******************************/ - /* Selected TTL I/O port error */ + /* Selected TTL I/O port error */ /*******************************/ - DPRINTK("Selected TTL I/O port error\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Selected TTL I/O port error\n"); + i_ReturnValue = + -4; + } + } else { /***************************/ - /* TTL I/O not initialised */ + /* TTL I/O not initialised */ /***************************/ - DPRINTK("TTL I/O not initialised\n"); - i_ReturnValue = -6; - } - } - else - { + DPRINTK("TTL I/O not initialised\n"); + i_ReturnValue = -6; + } + } else { /********************************/ - /* Selected digital input error */ + /* Selected digital input error */ /********************************/ - DPRINTK("Selected digital input error\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("Selected digital input error\n"); + i_ReturnValue = -5; + } + } else { /*******************************/ - /* Selected TTL I/O port error */ + /* Selected TTL I/O port error */ /*******************************/ - DPRINTK("Selected TTL I/O port error\n"); - i_ReturnValue = -4; - } - break; + DPRINTK("Selected TTL I/O port error\n"); + i_ReturnValue = -4; + } + break; - case APCI1710_TTL_READPORT: - pb_PortValue = (PBYTE) &data[0]; + case APCI1710_TTL_READPORT: + pb_PortValue = (PBYTE) & data[0]; /********************************/ - /* Test the TTL I/O port number */ - /********************************/ - - if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) || - ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230))) - { + /* Test the TTL I/O port number */ + /********************************/ + + if (((b_SelectedPort <= 2) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) == + 0x3130)) + || ((b_SelectedPort <= 3) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) >= + 0x3230))) { /******************************************/ - /* Test if the TTL I/O module initialised */ + /* Test if the TTL I/O module initialised */ /******************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_TTLInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_TTLInit == 1) { /***********************************/ - /* Test if TTL port used for input */ + /* Test if TTL port used for input */ /***********************************/ - if (((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) || - (((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) && - (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [b_SelectedPort] == 0))) - { + if (((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] + & + 0xFFFF) + == 0x3130) + || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) { /**************************/ - /* Read all digital input */ + /* Read all digital input */ /**************************/ - - dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr)); - *pb_PortValue = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) & 0xFF); - } - else - { + dw_StatusReg = + inl(devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + + *pb_PortValue = + (BYTE) ( + (dw_StatusReg >> + (8 * b_SelectedPort)) & 0xFF); + } else { /*******************************/ - /* Selected TTL I/O port error */ + /* Selected TTL I/O port error */ /*******************************/ - DPRINTK("Selected TTL I/O port error\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("Selected TTL I/O port error\n"); + i_ReturnValue = -4; + } + } else { /***************************/ - /* TTL I/O not initialised */ + /* TTL I/O not initialised */ /***************************/ - DPRINTK("TTL I/O not initialised\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("TTL I/O not initialised\n"); + i_ReturnValue = -5; + } + } else { /*******************************/ - /* Selected TTL I/O port error */ + /* Selected TTL I/O port error */ /*******************************/ - DPRINTK("Selected TTL I/O port error\n"); - i_ReturnValue = -4; - } - break; - - default: - printk("Bad ReadType\n"); - - }//End Switch - } - else - { + DPRINTK("Selected TTL I/O port error\n"); + i_ReturnValue = -4; + } + break; + + default: + printk("Bad ReadType\n"); + + } //End Switch + } else { /**********************************/ - /* The module is not a TTL module */ + /* The module is not a TTL module */ /**********************************/ - DPRINTK("The module is not a TTL module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a TTL module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -657,135 +655,130 @@ INT i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s, -comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; +INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; DWORD dw_StatusReg; - BYTE b_ModulNbr; - PULONG pul_PortValue; - - b_ModulNbr=(BYTE) CR_AREF(insn->chanspec); - i_ReturnValue=insn->n; - pul_PortValue=(PULONG) &data[0]; + BYTE b_ModulNbr; + PULONG pul_PortValue; + + b_ModulNbr = (BYTE) CR_AREF(insn->chanspec); + i_ReturnValue = insn->n; + pul_PortValue = (PULONG) & data[0]; /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /**************************/ - /* Test if TTL I/O module */ + /* Test if TTL I/O module */ /**************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TTL_IO) { /******************************************/ - /* Test if the TTL I/O module initialised */ + /* Test if the TTL I/O module initialised */ /******************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_TTLInit == 1) - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_TTLInit == 1) { /**************************/ - /* Read all digital input */ + /* Read all digital input */ /**************************/ - - dw_StatusReg=inl(devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); + dw_StatusReg = inl(devpriv->s_BoardInfos. + ui_Address + (64 * b_ModulNbr)); /**********************/ - /* Test if TTL Rev1.0 */ + /* Test if TTL Rev1.0 */ /**********************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) - { - *pul_PortValue = dw_StatusReg & 0xFFFFFFUL; - } - else - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & 0xFFFF) == + 0x3130) { + *pul_PortValue = + dw_StatusReg & 0xFFFFFFUL; + } else { /**************************************/ - /* Test if port A not used for output */ + /* Test if port A not used for output */ /**************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo.b_PortConfiguration [0] == 1) - { - *pul_PortValue = dw_StatusReg & 0x3FFFF00UL; - } + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration[0] == 1) { + *pul_PortValue = + dw_StatusReg & + 0x3FFFF00UL; + } /**************************************/ - /* Test if port B not used for output */ + /* Test if port B not used for output */ /**************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [1] == 1) - { - *pul_PortValue = dw_StatusReg & 0x3FF00FFUL; - } + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration[1] == 1) { + *pul_PortValue = + dw_StatusReg & + 0x3FF00FFUL; + } /**************************************/ - /* Test if port C not used for output */ + /* Test if port C not used for output */ /**************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [2] == 1) - { - *pul_PortValue = dw_StatusReg & 0x300FFFFUL; - } + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration[2] == 1) { + *pul_PortValue = + dw_StatusReg & + 0x300FFFFUL; + } /**************************************/ - /* Test if port D not used for output */ + /* Test if port D not used for output */ /**************************************/ - if (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [3] == 1) - { - *pul_PortValue = dw_StatusReg & 0xFFFFFFUL; - } - } - } - else - { + if (devpriv-> + s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration[3] == 1) { + *pul_PortValue = + dw_StatusReg & + 0xFFFFFFUL; + } + } + } else { /***************************/ - /* TTL I/O not initialised */ + /* TTL I/O not initialised */ /***************************/ - DPRINTK("TTL I/O not initialised\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("TTL I/O not initialised\n"); + i_ReturnValue = -5; + } + } else { /**********************************/ - /* The module is not a TTL module */ + /* The module is not a TTL module */ /**********************************/ - DPRINTK("The module is not a TTL module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a TTL module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } + DPRINTK("Module number error\n"); + i_ReturnValue = -2; + } return (i_ReturnValue); - } +} /* +----------------------------------------------------------------------------+ @@ -832,173 +825,214 @@ INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ -INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) - { - INT i_ReturnValue = 0; - DWORD dw_StatusReg = 0; +INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = 0; + DWORD dw_StatusReg = 0; BYTE b_ModulNbr; BYTE b_OutputChannel; UINT ui_State; - i_ReturnValue = insn->n; - b_ModulNbr = CR_AREF(insn->chanspec); - b_OutputChannel= CR_CHAN(insn->chanspec); - ui_State = data[0]; // ON or OFF + i_ReturnValue = insn->n; + b_ModulNbr = CR_AREF(insn->chanspec); + b_OutputChannel = CR_CHAN(insn->chanspec); + ui_State = data[0]; // ON or OFF /**************************/ /* Test the module number */ /**************************/ - if (b_ModulNbr < 4) - { + if (b_ModulNbr < 4) { /**************************/ - /* Test if TTL I/O module */ + /* Test if TTL I/O module */ /**************************/ - if ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModulNbr] & + 0xFFFF0000UL) == APCI1710_TTL_IO) { /******************************************/ - /* Test if the TTL I/O module initialised */ + /* Test if the TTL I/O module initialised */ /******************************************/ - if (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_TTLInit == 1) - { + if (devpriv->s_ModuleInfo[b_ModulNbr]. + s_TTLIOInfo.b_TTLInit == 1) { /***********************************/ - /* Test the TTL I/O channel number */ + /* Test the TTL I/O channel number */ /***********************************/ - if (((b_OutputChannel <= 1) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) || - ((b_OutputChannel <= 25) && ((devpriv->s_BoardInfos. - dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230))) - { + if (((b_OutputChannel <= 1) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) == + 0x3130)) + || ((b_OutputChannel <= 25) + && ((devpriv->s_BoardInfos. + dw_MolduleConfiguration + [b_ModulNbr] & + 0xFFFF) >= + 0x3230))) { /****************************************************/ - /* Test if the selected channel is a output channel */ + /* Test if the selected channel is a output channel */ /****************************************************/ - if (((b_OutputChannel <= 1) && (devpriv-> - s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [3] == 1)) || - ((b_OutputChannel >= 2) && (b_OutputChannel <= 9) && (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [0] == 1)) || - ((b_OutputChannel >= 10) && (b_OutputChannel <= 17) && (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [1] == 1)) || - ((b_OutputChannel >= 18) && (b_OutputChannel <= 25) && (devpriv->s_ModuleInfo [b_ModulNbr]. - s_TTLIOInfo. - b_PortConfiguration [2] == 1))) - { + if (((b_OutputChannel <= 1) + && (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [3] == 1)) + || ((b_OutputChannel >= 2) + && (b_OutputChannel <= + 9) + && (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [0] == 1)) + || ((b_OutputChannel >= 10) + && (b_OutputChannel <= + 17) + && (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [1] == 1)) + || ((b_OutputChannel >= 18) + && (b_OutputChannel <= + 25) + && (devpriv-> + s_ModuleInfo + [b_ModulNbr]. + s_TTLIOInfo. + b_PortConfiguration + [2] == 1))) { /************************/ - /* Test if PD0 selected */ + /* Test if PD0 selected */ /************************/ - if (b_OutputChannel == 0) - { + if (b_OutputChannel == 0) { - outl(ui_State,devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); - } - else - { + outl(ui_State, + devpriv-> + s_BoardInfos. + ui_Address + + (64 * b_ModulNbr)); + } else { /************************/ - /* Test if PD1 selected */ + /* Test if PD1 selected */ /************************/ - if (b_OutputChannel == 1) - { - - outl(ui_State,devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModulNbr)); - } - else - { - b_OutputChannel = b_OutputChannel - 2; + if (b_OutputChannel == + 1) { + + outl(ui_State, + devpriv-> + s_BoardInfos. + ui_Address + + 4 + + (64 * b_ModulNbr)); + } else { + b_OutputChannel + = + b_OutputChannel + - 2; /********************/ - /* Read all channel */ + /* Read all channel */ /********************/ - - dw_StatusReg =inl(devpriv->s_BoardInfos. - ui_Address + (64 * b_ModulNbr)); - if(ui_State) // ON - { - dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF; - dw_StatusReg = dw_StatusReg | (1 << (b_OutputChannel % 8)); - }else // Off - { - dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF; - dw_StatusReg = dw_StatusReg & (0xFF - (1 << (b_OutputChannel % 8))); - - } + dw_StatusReg = + inl + (devpriv-> + s_BoardInfos. + ui_Address + + + (64 * b_ModulNbr)); + if (ui_State) // ON + { + dw_StatusReg + = + (dw_StatusReg + >> + ((b_OutputChannel / 8) * 8)) & 0xFF; + dw_StatusReg + = + dw_StatusReg + | + (1 + << + (b_OutputChannel + % + 8)); + } else // Off + { + dw_StatusReg + = + (dw_StatusReg + >> + ((b_OutputChannel / 8) * 8)) & 0xFF; + dw_StatusReg + = + dw_StatusReg + & + (0xFF + - + (1 << (b_OutputChannel % 8))); + + } /****************************/ - /* Set the new output value */ + /* Set the new output value */ /****************************/ - - outl(dw_StatusReg,devpriv->s_BoardInfos. - ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr)); - } - } - } - else - { + outl(dw_StatusReg, devpriv->s_BoardInfos.ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr)); + } + } + } else { /************************************/ - /* The selected TTL output is wrong */ + /* The selected TTL output is wrong */ /************************************/ - DPRINTK(" The selected TTL output is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK(" The selected TTL output is wrong\n"); + i_ReturnValue = -4; + } + } else { /************************************/ - /* The selected TTL output is wrong */ + /* The selected TTL output is wrong */ /************************************/ - DPRINTK("The selected TTL output is wrong\n"); - i_ReturnValue = -4; - } - } - else - { + DPRINTK("The selected TTL output is wrong\n"); + i_ReturnValue = -4; + } + } else { /***************************/ - /* TTL I/O not initialised */ + /* TTL I/O not initialised */ /***************************/ - DPRINTK("TTL I/O not initialised\n"); - i_ReturnValue = -5; - } - } - else - { + DPRINTK("TTL I/O not initialised\n"); + i_ReturnValue = -5; + } + } else { /**************************************/ - /* The module is not a TTL I/O module */ + /* The module is not a TTL I/O module */ /**************************************/ - DPRINTK("The module is not a TTL I/O module\n"); - i_ReturnValue = -3; - } - } - else - { + DPRINTK("The module is not a TTL I/O module\n"); + i_ReturnValue = -3; + } + } else { /***********************/ - /* Module number error */ + /* Module number error */ /***********************/ - DPRINTK("Module number error\n"); - i_ReturnValue = -2; - } - - return (i_ReturnValue); + DPRINTK("Module number error\n"); + i_ReturnValue = -2; } - + return (i_ReturnValue); +} diff --git a/comedi/drivers/addi-data/APCI1710_Ttl.h b/comedi/drivers/addi-data/APCI1710_Ttl.h index f94318e8..18a55d61 100644 --- a/comedi/drivers/addi-data/APCI1710_Ttl.h +++ b/comedi/drivers/addi-data/APCI1710_Ttl.h @@ -22,41 +22,35 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - - #define APCI1710_TTL_INIT 0 #define APCI1710_TTL_INITDIRECTION 1 - #define APCI1710_TTL_READCHANNEL 0 #define APCI1710_TTL_READPORT 1 - /* +----------------------------------------------------------------------------+ | TTL INISIALISATION FUNCTION | +----------------------------------------------------------------------------+ */ - - INT i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnConfigInitTTLIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | TTL INPUT FUNCTION | +----------------------------------------------------------------------------+ */ - INT i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnBitsReadTTLIO(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ | TTL OUTPUT FUNCTIONS | +----------------------------------------------------------------------------+ */ - INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/addi_amcc_S5920.c b/comedi/drivers/addi-data/addi_amcc_S5920.c index 0419508b..54abfedf 100755 --- a/comedi/drivers/addi-data/addi_amcc_S5920.c +++ b/comedi/drivers/addi-data/addi_amcc_S5920.c @@ -46,140 +46,158 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +-----------------------------------------------------------------------+ */ - #include "addi_amcc_S5920.h" /*+----------------------------------------------------------------------------+*/ /*| Function Name : INT i_AddiHeaderRW_ReadEeprom |*/ -/*| (INT i_NbOfWordsToRead, |*/ +/*| (INT i_NbOfWordsToRead, |*/ /*| DWORD dw_PCIBoardEepromAddress, |*/ /*| WORD w_EepromStartAddress, |*/ /*| PWORD pw_DataRead) |*/ /*+----------------------------------------------------------------------------+*/ /*| Task : Read word from the 5920 eeprom. |*/ /*+----------------------------------------------------------------------------+*/ -/*| Input Parameters : INT i_NbOfWordsToRead : Nbr. of word to read |*/ +/*| Input Parameters : INT i_NbOfWordsToRead : Nbr. of word to read |*/ /*| DWORD dw_PCIBoardEepromAddress : Address of the eeprom |*/ /*| WORD w_EepromStartAddress : Eeprom strat address |*/ /*+----------------------------------------------------------------------------+*/ -/*| Output Parameters : PWORD pw_DataRead : Read data |*/ +/*| Output Parameters : PWORD pw_DataRead : Read data |*/ /*+----------------------------------------------------------------------------+*/ /*| Return Value : - |*/ /*+----------------------------------------------------------------------------+*/ -INT i_AddiHeaderRW_ReadEeprom (INT i_NbOfWordsToRead, - DWORD dw_PCIBoardEepromAddress, - WORD w_EepromStartAddress, - PWORD pw_DataRead) +INT i_AddiHeaderRW_ReadEeprom(INT i_NbOfWordsToRead, + DWORD dw_PCIBoardEepromAddress, + WORD w_EepromStartAddress, PWORD pw_DataRead) { - DWORD dw_eeprom_busy=0; - INT i_Counter=0; - INT i_WordCounter; - INT i; - BYTE pb_ReadByte[1]; - BYTE b_ReadLowByte = 0; - BYTE b_ReadHighByte = 0; - BYTE b_SelectedAddressLow = 0; - BYTE b_SelectedAddressHigh = 0; - WORD w_ReadWord = 0; - - for (i_WordCounter = 0;i_WordCountervendor==pci_vendor){ - amcc=kmalloc(sizeof(*amcc),GFP_KERNEL); - memset(amcc,0,sizeof(*amcc)); - - amcc->pcidev=pcidev; - if (last) { last->next=amcc; } - else { amcc_devices=amcc; } - last=amcc; - - amcc->vendor=pcidev->vendor; - amcc->device=pcidev->device; - amcc->pci_bus=pcidev->bus->number; - amcc->pci_slot=PCI_SLOT(pcidev->devfn); - amcc->pci_func=PCI_FUNC(pcidev->devfn); - /* Note: resources may be invalid if PCI device - * not enabled, but they are corrected in - * pci_card_alloc. */ - for (i=0;i<5;i++) - amcc->io_addr[i]=pci_resource_start(pcidev, i); - amcc->irq=pcidev->irq; - + int i_Count = 0; + amcc_devices = NULL; + last = NULL; + + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { + for (i_Count = 0; i_Count < 2; i_Count++) { + pci_vendor = i_ADDIDATADeviceID[i_Count]; + if (pcidev->vendor == pci_vendor) { + amcc = kmalloc(sizeof(*amcc), GFP_KERNEL); + memset(amcc, 0, sizeof(*amcc)); + + amcc->pcidev = pcidev; + if (last) { + last->next = amcc; + } else { + amcc_devices = amcc; + } + last = amcc; + + amcc->vendor = pcidev->vendor; + amcc->device = pcidev->device; + amcc->pci_bus = pcidev->bus->number; + amcc->pci_slot = PCI_SLOT(pcidev->devfn); + amcc->pci_func = PCI_FUNC(pcidev->devfn); + /* Note: resources may be invalid if PCI device + * not enabled, but they are corrected in + * pci_card_alloc. */ + for (i = 0; i < 5; i++) + amcc->io_addr[i] = + pci_resource_start(pcidev, i); + amcc->irq = pcidev->irq; + + } } - } } - if (display) v_pci_card_list_display(); + if (display) + v_pci_card_list_display(); } /****************************************************************************/ /* free up list of amcc cards in this system */ void v_pci_card_list_cleanup(unsigned short pci_vendor) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; - for(amcc=amcc_devices;amcc;amcc=next){ - next=amcc->next; + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; kfree(amcc); } - - amcc_devices=NULL; + + amcc_devices = NULL; } /****************************************************************************/ /* find first unused card with this device_id */ -struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id) +struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, + unsigned short device_id) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; + + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + if ((!amcc->used) && (amcc->device == device_id) + && (amcc->vendor == vendor_id)) + return amcc; - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - if ((!amcc->used)&&(amcc->device==device_id)&&(amcc->vendor==vendor_id)) return amcc; - } return NULL; @@ -341,25 +350,31 @@ struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, /****************************************************************************/ /* find card on requested position */ -int i_find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card) +int i_find_free_pci_card_by_position(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, struct pcilst_struct **card) { - struct pcilst_struct *amcc,*next; - - *card=NULL; - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - if ((amcc->vendor==vendor_id)&&(amcc->device==device_id)&&(amcc->pci_bus==pci_bus)&&(amcc->pci_slot==pci_slot)) { + struct pcilst_struct *amcc, *next; + + *card = NULL; + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + if ((amcc->vendor == vendor_id) && (amcc->device == device_id) + && (amcc->pci_bus == pci_bus) + && (amcc->pci_slot == pci_slot)) { if (!(amcc->used)) { - *card=amcc; + *card = amcc; return 0; // ok, card is found } else { - rt_printk(" - \nCard on requested position is used b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - \nCard on requested position is used b:s %d:%d!\n", + pci_bus, pci_slot); return 2; // card exist but is used } } } - return 1; // no card found + return 1; // no card found } /****************************************************************************/ @@ -368,15 +383,19 @@ int pci_card_alloc(struct pcilst_struct *amcc, int master) { int i; - if (!amcc) return -1; + if (!amcc) + return -1; - if (amcc->used) return 1; - if (comedi_pci_enable(amcc->pcidev, "addi_amcc_s5933")) return -1; + if (amcc->used) + return 1; + if (comedi_pci_enable(amcc->pcidev, "addi_amcc_s5933")) + return -1; /* Resources will be accurate now. */ - for (i=0;i<5;i++) - amcc->io_addr[i]=pci_resource_start(amcc->pcidev, i); - if (master) pci_set_master(amcc->pcidev); - amcc->used=1; + for (i = 0; i < 5; i++) + amcc->io_addr[i] = pci_resource_start(amcc->pcidev, i); + if (master) + pci_set_master(amcc->pcidev); + amcc->used = 1; return 0; } @@ -385,10 +404,12 @@ int pci_card_alloc(struct pcilst_struct *amcc, int master) /* mark card as free */ int i_pci_card_free(struct pcilst_struct *amcc) { - if (!amcc) return -1; + if (!amcc) + return -1; - if (!amcc->used) return 1; - amcc->used=0; + if (!amcc->used) + return 1; + amcc->used = 0; comedi_pci_disable(amcc->pcidev); return 0; } @@ -397,66 +418,71 @@ int i_pci_card_free(struct pcilst_struct *amcc) /* display list of found cards */ void v_pci_card_list_display(void) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; printk("List of pci cards\n"); printk("bus:slot:func vendor device io_amcc io_daq irq used\n"); - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - printk("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n", - amcc->pci_bus,amcc->pci_slot,amcc->pci_func,amcc->vendor,amcc->device, - (unsigned long long)amcc->io_addr[0],(unsigned long long)amcc->io_addr[2],amcc->irq,amcc->used); - + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + printk("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n", amcc->pci_bus, amcc->pci_slot, amcc->pci_func, amcc->vendor, amcc->device, (unsigned long long)amcc->io_addr[0], (unsigned long long)amcc->io_addr[2], amcc->irq, amcc->used); + } } /****************************************************************************/ /* return all card information for driver */ int i_pci_card_data(struct pcilst_struct *amcc, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - resource_size_t *io_addr, unsigned int *irq) + unsigned char *pci_bus, unsigned char *pci_slot, + unsigned char *pci_func, resource_size_t * io_addr, unsigned int *irq) { - int i; - - if (!amcc) return -1; - *pci_bus=amcc->pci_bus; - *pci_slot=amcc->pci_slot; - *pci_func=amcc->pci_func; - for (i=0;i<5;i++) - io_addr[i]=amcc->io_addr[i]; - *irq=amcc->irq; + int i; + + if (!amcc) + return -1; + *pci_bus = amcc->pci_bus; + *pci_slot = amcc->pci_slot; + *pci_func = amcc->pci_func; + for (i = 0; i < 5; i++) + io_addr[i] = amcc->io_addr[i]; + *irq = amcc->irq; return 0; } /****************************************************************************/ /* select and alloc card */ -struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, int i_Master) +struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, int i_Master) { struct pcilst_struct *card; - - if ((pci_bus<1)&(pci_slot<1)) { // use autodetection - if ((card=ptr_find_free_pci_card_by_device(vendor_id,device_id))==NULL) { + + if ((pci_bus < 1) & (pci_slot < 1)) { // use autodetection + if ((card = ptr_find_free_pci_card_by_device(vendor_id, + device_id)) == NULL) { rt_printk(" - Unused card not found in system!\n"); return NULL; } } else { - switch (i_find_free_pci_card_by_position(vendor_id,device_id,pci_bus,pci_slot,&card)) { + switch (i_find_free_pci_card_by_position(vendor_id, device_id, + pci_bus, pci_slot, &card)) { case 1: - rt_printk(" - Card not found on requested position b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card not found on requested position b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; case 2: - rt_printk(" - Card on requested position is used b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card on requested position is used b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; } } - - if (pci_card_alloc(card, i_Master)!=0) { + if (pci_card_alloc(card, i_Master) != 0) { rt_printk(" - Can't allocate card!\n"); return NULL; - - + } return card; diff --git a/comedi/drivers/addi-data/addi_common.c b/comedi/drivers/addi-data/addi_common.c index 441baa99..470c6915 100644 --- a/comedi/drivers/addi-data/addi_common.c +++ b/comedi/drivers/addi-data/addi_common.c @@ -46,10 +46,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - - - - #include #include #include @@ -82,2428 +78,2384 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #if defined(CONFIG_APCI_1710) || defined(CONFIG_APCI_3200) || defined(CONFIG_APCI_3300) //BYTE b_SaveFPUReg [94]; -void fpu_begin (void) - { +void fpu_begin(void) +{ //asm ("fstenv b_SaveFPUReg"); - kernel_fpu_begin (); - } + kernel_fpu_begin(); +} -void fpu_end (void) - { +void fpu_end(void) +{ // asm ("frstor b_SaveFPUReg"); - kernel_fpu_end (); - } + kernel_fpu_end(); +} #endif #include "addi_eeprom.c" #if (defined (CONFIG_APCI_3120) || defined (CONFIG_APCI_3001)) - #include "hwdrv_apci3120.c" +#include "hwdrv_apci3120.c" #endif #ifdef CONFIG_APCI_1032 - #include "hwdrv_apci1032.c" +#include "hwdrv_apci1032.c" #endif #ifdef CONFIG_APCI_1516 - #include "hwdrv_apci1516.c" +#include "hwdrv_apci1516.c" #endif #ifdef CONFIG_APCI_2016 - #include "hwdrv_apci2016.c" +#include "hwdrv_apci2016.c" #endif #ifdef CONFIG_APCI_2032 - #include "hwdrv_apci2032.c" +#include "hwdrv_apci2032.c" #endif #ifdef CONFIG_APCI_2200 - #include "hwdrv_apci2200.c" +#include "hwdrv_apci2200.c" #endif #ifdef CONFIG_APCI_1564 - #include "hwdrv_apci1564.c" +#include "hwdrv_apci1564.c" #endif #ifdef CONFIG_APCI_1500 - #include "hwdrv_apci1500.c" +#include "hwdrv_apci1500.c" #endif #ifdef CONFIG_APCI_3501 - #include "hwdrv_apci3501.c" +#include "hwdrv_apci3501.c" #endif #ifdef CONFIG_APCI_035 - #include "hwdrv_apci035.c" +#include "hwdrv_apci035.c" #endif #if (defined (CONFIG_APCI_3200) || defined (CONFIG_APCI_3300)) - #include "hwdrv_apci3200.c" +#include "hwdrv_apci3200.c" #endif #ifdef CONFIG_APCI_1710 - #include "hwdrv_APCI1710.c" +#include "hwdrv_APCI1710.c" #endif #ifdef CONFIG_APCI_16XX - #include "hwdrv_apci16xx.c" +#include "hwdrv_apci16xx.c" #endif #ifdef CONFIG_APCI_3XXX - #include "hwdrv_apci3xxx.c" +#include "hwdrv_apci3xxx.c" #endif #ifndef COMEDI_SUBD_TTLIO - #define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ #endif -static boardtype boardtypes[] = -{ +static boardtype boardtypes[] = { #ifdef CONFIG_APCI_3120 - {"apci3120", - APCI3120_BOARD_VENDOR_ID, - 0x818D, - AMCC_OP_REG_SIZE, - APCI3120_ADDRESS_RANGE, - 8, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 16, - 8, - 16, - 8, - 0xffff, - 0x3fff, - &range_apci3120_ai, - &range_apci3120_ao, - 4, - 4, - 0x0f, - 0, - NULL, - 1, - 1, - 1, - 10000, - 100000, - v_APCI3120_Interrupt, - i_APCI3120_Reset, - i_APCI3120_InsnConfigAnalogInput, - i_APCI3120_InsnReadAnalogInput, - NULL, - NULL, - i_APCI3120_CommandTestAnalogInput, - i_APCI3120_CommandAnalogInput, - i_APCI3120_StopCyclicAcquisition, - NULL, - i_APCI3120_InsnWriteAnalogOutput, - NULL, - NULL, - i_APCI3120_InsnReadDigitalInput, - NULL, - i_APCI3120_InsnBitsDigitalInput, - i_APCI3120_InsnConfigDigitalOutput, - i_APCI3120_InsnWriteDigitalOutput, - i_APCI3120_InsnBitsDigitalOutput, - NULL, - i_APCI3120_InsnConfigTimer, - i_APCI3120_InsnWriteTimer, - i_APCI3120_InsnReadTimer, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci3120", + APCI3120_BOARD_VENDOR_ID, + 0x818D, + AMCC_OP_REG_SIZE, + APCI3120_ADDRESS_RANGE, + 8, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 16, + 8, + 16, + 8, + 0xffff, + 0x3fff, + &range_apci3120_ai, + &range_apci3120_ao, + 4, + 4, + 0x0f, + 0, + NULL, + 1, + 1, + 1, + 10000, + 100000, + v_APCI3120_Interrupt, + i_APCI3120_Reset, + i_APCI3120_InsnConfigAnalogInput, + i_APCI3120_InsnReadAnalogInput, + NULL, + NULL, + i_APCI3120_CommandTestAnalogInput, + i_APCI3120_CommandAnalogInput, + i_APCI3120_StopCyclicAcquisition, + NULL, + i_APCI3120_InsnWriteAnalogOutput, + NULL, + NULL, + i_APCI3120_InsnReadDigitalInput, + NULL, + i_APCI3120_InsnBitsDigitalInput, + i_APCI3120_InsnConfigDigitalOutput, + i_APCI3120_InsnWriteDigitalOutput, + i_APCI3120_InsnBitsDigitalOutput, + NULL, + i_APCI3120_InsnConfigTimer, + i_APCI3120_InsnWriteTimer, + i_APCI3120_InsnReadTimer, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif -#ifdef CONFIG_APCI_1032 - {"apci1032", - APCI1032_BOARD_VENDOR_ID, - 0x1003, - 4, - APCI1032_ADDRESS_RANGE, - 0, - 0, - ADDIDATA_EEPROM, - ADDIDATA_93C76, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 32, - 0, - 0, - 0, - NULL, - 0, - 0, - 0, - 0, - 0, - v_APCI1032_Interrupt, - i_APCI1032_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI1032_ConfigDigitalInput, - i_APCI1032_Read1DigitalInput, - NULL, - i_APCI1032_ReadMoreDigitalInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, +#ifdef CONFIG_APCI_1032 + {"apci1032", + APCI1032_BOARD_VENDOR_ID, + 0x1003, + 4, + APCI1032_ADDRESS_RANGE, + 0, + 0, + ADDIDATA_EEPROM, + ADDIDATA_93C76, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 32, + 0, + 0, + 0, + NULL, + 0, + 0, + 0, + 0, + 0, + v_APCI1032_Interrupt, + i_APCI1032_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI1032_ConfigDigitalInput, + i_APCI1032_Read1DigitalInput, + NULL, + i_APCI1032_ReadMoreDigitalInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_1516 - {"apci1516", - APCI1516_BOARD_VENDOR_ID, - 0x1001, - 128, - APCI1516_ADDRESS_RANGE, - 32, - 0, - ADDIDATA_EEPROM, - ADDIDATA_S5920, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 8, - 8, - 0, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - NULL, - i_APCI1516_Reset, - NULL,NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI1516_Read1DigitalInput, - NULL, - i_APCI1516_ReadMoreDigitalInput, - i_APCI1516_ConfigDigitalOutput, - i_APCI1516_WriteDigitalOutput, - i_APCI1516_ReadDigitalOutput, - NULL, - i_APCI1516_ConfigWatchdog, - i_APCI1516_StartStopWriteWatchdog, - i_APCI1516_ReadWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci1516", + APCI1516_BOARD_VENDOR_ID, + 0x1001, + 128, + APCI1516_ADDRESS_RANGE, + 32, + 0, + ADDIDATA_EEPROM, + ADDIDATA_S5920, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 8, + 8, + 0, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + NULL, + i_APCI1516_Reset, + NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI1516_Read1DigitalInput, + NULL, + i_APCI1516_ReadMoreDigitalInput, + i_APCI1516_ConfigDigitalOutput, + i_APCI1516_WriteDigitalOutput, + i_APCI1516_ReadDigitalOutput, + NULL, + i_APCI1516_ConfigWatchdog, + i_APCI1516_StartStopWriteWatchdog, + i_APCI1516_ReadWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_2016 - {"apci2016", - APCI2016_BOARD_VENDOR_ID, - 0x1002, - 128, - APCI2016_ADDRESS_RANGE, - 32, - 0, - ADDIDATA_EEPROM, - ADDIDATA_S5920, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 0, - 16, - 0, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - NULL, - i_APCI2016_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI2016_ConfigDigitalOutput, - i_APCI2016_WriteDigitalOutput, - i_APCI2016_BitsDigitalOutput, - NULL, - i_APCI2016_ConfigWatchdog, - i_APCI2016_StartStopWriteWatchdog, - i_APCI2016_ReadWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci2016", + APCI2016_BOARD_VENDOR_ID, + 0x1002, + 128, + APCI2016_ADDRESS_RANGE, + 32, + 0, + ADDIDATA_EEPROM, + ADDIDATA_S5920, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 0, + 16, + 0, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + NULL, + i_APCI2016_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI2016_ConfigDigitalOutput, + i_APCI2016_WriteDigitalOutput, + i_APCI2016_BitsDigitalOutput, + NULL, + i_APCI2016_ConfigWatchdog, + i_APCI2016_StartStopWriteWatchdog, + i_APCI2016_ReadWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_2032 - {"apci2032", - APCI2032_BOARD_VENDOR_ID, - 0x1004, - 4, - APCI2032_ADDRESS_RANGE, - 0, - 0, - ADDIDATA_EEPROM, - ADDIDATA_93C76, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 0, - 32, - 0xffffffff, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - v_APCI2032_Interrupt, - i_APCI2032_Reset, - NULL,NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI2032_ConfigDigitalOutput, - i_APCI2032_WriteDigitalOutput, - i_APCI2032_ReadDigitalOutput, - i_APCI2032_ReadInterruptStatus, - i_APCI2032_ConfigWatchdog, - i_APCI2032_StartStopWriteWatchdog, - i_APCI2032_ReadWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci2032", + APCI2032_BOARD_VENDOR_ID, + 0x1004, + 4, + APCI2032_ADDRESS_RANGE, + 0, + 0, + ADDIDATA_EEPROM, + ADDIDATA_93C76, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 0, + 32, + 0xffffffff, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + v_APCI2032_Interrupt, + i_APCI2032_Reset, + NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI2032_ConfigDigitalOutput, + i_APCI2032_WriteDigitalOutput, + i_APCI2032_ReadDigitalOutput, + i_APCI2032_ReadInterruptStatus, + i_APCI2032_ConfigWatchdog, + i_APCI2032_StartStopWriteWatchdog, + i_APCI2032_ReadWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_2200 - {"apci2200", - APCI2200_BOARD_VENDOR_ID, - 0x1005, - 4, - APCI2200_ADDRESS_RANGE, - 0, - 0, - ADDIDATA_EEPROM, - ADDIDATA_93C76, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 8, - 16, - 0, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - NULL, - i_APCI2200_Reset, - NULL,NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI2200_Read1DigitalInput, - NULL, - i_APCI2200_ReadMoreDigitalInput, - i_APCI2200_ConfigDigitalOutput, - i_APCI2200_WriteDigitalOutput, - i_APCI2200_ReadDigitalOutput, - NULL, - i_APCI2200_ConfigWatchdog, - i_APCI2200_StartStopWriteWatchdog, - i_APCI2200_ReadWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci2200", + APCI2200_BOARD_VENDOR_ID, + 0x1005, + 4, + APCI2200_ADDRESS_RANGE, + 0, + 0, + ADDIDATA_EEPROM, + ADDIDATA_93C76, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 8, + 16, + 0, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + NULL, + i_APCI2200_Reset, + NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI2200_Read1DigitalInput, + NULL, + i_APCI2200_ReadMoreDigitalInput, + i_APCI2200_ConfigDigitalOutput, + i_APCI2200_WriteDigitalOutput, + i_APCI2200_ReadDigitalOutput, + NULL, + i_APCI2200_ConfigWatchdog, + i_APCI2200_StartStopWriteWatchdog, + i_APCI2200_ReadWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_1564 - {"apci1564", - APCI1564_BOARD_VENDOR_ID, - 0x1006, - 128, - APCI1564_ADDRESS_RANGE, - 0, - 0, - ADDIDATA_EEPROM, - ADDIDATA_93C76, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 32, - 32, - 0xffffffff, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - v_APCI1564_Interrupt, - i_APCI1564_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI1564_ConfigDigitalInput, - i_APCI1564_Read1DigitalInput, - NULL, - i_APCI1564_ReadMoreDigitalInput, - i_APCI1564_ConfigDigitalOutput, - i_APCI1564_WriteDigitalOutput, - i_APCI1564_ReadDigitalOutput, - i_APCI1564_ReadInterruptStatus, - i_APCI1564_ConfigTimerCounterWatchdog, - i_APCI1564_StartStopWriteTimerCounterWatchdog, - i_APCI1564_ReadTimerCounterWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci1564", + APCI1564_BOARD_VENDOR_ID, + 0x1006, + 128, + APCI1564_ADDRESS_RANGE, + 0, + 0, + ADDIDATA_EEPROM, + ADDIDATA_93C76, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 32, + 32, + 0xffffffff, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + v_APCI1564_Interrupt, + i_APCI1564_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI1564_ConfigDigitalInput, + i_APCI1564_Read1DigitalInput, + NULL, + i_APCI1564_ReadMoreDigitalInput, + i_APCI1564_ConfigDigitalOutput, + i_APCI1564_WriteDigitalOutput, + i_APCI1564_ReadDigitalOutput, + i_APCI1564_ReadInterruptStatus, + i_APCI1564_ConfigTimerCounterWatchdog, + i_APCI1564_StartStopWriteTimerCounterWatchdog, + i_APCI1564_ReadTimerCounterWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_1500 - {"apci1500", - APCI1500_BOARD_VENDOR_ID, - 0x80fc, - 128, - APCI1500_ADDRESS_RANGE, - 4, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 16, - 16, - 0xffff, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - v_APCI1500_Interrupt, - i_APCI1500_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI1500_ConfigDigitalInputEvent, - i_APCI1500_Initialisation, - i_APCI1500_StartStopInputEvent, - i_APCI1500_ReadMoreDigitalInput, - i_APCI1500_ConfigDigitalOutputErrorInterrupt, - i_APCI1500_WriteDigitalOutput, - i_APCI1500_ConfigureInterrupt, - NULL, - i_APCI1500_ConfigCounterTimerWatchdog, - i_APCI1500_StartStopTriggerTimerCounterWatchdog, - i_APCI1500_ReadInterruptMask, - i_APCI1500_ReadCounterTimerWatchdog, - NULL, - NULL, - NULL, - NULL - }, + {"apci1500", + APCI1500_BOARD_VENDOR_ID, + 0x80fc, + 128, + APCI1500_ADDRESS_RANGE, + 4, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 16, + 16, + 0xffff, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + v_APCI1500_Interrupt, + i_APCI1500_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI1500_ConfigDigitalInputEvent, + i_APCI1500_Initialisation, + i_APCI1500_StartStopInputEvent, + i_APCI1500_ReadMoreDigitalInput, + i_APCI1500_ConfigDigitalOutputErrorInterrupt, + i_APCI1500_WriteDigitalOutput, + i_APCI1500_ConfigureInterrupt, + NULL, + i_APCI1500_ConfigCounterTimerWatchdog, + i_APCI1500_StartStopTriggerTimerCounterWatchdog, + i_APCI1500_ReadInterruptMask, + i_APCI1500_ReadCounterTimerWatchdog, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_3001 - {"apci3001", - APCI3120_BOARD_VENDOR_ID, - 0x828D, - AMCC_OP_REG_SIZE, - APCI3120_ADDRESS_RANGE, - 8, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 16, - 8, - 16, - 0, - 0xfff, - 0, - &range_apci3120_ai, - NULL, - 4, - 4, - 0x0f, - 0, - NULL, - 1, - 1, - 1, - 10000, - 100000, - v_APCI3120_Interrupt, - i_APCI3120_Reset, - i_APCI3120_InsnConfigAnalogInput, - i_APCI3120_InsnReadAnalogInput, - NULL, - NULL, - i_APCI3120_CommandTestAnalogInput, - i_APCI3120_CommandAnalogInput, - i_APCI3120_StopCyclicAcquisition, - NULL, - NULL, - NULL, - NULL, - i_APCI3120_InsnReadDigitalInput, - NULL, - i_APCI3120_InsnBitsDigitalInput, - i_APCI3120_InsnConfigDigitalOutput, - i_APCI3120_InsnWriteDigitalOutput, - i_APCI3120_InsnBitsDigitalOutput, - NULL, - i_APCI3120_InsnConfigTimer, - i_APCI3120_InsnWriteTimer, - i_APCI3120_InsnReadTimer, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci3001", + APCI3120_BOARD_VENDOR_ID, + 0x828D, + AMCC_OP_REG_SIZE, + APCI3120_ADDRESS_RANGE, + 8, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 16, + 8, + 16, + 0, + 0xfff, + 0, + &range_apci3120_ai, + NULL, + 4, + 4, + 0x0f, + 0, + NULL, + 1, + 1, + 1, + 10000, + 100000, + v_APCI3120_Interrupt, + i_APCI3120_Reset, + i_APCI3120_InsnConfigAnalogInput, + i_APCI3120_InsnReadAnalogInput, + NULL, + NULL, + i_APCI3120_CommandTestAnalogInput, + i_APCI3120_CommandAnalogInput, + i_APCI3120_StopCyclicAcquisition, + NULL, + NULL, + NULL, + NULL, + i_APCI3120_InsnReadDigitalInput, + NULL, + i_APCI3120_InsnBitsDigitalInput, + i_APCI3120_InsnConfigDigitalOutput, + i_APCI3120_InsnWriteDigitalOutput, + i_APCI3120_InsnBitsDigitalOutput, + NULL, + i_APCI3120_InsnConfigTimer, + i_APCI3120_InsnWriteTimer, + i_APCI3120_InsnReadTimer, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_3501 - {"apci3501", - APCI3501_BOARD_VENDOR_ID, - 0x3001, - 64, - APCI3501_ADDRESS_RANGE, - 0, - 0, - ADDIDATA_EEPROM, - ADDIDATA_S5933, - 0, - 0, - 0, - 8, - 0, - 16383, - NULL, - &range_apci3501_ao, - 2, - 2, - 0x3, - 0, - NULL, - 0, - 1, - 0, - 0, - 0, - v_APCI3501_Interrupt, - i_APCI3501_Reset, - NULL,NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3501_ConfigAnalogOutput, - i_APCI3501_WriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3501_ReadDigitalInput, - i_APCI3501_ConfigDigitalOutput, - i_APCI3501_WriteDigitalOutput, - i_APCI3501_ReadDigitalOutput, - NULL, - i_APCI3501_ConfigTimerCounterWatchdog, - i_APCI3501_StartStopWriteTimerCounterWatchdog, - i_APCI3501_ReadTimerCounterWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci3501", + APCI3501_BOARD_VENDOR_ID, + 0x3001, + 64, + APCI3501_ADDRESS_RANGE, + 0, + 0, + ADDIDATA_EEPROM, + ADDIDATA_S5933, + 0, + 0, + 0, + 8, + 0, + 16383, + NULL, + &range_apci3501_ao, + 2, + 2, + 0x3, + 0, + NULL, + 0, + 1, + 0, + 0, + 0, + v_APCI3501_Interrupt, + i_APCI3501_Reset, + NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3501_ConfigAnalogOutput, + i_APCI3501_WriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3501_ReadDigitalInput, + i_APCI3501_ConfigDigitalOutput, + i_APCI3501_WriteDigitalOutput, + i_APCI3501_ReadDigitalOutput, + NULL, + i_APCI3501_ConfigTimerCounterWatchdog, + i_APCI3501_StartStopWriteTimerCounterWatchdog, + i_APCI3501_ReadTimerCounterWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_035 - {"apci035", - APCI035_BOARD_VENDOR_ID, - 0x0300, - 127, - APCI035_ADDRESS_RANGE , - 0, - 0, - 1, - ADDIDATA_S5920, - 16, - 8, - 16, - 0, - 0xff, - 0, - &range_apci035_ai, - NULL, - 0, - 0, - 0, - 0, - NULL, - 0, - 1, - 0, - 10000, - 100000, - v_APCI035_Interrupt, - i_APCI035_Reset, - i_APCI035_ConfigAnalogInput, - i_APCI035_ReadAnalogInput , - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI035_ConfigTimerWatchdog, - i_APCI035_StartStopWriteTimerWatchdog, - i_APCI035_ReadTimerWatchdog, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci035", + APCI035_BOARD_VENDOR_ID, + 0x0300, + 127, + APCI035_ADDRESS_RANGE, + 0, + 0, + 1, + ADDIDATA_S5920, + 16, + 8, + 16, + 0, + 0xff, + 0, + &range_apci035_ai, + NULL, + 0, + 0, + 0, + 0, + NULL, + 0, + 1, + 0, + 10000, + 100000, + v_APCI035_Interrupt, + i_APCI035_Reset, + i_APCI035_ConfigAnalogInput, + i_APCI035_ReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI035_ConfigTimerWatchdog, + i_APCI035_StartStopWriteTimerWatchdog, + i_APCI035_ReadTimerWatchdog, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_3200 - {"apci3200", - APCI3200_BOARD_VENDOR_ID, - 0x3000, - 128, - 256, - 4, - 4, - ADDIDATA_EEPROM, - ADDIDATA_S5920, - 16, - 8, - 16, - 0, - 0x3ffff, - 0, - &range_apci3200_ai, - NULL, - 4, - 4, - 0, - 0, - NULL, - 0, - 0, - 0, - 10000, - 100000, - v_APCI3200_Interrupt, - i_APCI3200_Reset, - i_APCI3200_ConfigAnalogInput, - i_APCI3200_ReadAnalogInput , - i_APCI3200_InsnWriteReleaseAnalogInput, - i_APCI3200_InsnBits_AnalogInput_Test, - i_APCI3200_CommandTestAnalogInput, - i_APCI3200_CommandAnalogInput, - i_APCI3200_StopCyclicAcquisition, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3200_ReadDigitalInput, - i_APCI3200_ConfigDigitalOutput, - i_APCI3200_WriteDigitalOutput, - i_APCI3200_ReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci3200", + APCI3200_BOARD_VENDOR_ID, + 0x3000, + 128, + 256, + 4, + 4, + ADDIDATA_EEPROM, + ADDIDATA_S5920, + 16, + 8, + 16, + 0, + 0x3ffff, + 0, + &range_apci3200_ai, + NULL, + 4, + 4, + 0, + 0, + NULL, + 0, + 0, + 0, + 10000, + 100000, + v_APCI3200_Interrupt, + i_APCI3200_Reset, + i_APCI3200_ConfigAnalogInput, + i_APCI3200_ReadAnalogInput, + i_APCI3200_InsnWriteReleaseAnalogInput, + i_APCI3200_InsnBits_AnalogInput_Test, + i_APCI3200_CommandTestAnalogInput, + i_APCI3200_CommandAnalogInput, + i_APCI3200_StopCyclicAcquisition, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3200_ReadDigitalInput, + i_APCI3200_ConfigDigitalOutput, + i_APCI3200_WriteDigitalOutput, + i_APCI3200_ReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_3300 - //Begin JK 20.10.2004: APCI-3300 integration - {"apci3300", - APCI3200_BOARD_VENDOR_ID, - 0x3007, - 128, - 256, - 4, - 4, - ADDIDATA_EEPROM, - ADDIDATA_S5920, - 0, - 8, - 8, - 0, - 0x3ffff, - 0, - &range_apci3300_ai, - NULL, - 4, - 4, - 0, - 0, - NULL, - 0, - 0, - 0, - 10000, - 100000, - v_APCI3200_Interrupt, - i_APCI3200_Reset, - i_APCI3200_ConfigAnalogInput, - i_APCI3200_ReadAnalogInput , - i_APCI3200_InsnWriteReleaseAnalogInput, - i_APCI3200_InsnBits_AnalogInput_Test, - i_APCI3200_CommandTestAnalogInput, - i_APCI3200_CommandAnalogInput, - i_APCI3200_StopCyclicAcquisition, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3200_ReadDigitalInput, - i_APCI3200_ConfigDigitalOutput, - i_APCI3200_WriteDigitalOutput, - i_APCI3200_ReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, + //Begin JK 20.10.2004: APCI-3300 integration + {"apci3300", + APCI3200_BOARD_VENDOR_ID, + 0x3007, + 128, + 256, + 4, + 4, + ADDIDATA_EEPROM, + ADDIDATA_S5920, + 0, + 8, + 8, + 0, + 0x3ffff, + 0, + &range_apci3300_ai, + NULL, + 4, + 4, + 0, + 0, + NULL, + 0, + 0, + 0, + 10000, + 100000, + v_APCI3200_Interrupt, + i_APCI3200_Reset, + i_APCI3200_ConfigAnalogInput, + i_APCI3200_ReadAnalogInput, + i_APCI3200_InsnWriteReleaseAnalogInput, + i_APCI3200_InsnBits_AnalogInput_Test, + i_APCI3200_CommandTestAnalogInput, + i_APCI3200_CommandAnalogInput, + i_APCI3200_StopCyclicAcquisition, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3200_ReadDigitalInput, + i_APCI3200_ConfigDigitalOutput, + i_APCI3200_WriteDigitalOutput, + i_APCI3200_ReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_1710 - {"apci1710",APCI1710_BOARD_VENDOR_ID,APCI1710_BOARD_DEVICE_ID, - 128, - 8, - 256, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 0, - 0, - 0, - 0, - NULL, - 0, - 0, - 0, - 0, - 0, - v_APCI1710_Interrupt, - i_APCI1710_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, + {"apci1710", APCI1710_BOARD_VENDOR_ID, APCI1710_BOARD_DEVICE_ID, + 128, + 8, + 256, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 0, + 0, + 0, + 0, + NULL, + 0, + 0, + 0, + 0, + 0, + v_APCI1710_Interrupt, + i_APCI1710_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, #endif #ifdef CONFIG_APCI_16XX - {"apci1648", - 0x15B8, - 0x1009, - 128, - 0, - 0, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 0, - 0, - 0, - 48, - &range_apci16xx_ttl, - 0, - 0, - 0, - 0, - 0, - NULL, - i_APCI16XX_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI16XX_InsnConfigInitTTLIO, - i_APCI16XX_InsnBitsReadTTLIO, - i_APCI16XX_InsnReadTTLIOAllPortValue, - i_APCI16XX_InsnBitsWriteTTLIO - }, - - - {"apci1696", - 0x15B8, - 0x100A, - 128, - 0, - 0, - 0, - ADDIDATA_NO_EEPROM, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - NULL, - NULL, - 0, - 0, - 0, - 96, - &range_apci16xx_ttl, - 0, - 0, - 0, - 0, - 0, - NULL, - i_APCI16XX_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI16XX_InsnConfigInitTTLIO, - i_APCI16XX_InsnBitsReadTTLIO, - i_APCI16XX_InsnReadTTLIOAllPortValue, - i_APCI16XX_InsnBitsWriteTTLIO - }, + {"apci1648", + 0x15B8, + 0x1009, + 128, + 0, + 0, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 0, + 0, + 0, + 48, + &range_apci16xx_ttl, + 0, + 0, + 0, + 0, + 0, + NULL, + i_APCI16XX_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI16XX_InsnConfigInitTTLIO, + i_APCI16XX_InsnBitsReadTTLIO, + i_APCI16XX_InsnReadTTLIOAllPortValue, + i_APCI16XX_InsnBitsWriteTTLIO}, + + {"apci1696", + 0x15B8, + 0x100A, + 128, + 0, + 0, + 0, + ADDIDATA_NO_EEPROM, + NULL, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + NULL, + 0, + 0, + 0, + 96, + &range_apci16xx_ttl, + 0, + 0, + 0, + 0, + 0, + NULL, + i_APCI16XX_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI16XX_InsnConfigInitTTLIO, + i_APCI16XX_InsnBitsReadTTLIO, + i_APCI16XX_InsnReadTTLIOAllPortValue, + i_APCI16XX_InsnBitsWriteTTLIO}, #endif #ifdef CONFIG_APCI_3XXX - {"apci3000-16", - 0x15B8, - 0x3010, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3000-8", - 0x15B8, - 0x300F, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3000-4", - 0x15B8, - 0x300E, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 4, - 2, - 4, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3006-16", - 0x15B8, - 0x3013, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3006-8", - 0x15B8, - 0x3014, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3006-4", - 0x15B8, - 0x3015, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 4, - 2, - 4, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3010-16", - 0x15B8, - 0x3016, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3010-8", - 0x15B8, - 0x3017, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3010-4", - 0x15B8, - 0x3018, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 4, - 2, - 4, - 0, - 4095, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3016-16", - 0x15B8, - 0x3019, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3016-8", - 0x15B8, - 0x301A, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3016-4", - 0x15B8, - 0x301B, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 4, - 2, - 4, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3100-16-4", - 0x15B8, - 0x301C, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 4, - 4095, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3100-8-4", - 0x15B8, - 0x301D, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 4, - 4095, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3106-16-4", - 0x15B8, - 0x301E, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 4, - 65535, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3106-8-4", - 0x15B8, - 0x301F, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 4, - 65535, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 10000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3110-16-4", - 0x15B8, - 0x3020, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 4, - 4095, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3110-8-4", - 0x15B8, - 0x3021, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 4, - 4095, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3116-16-4", - 0x15B8, - 0x3022, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 16, - 8, - 16, - 4, - 65535, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3116-8-4", - 0x15B8, - 0x3023, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 8, - 4, - 8, - 4, - 65535, - 4095, - &range_apci3XXX_ai, - &range_apci3XXX_ao, - 4, - 4, - 1, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, - - {"apci3003", - 0x15B8, - 0x300B, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 0, - 4, - 4, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 0, - NULL, - 0, - 0, - 7, - 2500, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, - - {"apci3002-16", - 0x15B8, - 0x3002, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 0, - 16, - 16, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 0, - NULL, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, - - {"apci3002-8", - 0x15B8, - 0x3003, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 0, - 8, - 8, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 0, - NULL, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, - - {"apci3002-4", - 0x15B8, - 0x3004, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 0, - 4, - 4, - 0, - 65535, - 0, - &range_apci3XXX_ai, - NULL, - 4, - 4, - 1, - 0, - NULL, - 0, - 0, - 6, - 5000, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - i_APCI3XXX_InsnConfigAnalogInput, - i_APCI3XXX_InsnReadAnalogInput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnReadDigitalInput, - NULL, - i_APCI3XXX_InsnBitsDigitalInput, - NULL, - i_APCI3XXX_InsnWriteDigitalOutput, - i_APCI3XXX_InsnBitsDigitalOutput, - i_APCI3XXX_InsnReadDigitalOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL - }, - - {"apci3500", - 0x15B8, - 0x3024, - 256, - 256, - 256, - 256, - ADDIDATA_NO_EEPROM, - ADDIDATA_9054, - 0, - 0, - 0, - 4, - 0, - 4095, - NULL, - &range_apci3XXX_ao, - 0, - 0, - 0, - 24, - &range_apci3XXX_ttl, - 0, - 0, - 0, - 0, - 0, - v_APCI3XXX_Interrupt, - i_APCI3XXX_Reset, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnWriteAnalogOutput, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - i_APCI3XXX_InsnConfigInitTTLIO, - i_APCI3XXX_InsnBitsTTLIO, - i_APCI3XXX_InsnReadTTLIO, - i_APCI3XXX_InsnWriteTTLIO - }, + {"apci3000-16", + 0x15B8, + 0x3010, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3000-8", + 0x15B8, + 0x300F, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3000-4", + 0x15B8, + 0x300E, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 4, + 2, + 4, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3006-16", + 0x15B8, + 0x3013, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3006-8", + 0x15B8, + 0x3014, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3006-4", + 0x15B8, + 0x3015, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 4, + 2, + 4, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3010-16", + 0x15B8, + 0x3016, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3010-8", + 0x15B8, + 0x3017, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3010-4", + 0x15B8, + 0x3018, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 4, + 2, + 4, + 0, + 4095, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3016-16", + 0x15B8, + 0x3019, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3016-8", + 0x15B8, + 0x301A, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3016-4", + 0x15B8, + 0x301B, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 4, + 2, + 4, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3100-16-4", + 0x15B8, + 0x301C, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 4, + 4095, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3100-8-4", + 0x15B8, + 0x301D, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 4, + 4095, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3106-16-4", + 0x15B8, + 0x301E, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 4, + 65535, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3106-8-4", + 0x15B8, + 0x301F, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 4, + 65535, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 10000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3110-16-4", + 0x15B8, + 0x3020, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 4, + 4095, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3110-8-4", + 0x15B8, + 0x3021, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 4, + 4095, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3116-16-4", + 0x15B8, + 0x3022, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 16, + 8, + 16, + 4, + 65535, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3116-8-4", + 0x15B8, + 0x3023, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 8, + 4, + 8, + 4, + 65535, + 4095, + &range_apci3XXX_ai, + &range_apci3XXX_ao, + 4, + 4, + 1, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, + + {"apci3003", + 0x15B8, + 0x300B, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 0, + 4, + 4, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 0, + NULL, + 0, + 0, + 7, + 2500, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, + + {"apci3002-16", + 0x15B8, + 0x3002, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 0, + 16, + 16, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 0, + NULL, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, + + {"apci3002-8", + 0x15B8, + 0x3003, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 0, + 8, + 8, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 0, + NULL, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, + + {"apci3002-4", + 0x15B8, + 0x3004, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 0, + 4, + 4, + 0, + 65535, + 0, + &range_apci3XXX_ai, + NULL, + 4, + 4, + 1, + 0, + NULL, + 0, + 0, + 6, + 5000, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + i_APCI3XXX_InsnConfigAnalogInput, + i_APCI3XXX_InsnReadAnalogInput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnReadDigitalInput, + NULL, + i_APCI3XXX_InsnBitsDigitalInput, + NULL, + i_APCI3XXX_InsnWriteDigitalOutput, + i_APCI3XXX_InsnBitsDigitalOutput, + i_APCI3XXX_InsnReadDigitalOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL}, + + {"apci3500", + 0x15B8, + 0x3024, + 256, + 256, + 256, + 256, + ADDIDATA_NO_EEPROM, + ADDIDATA_9054, + 0, + 0, + 0, + 4, + 0, + 4095, + NULL, + &range_apci3XXX_ao, + 0, + 0, + 0, + 24, + &range_apci3XXX_ttl, + 0, + 0, + 0, + 0, + 0, + v_APCI3XXX_Interrupt, + i_APCI3XXX_Reset, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnWriteAnalogOutput, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + i_APCI3XXX_InsnConfigInitTTLIO, + i_APCI3XXX_InsnBitsTTLIO, + i_APCI3XXX_InsnReadTTLIO, + i_APCI3XXX_InsnWriteTTLIO}, #endif }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -comedi_driver driver_addi ={ - driver_name: "addi_common", - module: THIS_MODULE, - attach: i_ADDI_Attach, - detach: i_ADDI_Detach, - num_names: n_boardtypes, - board_name: &boardtypes[0].pc_DriverName, - offset: sizeof(boardtype), - }; - +comedi_driver driver_addi = { + driver_name:"addi_common", + module:THIS_MODULE, + attach:i_ADDI_Attach, + detach:i_ADDI_Detach, + num_names:n_boardtypes, + board_name:&boardtypes[0].pc_DriverName, + offset:sizeof(boardtype), +}; //This macro is defined in comedidev.h /* #define COMEDI_INITCLEANUP(x) \ @@ -2513,8 +2465,6 @@ comedi_driver driver_addi ={ COMEDI_INITCLEANUP(driver_addi); - - /* +----------------------------------------------------------------------------+ | Function name :static int i_ADDI_Attach(comedi_device *dev, | @@ -2535,391 +2485,356 @@ COMEDI_INITCLEANUP(driver_addi); +----------------------------------------------------------------------------+ */ - -static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it) +static int i_ADDI_Attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int ret,pages,i,n_subdevices; - DWORD dw_Dummy; + int ret, pages, i, n_subdevices; + DWORD dw_Dummy; resource_size_t io_addr[5]; unsigned int irq; - resource_size_t iobase_a,iobase_main,iobase_addon,iobase_reserved; - struct pcilst_struct *card=NULL; - unsigned char pci_bus,pci_slot,pci_func; + resource_size_t iobase_a, iobase_main, iobase_addon, iobase_reserved; + struct pcilst_struct *card = NULL; + unsigned char pci_bus, pci_slot, pci_func; int i_Dma = 0; - static char c_Identifier [150]; - - sprintf (c_Identifier, "Addi-Data GmbH Comedi %s", this_board->pc_DriverName); - - if (!pci_list_builded) - { - v_pci_card_list_init(this_board->i_VendorId,1); //1 for displaying the list.. - pci_list_builded=1; - } - - //rt_printk("comedi%d: addi_common: board=%s",dev->minor,this_board->pc_DriverName); - - if ((this_board->i_Dma) && (it->options[2] == 0)) - { - i_Dma = 1; - } - - if ((card=ptr_select_and_alloc_pci_card(this_board->i_VendorId, - this_board->i_DeviceId, - it->options[0], - it->options[1], - i_Dma))==NULL) - { - return -EIO; - } - - if ((i_pci_card_data(card,&pci_bus,&pci_slot,&pci_func,&io_addr[0],&irq))<0) - { - i_pci_card_free(card); - printk(" - Can't get AMCC data!\n"); - return -EIO; - } - - iobase_a=io_addr[0]; - iobase_main=io_addr[1]; - iobase_addon=io_addr[2]; - iobase_reserved=io_addr[3]; - printk("\nBus %d: Slot %d: Funct%d\nBase0: 0x%8llx\nBase1: 0x%8llx\nBase2: 0x%8llx\nBase3: 0x%8llx\n", - pci_bus,pci_slot,pci_func,(unsigned long long)io_addr[0], - (unsigned long long)io_addr[1],(unsigned long long)io_addr[2], - (unsigned long long)io_addr[3]); - - if ((this_board->pc_EepromChip == NULL) || (strcmp (this_board->pc_EepromChip, ADDIDATA_9054) != 0)) - { - /************************************/ - /* Test if more that 1 address used */ - /************************************/ - - if (this_board->i_IorangeBase1 != 0) - { - dev->iobase=(unsigned long)iobase_main;// DAQ base address... - } - else - { - dev->iobase=(unsigned long)iobase_a;// DAQ base address... - } - - dev->board_name =this_board->pc_DriverName; - if((ret=alloc_private(dev,sizeof(addi_private)))<0) - { - return -ENOMEM; - } - devpriv->amcc=card; - devpriv->iobase=(INT)dev->iobase; - devpriv->i_IobaseAmcc=(INT)iobase_a;//AMCC base address... - devpriv->i_IobaseAddon=(INT)iobase_addon;//ADD ON base address.... - devpriv->i_IobaseReserved=(INT)iobase_reserved; - devpriv->ps_BoardInfo = this_board; - } - else - { - if((ret=alloc_private(dev,sizeof(addi_private)))<0) - { - return -ENOMEM; - } - - dev->board_name =this_board->pc_DriverName; - dev->iobase=(unsigned long)io_addr[2]; - devpriv->amcc=card; - devpriv->iobase=(INT)io_addr[2]; - devpriv->ps_BoardInfo = this_board; - devpriv->i_IobaseReserved=(INT)io_addr[3]; - printk ("\nioremap begin"); - devpriv->dw_AiBase=(ULONG_PTR) ioremap(io_addr[3],this_board->i_IorangeBase3); - printk ("\nioremap end"); - } - - //## - - if (irq>0) - { - if (comedi_request_irq(irq, v_ADDI_Interrupt, IRQF_SHARED, c_Identifier, dev) < 0) - { - printk(", unable to allocate IRQ %u, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ - } - else - { - rt_printk("\nirq=%u", irq); - } - } - else - { - rt_printk(", IRQ disabled"); - } - - printk("\nOption %d %d %d\n",it->options[0],it->options[1],it->options[2]); - dev->irq = irq; - - // Read eepeom and fill boardtype Structure - - if(this_board->i_PCIEeprom) - { - printk("\nPCI Eeprom used"); - if (!(strcmp(this_board->pc_EepromChip, "S5920"))) - { - // Set 3 wait stait - if(!(strcmp(this_board->pc_DriverName,"apci035"))) - { - outl(0x80808082,devpriv->i_IobaseAmcc+0x60); - } - else - { - outl(0x83838383,devpriv->i_IobaseAmcc+0x60); - } - // Enable the interrupt for the controler - dw_Dummy = inl(devpriv->i_IobaseAmcc+ 0x38); - outl(dw_Dummy | 0x2000,devpriv->i_IobaseAmcc+0x38); - printk ("\nEnable the interrupt for the controler"); - } - printk("\nRead Eeprom"); - i_EepromReadMainHeader(io_addr[0],this_board->pc_EepromChip,dev); - } - else - { - printk("\nPCI Eeprom unused"); - } - - if (it->options[2]>0) - { - devpriv->us_UseDma=ADDI_DISABLE; - } - else - { - devpriv->us_UseDma=ADDI_ENABLE; - } - - if(this_board->i_Dma) - { - printk("\nDMA used"); - if (devpriv->us_UseDma==ADDI_ENABLE) - { - // alloc DMA buffers - devpriv->b_DmaDoubleBuffer=0; - for (i=0; i<2; i++) - { - for (pages=4; pages>=0; pages--) - { - if((devpriv->ul_DmaBufferVirtual[i]=(void *)__get_free_pages(GFP_KERNEL,pages))) - { - break; - } - } - if (devpriv->ul_DmaBufferVirtual[i]) - { - devpriv->ui_DmaBufferPages[i]=pages; - devpriv->ui_DmaBufferSize[i]=PAGE_SIZE*pages; - devpriv->ui_DmaBufferSamples[i]=devpriv->ui_DmaBufferSize[i]>>1; - devpriv->ul_DmaBufferHw[i]=virt_to_bus((void*)devpriv->ul_DmaBufferVirtual[i]); - } - } - if (!devpriv->ul_DmaBufferVirtual[0]) - { - rt_printk(", Can't allocate DMA buffer, DMA disabled!"); - devpriv->us_UseDma=ADDI_DISABLE; - } - - if (devpriv->ul_DmaBufferVirtual[1]) - { - devpriv->b_DmaDoubleBuffer=1; - } - } - - - if ((devpriv->us_UseDma==ADDI_ENABLE)) - { - rt_printk("\nDMA ENABLED\n"); - } - else - { - printk("\nDMA DISABLED\n"); - } - } - - if (!strcmp(this_board->pc_DriverName,"apci1710")) - { -#ifdef CONFIG_APCI_1710 - i_ADDI_AttachPCI1710 (dev); - - // save base address - devpriv->s_BoardInfos.ui_Address=io_addr[2]; -#endif - } - else - { - //Update-0.7.57->0.7.68dev->n_subdevices = 7; - n_subdevices = 7; - if((ret=alloc_subdevices(dev,n_subdevices))<0) - return ret; - - // Allocate and Initialise AI Subdevice Structures - s = dev->subdevices + 0; - if((this_board->i_NbrAiChannel) || (this_board->i_NbrAiChannelDiff)) - { - dev->read_subdev = s; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_RT|SDF_COMMON|SDF_GROUND|SDF_DIFF; - if (this_board->i_NbrAiChannel) - { - s->n_chan = this_board->i_NbrAiChannel; - devpriv->b_SingelDiff = 0; - } - else - { - s->n_chan = this_board->i_NbrAiChannelDiff; - devpriv->b_SingelDiff = 1; - } - s->maxdata = this_board->i_AiMaxdata; - s->len_chanlist = this_board->i_AiChannelList; - s->range_table = this_board->pr_AiRangelist; - - /* Set the initialisation flag */ - devpriv->b_AiInitialisation = 1; - - s->insn_config=this_board->i_hwdrv_InsnConfigAnalogInput; - s->insn_read=this_board->i_hwdrv_InsnReadAnalogInput; - s->insn_write=this_board->i_hwdrv_InsnWriteAnalogInput; - s->insn_bits=this_board->i_hwdrv_InsnBitsAnalogInput; - s->do_cmdtest=this_board->i_hwdrv_CommandTestAnalogInput; - s->do_cmd=this_board->i_hwdrv_CommandAnalogInput; - s->cancel=this_board->i_hwdrv_CancelAnalogInput; - - } - else - { - s->type=COMEDI_SUBD_UNUSED; + static char c_Identifier[150]; + + sprintf(c_Identifier, "Addi-Data GmbH Comedi %s", + this_board->pc_DriverName); + + if (!pci_list_builded) { + v_pci_card_list_init(this_board->i_VendorId, 1); //1 for displaying the list.. + pci_list_builded = 1; } + //rt_printk("comedi%d: addi_common: board=%s",dev->minor,this_board->pc_DriverName); - // Allocate and Initialise AO Subdevice Structures - s = dev->subdevices + 1; - if(this_board->i_NbrAoChannel) - { - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE|SDF_GROUND|SDF_COMMON|SDF_RT; - s->n_chan = this_board->i_NbrAoChannel; - s->maxdata = this_board->i_AoMaxdata; - s->len_chanlist = this_board->i_NbrAoChannel; - s->range_table = this_board->pr_AoRangelist; - s->insn_config=this_board->i_hwdrv_InsnConfigAnalogOutput; - s->insn_write=this_board->i_hwdrv_InsnWriteAnalogOutput; + if ((this_board->i_Dma) && (it->options[2] == 0)) { + i_Dma = 1; } - else - { - s->type=COMEDI_SUBD_UNUSED; + + if ((card = ptr_select_and_alloc_pci_card(this_board->i_VendorId, + this_board->i_DeviceId, + it->options[0], + it->options[1], i_Dma)) == NULL) { + return -EIO; } - // Allocate and Initialise DI Subdevice Structures - s = dev->subdevices + 2; - if(this_board->i_NbrDiChannel) - { - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = this_board->i_NbrDiChannel; - s->maxdata = 1; - s->len_chanlist = this_board->i_NbrDiChannel; - s->range_table = &range_digital; - s->io_bits=0; /* all bits input */ - s->insn_config=this_board->i_hwdrv_InsnConfigDigitalInput; - s->insn_read=this_board->i_hwdrv_InsnReadDigitalInput; - s->insn_write=this_board->i_hwdrv_InsnWriteDigitalInput; - s->insn_bits=this_board->i_hwdrv_InsnBitsDigitalInput; + + if ((i_pci_card_data(card, &pci_bus, &pci_slot, &pci_func, &io_addr[0], + &irq)) < 0) { + i_pci_card_free(card); + printk(" - Can't get AMCC data!\n"); + return -EIO; } - else - { - s->type=COMEDI_SUBD_UNUSED; + + iobase_a = io_addr[0]; + iobase_main = io_addr[1]; + iobase_addon = io_addr[2]; + iobase_reserved = io_addr[3]; + printk("\nBus %d: Slot %d: Funct%d\nBase0: 0x%8llx\nBase1: 0x%8llx\nBase2: 0x%8llx\nBase3: 0x%8llx\n", pci_bus, pci_slot, pci_func, (unsigned long long)io_addr[0], (unsigned long long)io_addr[1], (unsigned long long)io_addr[2], (unsigned long long)io_addr[3]); + + if ((this_board->pc_EepromChip == NULL) + || (strcmp(this_board->pc_EepromChip, ADDIDATA_9054) != 0)) { + /************************************/ + /* Test if more that 1 address used */ + /************************************/ + + if (this_board->i_IorangeBase1 != 0) { + dev->iobase = (unsigned long)iobase_main; // DAQ base address... + } else { + dev->iobase = (unsigned long)iobase_a; // DAQ base address... + } + + dev->board_name = this_board->pc_DriverName; + if ((ret = alloc_private(dev, sizeof(addi_private))) < 0) { + return -ENOMEM; + } + devpriv->amcc = card; + devpriv->iobase = (INT) dev->iobase; + devpriv->i_IobaseAmcc = (INT) iobase_a; //AMCC base address... + devpriv->i_IobaseAddon = (INT) iobase_addon; //ADD ON base address.... + devpriv->i_IobaseReserved = (INT) iobase_reserved; + devpriv->ps_BoardInfo = this_board; + } else { + if ((ret = alloc_private(dev, sizeof(addi_private))) < 0) { + return -ENOMEM; + } + + dev->board_name = this_board->pc_DriverName; + dev->iobase = (unsigned long)io_addr[2]; + devpriv->amcc = card; + devpriv->iobase = (INT) io_addr[2]; + devpriv->ps_BoardInfo = this_board; + devpriv->i_IobaseReserved = (INT) io_addr[3]; + printk("\nioremap begin"); + devpriv->dw_AiBase = + (ULONG_PTR) ioremap(io_addr[3], + this_board->i_IorangeBase3); + printk("\nioremap end"); } - // Allocate and Initialise DO Subdevice Structures - s = dev->subdevices + 3; - if(this_board->i_NbrDoChannel) - { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_READABLE|SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan= this_board->i_NbrDoChannel; - s->maxdata = this_board->i_DoMaxdata; - s->len_chanlist =this_board->i_NbrDoChannel ; - s->range_table = &range_digital; - s->io_bits=0xf; /* all bits output */ - - s->insn_config=this_board->i_hwdrv_InsnConfigDigitalOutput;//for digital output memory.. - s->insn_write=this_board->i_hwdrv_InsnWriteDigitalOutput; - s->insn_bits=this_board->i_hwdrv_InsnBitsDigitalOutput; - s->insn_read=this_board->i_hwdrv_InsnReadDigitalOutput; - } - else - { - s->type=COMEDI_SUBD_UNUSED; + + //## + + if (irq > 0) { + if (comedi_request_irq(irq, v_ADDI_Interrupt, IRQF_SHARED, + c_Identifier, dev) < 0) { + printk(", unable to allocate IRQ %u, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ + } else { + rt_printk("\nirq=%u", irq); + } + } else { + rt_printk(", IRQ disabled"); } - - // Allocate and Initialise Timer Subdevice Structures - s = dev->subdevices + 4; - if(this_board->i_Timer) - { - s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = 1; - s->maxdata = 0; - s->len_chanlist = 1; - s->range_table = &range_digital; - - s->insn_write=this_board->i_hwdrv_InsnWriteTimer; - s->insn_read=this_board->i_hwdrv_InsnReadTimer; - s->insn_config=this_board->i_hwdrv_InsnConfigTimer; - s->insn_bits=this_board->i_hwdrv_InsnBitsTimer; - } - else - { - s->type=COMEDI_SUBD_UNUSED; + + printk("\nOption %d %d %d\n", it->options[0], it->options[1], + it->options[2]); + dev->irq = irq; + + // Read eepeom and fill boardtype Structure + + if (this_board->i_PCIEeprom) { + printk("\nPCI Eeprom used"); + if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { + // Set 3 wait stait + if (!(strcmp(this_board->pc_DriverName, "apci035"))) { + outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); + } else { + outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); + } + // Enable the interrupt for the controler + dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); + outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); + printk("\nEnable the interrupt for the controler"); + } + printk("\nRead Eeprom"); + i_EepromReadMainHeader(io_addr[0], this_board->pc_EepromChip, + dev); + } else { + printk("\nPCI Eeprom unused"); } - // Allocate and Initialise TTL - s = dev->subdevices + 5; - if(this_board->i_NbrTTLChannel) - { - s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = this_board->i_NbrTTLChannel; - s->maxdata = 1; - s->io_bits=0; /* all bits input */ - s->len_chanlist = this_board->i_NbrTTLChannel; - s->range_table = &range_digital; - s->insn_config = this_board->i_hwdr_ConfigInitTTLIO; - s->insn_bits = this_board->i_hwdr_ReadTTLIOBits; - s->insn_read = this_board->i_hwdr_ReadTTLIOAllPortValue; - s->insn_write = this_board->i_hwdr_WriteTTLIOChlOnOff; - } - else - { - s->type=COMEDI_SUBD_UNUSED; + if (it->options[2] > 0) { + devpriv->us_UseDma = ADDI_DISABLE; + } else { + devpriv->us_UseDma = ADDI_ENABLE; } - - /* EEPROM */ - s=dev->subdevices+6; - if(this_board->i_PCIEeprom) - { - s->type=COMEDI_SUBD_MEMORY; - s->subdev_flags=SDF_READABLE|SDF_INTERNAL; - s->n_chan=256; - s->maxdata=0xffff; - s->insn_read=i_ADDIDATA_InsnReadEeprom; + + if (this_board->i_Dma) { + printk("\nDMA used"); + if (devpriv->us_UseDma == ADDI_ENABLE) { + // alloc DMA buffers + devpriv->b_DmaDoubleBuffer = 0; + for (i = 0; i < 2; i++) { + for (pages = 4; pages >= 0; pages--) { + if ((devpriv->ul_DmaBufferVirtual[i] = + (void *) + __get_free_pages + (GFP_KERNEL, pages))) { + break; + } + } + if (devpriv->ul_DmaBufferVirtual[i]) { + devpriv->ui_DmaBufferPages[i] = pages; + devpriv->ui_DmaBufferSize[i] = + PAGE_SIZE * pages; + devpriv->ui_DmaBufferSamples[i] = + devpriv-> + ui_DmaBufferSize[i] >> 1; + devpriv->ul_DmaBufferHw[i] = + virt_to_bus((void *)devpriv-> + ul_DmaBufferVirtual[i]); + } + } + if (!devpriv->ul_DmaBufferVirtual[0]) { + rt_printk + (", Can't allocate DMA buffer, DMA disabled!"); + devpriv->us_UseDma = ADDI_DISABLE; + } + + if (devpriv->ul_DmaBufferVirtual[1]) { + devpriv->b_DmaDoubleBuffer = 1; + } + } + + if ((devpriv->us_UseDma == ADDI_ENABLE)) { + rt_printk("\nDMA ENABLED\n"); + } else { + printk("\nDMA DISABLED\n"); + } } - else - { - s->type=COMEDI_SUBD_UNUSED; + + if (!strcmp(this_board->pc_DriverName, "apci1710")) { +#ifdef CONFIG_APCI_1710 + i_ADDI_AttachPCI1710(dev); + + // save base address + devpriv->s_BoardInfos.ui_Address = io_addr[2]; +#endif + } else { + //Update-0.7.57->0.7.68dev->n_subdevices = 7; + n_subdevices = 7; + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) + return ret; + + // Allocate and Initialise AI Subdevice Structures + s = dev->subdevices + 0; + if ((this_board->i_NbrAiChannel) + || (this_board->i_NbrAiChannelDiff)) { + dev->read_subdev = s; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_RT | SDF_COMMON | SDF_GROUND + | SDF_DIFF; + if (this_board->i_NbrAiChannel) { + s->n_chan = this_board->i_NbrAiChannel; + devpriv->b_SingelDiff = 0; + } else { + s->n_chan = this_board->i_NbrAiChannelDiff; + devpriv->b_SingelDiff = 1; + } + s->maxdata = this_board->i_AiMaxdata; + s->len_chanlist = this_board->i_AiChannelList; + s->range_table = this_board->pr_AiRangelist; + + /* Set the initialisation flag */ + devpriv->b_AiInitialisation = 1; + + s->insn_config = + this_board->i_hwdrv_InsnConfigAnalogInput; + s->insn_read = this_board->i_hwdrv_InsnReadAnalogInput; + s->insn_write = + this_board->i_hwdrv_InsnWriteAnalogInput; + s->insn_bits = this_board->i_hwdrv_InsnBitsAnalogInput; + s->do_cmdtest = + this_board->i_hwdrv_CommandTestAnalogInput; + s->do_cmd = this_board->i_hwdrv_CommandAnalogInput; + s->cancel = this_board->i_hwdrv_CancelAnalogInput; + + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + // Allocate and Initialise AO Subdevice Structures + s = dev->subdevices + 1; + if (this_board->i_NbrAoChannel) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = + SDF_WRITEABLE | SDF_GROUND | SDF_COMMON | + SDF_RT; + s->n_chan = this_board->i_NbrAoChannel; + s->maxdata = this_board->i_AoMaxdata; + s->len_chanlist = this_board->i_NbrAoChannel; + s->range_table = this_board->pr_AoRangelist; + s->insn_config = + this_board->i_hwdrv_InsnConfigAnalogOutput; + s->insn_write = + this_board->i_hwdrv_InsnWriteAnalogOutput; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + // Allocate and Initialise DI Subdevice Structures + s = dev->subdevices + 2; + if (this_board->i_NbrDiChannel) { + s->type = COMEDI_SUBD_DI; + s->subdev_flags = + SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrDiChannel; + s->maxdata = 1; + s->len_chanlist = this_board->i_NbrDiChannel; + s->range_table = &range_digital; + s->io_bits = 0; /* all bits input */ + s->insn_config = + this_board->i_hwdrv_InsnConfigDigitalInput; + s->insn_read = this_board->i_hwdrv_InsnReadDigitalInput; + s->insn_write = + this_board->i_hwdrv_InsnWriteDigitalInput; + s->insn_bits = this_board->i_hwdrv_InsnBitsDigitalInput; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + // Allocate and Initialise DO Subdevice Structures + s = dev->subdevices + 3; + if (this_board->i_NbrDoChannel) { + s->type = COMEDI_SUBD_DO; + s->subdev_flags = + SDF_READABLE | SDF_WRITEABLE | SDF_RT | + SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrDoChannel; + s->maxdata = this_board->i_DoMaxdata; + s->len_chanlist = this_board->i_NbrDoChannel; + s->range_table = &range_digital; + s->io_bits = 0xf; /* all bits output */ + + s->insn_config = this_board->i_hwdrv_InsnConfigDigitalOutput; //for digital output memory.. + s->insn_write = + this_board->i_hwdrv_InsnWriteDigitalOutput; + s->insn_bits = + this_board->i_hwdrv_InsnBitsDigitalOutput; + s->insn_read = + this_board->i_hwdrv_InsnReadDigitalOutput; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + // Allocate and Initialise Timer Subdevice Structures + s = dev->subdevices + 4; + if (this_board->i_Timer) { + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = + SDF_WRITEABLE | SDF_RT | SDF_GROUND | + SDF_COMMON; + s->n_chan = 1; + s->maxdata = 0; + s->len_chanlist = 1; + s->range_table = &range_digital; + + s->insn_write = this_board->i_hwdrv_InsnWriteTimer; + s->insn_read = this_board->i_hwdrv_InsnReadTimer; + s->insn_config = this_board->i_hwdrv_InsnConfigTimer; + s->insn_bits = this_board->i_hwdrv_InsnBitsTimer; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + // Allocate and Initialise TTL + s = dev->subdevices + 5; + if (this_board->i_NbrTTLChannel) { + s->type = COMEDI_SUBD_TTLIO; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | + SDF_GROUND | SDF_COMMON; + s->n_chan = this_board->i_NbrTTLChannel; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->len_chanlist = this_board->i_NbrTTLChannel; + s->range_table = &range_digital; + s->insn_config = this_board->i_hwdr_ConfigInitTTLIO; + s->insn_bits = this_board->i_hwdr_ReadTTLIOBits; + s->insn_read = this_board->i_hwdr_ReadTTLIOAllPortValue; + s->insn_write = this_board->i_hwdr_WriteTTLIOChlOnOff; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* EEPROM */ + s = dev->subdevices + 6; + if (this_board->i_PCIEeprom) { + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->n_chan = 256; + s->maxdata = 0xffff; + s->insn_read = i_ADDIDATA_InsnReadEeprom; + } else { + s->type = COMEDI_SUBD_UNUSED; + } } - } - - printk("\ni_ADDI_Attach end\n"); + + printk("\ni_ADDI_Attach end\n"); i_ADDI_Reset(dev); - devpriv->b_ValidDriver=1; + devpriv->b_ValidDriver = 1; return 0; } - - /* +----------------------------------------------------------------------------+ | Function name : static int i_ADDI_Detach(comedi_device *dev) | @@ -2939,60 +2854,53 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it) +----------------------------------------------------------------------------+ */ +static int i_ADDI_Detach(comedi_device * dev) +{ -static int i_ADDI_Detach(comedi_device *dev) - { - - if (dev->private) - { - if (devpriv->b_ValidDriver) - { - i_ADDI_Reset(dev); - } - - if(dev->irq) - { - comedi_free_irq(dev->irq,dev); - } - - if ((devpriv->ps_BoardInfo->pc_EepromChip == NULL) || (strcmp (devpriv->ps_BoardInfo->pc_EepromChip, ADDIDATA_9054) != 0)) - { - if (devpriv->allocated) - { - i_pci_card_free(devpriv->amcc); - } - - if (devpriv->ul_DmaBufferVirtual[0]) - { - free_pages((unsigned long)devpriv->ul_DmaBufferVirtual[0],devpriv->ui_DmaBufferPages[0]); - } - - if (devpriv->ul_DmaBufferVirtual[1]) - { - free_pages((unsigned long)devpriv->ul_DmaBufferVirtual[1],devpriv->ui_DmaBufferPages[1]); - } - } - else - { - iounmap ((void *) devpriv->dw_AiBase); - - if (devpriv->allocated) - { - i_pci_card_free(devpriv->amcc); - } - } - - if (pci_list_builded) - { - //v_pci_card_list_cleanup(PCI_VENDOR_ID_AMCC); - v_pci_card_list_cleanup(this_board->i_VendorId); - pci_list_builded=0; - } - } - - return 0; + if (dev->private) { + if (devpriv->b_ValidDriver) { + i_ADDI_Reset(dev); + } + + if (dev->irq) { + comedi_free_irq(dev->irq, dev); + } + + if ((devpriv->ps_BoardInfo->pc_EepromChip == NULL) + || (strcmp(devpriv->ps_BoardInfo->pc_EepromChip, + ADDIDATA_9054) != 0)) { + if (devpriv->allocated) { + i_pci_card_free(devpriv->amcc); + } + + if (devpriv->ul_DmaBufferVirtual[0]) { + free_pages((unsigned long)devpriv-> + ul_DmaBufferVirtual[0], + devpriv->ui_DmaBufferPages[0]); + } + + if (devpriv->ul_DmaBufferVirtual[1]) { + free_pages((unsigned long)devpriv-> + ul_DmaBufferVirtual[1], + devpriv->ui_DmaBufferPages[1]); + } + } else { + iounmap((void *)devpriv->dw_AiBase); + + if (devpriv->allocated) { + i_pci_card_free(devpriv->amcc); + } + } + + if (pci_list_builded) { + //v_pci_card_list_cleanup(PCI_VENDOR_ID_AMCC); + v_pci_card_list_cleanup(this_board->i_VendorId); + pci_list_builded = 0; + } } + return 0; +} /* +----------------------------------------------------------------------------+ @@ -3012,15 +2920,13 @@ static int i_ADDI_Detach(comedi_device *dev) +----------------------------------------------------------------------------+ */ -static int i_ADDI_Reset(comedi_device *dev) +static int i_ADDI_Reset(comedi_device * dev) { - - this_board->i_hwdrv_Reset(dev); + + this_board->i_hwdrv_Reset(dev); return 0; } - - // Interrupt function /* +----------------------------------------------------------------------------+ @@ -3040,12 +2946,13 @@ static int i_ADDI_Reset(comedi_device *dev) +----------------------------------------------------------------------------+ */ -static irqreturn_t v_ADDI_Interrupt(int irq, void *d PT_REGS_ARG) +static irqreturn_t v_ADDI_Interrupt(int irq, void *d PT_REGS_ARG) { -comedi_device *dev = d; -this_board->v_hwdrv_Interrupt(irq,d); -return IRQ_RETVAL(1); + comedi_device *dev = d; + this_board->v_hwdrv_Interrupt(irq, d); + return IRQ_RETVAL(1); } + // EEPROM Read Function /* +----------------------------------------------------------------------------+ @@ -3067,16 +2974,17 @@ return IRQ_RETVAL(1); +----------------------------------------------------------------------------+ */ - -static int i_ADDIDATA_InsnReadEeprom(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - WORD w_Data; - WORD w_Address; - w_Address = CR_CHAN(insn->chanspec);// address to be read as 0,1,2,3...255 - - w_Data=w_EepromReadWord(devpriv->i_IobaseAmcc,this_board->pc_EepromChip,0x100+(2*w_Address)); - data[0]=w_Data; - //multiplied by 2 bcozinput will be like 0,1,2...255 - return insn->n; +static int i_ADDIDATA_InsnReadEeprom(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + WORD w_Data; + WORD w_Address; + w_Address = CR_CHAN(insn->chanspec); // address to be read as 0,1,2,3...255 + + w_Data = w_EepromReadWord(devpriv->i_IobaseAmcc, + this_board->pc_EepromChip, 0x100 + (2 * w_Address)); + data[0] = w_Data; + //multiplied by 2 bcozinput will be like 0,1,2...255 + return insn->n; } diff --git a/comedi/drivers/addi-data/addi_common.h b/comedi/drivers/addi-data/addi_common.h index 00854054..70b4fd63 100644 --- a/comedi/drivers/addi-data/addi_common.h +++ b/comedi/drivers/addi-data/addi_common.h @@ -38,9 +38,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +-----------------------------------------------------------------------+ */ - - - //including header files #include @@ -91,8 +88,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define DWORD unsigned int /* 32-bit */ #define WORD unsigned short -#define ADDI_ENABLE 1 -#define ADDI_DISABLE 0 +#define ADDI_ENABLE 1 +#define ADDI_DISABLE 0 #define APCI1710_SAVE_INTERRUPT 1 #define ADDIDATA_EEPROM 1 @@ -106,403 +103,382 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define ADDIDATA_ENABLE 1 #define ADDIDATA_DISABLE 0 - // Structures // structure for the boardtype typedef struct { - const PCHAR pc_DriverName; // driver name - INT i_VendorId; //PCI vendor a device ID of card - INT i_DeviceId; - INT i_IorangeBase0; - INT i_IorangeBase1; - INT i_IorangeBase2; // base 2 range - INT i_IorangeBase3; // base 3 range - INT i_PCIEeprom; // eeprom present or not - PCHAR pc_EepromChip; // type of chip - INT i_NbrAiChannel; // num of A/D chans - INT i_NbrAiChannelDiff;// num of A/D chans in diff mode - INT i_AiChannelList;// len of chanlist - INT i_NbrAoChannel;// num of D/A chans - INT i_AiMaxdata;// resolution of A/D - INT i_AoMaxdata;// resolution of D/A - PRANGE pr_AiRangelist; // rangelist for A/D - PRANGE pr_AoRangelist;// rangelist for D/A - - INT i_NbrDiChannel; // Number of DI channels - INT i_NbrDoChannel; // Number of DO channels - INT i_DoMaxdata; // data to set all chanels high - - INT i_NbrTTLChannel; // Number of TTL channels - PRANGE pr_TTLRangelist; // rangelist for TTL - - INT i_Dma; // dma present or not - INT i_Timer; // timer subdevice present or not - BYTE b_AvailableConvertUnit; - UINT ui_MinAcquisitiontimeNs; // Minimum Acquisition in Nano secs - UINT ui_MinDelaytimeNs; // Minimum Delay in Nano secs + const PCHAR pc_DriverName; // driver name + INT i_VendorId; //PCI vendor a device ID of card + INT i_DeviceId; + INT i_IorangeBase0; + INT i_IorangeBase1; + INT i_IorangeBase2; // base 2 range + INT i_IorangeBase3; // base 3 range + INT i_PCIEeprom; // eeprom present or not + PCHAR pc_EepromChip; // type of chip + INT i_NbrAiChannel; // num of A/D chans + INT i_NbrAiChannelDiff; // num of A/D chans in diff mode + INT i_AiChannelList; // len of chanlist + INT i_NbrAoChannel; // num of D/A chans + INT i_AiMaxdata; // resolution of A/D + INT i_AoMaxdata; // resolution of D/A + PRANGE pr_AiRangelist; // rangelist for A/D + PRANGE pr_AoRangelist; // rangelist for D/A + + INT i_NbrDiChannel; // Number of DI channels + INT i_NbrDoChannel; // Number of DO channels + INT i_DoMaxdata; // data to set all chanels high + + INT i_NbrTTLChannel; // Number of TTL channels + PRANGE pr_TTLRangelist; // rangelist for TTL + + INT i_Dma; // dma present or not + INT i_Timer; // timer subdevice present or not + BYTE b_AvailableConvertUnit; + UINT ui_MinAcquisitiontimeNs; // Minimum Acquisition in Nano secs + UINT ui_MinDelaytimeNs; // Minimum Delay in Nano secs // interrupt and reset - void (*v_hwdrv_Interrupt)(int irq, void *d); - int (*i_hwdrv_Reset)(comedi_device *dev); + void (*v_hwdrv_Interrupt) (int irq, void *d); + int (*i_hwdrv_Reset) (comedi_device * dev); //Subdevice functions //ANALOG INPUT -int (*i_hwdrv_InsnConfigAnalogInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnReadAnalogInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnWriteAnalogInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnBitsAnalogInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_CommandTestAnalogInput)(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) ; -int (*i_hwdrv_CommandAnalogInput)(comedi_device * dev,comedi_subdevice * s); -int (*i_hwdrv_CancelAnalogInput)(comedi_device * dev, comedi_subdevice * s); - + int (*i_hwdrv_InsnConfigAnalogInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnReadAnalogInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnWriteAnalogInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnBitsAnalogInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_CommandTestAnalogInput) (comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd); + int (*i_hwdrv_CommandAnalogInput) (comedi_device * dev, + comedi_subdevice * s); + int (*i_hwdrv_CancelAnalogInput) (comedi_device * dev, + comedi_subdevice * s); //Analog Output -int (*i_hwdrv_InsnConfigAnalogOutput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnWriteAnalogOutput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnBitsAnalogOutput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - + int (*i_hwdrv_InsnConfigAnalogOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnWriteAnalogOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnBitsAnalogOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); //Digital Input -int (*i_hwdrv_InsnConfigDigitalInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdrv_InsnReadDigitalInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnWriteDigitalInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnBitsDigitalInput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); + int (*i_hwdrv_InsnConfigDigitalInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnReadDigitalInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnWriteDigitalInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnBitsDigitalInput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); //Digital Output -int (*i_hwdrv_InsnConfigDigitalOutput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnWriteDigitalOutput)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnBitsDigitalOutput)(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); -int (*i_hwdrv_InsnReadDigitalOutput)(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); + int (*i_hwdrv_InsnConfigDigitalOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnWriteDigitalOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnBitsDigitalOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnReadDigitalOutput) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); //TIMER - int (*i_hwdrv_InsnConfigTimer)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdrv_InsnWriteTimer)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdrv_InsnReadTimer)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdrv_InsnBitsTimer)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); + int (*i_hwdrv_InsnConfigTimer) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnWriteTimer) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnReadTimer) (comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + int (*i_hwdrv_InsnBitsTimer) (comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //TTL IO - int (*i_hwdr_ConfigInitTTLIO)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdr_ReadTTLIOBits)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdr_ReadTTLIOAllPortValue)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - int (*i_hwdr_WriteTTLIOChlOnOff)(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); + int (*i_hwdr_ConfigInitTTLIO) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdr_ReadTTLIOBits) (comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + int (*i_hwdr_ReadTTLIOAllPortValue) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + int (*i_hwdr_WriteTTLIOChlOnOff) (comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); } boardtype; - - - - - //MODULE INFO STRUCTURE - - - typedef union - { +typedef union { /*****************************/ - /* Incremental counter infos */ + /* Incremental counter infos */ /*****************************/ - struct - { - union - { - struct - { - BYTE b_ModeRegister1; - BYTE b_ModeRegister2; - BYTE b_ModeRegister3; - BYTE b_ModeRegister4; - }s_ByteModeRegister; - DWORD dw_ModeRegister1_2_3_4; - }s_ModeRegister; - - struct - { - unsigned int b_IndexInit : 1; - unsigned int b_CounterInit : 1; - unsigned int b_ReferenceInit : 1; - unsigned int b_IndexInterruptOccur : 1; - unsigned int b_CompareLogicInit : 1; - unsigned int b_FrequencyMeasurementInit : 1; - unsigned int b_FrequencyMeasurementEnable : 1; - }s_InitFlag; - - }s_SiemensCounterInfo; + struct { + union { + struct { + BYTE b_ModeRegister1; + BYTE b_ModeRegister2; + BYTE b_ModeRegister3; + BYTE b_ModeRegister4; + } s_ByteModeRegister; + DWORD dw_ModeRegister1_2_3_4; + } s_ModeRegister; + + struct { + unsigned int b_IndexInit:1; + unsigned int b_CounterInit:1; + unsigned int b_ReferenceInit:1; + unsigned int b_IndexInterruptOccur:1; + unsigned int b_CompareLogicInit:1; + unsigned int b_FrequencyMeasurementInit:1; + unsigned int b_FrequencyMeasurementEnable:1; + } s_InitFlag; + + } s_SiemensCounterInfo; /*************/ - /* SSI infos */ + /* SSI infos */ /*************/ - struct - { - BYTE b_SSIProfile; - BYTE b_PositionTurnLength; - BYTE b_TurnCptLength; - BYTE b_SSIInit; - }s_SSICounterInfo; - + struct { + BYTE b_SSIProfile; + BYTE b_PositionTurnLength; + BYTE b_TurnCptLength; + BYTE b_SSIInit; + } s_SSICounterInfo; /*****************/ - /* TTL I/O infos */ + /* TTL I/O infos */ /*****************/ - struct - { - BYTE b_TTLInit; - BYTE b_PortConfiguration [4]; - }s_TTLIOInfo; + struct { + BYTE b_TTLInit; + BYTE b_PortConfiguration[4]; + } s_TTLIOInfo; /*********************/ - /* Digital I/O infos */ + /* Digital I/O infos */ /*********************/ - struct - { - BYTE b_DigitalInit; - BYTE b_ChannelAMode; - BYTE b_ChannelBMode; - BYTE b_OutputMemoryEnabled; - DWORD dw_OutputMemory; - }s_DigitalIOInfo; + struct { + BYTE b_DigitalInit; + BYTE b_ChannelAMode; + BYTE b_ChannelBMode; + BYTE b_OutputMemoryEnabled; + DWORD dw_OutputMemory; + } s_DigitalIOInfo; /*********************/ - /* 82X54 timer infos */ + /* 82X54 timer infos */ /*********************/ - struct - { - struct - { - BYTE b_82X54Init; - BYTE b_InputClockSelection; - BYTE b_InputClockLevel; - BYTE b_OutputLevel; - BYTE b_HardwareGateLevel; - DWORD dw_ConfigurationWord; - }s_82X54TimerInfo [3]; - BYTE b_InterruptMask; - }s_82X54ModuleInfo; + struct { + struct { + BYTE b_82X54Init; + BYTE b_InputClockSelection; + BYTE b_InputClockLevel; + BYTE b_OutputLevel; + BYTE b_HardwareGateLevel; + DWORD dw_ConfigurationWord; + } s_82X54TimerInfo[3]; + BYTE b_InterruptMask; + } s_82X54ModuleInfo; /*********************/ - /* Chronometer infos */ + /* Chronometer infos */ /*********************/ - struct - { - BYTE b_ChronoInit; - BYTE b_InterruptMask; - BYTE b_PCIInputClock; - BYTE b_TimingUnit; - BYTE b_CycleMode; - double d_TimingInterval; - DWORD dw_ConfigReg; - }s_ChronoModuleInfo; + struct { + BYTE b_ChronoInit; + BYTE b_InterruptMask; + BYTE b_PCIInputClock; + BYTE b_TimingUnit; + BYTE b_CycleMode; + double d_TimingInterval; + DWORD dw_ConfigReg; + } s_ChronoModuleInfo; /***********************/ - /* Pulse encoder infos */ + /* Pulse encoder infos */ /***********************/ - struct - { - struct - { - BYTE b_PulseEncoderInit; - }s_PulseEncoderInfo [4]; - DWORD dw_SetRegister; - DWORD dw_ControlRegister; - DWORD dw_StatusRegister; - }s_PulseEncoderModuleInfo; + struct { + struct { + BYTE b_PulseEncoderInit; + } s_PulseEncoderInfo[4]; + DWORD dw_SetRegister; + DWORD dw_ControlRegister; + DWORD dw_StatusRegister; + } s_PulseEncoderModuleInfo; /********************/ - /* Tor conter infos */ + /* Tor conter infos */ /********************/ - struct - { - struct - { - BYTE b_TorCounterInit; - BYTE b_TimingUnit; - BYTE b_InterruptEnable; - double d_TimingInterval; - ULONG ul_RealTimingInterval; - }s_TorCounterInfo [2]; - BYTE b_PCIInputClock; - }s_TorCounterModuleInfo; + struct { + struct { + BYTE b_TorCounterInit; + BYTE b_TimingUnit; + BYTE b_InterruptEnable; + double d_TimingInterval; + ULONG ul_RealTimingInterval; + } s_TorCounterInfo[2]; + BYTE b_PCIInputClock; + } s_TorCounterModuleInfo; /*************/ - /* PWM infos */ + /* PWM infos */ /*************/ - struct - { - struct - { - BYTE b_PWMInit; - BYTE b_TimingUnit; - BYTE b_InterruptEnable; - double d_LowTiming; - double d_HighTiming; - ULONG ul_RealLowTiming; - ULONG ul_RealHighTiming; - }s_PWMInfo [2]; - BYTE b_ClockSelection; - }s_PWMModuleInfo; + struct { + struct { + BYTE b_PWMInit; + BYTE b_TimingUnit; + BYTE b_InterruptEnable; + double d_LowTiming; + double d_HighTiming; + ULONG ul_RealLowTiming; + ULONG ul_RealHighTiming; + } s_PWMInfo[2]; + BYTE b_ClockSelection; + } s_PWMModuleInfo; /*************/ - /* ETM infos */ + /* ETM infos */ /*************/ - struct - { - struct - { - BYTE b_ETMEnable; - BYTE b_ETMInterrupt; - }s_ETMInfo [2]; - BYTE b_ETMInit; - BYTE b_TimingUnit; - BYTE b_ClockSelection; - double d_TimingInterval; - ULONG ul_Timing; - }s_ETMModuleInfo; + struct { + struct { + BYTE b_ETMEnable; + BYTE b_ETMInterrupt; + } s_ETMInfo[2]; + BYTE b_ETMInit; + BYTE b_TimingUnit; + BYTE b_ClockSelection; + double d_TimingInterval; + ULONG ul_Timing; + } s_ETMModuleInfo; /*************/ - /* CDA infos */ + /* CDA infos */ /*************/ - struct - { - BYTE b_CDAEnable; - BYTE b_CDAInterrupt; - BYTE b_CDAInit; - BYTE b_FctSelection; - BYTE b_CDAReadFIFOOverflow; - }s_CDAModuleInfo; + struct { + BYTE b_CDAEnable; + BYTE b_CDAInterrupt; + BYTE b_CDAInit; + BYTE b_FctSelection; + BYTE b_CDAReadFIFOOverflow; + } s_CDAModuleInfo; - }str_ModuleInfo; +} str_ModuleInfo; // Private structure for the addi_apci3120 driver -typedef struct{ - - INT iobase; - INT i_IobaseAmcc; // base+size for AMCC chip - INT i_IobaseAddon; //addon base address - INT i_IobaseReserved; - ULONG_PTR dw_AiBase; - struct pcilst_struct *amcc; // ptr too AMCC data - BYTE allocated; // we have blocked card - BYTE b_ValidDriver;// driver is ok - BYTE b_AiContinuous; // we do unlimited AI - BYTE b_AiInitialisation; - UINT ui_AiActualScan; //how many scans we finished - UINT ui_AiBufferPtr;// data buffer ptr in samples - UINT ui_AiNbrofChannels;// how many channels is measured - UINT ui_AiScanLength;// Length of actual scanlist - UINT ui_AiActualScanPosition; // position in actual scan - PUINT pui_AiChannelList; // actual chanlist - UINT ui_AiChannelList[32]; // actual chanlist - BYTE b_AiChannelConfiguration[32]; // actual chanlist - UINT ui_AiReadData[32]; - DWORD dw_AiInitialised; - UINT ui_AiTimer0; //Timer Constant for Timer0 - UINT ui_AiTimer1; //Timer constant for Timer1 - UINT ui_AiFlags; - UINT ui_AiDataLength; - sampl_t *AiData; // Pointer to sample data - UINT ui_AiNbrofScans;// number of scans to do - USHORT us_UseDma; // To use Dma or not - BYTE b_DmaDoubleBuffer;// we can use double buffering - UINT ui_DmaActualBuffer; // which buffer is used now - //*UPDATE-0.7.57->0.7.68 - //ULONG ul_DmaBufferVirtual[2];// pointers to begin of DMA buffer - sampl_t *ul_DmaBufferVirtual[2];// pointers to begin of DMA buffer - ULONG ul_DmaBufferHw[2]; // hw address of DMA buff - UINT ui_DmaBufferSize[2];// size of dma buffer in bytes - UINT ui_DmaBufferUsesize[2];// which size we may now used for transfer - UINT ui_DmaBufferSamples[2];// size in samples - UINT ui_DmaBufferPages[2];// number of pages in buffer - BYTE b_DigitalOutputRegister; // Digital Output Register - BYTE b_OutputMemoryStatus; - BYTE b_AnalogInputChannelNbr; // Analog input channel Nbr - BYTE b_AnalogOutputChannelNbr;// Analog input Output Nbr - BYTE b_TimerSelectMode; // Contain data written at iobase + 0C - BYTE b_ModeSelectRegister; // Contain data written at iobase + 0E - USHORT us_OutputRegister; // Contain data written at iobase + 0 - BYTE b_InterruptState; - BYTE b_TimerInit; // Specify if InitTimerWatchdog was load - BYTE b_TimerStarted; // Specify if timer 2 is running or not - BYTE b_Timer2Mode; // Specify the timer 2 mode - BYTE b_Timer2Interrupt;//Timer2 interrupt enable or disable - BYTE b_AiCyclicAcquisition;// indicate cyclic acquisition - BYTE b_InterruptMode; // eoc eos or dma - BYTE b_EocEosInterrupt; // Enable disable eoc eos interrupt - UINT ui_EocEosConversionTime; - BYTE b_EocEosConversionTimeBase; - BYTE b_SingelDiff; - BYTE b_ExttrigEnable; // To enable or disable external trigger - - struct task_struct *tsk_Current; // Pointer to the current process - boardtype *ps_BoardInfo; - - - - // Hardware board infos for 1710 - - struct - { - UINT ui_Address; // Board address - UINT ui_FlashAddress; - BYTE b_InterruptNbr; // Board interrupt number - BYTE b_SlotNumber; // PCI slot number - BYTE b_BoardVersion; - DWORD dw_MolduleConfiguration [4]; // Module configuration - }s_BoardInfos; - - - /*******************/ - /* Interrupt infos */ - /*******************/ - - - struct - { - ULONG ul_InterruptOccur; /* 0 : No interrupt occur */ - /* > 0 : Interrupt occur */ - UINT ui_Read; /* Read FIFO */ - UINT ui_Write; /* Write FIFO */ - struct - { - BYTE b_OldModuleMask; - ULONG ul_OldInterruptMask; /* Interrupt mask */ - ULONG ul_OldCounterLatchValue; /* Interrupt counter value */ - }s_FIFOInterruptParameters [APCI1710_SAVE_INTERRUPT]; - }s_InterruptParameters; - - str_ModuleInfo s_ModuleInfo [4]; - ULONG ul_TTLPortConfiguration[10]; - - } addi_private; - - -static unsigned short pci_list_builded=0; /* set to 1 when list of card is known */ - +typedef struct { + INT iobase; + INT i_IobaseAmcc; // base+size for AMCC chip + INT i_IobaseAddon; //addon base address + INT i_IobaseReserved; + ULONG_PTR dw_AiBase; + struct pcilst_struct *amcc; // ptr too AMCC data + BYTE allocated; // we have blocked card + BYTE b_ValidDriver; // driver is ok + BYTE b_AiContinuous; // we do unlimited AI + BYTE b_AiInitialisation; + UINT ui_AiActualScan; //how many scans we finished + UINT ui_AiBufferPtr; // data buffer ptr in samples + UINT ui_AiNbrofChannels; // how many channels is measured + UINT ui_AiScanLength; // Length of actual scanlist + UINT ui_AiActualScanPosition; // position in actual scan + PUINT pui_AiChannelList; // actual chanlist + UINT ui_AiChannelList[32]; // actual chanlist + BYTE b_AiChannelConfiguration[32]; // actual chanlist + UINT ui_AiReadData[32]; + DWORD dw_AiInitialised; + UINT ui_AiTimer0; //Timer Constant for Timer0 + UINT ui_AiTimer1; //Timer constant for Timer1 + UINT ui_AiFlags; + UINT ui_AiDataLength; + sampl_t *AiData; // Pointer to sample data + UINT ui_AiNbrofScans; // number of scans to do + USHORT us_UseDma; // To use Dma or not + BYTE b_DmaDoubleBuffer; // we can use double buffering + UINT ui_DmaActualBuffer; // which buffer is used now + //*UPDATE-0.7.57->0.7.68 + //ULONG ul_DmaBufferVirtual[2];// pointers to begin of DMA buffer + sampl_t *ul_DmaBufferVirtual[2]; // pointers to begin of DMA buffer + ULONG ul_DmaBufferHw[2]; // hw address of DMA buff + UINT ui_DmaBufferSize[2]; // size of dma buffer in bytes + UINT ui_DmaBufferUsesize[2]; // which size we may now used for transfer + UINT ui_DmaBufferSamples[2]; // size in samples + UINT ui_DmaBufferPages[2]; // number of pages in buffer + BYTE b_DigitalOutputRegister; // Digital Output Register + BYTE b_OutputMemoryStatus; + BYTE b_AnalogInputChannelNbr; // Analog input channel Nbr + BYTE b_AnalogOutputChannelNbr; // Analog input Output Nbr + BYTE b_TimerSelectMode; // Contain data written at iobase + 0C + BYTE b_ModeSelectRegister; // Contain data written at iobase + 0E + USHORT us_OutputRegister; // Contain data written at iobase + 0 + BYTE b_InterruptState; + BYTE b_TimerInit; // Specify if InitTimerWatchdog was load + BYTE b_TimerStarted; // Specify if timer 2 is running or not + BYTE b_Timer2Mode; // Specify the timer 2 mode + BYTE b_Timer2Interrupt; //Timer2 interrupt enable or disable + BYTE b_AiCyclicAcquisition; // indicate cyclic acquisition + BYTE b_InterruptMode; // eoc eos or dma + BYTE b_EocEosInterrupt; // Enable disable eoc eos interrupt + UINT ui_EocEosConversionTime; + BYTE b_EocEosConversionTimeBase; + BYTE b_SingelDiff; + BYTE b_ExttrigEnable; // To enable or disable external trigger + + struct task_struct *tsk_Current; // Pointer to the current process + boardtype *ps_BoardInfo; + + // Hardware board infos for 1710 + + struct { + UINT ui_Address; // Board address + UINT ui_FlashAddress; + BYTE b_InterruptNbr; // Board interrupt number + BYTE b_SlotNumber; // PCI slot number + BYTE b_BoardVersion; + DWORD dw_MolduleConfiguration[4]; // Module configuration + } s_BoardInfos; + + /*******************/ + /* Interrupt infos */ + /*******************/ + struct { + ULONG ul_InterruptOccur; /* 0 : No interrupt occur */ + /* > 0 : Interrupt occur */ + UINT ui_Read; /* Read FIFO */ + UINT ui_Write; /* Write FIFO */ + struct { + BYTE b_OldModuleMask; + ULONG ul_OldInterruptMask; /* Interrupt mask */ + ULONG ul_OldCounterLatchValue; /* Interrupt counter value */ + } s_FIFOInterruptParameters[APCI1710_SAVE_INTERRUPT]; + } s_InterruptParameters; + str_ModuleInfo s_ModuleInfo[4]; + ULONG ul_TTLPortConfiguration[10]; +} addi_private; +static unsigned short pci_list_builded = 0; /* set to 1 when list of card is known */ //Function declarations -static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it); -static int i_ADDI_Detach(comedi_device *dev); -static int i_ADDI_Reset(comedi_device *dev); - -static irqreturn_t v_ADDI_Interrupt(int irq, void *d PT_REGS_ARG); -static int i_ADDIDATA_InsnReadEeprom(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - - +static int i_ADDI_Attach(comedi_device * dev, comedi_devconfig * it); +static int i_ADDI_Detach(comedi_device * dev); +static int i_ADDI_Reset(comedi_device * dev); +static irqreturn_t v_ADDI_Interrupt(int irq, void *d PT_REGS_ARG); +static int i_ADDIDATA_InsnReadEeprom(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); diff --git a/comedi/drivers/addi-data/addi_eeprom.c b/comedi/drivers/addi-data/addi_eeprom.c index b0f5bb4a..cd7d06a9 100644 --- a/comedi/drivers/addi-data/addi_eeprom.c +++ b/comedi/drivers/addi-data/addi_eeprom.c @@ -45,18 +45,11 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - - - - - - - -#define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command -#define NVCMD_LOAD_LOW (0x4 << 5 ) // nvRam load low command -#define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command -#define EE76_CMD_LEN 13 // bits in instructions -#define EE_READ 0x0180 // 01 1000 0000 read instruction +#define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command +#define NVCMD_LOAD_LOW (0x4 << 5 ) // nvRam load low command +#define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command +#define EE76_CMD_LEN 13 // bits in instructions +#define EE_READ 0x0180 // 01 1000 0000 read instruction #define WORD unsigned short #define PWORD unsigned short * @@ -66,104 +59,101 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define DWORD unsigned int #endif - - #define EEPROM_DIGITALINPUT 0 #define EEPROM_DIGITALOUTPUT 1 #define EEPROM_ANALOGINPUT 2 #define EEPROM_ANALOGOUTPUT 3 #define EEPROM_TIMER 4 -#define EEPROM_WATCHDOG 5 +#define EEPROM_WATCHDOG 5 #define EEPROM_TIMER_WATCHDOG_COUNTER 10 -struct str_Functionality -{ - BYTE b_Type; - WORD w_Address; +struct str_Functionality { + BYTE b_Type; + WORD w_Address; }; +typedef struct { + WORD w_HeaderSize; + BYTE b_Nfunctions; + struct str_Functionality s_Functions[7]; +} str_MainHeader; -typedef struct -{ - WORD w_HeaderSize; - BYTE b_Nfunctions; - struct str_Functionality s_Functions[7]; -}str_MainHeader; - - +typedef struct { + WORD w_Nchannel; + BYTE b_Interruptible; + WORD w_NinterruptLogic; +} str_DigitalInputHeader; -typedef struct -{ - WORD w_Nchannel; - BYTE b_Interruptible; - WORD w_NinterruptLogic; -}str_DigitalInputHeader; - -typedef struct -{ - WORD w_Nchannel; -}str_DigitalOutputHeader; +typedef struct { + WORD w_Nchannel; +} str_DigitalOutputHeader; // used for timer as well as watchdog -typedef struct -{ - WORD w_HeaderSize; - BYTE b_Resolution; - BYTE b_Mode; // in case of Watchdog it is functionality - WORD w_MinTiming; - BYTE b_TimeBase; -}str_TimerDetails; -typedef struct -{ - - WORD w_Ntimer; - str_TimerDetails s_TimerDetails[4]; // supports 4 timers -}str_TimerMainHeader; - - -typedef struct -{ - WORD w_Nchannel; - BYTE b_Resolution; - }str_AnalogOutputHeader ; - -typedef struct -{ - WORD w_Nchannel; - WORD w_MinConvertTiming; - WORD w_MinDelayTiming; - BYTE b_HasDma; - BYTE b_Resolution; +typedef struct { + WORD w_HeaderSize; + BYTE b_Resolution; + BYTE b_Mode; // in case of Watchdog it is functionality + WORD w_MinTiming; + BYTE b_TimeBase; +} str_TimerDetails; +typedef struct { + + WORD w_Ntimer; + str_TimerDetails s_TimerDetails[4]; // supports 4 timers +} str_TimerMainHeader; + +typedef struct { + WORD w_Nchannel; + BYTE b_Resolution; +} str_AnalogOutputHeader; + +typedef struct { + WORD w_Nchannel; + WORD w_MinConvertTiming; + WORD w_MinDelayTiming; + BYTE b_HasDma; + BYTE b_Resolution; } str_AnalogInputHeader; /*****************************************/ - /* Read Header Functions */ + /* Read Header Functions */ /*****************************************/ -INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,comedi_device *dev); +INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, comedi_device * dev); -INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header); +INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_DigitalInputHeader * s_Header); -INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header); +INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_DigitalOutputHeader * s_Header); -INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header); +INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_TimerMainHeader * s_Header); -INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header); +INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_AnalogOutputHeader * s_Header); -INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header); +INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_AnalogInputHeader * s_Header); /******************************************/ - /* Eeprom Specific Functions */ + /* Eeprom Specific Functions */ /******************************************/ -WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_EepromStartAddress); -VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); -VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue); -VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); -VOID v_EepromSendCommand76(DWORD dw_Address,DWORD dw_EepromCommand,BYTE b_DataLengthInBits); -VOID v_EepromCs76Read(DWORD dw_Address,WORD w_offset,PWORD pw_Value); - - +WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress, PCHAR pc_PCIChipInformation, + WORD w_EepromStartAddress); +VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); +VOID v_EepromClock76(DWORD dw_Address, DWORD dw_RegisterValue); +VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); +VOID v_EepromSendCommand76(DWORD dw_Address, DWORD dw_EepromCommand, + BYTE b_DataLengthInBits); +VOID v_EepromCs76Read(DWORD dw_Address, WORD w_offset, PWORD pw_Value); /* +----------------------------------------------------------------------------+ @@ -186,8 +176,8 @@ VOID v_EepromCs76Read(DWORD dw_Address,WORD w_offset,PWORD pw_Value); +----------------------------------------------------------------------------+ */ -WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_EepromStartAddress) - +WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress, PCHAR pc_PCIChipInformation, + WORD w_EepromStartAddress) { BYTE b_Counter = 0; @@ -204,221 +194,164 @@ WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, WORD w_ReadWord = 0; - - - - /**************************/ - - /* Test the PCI chip type */ - - /**************************/ - - + /**************************/ + /* Test the PCI chip type */ - if ((!strcmp(pc_PCIChipInformation, "S5920")) || + /**************************/ - (!strcmp(pc_PCIChipInformation, "S5933"))) - - { - - - for (b_Counter=0; b_Counter<2; b_Counter++) - - { - - b_SelectedAddressLow = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part + if ((!strcmp(pc_PCIChipInformation, "S5920")) || + (!strcmp(pc_PCIChipInformation, "S5933"))) + { - b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part + for (b_Counter = 0; b_Counter < 2; b_Counter++) + { + b_SelectedAddressLow = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part + b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part /************************************/ - /* Select the load low address mode */ + /* Select the load low address mode */ /************************************/ + outb(NVCMD_LOAD_LOW, w_PCIBoardEepromAddress + 0x3F); - outb(NVCMD_LOAD_LOW,w_PCIBoardEepromAddress + 0x3F); - - - /****************/ - /* Wait on busy */ + /* Wait on busy */ /****************/ - v_EepromWaitBusy (w_PCIBoardEepromAddress); - + v_EepromWaitBusy(w_PCIBoardEepromAddress); /************************/ - /* Load the low address */ + /* Load the low address */ /************************/ + outb(b_SelectedAddressLow, + w_PCIBoardEepromAddress + 0x3E); - outb(b_SelectedAddressLow,w_PCIBoardEepromAddress + 0x3E); - - - /****************/ - /* Wait on busy */ + /* Wait on busy */ /****************/ - v_EepromWaitBusy (w_PCIBoardEepromAddress); - - + v_EepromWaitBusy(w_PCIBoardEepromAddress); /*************************************/ - /* Select the load high address mode */ + /* Select the load high address mode */ /*************************************/ - - outb(NVCMD_LOAD_HIGH,w_PCIBoardEepromAddress + 0x3F); - - + outb(NVCMD_LOAD_HIGH, w_PCIBoardEepromAddress + 0x3F); /****************/ - /* Wait on busy */ + /* Wait on busy */ /****************/ - v_EepromWaitBusy (w_PCIBoardEepromAddress); - - + v_EepromWaitBusy(w_PCIBoardEepromAddress); /*************************/ - /* Load the high address */ + /* Load the high address */ /*************************/ - - outb(b_SelectedAddressHigh,w_PCIBoardEepromAddress +0x3E); - - - /****************/ - - /* Wait on busy */ + outb(b_SelectedAddressHigh, + w_PCIBoardEepromAddress + 0x3E); /****************/ - v_EepromWaitBusy (w_PCIBoardEepromAddress); + /* Wait on busy */ + /****************/ + v_EepromWaitBusy(w_PCIBoardEepromAddress); /************************/ - /* Select the READ mode */ + /* Select the READ mode */ /************************/ - - outb(NVCMD_BEGIN_READ,w_PCIBoardEepromAddress + 0x3F); - + outb(NVCMD_BEGIN_READ, w_PCIBoardEepromAddress + 0x3F); /****************/ - /* Wait on busy */ + /* Wait on busy */ /****************/ - - v_EepromWaitBusy (w_PCIBoardEepromAddress); - - + v_EepromWaitBusy(w_PCIBoardEepromAddress); /*****************************/ - /* Read data into the EEPROM */ + /* Read data into the EEPROM */ /*****************************/ - b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E); + b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E); - - - /****************/ - /* Wait on busy */ + /* Wait on busy */ /****************/ - - - v_EepromWaitBusy (w_PCIBoardEepromAddress); - - + v_EepromWaitBusy(w_PCIBoardEepromAddress); /*********************************/ - /* Select the upper address part */ + /* Select the upper address part */ /*********************************/ + if (b_Counter == 0) + { + b_ReadLowByte = b_ReadByte; - if(b_Counter==0) - - { - - b_ReadLowByte=b_ReadByte; - - } // if(b_Counter==0) - - else + } // if(b_Counter==0) - { + else + { - b_ReadHighByte=b_ReadByte; + b_ReadHighByte = b_ReadByte; - } // if(b_Counter==0) + } // if(b_Counter==0) - } // for (b_Counter=0; b_Counter<2; b_Counter++) + } // for (b_Counter=0; b_Counter<2; b_Counter++) + w_ReadWord = (b_ReadLowByte | (((WORD) b_ReadHighByte) * 256)); + } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) - w_ReadWord=(b_ReadLowByte | (((WORD) b_ReadHighByte) * 256)); - - - - } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) - - if (!strcmp(pc_PCIChipInformation, "93C76")) - - { - - /*************************************/ - - /* Read 16 bit from the EEPROM 93C76 */ - - /*************************************/ + if (!strcmp(pc_PCIChipInformation, "93C76")) + { + /*************************************/ - - v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, &w_ReadWord); + /* Read 16 bit from the EEPROM 93C76 */ - } + /*************************************/ - - return (w_ReadWord); + v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, + &w_ReadWord); } + return (w_ReadWord); - - - - +} /* @@ -448,57 +381,41 @@ WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, */ - - -VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress) - - { +VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress) +{ BYTE b_EepromBusy = 0; - - do - - { + { /*************/ - /* IMPORTANT */ + /* IMPORTANT */ /*************/ - - /************************************************************************/ - /* An error has been written in the AMCC 5933 book at the page B-13*/ - - /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and */ - - /* the operator register is AMCC_OP_REG_MCSR+3*/ - - /* WORD read EEPROM=0x8000 andAMCC_OP_REG_MCSR+2 */ - - /* DWORD read EEPROM=0x80000000 and AMCC_OP_REG_MCSR */ - - /************************************************************************/ - - - b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F); - b_EepromBusy = b_EepromBusy &0x80; - - } - while(b_EepromBusy == 0x80); - + /* An error has been written in the AMCC 5933 book at the page B-13 */ + /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and */ - } + /* the operator register is AMCC_OP_REG_MCSR+3 */ + + /* WORD read EEPROM=0x8000 andAMCC_OP_REG_MCSR+2 */ + /* DWORD read EEPROM=0x80000000 and AMCC_OP_REG_MCSR */ + /************************************************************************/ + b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F); + b_EepromBusy = b_EepromBusy & 0x80; + } + while (b_EepromBusy == 0x80); +} /* @@ -530,55 +447,42 @@ VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress) */ - - -VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue) - - { - - +VOID v_EepromClock76(DWORD dw_Address, DWORD dw_RegisterValue) +{ /************************/ - /* Set EEPROM clock Low */ + /* Set EEPROM clock Low */ /************************/ - -outl(dw_RegisterValue & 0x6,dw_Address); + outl(dw_RegisterValue & 0x6, dw_Address); /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ - - udelay(100); - + udelay(100); /*************************/ - /* Set EEPROM clock High */ + /* Set EEPROM clock High */ /*************************/ - - outl(dw_RegisterValue | 0x1,dw_Address); - + outl(dw_RegisterValue | 0x1, dw_Address); /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ + udelay(100); - udelay(100); - - } - - +} /* @@ -614,143 +518,106 @@ outl(dw_RegisterValue & 0x6,dw_Address); */ +VOID v_EepromSendCommand76(DWORD dw_Address, DWORD dw_EepromCommand, + BYTE b_DataLengthInBits) +{ + CHAR c_BitPos = 0; -VOID v_EepromSendCommand76(DWORD dw_Address,DWORD dw_EepromCommand,BYTE b_DataLengthInBits) - - { - - CHAR c_BitPos = 0; - - DWORD dw_RegisterValue = 0; - - - - + DWORD dw_RegisterValue = 0; /*****************************/ - /* Enable EEPROM Chip Select */ + /* Enable EEPROM Chip Select */ /*****************************/ - dw_RegisterValue = 0x2; - - + dw_RegisterValue = 0x2; /********************************************************************/ - /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ + /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ /********************************************************************/ - outl(dw_RegisterValue,dw_Address); - - - + outl(dw_RegisterValue, dw_Address); /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ - -udelay(100); - - + udelay(100); /*******************************************/ - /* Send EEPROM command - one bit at a time */ + /* Send EEPROM command - one bit at a time */ /*******************************************/ - - - for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--) - - { + for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--) + { /**********************************/ - /* Check if current bit is 0 or 1 */ + /* Check if current bit is 0 or 1 */ /**********************************/ - - if (dw_EepromCommand & (1 << c_BitPos)) - - { + if (dw_EepromCommand & (1 << c_BitPos)) + { /***********/ - /* Write 1 */ + /* Write 1 */ /***********/ + dw_RegisterValue = dw_RegisterValue | 0x4; + } - dw_RegisterValue = dw_RegisterValue | 0x4; - - } - - else - - { + else + { /***********/ - /* Write 0 */ + /* Write 0 */ /***********/ + dw_RegisterValue = dw_RegisterValue & 0x3; - - dw_RegisterValue = dw_RegisterValue & 0x3; - - } - - + } /*********************/ - /* Write the command */ + /* Write the command */ /*********************/ - - outl(dw_RegisterValue,dw_Address); - - + outl(dw_RegisterValue, dw_Address); /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ - - udelay(100); - - + udelay(100); /****************************/ - /* Trigger the EEPROM clock */ + /* Trigger the EEPROM clock */ /****************************/ - v_EepromClock76(dw_Address, dw_RegisterValue); - - - } - - - - } + v_EepromClock76(dw_Address, dw_RegisterValue); + } +} /* @@ -786,173 +653,135 @@ udelay(100); */ +VOID v_EepromCs76Read(DWORD dw_Address, WORD w_offset, PWORD pw_Value) +{ + CHAR c_BitPos = 0; -VOID v_EepromCs76Read(DWORD dw_Address,WORD w_offset, -PWORD pw_Value) - - { - - CHAR c_BitPos = 0; - - DWORD dw_RegisterValue = 0; - - DWORD dw_RegisterValueRead = 0; - - - + DWORD dw_RegisterValue = 0; + DWORD dw_RegisterValueRead = 0; /*************************************************/ - /* Send EEPROM read command and offset to EEPROM */ + /* Send EEPROM read command and offset to EEPROM */ /*************************************************/ - v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), EE76_CMD_LEN); - - + v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), + EE76_CMD_LEN); /*******************************/ - /* Get the last register value */ + /* Get the last register value */ /*******************************/ - dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2; - - + dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2; /*****************************/ - /* Set the 16-bit value of 0 */ + /* Set the 16-bit value of 0 */ /*****************************/ - - *pw_Value = 0; - - + *pw_Value = 0; /************************/ - /* Get the 16-bit value */ + /* Get the 16-bit value */ /************************/ - for (c_BitPos = 0; c_BitPos < 16; c_BitPos++) - - { - + for (c_BitPos = 0; c_BitPos < 16; c_BitPos++) + { /****************************/ - /* Trigger the EEPROM clock */ + /* Trigger the EEPROM clock */ /****************************/ - - v_EepromClock76(dw_Address, dw_RegisterValue); - - + v_EepromClock76(dw_Address, dw_RegisterValue); /**********************/ - /* Get the result bit */ + /* Get the result bit */ /**********************/ - - dw_RegisterValueRead = inl(dw_Address); + dw_RegisterValueRead = inl(dw_Address); /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ - - udelay(100); - + udelay(100); /***************************************/ - /* Get bit value and shift into result */ + /* Get bit value and shift into result */ /***************************************/ - - if (dw_RegisterValueRead & 0x8) - - { - + if (dw_RegisterValueRead & 0x8) + { /**********/ - /* Read 1 */ + /* Read 1 */ /**********/ + *pw_Value = (*pw_Value << 1) | 0x1; - *pw_Value = (*pw_Value << 1) | 0x1; - - } - - else + } - { + else + { /**********/ - /* Read 0 */ + /* Read 0 */ /**********/ - *pw_Value = (*pw_Value << 1); - - - } - - } + *pw_Value = (*pw_Value << 1); + } + } /*************************/ - /* Clear all EEPROM bits */ + /* Clear all EEPROM bits */ /*************************/ - - dw_RegisterValue = 0x0; - - + dw_RegisterValue = 0x0; /********************************************************************/ - /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ + /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ /********************************************************************/ + outl(dw_RegisterValue, dw_Address); - outl(dw_RegisterValue,dw_Address); - /***************/ - /* Wait 0.1 ms */ + /* Wait 0.1 ms */ /***************/ - udelay(100); - - } - - - + udelay(100); +} /******************************************/ - /* EEPROM HEADER READ FUNCTIONS */ + /* EEPROM HEADER READ FUNCTIONS */ /******************************************/ /* @@ -975,98 +804,120 @@ PWORD pw_Value) +----------------------------------------------------------------------------+ */ - -INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,comedi_device *dev) +INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, comedi_device * dev) { - WORD w_Temp,i,w_Count=0; - UINT ui_Temp; - str_MainHeader s_MainHeader; - str_DigitalInputHeader s_DigitalInputHeader; + WORD w_Temp, i, w_Count = 0; + UINT ui_Temp; + str_MainHeader s_MainHeader; + str_DigitalInputHeader s_DigitalInputHeader; str_DigitalOutputHeader s_DigitalOutputHeader; //str_TimerMainHeader s_TimerMainHeader,s_WatchdogMainHeader; - str_AnalogOutputHeader s_AnalogOutputHeader; - str_AnalogInputHeader s_AnalogInputHeader; - - // Read size - s_MainHeader.w_HeaderSize = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+8); - - // Read nbr of functionality - w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+10); - s_MainHeader.b_Nfunctions =(BYTE)w_Temp & 0x00FF; - - // Read functionality details - for(i=0;ii_NbrDiChannel=s_DigitalInputHeader.w_Nchannel; - break; - - case EEPROM_DIGITALOUTPUT: - i_EepromReadDigitalOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation, - s_MainHeader.s_Functions[i].w_Address,&s_DigitalOutputHeader); - this_board->i_NbrDoChannel=s_DigitalOutputHeader.w_Nchannel; - ui_Temp=0xffffffff; - this_board->i_DoMaxdata= ui_Temp >>(32 - this_board->i_NbrDoChannel); - break; - - case EEPROM_ANALOGINPUT: - i_EepromReadAnlogInputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation, - s_MainHeader.s_Functions[i].w_Address,&s_AnalogInputHeader); - if (!(strcmp(this_board->pc_DriverName, "apci3200"))) - this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel * 4; - else - this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel; - this_board->i_Dma=s_AnalogInputHeader.b_HasDma; - this_board->ui_MinAcquisitiontimeNs=(UINT)s_AnalogInputHeader.w_MinConvertTiming * 1000; - this_board->ui_MinDelaytimeNs =(UINT)s_AnalogInputHeader.w_MinDelayTiming * 1000; - ui_Temp=0xffff; - this_board->i_AiMaxdata = ui_Temp >> (16 - s_AnalogInputHeader.b_Resolution); - break; - - case EEPROM_ANALOGOUTPUT: - i_EepromReadAnlogOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation, - s_MainHeader.s_Functions[i].w_Address,&s_AnalogOutputHeader); - this_board->i_NbrAoChannel=s_AnalogOutputHeader.w_Nchannel; - ui_Temp=0xffff; - this_board->i_AoMaxdata= ui_Temp >>(16 - s_AnalogOutputHeader.b_Resolution); - break; - - case EEPROM_TIMER: - this_board->i_Timer=1;//Timer subdevice present - break; - - case EEPROM_WATCHDOG: - this_board->i_Timer=1; //Timer subdevice present - break; - - case EEPROM_TIMER_WATCHDOG_COUNTER: - this_board->i_Timer=1; //Timer subdevice present - } + // Display main header info + for (i = 0; i < s_MainHeader.b_Nfunctions; i++) { + + switch (s_MainHeader.s_Functions[i].b_Type) { + case EEPROM_DIGITALINPUT: + i_EepromReadDigitalInputHeader(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + s_MainHeader.s_Functions[i].w_Address, + &s_DigitalInputHeader); + this_board->i_NbrDiChannel = + s_DigitalInputHeader.w_Nchannel; + break; + + case EEPROM_DIGITALOUTPUT: + i_EepromReadDigitalOutputHeader(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + s_MainHeader.s_Functions[i].w_Address, + &s_DigitalOutputHeader); + this_board->i_NbrDoChannel = + s_DigitalOutputHeader.w_Nchannel; + ui_Temp = 0xffffffff; + this_board->i_DoMaxdata = + ui_Temp >> (32 - this_board->i_NbrDoChannel); + break; + + case EEPROM_ANALOGINPUT: + i_EepromReadAnlogInputHeader(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + s_MainHeader.s_Functions[i].w_Address, + &s_AnalogInputHeader); + if (!(strcmp(this_board->pc_DriverName, "apci3200"))) + this_board->i_NbrAiChannel = + s_AnalogInputHeader.w_Nchannel * 4; + else + this_board->i_NbrAiChannel = + s_AnalogInputHeader.w_Nchannel; + this_board->i_Dma = s_AnalogInputHeader.b_HasDma; + this_board->ui_MinAcquisitiontimeNs = + (UINT) s_AnalogInputHeader.w_MinConvertTiming * + 1000; + this_board->ui_MinDelaytimeNs = + (UINT) s_AnalogInputHeader.w_MinDelayTiming * + 1000; + ui_Temp = 0xffff; + this_board->i_AiMaxdata = + ui_Temp >> (16 - + s_AnalogInputHeader.b_Resolution); + break; + + case EEPROM_ANALOGOUTPUT: + i_EepromReadAnlogOutputHeader(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + s_MainHeader.s_Functions[i].w_Address, + &s_AnalogOutputHeader); + this_board->i_NbrAoChannel = + s_AnalogOutputHeader.w_Nchannel; + ui_Temp = 0xffff; + this_board->i_AoMaxdata = + ui_Temp >> (16 - + s_AnalogOutputHeader.b_Resolution); + break; + + case EEPROM_TIMER: + this_board->i_Timer = 1; //Timer subdevice present + break; + + case EEPROM_WATCHDOG: + this_board->i_Timer = 1; //Timer subdevice present + break; + + case EEPROM_TIMER_WATCHDOG_COUNTER: + this_board->i_Timer = 1; //Timer subdevice present + } } return 0; } - - - /* +----------------------------------------------------------------------------+ | Function Name : INT i_EepromReadDigitalInputHeader(WORD | @@ -1088,21 +939,28 @@ INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInforma | Return Value : 0 | +----------------------------------------------------------------------------+ */ -INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header) +INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_DigitalInputHeader * s_Header) { - WORD w_Temp; + WORD w_Temp; - // read nbr of channels - s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6); + // read nbr of channels + s_Header->w_Nchannel = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 6); - // interruptible or not - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8); - s_Header->b_Interruptible=(BYTE) (w_Temp>>7)& 0x01; + // interruptible or not + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + 8); + s_Header->b_Interruptible = (BYTE) (w_Temp >> 7) & 0x01; // How many interruptible logic - s_Header->w_NinterruptLogic=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10); + s_Header->w_NinterruptLogic = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 10); - return 0; + return 0; } /* @@ -1126,11 +984,15 @@ INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChip | Return Value : 0 | +----------------------------------------------------------------------------+ */ -INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header) +INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_DigitalOutputHeader * s_Header) { // Read Nbr channels - s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6); -return 0; + s_Header->w_Nchannel = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 6); + return 0; } /* @@ -1153,42 +1015,51 @@ return 0; | Return Value : 0 | +----------------------------------------------------------------------------+ */ -INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header) +INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_TimerMainHeader * s_Header) { -WORD i,w_Size=0,w_Temp; - + WORD i, w_Size = 0, w_Temp; //Read No of Timer -s_Header->w_Ntimer=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6); + s_Header->w_Ntimer = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 6); //Read header size -for(i=0;iw_Ntimer;i++) -{ - s_Header->s_TimerDetails[i].w_HeaderSize=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+0); - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+2) ; - - //Read Resolution - s_Header->s_TimerDetails[i].b_Resolution=(BYTE)(w_Temp>>10)&0x3F; - - //Read Mode - s_Header->s_TimerDetails[i].b_Mode =(BYTE) (w_Temp>>4)&0x3F; - - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+4) ; - - //Read MinTiming - s_Header->s_TimerDetails[i].w_MinTiming =(w_Temp>>6)&0x3FF; + for (i = 0; i < s_Header->w_Ntimer; i++) { + s_Header->s_TimerDetails[i].w_HeaderSize = + w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + 0x100 + w_Address + 8 + w_Size + 0); + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + 0x100 + w_Address + 8 + w_Size + 2); + + //Read Resolution + s_Header->s_TimerDetails[i].b_Resolution = + (BYTE) (w_Temp >> 10) & 0x3F; + + //Read Mode + s_Header->s_TimerDetails[i].b_Mode = + (BYTE) (w_Temp >> 4) & 0x3F; + + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, + 0x100 + w_Address + 8 + w_Size + 4); + + //Read MinTiming + s_Header->s_TimerDetails[i].w_MinTiming = (w_Temp >> 6) & 0x3FF; + + //Read Timebase + s_Header->s_TimerDetails[i].b_TimeBase = (BYTE) (w_Temp) & 0x3F; + w_Size += s_Header->s_TimerDetails[i].w_HeaderSize; + } - //Read Timebase - s_Header->s_TimerDetails[i].b_TimeBase =(BYTE)(w_Temp)&0x3F; - w_Size += s_Header->s_TimerDetails[i].w_HeaderSize; -} - -return 0; + return 0; } - - /* +----------------------------------------------------------------------------+ | Function Name : INT i_EepromReadAnlogOutputHeader(WORD | @@ -1210,19 +1081,22 @@ return 0; +----------------------------------------------------------------------------+ */ -INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header) +INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_AnalogOutputHeader * s_Header) { - WORD w_Temp; - // No of channels for 1st hard component - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10); - s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF; - // Resolution for 1st hard component - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16); - s_Header->b_Resolution=(BYTE)(w_Temp>>8) & 0xFF; - return 0; + WORD w_Temp; + // No of channels for 1st hard component + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + 10); + s_Header->w_Nchannel = (w_Temp >> 4) & 0x03FF; + // Resolution for 1st hard component + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + 16); + s_Header->b_Resolution = (BYTE) (w_Temp >> 8) & 0xFF; + return 0; } - /* +----------------------------------------------------------------------------+ | Function Name : INT i_EepromReadAnlogInputHeader(WORD | @@ -1245,32 +1119,40 @@ INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipI */ // Reads only for ONE hardware component -INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header) -{ - WORD w_Temp,w_Offset; - w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10); - s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF; - s_Header->w_MinConvertTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16); -s_Header->w_MinDelayTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+30); -w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+20); -s_Header->b_HasDma=(w_Temp>>13) & 0x01; // whether dma present or not - -w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+72);// reading Y -w_Temp=w_Temp & 0x00FF; -if(w_Temp)//Y>0 +INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress, + PCHAR pc_PCIChipInformation, WORD w_Address, + str_AnalogInputHeader * s_Header) { -w_Offset=74+(2*w_Temp)+(10*(1+(w_Temp/16)));// offset of first analog input single header -w_Offset= w_Offset+2; // resolution -} -else//Y=0 -{ -w_Offset=74; -w_Offset= w_Offset+2; // resolution -} + WORD w_Temp, w_Offset; + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + 10); + s_Header->w_Nchannel = (w_Temp >> 4) & 0x03FF; + s_Header->w_MinConvertTiming = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 16); + s_Header->w_MinDelayTiming = + w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, + 0x100 + w_Address + 30); + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + 20); + s_Header->b_HasDma = (w_Temp >> 13) & 0x01; // whether dma present or not + + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 0x100 + w_Address + 72); // reading Y + w_Temp = w_Temp & 0x00FF; + if (w_Temp) //Y>0 + { + w_Offset = 74 + (2 * w_Temp) + (10 * (1 + (w_Temp / 16))); // offset of first analog input single header + w_Offset = w_Offset + 2; // resolution + } else //Y=0 + { + w_Offset = 74; + w_Offset = w_Offset + 2; // resolution + } // read Resolution -w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+w_Offset); -s_Header->b_Resolution=w_Temp & 0x001F;// last 5 bits + w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, + pc_PCIChipInformation, 0x100 + w_Address + w_Offset); + s_Header->b_Resolution = w_Temp & 0x001F; // last 5 bits -return 0; + return 0; } diff --git a/comedi/drivers/addi-data/amcc_s5933_58.h b/comedi/drivers/addi-data/amcc_s5933_58.h index 6a67cbd1..1ec37639 100644 --- a/comedi/drivers/addi-data/amcc_s5933_58.h +++ b/comedi/drivers/addi-data/amcc_s5933_58.h @@ -3,8 +3,6 @@ Modified by sarath on 22nd may 2001 */ - - /* comedi/drivers/amcc_s5933_v_58.h @@ -35,42 +33,39 @@ #define FIFO_ADVANCE_ON_BYTE_2 0x20000000 // written on base0 -#define AMWEN_ENABLE 0x02 // added for step 6 dma written on base2 -#define A2P_FIFO_WRITE_ENABLE 0x01 +#define AMWEN_ENABLE 0x02 // added for step 6 dma written on base2 +#define A2P_FIFO_WRITE_ENABLE 0x01 -#define AGCSTS_TC_ENABLE 0x10000000 // Added for transfer count enable bit +#define AGCSTS_TC_ENABLE 0x10000000 // Added for transfer count enable bit // ADDON RELATED ADDITIONS // Constant - #define APCI3120_ENABLE_TRANSFER_ADD_ON_LOW 0x00 - #define APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH 0x1200 - #define APCI3120_A2P_FIFO_MANAGEMENT 0x04000400L - #define APCI3120_AMWEN_ENABLE 0x02 - #define APCI3120_A2P_FIFO_WRITE_ENABLE 0x01 - #define APCI3120_FIFO_ADVANCE_ON_BYTE_2 0x20000000L - #define APCI3120_ENABLE_WRITE_TC_INT 0x00004000L - #define APCI3120_CLEAR_WRITE_TC_INT 0x00040000L - #define APCI3120_DISABLE_AMWEN_AND_A2P_FIFO_WRITE 0x0 - #define APCI3120_DISABLE_BUS_MASTER_ADD_ON 0x0 - #define APCI3120_DISABLE_BUS_MASTER_PCI 0x0 - +#define APCI3120_ENABLE_TRANSFER_ADD_ON_LOW 0x00 +#define APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH 0x1200 +#define APCI3120_A2P_FIFO_MANAGEMENT 0x04000400L +#define APCI3120_AMWEN_ENABLE 0x02 +#define APCI3120_A2P_FIFO_WRITE_ENABLE 0x01 +#define APCI3120_FIFO_ADVANCE_ON_BYTE_2 0x20000000L +#define APCI3120_ENABLE_WRITE_TC_INT 0x00004000L +#define APCI3120_CLEAR_WRITE_TC_INT 0x00040000L +#define APCI3120_DISABLE_AMWEN_AND_A2P_FIFO_WRITE 0x0 +#define APCI3120_DISABLE_BUS_MASTER_ADD_ON 0x0 +#define APCI3120_DISABLE_BUS_MASTER_PCI 0x0 // ADD_ON ::: this needed since apci supports 16 bit interface to add on - #define APCI3120_ADD_ON_AGCSTS_LOW 0x3C - #define APCI3120_ADD_ON_AGCSTS_HIGH APCI3120_ADD_ON_AGCSTS_LOW + 2 - #define APCI3120_ADD_ON_MWAR_LOW 0x24 - #define APCI3120_ADD_ON_MWAR_HIGH APCI3120_ADD_ON_MWAR_LOW + 2 - #define APCI3120_ADD_ON_MWTC_LOW 0x058 - #define APCI3120_ADD_ON_MWTC_HIGH APCI3120_ADD_ON_MWTC_LOW + 2 +#define APCI3120_ADD_ON_AGCSTS_LOW 0x3C +#define APCI3120_ADD_ON_AGCSTS_HIGH APCI3120_ADD_ON_AGCSTS_LOW + 2 +#define APCI3120_ADD_ON_MWAR_LOW 0x24 +#define APCI3120_ADD_ON_MWAR_HIGH APCI3120_ADD_ON_MWAR_LOW + 2 +#define APCI3120_ADD_ON_MWTC_LOW 0x058 +#define APCI3120_ADD_ON_MWTC_HIGH APCI3120_ADD_ON_MWTC_LOW + 2 // AMCC - #define APCI3120_AMCC_OP_MCSR 0x3C - #define APCI3120_AMCC_OP_REG_INTCSR 0x38 +#define APCI3120_AMCC_OP_MCSR 0x3C +#define APCI3120_AMCC_OP_REG_INTCSR 0x38 /*******from here all upward definitions are added by sarath */ - - /****************************************************************************/ /* AMCC Operation Register Offsets - PCI */ /****************************************************************************/ @@ -90,11 +85,11 @@ #define AMCC_OP_REG_MRTC 0x30 #define AMCC_OP_REG_MBEF 0x34 #define AMCC_OP_REG_INTCSR 0x38 -#define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2) /* INT source */ -#define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3) /* FIFO ctrl */ +#define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2) /* INT source */ +#define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3) /* FIFO ctrl */ #define AMCC_OP_REG_MCSR 0x3c -#define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2) /* Data in byte 2 */ -#define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3) /* Command in byte 3 */ +#define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2) /* Data in byte 2 */ +#define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3) /* Command in byte 3 */ #define AMCC_FIFO_DEPTH_DWORD 8 #define AMCC_FIFO_DEPTH_BYTES (8 * sizeof (u32)) @@ -203,18 +198,18 @@ /****************************************************************************/ -struct pcilst_struct{ - struct pcilst_struct *next; - int used; - struct pci_dev *pcidev; - unsigned short vendor; - unsigned short device; - unsigned int master; - unsigned char pci_bus; - unsigned char pci_slot; - unsigned char pci_func; - unsigned int io_addr[5]; - unsigned int irq; +struct pcilst_struct { + struct pcilst_struct *next; + int used; + struct pci_dev *pcidev; + unsigned short vendor; + unsigned short device; + unsigned int master; + unsigned char pci_bus; + unsigned char pci_slot; + unsigned char pci_func; + unsigned int io_addr[5]; + unsigned int irq; }; struct pcilst_struct *amcc_devices; // ptr to root list of all amcc devices @@ -223,16 +218,22 @@ struct pcilst_struct *amcc_devices; // ptr to root list of all amcc devices void v_pci_card_list_init(unsigned short pci_vendor, char display); void v_pci_card_list_cleanup(unsigned short pci_vendor); -struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id); -int i_find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card); -struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot); +struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, + unsigned short device_id); +int i_find_free_pci_card_by_position(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, struct pcilst_struct **card); +struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot); int i_pci_card_alloc(struct pcilst_struct *amcc); int i_pci_card_free(struct pcilst_struct *amcc); void v_pci_card_list_display(void); int i_pci_card_data(struct pcilst_struct *amcc, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - unsigned short *io_addr, unsigned short *irq, unsigned short *master); + unsigned char *pci_bus, unsigned char *pci_slot, + unsigned char *pci_func, unsigned short *io_addr, unsigned short *irq, + unsigned short *master); /****************************************************************************/ @@ -240,80 +241,89 @@ int i_pci_card_data(struct pcilst_struct *amcc, void v_pci_card_list_init(unsigned short pci_vendor, char display) { struct pci_dev *pcidev; - struct pcilst_struct *amcc,*last; + struct pcilst_struct *amcc, *last; int i; - amcc_devices=NULL; - last=NULL; - + amcc_devices = NULL; + last = NULL; + #if LINUX_VERSION_CODE < 0x020300 - for(pcidev=pci_devices;pcidev;pcidev=pcidev->next){ + for (pcidev = pci_devices; pcidev; pcidev = pcidev->next) { #else - pci_for_each_dev(pcidev){ + pci_for_each_dev(pcidev) { #endif - if(pcidev->vendor==pci_vendor){ - amcc=kmalloc(sizeof(*amcc),GFP_KERNEL); - memset(amcc,0,sizeof(*amcc)); - - amcc->pcidev=pcidev; - if (last) { last->next=amcc; } - else { amcc_devices=amcc; } - last=amcc; - + if (pcidev->vendor == pci_vendor) { + amcc = kmalloc(sizeof(*amcc), GFP_KERNEL); + memset(amcc, 0, sizeof(*amcc)); + + amcc->pcidev = pcidev; + if (last) { + last->next = amcc; + } else { + amcc_devices = amcc; + } + last = amcc; + #if LINUX_VERSION_CODE < 0x020300 - amcc->vendor=pcidev->vendor; - amcc->device=pcidev->device; - amcc->master=pcidev->master; - amcc->pci_bus=pcidev->bus->number; - amcc->pci_slot=PCI_SLOT(pcidev->devfn); - amcc->pci_func=PCI_FUNC(pcidev->devfn); - for (i=0;i<5;i++) - amcc->io_addr[i]=pcidev->base_address[i] & ~3UL; - amcc->irq=pcidev->irq; + amcc->vendor = pcidev->vendor; + amcc->device = pcidev->device; + amcc->master = pcidev->master; + amcc->pci_bus = pcidev->bus->number; + amcc->pci_slot = PCI_SLOT(pcidev->devfn); + amcc->pci_func = PCI_FUNC(pcidev->devfn); + for (i = 0; i < 5; i++) + amcc->io_addr[i] = + pcidev->base_address[i] & ~3UL; + amcc->irq = pcidev->irq; #else - amcc->vendor=pcidev->vendor; - amcc->device=pcidev->device; + amcc->vendor = pcidev->vendor; + amcc->device = pcidev->device; #if 0 - amcc->master=pcidev->master; // how get this information under 2.4 kernels? + amcc->master = pcidev->master; // how get this information under 2.4 kernels? #endif - amcc->pci_bus=pcidev->bus->number; - amcc->pci_slot=PCI_SLOT(pcidev->devfn); - amcc->pci_func=PCI_FUNC(pcidev->devfn); - for (i=0;i<5;i++) - amcc->io_addr[i]=pcidev->resource[i].start & ~3UL; - amcc->irq=pcidev->irq; + amcc->pci_bus = pcidev->bus->number; + amcc->pci_slot = PCI_SLOT(pcidev->devfn); + amcc->pci_func = PCI_FUNC(pcidev->devfn); + for (i = 0; i < 5; i++) + amcc->io_addr[i] = + pcidev->resource[i].start & ~3UL; + amcc->irq = pcidev->irq; #endif - + } } - if (display) v_pci_card_list_display(); + if (display) + v_pci_card_list_display(); } /****************************************************************************/ /* free up list of amcc cards in this system */ void v_pci_card_list_cleanup(unsigned short pci_vendor) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; - for(amcc=amcc_devices;amcc;amcc=next){ - next=amcc->next; + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; kfree(amcc); } - - amcc_devices=NULL; + + amcc_devices = NULL; } /****************************************************************************/ /* find first unused card with this device_id */ -struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id) +struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, + unsigned short device_id) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; + + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + if ((!amcc->used) && (amcc->device == device_id) + && (amcc->vendor == vendor_id)) + return amcc; - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - if ((!amcc->used)&&(amcc->device==device_id)&&(amcc->vendor==vendor_id)) return amcc; - } return NULL; @@ -321,35 +331,43 @@ struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, /****************************************************************************/ /* find card on requested position */ -int i_find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card) +int i_find_free_pci_card_by_position(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, struct pcilst_struct **card) { - struct pcilst_struct *amcc,*next; - - *card=NULL; - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - if ((amcc->vendor==vendor_id)&&(amcc->device==device_id)&&(amcc->pci_bus==pci_bus)&&(amcc->pci_slot==pci_slot)) { + struct pcilst_struct *amcc, *next; + + *card = NULL; + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + if ((amcc->vendor == vendor_id) && (amcc->device == device_id) + && (amcc->pci_bus == pci_bus) + && (amcc->pci_slot == pci_slot)) { if (!(amcc->used)) { - *card=amcc; + *card = amcc; return 0; // ok, card is found } else { - rt_printk(" - \nCard on requested position is used b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - \nCard on requested position is used b:s %d:%d!\n", + pci_bus, pci_slot); return 2; // card exist but is used } } } - return 1; // no card found + return 1; // no card found } /****************************************************************************/ /* mark card as used */ int i_pci_card_alloc(struct pcilst_struct *amcc) { - if (!amcc) return -1; + if (!amcc) + return -1; - if (amcc->used) return 1; - amcc->used=1; + if (amcc->used) + return 1; + amcc->used = 1; return 0; } @@ -357,10 +375,12 @@ int i_pci_card_alloc(struct pcilst_struct *amcc) /* mark card as free */ int i_pci_card_free(struct pcilst_struct *amcc) { - if (!amcc) return -1; + if (!amcc) + return -1; - if (!amcc->used) return 1; - amcc->used=0; + if (!amcc->used) + return 1; + amcc->used = 0; return 0; } @@ -368,63 +388,70 @@ int i_pci_card_free(struct pcilst_struct *amcc) /* display list of found cards */ void v_pci_card_list_display(void) { - struct pcilst_struct *amcc,*next; + struct pcilst_struct *amcc, *next; printk("List of pci cards\n"); printk("bus:slot:func vendor device master io_amcc io_daq irq used\n"); - for (amcc=amcc_devices;amcc;amcc=next) { - next=amcc->next; - printk("%2d %2d %2d 0x%4x 0x%4x %3s 0x%4x 0x%4x %2d %2d\n", - amcc->pci_bus,amcc->pci_slot,amcc->pci_func,amcc->vendor,amcc->device,amcc->master?"yes":"no", - amcc->io_addr[0],amcc->io_addr[2],amcc->irq,amcc->used); - + for (amcc = amcc_devices; amcc; amcc = next) { + next = amcc->next; + printk("%2d %2d %2d 0x%4x 0x%4x %3s 0x%4x 0x%4x %2d %2d\n", amcc->pci_bus, amcc->pci_slot, amcc->pci_func, amcc->vendor, amcc->device, amcc->master ? "yes" : "no", amcc->io_addr[0], amcc->io_addr[2], amcc->irq, amcc->used); + } } /****************************************************************************/ /* return all card information for driver */ int i_pci_card_data(struct pcilst_struct *amcc, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - unsigned short *io_addr, unsigned short *irq, unsigned short *master) + unsigned char *pci_bus, unsigned char *pci_slot, + unsigned char *pci_func, unsigned short *io_addr, unsigned short *irq, + unsigned short *master) { - int i; - - if (!amcc) return -1; - *pci_bus=amcc->pci_bus; - *pci_slot=amcc->pci_slot; - *pci_func=amcc->pci_func; - for (i=0;i<5;i++) - io_addr[i]=amcc->io_addr[i]; - *irq=amcc->irq; - *master=amcc->master; + int i; + + if (!amcc) + return -1; + *pci_bus = amcc->pci_bus; + *pci_slot = amcc->pci_slot; + *pci_func = amcc->pci_func; + for (i = 0; i < 5; i++) + io_addr[i] = amcc->io_addr[i]; + *irq = amcc->irq; + *master = amcc->master; return 0; } /****************************************************************************/ /* select and alloc card */ -struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot) +struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot) { struct pcilst_struct *card; - - if ((pci_bus<1)&(pci_slot<1)) { // use autodetection - if ((card=ptr_find_free_pci_card_by_device(vendor_id,device_id))==NULL) { + + if ((pci_bus < 1) & (pci_slot < 1)) { // use autodetection + if ((card = ptr_find_free_pci_card_by_device(vendor_id, + device_id)) == NULL) { rt_printk(" - Unused card not found in system!\n"); return NULL; } } else { - switch (i_find_free_pci_card_by_position(vendor_id,device_id,pci_bus,pci_slot,&card)) { + switch (i_find_free_pci_card_by_position(vendor_id, device_id, + pci_bus, pci_slot, &card)) { case 1: - rt_printk(" - Card not found on requested position b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card not found on requested position b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; case 2: - rt_printk(" - Card on requested position is used b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card on requested position is used b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; } } - - if (i_pci_card_alloc(card)!=0) { + if (i_pci_card_alloc(card) != 0) { rt_printk(" - Can't allocate card!\n"); return NULL; } @@ -433,6 +460,3 @@ struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, un } #endif - - - diff --git a/comedi/drivers/addi-data/hwdrv_APCI1710.c b/comedi/drivers/addi-data/hwdrv_APCI1710.c index a40c5b85..d5defd06 100644 --- a/comedi/drivers/addi-data/hwdrv_APCI1710.c +++ b/comedi/drivers/addi-data/hwdrv_APCI1710.c @@ -44,194 +44,193 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc | | | | +----------+-----------+------------------------------------------------+ */ - #include "hwdrv_APCI1710.h" - #include "APCI1710_Inp_cpt.c" - - #include "APCI1710_Ssi.c" - #include "APCI1710_Tor.c" - #include "APCI1710_Ttl.c" - #include "APCI1710_Dig_io.c" - #include "APCI1710_82x54.c" - #include "APCI1710_Chrono.c" - #include "APCI1710_Pwm.c" - #include "APCI1710_INCCPT.c" - - -void i_ADDI_AttachPCI1710 (comedi_device *dev) - { +#include "hwdrv_APCI1710.h" +#include "APCI1710_Inp_cpt.c" + +#include "APCI1710_Ssi.c" +#include "APCI1710_Tor.c" +#include "APCI1710_Ttl.c" +#include "APCI1710_Dig_io.c" +#include "APCI1710_82x54.c" +#include "APCI1710_Chrono.c" +#include "APCI1710_Pwm.c" +#include "APCI1710_INCCPT.c" + +void i_ADDI_AttachPCI1710(comedi_device * dev) +{ comedi_subdevice *s; - int ret = 0; + int ret = 0; int n_subdevices = 9; - + //Update-0.7.57->0.7.68dev->n_subdevices = 9; - if((ret=alloc_subdevices(dev,n_subdevices))<0) - return; - - // Allocate and Initialise Timer Subdevice Structures - s = dev->subdevices + 0; - + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) + return; + + // Allocate and Initialise Timer Subdevice Structures + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = 3; - s->maxdata = 0; + s->subdev_flags = SDF_WRITEABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = 3; + s->maxdata = 0; s->len_chanlist = 3; - s->range_table = &range_digital; - s->insn_write=i_APCI1710_InsnWriteEnableDisableTimer; - s->insn_read=i_APCI1710_InsnReadAllTimerValue; - s->insn_config=i_APCI1710_InsnConfigInitTimer; - s->insn_bits=i_APCI1710_InsnBitsTimer; - - - // Allocate and Initialise DIO Subdevice Structures + s->range_table = &range_digital; + s->insn_write = i_APCI1710_InsnWriteEnableDisableTimer; + s->insn_read = i_APCI1710_InsnReadAllTimerValue; + s->insn_config = i_APCI1710_InsnConfigInitTimer; + s->insn_bits = i_APCI1710_InsnBitsTimer; + + // Allocate and Initialise DIO Subdevice Structures s = dev->subdevices + 1; - + s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; s->n_chan = 7; s->maxdata = 1; s->len_chanlist = 7; - s->range_table = &range_digital; - s->insn_config=i_APCI1710_InsnConfigDigitalIO; - s->insn_read= i_APCI1710_InsnReadDigitalIOChlValue; - s->insn_bits=i_APCI1710_InsnBitsDigitalIOPortOnOff; - s->insn_write=i_APCI1710_InsnWriteDigitalIOChlOnOff; - + s->range_table = &range_digital; + s->insn_config = i_APCI1710_InsnConfigDigitalIO; + s->insn_read = i_APCI1710_InsnReadDigitalIOChlValue; + s->insn_bits = i_APCI1710_InsnBitsDigitalIOPortOnOff; + s->insn_write = i_APCI1710_InsnWriteDigitalIOChlOnOff; + + // Allocate and Initialise Chrono Subdevice Structures + s = dev->subdevices + 2; - // Allocate and Initialise Chrono Subdevice Structures - s = dev->subdevices + 2; - s->type = COMEDI_SUBD_CHRONO; - s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = 4; - s->maxdata = 0; + s->subdev_flags = SDF_WRITEABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = 4; + s->maxdata = 0; s->len_chanlist = 4; - s->range_table = &range_digital; - s->insn_write=i_APCI1710_InsnWriteEnableDisableChrono; - s->insn_read=i_APCI1710_InsnReadChrono; - s->insn_config=i_APCI1710_InsnConfigInitChrono; - s->insn_bits=i_APCI1710_InsnBitsChronoDigitalIO; - - - // Allocate and Initialise PWM Subdevice Structures + s->range_table = &range_digital; + s->insn_write = i_APCI1710_InsnWriteEnableDisableChrono; + s->insn_read = i_APCI1710_InsnReadChrono; + s->insn_config = i_APCI1710_InsnConfigInitChrono; + s->insn_bits = i_APCI1710_InsnBitsChronoDigitalIO; + + // Allocate and Initialise PWM Subdevice Structures s = dev->subdevices + 3; s->type = COMEDI_SUBD_PWM; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; s->n_chan = 3; s->maxdata = 1; s->len_chanlist = 3; - s->range_table = &range_digital; - s->io_bits=0; //all bits input + s->range_table = &range_digital; + s->io_bits = 0; //all bits input s->insn_config = i_APCI1710_InsnConfigPWM; - s->insn_read = i_APCI1710_InsnReadGetPWMStatus; - s->insn_write = i_APCI1710_InsnWritePWM; - s->insn_bits = i_APCI1710_InsnBitsReadPWMInterrupt; + s->insn_read = i_APCI1710_InsnReadGetPWMStatus; + s->insn_write = i_APCI1710_InsnWritePWM; + s->insn_bits = i_APCI1710_InsnBitsReadPWMInterrupt; // Allocate and Initialise TTLIO Subdevice Structures s = dev->subdevices + 4; s->type = COMEDI_SUBD_TTLIO; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; s->n_chan = 8; s->maxdata = 1; s->len_chanlist = 8; - s->range_table = &range_apci1710_ttl; // to pass arguments in range - s->insn_config = i_APCI1710_InsnConfigInitTTLIO; - s->insn_bits = i_APCI1710_InsnBitsReadTTLIO; - s->insn_write = i_APCI1710_InsnWriteSetTTLIOChlOnOff; - s->insn_read = i_APCI1710_InsnReadTTLIOAllPortValue; - + s->range_table = &range_apci1710_ttl; // to pass arguments in range + s->insn_config = i_APCI1710_InsnConfigInitTTLIO; + s->insn_bits = i_APCI1710_InsnBitsReadTTLIO; + s->insn_write = i_APCI1710_InsnWriteSetTTLIOChlOnOff; + s->insn_read = i_APCI1710_InsnReadTTLIOAllPortValue; // Allocate and Initialise TOR Subdevice Structures s = dev->subdevices + 5; s->type = COMEDI_SUBD_TOR; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; s->n_chan = 8; s->maxdata = 1; s->len_chanlist = 8; - s->range_table = &range_digital; - s->io_bits=0; //all bits input - s->insn_config = i_APCI1710_InsnConfigInitTorCounter; - s->insn_read = i_APCI1710_InsnReadGetTorCounterInitialisation; - s->insn_write = i_APCI1710_InsnWriteEnableDisableTorCounter; - s->insn_bits = i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue; - + s->range_table = &range_digital; + s->io_bits = 0; //all bits input + s->insn_config = i_APCI1710_InsnConfigInitTorCounter; + s->insn_read = i_APCI1710_InsnReadGetTorCounterInitialisation; + s->insn_write = i_APCI1710_InsnWriteEnableDisableTorCounter; + s->insn_bits = i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue; + // Allocate and Initialise SSI Subdevice Structures s = dev->subdevices + 6; s->type = COMEDI_SUBD_SSI; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan =4; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = 4; s->maxdata = 1; s->len_chanlist = 4; - s->range_table = &range_apci1710_ssi; + s->range_table = &range_apci1710_ssi; s->insn_config = i_APCI1710_InsnConfigInitSSI; - s->insn_read = i_APCI1710_InsnReadSSIValue; - s->insn_bits = i_APCI1710_InsnBitsSSIDigitalIO; - + s->insn_read = i_APCI1710_InsnReadSSIValue; + s->insn_bits = i_APCI1710_InsnBitsSSIDigitalIO; + // Allocate and Initialise PULSEENCODER Subdevice Structures - s = dev->subdevices + 7; - s->type = COMEDI_SUBD_PULSEENCODER; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = 4; - s->maxdata = 1; + s = dev->subdevices + 7; + s->type = COMEDI_SUBD_PULSEENCODER; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = 4; + s->maxdata = 1; s->len_chanlist = 4; - s->range_table = &range_digital; - s->insn_config = i_APCI1710_InsnConfigInitPulseEncoder; - s->insn_write = i_APCI1710_InsnWriteEnableDisablePulseEncoder; - s->insn_bits = i_APCI1710_InsnBitsReadWritePulseEncoder; - s->insn_read = i_APCI1710_InsnReadInterruptPulseEncoder; + s->range_table = &range_digital; + s->insn_config = i_APCI1710_InsnConfigInitPulseEncoder; + s->insn_write = i_APCI1710_InsnWriteEnableDisablePulseEncoder; + s->insn_bits = i_APCI1710_InsnBitsReadWritePulseEncoder; + s->insn_read = i_APCI1710_InsnReadInterruptPulseEncoder; // Allocate and Initialise INCREMENTALCOUNTER Subdevice Structures - s = dev->subdevices + 8; - s->type = COMEDI_SUBD_INCREMENTALCOUNTER; - s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON; - s->n_chan = 500; - s->maxdata = 1; + s = dev->subdevices + 8; + s->type = COMEDI_SUBD_INCREMENTALCOUNTER; + s->subdev_flags = + SDF_WRITEABLE | SDF_READABLE | SDF_RT | SDF_GROUND | SDF_COMMON; + s->n_chan = 500; + s->maxdata = 1; s->len_chanlist = 500; - s->range_table = &range_apci1710_inccpt; - s->insn_config = i_APCI1710_InsnConfigINCCPT; - s->insn_write = i_APCI1710_InsnWriteINCCPT; - s->insn_read = i_APCI1710_InsnReadINCCPT; - s->insn_bits = i_APCI1710_InsnBitsINCCPT; - } - - - -int i_APCI1710_Reset(comedi_device *dev); -VOID v_APCI1710_Interrupt(int irq, void *d) ; + s->range_table = &range_apci1710_inccpt; + s->insn_config = i_APCI1710_InsnConfigINCCPT; + s->insn_write = i_APCI1710_InsnWriteINCCPT; + s->insn_read = i_APCI1710_InsnReadINCCPT; + s->insn_bits = i_APCI1710_InsnBitsINCCPT; +} + +int i_APCI1710_Reset(comedi_device * dev); +VOID v_APCI1710_Interrupt(int irq, void *d); //for 1710 - int i_APCI1710_Reset(comedi_device *dev) +int i_APCI1710_Reset(comedi_device * dev) { - int ret; - DWORD dw_Dummy; - - /*********************************/ - /* Read all module configuration */ - /*********************************/ - ret=inl(devpriv->s_BoardInfos.ui_Address+60); - devpriv->s_BoardInfos.dw_MolduleConfiguration [0]=ret; - - ret=inl(devpriv->s_BoardInfos.ui_Address+124); - devpriv->s_BoardInfos.dw_MolduleConfiguration [1]=ret; - - ret=inl(devpriv->s_BoardInfos.ui_Address+188); - devpriv->s_BoardInfos.dw_MolduleConfiguration [2]=ret; - - ret=inl(devpriv->s_BoardInfos.ui_Address+252); - devpriv->s_BoardInfos.dw_MolduleConfiguration [3]=ret; + int ret; + DWORD dw_Dummy; + + /*********************************/ + /* Read all module configuration */ + /*********************************/ + ret = inl(devpriv->s_BoardInfos.ui_Address + 60); + devpriv->s_BoardInfos.dw_MolduleConfiguration[0] = ret; + + ret = inl(devpriv->s_BoardInfos.ui_Address + 124); + devpriv->s_BoardInfos.dw_MolduleConfiguration[1] = ret; + + ret = inl(devpriv->s_BoardInfos.ui_Address + 188); + devpriv->s_BoardInfos.dw_MolduleConfiguration[2] = ret; + + ret = inl(devpriv->s_BoardInfos.ui_Address + 252); + devpriv->s_BoardInfos.dw_MolduleConfiguration[3] = ret; // outl(0x80808082,devpriv->s_BoardInfos.ui_Address+0x60); - outl(0x83838383,devpriv->s_BoardInfos.ui_Address+0x60); - + outl(0x83838383, devpriv->s_BoardInfos.ui_Address + 0x60); + devpriv->s_BoardInfos.b_BoardVersion = 1; - // Enable the interrupt for the controler - dw_Dummy = inl(devpriv->s_BoardInfos.ui_Address+ 0x38); - outl(dw_Dummy | 0x2000,devpriv->s_BoardInfos.ui_Address+0x38); + // Enable the interrupt for the controler + dw_Dummy = inl(devpriv->s_BoardInfos.ui_Address + 0x38); + outl(dw_Dummy | 0x2000, devpriv->s_BoardInfos.ui_Address + 0x38); return 0; } - /* +----------------------------------------------------------------------------+ | Function's Name : __VOID__ v_APCI1710_InterruptFunction | @@ -248,1016 +247,1019 @@ VOID v_APCI1710_Interrupt(int irq, void *d) ; +----------------------------------------------------------------------------+ */ - - - - -VOID v_APCI1710_Interrupt(int irq, void *d) +VOID v_APCI1710_Interrupt(int irq, void *d) { comedi_device *dev = d; - BYTE b_ModuleCpt = 0; - BYTE b_InterruptFlag = 0; - BYTE b_PWMCpt = 0; - BYTE b_TorCounterCpt = 0; - BYTE b_PulseIncoderCpt = 0; - UINT ui_16BitValue; + BYTE b_ModuleCpt = 0; + BYTE b_InterruptFlag = 0; + BYTE b_PWMCpt = 0; + BYTE b_TorCounterCpt = 0; + BYTE b_PulseIncoderCpt = 0; + UINT ui_16BitValue; ULONG ul_InterruptLatchReg = 0; ULONG ul_LatchRegisterValue = 0; ULONG ul_82X54InterruptStatus; ULONG ul_StatusRegister; - str_ModuleInfo * ps_ModuleInfo; + str_ModuleInfo *ps_ModuleInfo; - printk("APCI1710 Interrupt\n"); - for (b_ModuleCpt = 0; b_ModuleCpt < 4; b_ModuleCpt ++, ps_ModuleInfo ++) - { + printk("APCI1710 Interrupt\n"); + for (b_ModuleCpt = 0; b_ModuleCpt < 4; b_ModuleCpt++, ps_ModuleInfo++) { /**************************/ - /* 1199/0225 to 0100/0226 */ + /* 1199/0225 to 0100/0226 */ /**************************/ - ps_ModuleInfo = &devpriv->s_ModuleInfo [b_ModuleCpt]; - + ps_ModuleInfo = &devpriv->s_ModuleInfo[b_ModuleCpt]; - /***********************/ - /* Test if 82X54 timer */ + /***********************/ + /* Test if 82X54 timer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_82X54_TIMER) - { - - //printk("TIMER Interrupt Occurred\n"); - ul_82X54InterruptStatus= inl(devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModuleCpt)); + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_82X54_TIMER) { + + //printk("TIMER Interrupt Occurred\n"); + ul_82X54InterruptStatus = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (64 * b_ModuleCpt)); /***************************/ - /* Test if interrupt occur */ + /* Test if interrupt occur */ /***************************/ - if ((ul_82X54InterruptStatus & ps_ModuleInfo-> - s_82X54ModuleInfo. - b_InterruptMask) != 0) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = (ul_82X54InterruptStatus & ps_ModuleInfo-> - s_82X54ModuleInfo. - b_InterruptMask) << 4; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = 0; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if ((ul_82X54InterruptStatus & ps_ModuleInfo-> + s_82X54ModuleInfo. + b_InterruptMask) != 0) { + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write]. + ul_OldInterruptMask = + (ul_82X54InterruptStatus & + ps_ModuleInfo->s_82X54ModuleInfo. + b_InterruptMask) << 4; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write]. + b_OldModuleMask = 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write].ul_OldCounterLatchValue = 0; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - } // if ((ul_82X54InterruptStatus & 0x7) != 0) - } // 82X54 timer - - - + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + } // if ((ul_82X54InterruptStatus & 0x7) != 0) + } // 82X54 timer /***************************/ - /* Test if increm. counter */ + /* Test if increm. counter */ /***************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER) { - ul_InterruptLatchReg=inl(devpriv->s_BoardInfos. - ui_Address + (64 * b_ModuleCpt)); + ul_InterruptLatchReg = inl(devpriv->s_BoardInfos. + ui_Address + (64 * b_ModuleCpt)); /*********************/ - /* Test if interrupt */ + /* Test if interrupt */ /*********************/ - if ((ul_InterruptLatchReg & 0x22) && (ps_ModuleInfo-> - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & 0x80)) - { + if ((ul_InterruptLatchReg & 0x22) && (ps_ModuleInfo-> + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 & 0x80)) { /************************************/ - /* Test if strobe latch I interrupt */ + /* Test if strobe latch I interrupt */ /************************************/ - if (ul_InterruptLatchReg & 2) - { - ul_LatchRegisterValue=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModuleCpt)); - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 1UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if (ul_InterruptLatchReg & 2) { + ul_LatchRegisterValue = + inl(devpriv->s_BoardInfos. + ui_Address + 4 + + (64 * b_ModuleCpt)); + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 1UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ - /****************************/ + /* Increment the write FIFO */ + /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - - } + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); + + } /*************************************/ - /* Test if strobe latch II interrupt */ + /* Test if strobe latch II interrupt */ /*************************************/ - if (ul_InterruptLatchReg & 0x20) - { - - ul_LatchRegisterValue=inl(devpriv->s_BoardInfos. - ui_Address + 8 + (64 * b_ModuleCpt)); - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 2UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if (ul_InterruptLatchReg & 0x20) { + + ul_LatchRegisterValue = + inl(devpriv->s_BoardInfos. + ui_Address + 8 + + (64 * b_ModuleCpt)); + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 2UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - } - } + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); + + } + } - - ul_InterruptLatchReg=inl(devpriv-> s_BoardInfos. - ui_Address + 24 + (64 * b_ModuleCpt)); + ul_InterruptLatchReg = inl(devpriv->s_BoardInfos. + ui_Address + 24 + (64 * b_ModuleCpt)); /***************************/ - /* Test if index interrupt */ + /* Test if index interrupt */ /***************************/ - if (ul_InterruptLatchReg & 0x8) - { - ps_ModuleInfo-> - s_SiemensCounterInfo. - s_InitFlag. - b_IndexInterruptOccur = 1; - - if (ps_ModuleInfo-> - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister2 & APCI1710_INDEX_AUTO_MODE) - { - - outl(ps_ModuleInfo-> - s_SiemensCounterInfo. - s_ModeRegister. - dw_ModeRegister1_2_3_4,devpriv-> - s_BoardInfos. - ui_Address + 20 + (64 * b_ModuleCpt)); - } + if (ul_InterruptLatchReg & 0x8) { + ps_ModuleInfo-> + s_SiemensCounterInfo. + s_InitFlag.b_IndexInterruptOccur = 1; + + if (ps_ModuleInfo-> + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister2 & + APCI1710_INDEX_AUTO_MODE) { + + outl(ps_ModuleInfo-> + s_SiemensCounterInfo. + s_ModeRegister. + dw_ModeRegister1_2_3_4, + devpriv->s_BoardInfos. + ui_Address + 20 + + (64 * b_ModuleCpt)); + } /*****************************/ - /* Test if interrupt enabled */ + /* Test if interrupt enabled */ /*****************************/ - if ((ps_ModuleInfo-> - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_ENABLE_INDEX_INT) == APCI1710_ENABLE_INDEX_INT) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 4UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if ((ps_ModuleInfo-> + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 & + APCI1710_ENABLE_INDEX_INT) == + APCI1710_ENABLE_INDEX_INT) { + devpriv->s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 4UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); + } - } + } /*****************************/ - /* Test if compare interrupt */ + /* Test if compare interrupt */ /*****************************/ - if (ul_InterruptLatchReg & 0x10) - { + if (ul_InterruptLatchReg & 0x10) { /*****************************/ - /* Test if interrupt enabled */ + /* Test if interrupt enabled */ /*****************************/ - if ((ps_ModuleInfo-> - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister3 & APCI1710_ENABLE_COMPARE_INT) == APCI1710_ENABLE_COMPARE_INT) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 8UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if ((ps_ModuleInfo-> + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister3 & + APCI1710_ENABLE_COMPARE_INT) == + APCI1710_ENABLE_COMPARE_INT) { + devpriv->s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 8UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ - /****************************/ + /* Increment the write FIFO */ + /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - - } - } + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); + + } + } /*******************************************/ - /* Test if frequency measurement interrupt */ + /* Test if frequency measurement interrupt */ /*******************************************/ - if (ul_InterruptLatchReg & 0x20) - { + if (ul_InterruptLatchReg & 0x20) { /*******************/ - /* Read the status */ + /* Read the status */ /*******************/ - ul_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 32 + (64 * b_ModuleCpt)); + ul_StatusRegister = inl(devpriv->s_BoardInfos. + ui_Address + 32 + (64 * b_ModuleCpt)); /******************/ - /* Read the value */ + /* Read the value */ /******************/ + ul_LatchRegisterValue = + inl(devpriv->s_BoardInfos.ui_Address + + 28 + (64 * b_ModuleCpt)); - ul_LatchRegisterValue=inl(devpriv->s_BoardInfos. - ui_Address + 28 + (64 * b_ModuleCpt)); - - switch ((ul_StatusRegister >> 1) & 3) - { - case 0: + switch ((ul_StatusRegister >> 1) & 3) { + case 0: /*************************/ - /* Test the counter mode */ + /* Test the counter mode */ /*************************/ - if ((devpriv-> - s_ModuleInfo [b_ModuleCpt]. - s_SiemensCounterInfo. - s_ModeRegister. - s_ByteModeRegister. - b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER) - { + if ((devpriv->s_ModuleInfo[b_ModuleCpt]. + s_SiemensCounterInfo. + s_ModeRegister. + s_ByteModeRegister. + b_ModeRegister1 & + APCI1710_16BIT_COUNTER) + == APCI1710_16BIT_COUNTER) { /****************************************/ - /* Test if 16-bit counter 1 pulse occur */ + /* Test if 16-bit counter 1 pulse occur */ /****************************************/ - if ((ul_LatchRegisterValue & 0xFFFFU) != 0) - { - ui_16BitValue = (UINT) ul_LatchRegisterValue & 0xFFFFU; - ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue); - } + if ((ul_LatchRegisterValue & + 0xFFFFU) != 0) { + ui_16BitValue = + (UINT) + ul_LatchRegisterValue + & 0xFFFFU; + ul_LatchRegisterValue = + (ul_LatchRegisterValue + & 0xFFFF0000UL) + | (0xFFFFU - + ui_16BitValue); + } /****************************************/ - /* Test if 16-bit counter 2 pulse occur */ + /* Test if 16-bit counter 2 pulse occur */ /****************************************/ - if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0) - { - ui_16BitValue = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU); - ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16); - } - } - else - { - if (ul_LatchRegisterValue != 0) - { - ul_LatchRegisterValue = 0xFFFFFFFFUL - ul_LatchRegisterValue; - } - } - break; - - case 1: + if ((ul_LatchRegisterValue & + 0xFFFF0000UL) != + 0) { + ui_16BitValue = + (UINT) ( + (ul_LatchRegisterValue + >> 16) & + 0xFFFFU); + ul_LatchRegisterValue = + (ul_LatchRegisterValue + & 0xFFFFUL) | + ((0xFFFFU - + ui_16BitValue) + << 16); + } + } else { + if (ul_LatchRegisterValue != 0) { + ul_LatchRegisterValue = + 0xFFFFFFFFUL - + ul_LatchRegisterValue; + } + } + break; + + case 1: /****************************************/ - /* Test if 16-bit counter 2 pulse occur */ + /* Test if 16-bit counter 2 pulse occur */ /****************************************/ - if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0) - { - ui_16BitValue = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU); - ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16); - } - break; - - case 2: + if ((ul_LatchRegisterValue & + 0xFFFF0000UL) != 0) { + ui_16BitValue = + (UINT) ( + (ul_LatchRegisterValue + >> 16) & + 0xFFFFU); + ul_LatchRegisterValue = + (ul_LatchRegisterValue & + 0xFFFFUL) | ((0xFFFFU - + ui_16BitValue) + << 16); + } + break; + + case 2: /****************************************/ - /* Test if 16-bit counter 1 pulse occur */ + /* Test if 16-bit counter 1 pulse occur */ /****************************************/ - if ((ul_LatchRegisterValue & 0xFFFFU) != 0) - { - ui_16BitValue = (UINT) ul_LatchRegisterValue & 0xFFFFU; - ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue); - } - break; - } - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 0x10000UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if ((ul_LatchRegisterValue & 0xFFFFU) != + 0) { + ui_16BitValue = + (UINT) + ul_LatchRegisterValue & + 0xFFFFU; + ul_LatchRegisterValue = + (ul_LatchRegisterValue & + 0xFFFF0000UL) | (0xFFFFU + - ui_16BitValue); + } + break; + } + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write]. + ul_OldInterruptMask = 0x10000UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write]. + b_OldModuleMask = 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters[devpriv-> + s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - - - } - } // Incremental counter - - - - + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + } + } // Incremental counter - /***************/ - /* Test if CDA */ + /***************/ + /* Test if CDA */ /***************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CDA) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_CDA) { /******************************************/ - /* Test if CDA enable and functionality 0 */ + /* Test if CDA enable and functionality 0 */ /******************************************/ - if ((devpriv-> - s_ModuleInfo [b_ModuleCpt]. - s_CDAModuleInfo. - b_CDAEnable == APCI1710_ENABLE) && (devpriv-> - s_ModuleInfo [b_ModuleCpt]. - s_CDAModuleInfo. - b_FctSelection == 0)) - { + if ((devpriv->s_ModuleInfo[b_ModuleCpt]. + s_CDAModuleInfo. + b_CDAEnable == APCI1710_ENABLE) + && (devpriv->s_ModuleInfo[b_ModuleCpt]. + s_CDAModuleInfo.b_FctSelection == 0)) { + /****************************/ + /* Get the interrupt status */ /****************************/ - /* Get the interrupt status */ - /****************************/ - - ul_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (64 * b_ModuleCpt)); + ul_StatusRegister = inl(devpriv->s_BoardInfos. + ui_Address + 16 + (64 * b_ModuleCpt)); /***************************/ - /* Test if interrupt occur */ + /* Test if interrupt occur */ /***************************/ - if (ul_StatusRegister & 1) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 0x80000UL; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = 0; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; - - + if (ul_StatusRegister & 1) { + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 0x80000UL; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = 0; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; + /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); - } // if (ul_StatusRegister & 1) - - } - } // CDA + } // if (ul_StatusRegister & 1) + } + } // CDA /***********************/ - /* Test if PWM counter */ + /* Test if PWM counter */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PWM) - { - for (b_PWMCpt = 0; b_PWMCpt < 2; b_PWMCpt ++) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_PWM) { + for (b_PWMCpt = 0; b_PWMCpt < 2; b_PWMCpt++) { /*************************************/ - /* Test if PWM interrupt initialised */ + /* Test if PWM interrupt initialised */ /*************************************/ - if (devpriv-> - s_ModuleInfo [b_ModuleCpt]. - s_PWMModuleInfo. - s_PWMInfo [b_PWMCpt]. - b_InterruptEnable == APCI1710_ENABLE) - { + if (devpriv-> + s_ModuleInfo[b_ModuleCpt]. + s_PWMModuleInfo. + s_PWMInfo[b_PWMCpt]. + b_InterruptEnable == APCI1710_ENABLE) { /*****************************/ - /* Read the interrupt status */ + /* Read the interrupt status */ /*****************************/ - ul_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 16 + (20 * b_PWMCpt) + (64 * b_ModuleCpt)); - + ul_StatusRegister = + inl(devpriv->s_BoardInfos. + ui_Address + 16 + + (20 * b_PWMCpt) + + (64 * b_ModuleCpt)); /***************************/ - /* Test if interrupt occur */ + /* Test if interrupt occur */ /***************************/ - if (ul_StatusRegister & 0x1) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + if (ul_StatusRegister & 0x1) { + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - ul_OldInterruptMask = 0x4000UL << b_PWMCpt; + ul_OldInterruptMask = + 0x4000UL << b_PWMCpt; - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; + b_OldModuleMask = + 1 << b_ModuleCpt; - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % + APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - - } // if (ul_StatusRegister & 0x1) - } // if (APCI1710_ENABLE) - } // for (b_PWMCpt == 0; b_PWMCpt < 0; b_PWMCpt ++) - } // PWM counter - + //Send a signal to from kernel to user space + send_sig(SIGIO, + devpriv->tsk_Current, + 0); + } // if (ul_StatusRegister & 0x1) + } // if (APCI1710_ENABLE) + } // for (b_PWMCpt == 0; b_PWMCpt < 0; b_PWMCpt ++) + } // PWM counter /***********************/ - /* Test if tor counter */ + /* Test if tor counter */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER) - { - for (b_TorCounterCpt = 0; b_TorCounterCpt < 2; b_TorCounterCpt ++) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_TOR_COUNTER) { + for (b_TorCounterCpt = 0; b_TorCounterCpt < 2; + b_TorCounterCpt++) { /*************************************/ - /* Test if tor interrupt initialised */ + /* Test if tor interrupt initialised */ /*************************************/ - if (devpriv-> - s_ModuleInfo [b_ModuleCpt]. - s_TorCounterModuleInfo. - s_TorCounterInfo [b_TorCounterCpt]. - b_InterruptEnable == APCI1710_ENABLE) - { + if (devpriv-> + s_ModuleInfo[b_ModuleCpt]. + s_TorCounterModuleInfo. + s_TorCounterInfo[b_TorCounterCpt]. + b_InterruptEnable == APCI1710_ENABLE) { /*****************************/ - /* Read the interrupt status */ + /* Read the interrupt status */ /*****************************/ - - ul_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt)); + ul_StatusRegister = + inl(devpriv->s_BoardInfos. + ui_Address + 12 + + (16 * b_TorCounterCpt) + + (64 * b_ModuleCpt)); /***************************/ - /* Test if interrupt occur */ + /* Test if interrupt occur */ /***************************/ - if (ul_StatusRegister & 0x1) - { + if (ul_StatusRegister & 0x1) { /******************************/ - /* Read the tor counter value */ + /* Read the tor counter value */ /******************************/ - - ul_LatchRegisterValue=inl(devpriv->s_BoardInfos. - ui_Address + 0 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt)); + ul_LatchRegisterValue = + inl(devpriv-> + s_BoardInfos. + ui_Address + 0 + + (16 * b_TorCounterCpt) + + (64 * b_ModuleCpt)); - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - ul_OldInterruptMask = 0x1000UL << b_TorCounterCpt; + ul_OldInterruptMask = + 0x1000UL << + b_TorCounterCpt; - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; + b_OldModuleMask = + 1 << b_ModuleCpt; - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; + ul_OldCounterLatchValue + = ul_LatchRegisterValue; - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; - /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % + APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - } // if (ul_StatusRegister & 0x1) - } // if (APCI1710_ENABLE) - } // for (b_TorCounterCpt == 0; b_TorCounterCpt < 0; b_TorCounterCpt ++) - } // Tor counter - - - + //Send a signal to from kernel to user space + send_sig(SIGIO, + devpriv->tsk_Current, + 0); + } // if (ul_StatusRegister & 0x1) + } // if (APCI1710_ENABLE) + } // for (b_TorCounterCpt == 0; b_TorCounterCpt < 0; b_TorCounterCpt ++) + } // Tor counter /***********************/ - /* Test if chronometer */ + /* Test if chronometer */ /***********************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) - { - - //printk("APCI1710 Chrono Interrupt\n"); + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_CHRONOMETER) { + + //printk("APCI1710 Chrono Interrupt\n"); /*****************************/ - /* Read the interrupt status */ + /* Read the interrupt status */ /*****************************/ - - ul_InterruptLatchReg=inl(devpriv->s_BoardInfos. - ui_Address + 12 + (64 * b_ModuleCpt)); + ul_InterruptLatchReg = inl(devpriv->s_BoardInfos. + ui_Address + 12 + (64 * b_ModuleCpt)); /***************************/ - /* Test if interrupt occur */ + /* Test if interrupt occur */ /***************************/ - if ((ul_InterruptLatchReg & 0x8) == 0x8) - { + if ((ul_InterruptLatchReg & 0x8) == 0x8) { /****************************/ - /* Clear the interrupt flag */ + /* Clear the interrupt flag */ /****************************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 32 + (64 * b_ModuleCpt)); + outl(0, devpriv->s_BoardInfos. + ui_Address + 32 + (64 * b_ModuleCpt)); /***************************/ - /* Test if continuous mode */ + /* Test if continuous mode */ /***************************/ - if (ps_ModuleInfo-> - s_ChronoModuleInfo. - b_CycleMode == APCI1710_ENABLE) - { + if (ps_ModuleInfo-> + s_ChronoModuleInfo. + b_CycleMode == APCI1710_ENABLE) { /********************/ - /* Clear the status */ + /* Clear the status */ /********************/ - - outl(0,devpriv->s_BoardInfos. - ui_Address + 36 + (64 * b_ModuleCpt)); - } + outl(0, devpriv->s_BoardInfos. + ui_Address + 36 + + (64 * b_ModuleCpt)); + } /*************************/ - /* Read the timing value */ + /* Read the timing value */ /*************************/ - - ul_LatchRegisterValue=inl(devpriv->s_BoardInfos. - ui_Address + 4 + (64 * b_ModuleCpt)); + ul_LatchRegisterValue = + inl(devpriv->s_BoardInfos.ui_Address + + 4 + (64 * b_ModuleCpt)); /*****************************/ - /* Test if interrupt enabled */ + /* Test if interrupt enabled */ /*****************************/ - if (ps_ModuleInfo-> - s_ChronoModuleInfo. - b_InterruptMask) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldInterruptMask = 0x80; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; - - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> - s_InterruptParameters. - ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; - - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + if (ps_ModuleInfo-> + s_ChronoModuleInfo.b_InterruptMask) { + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].ul_OldInterruptMask = + 0x80; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write].b_OldModuleMask = + 1 << b_ModuleCpt; + + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv->s_InterruptParameters. + ui_Write]. + ul_OldCounterLatchValue = + ul_LatchRegisterValue; + + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* Increment the write FIFO */ - /****************************/ + /* Increment the write FIFO */ + /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % APCI1710_SAVE_INTERRUPT; - b_InterruptFlag = 1; + b_InterruptFlag = 1; - - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - } - } - } // Chronometer - + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, + 0); + } + } + } // Chronometer /*************************/ - /* Test if pulse encoder */ + /* Test if pulse encoder */ /*************************/ - if ((devpriv-> - s_BoardInfos. - dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PULSE_ENCODER) - { + if ((devpriv->s_BoardInfos. + dw_MolduleConfiguration[b_ModuleCpt] & + 0xFFFF0000UL) == APCI1710_PULSE_ENCODER) { /****************************/ - /* Read the status register */ + /* Read the status register */ /****************************/ - - ul_StatusRegister=inl(devpriv->s_BoardInfos. - ui_Address + 20 + (64 * b_ModuleCpt)); + ul_StatusRegister = inl(devpriv->s_BoardInfos. + ui_Address + 20 + (64 * b_ModuleCpt)); - if (ul_StatusRegister & 0xF) - { - for (b_PulseIncoderCpt = 0; b_PulseIncoderCpt < 4; b_PulseIncoderCpt ++) - { + if (ul_StatusRegister & 0xF) { + for (b_PulseIncoderCpt = 0; + b_PulseIncoderCpt < 4; + b_PulseIncoderCpt++) { /*************************************/ - /* Test if pulse encoder initialised */ + /* Test if pulse encoder initialised */ /*************************************/ - if ((ps_ModuleInfo-> - s_PulseEncoderModuleInfo. - s_PulseEncoderInfo [b_PulseIncoderCpt]. - b_PulseEncoderInit == 1) && - (((ps_ModuleInfo-> - s_PulseEncoderModuleInfo. - dw_SetRegister >> b_PulseIncoderCpt) & 1) == 1) && - (((ul_StatusRegister >> (b_PulseIncoderCpt)) & 1) == 1)) - { - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + if ((ps_ModuleInfo-> + s_PulseEncoderModuleInfo. + s_PulseEncoderInfo + [b_PulseIncoderCpt]. + b_PulseEncoderInit == 1) + && (((ps_ModuleInfo->s_PulseEncoderModuleInfo.dw_SetRegister >> b_PulseIncoderCpt) & 1) == 1) && (((ul_StatusRegister >> (b_PulseIncoderCpt)) & 1) == 1)) { + devpriv->s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - ul_OldInterruptMask = 0x100UL << b_PulseIncoderCpt; + ul_OldInterruptMask = + 0x100UL << + b_PulseIncoderCpt; - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - b_OldModuleMask = 1 << b_ModuleCpt; + b_OldModuleMask = + 1 << b_ModuleCpt; - devpriv-> - s_InterruptParameters. - s_FIFOInterruptParameters [devpriv-> + devpriv-> + s_InterruptParameters. + s_FIFOInterruptParameters + [devpriv-> s_InterruptParameters. ui_Write]. - ul_OldCounterLatchValue = ul_LatchRegisterValue; + ul_OldCounterLatchValue + = ul_LatchRegisterValue; - devpriv-> - s_InterruptParameters. - ul_InterruptOccur ++; + devpriv-> + s_InterruptParameters. + ul_InterruptOccur++; /****************************/ - /* 0899/0224 to 1199/0225 */ + /* 0899/0224 to 1199/0225 */ /****************************/ - /* Increment the write FIFO */ + /* Increment the write FIFO */ /****************************/ - devpriv-> - s_InterruptParameters. - ui_Write = (devpriv-> - s_InterruptParameters. - ui_Write + 1) % APCI1710_SAVE_INTERRUPT; + devpriv-> + s_InterruptParameters. + ui_Write = (devpriv-> + s_InterruptParameters. + ui_Write + + 1) % + APCI1710_SAVE_INTERRUPT; + + b_InterruptFlag = 1; - b_InterruptFlag = 1; - /**********************/ - /* Call user function */ + /* Call user function */ /**********************/ - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - - } + //Send a signal to from kernel to user space + send_sig(SIGIO, + devpriv->tsk_Current, + 0); + + } } - } - }//pulse encoder + } + } //pulse encoder - } - return ; + } + return; } - diff --git a/comedi/drivers/addi-data/hwdrv_APCI1710.h b/comedi/drivers/addi-data/hwdrv_APCI1710.h index e7328616..dc475c4f 100644 --- a/comedi/drivers/addi-data/hwdrv_APCI1710.h +++ b/comedi/drivers/addi-data/hwdrv_APCI1710.h @@ -22,81 +22,73 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - - -#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ -#define COMEDI_SUBD_PWM 12 /* Pulse width Measurement */ -#define COMEDI_SUBD_SSI 13 /* Synchronous serial interface */ -#define COMEDI_SUBD_TOR 14 /* Tor counter */ -#define COMEDI_SUBD_CHRONO 15 /* Chrono meter*/ -#define COMEDI_SUBD_PULSEENCODER 16 /* Pulse Encoder INP CPT*/ -#define COMEDI_SUBD_INCREMENTALCOUNTER 17 /* Incremental Counter */ - - - #define INT int - #define UINT unsigned int - #define BYTE unsigned char - #define CHAR char - #define LONG long - #define ULONG unsigned long - #define VOID void - #define PINT int * - #define PUINT unsigned int * - #define PBYTE unsigned char * - #define PCHAR char * - #define PLONG long * - #define PULONG unsigned long * - #define DWORD unsigned long - #define WORD unsigned short - - #define APCI1710_BOARD_NAME "apci1710" - #define APCI1710_BOARD_VENDOR_ID 0x10E8 - #define APCI1710_BOARD_DEVICE_ID 0x818F - #define APCI1710_ADDRESS_RANGE 256 - #define APCI1710_CONFIG_ADDRESS_RANGE 8 - #define APCI1710_INCREMENTAL_COUNTER 0x53430000UL - #define APCI1710_SSI_COUNTER 0x53490000UL - #define APCI1710_TTL_IO 0x544C0000UL - #define APCI1710_DIGITAL_IO 0x44490000UL - #define APCI1710_82X54_TIMER 0x49430000UL - #define APCI1710_CHRONOMETER 0x43480000UL - #define APCI1710_PULSE_ENCODER 0x495A0000UL - #define APCI1710_TOR_COUNTER 0x544F0000UL - #define APCI1710_PWM 0x50570000UL - #define APCI1710_ETM 0x45540000UL - #define APCI1710_CDA 0x43440000UL - #define APCI1710_DISABLE 0 - #define APCI1710_ENABLE 1 - #define APCI1710_SYNCHRONOUS_MODE 1 - #define APCI1710_ASYNCHRONOUS_MODE 0 - +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#define COMEDI_SUBD_PWM 12 /* Pulse width Measurement */ +#define COMEDI_SUBD_SSI 13 /* Synchronous serial interface */ +#define COMEDI_SUBD_TOR 14 /* Tor counter */ +#define COMEDI_SUBD_CHRONO 15 /* Chrono meter */ +#define COMEDI_SUBD_PULSEENCODER 16 /* Pulse Encoder INP CPT */ +#define COMEDI_SUBD_INCREMENTALCOUNTER 17 /* Incremental Counter */ + +#define INT int +#define UINT unsigned int +#define BYTE unsigned char +#define CHAR char +#define LONG long +#define ULONG unsigned long +#define VOID void +#define PINT int * +#define PUINT unsigned int * +#define PBYTE unsigned char * +#define PCHAR char * +#define PLONG long * +#define PULONG unsigned long * +#define DWORD unsigned long +#define WORD unsigned short + +#define APCI1710_BOARD_NAME "apci1710" +#define APCI1710_BOARD_VENDOR_ID 0x10E8 +#define APCI1710_BOARD_DEVICE_ID 0x818F +#define APCI1710_ADDRESS_RANGE 256 +#define APCI1710_CONFIG_ADDRESS_RANGE 8 +#define APCI1710_INCREMENTAL_COUNTER 0x53430000UL +#define APCI1710_SSI_COUNTER 0x53490000UL +#define APCI1710_TTL_IO 0x544C0000UL +#define APCI1710_DIGITAL_IO 0x44490000UL +#define APCI1710_82X54_TIMER 0x49430000UL +#define APCI1710_CHRONOMETER 0x43480000UL +#define APCI1710_PULSE_ENCODER 0x495A0000UL +#define APCI1710_TOR_COUNTER 0x544F0000UL +#define APCI1710_PWM 0x50570000UL +#define APCI1710_ETM 0x45540000UL +#define APCI1710_CDA 0x43440000UL +#define APCI1710_DISABLE 0 +#define APCI1710_ENABLE 1 +#define APCI1710_SYNCHRONOUS_MODE 1 +#define APCI1710_ASYNCHRONOUS_MODE 0 //MODULE INFO STRUCTURE - -comedi_lrange range_apci1710_ttl={ 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1) +comedi_lrange range_apci1710_ttl = { 4, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1) } }; - - -comedi_lrange range_apci1710_ssi={ 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1) +comedi_lrange range_apci1710_ssi = { 4, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1) } }; -comedi_lrange range_apci1710_inccpt={ 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1) +comedi_lrange range_apci1710_inccpt = { 4, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1) } }; diff --git a/comedi/drivers/addi-data/hwdrv_apci035.c b/comedi/drivers/addi-data/hwdrv_apci035.c index 8952f3bf..a5e9a0b8 100644 --- a/comedi/drivers/addi-data/hwdrv_apci035.c +++ b/comedi/drivers/addi-data/hwdrv_apci035.c @@ -52,9 +52,9 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ #include "hwdrv_apci035.h" -INT i_WatchdogNbr=0; -INT i_Temp=0; -INT i_Flag=1; +INT i_WatchdogNbr = 0; +INT i_Temp = 0; +INT i_Flag = 1; /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI035_ConfigTimerWatchdog | @@ -109,159 +109,148 @@ INT i_Flag=1; | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_ConfigTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI035_ConfigTimerWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Status=0; -UINT ui_Command=0; -UINT ui_Mode=0; -i_Temp=0; -devpriv->tsk_Current=current; -devpriv->b_TimerSelectMode=data[0]; -i_WatchdogNbr=data[1]; -if(data[0]==0) - { - ui_Mode=2; - } -else - { - ui_Mode=0; - } + UINT ui_Status = 0; + UINT ui_Command = 0; + UINT ui_Mode = 0; + i_Temp = 0; + devpriv->tsk_Current = current; + devpriv->b_TimerSelectMode = data[0]; + i_WatchdogNbr = data[1]; + if (data[0] == 0) { + ui_Mode = 2; + } else { + ui_Mode = 0; + } //ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -ui_Command=0; + ui_Command = 0; //ui_Command = ui_Command & 0xFFFFF9FEUL; -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -ui_Command=0; -ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /************************/ /* Set the reload value */ /************************/ -outl( data[3],devpriv->iobase+((i_WatchdogNbr-1)*32) + 4); + outl(data[3], devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 4); /*********************/ /* Set the time unit */ -/*********************/ -outl(data[2],devpriv->iobase+((i_WatchdogNbr-1)*32) + 8); -if (data[0] == ADDIDATA_TIMER) - { - - - /******************************/ - /* Set the mode : */ - /* - Disable the hardware */ - /* - Disable the counter mode */ - /* - Disable the warning */ - /* - Disable the reset */ - /* - Enable the timer mode */ - /* - Set the timer mode */ - /******************************/ - - - ui_Command = (ui_Command & 0xFFF719E2UL) | ui_Mode << 13UL | 0x10UL; - - }//if (data[0] == ADDIDATA_TIMER) - else - { - if(data[0]==ADDIDATA_WATCHDOG) - { - - /******************************/ - /* Set the mode : */ - /* - Disable the hardware */ - /* - Disable the counter mode */ - /* - Disable the warning */ - /* - Disable the reset */ - /* - Disable the timer mode */ - /******************************/ - - - ui_Command = ui_Command & 0xFFF819E2UL; - - } - else - { - printk("\n The parameter for Timer/watchdog selection is in error\n"); - return -EINVAL; - } - } -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -ui_Command=0; -ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); +/*********************/ + outl(data[2], devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 8); + if (data[0] == ADDIDATA_TIMER) { + + /******************************/ + /* Set the mode : */ + /* - Disable the hardware */ + /* - Disable the counter mode */ + /* - Disable the warning */ + /* - Disable the reset */ + /* - Enable the timer mode */ + /* - Set the timer mode */ + /******************************/ + + ui_Command = + (ui_Command & 0xFFF719E2UL) | ui_Mode << 13UL | 0x10UL; + + } //if (data[0] == ADDIDATA_TIMER) + else { + if (data[0] == ADDIDATA_WATCHDOG) { + + /******************************/ + /* Set the mode : */ + /* - Disable the hardware */ + /* - Disable the counter mode */ + /* - Disable the warning */ + /* - Disable the reset */ + /* - Disable the timer mode */ + /******************************/ + + ui_Command = ui_Command & 0xFFF819E2UL; + + } else { + printk("\n The parameter for Timer/watchdog selection is in error\n"); + return -EINVAL; + } + } + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /********************************/ /* Disable the hardware trigger */ /********************************/ -ui_Command = ui_Command & 0xFFFFF89FUL; - if (data[4] == ADDIDATA_ENABLE) - { + ui_Command = ui_Command & 0xFFFFF89FUL; + if (data[4] == ADDIDATA_ENABLE) { + /**********************************/ + /* Set the hardware trigger level */ /**********************************/ - /* Set the hardware trigger level */ - /**********************************/ - ui_Command = ui_Command | ( data[5] << 5); - } -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -ui_Command=0; -ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + ui_Command = ui_Command | (data[5] << 5); + } + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /*****************************/ /* Disable the hardware gate */ -/*****************************/ -ui_Command = ui_Command & 0xFFFFF87FUL; -if (data[6] == ADDIDATA_ENABLE) - { +/*****************************/ + ui_Command = ui_Command & 0xFFFFF87FUL; + if (data[6] == ADDIDATA_ENABLE) { /*******************************/ /* Set the hardware gate level */ -/*******************************/ - ui_Command = ui_Command |( data[7] << 7); - } -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -ui_Command=0; -ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); +/*******************************/ + ui_Command = ui_Command | (data[7] << 7); + } + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /*******************************/ /* Disable the hardware output */ /*******************************/ -ui_Command = ui_Command & 0xFFFFF9FBUL; + ui_Command = ui_Command & 0xFFFFF9FBUL; /*********************************/ /* Set the hardware output level */ /*********************************/ -ui_Command = ui_Command |( data[8] << 2); -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); -if(data[9]==ADDIDATA_ENABLE) - { + ui_Command = ui_Command | (data[8] << 2); + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + if (data[9] == ADDIDATA_ENABLE) { /************************/ - /* Set the reload value */ - /************************/ - outl (data[11],devpriv->iobase+((i_WatchdogNbr-1)*32) + 24); + /* Set the reload value */ + /************************/ + outl(data[11], + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 24); + /**********************/ + /* Set the time unite */ /**********************/ - /* Set the time unite */ - /**********************/ - outl(data[10],devpriv->iobase+((i_WatchdogNbr-1)*32)+ 28); - } + outl(data[10], + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 28); + } - ui_Command=0; - ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /*******************************/ - /* Disable the hardware output */ - /*******************************/ - ui_Command = ui_Command & 0xFFFFF9F7UL; + /* Disable the hardware output */ + /*******************************/ + ui_Command = ui_Command & 0xFFFFF9F7UL; /*********************************/ - /* Set the hardware output level */ + /* Set the hardware output level */ /*********************************/ - ui_Command = ui_Command |( data[12] << 3); - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + ui_Command = ui_Command | (data[12] << 3); + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /*************************************/ /** Enable the watchdog interrupt **/ - /*************************************/ -ui_Command=0; -ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + /*************************************/ + ui_Command = 0; + ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); /*******************************/ /* Set the interrupt selection */ /*******************************/ -ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16); + ui_Status = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 16); -ui_Command = (ui_Command & 0xFFFFF9FDUL) | ( data[13] << 1); -outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + ui_Command = (ui_Command & 0xFFFFF9FDUL) | (data[13] << 1); + outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); -return insn->n; + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI035_StartStopWriteTimerWatchdog | @@ -289,92 +278,90 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - UINT ui_Command = 0; - INT i_Count=0; - if (data[0]==1) - { - ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - /**********************/ - /* Start the hardware */ - /**********************/ - ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x1UL; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - } // if (data[0]==1) - if(data[0]==2) - { - ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - /***************************/ - /* Set the trigger command */ - /***************************/ - ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x200UL; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - } - - if (data[0]==0) //Stop The Watchdog - { - //Stop The Watchdog - ui_Command=0; - //ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - //ui_Command = ui_Command & 0xFFFFF9FEUL; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); - } // if (data[1]==0) - if(data[0]==3)//stop all Watchdogs - { - ui_Command=0; - for(i_Count=1;i_Count<=4;i_Count++) - { - if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - ui_Command=0x2UL; - } - else - { - ui_Command = 0x10UL; - } - i_WatchdogNbr=i_Count; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0); - } - - } - if(data[0]==4)//start all Watchdogs - { - ui_Command = 0; - for(i_Count=1;i_Count<=4;i_Count++) - { - if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - ui_Command = 0x1UL; - } - else - { - ui_Command = 0x8UL; - } - i_WatchdogNbr=i_Count; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0); - } - } - if(data[0]==5)//trigger all Watchdogs - { - ui_Command =0; - for(i_Count=1;i_Count<=4;i_Count++) - { - if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - ui_Command=0x4UL; - } - else - { - ui_Command = 0x20UL; - } - - i_WatchdogNbr=i_Count; - outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0); - } - i_Temp=1; - } - return insn->n; + UINT ui_Command = 0; + INT i_Count = 0; + if (data[0] == 1) { + ui_Command = + inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + /**********************/ + /* Start the hardware */ + /**********************/ + ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x1UL; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + } // if (data[0]==1) + if (data[0] == 2) { + ui_Command = + inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + /***************************/ + /* Set the trigger command */ + /***************************/ + ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x200UL; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + } + + if (data[0] == 0) //Stop The Watchdog + { + //Stop The Watchdog + ui_Command = 0; + //ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); + //ui_Command = ui_Command & 0xFFFFF9FEUL; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12); + } // if (data[1]==0) + if (data[0] == 3) //stop all Watchdogs + { + ui_Command = 0; + for (i_Count = 1; i_Count <= 4; i_Count++) { + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + ui_Command = 0x2UL; + } else { + ui_Command = 0x10UL; + } + i_WatchdogNbr = i_Count; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + + 0); + } + + } + if (data[0] == 4) //start all Watchdogs + { + ui_Command = 0; + for (i_Count = 1; i_Count <= 4; i_Count++) { + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + ui_Command = 0x1UL; + } else { + ui_Command = 0x8UL; + } + i_WatchdogNbr = i_Count; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + + 0); + } + } + if (data[0] == 5) //trigger all Watchdogs + { + ui_Command = 0; + for (i_Count = 1; i_Count <= 4; i_Count++) { + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + ui_Command = 0x4UL; + } else { + ui_Command = 0x20UL; + } + + i_WatchdogNbr = i_Count; + outl(ui_Command, + devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + + 0); + } + i_Temp = 1; + } + return insn->n; } /* @@ -404,38 +391,37 @@ INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI035_ReadTimerWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Status = 0; // Status register - i_WatchdogNbr=insn->unused[0]; - /******************/ - /* Get the status */ - /******************/ - ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16); + UINT ui_Status = 0; // Status register + i_WatchdogNbr = insn->unused[0]; + /******************/ + /* Get the status */ + /******************/ + ui_Status = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 16); /***********************************/ - /* Get the software trigger status */ + /* Get the software trigger status */ /***********************************/ - data[0] = ((ui_Status >> 1) & 1); + data[0] = ((ui_Status >> 1) & 1); /***********************************/ - /* Get the hardware trigger status */ + /* Get the hardware trigger status */ /***********************************/ - data[1] = ((ui_Status >> 2) & 1); + data[1] = ((ui_Status >> 2) & 1); + /*********************************/ + /* Get the software clear status */ /*********************************/ - /* Get the software clear status */ - /*********************************/ - data[2] = ((ui_Status >> 3) & 1); + data[2] = ((ui_Status >> 3) & 1); /***************************/ - /* Get the overflow status */ + /* Get the overflow status */ /***************************/ - data[3] = ((ui_Status >> 0) & 1); - if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - { - data[4]=inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 0); - - } // if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - - - return insn->n; + data[3] = ((ui_Status >> 0) & 1); + if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { + data[4] = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 0); + + } // if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) + + return insn->n; } /* @@ -461,20 +447,21 @@ UINT ui_Status = 0; // Status register | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI035_ConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -devpriv->tsk_Current=current; -outl(0x200 | 0, devpriv->iobase+128 + 0x4); -outl(0, devpriv->iobase+128 + 0); + devpriv->tsk_Current = current; + outl(0x200 | 0, devpriv->iobase + 128 + 0x4); + outl(0, devpriv->iobase + 128 + 0); /********************************/ /* Initialise the warning value */ /********************************/ -outl(0x300 | 0, devpriv->iobase+128 + 0x4); -outl((data[0] << 8), devpriv->iobase+128 + 0); -outl(0x200000UL , devpriv->iobase+128 + 12); + outl(0x300 | 0, devpriv->iobase + 128 + 0x4); + outl((data[0] << 8), devpriv->iobase + 128 + 0); + outl(0x200000UL, devpriv->iobase + 128 + 12); -return insn->n; -} + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -497,31 +484,26 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ -UINT ui_CommandRegister=0; +INT i_APCI035_ReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_CommandRegister = 0; /******************/ /* Set the start */ /******************/ -ui_CommandRegister =0x80000; + ui_CommandRegister = 0x80000; /******************************/ - /* Write the command register */ + /* Write the command register */ /******************************/ -outl(ui_CommandRegister, devpriv->iobase+128 + 8); - + outl(ui_CommandRegister, devpriv->iobase + 128 + 8); + /***************************************/ /* Read the digital value of the input */ /***************************************/ -data[0] = inl (devpriv->iobase+ 128 + 28); -return insn->n; + data[0] = inl(devpriv->iobase + 128 + 28); + return insn->n; } - - - - - - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI035_Reset(comedi_device *dev) | @@ -537,17 +519,16 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI035_Reset(comedi_device *dev) +INT i_APCI035_Reset(comedi_device * dev) { -INT i_Count=0; -for(i_Count=1;i_Count<=4;i_Count++) - { - i_WatchdogNbr=i_Count; - outl(0x0,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);//stop all timers - } -outl(0x0 , devpriv->iobase+128 + 12);//Disable the warning delay - - return 0; + INT i_Count = 0; + for (i_Count = 1; i_Count <= 4; i_Count++) { + i_WatchdogNbr = i_Count; + outl(0x0, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 0); //stop all timers + } + outl(0x0, devpriv->iobase + 128 + 12); //Disable the warning delay + + return 0; } /* @@ -567,61 +548,53 @@ outl(0x0 , devpriv->iobase+128 + 12);//Disable the warning delay | | +----------------------------------------------------------------------------+ */ -static void v_APCI035_Interrupt(int irq, void *d) -{ - comedi_device *dev = d; - UINT ui_StatusRegister1 = 0; - UINT ui_StatusRegister2=0; - UINT ui_ReadCommand =0; - UINT ui_ChannelNumber=0; - UINT ui_DigitalTemperature=0; - if(i_Temp==1) - { - i_WatchdogNbr=i_Flag; - i_Flag=i_Flag+1; - } +static void v_APCI035_Interrupt(int irq, void *d) +{ + comedi_device *dev = d; + UINT ui_StatusRegister1 = 0; + UINT ui_StatusRegister2 = 0; + UINT ui_ReadCommand = 0; + UINT ui_ChannelNumber = 0; + UINT ui_DigitalTemperature = 0; + if (i_Temp == 1) { + i_WatchdogNbr = i_Flag; + i_Flag = i_Flag + 1; + } /**************************************/ - /* Read the interrupt status register of temperature Warning */ + /* Read the interrupt status register of temperature Warning */ /**************************************/ - ui_StatusRegister1 = inl(devpriv->iobase+128 + 16); + ui_StatusRegister1 = inl(devpriv->iobase + 128 + 16); /**************************************/ - /* Read the interrupt status register for Watchdog/timer */ + /* Read the interrupt status register for Watchdog/timer */ /**************************************/ - - ui_StatusRegister2 = inl (devpriv->iobase+((i_WatchdogNbr-1)*32) + 20); - - if ((((ui_StatusRegister1 ) & 0x8) == 0x8))//Test if warning relay interrupt - { - /**********************************/ - /* Disable the temperature warning */ - /**********************************/ - ui_ReadCommand = inl (devpriv->iobase+128 + 12); - ui_ReadCommand = ui_ReadCommand & 0xFFDF0000UL; - outl(ui_ReadCommand , devpriv->iobase+128 + 12); + + ui_StatusRegister2 = + inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 20); + + if ((((ui_StatusRegister1) & 0x8) == 0x8)) //Test if warning relay interrupt + { + /**********************************/ + /* Disable the temperature warning */ + /**********************************/ + ui_ReadCommand = inl(devpriv->iobase + 128 + 12); + ui_ReadCommand = ui_ReadCommand & 0xFFDF0000UL; + outl(ui_ReadCommand, devpriv->iobase + 128 + 12); /***************************/ - /* Read the channel number */ - /***************************/ - ui_ChannelNumber = inl(devpriv->iobase+128 + 60); - /**************************************/ - /* Read the digital temperature value */ - /**************************************/ - ui_DigitalTemperature = inl(devpriv->iobase+128 + 60); - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - }//if (((ui_StatusRegister1 & 0x8) == 0x8)) - - else - { - if((ui_StatusRegister2 & 0x1) == 0x1) - { - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - } - }//else if (((ui_StatusRegister1 & 0x8) == 0x8)) - - -return; + /* Read the channel number */ + /***************************/ + ui_ChannelNumber = inl(devpriv->iobase + 128 + 60); + /**************************************/ + /* Read the digital temperature value */ + /**************************************/ + ui_DigitalTemperature = inl(devpriv->iobase + 128 + 60); + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } //if (((ui_StatusRegister1 & 0x8) == 0x8)) + + else { + if ((ui_StatusRegister2 & 0x1) == 0x1) { + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } + } //else if (((ui_StatusRegister1 & 0x8) == 0x8)) + + return; } - - - - - diff --git a/comedi/drivers/addi-data/hwdrv_apci035.h b/comedi/drivers/addi-data/hwdrv_apci035.h index 0b275ec2..52d9ca46 100644 --- a/comedi/drivers/addi-data/hwdrv_apci035.h +++ b/comedi/drivers/addi-data/hwdrv_apci035.h @@ -26,32 +26,29 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI035_ADDRESS_RANGE 255 INT i_TW_Number; -struct -{ - INT i_Gain ; - INT i_Polarity; - INT i_OffsetRange; - INT i_Coupling; - INT i_SingleDiff; - INT i_AutoCalibration; - UINT ui_ReloadValue; - UINT ui_TimeUnitReloadVal; - INT i_Interrupt; - INT i_ModuleSelection; -}Config_Parameters_Main; - - +struct { + INT i_Gain; + INT i_Polarity; + INT i_OffsetRange; + INT i_Coupling; + INT i_SingleDiff; + INT i_AutoCalibration; + UINT ui_ReloadValue; + UINT ui_TimeUnitReloadVal; + INT i_Interrupt; + INT i_ModuleSelection; +} Config_Parameters_Main; //ANALOG INPUT RANGE -comedi_lrange range_apci035_ai={ 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1) +comedi_lrange range_apci035_ai = { 8, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1) } }; @@ -98,7 +95,6 @@ comedi_lrange range_apci035_ai={ 8, { #define ADDIDATA_GREATER_THAN_TEST 0 #define ADDIDATA_LESS_THAN_TEST 1 - #define APCI035_MAXVOLT 2.5 #define ADDIDATA_UNIPOLAR 1 @@ -108,30 +104,26 @@ comedi_lrange range_apci035_ai={ 8, { #define ADDIDATA_ENABLE 1 #define ADDIDATA_DISABLE 0 - - - - - // Hardware Layer functions for Apci035 - - // TIMER // timer value is passed as u seconds -INT i_APCI035_ConfigTimerWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +INT i_APCI035_ConfigTimerWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +INT i_APCI035_ReadTimerWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //Temperature Related Defines (Analog Input Subdevice) -INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +INT i_APCI035_ConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI035_ReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //Interrupt -static void v_APCI035_Interrupt(int irq, void *d) ; +static void v_APCI035_Interrupt(int irq, void *d); //Reset functions -INT i_APCI035_Reset(comedi_device *dev); +INT i_APCI035_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci1032.c b/comedi/drivers/addi-data/hwdrv_apci1032.c index 021bd552..d011a919 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1032.c +++ b/comedi/drivers/addi-data/hwdrv_apci1032.c @@ -54,7 +54,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #include "hwdrv_apci1032.h" #include //Global variables - UINT ui_InterruptStatus=0 ; +UINT ui_InterruptStatus = 0; /* +----------------------------------------------------------------------------+ @@ -84,44 +84,45 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ -INT i_APCI1032_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1032_ConfigDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue; - - ULONG ul_Command1 = 0; - ULONG ul_Command2 = 0; - devpriv->tsk_Current=current; - + UINT ui_TmpValue; + + ULONG ul_Command1 = 0; + ULONG ul_Command2 = 0; + devpriv->tsk_Current = current; + /*******************************/ - /* Set the digital input logic */ + /* Set the digital input logic */ /*******************************/ - if ( data[0] == ADDIDATA_ENABLE) - { - ul_Command1 = ul_Command1 | data[2]; - ul_Command2 = ul_Command2 | data[3]; - outl (ul_Command1 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE1); - outl (ul_Command2 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE2); - if (data[1] == ADDIDATA_OR) - { - outl(0x4 ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - ui_TmpValue=inl(devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - }//if (data[1] == ADDIDATA_OR) - else - { - outl(0x6 ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - }//else if(data[1] == ADDIDATA_OR) - }// if( data[0] == ADDIDATA_ENABLE) - else - { - ul_Command1 = ul_Command1 & 0xFFFF0000; - ul_Command2 = ul_Command2 & 0xFFFF0000; - outl (ul_Command1 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE1); - outl (ul_Command2 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE2); - outl(0x0 ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - }//else if ( data[0] == ADDIDATA_ENABLE) - - - return insn->n; + if (data[0] == ADDIDATA_ENABLE) { + ul_Command1 = ul_Command1 | data[2]; + ul_Command2 = ul_Command2 | data[3]; + outl(ul_Command1, + devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1); + outl(ul_Command2, + devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2); + if (data[1] == ADDIDATA_OR) { + outl(0x4, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + ui_TmpValue = + inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + } //if (data[1] == ADDIDATA_OR) + else { + outl(0x6, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + } //else if(data[1] == ADDIDATA_OR) + } // if( data[0] == ADDIDATA_ENABLE) + else { + ul_Command1 = ul_Command1 & 0xFFFF0000; + ul_Command2 = ul_Command2 & 0xFFFF0000; + outl(ul_Command1, + devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1); + outl(ul_Command2, + devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2); + outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + } //else if ( data[0] == ADDIDATA_ENABLE) + + return insn->n; } /* @@ -143,24 +144,23 @@ INT i_APCI1032_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_ | | +----------------------------------------------------------------------------+ */ -INT i_APCI1032_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1032_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue=0; - UINT ui_Channel; - ui_Channel=CR_CHAN(insn->chanspec); - if (ui_Channel >= 0 && ui_Channel <=31) - { - ui_TmpValue=(UINT) inl(devpriv->iobase + APCI1032_DIGITAL_IP); - // since only 1 channel reqd to bring it to last bit it is rotated - // 8 +(chan - 1) times then ANDed with 1 for last bit. - *data = (ui_TmpValue >> ui_Channel)&0x1 ; - }//if(ui_Channel >= 0 && ui_Channel <=31) - else - { - //comedi_error(dev," \n chan spec wrong\n"); - return -EINVAL; // "sorry channel spec wrong " - }//else if(ui_Channel >= 0 && ui_Channel <=31) - return insn->n; + UINT ui_TmpValue = 0; + UINT ui_Channel; + ui_Channel = CR_CHAN(insn->chanspec); + if (ui_Channel >= 0 && ui_Channel <= 31) { + ui_TmpValue = (UINT) inl(devpriv->iobase + APCI1032_DIGITAL_IP); + // since only 1 channel reqd to bring it to last bit it is rotated + // 8 +(chan - 1) times then ANDed with 1 for last bit. + *data = (ui_TmpValue >> ui_Channel) & 0x1; + } //if(ui_Channel >= 0 && ui_Channel <=31) + else { + //comedi_error(dev," \n chan spec wrong\n"); + return -EINVAL; // "sorry channel spec wrong " + } //else if(ui_Channel >= 0 && ui_Channel <=31) + return insn->n; } /* @@ -183,45 +183,47 @@ INT i_APCI1032_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_i +----------------------------------------------------------------------------+ */ -INT i_APCI1032_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1032_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_PortValue=data[0]; - UINT ui_Mask=0; - UINT ui_NoOfChannels; - - ui_NoOfChannels=CR_CHAN(insn->chanspec); - if (data[1]==0) - { - *data=(UINT)inl(devpriv->iobase + APCI1032_DIGITAL_IP ); - switch (ui_NoOfChannels) - { - case 2:ui_Mask=3; - *data=(*data >>(2*ui_PortValue))&ui_Mask; - break; - case 4:ui_Mask=15; - *data=(*data >>(4*ui_PortValue))&ui_Mask; - break; - case 8:ui_Mask=255; - *data=(*data >>(8*ui_PortValue))&ui_Mask; - break; - case 16:ui_Mask=65535; - *data=(*data >>(16*ui_PortValue))&ui_Mask; - break; - case 31: break; - default: - //comedi_error(dev," \nchan spec wrong\n"); - return -EINVAL; // "sorry channel spec wrong " - break; - }//switch(ui_NoOfChannels) - }//if(data[1]==0) - else - { - if (data[1]==1) - { - *data=ui_InterruptStatus; - }//if(data[1]==1) - }//else if(data[1]==0) - return insn->n; + UINT ui_PortValue = data[0]; + UINT ui_Mask = 0; + UINT ui_NoOfChannels; + + ui_NoOfChannels = CR_CHAN(insn->chanspec); + if (data[1] == 0) { + *data = (UINT) inl(devpriv->iobase + APCI1032_DIGITAL_IP); + switch (ui_NoOfChannels) { + case 2: + ui_Mask = 3; + *data = (*data >> (2 * ui_PortValue)) & ui_Mask; + break; + case 4: + ui_Mask = 15; + *data = (*data >> (4 * ui_PortValue)) & ui_Mask; + break; + case 8: + ui_Mask = 255; + *data = (*data >> (8 * ui_PortValue)) & ui_Mask; + break; + case 16: + ui_Mask = 65535; + *data = (*data >> (16 * ui_PortValue)) & ui_Mask; + break; + case 31: + break; + default: + //comedi_error(dev," \nchan spec wrong\n"); + return -EINVAL; // "sorry channel spec wrong " + break; + } //switch(ui_NoOfChannels) + } //if(data[1]==0) + else { + if (data[1] == 1) { + *data = ui_InterruptStatus; + } //if(data[1]==1) + } //else if(data[1]==0) + return insn->n; } /* @@ -241,21 +243,23 @@ INT i_APCI1032_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comed | | +----------------------------------------------------------------------------+ */ -static VOID v_APCI1032_Interrupt(int irq,void* d) +static VOID v_APCI1032_Interrupt(int irq, void *d) { - comedi_device *dev =d; - - UINT ui_Temp; - //disable the interrupt - ui_Temp=inl(devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - outl(ui_Temp& APCI1032_DIGITAL_IP_INTERRUPT_DISABLE ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ); - ui_InterruptStatus=inl(devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_STATUS); - ui_InterruptStatus=ui_InterruptStatus & 0X0000FFFF; - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - outl(ui_Temp ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ);//enable the interrupt -return; -} - + comedi_device *dev = d; + + UINT ui_Temp; + //disable the interrupt + ui_Temp = inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + outl(ui_Temp & APCI1032_DIGITAL_IP_INTERRUPT_DISABLE, + devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); + ui_InterruptStatus = + inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS); + ui_InterruptStatus = ui_InterruptStatus & 0X0000FFFF; + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + outl(ui_Temp, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); //enable the interrupt + return; +} + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1032_Reset(comedi_device *dev) | | @@ -270,22 +274,12 @@ return; | | +----------------------------------------------------------------------------+ */ - -INT i_APCI1032_Reset(comedi_device *dev) -{ - outl(0x0 ,devpriv->iobase+APCI1032_DIGITAL_IP_IRQ);//disable the interrupts - inl(devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_STATUS);//Reset the interrupt status register - outl (0x0 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE1);//Disable the and/or interrupt - outl (0x0 , devpriv->iobase+APCI1032_DIGITAL_IP_INTERRUPT_MODE2); - return 0; -} - - - - - - - - - +INT i_APCI1032_Reset(comedi_device * dev) +{ + outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); //disable the interrupts + inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS); //Reset the interrupt status register + outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1); //Disable the and/or interrupt + outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2); + return 0; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci1032.h b/comedi/drivers/addi-data/hwdrv_apci1032.h index fd8cd587..cd4c518f 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1032.h +++ b/comedi/drivers/addi-data/hwdrv_apci1032.h @@ -28,7 +28,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1032_ADDRESS_RANGE 20 //DIGITAL INPUT DEFINE -#define APCI1032_DIGITAL_IP 0 +#define APCI1032_DIGITAL_IP 0 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE1 4 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE2 8 #define APCI1032_DIGITAL_IP_IRQ 16 @@ -40,42 +40,31 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc //Digital Input Interrupt Status #define APCI1032_DIGITAL_IP_INTERRUPT_STATUS 12 - - //Digital Input Interrupt Enable Disable. -#define APCI1032_DIGITAL_IP_INTERRUPT_ENABLE 0x4 +#define APCI1032_DIGITAL_IP_INTERRUPT_ENABLE 0x4 #define APCI1032_DIGITAL_IP_INTERRUPT_DISABLE 0xFFFFFFFB - - //ADDIDATA Enable Disable #define ADDIDATA_ENABLE 1 #define ADDIDATA_DISABLE 0 - - - // Hardware Layer functions for Apci1032 - //DI // for di read -INT i_APCI1032_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - -INT i_APCI1032_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - -INT i_APCI1032_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - - - - +INT i_APCI1032_ConfigDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1032_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1032_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // Interrupt functions..... -static VOID v_APCI1032_Interrupt(int irq, void *d) ; +static VOID v_APCI1032_Interrupt(int irq, void *d); //Reset -INT i_APCI1032_Reset(comedi_device *dev); +INT i_APCI1032_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci1500.c b/comedi/drivers/addi-data/hwdrv_apci1500.c index a0819e35..5dbd9754 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1500.c +++ b/comedi/drivers/addi-data/hwdrv_apci1500.c @@ -47,17 +47,16 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "hwdrv_apci1500.h" -int i_TimerCounter1Init=0; -int i_TimerCounter2Init=0; -int i_WatchdogCounter3Init=0; -int i_Event1Status=0,i_Event2Status=0; -int i_TimerCounterWatchdogInterrupt=0; -int i_Logic=0,i_CounterLogic=0; -int i_InterruptMask=0; -int i_InputChannel=0; - int i_TimerCounter1Enabled=0, i_TimerCounter2Enabled=0,i_WatchdogCounter3Enabled=0; - - +int i_TimerCounter1Init = 0; +int i_TimerCounter2Init = 0; +int i_WatchdogCounter3Init = 0; +int i_Event1Status = 0, i_Event2Status = 0; +int i_TimerCounterWatchdogInterrupt = 0; +int i_Logic = 0, i_CounterLogic = 0; +int i_InterruptMask = 0; +int i_InputChannel = 0; +int i_TimerCounter1Enabled = 0, i_TimerCounter2Enabled = + 0, i_WatchdogCounter3Enabled = 0; /* +----------------------------------------------------------------------------+ @@ -138,291 +137,365 @@ int i_InputChannel=0; +----------------------------------------------------------------------------+ */ -INT i_APCI1500_ConfigDigitalInputEvent(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1500_ConfigDigitalInputEvent(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { -int i_PatternPolarity=0,i_PatternTransition=0,i_PatternMask=0; -int i_MaxChannel=0,i_Count=0,i_EventMask=0; -int i_PatternTransitionCount=0,i_RegValue; -int i; - + int i_PatternPolarity = 0, i_PatternTransition = 0, i_PatternMask = 0; + int i_MaxChannel = 0, i_Count = 0, i_EventMask = 0; + int i_PatternTransitionCount = 0, i_RegValue; + int i; + /*************************************************/ - /* Selects the master interrupt control register */ + /* Selects the master interrupt control register */ /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /**********************************************/ - /* Disables the main interrupt on the board */ - /**********************************************/ - outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - if (data[0] == 1) - { - i_MaxChannel = 8; - }// if (data[0] == 1) - else - { - if(data[0]==2) - { - i_MaxChannel = 6; - }// if(data[0]==2) - else - { - printk("\nThe specified port event does not exist\n"); - return -EINVAL; - }//else if(data[0]==2) - }//else if (data[0] == 1) -switch(data[1]) - { - case 0: data[1]= APCI1500_AND; - break; - case 1: data[1]= APCI1500_OR; - break; - case 2: data[1]= APCI1500_OR_PRIORITY; - break; - default:printk("\nThe specified interrupt logic does not exist\n"); - return -EINVAL; - }//switch(data[1]); - -i_Logic=data[1]; -for (i_Count = i_MaxChannel,i=0; i_Count >0;i_Count --,i++) - { - i_EventMask=data[2+i]; - switch(i_EventMask) - { - case 0 : i_PatternMask = i_PatternMask | (1 << (i_MaxChannel-i_Count)); - break; - case 1 : i_PatternMask = i_PatternMask | (1 << (i_MaxChannel-i_Count)); - i_PatternPolarity = i_PatternPolarity |(1 << (i_MaxChannel-i_Count)); - break; - case 2 : i_PatternMask = i_PatternMask |(1 << (i_MaxChannel-i_Count)); - i_PatternTransition = i_PatternTransition |(1 << (i_MaxChannel-i_Count)); - break; - case 3 : i_PatternMask = i_PatternMask | (1 << (i_MaxChannel-i_Count)); - i_PatternPolarity = i_PatternPolarity |(1 << (i_MaxChannel-i_Count)); - i_PatternTransition = i_PatternTransition |(1 << (i_MaxChannel-i_Count)); - break; - case 4 : i_PatternTransition = i_PatternTransition |(1 << (i_MaxChannel-i_Count)); - break; - case 5 : break; - default : printk("\nThe option indicated in the event mask does not exist\n"); - return -EINVAL; - }// switch(i_EventMask) - }//for (i_Count = i_MaxChannel; i_Count >0;i_Count --) - - if (data[0]== 1) - { + /* Disables the main interrupt on the board */ + /**********************************************/ + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + if (data[0] == 1) { + i_MaxChannel = 8; + } // if (data[0] == 1) + else { + if (data[0] == 2) { + i_MaxChannel = 6; + } // if(data[0]==2) + else { + printk("\nThe specified port event does not exist\n"); + return -EINVAL; + } //else if(data[0]==2) + } //else if (data[0] == 1) + switch (data[1]) { + case 0: + data[1] = APCI1500_AND; + break; + case 1: + data[1] = APCI1500_OR; + break; + case 2: + data[1] = APCI1500_OR_PRIORITY; + break; + default: + printk("\nThe specified interrupt logic does not exist\n"); + return -EINVAL; + } //switch(data[1]); + + i_Logic = data[1]; + for (i_Count = i_MaxChannel, i = 0; i_Count > 0; i_Count--, i++) { + i_EventMask = data[2 + i]; + switch (i_EventMask) { + case 0: + i_PatternMask = + i_PatternMask | (1 << (i_MaxChannel - i_Count)); + break; + case 1: + i_PatternMask = + i_PatternMask | (1 << (i_MaxChannel - i_Count)); + i_PatternPolarity = + i_PatternPolarity | (1 << (i_MaxChannel - + i_Count)); + break; + case 2: + i_PatternMask = + i_PatternMask | (1 << (i_MaxChannel - i_Count)); + i_PatternTransition = + i_PatternTransition | (1 << (i_MaxChannel - + i_Count)); + break; + case 3: + i_PatternMask = + i_PatternMask | (1 << (i_MaxChannel - i_Count)); + i_PatternPolarity = + i_PatternPolarity | (1 << (i_MaxChannel - + i_Count)); + i_PatternTransition = + i_PatternTransition | (1 << (i_MaxChannel - + i_Count)); + break; + case 4: + i_PatternTransition = + i_PatternTransition | (1 << (i_MaxChannel - + i_Count)); + break; + case 5: + break; + default: + printk("\nThe option indicated in the event mask does not exist\n"); + return -EINVAL; + } // switch(i_EventMask) + } //for (i_Count = i_MaxChannel; i_Count >0;i_Count --) + + if (data[0] == 1) { /****************************/ - /* Test the interrupt logic */ + /* Test the interrupt logic */ /****************************/ - if (data[1] == APCI1500_AND || - data[1] == APCI1500_OR || - data[1] == APCI1500_OR_PRIORITY) - { + if (data[1] == APCI1500_AND || + data[1] == APCI1500_OR || + data[1] == APCI1500_OR_PRIORITY) { /**************************************/ - /* Tests if a transition was declared */ - /* for a OR PRIORITY logic */ + /* Tests if a transition was declared */ + /* for a OR PRIORITY logic */ /**************************************/ - if (data[1]== APCI1500_OR_PRIORITY && i_PatternTransition != 0) - { + if (data[1] == APCI1500_OR_PRIORITY + && i_PatternTransition != 0) { /********************************************/ - /* Transition error on an OR PRIORITY logic */ + /* Transition error on an OR PRIORITY logic */ /********************************************/ - printk("\nTransition error on an OR PRIORITY logic\n"); - return -EINVAL; - }// if (data[1]== APCI1500_OR_PRIORITY && i_PatternTransition != 0) - - + printk("\nTransition error on an OR PRIORITY logic\n"); + return -EINVAL; + } // if (data[1]== APCI1500_OR_PRIORITY && i_PatternTransition != 0) /*************************************/ - /* Tests if more than one transition */ - /* was declared for an AND logic */ + /* Tests if more than one transition */ + /* was declared for an AND logic */ /*************************************/ - if (data[1]== APCI1500_AND) - { - for (i_Count = 0; i_Count < 8; i_Count++) - { - i_PatternTransitionCount=i_PatternTransitionCount+((i_PatternTransition>>i_Count)&0x1); - - } //for (i_Count = 0; i_Count < 8; i_Count++) - - if (i_PatternTransitionCount > 1) - { - /****************************************/ - /* Transition error on an AND logic */ - /****************************************/ - printk("\n Transition error on an AND logic\n"); - return -EINVAL; - }// if (i_PatternTransitionCount > 1) - }// if (data[1]== APCI1500_AND) - + if (data[1] == APCI1500_AND) { + for (i_Count = 0; i_Count < 8; i_Count++) { + i_PatternTransitionCount = + i_PatternTransitionCount + + ((i_PatternTransition >> + i_Count) & 0x1); + + } //for (i_Count = 0; i_Count < 8; i_Count++) + + if (i_PatternTransitionCount > 1) { + /****************************************/ + /* Transition error on an AND logic */ + /****************************************/ + printk("\n Transition error on an AND logic\n"); + return -EINVAL; + } // if (i_PatternTransitionCount > 1) + } // if (data[1]== APCI1500_AND) + /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port A */ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port A */ /******************/ - outb(0xF0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Selects the polarity register of port 1 */ - /**********************************************/ - outb(APCI1500_RW_PORT_A_PATTERN_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_PatternPolarity,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*********************************************/ - /* Selects the pattern mask register of */ - /* port 1 */ + outb(0xF0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Selects the polarity register of port 1 */ + /**********************************************/ + outb(APCI1500_RW_PORT_A_PATTERN_POLARITY, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternPolarity, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*********************************************/ + /* Selects the pattern mask register of */ + /* port 1 */ /*********************************************/ - outb(APCI1500_RW_PORT_A_PATTERN_MASK,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_PatternMask,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /********************************************/ - /* Selects the pattern transition register */ - /* of port 1 */ + outb(APCI1500_RW_PORT_A_PATTERN_MASK, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternMask, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /********************************************/ + /* Selects the pattern transition register */ + /* of port 1 */ /********************************************/ - outb(APCI1500_RW_PORT_A_PATTERN_TRANSITION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_PatternTransition,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /******************************************/ - /* Selects the mode specification mask */ - /* register of port 1 */ + outb(APCI1500_RW_PORT_A_PATTERN_TRANSITION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternTransition, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /******************************************/ + /* Selects the mode specification mask */ + /* register of port 1 */ /******************************************/ - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /******************************************/ - /* Selects the mode specification mask */ - /* register of port 1 */ + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /******************************************/ + /* Selects the mode specification mask */ + /* register of port 1 */ /******************************************/ - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**********************/ - /* Port A new mode */ - /**********************/ - - i_RegValue=(i_RegValue & 0xF9) | data[1]|0x9; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - i_Event1Status=1; - - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**********************/ + /* Port A new mode */ + /**********************/ + + i_RegValue = (i_RegValue & 0xF9) | data[1] | 0x9; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + i_Event1Status = 1; + + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port A */ + + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port A */ /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); - }// if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) - else - { - printk("\nThe choice for interrupt logic does not exist\n"); - return -EINVAL; - }// else }// if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) - }// if (data[0]== 1) + } // if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) + else { + printk("\nThe choice for interrupt logic does not exist\n"); + return -EINVAL; + } // else }// if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) + } // if (data[0]== 1) - /************************************/ - /* Test if event setting for port 2 */ + /* Test if event setting for port 2 */ /************************************/ - if (data[0] == 2) - { + if (data[0] == 2) { /************************/ - /* Test the event logic */ + /* Test the event logic */ /************************/ - if (data[1] == APCI1500_OR) - { - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ - /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port B */ - /******************/ - outb(0x74,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /****************************************/ - /* Selects the mode specification mask */ - /* register of port B */ - /****************************************/ - outb( APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - + if (data[1] == APCI1500_OR) { + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port B */ + /******************/ + outb(0x74, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /****************************************/ + /* Selects the mode specification mask */ + /* register of port B */ + /****************************************/ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************/ - /* Selects the mode specification mask */ - /* register of port B */ + /* Selects the mode specification mask */ + /* register of port B */ /******************************************/ - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=i_RegValue & 0xF9; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = i_RegValue & 0xF9; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************/ - /* Selects error channels 1 and 2 */ + /* Selects error channels 1 and 2 */ /**********************************/ - - i_PatternMask = (i_PatternMask | 0xC0); - i_PatternPolarity = (i_PatternPolarity | 0xC0); - i_PatternTransition = (i_PatternTransition | 0xC0); - /**********************************************/ - /* Selects the polarity register of port 2 */ + i_PatternMask = (i_PatternMask | 0xC0); + i_PatternPolarity = (i_PatternPolarity | 0xC0); + i_PatternTransition = (i_PatternTransition | 0xC0); + + /**********************************************/ + /* Selects the polarity register of port 2 */ + /**********************************************/ + outb(APCI1500_RW_PORT_B_PATTERN_POLARITY, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternPolarity, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /**********************************************/ - outb(APCI1500_RW_PORT_B_PATTERN_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb( i_PatternPolarity,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Selects the pattern transition register */ - /* of port 2 */ - /**********************************************/ - outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_PatternTransition,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Selects the pattern Mask register */ - /* of port 2 */ + /* Selects the pattern transition register */ + /* of port 2 */ + /**********************************************/ + outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternTransition, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Selects the pattern Mask register */ + /* of port 2 */ /**********************************************/ - outb(APCI1500_RW_PORT_B_PATTERN_MASK,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_PatternMask,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_B_PATTERN_MASK, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_PatternMask, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); - /******************************************/ - /* Selects the mode specification mask */ - /* register of port 2 */ /******************************************/ - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************/ - /* Selects the mode specification mask */ - /* register of port 2 */ + /* Selects the mode specification mask */ + /* register of port 2 */ + /******************************************/ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************/ + /* Selects the mode specification mask */ + /* register of port 2 */ /******************************************/ - outb( APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=(i_RegValue & 0xF9) | 4; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - i_Event2Status=1; - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = (i_RegValue & 0xF9) | 4; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + i_Event2Status = 1; /*****************************************************************/ - - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port B */ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port B */ /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }// if (data[1] == APCI1500_OR) - else - { - printk("\nThe choice for interrupt logic does not exist\n"); - return -EINVAL; - }//elseif (data[1] == APCI1500_OR) - }//if(data[0]==2) - - return insn->n; -} + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } // if (data[1] == APCI1500_OR) + else { + printk("\nThe choice for interrupt logic does not exist\n"); + return -EINVAL; + } //elseif (data[1] == APCI1500_OR) + } //if(data[0]==2) + + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -446,232 +519,250 @@ for (i_Count = i_MaxChannel,i=0; i_Count >0;i_Count --,i++) | | +----------------------------------------------------------------------------+ */ -int i_APCI1500_StartStopInputEvent(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_StartStopInputEvent(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -int i_Event1InterruptStatus=0,i_Event2InterruptStatus=0,i_RegValue; -switch(data[0]) - { - case START : - /*************************/ - /* Tests the port number */ + int i_Event1InterruptStatus = 0, i_Event2InterruptStatus = + 0, i_RegValue; + switch (data[0]) { + case START: + /*************************/ + /* Tests the port number */ /*************************/ - - if (data[1] == 1 || data[1] == 2) - { - /***************************/ - /* Test if port 1 selected */ - /***************************/ - - if ( data[1] == 1) - { + + if (data[1] == 1 || data[1] == 2) { + /***************************/ + /* Test if port 1 selected */ + /***************************/ + + if (data[1] == 1) { /*****************************/ - /* Test if event initialised */ + /* Test if event initialised */ /*****************************/ - if(i_Event1Status==1) - { - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + if (i_Event1Status == 1) { /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port A */ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port A */ /******************/ - outb(0xF0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0xF0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /***************************************************/ - /* Selects the command and status register of */ - /* port 1 */ + /* Selects the command and status register of */ + /* port 1 */ /***************************************************/ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************/ - /* Allows the pattern interrupt */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*************************************/ + /* Allows the pattern interrupt */ /*************************************/ - outb(0xC0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + outb(0xC0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port A */ - /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_Event1InterruptStatus=1; - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the master interrupt control register */ - /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Authorizes the main interrupt on the board */ - /**********************************************/ - outb(0xD0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - }// if(i_Event1Status==1) - else - { - printk("\nEvent 1 not initialised\n"); - return -EINVAL; - }//else if(i_Event1Status==1) - }//if (data[1]==1) - if(data[1]==2) - { - - if(i_Event2Status==1) - { - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ - /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port B */ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port A */ + /*****************/ + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_Event1InterruptStatus = 1; + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the master interrupt control register */ + /*************************************************/ + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Authorizes the main interrupt on the board */ + /**********************************************/ + outb(0xD0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + } // if(i_Event1Status==1) + else { + printk("\nEvent 1 not initialised\n"); + return -EINVAL; + } //else if(i_Event1Status==1) + } //if (data[1]==1) + if (data[1] == 2) { + + if (i_Event2Status == 1) { + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port B */ /******************/ - outb(0x74,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0x74, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /***************************************************/ - /* Selects the command and status register of */ - /* port 2 */ + /* Selects the command and status register of */ + /* port 2 */ /***************************************************/ - outb( APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************/ - /* Allows the pattern interrupt */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*************************************/ - outb(0xC0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /* Allows the pattern interrupt */ + /*************************************/ + outb(0xC0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port B */ - /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the master interrupt control register */ - /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Authorizes the main interrupt on the board */ - /**********************************************/ - outb(0xD0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_Event2InterruptStatus=1; - }// if(i_Event2Status==1) - else - { - printk("\nEvent 2 not initialised\n"); - return -EINVAL; - }//else if(i_Event2Status==1) - }// if(data[1]==2) - }// if (data[1] == 1 || data[0] == 2) - else - { - printk("\nThe port parameter is in error\n"); - return -EINVAL; - }//else if (data[1] == 1 || data[0] == 2) - - break; - - case STOP : - /*************************/ - /* Tests the port number */ - /*************************/ - - if (data[1] == 1 || data[1] == 2) - { - /***************************/ - /* Test if port 1 selected */ - /***************************/ - - if ( data[1] == 1) - { + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port B */ + /*****************/ + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the master interrupt control register */ + /*************************************************/ + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Authorizes the main interrupt on the board */ + /**********************************************/ + outb(0xD0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_Event2InterruptStatus = 1; + } // if(i_Event2Status==1) + else { + printk("\nEvent 2 not initialised\n"); + return -EINVAL; + } //else if(i_Event2Status==1) + } // if(data[1]==2) + } // if (data[1] == 1 || data[0] == 2) + else { + printk("\nThe port parameter is in error\n"); + return -EINVAL; + } //else if (data[1] == 1 || data[0] == 2) + + break; + + case STOP: + /*************************/ + /* Tests the port number */ + /*************************/ + + if (data[1] == 1 || data[1] == 2) { + /***************************/ + /* Test if port 1 selected */ + /***************************/ + + if (data[1] == 1) { /*****************************/ - /* Test if event initialised */ + /* Test if event initialised */ /*****************************/ - if(i_Event1Status==1) - { - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + if (i_Event1Status == 1) { + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port A */ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port A */ /******************/ - outb(0xF0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0xF0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /***************************************************/ - /* Selects the command and status register of */ - /* port 1 */ + /* Selects the command and status register of */ + /* port 1 */ /***************************************************/ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************/ - /* Inhibits the pattern interrupt */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*************************************/ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /* Inhibits the pattern interrupt */ + /*************************************/ + outb(0xE0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port A */ - /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_Event1InterruptStatus=0; - }// if(i_Event1Status==1) - else - { - printk("\nEvent 1 not initialised\n"); - return -EINVAL; - }//else if(i_Event1Status==1) - }//if (data[1]==1) - if(data[1]==2) - { - /*****************************/ - /* Test if event initialised */ - /*****************************/ - if(i_Event2Status==1) - { - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ - /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************/ - /* Disable Port B */ - /******************/ - outb(0x74,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***************************************************/ - /* Selects the command and status register of */ - /* port 2 */ - /***************************************************/ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************/ - /* Inhibits the pattern interrupt */ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port A */ + /*****************/ + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_Event1InterruptStatus = 0; + } // if(i_Event1Status==1) + else { + printk("\nEvent 1 not initialised\n"); + return -EINVAL; + } //else if(i_Event1Status==1) + } //if (data[1]==1) + if (data[1] == 2) { + /*****************************/ + /* Test if event initialised */ + /*****************************/ + if (i_Event2Status == 1) { + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /*****************************************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************/ + /* Disable Port B */ + /******************/ + outb(0x74, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***************************************************/ + /* Selects the command and status register of */ + /* port 2 */ + /***************************************************/ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*************************************/ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************************/ - /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ + /* Inhibits the pattern interrupt */ + /*************************************/ + outb(0xE0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************************/ + /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */ /*****************************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************/ - /* Enable Port B */ - /*****************/ - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_Event2InterruptStatus=0; - }// if(i_Event2Status==1) - else - { - printk("\nEvent 2 not initialised\n"); - return -EINVAL; - }//else if(i_Event2Status==1) - }//if(data[1]==2) - - }// if (data[1] == 1 || data[1] == 2) - else - { - printk("\nThe port parameter is in error\n"); - return -EINVAL; - }//else if (data[1] == 1 || data[1] == 2) - break; - default :printk("\nThe option of START/STOP logic does not exist\n"); - return -EINVAL; - }//switch(data[0]) - -return insn->n; + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************/ + /* Enable Port B */ + /*****************/ + outb(0xF4, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_Event2InterruptStatus = 0; + } // if(i_Event2Status==1) + else { + printk("\nEvent 2 not initialised\n"); + return -EINVAL; + } //else if(i_Event2Status==1) + } //if(data[1]==2) + + } // if (data[1] == 1 || data[1] == 2) + else { + printk("\nThe port parameter is in error\n"); + return -EINVAL; + } //else if (data[1] == 1 || data[1] == 2) + break; + default: + printk("\nThe option of START/STOP logic does not exist\n"); + return -EINVAL; + } //switch(data[0]) + + return insn->n; } /* @@ -693,130 +784,154 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI1500_Initialisation(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1500_Initialisation(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -int i_DummyRead=0; + int i_DummyRead = 0; /******************/ - /* Software reset */ + /* Software reset */ /******************/ - i_DummyRead=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_DummyRead=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(1,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - + i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(1, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************/ - /* Selects the master configuration control register */ + /* Selects the master configuration control register */ /*****************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the mode specification register of port A */ - /*****************************************************/ - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x10,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the data path polarity register of port A */ - outb( APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* High level of port A means 1 */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the data direction register of port A */ - outb(APCI1500_RW_PORT_A_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port A */ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port A */ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of port A: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the handshake specification register of port A */ - outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes the register */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the mode specification register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x10,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data path polarity register of port B */ - outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* A high level of port B means 1 */ - outb(0x7F,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data direction register of port B */ - outb(APCI1500_RW_PORT_B_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port B */ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port B */ - outb( APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of port B: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the handshake specification register of port B */ - outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes the register */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the data path polarity register of port C */ - /*****************************************************/ - outb( APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* High level of port C means 1 */ - outb(0x9,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data direction register of port C */ - outb(APCI1500_RW_PORT_C_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs except channel 1 */ - outb(0x0E,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the special IO register of port C */ - outb( APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes it */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 1 */ - /******************************************************/ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of timer 1 */ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of timer 1 */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 2 */ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0xF4, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the mode specification register of port A */ + /*****************************************************/ + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the data path polarity register of port A */ + outb(APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* High level of port A means 1 */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the data direction register of port A */ + outb(APCI1500_RW_PORT_A_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port A */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port A */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of port A: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the handshake specification register of port A */ + outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes the register */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the mode specification register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data path polarity register of port B */ + outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* A high level of port B means 1 */ + outb(0x7F, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data direction register of port B */ + outb(APCI1500_RW_PORT_B_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port B */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port B */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of port B: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the handshake specification register of port B */ + outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes the register */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the data path polarity register of port C */ + /*****************************************************/ + outb(APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* High level of port C means 1 */ + outb(0x9, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data direction register of port C */ + outb(APCI1500_RW_PORT_C_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs except channel 1 */ + outb(0x0E, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the special IO register of port C */ + outb(APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes it */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************************/ + /* Selects the command and status register of timer 1 */ + /******************************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of timer 1 */ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of timer 1 */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /******************************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of timer 2 */ - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates Timer 2 interrupt management: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 3 */ + /* Selects the command and status register of timer 2 */ + /******************************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of timer 2 */ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates Timer 2 interrupt management: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************************/ + /* Selects the command and status register of timer 3 */ /******************************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of Timer 3 */ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates interrupt management of timer 3: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************************/ - /* Selects the master interrupt control register */ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of Timer 3 */ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates interrupt management of timer 3: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes all interrupts */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - return insn->n; + /* Selects the master interrupt control register */ + /*************************************************/ + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes all interrupts */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + return insn->n; } /* @@ -842,56 +957,59 @@ int i_DummyRead=0; +----------------------------------------------------------------------------+ */ -INT i_APCI1500_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1500_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_PortValue=data[1]; - UINT ui_Mask=0; - UINT ui_Channel; - UINT ui_TmpValue=0; - ui_Channel=CR_CHAN(insn->chanspec); - - - switch(data[0]) - { - case 0: - if (ui_Channel >= 0 && ui_Channel <=15) - { - ui_TmpValue=(UINT) inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP); - *data = (ui_TmpValue >> ui_Channel)&0x1 ; - }//if(ui_Channel >= 0 && ui_Channel <=15) - else - { - printk("\nThe channel specification are in error\n"); - return -EINVAL; // "sorry channel spec wrong " - }//else if(ui_Channel >= 0 && ui_Channel <=15) - break; - case 1: - - *data=(UINT)inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP ); - switch (ui_Channel) - { - case 2:ui_Mask=3; - *data=(*data >>(2*ui_PortValue))&ui_Mask; - break; - case 4:ui_Mask=15; - *data=(*data >>(4*ui_PortValue))&ui_Mask; - break; - case 8:ui_Mask=255; - *data=(*data >>(8*ui_PortValue))&ui_Mask; - break; - case 15: break; - - default: - printk("\nSpecified channel cannot be read \n"); - return -EINVAL; // "sorry channel spec wrong " - break; - }//switch(ui_Channel) - break; - default: - printk("\nThe specified functionality does not exist\n"); - return -EINVAL; - }//switch(data[0]) - return insn->n; + UINT ui_PortValue = data[1]; + UINT ui_Mask = 0; + UINT ui_Channel; + UINT ui_TmpValue = 0; + ui_Channel = CR_CHAN(insn->chanspec); + + switch (data[0]) { + case 0: + if (ui_Channel >= 0 && ui_Channel <= 15) { + ui_TmpValue = + (UINT) inw(devpriv->i_IobaseAddon + + APCI1500_DIGITAL_IP); + *data = (ui_TmpValue >> ui_Channel) & 0x1; + } //if(ui_Channel >= 0 && ui_Channel <=15) + else { + printk("\nThe channel specification are in error\n"); + return -EINVAL; // "sorry channel spec wrong " + } //else if(ui_Channel >= 0 && ui_Channel <=15) + break; + case 1: + + *data = (UINT) inw(devpriv->i_IobaseAddon + + APCI1500_DIGITAL_IP); + switch (ui_Channel) { + case 2: + ui_Mask = 3; + *data = (*data >> (2 * ui_PortValue)) & ui_Mask; + break; + case 4: + ui_Mask = 15; + *data = (*data >> (4 * ui_PortValue)) & ui_Mask; + break; + case 8: + ui_Mask = 255; + *data = (*data >> (8 * ui_PortValue)) & ui_Mask; + break; + case 15: + break; + + default: + printk("\nSpecified channel cannot be read \n"); + return -EINVAL; // "sorry channel spec wrong " + break; + } //switch(ui_Channel) + break; + default: + printk("\nThe specified functionality does not exist\n"); + return -EINVAL; + } //switch(data[0]) + return insn->n; } /* @@ -922,13 +1040,13 @@ INT i_APCI1500_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comed | | +----------------------------------------------------------------------------+ */ -int i_APCI1500_ConfigDigitalOutputErrorInterrupt(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_ConfigDigitalOutputErrorInterrupt(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { -devpriv->b_OutputMemoryStatus=data[0]; -return insn->n; + devpriv->b_OutputMemoryStatus = data[0]; + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1500_WriteDigitalOutput | @@ -949,130 +1067,149 @@ return insn->n; +----------------------------------------------------------------------------+ */ -INT i_APCI1500_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1500_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -static UINT ui_Temp=0; -UINT ui_Temp1; - -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - - if(!devpriv->b_OutputMemoryStatus ) - { - ui_Temp=0; - - }//if(!devpriv->b_OutputMemoryStatus ) -if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outw(data[0],devpriv->i_IobaseAddon+APCI1500_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - - - case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - - case 8: - data[0]=(data[0] <<(8*data[2]))|ui_Temp; - break; - - case 15:data[0]=data[0]|ui_Temp; - break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->i_IobaseAddon+APCI1500_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) -else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<i_IobaseAddon+APCI1500_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; - break; - - - case 4:data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xffffffff)&ui_Temp; - break; - - case 8:data[0]=~data[0]&0xff; - ui_Temp1=255; - ui_Temp1=ui_Temp1<<8*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (8*data[2]))^0xffffffff)&ui_Temp; - break; - - case 15:break; - - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->i_IobaseAddon+APCI1500_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - ui_Temp=data[0]; - return (insn->n);; + static UINT ui_Temp = 0; + UINT ui_Temp1; + + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + + if (!devpriv->b_OutputMemoryStatus) { + ui_Temp = 0; + + } //if(!devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outw(data[0], + devpriv->i_IobaseAddon + APCI1500_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + + case 8: + data[0] = + (data[0] << (8 * + data[2])) | ui_Temp; + break; + + case 15: + data[0] = data[0] | ui_Temp; + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->i_IobaseAddon + + APCI1500_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + (data[0] << ui_NoOfChannel) ^ + 0xffffffff; + data[0] = data[0] & ui_Temp; + outw(data[0], + devpriv->i_IobaseAddon + + APCI1500_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 8: + data[0] = ~data[0] & 0xff; + ui_Temp1 = 255; + ui_Temp1 = + ui_Temp1 << 8 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (8 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 15: + break; + + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->i_IobaseAddon + + APCI1500_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + ui_Temp = data[0]; + return (insn->n);; } /* @@ -1124,500 +1261,577 @@ else +----------------------------------------------------------------------------+ */ -int i_APCI1500_ConfigCounterTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_ConfigCounterTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { -int i_TimerCounterMode,i_MasterConfiguration; + int i_TimerCounterMode, i_MasterConfiguration; + + devpriv->tsk_Current = current; - devpriv->tsk_Current=current; - //Selection of the input clock -if(data[0]==0||data[0]==1||data[0]==2) - { - outw(data[0],devpriv->i_IobaseAddon+APCI1500_CLK_SELECT); - }// if(data[0]==0||data[0]==1||data[0]==2) -else - { - if(data[0]!=3) - { - printk("\nThe option for input clock selection does not exist\n"); - return -EINVAL; - }// if(data[0]!=3) - }//elseif(data[0]==0||data[0]==1||data[0]==2) - //Select the counter/timer -switch(data[1]) - { - case COUNTER1: - //selecting counter or timer - switch(data[2]) - { - case 0: data[2]=APCI1500_COUNTER ; - break; - case 1: data[2]=APCI1500_TIMER; - break; - default:printk("\nThis choice is not a timer nor a counter\n"); - return -EINVAL; - }// switch(data[2]) - - //Selecting single or continuous mode - switch(data[4]) - { - case 0: data[4]= APCI1500_CONTINUOUS; - break; - case 1: data[4]= APCI1500_SINGLE; - break; - default:printk("\nThis option for single/continuous mode does not exist\n"); - return -EINVAL; - }// switch(data[4]) - - - i_TimerCounterMode = data[2]|data[4]|7; - /*************************/ - /* Test the reload value */ - /*************************/ - - if ((data[3]>= 0) && (data[3] <= 65535)) - { - if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - { - - /************************************************/ - /* Selects the mode register of timer/counter 1 */ - /************************************************/ - outb(APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************/ - /* Writes the new mode */ - /***********************/ - outb(i_TimerCounterMode,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of timer/counter 1 */ - /****************************************************/ - - outb(APCI1500_RW_CPT_TMR1_TIME_CST_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*************************/ - /* Writes the low value */ - /*************************/ - - outb( data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of timer/counter 1 */ - /****************************************************/ - - outb( APCI1500_RW_CPT_TMR1_TIME_CST_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**************************/ - /* Writes the high value */ - /**************************/ - - data[3]=data[3]>>8; - outb(data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**********************/ - /* Reads the register */ - /**********************/ - - i_MasterConfiguration=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************************************/ - /* Enables timer/counter 1 and triggers timer/counter 1 */ - /********************************************************/ - - i_MasterConfiguration = i_MasterConfiguration | 0x40; - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************/ - /* Writes the new configuration */ - /********************************/ - outb(i_MasterConfiguration,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /****************************************/ - /* Selects the commands register of */ - /* timer/counter 1 */ - /****************************************/ - - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************/ - /* Disable timer/counter 1 */ - /***************************/ - - outb(0x0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /****************************************/ - /* Selects the commands register of */ - /* timer/counter 1 */ - /****************************************/ - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************/ - /* Trigger timer/counter 1 */ - /***************************/ - outb(0x2,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - else - { - printk("\nError in selection of interrupt enable or disable\n"); - return -EINVAL; - }//elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - }// if ((data[3]>= 0) && (data[3] <= 65535)) - else - { - printk("\nError in selection of reload value\n"); - return -EINVAL; - }//else if ((data[3]>= 0) && (data[3] <= 65535)) - i_TimerCounterWatchdogInterrupt=data[7]; - i_TimerCounter1Init=1; - break; - - - - case COUNTER2: //selecting counter or timer - switch(data[2]) - { - case 0: data[2]=APCI1500_COUNTER ; - break; - case 1: data[2]=APCI1500_TIMER; - break; - default:printk("\nThis choice is not a timer nor a counter\n"); - return -EINVAL; - }// switch(data[2]) - - //Selecting single or continuous mode - switch(data[4]) - { - case 0: data[4]= APCI1500_CONTINUOUS; - break; - case 1: data[4]= APCI1500_SINGLE; - break; - default:printk("\nThis option for single/continuous mode does not exist\n"); - return -EINVAL; - }// switch(data[4]) - - //Selecting software or hardware trigger - switch(data[5]) - { - case 0: data[5]= APCI1500_SOFTWARE_TRIGGER ; - break; - case 1: data[5]= APCI1500_HARDWARE_TRIGGER ; - break; - default:printk("\nThis choice for software or hardware trigger does not exist\n"); - return -EINVAL; - }// switch(data[5]) - - //Selecting software or hardware gate - switch(data[6]) - { - case 0: data[6]= APCI1500_SOFTWARE_GATE ; - break; - case 1: data[6]= APCI1500_HARDWARE_GATE ; - break; - default:printk("\nThis choice for software or hardware gate does not exist\n"); - return -EINVAL; - }// switch(data[6]) - - - i_TimerCounterMode=data[2]|data[4]|data[5]|data[6]|7; - - /*************************/ - /* Test the reload value */ - /*************************/ - - if ((data[3]>= 0) && (data[3] <= 65535)) - { - if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - { - - /************************************************/ - /* Selects the mode register of timer/counter 2 */ - /************************************************/ - outb( APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************/ - /* Writes the new mode */ - /***********************/ - outb(i_TimerCounterMode,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of timer/counter 2 */ - /****************************************************/ - - outb(APCI1500_RW_CPT_TMR2_TIME_CST_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*************************/ - /* Writes the low value */ - /*************************/ - - outb( data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of timer/counter 2 */ - /****************************************************/ - - outb(APCI1500_RW_CPT_TMR2_TIME_CST_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**************************/ - /* Writes the high value */ - /**************************/ - - data[3]=data[3]>>8; - outb(data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**********************/ - /* Reads the register */ - /**********************/ - - i_MasterConfiguration=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************************************/ - /* Enables timer/counter 2 and triggers timer/counter 2 */ - /********************************************************/ - - i_MasterConfiguration = i_MasterConfiguration | 0x20; - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************/ - /* Writes the new configuration */ - /********************************/ - outb(i_MasterConfiguration,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /****************************************/ - /* Selects the commands register of */ - /* timer/counter 2 */ - /****************************************/ - - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************/ - /* Disable timer/counter 2 */ - /***************************/ - - outb(0x0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /****************************************/ - /* Selects the commands register of */ - /* timer/counter 2 */ - /****************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************/ - /* Trigger timer/counter 1 */ - /***************************/ - outb(0x2,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - else - { - printk("\nError in selection of interrupt enable or disable\n"); - return -EINVAL; - }//elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - }// if ((data[3]>= 0) && (data[3] <= 65535)) - else - { - printk("\nError in selection of reload value\n"); - return -EINVAL; - }//else if ((data[3]>= 0) && (data[3] <= 65535)) - i_TimerCounterWatchdogInterrupt=data[7]; - i_TimerCounter2Init=1; - break; - - - - - case COUNTER3://selecting counter or watchdog - switch(data[2]) - { - case 0: data[2]=APCI1500_COUNTER ; - break; - case 1: data[2]= APCI1500_WATCHDOG; - break; - default:printk("\nThis choice is not a watchdog nor a counter\n"); - return -EINVAL; - }// switch(data[2]) - - //Selecting single or continuous mode - switch(data[4]) - { - case 0: data[4]= APCI1500_CONTINUOUS; - break; - case 1: data[4]= APCI1500_SINGLE; - break; - default:printk("\nThis option for single/continuous mode does not exist\n"); - return -EINVAL; - }// switch(data[4]) - - - - - //Selecting software or hardware gate - switch(data[6]) - { - case 0: data[6]= APCI1500_SOFTWARE_GATE ; - break; - case 1: data[6]= APCI1500_HARDWARE_GATE ; - break; - default:printk("\nThis choice for software or hardware gate does not exist\n"); - return -EINVAL; - }// switch(data[6]) - - - - /*****************************/ - /* Test if used for watchdog */ + if (data[0] == 0 || data[0] == 1 || data[0] == 2) { + outw(data[0], devpriv->i_IobaseAddon + APCI1500_CLK_SELECT); + } // if(data[0]==0||data[0]==1||data[0]==2) + else { + if (data[0] != 3) { + printk("\nThe option for input clock selection does not exist\n"); + return -EINVAL; + } // if(data[0]!=3) + } //elseif(data[0]==0||data[0]==1||data[0]==2) + //Select the counter/timer + switch (data[1]) { + case COUNTER1: + //selecting counter or timer + switch (data[2]) { + case 0: + data[2] = APCI1500_COUNTER; + break; + case 1: + data[2] = APCI1500_TIMER; + break; + default: + printk("\nThis choice is not a timer nor a counter\n"); + return -EINVAL; + } // switch(data[2]) + + //Selecting single or continuous mode + switch (data[4]) { + case 0: + data[4] = APCI1500_CONTINUOUS; + break; + case 1: + data[4] = APCI1500_SINGLE; + break; + default: + printk("\nThis option for single/continuous mode does not exist\n"); + return -EINVAL; + } // switch(data[4]) + + i_TimerCounterMode = data[2] | data[4] | 7; + /*************************/ + /* Test the reload value */ + /*************************/ + + if ((data[3] >= 0) && (data[3] <= 65535)) { + if (data[7] == APCI1500_ENABLE + || data[7] == APCI1500_DISABLE) { + + /************************************************/ + /* Selects the mode register of timer/counter 1 */ + /************************************************/ + outb(APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************/ + /* Writes the new mode */ + /***********************/ + outb(i_TimerCounterMode, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of timer/counter 1 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR1_TIME_CST_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*************************/ + /* Writes the low value */ + /*************************/ + + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of timer/counter 1 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR1_TIME_CST_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**************************/ + /* Writes the high value */ + /**************************/ + + data[3] = data[3] >> 8; + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**********************/ + /* Reads the register */ + /**********************/ + + i_MasterConfiguration = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************************************/ + /* Enables timer/counter 1 and triggers timer/counter 1 */ + /********************************************************/ + + i_MasterConfiguration = + i_MasterConfiguration | 0x40; + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************/ + /* Writes the new configuration */ + /********************************/ + outb(i_MasterConfiguration, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /****************************************/ + /* Selects the commands register of */ + /* timer/counter 1 */ + /****************************************/ + + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************/ + /* Disable timer/counter 1 */ + /***************************/ + + outb(0x0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /****************************************/ + /* Selects the commands register of */ + /* timer/counter 1 */ + /****************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************/ + /* Trigger timer/counter 1 */ + /***************************/ + outb(0x2, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + else { + printk("\nError in selection of interrupt enable or disable\n"); + return -EINVAL; + } //elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + } // if ((data[3]>= 0) && (data[3] <= 65535)) + else { + printk("\nError in selection of reload value\n"); + return -EINVAL; + } //else if ((data[3]>= 0) && (data[3] <= 65535)) + i_TimerCounterWatchdogInterrupt = data[7]; + i_TimerCounter1Init = 1; + break; + + case COUNTER2: //selecting counter or timer + switch (data[2]) { + case 0: + data[2] = APCI1500_COUNTER; + break; + case 1: + data[2] = APCI1500_TIMER; + break; + default: + printk("\nThis choice is not a timer nor a counter\n"); + return -EINVAL; + } // switch(data[2]) + + //Selecting single or continuous mode + switch (data[4]) { + case 0: + data[4] = APCI1500_CONTINUOUS; + break; + case 1: + data[4] = APCI1500_SINGLE; + break; + default: + printk("\nThis option for single/continuous mode does not exist\n"); + return -EINVAL; + } // switch(data[4]) + + //Selecting software or hardware trigger + switch (data[5]) { + case 0: + data[5] = APCI1500_SOFTWARE_TRIGGER; + break; + case 1: + data[5] = APCI1500_HARDWARE_TRIGGER; + break; + default: + printk("\nThis choice for software or hardware trigger does not exist\n"); + return -EINVAL; + } // switch(data[5]) + + //Selecting software or hardware gate + switch (data[6]) { + case 0: + data[6] = APCI1500_SOFTWARE_GATE; + break; + case 1: + data[6] = APCI1500_HARDWARE_GATE; + break; + default: + printk("\nThis choice for software or hardware gate does not exist\n"); + return -EINVAL; + } // switch(data[6]) + + i_TimerCounterMode = data[2] | data[4] | data[5] | data[6] | 7; + + /*************************/ + /* Test the reload value */ + /*************************/ + + if ((data[3] >= 0) && (data[3] <= 65535)) { + if (data[7] == APCI1500_ENABLE + || data[7] == APCI1500_DISABLE) { + + /************************************************/ + /* Selects the mode register of timer/counter 2 */ + /************************************************/ + outb(APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************/ + /* Writes the new mode */ + /***********************/ + outb(i_TimerCounterMode, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of timer/counter 2 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR2_TIME_CST_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*************************/ + /* Writes the low value */ + /*************************/ + + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of timer/counter 2 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR2_TIME_CST_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**************************/ + /* Writes the high value */ + /**************************/ + + data[3] = data[3] >> 8; + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**********************/ + /* Reads the register */ + /**********************/ + + i_MasterConfiguration = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************************************/ + /* Enables timer/counter 2 and triggers timer/counter 2 */ + /********************************************************/ + + i_MasterConfiguration = + i_MasterConfiguration | 0x20; + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************/ + /* Writes the new configuration */ + /********************************/ + outb(i_MasterConfiguration, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /****************************************/ + /* Selects the commands register of */ + /* timer/counter 2 */ + /****************************************/ + + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************/ + /* Disable timer/counter 2 */ + /***************************/ + + outb(0x0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /****************************************/ + /* Selects the commands register of */ + /* timer/counter 2 */ + /****************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************/ + /* Trigger timer/counter 1 */ + /***************************/ + outb(0x2, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + else { + printk("\nError in selection of interrupt enable or disable\n"); + return -EINVAL; + } //elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + } // if ((data[3]>= 0) && (data[3] <= 65535)) + else { + printk("\nError in selection of reload value\n"); + return -EINVAL; + } //else if ((data[3]>= 0) && (data[3] <= 65535)) + i_TimerCounterWatchdogInterrupt = data[7]; + i_TimerCounter2Init = 1; + break; + + case COUNTER3: //selecting counter or watchdog + switch (data[2]) { + case 0: + data[2] = APCI1500_COUNTER; + break; + case 1: + data[2] = APCI1500_WATCHDOG; + break; + default: + printk("\nThis choice is not a watchdog nor a counter\n"); + return -EINVAL; + } // switch(data[2]) + + //Selecting single or continuous mode + switch (data[4]) { + case 0: + data[4] = APCI1500_CONTINUOUS; + break; + case 1: + data[4] = APCI1500_SINGLE; + break; + default: + printk("\nThis option for single/continuous mode does not exist\n"); + return -EINVAL; + } // switch(data[4]) + + //Selecting software or hardware gate + switch (data[6]) { + case 0: + data[6] = APCI1500_SOFTWARE_GATE; + break; + case 1: + data[6] = APCI1500_HARDWARE_GATE; + break; + default: + printk("\nThis choice for software or hardware gate does not exist\n"); + return -EINVAL; + } // switch(data[6]) + + /*****************************/ + /* Test if used for watchdog */ /*****************************/ - if (data[2] == APCI1500_WATCHDOG) - { + if (data[2] == APCI1500_WATCHDOG) { /*****************************/ - /* - Enables the output line */ - /* - Enables retrigger */ - /* - Pulses output */ + /* - Enables the output line */ + /* - Enables retrigger */ + /* - Pulses output */ /*****************************/ - i_TimerCounterMode=data[2]|data[4]|0x54; - }//if (data[2] == APCI1500_WATCHDOG) - else - { - i_TimerCounterMode=data[2]|data[4]|data[6]|7; - }//elseif (data[2] == APCI1500_WATCHDOG) - /*************************/ - /* Test the reload value */ - /*************************/ - - if ((data[3]>= 0) && (data[3] <= 65535)) - { - if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - { - - /************************************************/ - /* Selects the mode register of watchdog/counter 3 */ - /************************************************/ - outb(APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************/ - /* Writes the new mode */ - /***********************/ - outb(i_TimerCounterMode,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of watchdog/counter 3 */ - /****************************************************/ - - outb(APCI1500_RW_CPT_TMR3_TIME_CST_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*************************/ - /* Writes the low value */ - /*************************/ - - outb( data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /****************************************************/ - /* Selects the constant register of watchdog/counter 3 */ - /****************************************************/ - - outb(APCI1500_RW_CPT_TMR3_TIME_CST_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**************************/ - /* Writes the high value */ - /**************************/ - - data[3]=data[3]>>8; - outb(data[3],devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /**********************/ - /* Reads the register */ - /**********************/ - - i_MasterConfiguration=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************************************/ - /* Enables watchdog/counter 3 and triggers watchdog/counter 3 */ - /********************************************************/ - - i_MasterConfiguration = i_MasterConfiguration | 0x10; - - /*********************************************/ - /* Selects the master configuration register */ - /*********************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************************/ - /* Writes the new configuration */ - /********************************/ - outb(i_MasterConfiguration,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /********************/ - /* Test if COUNTER */ - /********************/ - if(data[2]==APCI1500_COUNTER) - { - - /*************************************/ - /* Selects the command register of */ - /* watchdog/counter 3 */ - /*************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************************/ - /* Disable the watchdog/counter 3 and starts it */ - /*************************************************/ - outb(0x0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*************************************/ - /* Selects the command register of */ - /* watchdog/counter 3 */ - /*************************************/ - - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************************/ - /* Trigger the watchdog/counter 3 and starts it */ - /*************************************************/ - outb(0x2,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - }//elseif(data[2]==APCI1500_COUNTER) - - - }//if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - else - { - printk("\nError in selection of interrupt enable or disable\n"); - return -EINVAL; - }//elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) - }// if ((data[3]>= 0) && (data[3] <= 65535)) - else - { - printk("\nError in selection of reload value\n"); - return -EINVAL; - }//else if ((data[3]>= 0) && (data[3] <= 65535)) - i_TimerCounterWatchdogInterrupt=data[7]; - i_WatchdogCounter3Init=1; - break; - - default:printk("\nThe specified counter\timer option does not exist\n"); - }//switch(data[1]) -i_CounterLogic=data[2]; -return insn->n; + i_TimerCounterMode = data[2] | data[4] | 0x54; + } //if (data[2] == APCI1500_WATCHDOG) + else { + i_TimerCounterMode = data[2] | data[4] | data[6] | 7; + } //elseif (data[2] == APCI1500_WATCHDOG) + /*************************/ + /* Test the reload value */ + /*************************/ + + if ((data[3] >= 0) && (data[3] <= 65535)) { + if (data[7] == APCI1500_ENABLE + || data[7] == APCI1500_DISABLE) { + + /************************************************/ + /* Selects the mode register of watchdog/counter 3 */ + /************************************************/ + outb(APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************/ + /* Writes the new mode */ + /***********************/ + outb(i_TimerCounterMode, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of watchdog/counter 3 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR3_TIME_CST_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*************************/ + /* Writes the low value */ + /*************************/ + + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /****************************************************/ + /* Selects the constant register of watchdog/counter 3 */ + /****************************************************/ + + outb(APCI1500_RW_CPT_TMR3_TIME_CST_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**************************/ + /* Writes the high value */ + /**************************/ + + data[3] = data[3] >> 8; + outb(data[3], + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /**********************/ + /* Reads the register */ + /**********************/ + + i_MasterConfiguration = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************************************/ + /* Enables watchdog/counter 3 and triggers watchdog/counter 3 */ + /********************************************************/ + + i_MasterConfiguration = + i_MasterConfiguration | 0x10; + + /*********************************************/ + /* Selects the master configuration register */ + /*********************************************/ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************************/ + /* Writes the new configuration */ + /********************************/ + outb(i_MasterConfiguration, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /********************/ + /* Test if COUNTER */ + /********************/ + if (data[2] == APCI1500_COUNTER) { + + /*************************************/ + /* Selects the command register of */ + /* watchdog/counter 3 */ + /*************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*************************************************/ + /* Disable the watchdog/counter 3 and starts it */ + /*************************************************/ + outb(0x0, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /*************************************/ + /* Selects the command register of */ + /* watchdog/counter 3 */ + /*************************************/ + + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /*************************************************/ + /* Trigger the watchdog/counter 3 and starts it */ + /*************************************************/ + outb(0x2, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + } //elseif(data[2]==APCI1500_COUNTER) + + } //if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + else { + printk("\nError in selection of interrupt enable or disable\n"); + return -EINVAL; + } //elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) + } // if ((data[3]>= 0) && (data[3] <= 65535)) + else { + printk("\nError in selection of reload value\n"); + return -EINVAL; + } //else if ((data[3]>= 0) && (data[3] <= 65535)) + i_TimerCounterWatchdogInterrupt = data[7]; + i_WatchdogCounter3Init = 1; + break; + + default: + printk("\nThe specified counter\timer option does not exist\n"); + } //switch(data[1]) + i_CounterLogic = data[2]; + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1500_StartStopTriggerTimerCounterWatchdog | @@ -1646,292 +1860,303 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -int i_APCI1500_StartStopTriggerTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_StartStopTriggerTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { -int i_CommandAndStatusValue; - -switch(data[0]) - { - case COUNTER1: - switch(data[1]) - { - case START: - if( i_TimerCounter1Init==1) - { - if(i_TimerCounterWatchdogInterrupt==1) - { - i_CommandAndStatusValue = 0xC4;//Enable the interrupt - }// if(i_TimerCounterWatchdogInterrupt==1) - else - { - i_CommandAndStatusValue =0xE4;//disable the interrupt - }//elseif(i_TimerCounterWatchdogInterrupt==1) - /**************************/ - /* Starts timer/counter 1 */ - /**************************/ - i_TimerCounter1Enabled=1; - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter1Init==1) - else - { - printk("\nCounter/Timer1 not configured\n"); - return -EINVAL; - } - break; - - case STOP : - - - /**************************/ - /* Stop timer/counter 1 */ - /**************************/ - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_TimerCounter1Enabled=0; - break; - - case TRIGGER: - if( i_TimerCounter1Init==1) - { - if( i_TimerCounter1Enabled==1) - { - /************************/ - /* Set Trigger and gate */ - /************************/ - - i_CommandAndStatusValue = 0x6; - }//if( i_TimerCounter1Enabled==1) - else - { - /***************/ - /* Set Trigger */ - /***************/ - - i_CommandAndStatusValue = 0x2; - }//elseif(i_TimerCounter1Enabled==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter1Init==1) - else - { - printk("\nCounter/Timer1 not configured\n"); - return -EINVAL; - } - break; - - default :printk("\nThe specified option for start/stop/trigger does not exist\n"); - return -EINVAL; - }//switch(data[1]) - break; - - case COUNTER2: - switch(data[1]) - { - case START: - if( i_TimerCounter2Init==1) - { - if(i_TimerCounterWatchdogInterrupt==1) - { - i_CommandAndStatusValue = 0xC4;//Enable the interrupt - }// if(i_TimerCounterWatchdogInterrupt==1) - else - { - i_CommandAndStatusValue =0xE4;//disable the interrupt - }//elseif(i_TimerCounterWatchdogInterrupt==1) - /**************************/ - /* Starts timer/counter 2 */ - /**************************/ - i_TimerCounter2Enabled=1; - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter2Init==1) - else - { - printk("\nCounter/Timer2 not configured\n"); - return -EINVAL; - } - break; - - case STOP : - - - /**************************/ - /* Stop timer/counter 2 */ - /**************************/ - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x00 ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_TimerCounter2Enabled=0; - break; - case TRIGGER: - if( i_TimerCounter2Init==1) - { - if( i_TimerCounter2Enabled==1) - { - /************************/ - /* Set Trigger and gate */ - /************************/ - - i_CommandAndStatusValue = 0x6; - }//if( i_TimerCounter2Enabled==1) - else - { - /***************/ - /* Set Trigger */ - /***************/ - - i_CommandAndStatusValue = 0x2; - }//elseif(i_TimerCounter2Enabled==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter2Init==1) - else - { - printk("\nCounter/Timer2 not configured\n"); - return -EINVAL; - } - break; - default :printk("\nThe specified option for start/stop/trigger does not exist\n"); - return -EINVAL; - }//switch(data[1]) - break; - case COUNTER3: - switch(data[1]) - { - case START: - if( i_WatchdogCounter3Init==1) - { - - if(i_TimerCounterWatchdogInterrupt==1) - { - i_CommandAndStatusValue = 0xC4;//Enable the interrupt - }// if(i_TimerCounterWatchdogInterrupt==1) - else - { - i_CommandAndStatusValue =0xE4;//disable the interrupt - }//elseif(i_TimerCounterWatchdogInterrupt==1) - /**************************/ - /* Starts Watchdog/counter 3 */ - /**************************/ - i_WatchdogCounter3Enabled=1; - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - }// if( i_WatchdogCounter3init==1) - else - { - printk("\nWatchdog/Counter3 not configured\n"); - return -EINVAL; - } - break; - - case STOP : - - - /**************************/ - /* Stop Watchdog/counter 3 */ - /**************************/ - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x00 ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_WatchdogCounter3Enabled=0; - break; - - case TRIGGER: - switch(data[2]) - { - case 0://triggering counter 3 - if( i_WatchdogCounter3Init==1) - { - if( i_WatchdogCounter3Enabled==1) - { - /************************/ - /* Set Trigger and gate */ - /************************/ - - i_CommandAndStatusValue = 0x6; - }//if( i_WatchdogCounter3Enabled==1) - else - { - /***************/ - /* Set Trigger */ - /***************/ - - i_CommandAndStatusValue = 0x2; - }//elseif(i_WatchdogCounter3Enabled==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_WatchdogCounter3Init==1) - else - { - printk("\nCounter3 not configured\n"); - return -EINVAL; - } - break; - case 1 : - //triggering Watchdog 3 - if( i_WatchdogCounter3Init==1) - { - - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x6 ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_WatchdogCounter3Init==1) - else - { - printk("\nWatchdog 3 not configured\n"); - return -EINVAL; - } - break; - default :printk("\nWrong choice of watchdog/counter3\n"); - return -EINVAL; - }//switch(data[2]) - break; - default:printk("\nThe specified option for start/stop/trigger does not exist\n"); - return -EINVAL; - }//switch(data[1]) - break; - default : printk("\nThe specified choice for counter/watchdog/timer does not exist\n"); - return -EINVAL; - }//switch(data[0]) -return insn->n; + int i_CommandAndStatusValue; + + switch (data[0]) { + case COUNTER1: + switch (data[1]) { + case START: + if (i_TimerCounter1Init == 1) { + if (i_TimerCounterWatchdogInterrupt == 1) { + i_CommandAndStatusValue = 0xC4; //Enable the interrupt + } // if(i_TimerCounterWatchdogInterrupt==1) + else { + i_CommandAndStatusValue = 0xE4; //disable the interrupt + } //elseif(i_TimerCounterWatchdogInterrupt==1) + /**************************/ + /* Starts timer/counter 1 */ + /**************************/ + i_TimerCounter1Enabled = 1; + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter1Init==1) + else { + printk("\nCounter/Timer1 not configured\n"); + return -EINVAL; + } + break; + + case STOP: + + /**************************/ + /* Stop timer/counter 1 */ + /**************************/ + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_TimerCounter1Enabled = 0; + break; + + case TRIGGER: + if (i_TimerCounter1Init == 1) { + if (i_TimerCounter1Enabled == 1) { + /************************/ + /* Set Trigger and gate */ + /************************/ + + i_CommandAndStatusValue = 0x6; + } //if( i_TimerCounter1Enabled==1) + else { + /***************/ + /* Set Trigger */ + /***************/ + + i_CommandAndStatusValue = 0x2; + } //elseif(i_TimerCounter1Enabled==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter1Init==1) + else { + printk("\nCounter/Timer1 not configured\n"); + return -EINVAL; + } + break; + + default: + printk("\nThe specified option for start/stop/trigger does not exist\n"); + return -EINVAL; + } //switch(data[1]) + break; + + case COUNTER2: + switch (data[1]) { + case START: + if (i_TimerCounter2Init == 1) { + if (i_TimerCounterWatchdogInterrupt == 1) { + i_CommandAndStatusValue = 0xC4; //Enable the interrupt + } // if(i_TimerCounterWatchdogInterrupt==1) + else { + i_CommandAndStatusValue = 0xE4; //disable the interrupt + } //elseif(i_TimerCounterWatchdogInterrupt==1) + /**************************/ + /* Starts timer/counter 2 */ + /**************************/ + i_TimerCounter2Enabled = 1; + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter2Init==1) + else { + printk("\nCounter/Timer2 not configured\n"); + return -EINVAL; + } + break; + + case STOP: + + /**************************/ + /* Stop timer/counter 2 */ + /**************************/ + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_TimerCounter2Enabled = 0; + break; + case TRIGGER: + if (i_TimerCounter2Init == 1) { + if (i_TimerCounter2Enabled == 1) { + /************************/ + /* Set Trigger and gate */ + /************************/ + + i_CommandAndStatusValue = 0x6; + } //if( i_TimerCounter2Enabled==1) + else { + /***************/ + /* Set Trigger */ + /***************/ + + i_CommandAndStatusValue = 0x2; + } //elseif(i_TimerCounter2Enabled==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter2Init==1) + else { + printk("\nCounter/Timer2 not configured\n"); + return -EINVAL; + } + break; + default: + printk("\nThe specified option for start/stop/trigger does not exist\n"); + return -EINVAL; + } //switch(data[1]) + break; + case COUNTER3: + switch (data[1]) { + case START: + if (i_WatchdogCounter3Init == 1) { + + if (i_TimerCounterWatchdogInterrupt == 1) { + i_CommandAndStatusValue = 0xC4; //Enable the interrupt + } // if(i_TimerCounterWatchdogInterrupt==1) + else { + i_CommandAndStatusValue = 0xE4; //disable the interrupt + } //elseif(i_TimerCounterWatchdogInterrupt==1) + /**************************/ + /* Starts Watchdog/counter 3 */ + /**************************/ + i_WatchdogCounter3Enabled = 1; + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + } // if( i_WatchdogCounter3init==1) + else { + printk("\nWatchdog/Counter3 not configured\n"); + return -EINVAL; + } + break; + + case STOP: + + /**************************/ + /* Stop Watchdog/counter 3 */ + /**************************/ + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_WatchdogCounter3Enabled = 0; + break; + + case TRIGGER: + switch (data[2]) { + case 0: //triggering counter 3 + if (i_WatchdogCounter3Init == 1) { + if (i_WatchdogCounter3Enabled == 1) { + /************************/ + /* Set Trigger and gate */ + /************************/ + + i_CommandAndStatusValue = 0x6; + } //if( i_WatchdogCounter3Enabled==1) + else { + /***************/ + /* Set Trigger */ + /***************/ + + i_CommandAndStatusValue = 0x2; + } //elseif(i_WatchdogCounter3Enabled==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_WatchdogCounter3Init==1) + else { + printk("\nCounter3 not configured\n"); + return -EINVAL; + } + break; + case 1: + //triggering Watchdog 3 + if (i_WatchdogCounter3Init == 1) { + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x6, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_WatchdogCounter3Init==1) + else { + printk("\nWatchdog 3 not configured\n"); + return -EINVAL; + } + break; + default: + printk("\nWrong choice of watchdog/counter3\n"); + return -EINVAL; + } //switch(data[2]) + break; + default: + printk("\nThe specified option for start/stop/trigger does not exist\n"); + return -EINVAL; + } //switch(data[1]) + break; + default: + printk("\nThe specified choice for counter/watchdog/timer does not exist\n"); + return -EINVAL; + } //switch(data[0]) + return insn->n; } - + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1500_ReadCounterTimerWatchdog | @@ -1957,147 +2182,170 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI1500_ReadCounterTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_ReadCounterTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i_CommandAndStatusValue; -switch(data[0]) - { - case COUNTER1: - //Read counter/timer1 - if( i_TimerCounter1Init==1) - { - if( i_TimerCounter1Enabled==1) - { - /************************/ - /* Set RCC and gate */ - /************************/ - - i_CommandAndStatusValue = 0xC; - }//if( i_TimerCounter1Init==1) - else - { - /***************/ - /* Set RCC */ - /***************/ - - i_CommandAndStatusValue = 0x8; - }//elseif(i_TimerCounter1Init==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************************/ - /* Selects the counter register (high) */ - /***************************************/ - outb(APCI1500_R_CPT_TMR1_VALUE_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]<<8; - data[0]=data[0]&0xff00; - outb(APCI1500_R_CPT_TMR1_VALUE_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]|inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter1Init==1) - else - { - printk("\nTimer/Counter1 not configured\n"); - return -EINVAL; - }//elseif( i_TimerCounter1Init==1) - break; - case COUNTER2 : - //Read counter/timer2 - if( i_TimerCounter2Init==1) - { - if( i_TimerCounter2Enabled==1) - { - /************************/ - /* Set RCC and gate */ - /************************/ - - i_CommandAndStatusValue = 0xC; - }//if( i_TimerCounter2Init==1) - else - { - /***************/ - /* Set RCC */ - /***************/ - - i_CommandAndStatusValue = 0x8; - }//elseif(i_TimerCounter2Init==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************************/ - /* Selects the counter register (high) */ - /***************************************/ - outb(APCI1500_R_CPT_TMR2_VALUE_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]<<8; - data[0]=data[0]&0xff00; - outb(APCI1500_R_CPT_TMR2_VALUE_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]|inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_TimerCounter2Init==1) - else - { - printk("\nTimer/Counter2 not configured\n"); - return -EINVAL; - }//elseif( i_TimerCounter2Init==1) - break; - case COUNTER3: - //Read counter/watchdog2 - if( i_WatchdogCounter3Init==1) - { - if( i_WatchdogCounter3Enabled==1) - { - /************************/ - /* Set RCC and gate */ - /************************/ - - i_CommandAndStatusValue = 0xC; - }//if( i_TimerCounter2Init==1) - else - { - /***************/ - /* Set RCC */ - /***************/ - - i_CommandAndStatusValue = 0x8; - }//elseif(i_WatchdogCounter3Init==1) - - /********************************************/ - /* Selects the commands and status register */ - /********************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_CommandAndStatusValue ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************************/ - /* Selects the counter register (high) */ - /***************************************/ - outb( APCI1500_R_CPT_TMR3_VALUE_HIGH,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]<<8; - data[0]=data[0]&0xff00; - outb(APCI1500_R_CPT_TMR3_VALUE_LOW,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - data[0]=data[0]|inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }//if( i_WatchdogCounter3Init==1) - else - { - printk("\nWatchdogCounter3 not configured\n"); - return -EINVAL; - }//elseif( i_WatchdogCounter3Init==1) - break; - default : - printk("\nThe choice of timer/counter/watchdog does not exist\n"); - return -EINVAL; - }//switch(data[0]) - - -return insn->n; + int i_CommandAndStatusValue; + switch (data[0]) { + case COUNTER1: + //Read counter/timer1 + if (i_TimerCounter1Init == 1) { + if (i_TimerCounter1Enabled == 1) { + /************************/ + /* Set RCC and gate */ + /************************/ + + i_CommandAndStatusValue = 0xC; + } //if( i_TimerCounter1Init==1) + else { + /***************/ + /* Set RCC */ + /***************/ + + i_CommandAndStatusValue = 0x8; + } //elseif(i_TimerCounter1Init==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************************/ + /* Selects the counter register (high) */ + /***************************************/ + outb(APCI1500_R_CPT_TMR1_VALUE_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = data[0] << 8; + data[0] = data[0] & 0xff00; + outb(APCI1500_R_CPT_TMR1_VALUE_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + data[0] | inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter1Init==1) + else { + printk("\nTimer/Counter1 not configured\n"); + return -EINVAL; + } //elseif( i_TimerCounter1Init==1) + break; + case COUNTER2: + //Read counter/timer2 + if (i_TimerCounter2Init == 1) { + if (i_TimerCounter2Enabled == 1) { + /************************/ + /* Set RCC and gate */ + /************************/ + + i_CommandAndStatusValue = 0xC; + } //if( i_TimerCounter2Init==1) + else { + /***************/ + /* Set RCC */ + /***************/ + + i_CommandAndStatusValue = 0x8; + } //elseif(i_TimerCounter2Init==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************************/ + /* Selects the counter register (high) */ + /***************************************/ + outb(APCI1500_R_CPT_TMR2_VALUE_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = data[0] << 8; + data[0] = data[0] & 0xff00; + outb(APCI1500_R_CPT_TMR2_VALUE_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + data[0] | inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_TimerCounter2Init==1) + else { + printk("\nTimer/Counter2 not configured\n"); + return -EINVAL; + } //elseif( i_TimerCounter2Init==1) + break; + case COUNTER3: + //Read counter/watchdog2 + if (i_WatchdogCounter3Init == 1) { + if (i_WatchdogCounter3Enabled == 1) { + /************************/ + /* Set RCC and gate */ + /************************/ + + i_CommandAndStatusValue = 0xC; + } //if( i_TimerCounter2Init==1) + else { + /***************/ + /* Set RCC */ + /***************/ + + i_CommandAndStatusValue = 0x8; + } //elseif(i_WatchdogCounter3Init==1) + + /********************************************/ + /* Selects the commands and status register */ + /********************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_CommandAndStatusValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************************/ + /* Selects the counter register (high) */ + /***************************************/ + outb(APCI1500_R_CPT_TMR3_VALUE_HIGH, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = data[0] << 8; + data[0] = data[0] & 0xff00; + outb(APCI1500_R_CPT_TMR3_VALUE_LOW, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + data[0] = + data[0] | inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + } //if( i_WatchdogCounter3Init==1) + else { + printk("\nWatchdogCounter3 not configured\n"); + return -EINVAL; + } //elseif( i_WatchdogCounter3Init==1) + break; + default: + printk("\nThe choice of timer/counter/watchdog does not exist\n"); + return -EINVAL; + } //switch(data[0]) + + return insn->n; } /* @@ -2122,13 +2370,15 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -int i_APCI1500_ReadInterruptMask(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_ReadInterruptMask(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[0]=i_InterruptMask; - data[1]=i_InputChannel; - i_InterruptMask=0; - return insn->n; -} + data[0] = i_InterruptMask; + data[1] = i_InputChannel; + i_InterruptMask = 0; + return insn->n; +} + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1500_ConfigureInterrupt | @@ -2151,154 +2401,163 @@ int i_APCI1500_ReadInterruptMask(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -int i_APCI1500_ConfigureInterrupt(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1500_ConfigureInterrupt(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Status; -int i_RegValue; -int i_Constant; -devpriv->tsk_Current=current; -outl(0x0,devpriv->i_IobaseAmcc+0x38); -if(data[0]==1) - { - i_Constant=0xC0; - }//if(data[0]==1) -else - { - if(data[0]==0) - { - i_Constant=0x00; - }//if{data[0]==0) - else - { - printk("\nThe parameter passed to driver is in error for enabling the voltage interrupt\n"); - return -EINVAL; - }//else if(data[0]==0) - }//elseif(data[0]==1) - - - /*****************************************************/ - /* Selects the mode specification register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + UINT ui_Status; + int i_RegValue; + int i_Constant; + devpriv->tsk_Current = current; + outl(0x0, devpriv->i_IobaseAmcc + 0x38); + if (data[0] == 1) { + i_Constant = 0xC0; + } //if(data[0]==1) + else { + if (data[0] == 0) { + i_Constant = 0x00; + } //if{data[0]==0) + else { + printk("\nThe parameter passed to driver is in error for enabling the voltage interrupt\n"); + return -EINVAL; + } //else if(data[0]==0) + } //elseif(data[0]==1) + + /*****************************************************/ + /* Selects the mode specification register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*********************************************/ - /* Writes the new configuration (APCI1500_OR) */ + /* Writes the new configuration (APCI1500_OR) */ /*********************************************/ - i_RegValue =(i_RegValue & 0xF9) | APCI1500_OR; - - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = (i_RegValue & 0xF9) | APCI1500_OR; + + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ - /* Selects the command and status register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************/ - /* Authorises the interrupt on the board */ - /*****************************************/ - outb(0xC0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***************************************************/ - /* Selects the pattern polarity register of port B */ - /***************************************************/ - outb(APCI1500_RW_PORT_B_PATTERN_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_Constant,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************/ - /* Selects the pattern transition register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_Constant ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************************/ - /* Selects the pattern mask register of port B */ - /***********************************************/ - outb( APCI1500_RW_PORT_B_PATTERN_MASK,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(i_Constant ,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ + /* Selects the command and status register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************/ + /* Authorises the interrupt on the board */ + /*****************************************/ + outb(0xC0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /***************************************************/ + /* Selects the pattern polarity register of port B */ + /***************************************************/ + outb(APCI1500_RW_PORT_B_PATTERN_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************/ + /* Selects the pattern transition register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************************/ + /* Selects the pattern mask register of port B */ + /***********************************************/ + outb(APCI1500_RW_PORT_B_PATTERN_MASK, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ /* Selects the command and status register of port A */ - /*****************************************************/ - outb( APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb( APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of port A */ + /*****************************************************/ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /***********************************/ - - i_RegValue=(i_RegValue & 0x0F)| 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*****************************************************/ - /* Selects the command and status register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of port B */ + /* Deletes the interrupt of port A */ /***********************************/ - - i_RegValue=(i_RegValue & 0x0F)| 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the command and status register of timer 1*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 1 */ + + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************/ + /* Selects the command and status register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /***********************************/ - - i_RegValue=(i_RegValue & 0x0F)| 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the command and status register of timer 2*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 2 */ + /* Deletes the interrupt of port B */ /***********************************/ - - i_RegValue=(i_RegValue & 0x0F)| 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - - /*****************************************************/ - /* Selects the command and status register of timer 3*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb( APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 3 */ + + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the command and status register of timer 1 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /***********************************/ - - i_RegValue=(i_RegValue & 0x0F)| 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*************************************************/ - /* Selects the master interrupt control register */ - /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Authorizes the main interrupt on the board */ - /**********************************************/ - outb(0xD0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - + /* Deletes the interrupt of timer 1 */ + /***********************************/ + + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the command and status register of timer 2 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of timer 2 */ + /***********************************/ + + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the command and status register of timer 3 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of timer 3 */ + /***********************************/ + + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*************************************************/ + /* Selects the master interrupt control register */ + /*************************************************/ + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Authorizes the main interrupt on the board */ + /**********************************************/ + outb(0xD0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /***************************/ - /* Enables the PCI interrupt */ + /* Enables the PCI interrupt */ /*****************************/ - outl(0x3000,devpriv->i_IobaseAmcc+0x38); - ui_Status=inl(devpriv->i_IobaseAmcc+0x10); - ui_Status=inl(devpriv->i_IobaseAmcc+0x38); - outl(0x23000,devpriv->i_IobaseAmcc+0x38); - - -return insn->n; -} + outl(0x3000, devpriv->i_IobaseAmcc + 0x38); + ui_Status = inl(devpriv->i_IobaseAmcc + 0x10); + ui_Status = inl(devpriv->i_IobaseAmcc + 0x38); + outl(0x23000, devpriv->i_IobaseAmcc + 0x38); + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -2317,210 +2576,237 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -static VOID v_APCI1500_Interrupt(int irq,void* d) +static VOID v_APCI1500_Interrupt(int irq, void *d) { - - comedi_device *dev =d; - UINT ui_InterruptStatus=0; - int i_RegValue=0; - i_InterruptMask=0; - + + comedi_device *dev = d; + UINT ui_InterruptStatus = 0; + int i_RegValue = 0; + i_InterruptMask = 0; + + /***********************************/ + /* Read the board interrupt status */ /***********************************/ - /* Read the board interrupt status */ - /***********************************/ - ui_InterruptStatus=inl(devpriv->i_IobaseAmcc+0x38); - + ui_InterruptStatus = inl(devpriv->i_IobaseAmcc + 0x38); + /***************************************/ - /* Test if board generated a interrupt */ + /* Test if board generated a interrupt */ /***************************************/ - if ((ui_InterruptStatus & 0x800000) == 0x800000) - { + if ((ui_InterruptStatus & 0x800000) == 0x800000) { /************************/ - /* Disable all Interrupt*/ + /* Disable all Interrupt */ /************************/ /*************************************************/ - /* Selects the master interrupt control register */ + /* Selects the master interrupt control register */ /*************************************************/ - //outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Disables the main interrupt on the board */ - /**********************************************/ - //outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - + //outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Disables the main interrupt on the board */ + /**********************************************/ + //outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************/ - /* Selects the command and status register of port A */ + /* Selects the command and status register of port A */ /*****************************************************/ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if ((i_RegValue & 0x60) == 0x60) - { - /*****************************************************/ - /* Selects the command and status register of port A */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + if ((i_RegValue & 0x60) == 0x60) { /*****************************************************/ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of port A */ + /* Selects the command and status register of port A */ + /*****************************************************/ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of port A */ /***********************************/ - i_RegValue = (i_RegValue & 0x0F) | 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_InterruptMask=i_InterruptMask | 1; - if(i_Logic==APCI1500_OR_PRIORITY) - { - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /***************************************************/ - /* Selects the interrupt vector register of port A */ - /***************************************************/ - outb(APCI1500_RW_PORT_A_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - i_InputChannel = 1 + (i_RegValue >> 1); - - }// if(i_Logic==APCI1500_OR_PRIORITY) - else - { - i_InputChannel=0; - }//elseif(i_Logic==APCI1500_OR_PRIORITY) - }// if ((i_RegValue & 0x60) == 0x60) - - /*****************************************************/ - /* Selects the command and status register of port B*/ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if ((i_RegValue & 0x60) == 0x60) - { - /*****************************************************/ - /* Selects the command and status register of port B */ + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_InterruptMask = i_InterruptMask | 1; + if (i_Logic == APCI1500_OR_PRIORITY) { + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + /***************************************************/ + /* Selects the interrupt vector register of port A */ + /***************************************************/ + outb(APCI1500_RW_PORT_A_INTERRUPT_CONTROL, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + + i_InputChannel = 1 + (i_RegValue >> 1); + + } // if(i_Logic==APCI1500_OR_PRIORITY) + else { + i_InputChannel = 0; + } //elseif(i_Logic==APCI1500_OR_PRIORITY) + } // if ((i_RegValue & 0x60) == 0x60) + + /*****************************************************/ + /* Selects the command and status register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + if ((i_RegValue & 0x60) == 0x60) { + /*****************************************************/ + /* Selects the command and status register of port B */ /*****************************************************/ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of port B */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); /***********************************/ - i_RegValue = (i_RegValue & 0x0F) | 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - printk("\n\n\n"); - /****************/ - /* Reads port B */ + /* Deletes the interrupt of port B */ + /***********************************/ + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + printk("\n\n\n"); + /****************/ + /* Reads port B */ /****************/ - i_RegValue=inb((UINT)devpriv->iobase+APCI1500_Z8536_PORT_B); + i_RegValue = + inb((UINT) devpriv->iobase + + APCI1500_Z8536_PORT_B); - i_RegValue = i_RegValue & 0xC0; - /**************************************/ - /* Tests if this is an external error */ + i_RegValue = i_RegValue & 0xC0; + /**************************************/ + /* Tests if this is an external error */ /**************************************/ - - if (i_RegValue) - { - //Disable the interrupt - /*****************************************************/ - /* Selects the command and status register of port B */ - /*****************************************************/ - outl(0x0,devpriv->i_IobaseAmcc+0x38); - - if (i_RegValue & 0x80) - { - i_InterruptMask = i_InterruptMask | 0x40; - }//if (i_RegValue & 0x80) - - if (i_RegValue & 0x40) - { - i_InterruptMask = i_InterruptMask | 0x80; - }//if (i_RegValue & 0x40) - }// if (i_RegValue) - else - { - i_InterruptMask = i_InterruptMask | 2; - }// if (i_RegValue) - }//if ((i_RegValue & 0x60) == 0x60) - - /*****************************************************/ - /* Selects the command and status register of timer 1*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if ((i_RegValue & 0x60) == 0x60) - { - /*****************************************************/ - /* Selects the command and status register of timer 1 */ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 1*/ - /***********************************/ - i_RegValue = (i_RegValue & 0x0F) | 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_InterruptMask = i_InterruptMask | 4; - } // if ((i_RegValue & 0x60) == 0x60) - /*****************************************************/ - /* Selects the command and status register of timer 2*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if ((i_RegValue & 0x60) == 0x60) - { - /*****************************************************/ - /* Selects the command and status register of timer 2 */ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 2*/ - /***********************************/ - i_RegValue = (i_RegValue & 0x0F) | 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_InterruptMask = i_InterruptMask | 8; - } // if ((i_RegValue & 0x60) == 0x60) - - /*****************************************************/ - /* Selects the command and status register of timer 3*/ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_RegValue=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if ((i_RegValue & 0x60) == 0x60) - { - /*****************************************************/ - /* Selects the command and status register of timer 3 */ - /*****************************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /***********************************/ - /* Deletes the interrupt of timer 3*/ - /***********************************/ - i_RegValue = (i_RegValue & 0x0F) | 0x20; - outb(i_RegValue,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - if(i_CounterLogic==APCI1500_COUNTER) - { - i_InterruptMask = i_InterruptMask | 0x10; - }//if(i_CounterLogic==APCI1500_COUNTER) - else - { - i_InterruptMask =i_InterruptMask | 0x20; - } - } // if ((i_RegValue & 0x60) == 0x60) - - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - /***********************/ - /* Enable all Interrupts */ + if (i_RegValue) { + //Disable the interrupt + /*****************************************************/ + /* Selects the command and status register of port B */ + /*****************************************************/ + outl(0x0, devpriv->i_IobaseAmcc + 0x38); + + if (i_RegValue & 0x80) { + i_InterruptMask = + i_InterruptMask | 0x40; + } //if (i_RegValue & 0x80) + + if (i_RegValue & 0x40) { + i_InterruptMask = + i_InterruptMask | 0x80; + } //if (i_RegValue & 0x40) + } // if (i_RegValue) + else { + i_InterruptMask = i_InterruptMask | 2; + } // if (i_RegValue) + } //if ((i_RegValue & 0x60) == 0x60) + + /*****************************************************/ + /* Selects the command and status register of timer 1 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + if ((i_RegValue & 0x60) == 0x60) { + /*****************************************************/ + /* Selects the command and status register of timer 1 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of timer 1 */ + /***********************************/ + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_InterruptMask = i_InterruptMask | 4; + } // if ((i_RegValue & 0x60) == 0x60) + /*****************************************************/ + /* Selects the command and status register of timer 2 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + if ((i_RegValue & 0x60) == 0x60) { + /*****************************************************/ + /* Selects the command and status register of timer 2 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of timer 2 */ + /***********************************/ + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + i_InterruptMask = i_InterruptMask | 8; + } // if ((i_RegValue & 0x60) == 0x60) + + /*****************************************************/ + /* Selects the command and status register of timer 3 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_RegValue = + inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + if ((i_RegValue & 0x60) == 0x60) { + /*****************************************************/ + /* Selects the command and status register of timer 3 */ + /*****************************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + /***********************************/ + /* Deletes the interrupt of timer 3 */ + /***********************************/ + i_RegValue = (i_RegValue & 0x0F) | 0x20; + outb(i_RegValue, + devpriv->iobase + + APCI1500_Z8536_CONTROL_REGISTER); + if (i_CounterLogic == APCI1500_COUNTER) { + i_InterruptMask = i_InterruptMask | 0x10; + } //if(i_CounterLogic==APCI1500_COUNTER) + else { + i_InterruptMask = i_InterruptMask | 0x20; + } + } // if ((i_RegValue & 0x60) == 0x60) + + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample /***********************/ + /* Enable all Interrupts */ + /***********************/ + + /*************************************************/ + /* Selects the master interrupt control register */ + /*************************************************/ + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /**********************************************/ + /* Authorizes the main interrupt on the board */ + /**********************************************/ + outb(0xD0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + } // if ((ui_InterruptStatus & 0x800000) == 0x800000) + else { + printk("\nInterrupt from unknown source\n"); + + } //else if ((ui_InterruptStatus & 0x800000) == 0x800000) + return; +} - /*************************************************/ - /* Selects the master interrupt control register */ - /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /**********************************************/ - /* Authorizes the main interrupt on the board */ - /**********************************************/ - outb(0xD0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - }// if ((ui_InterruptStatus & 0x800000) == 0x800000) - else - { - printk("\nInterrupt from unknown source\n"); - - }//else if ((ui_InterruptStatus & 0x800000) == 0x800000) -return; -} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1500_Reset(comedi_device *dev) | | @@ -2535,197 +2821,225 @@ return; | | +----------------------------------------------------------------------------+ */ - -INT i_APCI1500_Reset(comedi_device *dev) -{ -int i_DummyRead=0; -i_TimerCounter1Init=0; -i_TimerCounter2Init=0; -i_WatchdogCounter3Init=0; -i_Event1Status=0; -i_Event2Status=0; -i_TimerCounterWatchdogInterrupt=0; -i_Logic=0; -i_CounterLogic=0; -i_InterruptMask=0; -i_InputChannel=0;; - i_TimerCounter1Enabled=0; - i_TimerCounter2Enabled=0; -i_WatchdogCounter3Enabled=0; +INT i_APCI1500_Reset(comedi_device * dev) +{ + int i_DummyRead = 0; + i_TimerCounter1Init = 0; + i_TimerCounter2Init = 0; + i_WatchdogCounter3Init = 0; + i_Event1Status = 0; + i_Event2Status = 0; + i_TimerCounterWatchdogInterrupt = 0; + i_Logic = 0; + i_CounterLogic = 0; + i_InterruptMask = 0; + i_InputChannel = 0;; + i_TimerCounter1Enabled = 0; + i_TimerCounter2Enabled = 0; + i_WatchdogCounter3Enabled = 0; /******************/ - /* Software reset */ + /* Software reset */ /******************/ - i_DummyRead=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - i_DummyRead=inb(devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(1,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - + i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(1, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*****************************************************/ - /* Selects the master configuration control register */ + /* Selects the master configuration control register */ /*****************************************************/ - outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0xF4,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the mode specification register of port A */ - /*****************************************************/ - outb(APCI1500_RW_PORT_A_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x10,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the data path polarity register of port A */ - outb( APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* High level of port A means 1 */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /* Selects the data direction register of port A */ - outb(APCI1500_RW_PORT_A_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port A */ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port A */ - outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of port A: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the handshake specification register of port A */ - outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes the register */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the mode specification register of port B */ - /*****************************************************/ - outb(APCI1500_RW_PORT_B_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - outb(0x10,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data path polarity register of port B */ - outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* A high level of port B means 1 */ - outb(0x7F,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data direction register of port B */ - outb(APCI1500_RW_PORT_B_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs */ - outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port B */ - outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of port B */ - outb( APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of port B: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the handshake specification register of port B */ - outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes the register */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - - /*****************************************************/ - /* Selects the data path polarity register of port C */ - /*****************************************************/ - outb( APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* High level of port C means 1 */ - outb(0x9,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the data direction register of port C */ - outb(APCI1500_RW_PORT_C_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* All bits used as inputs except channel 1 */ - outb(0x0E,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the special IO register of port C */ - outb( APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes it */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 1 */ - /******************************************************/ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of timer 1 */ - outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates the interrupt management of timer 1 */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 2 */ + outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0xF4, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the mode specification register of port A */ + /*****************************************************/ + outb(APCI1500_RW_PORT_A_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the data path polarity register of port A */ + outb(APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* High level of port A means 1 */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /* Selects the data direction register of port A */ + outb(APCI1500_RW_PORT_A_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port A */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port A */ + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of port A: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the handshake specification register of port A */ + outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes the register */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the mode specification register of port B */ + /*****************************************************/ + outb(APCI1500_RW_PORT_B_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data path polarity register of port B */ + outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* A high level of port B means 1 */ + outb(0x7F, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data direction register of port B */ + outb(APCI1500_RW_PORT_B_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs */ + outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port B */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of port B */ + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of port B: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the handshake specification register of port B */ + outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes the register */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + + /*****************************************************/ + /* Selects the data path polarity register of port C */ + /*****************************************************/ + outb(APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* High level of port C means 1 */ + outb(0x9, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the data direction register of port C */ + outb(APCI1500_RW_PORT_C_DATA_DIRECTION, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* All bits used as inputs except channel 1 */ + outb(0x0E, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the special IO register of port C */ + outb(APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes it */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************************/ + /* Selects the command and status register of timer 1 */ + /******************************************************/ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of timer 1 */ + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates the interrupt management of timer 1 */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /******************************************************/ + /* Selects the command and status register of timer 2 */ /******************************************************/ - outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of timer 2 */ - outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates Timer 2 interrupt management: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /******************************************************/ - /* Selects the command and status register of timer 3 */ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of timer 2 */ + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates Timer 2 interrupt management: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /******************************************************/ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes IP and IUS */ - outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Selects the command and status register of Timer 3 */ - outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deactivates interrupt management of timer 3: */ - outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /*************************************************/ - /* Selects the master interrupt control register */ + /* Selects the command and status register of timer 3 */ + /******************************************************/ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes IP and IUS */ + outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Selects the command and status register of Timer 3 */ + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deactivates interrupt management of timer 3: */ + outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /*************************************************/ + /* Selects the master interrupt control register */ /*************************************************/ - outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - /* Deletes all interrupts */ - outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); - //reset all the digital outputs -outw(0x0,devpriv->i_IobaseAddon+APCI1500_DIGITAL_OP); + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + /* Deletes all interrupts */ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + //reset all the digital outputs + outw(0x0, devpriv->i_IobaseAddon + APCI1500_DIGITAL_OP); /*******************************/ /* Disable the board interrupt */ /*******************************/ /*************************************************/ - /* Selects the master interrupt control register */ + /* Selects the master interrupt control register */ /*************************************************/ -outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ -/******************************/ -outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); +/******************************/ + outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ - /* Selects the command and status register of port A */ + /* Selects the command and status register of port A */ /*****************************************************/ -outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ /******************************/ -outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ - /* Selects the command and status register of port B */ + /* Selects the command and status register of port B */ /*****************************************************/ -outb( APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ /******************************/ -outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ - /* Selects the command and status register of timer 1*/ + /* Selects the command and status register of timer 1 */ /*****************************************************/ -outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR1_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ /******************************/ -outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ - /* Selects the command and status register of timer 2*/ + /* Selects the command and status register of timer 2 */ /*****************************************************/ -outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR2_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ /******************************/ -outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ /* Selects the command and status register of timer 3*/ /*****************************************************/ -outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); + outb(APCI1500_RW_CPT_TMR3_CMD_STATUS, + devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); /****************************/ /* Deactivates all interrupts */ /******************************/ -outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); -return 0; + outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER); + return 0; } diff --git a/comedi/drivers/addi-data/hwdrv_apci1500.h b/comedi/drivers/addi-data/hwdrv_apci1500.h index 47df6d79..5a3b4854 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1500.h +++ b/comedi/drivers/addi-data/hwdrv_apci1500.h @@ -25,20 +25,19 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc /********* Definitions for APCI-1500 card *****/ // Card Specific information -#define APCI1500_BOARD_VENDOR_ID 0x10e8 -#define APCI1500_ADDRESS_RANGE 4 - +#define APCI1500_BOARD_VENDOR_ID 0x10e8 +#define APCI1500_ADDRESS_RANGE 4 //DIGITAL INPUT-OUTPUT DEFINE -#define APCI1500_DIGITAL_OP 2 -#define APCI1500_DIGITAL_IP 0 +#define APCI1500_DIGITAL_OP 2 +#define APCI1500_DIGITAL_IP 0 #define APCI1500_AND 2 #define APCI1500_OR 4 #define APCI1500_OR_PRIORITY 6 #define APCI1500_CLK_SELECT 0 -#define COUNTER1 0 -#define COUNTER2 1 +#define COUNTER1 0 +#define COUNTER2 1 #define COUNTER3 2 #define APCI1500_COUNTER 0x20 #define APCI1500_TIMER 0 @@ -46,104 +45,113 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1500_SINGLE 0 #define APCI1500_CONTINUOUS 0x80 #define APCI1500_DISABLE 0 -#define APCI1500_ENABLE 1 +#define APCI1500_ENABLE 1 #define APCI1500_SOFTWARE_TRIGGER 0x4 #define APCI1500_HARDWARE_TRIGGER 0x10 #define APCI1500_SOFTWARE_GATE 0 #define APCI1500_HARDWARE_GATE 0x8 #define START 0 #define STOP 1 -#define TRIGGER 2 - /**************************/ +#define TRIGGER 2 + /**************************/ /* Zillog I/O enumeration */ /**************************/ - enum - { - APCI1500_Z8536_PORT_C, - APCI1500_Z8536_PORT_B, - APCI1500_Z8536_PORT_A, - APCI1500_Z8536_CONTROL_REGISTER - }; - +enum { + APCI1500_Z8536_PORT_C, + APCI1500_Z8536_PORT_B, + APCI1500_Z8536_PORT_A, + APCI1500_Z8536_CONTROL_REGISTER +}; + /******************************/ /* Z8536 CIO Internal Address */ /******************************/ - enum - { - APCI1500_RW_MASTER_INTERRUPT_CONTROL, - APCI1500_RW_MASTER_CONFIGURATION_CONTROL, - APCI1500_RW_PORT_A_INTERRUPT_CONTROL, - APCI1500_RW_PORT_B_INTERRUPT_CONTROL, - APCI1500_RW_TIMER_COUNTER_INTERRUPT_VECTOR, - APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY, - APCI1500_RW_PORT_C_DATA_DIRECTION, - APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL, - - APCI1500_RW_PORT_A_COMMAND_AND_STATUS, - APCI1500_RW_PORT_B_COMMAND_AND_STATUS, - APCI1500_RW_CPT_TMR1_CMD_STATUS, - APCI1500_RW_CPT_TMR2_CMD_STATUS, - APCI1500_RW_CPT_TMR3_CMD_STATUS, - APCI1500_RW_PORT_A_DATA, - APCI1500_RW_PORT_B_DATA, - APCI1500_RW_PORT_C_DATA, - - APCI1500_R_CPT_TMR1_VALUE_HIGH, - APCI1500_R_CPT_TMR1_VALUE_LOW, - APCI1500_R_CPT_TMR2_VALUE_HIGH, - APCI1500_R_CPT_TMR2_VALUE_LOW, - APCI1500_R_CPT_TMR3_VALUE_HIGH, - APCI1500_R_CPT_TMR3_VALUE_LOW, - APCI1500_RW_CPT_TMR1_TIME_CST_HIGH, - APCI1500_RW_CPT_TMR1_TIME_CST_LOW, - APCI1500_RW_CPT_TMR2_TIME_CST_HIGH, - APCI1500_RW_CPT_TMR2_TIME_CST_LOW, - APCI1500_RW_CPT_TMR3_TIME_CST_HIGH, - APCI1500_RW_CPT_TMR3_TIME_CST_LOW, - APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION, - APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION, - APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION, - APCI1500_R_CURRENT_VECTOR, - - APCI1500_RW_PORT_A_SPECIFICATION, - APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION, - APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY, - APCI1500_RW_PORT_A_DATA_DIRECTION, - APCI1500_RW_PORT_A_SPECIAL_IO_CONTROL, - APCI1500_RW_PORT_A_PATTERN_POLARITY, - APCI1500_RW_PORT_A_PATTERN_TRANSITION, - APCI1500_RW_PORT_A_PATTERN_MASK, - - APCI1500_RW_PORT_B_SPECIFICATION, - APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION, - APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY, - APCI1500_RW_PORT_B_DATA_DIRECTION, - APCI1500_RW_PORT_B_SPECIAL_IO_CONTROL, - APCI1500_RW_PORT_B_PATTERN_POLARITY, - APCI1500_RW_PORT_B_PATTERN_TRANSITION, - APCI1500_RW_PORT_B_PATTERN_MASK - }; +enum { + APCI1500_RW_MASTER_INTERRUPT_CONTROL, + APCI1500_RW_MASTER_CONFIGURATION_CONTROL, + APCI1500_RW_PORT_A_INTERRUPT_CONTROL, + APCI1500_RW_PORT_B_INTERRUPT_CONTROL, + APCI1500_RW_TIMER_COUNTER_INTERRUPT_VECTOR, + APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY, + APCI1500_RW_PORT_C_DATA_DIRECTION, + APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL, + + APCI1500_RW_PORT_A_COMMAND_AND_STATUS, + APCI1500_RW_PORT_B_COMMAND_AND_STATUS, + APCI1500_RW_CPT_TMR1_CMD_STATUS, + APCI1500_RW_CPT_TMR2_CMD_STATUS, + APCI1500_RW_CPT_TMR3_CMD_STATUS, + APCI1500_RW_PORT_A_DATA, + APCI1500_RW_PORT_B_DATA, + APCI1500_RW_PORT_C_DATA, + + APCI1500_R_CPT_TMR1_VALUE_HIGH, + APCI1500_R_CPT_TMR1_VALUE_LOW, + APCI1500_R_CPT_TMR2_VALUE_HIGH, + APCI1500_R_CPT_TMR2_VALUE_LOW, + APCI1500_R_CPT_TMR3_VALUE_HIGH, + APCI1500_R_CPT_TMR3_VALUE_LOW, + APCI1500_RW_CPT_TMR1_TIME_CST_HIGH, + APCI1500_RW_CPT_TMR1_TIME_CST_LOW, + APCI1500_RW_CPT_TMR2_TIME_CST_HIGH, + APCI1500_RW_CPT_TMR2_TIME_CST_LOW, + APCI1500_RW_CPT_TMR3_TIME_CST_HIGH, + APCI1500_RW_CPT_TMR3_TIME_CST_LOW, + APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION, + APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION, + APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION, + APCI1500_R_CURRENT_VECTOR, + + APCI1500_RW_PORT_A_SPECIFICATION, + APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION, + APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY, + APCI1500_RW_PORT_A_DATA_DIRECTION, + APCI1500_RW_PORT_A_SPECIAL_IO_CONTROL, + APCI1500_RW_PORT_A_PATTERN_POLARITY, + APCI1500_RW_PORT_A_PATTERN_TRANSITION, + APCI1500_RW_PORT_A_PATTERN_MASK, + + APCI1500_RW_PORT_B_SPECIFICATION, + APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION, + APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY, + APCI1500_RW_PORT_B_DATA_DIRECTION, + APCI1500_RW_PORT_B_SPECIAL_IO_CONTROL, + APCI1500_RW_PORT_B_PATTERN_POLARITY, + APCI1500_RW_PORT_B_PATTERN_TRANSITION, + APCI1500_RW_PORT_B_PATTERN_MASK +}; /*----------DIGITAL INPUT----------------*/ -static int i_APCI1500_Initialisation(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - static int i_APCI1500_ConfigDigitalInputEvent(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int i_APCI1500_Initialisation(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_ConfigDigitalInputEvent(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int i_APCI1500_StartStopInputEvent(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int i_APCI1500_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int i_APCI1500_StartStopInputEvent(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_ReadMoreDigitalInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /*---------- DIGITAL OUTPUT------------*/ -static int i_APCI1500_ConfigDigitalOutputErrorInterrupt(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int i_APCI1500_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int i_APCI1500_ConfigDigitalOutputErrorInterrupt(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_WriteDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /*----------TIMER----------------*/ - static int i_APCI1500_ConfigCounterTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int i_APCI1500_StartStopTriggerTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int i_APCI1500_ReadCounterTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int i_APCI1500_ReadInterruptMask(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int i_APCI1500_ConfigCounterTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_StartStopTriggerTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_ReadCounterTimerWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int i_APCI1500_ReadInterruptMask(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /*----------INTERRUPT HANDLER------*/ static void v_APCI1500_Interrupt(int irq, void *d); -static int i_APCI1500_ConfigureInterrupt(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int i_APCI1500_ConfigureInterrupt(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /*----------RESET---------------*/ -static int i_APCI1500_Reset(comedi_device *dev) ; +static int i_APCI1500_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci1516.c b/comedi/drivers/addi-data/hwdrv_apci1516.c index 9db945ee..6fdb629d 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1516.c +++ b/comedi/drivers/addi-data/hwdrv_apci1516.c @@ -53,7 +53,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "hwdrv_apci1516.h" - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1516_Read1DigitalInput | @@ -74,25 +73,24 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc | | +----------------------------------------------------------------------------+ */ -INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1516_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue=0; - UINT ui_Channel; - ui_Channel=CR_CHAN(insn->chanspec); - if (ui_Channel >= 0 && ui_Channel <=7) - { - ui_TmpValue=(UINT) inw(devpriv->iobase + APCI1516_DIGITAL_IP); - // since only 1 channel reqd to bring it to last bit it is rotated - // 8 +(chan - 1) times then ANDed with 1 for last bit. - *data = (ui_TmpValue >> ui_Channel)&0x1 ; - }//if(ui_Channel >= 0 && ui_Channel <=7) - else - { - //comedi_error(dev," \n chan spec wrong\n"); - return -EINVAL; // "sorry channel spec wrong " - }//else if(ui_Channel >= 0 && ui_Channel <=7) - - return insn->n; + UINT ui_TmpValue = 0; + UINT ui_Channel; + ui_Channel = CR_CHAN(insn->chanspec); + if (ui_Channel >= 0 && ui_Channel <= 7) { + ui_TmpValue = (UINT) inw(devpriv->iobase + APCI1516_DIGITAL_IP); + // since only 1 channel reqd to bring it to last bit it is rotated + // 8 +(chan - 1) times then ANDed with 1 for last bit. + *data = (ui_TmpValue >> ui_Channel) & 0x1; + } //if(ui_Channel >= 0 && ui_Channel <=7) + else { + //comedi_error(dev," \n chan spec wrong\n"); + return -EINVAL; // "sorry channel spec wrong " + } //else if(ui_Channel >= 0 && ui_Channel <=7) + + return insn->n; } /* @@ -116,34 +114,36 @@ INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_i +----------------------------------------------------------------------------+ */ -INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1516_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - - UINT ui_PortValue=data[0]; - UINT ui_Mask=0; - UINT ui_NoOfChannels; - - ui_NoOfChannels=CR_CHAN(insn->chanspec); - - *data=(UINT)inw(devpriv->iobase + APCI1516_DIGITAL_IP ); - switch (ui_NoOfChannels) - { - case 2:ui_Mask=3; - *data=(*data >>(2*ui_PortValue))&ui_Mask; - break; - case 4:ui_Mask=15; - *data=(*data >>(4*ui_PortValue))&ui_Mask; - break; - case 7:break; - - default: - printk("\nWrong parameters\n"); - return -EINVAL; // "sorry channel spec wrong " - break; - }//switch(ui_NoOfChannels) - - - return insn->n; + + UINT ui_PortValue = data[0]; + UINT ui_Mask = 0; + UINT ui_NoOfChannels; + + ui_NoOfChannels = CR_CHAN(insn->chanspec); + + *data = (UINT) inw(devpriv->iobase + APCI1516_DIGITAL_IP); + switch (ui_NoOfChannels) { + case 2: + ui_Mask = 3; + *data = (*data >> (2 * ui_PortValue)) & ui_Mask; + break; + case 4: + ui_Mask = 15; + *data = (*data >> (4 * ui_PortValue)) & ui_Mask; + break; + case 7: + break; + + default: + printk("\nWrong parameters\n"); + return -EINVAL; // "sorry channel spec wrong " + break; + } //switch(ui_NoOfChannels) + + return insn->n; } /* @@ -171,9 +171,11 @@ INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comed | | +----------------------------------------------------------------------------+ */ -int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ - devpriv->b_OutputMemoryStatus=data[0]; -return insn->n; +int i_APCI1516_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + devpriv->b_OutputMemoryStatus = data[0]; + return insn->n; } /* @@ -197,134 +199,145 @@ return insn->n; +----------------------------------------------------------------------------+ */ -INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1516_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Temp,ui_Temp1; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - -printk("EL311003 : @=%x\n",devpriv->iobase+APCI1516_DIGITAL_OP); - - if(devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inw(devpriv->iobase+APCI1516_DIGITAL_OP); - - }//if(devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - }//if(devpriv->b_OutputMemoryStatus ) -if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - - printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - - - case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - - case 7:data[0]=data[0]|ui_Temp; - break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - - printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) -else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<iobase+APCI1516_DIGITAL_OP); - - printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xff)& ui_Temp; - break; - - - case 4:data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xff)&ui_Temp; - break; - - case 7: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - - printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - return (insn->n);; + UINT ui_Temp, ui_Temp1; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + + printk("EL311003 : @=%x\n", devpriv->iobase + APCI1516_DIGITAL_OP); + + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inw(devpriv->iobase + APCI1516_DIGITAL_OP); + + } //if(devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } //if(devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outw(data[0], devpriv->iobase + APCI1516_DIGITAL_OP); + + printk("EL311003 : d=%d @=%x\n", data[0], + devpriv->iobase + APCI1516_DIGITAL_OP); + + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + + case 7: + data[0] = data[0] | ui_Temp; + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->iobase + APCI1516_DIGITAL_OP); + + printk("EL311003 : d=%d @=%x\n", data[0], + devpriv->iobase + APCI1516_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = (data[0] << ui_NoOfChannel) ^ 0xff; + data[0] = data[0] & ui_Temp; + outw(data[0], + devpriv->iobase + APCI1516_DIGITAL_OP); + + printk("EL311003 : d=%d @=%x\n", data[0], + devpriv->iobase + APCI1516_DIGITAL_OP); + + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xff) & ui_Temp; + break; + + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xff) & ui_Temp; + break; + + case 7: + break; + + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->iobase + + APCI1516_DIGITAL_OP); + + printk("EL311003 : d=%d @=%x\n", + data[0], + devpriv->iobase + + APCI1516_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return (insn->n);; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1516_ReadDigitalOutput | @@ -346,46 +359,43 @@ else +----------------------------------------------------------------------------+ */ -INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1516_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Temp; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel -ui_Temp=data[0]; -*data=inw(devpriv->iobase+APCI1516_DIGITAL_OP_RW); -if(ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - }//if(ui_Temp==0) -else - { - if(ui_Temp==1) - { - switch( ui_NoOfChannel) - { - - case 2:*data=(*data >>(2*data[1]))&3; - break; - - - case 4:*data=(*data >>(4*data[1]))&15; - break; - - case 7: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - }//if(ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - }//elseif(ui_Temp==1) - }//elseif(ui_Temp==0) -return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + ui_Temp = data[0]; + *data = inw(devpriv->iobase + APCI1516_DIGITAL_OP_RW); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } //if(ui_Temp==0) + else { + if (ui_Temp == 1) { + switch (ui_NoOfChannel) { + + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; + + case 4: + *data = (*data >> (4 * data[1])) & 15; + break; + + case 7: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + } //if(ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } //elseif(ui_Temp==1) + } //elseif(ui_Temp==0) + return insn->n; } /* @@ -409,65 +419,76 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI1516_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -if(data[0]==0) - { - //Disable the watchdog - outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE); - //Loading the Reload value - outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE); - data[1]=data[1]>>16; - outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2); - }//if(data[0]==0) -else - { - printk("\nThe input parameters are wrong\n"); - return -EINVAL; - }//elseif(data[0]==0) - -return insn->n; + if (data[0] == 0) { + //Disable the watchdog + outw(0x0, + devpriv->i_IobaseAddon + + APCI1516_WATCHDOG_ENABLEDISABLE); + //Loading the Reload value + outw(data[1], + devpriv->i_IobaseAddon + + APCI1516_WATCHDOG_RELOAD_VALUE); + data[1] = data[1] >> 16; + outw(data[1], + devpriv->i_IobaseAddon + + APCI1516_WATCHDOG_RELOAD_VALUE + 2); + } //if(data[0]==0) + else { + printk("\nThe input parameters are wrong\n"); + return -EINVAL; + } //elseif(data[0]==0) + + return insn->n; } /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI1516_StartStopWriteWatchdog | -| (comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); | -+----------------------------------------------------------------------------+ -| Task : Start / Stop The Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : comedi_device *dev : Driver handle | -| comedi_subdevice *s, :pointer to subdevice structure - comedi_insn *insn :pointer to insn structure | -| lsampl_t *data : Data Pointer to read status | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - -int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) + +----------------------------------------------------------------------------+ + | Function Name : int i_APCI1516_StartStopWriteWatchdog | + | (comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data); | + +----------------------------------------------------------------------------+ + | Task : Start / Stop The Watchdog | + +----------------------------------------------------------------------------+ + | Input Parameters : comedi_device *dev : Driver handle | + | comedi_subdevice *s, :pointer to subdevice structure + comedi_insn *insn :pointer to insn structure | + | lsampl_t *data : Data Pointer to read status | + +----------------------------------------------------------------------------+ + | Output Parameters : -- | + +----------------------------------------------------------------------------+ + | Return Value : TRUE : No error occur | + | : FALSE : Error occur. Return the error | + | | + +----------------------------------------------------------------------------+ + */ + +int i_APCI1516_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { - case 0://stop the watchdog - outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);//disable the watchdog - break; - case 1://start the watchdog - outw(0x0001,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE); - break; - case 2://Software trigger - outw(0x0201,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE); - break; - default:printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }// switch(data[0]) -return insn->n; + switch (data[0]) { + case 0: //stop the watchdog + outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_ENABLEDISABLE); //disable the watchdog + break; + case 1: //start the watchdog + outw(0x0001, + devpriv->i_IobaseAddon + + APCI1516_WATCHDOG_ENABLEDISABLE); + break; + case 2: //Software trigger + outw(0x0201, + devpriv->i_IobaseAddon + + APCI1516_WATCHDOG_ENABLEDISABLE); + break; + default: + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } // switch(data[0]) + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1516_ReadWatchdog | @@ -489,11 +510,13 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) - { - data[0]= inw(devpriv->i_IobaseAddon+APCI1516_WATCHDOG_STATUS)&0x1; -return insn->n; +int i_APCI1516_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + data[0] = inw(devpriv->i_IobaseAddon + APCI1516_WATCHDOG_STATUS) & 0x1; + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1516_Reset(comedi_device *dev) | | @@ -508,14 +531,12 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ - -INT i_APCI1516_Reset(comedi_device *dev) -{ - outw(0x0 ,devpriv->iobase+APCI1516_DIGITAL_OP);//RESETS THE DIGITAL OUTPUTS - outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE); - outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE); - outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2); - return 0; -} - +INT i_APCI1516_Reset(comedi_device * dev) +{ + outw(0x0, devpriv->iobase + APCI1516_DIGITAL_OP); //RESETS THE DIGITAL OUTPUTS + outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_ENABLEDISABLE); + outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_RELOAD_VALUE); + outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_RELOAD_VALUE + 2); + return 0; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci1516.h b/comedi/drivers/addi-data/hwdrv_apci1516.h index 26f9440d..6cab4662 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1516.h +++ b/comedi/drivers/addi-data/hwdrv_apci1516.h @@ -28,15 +28,11 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1516_BOARD_VENDOR_ID 0x15B8 #define APCI1516_ADDRESS_RANGE 8 - //DIGITAL INPUT-OUTPUT DEFINE -#define APCI1516_DIGITAL_OP 4 -#define APCI1516_DIGITAL_OP_RW 4 -#define APCI1516_DIGITAL_IP 0 - - - +#define APCI1516_DIGITAL_OP 4 +#define APCI1516_DIGITAL_OP_RW 4 +#define APCI1516_DIGITAL_IP 0 // TIMER COUNTER WATCHDOG DEFINES @@ -46,30 +42,30 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1516_WATCHDOG_RELOAD_VALUE 4 #define APCI1516_WATCHDOG_STATUS 16 - // Hardware Layer functions for Apci1516 - //Digital Input -INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - - - +INT i_APCI1516_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1516_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //Digital Output -int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ; - +int i_APCI1516_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1516_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1516_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER // timer value is passed as u seconds -int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +int i_APCI1516_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI1516_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI1516_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //reset -INT i_APCI1516_Reset(comedi_device *dev); - +INT i_APCI1516_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci1564.c b/comedi/drivers/addi-data/hwdrv_apci1564.c index b1078b08..7d08fa05 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1564.c +++ b/comedi/drivers/addi-data/hwdrv_apci1564.c @@ -56,8 +56,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #include "hwdrv_apci1564.h" //Global variables -UINT ui_InterruptStatus_1564=0 ; -UINT ui_InterruptData,ui_Type; +UINT ui_InterruptStatus_1564 = 0; +UINT ui_InterruptData, ui_Type; /* +----------------------------------------------------------------------------+ @@ -86,35 +86,46 @@ UINT ui_InterruptData,ui_Type; | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ConfigDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - devpriv->tsk_Current=current; + devpriv->tsk_Current = current; /*******************************/ - /* Set the digital input logic */ + /* Set the digital input logic */ /*******************************/ - if ( data[0] == ADDIDATA_ENABLE) - { - data[2]=data[2]<<4; - data[3]=data[3]<<4; - outl (data[2] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE1); - outl (data[3] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE2); - if (data[1] == ADDIDATA_OR) - { - outl(0x4 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); - } // if (data[1] == ADDIDATA_OR) - else - { - outl(0x6 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); - } // else if (data[1] == ADDIDATA_OR) - } // if (data[0] == ADDIDATA_ENABLE) - else - { - outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE1); - outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE2); - outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_IRQ); - } // else if (data[0] == ADDIDATA_ENABLE) - - return insn->n; + if (data[0] == ADDIDATA_ENABLE) { + data[2] = data[2] << 4; + data[3] = data[3] << 4; + outl(data[2], + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_INTERRUPT_MODE1); + outl(data[3], + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_INTERRUPT_MODE2); + if (data[1] == ADDIDATA_OR) { + outl(0x4, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + } // if (data[1] == ADDIDATA_OR) + else { + outl(0x6, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + } // else if (data[1] == ADDIDATA_OR) + } // if (data[0] == ADDIDATA_ENABLE) + else { + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_INTERRUPT_MODE1); + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_INTERRUPT_MODE2); + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + } // else if (data[0] == ADDIDATA_ENABLE) + + return insn->n; } /* @@ -136,25 +147,25 @@ INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_ | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue=0; - UINT ui_Channel; - - ui_Channel=CR_CHAN(insn->chanspec); - if (ui_Channel >= 0 && ui_Channel <=31) - { - ui_TmpValue=(UINT) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP ); - // since only 1 channel reqd to bring it to last bit it is rotated - // 8 +(chan - 1) times then ANDed with 1 for last bit. - *data = (ui_TmpValue >> ui_Channel)&0x1 ; - } // if (ui_Channel >= 0 && ui_Channel <=31) - else - { - comedi_error(dev,"Not a valid channel number !!! \n"); - return -EINVAL; // "sorry channel spec wrong " - } //else if (ui_Channel >= 0 && ui_Channel <=31) - return insn->n; + UINT ui_TmpValue = 0; + UINT ui_Channel; + + ui_Channel = CR_CHAN(insn->chanspec); + if (ui_Channel >= 0 && ui_Channel <= 31) { + ui_TmpValue = + (UINT) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP); + // since only 1 channel reqd to bring it to last bit it is rotated + // 8 +(chan - 1) times then ANDed with 1 for last bit. + *data = (ui_TmpValue >> ui_Channel) & 0x1; + } // if (ui_Channel >= 0 && ui_Channel <=31) + else { + comedi_error(dev, "Not a valid channel number !!! \n"); + return -EINVAL; // "sorry channel spec wrong " + } //else if (ui_Channel >= 0 && ui_Channel <=31) + return insn->n; } /* @@ -176,45 +187,47 @@ INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_PortValue=data[0]; - UINT ui_Mask=0; - UINT ui_NoOfChannels; - - ui_NoOfChannels=CR_CHAN(insn->chanspec); - if (data[1]==0) - { - *data=(UINT)inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP ); - switch (ui_NoOfChannels) - { - case 2: ui_Mask=3; - *data=(*data >>(2*ui_PortValue))&ui_Mask; - break; - case 4: ui_Mask=15; - *data=(*data >>(4*ui_PortValue))&ui_Mask; - break; - case 8: ui_Mask=255; - *data=(*data >>(8*ui_PortValue))&ui_Mask; - break; - case 16:ui_Mask=65535; - *data=(*data >>(16*ui_PortValue))&ui_Mask; - break; - case 31:break; - default: - comedi_error(dev,"Not a valid Channel number !!!\n"); - return -EINVAL; // "sorry channel spec wrong " - break; - } // switch (ui_NoOfChannels) - } // if (data[1]==0) - else - { - if (data[1]==1) - { - *data=ui_InterruptStatus_1564; - } // if (data[1]==1) - } // else if (data[1]==0) - return insn->n; + UINT ui_PortValue = data[0]; + UINT ui_Mask = 0; + UINT ui_NoOfChannels; + + ui_NoOfChannels = CR_CHAN(insn->chanspec); + if (data[1] == 0) { + *data = (UINT) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP); + switch (ui_NoOfChannels) { + case 2: + ui_Mask = 3; + *data = (*data >> (2 * ui_PortValue)) & ui_Mask; + break; + case 4: + ui_Mask = 15; + *data = (*data >> (4 * ui_PortValue)) & ui_Mask; + break; + case 8: + ui_Mask = 255; + *data = (*data >> (8 * ui_PortValue)) & ui_Mask; + break; + case 16: + ui_Mask = 65535; + *data = (*data >> (16 * ui_PortValue)) & ui_Mask; + break; + case 31: + break; + default: + comedi_error(dev, "Not a valid Channel number !!!\n"); + return -EINVAL; // "sorry channel spec wrong " + break; + } // switch (ui_NoOfChannels) + } // if (data[1]==0) + else { + if (data[1] == 1) { + *data = ui_InterruptStatus_1564; + } // if (data[1]==1) + } // else if (data[1]==0) + return insn->n; } /* @@ -242,43 +255,42 @@ INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comed | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command = 0; - - if ((data[0]!=0) && (data[0]!=1)) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); - return -EINVAL; - } // if ((data[0]!=0) && (data[0]!=1)) - if (data[0]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; - } // if (data[0]) - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - } // else if (data[0]) - if (data[1] == ADDIDATA_ENABLE) - { - ul_Command = ul_Command | 0x1; - } // if (data[1] == ADDIDATA_ENABLE) - else - { - ul_Command = ul_Command & 0xFFFFFFFE; - } // else if (data[1] == ADDIDATA_ENABLE) - if (data[2] == ADDIDATA_ENABLE) - { - ul_Command = ul_Command | 0x2; - } // if (data[2] == ADDIDATA_ENABLE) - else - { - ul_Command = ul_Command & 0xFFFFFFFD; - } // else if (data[2] == ADDIDATA_ENABLE) - outl( ul_Command , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT); - ui_InterruptData=inl( devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT); - devpriv->tsk_Current=current; - return insn->n; + ULONG ul_Command = 0; + + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); + return -EINVAL; + } // if ((data[0]!=0) && (data[0]!=1)) + if (data[0]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } // if (data[0]) + else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } // else if (data[0]) + if (data[1] == ADDIDATA_ENABLE) { + ul_Command = ul_Command | 0x1; + } // if (data[1] == ADDIDATA_ENABLE) + else { + ul_Command = ul_Command & 0xFFFFFFFE; + } // else if (data[1] == ADDIDATA_ENABLE) + if (data[2] == ADDIDATA_ENABLE) { + ul_Command = ul_Command | 0x2; + } // if (data[2] == ADDIDATA_ENABLE) + else { + ul_Command = ul_Command & 0xFFFFFFFD; + } // else if (data[2] == ADDIDATA_ENABLE) + outl(ul_Command, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_INTERRUPT); + ui_InterruptData = + inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_INTERRUPT); + devpriv->tsk_Current = current; + return insn->n; } /* @@ -300,116 +312,159 @@ INT i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) { - UINT ui_Temp,ui_Temp1; - UINT ui_NoOfChannel; - - ui_NoOfChannel=CR_CHAN(insn->chanspec); - if (devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW); - } // if (devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - } // else if (devpriv->b_OutputMemoryStatus ) - if (data[3]==0) - { - if (data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW); - } // if (data[1]==0) - else - { - if (data[1]==1) - { - switch (ui_NoOfChannel) - { - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - case 4: data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - case 8: data[0]=(data[0] <<(8*data[2]))|ui_Temp; - break; - case 16: data[0]=(data[0] <<(16*data[2]))|ui_Temp; - break; - case 31: data[0]=data[0]|ui_Temp; - break; - default: comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - } // switch (ui_NoOfChannels) - outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW); - } // if (data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - } // else if (data[1]==1) - } // else if (data[1]==0) - }//if(data[3]==0) - else - { - if (data[3]==1) - { - if (data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW); - } // if (data[1]==0) - else - { - if (data[1]==1) - { - switch (ui_NoOfChannel) - { - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; - break; - case 4: data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xffffffff)&ui_Temp; - break; - case 8: data[0]=~data[0]&0xff; - ui_Temp1=255; - ui_Temp1=ui_Temp1<<8*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (8*data[2]))^0xffffffff)&ui_Temp; - break; - case 16: data[0]=~data[0]&0xffff; - ui_Temp1=65535; - ui_Temp1=ui_Temp1<<16*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (16*data[2]))^0xffffffff)&ui_Temp; - break; - case 31: break; - default: comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - }//switch(ui_NoOfChannels) - outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW); - } // if (data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - } // else if (data[1]==1) - } // else if (data[1]==0) - } // if (data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - } // else if (data[3]==1) - } // else if (data[3]==0) - return insn->n; +INT i_APCI1564_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_Temp, ui_Temp1; + UINT ui_NoOfChannel; + + ui_NoOfChannel = CR_CHAN(insn->chanspec); + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = + inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + } // if (devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } // else if (devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outl(data[0], + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + } // if (data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + case 8: + data[0] = + (data[0] << (8 * + data[2])) | ui_Temp; + break; + case 16: + data[0] = + (data[0] << (16 * + data[2])) | ui_Temp; + break; + case 31: + data[0] = data[0] | ui_Temp; + break; + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } // switch (ui_NoOfChannels) + outl(data[0], + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + } // if (data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } // else if (data[1]==1) + } // else if (data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + (data[0] << ui_NoOfChannel) ^ + 0xffffffff; + data[0] = data[0] & ui_Temp; + outl(data[0], + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + } // if (data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + case 8: + data[0] = ~data[0] & 0xff; + ui_Temp1 = 255; + ui_Temp1 = + ui_Temp1 << 8 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (8 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + case 16: + data[0] = ~data[0] & 0xffff; + ui_Temp1 = 65535; + ui_Temp1 = + ui_Temp1 << 16 * + data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (16 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + case 31: + break; + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } //switch(ui_NoOfChannels) + outl(data[0], + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + } // if (data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } // else if (data[1]==1) + } // else if (data[1]==0) + } // if (data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } // else if (data[3]==1) + } // else if (data[3]==0) + return insn->n; } /* @@ -431,54 +486,52 @@ INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_ | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp; - UINT ui_NoOfChannel; - - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_RW); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } // if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - switch (ui_NoOfChannel) - { - case 2: - *data=(*data >>(2*data[1]))&3; - break; - - case 4: - *data=(*data >>(4*data[1]))&15; - break; - - case 8: - *data=(*data >>(8*data[1]))&255; - break; - - case 16: - *data=(*data >>(16*data[1]))&65535; - break; - - case 31: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - break; - } // switch(ui_NoOfChannels) - } // if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - } // else if (ui_Temp==1) - } // else if (ui_Temp==0) - return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel; + + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_RW); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } // if (ui_Temp==0) + else { + if (ui_Temp == 1) { + switch (ui_NoOfChannel) { + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; + + case 4: + *data = (*data >> (4 * data[1])) & 15; + break; + + case 8: + *data = (*data >> (8 * data[1])) & 255; + break; + + case 16: + *data = (*data >> (16 * data[1])) & 65535; + break; + + case 31: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + break; + } // switch(ui_NoOfChannels) + } // if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } // else if (ui_Temp==1) + } // else if (ui_Temp==0) + return insn->n; } /* @@ -511,97 +564,132 @@ INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ConfigTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command1 = 0; - devpriv->tsk_Current=current; - if (data[0]==ADDIDATA_WATCHDOG) - { - devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; - - //Disable the watchdog - outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG); - //Loading the Reload value - outl(data[3],devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE); - } // if (data[0]==ADDIDATA_WATCHDOG) - else if (data[0]==ADDIDATA_TIMER) - { - //First Stop The Timer - ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Stop The Timer - - devpriv->b_TimerSelectMode =ADDIDATA_TIMER; - if (data[1]==1) - { - outl(0x02,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Enable TIMER int & DISABLE ALL THE OTHER int SOURCES - outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); - outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ); - outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_IRQ); - outl(0x0,devpriv->iobase+APCI1564_COUNTER1 + APCI1564_TCW_IRQ); - outl(0x0,devpriv->iobase+APCI1564_COUNTER2 + APCI1564_TCW_IRQ); - outl(0x0,devpriv->iobase+APCI1564_COUNTER3 + APCI1564_TCW_IRQ); - outl(0x0,devpriv->iobase+APCI1564_COUNTER4 + APCI1564_TCW_IRQ); - } // if (data[1]==1) - else - { - outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//disable Timer interrupt - } // else if (data[1]==1) - - // Loading Timebase - - outl(data[2],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TIMEBASE); - - //Loading the Reload value - outl(data[3],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_RELOAD_VALUE); - - ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - ul_Command1 = (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; - outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//mode 2 - } // else if (data[0]==ADDIDATA_TIMER) - else if (data[0]==ADDIDATA_COUNTER) - { - devpriv->b_TimerSelectMode =ADDIDATA_COUNTER; - devpriv->b_ModeSelectRegister=data[5]; - - //First Stop The Counter - ul_Command1 =inl(devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1,devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);//Stop The Timer + ULONG ul_Command1 = 0; + devpriv->tsk_Current = current; + if (data[0] == ADDIDATA_WATCHDOG) { + devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; + + //Disable the watchdog + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_PROG); + //Loading the Reload value + outl(data[3], + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_RELOAD_VALUE); + } // if (data[0]==ADDIDATA_WATCHDOG) + else if (data[0] == ADDIDATA_TIMER) { + //First Stop The Timer + ul_Command1 = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(ul_Command1, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); //Stop The Timer + + devpriv->b_TimerSelectMode = ADDIDATA_TIMER; + if (data[1] == 1) { + outl(0x02, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); //Enable TIMER int & DISABLE ALL THE OTHER int SOURCES + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_IRQ); + outl(0x0, + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_IRQ); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER1 + + APCI1564_TCW_IRQ); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER2 + + APCI1564_TCW_IRQ); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER3 + + APCI1564_TCW_IRQ); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER4 + + APCI1564_TCW_IRQ); + } // if (data[1]==1) + else { + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); //disable Timer interrupt + } // else if (data[1]==1) + + // Loading Timebase + + outl(data[2], + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_TIMEBASE); + + //Loading the Reload value + outl(data[3], + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_RELOAD_VALUE); + + ul_Command1 = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + ul_Command1 = + (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; + outl(ul_Command1, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); //mode 2 + } // else if (data[0]==ADDIDATA_TIMER) + else if (data[0] == ADDIDATA_COUNTER) { + devpriv->b_TimerSelectMode = ADDIDATA_COUNTER; + devpriv->b_ModeSelectRegister = data[5]; + + //First Stop The Counter + ul_Command1 = + inl(devpriv->iobase + ((data[5] - 1) * 0x20) + + APCI1564_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(ul_Command1, devpriv->iobase + ((data[5] - 1) * 0x20) + APCI1564_TCW_PROG); //Stop The Timer /************************/ - /* Set the reload value */ + /* Set the reload value */ /************************/ - outl(data[3] , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_RELOAD_VALUE); - + outl(data[3], + devpriv->iobase + ((data[5] - 1) * 0x20) + + APCI1564_TCW_RELOAD_VALUE); + /******************************/ - /* Set the mode : */ - /* - Disable the hardware */ - /* - Disable the counter mode */ - /* - Disable the warning */ - /* - Disable the reset */ - /* - Disable the timer mode */ - /* - Enable the counter mode */ + /* Set the mode : */ + /* - Disable the hardware */ + /* - Disable the counter mode */ + /* - Disable the warning */ + /* - Disable the reset */ + /* - Disable the timer mode */ + /* - Enable the counter mode */ /******************************/ - ul_Command1 = (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL | (ULONG) ((ULONG) data[4] << 16UL); - outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); + ul_Command1 = + (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL | + (ULONG) ((ULONG) data[4] << 16UL); + outl(ul_Command1, + devpriv->iobase + ((data[5] - 1) * 0x20) + + APCI1564_TCW_PROG); + + // Enable or Disable Interrupt + ul_Command1 = (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1); + outl(ul_Command1, + devpriv->iobase + ((data[5] - 1) * 0x20) + + APCI1564_TCW_PROG); - // Enable or Disable Interrupt - ul_Command1= (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1); - outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); - /*****************************/ - /* Set the Up/Down selection */ + /* Set the Up/Down selection */ /*****************************/ - ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) | (data[6] << 18); - outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); - } // else if (data[0]==ADDIDATA_COUNTER) - else - { - printk(" Invalid subdevice."); - } // else if (data[0]==ADDIDATA_WATCHDOG) - - return insn->n; + ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) | (data[6] << 18); + outl(ul_Command1, + devpriv->iobase + ((data[5] - 1) * 0x20) + + APCI1564_TCW_PROG); + } // else if (data[0]==ADDIDATA_COUNTER) + else { + printk(" Invalid subdevice."); + } // else if (data[0]==ADDIDATA_WATCHDOG) + + return insn->n; } /* @@ -630,67 +718,78 @@ INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice * | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command1 = 0; - if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - switch (data[1]) - { - case 0: //stop the watchdog - outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG );//disable the watchdog - break; - case 1: //start the watchdog - outl(0x0001,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG); - break; - case 2: //Software trigger - outl(0x0201,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG); - break; - default: printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - } // switch (data[1]) - } // if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - { - if (data[1]==1) - { - ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - ul_Command1=(ul_Command1& 0xFFFFF9FFUL) | 0x1UL; - - //Enable the Timer - outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - } // if (data[1]==1) - else if(data[1]==0) - { - //Stop The Timer - - ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG); - } // else if(data[1]==0) - } // if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) - { - ul_Command1=inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG); - if (data[1] == 1) - { - //Start the Counter subdevice - ul_Command1= (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; - } // if (data[1] == 1) - else if (data[1] == 0) - { - // Stops the Counter subdevice - ul_Command1 = 0; - - } // else if (data[1] == 0) - else if (data[1] == 2) - { - // Clears the Counter subdevice - ul_Command1= (ul_Command1 & 0xFFFFF9FFUL)|0x400; - } // else if (data[1] == 3) - outl(ul_Command1 , devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG); - } // if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) - return insn->n; + ULONG ul_Command1 = 0; + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + switch (data[1]) { + case 0: //stop the watchdog + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_PROG); //disable the watchdog + break; + case 1: //start the watchdog + outl(0x0001, + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_PROG); + break; + case 2: //Software trigger + outl(0x0201, + devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_PROG); + break; + default: + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } // switch (data[1]) + } // if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) + if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { + if (data[1] == 1) { + ul_Command1 = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; + + //Enable the Timer + outl(ul_Command1, + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + } // if (data[1]==1) + else if (data[1] == 0) { + //Stop The Timer + + ul_Command1 = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(ul_Command1, + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + } // else if(data[1]==0) + } // if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) + if (devpriv->b_TimerSelectMode == ADDIDATA_COUNTER) { + ul_Command1 = + inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister - + 1) * 0x20) + APCI1564_TCW_PROG); + if (data[1] == 1) { + //Start the Counter subdevice + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; + } // if (data[1] == 1) + else if (data[1] == 0) { + // Stops the Counter subdevice + ul_Command1 = 0; + + } // else if (data[1] == 0) + else if (data[1] == 2) { + // Clears the Counter subdevice + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x400; + } // else if (data[1] == 3) + outl(ul_Command1, + devpriv->iobase + ((devpriv->b_ModeSelectRegister - + 1) * 0x20) + APCI1564_TCW_PROG); + } // if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) + return insn->n; } /* @@ -714,55 +813,66 @@ INT i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subd | | +----------------------------------------------------------------------------+ */ -INT i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI1564_ReadTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command1 = 0; - - if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - // Stores the status of the Watchdog - data[0]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_TRIG_STATUS)&0x1; - data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG); - } // if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - else if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - { - // Stores the status of the Timer - data[0]= inl(devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TRIG_STATUS)&0x1; - - // Stores the Actual value of the Timer - data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_TIMER); - } // else if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - else if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) - { - // Read the Counter Actual Value. - data[0] = inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_SYNC_ENABLEDISABLE); - ul_Command1 = inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_TRIG_STATUS); + ULONG ul_Command1 = 0; + + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + // Stores the status of the Watchdog + data[0] = + inl(devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_TRIG_STATUS) & 0x1; + data[1] = + inl(devpriv->i_IobaseAmcc + + APCI1564_DIGITAL_OP_WATCHDOG); + } // if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) + else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { + // Stores the status of the Timer + data[0] = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_TRIG_STATUS) & 0x1; + + // Stores the Actual value of the Timer + data[1] = inl(devpriv->i_IobaseAmcc + APCI1564_TIMER); + } // else if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) + else if (devpriv->b_TimerSelectMode == ADDIDATA_COUNTER) { + // Read the Counter Actual Value. + data[0] = + inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister - + 1) * 0x20) + + APCI1564_TCW_SYNC_ENABLEDISABLE); + ul_Command1 = + inl(devpriv->iobase + ((devpriv->b_ModeSelectRegister - + 1) * 0x20) + APCI1564_TCW_TRIG_STATUS); /***********************************/ - /* Get the software trigger status */ + /* Get the software trigger status */ /***********************************/ - data[1]= (BYTE) ((ul_Command1 >> 1) & 1); + data[1] = (BYTE) ((ul_Command1 >> 1) & 1); /***********************************/ - /* Get the hardware trigger status */ + /* Get the hardware trigger status */ /***********************************/ - data[2]= (BYTE) ((ul_Command1 >> 2) & 1); + data[2] = (BYTE) ((ul_Command1 >> 2) & 1); /*********************************/ - /* Get the software clear status */ + /* Get the software clear status */ /*********************************/ - data[3]= (BYTE) ((ul_Command1 >> 3) & 1); + data[3] = (BYTE) ((ul_Command1 >> 3) & 1); /***************************/ - /* Get the overflow status */ + /* Get the overflow status */ /***************************/ - data[4]= (BYTE) ((ul_Command1 >> 0) & 1); - } // else if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) - else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER)) - { - printk ("\n Invalid Subdevice !!!\n"); - } // else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER)) - return insn->n; + data[4] = (BYTE) ((ul_Command1 >> 0) & 1); + } // else if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) + else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER) + && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG) + && (devpriv->b_TimerSelectMode != ADDIDATA_COUNTER)) { + printk("\n Invalid Subdevice !!!\n"); + } // else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER)) + return insn->n; } /* @@ -782,11 +892,12 @@ INT i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,c +----------------------------------------------------------------------------+ */ -int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - *data=ui_Type; - return insn->n; -} +int i_APCI1564_ReadInterruptStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + *data = ui_Type; + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -805,117 +916,156 @@ int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi | | +----------------------------------------------------------------------------+ */ -static VOID v_APCI1564_Interrupt(int irq,void* d) +static VOID v_APCI1564_Interrupt(int irq, void *d) { - comedi_device *dev =d; - UINT ui_DO, ui_DI; - UINT ui_Timer; - UINT ui_C1, ui_C2, ui_C3, ui_C4; - ULONG ul_Command2=0; - ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ) & 0x01; - ui_DO = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ) & 0x01; - ui_Timer = inl(devpriv->i_IobaseAmcc + APCI1564_TIMER+ APCI1564_TCW_IRQ) & 0x01; - ui_C1=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_IRQ ) & 0x1; - ui_C2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_IRQ ) & 0x1; - ui_C3=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_IRQ ) & 0x1; - ui_C4=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_IRQ ) & 0x1; - if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0) - { - printk("\nInterrupt from unknown source\n"); - }// if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0) - - if (ui_DI == 1) - { - ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); - outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); - ui_InterruptStatus_1564=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_STATUS); - ui_InterruptStatus_1564=ui_InterruptStatus_1564 & 0X000FFFF0; - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - outl(ui_DI ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);//enable the interrupt - return; - } - - if (ui_DO == 1) - { - // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt. - ui_Type=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT_STATUS) & 0x3; - //Disable the Interrupt - outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT); - - //Sends signal to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - } // if (ui_DO) - - if ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER)) - { - // Disable Timer Interrupt - ul_Command2=inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); - outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - // Enable Timer Interrupt - - outl(ul_Command2 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); - } // if ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER)) - - - if ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) - { - // Disable Counter Interrupt - ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG); - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - // Enable Counter Interrupt - outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG); - } // if ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) - - if ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - { - // Disable Counter Interrupt - ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - // Enable Counter Interrupt - outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); - } // if ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - - if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - { - // Disable Counter Interrupt - ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - // Enable Counter Interrupt - outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); - } // if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - - if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - { - // Disable Counter Interrupt - ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG); - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - - // Enable Counter Interrupt - outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG); - } // if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) - return; -} - + comedi_device *dev = d; + UINT ui_DO, ui_DI; + UINT ui_Timer; + UINT ui_C1, ui_C2, ui_C3, ui_C4; + ULONG ul_Command2 = 0; + ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ) & 0x01; + ui_DO = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_IRQ) & 0x01; + ui_Timer = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_IRQ) & 0x01; + ui_C1 = inl(devpriv->iobase + APCI1564_COUNTER1 + + APCI1564_TCW_IRQ) & 0x1; + ui_C2 = inl(devpriv->iobase + APCI1564_COUNTER2 + + APCI1564_TCW_IRQ) & 0x1; + ui_C3 = inl(devpriv->iobase + APCI1564_COUNTER3 + + APCI1564_TCW_IRQ) & 0x1; + ui_C4 = inl(devpriv->iobase + APCI1564_COUNTER4 + + APCI1564_TCW_IRQ) & 0x1; + if (ui_DI == 0 && ui_DO == 0 && ui_Timer == 0 && ui_C1 == 0 + && ui_C2 == 0 && ui_C3 == 0 && ui_C4 == 0) { + printk("\nInterrupt from unknown source\n"); + } // if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0) + + if (ui_DI == 1) { + ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_IRQ); + ui_InterruptStatus_1564 = + inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + + APCI1564_DIGITAL_IP_INTERRUPT_STATUS); + ui_InterruptStatus_1564 = ui_InterruptStatus_1564 & 0X000FFFF0; + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + outl(ui_DI, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ); //enable the interrupt + return; + } + + if (ui_DO == 1) { + // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt. + ui_Type = + inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_INTERRUPT_STATUS) & 0x3; + //Disable the Interrupt + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + + APCI1564_DIGITAL_OP_INTERRUPT); + + //Sends signal to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + } // if (ui_DO) + + if ((ui_Timer == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_TIMER)) { + // Disable Timer Interrupt + ul_Command2 = + inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + // Enable Timer Interrupt + + outl(ul_Command2, + devpriv->i_IobaseAmcc + APCI1564_TIMER + + APCI1564_TCW_PROG); + } // if ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER)) + + if ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) { + // Disable Counter Interrupt + ul_Command2 = + inl(devpriv->iobase + APCI1564_COUNTER1 + + APCI1564_TCW_PROG); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER1 + + APCI1564_TCW_PROG); + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + // Enable Counter Interrupt + outl(ul_Command2, + devpriv->iobase + APCI1564_COUNTER1 + + APCI1564_TCW_PROG); + } // if ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) + + if ((ui_C2 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) { + // Disable Counter Interrupt + ul_Command2 = + inl(devpriv->iobase + APCI1564_COUNTER2 + + APCI1564_TCW_PROG); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER2 + + APCI1564_TCW_PROG); + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + // Enable Counter Interrupt + outl(ul_Command2, + devpriv->iobase + APCI1564_COUNTER2 + + APCI1564_TCW_PROG); + } // if ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) + + if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) { + // Disable Counter Interrupt + ul_Command2 = + inl(devpriv->iobase + APCI1564_COUNTER3 + + APCI1564_TCW_PROG); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER3 + + APCI1564_TCW_PROG); + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + // Enable Counter Interrupt + outl(ul_Command2, + devpriv->iobase + APCI1564_COUNTER3 + + APCI1564_TCW_PROG); + } // if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) + + if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER)) { + // Disable Counter Interrupt + ul_Command2 = + inl(devpriv->iobase + APCI1564_COUNTER4 + + APCI1564_TCW_PROG); + outl(0x0, + devpriv->iobase + APCI1564_COUNTER4 + + APCI1564_TCW_PROG); + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + + // Enable Counter Interrupt + outl(ul_Command2, + devpriv->iobase + APCI1564_COUNTER4 + + APCI1564_TCW_PROG); + } // if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) + return; +} + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI1564_Reset(comedi_device *dev) | | @@ -930,24 +1080,26 @@ static VOID v_APCI1564_Interrupt(int irq,void* d) | | +----------------------------------------------------------------------------+ */ - -INT i_APCI1564_Reset(comedi_device *dev) + +INT i_APCI1564_Reset(comedi_device * dev) { - outl(0x0 ,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_IRQ);//disable the interrupts - inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_STATUS);//Reset the interrupt status register - outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE1);//Disable the and/or interrupt - outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE2); - devpriv->b_DigitalOutputRegister=0; - ui_Type=0; - outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP);//Resets the output channels - outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_INTERRUPT);//Disables the interrupt. - outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE); - outl(0x0,devpriv->i_IobaseAmcc+APCI1564_TIMER); - outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); - - outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); - outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG); - return 0; -} + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_IRQ); //disable the interrupts + inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_STATUS); //Reset the interrupt status register + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_MODE1); //Disable the and/or interrupt + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP_INTERRUPT_MODE2); + devpriv->b_DigitalOutputRegister = 0; + ui_Type = 0; + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP); //Resets the output channels + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_INTERRUPT); //Disables the interrupt. + outl(0x0, + devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + + APCI1564_TCW_RELOAD_VALUE); + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER); + outl(0x0, devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG); + + outl(0x0, devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG); + outl(0x0, devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); + outl(0x0, devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); + outl(0x0, devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG); + return 0; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci1564.h b/comedi/drivers/addi-data/hwdrv_apci1564.h index d70c2d2e..4343286f 100644 --- a/comedi/drivers/addi-data/hwdrv_apci1564.h +++ b/comedi/drivers/addi-data/hwdrv_apci1564.h @@ -29,17 +29,16 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc //DIGITAL INPUT-OUTPUT DEFINE // Input defines -#define APCI1564_DIGITAL_IP 0x04 +#define APCI1564_DIGITAL_IP 0x04 #define APCI1564_DIGITAL_IP_INTERRUPT_MODE1 4 #define APCI1564_DIGITAL_IP_INTERRUPT_MODE2 8 #define APCI1564_DIGITAL_IP_IRQ 16 // Output defines #define APCI1564_DIGITAL_OP 0x18 -#define APCI1564_DIGITAL_OP_RW 0 -#define APCI1564_DIGITAL_OP_INTERRUPT 4 -#define APCI1564_DIGITAL_OP_IRQ 12 - +#define APCI1564_DIGITAL_OP_RW 0 +#define APCI1564_DIGITAL_OP_INTERRUPT 4 +#define APCI1564_DIGITAL_OP_IRQ 12 //Digital Input IRQ Function Selection #define ADDIDATA_OR 0 @@ -49,10 +48,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1564_DIGITAL_IP_INTERRUPT_STATUS 12 //Digital Output Interrupt Status -#define APCI1564_DIGITAL_OP_INTERRUPT_STATUS 8 +#define APCI1564_DIGITAL_OP_INTERRUPT_STATUS 8 //Digital Input Interrupt Enable Disable. -#define APCI1564_DIGITAL_IP_INTERRUPT_ENABLE 0x4 +#define APCI1564_DIGITAL_IP_INTERRUPT_ENABLE 0x4 #define APCI1564_DIGITAL_IP_INTERRUPT_DISABLE 0xFFFFFFFB //Digital Output Interrupt Enable Disable. @@ -76,7 +75,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1564_COUNTER1 0x0 #define APCI1564_COUNTER2 0x20 #define APCI1564_COUNTER3 0x40 -#define APCI1564_COUNTER4 0x60 +#define APCI1564_COUNTER4 0x60 #define APCI1564_TCW_SYNC_ENABLEDISABLE 0 #define APCI1564_TCW_RELOAD_VALUE 4 #define APCI1564_TCW_TIMEBASE 8 @@ -86,31 +85,38 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI1564_TCW_WARN_TIMEVAL 24 #define APCI1564_TCW_WARN_TIMEBASE 28 - // Hardware Layer functions for Apci1564 - //DI // for di read -INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +INT i_APCI1564_ConfigDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1564_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1564_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //DO -int i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +int i_APCI1564_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1564_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI1564_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI1564_ReadInterruptStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER // timer value is passed as u seconds -INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +INT i_APCI1564_ConfigTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI1564_ReadTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); // INTERRUPT -static VOID v_APCI1564_Interrupt(int irq, void *d) ; +static VOID v_APCI1564_Interrupt(int irq, void *d); // RESET -INT i_APCI1564_Reset(comedi_device *dev); +INT i_APCI1564_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci16xx.c b/comedi/drivers/addi-data/hwdrv_apci16xx.c index a08df25b..02f91017 100755 --- a/comedi/drivers/addi-data/hwdrv_apci16xx.c +++ b/comedi/drivers/addi-data/hwdrv_apci16xx.c @@ -55,7 +55,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #include "hwdrv_apci16xx.h" - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI16XX_InsnConfigInitTTLIO | @@ -91,170 +90,157 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ +int i_APCI16XX_InsnConfigInitTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Command = 0; + BYTE b_Cpt = 0; + BYTE b_NumberOfPort = + (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); -int i_APCI16XX_InsnConfigInitTTLIO(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Command = 0; - BYTE b_Cpt = 0; - BYTE b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); - - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /*******************/ - /* Get the command */ - /* *****************/ - - b_Command = (BYTE) data[0]; - + /* Get the command */ + /* **************** */ + + b_Command = (BYTE) data[0]; + /********************/ - /* Test the command */ + /* Test the command */ /********************/ - - if ((b_Command == APCI16XX_TTL_INIT) || - (b_Command == APCI16XX_TTL_INITDIRECTION) || - (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) - { + + if ((b_Command == APCI16XX_TTL_INIT) || + (b_Command == APCI16XX_TTL_INITDIRECTION) || + (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) { /***************************************/ - /* Test the initialisation buffer size */ + /* Test the initialisation buffer size */ /***************************************/ - - if ((b_Command == APCI16XX_TTL_INITDIRECTION) && ((BYTE) (insn->n - 1) != b_NumberOfPort)) - { - /*******************/ - /* Data size error */ - /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) && ((BYTE) (insn->n) != 2)) - { - /*******************/ - /* Data size error */ - /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } - else - { + + if ((b_Command == APCI16XX_TTL_INITDIRECTION) + && ((BYTE) (insn->n - 1) != b_NumberOfPort)) { + /*******************/ + /* Data size error */ + /*******************/ + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + + if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) + && ((BYTE) (insn->n) != 2)) { + /*******************/ + /* Data size error */ + /*******************/ + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } - else - { + + printk("\nCommand selection error"); + i_ReturnValue = -100; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + /**************************************************************************/ /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */ /**************************************************************************/ - - if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) - { - memset (devpriv->ul_TTLPortConfiguration, 0, sizeof(devpriv->ul_TTLPortConfiguration)); + + if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) { + memset(devpriv->ul_TTLPortConfiguration, 0, + sizeof(devpriv->ul_TTLPortConfiguration)); /*************************************/ - /* Test the port direction selection */ + /* Test the port direction selection */ /*************************************/ - - for (b_Cpt = 1; (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); b_Cpt ++) - { + + for (b_Cpt = 1; + (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); + b_Cpt++) { /**********************/ - /* Test the direction */ + /* Test the direction */ /**********************/ - - if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) - { - /************************/ - /* Port direction error */ - /************************/ - - printk("\nPort %d direction selection error", (INT) b_Cpt); - i_ReturnValue = - (INT) b_Cpt; - } - - /**************************/ - /* Save the configuration */ - /**************************/ - - - devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] | - (data[b_Cpt] << (8 * ((b_Cpt - 1) % 4))); - } - } - + + if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) { + /************************/ + /* Port direction error */ + /************************/ + + printk("\nPort %d direction selection error", + (INT) b_Cpt); + i_ReturnValue = -(INT) b_Cpt; + } + + /**************************/ + /* Save the configuration */ + /**************************/ + + devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = + devpriv->ul_TTLPortConfiguration[(b_Cpt - + 1) / 4] | (data[b_Cpt] << (8 * ((b_Cpt - + 1) % 4))); + } + } + /**************************/ /* Test if no error occur */ /**************************/ - - if (i_ReturnValue >= 0) - { + + if (i_ReturnValue >= 0) { /***********************************/ - /* Test if TTL port initilaisation */ + /* Test if TTL port initilaisation */ /***********************************/ - - if ((b_Command == APCI16XX_TTL_INIT) || (b_Command == APCI16XX_TTL_INITDIRECTION)) - { + + if ((b_Command == APCI16XX_TTL_INIT) + || (b_Command == APCI16XX_TTL_INITDIRECTION)) { /******************************/ - /* Set all port configuration */ + /* Set all port configuration */ /******************************/ - - for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt ++) - { - if ((b_Cpt % 4) == 0) - { - /*************************/ - /* Set the configuration */ - /*************************/ - - outl(devpriv->ul_TTLPortConfiguration[b_Cpt / 4],devpriv->iobase + 32 + b_Cpt); - } - } - } - } - + + for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt++) { + if ((b_Cpt % 4) == 0) { + /*************************/ + /* Set the configuration */ + /*************************/ + + outl(devpriv-> + ul_TTLPortConfiguration[b_Cpt / + 4], + devpriv->iobase + 32 + b_Cpt); + } + } + } + } + /************************************************/ /* Test if output memory initialisation command */ /************************************************/ - - if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) - { - if (data[1]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; - } - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - } - } - return (i_ReturnValue); + if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) { + if (data[1]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -262,7 +248,6 @@ int i_APCI16XX_InsnConfigInitTTLIO(comedi_device *dev, +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI16XX_InsnBitsReadTTLIO | @@ -298,140 +283,130 @@ int i_APCI16XX_InsnConfigInitTTLIO(comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI16XX_InsnBitsReadTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Command = 0; + BYTE b_NumberOfPort = + (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); + BYTE b_SelectedPort = CR_RANGE(insn->chanspec); + BYTE b_InputChannel = CR_CHAN(insn->chanspec); + BYTE *pb_Status; + DWORD dw_Status; -int i_APCI16XX_InsnBitsReadTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Command = 0; - BYTE b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); - BYTE b_SelectedPort = CR_RANGE(insn->chanspec); - BYTE b_InputChannel = CR_CHAN(insn->chanspec); - BYTE * pb_Status; - DWORD dw_Status; - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /*******************/ - /* Get the command */ - /* *****************/ - - b_Command = (BYTE) data[0]; - + /* Get the command */ + /* **************** */ + + b_Command = (BYTE) data[0]; + /********************/ - /* Test the command */ + /* Test the command */ /********************/ - - if ((b_Command == APCI16XX_TTL_READCHANNEL) || (b_Command == APCI16XX_TTL_READPORT)) - { + + if ((b_Command == APCI16XX_TTL_READCHANNEL) + || (b_Command == APCI16XX_TTL_READPORT)) { /**************************/ - /* Test the selected port */ + /* Test the selected port */ /**************************/ - - if (b_SelectedPort < b_NumberOfPort) - { - /**********************/ - /* Test if input port */ - /**********************/ - - if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0) - { - /***************************/ - /* Test the channel number */ - /***************************/ - - if ((b_Command == APCI16XX_TTL_READCHANNEL) && (b_InputChannel > 7)) - { - /*******************************************/ - /* The selected TTL digital input is wrong */ - /*******************************************/ - - printk("\nChannel selection error"); - i_ReturnValue = -103; - } - } - else - { - /****************************************/ - /* The selected TTL input port is wrong */ - /****************************************/ - - printk("\nPort selection error"); - i_ReturnValue = -102; - } - } - else - { - /****************************************/ - /* The selected TTL input port is wrong */ - /****************************************/ - - printk("\nPort selection error"); - i_ReturnValue = -102; - } - } - else - { + + if (b_SelectedPort < b_NumberOfPort) { + /**********************/ + /* Test if input port */ + /**********************/ + + if (((devpriv->ul_TTLPortConfiguration + [b_SelectedPort / + 4] >> (8 * + (b_SelectedPort + % + 4))) & + 0xFF) == 0) { + /***************************/ + /* Test the channel number */ + /***************************/ + + if ((b_Command == + APCI16XX_TTL_READCHANNEL) + && (b_InputChannel > 7)) { + /*******************************************/ + /* The selected TTL digital input is wrong */ + /*******************************************/ + + printk("\nChannel selection error"); + i_ReturnValue = -103; + } + } else { + /****************************************/ + /* The selected TTL input port is wrong */ + /****************************************/ + + printk("\nPort selection error"); + i_ReturnValue = -102; + } + } else { + /****************************************/ + /* The selected TTL input port is wrong */ + /****************************************/ + + printk("\nPort selection error"); + i_ReturnValue = -102; + } + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } - else - { + + printk("\nCommand selection error"); + i_ReturnValue = -100; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + /**************************/ /* Test if no error occur */ /**************************/ - - if (i_ReturnValue >= 0) - { - pb_Status = (PBYTE) &data[0]; - - /*******************************/ - /* Get the digital inpu status */ - /*******************************/ - - dw_Status = inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4)); - dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF; - + + if (i_ReturnValue >= 0) { + pb_Status = (PBYTE) & data[0]; + + /*******************************/ + /* Get the digital inpu status */ + /*******************************/ + + dw_Status = + inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4)); + dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF; + /***********************/ - /* Save the port value */ + /* Save the port value */ /***********************/ - - *pb_Status = (BYTE) dw_Status; - + + *pb_Status = (BYTE) dw_Status; + /***************************************/ - /* Test if read channel status command */ + /* Test if read channel status command */ /***************************************/ - - if (b_Command == APCI16XX_TTL_READCHANNEL) - { - *pb_Status = (*pb_Status >> b_InputChannel) & 1; - } - } - return (i_ReturnValue); + if (b_Command == APCI16XX_TTL_READCHANNEL) { + *pb_Status = (*pb_Status >> b_InputChannel) & 1; + } } - + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -455,105 +430,103 @@ int i_APCI16XX_InsnBitsReadTTLIO (comedi_device *dev, +----------------------------------------------------------------------------+ */ -int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - BYTE b_Command = (BYTE) CR_AREF(insn->chanspec); - INT i_ReturnValue = insn->n; - BYTE b_Cpt = 0; - BYTE b_NumberOfPort = 0; - lsampl_t * pls_ReadData = data; - +int i_APCI16XX_InsnReadTTLIOAllPortValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + BYTE b_Command = (BYTE) CR_AREF(insn->chanspec); + INT i_ReturnValue = insn->n; + BYTE b_Cpt = 0; + BYTE b_NumberOfPort = 0; + lsampl_t *pls_ReadData = data; + /********************/ /* Test the command */ /********************/ - - if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) - { + + if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) + || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) { /**********************************/ - /* Get the number of 32-Bit ports */ + /* Get the number of 32-Bit ports */ /**********************************/ - - b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 32); - if ((b_NumberOfPort * 32) < devpriv->ps_BoardInfo->i_NbrTTLChannel) - { - b_NumberOfPort = b_NumberOfPort + 1; - } - + + b_NumberOfPort = + (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 32); + if ((b_NumberOfPort * 32) < + devpriv->ps_BoardInfo->i_NbrTTLChannel) { + b_NumberOfPort = b_NumberOfPort + 1; + } + /************************/ - /* Test the buffer size */ + /* Test the buffer size */ /************************/ - - if (insn->n >= b_NumberOfPort) - { - if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) - { - /**************************/ - /* Read all digital input */ - /**************************/ - - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++) - { - /************************/ - /* Read the 32-Bit port */ - /************************/ - - pls_ReadData [b_Cpt] = inl(devpriv->iobase + 8 + (b_Cpt * 4)); - - /**************************************/ - /* Mask all channels used als outputs */ - /**************************************/ - - pls_ReadData [b_Cpt] = pls_ReadData [b_Cpt] & (~devpriv->ul_TTLPortConfiguration[b_Cpt]); - } - } - else - { - /****************************/ - /* Read all digital outputs */ - /****************************/ - - for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++) - { - /************************/ - /* Read the 32-Bit port */ - /************************/ - - pls_ReadData [b_Cpt] = inl(devpriv->iobase + 20 + (b_Cpt * 4)); - - /**************************************/ - /* Mask all channels used als outputs */ - /**************************************/ - - pls_ReadData [b_Cpt] = pls_ReadData [b_Cpt] & devpriv->ul_TTLPortConfiguration[b_Cpt]; - } - } - } - else - { + + if (insn->n >= b_NumberOfPort) { + if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) { + /**************************/ + /* Read all digital input */ + /**************************/ + + for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { + /************************/ + /* Read the 32-Bit port */ + /************************/ + + pls_ReadData[b_Cpt] = + inl(devpriv->iobase + 8 + + (b_Cpt * 4)); + + /**************************************/ + /* Mask all channels used als outputs */ + /**************************************/ + + pls_ReadData[b_Cpt] = + pls_ReadData[b_Cpt] & + (~devpriv-> + ul_TTLPortConfiguration[b_Cpt]); + } + } else { + /****************************/ + /* Read all digital outputs */ + /****************************/ + + for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) { + /************************/ + /* Read the 32-Bit port */ + /************************/ + + pls_ReadData[b_Cpt] = + inl(devpriv->iobase + 20 + + (b_Cpt * 4)); + + /**************************************/ + /* Mask all channels used als outputs */ + /**************************************/ + + pls_ReadData[b_Cpt] = + pls_ReadData[b_Cpt] & devpriv-> + ul_TTLPortConfiguration[b_Cpt]; + } + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } - else - { + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + } else { /*****************/ - /* Command error */ + /* Command error */ /*****************/ - - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - return (i_ReturnValue); + printk("\nCommand selection error"); + i_ReturnValue = -100; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | OUTPUT FUNCTIONS | @@ -597,203 +570,197 @@ int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI16XX_InsnBitsWriteTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Command = 0; + BYTE b_NumberOfPort = + (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); + BYTE b_SelectedPort = CR_RANGE(insn->chanspec); + BYTE b_OutputChannel = CR_CHAN(insn->chanspec); + DWORD dw_Status = 0; -int i_APCI16XX_InsnBitsWriteTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Command = 0; - BYTE b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8); - BYTE b_SelectedPort = CR_RANGE(insn->chanspec); - BYTE b_OutputChannel = CR_CHAN(insn->chanspec); - DWORD dw_Status = 0; - - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /*******************/ - /* Get the command */ - /* *****************/ - - b_Command = (BYTE) data[0]; - + /* Get the command */ + /* **************** */ + + b_Command = (BYTE) data[0]; + /********************/ - /* Test the command */ + /* Test the command */ /********************/ - - if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || - (b_Command == APCI16XX_TTL_WRITEPORT_ON) || - (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || - (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) - { + + if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || + (b_Command == APCI16XX_TTL_WRITEPORT_ON) || + (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || + (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) { /**************************/ - /* Test the selected port */ + /* Test the selected port */ /**************************/ - - if (b_SelectedPort < b_NumberOfPort) - { - /***********************/ - /* Test if output port */ - /***********************/ - - if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0xFF) - { - /***************************/ - /* Test the channel number */ - /***************************/ - - if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || - (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) - { - /********************************************/ - /* The selected TTL digital output is wrong */ - /********************************************/ - - printk("\nChannel selection error"); - i_ReturnValue = -103; - } - - if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || - (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) - { - /********************************************/ - /* The selected TTL digital output is wrong */ - /********************************************/ - - printk("\nOutput memory disabled"); - i_ReturnValue = -104; - } - - /************************/ - /* Test the buffer size */ - /************************/ - - if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || - (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) - { - /*******************/ - /* Data size error */ - /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - } - else - { - /*****************************************/ - /* The selected TTL output port is wrong */ - /*****************************************/ - - printk("\nPort selection error %lX", (unsigned long)devpriv->ul_TTLPortConfiguration[0]); - i_ReturnValue = -102; - } - } - else - { - /****************************************/ - /* The selected TTL output port is wrong */ - /****************************************/ - - printk("\nPort selection error %d %d",b_SelectedPort , b_NumberOfPort); - i_ReturnValue = -102; - } - } - else - { + + if (b_SelectedPort < b_NumberOfPort) { + /***********************/ + /* Test if output port */ + /***********************/ + + if (((devpriv->ul_TTLPortConfiguration + [b_SelectedPort / + 4] >> (8 * + (b_SelectedPort + % + 4))) & + 0xFF) == 0xFF) { + /***************************/ + /* Test the channel number */ + /***************************/ + + if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) { + /********************************************/ + /* The selected TTL digital output is wrong */ + /********************************************/ + + printk("\nChannel selection error"); + i_ReturnValue = -103; + } + + if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) { + /********************************************/ + /* The selected TTL digital output is wrong */ + /********************************************/ + + printk("\nOutput memory disabled"); + i_ReturnValue = -104; + } + + /************************/ + /* Test the buffer size */ + /************************/ + + if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) { + /*******************/ + /* Data size error */ + /*******************/ + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + } else { + /*****************************************/ + /* The selected TTL output port is wrong */ + /*****************************************/ + + printk("\nPort selection error %lX", + (unsigned long)devpriv-> + ul_TTLPortConfiguration[0]); + i_ReturnValue = -102; + } + } else { + /****************************************/ + /* The selected TTL output port is wrong */ + /****************************************/ + + printk("\nPort selection error %d %d", + b_SelectedPort, b_NumberOfPort); + i_ReturnValue = -102; + } + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("\nCommand selection error"); - i_ReturnValue = -100; - } - } - else - { + + printk("\nCommand selection error"); + i_ReturnValue = -100; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("\nBuffer size error"); - i_ReturnValue = -101; - } - - + + printk("\nBuffer size error"); + i_ReturnValue = -101; + } + /**************************/ /* Test if no error occur */ /**************************/ - - if (i_ReturnValue >= 0) - { - /********************************/ - /* Get the digital output state */ - /********************************/ - - dw_Status = inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); + + if (i_ReturnValue >= 0) { + /********************************/ + /* Get the digital output state */ + /********************************/ + + dw_Status = + inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); /**********************************/ - /* Test if output memory not used */ + /* Test if output memory not used */ /**********************************/ - - if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) - { + + if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) { /*********************************/ - /* Clear the selected port value */ + /* Clear the selected port value */ /*********************************/ - - dw_Status = dw_Status & (0xFFFFFFFFUL - (0xFFUL << (8 * (b_SelectedPort % 4)))); - } - + + dw_Status = + dw_Status & (0xFFFFFFFFUL - + (0xFFUL << (8 * (b_SelectedPort % 4)))); + } + + /******************************/ + /* Test if setting channel ON */ /******************************/ - /* Test if setting channel ON */ - /******************************/ - - if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) - { - dw_Status = dw_Status | (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel)); - } + if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) { + dw_Status = + dw_Status | (1UL << ((8 * (b_SelectedPort % + 4)) + b_OutputChannel)); + } + + /***************************/ + /* Test if setting port ON */ /***************************/ - /* Test if setting port ON */ - /***************************/ - - if (b_Command == APCI16XX_TTL_WRITEPORT_ON) - { - dw_Status = dw_Status | ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4))); - } + if (b_Command == APCI16XX_TTL_WRITEPORT_ON) { + dw_Status = + dw_Status | ((data[1] & 0xFF) << (8 * + (b_SelectedPort % 4))); + } + + /*******************************/ + /* Test if setting channel OFF */ /*******************************/ - /* Test if setting channel OFF */ - /*******************************/ - - if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) - { - dw_Status = dw_Status & (0xFFFFFFFFUL - (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel))); - } - + + if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) { + dw_Status = + dw_Status & (0xFFFFFFFFUL - + (1UL << ((8 * (b_SelectedPort % 4)) + + b_OutputChannel))); + } + + /****************************/ + /* Test if setting port OFF */ /****************************/ - /* Test if setting port OFF */ - /****************************/ - - if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) - { - dw_Status = dw_Status & (0xFFFFFFFFUL - ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4)))); - } - - - outl(dw_Status, devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); - } - return (i_ReturnValue); + if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) { + dw_Status = + dw_Status & (0xFFFFFFFFUL - + ((data[1] & 0xFF) << (8 * (b_SelectedPort % + 4)))); + } + + outl(dw_Status, + devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4)); } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_Reset(comedi_device *dev) | +----------------------------------------------------------------------------+ @@ -806,8 +773,8 @@ int i_APCI16XX_InsnBitsWriteTTLIO (comedi_device *dev, | Return Value : - | +----------------------------------------------------------------------------+ */ - -int i_APCI16XX_Reset(comedi_device *dev) - { + +int i_APCI16XX_Reset(comedi_device * dev) +{ return 0; - } +} diff --git a/comedi/drivers/addi-data/hwdrv_apci16xx.h b/comedi/drivers/addi-data/hwdrv_apci16xx.h index e25c94fb..4f56eb1c 100755 --- a/comedi/drivers/addi-data/hwdrv_apci16xx.h +++ b/comedi/drivers/addi-data/hwdrv_apci16xx.h @@ -22,22 +22,19 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - #ifndef COMEDI_SUBD_TTLIO - #define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ #endif #ifndef ADDIDATA_ENABLE - #define ADDIDATA_ENABLE 1 - #define ADDIDATA_DISABLE 0 +#define ADDIDATA_ENABLE 1 +#define ADDIDATA_DISABLE 0 #endif #define APCI16XX_TTL_INIT 0 #define APCI16XX_TTL_INITDIRECTION 1 #define APCI16XX_TTL_OUTPUTMEMORY 2 - #define APCI16XX_TTL_READCHANNEL 0 #define APCI16XX_TTL_READPORT 1 @@ -51,21 +48,20 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #ifdef __KERNEL__ - -comedi_lrange range_apci16xx_ttl= - {12, - {BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1)}}; +comedi_lrange range_apci16xx_ttl = { 12, + {BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1)} +}; /* +----------------------------------------------------------------------------+ @@ -73,11 +69,8 @@ comedi_lrange range_apci16xx_ttl= +----------------------------------------------------------------------------+ */ -int i_APCI16XX_InsnConfigInitTTLIO(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - +int i_APCI16XX_InsnConfigInitTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ @@ -85,16 +78,11 @@ int i_APCI16XX_InsnConfigInitTTLIO(comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI16XX_InsnBitsReadTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -int i_APCI16XX_InsnBitsReadTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); +int i_APCI16XX_InsnReadTTLIOAllPortValue(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* +----------------------------------------------------------------------------+ @@ -102,10 +90,8 @@ int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device *dev, +----------------------------------------------------------------------------+ */ -int i_APCI16XX_InsnBitsWriteTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -int i_APCI16XX_Reset(comedi_device *dev) ; +int i_APCI16XX_InsnBitsWriteTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +int i_APCI16XX_Reset(comedi_device * dev); #endif diff --git a/comedi/drivers/addi-data/hwdrv_apci2016.c b/comedi/drivers/addi-data/hwdrv_apci2016.c index f1eada49..09bd0b7b 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2016.c +++ b/comedi/drivers/addi-data/hwdrv_apci2016.c @@ -75,22 +75,21 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc | | +----------------------------------------------------------------------------+ */ -int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2016_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if ((data[0]!=0) && (data[0]!=1)) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); - return -EINVAL; - } // if ((data[0]!=0) && (data[0]!=1)) - if (data[0]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; - } // if (data[0] - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - } // else if (data[0] - return insn->n; + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); + return -EINVAL; + } // if ((data[0]!=0) && (data[0]!=1)) + if (data[0]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } // if (data[0] + else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } // else if (data[0] + return insn->n; } /* @@ -112,119 +111,140 @@ int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi | | +----------------------------------------------------------------------------+ */ -int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2016_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_NoOfChannel; - UINT ui_Temp,ui_Temp1; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) - { - comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n"); - return -EINVAL; - } // if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) - if (devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inw(devpriv->iobase+APCI2016_DIGITAL_OP); - } // if (devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - } // else if (devpriv->b_OutputMemoryStatus ) - if ((data[1]!=0) && (data[1]!=1)) - { - comedi_error(dev,"Invalid Data[1] value !!!, Data[1] should be 0 or 1\n"); - return -EINVAL; - } // if ((data[1]!=0) && (data[1]!=1)) - - if (data[3]==0) - { - if (data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); - } // if (data[1]==0) - else - { - if (data[1]==1) - { - switch (ui_NoOfChannel) - { - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - case 4: data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - case 8: data[0]=(data[0] << (8*data[2]))|ui_Temp; - break; - case 15: data[0]=data[0]|ui_Temp; - break; - default: comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - }//switch(ui_NoOfChannels) - outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); - }// if (data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - } // else if (data[1]==1) - } // else if (data[1]==0) - } // if (data[3]==0) - else - { - if (data[3]==1) - { - if (data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<iobase+APCI2016_DIGITAL_OP); - } // if (data[1]==0) - else - { - if (data[1]==1) - { - switch (ui_NoOfChannel) - { - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffff)& ui_Temp; - break; - case 4: data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xffff)&ui_Temp; - break; - case 8: data[0]=~data[0]&0xff; - ui_Temp1=255; - ui_Temp1=ui_Temp1<<8*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (8*data[2]))^0xffff)&ui_Temp; - break; - case 15: break; - default: comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - }//switch(ui_NoOfChannels) - outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - return insn->n; + UINT ui_NoOfChannel; + UINT ui_Temp, ui_Temp1; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + if ((ui_NoOfChannel < 0) || (ui_NoOfChannel > 15)) { + comedi_error(dev, + "Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n"); + return -EINVAL; + } // if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inw(devpriv->iobase + APCI2016_DIGITAL_OP); + } // if (devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } // else if (devpriv->b_OutputMemoryStatus ) + if ((data[1] != 0) && (data[1] != 1)) { + comedi_error(dev, + "Invalid Data[1] value !!!, Data[1] should be 0 or 1\n"); + return -EINVAL; + } // if ((data[1]!=0) && (data[1]!=1)) + + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outw(data[0], devpriv->iobase + APCI2016_DIGITAL_OP); + } // if (data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + case 8: + data[0] = + (data[0] << (8 * + data[2])) | ui_Temp; + break; + case 15: + data[0] = data[0] | ui_Temp; + break; + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } //switch(ui_NoOfChannels) + outw(data[0], + devpriv->iobase + APCI2016_DIGITAL_OP); + } // if (data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } // else if (data[1]==1) + } // else if (data[1]==0) + } // if (data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = (data[0] << ui_NoOfChannel) ^ 0xffff; + data[0] = data[0] & ui_Temp; + outw(data[0], + devpriv->iobase + APCI2016_DIGITAL_OP); + } // if (data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + case 8: + data[0] = ~data[0] & 0xff; + ui_Temp1 = 255; + ui_Temp1 = + ui_Temp1 << 8 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (8 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + case 15: + break; + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } //switch(ui_NoOfChannels) + outw(data[0], + devpriv->iobase + + APCI2016_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return insn->n; } /* @@ -246,57 +266,56 @@ int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_ | | +----------------------------------------------------------------------------+ */ -int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2016_BitsDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp; - UINT ui_NoOfChannel; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) - { - comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n"); - return -EINVAL; - } // if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) - if ((data[0]!=0) && (data[0]!=1)) - { - comedi_error(dev,"Invalid Data[0] value !!!, Data[0] should be 0 or 1\n"); - return -EINVAL; - } // if ((data[0]!=0) && (data[0]!=1)) - ui_Temp=data[0]; - *data=inw(devpriv->iobase+APCI2016_DIGITAL_OP_RW); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } // if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - switch (ui_NoOfChannel) - { - case 2: *data=(*data >>(2*data[1]))&3; - break; - - case 4: *data=(*data >>(4*data[1]))&15; - break; + UINT ui_Temp; + UINT ui_NoOfChannel; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + if ((ui_NoOfChannel < 0) || (ui_NoOfChannel > 15)) { + comedi_error(dev, + "Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n"); + return -EINVAL; + } // if ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Invalid Data[0] value !!!, Data[0] should be 0 or 1\n"); + return -EINVAL; + } // if ((data[0]!=0) && (data[0]!=1)) + ui_Temp = data[0]; + *data = inw(devpriv->iobase + APCI2016_DIGITAL_OP_RW); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } // if (ui_Temp==0) + else { + if (ui_Temp == 1) { + switch (ui_NoOfChannel) { + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; - case 8: *data=(*data >>(8*data[1]))&255; - break; - - case 15: break; + case 4: + *data = (*data >> (4 * data[1])) & 15; + break; - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - }//switch(ui_NoOfChannel) - } // if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - } // else if (ui_Temp==1) - } // if (ui_Temp==0) - return insn->n; -} + case 8: + *data = (*data >> (8 * data[1])) & 255; + break; + case 15: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } //switch(ui_NoOfChannel) + } // if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } // else if (ui_Temp==1) + } // if (ui_Temp==0) + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -318,25 +337,28 @@ int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - - if (data[0]==0) - { - //Disable the watchdog - outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE); - //Loading the Reload value - outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE); - data[1]=data[1]>>16; - outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2); - } - else - { - printk("\nThe input parameters are wrong\n"); - } - return insn->n; -} +int i_APCI2016_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + if (data[0] == 0) { + //Disable the watchdog + outw(0x0, + devpriv->i_IobaseAddon + + APCI2016_WATCHDOG_ENABLEDISABLE); + //Loading the Reload value + outw(data[1], + devpriv->i_IobaseAddon + + APCI2016_WATCHDOG_RELOAD_VALUE); + data[1] = data[1] >> 16; + outw(data[1], + devpriv->i_IobaseAddon + + APCI2016_WATCHDOG_RELOAD_VALUE + 2); + } else { + printk("\nThe input parameters are wrong\n"); + } + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -358,28 +380,32 @@ int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn | | +----------------------------------------------------------------------------+ */ -int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2016_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { - case 0://stop the watchdog - outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);//disable the watchdog - break; - case 1://start the watchdog - outw(0x0001,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE); - break; - case 2://Software trigger - outw(0x0201,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE); - break; - default:printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }// switch(data[0]) + switch (data[0]) { + case 0: //stop the watchdog + outw(0x0, devpriv->i_IobaseAddon + APCI2016_WATCHDOG_ENABLEDISABLE); //disable the watchdog + break; + case 1: //start the watchdog + outw(0x0001, + devpriv->i_IobaseAddon + + APCI2016_WATCHDOG_ENABLEDISABLE); + break; + case 2: //Software trigger + outw(0x0201, + devpriv->i_IobaseAddon + + APCI2016_WATCHDOG_ENABLEDISABLE); + break; + default: + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } // switch(data[0]) - return insn->n; + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2016_ReadWatchdog | @@ -401,11 +427,12 @@ int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,com +----------------------------------------------------------------------------+ */ -int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - udelay(5); - data[0]= inw(devpriv->i_IobaseAddon+APCI2016_WATCHDOG_STATUS)&0x1; - return insn->n; +int i_APCI2016_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + udelay(5); + data[0] = inw(devpriv->i_IobaseAddon + APCI2016_WATCHDOG_STATUS) & 0x1; + return insn->n; } /* @@ -422,12 +449,12 @@ int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn * | | +----------------------------------------------------------------------------+ */ - -INT i_APCI2016_Reset(comedi_device *dev) + +INT i_APCI2016_Reset(comedi_device * dev) { - outw(0x0,devpriv->iobase+APCI2016_DIGITAL_OP); // Resets the digital output channels - outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE); - outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE); - outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2); - return 0; + outw(0x0, devpriv->iobase + APCI2016_DIGITAL_OP); // Resets the digital output channels + outw(0x0, devpriv->i_IobaseAddon + APCI2016_WATCHDOG_ENABLEDISABLE); + outw(0x0, devpriv->i_IobaseAddon + APCI2016_WATCHDOG_RELOAD_VALUE); + outw(0x0, devpriv->i_IobaseAddon + APCI2016_WATCHDOG_RELOAD_VALUE + 2); + return 0; } diff --git a/comedi/drivers/addi-data/hwdrv_apci2016.h b/comedi/drivers/addi-data/hwdrv_apci2016.h index 8550941c..ca383898 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2016.h +++ b/comedi/drivers/addi-data/hwdrv_apci2016.h @@ -26,11 +26,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2016_BOARD_VENDOR_ID 0x15B8 #define APCI2016_ADDRESS_RANGE 8 - //DIGITAL INPUT-OUTPUT DEFINE -#define APCI2016_DIGITAL_OP 0x04 -#define APCI2016_DIGITAL_OP_RW 4 +#define APCI2016_DIGITAL_OP 0x04 +#define APCI2016_DIGITAL_OP_RW 4 //ADDIDATA Enable Disable @@ -45,27 +44,29 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2016_WATCHDOG_RELOAD_VALUE 4 #define APCI2016_WATCHDOG_STATUS 16 - // Hardware Layer functions for Apci2016 //DO -int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ; - -int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +int i_APCI2016_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +int i_APCI2016_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2016_BitsDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER // timer value is passed as u seconds +int i_APCI2016_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ; - -int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - -int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +int i_APCI2016_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2016_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // Interrupt functions..... @@ -73,4 +74,4 @@ int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn * //VOID v_APCI2016_Interrupt(int irq, void *d); // RESET -INT i_APCI2016_Reset(comedi_device *dev); +INT i_APCI2016_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci2032.c b/comedi/drivers/addi-data/hwdrv_apci2032.c index 123c8546..78b01e74 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2032.c +++ b/comedi/drivers/addi-data/hwdrv_apci2032.c @@ -53,7 +53,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "hwdrv_apci2032.h" -UINT ui_InterruptData,ui_Type; +UINT ui_InterruptData, ui_Type; /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2032_ConfigDigitalOutput | @@ -79,46 +79,39 @@ UINT ui_InterruptData,ui_Type; | | +----------------------------------------------------------------------------+ */ -int i_APCI2032_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2032_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command = 0; - devpriv->tsk_Current=current; - -if ( (data[0]!=0) && (data[0]!=1) ) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); - return -EINVAL; - }//if ( (data[0]!=0) && (data[0]!=1) ) - if (data[0]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; - }// if (data[0]) - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - }//else if (data[0]) - - - - if (data[1] == ADDIDATA_ENABLE) - { - ul_Command = ul_Command | 0x1; - }//if (data[1] == ADDIDATA_ENABLE) - else - { - ul_Command = ul_Command & 0xFFFFFFFE; - }//elseif (data[1] == ADDIDATA_ENABLE) - if (data[2] == ADDIDATA_ENABLE) - { - ul_Command = ul_Command | 0x2; - }//if (data[2] == ADDIDATA_ENABLE) - else - { - ul_Command = ul_Command & 0xFFFFFFFD; - }//elseif (data[2] == ADDIDATA_ENABLE) - outl( ul_Command , devpriv->iobase+APCI2032_DIGITAL_OP_INTERRUPT); - ui_InterruptData=inl( devpriv->iobase+APCI2032_DIGITAL_OP_INTERRUPT); -return insn->n; + ULONG ul_Command = 0; + devpriv->tsk_Current = current; + + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); + return -EINVAL; + } //if ( (data[0]!=0) && (data[0]!=1) ) + if (data[0]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } // if (data[0]) + else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } //else if (data[0]) + + if (data[1] == ADDIDATA_ENABLE) { + ul_Command = ul_Command | 0x1; + } //if (data[1] == ADDIDATA_ENABLE) + else { + ul_Command = ul_Command & 0xFFFFFFFE; + } //elseif (data[1] == ADDIDATA_ENABLE) + if (data[2] == ADDIDATA_ENABLE) { + ul_Command = ul_Command | 0x2; + } //if (data[2] == ADDIDATA_ENABLE) + else { + ul_Command = ul_Command & 0xFFFFFFFD; + } //elseif (data[2] == ADDIDATA_ENABLE) + outl(ul_Command, devpriv->iobase + APCI2032_DIGITAL_OP_INTERRUPT); + ui_InterruptData = inl(devpriv->iobase + APCI2032_DIGITAL_OP_INTERRUPT); + return insn->n; } /* @@ -141,141 +134,165 @@ return insn->n; +----------------------------------------------------------------------------+ */ -INT i_APCI2032_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2032_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Temp,ui_Temp1; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - if(devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inl(devpriv->iobase+APCI2032_DIGITAL_OP); - - }//if(devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - }//if(devpriv->b_OutputMemoryStatus ) -if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outl(data[0],devpriv->iobase+APCI2032_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - - - case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - - case 8: - data[0]=(data[0] <<(8*data[2]))|ui_Temp; - break; - - case 16: - data[0]=(data[0] <<(16*data[2]))|ui_Temp; - break; - case 31:data[0]=data[0]|ui_Temp; - break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outl(data[0],devpriv->iobase+APCI2032_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) -else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<iobase+APCI2032_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; - break; - - - case 4:data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xffffffff)&ui_Temp; - break; - - case 8:data[0]=~data[0]&0xff; - ui_Temp1=255; - ui_Temp1=ui_Temp1<<8*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (8*data[2]))^0xffffffff)&ui_Temp; - break; - - case 16:data[0]=~data[0]&0xffff; - ui_Temp1=65535; - ui_Temp1=ui_Temp1<<16*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (16*data[2]))^0xffffffff)&ui_Temp; - break; - - case 31: break; - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outl(data[0],devpriv->iobase+APCI2032_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - return (insn->n);; + UINT ui_Temp, ui_Temp1; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inl(devpriv->iobase + APCI2032_DIGITAL_OP); + + } //if(devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } //if(devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outl(data[0], devpriv->iobase + APCI2032_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + + case 8: + data[0] = + (data[0] << (8 * + data[2])) | ui_Temp; + break; + + case 16: + data[0] = + (data[0] << (16 * + data[2])) | ui_Temp; + break; + case 31: + data[0] = data[0] | ui_Temp; + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outl(data[0], + devpriv->iobase + APCI2032_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + (data[0] << ui_NoOfChannel) ^ + 0xffffffff; + data[0] = data[0] & ui_Temp; + outl(data[0], + devpriv->iobase + APCI2032_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 8: + data[0] = ~data[0] & 0xff; + ui_Temp1 = 255; + ui_Temp1 = + ui_Temp1 << 8 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (8 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 16: + data[0] = ~data[0] & 0xffff; + ui_Temp1 = 65535; + ui_Temp1 = + ui_Temp1 << 16 * + data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (16 * + data + [2])) ^ + 0xffffffff) & ui_Temp; + break; + + case 31: + break; + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outl(data[0], + devpriv->iobase + + APCI2032_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return (insn->n);; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2032_ReadDigitalOutput | @@ -296,55 +313,51 @@ else +----------------------------------------------------------------------------+ */ -INT i_APCI2032_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2032_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp; - UINT ui_NoOfChannel; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->iobase+APCI2032_DIGITAL_OP_RW); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } //if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - switch( ui_NoOfChannel) - { - - case 2: - *data=(*data >>(2*data[1]))&3; - break; - - - case 4: - *data=(*data >>(4*data[1]))&15; - break; - - case 8: - *data=(*data >>(8*data[1]))&255; - break; - - case 16: - *data=(*data >>(16*data[1]))&65535; - break; - - case 31: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - }//switch(ui_NoOfChannels) - }//if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - }//elseif (ui_Temp==1) - } -return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->iobase + APCI2032_DIGITAL_OP_RW); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } //if (ui_Temp==0) + else { + if (ui_Temp == 1) { + switch (ui_NoOfChannel) { + + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; + + case 4: + *data = (*data >> (4 * data[1])) & 15; + break; + + case 8: + *data = (*data >> (8 * data[1])) & 255; + break; + + case 16: + *data = (*data >> (16 * data[1])) & 65535; + break; + + case 31: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + } //if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } //elseif (ui_Temp==1) + } + return insn->n; } /* @@ -367,72 +380,71 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI2032_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2032_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -if(data[0]==0) - { - //Disable the watchdog - outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_PROG); - //Loading the Reload value - outl(data[1],devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_RELOAD_VALUE); - } -else - { - printk("\nThe input parameters are wrong\n"); - return -EINVAL; - } - -return insn->n; + if (data[0] == 0) { + //Disable the watchdog + outl(0x0, + devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + + APCI2032_TCW_PROG); + //Loading the Reload value + outl(data[1], + devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + + APCI2032_TCW_RELOAD_VALUE); + } else { + printk("\nThe input parameters are wrong\n"); + return -EINVAL; + } + + return insn->n; } - - - - /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2032_StartStopWriteWatchdog | -| (comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); | -+----------------------------------------------------------------------------+ -| Task : Start / Stop The Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : comedi_device *dev : Driver handle | -| comedi_subdevice *s, :pointer to subdevice structure - comedi_insn *insn :pointer to insn structure | -| lsampl_t *data : Data Pointer to read status | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - -int i_APCI2032_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) + +----------------------------------------------------------------------------+ + | Function Name : int i_APCI2032_StartStopWriteWatchdog | + | (comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data); | + +----------------------------------------------------------------------------+ + | Task : Start / Stop The Watchdog | + +----------------------------------------------------------------------------+ + | Input Parameters : comedi_device *dev : Driver handle | + | comedi_subdevice *s, :pointer to subdevice structure + comedi_insn *insn :pointer to insn structure | + | lsampl_t *data : Data Pointer to read status | + +----------------------------------------------------------------------------+ + | Output Parameters : -- | + +----------------------------------------------------------------------------+ + | Return Value : TRUE : No error occur | + | : FALSE : Error occur. Return the error | + | | + +----------------------------------------------------------------------------+ + */ + +int i_APCI2032_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { - case 0://stop the watchdog - outl(0x0,devpriv->iobase +APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_PROG );//disable the watchdog - break; - case 1://start the watchdog - outl(0x0001,devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_PROG); - break; - case 2://Software trigger - outl(0x0201,devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_PROG); - break; - default:printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - } -return insn->n; + switch (data[0]) { + case 0: //stop the watchdog + outl(0x0, devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + APCI2032_TCW_PROG); //disable the watchdog + break; + case 1: //start the watchdog + outl(0x0001, + devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + + APCI2032_TCW_PROG); + break; + case 2: //Software trigger + outl(0x0201, + devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + + APCI2032_TCW_PROG); + break; + default: + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } + return insn->n; } - - - - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2032_ReadWatchdog | @@ -454,15 +466,16 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI2032_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) - { +int i_APCI2032_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - data[0]= inl(devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_TRIG_STATUS )&0x1; -return insn->n; + data[0] = + inl(devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + + APCI2032_TCW_TRIG_STATUS) & 0x1; + return insn->n; } - - /* +----------------------------------------------------------------------------+ | Function Name : void v_APCI2032_Interrupt | @@ -480,55 +493,39 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ - void v_APCI2032_Interrupt(int irq, void *d) -{ +void v_APCI2032_Interrupt(int irq, void *d) +{ comedi_device *dev = d; - unsigned int ui_DO; - - ui_DO=inl(devpriv->iobase+APCI2032_DIGITAL_OP_IRQ)&0x1;//Check if VCC OR CC interrupt has occured. - - if(ui_DO==0) - { - printk("\nInterrupt from unKnown source\n"); - }// if(ui_DO==0) - if (ui_DO) - { - // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt. - ui_Type=inl(devpriv->iobase+ APCI2032_DIGITAL_OP_INTERRUPT_STATUS)&0x3; - outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP+APCI2032_DIGITAL_OP_INTERRUPT); - if (ui_Type==1) - { - //Sends signal to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - }// if (ui_Type==1) - else - { - if (ui_Type==2) - { - // Sends signal to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - }//if (ui_Type==2) - }//else if (ui_Type==1) - } //if(ui_DO) - - return; - - } - - - - - - - - - - - - - - + unsigned int ui_DO; + + ui_DO = inl(devpriv->iobase + APCI2032_DIGITAL_OP_IRQ) & 0x1; //Check if VCC OR CC interrupt has occured. + + if (ui_DO == 0) { + printk("\nInterrupt from unKnown source\n"); + } // if(ui_DO==0) + if (ui_DO) { + // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt. + ui_Type = + inl(devpriv->iobase + + APCI2032_DIGITAL_OP_INTERRUPT_STATUS) & 0x3; + outl(0x0, + devpriv->iobase + APCI2032_DIGITAL_OP + + APCI2032_DIGITAL_OP_INTERRUPT); + if (ui_Type == 1) { + //Sends signal to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + } // if (ui_Type==1) + else { + if (ui_Type == 2) { + // Sends signal to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + } //if (ui_Type==2) + } //else if (ui_Type==1) + } //if(ui_DO) + + return; +} /* +----------------------------------------------------------------------------+ @@ -547,12 +544,12 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI2032_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - *data=ui_Type; - return insn->n; -} - +int i_APCI2032_ReadInterruptStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + *data = ui_Type; + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -570,15 +567,13 @@ int i_APCI2032_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi +----------------------------------------------------------------------------+ */ -int i_APCI2032_Reset(comedi_device *dev) +int i_APCI2032_Reset(comedi_device * dev) { -devpriv->b_DigitalOutputRegister=0; -ui_Type=0; -outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP);//Resets the output channels -outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP_INTERRUPT);//Disables the interrupt. -outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_PROG);//disable the watchdog -outl(0x0,devpriv->iobase+APCI2032_DIGITAL_OP_WATCHDOG+APCI2032_TCW_RELOAD_VALUE);//reload=0 -return 0; + devpriv->b_DigitalOutputRegister = 0; + ui_Type = 0; + outl(0x0, devpriv->iobase + APCI2032_DIGITAL_OP); //Resets the output channels + outl(0x0, devpriv->iobase + APCI2032_DIGITAL_OP_INTERRUPT); //Disables the interrupt. + outl(0x0, devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + APCI2032_TCW_PROG); //disable the watchdog + outl(0x0, devpriv->iobase + APCI2032_DIGITAL_OP_WATCHDOG + APCI2032_TCW_RELOAD_VALUE); //reload=0 + return 0; } - - diff --git a/comedi/drivers/addi-data/hwdrv_apci2032.h b/comedi/drivers/addi-data/hwdrv_apci2032.h index 8f8c6292..d87f4961 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2032.h +++ b/comedi/drivers/addi-data/hwdrv_apci2032.h @@ -27,11 +27,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2032_BOARD_VENDOR_ID 0x15B8 #define APCI2032_ADDRESS_RANGE 63 - //DIGITAL INPUT-OUTPUT DEFINE -#define APCI2032_DIGITAL_OP 0 -#define APCI2032_DIGITAL_OP_RW 0 +#define APCI2032_DIGITAL_OP 0 +#define APCI2032_DIGITAL_OP_RW 0 #define APCI2032_DIGITAL_OP_INTERRUPT 4 #define APCI2032_DIGITAL_OP_IRQ 12 @@ -59,27 +58,30 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2032_TCW_TRIG_STATUS 16 #define APCI2032_TCW_IRQ 20 - - - // Hardware Layer functions for Apci2032 - //DO -int i_APCI2032_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI2032_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI2032_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI2032_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +int i_APCI2032_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI2032_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI2032_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2032_ReadInterruptStatus(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER // timer value is passed as u seconds -INT i_APCI2032_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI2032_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI2032_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +INT i_APCI2032_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2032_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2032_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + // Interrupt functions..... -void v_APCI2032_Interrupt(int irq, void *d) ; +void v_APCI2032_Interrupt(int irq, void *d); //Reset functions - int i_APCI2032_Reset(comedi_device *dev); +int i_APCI2032_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci2200.c b/comedi/drivers/addi-data/hwdrv_apci2200.c index 44fcf106..32dc4ee3 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2200.c +++ b/comedi/drivers/addi-data/hwdrv_apci2200.c @@ -53,7 +53,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "hwdrv_apci2200.h" - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_Read1DigitalInput | @@ -74,23 +73,22 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc | | +----------------------------------------------------------------------------+ */ -INT i_APCI2200_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2200_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue=0; - UINT ui_Channel; - ui_Channel=CR_CHAN(insn->chanspec); - if (ui_Channel >= 0 && ui_Channel <=7) - { - ui_TmpValue=(UINT) inw(devpriv->iobase + APCI2200_DIGITAL_IP); - *data = (ui_TmpValue >> ui_Channel)&0x1 ; - }//if(ui_Channel >= 0 && ui_Channel <=7) - else - { - printk("\nThe specified channel does not exist\n"); - return -EINVAL; // "sorry channel spec wrong " - }//else if(ui_Channel >= 0 && ui_Channel <=7) - - return insn->n; + UINT ui_TmpValue = 0; + UINT ui_Channel; + ui_Channel = CR_CHAN(insn->chanspec); + if (ui_Channel >= 0 && ui_Channel <= 7) { + ui_TmpValue = (UINT) inw(devpriv->iobase + APCI2200_DIGITAL_IP); + *data = (ui_TmpValue >> ui_Channel) & 0x1; + } //if(ui_Channel >= 0 && ui_Channel <=7) + else { + printk("\nThe specified channel does not exist\n"); + return -EINVAL; // "sorry channel spec wrong " + } //else if(ui_Channel >= 0 && ui_Channel <=7) + + return insn->n; } /* @@ -114,34 +112,36 @@ INT i_APCI2200_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_i +----------------------------------------------------------------------------+ */ -INT i_APCI2200_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2200_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - - UINT ui_PortValue=data[0]; - UINT ui_Mask=0; - UINT ui_NoOfChannels; - - ui_NoOfChannels=CR_CHAN(insn->chanspec); - - *data=(UINT)inw(devpriv->iobase + APCI2200_DIGITAL_IP ); - switch (ui_NoOfChannels) - { - case 2:ui_Mask=3; - *data=(*data >>(2*ui_PortValue))&ui_Mask; - break; - case 4:ui_Mask=15; - *data=(*data >>(4*ui_PortValue))&ui_Mask; - break; - case 7:break; - - default: - printk("\nWrong parameters\n"); - return -EINVAL; // "sorry channel spec wrong " - break; - }//switch(ui_NoOfChannels) - - - return insn->n; + + UINT ui_PortValue = data[0]; + UINT ui_Mask = 0; + UINT ui_NoOfChannels; + + ui_NoOfChannels = CR_CHAN(insn->chanspec); + + *data = (UINT) inw(devpriv->iobase + APCI2200_DIGITAL_IP); + switch (ui_NoOfChannels) { + case 2: + ui_Mask = 3; + *data = (*data >> (2 * ui_PortValue)) & ui_Mask; + break; + case 4: + ui_Mask = 15; + *data = (*data >> (4 * ui_PortValue)) & ui_Mask; + break; + case 7: + break; + + default: + printk("\nWrong parameters\n"); + return -EINVAL; // "sorry channel spec wrong " + break; + } //switch(ui_NoOfChannels) + + return insn->n; } /* @@ -169,9 +169,11 @@ INT i_APCI2200_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comed | | +----------------------------------------------------------------------------+ */ -int i_APCI2200_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ - devpriv->b_OutputMemoryStatus=data[0]; -return insn->n; +int i_APCI2200_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + devpriv->b_OutputMemoryStatus = data[0]; + return insn->n; } /* @@ -195,128 +197,142 @@ return insn->n; +----------------------------------------------------------------------------+ */ -INT i_APCI2200_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2200_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Temp,ui_Temp1; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - if(devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inw(devpriv->iobase+APCI2200_DIGITAL_OP); - - }//if(devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - }//if(devpriv->b_OutputMemoryStatus ) -if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outw(data[0],devpriv->iobase+APCI2200_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; - break; - - - case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp; - break; - - case 8: data[0]=(data[0] << (8*data[2]))|ui_Temp; - break; - case 15: data[0]=data[0]|ui_Temp; - break; - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->iobase+APCI2200_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) -else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<iobase+APCI2200_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffff)& ui_Temp; - break; - - - case 4:data[0]=~data[0]&0xf; - ui_Temp1=15; - ui_Temp1=ui_Temp1<<4*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (4*data[2]))^0xffff)&ui_Temp; - break; - - case 8: data[0]=~data[0]&0xff; - ui_Temp1=255; - ui_Temp1=ui_Temp1<<8*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (8*data[2]))^0xffff)&ui_Temp; - break; - case 15: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - - outw(data[0],devpriv->iobase+APCI2200_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - return (insn->n);; + UINT ui_Temp, ui_Temp1; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inw(devpriv->iobase + APCI2200_DIGITAL_OP); + + } //if(devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } //if(devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outw(data[0], devpriv->iobase + APCI2200_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + + case 4: + data[0] = + (data[0] << (4 * + data[2])) | ui_Temp; + break; + + case 8: + data[0] = + (data[0] << (8 * + data[2])) | ui_Temp; + break; + case 15: + data[0] = data[0] | ui_Temp; + break; + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->iobase + APCI2200_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = (data[0] << ui_NoOfChannel) ^ 0xffff; + data[0] = data[0] & ui_Temp; + outw(data[0], + devpriv->iobase + APCI2200_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + + case 4: + data[0] = ~data[0] & 0xf; + ui_Temp1 = 15; + ui_Temp1 = + ui_Temp1 << 4 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (4 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + + case 8: + data[0] = ~data[0] & 0xff; + ui_Temp1 = 255; + ui_Temp1 = + ui_Temp1 << 8 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (8 * + data + [2])) ^ + 0xffff) & ui_Temp; + break; + case 15: + break; + + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + + outw(data[0], + devpriv->iobase + + APCI2200_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return (insn->n);; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_ReadDigitalOutput | @@ -338,49 +354,47 @@ else +----------------------------------------------------------------------------+ */ -INT i_APCI2200_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI2200_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -UINT ui_Temp; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel -ui_Temp=data[0]; -*data=inw(devpriv->iobase+APCI2200_DIGITAL_OP); -if(ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - }//if(ui_Temp==0) -else - { - if(ui_Temp==1) - { - switch( ui_NoOfChannel) - { - - case 2:*data=(*data >>(2*data[1]))&3; - break; - - - case 4:*data=(*data >>(4*data[1]))&15; - break; - - case 8: *data=(*data >>(8*data[1]))&255; - break; - - case 15: break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - - }//switch(ui_NoOfChannels) - }//if(ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - }//elseif(ui_Temp==1) - }//elseif(ui_Temp==0) -return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + ui_Temp = data[0]; + *data = inw(devpriv->iobase + APCI2200_DIGITAL_OP); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } //if(ui_Temp==0) + else { + if (ui_Temp == 1) { + switch (ui_NoOfChannel) { + + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; + + case 4: + *data = (*data >> (4 * data[1])) & 15; + break; + + case 8: + *data = (*data >> (8 * data[1])) & 255; + break; + + case 15: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + } //if(ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } //elseif(ui_Temp==1) + } //elseif(ui_Temp==0) + return insn->n; } /* @@ -404,65 +418,76 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI2200_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI2200_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -if(data[0]==0) - { - //Disable the watchdog - outw(0x0,devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); - //Loading the Reload value - outw(data[1],devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_RELOAD_VALUE); - data[1]=data[1]>>16; - outw(data[1],devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_RELOAD_VALUE+2); - }//if(data[0]==0) -else - { - printk("\nThe input parameters are wrong\n"); - return -EINVAL; - }//elseif(data[0]==0) - -return insn->n; + if (data[0] == 0) { + //Disable the watchdog + outw(0x0, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); + //Loading the Reload value + outw(data[1], + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE); + data[1] = data[1] >> 16; + outw(data[1], + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE + 2); + } //if(data[0]==0) + else { + printk("\nThe input parameters are wrong\n"); + return -EINVAL; + } //elseif(data[0]==0) + + return insn->n; } /* -+----------------------------------------------------------------------------+ -| Function Name : int i_APCI2200_StartStopWriteWatchdog | -| (comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); | -+----------------------------------------------------------------------------+ -| Task : Start / Stop The Watchdog | -+----------------------------------------------------------------------------+ -| Input Parameters : comedi_device *dev : Driver handle | -| comedi_subdevice *s, :pointer to subdevice structure - comedi_insn *insn :pointer to insn structure | -| lsampl_t *data : Data Pointer to read status | -+----------------------------------------------------------------------------+ -| Output Parameters : -- | -+----------------------------------------------------------------------------+ -| Return Value : TRUE : No error occur | -| : FALSE : Error occur. Return the error | -| | -+----------------------------------------------------------------------------+ -*/ - -int i_APCI2200_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) + +----------------------------------------------------------------------------+ + | Function Name : int i_APCI2200_StartStopWriteWatchdog | + | (comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data); | + +----------------------------------------------------------------------------+ + | Task : Start / Stop The Watchdog | + +----------------------------------------------------------------------------+ + | Input Parameters : comedi_device *dev : Driver handle | + | comedi_subdevice *s, :pointer to subdevice structure + comedi_insn *insn :pointer to insn structure | + | lsampl_t *data : Data Pointer to read status | + +----------------------------------------------------------------------------+ + | Output Parameters : -- | + +----------------------------------------------------------------------------+ + | Return Value : TRUE : No error occur | + | : FALSE : Error occur. Return the error | + | | + +----------------------------------------------------------------------------+ + */ + +int i_APCI2200_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { - case 0://stop the watchdog - outw(0x0,devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE);//disable the watchdog - break; - case 1://start the watchdog - outw(0x0001,devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); - break; - case 2://Software trigger - outw(0x0201,devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); - break; - default:printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }// switch(data[0]) -return insn->n; + switch (data[0]) { + case 0: //stop the watchdog + outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); //disable the watchdog + break; + case 1: //start the watchdog + outw(0x0001, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); + break; + case 2: //Software trigger + outw(0x0201, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); + break; + default: + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } // switch(data[0]) + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_ReadWatchdog | @@ -484,11 +509,15 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI2200_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) - { - data[0]= inw(devpriv->iobase+APCI2200_WATCHDOG +APCI2200_WATCHDOG_STATUS)&0x1; -return insn->n; +int i_APCI2200_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + data[0] = + inw(devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_STATUS) & 0x1; + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI2200_Reset(comedi_device *dev) | | @@ -503,14 +532,18 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ - -INT i_APCI2200_Reset(comedi_device *dev) -{ - outw(0x0 ,devpriv->iobase+APCI2200_DIGITAL_OP);//RESETS THE DIGITAL OUTPUTS - outw(0x0,devpriv->iobase+APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); - outw(0x0,devpriv->iobase+APCI2200_WATCHDOG +APCI2200_WATCHDOG_RELOAD_VALUE); - outw(0x0,devpriv->iobase+APCI2200_WATCHDOG +APCI2200_WATCHDOG_RELOAD_VALUE+2); - return 0; -} - +INT i_APCI2200_Reset(comedi_device * dev) +{ + outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); //RESETS THE DIGITAL OUTPUTS + outw(0x0, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_ENABLEDISABLE); + outw(0x0, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE); + outw(0x0, + devpriv->iobase + APCI2200_WATCHDOG + + APCI2200_WATCHDOG_RELOAD_VALUE + 2); + return 0; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci2200.h b/comedi/drivers/addi-data/hwdrv_apci2200.h index 574bacc2..49e8798f 100644 --- a/comedi/drivers/addi-data/hwdrv_apci2200.h +++ b/comedi/drivers/addi-data/hwdrv_apci2200.h @@ -27,14 +27,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2200_BOARD_VENDOR_ID 0x15b8 #define APCI2200_ADDRESS_RANGE 64 - //DIGITAL INPUT-OUTPUT DEFINE -#define APCI2200_DIGITAL_OP 4 -#define APCI2200_DIGITAL_IP 0 - - - +#define APCI2200_DIGITAL_OP 4 +#define APCI2200_DIGITAL_IP 0 // TIMER COUNTER WATCHDOG DEFINES @@ -43,29 +39,29 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI2200_WATCHDOG_RELOAD_VALUE 4 #define APCI2200_WATCHDOG_STATUS 16 - // Hardware Layer functions for Apci2200 - //Digital Input -INT i_APCI2200_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI2200_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - - - +INT i_APCI2200_ReadMoreDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI2200_Read1DigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //Digital Output -int i_APCI2200_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI2200_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI2200_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ; - +int i_APCI2200_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI2200_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI2200_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER -int i_APCI2200_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI2200_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI2200_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +int i_APCI2200_ConfigWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2200_StartStopWriteWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI2200_ReadWatchdog(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //reset -INT i_APCI2200_Reset(comedi_device *dev); - +INT i_APCI2200_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci3120.c b/comedi/drivers/addi-data/hwdrv_apci3120.c index 43529bbc..2375fad3 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3120.c +++ b/comedi/drivers/addi-data/hwdrv_apci3120.c @@ -44,12 +44,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - - - - #include "hwdrv_apci3120.h" -static UINT ui_Temp=0; +static UINT ui_Temp = 0; // FUNCTION DEFINITIONS @@ -59,7 +55,6 @@ static UINT ui_Temp=0; +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3120_InsnConfigAnalogInput(comedi_device *dev,| @@ -79,69 +74,53 @@ static UINT ui_Temp=0; +----------------------------------------------------------------------------+ */ +int i_APCI3120_InsnConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT i; + if ((data[0] != APCI3120_EOC_MODE) && (data[0] != APCI3120_EOS_MODE)) + return -1; + // Check for Conversion time to be added ?? + devpriv->ui_EocEosConversionTime = data[2]; -int i_APCI3120_InsnConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, - lsampl_t *data) -{ - UINT i; - - if((data[0] != APCI3120_EOC_MODE) && (data[0] != APCI3120_EOS_MODE)) - return -1 ; - - // Check for Conversion time to be added ?? - devpriv->ui_EocEosConversionTime=data[2]; - - if(data[0] == APCI3120_EOS_MODE) - { - - //Test the number of the channel - for(i=0;i=this_board->i_NbrAiChannel) - { - printk("bad channel list\n"); - return -2; - } - } - - devpriv->b_InterruptMode= APCI3120_EOS_MODE; - - if(data[1]) - { - devpriv->b_EocEosInterrupt=APCI3120_ENABLE; - } - else devpriv->b_EocEosInterrupt=APCI3120_DISABLE; - // Copy channel list and Range List to devpriv - - devpriv->ui_AiNbrofChannels= data[3]; - for(i=0;i< devpriv->ui_AiNbrofChannels;i++) - { - devpriv->ui_AiChannelList[i]=data[4+i]; - } - - - } - else // EOC - { - devpriv->b_InterruptMode=APCI3120_EOC_MODE; - if(data[1]) - { - devpriv->b_EocEosInterrupt=APCI3120_ENABLE; - } - else - { - devpriv->b_EocEosInterrupt=APCI3120_DISABLE; - } - } + if (data[0] == APCI3120_EOS_MODE) { - return insn->n; -} + //Test the number of the channel + for (i = 0; i < data[3]; i++) { + + if (CR_CHAN(data[4 + i]) >= this_board->i_NbrAiChannel) { + printk("bad channel list\n"); + return -2; + } + } + + devpriv->b_InterruptMode = APCI3120_EOS_MODE; + if (data[1]) { + devpriv->b_EocEosInterrupt = APCI3120_ENABLE; + } else + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + // Copy channel list and Range List to devpriv + + devpriv->ui_AiNbrofChannels = data[3]; + for (i = 0; i < devpriv->ui_AiNbrofChannels; i++) { + devpriv->ui_AiChannelList[i] = data[4 + i]; + } + } else // EOC + { + devpriv->b_InterruptMode = APCI3120_EOC_MODE; + if (data[1]) { + devpriv->b_EocEosInterrupt = APCI3120_ENABLE; + } else { + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + } + } + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -166,218 +145,251 @@ int i_APCI3120_InsnConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,come +----------------------------------------------------------------------------+ */ -int i_APCI3120_InsnReadAnalogInput(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +int i_APCI3120_InsnReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - USHORT us_ConvertTiming,us_TmpValue,i; + USHORT us_ConvertTiming, us_TmpValue, i; BYTE b_Tmp; - // fix convertion time to 10 us - if(!devpriv->ui_EocEosConversionTime) - { - printk("No timer0 Value using 10 us\n"); - us_ConvertTiming=10; - } - else us_ConvertTiming =(USHORT) (devpriv->ui_EocEosConversionTime/1000);// nano to useconds - - // this_board->i_hwdrv_InsnReadAnalogInput(dev,us_ConvertTiming,insn->n,&insn->chanspec,data,insn->unused[0]); + if (!devpriv->ui_EocEosConversionTime) { + printk("No timer0 Value using 10 us\n"); + us_ConvertTiming = 10; + } else + us_ConvertTiming = (USHORT) (devpriv->ui_EocEosConversionTime / 1000); // nano to useconds + + // this_board->i_hwdrv_InsnReadAnalogInput(dev,us_ConvertTiming,insn->n,&insn->chanspec,data,insn->unused[0]); // Clear software registers - devpriv->b_TimerSelectMode=0; - devpriv->b_ModeSelectRegister=0; - devpriv->us_OutputRegister=0; + devpriv->b_TimerSelectMode = 0; + devpriv->b_ModeSelectRegister = 0; + devpriv->us_OutputRegister = 0; // devpriv->b_DigitalOutputRegister=0; - if(insn->unused[0]==222)// second insn read - { - - for(i=0;i< insn->n;i++) - { - data[i]=devpriv->ui_AiReadData[i]; - } - - } - else - { - devpriv->tsk_Current=current; // Save the current process task structure - //Testing if board have the new Quartz and calculate the time value - //to set in the timer - - us_TmpValue=(USHORT) inw(devpriv->iobase+APCI3120_RD_STATUS); - - //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 - if((us_TmpValue & 0x00B0)==0x00B0 || !strcmp(this_board->pc_DriverName,"apci3001") ) - { - us_ConvertTiming=(us_ConvertTiming * 2) -2; - } - else - { - us_ConvertTiming=((us_ConvertTiming * 12926)/10000) -1; - } - - us_TmpValue=(USHORT)devpriv->b_InterruptMode; - - switch(us_TmpValue) - { - - case APCI3120_EOC_MODE: - - - + if (insn->unused[0] == 222) // second insn read + { + + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ui_AiReadData[i]; + } + + } else { + devpriv->tsk_Current = current; // Save the current process task structure + //Testing if board have the new Quartz and calculate the time value + //to set in the timer + + us_TmpValue = + (USHORT) inw(devpriv->iobase + APCI3120_RD_STATUS); + + //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 + if ((us_TmpValue & 0x00B0) == 0x00B0 + || !strcmp(this_board->pc_DriverName, "apci3001")) { + us_ConvertTiming = (us_ConvertTiming * 2) - 2; + } else { + us_ConvertTiming = + ((us_ConvertTiming * 12926) / 10000) - 1; + } + + us_TmpValue = (USHORT) devpriv->b_InterruptMode; + + switch (us_TmpValue) { + + case APCI3120_EOC_MODE: + // Testing the interrupt flag and set the EOC bit // Clears the FIFO - inw(devpriv->iobase+APCI3120_RESET_FIFO); + inw(devpriv->iobase + APCI3120_RESET_FIFO); - // Initialize the sequence array - //if (!i_APCI3120_SetupChannelList(dev,s,1,chanlist,0)) return -EINVAL; - - if (!i_APCI3120_SetupChannelList(dev,s,1,&insn->chanspec,0)) return -EINVAL; - + //if (!i_APCI3120_SetupChannelList(dev,s,1,chanlist,0)) return -EINVAL; + + if (!i_APCI3120_SetupChannelList(dev, s, 1, + &insn->chanspec, 0)) + return -EINVAL; + //Initialize Timer 0 mode 4 - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode & 0xFC) |APCI3120_TIMER_0_MODE_4; - outb(devpriv->b_TimerSelectMode,devpriv->iobase+APCI3120_TIMER_CRT1); + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0xFC) | + APCI3120_TIMER_0_MODE_4; + outb(devpriv->b_TimerSelectMode, + devpriv->iobase + APCI3120_TIMER_CRT1); // Reset the scan bit and Disables the EOS, DMA, EOC interrupt - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_SCAN; - - if(devpriv->b_EocEosInterrupt==APCI3120_ENABLE) - { - - //Disables the EOS,DMA and enables the EOC interrupt - devpriv->b_ModeSelectRegister=(devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT) | APCI3120_ENABLE_EOC_INT; - inw(devpriv->iobase); - - } - else - { - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER; - } - - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_SCAN; + + if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) { + + //Disables the EOS,DMA and enables the EOC interrupt + devpriv->b_ModeSelectRegister = + (devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_EOS_INT) | + APCI3120_ENABLE_EOC_INT; + inw(devpriv->iobase); + + } else { + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER; + } + + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); // Sets gate 0 - devpriv->us_OutputRegister=(devpriv->us_OutputRegister & APCI3120_CLEAR_PA_PR) | APCI3120_ENABLE_TIMER0; - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); + devpriv->us_OutputRegister = + (devpriv-> + us_OutputRegister & APCI3120_CLEAR_PA_PR) | + APCI3120_ENABLE_TIMER0; + outw(devpriv->us_OutputRegister, + devpriv->iobase + APCI3120_WR_ADDRESS); // Select Timer 0 - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_0_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_0_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); //Set the convertion time - outw(us_ConvertTiming,devpriv->iobase+APCI3120_TIMER_VALUE); + outw(us_ConvertTiming, + devpriv->iobase + APCI3120_TIMER_VALUE); - us_TmpValue=(USHORT) inw(dev->iobase+APCI3120_RD_STATUS); - + us_TmpValue = + (USHORT) inw(dev->iobase + APCI3120_RD_STATUS); - if(devpriv->b_EocEosInterrupt==APCI3120_DISABLE) - { + if (devpriv->b_EocEosInterrupt == APCI3120_DISABLE) { - do - { + do { // Waiting for the end of conversion - us_TmpValue=inw(devpriv->iobase+APCI3120_RD_STATUS); - }while((us_TmpValue & APCI3120_EOC)==APCI3120_EOC); - - //Read the result in FIFO and put it in insn data pointer - us_TmpValue=inw(devpriv->iobase+0); - *data=us_TmpValue; - - inw(devpriv->iobase+APCI3120_RESET_FIFO); - } - - break; - - - case APCI3120_EOS_MODE: - - inw(devpriv->iobase); - // Clears the FIFO - inw(devpriv->iobase+APCI3120_RESET_FIFO); - // clear PA PR and disable timer 0 - - devpriv->us_OutputRegister=(devpriv->us_OutputRegister & APCI3120_CLEAR_PA_PR) | APCI3120_DISABLE_TIMER0; - - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); - - if (!i_APCI3120_SetupChannelList(dev,s,devpriv->ui_AiNbrofChannels,devpriv->ui_AiChannelList,0)) return -EINVAL; + us_TmpValue = + inw(devpriv->iobase + + APCI3120_RD_STATUS); + } while ((us_TmpValue & APCI3120_EOC) == + APCI3120_EOC); + + //Read the result in FIFO and put it in insn data pointer + us_TmpValue = inw(devpriv->iobase + 0); + *data = us_TmpValue; + + inw(devpriv->iobase + APCI3120_RESET_FIFO); + } + + break; + + case APCI3120_EOS_MODE: + + inw(devpriv->iobase); + // Clears the FIFO + inw(devpriv->iobase + APCI3120_RESET_FIFO); + // clear PA PR and disable timer 0 + + devpriv->us_OutputRegister = + (devpriv-> + us_OutputRegister & APCI3120_CLEAR_PA_PR) | + APCI3120_DISABLE_TIMER0; + + outw(devpriv->us_OutputRegister, + devpriv->iobase + APCI3120_WR_ADDRESS); + + if (!i_APCI3120_SetupChannelList(dev, s, + devpriv->ui_AiNbrofChannels, + devpriv->ui_AiChannelList, 0)) + return -EINVAL; //Initialize Timer 0 mode 2 - devpriv->b_TimerSelectMode = (devpriv->b_TimerSelectMode & 0xFC) | APCI3120_TIMER_0_MODE_2; - outb(devpriv->b_TimerSelectMode,devpriv->iobase+APCI3120_TIMER_CRT1); - + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0xFC) | + APCI3120_TIMER_0_MODE_2; + outb(devpriv->b_TimerSelectMode, + devpriv->iobase + APCI3120_TIMER_CRT1); + //Select Timer 0 - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_0_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_0_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + //Set the convertion time - outw(us_ConvertTiming,devpriv->iobase+APCI3120_TIMER_VALUE); - - //Set the scan bit - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister | APCI3120_ENABLE_SCAN; - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); - - //If Interrupt function is loaded - if(devpriv->b_EocEosInterrupt==APCI3120_ENABLE) - { - //Disables the EOC,DMA and enables the EOS interrupt - devpriv->b_ModeSelectRegister=(devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT) | APCI3120_ENABLE_EOS_INT; - inw(devpriv->iobase); - - - } - else - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER; - - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); + outw(us_ConvertTiming, + devpriv->iobase + APCI3120_TIMER_VALUE); - inw(devpriv->iobase+APCI3120_RD_STATUS); - - //Sets gate 0 - - devpriv->us_OutputRegister=devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0; - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); - - //Start conversion - outw(0,devpriv->iobase+APCI3120_START_CONVERSION); - - //Waiting of end of convertion if interrupt is not installed - if(devpriv->b_EocEosInterrupt==APCI3120_DISABLE) - { - //Waiting the end of convertion - do - { - us_TmpValue=inw(devpriv->iobase+APCI3120_RD_STATUS); - } - while((us_TmpValue & APCI3120_EOS)!=APCI3120_EOS); - - for(i=0;i< devpriv->ui_AiNbrofChannels;i++) - { - //Read the result in FIFO and write them in shared memory - us_TmpValue=inw(devpriv->iobase); - data[i]=(UINT) us_TmpValue; - } - - devpriv->b_InterruptMode = APCI3120_EOC_MODE; // Restore defaults. - } - break; - - default: - printk("inputs wrong\n"); - - } - devpriv->ui_EocEosConversionTime=0;// re initializing the variable; - } - - return insn->n; + //Set the scan bit + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister | APCI3120_ENABLE_SCAN; + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + + //If Interrupt function is loaded + if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) { + //Disables the EOC,DMA and enables the EOS interrupt + devpriv->b_ModeSelectRegister = + (devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_EOC_INT) | + APCI3120_ENABLE_EOS_INT; + inw(devpriv->iobase); + + } else + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER; + + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + + inw(devpriv->iobase + APCI3120_RD_STATUS); + + //Sets gate 0 + + devpriv->us_OutputRegister = + devpriv-> + us_OutputRegister | APCI3120_ENABLE_TIMER0; + outw(devpriv->us_OutputRegister, + devpriv->iobase + APCI3120_WR_ADDRESS); + + //Start conversion + outw(0, devpriv->iobase + APCI3120_START_CONVERSION); + + //Waiting of end of convertion if interrupt is not installed + if (devpriv->b_EocEosInterrupt == APCI3120_DISABLE) { + //Waiting the end of convertion + do { + us_TmpValue = + inw(devpriv->iobase + + APCI3120_RD_STATUS); + } + while ((us_TmpValue & APCI3120_EOS) != + APCI3120_EOS); + + for (i = 0; i < devpriv->ui_AiNbrofChannels; + i++) { + //Read the result in FIFO and write them in shared memory + us_TmpValue = inw(devpriv->iobase); + data[i] = (UINT) us_TmpValue; + } + + devpriv->b_InterruptMode = APCI3120_EOC_MODE; // Restore defaults. + } + break; -} + default: + printk("inputs wrong\n"); + } + devpriv->ui_EocEosConversionTime = 0; // re initializing the variable; + } + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -397,50 +409,52 @@ int i_APCI3120_InsnReadAnalogInput(comedi_device *dev, comedi_subdevice *s, +----------------------------------------------------------------------------+ */ -int i_APCI3120_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s) +int i_APCI3120_StopCyclicAcquisition(comedi_device * dev, comedi_subdevice * s) { - // Disable A2P Fifo write and AMWEN signal - outw(0,devpriv->i_IobaseAddon + 4); - - //Disable Bus Master ADD ON - outw(APCI3120_ADD_ON_AGCSTS_LOW,devpriv->i_IobaseAddon+0); - outw(0,devpriv->i_IobaseAddon+2); - outw(APCI3120_ADD_ON_AGCSTS_HIGH,devpriv->i_IobaseAddon+0); - outw(0,devpriv->i_IobaseAddon+2); - - //Disable BUS Master PCI - outl(0,devpriv->i_IobaseAmcc+AMCC_OP_REG_MCSR ); - - //outl(inl(devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR)&(~AINT_WRITE_COMPL), devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); // stop amcc irqs + // Disable A2P Fifo write and AMWEN signal + outw(0, devpriv->i_IobaseAddon + 4); + + //Disable Bus Master ADD ON + outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0); + outw(0, devpriv->i_IobaseAddon + 2); + outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0); + outw(0, devpriv->i_IobaseAddon + 2); + + //Disable BUS Master PCI + outl(0, devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR); + + //outl(inl(devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR)&(~AINT_WRITE_COMPL), devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); // stop amcc irqs //outl(inl(devpriv->i_IobaseAmcc+AMCC_OP_REG_MCSR)&(~EN_A2P_TRANSFERS), devpriv->i_IobaseAmcc+AMCC_OP_REG_MCSR); // stop DMA - //Disable ext trigger i_APCI3120_ExttrigDisable(dev); - devpriv->us_OutputRegister=0; + devpriv->us_OutputRegister = 0; //stop counters - outw(devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER0 & APCI3120_DISABLE_TIMER1,dev->iobase+APCI3120_WR_ADDRESS); - - outw(APCI3120_DISABLE_ALL_TIMER,dev->iobase+APCI3120_WR_ADDRESS); + outw(devpriv-> + us_OutputRegister & APCI3120_DISABLE_TIMER0 & + APCI3120_DISABLE_TIMER1, dev->iobase + APCI3120_WR_ADDRESS); - //DISABLE_ALL_INTERRUPT - outb(APCI3120_DISABLE_ALL_INTERRUPT,dev->iobase+APCI3120_WRITE_MODE_SELECT); + outw(APCI3120_DISABLE_ALL_TIMER, dev->iobase + APCI3120_WR_ADDRESS); + + //DISABLE_ALL_INTERRUPT + outb(APCI3120_DISABLE_ALL_INTERRUPT, + dev->iobase + APCI3120_WRITE_MODE_SELECT); //Flush FIFO - inb(dev->iobase+APCI3120_RESET_FIFO); - inw(dev->iobase+APCI3120_RD_STATUS); - devpriv->ui_AiActualScan=0; - devpriv->ui_AiActualScanPosition=0; - s->async->cur_chan=0; - devpriv->ui_AiBufferPtr=0; - devpriv->b_AiContinuous=0; - devpriv->ui_DmaActualBuffer=0; - - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; - devpriv->b_InterruptMode=APCI3120_EOC_MODE; - devpriv->b_EocEosInterrupt=APCI3120_DISABLE; - i_APCI3120_Reset(dev); - return 0; + inb(dev->iobase + APCI3120_RESET_FIFO); + inw(dev->iobase + APCI3120_RD_STATUS); + devpriv->ui_AiActualScan = 0; + devpriv->ui_AiActualScanPosition = 0; + s->async->cur_chan = 0; + devpriv->ui_AiBufferPtr = 0; + devpriv->b_AiContinuous = 0; + devpriv->ui_DmaActualBuffer = 0; + + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; + devpriv->b_InterruptMode = APCI3120_EOC_MODE; + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + i_APCI3120_Reset(dev); + return 0; } /* @@ -462,153 +476,143 @@ int i_APCI3120_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s) +----------------------------------------------------------------------------+ */ -int i_APCI3120_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) - { - int err=0; - int tmp;// divisor1,divisor2; - +int i_APCI3120_CommandTestAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) +{ + int err = 0; + int tmp; // divisor1,divisor2; + // step 1: make sure trigger sources are trivially valid + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_EXT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; - - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; - //step 2: make sure trigger sources are unique and mutually compatible - if(cmd->start_src!=TRIG_NOW && cmd->start_src!=TRIG_EXT) - { + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) { err++; } + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_FOLLOW) + err++; - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_FOLLOW) err++; + if (cmd->convert_src != TRIG_TIMER) + err++; - if(cmd->convert_src!=TRIG_TIMER ) err++; - - if(cmd->scan_end_src!=TRIG_COUNT) - { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT ) err++; - if(err) return 2; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; + if (err) + return 2; - // step 3: make sure arguments are trivially compatible + // step 3: make sure arguments are trivially compatible - if(cmd->start_arg!=0) - { - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_TIMER) // Test Delay timing - { - if(cmd->scan_begin_argui_MinDelaytimeNs) - { - cmd->scan_begin_arg=this_board->ui_MinDelaytimeNs; + if (cmd->scan_begin_src == TRIG_TIMER) // Test Delay timing + { + if (cmd->scan_begin_arg < this_board->ui_MinDelaytimeNs) { + cmd->scan_begin_arg = this_board->ui_MinDelaytimeNs; err++; } } - - - - if(cmd->convert_src==TRIG_TIMER) // Test Acquisition timing + if (cmd->convert_src == TRIG_TIMER) // Test Acquisition timing { - if (cmd->scan_begin_src==TRIG_TIMER) - { - if((cmd->convert_arg)&&(cmd->convert_argui_MinAcquisitiontimeNs)) - { - cmd->convert_arg=this_board->ui_MinAcquisitiontimeNs; + if (cmd->scan_begin_src == TRIG_TIMER) { + if ((cmd->convert_arg) + && (cmd->convert_arg < + this_board->ui_MinAcquisitiontimeNs)) { + cmd->convert_arg = + this_board->ui_MinAcquisitiontimeNs; err++; - } - } - else - { - if(cmd->convert_argui_MinAcquisitiontimeNs) - { - cmd->convert_arg=this_board->ui_MinAcquisitiontimeNs; + } + } else { + if (cmd->convert_arg < + this_board->ui_MinAcquisitiontimeNs) { + cmd->convert_arg = + this_board->ui_MinAcquisitiontimeNs; err++; } } } - - if(!cmd->chanlist_len) - { - cmd->chanlist_len=1; + if (!cmd->chanlist_len) { + cmd->chanlist_len = 1; err++; } - if(cmd->chanlist_len > this_board->i_AiChannelList) - { - cmd->chanlist_len=this_board->i_AiChannelList; + if (cmd->chanlist_len > this_board->i_AiChannelList) { + cmd->chanlist_len = this_board->i_AiChannelList; err++; } - if(cmd->stop_src==TRIG_COUNT) - { - if(!cmd->stop_arg) - { - cmd->stop_arg=1; + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { + cmd->stop_arg = 1; err++; } - } - else - { // TRIG_NONE - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + } else { // TRIG_NONE + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - - if(err) return 3; - - // step 4: fix up any arguments + if (err) + return 3; + // step 4: fix up any arguments - if(cmd->convert_src==TRIG_TIMER) - { - - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg) - { - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; + if (cmd->convert_src == TRIG_TIMER) { + + 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; - } + if (err) + return 4; + return 0; +} /* +----------------------------------------------------------------------------+ @@ -629,63 +633,58 @@ int i_APCI3120_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,com +----------------------------------------------------------------------------+ */ - int i_APCI3120_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s) -{ - comedi_cmd *cmd=&s->async->cmd; - +int i_APCI3120_CommandAnalogInput(comedi_device * dev, comedi_subdevice * s) +{ + comedi_cmd *cmd = &s->async->cmd; + //loading private structure with cmd structure inputs - devpriv->ui_AiFlags=cmd->flags; - devpriv->ui_AiNbrofChannels=cmd->chanlist_len; - devpriv->ui_AiScanLength=cmd->scan_end_arg; - devpriv->pui_AiChannelList=cmd->chanlist; - + devpriv->ui_AiFlags = cmd->flags; + devpriv->ui_AiNbrofChannels = cmd->chanlist_len; + devpriv->ui_AiScanLength = cmd->scan_end_arg; + devpriv->pui_AiChannelList = cmd->chanlist; + //UPDATE-0.7.57->0.7.68devpriv->AiData=s->async->data; - devpriv->AiData=s->async->prealloc_buf; + devpriv->AiData = s->async->prealloc_buf; //UPDATE-0.7.57->0.7.68devpriv->ui_AiDataLength=s->async->data_len; - devpriv->ui_AiDataLength=s->async->prealloc_bufsz; - - if (cmd->stop_src==TRIG_COUNT) - { - devpriv->ui_AiNbrofScans=cmd->stop_arg; - } - else - { - devpriv->ui_AiNbrofScans=0; + devpriv->ui_AiDataLength = s->async->prealloc_bufsz; + + if (cmd->stop_src == TRIG_COUNT) { + devpriv->ui_AiNbrofScans = cmd->stop_arg; + } else { + devpriv->ui_AiNbrofScans = 0; } - devpriv->ui_AiTimer0=0; // variables changed to timer0,timer1 - devpriv->ui_AiTimer1=0; - if ((devpriv->ui_AiNbrofScans==0)||(devpriv->ui_AiNbrofScans==-1)) - devpriv->b_AiContinuous=1; // user want neverending analog acquisition - // stopped using cancel - - if(cmd->start_src==TRIG_EXT) + devpriv->ui_AiTimer0 = 0; // variables changed to timer0,timer1 + devpriv->ui_AiTimer1 = 0; + if ((devpriv->ui_AiNbrofScans == 0) || (devpriv->ui_AiNbrofScans == -1)) + devpriv->b_AiContinuous = 1; // user want neverending analog acquisition + // stopped using cancel + + if (cmd->start_src == TRIG_EXT) devpriv->b_ExttrigEnable = APCI3120_ENABLE; - else - devpriv->b_ExttrigEnable = APCI3120_DISABLE; - - if(cmd->scan_begin_src==TRIG_FOLLOW) - { + else + devpriv->b_ExttrigEnable = APCI3120_DISABLE; + + if (cmd->scan_begin_src == TRIG_FOLLOW) { // mode 1 or 3 - if (cmd->convert_src==TRIG_TIMER) - { - // mode 1 - - devpriv->ui_AiTimer0=cmd->convert_arg;// timer constant in nano seconds + if (cmd->convert_src == TRIG_TIMER) { + // mode 1 + + devpriv->ui_AiTimer0 = cmd->convert_arg; // timer constant in nano seconds //return this_board->i_hwdrv_CommandAnalogInput(1,dev,s); - return i_APCI3120_CyclicAnalogInput(1,dev,s); + return i_APCI3120_CyclicAnalogInput(1, dev, s); } - + } - if((cmd->scan_begin_src==TRIG_TIMER)&&(cmd->convert_src==TRIG_TIMER)) - { + if ((cmd->scan_begin_src == TRIG_TIMER) + && (cmd->convert_src == TRIG_TIMER)) { // mode 2 - devpriv->ui_AiTimer1=cmd->scan_begin_arg; - devpriv->ui_AiTimer0=cmd->convert_arg;// variable changed timer2 to timer0 - //return this_board->i_hwdrv_CommandAnalogInput(2,dev,s); - return i_APCI3120_CyclicAnalogInput(2,dev,s); + devpriv->ui_AiTimer1 = cmd->scan_begin_arg; + devpriv->ui_AiTimer0 = cmd->convert_arg; // variable changed timer2 to timer0 + //return this_board->i_hwdrv_CommandAnalogInput(2,dev,s); + return i_APCI3120_CyclicAnalogInput(2, dev, s); } - return -1; + return -1; } /* @@ -708,93 +707,95 @@ int i_APCI3120_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,com +----------------------------------------------------------------------------+ */ -int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev,comedi_subdevice * s) -{ +int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev, + comedi_subdevice * s) +{ BYTE b_Tmp; - UINT ui_Tmp,ui_DelayTiming=0,ui_TimerValue1=0,dmalen0=0,dmalen1=0,ui_TimerValue2=0,ui_TimerValue0,ui_ConvertTiming; + UINT ui_Tmp, ui_DelayTiming = 0, ui_TimerValue1 = 0, dmalen0 = + 0, dmalen1 = 0, ui_TimerValue2 = + 0, ui_TimerValue0, ui_ConvertTiming; USHORT us_TmpValue; - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - //devpriv->b_AiCyclicAcquisition=APCI3120_ENABLE; + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //devpriv->b_AiCyclicAcquisition=APCI3120_ENABLE; //END JK 07.05.04: Comparison between WIN32 and Linux driver - + /*******************/ /* Resets the FIFO */ /*******************/ - inb(dev->iobase + APCI3120_RESET_FIFO); - + inb(dev->iobase + APCI3120_RESET_FIFO); + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver //inw(dev->iobase+APCI3120_RD_STATUS); //END JK 07.05.04: Comparison between WIN32 and Linux driver - + /***************************/ /* Acquisition initialized */ - /***************************/ - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - devpriv->b_AiCyclicAcquisition = APCI3120_ENABLE; + /***************************/ + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + devpriv->b_AiCyclicAcquisition = APCI3120_ENABLE; //END JK 07.05.04: Comparison between WIN32 and Linux driver - - // clear software registers - devpriv->b_TimerSelectMode=0; - devpriv->us_OutputRegister=0; - devpriv->b_ModeSelectRegister=0; + // clear software registers + devpriv->b_TimerSelectMode = 0; + devpriv->us_OutputRegister = 0; + devpriv->b_ModeSelectRegister = 0; //devpriv->b_DigitalOutputRegister=0; - - //COMMENT JK 07.05.04: Followings calls are in i_APCI3120_StartAnalogInputAcquisition - + + //COMMENT JK 07.05.04: Followings calls are in i_APCI3120_StartAnalogInputAcquisition + /****************************/ - /* Clear Timer Write TC INT */ + /* Clear Timer Write TC INT */ /****************************/ - outl(APCI3120_CLEAR_WRITE_TC_INT,devpriv->i_IobaseAmcc+ APCI3120_AMCC_OP_REG_INTCSR); + outl(APCI3120_CLEAR_WRITE_TC_INT, + devpriv->i_IobaseAmcc + APCI3120_AMCC_OP_REG_INTCSR); /************************************/ - /* Clears the timer status register */ + /* Clears the timer status register */ /************************************/ - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - //inw(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); - inb(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); - //END JK 07.05.04: Comparison between WIN32 and Linux driver + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //inw(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); + inb(dev->iobase + APCI3120_TIMER_STATUS_REGISTER); + //END JK 07.05.04: Comparison between WIN32 and Linux driver /**************************/ - /* Disables All Timer */ - /* Sets PR and PA to 0 */ - /**************************/ - devpriv->us_OutputRegister = devpriv->us_OutputRegister & - APCI3120_DISABLE_TIMER0 & - APCI3120_DISABLE_TIMER1 & - APCI3120_CLEAR_PA_PR; - - outw(devpriv->us_OutputRegister,dev->iobase + APCI3120_WR_ADDRESS); + /* Disables All Timer */ + /* Sets PR and PA to 0 */ + /**************************/ + devpriv->us_OutputRegister = devpriv->us_OutputRegister & + APCI3120_DISABLE_TIMER0 & + APCI3120_DISABLE_TIMER1 & APCI3120_CLEAR_PA_PR; + + outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS); /*******************/ - /* Resets the FIFO */ + /* Resets the FIFO */ /*******************/ - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - inb (devpriv->iobase + APCI3120_RESET_FIFO); - //END JK 07.05.04: Comparison between WIN32 and Linux driver + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + inb(devpriv->iobase + APCI3120_RESET_FIFO); + //END JK 07.05.04: Comparison between WIN32 and Linux driver - devpriv->ui_AiActualScan=0; - devpriv->ui_AiActualScanPosition=0; - s->async->cur_chan=0; - devpriv->ui_AiBufferPtr=0; - devpriv->ui_DmaActualBuffer=0; + devpriv->ui_AiActualScan = 0; + devpriv->ui_AiActualScanPosition = 0; + s->async->cur_chan = 0; + devpriv->ui_AiBufferPtr = 0; + devpriv->ui_DmaActualBuffer = 0; - // value for timer2 minus -2 has to be done .....dunno y?? - ui_TimerValue2 = devpriv->ui_AiNbrofScans-2; - ui_ConvertTiming=devpriv->ui_AiTimer0; - - if (mode==2) - ui_DelayTiming = devpriv->ui_AiTimer1; + // value for timer2 minus -2 has to be done .....dunno y?? + ui_TimerValue2 = devpriv->ui_AiNbrofScans - 2; + ui_ConvertTiming = devpriv->ui_AiTimer0; + if (mode == 2) + ui_DelayTiming = devpriv->ui_AiTimer1; /**********************************/ - /* Initializes the sequence array */ + /* Initializes the sequence array */ /**********************************/ - if (!i_APCI3120_SetupChannelList(dev, s, devpriv->ui_AiNbrofChannels, devpriv->pui_AiChannelList, 0)) - return -EINVAL; + if (!i_APCI3120_SetupChannelList(dev, s, devpriv->ui_AiNbrofChannels, + devpriv->pui_AiChannelList, 0)) + return -EINVAL; - us_TmpValue=(USHORT) inw(dev->iobase+APCI3120_RD_STATUS); + us_TmpValue = (USHORT) inw(dev->iobase + APCI3120_RD_STATUS); /*** EL241003 : add this section in comment because floats must not be used if((us_TmpValue & 0x00B0)==0x00B0) { @@ -819,330 +820,376 @@ int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev,comedi_subdevice ***********************************************************************************************/ /*** EL241003 Begin : add this section to replace floats calculation by integer calculations **/ //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 - if((us_TmpValue & 0x00B0)==0x00B0 || !strcmp(this_board->pc_DriverName,"apci3001") ) - { - ui_TimerValue0 = ui_ConvertTiming * 2 - 2000; - ui_TimerValue0 = ui_TimerValue0 / 1000; - - if (mode==2) - { - ui_DelayTiming = ui_DelayTiming / 1000; - ui_TimerValue1 = ui_DelayTiming * 2 - 200; - ui_TimerValue1 = ui_TimerValue1 / 100; - } - } - else - { - ui_ConvertTiming = ui_ConvertTiming / 1000; - ui_TimerValue0 = ui_ConvertTiming * 12926 - 10000; - ui_TimerValue0 = ui_TimerValue0 / 10000; - - if (mode == 2) - { - ui_DelayTiming = ui_DelayTiming / 1000; - ui_TimerValue1 = ui_DelayTiming * 12926 -1; - ui_TimerValue1 = ui_TimerValue1 / 1000000; - } - } -/*** EL241003 End ******************************************************************************/ - - if(devpriv->b_ExttrigEnable==APCI3120_ENABLE) - { - i_APCI3120_ExttrigEnable(dev); // activate EXT trigger + if ((us_TmpValue & 0x00B0) == 0x00B0 + || !strcmp(this_board->pc_DriverName, "apci3001")) { + ui_TimerValue0 = ui_ConvertTiming * 2 - 2000; + ui_TimerValue0 = ui_TimerValue0 / 1000; + + if (mode == 2) { + ui_DelayTiming = ui_DelayTiming / 1000; + ui_TimerValue1 = ui_DelayTiming * 2 - 200; + ui_TimerValue1 = ui_TimerValue1 / 100; + } + } else { + ui_ConvertTiming = ui_ConvertTiming / 1000; + ui_TimerValue0 = ui_ConvertTiming * 12926 - 10000; + ui_TimerValue0 = ui_TimerValue0 / 10000; + + if (mode == 2) { + ui_DelayTiming = ui_DelayTiming / 1000; + ui_TimerValue1 = ui_DelayTiming * 12926 - 1; + ui_TimerValue1 = ui_TimerValue1 / 1000000; + } } - switch(mode) - { - case 1: - // init timer0 in mode 2 - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode& 0xFC) | APCI3120_TIMER_0_MODE_2; - outb(devpriv->b_TimerSelectMode,dev->iobase+APCI3120_TIMER_CRT1); +/*** EL241003 End ******************************************************************************/ + + if (devpriv->b_ExttrigEnable == APCI3120_ENABLE) { + i_APCI3120_ExttrigEnable(dev); // activate EXT trigger + } + switch (mode) { + case 1: + // init timer0 in mode 2 + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0xFC) | APCI3120_TIMER_0_MODE_2; + outb(devpriv->b_TimerSelectMode, + dev->iobase + APCI3120_TIMER_CRT1); //Select Timer 0 - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_0_WORD; - outb(b_Tmp,dev->iobase+APCI3120_TIMER_CRT0); + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_0_WORD; + outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0); //Set the convertion time - outw(((USHORT)ui_TimerValue0),dev->iobase+APCI3120_TIMER_VALUE); + outw(((USHORT) ui_TimerValue0), + dev->iobase + APCI3120_TIMER_VALUE); break; - case 2: - // init timer1 in mode 2 - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode& 0xF3) | APCI3120_TIMER_1_MODE_2; - outb(devpriv->b_TimerSelectMode,dev->iobase+APCI3120_TIMER_CRT1); + case 2: + // init timer1 in mode 2 + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0xF3) | APCI3120_TIMER_1_MODE_2; + outb(devpriv->b_TimerSelectMode, + dev->iobase + APCI3120_TIMER_CRT1); //Select Timer 1 - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_1_WORD; - outb(b_Tmp,dev->iobase+APCI3120_TIMER_CRT0); + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_1_WORD; + outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0); //Set the convertion time - outw(((USHORT)ui_TimerValue1),dev->iobase+APCI3120_TIMER_VALUE); + outw(((USHORT) ui_TimerValue1), + dev->iobase + APCI3120_TIMER_VALUE); // init timer0 in mode 2 - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode& 0xFC) | APCI3120_TIMER_0_MODE_2; - outb(devpriv->b_TimerSelectMode,dev->iobase+APCI3120_TIMER_CRT1); - + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0xFC) | APCI3120_TIMER_0_MODE_2; + outb(devpriv->b_TimerSelectMode, + dev->iobase + APCI3120_TIMER_CRT1); + //Select Timer 0 - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_0_WORD; - outb(b_Tmp,dev->iobase+APCI3120_TIMER_CRT0); - - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_0_WORD; + outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0); + //Set the convertion time - outw(((USHORT)ui_TimerValue0),dev->iobase+APCI3120_TIMER_VALUE); + outw(((USHORT) ui_TimerValue0), + dev->iobase + APCI3120_TIMER_VALUE); break; - + } // ##########common for all modes################# /***********************/ /* Clears the SCAN bit */ /***********************/ - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - //devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister | APCI3120_DISABLE_SCAN; - devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & - APCI3120_DISABLE_SCAN; - //END JK 07.05.04: Comparison between WIN32 and Linux driver - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister | APCI3120_DISABLE_SCAN; + devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & + APCI3120_DISABLE_SCAN; + //END JK 07.05.04: Comparison between WIN32 and Linux driver + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); // If DMA is disabled - if(devpriv->us_UseDma==APCI3120_DISABLE) - { + if (devpriv->us_UseDma == APCI3120_DISABLE) { // disable EOC and enable EOS - devpriv->b_InterruptMode=APCI3120_EOS_MODE; - devpriv->b_EocEosInterrupt=APCI3120_ENABLE; + devpriv->b_InterruptMode = APCI3120_EOS_MODE; + devpriv->b_EocEosInterrupt = APCI3120_ENABLE; + + devpriv->b_ModeSelectRegister = + (devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT) | + APCI3120_ENABLE_EOS_INT; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + + if (!devpriv->b_AiContinuous) { + // configure Timer2 For counting EOS + //Reset gate 2 of Timer 2 to disable it (Set Bit D14 to 0) + devpriv->us_OutputRegister = + devpriv-> + us_OutputRegister & APCI3120_DISABLE_TIMER2; + outw(devpriv->us_OutputRegister, + dev->iobase + APCI3120_WR_ADDRESS); + + // DISABLE TIMER INTERRUPT + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_TIMER_INT & 0xEF; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + + //(1) Init timer 2 in mode 0 and write timer value + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0x0F) | + APCI3120_TIMER_2_MODE_0; + outb(devpriv->b_TimerSelectMode, + dev->iobase + APCI3120_TIMER_CRT1); - devpriv->b_ModeSelectRegister = (devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT) | APCI3120_ENABLE_EOS_INT; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - + //Writing LOW WORD + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_LOW_WORD; + outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0); + outw(LOWORD(ui_TimerValue2), + dev->iobase + APCI3120_TIMER_VALUE); - if (!devpriv->b_AiContinuous) - { - // configure Timer2 For counting EOS - //Reset gate 2 of Timer 2 to disable it (Set Bit D14 to 0) - devpriv->us_OutputRegister=devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER2 ; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); - - // DISABLE TIMER INTERRUPT - devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT & 0xEF; - outb(devpriv->b_ModeSelectRegister,dev->iobase + APCI3120_WRITE_MODE_SELECT); - - //(1) Init timer 2 in mode 0 and write timer value - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_0; - outb(devpriv->b_TimerSelectMode,dev->iobase+APCI3120_TIMER_CRT1); - - //Writing LOW WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_LOW_WORD; - outb(b_Tmp,dev->iobase+APCI3120_TIMER_CRT0); - outw(LOWORD(ui_TimerValue2),dev->iobase+APCI3120_TIMER_VALUE); - - //Writing HIGH WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_HIGH_WORD; - outb(b_Tmp,dev->iobase+APCI3120_TIMER_CRT0); - outw(HIWORD(ui_TimerValue2),dev->iobase+APCI3120_TIMER_VALUE); - - //(2) Reset FC_TIMER BIT Clearing timer status register - inb(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); - // enable timer counter and disable watch dog - devpriv->b_ModeSelectRegister=(devpriv->b_ModeSelectRegister| APCI3120_ENABLE_TIMER_COUNTER) & APCI3120_DISABLE_WATCHDOG; - // select EOS clock input for timer 2 - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister| APCI3120_TIMER2_SELECT_EOS; - // Enable timer2 interrupt - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister| APCI3120_ENABLE_TIMER_INT; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - devpriv->b_Timer2Mode=APCI3120_COUNTER; - devpriv->b_Timer2Interrupt=APCI3120_ENABLE; - } - } - else - { - // If DMA Enabled - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - //inw(dev->iobase+0);// reset EOC bit - //END JK 07.05.04: Comparison between WIN32 and Linux driver - devpriv->b_InterruptMode=APCI3120_DMA_MODE; + //Writing HIGH WORD + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_HIGH_WORD; + outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0); + outw(HIWORD(ui_TimerValue2), + dev->iobase + APCI3120_TIMER_VALUE); + + //(2) Reset FC_TIMER BIT Clearing timer status register + inb(dev->iobase + APCI3120_TIMER_STATUS_REGISTER); + // enable timer counter and disable watch dog + devpriv->b_ModeSelectRegister = + (devpriv-> + b_ModeSelectRegister | + APCI3120_ENABLE_TIMER_COUNTER) & + APCI3120_DISABLE_WATCHDOG; + // select EOS clock input for timer 2 + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister | + APCI3120_TIMER2_SELECT_EOS; + // Enable timer2 interrupt + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister | + APCI3120_ENABLE_TIMER_INT; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + devpriv->b_Timer2Mode = APCI3120_COUNTER; + devpriv->b_Timer2Interrupt = APCI3120_ENABLE; + } + } else { + // If DMA Enabled + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //inw(dev->iobase+0);// reset EOC bit + //END JK 07.05.04: Comparison between WIN32 and Linux driver + devpriv->b_InterruptMode = APCI3120_DMA_MODE; /************************************/ - /* Disables the EOC, EOS interrupt */ - /************************************/ - devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & - APCI3120_DISABLE_EOC_INT & - APCI3120_DISABLE_EOS_INT; - - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - - - dmalen0=devpriv->ui_DmaBufferSize[0]; - dmalen1=devpriv->ui_DmaBufferSize[1]; - - if (!devpriv->b_AiContinuous) - { - - if (dmalen0>(devpriv->ui_AiNbrofScans*devpriv->ui_AiScanLength*2)) - { // must we fill full first buffer? - dmalen0=devpriv->ui_AiNbrofScans*devpriv->ui_AiScanLength*2; - } - else - if (dmalen1>(devpriv->ui_AiNbrofScans*devpriv->ui_AiScanLength*2-dmalen0)) // and must we fill full second buffer when first is once filled? - dmalen1=devpriv->ui_AiNbrofScans*devpriv->ui_AiScanLength*2-dmalen0; + /* Disables the EOC, EOS interrupt */ + /************************************/ + devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & + APCI3120_DISABLE_EOC_INT & APCI3120_DISABLE_EOS_INT; + + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + + dmalen0 = devpriv->ui_DmaBufferSize[0]; + dmalen1 = devpriv->ui_DmaBufferSize[1]; + + if (!devpriv->b_AiContinuous) { + + if (dmalen0 > (devpriv->ui_AiNbrofScans * devpriv->ui_AiScanLength * 2)) { // must we fill full first buffer? + dmalen0 = + devpriv->ui_AiNbrofScans * + devpriv->ui_AiScanLength * 2; + } else if (dmalen1 > (devpriv->ui_AiNbrofScans * devpriv->ui_AiScanLength * 2 - dmalen0)) // and must we fill full second buffer when first is once filled? + dmalen1 = + devpriv->ui_AiNbrofScans * + devpriv->ui_AiScanLength * 2 - dmalen0; } - if (devpriv->ui_AiFlags & TRIG_WAKE_EOS) - { - // don't we want wake up every scan? - if (dmalen0>(devpriv->ui_AiScanLength*2)) - { - dmalen0=devpriv->ui_AiScanLength*2; - if (devpriv->ui_AiScanLength&1) dmalen0+=2; + if (devpriv->ui_AiFlags & TRIG_WAKE_EOS) { + // don't we want wake up every scan? + if (dmalen0 > (devpriv->ui_AiScanLength * 2)) { + dmalen0 = devpriv->ui_AiScanLength * 2; + if (devpriv->ui_AiScanLength & 1) + dmalen0 += 2; } - if (dmalen1>(devpriv->ui_AiScanLength*2)) - { - dmalen1=devpriv->ui_AiScanLength*2; - if (devpriv->ui_AiScanLength&1) dmalen1-=2; - if (dmalen1<4) dmalen1=4; + if (dmalen1 > (devpriv->ui_AiScanLength * 2)) { + dmalen1 = devpriv->ui_AiScanLength * 2; + if (devpriv->ui_AiScanLength & 1) + dmalen1 -= 2; + if (dmalen1 < 4) + dmalen1 = 4; } - } - else - { // isn't output buff smaller that our DMA buff? - if (dmalen0>(devpriv->ui_AiDataLength)) - { - dmalen0=devpriv->ui_AiDataLength; + } else { // isn't output buff smaller that our DMA buff? + if (dmalen0 > (devpriv->ui_AiDataLength)) { + dmalen0 = devpriv->ui_AiDataLength; } - if (dmalen1>(devpriv->ui_AiDataLength)) - { - dmalen1=devpriv->ui_AiDataLength; + if (dmalen1 > (devpriv->ui_AiDataLength)) { + dmalen1 = devpriv->ui_AiDataLength; } } - devpriv->ui_DmaBufferUsesize[0]=dmalen0; - devpriv->ui_DmaBufferUsesize[1]=dmalen1; + devpriv->ui_DmaBufferUsesize[0] = dmalen0; + devpriv->ui_DmaBufferUsesize[1] = dmalen1; - //Initialize DMA - + // Set Transfer count enable bit and A2P_fifo reset bit in AGCSTS register //1 - ui_Tmp=AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO ; - outl(ui_Tmp,devpriv->i_IobaseAmcc+AMCC_OP_REG_AGCSTS); - + ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO; + outl(ui_Tmp, devpriv->i_IobaseAmcc + AMCC_OP_REG_AGCSTS); + // changed since 16 bit interface for add on /*********************/ - /* ENABLE BUS MASTER */ - /*********************/ - outw(APCI3120_ADD_ON_AGCSTS_LOW,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,devpriv->i_IobaseAddon+2); - - outw(APCI3120_ADD_ON_AGCSTS_HIGH,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH,devpriv->i_IobaseAddon+2); - + /* ENABLE BUS MASTER */ + /*********************/ + outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW, + devpriv->i_IobaseAddon + 2); + + outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH, + devpriv->i_IobaseAddon + 2); + // TO VERIFIED - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - outw(0x1000,devpriv->i_IobaseAddon+2); - //END JK 07.05.04: Comparison between WIN32 and Linux driver - - //2 No change + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + outw(0x1000, devpriv->i_IobaseAddon + 2); + //END JK 07.05.04: Comparison between WIN32 and Linux driver + + //2 No change // A2P FIFO MANAGEMENT - // A2P fifo reset & transfer control enable + // A2P fifo reset & transfer control enable + /***********************/ + /* A2P FIFO MANAGEMENT */ /***********************/ - /* A2P FIFO MANAGEMENT */ - /***********************/ - outl(APCI3120_A2P_FIFO_MANAGEMENT,devpriv->i_IobaseAmcc + - APCI3120_AMCC_OP_MCSR); + outl(APCI3120_A2P_FIFO_MANAGEMENT, devpriv->i_IobaseAmcc + + APCI3120_AMCC_OP_MCSR); //3 //beginning address of dma buf //The 32 bit address of dma buffer is converted into two 16 bit addresses - // Can done by using _attach and put into into an array + // Can done by using _attach and put into into an array // array used may be for differnet pages - + // DMA Start Adress Low - outw(APCI3120_ADD_ON_MWAR_LOW,devpriv->i_IobaseAddon+0); - outw((devpriv->ul_DmaBufferHw[0]& 0xFFFF),devpriv->i_IobaseAddon+2); + outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0); + outw((devpriv->ul_DmaBufferHw[0] & 0xFFFF), + devpriv->i_IobaseAddon + 2); /*************************/ - /* DMA Start Adress High */ - /*************************/ - outw(APCI3120_ADD_ON_MWAR_HIGH,devpriv->i_IobaseAddon+0); - outw((devpriv->ul_DmaBufferHw[0]/65536),devpriv->i_IobaseAddon+2); + /* DMA Start Adress High */ + /*************************/ + outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0); + outw((devpriv->ul_DmaBufferHw[0] / 65536), + devpriv->i_IobaseAddon + 2); - //4 + //4 // amount of bytes to be transfered set transfer count // used ADDON MWTC register - //commented testing outl(devpriv->ui_DmaBufferUsesize[0], devpriv->i_IobaseAddon+AMCC_OP_REG_AMWTC); + //commented testing outl(devpriv->ui_DmaBufferUsesize[0], devpriv->i_IobaseAddon+AMCC_OP_REG_AMWTC); /**************************/ - /* Nbr of acquisition LOW */ - /**************************/ - outw(APCI3120_ADD_ON_MWTC_LOW,devpriv->i_IobaseAddon + 0); - outw((devpriv->ui_DmaBufferUsesize[0] & 0xFFFF),devpriv->i_IobaseAddon + 2); + /* Nbr of acquisition LOW */ + /**************************/ + outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0); + outw((devpriv->ui_DmaBufferUsesize[0] & 0xFFFF), + devpriv->i_IobaseAddon + 2); /***************************/ - /* Nbr of acquisition HIGH */ + /* Nbr of acquisition HIGH */ /***************************/ - outw(APCI3120_ADD_ON_MWTC_HIGH,devpriv->i_IobaseAddon + 0); - outw((devpriv->ui_DmaBufferUsesize[0]/65536),devpriv->i_IobaseAddon + 2); - - //5 + outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0); + outw((devpriv->ui_DmaBufferUsesize[0] / 65536), + devpriv->i_IobaseAddon + 2); + + //5 // To configure A2P FIFO - // testing outl( FIFO_ADVANCE_ON_BYTE_2,devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); + // testing outl( FIFO_ADVANCE_ON_BYTE_2,devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); /******************/ /* A2P FIFO RESET */ /******************/ // TO VERIFY - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - outl(0x04000000UL, devpriv->i_IobaseAmcc+AMCC_OP_REG_MCSR); - //END JK 07.05.04: Comparison between WIN32 and Linux driver - + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + outl(0x04000000UL, devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR); + //END JK 07.05.04: Comparison between WIN32 and Linux driver + //6 //ENABLE A2P FIFO WRITE AND ENABLE AMWEN // AMWEN_ENABLE | A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03 - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver //outw(3,devpriv->i_IobaseAddon + 4); - //END JK 07.05.04: Comparison between WIN32 and Linux driver + //END JK 07.05.04: Comparison between WIN32 and Linux driver //7 - //initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) + //initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) /***************************************************/ /* A2P FIFO CONFIGURATE, END OF DMA INTERRUPT INIT */ - /***************************************************/ - outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 | APCI3120_ENABLE_WRITE_TC_INT), - devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); + /***************************************************/ + outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 | + APCI3120_ENABLE_WRITE_TC_INT), + devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver /******************************************/ /* ENABLE A2P FIFO WRITE AND ENABLE AMWEN */ - /******************************************/ - outw(3,devpriv->i_IobaseAddon + 4); - //END JK 07.05.04: Comparison between WIN32 and Linux driver - + /******************************************/ + outw(3, devpriv->i_IobaseAddon + 4); + //END JK 07.05.04: Comparison between WIN32 and Linux driver + /******************/ /* A2P FIFO RESET */ /******************/ - //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver - outl(0x04000000UL, devpriv->i_IobaseAmcc+APCI3120_AMCC_OP_MCSR); - //END JK 07.05.04: Comparison between WIN32 and Linux driver - } - - if ((devpriv->us_UseDma==APCI3120_DISABLE) && !devpriv->b_AiContinuous) - { - // set gate 2 to start conversion - devpriv->us_OutputRegister = devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER2; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); - } - - - switch(mode) - { - case 1: - // set gate 0 to start conversion - devpriv->us_OutputRegister = devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); - break; - case 2: - // set gate 0 and gate 1 - devpriv->us_OutputRegister= devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER1; - devpriv->us_OutputRegister= devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); - break; - - } - + //BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver + outl(0x04000000UL, + devpriv->i_IobaseAmcc + APCI3120_AMCC_OP_MCSR); + //END JK 07.05.04: Comparison between WIN32 and Linux driver + } + + if ((devpriv->us_UseDma == APCI3120_DISABLE) + && !devpriv->b_AiContinuous) { + // set gate 2 to start conversion + devpriv->us_OutputRegister = + devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER2; + outw(devpriv->us_OutputRegister, + dev->iobase + APCI3120_WR_ADDRESS); + } + + switch (mode) { + case 1: + // set gate 0 to start conversion + devpriv->us_OutputRegister = + devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0; + outw(devpriv->us_OutputRegister, + dev->iobase + APCI3120_WR_ADDRESS); + break; + case 2: + // set gate 0 and gate 1 + devpriv->us_OutputRegister = + devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER1; + devpriv->us_OutputRegister = + devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0; + outw(devpriv->us_OutputRegister, + dev->iobase + APCI3120_WR_ADDRESS); + break; + + } + return 0; } @@ -1153,7 +1200,6 @@ int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev,comedi_subdevice +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name : int i_APCI3120_Reset(comedi_device *dev) | @@ -1172,63 +1218,60 @@ int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev,comedi_subdevice +----------------------------------------------------------------------------+ */ -int i_APCI3120_Reset(comedi_device *dev) +int i_APCI3120_Reset(comedi_device * dev) { unsigned int i; unsigned short us_TmpValue; - - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; - devpriv->b_EocEosInterrupt=APCI3120_DISABLE; - devpriv->b_InterruptMode=APCI3120_EOC_MODE; - devpriv->ui_EocEosConversionTime=0; // set eoc eos conv time to 0 - devpriv->b_OutputMemoryStatus =0; - // variables used in timer subdevice - devpriv->b_Timer2Mode=0; - devpriv->b_Timer2Interrupt=0; - devpriv->b_ExttrigEnable=0; // Disable ext trigger + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + devpriv->b_InterruptMode = APCI3120_EOC_MODE; + devpriv->ui_EocEosConversionTime = 0; // set eoc eos conv time to 0 + devpriv->b_OutputMemoryStatus = 0; + + // variables used in timer subdevice + devpriv->b_Timer2Mode = 0; + devpriv->b_Timer2Interrupt = 0; + devpriv->b_ExttrigEnable = 0; // Disable ext trigger - /* Disable all interrupts, watchdog for the anolog output */ - devpriv->b_ModeSelectRegister=0; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); + /* Disable all interrupts, watchdog for the anolog output */ + devpriv->b_ModeSelectRegister = 0; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); // Disables all counters, ext trigger and clears PA, PR - devpriv->us_OutputRegister=0; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); + devpriv->us_OutputRegister = 0; + outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS); //Code to set the all anolog o/p channel to 0v //8191 is decimal value for zero(0 v)volt in bipolar mode(default) - outw(8191|APCI3120_ANALOG_OP_CHANNEL_1, dev->iobase+APCI3120_ANALOG_OUTPUT_1);//channel 1 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_2, dev->iobase+APCI3120_ANALOG_OUTPUT_1);//channel 2 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_3, dev->iobase+APCI3120_ANALOG_OUTPUT_1);//channel 3 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_4, dev->iobase+APCI3120_ANALOG_OUTPUT_1);//channel 4 - - outw(8191|APCI3120_ANALOG_OP_CHANNEL_5, dev->iobase+APCI3120_ANALOG_OUTPUT_2);//channel 5 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_6, dev->iobase+APCI3120_ANALOG_OUTPUT_2);//channel 6 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_7, dev->iobase+APCI3120_ANALOG_OUTPUT_2);//channel 7 - outw(8191|APCI3120_ANALOG_OP_CHANNEL_8, dev->iobase+APCI3120_ANALOG_OUTPUT_2);//channel 8 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_1, dev->iobase + APCI3120_ANALOG_OUTPUT_1); //channel 1 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_2, dev->iobase + APCI3120_ANALOG_OUTPUT_1); //channel 2 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_3, dev->iobase + APCI3120_ANALOG_OUTPUT_1); //channel 3 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_4, dev->iobase + APCI3120_ANALOG_OUTPUT_1); //channel 4 + + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_5, dev->iobase + APCI3120_ANALOG_OUTPUT_2); //channel 5 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_6, dev->iobase + APCI3120_ANALOG_OUTPUT_2); //channel 6 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_7, dev->iobase + APCI3120_ANALOG_OUTPUT_2); //channel 7 + outw(8191 | APCI3120_ANALOG_OP_CHANNEL_8, dev->iobase + APCI3120_ANALOG_OUTPUT_2); //channel 8 // Reset digital output to L0W - -//ES05 outb(0x0,dev->iobase+APCI3120_DIGITAL_OUTPUT); + +//ES05 outb(0x0,dev->iobase+APCI3120_DIGITAL_OUTPUT); udelay(10); - inw(dev->iobase+0); //make a dummy read - inb(dev->iobase+APCI3120_RESET_FIFO); // flush FIFO - inw(dev->iobase+APCI3120_RD_STATUS); // flush A/D status register + inw(dev->iobase + 0); //make a dummy read + inb(dev->iobase + APCI3120_RESET_FIFO); // flush FIFO + inw(dev->iobase + APCI3120_RD_STATUS); // flush A/D status register - //code to reset the RAM sequence - for (i=0;i<16;i++) - { - us_TmpValue = i<<8; //select the location - outw(us_TmpValue,dev->iobase+APCI3120_SEQ_RAM_ADDRESS); + //code to reset the RAM sequence + for (i = 0; i < 16; i++) { + us_TmpValue = i << 8; //select the location + outw(us_TmpValue, dev->iobase + APCI3120_SEQ_RAM_ADDRESS); } - return 0; + return 0; } - - - /* +----------------------------------------------------------------------------+ | Function name : int i_APCI3120_SetupChannelList(comedi_device * dev, | @@ -1253,58 +1296,51 @@ int i_APCI3120_Reset(comedi_device *dev) +----------------------------------------------------------------------------+ */ -int i_APCI3120_SetupChannelList(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist,char check) +int i_APCI3120_SetupChannelList(comedi_device * dev, comedi_subdevice * s, + int n_chan, unsigned int *chanlist, char check) { - unsigned int i;//, differencial=0, bipolar=0; - unsigned int gain; - unsigned short us_TmpValue; - - /* correct channel and range number check itself comedi/range.c */ - if (n_chan<1) - { - if (!check) comedi_error(dev,"range/channel list is empty!"); - return 0; - } - - // All is ok, so we can setup channel/range list - if (check) return 1; - - //Code to set the PA and PR...Here it set PA to 0.. - devpriv->us_OutputRegister=devpriv->us_OutputRegister & APCI3120_CLEAR_PA_PR; - devpriv->us_OutputRegister= ((n_chan-1) & 0xf)<<8; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); + unsigned int i; //, differencial=0, bipolar=0; + unsigned int gain; + unsigned short us_TmpValue; - for (i=0; ius_OutputRegister = + devpriv->us_OutputRegister & APCI3120_CLEAR_PA_PR; + devpriv->us_OutputRegister = ((n_chan - 1) & 0xf) << 8; + outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS); + + for (i = 0; i < n_chan; i++) { + // store range list to card + us_TmpValue = CR_CHAN(chanlist[i]); // get channel number; + + if (CR_RANGE(chanlist[i]) < APCI3120_BIPOLAR_RANGES) { + us_TmpValue &= ((~APCI3120_UNIPOLAR) & 0xff); // set bipolar + } else { + us_TmpValue |= APCI3120_UNIPOLAR; // enable unipolar...... } - else - { - us_TmpValue|=APCI3120_UNIPOLAR; // enable unipolar...... - } - - gain=CR_RANGE(chanlist[i]); // get gain number - us_TmpValue|=((gain & 0x03)<<4); //<<4 for G0 and G1 bit in RAM - us_TmpValue|= i<<8; //To select the RAM LOCATION.... - outw(us_TmpValue,dev->iobase+APCI3120_SEQ_RAM_ADDRESS); - - - printk ("\n Gain = %i", (((unsigned char) CR_RANGE(chanlist[i]) & 0x03) << 2)); - printk ("\n Channel = %i", CR_CHAN(chanlist[i])); - printk ("\n Polarity = %i", us_TmpValue & APCI3120_UNIPOLAR); - } - return 1; // we can serve this with scan logic -} - - - + gain = CR_RANGE(chanlist[i]); // get gain number + us_TmpValue |= ((gain & 0x03) << 4); //<<4 for G0 and G1 bit in RAM + us_TmpValue |= i << 8; //To select the RAM LOCATION.... + outw(us_TmpValue, dev->iobase + APCI3120_SEQ_RAM_ADDRESS); + printk("\n Gain = %i", + (((unsigned char)CR_RANGE(chanlist[i]) & 0x03) << 2)); + printk("\n Channel = %i", CR_CHAN(chanlist[i])); + printk("\n Polarity = %i", us_TmpValue & APCI3120_UNIPOLAR); + } + return 1; // we can serve this with scan logic +} /* +----------------------------------------------------------------------------+ @@ -1327,14 +1363,11 @@ int i_APCI3120_SetupChannelList(comedi_device * dev, comedi_subdevice * s, int n int i_APCI3120_ExttrigEnable(comedi_device * dev) { - - devpriv->us_OutputRegister|=APCI3120_ENABLE_EXT_TRIGGER; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); + devpriv->us_OutputRegister |= APCI3120_ENABLE_EXT_TRIGGER; + outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS); return 0; } - - /* +----------------------------------------------------------------------------+ | Function name : int i_APCI3120_ExttrigDisable(comedi_device * dev) | @@ -1354,23 +1387,17 @@ int i_APCI3120_ExttrigEnable(comedi_device * dev) int i_APCI3120_ExttrigDisable(comedi_device * dev) { - devpriv->us_OutputRegister&=~APCI3120_ENABLE_EXT_TRIGGER; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); + devpriv->us_OutputRegister &= ~APCI3120_ENABLE_EXT_TRIGGER; + outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS); return 0; } - - - - - /* +----------------------------------------------------------------------------+ | INTERRUPT FUNCTIONS | +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name : void v_APCI3120_Interrupt(int irq, void *d) | @@ -1392,197 +1419,195 @@ int i_APCI3120_ExttrigDisable(comedi_device * dev) +----------------------------------------------------------------------------+ */ - - void v_APCI3120_Interrupt(int irq, void *d) -{ +void v_APCI3120_Interrupt(int irq, void *d) +{ comedi_device *dev = d; - USHORT int_daq; + USHORT int_daq; - unsigned int int_amcc,ui_Check,i; - USHORT us_TmpValue; - BYTE b_DummyRead; - - comedi_subdevice *s = dev->subdevices + 0; - ui_Check=1; + unsigned int int_amcc, ui_Check, i; + USHORT us_TmpValue; + BYTE b_DummyRead; + comedi_subdevice *s = dev->subdevices + 0; + ui_Check = 1; - int_daq=inw(dev->iobase+APCI3120_RD_STATUS) & 0xf000; // get IRQ reasons - int_amcc=inl(devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); // get AMCC INT register - - - - if ((!int_daq)&&(!(int_amcc&ANY_S593X_INT))) - { - comedi_error(dev,"IRQ from unknow source"); + int_daq = inw(dev->iobase + APCI3120_RD_STATUS) & 0xf000; // get IRQ reasons + int_amcc = inl(devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); // get AMCC INT register + + if ((!int_daq) && (!(int_amcc & ANY_S593X_INT))) { + comedi_error(dev, "IRQ from unknow source"); return; } - - outl(int_amcc|0x00ff0000, devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR);// shutdown IRQ reasons in AMCC - - int_daq = (int_daq >> 12) & 0xF; - - - if(devpriv->b_ExttrigEnable == APCI3120_ENABLE) - { + + outl(int_amcc | 0x00ff0000, devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); // shutdown IRQ reasons in AMCC + + int_daq = (int_daq >> 12) & 0xF; + + if (devpriv->b_ExttrigEnable == APCI3120_ENABLE) { //Disable ext trigger i_APCI3120_ExttrigDisable(dev); devpriv->b_ExttrigEnable = APCI3120_DISABLE; } - //clear the timer 2 interrupt - inb(devpriv->i_IobaseAmcc+ APCI3120_TIMER_STATUS_REGISTER); - - if (int_amcc&MASTER_ABORT_INT) - comedi_error(dev,"AMCC IRQ - MASTER DMA ABORT!"); - if (int_amcc&TARGET_ABORT_INT) - comedi_error(dev,"AMCC IRQ - TARGET DMA ABORT!"); - - // Ckeck if EOC interrupt - if(((int_daq & 0x8) == 0) && (devpriv->b_InterruptMode==APCI3120_EOC_MODE)) - { - if(devpriv->b_EocEosInterrupt==APCI3120_ENABLE) - { - - // Read the AI Value - - devpriv->ui_AiReadData[0]=(UINT)inw(devpriv->iobase+0); - devpriv->b_EocEosInterrupt = APCI3120_DISABLE; - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - } - else - { - //Disable EOC Interrupt - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT; - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); - - } - } + inb(devpriv->i_IobaseAmcc + APCI3120_TIMER_STATUS_REGISTER); + + if (int_amcc & MASTER_ABORT_INT) + comedi_error(dev, "AMCC IRQ - MASTER DMA ABORT!"); + if (int_amcc & TARGET_ABORT_INT) + comedi_error(dev, "AMCC IRQ - TARGET DMA ABORT!"); + + // Ckeck if EOC interrupt + if (((int_daq & 0x8) == 0) + && (devpriv->b_InterruptMode == APCI3120_EOC_MODE)) { + if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) { + + // Read the AI Value + + devpriv->ui_AiReadData[0] = + (UINT) inw(devpriv->iobase + 0); + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } else { + //Disable EOC Interrupt + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT; + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + + } + } + + // Check If EOS interrupt + if ((int_daq & 0x2) && (devpriv->b_InterruptMode == APCI3120_EOS_MODE)) { + + if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) // enable this in without DMA ??? + { + + if (devpriv->b_AiCyclicAcquisition == APCI3120_ENABLE) { + ui_Check = 0; + i_APCI3120_InterruptHandleEos(dev); + devpriv->ui_AiActualScan++; + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister | + APCI3120_ENABLE_EOS_INT; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + + APCI3120_WRITE_MODE_SELECT); + } else { + ui_Check = 0; + for (i = 0; i < devpriv->ui_AiNbrofChannels; + i++) { + us_TmpValue = inw(devpriv->iobase + 0); + devpriv->ui_AiReadData[i] = + (UINT) us_TmpValue; + } + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; + devpriv->b_InterruptMode = APCI3120_EOC_MODE; + + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + + } + + } else { + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + devpriv->b_EocEosInterrupt = APCI3120_DISABLE; //Default settings + devpriv->b_InterruptMode = APCI3120_EOC_MODE; + } + + } + //Timer2 interrupt + if (int_daq & 0x1) { + + switch (devpriv->b_Timer2Mode) { + case APCI3120_COUNTER: + + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT; + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); + + // stop timer 2 + devpriv->us_OutputRegister = + devpriv-> + us_OutputRegister & APCI3120_DISABLE_ALL_TIMER; + outw(devpriv->us_OutputRegister, + dev->iobase + APCI3120_WR_ADDRESS); + + //stop timer 0 and timer 1 + i_APCI3120_StopCyclicAcquisition(dev, s); + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; - - // Check If EOS interrupt - if( (int_daq & 0x2) && (devpriv->b_InterruptMode==APCI3120_EOS_MODE) ) - { - - if(devpriv->b_EocEosInterrupt==APCI3120_ENABLE)// enable this in without DMA ??? - { - - if(devpriv->b_AiCyclicAcquisition==APCI3120_ENABLE) - { - ui_Check=0; - i_APCI3120_InterruptHandleEos(dev); - devpriv->ui_AiActualScan++; - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister | APCI3120_ENABLE_EOS_INT; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - } - else - { - ui_Check=0; - for(i=0;i< devpriv->ui_AiNbrofChannels;i++) - { - us_TmpValue=inw(devpriv->iobase+0); - devpriv->ui_AiReadData[i]=(UINT) us_TmpValue; - } - devpriv->b_EocEosInterrupt = APCI3120_DISABLE; - devpriv->b_InterruptMode=APCI3120_EOC_MODE; - - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - - } - - } - else - { - devpriv->b_ModeSelectRegister= devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - devpriv->b_EocEosInterrupt = APCI3120_DISABLE; //Default settings - devpriv->b_InterruptMode=APCI3120_EOC_MODE; - } - - } - - //Timer2 interrupt - if(int_daq & 0x1) - { - - switch(devpriv->b_Timer2Mode) - { - case APCI3120_COUNTER: - - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; - devpriv->b_ModeSelectRegister= devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT; - outb(devpriv->b_ModeSelectRegister,dev->iobase+APCI3120_WRITE_MODE_SELECT); - - // stop timer 2 - devpriv->us_OutputRegister=devpriv->us_OutputRegister & APCI3120_DISABLE_ALL_TIMER; - outw(devpriv->us_OutputRegister,dev->iobase+APCI3120_WR_ADDRESS); - - //stop timer 0 and timer 1 - i_APCI3120_StopCyclicAcquisition(dev,s); - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; - //UPDATE-0.7.57->0.7.68comedi_done(dev,s); s->async->events |= COMEDI_CB_EOA; - comedi_event(dev,s); - - break; - - - case APCI3120_TIMER: - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - break; - - case APCI3120_WATCHDOG: - - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - break; - - default : - - // disable Timer Interrupt - - devpriv->b_ModeSelectRegister = devpriv-> b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT; - - outb(devpriv->b_ModeSelectRegister, dev->iobase+ APCI3120_WRITE_MODE_SELECT); - - - - - } - - b_DummyRead= inb(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); - - } + comedi_event(dev, s); - - if ((int_daq & 0x4) &&(devpriv->b_InterruptMode == APCI3120_DMA_MODE)) - { - if(devpriv->b_AiCyclicAcquisition==APCI3120_ENABLE) - { - - /****************************/ - /* Clear Timer Write TC INT */ - /****************************/ + break; + + case APCI3120_TIMER: + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + break; - outl(APCI3120_CLEAR_WRITE_TC_INT,devpriv->i_IobaseAmcc+ APCI3120_AMCC_OP_REG_INTCSR); + case APCI3120_WATCHDOG: + + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + break; + + default: + + // disable Timer Interrupt + + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_TIMER_INT; + + outb(devpriv->b_ModeSelectRegister, + dev->iobase + APCI3120_WRITE_MODE_SELECT); - /************************************/ - /* Clears the timer status register */ - /************************************/ - inw(dev->iobase+APCI3120_TIMER_STATUS_REGISTER); - v_APCI3120_InterruptDma(irq,d); // do some data transfer } - else - { - /* Stops the Timer */ - outw(devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER0 & APCI3120_DISABLE_TIMER1,dev->iobase+APCI3120_WR_ADDRESS); - } - } - - return; + b_DummyRead = inb(dev->iobase + APCI3120_TIMER_STATUS_REGISTER); + + } + + if ((int_daq & 0x4) && (devpriv->b_InterruptMode == APCI3120_DMA_MODE)) { + if (devpriv->b_AiCyclicAcquisition == APCI3120_ENABLE) { + + /****************************/ + /* Clear Timer Write TC INT */ + /****************************/ + + outl(APCI3120_CLEAR_WRITE_TC_INT, + devpriv->i_IobaseAmcc + + APCI3120_AMCC_OP_REG_INTCSR); + + /************************************/ + /* Clears the timer status register */ + /************************************/ + inw(dev->iobase + APCI3120_TIMER_STATUS_REGISTER); + v_APCI3120_InterruptDma(irq, d); // do some data transfer + } else { + /* Stops the Timer */ + outw(devpriv-> + us_OutputRegister & APCI3120_DISABLE_TIMER0 & + APCI3120_DISABLE_TIMER1, + dev->iobase + APCI3120_WR_ADDRESS); + } + + } + + return; } /* @@ -1605,7 +1630,6 @@ int i_APCI3120_ExttrigDisable(comedi_device * dev) +----------------------------------------------------------------------------+ */ - /*int i_APCI3120_InterruptHandleEos(comedi_device *dev) { int n_chan,i; @@ -1623,37 +1647,35 @@ int i_APCI3120_ExttrigDisable(comedi_device * dev) async->buf_int_ptr+=n_chan*sizeof(sampl_t); comedi_eos(dev,s); if (s->async->buf_int_ptr>=s->async->data_len) // for buffer rool over - { -*/ /* buffer rollover */ + { +*//* buffer rollover */ /* s->async->buf_int_ptr=0; comedi_eobuf(dev,s); } return 0; -}*/ -int i_APCI3120_InterruptHandleEos(comedi_device *dev) -{ - int n_chan,i; - comedi_subdevice *s=dev->subdevices+0; - int err=1; - - n_chan=devpriv->ui_AiNbrofChannels; - - s->async->events = 0; - - for(i=0;iasync, inw(dev->iobase+0)); - - s->async->events |= COMEDI_CB_EOS; - - if (err==0) - s->async->events |= COMEDI_CB_OVERFLOW; - - comedi_event(dev,s); - - return 0; -} +}*/ +int i_APCI3120_InterruptHandleEos(comedi_device * dev) +{ + int n_chan, i; + comedi_subdevice *s = dev->subdevices + 0; + int err = 1; + + n_chan = devpriv->ui_AiNbrofChannels; + + s->async->events = 0; + + for (i = 0; i < n_chan; i++) + err &= comedi_buf_put(s->async, inw(dev->iobase + 0)); + + s->async->events |= COMEDI_CB_EOS; + if (err == 0) + s->async->events |= COMEDI_CB_OVERFLOW; + comedi_event(dev, s); + + return 0; +} /* +----------------------------------------------------------------------------+ @@ -1674,77 +1696,80 @@ int i_APCI3120_InterruptHandleEos(comedi_device *dev) +----------------------------------------------------------------------------+ */ - void v_APCI3120_InterruptDma(int irq, void *d) +void v_APCI3120_InterruptDma(int irq, void *d) { - comedi_device *dev = d; - comedi_subdevice *s = dev->subdevices + 0; + comedi_device *dev = d; + comedi_subdevice *s = dev->subdevices + 0; unsigned int next_dma_buf, samplesinbuf; - unsigned long low_word,high_word,var; - - UINT ui_Tmp; - samplesinbuf=devpriv->ui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer]-inl(devpriv->i_IobaseAmcc+AMCC_OP_REG_MWTC); - - if (samplesinbufui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer]) - { - comedi_error(dev,"Interrupted DMA transfer!"); + unsigned long low_word, high_word, var; + + UINT ui_Tmp; + samplesinbuf = + devpriv->ui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer] - + inl(devpriv->i_IobaseAmcc + AMCC_OP_REG_MWTC); + + if (samplesinbuf < + devpriv->ui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer]) { + comedi_error(dev, "Interrupted DMA transfer!"); } - if (samplesinbuf & 1) - { - comedi_error(dev,"Odd count of bytes in DMA ring!"); - i_APCI3120_StopCyclicAcquisition(dev,s); - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; + if (samplesinbuf & 1) { + comedi_error(dev, "Odd count of bytes in DMA ring!"); + i_APCI3120_StopCyclicAcquisition(dev, s); + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; return; } - samplesinbuf=samplesinbuf>>1; // number of received samples - if (devpriv->b_DmaDoubleBuffer) - { + samplesinbuf = samplesinbuf >> 1; // number of received samples + if (devpriv->b_DmaDoubleBuffer) { // switch DMA buffers if is used double buffering - next_dma_buf=1-devpriv->ui_DmaActualBuffer; - - ui_Tmp=AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO ; - outl(ui_Tmp,devpriv->i_IobaseAddon+AMCC_OP_REG_AGCSTS); - + next_dma_buf = 1 - devpriv->ui_DmaActualBuffer; + + ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO; + outl(ui_Tmp, devpriv->i_IobaseAddon + AMCC_OP_REG_AGCSTS); + // changed since 16 bit interface for add on - outw(APCI3120_ADD_ON_AGCSTS_LOW,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,devpriv->i_IobaseAddon+2); - outw(APCI3120_ADD_ON_AGCSTS_HIGH,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH ,devpriv->i_IobaseAddon+2); // 0x1000 is out putted in windows driver - - var=devpriv->ul_DmaBufferHw[next_dma_buf]; - low_word=var & 0xffff; - var=devpriv->ul_DmaBufferHw[next_dma_buf]; - high_word=var /65536; - + outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW, + devpriv->i_IobaseAddon + 2); + outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH, devpriv->i_IobaseAddon + 2); // 0x1000 is out putted in windows driver + + var = devpriv->ul_DmaBufferHw[next_dma_buf]; + low_word = var & 0xffff; + var = devpriv->ul_DmaBufferHw[next_dma_buf]; + high_word = var / 65536; + /* DMA Start Adress Low */ - outw(APCI3120_ADD_ON_MWAR_LOW,devpriv->i_IobaseAddon+0); - outw(low_word,devpriv->i_IobaseAddon+2); - + outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0); + outw(low_word, devpriv->i_IobaseAddon + 2); + /* DMA Start Adress High */ - outw(APCI3120_ADD_ON_MWAR_HIGH,devpriv->i_IobaseAddon+0); - outw(high_word,devpriv->i_IobaseAddon+2); - - var=devpriv->ui_DmaBufferUsesize[next_dma_buf]; - low_word=var & 0xffff; - var=devpriv->ui_DmaBufferUsesize[next_dma_buf]; - high_word=var /65536; - + outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0); + outw(high_word, devpriv->i_IobaseAddon + 2); + + var = devpriv->ui_DmaBufferUsesize[next_dma_buf]; + low_word = var & 0xffff; + var = devpriv->ui_DmaBufferUsesize[next_dma_buf]; + high_word = var / 65536; + /* Nbr of acquisition LOW */ - outw(APCI3120_ADD_ON_MWTC_LOW,devpriv->i_IobaseAddon+0); - outw(low_word,devpriv->i_IobaseAddon+2); - + outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0); + outw(low_word, devpriv->i_IobaseAddon + 2); + /* Nbr of acquisition HIGH */ - outw(APCI3120_ADD_ON_MWTC_HIGH,devpriv->i_IobaseAddon+0); - outw(high_word,devpriv->i_IobaseAddon+2); - + outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0); + outw(high_word, devpriv->i_IobaseAddon + 2); + // To configure A2P FIFO // ENABLE A2P FIFO WRITE AND ENABLE AMWEN // AMWEN_ENABLE | A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03 - outw(3,devpriv->i_IobaseAddon + 4); + outw(3, devpriv->i_IobaseAddon + 4); //initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) - outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2| APCI3120_ENABLE_WRITE_TC_INT), devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); - - } + outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 | + APCI3120_ENABLE_WRITE_TC_INT), + devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); + + } /*UPDATE-0.7.57->0.7.68 ptr=(sampl_t *)devpriv->ul_DmaBufferVirtual[devpriv->ui_DmaActualBuffer]; @@ -1782,77 +1807,75 @@ int i_APCI3120_InterruptHandleEos(comedi_device *dev) comedi_done(dev,s); return; } -*/ - if (samplesinbuf) - { - v_APCI3120_InterruptDmaMoveBlock16bit(dev,s,devpriv->ul_DmaBufferVirtual[devpriv->ui_DmaActualBuffer],samplesinbuf); - - if (!(devpriv->ui_AiFlags & TRIG_WAKE_EOS)) - { +*/ + if (samplesinbuf) { + v_APCI3120_InterruptDmaMoveBlock16bit(dev, s, + devpriv->ul_DmaBufferVirtual[devpriv-> + ui_DmaActualBuffer], samplesinbuf); + + if (!(devpriv->ui_AiFlags & TRIG_WAKE_EOS)) { s->async->events |= COMEDI_CB_EOS; - comedi_event(dev,s); - } + comedi_event(dev, s); + } } if (!devpriv->b_AiContinuous) - if ( devpriv->ui_AiActualScan>=devpriv->ui_AiNbrofScans ) - { - // all data sampled - i_APCI3120_StopCyclicAcquisition(dev,s); - devpriv->b_AiCyclicAcquisition=APCI3120_DISABLE; - s->async->events |= COMEDI_CB_EOA; - comedi_event(dev,s); - return; - } - - if (devpriv->b_DmaDoubleBuffer) - { // switch dma buffers - devpriv->ui_DmaActualBuffer=1-devpriv->ui_DmaActualBuffer; - } - else - { + if (devpriv->ui_AiActualScan >= devpriv->ui_AiNbrofScans) { + // all data sampled + i_APCI3120_StopCyclicAcquisition(dev, s); + devpriv->b_AiCyclicAcquisition = APCI3120_DISABLE; + s->async->events |= COMEDI_CB_EOA; + comedi_event(dev, s); + return; + } + + if (devpriv->b_DmaDoubleBuffer) { // switch dma buffers + devpriv->ui_DmaActualBuffer = 1 - devpriv->ui_DmaActualBuffer; + } else { // restart DMA if is not used double buffering - //ADDED REINITIALISE THE DMA - ui_Tmp=AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO ; - outl(ui_Tmp,devpriv->i_IobaseAddon+AMCC_OP_REG_AGCSTS); - + //ADDED REINITIALISE THE DMA + ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO; + outl(ui_Tmp, devpriv->i_IobaseAddon + AMCC_OP_REG_AGCSTS); + // changed since 16 bit interface for add on - outw(APCI3120_ADD_ON_AGCSTS_LOW,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,devpriv->i_IobaseAddon+2); - outw(APCI3120_ADD_ON_AGCSTS_HIGH,devpriv->i_IobaseAddon+0); - outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH ,devpriv->i_IobaseAddon+2); // + outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW, + devpriv->i_IobaseAddon + 2); + outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0); + outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH, devpriv->i_IobaseAddon + 2); // // A2P FIFO MANAGEMENT // A2P fifo reset & transfer control enable - outl(APCI3120_A2P_FIFO_MANAGEMENT,devpriv->i_IobaseAmcc+AMCC_OP_REG_MCSR ); - - var=devpriv->ul_DmaBufferHw[0]; - low_word=var & 0xffff; - var=devpriv->ul_DmaBufferHw[0]; - high_word=var/65536; - outw(APCI3120_ADD_ON_MWAR_LOW,devpriv->i_IobaseAddon+0); - outw(low_word,devpriv->i_IobaseAddon+2); - outw(APCI3120_ADD_ON_MWAR_HIGH,devpriv->i_IobaseAddon+0); - outw(high_word,devpriv->i_IobaseAddon+2); - - var=devpriv->ui_DmaBufferUsesize[0]; - low_word=var & 0xffff;//changed - var=devpriv->ui_DmaBufferUsesize[0]; - high_word=var/65536; - outw(APCI3120_ADD_ON_MWTC_LOW,devpriv->i_IobaseAddon+0); - outw(low_word,devpriv->i_IobaseAddon+2); - outw(APCI3120_ADD_ON_MWTC_HIGH,devpriv->i_IobaseAddon+0); - outw(high_word,devpriv->i_IobaseAddon+2); - + outl(APCI3120_A2P_FIFO_MANAGEMENT, + devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR); + + var = devpriv->ul_DmaBufferHw[0]; + low_word = var & 0xffff; + var = devpriv->ul_DmaBufferHw[0]; + high_word = var / 65536; + outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0); + outw(low_word, devpriv->i_IobaseAddon + 2); + outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0); + outw(high_word, devpriv->i_IobaseAddon + 2); + + var = devpriv->ui_DmaBufferUsesize[0]; + low_word = var & 0xffff; //changed + var = devpriv->ui_DmaBufferUsesize[0]; + high_word = var / 65536; + outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0); + outw(low_word, devpriv->i_IobaseAddon + 2); + outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0); + outw(high_word, devpriv->i_IobaseAddon + 2); // To configure A2P FIFO //ENABLE A2P FIFO WRITE AND ENABLE AMWEN // AMWEN_ENABLE | A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03 - outw(3,devpriv->i_IobaseAddon + 4); + outw(3, devpriv->i_IobaseAddon + 4); //initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) - outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2| APCI3120_ENABLE_WRITE_TC_INT), devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR); + outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 | + APCI3120_ENABLE_WRITE_TC_INT), + devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); } } - /* +----------------------------------------------------------------------------+ | Function name :void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device| @@ -1902,19 +1925,17 @@ int i_APCI3120_InterruptHandleEos(comedi_device *dev) } */ -void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device *dev,comedi_subdevice *s,sampl_t *dma_buffer,unsigned int num_samples) +void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device * dev, + comedi_subdevice * s, sampl_t * dma_buffer, unsigned int num_samples) { - devpriv->ui_AiActualScan += (s->async->cur_chan + num_samples) / devpriv->ui_AiScanLength; + devpriv->ui_AiActualScan += + (s->async->cur_chan + num_samples) / devpriv->ui_AiScanLength; s->async->cur_chan += num_samples; s->async->cur_chan %= devpriv->ui_AiScanLength; - - cfc_write_array_to_buffer(s, dma_buffer, num_samples * sizeof(sampl_t)); -} - - + cfc_write_array_to_buffer(s, dma_buffer, num_samples * sizeof(sampl_t)); +} - /* +----------------------------------------------------------------------------+ | TIMER SUBDEVICE | @@ -1946,56 +1967,64 @@ void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device *dev,comedi_subdevice * +----------------------------------------------------------------------------+ */ - -int i_APCI3120_InsnConfigTimer(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnConfigTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { UINT ui_Timervalue2; - USHORT us_TmpValue; + USHORT us_TmpValue; BYTE b_Tmp; - - - if(!data[1]) comedi_error(dev,"config:No timer constant !"); - - devpriv->b_Timer2Interrupt=(BYTE)data[2]; // save info whether to enable or disable interrupt - - ui_Timervalue2=data[1]/1000; // convert nano seconds to u seconds - + + if (!data[1]) + comedi_error(dev, "config:No timer constant !"); + + devpriv->b_Timer2Interrupt = (BYTE) data[2]; // save info whether to enable or disable interrupt + + ui_Timervalue2 = data[1] / 1000; // convert nano seconds to u seconds + //this_board->i_hwdrv_InsnConfigTimer(dev, ui_Timervalue2,(BYTE)data[0]); - us_TmpValue=(USHORT) inw(devpriv->iobase+APCI3120_RD_STATUS); - + us_TmpValue = (USHORT) inw(devpriv->iobase + APCI3120_RD_STATUS); + //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 // and calculate the time value to set in the timer - if((us_TmpValue & 0x00B0)==0x00B0 || !strcmp(this_board->pc_DriverName,"apci3001") ) - { + if ((us_TmpValue & 0x00B0) == 0x00B0 + || !strcmp(this_board->pc_DriverName, "apci3001")) { //Calculate the time value to set in the timer - ui_Timervalue2=ui_Timervalue2 / 50; - } - else - { + ui_Timervalue2 = ui_Timervalue2 / 50; + } else { //Calculate the time value to set in the timer - ui_Timervalue2=ui_Timervalue2 / 70; + ui_Timervalue2 = ui_Timervalue2 / 70; } - + //Reset gate 2 of Timer 2 to disable it (Set Bit D14 to 0) - devpriv->us_OutputRegister=devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER2 ; - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); - + devpriv->us_OutputRegister = + devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER2; + outw(devpriv->us_OutputRegister, devpriv->iobase + APCI3120_WR_ADDRESS); + // Disable TIMER Interrupt - devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT & 0xEF; - + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT & 0xEF; + // Disable Eoc and Eos Interrupts - devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT & APCI3120_DISABLE_EOS_INT; - outb(devpriv->b_ModeSelectRegister,devpriv->iobase + APCI3120_WRITE_MODE_SELECT); - if(data[0]==APCI3120_TIMER)//initialize timer + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT & + APCI3120_DISABLE_EOS_INT; + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + if (data[0] == APCI3120_TIMER) //initialize timer { //devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister| APCI3120_ENABLE_TIMER_INT ; //outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); //Set the Timer 2 in mode 2(Timer) - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_2; - outb(devpriv->b_TimerSelectMode,devpriv->iobase + APCI3120_TIMER_CRT1); + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_2; + outb(devpriv->b_TimerSelectMode, + devpriv->iobase + APCI3120_TIMER_CRT1); //Configure the timer 2 for writing the LOW WORD of timer is Delay value //You must make a b_tmp variable with DigitalOutPutRegister because at Address_1+APCI3120_TIMER_CRT0 @@ -2003,26 +2032,33 @@ int i_APCI3120_InsnConfigTimer(comedi_device *dev,comedi_subdevice *s,comedi_ins //are erase (Set to 0) //Writing LOW WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_LOW_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - outw(LOWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_LOW_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + outw(LOWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); + //Writing HIGH WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_HIGH_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - outw(HIWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_HIGH_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + outw(HIWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); // timer2 in Timer mode enabled - devpriv->b_Timer2Mode=APCI3120_TIMER; - - } - else // Initialize Watch dog + devpriv->b_Timer2Mode = APCI3120_TIMER; + + } else // Initialize Watch dog { - - + //Set the Timer 2 in mode 5(Watchdog) - devpriv->b_TimerSelectMode=(devpriv->b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_5; - outb(devpriv->b_TimerSelectMode,devpriv->iobase + APCI3120_TIMER_CRT1); + devpriv->b_TimerSelectMode = + (devpriv-> + b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_5; + outb(devpriv->b_TimerSelectMode, + devpriv->iobase + APCI3120_TIMER_CRT1); //Configure the timer 2 for writing the LOW WORD of timer is Delay value //You must make a b_tmp variable with DigitalOutPutRegister because at Address_1+APCI3120_TIMER_CRT0 @@ -2030,25 +2066,29 @@ int i_APCI3120_InsnConfigTimer(comedi_device *dev,comedi_subdevice *s,comedi_ins //are erase (Set to 0) //Writing LOW WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_LOW_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - outw(LOWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_LOW_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + outw(LOWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); + //Writing HIGH WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_HIGH_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_HIGH_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); - outw(HIWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); + outw(HIWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); //watchdog enabled - devpriv->b_Timer2Mode=APCI3120_WATCHDOG; - - } + devpriv->b_Timer2Mode = APCI3120_WATCHDOG; - - return insn->n; + } -} + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -2078,144 +2118,165 @@ int i_APCI3120_InsnConfigTimer(comedi_device *dev,comedi_subdevice *s,comedi_ins +----------------------------------------------------------------------------+ */ - -int i_APCI3120_InsnWriteTimer(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnWriteTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - - UINT ui_Timervalue2=0; - USHORT us_TmpValue; + + UINT ui_Timervalue2 = 0; + USHORT us_TmpValue; BYTE b_Tmp; - - if((devpriv->b_Timer2Mode!=APCI3120_WATCHDOG) && (devpriv->b_Timer2Mode!=APCI3120_TIMER)) - { - comedi_error(dev,"\nwrite:timer2 not configured "); - return -EINVAL; + if ((devpriv->b_Timer2Mode != APCI3120_WATCHDOG) + && (devpriv->b_Timer2Mode != APCI3120_TIMER)) { + comedi_error(dev, "\nwrite:timer2 not configured "); + return -EINVAL; } - if(data[0]==2) // write new value + if (data[0] == 2) // write new value { - if(devpriv->b_Timer2Mode!=APCI3120_TIMER) - { - comedi_error(dev,"write :timer2 not configured in TIMER MODE"); + if (devpriv->b_Timer2Mode != APCI3120_TIMER) { + comedi_error(dev, + "write :timer2 not configured in TIMER MODE"); return -EINVAL; } - if(data[1]) ui_Timervalue2=data[1]; - else ui_Timervalue2=0; + if (data[1]) + ui_Timervalue2 = data[1]; + else + ui_Timervalue2 = 0; } - - + //this_board->i_hwdrv_InsnWriteTimer(dev,data[0],ui_Timervalue2); - - switch(data[0]) - { - case APCI3120_START: - - // Reset FC_TIMER BIT - inb(devpriv->iobase+APCI3120_TIMER_STATUS_REGISTER); - if(devpriv->b_Timer2Mode==APCI3120_TIMER) //start timer - { - //Enable Timer - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & 0x0B; - } - else //start watch dog - { - //Enable WatchDog - devpriv->b_ModeSelectRegister=(devpriv->b_ModeSelectRegister & 0x0B) | APCI3120_ENABLE_WATCHDOG; - } - - //enable disable interrupt - if((devpriv->b_Timer2Interrupt)==APCI3120_ENABLE) - { - - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister| APCI3120_ENABLE_TIMER_INT ; - // save the task structure to pass info to user - devpriv->tsk_Current=current; - } - else - { - - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT; - } - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); - - - if(devpriv->b_Timer2Mode==APCI3120_TIMER) //start timer - { - //For Timer mode is Gate2 must be activated **timer started - devpriv->us_OutputRegister=devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER2; - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); - } - - break; - case APCI3120_STOP: - if(devpriv->b_Timer2Mode==APCI3120_TIMER) - { - //Disable timer - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_TIMER_COUNTER; - } - else - { - //Disable WatchDog - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_WATCHDOG; - } - // Disable timer interrupt - devpriv->b_ModeSelectRegister=devpriv->b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT; - - // Write above states to register - outb(devpriv->b_ModeSelectRegister,devpriv->iobase+APCI3120_WRITE_MODE_SELECT); - - // Reset Gate 2 - devpriv->us_OutputRegister=devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER_INT ; - outw(devpriv->us_OutputRegister,devpriv->iobase+APCI3120_WR_ADDRESS); - - // Reset FC_TIMER BIT - inb(devpriv->iobase+APCI3120_TIMER_STATUS_REGISTER); - - // Disable timer - //devpriv->b_Timer2Mode=APCI3120_DISABLE; - - break; + switch (data[0]) { + case APCI3120_START: - case 2: //write new value to Timer - if( devpriv->b_Timer2Mode!=APCI3120_TIMER) - { - comedi_error(dev,"write :timer2 not configured in TIMER MODE"); - return -EINVAL; - } - // ui_Timervalue2=data[1]; // passed as argument - us_TmpValue=(USHORT) inw(devpriv->iobase+APCI3120_RD_STATUS); - - //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 - // and calculate the time value to set in the timer - if((us_TmpValue & 0x00B0)==0x00B0 || !strcmp(this_board->pc_DriverName,"apci3001") ) - { - //Calculate the time value to set in the timer - ui_Timervalue2=ui_Timervalue2 / 50; - } - else - { + // Reset FC_TIMER BIT + inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER); + if (devpriv->b_Timer2Mode == APCI3120_TIMER) //start timer + { + //Enable Timer + devpriv->b_ModeSelectRegister = + devpriv->b_ModeSelectRegister & 0x0B; + } else //start watch dog + { + //Enable WatchDog + devpriv->b_ModeSelectRegister = + (devpriv-> + b_ModeSelectRegister & 0x0B) | + APCI3120_ENABLE_WATCHDOG; + } + + //enable disable interrupt + if ((devpriv->b_Timer2Interrupt) == APCI3120_ENABLE) { + + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister | + APCI3120_ENABLE_TIMER_INT; + // save the task structure to pass info to user + devpriv->tsk_Current = current; + } else { + + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_TIMER_INT; + } + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + + if (devpriv->b_Timer2Mode == APCI3120_TIMER) //start timer + { + //For Timer mode is Gate2 must be activated **timer started + devpriv->us_OutputRegister = + devpriv-> + us_OutputRegister | APCI3120_ENABLE_TIMER2; + outw(devpriv->us_OutputRegister, + devpriv->iobase + APCI3120_WR_ADDRESS); + } + + break; + + case APCI3120_STOP: + if (devpriv->b_Timer2Mode == APCI3120_TIMER) { + //Disable timer + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_TIMER_COUNTER; + } else { + //Disable WatchDog + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & + APCI3120_DISABLE_WATCHDOG; + } + // Disable timer interrupt + devpriv->b_ModeSelectRegister = + devpriv-> + b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT; + + // Write above states to register + outb(devpriv->b_ModeSelectRegister, + devpriv->iobase + APCI3120_WRITE_MODE_SELECT); + + // Reset Gate 2 + devpriv->us_OutputRegister = + devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER_INT; + outw(devpriv->us_OutputRegister, + devpriv->iobase + APCI3120_WR_ADDRESS); + + // Reset FC_TIMER BIT + inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER); + + // Disable timer + //devpriv->b_Timer2Mode=APCI3120_DISABLE; + + break; + + case 2: //write new value to Timer + if (devpriv->b_Timer2Mode != APCI3120_TIMER) { + comedi_error(dev, + "write :timer2 not configured in TIMER MODE"); + return -EINVAL; + } + // ui_Timervalue2=data[1]; // passed as argument + us_TmpValue = + (USHORT) inw(devpriv->iobase + APCI3120_RD_STATUS); + + //EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 + // and calculate the time value to set in the timer + if ((us_TmpValue & 0x00B0) == 0x00B0 + || !strcmp(this_board->pc_DriverName, "apci3001")) { //Calculate the time value to set in the timer - ui_Timervalue2=ui_Timervalue2 / 70; - } - //Writing LOW WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_LOW_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); + ui_Timervalue2 = ui_Timervalue2 / 50; + } else { + //Calculate the time value to set in the timer + ui_Timervalue2 = ui_Timervalue2 / 70; + } + //Writing LOW WORD + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_LOW_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); - outw(LOWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); - - //Writing HIGH WORD - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_HIGH_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - - outw(HIWORD(ui_Timervalue2),devpriv->iobase+APCI3120_TIMER_VALUE); + outw(LOWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); - break; - default: - return -EINVAL;// Not a valid input - } + //Writing HIGH WORD + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_HIGH_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + + outw(HIWORD(ui_Timervalue2), + devpriv->iobase + APCI3120_TIMER_VALUE); + + break; + default: + return -EINVAL; // Not a valid input + } return insn->n; } @@ -2243,61 +2304,60 @@ int i_APCI3120_InsnWriteTimer(comedi_device *dev,comedi_subdevice *s, comedi_ins | | +----------------------------------------------------------------------------+ */ -int i_APCI3120_InsnReadTimer(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +int i_APCI3120_InsnReadTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - BYTE b_Tmp; - USHORT us_TmpValue,us_TmpValue_2,us_StatusValue; - - - if((devpriv->b_Timer2Mode!=APCI3120_WATCHDOG) && (devpriv->b_Timer2Mode!=APCI3120_TIMER)) - { - comedi_error(dev,"\nread:timer2 not configured "); + BYTE b_Tmp; + USHORT us_TmpValue, us_TmpValue_2, us_StatusValue; + + if ((devpriv->b_Timer2Mode != APCI3120_WATCHDOG) + && (devpriv->b_Timer2Mode != APCI3120_TIMER)) { + comedi_error(dev, "\nread:timer2 not configured "); } - //this_board->i_hwdrv_InsnReadTimer(dev,data); - if(devpriv->b_Timer2Mode==APCI3120_TIMER) - { - + if (devpriv->b_Timer2Mode == APCI3120_TIMER) { + //Read the LOW WORD of Timer 2 register - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_LOW_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - - us_TmpValue=inw(devpriv->iobase+APCI3120_TIMER_VALUE); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_LOW_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + + us_TmpValue = inw(devpriv->iobase + APCI3120_TIMER_VALUE); + //Read the HIGH WORD of Timer 2 register - b_Tmp=((devpriv->b_DigitalOutputRegister) & 0xF0) | APCI3120_SELECT_TIMER_2_HIGH_WORD; - outb(b_Tmp,devpriv->iobase+APCI3120_TIMER_CRT0); - - us_TmpValue_2=inw(devpriv->iobase+APCI3120_TIMER_VALUE); - + b_Tmp = ((devpriv-> + b_DigitalOutputRegister) & 0xF0) | + APCI3120_SELECT_TIMER_2_HIGH_WORD; + outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0); + + us_TmpValue_2 = inw(devpriv->iobase + APCI3120_TIMER_VALUE); + // combining both words - data[0]=(UINT) ( (us_TmpValue)|((us_TmpValue_2)<<16)); + data[0] = (UINT) ((us_TmpValue) | ((us_TmpValue_2) << 16)); - } - else // Read watch dog status + } else // Read watch dog status { - - us_StatusValue= inw(devpriv->iobase+APCI3120_RD_STATUS); - us_StatusValue=((us_StatusValue & APCI3120_FC_TIMER) >> 12) & 1; - if(us_StatusValue==1) - { + + us_StatusValue = inw(devpriv->iobase + APCI3120_RD_STATUS); + us_StatusValue = + ((us_StatusValue & APCI3120_FC_TIMER) >> 12) & 1; + if (us_StatusValue == 1) { // RESET FC_TIMER BIT - inb(devpriv->iobase+APCI3120_TIMER_STATUS_REGISTER); + inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER); } - data[0]= us_StatusValue;// when data[0] = 1 then the watch dog has rundown + data[0] = us_StatusValue; // when data[0] = 1 then the watch dog has rundown } - return insn->n; + return insn->n; } - /* +----------------------------------------------------------------------------+ | DIGITAL INPUT SUBDEVICE | +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3120_InsnReadDigitalInput(comedi_device *dev, | @@ -2318,34 +2378,28 @@ int i_APCI3120_InsnReadTimer(comedi_device *dev,comedi_subdevice *s,comedi_insn +----------------------------------------------------------------------------+ */ +int i_APCI3120_InsnReadDigitalInput(comedi_device * dev, comedi_subdevice + * s, comedi_insn * insn, lsampl_t * data) +{ + UINT ui_Chan, ui_TmpValue; + ui_Chan = CR_CHAN(insn->chanspec); // channel specified + //this_board->i_hwdrv_InsnReadDigitalInput(dev,ui_Chan,data); + if (ui_Chan >= 0 && ui_Chan <= 3) { + ui_TmpValue = (UINT) inw(devpriv->iobase + APCI3120_RD_STATUS); -int i_APCI3120_InsnReadDigitalInput(comedi_device *dev,comedi_subdevice - *s, comedi_insn *insn,lsampl_t *data) - { - UINT ui_Chan,ui_TmpValue; - - ui_Chan = CR_CHAN(insn->chanspec); // channel specified - - //this_board->i_hwdrv_InsnReadDigitalInput(dev,ui_Chan,data); - if(ui_Chan >= 0 && ui_Chan <= 3) - { - ui_TmpValue=(UINT) inw(devpriv->iobase + APCI3120_RD_STATUS); - - // since only 1 channel reqd to bring it to last bit it is rotated + // since only 1 channel reqd to bring it to last bit it is rotated // 8 +(chan - 1) times then ANDed with 1 for last bit. *data = (ui_TmpValue >> (ui_Chan + 8)) & 1; //return 0; + } else { + // comedi_error(dev," chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " } - else - { - // comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - } - return insn->n; + return insn->n; - } +} /* +----------------------------------------------------------------------------+ @@ -2366,18 +2420,18 @@ int i_APCI3120_InsnReadDigitalInput(comedi_device *dev,comedi_subdevice | | +----------------------------------------------------------------------------+ */ -int i_APCI3120_InsnBitsDigitalInput(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnBitsDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_TmpValue; - ui_TmpValue=(UINT) inw(devpriv->iobase+APCI3120_RD_STATUS); + UINT ui_TmpValue; + ui_TmpValue = (UINT) inw(devpriv->iobase + APCI3120_RD_STATUS); /***** state of 4 channels in the 11, 10, 9, 8 bits of status reg rotated right 8 times to bring them to last four bits ANDed with oxf for value. *****/ - - *data=(ui_TmpValue >>8) & 0xf; - //this_board->i_hwdrv_InsnBitsDigitalInput(dev,data); + + *data = (ui_TmpValue >> 8) & 0xf; + //this_board->i_hwdrv_InsnBitsDigitalInput(dev,data); return insn->n; } @@ -2405,37 +2459,29 @@ int i_APCI3120_InsnBitsDigitalInput(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ - - -int i_APCI3120_InsnConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnConfigDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - - if ( (data[0]!=0) && (data[0]!=1) ) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); + + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); return -EINVAL; } - if(data[0]) - { - devpriv->b_OutputMemoryStatus = APCI3120_ENABLE; - - } - else - { - devpriv->b_OutputMemoryStatus = APCI3120_DISABLE; - devpriv -> b_DigitalOutputRegister = 0; + if (data[0]) { + devpriv->b_OutputMemoryStatus = APCI3120_ENABLE; + + } else { + devpriv->b_OutputMemoryStatus = APCI3120_DISABLE; + devpriv->b_DigitalOutputRegister = 0; } - if(!devpriv->b_OutputMemoryStatus ) - { - ui_Temp=0; - - }//if(!devpriv->b_OutputMemoryStatus ) - - return insn->n; -} + if (!devpriv->b_OutputMemoryStatus) { + ui_Temp = 0; + } //if(!devpriv->b_OutputMemoryStatus ) + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -2459,33 +2505,32 @@ int i_APCI3120_InsnConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ - -int i_APCI3120_InsnBitsDigitalOutput(comedi_device *dev,comedi_subdevice - *s, comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnBitsDigitalOutput(comedi_device * dev, comedi_subdevice + * s, comedi_insn * insn, lsampl_t * data) { - if ((data[0] > this_board->i_DoMaxdata) || (data[0]<0)) - { - - comedi_error(dev,"Data is not valid !!! \n"); + if ((data[0] > this_board->i_DoMaxdata) || (data[0] < 0)) { + + comedi_error(dev, "Data is not valid !!! \n"); return -EINVAL; } - - - switch(data[1]) - { - case 1 :data[0]=(data[0]<<4)|devpriv -> b_DigitalOutputRegister; - break; - - case 2 :data[0]=data[0]; - break; - default :printk("\nThe parameter passed is in error \n"); - return -EINVAL; - }// switch(data[1]) - outb(data[0], devpriv->iobase + APCI3120_DIGITAL_OUTPUT); - - devpriv->b_DigitalOutputRegister = data[0]&0xF0; - - return insn->n; + + switch (data[1]) { + case 1: + data[0] = (data[0] << 4) | devpriv->b_DigitalOutputRegister; + break; + + case 2: + data[0] = data[0]; + break; + default: + printk("\nThe parameter passed is in error \n"); + return -EINVAL; + } // switch(data[1]) + outb(data[0], devpriv->iobase + APCI3120_DIGITAL_OUTPUT); + + devpriv->b_DigitalOutputRegister = data[0] & 0xF0; + + return insn->n; } @@ -2511,72 +2556,65 @@ int i_APCI3120_InsnBitsDigitalOutput(comedi_device *dev,comedi_subdevice +----------------------------------------------------------------------------+ */ - -int i_APCI3120_InsnWriteDigitalOutput(comedi_device *dev,comedi_subdevice - *s,comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnWriteDigitalOutput(comedi_device * dev, comedi_subdevice + * s, comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp1; - - UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - - if ( (data[0]!=0) && (data[0]!=1) ) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); + UINT ui_Temp1; + + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); return -EINVAL; } - if ( (ui_NoOfChannel > (this_board->i_NbrDoChannel-1)) || (ui_NoOfChannel < 0) ) - { - comedi_error(dev,"This board doesn't have specified channel !!! \n"); + if ((ui_NoOfChannel > (this_board->i_NbrDoChannel - 1)) + || (ui_NoOfChannel < 0)) { + comedi_error(dev, + "This board doesn't have specified channel !!! \n"); return -EINVAL; } - - - - switch(data[1]) - { - case 1 :data[0]=(data[0] << ui_NoOfChannel); + + switch (data[1]) { + case 1: + data[0] = (data[0] << ui_NoOfChannel); //ES05 data[0]=(data[0]<<4)|ui_Temp; - data[0]=(data[0]<<4)|devpriv -> b_DigitalOutputRegister; - break; - - case 2 : - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<b_DigitalOutputRegister; + break; + + case 2: + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp1 = ui_Temp1 << 4; //ES05 ui_Temp=ui_Temp|ui_Temp1; - devpriv -> b_DigitalOutputRegister = - devpriv -> b_DigitalOutputRegister | ui_Temp1; + devpriv->b_DigitalOutputRegister = + devpriv->b_DigitalOutputRegister | ui_Temp1; - data[0]=(data[0] << ui_NoOfChannel)^0xf; - data[0]=data[0]<<4; + data[0] = (data[0] << ui_NoOfChannel) ^ 0xf; + data[0] = data[0] << 4; //ES05 data[0]=data[0]& ui_Temp; - data[0]=data[0] & devpriv -> b_DigitalOutputRegister; - break; - default :printk("\nThe parameter passed is in error \n"); - return -EINVAL; - }// switch(data[1]) - outb(data[0], devpriv->iobase + APCI3120_DIGITAL_OUTPUT); - + data[0] = data[0] & devpriv->b_DigitalOutputRegister; + break; + default: + printk("\nThe parameter passed is in error \n"); + return -EINVAL; + } // switch(data[1]) + outb(data[0], devpriv->iobase + APCI3120_DIGITAL_OUTPUT); + //ES05 ui_Temp=data[0] & 0xf0; - devpriv -> b_DigitalOutputRegister = data[0] & 0xf0; + devpriv->b_DigitalOutputRegister = data[0] & 0xf0; return (insn->n); } - - - - - /* +----------------------------------------------------------------------------+ | ANALOG OUTPUT SUBDEVICE | +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3120_InsnWriteAnalogOutput(comedi_device *dev,| @@ -2596,51 +2634,55 @@ int i_APCI3120_InsnWriteDigitalOutput(comedi_device *dev,comedi_subdevice +----------------------------------------------------------------------------+ */ -int i_APCI3120_InsnWriteAnalogOutput(comedi_device *dev,comedi_subdevice - *s, comedi_insn *insn,lsampl_t *data) +int i_APCI3120_InsnWriteAnalogOutput(comedi_device * dev, comedi_subdevice + * s, comedi_insn * insn, lsampl_t * data) { - UINT ui_Range,ui_Channel; - USHORT us_TmpValue; - - ui_Range = CR_RANGE(insn->chanspec); - ui_Channel = CR_CHAN(insn->chanspec); + UINT ui_Range, ui_Channel; + USHORT us_TmpValue; - - //this_board->i_hwdrv_InsnWriteAnalogOutput(dev, ui_Range, ui_Channel,data[0]); - if(ui_Range) // if 1 then unipolar - { - - if(data[0]!=0) - data[0]=((((ui_Channel & 0x03)<<14) & 0xC000) | (1<<13) | (data[0]+8191)); - else - data[0]=((((ui_Channel & 0x03)<<14) & 0xC000) | (1<<13) | 8192); - - } - else // if 0 then bipolar - { - data[0]= ((((ui_Channel & 0x03)<<14) & 0xC000) | (0<<13) | data[0]); - - } + ui_Range = CR_RANGE(insn->chanspec); + ui_Channel = CR_CHAN(insn->chanspec); + //this_board->i_hwdrv_InsnWriteAnalogOutput(dev, ui_Range, ui_Channel,data[0]); + if (ui_Range) // if 1 then unipolar + { - - //out put n values at the given channel. - // rt_printk("\nwaiting for DA_READY BIT"); - do //Waiting of DA_READY BIT - { - us_TmpValue=((USHORT) inw(devpriv->iobase+APCI3120_RD_STATUS)) & 0x0001; - } while(us_TmpValue!=0x0001); - - if(ui_Channel<=3) + if (data[0] != 0) + data[0] = + ((((ui_Channel & 0x03) << 14) & 0xC000) | (1 << + 13) | (data[0] + 8191)); + else + data[0] = + ((((ui_Channel & 0x03) << 14) & 0xC000) | (1 << + 13) | 8192); + + } else // if 0 then bipolar + { + data[0] = + ((((ui_Channel & 0x03) << 14) & 0xC000) | (0 << 13) | + data[0]); + + } + + //out put n values at the given channel. + // rt_printk("\nwaiting for DA_READY BIT"); + do //Waiting of DA_READY BIT + { + us_TmpValue = + ((USHORT) inw(devpriv->iobase + + APCI3120_RD_STATUS)) & 0x0001; + } while (us_TmpValue != 0x0001); + + if (ui_Channel <= 3) // for channel 0-3 out at the register 1 (wrDac1-8) // data[i] typecasted to ushort since word write is to be done - outw((USHORT)data[0],devpriv->iobase+ APCI3120_ANALOG_OUTPUT_1); - else + outw((USHORT) data[0], + devpriv->iobase + APCI3120_ANALOG_OUTPUT_1); + else // for channel 4-7 out at the register 2 (wrDac5-8) //data[i] typecasted to ushort since word write is to be done - outw((USHORT)data[0],devpriv->iobase+ APCI3120_ANALOG_OUTPUT_2); - - return insn->n; -} - + outw((USHORT) data[0], + devpriv->iobase + APCI3120_ANALOG_OUTPUT_2); + return insn->n; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci3120.h b/comedi/drivers/addi-data/hwdrv_apci3120.h index 41ad7e5a..e7536e51 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3120.h +++ b/comedi/drivers/addi-data/hwdrv_apci3120.h @@ -1,5 +1,4 @@ - // hwdrv_apci3120.h /** @@ -57,34 +56,29 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - - - - // comedi related defines //ANALOG INPUT RANGE -comedi_lrange range_apci3120_ai={ 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1) +comedi_lrange range_apci3120_ai = { 8, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1) } }; // ANALOG OUTPUT RANGE -comedi_lrange range_apci3120_ao= { 2, { - BIP_RANGE(10), - UNI_RANGE(10) - } +comedi_lrange range_apci3120_ao = { 2, { + BIP_RANGE(10), + UNI_RANGE(10) + } }; -#define APCI3120_BIPOLAR_RANGES 4 // used for test on mixture of BIP/UNI ranges - +#define APCI3120_BIPOLAR_RANGES 4 // used for test on mixture of BIP/UNI ranges #define APCI3120_BOARD_VENDOR_ID 0x10E8 #define APCI3120_ADDRESS_RANGE 16 @@ -101,7 +95,7 @@ comedi_lrange range_apci3120_ao= { 2, { //DIGITAL INPUT-OUTPUT DEFINE -#define APCI3120_DIGITAL_OUTPUT 0x0D +#define APCI3120_DIGITAL_OUTPUT 0x0D #define APCI3120_RD_STATUS 0x02 #define APCI3120_RD_FIFO 0x00 @@ -110,11 +104,11 @@ comedi_lrange range_apci3120_ao= { 2, { #define APCI3120_SET4DIGITALOUTPUTOFF 0 // analog output SELECT BIT -#define APCI3120_ANALOG_OP_CHANNEL_1 0x0000 +#define APCI3120_ANALOG_OP_CHANNEL_1 0x0000 #define APCI3120_ANALOG_OP_CHANNEL_2 0x4000 #define APCI3120_ANALOG_OP_CHANNEL_3 0x8000 #define APCI3120_ANALOG_OP_CHANNEL_4 0xC000 -#define APCI3120_ANALOG_OP_CHANNEL_5 0x0000 +#define APCI3120_ANALOG_OP_CHANNEL_5 0x0000 #define APCI3120_ANALOG_OP_CHANNEL_6 0x4000 #define APCI3120_ANALOG_OP_CHANNEL_7 0x8000 #define APCI3120_ANALOG_OP_CHANNEL_8 0xC000 @@ -123,28 +117,28 @@ comedi_lrange range_apci3120_ao= { 2, { #define APCI3120_ENABLE_EXT_TRIGGER 0x8000 //ANALOG OUTPUT AND INPUT DEFINE -#define APCI3120_UNIPOLAR 0x80 //$$ RAM sequence polarity BIT -#define APCI3120_BIPOLAR 0x00 //$$ RAM sequence polarity BIT -#define APCI3120_ANALOG_OUTPUT_1 0x08 // (ADDRESS ) -#define APCI3120_ANALOG_OUTPUT_2 0x0A // (ADDRESS ) -#define APCI3120_1_GAIN 0x00 //$$ RAM sequence Gain Bits for gain 1 -#define APCI3120_2_GAIN 0x10 //$$ RAM sequence Gain Bits for gain 2 -#define APCI3120_5_GAIN 0x20 //$$ RAM sequence Gain Bits for gain 5 -#define APCI3120_10_GAIN 0x30 //$$ RAM sequence Gain Bits for gain 10 -#define APCI3120_SEQ_RAM_ADDRESS 0x06 //$$ EARLIER NAMED APCI3120_FIFO_ADDRESS -#define APCI3120_RESET_FIFO 0x0C //(ADDRESS) -#define APCI3120_TIMER_0_MODE_2 0x01 //$$ Bits for timer mode +#define APCI3120_UNIPOLAR 0x80 //$$ RAM sequence polarity BIT +#define APCI3120_BIPOLAR 0x00 //$$ RAM sequence polarity BIT +#define APCI3120_ANALOG_OUTPUT_1 0x08 // (ADDRESS ) +#define APCI3120_ANALOG_OUTPUT_2 0x0A // (ADDRESS ) +#define APCI3120_1_GAIN 0x00 //$$ RAM sequence Gain Bits for gain 1 +#define APCI3120_2_GAIN 0x10 //$$ RAM sequence Gain Bits for gain 2 +#define APCI3120_5_GAIN 0x20 //$$ RAM sequence Gain Bits for gain 5 +#define APCI3120_10_GAIN 0x30 //$$ RAM sequence Gain Bits for gain 10 +#define APCI3120_SEQ_RAM_ADDRESS 0x06 //$$ EARLIER NAMED APCI3120_FIFO_ADDRESS +#define APCI3120_RESET_FIFO 0x0C //(ADDRESS) +#define APCI3120_TIMER_0_MODE_2 0x01 //$$ Bits for timer mode #define APCI3120_TIMER_0_MODE_4 0x2 #define APCI3120_SELECT_TIMER_0_WORD 0x00 -#define APCI3120_ENABLE_TIMER0 0x1000 //$$Gatebit 0 in nWrAddress -#define APCI3120_CLEAR_PR 0xF0FF +#define APCI3120_ENABLE_TIMER0 0x1000 //$$Gatebit 0 in nWrAddress +#define APCI3120_CLEAR_PR 0xF0FF #define APCI3120_CLEAR_PA 0xFFF0 #define APCI3120_CLEAR_PA_PR (APCI3120_CLEAR_PR & APCI3120_CLEAR_PA) // nWrMode_Select -#define APCI3120_ENABLE_SCAN 0x8 //$$ bit in nWrMode_Select +#define APCI3120_ENABLE_SCAN 0x8 //$$ bit in nWrMode_Select #define APCI3120_DISABLE_SCAN (~APCI3120_ENABLE_SCAN) -#define APCI3120_ENABLE_EOS_INT 0x2 //$$ bit in nWrMode_Select +#define APCI3120_ENABLE_EOS_INT 0x2 //$$ bit in nWrMode_Select #define APCI3120_DISABLE_EOS_INT (~APCI3120_ENABLE_EOS_INT) #define APCI3120_ENABLE_EOC_INT 0x1 @@ -157,7 +151,7 @@ comedi_lrange range_apci3120_ao= { 2, { #define APCI3120_EOS 0x2000 // software trigger dummy register -#define APCI3120_START_CONVERSION 0x02 //(ADDRESS) +#define APCI3120_START_CONVERSION 0x02 //(ADDRESS) //TIMER DEFINE #define APCI3120_QUARTZ_A 70 @@ -166,120 +160,117 @@ comedi_lrange range_apci3120_ao= { 2, { #define APCI3120_WATCHDOG 2 #define APCI3120_TIMER_DISABLE 0 #define APCI3120_TIMER_ENABLE 1 -#define APCI3120_ENABLE_TIMER2 0x4000 //$$ gatebit 2 in nWrAddress +#define APCI3120_ENABLE_TIMER2 0x4000 //$$ gatebit 2 in nWrAddress #define APCI3120_DISABLE_TIMER2 (~APCI3120_ENABLE_TIMER2) -#define APCI3120_ENABLE_TIMER_INT 0x04 //$$ ENAIRQ_FC_Bit in nWrModeSelect +#define APCI3120_ENABLE_TIMER_INT 0x04 //$$ ENAIRQ_FC_Bit in nWrModeSelect #define APCI3120_DISABLE_TIMER_INT (~APCI3120_ENABLE_TIMER_INT) -#define APCI3120_WRITE_MODE_SELECT 0x0E // (ADDRESS) +#define APCI3120_WRITE_MODE_SELECT 0x0E // (ADDRESS) #define APCI3120_SELECT_TIMER_0_WORD 0x00 #define APCI3120_SELECT_TIMER_1_WORD 0x01 #define APCI3120_TIMER_1_MODE_2 0x4 //$$ BIT FOR MODE IN nCsTimerCtr1 -#define APCI3120_TIMER_2_MODE_0 0x0 -#define APCI3120_TIMER_2_MODE_2 0x10 +#define APCI3120_TIMER_2_MODE_0 0x0 +#define APCI3120_TIMER_2_MODE_2 0x10 #define APCI3120_TIMER_2_MODE_5 0x30 //$$ BIT FOR MODE IN nCsTimerCtr0 #define APCI3120_SELECT_TIMER_2_LOW_WORD 0x02 #define APCI3120_SELECT_TIMER_2_HIGH_WORD 0x03 -#define APCI3120_TIMER_CRT0 0x0D //(ADDRESS for cCsTimerCtr0) -#define APCI3120_TIMER_CRT1 0x0C //(ADDRESS for cCsTimerCtr1) +#define APCI3120_TIMER_CRT0 0x0D //(ADDRESS for cCsTimerCtr0) +#define APCI3120_TIMER_CRT1 0x0C //(ADDRESS for cCsTimerCtr1) -#define APCI3120_TIMER_VALUE 0x04 //ADDRESS for nCsTimerWert -#define APCI3120_TIMER_STATUS_REGISTER 0x0D //ADDRESS for delete timer 2 interrupt -#define APCI3120_RD_STATUS 0x02 //ADDRESS -#define APCI3120_WR_ADDRESS 0x00 //ADDRESS -#define APCI3120_ENABLE_WATCHDOG 0x20 //$$BIT in nWrMode_Select +#define APCI3120_TIMER_VALUE 0x04 //ADDRESS for nCsTimerWert +#define APCI3120_TIMER_STATUS_REGISTER 0x0D //ADDRESS for delete timer 2 interrupt +#define APCI3120_RD_STATUS 0x02 //ADDRESS +#define APCI3120_WR_ADDRESS 0x00 //ADDRESS +#define APCI3120_ENABLE_WATCHDOG 0x20 //$$BIT in nWrMode_Select #define APCI3120_DISABLE_WATCHDOG (~APCI3120_ENABLE_WATCHDOG) -#define APCI3120_ENABLE_TIMER_COUNTER 0x10 //$$BIT in nWrMode_Select +#define APCI3120_ENABLE_TIMER_COUNTER 0x10 //$$BIT in nWrMode_Select #define APCI3120_DISABLE_TIMER_COUNTER (~APCI3120_ENABLE_TIMER_COUNTER) -#define APCI3120_FC_TIMER 0x1000 //bit in status register +#define APCI3120_FC_TIMER 0x1000 //bit in status register #define APCI3120_ENABLE_TIMER0 0x1000 #define APCI3120_ENABLE_TIMER1 0x2000 #define APCI3120_ENABLE_TIMER2 0x4000 #define APCI3120_DISABLE_TIMER0 (~APCI3120_ENABLE_TIMER0) #define APCI3120_DISABLE_TIMER1 (~APCI3120_ENABLE_TIMER1) #define APCI3120_DISABLE_TIMER2 (~APCI3120_ENABLE_TIMER2) - -#define APCI3120_TIMER2_SELECT_EOS 0xC0 // ADDED on 20-6 -#define APCI3120_COUNTER 3 // on 20-6 -#define APCI3120_DISABLE_ALL_TIMER ( APCI3120_DISABLE_TIMER0 & APCI3120_DISABLE_TIMER1 & APCI3120_DISABLE_TIMER2 )// on 20-6 - - +#define APCI3120_TIMER2_SELECT_EOS 0xC0 // ADDED on 20-6 +#define APCI3120_COUNTER 3 // on 20-6 +#define APCI3120_DISABLE_ALL_TIMER ( APCI3120_DISABLE_TIMER0 & APCI3120_DISABLE_TIMER1 & APCI3120_DISABLE_TIMER2 ) // on 20-6 #define MAX_ANALOGINPUT_CHANNELS 32 -typedef struct -{ - BYTE b_Type ; /* EOC or EOS */ - BYTE b_InterruptFlag ; /* Interrupt use or not */ - UINT ui_ConvertTiming ; /* Selection of the convertion time */ - BYTE b_NbrOfChannel ; /* Number of channel to read */ - UINT ui_ChannelList[MAX_ANALOGINPUT_CHANNELS] ; /* Number of the channel to be read */ - UINT ui_RangeList[MAX_ANALOGINPUT_CHANNELS] ; /* Gain of each channel */ - -}str_AnalogReadInformation; - - - - +typedef struct { + BYTE b_Type; /* EOC or EOS */ + BYTE b_InterruptFlag; /* Interrupt use or not */ + UINT ui_ConvertTiming; /* Selection of the convertion time */ + BYTE b_NbrOfChannel; /* Number of channel to read */ + UINT ui_ChannelList[MAX_ANALOGINPUT_CHANNELS]; /* Number of the channel to be read */ + UINT ui_RangeList[MAX_ANALOGINPUT_CHANNELS]; /* Gain of each channel */ +} str_AnalogReadInformation; // Function Declaration For APCI-3120 // Internal functions -int i_APCI3120_SetupChannelList(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist,char check); +int i_APCI3120_SetupChannelList(comedi_device * dev, comedi_subdevice * s, + int n_chan, unsigned int *chanlist, char check); int i_APCI3120_ExttrigEnable(comedi_device * dev); int i_APCI3120_ExttrigDisable(comedi_device * dev); -int i_APCI3120_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s); -int i_APCI3120_Reset(comedi_device *dev); -int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev,comedi_subdevice * s); +int i_APCI3120_StopCyclicAcquisition(comedi_device * dev, comedi_subdevice * s); +int i_APCI3120_Reset(comedi_device * dev); +int i_APCI3120_CyclicAnalogInput(int mode, comedi_device * dev, + comedi_subdevice * s); // Interrupt functions -void v_APCI3120_Interrupt(int irq, void *d) ; -//UPDATE-0.7.57->0.7.68 void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device *dev,comedi_subdevice *s,sampl_t *dma,sampl_t *data,int n); -void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device *dev,comedi_subdevice *s,sampl_t *dma_buffer,unsigned int num_samples); -int i_APCI3120_InterruptHandleEos(comedi_device *dev); -void v_APCI3120_InterruptDma(int irq, void *d) ; - - - +void v_APCI3120_Interrupt(int irq, void *d); +//UPDATE-0.7.57->0.7.68 void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device *dev,comedi_subdevice *s,sampl_t *dma,sampl_t *data,int n); +void v_APCI3120_InterruptDmaMoveBlock16bit(comedi_device * dev, + comedi_subdevice * s, sampl_t * dma_buffer, unsigned int num_samples); +int i_APCI3120_InterruptHandleEos(comedi_device * dev); +void v_APCI3120_InterruptDma(int irq, void *d); // TIMER -int i_APCI3120_InsnConfigTimer(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnWriteTimer(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnReadTimer(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); - +int i_APCI3120_InsnConfigTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnWriteTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnReadTimer(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //DI // for di read - -int i_APCI3120_InsnBitsDigitalInput(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnReadDigitalInput(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); +int i_APCI3120_InsnBitsDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnReadDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //DO //int i_APCI3120_WriteDigitalOutput(comedi_device *dev, BYTE data); -int i_APCI3120_InsnConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnBitsDigitalOutput(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnWriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - - +int i_APCI3120_InsnConfigDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnBitsDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnWriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //AO //int i_APCI3120_Write1AnalogValue(comedi_device *dev,UINT ui_Range,UINT ui_Channel,UINT data ); -int i_APCI3120_InsnWriteAnalogOutput(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); - +int i_APCI3120_InsnWriteAnalogOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //AI HArdware layer -int i_APCI3120_InsnConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3120_InsnReadAnalogInput(comedi_device *dev, comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); -int i_APCI3120_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) ; -int i_APCI3120_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s); +int i_APCI3120_InsnConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_InsnReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +int i_APCI3120_CommandTestAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +int i_APCI3120_CommandAnalogInput(comedi_device * dev, comedi_subdevice * s); //int i_APCI3120_CancelAnalogInput(comedi_device * dev, comedi_subdevice * s); -int i_APCI3120_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s); - +int i_APCI3120_StopCyclicAcquisition(comedi_device * dev, comedi_subdevice * s); diff --git a/comedi/drivers/addi-data/hwdrv_apci3200.c b/comedi/drivers/addi-data/hwdrv_apci3200.c index 0251970e..4c54e706 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3200.c +++ b/comedi/drivers/addi-data/hwdrv_apci3200.c @@ -51,7 +51,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Included files | @@ -88,144 +87,163 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc INT i_Initialised=0; UINT ui_InterruptChannelValue[96]; //Buffer */ -str_BoardInfos s_BoardInfos [100]; // 100 will be the max number of boards to be used +str_BoardInfos s_BoardInfos[100]; // 100 will be the max number of boards to be used //END JK 06.07.04: Management of sevrals boards //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values /*+----------------------------------------------------------------------------+*/ /*| Function Name : INT i_AddiHeaderRW_ReadEeprom |*/ -/*| (INT i_NbOfWordsToRead, |*/ +/*| (INT i_NbOfWordsToRead, |*/ /*| DWORD dw_PCIBoardEepromAddress, |*/ /*| WORD w_EepromStartAddress, |*/ /*| PWORD pw_DataRead) |*/ /*+----------------------------------------------------------------------------+*/ /*| Task : Read word from the 5920 eeprom. |*/ /*+----------------------------------------------------------------------------+*/ -/*| Input Parameters : INT i_NbOfWordsToRead : Nbr. of word to read |*/ +/*| Input Parameters : INT i_NbOfWordsToRead : Nbr. of word to read |*/ /*| DWORD dw_PCIBoardEepromAddress : Address of the eeprom |*/ /*| WORD w_EepromStartAddress : Eeprom strat address |*/ /*+----------------------------------------------------------------------------+*/ -/*| Output Parameters : PWORD pw_DataRead : Read data |*/ +/*| Output Parameters : PWORD pw_DataRead : Read data |*/ /*+----------------------------------------------------------------------------+*/ /*| Return Value : - |*/ /*+----------------------------------------------------------------------------+*/ -INT i_AddiHeaderRW_ReadEeprom (INT i_NbOfWordsToRead, - DWORD dw_PCIBoardEepromAddress, - WORD w_EepromStartAddress, - PWORD pw_DataRead) +INT i_AddiHeaderRW_ReadEeprom(INT i_NbOfWordsToRead, + DWORD dw_PCIBoardEepromAddress, + WORD w_EepromStartAddress, PWORD pw_DataRead) { - DWORD dw_eeprom_busy=0; - INT i_Counter=0; - INT i_WordCounter; - INT i; - BYTE pb_ReadByte[1]; - BYTE b_ReadLowByte = 0; - BYTE b_ReadHighByte = 0; - BYTE b_SelectedAddressLow = 0; - BYTE b_SelectedAddressHigh = 0; - WORD w_ReadWord = 0; - - for (i_WordCounter = 0;i_WordCounter> 4; + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress, // Address of the first header + &w_FirstHeaderSize); + + w_FirstHeaderSize = w_FirstHeaderSize >> 4; /***************************/ /** Read number of inputs **/ /***************************/ - i_AddiHeaderRW_ReadEeprom (1, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_AnalogInputComponentAddress + 0x06, // Number of inputs for the first modul - &w_NumberOfInputs); + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x06, // Number of inputs for the first modul + &w_NumberOfInputs); - w_NumberOfInputs = w_NumberOfInputs >> 4; + w_NumberOfInputs = w_NumberOfInputs >> 4; /***********************/ /** Read the CJC flag **/ /***********************/ - i_AddiHeaderRW_ReadEeprom (1, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_AnalogInputComponentAddress + 0x08, // CJC flag - &w_CJCFlag); - - w_CJCFlag = (w_CJCFlag >> 3) & 0x1; // Get only the CJC flag + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x08, // CJC flag + &w_CJCFlag); + + w_CJCFlag = (w_CJCFlag >> 3) & 0x1; // Get only the CJC flag /*******************************/ /** Read number of gain value **/ /*******************************/ - i_AddiHeaderRW_ReadEeprom (1, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_AnalogInputComponentAddress + 0x44, // Number of gain value - &w_NumberOfGainValue); + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x44, // Number of gain value + &w_NumberOfGainValue); - w_NumberOfGainValue = w_NumberOfGainValue & 0xFF; + w_NumberOfGainValue = w_NumberOfGainValue & 0xFF; /***********************************/ /** Compute single header address **/ /***********************************/ - w_SingleHeaderAddress = w_AnalogInputComponentAddress + 0x46 + (((w_NumberOfGainValue / 16) + 1) * 2) + (6 * w_NumberOfGainValue) + (4 * (((w_NumberOfGainValue / 16) + 1) * 2)); + w_SingleHeaderAddress = + w_AnalogInputComponentAddress + 0x46 + + (((w_NumberOfGainValue / 16) + 1) * 2) + + (6 * w_NumberOfGainValue) + + (4 * (((w_NumberOfGainValue / 16) + 1) * 2)); /********************************************/ /** Read current sources value for input 1 **/ /********************************************/ - i_AddiHeaderRW_ReadEeprom (1, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_SingleHeaderAddress ,//w_EepromStartAddress: Single header address - &w_SingleHeaderSize); + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_SingleHeaderAddress, //w_EepromStartAddress: Single header address + &w_SingleHeaderSize); - w_SingleHeaderSize = w_SingleHeaderSize >> 4; + w_SingleHeaderSize = w_SingleHeaderSize >> 4; /*************************************/ /** Read gain factor for the module **/ /*************************************/ - w_GainFactorAddress = w_AnalogInputComponentAddress; - - for (w_GainIndex = 0; w_GainIndex < w_NumberOfGainValue; w_GainIndex++) - { + w_GainFactorAddress = w_AnalogInputComponentAddress; + + for (w_GainIndex = 0; w_GainIndex < w_NumberOfGainValue; + w_GainIndex++) { /************************************/ - /** Read gain value for the module **/ + /** Read gain value for the module **/ /************************************/ - i_AddiHeaderRW_ReadEeprom (1, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_AnalogInputComponentAddress + 70 + (2 * (1 + ( w_NumberOfGainValue / 16))) + (0x02 * w_GainIndex), // Gain value - &w_GainValue); - - BoardInformations->s_Module [w_ModulCounter].w_GainValue [w_GainIndex] = w_GainValue; - -# ifdef PRINT_INFO - printk ("\n Gain value = %d", BoardInformations->s_Module [w_ModulCounter].w_GainValue [w_GainIndex]); + i_AddiHeaderRW_ReadEeprom(1, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 70 + (2 * (1 + (w_NumberOfGainValue / 16))) + (0x02 * w_GainIndex), // Gain value + &w_GainValue); + + BoardInformations->s_Module[w_ModulCounter]. + w_GainValue[w_GainIndex] = w_GainValue; + +# ifdef PRINT_INFO + printk("\n Gain value = %d", + BoardInformations->s_Module[w_ModulCounter]. + w_GainValue[w_GainIndex]); # endif /*************************************/ /** Read gain factor for the module **/ /*************************************/ - i_AddiHeaderRW_ReadEeprom (2, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - w_AnalogInputComponentAddress + 70 + ((2 * w_NumberOfGainValue) + (2 * (1 + ( w_NumberOfGainValue / 16)))) + (0x04 * w_GainIndex), // Gain factor - w_GainFactorValue); - - BoardInformations->s_Module [w_ModulCounter].ul_GainFactor [w_GainIndex] = (w_GainFactorValue [1] << 16) + w_GainFactorValue [0]; - -# ifdef PRINT_INFO - printk ("\n w_GainFactorValue [%d] = %lu", w_GainIndex, BoardInformations->s_Module [w_ModulCounter].ul_GainFactor [w_GainIndex]); + i_AddiHeaderRW_ReadEeprom(2, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 70 + ((2 * w_NumberOfGainValue) + (2 * (1 + (w_NumberOfGainValue / 16)))) + (0x04 * w_GainIndex), // Gain factor + w_GainFactorValue); + + BoardInformations->s_Module[w_ModulCounter]. + ul_GainFactor[w_GainIndex] = + (w_GainFactorValue[1] << 16) + + w_GainFactorValue[0]; + +# ifdef PRINT_INFO + printk("\n w_GainFactorValue [%d] = %lu", w_GainIndex, + BoardInformations->s_Module[w_ModulCounter]. + ul_GainFactor[w_GainIndex]); # endif - } + } /***************************************************************/ /** Read current source value for each channels of the module **/ /***************************************************************/ - for (w_Input = 0; w_Input < w_NumberOfInputs; w_Input++) - { + for (w_Input = 0; w_Input < w_NumberOfInputs; w_Input++) { /********************************************/ /** Read current sources value for input 1 **/ /********************************************/ - i_AddiHeaderRW_ReadEeprom (2, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - (w_Input * w_SingleHeaderSize) + w_SingleHeaderAddress + 0x0C, - w_CurrentSources); + i_AddiHeaderRW_ReadEeprom(2, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, + (w_Input * w_SingleHeaderSize) + + w_SingleHeaderAddress + 0x0C, w_CurrentSources); - /************************************/ /** Save the current sources value **/ /************************************/ - BoardInformations->s_Module [w_ModulCounter].ul_CurrentSource [w_Input] = (w_CurrentSources [0] + ((w_CurrentSources [1] & 0xFFF) << 16)); + BoardInformations->s_Module[w_ModulCounter]. + ul_CurrentSource[w_Input] = + (w_CurrentSources[0] + + ((w_CurrentSources[1] & 0xFFF) << 16)); + +# ifdef PRINT_INFO + printk("\n Current sources [%d] = %lu", w_Input, + BoardInformations->s_Module[w_ModulCounter]. + ul_CurrentSource[w_Input]); +# endif + } -# ifdef PRINT_INFO - printk ("\n Current sources [%d] = %lu", w_Input, BoardInformations->s_Module [w_ModulCounter].ul_CurrentSource [w_Input]); -# endif - } - /***************************************/ /** Read the CJC current source value **/ /***************************************/ - i_AddiHeaderRW_ReadEeprom (2, //i_NbOfWordsToRead - dw_PCIBoardEepromAddress, - (w_Input * w_SingleHeaderSize) + w_SingleHeaderAddress + 0x0C, - w_CurrentSources); - + i_AddiHeaderRW_ReadEeprom(2, //i_NbOfWordsToRead + dw_PCIBoardEepromAddress, + (w_Input * w_SingleHeaderSize) + w_SingleHeaderAddress + + 0x0C, w_CurrentSources); + /************************************/ /** Save the current sources value **/ /************************************/ - BoardInformations->s_Module [w_ModulCounter].ul_CurrentSourceCJC = (w_CurrentSources [0] + ((w_CurrentSources [1] & 0xFFF) << 16)); - -# ifdef PRINT_INFO - printk ("\n Current sources CJC = %lu", BoardInformations->s_Module [w_ModulCounter].ul_CurrentSourceCJC); + BoardInformations->s_Module[w_ModulCounter]. + ul_CurrentSourceCJC = + (w_CurrentSources[0] + + ((w_CurrentSources[1] & 0xFFF) << 16)); + +# ifdef PRINT_INFO + printk("\n Current sources CJC = %lu", + BoardInformations->s_Module[w_ModulCounter]. + ul_CurrentSourceCJC); # endif - } + } } -INT i_APCI3200_GetChannelCalibrationValue (comedi_device *dev, unsigned int ui_Channel_num, lsampl_t *CJCCurrentSource, - lsampl_t *ChannelCurrentSource, - lsampl_t *ChannelGainFactor) -{ - int i_DiffChannel = 0; - int i_Module = 0; - -#ifdef PRINT_INFO - printk ("\n Channel = %u", ui_Channel_num); -#endif +INT i_APCI3200_GetChannelCalibrationValue(comedi_device * dev, + unsigned int ui_Channel_num, lsampl_t * CJCCurrentSource, + lsampl_t * ChannelCurrentSource, lsampl_t * ChannelGainFactor) +{ + int i_DiffChannel = 0; + int i_Module = 0; - //Test if single or differential mode - if (s_BoardInfos [dev->minor].i_ConnectionType == 1) - { - //if diff - - if((ui_Channel_num >=0) && (ui_Channel_num <=1)) - i_DiffChannel=ui_Channel_num, i_Module = 0; - else - if((ui_Channel_num >=2) && (ui_Channel_num <=3)) - i_DiffChannel=ui_Channel_num-2, i_Module = 1; - else - if((ui_Channel_num >=4) && (ui_Channel_num <=5)) - i_DiffChannel=ui_Channel_num-4, i_Module = 2; - else - if((ui_Channel_num >=6) && (ui_Channel_num <=7)) - i_DiffChannel=ui_Channel_num-6, i_Module = 3; - - } - else - { - // if single - if((ui_Channel_num == 0) || (ui_Channel_num == 1)) - i_DiffChannel=0, i_Module = 0; - else - if((ui_Channel_num == 2) || (ui_Channel_num == 3)) - i_DiffChannel=1, i_Module = 0; - else - if((ui_Channel_num == 4) || (ui_Channel_num == 5)) - i_DiffChannel=0, i_Module = 1; - else - if((ui_Channel_num == 6) || (ui_Channel_num == 7)) - i_DiffChannel=1, i_Module = 1; - else - if((ui_Channel_num == 8) || (ui_Channel_num == 9)) - i_DiffChannel=0, i_Module = 2; - else - if((ui_Channel_num == 10) || (ui_Channel_num == 11)) - i_DiffChannel=1, i_Module = 2; - else - if((ui_Channel_num == 12) || (ui_Channel_num == 13)) - i_DiffChannel=0, i_Module = 3; - else - if((ui_Channel_num == 14) || (ui_Channel_num == 15)) - i_DiffChannel=1, i_Module = 3; - } - - //Test if thermocouple or RTD mode - *CJCCurrentSource = s_BoardInfos [dev->minor].s_Module[i_Module].ul_CurrentSourceCJC; -#ifdef PRINT_INFO - printk ("\n CJCCurrentSource = %lu", *CJCCurrentSource); +#ifdef PRINT_INFO + printk("\n Channel = %u", ui_Channel_num); #endif - - *ChannelCurrentSource = s_BoardInfos [dev->minor].s_Module[i_Module].ul_CurrentSource [i_DiffChannel]; -#ifdef PRINT_INFO - printk ("\n ChannelCurrentSource = %lu", *ChannelCurrentSource); -#endif - // } - // } - - //Channle gain factor - *ChannelGainFactor = s_BoardInfos [dev->minor].s_Module[i_Module].ul_GainFactor [s_BoardInfos [dev->minor].i_ADDIDATAGain]; -#ifdef PRINT_INFO - printk ("\n ChannelGainFactor = %lu", *ChannelGainFactor); -#endif - //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - - return (0); -} - -//End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //Test if single or differential mode + if (s_BoardInfos[dev->minor].i_ConnectionType == 1) { + //if diff + + if ((ui_Channel_num >= 0) && (ui_Channel_num <= 1)) + i_DiffChannel = ui_Channel_num, i_Module = 0; + else if ((ui_Channel_num >= 2) && (ui_Channel_num <= 3)) + i_DiffChannel = ui_Channel_num - 2, i_Module = 1; + else if ((ui_Channel_num >= 4) && (ui_Channel_num <= 5)) + i_DiffChannel = ui_Channel_num - 4, i_Module = 2; + else if ((ui_Channel_num >= 6) && (ui_Channel_num <= 7)) + i_DiffChannel = ui_Channel_num - 6, i_Module = 3; + + } else { + // if single + if ((ui_Channel_num == 0) || (ui_Channel_num == 1)) + i_DiffChannel = 0, i_Module = 0; + else if ((ui_Channel_num == 2) || (ui_Channel_num == 3)) + i_DiffChannel = 1, i_Module = 0; + else if ((ui_Channel_num == 4) || (ui_Channel_num == 5)) + i_DiffChannel = 0, i_Module = 1; + else if ((ui_Channel_num == 6) || (ui_Channel_num == 7)) + i_DiffChannel = 1, i_Module = 1; + else if ((ui_Channel_num == 8) || (ui_Channel_num == 9)) + i_DiffChannel = 0, i_Module = 2; + else if ((ui_Channel_num == 10) || (ui_Channel_num == 11)) + i_DiffChannel = 1, i_Module = 2; + else if ((ui_Channel_num == 12) || (ui_Channel_num == 13)) + i_DiffChannel = 0, i_Module = 3; + else if ((ui_Channel_num == 14) || (ui_Channel_num == 15)) + i_DiffChannel = 1, i_Module = 3; + } + //Test if thermocouple or RTD mode + *CJCCurrentSource = + s_BoardInfos[dev->minor].s_Module[i_Module].ul_CurrentSourceCJC; +#ifdef PRINT_INFO + printk("\n CJCCurrentSource = %lu", *CJCCurrentSource); +#endif + *ChannelCurrentSource = + s_BoardInfos[dev->minor].s_Module[i_Module]. + ul_CurrentSource[i_DiffChannel]; +#ifdef PRINT_INFO + printk("\n ChannelCurrentSource = %lu", *ChannelCurrentSource); +#endif + // } + // } + + //Channle gain factor + *ChannelGainFactor = + s_BoardInfos[dev->minor].s_Module[i_Module]. + ul_GainFactor[s_BoardInfos[dev->minor].i_ADDIDATAGain]; +#ifdef PRINT_INFO + printk("\n ChannelGainFactor = %lu", *ChannelGainFactor); +#endif + //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + return (0); +} +//End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values /* +----------------------------------------------------------------------------+ @@ -532,48 +550,43 @@ INT i_APCI3200_GetChannelCalibrationValue (comedi_device *dev, unsigned int ui_C +----------------------------------------------------------------------------+ */ -INT i_APCI3200_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - UINT ui_Temp=0; - UINT ui_NoOfChannel=0; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->i_IobaseReserved); - - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } //if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - if(data[1] < 0 || data[1] >1) - { - printk("\nThe port number is in error\n"); - return -EINVAL; - }//if(data[1] < 0 || data[1] >1) - switch( ui_NoOfChannel) - { - - case 2: - *data=(*data >>(2*data[1]))&0x3; - break; - case 3: - *data=(*data & 15 ); - break; - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - - }//switch(ui_NoOfChannels) - }//if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - }//elseif (ui_Temp==1) - } - return insn->n; +INT i_APCI3200_ReadDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_Temp = 0; + UINT ui_NoOfChannel = 0; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->i_IobaseReserved); + + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } //if (ui_Temp==0) + else { + if (ui_Temp == 1) { + if (data[1] < 0 || data[1] > 1) { + printk("\nThe port number is in error\n"); + return -EINVAL; + } //if(data[1] < 0 || data[1] >1) + switch (ui_NoOfChannel) { + + case 2: + *data = (*data >> (2 * data[1])) & 0x3; + break; + case 3: + *data = (*data & 15); + break; + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + + } //switch(ui_NoOfChannels) + } //if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } //elseif (ui_Temp==1) + } + return insn->n; } /* @@ -595,26 +608,23 @@ INT i_APCI3200_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_in | | +----------------------------------------------------------------------------+ */ -int i_APCI3200_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - - if ( (data[0]!=0) && (data[0]!=1) ) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); - return -EINVAL; - }//if ( (data[0]!=0) && (data[0]!=1) ) - if (data[0]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; - }// if (data[0]) - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - }//else if (data[0]) - return insn->n; -} - +int i_APCI3200_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); + return -EINVAL; + } //if ( (data[0]!=0) && (data[0]!=1) ) + if (data[0]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } // if (data[0]) + else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } //else if (data[0]) + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -643,98 +653,94 @@ int i_APCI3200_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi | | +----------------------------------------------------------------------------+ */ -INT i_APCI3200_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3200_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp=0,ui_Temp1=0; - UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - if(devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inl(devpriv->i_IobaseAddon); - - }//if(devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - }//if(devpriv->b_OutputMemoryStatus ) - if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outl(data[0],devpriv->i_IobaseAddon); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2:data[0]=(data[0] << (2 * data[2]))|ui_Temp; - break; - case 3:data[0]=(data[0]|ui_Temp); - break; - }//switch(ui_NoOfChannels) - - outl(data[0],devpriv->i_IobaseAddon); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) - else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<i_IobaseAddon); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - switch( ui_NoOfChannel) - { - - case 2: data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2 * data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2 * data[2]))^0xf)& ui_Temp; - - break; - case 3: - break; - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - }//switch(ui_NoOfChannels) - - outl(data[0],devpriv->i_IobaseAddon); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) - return insn->n; + UINT ui_Temp = 0, ui_Temp1 = 0; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inl(devpriv->i_IobaseAddon); + + } //if(devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } //if(devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outl(data[0], devpriv->i_IobaseAddon); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = + (data[0] << (2 * + data[2])) | ui_Temp; + break; + case 3: + data[0] = (data[0] | ui_Temp); + break; + } //switch(ui_NoOfChannels) + + outl(data[0], devpriv->i_IobaseAddon); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = (data[0] << ui_NoOfChannel) ^ 0xf; + data[0] = data[0] & ui_Temp; + outl(data[0], devpriv->i_IobaseAddon); + } //if(data[1]==0) + else { + if (data[1] == 1) { + switch (ui_NoOfChannel) { + + case 2: + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = + ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data + [2])) ^ + 0xf) & ui_Temp; + + break; + case 3: + break; + + default: + comedi_error(dev, + " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + } //switch(ui_NoOfChannels) + + outl(data[0], devpriv->i_IobaseAddon); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return insn->n; } /* @@ -760,47 +766,42 @@ INT i_APCI3200_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_ | | +----------------------------------------------------------------------------+ */ -INT i_APCI3200_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3200_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp; - UINT ui_NoOfChannel; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->i_IobaseAddon); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } // if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - if(data[1] <0 ||data[1] >1) - { - printk("\nThe port selection is in error\n"); - return -EINVAL; - }//if(data[1] <0 ||data[1] >1) - switch (ui_NoOfChannel) - { - case 2: - *data=(*data >>(2*data[1]))&3; - break; - - case 3:break; - - - default: - comedi_error(dev," chan spec wrong"); - return -EINVAL; // "sorry channel spec wrong " - break; - } // switch(ui_NoOfChannels) - } // if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - } // else if (ui_Temp==1) - } // else if (ui_Temp==0) - return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->i_IobaseAddon); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } // if (ui_Temp==0) + else { + if (ui_Temp == 1) { + if (data[1] < 0 || data[1] > 1) { + printk("\nThe port selection is in error\n"); + return -EINVAL; + } //if(data[1] <0 ||data[1] >1) + switch (ui_NoOfChannel) { + case 2: + *data = (*data >> (2 * data[1])) & 3; + break; + + case 3: + break; + + default: + comedi_error(dev, " chan spec wrong"); + return -EINVAL; // "sorry channel spec wrong " + break; + } // switch(ui_NoOfChannels) + } // if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } // else if (ui_Temp==1) + } // else if (ui_Temp==0) + return insn->n; } /* @@ -873,486 +874,462 @@ INT i_APCI3200_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -INT i_APCI3200_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3200_ConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ul_Config = 0,ul_Temp=0 ; - UINT ui_ChannelNo=0; - UINT ui_Dummy=0; - INT i_err=0; - - //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - -#ifdef PRINT_INFO - INT i=0, i2=0; -#endif - //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - - //BEGIN JK 06.07.04: Management of sevrals boards - // Initialize the structure - if (s_BoardInfos [dev->minor].b_StructInitialized != 1) - { - s_BoardInfos [dev->minor].i_CJCAvailable=1; - s_BoardInfos [dev->minor].i_CJCPolarity=0; - s_BoardInfos [dev->minor].i_CJCGain=2;//changed from 0 to 2 - s_BoardInfos [dev->minor].i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_AutoCalibration=0; //: auto calibration - s_BoardInfos [dev->minor].i_ChannelCount=0; - s_BoardInfos [dev->minor].i_Sum=0; - s_BoardInfos [dev->minor].ui_Channel_num=0; - s_BoardInfos [dev->minor].i_Count=0; - s_BoardInfos [dev->minor].i_Initialised=0; - s_BoardInfos [dev->minor].b_StructInitialized = 1; - - //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - s_BoardInfos [dev->minor].i_ConnectionType = 0; - //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - - //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - memset (s_BoardInfos [dev->minor].s_Module, 0, sizeof (s_BoardInfos [dev->minor].s_Module[MAX_MODULE])); - - v_GetAPCI3200EepromCalibrationValue (devpriv->i_IobaseAmcc, &s_BoardInfos [dev->minor]); - -#ifdef PRINT_INFO - for (i=0; iminor].s_Module[i].ul_CurrentSourceCJC); - - for (i2=0; i2<5; i2++) - { - printk ("\n s_Module[%i].ul_CurrentSource [%i] = %lu",i, i2, s_BoardInfos [dev->minor].s_Module[i].ul_CurrentSource [i2]); - } - - for (i2=0; i2<8; i2++) - { - printk ("\n s_Module[%i].ul_GainFactor [%i] = %lu",i, i2, s_BoardInfos [dev->minor].s_Module[i].ul_GainFactor [i2]); - } - - for (i2=0; i2<8; i2++) - { - printk ("\n s_Module[%i].w_GainValue [%i] = %u",i, i2, s_BoardInfos [dev->minor].s_Module[i].w_GainValue [i2]); - } - } + UINT ul_Config = 0, ul_Temp = 0; + UINT ui_ChannelNo = 0; + UINT ui_Dummy = 0; + INT i_err = 0; + + //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + +#ifdef PRINT_INFO + INT i = 0, i2 = 0; #endif - //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - } - - if(data[0]!=0 && data[0]!=1 && data[0]!=2) - { - printk("\nThe selection of acquisition type is in error\n"); - i_err++; - }//if(data[0]!=0 && data[0]!=1 && data[0]!=2) - if(data[0]==1) - { - if(data[14]!=0 && data[14]!=1 && data[14]!=2 && data[14]!=4) - { - printk("\n Error in selection of RTD connection type\n"); - i_err++; - }//if(data[14]!=0 && data[14]!=1 && data[14]!=2 && data[14]!=4) - }//if(data[0]==1 ) - if(data[1]<0 || data[1]>7) - { - printk("\nThe selection of gain is in error\n"); - i_err++; - } // if(data[1]<0 || data[1]>7) - if(data[2]!=0 && data[2]!=1) - { - printk("\nThe selection of polarity is in error\n"); - i_err++; - }//if(data[2]!=0 && data[2]!=1) - if(data[3]!=0) - { - printk("\nThe selection of offset range is in error\n"); - i_err++; - }// if(data[3]!=0) - if(data[4]!=0 && data[4]!=1) - { - printk("\nThe selection of coupling is in error\n"); - i_err++; - }//if(data[4]!=0 && data[4]!=1) - if(data[5]!=0 && data[5]!=1) - { - printk("\nThe selection of single/differential mode is in error\n"); - i_err++; - }//if(data[5]!=0 && data[5]!=1) - if(data[8]!=0 && data[8]!=1 && data[2]!=2) - { - printk("\nError in selection of functionality\n"); - }//if(data[8]!=0 && data[8]!=1 && data[2]!=2) - if(data[12]==0 || data[12]==1) - { - if (data[6]!=20 && data[6]!=40 && data[6]!=80 && data[6]!=160 ) - { - printk("\nThe selection of conversion time reload value is in error\n"); - i_err++; - }// if (data[6]!=20 && data[6]!=40 && data[6]!=80 && data[6]!=160 ) - if(data[7]!=2) - { - printk("\nThe selection of conversion time unit is in error\n"); - i_err++; - }// if(data[7]!=2) - } - if(data[9]!=0 && data[9]!=1) - { - printk("\nThe selection of interrupt enable is in error\n"); - i_err++; - }//if(data[9]!=0 && data[9]!=1) - if(data[11] < 0 || data[11] > 4) - { - printk("\nThe selection of module is in error\n"); - i_err++; - }//if(data[11] <0 || data[11]>1) - if(data[12] < 0 || data[12] > 3) - { - printk("\nThe selection of singlechannel/scan selection is in error\n"); - i_err++; - }//if(data[12] < 0 || data[12]> 3) - if(data[13] <0 ||data[13] >16) - { - printk("\nThe selection of number of channels is in error\n"); - i_err++; - }// if(data[13] <0 ||data[13] >15) - - - //BEGIN JK 06.07.04: Management of sevrals boards - /* - i_ChannelCount=data[13]; - i_ScanType=data[12]; - i_ADDIDATAPolarity = data[2]; - i_ADDIDATAGain=data[1]; - i_ADDIDATAConversionTime=data[6]; - i_ADDIDATAConversionTimeUnit=data[7]; - i_ADDIDATAType=data[0]; - */ - - // Save acquisition configuration for the actual board - s_BoardInfos [dev->minor].i_ChannelCount=data[13]; - s_BoardInfos [dev->minor].i_ScanType=data[12]; - s_BoardInfos [dev->minor].i_ADDIDATAPolarity = data[2]; - s_BoardInfos [dev->minor].i_ADDIDATAGain=data[1]; - s_BoardInfos [dev->minor].i_ADDIDATAConversionTime=data[6]; - s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit=data[7]; - s_BoardInfos [dev->minor].i_ADDIDATAType=data[0]; - //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - s_BoardInfos [dev->minor].i_ConnectionType=data[5]; - //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //END JK 06.07.04: Management of sevrals boards - - //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - memset (s_BoardInfos [dev->minor].ui_ScanValueArray, 0, (7+12)*sizeof (lsampl_t)); // 7 is the maximal number of channels - //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - - //BEGIN JK 02.07.04 : This while can't be do, it block the process when using severals boards - //while(i_InterruptFlag==1) - while(s_BoardInfos [dev->minor].i_InterruptFlag==1) - { + //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + + //BEGIN JK 06.07.04: Management of sevrals boards + // Initialize the structure + if (s_BoardInfos[dev->minor].b_StructInitialized != 1) { + s_BoardInfos[dev->minor].i_CJCAvailable = 1; + s_BoardInfos[dev->minor].i_CJCPolarity = 0; + s_BoardInfos[dev->minor].i_CJCGain = 2; //changed from 0 to 2 + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + s_BoardInfos[dev->minor].i_AutoCalibration = 0; //: auto calibration + s_BoardInfos[dev->minor].i_ChannelCount = 0; + s_BoardInfos[dev->minor].i_Sum = 0; + s_BoardInfos[dev->minor].ui_Channel_num = 0; + s_BoardInfos[dev->minor].i_Count = 0; + s_BoardInfos[dev->minor].i_Initialised = 0; + s_BoardInfos[dev->minor].b_StructInitialized = 1; + + //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + s_BoardInfos[dev->minor].i_ConnectionType = 0; + //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + + //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + memset(s_BoardInfos[dev->minor].s_Module, 0, + sizeof(s_BoardInfos[dev->minor].s_Module[MAX_MODULE])); + + v_GetAPCI3200EepromCalibrationValue(devpriv->i_IobaseAmcc, + &s_BoardInfos[dev->minor]); + +#ifdef PRINT_INFO + for (i = 0; i < MAX_MODULE; i++) { + printk("\n s_Module[%i].ul_CurrentSourceCJC = %lu", i, + s_BoardInfos[dev->minor].s_Module[i]. + ul_CurrentSourceCJC); + + for (i2 = 0; i2 < 5; i2++) { + printk("\n s_Module[%i].ul_CurrentSource [%i] = %lu", i, i2, s_BoardInfos[dev->minor].s_Module[i].ul_CurrentSource[i2]); + } + + for (i2 = 0; i2 < 8; i2++) { + printk("\n s_Module[%i].ul_GainFactor [%i] = %lu", i, i2, s_BoardInfos[dev->minor].s_Module[i].ul_GainFactor[i2]); + } + + for (i2 = 0; i2 < 8; i2++) { + printk("\n s_Module[%i].w_GainValue [%i] = %u", + i, i2, + s_BoardInfos[dev->minor].s_Module[i]. + w_GainValue[i2]); + } + } +#endif + //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } + + if (data[0] != 0 && data[0] != 1 && data[0] != 2) { + printk("\nThe selection of acquisition type is in error\n"); + i_err++; + } //if(data[0]!=0 && data[0]!=1 && data[0]!=2) + if (data[0] == 1) { + if (data[14] != 0 && data[14] != 1 && data[14] != 2 + && data[14] != 4) { + printk("\n Error in selection of RTD connection type\n"); + i_err++; + } //if(data[14]!=0 && data[14]!=1 && data[14]!=2 && data[14]!=4) + } //if(data[0]==1 ) + if (data[1] < 0 || data[1] > 7) { + printk("\nThe selection of gain is in error\n"); + i_err++; + } // if(data[1]<0 || data[1]>7) + if (data[2] != 0 && data[2] != 1) { + printk("\nThe selection of polarity is in error\n"); + i_err++; + } //if(data[2]!=0 && data[2]!=1) + if (data[3] != 0) { + printk("\nThe selection of offset range is in error\n"); + i_err++; + } // if(data[3]!=0) + if (data[4] != 0 && data[4] != 1) { + printk("\nThe selection of coupling is in error\n"); + i_err++; + } //if(data[4]!=0 && data[4]!=1) + if (data[5] != 0 && data[5] != 1) { + printk("\nThe selection of single/differential mode is in error\n"); + i_err++; + } //if(data[5]!=0 && data[5]!=1) + if (data[8] != 0 && data[8] != 1 && data[2] != 2) { + printk("\nError in selection of functionality\n"); + } //if(data[8]!=0 && data[8]!=1 && data[2]!=2) + if (data[12] == 0 || data[12] == 1) { + if (data[6] != 20 && data[6] != 40 && data[6] != 80 + && data[6] != 160) { + printk("\nThe selection of conversion time reload value is in error\n"); + i_err++; + } // if (data[6]!=20 && data[6]!=40 && data[6]!=80 && data[6]!=160 ) + if (data[7] != 2) { + printk("\nThe selection of conversion time unit is in error\n"); + i_err++; + } // if(data[7]!=2) + } + if (data[9] != 0 && data[9] != 1) { + printk("\nThe selection of interrupt enable is in error\n"); + i_err++; + } //if(data[9]!=0 && data[9]!=1) + if (data[11] < 0 || data[11] > 4) { + printk("\nThe selection of module is in error\n"); + i_err++; + } //if(data[11] <0 || data[11]>1) + if (data[12] < 0 || data[12] > 3) { + printk("\nThe selection of singlechannel/scan selection is in error\n"); + i_err++; + } //if(data[12] < 0 || data[12]> 3) + if (data[13] < 0 || data[13] > 16) { + printk("\nThe selection of number of channels is in error\n"); + i_err++; + } // if(data[13] <0 ||data[13] >15) + + //BEGIN JK 06.07.04: Management of sevrals boards + /* + i_ChannelCount=data[13]; + i_ScanType=data[12]; + i_ADDIDATAPolarity = data[2]; + i_ADDIDATAGain=data[1]; + i_ADDIDATAConversionTime=data[6]; + i_ADDIDATAConversionTimeUnit=data[7]; + i_ADDIDATAType=data[0]; + */ + + // Save acquisition configuration for the actual board + s_BoardInfos[dev->minor].i_ChannelCount = data[13]; + s_BoardInfos[dev->minor].i_ScanType = data[12]; + s_BoardInfos[dev->minor].i_ADDIDATAPolarity = data[2]; + s_BoardInfos[dev->minor].i_ADDIDATAGain = data[1]; + s_BoardInfos[dev->minor].i_ADDIDATAConversionTime = data[6]; + s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit = data[7]; + s_BoardInfos[dev->minor].i_ADDIDATAType = data[0]; + //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + s_BoardInfos[dev->minor].i_ConnectionType = data[5]; + //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //END JK 06.07.04: Management of sevrals boards + + //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + memset(s_BoardInfos[dev->minor].ui_ScanValueArray, 0, (7 + 12) * sizeof(lsampl_t)); // 7 is the maximal number of channels + //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + + //BEGIN JK 02.07.04 : This while can't be do, it block the process when using severals boards + //while(i_InterruptFlag==1) + while (s_BoardInfos[dev->minor].i_InterruptFlag == 1) { #ifndef MSXBOX - udelay(1); + udelay(1); #else - // In the case where the driver is compiled for the MSX-Box - // we used a printk to have a little delay because udelay - // seems to be broken under the MSX-Box. - // This solution hat to be studied. - printk(""); + // In the case where the driver is compiled for the MSX-Box + // we used a printk to have a little delay because udelay + // seems to be broken under the MSX-Box. + // This solution hat to be studied. + printk(""); #endif - } - //END JK 02.07.04 : This while can't be do, it block the process when using severals boards - - ui_ChannelNo = CR_CHAN(insn->chanspec); // get the channel - //BEGIN JK 06.07.04: Management of sevrals boards - //i_ChannelNo=ui_ChannelNo; - //ui_Channel_num =ui_ChannelNo; - - s_BoardInfos [dev->minor].i_ChannelNo=ui_ChannelNo; - s_BoardInfos [dev->minor].ui_Channel_num=ui_ChannelNo; - - //END JK 06.07.04: Management of sevrals boards - - if(data[5]==0) - { - if(ui_ChannelNo<0 || ui_ChannelNo>15) - { - printk("\nThe Selection of the channel is in error\n"); - i_err++; - }// if(ui_ChannelNo<0 || ui_ChannelNo>15) - }//if(data[5]==0) - else - { - if(data[14]==2) - { - if(ui_ChannelNo<0 || ui_ChannelNo>3) - { - printk("\nThe Selection of the channel is in error\n"); - i_err++; - }// if(ui_ChannelNo<0 || ui_ChannelNo>3) - }//if(data[14]==2) - else - { - if(ui_ChannelNo<0 || ui_ChannelNo>7) - { - printk("\nThe Selection of the channel is in error\n"); - i_err++; - }// if(ui_ChannelNo<0 || ui_ChannelNo>7) - }//elseif(data[14]==2) - }//elseif(data[5]==0) - if(data[12]==0 || data[12]==1) - { - switch(data[5]) - { - case 0: - if(ui_ChannelNo >=0 && ui_ChannelNo <=3) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=0; - s_BoardInfos [dev->minor].i_Offset=0; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo >=0 && ui_ChannelNo <=3) - if(ui_ChannelNo >=4 && ui_ChannelNo <=7) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=64; - s_BoardInfos [dev->minor].i_Offset=64; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo >=4 && ui_ChannelNo <=7) - if(ui_ChannelNo >=8 && ui_ChannelNo <=11) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=128; - s_BoardInfos [dev->minor].i_Offset=128; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo >=8 && ui_ChannelNo <=11) - if(ui_ChannelNo >=12 && ui_ChannelNo <=15) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=192; - s_BoardInfos [dev->minor].i_Offset=192; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo >=12 && ui_ChannelNo <=15) - break; - case 1: - if(data[14]==2) - { - if(ui_ChannelNo ==0 ) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=0; - s_BoardInfos [dev->minor].i_Offset=0; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo ==0 ) - if(ui_ChannelNo ==1) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=0; - s_BoardInfos [dev->minor].i_Offset=64; - //END JK 06.07.04: Management of sevrals boards - }// if(ui_ChannelNo ==1) - if(ui_ChannelNo ==2 ) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=128; - s_BoardInfos [dev->minor].i_Offset=128; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo ==2 ) - if(ui_ChannelNo ==3) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=192; - s_BoardInfos [dev->minor].i_Offset=192; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo ==3) - - //BEGIN JK 06.07.04: Management of sevrals boards - //i_ChannelNo=0; - s_BoardInfos [dev->minor].i_ChannelNo=0; - //END JK 06.07.04: Management of sevrals boards - ui_ChannelNo=0; - break; - }//if(data[14]==2) - if(ui_ChannelNo >=0 && ui_ChannelNo <=1) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=0; - s_BoardInfos [dev->minor].i_Offset=0; - //END JK 06.07.04: Management of sevrals boards - }//if(ui_ChannelNo >=0 && ui_ChannelNo <=1) - if(ui_ChannelNo >=2 && ui_ChannelNo <=3) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_ChannelNo=i_ChannelNo-2; - //i_Offset=64; - s_BoardInfos [dev->minor].i_ChannelNo=s_BoardInfos [dev->minor].i_ChannelNo-2; - s_BoardInfos [dev->minor].i_Offset=64; - //END JK 06.07.04: Management of sevrals boards - ui_ChannelNo=ui_ChannelNo-2; - }//if(ui_ChannelNo >=2 && ui_ChannelNo <=3) - if(ui_ChannelNo >=4 && ui_ChannelNo <=5) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_ChannelNo=i_ChannelNo-4; - //i_Offset=128; - s_BoardInfos [dev->minor].i_ChannelNo=s_BoardInfos [dev->minor].i_ChannelNo-4; - s_BoardInfos [dev->minor].i_Offset=128; - //END JK 06.07.04: Management of sevrals boards - ui_ChannelNo=ui_ChannelNo-4; - }//if(ui_ChannelNo >=4 && ui_ChannelNo <=5) - if(ui_ChannelNo >=6 && ui_ChannelNo <=7) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_ChannelNo=i_ChannelNo-6; - //i_Offset=192; - s_BoardInfos [dev->minor].i_ChannelNo=s_BoardInfos [dev->minor].i_ChannelNo-6; - s_BoardInfos [dev->minor].i_Offset=192; - //END JK 06.07.04: Management of sevrals boards - ui_ChannelNo=ui_ChannelNo-6; - }//if(ui_ChannelNo >=6 && ui_ChannelNo <=7) - break; - - default: printk("\n This selection of polarity does not exist\n"); - i_err++; - }//switch(data[2]) - }//if(data[12]==0 || data[12]==1) - else - { - switch(data[11]) - { - case 1: - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=0; - s_BoardInfos [dev->minor].i_Offset=0; - //END JK 06.07.04: Management of sevrals boards - break; - case 2: - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=64; - s_BoardInfos [dev->minor].i_Offset=64; - //END JK 06.07.04: Management of sevrals boards - break; - case 3: - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=128; - s_BoardInfos [dev->minor].i_Offset=128; - //END JK 06.07.04: Management of sevrals boards - break; - case 4: - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Offset=192; - s_BoardInfos [dev->minor].i_Offset=192; - //END JK 06.07.04: Management of sevrals boards - break; - default: - printk("\nError in module selection\n"); - i_err++; - }// switch(data[11]) - }// elseif(data[12]==0 || data[12]==1) - if(i_err) - { - i_APCI3200_Reset(dev); - return -EINVAL; - } - //if(i_ScanType!=1) - if(s_BoardInfos [dev->minor].i_ScanType!=1) - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Count=0; - //i_Sum=0; - s_BoardInfos [dev->minor].i_Count=0; - s_BoardInfos [dev->minor].i_Sum=0; - //END JK 06.07.04: Management of sevrals boards - }//if(i_ScanType!=1) - - ul_Config = data[1] |(data[2] << 6) |(data[5]<< 7) |(data[3] << 8) |(data[4] << 9); - //BEGIN JK 06.07.04: Management of sevrals boards - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //END JK 06.07.04: Management of sevrals boards + } + //END JK 02.07.04 : This while can't be do, it block the process when using severals boards + + ui_ChannelNo = CR_CHAN(insn->chanspec); // get the channel + //BEGIN JK 06.07.04: Management of sevrals boards + //i_ChannelNo=ui_ChannelNo; + //ui_Channel_num =ui_ChannelNo; + + s_BoardInfos[dev->minor].i_ChannelNo = ui_ChannelNo; + s_BoardInfos[dev->minor].ui_Channel_num = ui_ChannelNo; + + //END JK 06.07.04: Management of sevrals boards + + if (data[5] == 0) { + if (ui_ChannelNo < 0 || ui_ChannelNo > 15) { + printk("\nThe Selection of the channel is in error\n"); + i_err++; + } // if(ui_ChannelNo<0 || ui_ChannelNo>15) + } //if(data[5]==0) + else { + if (data[14] == 2) { + if (ui_ChannelNo < 0 || ui_ChannelNo > 3) { + printk("\nThe Selection of the channel is in error\n"); + i_err++; + } // if(ui_ChannelNo<0 || ui_ChannelNo>3) + } //if(data[14]==2) + else { + if (ui_ChannelNo < 0 || ui_ChannelNo > 7) { + printk("\nThe Selection of the channel is in error\n"); + i_err++; + } // if(ui_ChannelNo<0 || ui_ChannelNo>7) + } //elseif(data[14]==2) + } //elseif(data[5]==0) + if (data[12] == 0 || data[12] == 1) { + switch (data[5]) { + case 0: + if (ui_ChannelNo >= 0 && ui_ChannelNo <= 3) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=0; + s_BoardInfos[dev->minor].i_Offset = 0; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo >=0 && ui_ChannelNo <=3) + if (ui_ChannelNo >= 4 && ui_ChannelNo <= 7) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=64; + s_BoardInfos[dev->minor].i_Offset = 64; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo >=4 && ui_ChannelNo <=7) + if (ui_ChannelNo >= 8 && ui_ChannelNo <= 11) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=128; + s_BoardInfos[dev->minor].i_Offset = 128; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo >=8 && ui_ChannelNo <=11) + if (ui_ChannelNo >= 12 && ui_ChannelNo <= 15) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=192; + s_BoardInfos[dev->minor].i_Offset = 192; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo >=12 && ui_ChannelNo <=15) + break; + case 1: + if (data[14] == 2) { + if (ui_ChannelNo == 0) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=0; + s_BoardInfos[dev->minor].i_Offset = 0; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo ==0 ) + if (ui_ChannelNo == 1) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=0; + s_BoardInfos[dev->minor].i_Offset = 64; + //END JK 06.07.04: Management of sevrals boards + } // if(ui_ChannelNo ==1) + if (ui_ChannelNo == 2) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=128; + s_BoardInfos[dev->minor].i_Offset = 128; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo ==2 ) + if (ui_ChannelNo == 3) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=192; + s_BoardInfos[dev->minor].i_Offset = 192; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo ==3) + + //BEGIN JK 06.07.04: Management of sevrals boards + //i_ChannelNo=0; + s_BoardInfos[dev->minor].i_ChannelNo = 0; + //END JK 06.07.04: Management of sevrals boards + ui_ChannelNo = 0; + break; + } //if(data[14]==2) + if (ui_ChannelNo >= 0 && ui_ChannelNo <= 1) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=0; + s_BoardInfos[dev->minor].i_Offset = 0; + //END JK 06.07.04: Management of sevrals boards + } //if(ui_ChannelNo >=0 && ui_ChannelNo <=1) + if (ui_ChannelNo >= 2 && ui_ChannelNo <= 3) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_ChannelNo=i_ChannelNo-2; + //i_Offset=64; + s_BoardInfos[dev->minor].i_ChannelNo = + s_BoardInfos[dev->minor].i_ChannelNo - + 2; + s_BoardInfos[dev->minor].i_Offset = 64; + //END JK 06.07.04: Management of sevrals boards + ui_ChannelNo = ui_ChannelNo - 2; + } //if(ui_ChannelNo >=2 && ui_ChannelNo <=3) + if (ui_ChannelNo >= 4 && ui_ChannelNo <= 5) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_ChannelNo=i_ChannelNo-4; + //i_Offset=128; + s_BoardInfos[dev->minor].i_ChannelNo = + s_BoardInfos[dev->minor].i_ChannelNo - + 4; + s_BoardInfos[dev->minor].i_Offset = 128; + //END JK 06.07.04: Management of sevrals boards + ui_ChannelNo = ui_ChannelNo - 4; + } //if(ui_ChannelNo >=4 && ui_ChannelNo <=5) + if (ui_ChannelNo >= 6 && ui_ChannelNo <= 7) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_ChannelNo=i_ChannelNo-6; + //i_Offset=192; + s_BoardInfos[dev->minor].i_ChannelNo = + s_BoardInfos[dev->minor].i_ChannelNo - + 6; + s_BoardInfos[dev->minor].i_Offset = 192; + //END JK 06.07.04: Management of sevrals boards + ui_ChannelNo = ui_ChannelNo - 6; + } //if(ui_ChannelNo >=6 && ui_ChannelNo <=7) + break; + + default: + printk("\n This selection of polarity does not exist\n"); + i_err++; + } //switch(data[2]) + } //if(data[12]==0 || data[12]==1) + else { + switch (data[11]) { + case 1: + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=0; + s_BoardInfos[dev->minor].i_Offset = 0; + //END JK 06.07.04: Management of sevrals boards + break; + case 2: + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=64; + s_BoardInfos[dev->minor].i_Offset = 64; + //END JK 06.07.04: Management of sevrals boards + break; + case 3: + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=128; + s_BoardInfos[dev->minor].i_Offset = 128; + //END JK 06.07.04: Management of sevrals boards + break; + case 4: + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Offset=192; + s_BoardInfos[dev->minor].i_Offset = 192; + //END JK 06.07.04: Management of sevrals boards + break; + default: + printk("\nError in module selection\n"); + i_err++; + } // switch(data[11]) + } // elseif(data[12]==0 || data[12]==1) + if (i_err) { + i_APCI3200_Reset(dev); + return -EINVAL; + } + //if(i_ScanType!=1) + if (s_BoardInfos[dev->minor].i_ScanType != 1) { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Count=0; + //i_Sum=0; + s_BoardInfos[dev->minor].i_Count = 0; + s_BoardInfos[dev->minor].i_Sum = 0; + //END JK 06.07.04: Management of sevrals boards + } //if(i_ScanType!=1) + + ul_Config = + data[1] | (data[2] << 6) | (data[5] << 7) | (data[3] << 8) | + (data[4] << 9); + //BEGIN JK 06.07.04: Management of sevrals boards + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //END JK 06.07.04: Management of sevrals boards /*********************************/ - /* Write the channel to configure*/ + /* Write the channel to configure */ /*********************************/ - //BEGIN JK 06.07.04: Management of sevrals boards - //outl(0 | ui_ChannelNo , devpriv->iobase+i_Offset + 0x4); - outl(0 | ui_ChannelNo , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); - //END JK 06.07.04: Management of sevrals boards - - //BEGIN JK 06.07.04: Management of sevrals boards - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //END JK 06.07.04: Management of sevrals boards - /**************************/ - /* Reset the configuration */ - /**************************/ - //BEGIN JK 06.07.04: Management of sevrals boards - //outl(0 , devpriv->iobase+i_Offset + 0x0); - outl(0 , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x0); - //END JK 06.07.04: Management of sevrals boards - - //BEGIN JK 06.07.04: Management of sevrals boards - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //END JK 06.07.04: Management of sevrals boards - + //BEGIN JK 06.07.04: Management of sevrals boards + //outl(0 | ui_ChannelNo , devpriv->iobase+i_Offset + 0x4); + outl(0 | ui_ChannelNo, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x4); + //END JK 06.07.04: Management of sevrals boards + + //BEGIN JK 06.07.04: Management of sevrals boards + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //END JK 06.07.04: Management of sevrals boards + /**************************/ + /* Reset the configuration */ + /**************************/ + //BEGIN JK 06.07.04: Management of sevrals boards + //outl(0 , devpriv->iobase+i_Offset + 0x0); + outl(0, devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x0); + //END JK 06.07.04: Management of sevrals boards + + //BEGIN JK 06.07.04: Management of sevrals boards + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //END JK 06.07.04: Management of sevrals boards + /***************************/ - /* Write the configuration */ + /* Write the configuration */ /***************************/ - //BEGIN JK 06.07.04: Management of sevrals boards - //outl(ul_Config , devpriv->iobase+i_Offset + 0x0); - outl(ul_Config , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x0); - //END JK 06.07.04: Management of sevrals boards + //BEGIN JK 06.07.04: Management of sevrals boards + //outl(ul_Config , devpriv->iobase+i_Offset + 0x0); + outl(ul_Config, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x0); + //END JK 06.07.04: Management of sevrals boards /***************************/ - /*Reset the calibration bit*/ + /*Reset the calibration bit */ /***************************/ - //BEGIN JK 06.07.04: Management of sevrals boards - //ul_Temp = inl(devpriv->iobase+i_Offset + 12); - ul_Temp = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); - //END JK 06.07.04: Management of sevrals boards - - //BEGIN JK 06.07.04: Management of sevrals boards - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //END JK 06.07.04: Management of sevrals boards - - //BEGIN JK 06.07.04: Management of sevrals boards - //outl((ul_Temp & 0xFFF9FFFF) , devpriv->iobase+.i_Offset + 12); - outl((ul_Temp & 0xFFF9FFFF) , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); - //END JK 06.07.04: Management of sevrals boards - - if(data[9]==1) - { - devpriv->tsk_Current=current; - //BEGIN JK 06.07.04: Management of sevrals boards - //i_InterruptFlag=1; - s_BoardInfos [dev->minor].i_InterruptFlag=1; - //END JK 06.07.04: Management of sevrals boards - }// if(data[9]==1) - else - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - //END JK 06.07.04: Management of sevrals boards - }//else if(data[9]==1) - - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Initialised=1; - s_BoardInfos [dev->minor].i_Initialised=1; - //END JK 06.07.04: Management of sevrals boards - - //BEGIN JK 06.07.04: Management of sevrals boards - //if(i_ScanType==1) - if(s_BoardInfos [dev->minor].i_ScanType==1) - //END JK 06.07.04: Management of sevrals boards - { - //BEGIN JK 06.07.04: Management of sevrals boards - //i_Sum=i_Sum+1; - s_BoardInfos [dev->minor].i_Sum=s_BoardInfos [dev->minor].i_Sum+1; - //END JK 06.07.04: Management of sevrals boards - - insn->unused[0]=0; - i_APCI3200_ReadAnalogInput(dev,s,insn,&ui_Dummy); - } - - return insn->n; -} + //BEGIN JK 06.07.04: Management of sevrals boards + //ul_Temp = inl(devpriv->iobase+i_Offset + 12); + ul_Temp = inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); + //END JK 06.07.04: Management of sevrals boards + + //BEGIN JK 06.07.04: Management of sevrals boards + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //END JK 06.07.04: Management of sevrals boards + + //BEGIN JK 06.07.04: Management of sevrals boards + //outl((ul_Temp & 0xFFF9FFFF) , devpriv->iobase+.i_Offset + 12); + outl((ul_Temp & 0xFFF9FFFF), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); + //END JK 06.07.04: Management of sevrals boards + + if (data[9] == 1) { + devpriv->tsk_Current = current; + //BEGIN JK 06.07.04: Management of sevrals boards + //i_InterruptFlag=1; + s_BoardInfos[dev->minor].i_InterruptFlag = 1; + //END JK 06.07.04: Management of sevrals boards + } // if(data[9]==1) + else { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_InterruptFlag=0; + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + //END JK 06.07.04: Management of sevrals boards + } //else if(data[9]==1) + + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Initialised=1; + s_BoardInfos[dev->minor].i_Initialised = 1; + //END JK 06.07.04: Management of sevrals boards + + //BEGIN JK 06.07.04: Management of sevrals boards + //if(i_ScanType==1) + if (s_BoardInfos[dev->minor].i_ScanType == 1) + //END JK 06.07.04: Management of sevrals boards + { + //BEGIN JK 06.07.04: Management of sevrals boards + //i_Sum=i_Sum+1; + s_BoardInfos[dev->minor].i_Sum = + s_BoardInfos[dev->minor].i_Sum + 1; + //END JK 06.07.04: Management of sevrals boards + + insn->unused[0] = 0; + i_APCI3200_ReadAnalogInput(dev, s, insn, &ui_Dummy); + } + + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -1384,228 +1361,273 @@ INT i_APCI3200_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -INT i_APCI3200_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - UINT ui_DummyValue=0; - int i_ConvertCJCCalibration; - int i=0; - - //BEGIN JK 06.07.04: Management of sevrals boards - //if(i_Initialised==0) - if(s_BoardInfos [dev->minor].i_Initialised==0) - //END JK 06.07.04: Management of sevrals boards - { - i_APCI3200_Reset(dev); - return -EINVAL; - }//if(i_Initialised==0); - -#ifdef PRINT_INFO - printk ("\n insn->unused[0] = %i", insn->unused[0]); +INT i_APCI3200_ReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_DummyValue = 0; + int i_ConvertCJCCalibration; + int i = 0; + + //BEGIN JK 06.07.04: Management of sevrals boards + //if(i_Initialised==0) + if (s_BoardInfos[dev->minor].i_Initialised == 0) + //END JK 06.07.04: Management of sevrals boards + { + i_APCI3200_Reset(dev); + return -EINVAL; + } //if(i_Initialised==0); + +#ifdef PRINT_INFO + printk("\n insn->unused[0] = %i", insn->unused[0]); #endif - - switch(insn->unused[0]) - { - case 0: - - i_APCI3200_Read1AnalogInputChannel(dev,s,insn,&ui_DummyValue); - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count+0]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+0]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - - //Begin JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - i_APCI3200_GetChannelCalibrationValue (dev,s_BoardInfos [dev->minor].ui_Channel_num, - &s_BoardInfos [dev->minor].ui_InterruptChannelValue [s_BoardInfos [dev->minor].i_Count+6], - &s_BoardInfos [dev->minor].ui_InterruptChannelValue [s_BoardInfos [dev->minor].i_Count+7], - &s_BoardInfos [dev->minor].ui_InterruptChannelValue [s_BoardInfos [dev->minor].i_Count+8]); - -#ifdef PRINT_INFO - printk ("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+6] = %lu", s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+6]); - - printk ("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+7] = %lu", s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+7]); - - printk ("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+8] = %lu", s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+8]); + + switch (insn->unused[0]) { + case 0: + + i_APCI3200_Read1AnalogInputChannel(dev, s, insn, + &ui_DummyValue); + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count+0]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev->minor]. + i_Count + 0] = ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + + //Begin JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + i_APCI3200_GetChannelCalibrationValue(dev, + s_BoardInfos[dev->minor].ui_Channel_num, + &s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev->minor]. + i_Count + 6], + &s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev->minor]. + i_Count + 7], + &s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev->minor]. + i_Count + 8]); + +#ifdef PRINT_INFO + printk("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+6] = %lu", s_BoardInfos[dev->minor].ui_InterruptChannelValue[s_BoardInfos[dev->minor].i_Count + 6]); + + printk("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+7] = %lu", s_BoardInfos[dev->minor].ui_InterruptChannelValue[s_BoardInfos[dev->minor].i_Count + 7]); + + printk("\n s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+8] = %lu", s_BoardInfos[dev->minor].ui_InterruptChannelValue[s_BoardInfos[dev->minor].i_Count + 8]); #endif - - //End JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - - //BEGIN JK 06.07.04: Management of sevrals boards - //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) - if((s_BoardInfos [dev->minor].i_ADDIDATAType==2) && (s_BoardInfos [dev->minor].i_InterruptFlag == FALSE) && (s_BoardInfos [dev->minor].i_CJCAvailable==1)) - //END JK 06.07.04: Management of sevrals boards - { - i_APCI3200_ReadCJCValue(dev,&ui_DummyValue); - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count + 3]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 3]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - }//if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) - else - { - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count + 3]=0; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 3]=0; - //END JK 06.07.04: Management of sevrals boards - }//elseif((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) - - //BEGIN JK 06.07.04: Management of sevrals boards - //if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) - if ((s_BoardInfos [dev->minor].i_AutoCalibration == FALSE) && (s_BoardInfos [dev->minor].i_InterruptFlag == FALSE)) - //END JK 06.07.04: Management of sevrals boards - { - i_APCI3200_ReadCalibrationOffsetValue(dev,&ui_DummyValue); - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count + 1]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 1]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - i_APCI3200_ReadCalibrationGainValue(dev,&ui_DummyValue); - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count + 2]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 2]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - }//if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) - - //BEGIN JK 06.07.04: Management of sevrals boards - //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)&& (i_CJCAvailable==1)) - if((s_BoardInfos [dev->minor].i_ADDIDATAType==2) && (s_BoardInfos [dev->minor].i_InterruptFlag == FALSE)&& (s_BoardInfos [dev->minor].i_CJCAvailable==1)) - //END JK 06.07.04: Management of sevrals boards - { + + //End JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + + //BEGIN JK 06.07.04: Management of sevrals boards + //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) + if ((s_BoardInfos[dev->minor].i_ADDIDATAType == 2) + && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE) + && (s_BoardInfos[dev->minor].i_CJCAvailable == 1)) + //END JK 06.07.04: Management of sevrals boards + { + i_APCI3200_ReadCJCValue(dev, &ui_DummyValue); + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count + 3]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev-> + minor].i_Count + 3] = ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + } //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) + else { + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count + 3]=0; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev-> + minor].i_Count + 3] = 0; + //END JK 06.07.04: Management of sevrals boards + } //elseif((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) + + //BEGIN JK 06.07.04: Management of sevrals boards + //if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) + if ((s_BoardInfos[dev->minor].i_AutoCalibration == FALSE) + && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE)) + //END JK 06.07.04: Management of sevrals boards + { + i_APCI3200_ReadCalibrationOffsetValue(dev, + &ui_DummyValue); + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count + 1]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev-> + minor].i_Count + 1] = ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + i_APCI3200_ReadCalibrationGainValue(dev, + &ui_DummyValue); + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count + 2]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos[dev-> + minor].i_Count + 2] = ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + } //if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) + + //BEGIN JK 06.07.04: Management of sevrals boards + //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)&& (i_CJCAvailable==1)) + if ((s_BoardInfos[dev->minor].i_ADDIDATAType == 2) + && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE) + && (s_BoardInfos[dev->minor].i_CJCAvailable == 1)) + //END JK 06.07.04: Management of sevrals boards + { /**********************************************************/ - /*Test if the Calibration channel must be read for the CJC*/ + /*Test if the Calibration channel must be read for the CJC */ /**********************************************************/ /**********************************/ - /*Test if the polarity is the same*/ - /**********************************/ - //BEGIN JK 06.07.04: Management of sevrals boards - //if(i_CJCPolarity!=i_ADDIDATAPolarity) - if(s_BoardInfos [dev->minor].i_CJCPolarity!=s_BoardInfos [dev->minor].i_ADDIDATAPolarity) - //END JK 06.07.04: Management of sevrals boards - { - i_ConvertCJCCalibration=1; - }//if(i_CJCPolarity!=i_ADDIDATAPolarity) - else - { - //BEGIN JK 06.07.04: Management of sevrals boards - //if(i_CJCGain==i_ADDIDATAGain) - if(s_BoardInfos [dev->minor].i_CJCGain==s_BoardInfos [dev->minor].i_ADDIDATAGain) - //END JK 06.07.04: Management of sevrals boards - { - i_ConvertCJCCalibration=0; - }//if(i_CJCGain==i_ADDIDATAGain) - else - { - i_ConvertCJCCalibration=1; - }//elseif(i_CJCGain==i_ADDIDATAGain) - }//elseif(i_CJCPolarity!=i_ADDIDATAPolarity) - if(i_ConvertCJCCalibration==1) - { - i_APCI3200_ReadCJCCalOffset(dev,&ui_DummyValue); - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count+4]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+4]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - - i_APCI3200_ReadCJCCalGain(dev,&ui_DummyValue); - - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count+5]=ui_DummyValue; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+5]=ui_DummyValue; - //END JK 06.07.04: Management of sevrals boards - }//if(i_ConvertCJCCalibration==1) - else - { - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_InterruptChannelValue[i_Count+4]=0; - //ui_InterruptChannelValue[i_Count+5]=0; - - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+4]=0; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count+5]=0; - //END JK 06.07.04: Management of sevrals boards - }//elseif(i_ConvertCJCCalibration==1) - }//if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) - - //BEGIN JK 06.07.04: Management of sevrals boards - //if(i_ScanType!=1) - if(s_BoardInfos [dev->minor].i_ScanType!=1) - { - //i_Count=0; - s_BoardInfos [dev->minor].i_Count=0; - }//if(i_ScanType!=1) - else - { - //i_Count=i_Count +6; - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count +6; - s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count +9; - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - }//else if(i_ScanType!=1) - - //if((i_ScanType==1) &&(i_InterruptFlag==1)) - if((s_BoardInfos [dev->minor].i_ScanType==1) &&(s_BoardInfos [dev->minor].i_InterruptFlag==1)) - { - //i_Count=i_Count-6; - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count-6; - s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count-9; - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - } - //if(i_ScanType==0) - if(s_BoardInfos [dev->minor].i_ScanType==0) - { - /* - data[0]= ui_InterruptChannelValue[0]; - data[1]= ui_InterruptChannelValue[1]; - data[2]= ui_InterruptChannelValue[2]; - data[3]= ui_InterruptChannelValue[3]; - data[4]= ui_InterruptChannelValue[4]; - data[5]= ui_InterruptChannelValue[5]; - */ -#ifdef PRINT_INFO - printk("\n data[0]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[0];"); -#endif - data[0]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[0]; - data[1]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[1]; - data[2]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[2]; - data[3]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[3]; - data[4]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[4]; - data[5]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[5]; - - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - //printk("\n 0 - i_APCI3200_GetChannelCalibrationValue data [6] = %lu, data [7] = %lu, data [8] = %lu", data [6], data [7], data [8]); - i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos [dev->minor].ui_Channel_num, &data [6], &data [7], &data [8]); - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - } - break; - case 1 : - - for(i=0;in;i++) - { - //data[i]=ui_InterruptChannelValue[i]; - data[i]=s_BoardInfos [dev->minor].ui_InterruptChannelValue[i]; - } - - //i_Count=0; - //i_Sum=0; - //if(i_ScanType==1) - s_BoardInfos [dev->minor].i_Count=0; - s_BoardInfos [dev->minor].i_Sum=0; - if(s_BoardInfos [dev->minor].i_ScanType==1) - { - //i_Initialised=0; - //i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_Initialised=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - //END JK 06.07.04: Management of sevrals boards - } - break; - default:printk("\nThe parameters passed are in error\n"); - i_APCI3200_Reset(dev); - return -EINVAL; - }//switch(insn->unused[0]) - - - - return insn->n; + /*Test if the polarity is the same */ + /**********************************/ + //BEGIN JK 06.07.04: Management of sevrals boards + //if(i_CJCPolarity!=i_ADDIDATAPolarity) + if (s_BoardInfos[dev->minor].i_CJCPolarity != + s_BoardInfos[dev->minor].i_ADDIDATAPolarity) + //END JK 06.07.04: Management of sevrals boards + { + i_ConvertCJCCalibration = 1; + } //if(i_CJCPolarity!=i_ADDIDATAPolarity) + else { + //BEGIN JK 06.07.04: Management of sevrals boards + //if(i_CJCGain==i_ADDIDATAGain) + if (s_BoardInfos[dev->minor].i_CJCGain == + s_BoardInfos[dev->minor].i_ADDIDATAGain) + //END JK 06.07.04: Management of sevrals boards + { + i_ConvertCJCCalibration = 0; + } //if(i_CJCGain==i_ADDIDATAGain) + else { + i_ConvertCJCCalibration = 1; + } //elseif(i_CJCGain==i_ADDIDATAGain) + } //elseif(i_CJCPolarity!=i_ADDIDATAPolarity) + if (i_ConvertCJCCalibration == 1) { + i_APCI3200_ReadCJCCalOffset(dev, + &ui_DummyValue); + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count+4]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos + [dev->minor].i_Count + 4] = + ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + + i_APCI3200_ReadCJCCalGain(dev, &ui_DummyValue); + + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count+5]=ui_DummyValue; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos + [dev->minor].i_Count + 5] = + ui_DummyValue; + //END JK 06.07.04: Management of sevrals boards + } //if(i_ConvertCJCCalibration==1) + else { + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_InterruptChannelValue[i_Count+4]=0; + //ui_InterruptChannelValue[i_Count+5]=0; + + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos + [dev->minor].i_Count + 4] = 0; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[s_BoardInfos + [dev->minor].i_Count + 5] = 0; + //END JK 06.07.04: Management of sevrals boards + } //elseif(i_ConvertCJCCalibration==1) + } //if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) + + //BEGIN JK 06.07.04: Management of sevrals boards + //if(i_ScanType!=1) + if (s_BoardInfos[dev->minor].i_ScanType != 1) { + //i_Count=0; + s_BoardInfos[dev->minor].i_Count = 0; + } //if(i_ScanType!=1) + else { + //i_Count=i_Count +6; + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count +6; + s_BoardInfos[dev->minor].i_Count = + s_BoardInfos[dev->minor].i_Count + 9; + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } //else if(i_ScanType!=1) + + //if((i_ScanType==1) &&(i_InterruptFlag==1)) + if ((s_BoardInfos[dev->minor].i_ScanType == 1) + && (s_BoardInfos[dev->minor].i_InterruptFlag == 1)) { + //i_Count=i_Count-6; + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count-6; + s_BoardInfos[dev->minor].i_Count = + s_BoardInfos[dev->minor].i_Count - 9; + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } + //if(i_ScanType==0) + if (s_BoardInfos[dev->minor].i_ScanType == 0) { + /* + data[0]= ui_InterruptChannelValue[0]; + data[1]= ui_InterruptChannelValue[1]; + data[2]= ui_InterruptChannelValue[2]; + data[3]= ui_InterruptChannelValue[3]; + data[4]= ui_InterruptChannelValue[4]; + data[5]= ui_InterruptChannelValue[5]; + */ +#ifdef PRINT_INFO + printk("\n data[0]= s_BoardInfos [dev->minor].ui_InterruptChannelValue[0];"); +#endif + data[0] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[0]; + data[1] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[1]; + data[2] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[2]; + data[3] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[3]; + data[4] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[4]; + data[5] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[5]; + + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //printk("\n 0 - i_APCI3200_GetChannelCalibrationValue data [6] = %lu, data [7] = %lu, data [8] = %lu", data [6], data [7], data [8]); + i_APCI3200_GetChannelCalibrationValue(dev, + s_BoardInfos[dev->minor].ui_Channel_num, + &data[6], &data[7], &data[8]); + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } + break; + case 1: + + for (i = 0; i < insn->n; i++) { + //data[i]=ui_InterruptChannelValue[i]; + data[i] = + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue[i]; + } + + //i_Count=0; + //i_Sum=0; + //if(i_ScanType==1) + s_BoardInfos[dev->minor].i_Count = 0; + s_BoardInfos[dev->minor].i_Sum = 0; + if (s_BoardInfos[dev->minor].i_ScanType == 1) { + //i_Initialised=0; + //i_InterruptFlag=0; + s_BoardInfos[dev->minor].i_Initialised = 0; + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + //END JK 06.07.04: Management of sevrals boards + } + break; + default: + printk("\nThe parameters passed are in error\n"); + i_APCI3200_Reset(dev); + return -EINVAL; + } //switch(insn->unused[0]) + + return insn->n; } /* @@ -1629,102 +1651,110 @@ INT i_APCI3200_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_ins | | +----------------------------------------------------------------------------+ */ -INT i_APCI3200_Read1AnalogInputChannel(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ - UINT ui_EOC=0; - UINT ui_ChannelNo=0; - UINT ui_CommandRegister=0; - - //BEGIN JK 06.07.04: Management of sevrals boards - //ui_ChannelNo=i_ChannelNo; - ui_ChannelNo=s_BoardInfos [dev->minor].i_ChannelNo; - - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); +INT i_APCI3200_Read1AnalogInputChannel(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + UINT ui_EOC = 0; + UINT ui_ChannelNo = 0; + UINT ui_CommandRegister = 0; + + //BEGIN JK 06.07.04: Management of sevrals boards + //ui_ChannelNo=i_ChannelNo; + ui_ChannelNo = s_BoardInfos[dev->minor].i_ChannelNo; + + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; /*********************************/ - /* Write the channel to configure*/ + /* Write the channel to configure */ /*********************************/ - //Begin JK 20.10.2004: Bad channel value is used when using differential mode - //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); - //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); - outl(0 | s_BoardInfos [dev->minor].i_ChannelNo , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); - //End JK 20.10.2004: Bad channel value is used when using differential mode - + //Begin JK 20.10.2004: Bad channel value is used when using differential mode + //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); + //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); + outl(0 | s_BoardInfos[dev->minor].i_ChannelNo, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x4); + //End JK 20.10.2004: Bad channel value is used when using differential mode + /*******************************/ - /* Set the convert timing unit */ + /* Set the convert timing unit */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); - /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); - + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); + + /**************************************************************************/ + /* Set the start end stop index to the selected channel and set the start */ /**************************************************************************/ - /* Set the start end stop index to the selected channel and set the start */ - /**************************************************************************/ - ui_CommandRegister = ui_ChannelNo | (ui_ChannelNo << 8) | 0x80000; - + ui_CommandRegister = ui_ChannelNo | (ui_ChannelNo << 8) | 0x80000; + /*********************************/ - /*Test if the interrupt is enable*/ + /*Test if the interrupt is enable */ /*********************************/ - - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { + + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { /************************/ - /* Enable the interrupt */ + /* Enable the interrupt */ /************************/ - ui_CommandRegister = ui_CommandRegister | 0x00100000; - }//if (i_InterruptFlag == ADDIDATA_ENABLE) - + ui_CommandRegister = ui_CommandRegister | 0x00100000; + } //if (i_InterruptFlag == ADDIDATA_ENABLE) + /******************************/ - /* Write the command register */ + /* Write the command register */ /******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; - //outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister, devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); + //outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); /*****************************/ - /*Test if interrupt is enable*/ - /*****************************/ - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - do - { + /*Test if interrupt is enable */ + /*****************************/ + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + do { /*************************/ - /*Read the EOC Status bit*/ + /*Read the EOC Status bit */ /*************************/ - - //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); - + //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + + } while (ui_EOC != 1); /***************************************/ - /* Read the digital value of the input */ + /* Read the digital value of the input */ /***************************************/ - - //data[0] = inl (devpriv->iobase+i_Offset + 28); - data[0] = inl (devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - //END JK 06.07.04: Management of sevrals boards - - }// if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; -} + //data[0] = inl (devpriv->iobase+i_Offset + 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + //END JK 06.07.04: Management of sevrals boards + + } // if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; +} /* +----------------------------------------------------------------------------+ @@ -1746,114 +1776,120 @@ INT i_APCI3200_Read1AnalogInputChannel(comedi_device *dev,comedi_subdevice *s,co | | +----------------------------------------------------------------------------+ */ -int i_APCI3200_ReadCalibrationOffsetValue(comedi_device *dev,UINT *data) +int i_APCI3200_ReadCalibrationOffsetValue(comedi_device * dev, UINT * data) { - UINT ui_Temp=0 , ui_EOC=0; - UINT ui_CommandRegister=0; - - //BEGIN JK 06.07.04: Management of sevrals boards - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + UINT ui_Temp = 0, ui_EOC = 0; + UINT ui_CommandRegister = 0; + + //BEGIN JK 06.07.04: Management of sevrals boards + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + /*********************************/ + /* Write the channel to configure */ /*********************************/ - /* Write the channel to configure*/ - /*********************************/ - //Begin JK 20.10.2004: This seems not necessary ! - //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); - //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); - //End JK 20.10.2004: This seems not necessary ! - + //Begin JK 20.10.2004: This seems not necessary ! + //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); + //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); + //End JK 20.10.2004: This seems not necessary ! + /*******************************/ - /* Set the convert timing unit */ + /* Set the convert timing unit */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); /*****************************/ - /*Read the calibration offset*/ + /*Read the calibration offset */ /*****************************/ - //ui_Temp = inl(devpriv->iobase+i_Offset + 12); - ui_Temp = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); + //ui_Temp = inl(devpriv->iobase+i_Offset + 12); + ui_Temp = inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /*********************************/ - /*Configure the Offset Conversion*/ + /*Configure the Offset Conversion */ /*********************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((ui_Temp | 0x00020000), devpriv->iobase+i_Offset + 12); - outl((ui_Temp | 0x00020000), devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl((ui_Temp | 0x00020000), devpriv->iobase+i_Offset + 12); + outl((ui_Temp | 0x00020000), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /*******************************/ - /*Initialise ui_CommandRegister*/ + /*Initialise ui_CommandRegister */ /*******************************/ - - ui_CommandRegister = 0; + + ui_CommandRegister = 0; /*********************************/ - /*Test if the interrupt is enable*/ + /*Test if the interrupt is enable */ /*********************************/ - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { - + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { + /**********************/ - /*Enable the interrupt*/ + /*Enable the interrupt */ /**********************/ - ui_CommandRegister = ui_CommandRegister | 0x00100000; + ui_CommandRegister = ui_CommandRegister | 0x00100000; + + } //if (i_InterruptFlag == ADDIDATA_ENABLE) - }//if (i_InterruptFlag == ADDIDATA_ENABLE) - /**********************/ - /*Start the conversion*/ + /*Start the conversion */ /**********************/ - ui_CommandRegister = ui_CommandRegister | 0x00080000; - + ui_CommandRegister = ui_CommandRegister | 0x00080000; /***************************/ - /*Write the command regiter*/ + /*Write the command regiter */ /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister, devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); /*****************************/ - /*Test if interrupt is enable*/ + /*Test if interrupt is enable */ /*****************************/ - - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - - do - { + + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + + do { /*******************/ - /*Read the EOC flag*/ + /*Read the EOC flag */ /*******************/ - - //ui_EOC = inl (devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl (devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); - + //ui_EOC = inl (devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + + } while (ui_EOC != 1); /**************************************************/ - /*Read the digital value of the calibration Offset*/ + /*Read the digital value of the calibration Offset */ /**************************************************/ - - //data[0] = inl(devpriv->iobase+i_Offset+ 28); - data[0] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+ 28); - }//if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; + //data[0] = inl(devpriv->iobase+i_Offset+ 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + } //if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; } /* @@ -1875,112 +1911,120 @@ int i_APCI3200_ReadCalibrationOffsetValue(comedi_device *dev,UINT *data) | : FALSE : Error occur. Return the error | | | +----------------------------------------------------------------------------+ -*/ -int i_APCI3200_ReadCalibrationGainValue(comedi_device *dev,UINT *data) +*/ +int i_APCI3200_ReadCalibrationGainValue(comedi_device * dev, UINT * data) { - UINT ui_EOC=0; - INT ui_CommandRegister=0; + UINT ui_EOC = 0; + INT ui_CommandRegister = 0; - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; /*********************************/ - /* Write the channel to configure*/ + /* Write the channel to configure */ /*********************************/ - //Begin JK 20.10.2004: This seems not necessary ! - //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); - //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); - //End JK 20.10.2004: This seems not necessary ! - + //Begin JK 20.10.2004: This seems not necessary ! + //outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); + //outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); + //End JK 20.10.2004: This seems not necessary ! + /***************************/ - /*Read the calibration gain*/ + /*Read the calibration gain */ /***************************/ /*******************************/ - /* Set the convert timing unit */ + /* Set the convert timing unit */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); /*******************************/ - /*Configure the Gain Conversion*/ + /*Configure the Gain Conversion */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(0x00040000 , devpriv->iobase+i_Offset + 12); - outl(0x00040000 , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); - + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(0x00040000 , devpriv->iobase+i_Offset + 12); + outl(0x00040000, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /*******************************/ - /*Initialise ui_CommandRegister*/ + /*Initialise ui_CommandRegister */ /*******************************/ - ui_CommandRegister = 0; + ui_CommandRegister = 0; /*********************************/ - /*Test if the interrupt is enable*/ + /*Test if the interrupt is enable */ /*********************************/ - - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { - + + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { + /**********************/ - /*Enable the interrupt*/ + /*Enable the interrupt */ /**********************/ - - ui_CommandRegister = ui_CommandRegister | 0x00100000; - }//if (i_InterruptFlag == ADDIDATA_ENABLE) - + ui_CommandRegister = ui_CommandRegister | 0x00100000; + + } //if (i_InterruptFlag == ADDIDATA_ENABLE) + /**********************/ - /*Start the conversion*/ + /*Start the conversion */ /**********************/ - - ui_CommandRegister = ui_CommandRegister | 0x00080000; + + ui_CommandRegister = ui_CommandRegister | 0x00080000; /***************************/ - /*Write the command regiter*/ + /*Write the command regiter */ /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); /*****************************/ - /*Test if interrupt is enable*/ + /*Test if interrupt is enable */ /*****************************/ - - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - - do - { - + + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + + do { + /*******************/ - /*Read the EOC flag*/ + /*Read the EOC flag */ /*******************/ - - //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); - + //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + + } while (ui_EOC != 1); + /************************************************/ - /*Read the digital value of the calibration Gain*/ + /*Read the digital value of the calibration Gain */ /************************************************/ - //data[0] = inl(devpriv->iobase+i_Offset + 28); - data[0] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); + //data[0] = inl(devpriv->iobase+i_Offset + 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); - }//if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; + } //if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; } /* @@ -2002,98 +2046,106 @@ int i_APCI3200_ReadCalibrationGainValue(comedi_device *dev,UINT *data) | : FALSE : Error occur. Return the error | | | +----------------------------------------------------------------------------+ -*/ +*/ -int i_APCI3200_ReadCJCValue(comedi_device *dev,lsampl_t *data) +int i_APCI3200_ReadCJCValue(comedi_device * dev, lsampl_t * data) { - UINT ui_EOC=0; - INT ui_CommandRegister=0; - + UINT ui_EOC = 0; + INT ui_CommandRegister = 0; + /******************************/ - /*Set the converting time unit*/ + /*Set the converting time unit */ /******************************/ - - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); /******************************/ - /*Configure the CJC Conversion*/ + /*Configure the CJC Conversion */ /******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; - //outl( 0x00000400 , devpriv->iobase+i_Offset + 4); - outl( 0x00000400 , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //outl( 0x00000400 , devpriv->iobase+i_Offset + 4); + outl(0x00000400, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4); /*******************************/ - /*Initialise dw_CommandRegister*/ + /*Initialise dw_CommandRegister */ /*******************************/ - ui_CommandRegister = 0; + ui_CommandRegister = 0; /*********************************/ - /*Test if the interrupt is enable*/ - /*********************************/ - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { + /*Test if the interrupt is enable */ + /*********************************/ + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { /**********************/ - /*Enable the interrupt*/ + /*Enable the interrupt */ /**********************/ - ui_CommandRegister =ui_CommandRegister | 0x00100000; - } - + ui_CommandRegister = ui_CommandRegister | 0x00100000; + } + /**********************/ - /*Start the conversion*/ + /*Start the conversion */ /**********************/ - - ui_CommandRegister = ui_CommandRegister | 0x00080000; + + ui_CommandRegister = ui_CommandRegister | 0x00080000; /***************************/ - /*Write the command regiter*/ + /*Write the command regiter */ /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); - + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); + /*****************************/ - /*Test if interrupt is enable*/ + /*Test if interrupt is enable */ /*****************************/ - - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - do - { - + + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + do { + /*******************/ - /*Read the EOC flag*/ + /*Read the EOC flag */ /*******************/ - - //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); - + //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + + } while (ui_EOC != 1); + /***********************************/ - /*Read the digital value of the CJC*/ + /*Read the digital value of the CJC */ /***********************************/ - - //data[0] = inl(devpriv->iobase+i_Offset + 28); - data[0] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - }//if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; -} + //data[0] = inl(devpriv->iobase+i_Offset + 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + + } //if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; +} /* +----------------------------------------------------------------------------+ @@ -2115,90 +2167,100 @@ int i_APCI3200_ReadCJCValue(comedi_device *dev,lsampl_t *data) | | +----------------------------------------------------------------------------+ */ -int i_APCI3200_ReadCJCCalOffset(comedi_device *dev,lsampl_t *data) +int i_APCI3200_ReadCJCCalOffset(comedi_device * dev, lsampl_t * data) { - UINT ui_EOC=0; - INT ui_CommandRegister=0; + UINT ui_EOC = 0; + INT ui_CommandRegister = 0; + /*******************************************/ + /*Read calibration offset value for the CJC */ /*******************************************/ - /*Read calibration offset value for the CJC*/ - /*******************************************/ /*******************************/ - /* Set the convert timing unit */ + /* Set the convert timing unit */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); /******************************/ - /*Configure the CJC Conversion*/ + /*Configure the CJC Conversion */ /******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(0x00000400 , devpriv->iobase+i_Offset + 4); - outl(0x00000400 , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(0x00000400 , devpriv->iobase+i_Offset + 4); + outl(0x00000400, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4); /*********************************/ - /*Configure the Offset Conversion*/ + /*Configure the Offset Conversion */ /*********************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(0x00020000, devpriv->iobase+i_Offset + 12); - outl(0x00020000, devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(0x00020000, devpriv->iobase+i_Offset + 12); + outl(0x00020000, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /*******************************/ - /*Initialise ui_CommandRegister*/ + /*Initialise ui_CommandRegister */ /*******************************/ - ui_CommandRegister = 0; + ui_CommandRegister = 0; /*********************************/ - /*Test if the interrupt is enable*/ + /*Test if the interrupt is enable */ /*********************************/ - - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { + + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { /**********************/ - /*Enable the interrupt*/ + /*Enable the interrupt */ /**********************/ - ui_CommandRegister =ui_CommandRegister | 0x00100000; - - } - + ui_CommandRegister = ui_CommandRegister | 0x00100000; + + } + /**********************/ - /*Start the conversion*/ + /*Start the conversion */ /**********************/ - ui_CommandRegister = ui_CommandRegister | 0x00080000; + ui_CommandRegister = ui_CommandRegister | 0x00080000; /***************************/ - /*Write the command regiter*/ + /*Write the command regiter */ /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_CommandRegister,devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - do - { + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_CommandRegister,devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + do { /*******************/ - /*Read the EOC flag*/ + /*Read the EOC flag */ /*******************/ - //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); - + //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + } while (ui_EOC != 1); + /**************************************************/ - /*Read the digital value of the calibration Offset*/ + /*Read the digital value of the calibration Offset */ /**************************************************/ - //data[0] = inl(devpriv->iobase+i_Offset + 28); - data[0] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - }//if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; -} + //data[0] = inl(devpriv->iobase+i_Offset + 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + } //if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; +} /* +----------------------------------------------------------------------------+ @@ -2220,87 +2282,96 @@ int i_APCI3200_ReadCJCCalOffset(comedi_device *dev,lsampl_t *data) | : FALSE : Error occur. Return the error | | | +----------------------------------------------------------------------------+ -*/ -int i_APCI3200_ReadCJCCalGain(comedi_device *dev,lsampl_t *data) -{ - UINT ui_EOC=0; - INT ui_CommandRegister=0; +*/ +int i_APCI3200_ReadCJCCalGain(comedi_device * dev, lsampl_t * data) +{ + UINT ui_EOC = 0; + INT ui_CommandRegister = 0; /*******************************/ - /* Set the convert timing unit */ + /* Set the convert timing unit */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTimeUnit , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /**************************/ - /* Set the convert timing */ + /* Set the convert timing */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); - outl(s_BoardInfos [dev->minor].i_ADDIDATAConversionTime , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); + outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); /******************************/ - /*Configure the CJC Conversion*/ + /*Configure the CJC Conversion */ /******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(0x00000400,devpriv->iobase+i_Offset + 4); - outl(0x00000400,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(0x00000400,devpriv->iobase+i_Offset + 4); + outl(0x00000400, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4); /*******************************/ - /*Configure the Gain Conversion*/ + /*Configure the Gain Conversion */ /*******************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(0x00040000,devpriv->iobase+i_Offset + 12); - outl(0x00040000,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(0x00040000,devpriv->iobase+i_Offset + 12); + outl(0x00040000, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /*******************************/ - /*Initialise dw_CommandRegister*/ + /*Initialise dw_CommandRegister */ /*******************************/ - ui_CommandRegister = 0; + ui_CommandRegister = 0; /*********************************/ - /*Test if the interrupt is enable*/ + /*Test if the interrupt is enable */ /*********************************/ - //if (i_InterruptFlag == ADDIDATA_ENABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) - { + //if (i_InterruptFlag == ADDIDATA_ENABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_ENABLE) { /**********************/ - /*Enable the interrupt*/ + /*Enable the interrupt */ /**********************/ - ui_CommandRegister = ui_CommandRegister | 0x00100000; - } + ui_CommandRegister = ui_CommandRegister | 0x00100000; + } + /**********************/ + /*Start the conversion */ /**********************/ - /*Start the conversion*/ - /**********************/ - ui_CommandRegister = ui_CommandRegister | 0x00080000; + ui_CommandRegister = ui_CommandRegister | 0x00080000; + /***************************/ + /*Write the command regiter */ /***************************/ - /*Write the command regiter*/ - /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_CommandRegister ,devpriv->iobase+i_Offset + 8); - outl(ui_CommandRegister ,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); - //if (i_InterruptFlag == ADDIDATA_DISABLE) - if (s_BoardInfos [dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) - { - do - { + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_CommandRegister ,devpriv->iobase+i_Offset + 8); + outl(ui_CommandRegister, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); + //if (i_InterruptFlag == ADDIDATA_DISABLE) + if (s_BoardInfos[dev->minor].i_InterruptFlag == ADDIDATA_DISABLE) { + do { /*******************/ - /*Read the EOC flag*/ + /*Read the EOC flag */ /*******************/ - //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; - ui_EOC = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 20) & 1; - } while (ui_EOC != 1); + //ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; + ui_EOC = inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 20) & 1; + } while (ui_EOC != 1); /************************************************/ - /*Read the digital value of the calibration Gain*/ + /*Read the digital value of the calibration Gain */ /************************************************/ - //data[0] = inl (devpriv->iobase+i_Offset + 28); - data[0] = inl (devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - }//if (i_InterruptFlag == ADDIDATA_DISABLE) - return 0; -} + //data[0] = inl (devpriv->iobase+i_Offset + 28); + data[0] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + } //if (i_InterruptFlag == ADDIDATA_DISABLE) + return 0; +} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3200_InsnBits_AnalogInput_Test | @@ -2333,93 +2404,108 @@ int i_APCI3200_ReadCJCCalGain(comedi_device *dev,lsampl_t *data) +----------------------------------------------------------------------------+ */ -INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - UINT ui_Configuration=0; - INT i_Temp;//,i_TimeUnit; - //if(i_Initialised==0) - - if(s_BoardInfos [dev->minor].i_Initialised==0) - { - i_APCI3200_Reset(dev); - return -EINVAL; - }//if(i_Initialised==0); - if(data[0]!=0 && data[0]!=1) - { - printk("\nError in selection of functionality\n"); - i_APCI3200_Reset(dev); - return -EINVAL; - }//if(data[0]!=0 && data[0]!=1) - - if(data[0]==1) //Perform Short Circuit TEST - { + UINT ui_Configuration = 0; + INT i_Temp; //,i_TimeUnit; + //if(i_Initialised==0) + + if (s_BoardInfos[dev->minor].i_Initialised == 0) { + i_APCI3200_Reset(dev); + return -EINVAL; + } //if(i_Initialised==0); + if (data[0] != 0 && data[0] != 1) { + printk("\nError in selection of functionality\n"); + i_APCI3200_Reset(dev); + return -EINVAL; + } //if(data[0]!=0 && data[0]!=1) + + if (data[0] == 1) //Perform Short Circuit TEST + { /**************************/ - /*Set the short-cicuit bit*/ + /*Set the short-cicuit bit */ /**************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); - outl((0x00001000 |s_BoardInfos [dev->minor].i_ChannelNo) , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor]. + i_Offset + 12) >> 19) & 1) != + 1) ; + //outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); + outl((0x00001000 | s_BoardInfos[dev->minor].i_ChannelNo), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 4); /*************************/ - /*Set the time unit to ns*/ + /*Set the time unit to ns */ /*************************/ - /* i_TimeUnit= i_ADDIDATAConversionTimeUnit; - i_ADDIDATAConversionTimeUnit= 1;*/ - //i_Temp= i_InterruptFlag ; - i_Temp= s_BoardInfos [dev->minor].i_InterruptFlag ; - //i_InterruptFlag = ADDIDATA_DISABLE; - s_BoardInfos [dev->minor].i_InterruptFlag = ADDIDATA_DISABLE; - i_APCI3200_Read1AnalogInputChannel(dev,s,insn,data); - //if(i_AutoCalibration == FALSE) - if(s_BoardInfos [dev->minor].i_AutoCalibration == FALSE) - { - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - - //outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); - outl((0x00001000 |s_BoardInfos [dev->minor].i_ChannelNo) , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); - data++; - i_APCI3200_ReadCalibrationOffsetValue(dev,data); - data++; - i_APCI3200_ReadCalibrationGainValue(dev,data); - } - } - else - { - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); - outl((0x00000800|s_BoardInfos [dev->minor].i_ChannelNo) , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); - //ui_Configuration = inl(devpriv->iobase+i_Offset + 0); - ui_Configuration = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0); + /* i_TimeUnit= i_ADDIDATAConversionTimeUnit; + i_ADDIDATAConversionTimeUnit= 1; */ + //i_Temp= i_InterruptFlag ; + i_Temp = s_BoardInfos[dev->minor].i_InterruptFlag; + //i_InterruptFlag = ADDIDATA_DISABLE; + s_BoardInfos[dev->minor].i_InterruptFlag = ADDIDATA_DISABLE; + i_APCI3200_Read1AnalogInputChannel(dev, s, insn, data); + //if(i_AutoCalibration == FALSE) + if (s_BoardInfos[dev->minor].i_AutoCalibration == FALSE) { + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor]. + i_Offset + + 12) >> 19) & 1) != 1) ; + + //outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); + outl((0x00001000 | s_BoardInfos[dev->minor]. + i_ChannelNo), + devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 4); + data++; + i_APCI3200_ReadCalibrationOffsetValue(dev, data); + data++; + i_APCI3200_ReadCalibrationGainValue(dev, data); + } + } else { + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor]. + i_Offset + 12) >> 19) & 1) != + 1) ; + //outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); + outl((0x00000800 | s_BoardInfos[dev->minor].i_ChannelNo), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 4); + //ui_Configuration = inl(devpriv->iobase+i_Offset + 0); + ui_Configuration = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 0); /*************************/ - /*Set the time unit to ns*/ + /*Set the time unit to ns */ /*************************/ - /* i_TimeUnit= i_ADDIDATAConversionTimeUnit; - i_ADDIDATAConversionTimeUnit= 1;*/ - //i_Temp= i_InterruptFlag ; - i_Temp= s_BoardInfos [dev->minor].i_InterruptFlag ; - //i_InterruptFlag = ADDIDATA_DISABLE; - s_BoardInfos [dev->minor].i_InterruptFlag = ADDIDATA_DISABLE; - i_APCI3200_Read1AnalogInputChannel(dev,s,insn,data); - //if(i_AutoCalibration == FALSE) - if(s_BoardInfos [dev->minor].i_AutoCalibration == FALSE) - { - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); - outl((0x00000800|s_BoardInfos [dev->minor].i_ChannelNo) , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); - data++; - i_APCI3200_ReadCalibrationOffsetValue(dev,data); - data++; - i_APCI3200_ReadCalibrationGainValue(dev,data); + /* i_TimeUnit= i_ADDIDATAConversionTimeUnit; + i_ADDIDATAConversionTimeUnit= 1; */ + //i_Temp= i_InterruptFlag ; + i_Temp = s_BoardInfos[dev->minor].i_InterruptFlag; + //i_InterruptFlag = ADDIDATA_DISABLE; + s_BoardInfos[dev->minor].i_InterruptFlag = ADDIDATA_DISABLE; + i_APCI3200_Read1AnalogInputChannel(dev, s, insn, data); + //if(i_AutoCalibration == FALSE) + if (s_BoardInfos[dev->minor].i_AutoCalibration == FALSE) { + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor]. + i_Offset + + 12) >> 19) & 1) != 1) ; + //outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); + outl((0x00000800 | s_BoardInfos[dev->minor]. + i_ChannelNo), + devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 4); + data++; + i_APCI3200_ReadCalibrationOffsetValue(dev, data); + data++; + i_APCI3200_ReadCalibrationGainValue(dev, data); + } } - } - //i_InterruptFlag=i_Temp ; - s_BoardInfos [dev->minor].i_InterruptFlag=i_Temp ; - //printk("\ni_InterruptFlag=%d\n",i_InterruptFlag); - return insn->n; -} + //i_InterruptFlag=i_Temp ; + s_BoardInfos[dev->minor].i_InterruptFlag = i_Temp; + //printk("\ni_InterruptFlag=%d\n",i_InterruptFlag); + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -2443,13 +2529,13 @@ INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device *dev,comedi_subdevice *s, +----------------------------------------------------------------------------+ */ -INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - i_APCI3200_Reset(dev); - return insn->n; -} - - +INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + i_APCI3200_Reset(dev); + return insn->n; +} + /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3200_CommandTestAnalogInput(comedi_device *dev| @@ -2474,200 +2560,190 @@ INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device *dev,comedi_subdevice * +----------------------------------------------------------------------------+ */ -int i_APCI3200_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +int i_APCI3200_CommandTestAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; - int tmp;// divisor1,divisor2; - UINT ui_ConvertTime=0; - UINT ui_ConvertTimeBase=0; - UINT ui_DelayTime=0; - UINT ui_DelayTimeBase=0; - INT i_Triggermode=0; - INT i_TriggerEdge=0; - INT i_NbrOfChannel=0; - INT i_Cpt=0; - double d_ConversionTimeForAllChannels=0.0; - double d_SCANTimeNewUnit=0.0; - // step 1: make sure trigger sources are trivially valid - - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; - tmp=cmd->scan_end_src; - cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; - //if(i_InterruptFlag==0) - if(s_BoardInfos [dev->minor].i_InterruptFlag==0) - { - err++; - // printk("\nThe interrupt should be enabled\n"); - } - if(err) - { - i_APCI3200_Reset(dev); - return 1; - } - + int err = 0; + int tmp; // divisor1,divisor2; + UINT ui_ConvertTime = 0; + UINT ui_ConvertTimeBase = 0; + UINT ui_DelayTime = 0; + UINT ui_DelayTimeBase = 0; + INT i_Triggermode = 0; + INT i_TriggerEdge = 0; + INT i_NbrOfChannel = 0; + INT i_Cpt = 0; + double d_ConversionTimeForAllChannels = 0.0; + double d_SCANTimeNewUnit = 0.0; + // step 1: make sure trigger sources are trivially valid + + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_EXT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; + tmp = cmd->scan_end_src; + cmd->scan_end_src &= TRIG_COUNT; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; + //if(i_InterruptFlag==0) + if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) { + err++; + // printk("\nThe interrupt should be enabled\n"); + } + if (err) { + i_APCI3200_Reset(dev); + return 1; + } - if(cmd->start_src!=TRIG_NOW && cmd->start_src!=TRIG_EXT) - { - err++; - } - if(cmd->start_src==TRIG_EXT) - { - i_TriggerEdge=cmd->start_arg & 0xFFFF; - i_Triggermode=cmd->start_arg >> 16; - if(i_TriggerEdge < 1 || i_TriggerEdge >3 ) - { - err++; - printk("\nThe trigger edge selection is in error\n") ; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) { + err++; + } + if (cmd->start_src == TRIG_EXT) { + i_TriggerEdge = cmd->start_arg & 0xFFFF; + i_Triggermode = cmd->start_arg >> 16; + if (i_TriggerEdge < 1 || i_TriggerEdge > 3) { + err++; + printk("\nThe trigger edge selection is in error\n"); + } + if (i_Triggermode != 2) { + err++; + printk("\nThe trigger mode selection is in error\n"); + } } - if(i_Triggermode!=2) - { - err++; - printk("\nThe trigger mode selection is in error\n") ; - } - } - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_FOLLOW) err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_FOLLOW) + err++; - if(cmd->convert_src!=TRIG_TIMER ) err++; - - if(cmd->scan_end_src!=TRIG_COUNT) - { - cmd->scan_end_src=TRIG_COUNT; - err++; - } - - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT ) err++; - - if(err) - { - i_APCI3200_Reset(dev); - return 2; - } - - //i_FirstChannel=cmd->chanlist[0]; - s_BoardInfos [dev->minor].i_FirstChannel=cmd->chanlist[0]; - //i_LastChannel=cmd->chanlist[1]; - s_BoardInfos [dev->minor].i_LastChannel=cmd->chanlist[1]; - - - if (cmd->convert_src==TRIG_TIMER) - { - ui_ConvertTime=cmd->convert_arg & 0xFFFF; - ui_ConvertTimeBase=cmd->convert_arg >> 16; - if (ui_ConvertTime!=20 && ui_ConvertTime!=40 && ui_ConvertTime!=80 && ui_ConvertTime!=160 ) + if (cmd->convert_src != TRIG_TIMER) + err++; - { - printk("\nThe selection of conversion time reload value is in error\n"); - err++; - }// if (ui_ConvertTime!=20 && ui_ConvertTime!=40 && ui_ConvertTime!=80 && ui_ConvertTime!=160 ) - if(ui_ConvertTimeBase!=2) - { - printk("\nThe selection of conversion time unit is in error\n"); - err++; - }//if(ui_ConvertTimeBase!=2) - } - else - { - ui_ConvertTime=0; - ui_ConvertTimeBase=0; - } - if(cmd->scan_begin_src==TRIG_FOLLOW) - { - ui_DelayTime=0; - ui_DelayTimeBase=0; - }//if(cmd->scan_begin_src==TRIG_FOLLOW) - else - { - ui_DelayTime=cmd->scan_begin_arg & 0xFFFF; - ui_DelayTimeBase=cmd->scan_begin_arg >> 16; - if(ui_DelayTimeBase!=2 && ui_DelayTimeBase!=3) - { - err++; - printk("\nThe Delay time base selection is in error\n"); + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; + err++; } - if(ui_DelayTime < 1 && ui_DelayTime >1023) - { - err++; - printk("\nThe Delay time value is in error\n"); + + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; + + if (err) { + i_APCI3200_Reset(dev); + return 2; } - if(err) - { - i_APCI3200_Reset(dev); - return 3; + //i_FirstChannel=cmd->chanlist[0]; + s_BoardInfos[dev->minor].i_FirstChannel = cmd->chanlist[0]; + //i_LastChannel=cmd->chanlist[1]; + s_BoardInfos[dev->minor].i_LastChannel = cmd->chanlist[1]; + + if (cmd->convert_src == TRIG_TIMER) { + ui_ConvertTime = cmd->convert_arg & 0xFFFF; + ui_ConvertTimeBase = cmd->convert_arg >> 16; + if (ui_ConvertTime != 20 && ui_ConvertTime != 40 + && ui_ConvertTime != 80 && ui_ConvertTime != 160) + { + printk("\nThe selection of conversion time reload value is in error\n"); + err++; + } // if (ui_ConvertTime!=20 && ui_ConvertTime!=40 && ui_ConvertTime!=80 && ui_ConvertTime!=160 ) + if (ui_ConvertTimeBase != 2) { + printk("\nThe selection of conversion time unit is in error\n"); + err++; + } //if(ui_ConvertTimeBase!=2) + } else { + ui_ConvertTime = 0; + ui_ConvertTimeBase = 0; } - fpu_begin (); - d_SCANTimeNewUnit = (double)ui_DelayTime; - //i_NbrOfChannel= i_LastChannel-i_FirstChannel + 4; - i_NbrOfChannel= s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel + 4; + if (cmd->scan_begin_src == TRIG_FOLLOW) { + ui_DelayTime = 0; + ui_DelayTimeBase = 0; + } //if(cmd->scan_begin_src==TRIG_FOLLOW) + else { + ui_DelayTime = cmd->scan_begin_arg & 0xFFFF; + ui_DelayTimeBase = cmd->scan_begin_arg >> 16; + if (ui_DelayTimeBase != 2 && ui_DelayTimeBase != 3) { + err++; + printk("\nThe Delay time base selection is in error\n"); + } + if (ui_DelayTime < 1 && ui_DelayTime > 1023) { + err++; + printk("\nThe Delay time value is in error\n"); + } + if (err) { + i_APCI3200_Reset(dev); + return 3; + } + fpu_begin(); + d_SCANTimeNewUnit = (double)ui_DelayTime; + //i_NbrOfChannel= i_LastChannel-i_FirstChannel + 4; + i_NbrOfChannel = + s_BoardInfos[dev->minor].i_LastChannel - + s_BoardInfos[dev->minor].i_FirstChannel + 4; /**********************************************************/ - /*calculate the total conversion time for all the channels*/ + /*calculate the total conversion time for all the channels */ /**********************************************************/ - d_ConversionTimeForAllChannels = (double)((double)ui_ConvertTime / (double)i_NbrOfChannel); - + d_ConversionTimeForAllChannels = + (double)((double)ui_ConvertTime / + (double)i_NbrOfChannel); + + /*******************************/ + /*Convert the frequence in time */ /*******************************/ - /*Convert the frequence in time*/ - /*******************************/ - d_ConversionTimeForAllChannels =(double) 1.0/ d_ConversionTimeForAllChannels; - ui_ConvertTimeBase=3; + d_ConversionTimeForAllChannels = + (double)1.0 / d_ConversionTimeForAllChannels; + ui_ConvertTimeBase = 3; /***********************************/ - /*Test if the time unit is the same*/ + /*Test if the time unit is the same */ /***********************************/ - - if (ui_DelayTimeBase <= ui_ConvertTimeBase) - { - - for (i_Cpt = 0; i_Cpt < (ui_ConvertTimeBase-ui_DelayTimeBase);i_Cpt++) - { - - d_ConversionTimeForAllChannels = d_ConversionTimeForAllChannels * 1000; - d_ConversionTimeForAllChannels=d_ConversionTimeForAllChannels+1; - } - } - else - { - for (i_Cpt = 0; i_Cpt < (ui_DelayTimeBase-ui_ConvertTimeBase);i_Cpt++) - { - d_SCANTimeNewUnit = d_SCANTimeNewUnit * 1000; - } - } - - if (d_ConversionTimeForAllChannels >= d_SCANTimeNewUnit) - { - - printk("\nSCAN Delay value cannot be used\n"); + if (ui_DelayTimeBase <= ui_ConvertTimeBase) { + + for (i_Cpt = 0; + i_Cpt < (ui_ConvertTimeBase - ui_DelayTimeBase); + i_Cpt++) { + + d_ConversionTimeForAllChannels = + d_ConversionTimeForAllChannels * 1000; + d_ConversionTimeForAllChannels = + d_ConversionTimeForAllChannels + 1; + } + } else { + for (i_Cpt = 0; + i_Cpt < (ui_DelayTimeBase - ui_ConvertTimeBase); + i_Cpt++) { + d_SCANTimeNewUnit = d_SCANTimeNewUnit * 1000; + + } + } + + if (d_ConversionTimeForAllChannels >= d_SCANTimeNewUnit) { + + printk("\nSCAN Delay value cannot be used\n"); /*********************************/ - /*SCAN Delay value cannot be used*/ + /*SCAN Delay value cannot be used */ /*********************************/ - err++; - } - fpu_end (); - }//else if(cmd->scan_begin_src==TRIG_FOLLOW) - - - - if(err) - { - i_APCI3200_Reset(dev); - return 4; - } - - return 0; + err++; + } + fpu_end(); + } //else if(cmd->scan_begin_src==TRIG_FOLLOW) + + if (err) { + i_APCI3200_Reset(dev); + return 4; + } + + return 0; } /* @@ -2688,32 +2764,36 @@ int i_APCI3200_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,com +----------------------------------------------------------------------------+ */ -int i_APCI3200_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s) +int i_APCI3200_StopCyclicAcquisition(comedi_device * dev, comedi_subdevice * s) { - UINT ui_Configuration=0; - //i_InterruptFlag=0; - //i_Initialised=0; - //i_Count=0; - //i_Sum=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_Initialised=0; - s_BoardInfos [dev->minor].i_Count=0; - s_BoardInfos [dev->minor].i_Sum=0; + UINT ui_Configuration = 0; + //i_InterruptFlag=0; + //i_Initialised=0; + //i_Count=0; + //i_Sum=0; + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + s_BoardInfos[dev->minor].i_Initialised = 0; + s_BoardInfos[dev->minor].i_Count = 0; + s_BoardInfos[dev->minor].i_Sum = 0; /*******************/ - /*Read the register*/ + /*Read the register */ /*******************/ - //ui_Configuration = inl(devpriv->iobase+i_Offset + 8); - ui_Configuration = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); + //ui_Configuration = inl(devpriv->iobase+i_Offset + 8); + ui_Configuration = + inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); /*****************************/ - /*Reset the START and IRQ bit*/ + /*Reset the START and IRQ bit */ /*****************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((ui_Configuration & 0xFFE7FFFF),devpriv->iobase+i_Offset + 8); - outl((ui_Configuration & 0xFFE7FFFF),devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); - return 0; + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl((ui_Configuration & 0xFFE7FFFF),devpriv->iobase+i_Offset + 8); + outl((ui_Configuration & 0xFFE7FFFF), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); + return 0; } + /* +----------------------------------------------------------------------------+ | Function name : int i_APCI3200_CommandAnalogInput(comedi_device *dev, | @@ -2734,172 +2814,177 @@ int i_APCI3200_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s) +----------------------------------------------------------------------------+ */ -int i_APCI3200_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s) +int i_APCI3200_CommandAnalogInput(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; - UINT ui_Configuration=0; - //INT i_CurrentSource = 0; - UINT ui_Trigger=0; - UINT ui_TriggerEdge=0; - UINT ui_Triggermode=0; - UINT ui_ScanMode=0; - UINT ui_ConvertTime=0; - UINT ui_ConvertTimeBase=0; - UINT ui_DelayTime=0; - UINT ui_DelayTimeBase=0; - UINT ui_DelayMode=0; - //i_FirstChannel=cmd->chanlist[0]; - //i_LastChannel=cmd->chanlist[1]; - s_BoardInfos [dev->minor].i_FirstChannel=cmd->chanlist[0]; - s_BoardInfos [dev->minor].i_LastChannel=cmd->chanlist[1]; - if(cmd->start_src==TRIG_EXT) - { - ui_Trigger=1; - ui_TriggerEdge=cmd->start_arg &0xFFFF; - ui_Triggermode=cmd->start_arg >> 16; - }//if(cmd->start_src==TRIG_EXT) - else - { - ui_Trigger=0; - }//elseif(cmd->start_src==TRIG_EXT) - - if (cmd->stop_src==TRIG_COUNT) - { - ui_ScanMode=0; - }// if (cmd->stop_src==TRIG_COUNT) - else - { - ui_ScanMode=2; - }//else if (cmd->stop_src==TRIG_COUNT) - - if(cmd->scan_begin_src==TRIG_FOLLOW) - { - ui_DelayTime=0; - ui_DelayTimeBase=0; - ui_DelayMode=0; - }//if(cmd->scan_begin_src==TRIG_FOLLOW) - else - { - ui_DelayTime=cmd->scan_begin_arg & 0xFFFF; - ui_DelayTimeBase=cmd->scan_begin_arg >> 16; - ui_DelayMode =1; - }//else if(cmd->scan_begin_src==TRIG_FOLLOW) - // printk("\nui_DelayTime=%u\n",ui_DelayTime); - // printk("\nui_DelayTimeBase=%u\n",ui_DelayTimeBase); - if (cmd->convert_src==TRIG_TIMER) - { - ui_ConvertTime=cmd->convert_arg & 0xFFFF; - ui_ConvertTimeBase=cmd->convert_arg >> 16; - } - else - { - ui_ConvertTime=0; - ui_ConvertTimeBase=0; - } - - // if(i_ADDIDATAType ==1 || ((i_ADDIDATAType==2))) - // { + comedi_cmd *cmd = &s->async->cmd; + UINT ui_Configuration = 0; + //INT i_CurrentSource = 0; + UINT ui_Trigger = 0; + UINT ui_TriggerEdge = 0; + UINT ui_Triggermode = 0; + UINT ui_ScanMode = 0; + UINT ui_ConvertTime = 0; + UINT ui_ConvertTimeBase = 0; + UINT ui_DelayTime = 0; + UINT ui_DelayTimeBase = 0; + UINT ui_DelayMode = 0; + //i_FirstChannel=cmd->chanlist[0]; + //i_LastChannel=cmd->chanlist[1]; + s_BoardInfos[dev->minor].i_FirstChannel = cmd->chanlist[0]; + s_BoardInfos[dev->minor].i_LastChannel = cmd->chanlist[1]; + if (cmd->start_src == TRIG_EXT) { + ui_Trigger = 1; + ui_TriggerEdge = cmd->start_arg & 0xFFFF; + ui_Triggermode = cmd->start_arg >> 16; + } //if(cmd->start_src==TRIG_EXT) + else { + ui_Trigger = 0; + } //elseif(cmd->start_src==TRIG_EXT) + + if (cmd->stop_src == TRIG_COUNT) { + ui_ScanMode = 0; + } // if (cmd->stop_src==TRIG_COUNT) + else { + ui_ScanMode = 2; + } //else if (cmd->stop_src==TRIG_COUNT) + + if (cmd->scan_begin_src == TRIG_FOLLOW) { + ui_DelayTime = 0; + ui_DelayTimeBase = 0; + ui_DelayMode = 0; + } //if(cmd->scan_begin_src==TRIG_FOLLOW) + else { + ui_DelayTime = cmd->scan_begin_arg & 0xFFFF; + ui_DelayTimeBase = cmd->scan_begin_arg >> 16; + ui_DelayMode = 1; + } //else if(cmd->scan_begin_src==TRIG_FOLLOW) + // printk("\nui_DelayTime=%u\n",ui_DelayTime); + // printk("\nui_DelayTimeBase=%u\n",ui_DelayTimeBase); + if (cmd->convert_src == TRIG_TIMER) { + ui_ConvertTime = cmd->convert_arg & 0xFFFF; + ui_ConvertTimeBase = cmd->convert_arg >> 16; + } else { + ui_ConvertTime = 0; + ui_ConvertTimeBase = 0; + } + + // if(i_ADDIDATAType ==1 || ((i_ADDIDATAType==2))) + // { + /**************************************************/ + /*Read the old configuration of the current source */ /**************************************************/ - /*Read the old configuration of the current source*/ - /**************************************************/ - //ui_Configuration = inl(devpriv->iobase+i_Offset + 12); - ui_Configuration = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12); + //ui_Configuration = inl(devpriv->iobase+i_Offset + 12); + ui_Configuration = + inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); /***********************************************/ - /*Write the configuration of the current source*/ + /*Write the configuration of the current source */ /***********************************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((ui_Configuration & 0xFFC00000 ), devpriv->iobase+i_Offset +12); - outl((ui_Configuration & 0xFFC00000 ), devpriv->iobase+s_BoardInfos [dev->minor].i_Offset +12); - // } - ui_Configuration=0; - // printk("\nfirstchannel=%u\n",i_FirstChannel); - // printk("\nlastchannel=%u\n",i_LastChannel); - // printk("\nui_Trigger=%u\n",ui_Trigger); - // printk("\nui_TriggerEdge=%u\n",ui_TriggerEdge); - // printk("\nui_Triggermode=%u\n",ui_Triggermode); - // printk("\nui_DelayMode=%u\n",ui_DelayMode); - // printk("\nui_ScanMode=%u\n",ui_ScanMode); - - //ui_Configuration = i_FirstChannel |(i_LastChannel << 8)| 0x00100000 | - ui_Configuration = s_BoardInfos [dev->minor].i_FirstChannel |(s_BoardInfos [dev->minor].i_LastChannel << 8)| 0x00100000 | - (ui_Trigger << 24) | - (ui_TriggerEdge << 25)| - (ui_Triggermode << 27)| - (ui_DelayMode << 18) | - (ui_ScanMode << 16); - - + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl((ui_Configuration & 0xFFC00000 ), devpriv->iobase+i_Offset +12); + outl((ui_Configuration & 0xFFC00000), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12); + // } + ui_Configuration = 0; + // printk("\nfirstchannel=%u\n",i_FirstChannel); + // printk("\nlastchannel=%u\n",i_LastChannel); + // printk("\nui_Trigger=%u\n",ui_Trigger); + // printk("\nui_TriggerEdge=%u\n",ui_TriggerEdge); + // printk("\nui_Triggermode=%u\n",ui_Triggermode); + // printk("\nui_DelayMode=%u\n",ui_DelayMode); + // printk("\nui_ScanMode=%u\n",ui_ScanMode); + + //ui_Configuration = i_FirstChannel |(i_LastChannel << 8)| 0x00100000 | + ui_Configuration = + s_BoardInfos[dev->minor].i_FirstChannel | (s_BoardInfos[dev-> + minor]. + i_LastChannel << 8) | 0x00100000 | (ui_Trigger << 24) | + (ui_TriggerEdge << 25) | (ui_Triggermode << 27) | (ui_DelayMode + << 18) | (ui_ScanMode << 16); + /*************************/ - /*Write the Configuration*/ + /*Write the Configuration */ /*************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl( ui_Configuration, devpriv->iobase+i_Offset + 0x8); - outl( ui_Configuration, devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x8); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl( ui_Configuration, devpriv->iobase+i_Offset + 0x8); + outl(ui_Configuration, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x8); /***********************/ - /*Write the Delay Value*/ + /*Write the Delay Value */ /***********************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_DelayTime,devpriv->iobase+i_Offset + 40); - outl(ui_DelayTime,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 40); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_DelayTime,devpriv->iobase+i_Offset + 40); + outl(ui_DelayTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 40); /***************************/ - /*Write the Delay time base*/ + /*Write the Delay time base */ /***************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_DelayTimeBase,devpriv->iobase+i_Offset + 44); - outl(ui_DelayTimeBase,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 44); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_DelayTimeBase,devpriv->iobase+i_Offset + 44); + outl(ui_DelayTimeBase, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 44); /*********************************/ - /*Write the conversion time value*/ + /*Write the conversion time value */ /*********************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_ConvertTime,devpriv->iobase+i_Offset + 32); - outl(ui_ConvertTime,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 32); - + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_ConvertTime,devpriv->iobase+i_Offset + 32); + outl(ui_ConvertTime, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32); + /********************************/ - /*Write the conversion time base*/ + /*Write the conversion time base */ /********************************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl(ui_ConvertTimeBase,devpriv->iobase+i_Offset + 36); - outl(ui_ConvertTimeBase,devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 36); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl(ui_ConvertTimeBase,devpriv->iobase+i_Offset + 36); + outl(ui_ConvertTimeBase, + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36); /*******************/ - /*Read the register*/ + /*Read the register */ /*******************/ - //ui_Configuration = inl(devpriv->iobase+i_Offset + 4); - ui_Configuration = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //ui_Configuration = inl(devpriv->iobase+i_Offset + 4); + ui_Configuration = + inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4); /******************/ - /*Set the SCAN bit*/ + /*Set the SCAN bit */ /******************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; - //outl(((ui_Configuration & 0x1E0FF) | 0x00002000),devpriv->iobase+i_Offset + 4); - outl(((ui_Configuration & 0x1E0FF) | 0x00002000),devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4); + //outl(((ui_Configuration & 0x1E0FF) | 0x00002000),devpriv->iobase+i_Offset + 4); + outl(((ui_Configuration & 0x1E0FF) | 0x00002000), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4); /*******************/ - /*Read the register*/ + /*Read the register */ /*******************/ - ui_Configuration=0; - //ui_Configuration = inl(devpriv->iobase+i_Offset + 8); - ui_Configuration = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); + ui_Configuration = 0; + //ui_Configuration = inl(devpriv->iobase+i_Offset + 8); + ui_Configuration = + inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); /*******************/ - /*Set the START bit*/ + /*Set the START bit */ /*******************/ - //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); - while (((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset+12)>>19) & 1) != 1); - //outl((ui_Configuration | 0x00080000),devpriv->iobase+i_Offset + 8); - outl((ui_Configuration | 0x00080000),devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 8); - return 0; + //while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); + while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + + 12) >> 19) & 1) != 1) ; + //outl((ui_Configuration | 0x00080000),devpriv->iobase+i_Offset + 8); + outl((ui_Configuration | 0x00080000), + devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8); + return 0; } - - - - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3200_Reset(comedi_device *dev) | @@ -2916,45 +3001,43 @@ int i_APCI3200_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s) +----------------------------------------------------------------------------+ */ -int i_APCI3200_Reset(comedi_device *dev) +int i_APCI3200_Reset(comedi_device * dev) { - INT i_Temp; - DWORD dw_Dummy; - //i_InterruptFlag=0; - //i_Initialised==0; - //i_Count=0; - //i_Sum=0; - - s_BoardInfos [dev->minor].i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_Initialised=0; - s_BoardInfos [dev->minor].i_Count=0; - s_BoardInfos [dev->minor].i_Sum=0; - s_BoardInfos [dev->minor].b_StructInitialized = 0; - - outl(0x83838383,devpriv->i_IobaseAmcc+0x60); - - // Enable the interrupt for the controler - dw_Dummy = inl(devpriv->i_IobaseAmcc+ 0x38); - outl(dw_Dummy | 0x2000,devpriv->i_IobaseAmcc+0x38); - outl(0,devpriv->i_IobaseAddon);//Resets the output + INT i_Temp; + DWORD dw_Dummy; + //i_InterruptFlag=0; + //i_Initialised==0; + //i_Count=0; + //i_Sum=0; + + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + s_BoardInfos[dev->minor].i_Initialised = 0; + s_BoardInfos[dev->minor].i_Count = 0; + s_BoardInfos[dev->minor].i_Sum = 0; + s_BoardInfos[dev->minor].b_StructInitialized = 0; + + outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); + + // Enable the interrupt for the controler + dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); + outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); + outl(0, devpriv->i_IobaseAddon); //Resets the output /***************/ - /*Empty the buffer*/ + /*Empty the buffer */ /**************/ - for(i_Temp=0;i_Temp<=95;i_Temp++) - { - //ui_InterruptChannelValue[i_Temp]=0; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[i_Temp]=0; - }//for(i_Temp=0;i_Temp<=95;i_Temp++) + for (i_Temp = 0; i_Temp <= 95; i_Temp++) { + //ui_InterruptChannelValue[i_Temp]=0; + s_BoardInfos[dev->minor].ui_InterruptChannelValue[i_Temp] = 0; + } //for(i_Temp=0;i_Temp<=95;i_Temp++) /*****************************/ - /*Reset the START and IRQ bit*/ + /*Reset the START and IRQ bit */ /*****************************/ - for(i_Temp=0;i_Temp<=192;) - { - while (((inl(devpriv->iobase+i_Temp+12)>>19) & 1) != 1); - outl(0,devpriv->iobase+i_Temp + 8); - i_Temp=i_Temp+64; - }//for(i_Temp=0;i_Temp<=192;i_Temp+64) - return 0; + for (i_Temp = 0; i_Temp <= 192;) { + while (((inl(devpriv->iobase + i_Temp + 12) >> 19) & 1) != 1) ; + outl(0, devpriv->iobase + i_Temp + 8); + i_Temp = i_Temp + 64; + } //for(i_Temp=0;i_Temp<=192;i_Temp+64) + return 0; } /* @@ -2974,359 +3057,429 @@ int i_APCI3200_Reset(comedi_device *dev) | | +----------------------------------------------------------------------------+ */ -void v_APCI3200_Interrupt(int irq, void *d) -{ - comedi_device *dev = d; - UINT ui_StatusRegister=0; - UINT ui_ChannelNumber = 0; - INT i_CalibrationFlag = 0; - INT i_CJCFlag=0; - UINT ui_DummyValue = 0; - UINT ui_DigitalTemperature=0; - UINT ui_DigitalInput =0; - int i_ConvertCJCCalibration; - - //BEGIN JK TEST - int i_ReturnValue = 0; - //END JK TEST - - - //printk ("\n i_ScanType = %i i_ADDIDATAType = %i", s_BoardInfos [dev->minor].i_ScanType, s_BoardInfos [dev->minor].i_ADDIDATAType); - - //switch(i_ScanType) - switch(s_BoardInfos [dev->minor].i_ScanType) - { - case 0: - case 1: - //switch(i_ADDIDATAType) - switch(s_BoardInfos [dev->minor].i_ADDIDATAType) - { +void v_APCI3200_Interrupt(int irq, void *d) +{ + comedi_device *dev = d; + UINT ui_StatusRegister = 0; + UINT ui_ChannelNumber = 0; + INT i_CalibrationFlag = 0; + INT i_CJCFlag = 0; + UINT ui_DummyValue = 0; + UINT ui_DigitalTemperature = 0; + UINT ui_DigitalInput = 0; + int i_ConvertCJCCalibration; + + //BEGIN JK TEST + int i_ReturnValue = 0; + //END JK TEST + + //printk ("\n i_ScanType = %i i_ADDIDATAType = %i", s_BoardInfos [dev->minor].i_ScanType, s_BoardInfos [dev->minor].i_ADDIDATAType); + + //switch(i_ScanType) + switch (s_BoardInfos[dev->minor].i_ScanType) { case 0: - case 1: - + case 1: + //switch(i_ADDIDATAType) + switch (s_BoardInfos[dev->minor].i_ADDIDATAType) { + case 0: + case 1: + /************************************/ - /*Read the interrupt status register*/ + /*Read the interrupt status register */ /************************************/ - //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); - ui_StatusRegister = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 16); - if ((ui_StatusRegister & 0x2) == 0x2) - { - //i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); - i_CalibrationFlag = ((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12) & 0x00060000) >> 17); + //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); + ui_StatusRegister = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 16); + if ((ui_StatusRegister & 0x2) == 0x2) { + //i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); + i_CalibrationFlag = + ((inl(devpriv->iobase + + s_BoardInfos[dev-> + minor]. + i_Offset + + 12) & 0x00060000) >> + 17); /*************************/ - /*Read the channel number*/ + /*Read the channel number */ /*************************/ - //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); - + //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); + /*************************************/ - /*Read the digital analog input value*/ + /*Read the digital analog input value */ /*************************************/ - //ui_DigitalInput = inl(devpriv->iobase+i_Offset + 28); - ui_DigitalInput = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - + //ui_DigitalInput = inl(devpriv->iobase+i_Offset + 28); + ui_DigitalInput = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + /***********************************************/ - /* Test if the value read is the channel value */ + /* Test if the value read is the channel value */ /***********************************************/ - if (i_CalibrationFlag == 0) - { - //ui_InterruptChannelValue[i_Count + 0] = ui_DigitalInput; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 0] = ui_DigitalInput; - - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - /* - printk("\n 1 - i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos %i", ui_ChannelNumber); - i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos [dev->minor].ui_Channel_num, - &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 6], - &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 7], - &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 8]); - */ - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + if (i_CalibrationFlag == 0) { + //ui_InterruptChannelValue[i_Count + 0] = ui_DigitalInput; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 0] = ui_DigitalInput; + + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + /* + printk("\n 1 - i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos %i", ui_ChannelNumber); + i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos [dev->minor].ui_Channel_num, + &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 6], + &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 7], + &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 8]); + */ + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values /******************************************************/ - /*Start the conversion of the calibration offset value*/ + /*Start the conversion of the calibration offset value */ /******************************************************/ - i_APCI3200_ReadCalibrationOffsetValue(dev,&ui_DummyValue); - }//if (i_CalibrationFlag == 0) + i_APCI3200_ReadCalibrationOffsetValue + (dev, &ui_DummyValue); + } //if (i_CalibrationFlag == 0) /**********************************************************/ - /* Test if the value read is the calibration offset value */ + /* Test if the value read is the calibration offset value */ /**********************************************************/ - if (i_CalibrationFlag == 1) - { - + if (i_CalibrationFlag == 1) { + /******************/ - /* Save the value */ + /* Save the value */ /******************/ - - //ui_InterruptChannelValue[i_Count + 1] = ui_DigitalInput; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 1] = ui_DigitalInput; + + //ui_InterruptChannelValue[i_Count + 1] = ui_DigitalInput; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 1] = ui_DigitalInput; /******************************************************/ - /* Start the conversion of the calibration gain value */ + /* Start the conversion of the calibration gain value */ /******************************************************/ - i_APCI3200_ReadCalibrationGainValue(dev,&ui_DummyValue); - }//if (i_CalibrationFlag == 1) - /******************************************************/ - /*Test if the value read is the calibration gain value*/ - /******************************************************/ - - if (i_CalibrationFlag == 2) - { - + i_APCI3200_ReadCalibrationGainValue(dev, + &ui_DummyValue); + } //if (i_CalibrationFlag == 1) + /******************************************************/ + /*Test if the value read is the calibration gain value */ + /******************************************************/ + + if (i_CalibrationFlag == 2) { + /****************/ - /*Save the value*/ - /****************/ - //ui_InterruptChannelValue[i_Count + 2] = ui_DigitalInput; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 2] = ui_DigitalInput; - //if(i_ScanType==1) - if(s_BoardInfos [dev->minor].i_ScanType==1) - { - - //i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - //i_Count=i_Count + 6; - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; - s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 9; - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - }//if(i_ScanType==1) - else - { - //i_Count=0; - s_BoardInfos [dev->minor].i_Count=0; - }//elseif(i_ScanType==1) - //if(i_ScanType!=1) - if(s_BoardInfos [dev->minor].i_ScanType!=1) - { - i_ReturnValue = send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - }//if(i_ScanType!=1) - else - { - //if(i_ChannelCount==i_Sum) - if(s_BoardInfos [dev->minor].i_ChannelCount==s_BoardInfos [dev->minor].i_Sum) - { - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - } - }//if(i_ScanType!=1) - }//if (i_CalibrationFlag == 2) - }// if ((ui_StatusRegister & 0x2) == 0x2) - - break; - - case 2: + /*Save the value */ + /****************/ + //ui_InterruptChannelValue[i_Count + 2] = ui_DigitalInput; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 2] = ui_DigitalInput; + //if(i_ScanType==1) + if (s_BoardInfos[dev->minor]. + i_ScanType == 1) { + + //i_InterruptFlag=0; + s_BoardInfos[dev->minor]. + i_InterruptFlag = 0; + //i_Count=i_Count + 6; + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; + s_BoardInfos[dev->minor]. + i_Count = + s_BoardInfos[dev-> + minor].i_Count + 9; + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } //if(i_ScanType==1) + else { + //i_Count=0; + s_BoardInfos[dev->minor]. + i_Count = 0; + } //elseif(i_ScanType==1) + //if(i_ScanType!=1) + if (s_BoardInfos[dev->minor]. + i_ScanType != 1) { + i_ReturnValue = send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } //if(i_ScanType!=1) + else { + //if(i_ChannelCount==i_Sum) + if (s_BoardInfos[dev->minor]. + i_ChannelCount == + s_BoardInfos[dev-> + minor].i_Sum) { + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } + } //if(i_ScanType!=1) + } //if (i_CalibrationFlag == 2) + } // if ((ui_StatusRegister & 0x2) == 0x2) + + break; + + case 2: /************************************/ - /*Read the interrupt status register*/ + /*Read the interrupt status register */ /************************************/ - //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); - ui_StatusRegister = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 16); + //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); + ui_StatusRegister = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 16); /*************************/ - /*Test if interrupt occur*/ + /*Test if interrupt occur */ /*************************/ - - if ((ui_StatusRegister & 0x2) == 0x2) - { - - //i_CJCFlag = ((inl(devpriv->iobase+i_Offset + 4) & 0x00000400) >> 10); - i_CJCFlag = ((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 4) & 0x00000400) >> 10); - - //i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); - i_CalibrationFlag = ((inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 12) & 0x00060000) >> 17); + if ((ui_StatusRegister & 0x2) == 0x2) { + + //i_CJCFlag = ((inl(devpriv->iobase+i_Offset + 4) & 0x00000400) >> 10); + i_CJCFlag = + ((inl(devpriv->iobase + + s_BoardInfos[dev-> + minor]. + i_Offset + + 4) & 0x00000400) >> 10); + + //i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); + i_CalibrationFlag = + ((inl(devpriv->iobase + + s_BoardInfos[dev-> + minor]. + i_Offset + + 12) & 0x00060000) >> + 17); /*************************/ - /*Read the channel number*/ + /*Read the channel number */ /*************************/ - - //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); - ui_ChannelNumber = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 24); - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - s_BoardInfos [dev->minor].ui_Channel_num = ui_ChannelNumber; - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - + + //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); + ui_ChannelNumber = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 24); + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + s_BoardInfos[dev->minor].ui_Channel_num = + ui_ChannelNumber; + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + /************************************/ - /*Read the digital temperature value*/ + /*Read the digital temperature value */ /************************************/ - //ui_DigitalTemperature = inl(devpriv->iobase+i_Offset + 28); - ui_DigitalTemperature = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - + //ui_DigitalTemperature = inl(devpriv->iobase+i_Offset + 28); + ui_DigitalTemperature = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + /*********************************************/ - /*Test if the value read is the channel value*/ + /*Test if the value read is the channel value */ /*********************************************/ - - if ((i_CalibrationFlag == 0) && (i_CJCFlag == 0)) - { - //ui_InterruptChannelValue[i_Count + 0]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 0]=ui_DigitalTemperature; - + + if ((i_CalibrationFlag == 0) + && (i_CJCFlag == 0)) { + //ui_InterruptChannelValue[i_Count + 0]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 0] = + ui_DigitalTemperature; + /*********************************/ - /*Start the conversion of the CJC*/ + /*Start the conversion of the CJC */ /*********************************/ - i_APCI3200_ReadCJCValue(dev,&ui_DummyValue); + i_APCI3200_ReadCJCValue(dev, + &ui_DummyValue); - }//if ((i_CalibrationFlag == 0) && (i_CJCFlag == 0)) - + } //if ((i_CalibrationFlag == 0) && (i_CJCFlag == 0)) - /*****************************************/ - /*Test if the value read is the CJC value*/ - /*****************************************/ - - if ((i_CJCFlag == 1) && (i_CalibrationFlag == 0)) - { - //ui_InterruptChannelValue[i_Count + 3]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 3]=ui_DigitalTemperature; + /*****************************************/ + /*Test if the value read is the CJC value */ + /*****************************************/ + + if ((i_CJCFlag == 1) + && (i_CalibrationFlag == 0)) { + //ui_InterruptChannelValue[i_Count + 3]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 3] = + ui_DigitalTemperature; - /******************************************************/ - /*Start the conversion of the calibration offset value*/ + /*Start the conversion of the calibration offset value */ /******************************************************/ - i_APCI3200_ReadCalibrationOffsetValue(dev,&ui_DummyValue); - }// if ((i_CJCFlag == 1) && (i_CalibrationFlag == 0)) - - - /********************************************************/ - /*Test if the value read is the calibration offset value*/ - /********************************************************/ - - if ((i_CalibrationFlag == 1) && (i_CJCFlag == 0)) - { - //ui_InterruptChannelValue[i_Count + 1]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 1]=ui_DigitalTemperature; + i_APCI3200_ReadCalibrationOffsetValue + (dev, &ui_DummyValue); + } // if ((i_CJCFlag == 1) && (i_CalibrationFlag == 0)) + + /********************************************************/ + /*Test if the value read is the calibration offset value */ + /********************************************************/ + + if ((i_CalibrationFlag == 1) + && (i_CJCFlag == 0)) { + //ui_InterruptChannelValue[i_Count + 1]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 1] = + ui_DigitalTemperature; /****************************************************/ - /*Start the conversion of the calibration gain value*/ + /*Start the conversion of the calibration gain value */ /****************************************************/ - i_APCI3200_ReadCalibrationGainValue(dev,&ui_DummyValue); + i_APCI3200_ReadCalibrationGainValue(dev, + &ui_DummyValue); - }//if ((i_CalibrationFlag == 1) && (i_CJCFlag == 0)) - + } //if ((i_CalibrationFlag == 1) && (i_CJCFlag == 0)) /******************************************************/ - /*Test if the value read is the calibration gain value*/ + /*Test if the value read is the calibration gain value */ /******************************************************/ - - if ((i_CalibrationFlag == 2) && (i_CJCFlag == 0)) - { - //ui_InterruptChannelValue[i_Count + 2]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 2]=ui_DigitalTemperature; + if ((i_CalibrationFlag == 2) + && (i_CJCFlag == 0)) { + //ui_InterruptChannelValue[i_Count + 2]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 2] = + ui_DigitalTemperature; /**********************************************************/ - /*Test if the Calibration channel must be read for the CJC*/ + /*Test if the Calibration channel must be read for the CJC */ /**********************************************************/ - - /*Test if the polarity is the same*/ - /**********************************/ - //if(i_CJCPolarity!=i_ADDIDATAPolarity) - if(s_BoardInfos [dev->minor].i_CJCPolarity!=s_BoardInfos [dev->minor].i_ADDIDATAPolarity) - { - i_ConvertCJCCalibration=1; - }//if(i_CJCPolarity!=i_ADDIDATAPolarity) - else - { - //if(i_CJCGain==i_ADDIDATAGain) - if(s_BoardInfos [dev->minor].i_CJCGain==s_BoardInfos [dev->minor].i_ADDIDATAGain) - { - i_ConvertCJCCalibration=0; - }//if(i_CJCGain==i_ADDIDATAGain) - else - { - i_ConvertCJCCalibration=1; - }//elseif(i_CJCGain==i_ADDIDATAGain) - }//elseif(i_CJCPolarity!=i_ADDIDATAPolarity) - if(i_ConvertCJCCalibration==1) - { + + /*Test if the polarity is the same */ + /**********************************/ + //if(i_CJCPolarity!=i_ADDIDATAPolarity) + if (s_BoardInfos[dev->minor]. + i_CJCPolarity != + s_BoardInfos[dev->minor]. + i_ADDIDATAPolarity) { + i_ConvertCJCCalibration = 1; + } //if(i_CJCPolarity!=i_ADDIDATAPolarity) + else { + //if(i_CJCGain==i_ADDIDATAGain) + if (s_BoardInfos[dev->minor]. + i_CJCGain == + s_BoardInfos[dev-> + minor]. + i_ADDIDATAGain) { + i_ConvertCJCCalibration + = 0; + } //if(i_CJCGain==i_ADDIDATAGain) + else { + i_ConvertCJCCalibration + = 1; + } //elseif(i_CJCGain==i_ADDIDATAGain) + } //elseif(i_CJCPolarity!=i_ADDIDATAPolarity) + if (i_ConvertCJCCalibration == 1) { /****************************************************************/ - /*Start the conversion of the calibration gain value for the CJC*/ + /*Start the conversion of the calibration gain value for the CJC */ /****************************************************************/ - i_APCI3200_ReadCJCCalOffset(dev,&ui_DummyValue); - - }//if(i_ConvertCJCCalibration==1) - else - { - //ui_InterruptChannelValue[i_Count + 4]=0; - //ui_InterruptChannelValue[i_Count + 5]=0; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 4]=0; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 5]=0; - }//elseif(i_ConvertCJCCalibration==1) - }//else if ((i_CalibrationFlag == 2) && (i_CJCFlag == 0)) - - /********************************************************************/ - /*Test if the value read is the calibration offset value for the CJC*/ - /********************************************************************/ - - - if ((i_CalibrationFlag == 1) && (i_CJCFlag == 1)) - { - //ui_InterruptChannelValue[i_Count + 4]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 4]=ui_DigitalTemperature; - - /****************************************************************/ - /*Start the conversion of the calibration gain value for the CJC*/ - /****************************************************************/ - i_APCI3200_ReadCJCCalGain(dev,&ui_DummyValue); - - }//if ((i_CalibrationFlag == 1) && (i_CJCFlag == 1)) - + i_APCI3200_ReadCJCCalOffset(dev, + &ui_DummyValue); + + } //if(i_ConvertCJCCalibration==1) + else { + //ui_InterruptChannelValue[i_Count + 4]=0; + //ui_InterruptChannelValue[i_Count + 5]=0; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev-> + minor].i_Count + + 4] = 0; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev-> + minor].i_Count + + 5] = 0; + } //elseif(i_ConvertCJCCalibration==1) + } //else if ((i_CalibrationFlag == 2) && (i_CJCFlag == 0)) + + /********************************************************************/ + /*Test if the value read is the calibration offset value for the CJC */ + /********************************************************************/ + + if ((i_CalibrationFlag == 1) + && (i_CJCFlag == 1)) { + //ui_InterruptChannelValue[i_Count + 4]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 4] = + ui_DigitalTemperature; + + /****************************************************************/ + /*Start the conversion of the calibration gain value for the CJC */ + /****************************************************************/ + i_APCI3200_ReadCJCCalGain(dev, + &ui_DummyValue); + + } //if ((i_CalibrationFlag == 1) && (i_CJCFlag == 1)) /******************************************************************/ - /*Test if the value read is the calibration gain value for the CJC*/ + /*Test if the value read is the calibration gain value for the CJC */ /******************************************************************/ - - if ((i_CalibrationFlag == 2) && (i_CJCFlag == 1)) - { - //ui_InterruptChannelValue[i_Count + 5]=ui_DigitalTemperature; - s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 5]=ui_DigitalTemperature; - - //if(i_ScanType==1) - if(s_BoardInfos [dev->minor].i_ScanType==1) - { - - //i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - //i_Count=i_Count + 6; - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; - s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 9; - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - }//if(i_ScanType==1) - else - { - //i_Count=0; - s_BoardInfos [dev->minor].i_Count=0; - }//elseif(i_ScanType==1) - - //if(i_ScanType!=1) - if(s_BoardInfos [dev->minor].i_ScanType!=1) - { - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - }//if(i_ScanType!=1) - else - { - //if(i_ChannelCount==i_Sum) - if(s_BoardInfos [dev->minor].i_ChannelCount==s_BoardInfos [dev->minor].i_Sum) - { - send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample - - }//if(i_ChannelCount==i_Sum) - }//else if(i_ScanType!=1) - }//if ((i_CalibrationFlag == 2) && (i_CJCFlag == 1)) - - }//else if ((ui_StatusRegister & 0x2) == 0x2) - break; - }//switch(i_ADDIDATAType) - break; - case 2: - case 3: - i_APCI3200_InterruptHandleEos(dev); - break; - }//switch(i_ScanType) - return; + if ((i_CalibrationFlag == 2) + && (i_CJCFlag == 1)) { + //ui_InterruptChannelValue[i_Count + 5]=ui_DigitalTemperature; + s_BoardInfos[dev->minor]. + ui_InterruptChannelValue + [s_BoardInfos[dev->minor]. + i_Count + 5] = + ui_DigitalTemperature; + + //if(i_ScanType==1) + if (s_BoardInfos[dev->minor]. + i_ScanType == 1) { + + //i_InterruptFlag=0; + s_BoardInfos[dev->minor]. + i_InterruptFlag = 0; + //i_Count=i_Count + 6; + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + //s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; + s_BoardInfos[dev->minor]. + i_Count = + s_BoardInfos[dev-> + minor].i_Count + 9; + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + } //if(i_ScanType==1) + else { + //i_Count=0; + s_BoardInfos[dev->minor]. + i_Count = 0; + } //elseif(i_ScanType==1) + + //if(i_ScanType!=1) + if (s_BoardInfos[dev->minor]. + i_ScanType != 1) { + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + } //if(i_ScanType!=1) + else { + //if(i_ChannelCount==i_Sum) + if (s_BoardInfos[dev->minor]. + i_ChannelCount == + s_BoardInfos[dev-> + minor].i_Sum) { + send_sig(SIGIO, devpriv->tsk_Current, 0); // send signal to the sample + + } //if(i_ChannelCount==i_Sum) + } //else if(i_ScanType!=1) + } //if ((i_CalibrationFlag == 2) && (i_CJCFlag == 1)) + + } //else if ((ui_StatusRegister & 0x2) == 0x2) + break; + } //switch(i_ADDIDATAType) + break; + case 2: + case 3: + i_APCI3200_InterruptHandleEos(dev); + break; + } //switch(i_ScanType) + return; } - - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3200_InterruptHandleEos(comedi_device *dev) | @@ -3346,124 +3499,144 @@ void v_APCI3200_Interrupt(int irq, void *d) | | +----------------------------------------------------------------------------+ */ -int i_APCI3200_InterruptHandleEos(comedi_device *dev) -{ - UINT ui_StatusRegister=0; - comedi_subdevice *s=dev->subdevices+0; - - //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //comedi_async *async = s->async; - //UINT *data; - //data=async->data+async->buf_int_ptr;//new samples added from here onwards - int n = 0, i = 0; - //END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - +int i_APCI3200_InterruptHandleEos(comedi_device * dev) +{ + UINT ui_StatusRegister = 0; + comedi_subdevice *s = dev->subdevices + 0; + + //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //comedi_async *async = s->async; + //UINT *data; + //data=async->data+async->buf_int_ptr;//new samples added from here onwards + int n = 0, i = 0; + //END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + /************************************/ - /*Read the interrupt status register*/ + /*Read the interrupt status register */ /************************************/ - //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); - ui_StatusRegister = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 16); - + //ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); + ui_StatusRegister = + inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 16); + /*************************/ - /*Test if interrupt occur*/ + /*Test if interrupt occur */ /*************************/ - - if ((ui_StatusRegister & 0x2) == 0x2) - { + + if ((ui_StatusRegister & 0x2) == 0x2) { /*************************/ - /*Read the channel number*/ + /*Read the channel number */ /*************************/ - //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); - //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //This value is not used - //ui_ChannelNumber = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 24); - s->async->events = 0; - //END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); + //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //This value is not used + //ui_ChannelNumber = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 24); + s->async->events = 0; + //END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 /*************************************/ - /*Read the digital Analog Input value*/ + /*Read the digital Analog Input value */ /*************************************/ - //data[i_Count] = inl(devpriv->iobase+i_Offset + 28); - //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //data[s_BoardInfos [dev->minor].i_Count] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - s_BoardInfos [dev->minor].ui_ScanValueArray [s_BoardInfos [dev->minor].i_Count] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); - //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - - //if((i_Count == (i_LastChannel-i_FirstChannel+3))) - if((s_BoardInfos [dev->minor].i_Count == (s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+3))) - { - - //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - s_BoardInfos [dev->minor].i_Count++; - - for (i=s_BoardInfos [dev->minor].i_FirstChannel; i<=s_BoardInfos [dev->minor].i_LastChannel; i++) - { - i_APCI3200_GetChannelCalibrationValue (dev, i, - &s_BoardInfos [dev->minor].ui_ScanValueArray [s_BoardInfos [dev->minor].i_Count + - ((i-s_BoardInfos [dev->minor].i_FirstChannel)*3)], - &s_BoardInfos [dev->minor].ui_ScanValueArray [s_BoardInfos [dev->minor].i_Count + - ((i-s_BoardInfos [dev->minor].i_FirstChannel)*3) + 1], - &s_BoardInfos [dev->minor].ui_ScanValueArray [s_BoardInfos [dev->minor].i_Count + - ((i-s_BoardInfos [dev->minor].i_FirstChannel)*3) + 2]); - } - - //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - - //i_Count=-1; - - s_BoardInfos [dev->minor].i_Count=-1; - - //async->buf_int_count+=(i_LastChannel-i_FirstChannel+4)*sizeof(UINT); - //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //async->buf_int_count+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(UINT); - //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //async->buf_int_ptr+=(i_LastChannel-i_FirstChannel+4)*sizeof(UINT); - //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - //async->buf_int_ptr+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(UINT); - //comedi_eos(dev,s); - - // Set the event type (Comedi Buffer End Of Scan) - s->async->events |= COMEDI_CB_EOS; - - // Test if enougth memory is available and allocate it for 7 values - //n = comedi_buf_write_alloc(s->async, 7*sizeof(lsampl_t)); - n = comedi_buf_write_alloc(s->async, (7+12)*sizeof(lsampl_t)); - - // If not enougth memory available, event is set to Comedi Buffer Errror - if (n > ((7+12)*sizeof(lsampl_t))) - { - printk ("\ncomedi_buf_write_alloc n = %i", n); - s->async->events |= COMEDI_CB_ERROR; - } - - // Write all 7 scan values in the comedi buffer - comedi_buf_memcpy_to(s->async, 0, (lsampl_t*)s_BoardInfos [dev->minor].ui_ScanValueArray, (7+12)*sizeof(lsampl_t)); - - // Update comedi buffer pinters indexes - comedi_buf_write_free(s->async, (7+12)*sizeof(lsampl_t)); - - // Send events - comedi_event(dev,s); - //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - - //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - // - //if (s->async->buf_int_ptr>=s->async->data_len) // for buffer rool over - // { - // /* buffer rollover */ - // s->async->buf_int_ptr=0; - // comedi_eobuf(dev,s); - // } - //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - } - //i_Count++; - s_BoardInfos [dev->minor].i_Count++; - } - //i_InterruptFlag=0; - s_BoardInfos [dev->minor].i_InterruptFlag=0; - return 0; -} - - - + //data[i_Count] = inl(devpriv->iobase+i_Offset + 28); + //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //data[s_BoardInfos [dev->minor].i_Count] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); + s_BoardInfos[dev->minor].ui_ScanValueArray[s_BoardInfos[dev-> + minor].i_Count] = + inl(devpriv->iobase + + s_BoardInfos[dev->minor].i_Offset + 28); + //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + + //if((i_Count == (i_LastChannel-i_FirstChannel+3))) + if ((s_BoardInfos[dev->minor].i_Count == + (s_BoardInfos[dev->minor].i_LastChannel - + s_BoardInfos[dev->minor]. + i_FirstChannel + 3))) { + + //Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + s_BoardInfos[dev->minor].i_Count++; + + for (i = s_BoardInfos[dev->minor].i_FirstChannel; + i <= s_BoardInfos[dev->minor].i_LastChannel; + i++) { + i_APCI3200_GetChannelCalibrationValue(dev, i, + &s_BoardInfos[dev->minor]. + ui_ScanValueArray[s_BoardInfos[dev-> + minor].i_Count + ((i - + s_BoardInfos + [dev->minor]. + i_FirstChannel) + * 3)], + &s_BoardInfos[dev->minor]. + ui_ScanValueArray[s_BoardInfos[dev-> + minor].i_Count + ((i - + s_BoardInfos + [dev->minor]. + i_FirstChannel) + * 3) + 1], + &s_BoardInfos[dev->minor]. + ui_ScanValueArray[s_BoardInfos[dev-> + minor].i_Count + ((i - + s_BoardInfos + [dev->minor]. + i_FirstChannel) + * 3) + 2]); + } + + //End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + + //i_Count=-1; + + s_BoardInfos[dev->minor].i_Count = -1; + + //async->buf_int_count+=(i_LastChannel-i_FirstChannel+4)*sizeof(UINT); + //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //async->buf_int_count+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(UINT); + //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //async->buf_int_ptr+=(i_LastChannel-i_FirstChannel+4)*sizeof(UINT); + //Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + //async->buf_int_ptr+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(UINT); + //comedi_eos(dev,s); + + // Set the event type (Comedi Buffer End Of Scan) + s->async->events |= COMEDI_CB_EOS; + + // Test if enougth memory is available and allocate it for 7 values + //n = comedi_buf_write_alloc(s->async, 7*sizeof(lsampl_t)); + n = comedi_buf_write_alloc(s->async, + (7 + 12) * sizeof(lsampl_t)); + + // If not enougth memory available, event is set to Comedi Buffer Errror + if (n > ((7 + 12) * sizeof(lsampl_t))) { + printk("\ncomedi_buf_write_alloc n = %i", n); + s->async->events |= COMEDI_CB_ERROR; + } + // Write all 7 scan values in the comedi buffer + comedi_buf_memcpy_to(s->async, 0, + (lsampl_t *) s_BoardInfos[dev->minor]. + ui_ScanValueArray, (7 + 12) * sizeof(lsampl_t)); + + // Update comedi buffer pinters indexes + comedi_buf_write_free(s->async, + (7 + 12) * sizeof(lsampl_t)); + + // Send events + comedi_event(dev, s); + //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + + //BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + // + //if (s->async->buf_int_ptr>=s->async->data_len) // for buffer rool over + // { + // /* buffer rollover */ + // s->async->buf_int_ptr=0; + // comedi_eobuf(dev,s); + // } + //End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + } + //i_Count++; + s_BoardInfos[dev->minor].i_Count++; + } + //i_InterruptFlag=0; + s_BoardInfos[dev->minor].i_InterruptFlag = 0; + return 0; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci3200.h b/comedi/drivers/addi-data/hwdrv_apci3200.h index 96523646..e352f476 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3200.h +++ b/comedi/drivers/addi-data/hwdrv_apci3200.h @@ -26,43 +26,39 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define APCI3200_BOARD_VENDOR_ID 0x15B8 //#define APCI3200_ADDRESS_RANGE 264 - - -int MODULE_NO ; - struct -{ - INT i_Gain ; - INT i_Polarity; - INT i_OffsetRange; - INT i_Coupling; - INT i_SingleDiff; - INT i_AutoCalibration; - UINT ui_ReloadValue; - UINT ui_TimeUnitReloadVal; - INT i_Interrupt; - INT i_ModuleSelection; -}Config_Parameters_Module1,Config_Parameters_Module2,Config_Parameters_Module3,Config_Parameters_Module4; - - +int MODULE_NO; +struct { + INT i_Gain; + INT i_Polarity; + INT i_OffsetRange; + INT i_Coupling; + INT i_SingleDiff; + INT i_AutoCalibration; + UINT ui_ReloadValue; + UINT ui_TimeUnitReloadVal; + INT i_Interrupt; + INT i_ModuleSelection; +} Config_Parameters_Module1, Config_Parameters_Module2, + Config_Parameters_Module3, Config_Parameters_Module4; //ANALOG INPUT RANGE -comedi_lrange range_apci3200_ai={ 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1) +comedi_lrange range_apci3200_ai = { 8, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1) } }; -comedi_lrange range_apci3300_ai={ 4, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1) +comedi_lrange range_apci3300_ai = { 4, { + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1) } }; @@ -93,7 +89,6 @@ comedi_lrange range_apci3300_ai={ 4, { #define ENABLE_EXT_GATE 2 #define ENABLE_EXT_TRIG_GATE 3 - #define APCI3200_MAXVOLT 2.5 #define ADDIDATA_GREATER_THAN_TEST 0 #define ADDIDATA_LESS_THAN_TEST 1 @@ -105,90 +100,92 @@ comedi_lrange range_apci3300_ai={ 4, { #define MAX_MODULE 4 //END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values -typedef struct - { - ULONG ul_NumberOfValue; - ULONG *pul_ResistanceValue; - ULONG *pul_TemperatureValue; - }str_ADDIDATA_RTDStruct,*pstr_ADDIDATA_RTDStruct; +typedef struct { + ULONG ul_NumberOfValue; + ULONG *pul_ResistanceValue; + ULONG *pul_TemperatureValue; +} str_ADDIDATA_RTDStruct, *pstr_ADDIDATA_RTDStruct; //BEGIN JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values -typedef struct - { - // Begin JK 05/08/2003 change for Linux - unsigned long ul_CurrentSourceCJC; - unsigned long ul_CurrentSource [5]; - // End JK 05/08/2003 change for Linux - - // Begin CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1 - unsigned long ul_GainFactor [8]; // Gain Factor - unsigned int w_GainValue [10]; - // End CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1 - }str_Module; +typedef struct { + // Begin JK 05/08/2003 change for Linux + unsigned long ul_CurrentSourceCJC; + unsigned long ul_CurrentSource[5]; + // End JK 05/08/2003 change for Linux + + // Begin CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1 + unsigned long ul_GainFactor[8]; // Gain Factor + unsigned int w_GainValue[10]; + // End CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1 +} str_Module; //END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - + //BEGIN JK 06.07.04: Management of sevrals boards -typedef struct - { - INT i_CJCAvailable; - INT i_CJCPolarity; - INT i_CJCGain; - INT i_InterruptFlag; - INT i_ADDIDATAPolarity; - INT i_ADDIDATAGain; - INT i_AutoCalibration; - INT i_ADDIDATAConversionTime; - INT i_ADDIDATAConversionTimeUnit; - INT i_ADDIDATAType; - INT i_ChannelNo; - INT i_ChannelCount; - INT i_ScanType; - INT i_FirstChannel; - INT i_LastChannel; - INT i_Sum; - INT i_Offset; - UINT ui_Channel_num; - INT i_Count; - INT i_Initialised; - //UINT ui_InterruptChannelValue[96]; //Buffer - UINT ui_InterruptChannelValue[144]; //Buffer - BYTE b_StructInitialized; - //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - lsampl_t ui_ScanValueArray [7+12]; // 7 is the maximal number of channels - //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 - - //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - INT i_ConnectionType; - INT i_NbrOfModule; - str_Module s_Module [MAX_MODULE]; - //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values - } str_BoardInfos; +typedef struct { + INT i_CJCAvailable; + INT i_CJCPolarity; + INT i_CJCGain; + INT i_InterruptFlag; + INT i_ADDIDATAPolarity; + INT i_ADDIDATAGain; + INT i_AutoCalibration; + INT i_ADDIDATAConversionTime; + INT i_ADDIDATAConversionTimeUnit; + INT i_ADDIDATAType; + INT i_ChannelNo; + INT i_ChannelCount; + INT i_ScanType; + INT i_FirstChannel; + INT i_LastChannel; + INT i_Sum; + INT i_Offset; + UINT ui_Channel_num; + INT i_Count; + INT i_Initialised; + //UINT ui_InterruptChannelValue[96]; //Buffer + UINT ui_InterruptChannelValue[144]; //Buffer + BYTE b_StructInitialized; + //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + lsampl_t ui_ScanValueArray[7 + 12]; // 7 is the maximal number of channels + //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 + + //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values + INT i_ConnectionType; + INT i_NbrOfModule; + str_Module s_Module[MAX_MODULE]; + //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values +} str_BoardInfos; //END JK 06.07.04: Management of sevrals boards - // Hardware Layer functions for Apci3200 //AI -INT i_APCI3200_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3200_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3200_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s); -INT i_APCI3200_InterruptHandleEos(comedi_device *dev); -INT i_APCI3200_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) ; -INT i_APCI3200_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s); -INT i_APCI3200_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +INT i_APCI3200_ConfigAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI3200_ReadAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +INT i_APCI3200_StopCyclicAcquisition(comedi_device * dev, comedi_subdevice * s); +INT i_APCI3200_InterruptHandleEos(comedi_device * dev); +INT i_APCI3200_CommandTestAnalogInput(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +INT i_APCI3200_CommandAnalogInput(comedi_device * dev, comedi_subdevice * s); +INT i_APCI3200_ReadDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //Interrupt -void v_APCI3200_Interrupt(int irq, void *d) ; -int i_APCI3200_InterruptHandleEos(comedi_device *dev); +void v_APCI3200_Interrupt(int irq, void *d); +int i_APCI3200_InterruptHandleEos(comedi_device * dev); //Reset functions -INT i_APCI3200_Reset(comedi_device *dev); - - -int i_APCI3200_ReadCJCCalOffset(comedi_device *dev,lsampl_t *data); -int i_APCI3200_ReadCJCValue(comedi_device *dev,lsampl_t *data); -int i_APCI3200_ReadCalibrationGainValue(comedi_device *dev,UINT *data); -int i_APCI3200_ReadCalibrationOffsetValue(comedi_device *dev,UINT *data); -int i_APCI3200_Read1AnalogInputChannel(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3200_ReadCJCCalGain(comedi_device *dev,lsampl_t *data); +INT i_APCI3200_Reset(comedi_device * dev); + +int i_APCI3200_ReadCJCCalOffset(comedi_device * dev, lsampl_t * data); +int i_APCI3200_ReadCJCValue(comedi_device * dev, lsampl_t * data); +int i_APCI3200_ReadCalibrationGainValue(comedi_device * dev, UINT * data); +int i_APCI3200_ReadCalibrationOffsetValue(comedi_device * dev, UINT * data); +int i_APCI3200_Read1AnalogInputChannel(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI3200_ReadCJCCalGain(comedi_device * dev, lsampl_t * data); diff --git a/comedi/drivers/addi-data/hwdrv_apci3501.c b/comedi/drivers/addi-data/hwdrv_apci3501.c index 3c07ee65..f02fac6d 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -53,10 +53,6 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc */ #include "hwdrv_apci3501.h" - - - - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ReadDigitalInput | @@ -77,30 +73,27 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ -INT i_APCI3501_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ - UINT ui_Temp; - UINT ui_NoOfChannel; - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->iobase+APCI3501_DIGITAL_IP); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } //if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - - *data=*data & 0x3; - }//if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - }//elseif (ui_Temp==1) - }//elseif (ui_Temp==0) -return insn->n; +INT i_APCI3501_ReadDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + UINT ui_Temp; + UINT ui_NoOfChannel; + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->iobase + APCI3501_DIGITAL_IP); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } //if (ui_Temp==0) + else { + if (ui_Temp == 1) { + + *data = *data & 0x3; + } //if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } //elseif (ui_Temp==1) + } //elseif (ui_Temp==0) + return insn->n; } /* @@ -128,27 +121,24 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -int i_APCI3501_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI3501_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { -if ( (data[0]!=0) && (data[0]!=1) ) - { - comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n"); - return -EINVAL; - }//if ( (data[0]!=0) && (data[0]!=1) ) - if (data[0]) - { - devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; - }// if (data[0]) - else - { - devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; - }//else if (data[0]) -return insn->n; + if ((data[0] != 0) && (data[0] != 1)) { + comedi_error(dev, + "Not a valid Data !!! ,Data should be 1 or 0\n"); + return -EINVAL; + } //if ( (data[0]!=0) && (data[0]!=1) ) + if (data[0]) { + devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; + } // if (data[0]) + else { + devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE; + } //else if (data[0]) + return insn->n; } - - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_WriteDigitalOutput | @@ -171,77 +161,74 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI3501_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3501_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp,ui_Temp1; -UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel - if(devpriv->b_OutputMemoryStatus ) - { - ui_Temp=inl(devpriv->iobase+APCI3501_DIGITAL_OP); - }//if(devpriv->b_OutputMemoryStatus ) - else - { - ui_Temp=0; - }//if(devpriv->b_OutputMemoryStatus ) -if(data[3]==0) - { - if(data[1]==0) - { - data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; - outl(data[0],devpriv->iobase+APCI3501_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - data[0]=(data[0] << (2*data[2]))|ui_Temp; - outl(data[0],devpriv->iobase+APCI3501_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==0) -else - { - if(data[3]==1) - { - if(data[1]==0) - { - data[0]=~data[0]&0x1; - ui_Temp1=1; - ui_Temp1=ui_Temp1<iobase+APCI3501_DIGITAL_OP); - }//if(data[1]==0) - else - { - if(data[1]==1) - { - data[0]=~data[0]&0x3; - ui_Temp1=3; - ui_Temp1=ui_Temp1<<2*data[2]; - ui_Temp=ui_Temp|ui_Temp1; - data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; - outl(data[0],devpriv->iobase+APCI3501_DIGITAL_OP); - }// if(data[1]==1) - else - { - printk("\nSpecified channel not supported\n"); - }//else if(data[1]==1) - }//elseif(data[1]==0) - }//if(data[3]==1); - else - { - printk("\nSpecified functionality does not exist\n"); - return -EINVAL; - }//if else data[3]==1) - }//if else data[3]==0) -return insn->n; + UINT ui_Temp, ui_Temp1; + UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel + if (devpriv->b_OutputMemoryStatus) { + ui_Temp = inl(devpriv->iobase + APCI3501_DIGITAL_OP); + } //if(devpriv->b_OutputMemoryStatus ) + else { + ui_Temp = 0; + } //if(devpriv->b_OutputMemoryStatus ) + if (data[3] == 0) { + if (data[1] == 0) { + data[0] = (data[0] << ui_NoOfChannel) | ui_Temp; + outl(data[0], devpriv->iobase + APCI3501_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + data[0] = (data[0] << (2 * data[2])) | ui_Temp; + outl(data[0], + devpriv->iobase + APCI3501_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==0) + else { + if (data[3] == 1) { + if (data[1] == 0) { + data[0] = ~data[0] & 0x1; + ui_Temp1 = 1; + ui_Temp1 = ui_Temp1 << ui_NoOfChannel; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + (data[0] << ui_NoOfChannel) ^ + 0xffffffff; + data[0] = data[0] & ui_Temp; + outl(data[0], + devpriv->iobase + APCI3501_DIGITAL_OP); + } //if(data[1]==0) + else { + if (data[1] == 1) { + data[0] = ~data[0] & 0x3; + ui_Temp1 = 3; + ui_Temp1 = ui_Temp1 << 2 * data[2]; + ui_Temp = ui_Temp | ui_Temp1; + data[0] = + ((data[0] << (2 * + data[2])) ^ + 0xffffffff) & ui_Temp; + outl(data[0], + devpriv->iobase + + APCI3501_DIGITAL_OP); + } // if(data[1]==1) + else { + printk("\nSpecified channel not supported\n"); + } //else if(data[1]==1) + } //elseif(data[1]==0) + } //if(data[3]==1); + else { + printk("\nSpecified functionality does not exist\n"); + return -EINVAL; + } //if else data[3]==1) + } //if else data[3]==0) + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ReadDigitalOutput | @@ -261,31 +248,28 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI3501_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3501_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - UINT ui_Temp; - UINT ui_NoOfChannel; - - ui_NoOfChannel=CR_CHAN(insn->chanspec); - ui_Temp=data[0]; - *data=inl(devpriv->iobase+APCI3501_DIGITAL_OP); - if (ui_Temp==0) - { - *data=(*data >> ui_NoOfChannel)&0x1; - } // if (ui_Temp==0) - else - { - if (ui_Temp==1) - { - *data=*data & 0x3; - - } // if (ui_Temp==1) - else - { - printk("\nSpecified channel not supported \n"); - } // else if (ui_Temp==1) - } // else if (ui_Temp==0) - return insn->n; + UINT ui_Temp; + UINT ui_NoOfChannel; + + ui_NoOfChannel = CR_CHAN(insn->chanspec); + ui_Temp = data[0]; + *data = inl(devpriv->iobase + APCI3501_DIGITAL_OP); + if (ui_Temp == 0) { + *data = (*data >> ui_NoOfChannel) & 0x1; + } // if (ui_Temp==0) + else { + if (ui_Temp == 1) { + *data = *data & 0x3; + + } // if (ui_Temp==1) + else { + printk("\nSpecified channel not supported \n"); + } // else if (ui_Temp==1) + } // else if (ui_Temp==0) + return insn->n; } /* @@ -314,21 +298,20 @@ INT i_APCI3501_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_i | | +----------------------------------------------------------------------------+ */ -INT i_APCI3501_ConfigAnalogOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3501_ConfigAnalogOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - outl(data[0],devpriv->iobase+APCI3501_ANALOG_OUTPUT+APCI3501_AO_VOLT_MODE); - - if(data[0]) - { - devpriv->b_InterruptMode=MODE1; - } - else - { - devpriv->b_InterruptMode=MODE0; - } -return insn->n; -} - + outl(data[0], + devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_VOLT_MODE); + + if (data[0]) { + devpriv->b_InterruptMode = MODE1; + } else { + devpriv->b_InterruptMode = MODE0; + } + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -353,52 +336,52 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI3501_WriteAnalogOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) -{ -ULONG ul_Command1 = 0,ul_Channel_no,ul_Polarity,ul_DAC_Ready=0;; - -ul_Channel_no=CR_CHAN(insn->chanspec); - -if(devpriv->b_InterruptMode==MODE1) - { - ul_Polarity=0x80000000; - if((*data<0) || (*data>16384)) - { - printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); - } - - } // end if(devpriv->b_InterruptMode==MODE1) -else { - ul_Polarity=0; - if((*data<0) || (*data>8192)) - { - printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); - } - - }// end else - -if((ul_Channel_no<0)||(ul_Channel_no>7)) - { - printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); - } // end if((ul_Channel_no<0)||(ul_Channel_no>7)) - -ul_DAC_Ready=inl(devpriv->iobase+APCI3501_ANALOG_OUTPUT); - -while(ul_DAC_Ready==0) - { - ul_DAC_Ready=inl(devpriv->iobase+APCI3501_ANALOG_OUTPUT); - ul_DAC_Ready=(ul_DAC_Ready>>8)&1; - } - -if(ul_DAC_Ready) +INT i_APCI3501_WriteAnalogOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { + ULONG ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0;; + + ul_Channel_no = CR_CHAN(insn->chanspec); + + if (devpriv->b_InterruptMode == MODE1) { + ul_Polarity = 0x80000000; + if ((*data < 0) || (*data > 16384)) { + printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); + } + + } // end if(devpriv->b_InterruptMode==MODE1) + else { + ul_Polarity = 0; + if ((*data < 0) || (*data > 8192)) { + printk("\nIn WriteAnalogOutput :: Not Valid Data\n"); + } + + } // end else + + if ((ul_Channel_no < 0) || (ul_Channel_no > 7)) { + printk("\nIn WriteAnalogOutput :: Not Valid Channel\n"); + } // end if((ul_Channel_no<0)||(ul_Channel_no>7)) + + ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + + while (ul_DAC_Ready == 0) { + ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; + } + + if (ul_DAC_Ready) { // Output the Value on the output channels. -ul_Command1=(ULONG)((ULONG)(ul_Channel_no & 0xFF)|(ULONG)((*data << 0x8)&0x7FFFFF00L)|(ULONG)(ul_Polarity)); -outl(ul_Command1,devpriv->iobase+APCI3501_ANALOG_OUTPUT+APCI3501_AO_PROG); -} + ul_Command1 = + (ULONG) ((ULONG) (ul_Channel_no & 0xFF) | + (ULONG) ((*data << 0x8) & 0x7FFFFF00L) | + (ULONG) (ul_Polarity)); + outl(ul_Command1, + devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_PROG); + } -return insn->n; -} + return insn->n; +} /* +----------------------------------------------------------------------------+ @@ -427,73 +410,82 @@ return insn->n; | | +----------------------------------------------------------------------------+ */ -INT i_APCI3501_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +INT i_APCI3501_ConfigTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - ULONG ul_Command1 = 0; -devpriv->tsk_Current=current; - if (data[0]==ADDIDATA_WATCHDOG) - { - - devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; - //Disable the watchdog - outl(0x0,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); //disable Wa - - if (data[1]==1) - { - //Enable TIMER int & DISABLE ALL THE OTHER int SOURCES - outl(0x02,devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_PROG); - } - else - { - outl(0x0,devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_PROG);//disable Timer interrupt - } - - - //Loading the Timebase value - outl(data[2],devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_TIMEBASE); - - - //Loading the Reload value - outl(data[3],devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_RELOAD_VALUE); - //Set the mode - ul_Command1 = inl(devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_PROG) | 0xFFF819E0UL;//e2->e0 - outl(ul_Command1 , devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_PROG); - }//end if(data[0]==ADDIDATA_WATCHDOG) - - else if (data[0]==ADDIDATA_TIMER) - { - //First Stop The Timer - ul_Command1 =inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG);//Stop The Timer - devpriv->b_TimerSelectMode =ADDIDATA_TIMER; - if (data[1]==1) - { - //Enable TIMER int & DISABLE ALL THE OTHER int SOURCES - outl(0x02,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - else - { - outl(0x0,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG);//disable Timer interrupt - } - - // Loading Timebase - outl(data[2],devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_TIMEBASE); - - //Loading the Reload value - outl(data[3],devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_RELOAD_VALUE); - - // printk ("\nTimer Address :: %x\n", (devpriv->iobase+APCI3501_WATCHDOG)); - ul_Command1 =inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 = (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG);//mode 2 - - }//end if(data[0]==ADDIDATA_TIMER) - -return insn->n; + ULONG ul_Command1 = 0; + devpriv->tsk_Current = current; + if (data[0] == ADDIDATA_WATCHDOG) { + + devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; + //Disable the watchdog + outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); //disable Wa + + if (data[1] == 1) { + //Enable TIMER int & DISABLE ALL THE OTHER int SOURCES + outl(0x02, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } else { + outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); //disable Timer interrupt + } + + //Loading the Timebase value + outl(data[2], + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TIMEBASE); + + //Loading the Reload value + outl(data[3], + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_RELOAD_VALUE); + //Set the mode + ul_Command1 = inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG) | 0xFFF819E0UL; //e2->e0 + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } //end if(data[0]==ADDIDATA_WATCHDOG) + + else if (data[0] == ADDIDATA_TIMER) { + //First Stop The Timer + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); //Stop The Timer + devpriv->b_TimerSelectMode = ADDIDATA_TIMER; + if (data[1] == 1) { + //Enable TIMER int & DISABLE ALL THE OTHER int SOURCES + outl(0x02, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } else { + outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); //disable Timer interrupt + } + + // Loading Timebase + outl(data[2], + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TIMEBASE); + + //Loading the Reload value + outl(data[3], + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_RELOAD_VALUE); + + // printk ("\nTimer Address :: %x\n", (devpriv->iobase+APCI3501_WATCHDOG)); + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = + (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; + outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); //mode 2 + + } //end if(data[0]==ADDIDATA_TIMER) + + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_StartStopWriteTimerCounterWatchdog | @@ -519,68 +511,84 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI3501_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI3501_StartStopWriteTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { -ULONG ul_Command1 = 0; -int i_Temp; -if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - - if (data[1]==1) - { - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1=(ul_Command1& 0xFFFFF9FFUL) | 0x1UL; - //Enable the Watchdog - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - - else if(data[1]==0)//Stop The Watchdog - { - //Stop The Watchdog - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(0x0,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - else if(data[1]==2) - { - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - }//if(data[1]==2) - } // end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - -if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - { - if (data[1]==1) - { - - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1=(ul_Command1& 0xFFFFF9FFUL) | 0x1UL; - //Enable the Timer - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - else if(data[1]==0) - { - //Stop The Timer - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 =ul_Command1 & 0xFFFFF9FEUL; - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - - else if (data[1]==2) - { - //Trigger the Timer - ul_Command1=inl(devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; - outl(ul_Command1,devpriv->iobase+ APCI3501_WATCHDOG+ APCI3501_TCW_PROG); - } - - } // end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) -i_Temp= inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS)&0x1; -return insn->n; + ULONG ul_Command1 = 0; + int i_Temp; + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + + if (data[1] == 1) { + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; + //Enable the Watchdog + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } + + else if (data[1] == 0) //Stop The Watchdog + { + //Stop The Watchdog + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(0x0, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } else if (data[1] == 2) { + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } //if(data[1]==2) + } // end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) + + if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { + if (data[1] == 1) { + + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; + //Enable the Timer + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } else if (data[1] == 0) { + //Stop The Timer + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } + + else if (data[1] == 2) { + //Trigger the Timer + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_PROG); + } + + } // end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) + i_Temp = inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TRIG_STATUS) & 0x1; + return insn->n; } - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ReadTimerCounterWatchdog | @@ -605,27 +613,31 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI3501_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +int i_APCI3501_ReadTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - - if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - { - data[0]= inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS)&0x1; - data[1]= inl(devpriv->iobase + APCI3501_WATCHDOG); - }// end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) - - else if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - { - data[0]= inl(devpriv->iobase+APCI3501_WATCHDOG+APCI3501_TCW_TRIG_STATUS)&0x1; - data[1]= inl(devpriv->iobase + APCI3501_WATCHDOG); - } // end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) - - else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)) - { - printk ("\nIn ReadTimerCounterWatchdog :: Invalid Subdevice \n"); - } -return insn->n; + + if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { + data[0] = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TRIG_STATUS) & 0x1; + data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG); + } // end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) + + else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { + data[0] = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TRIG_STATUS) & 0x1; + data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG); + } // end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) + + else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER) + && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) { + printk("\nIn ReadTimerCounterWatchdog :: Invalid Subdevice \n"); + } + return insn->n; } + /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_Reset(comedi_device *dev) | @@ -642,39 +654,39 @@ return insn->n; +----------------------------------------------------------------------------+ */ -int i_APCI3501_Reset(comedi_device *dev) +int i_APCI3501_Reset(comedi_device * dev) { -int i_Count=0,i_temp=0; -ULONG ul_Command1 = 0,ul_Polarity,ul_DAC_Ready=0; -outl(0x0,devpriv->iobase+APCI3501_DIGITAL_OP); -outl(1,devpriv->iobase+APCI3501_ANALOG_OUTPUT+APCI3501_AO_VOLT_MODE); - - ul_Polarity=0x80000000; - -for(i_Count=0;i_Count<=7;i_Count++) - { - ul_DAC_Ready=inl(devpriv->iobase+APCI3501_ANALOG_OUTPUT); - - while(ul_DAC_Ready==0) - { - ul_DAC_Ready=inl(devpriv->iobase+APCI3501_ANALOG_OUTPUT); - ul_DAC_Ready=(ul_DAC_Ready>>8)&1; - } - - if(ul_DAC_Ready) - { - // Output the Value on the output channels. - ul_Command1=(ULONG)((ULONG)(i_Count & 0xFF)|(ULONG)((i_temp << 0x8)&0x7FFFFF00L)|(ULONG)(ul_Polarity)); - outl(ul_Command1,devpriv->iobase+APCI3501_ANALOG_OUTPUT+APCI3501_AO_PROG); - } - } - -return 0; -} - - - + int i_Count = 0, i_temp = 0; + ULONG ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0; + outl(0x0, devpriv->iobase + APCI3501_DIGITAL_OP); + outl(1, devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_VOLT_MODE); + + ul_Polarity = 0x80000000; + + for (i_Count = 0; i_Count <= 7; i_Count++) { + ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + + while (ul_DAC_Ready == 0) { + ul_DAC_Ready = + inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT); + ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1; + } + + if (ul_DAC_Ready) { + // Output the Value on the output channels. + ul_Command1 = + (ULONG) ((ULONG) (i_Count & 0xFF) | + (ULONG) ((i_temp << 0x8) & 0x7FFFFF00L) | + (ULONG) (ul_Polarity)); + outl(ul_Command1, + devpriv->iobase + APCI3501_ANALOG_OUTPUT + + APCI3501_AO_PROG); + } + } + return 0; +} /* +----------------------------------------------------------------------------+ @@ -693,37 +705,38 @@ return 0; | | +----------------------------------------------------------------------------+ */ - void v_APCI3501_Interrupt(int irq, void *d) +void v_APCI3501_Interrupt(int irq, void *d) { - int i_temp; - comedi_device *dev = d; - unsigned int ui_Timer_AOWatchdog ; - unsigned long ul_Command1; - // Disable Interrupt - ul_Command1=inl(devpriv->iobase+APCI3501_WATCHDOG +APCI3501_TCW_PROG); - - ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); - outl(ul_Command1 , devpriv->iobase+APCI3501_WATCHDOG +APCI3501_TCW_PROG); - - - ui_Timer_AOWatchdog=inl(devpriv->iobase+APCI3501_WATCHDOG +APCI3501_TCW_IRQ )& 0x1; - - if ((!ui_Timer_AOWatchdog)) - { - comedi_error(dev,"IRQ from unknow source"); - return; + int i_temp; + comedi_device *dev = d; + unsigned int ui_Timer_AOWatchdog; + unsigned long ul_Command1; + // Disable Interrupt + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + + ul_Command1 = (ul_Command1 & 0xFFFFF9FDul); + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + + ui_Timer_AOWatchdog = + inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_IRQ) & 0x1; + + if ((!ui_Timer_AOWatchdog)) { + comedi_error(dev, "IRQ from unknow source"); + return; } - - - // Enable Interrupt - //Send a signal to from kernel to user space - send_sig(SIGIO,devpriv->tsk_Current,0); - ul_Command1=inl(devpriv->iobase+APCI3501_WATCHDOG +APCI3501_TCW_PROG); - ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); - outl(ul_Command1 , devpriv->iobase+APCI3501_WATCHDOG +APCI3501_TCW_PROG); - i_temp= inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_TRIG_STATUS)&0x1; -return; -} - - + // Enable Interrupt + //Send a signal to from kernel to user space + send_sig(SIGIO, devpriv->tsk_Current, 0); + ul_Command1 = + inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1); + outl(ul_Command1, + devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); + i_temp = inl(devpriv->iobase + APCI3501_WATCHDOG + + APCI3501_TCW_TRIG_STATUS) & 0x1; + return; +} diff --git a/comedi/drivers/addi-data/hwdrv_apci3501.h b/comedi/drivers/addi-data/hwdrv_apci3501.h index d233acd9..d183d573 100644 --- a/comedi/drivers/addi-data/hwdrv_apci3501.h +++ b/comedi/drivers/addi-data/hwdrv_apci3501.h @@ -38,10 +38,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc #define MODE0 0 #define MODE1 1 // ANALOG OUTPUT RANGE -comedi_lrange range_apci3501_ao= { 2, { - BIP_RANGE(10), - UNI_RANGE(10) - } +comedi_lrange range_apci3501_ao = { 2, { + BIP_RANGE(10), + UNI_RANGE(10) + } }; //Watchdog Related Defines @@ -58,37 +58,39 @@ comedi_lrange range_apci3501_ao= { 2, { #define ADDIDATA_TIMER 0 #define ADDIDATA_WATCHDOG 2 - // Hardware Layer functions for Apci3501 //AO -INT i_APCI3501_ConfigAnalogOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3501_WriteAnalogOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - +INT i_APCI3501_ConfigAnalogOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI3501_WriteAnalogOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + //DI // for di read //INT i_APCI3501_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3501_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +INT i_APCI3501_ReadDigitalInput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //DO -int i_APCI3501_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3501_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -INT i_APCI3501_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +int i_APCI3501_ConfigDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI3501_WriteDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +INT i_APCI3501_ReadDigitalOutput(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); // TIMER // timer value is passed as u seconds -INT i_APCI3501_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3501_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -int i_APCI3501_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +INT i_APCI3501_ConfigTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI3501_StartStopWriteTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +int i_APCI3501_ReadTimerCounterWatchdog(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); //Interrupt -void v_APCI3501_Interrupt(int irq, void *d) ; +void v_APCI3501_Interrupt(int irq, void *d); //Reset functions - int i_APCI3501_Reset(comedi_device *dev); - - - - - - +int i_APCI3501_Reset(comedi_device * dev); diff --git a/comedi/drivers/addi-data/hwdrv_apci3xxx.c b/comedi/drivers/addi-data/hwdrv_apci3xxx.c index 41bcab7f..57e8060e 100755 --- a/comedi/drivers/addi-data/hwdrv_apci3xxx.c +++ b/comedi/drivers/addi-data/hwdrv_apci3xxx.c @@ -19,8 +19,6 @@ You should have received a copy of the GNU General Public License along with thi You shoud also find the complete GPL in the COPYING file accompanying this source code. - - @endverbatim */ /* @@ -46,10 +44,8 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------+-----------+------------------------------------------------+ */ - #include "hwdrv_apci3xxx.h" - /* +----------------------------------------------------------------------------+ | ANALOG INPUT FUNCTIONS | @@ -72,18 +68,14 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_TestConversionStarted (comedi_device *dev) - { - if ((readl ((void *) (devpriv->dw_AiBase + 8)) & 0x80000UL) == 0x80000UL) - { - return (1); - } - else - { - return (0); - } +int i_APCI3XXX_TestConversionStarted(comedi_device * dev) +{ + if ((readl((void *)(devpriv->dw_AiBase + 8)) & 0x80000UL) == 0x80000UL) { + return (1); + } else { + return (0); } - +} /* +----------------------------------------------------------------------------+ @@ -113,178 +105,171 @@ int i_APCI3XXX_TestConversionStarted (comedi_device *dev) +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_AnalogInputConfigOperatingMode (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_TimeBase = 0; - BYTE b_SingleDiff = 0; - DWORD dw_ReloadValue = 0; - DWORD dw_TestReloadValue = 0; - +int i_APCI3XXX_AnalogInputConfigOperatingMode(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_TimeBase = 0; + BYTE b_SingleDiff = 0; + DWORD dw_ReloadValue = 0; + DWORD dw_TestReloadValue = 0; + /************************/ /* Test the buffer size */ /************************/ - - if (insn->n == 4) - { + + if (insn->n == 4) { /****************************/ - /* Get the Singel/Diff flag */ + /* Get the Singel/Diff flag */ /****************************/ - - b_SingleDiff = (BYTE) data[1]; - + + b_SingleDiff = (BYTE) data[1]; + /****************************/ - /* Get the time base unitiy */ + /* Get the time base unitiy */ /****************************/ - - b_TimeBase = (BYTE) data[2]; - + + b_TimeBase = (BYTE) data[2]; + /*************************************/ - /* Get the convert time reload value */ + /* Get the convert time reload value */ /*************************************/ - - dw_ReloadValue = (DWORD) data[3]; - + + dw_ReloadValue = (DWORD) data[3]; + /**********************/ - /* Test the time base */ + /* Test the time base */ /**********************/ - - if ((devpriv->ps_BoardInfo->b_AvailableConvertUnit & (1 << b_TimeBase)) != 0) - { + + if ((devpriv->ps_BoardInfo-> + b_AvailableConvertUnit & (1 << b_TimeBase)) != + 0) { /*******************************/ - /* Test the convert time value */ + /* Test the convert time value */ /*******************************/ - - if ((dw_ReloadValue >= 0) && (dw_ReloadValue <= 65535)) - { - dw_TestReloadValue = dw_ReloadValue; - - if (b_TimeBase == 1) - { - dw_TestReloadValue = dw_TestReloadValue * 1000UL; - } - if (b_TimeBase == 2) - { - dw_TestReloadValue = dw_TestReloadValue * 1000000UL; - } - - /*******************************/ - /* Test the convert time value */ - /*******************************/ - - if (dw_TestReloadValue >= devpriv->ps_BoardInfo->ui_MinAcquisitiontimeNs) - { - if ((b_SingleDiff == APCI3XXX_SINGLE) || (b_SingleDiff == APCI3XXX_DIFF)) - { - if (((b_SingleDiff == APCI3XXX_SINGLE) && (devpriv->ps_BoardInfo->i_NbrAiChannel == 0)) || - ((b_SingleDiff == APCI3XXX_DIFF) && (devpriv->ps_BoardInfo->i_NbrAiChannelDiff == 0))) - { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } - else - { - /**********************************/ - /* Test if conversion not started */ - /**********************************/ - - if (i_APCI3XXX_TestConversionStarted (dev) == 0) - { - devpriv->ui_EocEosConversionTime = (UINT) dw_ReloadValue; - devpriv->b_EocEosConversionTimeBase = b_TimeBase; - devpriv->b_SingelDiff = b_SingleDiff; - devpriv->b_AiInitialisation = 1; - - - /*******************************/ - /* Set the convert timing unit */ - /*******************************/ - - writel((DWORD) b_TimeBase, (void *) (devpriv->dw_AiBase + 36)); - - /**************************/ - /* Set the convert timing */ - /*************************/ - - writel(dw_ReloadValue, (void *) (devpriv->dw_AiBase + 32)); - } - else - { - /**************************/ - /* Any conversion started */ - /**************************/ - - printk("Any conversion started\n"); - i_ReturnValue = -10; - } - } - } - else - { - /*******************************/ - /* Single/Diff selection error */ - /*******************************/ - - printk("Single/Diff selection error\n"); - i_ReturnValue = -1; - } - } - else - { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } - else - { - /************************/ - /* Time selection error */ - /************************/ - - printk("Convert time value selection error\n"); - i_ReturnValue = -3; - } - } - else - { + + if ((dw_ReloadValue >= 0) && (dw_ReloadValue <= 65535)) { + dw_TestReloadValue = dw_ReloadValue; + + if (b_TimeBase == 1) { + dw_TestReloadValue = + dw_TestReloadValue * 1000UL; + } + if (b_TimeBase == 2) { + dw_TestReloadValue = + dw_TestReloadValue * 1000000UL; + } + + /*******************************/ + /* Test the convert time value */ + /*******************************/ + + if (dw_TestReloadValue >= + devpriv->ps_BoardInfo-> + ui_MinAcquisitiontimeNs) { + if ((b_SingleDiff == APCI3XXX_SINGLE) + || (b_SingleDiff == + APCI3XXX_DIFF)) { + if (((b_SingleDiff == APCI3XXX_SINGLE) && (devpriv->ps_BoardInfo->i_NbrAiChannel == 0)) || ((b_SingleDiff == APCI3XXX_DIFF) && (devpriv->ps_BoardInfo->i_NbrAiChannelDiff == 0))) { + /*******************************/ + /* Single/Diff selection error */ + /*******************************/ + + printk("Single/Diff selection error\n"); + i_ReturnValue = -1; + } else { + /**********************************/ + /* Test if conversion not started */ + /**********************************/ + + if (i_APCI3XXX_TestConversionStarted(dev) == 0) { + devpriv-> + ui_EocEosConversionTime + = + (UINT) + dw_ReloadValue; + devpriv-> + b_EocEosConversionTimeBase + = + b_TimeBase; + devpriv-> + b_SingelDiff + = + b_SingleDiff; + devpriv-> + b_AiInitialisation + = 1; + + /*******************************/ + /* Set the convert timing unit */ + /*******************************/ + + writel((DWORD) + b_TimeBase, + (void *) + (devpriv-> + dw_AiBase + + + 36)); + + /**************************/ + /* Set the convert timing */ + /*************************/ + + writel(dw_ReloadValue, (void *)(devpriv->dw_AiBase + 32)); + } else { + /**************************/ + /* Any conversion started */ + /**************************/ + + printk("Any conversion started\n"); + i_ReturnValue = + -10; + } + } + } else { + /*******************************/ + /* Single/Diff selection error */ + /*******************************/ + + printk("Single/Diff selection error\n"); + i_ReturnValue = -1; + } + } else { + /************************/ + /* Time selection error */ + /************************/ + + printk("Convert time value selection error\n"); + i_ReturnValue = -3; + } + } else { + /************************/ + /* Time selection error */ + /************************/ + + printk("Convert time value selection error\n"); + i_ReturnValue = -3; + } + } else { /*****************************/ - /* Time base selection error */ + /* Time base selection error */ /*****************************/ - - printk("Convert time base unity selection error\n"); - i_ReturnValue = -2; - } - } - else - { + + printk("Convert time base unity selection error\n"); + i_ReturnValue = -2; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); - } - - - - - + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -310,45 +295,39 @@ int i_APCI3XXX_AnalogInputConfigOperatingMode (comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI3XXX_InsnConfigAnalogInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; -int i_APCI3XXX_InsnConfigAnalogInput(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { - switch ((BYTE) data[0]) - { - case APCI3XXX_CONFIGURATION: - i_ReturnValue = i_APCI3XXX_AnalogInputConfigOperatingMode (dev, s, insn, data) ; - break; - - default: - i_ReturnValue = -100; - printk("Config command error %d\n", data[0]); - break; - } - } - else - { + + if (insn->n >= 1) { + switch ((BYTE) data[0]) { + case APCI3XXX_CONFIGURATION: + i_ReturnValue = + i_APCI3XXX_AnalogInputConfigOperatingMode(dev, + s, insn, data); + break; + + default: + i_ReturnValue = -100; + printk("Config command error %d\n", data[0]); + break; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -376,214 +355,239 @@ int i_APCI3XXX_InsnConfigAnalogInput(comedi_device *dev, +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnReadAnalogInput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Configuration = (BYTE) CR_RANGE(insn->chanspec); - BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); - DWORD dw_Temp = 0; - DWORD dw_Configuration = 0; - DWORD dw_AcquisitionCpt = 0; - BYTE b_Interrupt = 0; +int i_APCI3XXX_InsnReadAnalogInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Configuration = (BYTE) CR_RANGE(insn->chanspec); + BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); + DWORD dw_Temp = 0; + DWORD dw_Configuration = 0; + DWORD dw_AcquisitionCpt = 0; + BYTE b_Interrupt = 0; /*************************************/ /* Test if operating mode configured */ /*************************************/ - if (devpriv->b_AiInitialisation) - { + if (devpriv->b_AiInitialisation) { /***************************/ - /* Test the channel number */ + /* Test the channel number */ /***************************/ - - if (((b_Channel < devpriv->ps_BoardInfo->i_NbrAiChannel) && (devpriv->b_SingelDiff == APCI3XXX_SINGLE)) || - ((b_Channel < devpriv->ps_BoardInfo->i_NbrAiChannelDiff) && (devpriv->b_SingelDiff == APCI3XXX_DIFF))) - { + + if (((b_Channel < devpriv->ps_BoardInfo->i_NbrAiChannel) + && (devpriv->b_SingelDiff == APCI3XXX_SINGLE)) + || ((b_Channel < devpriv->ps_BoardInfo-> + i_NbrAiChannelDiff) + && (devpriv->b_SingelDiff == APCI3XXX_DIFF))) { /**********************************/ - /* Test the channel configuration */ + /* Test the channel configuration */ /**********************************/ - - if (b_Configuration > 7) - { - /***************************/ - /* Channel not initialised */ - /***************************/ - - i_ReturnValue = -4; - printk ("Channel %d range %d selection error\n", b_Channel, b_Configuration); - } - } - else - { + + if (b_Configuration > 7) { + /***************************/ + /* Channel not initialised */ + /***************************/ + + i_ReturnValue = -4; + printk("Channel %d range %d selection error\n", + b_Channel, b_Configuration); + } + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - i_ReturnValue = -3; - printk ("Channel %d selection error\n", b_Channel); - } - + + i_ReturnValue = -3; + printk("Channel %d selection error\n", b_Channel); + } + + /**************************/ + /* Test if no error occur */ /**************************/ - /* Test if no error occur */ - /**************************/ - - if (i_ReturnValue >= 0) - { + + if (i_ReturnValue >= 0) { /************************/ - /* Test the buffer size */ + /* Test the buffer size */ /************************/ - - if ((b_Interrupt != 0) || ((b_Interrupt == 0) && (insn->n >= 1))) - { - /**********************************/ - /* Test if conversion not started */ - /**********************************/ - - if (i_APCI3XXX_TestConversionStarted (dev) == 0) - { - /******************/ - /* Clear the FIFO */ - /******************/ - - writel(0x10000UL, (void *) (devpriv->dw_AiBase + 12)); - - /*******************************/ - /* Get and save the delay mode */ - /*******************************/ - - dw_Temp = readl((void *) (devpriv->dw_AiBase + 4)); - dw_Temp = dw_Temp & 0xFFFFFEF0UL; - - /***********************************/ - /* Channel configuration selection */ - /***********************************/ - - writel(dw_Temp, (void *) (devpriv->dw_AiBase + 4)); - - /**************************/ - /* Make the configuration */ - /**************************/ - - dw_Configuration = (b_Configuration & 3) | - ((DWORD) (b_Configuration >> 2) << 6) | - ((DWORD) devpriv->b_SingelDiff << 7); - - /***************************/ - /* Write the configuration */ - /***************************/ - - writel(dw_Configuration, (void *) (devpriv->dw_AiBase + 0)); - - /*********************/ - /* Channel selection */ - /*********************/ - - writel(dw_Temp | 0x100UL, (void *) (devpriv->dw_AiBase + 4)); - writel((DWORD) b_Channel, (void *) (devpriv->dw_AiBase + 0)); - - /***********************/ - /* Restaure delay mode */ - /***********************/ - - writel(dw_Temp, (void *) (devpriv->dw_AiBase + 4)); - - /***********************************/ - /* Set the number of sequence to 1 */ - /***********************************/ - - writel(1, (void *) (devpriv->dw_AiBase + 48)); - - /***************************/ - /* Save the interrupt flag */ - /***************************/ - - devpriv->b_EocEosInterrupt = b_Interrupt; - - /*******************************/ - /* Save the number of channels */ - /*******************************/ - - devpriv->ui_AiNbrofChannels = 1; - - /******************************/ - /* Test if interrupt not used */ - /******************************/ - - if (b_Interrupt == 0) - { - for (dw_AcquisitionCpt = 0; dw_AcquisitionCpt < insn->n; dw_AcquisitionCpt ++) - { - /************************/ - /* Start the conversion */ - /************************/ - - writel(0x80000UL, (void *) (devpriv->dw_AiBase + 8)); - - /****************/ - /* Wait the EOS */ - /****************/ - - do - { - dw_Temp = readl((void *) (devpriv->dw_AiBase + 20)); - dw_Temp = dw_Temp & 1; - } - while (dw_Temp != 1); - - /*************************/ - /* Read the analog value */ - /*************************/ - - data[dw_AcquisitionCpt] = (lsampl_t) readl((void *) (devpriv->dw_AiBase + 28)); - } - } - else - { - /************************/ - /* Start the conversion */ - /************************/ - - writel(0x180000UL, (void *) (devpriv->dw_AiBase + 8)); - } - } - else - { - /**************************/ - /* Any conversion started */ - /**************************/ - - printk("Any conversion started\n"); - i_ReturnValue = -10; - } - } - else - { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } - } - else - { + + if ((b_Interrupt != 0) || ((b_Interrupt == 0) + && (insn->n >= 1))) { + /**********************************/ + /* Test if conversion not started */ + /**********************************/ + + if (i_APCI3XXX_TestConversionStarted(dev) == 0) { + /******************/ + /* Clear the FIFO */ + /******************/ + + writel(0x10000UL, + (void *)(devpriv->dw_AiBase + + 12)); + + /*******************************/ + /* Get and save the delay mode */ + /*******************************/ + + dw_Temp = + readl((void *)(devpriv-> + dw_AiBase + 4)); + dw_Temp = dw_Temp & 0xFFFFFEF0UL; + + /***********************************/ + /* Channel configuration selection */ + /***********************************/ + + writel(dw_Temp, + (void *)(devpriv->dw_AiBase + + 4)); + + /**************************/ + /* Make the configuration */ + /**************************/ + + dw_Configuration = + (b_Configuration & 3) | + ((DWORD) (b_Configuration >> 2) + << 6) | ((DWORD) devpriv-> + b_SingelDiff << 7); + + /***************************/ + /* Write the configuration */ + /***************************/ + + writel(dw_Configuration, + (void *)(devpriv->dw_AiBase + + 0)); + + /*********************/ + /* Channel selection */ + /*********************/ + + writel(dw_Temp | 0x100UL, + (void *)(devpriv->dw_AiBase + + 4)); + writel((DWORD) b_Channel, + (void *)(devpriv->dw_AiBase + + 0)); + + /***********************/ + /* Restaure delay mode */ + /***********************/ + + writel(dw_Temp, + (void *)(devpriv->dw_AiBase + + 4)); + + /***********************************/ + /* Set the number of sequence to 1 */ + /***********************************/ + + writel(1, + (void *)(devpriv->dw_AiBase + + 48)); + + /***************************/ + /* Save the interrupt flag */ + /***************************/ + + devpriv->b_EocEosInterrupt = + b_Interrupt; + + /*******************************/ + /* Save the number of channels */ + /*******************************/ + + devpriv->ui_AiNbrofChannels = 1; + + /******************************/ + /* Test if interrupt not used */ + /******************************/ + + if (b_Interrupt == 0) { + for (dw_AcquisitionCpt = 0; + dw_AcquisitionCpt < + insn->n; + dw_AcquisitionCpt++) { + /************************/ + /* Start the conversion */ + /************************/ + + writel(0x80000UL, + (void *) + (devpriv-> + dw_AiBase + + 8)); + + /****************/ + /* Wait the EOS */ + /****************/ + + do { + dw_Temp = + readl( + (void *) + (devpriv-> + dw_AiBase + + + 20)); + dw_Temp = + dw_Temp + & 1; + } + while (dw_Temp != 1); + + /*************************/ + /* Read the analog value */ + /*************************/ + + data[dw_AcquisitionCpt] + = + (lsampl_t) + readl((void + *) + (devpriv-> + dw_AiBase + + 28)); + } + } else { + /************************/ + /* Start the conversion */ + /************************/ + + writel(0x180000UL, + (void *)(devpriv-> + dw_AiBase + 8)); + } + } else { + /**************************/ + /* Any conversion started */ + /**************************/ + + printk("Any conversion started\n"); + i_ReturnValue = -10; + } + } else { + /*******************/ + /* Data size error */ + /*******************/ + + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + } + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - printk("Operating mode not configured\n"); - i_ReturnValue = -1; - } + + printk("Operating mode not configured\n"); + i_ReturnValue = -1; + } printk("%x\n", i_ReturnValue); return (i_ReturnValue); - } - - +} /* +----------------------------------------------------------------------------+ @@ -601,57 +605,55 @@ int i_APCI3XXX_InsnReadAnalogInput (comedi_device *dev, +----------------------------------------------------------------------------+ */ +void v_APCI3XXX_Interrupt(int irq, void *d) +{ + comedi_device *dev = d; + BYTE b_CopyCpt = 0; + DWORD dw_Status = 0; -void v_APCI3XXX_Interrupt(int irq, void *d) - { - comedi_device *dev = d; - BYTE b_CopyCpt = 0; - DWORD dw_Status = 0; - - /***************************/ /* Test if interrupt occur */ /***************************/ - - if (((dw_Status = readl ((void *) (devpriv->dw_AiBase + 16))) & 0x2UL) == 0x2UL) - { + + if (((dw_Status = readl((void *)(devpriv->dw_AiBase + 16))) & 0x2UL) == + 0x2UL) { /***********************/ - /* Reset the interrupt */ + /* Reset the interrupt */ /***********************/ - - writel(dw_Status, (void *) (devpriv->dw_AiBase + 16)); - + + writel(dw_Status, (void *)(devpriv->dw_AiBase + 16)); + /*****************************/ - /* Test if interrupt enabled */ + /* Test if interrupt enabled */ /*****************************/ - - if (devpriv->b_EocEosInterrupt == 1) - { + + if (devpriv->b_EocEosInterrupt == 1) { /********************************/ - /* Read all analog inputs value */ + /* Read all analog inputs value */ /********************************/ - - for (b_CopyCpt = 0; b_CopyCpt < devpriv->ui_AiNbrofChannels; b_CopyCpt ++) - { - devpriv->ui_AiReadData[b_CopyCpt] = (UINT) readl((void *) (devpriv->dw_AiBase + 28)); - } - + + for (b_CopyCpt = 0; + b_CopyCpt < devpriv->ui_AiNbrofChannels; + b_CopyCpt++) { + devpriv->ui_AiReadData[b_CopyCpt] = + (UINT) readl((void *)(devpriv-> + dw_AiBase + 28)); + } + /**************************/ - /* Set the interrupt flag */ + /* Set the interrupt flag */ /**************************/ - - devpriv->b_EocEosInterrupt = 2; - + + devpriv->b_EocEosInterrupt = 2; + /**********************************************/ - /* Send a signal to from kernel to user space */ + /* Send a signal to from kernel to user space */ /**********************************************/ - - send_sig(SIGIO,devpriv->tsk_Current,0); - } - } - } - + send_sig(SIGIO, devpriv->tsk_Current, 0); + } + } +} /* +----------------------------------------------------------------------------+ @@ -659,7 +661,6 @@ void v_APCI3XXX_Interrupt(int irq, void *d) +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI3XXX_InsnWriteAnalogOutput | @@ -684,91 +685,81 @@ void v_APCI3XXX_Interrupt(int irq, void *d) +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnWriteAnalogOutput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - BYTE b_Range = (BYTE) CR_RANGE(insn->chanspec); - BYTE b_Channel = (BYTE) CR_CHAN (insn->chanspec); - DWORD dw_Status = 0; - INT i_ReturnValue = insn->n; - - +int i_APCI3XXX_InsnWriteAnalogOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + BYTE b_Range = (BYTE) CR_RANGE(insn->chanspec); + BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); + DWORD dw_Status = 0; + INT i_ReturnValue = insn->n; + /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /***************************/ - /* Test the channel number */ + /* Test the channel number */ /***************************/ - - if (b_Channel < devpriv->ps_BoardInfo->i_NbrAoChannel) - { + + if (b_Channel < devpriv->ps_BoardInfo->i_NbrAoChannel) { /**********************************/ - /* Test the channel configuration */ + /* Test the channel configuration */ /**********************************/ - - if (b_Range < 2) - { - /***************************/ - /* Set the range selection */ - /***************************/ - - writel(b_Range, (void *) (devpriv->dw_AiBase + 96)); - - /**************************************************/ - /* Write the analog value to the selected channel */ - /**************************************************/ - - writel((data[0] << 8) | b_Channel, (void *) (devpriv->dw_AiBase + 100)); - - /****************************/ - /* Wait the end of transfer */ - /****************************/ - - do - { - dw_Status = readl ((void *) (devpriv->dw_AiBase + 96)); - } - while ((dw_Status & 0x100) != 0x100); - } - else - { - /***************************/ - /* Channel not initialised */ - /***************************/ - - i_ReturnValue = -4; - printk ("Channel %d range %d selection error\n", b_Channel, b_Range); - } - } - else - { + + if (b_Range < 2) { + /***************************/ + /* Set the range selection */ + /***************************/ + + writel(b_Range, + (void *)(devpriv->dw_AiBase + 96)); + + /**************************************************/ + /* Write the analog value to the selected channel */ + /**************************************************/ + + writel((data[0] << 8) | b_Channel, + (void *)(devpriv->dw_AiBase + 100)); + + /****************************/ + /* Wait the end of transfer */ + /****************************/ + + do { + dw_Status = + readl((void *)(devpriv-> + dw_AiBase + 96)); + } + while ((dw_Status & 0x100) != 0x100); + } else { + /***************************/ + /* Channel not initialised */ + /***************************/ + + i_ReturnValue = -4; + printk("Channel %d range %d selection error\n", + b_Channel, b_Range); + } + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - i_ReturnValue = -3; - printk ("Channel %d selection error\n", b_Channel); - } - } - else - { + + i_ReturnValue = -3; + printk("Channel %d selection error\n", b_Channel); + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); - } + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -801,120 +792,105 @@ int i_APCI3XXX_InsnWriteAnalogOutput (comedi_device *dev, +----------------------------------------------------------------------------+ */ - -int i_APCI3XXX_InsnConfigInitTTLIO(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Command = 0; +int i_APCI3XXX_InsnConfigInitTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Command = 0; /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /*******************/ - /* Get the command */ - /* *****************/ - - b_Command = (BYTE) data[0]; - + /* Get the command */ + /* **************** */ + + b_Command = (BYTE) data[0]; + /********************/ - /* Test the command */ + /* Test the command */ /********************/ - - if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) - { + + if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) { /***************************************/ - /* Test the initialisation buffer size */ + /* Test the initialisation buffer size */ /***************************************/ - - if ((b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) && (insn->n != 2)) - { - /*******************/ - /* Data size error */ - /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } - else - { + + if ((b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) + && (insn->n != 2)) { + /*******************/ + /* Data size error */ + /*******************/ + + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("Command selection error\n"); - i_ReturnValue = -100; - } - } - else - { + + printk("Command selection error\n"); + i_ReturnValue = -100; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - + + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + /*********************************************************************************/ /* Test if no error occur and APCI3XXX_TTL_INIT_DIRECTION_PORT2 command selected */ /*********************************************************************************/ - - if ((i_ReturnValue >= 0) && (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2)) - { + + if ((i_ReturnValue >= 0) + && (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2)) { /**********************/ - /* Test the direction */ + /* Test the direction */ /**********************/ - - if ((data[1] == 0) || (data[1] == 0xFF)) - { + + if ((data[1] == 0) || (data[1] == 0xFF)) { /**************************/ - /* Save the configuration */ + /* Save the configuration */ /**************************/ - - devpriv->ul_TTLPortConfiguration[0] = devpriv->ul_TTLPortConfiguration[0] | data[1]; - } - else - { + + devpriv->ul_TTLPortConfiguration[0] = + devpriv->ul_TTLPortConfiguration[0] | data[1]; + } else { /************************/ - /* Port direction error */ + /* Port direction error */ /************************/ - - printk("Port 2 direction selection error\n"); - i_ReturnValue = - 1; - } - } - + + printk("Port 2 direction selection error\n"); + i_ReturnValue = -1; + } + } + /**************************/ /* Test if no error occur */ /**************************/ - - if (i_ReturnValue >= 0) - { + + if (i_ReturnValue >= 0) { /***********************************/ - /* Test if TTL port initilaisation */ + /* Test if TTL port initilaisation */ /***********************************/ - - if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) - { + + if (b_Command == APCI3XXX_TTL_INIT_DIRECTION_PORT2) { /*************************/ - /* Set the configuration */ + /* Set the configuration */ /*************************/ - - outl(data[1],devpriv->iobase + 224); - } - } - - return (i_ReturnValue); + + outl(data[1], devpriv->iobase + 224); + } } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -922,7 +898,6 @@ int i_APCI3XXX_InsnConfigInitTTLIO(comedi_device *dev, +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function Name : INT i_APCI3XXX_InsnBitsTTLIO | @@ -945,144 +920,140 @@ int i_APCI3XXX_InsnConfigInitTTLIO(comedi_device *dev, +----------------------------------------------------------------------------+ */ - -int i_APCI3XXX_InsnBitsTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_ChannelCpt = 0; - DWORD dw_ChannelMask = 0; - DWORD dw_BitMask = 0; - DWORD dw_Status = 0; +int i_APCI3XXX_InsnBitsTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_ChannelCpt = 0; + DWORD dw_ChannelMask = 0; + DWORD dw_BitMask = 0; + DWORD dw_Status = 0; /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 2) - { + + if (insn->n >= 2) { /*******************************/ - /* Get the channe and bit mask */ + /* Get the channe and bit mask */ /*******************************/ - - dw_ChannelMask = data [0]; - dw_BitMask = data [1]; - + + dw_ChannelMask = data[0]; + dw_BitMask = data[1]; + /*************************/ - /* Test the channel mask */ + /* Test the channel mask */ /*************************/ - - if (((dw_ChannelMask & 0XFF00FF00) == 0) && - (((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0xFF) || - (((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0) && ((dw_ChannelMask & 0XFF0000) == 0)))) - { + + if (((dw_ChannelMask & 0XFF00FF00) == 0) && + (((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0xFF) + || (((devpriv->ul_TTLPortConfiguration[0] & + 0xFF) == 0) + && ((dw_ChannelMask & 0XFF0000) == + 0)))) { /*********************************/ - /* Test if set/reset any channel */ + /* Test if set/reset any channel */ /*********************************/ - - if (dw_ChannelMask) - { - /****************************************/ - /* Test if set/rest any port 0 channels */ - /****************************************/ - - if (dw_ChannelMask & 0xFF) - { - /*******************************************/ - /* Read port 0 (first digital output port) */ - /*******************************************/ - - dw_Status = inl(devpriv->iobase + 80); - - for (b_ChannelCpt = 0; b_ChannelCpt < 8; b_ChannelCpt ++) - { - if ((dw_ChannelMask >> b_ChannelCpt) & 1) - { - dw_Status = (dw_Status & (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); - } - } - - outl (dw_Status, devpriv->iobase + 80); - } - - /****************************************/ - /* Test if set/rest any port 2 channels */ - /****************************************/ - - if (dw_ChannelMask & 0xFF0000) - { - dw_BitMask = dw_BitMask >> 16; - dw_ChannelMask = dw_ChannelMask >> 16; - - /********************************************/ - /* Read port 2 (second digital output port) */ - /********************************************/ - - dw_Status = inl(devpriv->iobase + 112); - - for (b_ChannelCpt = 0; b_ChannelCpt < 8; b_ChannelCpt ++) - { - if ((dw_ChannelMask >> b_ChannelCpt) & 1) - { - dw_Status = (dw_Status & (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); - } - } - - outl (dw_Status, devpriv->iobase + 112); - } - } - + + if (dw_ChannelMask) { + /****************************************/ + /* Test if set/rest any port 0 channels */ + /****************************************/ + + if (dw_ChannelMask & 0xFF) { + /*******************************************/ + /* Read port 0 (first digital output port) */ + /*******************************************/ + + dw_Status = inl(devpriv->iobase + 80); + + for (b_ChannelCpt = 0; b_ChannelCpt < 8; + b_ChannelCpt++) { + if ((dw_ChannelMask >> + b_ChannelCpt) & + 1) { + dw_Status = + (dw_Status & + (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); + } + } + + outl(dw_Status, devpriv->iobase + 80); + } + + /****************************************/ + /* Test if set/rest any port 2 channels */ + /****************************************/ + + if (dw_ChannelMask & 0xFF0000) { + dw_BitMask = dw_BitMask >> 16; + dw_ChannelMask = dw_ChannelMask >> 16; + + /********************************************/ + /* Read port 2 (second digital output port) */ + /********************************************/ + + dw_Status = inl(devpriv->iobase + 112); + + for (b_ChannelCpt = 0; b_ChannelCpt < 8; + b_ChannelCpt++) { + if ((dw_ChannelMask >> + b_ChannelCpt) & + 1) { + dw_Status = + (dw_Status & + (0xFF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); + } + } + + outl(dw_Status, devpriv->iobase + 112); + } + } + /*******************************************/ - /* Read port 0 (first digital output port) */ + /* Read port 0 (first digital output port) */ /*******************************************/ - - data [1] = inl(devpriv->iobase + 80); - + + data[1] = inl(devpriv->iobase + 80); + /******************************************/ - /* Read port 1 (first digital input port) */ + /* Read port 1 (first digital input port) */ /******************************************/ - - data [1] = data [1] | (inl(devpriv->iobase + 64) << 8); - + + data[1] = data[1] | (inl(devpriv->iobase + 64) << 8); + /************************/ - /* Test if port 2 input */ + /* Test if port 2 input */ /************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0) - { - data [1] = data [1] | (inl(devpriv->iobase + 96) << 16); - } - else - { - data [1] = data [1] | (inl(devpriv->iobase + 112) << 16); - } - } - else - { + + if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0) { + data[1] = + data[1] | (inl(devpriv->iobase + + 96) << 16); + } else { + data[1] = + data[1] | (inl(devpriv->iobase + + 112) << 16); + } + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("Channel mask error\n"); - i_ReturnValue = -4; - } - } - else - { + + printk("Channel mask error\n"); + i_ReturnValue = -4; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1104,97 +1075,92 @@ int i_APCI3XXX_InsnBitsTTLIO (comedi_device *dev, +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnReadTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); - INT i_ReturnValue = insn->n; - lsampl_t * pls_ReadData = data; +int i_APCI3XXX_InsnReadTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); + INT i_ReturnValue = insn->n; + lsampl_t *pls_ReadData = data; /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /***********************/ - /* Test if read port 0 */ + /* Test if read port 0 */ /***********************/ - - if (b_Channel < 8) - { + + if (b_Channel < 8) { /*******************************************/ - /* Read port 0 (first digital output port) */ + /* Read port 0 (first digital output port) */ /*******************************************/ - - pls_ReadData [0] = inl(devpriv->iobase + 80); - pls_ReadData [0] = (pls_ReadData [0] >> b_Channel) & 1; - } - else - { + + pls_ReadData[0] = inl(devpriv->iobase + 80); + pls_ReadData[0] = (pls_ReadData[0] >> b_Channel) & 1; + } else { /***********************/ - /* Test if read port 1 */ + /* Test if read port 1 */ /***********************/ - - if ((b_Channel > 7) && (b_Channel < 16)) - { - /******************************************/ - /* Read port 1 (first digital input port) */ - /******************************************/ - - pls_ReadData [0] = inl(devpriv->iobase + 64); - pls_ReadData [0] = (pls_ReadData [0] >> (b_Channel - 8)) & 1; - } - else - { - /***********************/ - /* Test if read port 2 */ - /***********************/ - - if ((b_Channel > 15) && (b_Channel < 24)) - { - /************************/ - /* Test if port 2 input */ - /************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0) - { - pls_ReadData [0] = inl(devpriv->iobase + 96); - pls_ReadData [0] = (pls_ReadData [0] >> (b_Channel - 16)) & 1; - } - else - { - pls_ReadData [0] = inl(devpriv->iobase + 112); - pls_ReadData [0] = (pls_ReadData [0] >> (b_Channel - 16)) & 1; - } - } - else - { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk ("Channel %d selection error\n", b_Channel); - } - } - } - } - else - { + + if ((b_Channel > 7) && (b_Channel < 16)) { + /******************************************/ + /* Read port 1 (first digital input port) */ + /******************************************/ + + pls_ReadData[0] = inl(devpriv->iobase + 64); + pls_ReadData[0] = + (pls_ReadData[0] >> (b_Channel - + 8)) & 1; + } else { + /***********************/ + /* Test if read port 2 */ + /***********************/ + + if ((b_Channel > 15) && (b_Channel < 24)) { + /************************/ + /* Test if port 2 input */ + /************************/ + + if ((devpriv->ul_TTLPortConfiguration[0] + & 0xFF) == 0) { + pls_ReadData[0] = + inl(devpriv->iobase + + 96); + pls_ReadData[0] = + (pls_ReadData[0] >> + (b_Channel - 16)) & 1; + } else { + pls_ReadData[0] = + inl(devpriv->iobase + + 112); + pls_ReadData[0] = + (pls_ReadData[0] >> + (b_Channel - 16)) & 1; + } + } else { + /***************************/ + /* Channel selection error */ + /***************************/ + + i_ReturnValue = -3; + printk("Channel %d selection error\n", + b_Channel); + } + } + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - return (i_ReturnValue); + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | TTL OUTPUT FUNCTIONS | @@ -1222,102 +1188,97 @@ int i_APCI3XXX_InsnReadTTLIO (comedi_device *dev, +----------------------------------------------------------------------------+ */ - -int i_APCI3XXX_InsnWriteTTLIO (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); - BYTE b_State = 0; - DWORD dw_Status = 0; +int i_APCI3XXX_InsnWriteTTLIO(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); + BYTE b_State = 0; + DWORD dw_Status = 0; /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { - b_State = (BYTE) data [0]; - + + if (insn->n >= 1) { + b_State = (BYTE) data[0]; + /***********************/ - /* Test if read port 0 */ + /* Test if read port 0 */ /***********************/ - - if (b_Channel < 8) - { + + if (b_Channel < 8) { /*****************************************************************************/ - /* Read port 0 (first digital output port) and set/reset the selcted channel */ + /* Read port 0 (first digital output port) and set/reset the selcted channel */ /*****************************************************************************/ - - dw_Status = inl(devpriv->iobase + 80); - dw_Status = (dw_Status & (0xFF - (1 << b_Channel))) | ((b_State & 1) << b_Channel); - outl(dw_Status, devpriv->iobase + 80); - } - else - { + + dw_Status = inl(devpriv->iobase + 80); + dw_Status = + (dw_Status & (0xFF - + (1 << b_Channel))) | ((b_State & 1) << + b_Channel); + outl(dw_Status, devpriv->iobase + 80); + } else { /***********************/ - /* Test if read port 2 */ + /* Test if read port 2 */ /***********************/ - - if ((b_Channel > 15) && (b_Channel < 24)) - { - /*************************/ - /* Test if port 2 output */ - /*************************/ - - if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) == 0xFF) - { - /*****************************************************************************/ - /* Read port 2 (first digital output port) and set/reset the selcted channel */ - /*****************************************************************************/ - - dw_Status = inl(devpriv->iobase + 112); - dw_Status = (dw_Status & (0xFF - (1 << (b_Channel - 16)))) | ((b_State & 1) << (b_Channel - 16)); - outl(dw_Status, devpriv->iobase + 112); - } - else - { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk ("Channel %d selection error\n", b_Channel); - } - } - else - { - /***************************/ - /* Channel selection error */ - /***************************/ - - i_ReturnValue = -3; - printk ("Channel %d selection error\n", b_Channel); - } - } - } - else - { + + if ((b_Channel > 15) && (b_Channel < 24)) { + /*************************/ + /* Test if port 2 output */ + /*************************/ + + if ((devpriv->ul_TTLPortConfiguration[0] & 0xFF) + == 0xFF) { + /*****************************************************************************/ + /* Read port 2 (first digital output port) and set/reset the selcted channel */ + /*****************************************************************************/ + + dw_Status = inl(devpriv->iobase + 112); + dw_Status = + (dw_Status & (0xFF - + (1 << (b_Channel - + 16)))) | + ((b_State & 1) << (b_Channel - + 16)); + outl(dw_Status, devpriv->iobase + 112); + } else { + /***************************/ + /* Channel selection error */ + /***************************/ + + i_ReturnValue = -3; + printk("Channel %d selection error\n", + b_Channel); + } + } else { + /***************************/ + /* Channel selection error */ + /***************************/ + + i_ReturnValue = -3; + printk("Channel %d selection error\n", + b_Channel); + } + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - return (i_ReturnValue); + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | DIGITAL INPUT SUBDEVICE | +----------------------------------------------------------------------------+ */ - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3XXX_InsnReadDigitalInput | @@ -1338,53 +1299,45 @@ int i_APCI3XXX_InsnWriteTTLIO (comedi_device *dev, +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnReadDigitalInput(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); - DWORD dw_Temp = 0; - +int i_APCI3XXX_InsnReadDigitalInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); + DWORD dw_Temp = 0; + /***************************/ /* Test the channel number */ /***************************/ - - if(b_Channel <= devpriv->ps_BoardInfo->i_NbrDiChannel) - { + + if (b_Channel <= devpriv->ps_BoardInfo->i_NbrDiChannel) { /************************/ - /* Test the buffer size */ + /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { - dw_Temp = inl (devpriv->iobase + 32); - *data = (dw_Temp >> b_Channel) & 1; - } - else - { + + if (insn->n >= 1) { + dw_Temp = inl(devpriv->iobase + 32); + *data = (dw_Temp >> b_Channel) & 1; + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - } - else - { + + printk("Buffer size error\n"); + i_ReturnValue = -101; + } + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - printk("Channel selection error\n"); - i_ReturnValue = -3; - } - - return (i_ReturnValue); + + printk("Channel selection error\n"); + i_ReturnValue = -3; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3XXX_InsnBitsDigitalInput | @@ -1404,36 +1357,31 @@ int i_APCI3XXX_InsnReadDigitalInput(comedi_device *dev, | -101 : Data size error | +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnBitsDigitalInput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - DWORD dw_Temp = 0; - +int i_APCI3XXX_InsnBitsDigitalInput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + DWORD dw_Temp = 0; + /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { - dw_Temp= inl (devpriv->iobase + 32); - *data= dw_Temp & 0xf; - } - else - { + + if (insn->n >= 1) { + dw_Temp = inl(devpriv->iobase + 32); + *data = dw_Temp & 0xf; + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | DIGITAL OUTPUT SUBDEVICE | @@ -1441,8 +1389,6 @@ int i_APCI3XXX_InsnBitsDigitalInput (comedi_device *dev, */ - - /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3XXX_InsnBitsDigitalOutput | @@ -1464,89 +1410,81 @@ int i_APCI3XXX_InsnBitsDigitalInput (comedi_device *dev, | -101 : Data size error | +----------------------------------------------------------------------------+ */ -int i_APCI3XXX_InsnBitsDigitalOutput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_ChannelCpt = 0; - DWORD dw_ChannelMask = 0; - DWORD dw_BitMask = 0; - DWORD dw_Status = 0; +int i_APCI3XXX_InsnBitsDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_ChannelCpt = 0; + DWORD dw_ChannelMask = 0; + DWORD dw_BitMask = 0; + DWORD dw_Status = 0; /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 2) - { + + if (insn->n >= 2) { /*******************************/ - /* Get the channe and bit mask */ + /* Get the channe and bit mask */ /*******************************/ - - dw_ChannelMask = data [0]; - dw_BitMask = data [1]; - + + dw_ChannelMask = data[0]; + dw_BitMask = data[1]; + /*************************/ - /* Test the channel mask */ + /* Test the channel mask */ /*************************/ - - if ((dw_ChannelMask & 0XFFFFFFF0) == 0) - { + + if ((dw_ChannelMask & 0XFFFFFFF0) == 0) { /*********************************/ - /* Test if set/reset any channel */ + /* Test if set/reset any channel */ /*********************************/ - - if (dw_ChannelMask & 0xF) - { - /********************************/ - /* Read the digital output port */ - /********************************/ - - dw_Status = inl(devpriv->iobase + 48); - - for (b_ChannelCpt = 0; b_ChannelCpt < 4; b_ChannelCpt ++) - { - if ((dw_ChannelMask >> b_ChannelCpt) & 1) - { - dw_Status = (dw_Status & (0xF - (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); - } - } - - outl (dw_Status, devpriv->iobase + 48); - } - + + if (dw_ChannelMask & 0xF) { + /********************************/ + /* Read the digital output port */ + /********************************/ + + dw_Status = inl(devpriv->iobase + 48); + + for (b_ChannelCpt = 0; b_ChannelCpt < 4; + b_ChannelCpt++) { + if ((dw_ChannelMask >> b_ChannelCpt) & + 1) { + dw_Status = + (dw_Status & (0xF - + (1 << b_ChannelCpt))) | (dw_BitMask & (1 << b_ChannelCpt)); + } + } + + outl(dw_Status, devpriv->iobase + 48); + } + /********************************/ - /* Read the digital output port */ + /* Read the digital output port */ /********************************/ - - data [1] = inl(devpriv->iobase + 48); - } - else - { + + data[1] = inl(devpriv->iobase + 48); + } else { /************************/ - /* Config command error */ + /* Config command error */ /************************/ - - printk("Channel mask error\n"); - i_ReturnValue = -4; - } - } - else - { + + printk("Channel mask error\n"); + i_ReturnValue = -4; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3XXX_InsnWriteDigitalOutput | @@ -1568,67 +1506,61 @@ int i_APCI3XXX_InsnBitsDigitalOutput (comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI3XXX_InsnWriteDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Channel = CR_CHAN(insn->chanspec); + BYTE b_State = 0; + DWORD dw_Status = 0; -int i_APCI3XXX_InsnWriteDigitalOutput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Channel = CR_CHAN(insn->chanspec); - BYTE b_State = 0; - DWORD dw_Status = 0; - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /***************************/ - /* Test the channel number */ + /* Test the channel number */ /***************************/ - - if(b_Channel < devpriv->ps_BoardInfo->i_NbrDoChannel) - { + + if (b_Channel < devpriv->ps_BoardInfo->i_NbrDoChannel) { /*******************/ - /* Get the command */ + /* Get the command */ /*******************/ - - b_State = (BYTE) data[0]; - + + b_State = (BYTE) data[0]; + /********************************/ - /* Read the digital output port */ + /* Read the digital output port */ /********************************/ - - dw_Status = inl(devpriv->iobase + 48); - - dw_Status = (dw_Status & (0xF - (1 << b_Channel))) | ((b_State & 1) << b_Channel); - outl (dw_Status, devpriv->iobase + 48); - } - else - { + + dw_Status = inl(devpriv->iobase + 48); + + dw_Status = + (dw_Status & (0xF - + (1 << b_Channel))) | ((b_State & 1) << + b_Channel); + outl(dw_Status, devpriv->iobase + 48); + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - printk("Channel selection error\n"); - i_ReturnValue = -3; - } - } - else - { + + printk("Channel selection error\n"); + i_ReturnValue = -3; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} + /* +----------------------------------------------------------------------------+ | Function name :int i_APCI3XXX_InsnReadDigitalOutput | @@ -1649,60 +1581,50 @@ int i_APCI3XXX_InsnWriteDigitalOutput (comedi_device *dev, +----------------------------------------------------------------------------+ */ +int i_APCI3XXX_InsnReadDigitalOutput(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + INT i_ReturnValue = insn->n; + BYTE b_Channel = CR_CHAN(insn->chanspec); + DWORD dw_Status = 0; -int i_APCI3XXX_InsnReadDigitalOutput (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) - { - INT i_ReturnValue = insn->n; - BYTE b_Channel = CR_CHAN(insn->chanspec); - DWORD dw_Status = 0; - /************************/ /* Test the buffer size */ /************************/ - - if (insn->n >= 1) - { + + if (insn->n >= 1) { /***************************/ - /* Test the channel number */ + /* Test the channel number */ /***************************/ - - if(b_Channel < devpriv->ps_BoardInfo->i_NbrDoChannel) - { + + if (b_Channel < devpriv->ps_BoardInfo->i_NbrDoChannel) { /********************************/ - /* Read the digital output port */ + /* Read the digital output port */ /********************************/ - - dw_Status = inl(devpriv->iobase + 48); - - dw_Status = (dw_Status >> b_Channel) & 1; - *data = dw_Status; - } - else - { + + dw_Status = inl(devpriv->iobase + 48); + + dw_Status = (dw_Status >> b_Channel) & 1; + *data = dw_Status; + } else { /***************************/ - /* Channel selection error */ + /* Channel selection error */ /***************************/ - - printk("Channel selection error\n"); - i_ReturnValue = -3; - } - } - else - { + + printk("Channel selection error\n"); + i_ReturnValue = -3; + } + } else { /*******************/ - /* Data size error */ + /* Data size error */ /*******************/ - - printk("Buffer size error\n"); - i_ReturnValue = -101; - } - - return (i_ReturnValue); + + printk("Buffer size error\n"); + i_ReturnValue = -101; } + return (i_ReturnValue); +} /* +----------------------------------------------------------------------------+ @@ -1716,55 +1638,55 @@ int i_APCI3XXX_InsnReadDigitalOutput (comedi_device *dev, | Return Value : - | +----------------------------------------------------------------------------+ */ - -int i_APCI3XXX_Reset(comedi_device *dev) - { + +int i_APCI3XXX_Reset(comedi_device * dev) +{ unsigned char b_Cpt = 0; - + /*************************/ /* Disable the interrupt */ /*************************/ - + disable_irq(dev->irq); - + /****************************/ /* Reset the interrupt flag */ /****************************/ - + devpriv->b_EocEosInterrupt = 0; - + /***************************/ /* Clear the start command */ /***************************/ - - writel (0, (void *) (devpriv->dw_AiBase + 8)); - + + writel(0, (void *)(devpriv->dw_AiBase + 8)); + /*****************************/ /* Reset the interrupt flags */ /*****************************/ - - writel (readl ((void *) (devpriv->dw_AiBase + 16)), (void *) (devpriv->dw_AiBase + 16)); - + + writel(readl((void *)(devpriv->dw_AiBase + 16)), + (void *)(devpriv->dw_AiBase + 16)); + /*****************/ /* clear the EOS */ /*****************/ - - readl ((void *) (devpriv->dw_AiBase + 20)); - + + readl((void *)(devpriv->dw_AiBase + 20)); + /******************/ /* Clear the FIFO */ /******************/ - - for (b_Cpt = 0; b_Cpt < 16; b_Cpt ++) - { - readl ((void *) (devpriv->dw_AiBase + 28)); - } - + + for (b_Cpt = 0; b_Cpt < 16; b_Cpt++) { + readl((void *)(devpriv->dw_AiBase + 28)); + } + /************************/ /* Enable the interrupt */ /************************/ - + enable_irq(dev->irq); - + return 0; - } +} diff --git a/comedi/drivers/addi-data/hwdrv_apci3xxx.h b/comedi/drivers/addi-data/hwdrv_apci3xxx.h index 58d57340..0da6dc20 100755 --- a/comedi/drivers/addi-data/hwdrv_apci3xxx.h +++ b/comedi/drivers/addi-data/hwdrv_apci3xxx.h @@ -22,49 +22,48 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc @endverbatim */ - - #ifndef COMEDI_SUBD_TTLIO - #define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ +#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */ #endif #ifndef ADDIDATA_ENABLE - #define ADDIDATA_ENABLE 1 - #define ADDIDATA_DISABLE 0 +#define ADDIDATA_ENABLE 1 +#define ADDIDATA_DISABLE 0 #endif #define APCI3XXX_SINGLE 0 #define APCI3XXX_DIFF 1 #define APCI3XXX_CONFIGURATION 0 - #define APCI3XXX_TTL_INIT_DIRECTION_PORT2 0 #ifdef __KERNEL__ - -comedi_lrange range_apci3XXX_ai={ 8, {BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1)}}; - -comedi_lrange range_apci3XXX_ttl= {12, {BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1), - BIP_RANGE(1)}}; - -comedi_lrange range_apci3XXX_ao= { 2, {BIP_RANGE(10), - UNI_RANGE(10)}}; +comedi_lrange range_apci3XXX_ai = { 8, {BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1)} +}; + +comedi_lrange range_apci3XXX_ttl = { 12, {BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1), + BIP_RANGE(1)} +}; + +comedi_lrange range_apci3XXX_ao = { 2, {BIP_RANGE(10), + UNI_RANGE(10)} +}; #endif diff --git a/comedi/drivers/addi_apci_035.c b/comedi/drivers/addi_apci_035.c index d4ae7699..bac01820 100644 --- a/comedi/drivers/addi_apci_035.c +++ b/comedi/drivers/addi_apci_035.c @@ -1,5 +1,5 @@ #define CONFIG_APCI_035 1 -#define ADDIDATA_WATCHDOG 2 // Or shold it be something else +#define ADDIDATA_WATCHDOG 2 // Or shold it be something else #include "addi-data/addi_common.c" diff --git a/comedi/drivers/addi_apci_all.c b/comedi/drivers/addi_apci_all.c index ef742002..aeb1b268 100644 --- a/comedi/drivers/addi_apci_all.c +++ b/comedi/drivers/addi_apci_all.c @@ -1,5 +1,5 @@ #define CONFIG_APCI_035 1 -#define CONFIG_APCI_1032 1 +#define CONFIG_APCI_1032 1 #define CONFIG_APCI_1500 1 #define CONFIG_APCI_1516 1 #define CONFIG_APCI_1564 1 diff --git a/comedi/drivers/adl_pci6208.c b/comedi/drivers/adl_pci6208.c index 19a62aa8..b7af62e6 100644 --- a/comedi/drivers/adl_pci6208.c +++ b/comedi/drivers/adl_pci6208.c @@ -59,29 +59,29 @@ References: /* Board descriptions */ typedef struct { const char *name; - unsigned short dev_id; /* `lspci` will show you this */ + unsigned short dev_id; /* `lspci` will show you this */ int ao_chans; //int ao_bits; } pci6208_board; static const pci6208_board pci6208_boards[] = { /*{ - name : "pci6208v", - dev_id : 0x6208, //not sure - ao_chans: 8 - //, ao_bits : 16 - }, + name : "pci6208v", + dev_id : 0x6208, //not sure + ao_chans: 8 + //, ao_bits : 16 + }, + { + name : "pci6216v", + dev_id : 0x6208, //not sure + ao_chans: 16 + //, ao_bits : 16 + }, */ { - name : "pci6216v", - dev_id : 0x6208, //not sure - ao_chans: 16 - //, ao_bits : 16 - },*/ - { - name : "pci6208a", - dev_id : 0x6208, - ao_chans: 8 - //, ao_bits : 16 - } + name: "pci6208a", + dev_id: 0x6208, + ao_chans:8 + //, ao_bits : 16 + } }; /* This is used by modprobe to translate PCI IDs to drivers. Should @@ -89,50 +89,52 @@ static const pci6208_board pci6208_boards[] = { static struct pci_device_id pci6208_pci_table[] __devinitdata = { //{ PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, //{ PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci6208_pci_table); /* Will be initialized in pci6208_find device(). */ #define thisboard ((const pci6208_board *)dev->board_ptr) -typedef struct{ +typedef struct { int data; - struct pci_dev *pci_dev; /* for a PCI device */ - lsampl_t ao_readback[2]; /* Used for AO readback */ -}pci6208_private; + struct pci_dev *pci_dev; /* for a PCI device */ + lsampl_t ao_readback[2]; /* Used for AO readback */ +} pci6208_private; #define devpriv ((pci6208_private *)dev->private) -static int pci6208_attach(comedi_device *dev,comedi_devconfig *it); -static int pci6208_detach(comedi_device *dev); +static int pci6208_attach(comedi_device * dev, comedi_devconfig * it); +static int pci6208_detach(comedi_device * dev); #define pci6208_board_nbr \ (sizeof(pci6208_boards) / sizeof(pci6208_board)) -static comedi_driver driver_pci6208={ - driver_name: PCI6208_DRIVER_NAME, - module: THIS_MODULE, - attach: pci6208_attach, - detach: pci6208_detach, +static comedi_driver driver_pci6208 = { + driver_name:PCI6208_DRIVER_NAME, + module:THIS_MODULE, + attach:pci6208_attach, + detach:pci6208_detach, }; + COMEDI_INITCLEANUP(driver_pci6208); +static int pci6208_find_device(comedi_device * dev, int bus, int slot); static int -pci6208_find_device(comedi_device *dev, int bus, int slot); -static int -pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, int dev_minor); +pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, + int dev_minor); /*read/write functions*/ -static int pci6208_ao_winsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pci6208_ao_rinsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int pci6208_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci6208_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //static int pci6208_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, -// comedi_insn *insn,lsampl_t *data); +// comedi_insn *insn,lsampl_t *data); //static int pci6208_dio_insn_config(comedi_device *dev,comedi_subdevice *s, -// comedi_insn *insn,lsampl_t *data); +// comedi_insn *insn,lsampl_t *data); /* * Attach is called by the Comedi core to configure the driver @@ -140,43 +142,46 @@ static int pci6208_ao_rinsn(comedi_device *dev,comedi_subdevice *s, * in the driver structure, dev->board_ptr contains that * address. */ -static int pci6208_attach(comedi_device *dev,comedi_devconfig *it) +static int pci6208_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int retval; unsigned long io_base; - + printk("comedi%d: pci6208: ", dev->minor); retval = alloc_private(dev, sizeof(pci6208_private)); - if (retval < 0) return retval; - + if (retval < 0) + return retval; + retval = pci6208_find_device(dev, it->options[0], it->options[1]); - if (retval < 0) return retval; - + if (retval < 0) + return retval; + retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor); - if (retval < 0) return retval; + if (retval < 0) + return retval; - dev->iobase=io_base; + dev->iobase = io_base; dev->board_name = thisboard->name; - + /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; //anything else to add here?? - s->n_chan=thisboard->ao_chans; - s->maxdata=0xffff; //16-bit DAC - s->range_table=&range_bipolar10; //this needs to be checked. + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; //anything else to add here?? + s->n_chan = thisboard->ao_chans; + s->maxdata = 0xffff; //16-bit DAC + s->range_table = &range_bipolar10; //this needs to be checked. s->insn_write = pci6208_ao_winsn; s->insn_read = pci6208_ao_rinsn; - + //s=dev->subdevices+1; /* digital i/o subdevice */ //s->type=COMEDI_SUBD_DIO; @@ -186,13 +191,12 @@ static int pci6208_attach(comedi_device *dev,comedi_devconfig *it) //s->range_table=&range_digital; //s->insn_bits = pci6208_dio_insn_bits; //s->insn_config = pci6208_dio_insn_config; - + printk("attached\n"); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -201,35 +205,35 @@ static int pci6208_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pci6208_detach(comedi_device *dev) +static int pci6208_detach(comedi_device * dev) { - printk("comedi%d: pci6208: remove\n",dev->minor); - - if(devpriv && devpriv->pci_dev){ - if(dev->iobase) { + printk("comedi%d: pci6208: remove\n", dev->minor); + + if (devpriv && devpriv->pci_dev) { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } - + return 0; } -static int pci6208_ao_winsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pci6208_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i=0, Data_Read; + int i = 0, Data_Read; unsigned short chan = CR_CHAN(insn->chanspec); - unsigned long invert = 1 << (16-1); - unsigned long out_value; + unsigned long invert = 1 << (16 - 1); + unsigned long out_value; /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { out_value = data[i] ^ invert; /* a typical programming sequence */ - do{ + do { Data_Read = (inw(dev->iobase) & 1); - }while(Data_Read); + } while (Data_Read); outw(out_value, dev->iobase + (0x02 * chan)); devpriv->ao_readback[chan] = out_value; } @@ -240,13 +244,13 @@ static int pci6208_ao_winsn(comedi_device *dev,comedi_subdevice *s, /* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */ -static int pci6208_ao_rinsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pci6208_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -258,18 +262,18 @@ static int pci6208_ao_rinsn(comedi_device *dev,comedi_subdevice *s, * This allows packed reading/writing of the DIO channels. The * comedi core can convert between insn_bits and insn_read/write */ //static int pci6208_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, -// comedi_insn *insn,lsampl_t *data) +// comedi_insn *insn,lsampl_t *data) //{ -// if(insn->n!=2)return -EINVAL; +// if(insn->n!=2)return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ -// if(data[0]){ -// s->state &= ~data[0]; -// s->state |= data[0]&data[1]; +// if(data[0]){ +// s->state &= ~data[0]; +// s->state |= data[0]&data[1]; /* Write out the new digital output lines */ //outw(s->state,dev->iobase + SKEL_DIO); -// } +// } /* on return, data[1] contains the value of the digital * input and output lines. */ @@ -278,52 +282,47 @@ static int pci6208_ao_rinsn(comedi_device *dev,comedi_subdevice *s, * it was a purely digital output subdevice */ //data[1]=s->state; -// return 2; +// return 2; //} //static int pci6208_dio_insn_config(comedi_device *dev,comedi_subdevice *s, -// comedi_insn *insn,lsampl_t *data) +// comedi_insn *insn,lsampl_t *data) //{ -// int chan=CR_CHAN(insn->chanspec); +// int chan=CR_CHAN(insn->chanspec); /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ -// if(data[0]==COMEDI_OUTPUT){ -// s->io_bits |= 1<io_bits &= ~(1<io_bits |= 1<io_bits &= ~(1<io_bits,dev->iobase + SKEL_DIO_CONFIG); -// return 1; +// return 1; //} -static int -pci6208_find_device(comedi_device *dev, int bus, int slot) +static int pci6208_find_device(comedi_device * dev, int bus, int slot) { struct pci_dev *pci_dev; int i; - - for(pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; + + for (pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_dev != NULL; pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { - if (pci_dev->vendor == PCI_VENDOR_ID_ADLINK) - { - for (i= 0; i< pci6208_board_nbr; i++) - { - if(pci6208_boards[i].dev_id == pci_dev->device) - { + if (pci_dev->vendor == PCI_VENDOR_ID_ADLINK) { + for (i = 0; i < pci6208_board_nbr; i++) { + if (pci6208_boards[i].dev_id == pci_dev->device) { // was a particular bus/slot requested? - if((bus != 0) || (slot != 0)) - { + if ((bus != 0) || (slot != 0)) { // are we on the wrong bus/slot? - if(pci_dev->bus->number - != bus || - PCI_SLOT(pci_dev->devfn) - != slot) - { + if (pci_dev->bus->number + != bus || + PCI_SLOT(pci_dev->devfn) + != slot) { continue; } } @@ -333,32 +332,32 @@ pci6208_find_device(comedi_device *dev, int bus, int slot) } } } - - printk ("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", - dev->minor, bus, slot); + + printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", + dev->minor, bus, slot); return -EIO; -found: - printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n", + found: + printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n", dev->minor, pci6208_boards[i].name, pci_dev->bus->number, PCI_SLOT(pci_dev->devfn), - PCI_FUNC(pci_dev->devfn), - pci_dev->irq); + PCI_FUNC(pci_dev->devfn), pci_dev->irq); // TODO: Warn about non-tested boards. //switch(board->device_id) //{ //}; - + devpriv->pci_dev = pci_dev; - + return 0; } -static int -pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, int dev_minor) +static int +pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, + int dev_minor) { unsigned long io_base, io_range, lcr_io_base, lcr_io_range; @@ -367,32 +366,25 @@ pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr, int dev_m printk("comedi%d: Failed to enable PCI device and request regions\n", dev_minor); return -EIO; } - // Read local configuration register base address [PCI_BASE_ADDRESS #1]. lcr_io_base = pci_resource_start(pci_dev, 1); lcr_io_range = pci_resource_len(pci_dev, 1); - + printk("comedi%d: local config registers at address 0x%4lx [0x%4lx]\n", - dev_minor, - lcr_io_base, - lcr_io_range); - + dev_minor, lcr_io_base, lcr_io_range); + // Read PCI6208 register base address [PCI_BASE_ADDRESS #2]. - io_base = pci_resource_start (pci_dev, 2); - io_range = pci_resource_end (pci_dev, 2) - io_base +1; - - printk ("comedi%d: 6208 registers at address 0x%4lx [0x%4lx]\n", - dev_minor, - io_base, - io_range); - + io_base = pci_resource_start(pci_dev, 2); + io_range = pci_resource_end(pci_dev, 2) - io_base + 1; + + printk("comedi%d: 6208 registers at address 0x%4lx [0x%4lx]\n", + dev_minor, io_base, io_range); + *io_base_ptr = io_base; //devpriv->io_range = io_range; //devpriv->is_valid=0; //devpriv->lcr_io_base=lcr_io_base; //devpriv->lcr_io_range=lcr_io_range; - + return 0; } - - diff --git a/comedi/drivers/adl_pci7296.c b/comedi/drivers/adl_pci7296.c index f136acda..b26deb9f 100644 --- a/comedi/drivers/adl_pci7296.c +++ b/comedi/drivers/adl_pci7296.c @@ -45,96 +45,99 @@ Configuration Options: #define PCI_DEVICE_ID_PCI7296 0x7296 - - -typedef struct skel_board_struct{ +typedef struct skel_board_struct { const char *name; int vendor_id; int device_id; -}adl_pci7296_board; +} adl_pci7296_board; static const adl_pci7296_board adl_pci7296_boards[] = { - { "pci7296", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296 }, + {"pci7296", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296}, }; static struct pci_device_id adl_pci7296_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296, PCI_ANY_ID, PCI_ANY_ID, 0, + 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table); #define thisboard ((const adl_pci7296_board *)dev->board_ptr) -typedef struct{ +typedef struct { int data; struct pci_dev *pci_dev; -}adl_pci7296_private; +} adl_pci7296_private; #define devpriv ((adl_pci7296_private *)dev->private) -static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it); -static int adl_pci7296_detach(comedi_device *dev); -static comedi_driver driver_adl_pci7296={ - driver_name: "adl_pci7296", - module: THIS_MODULE, - attach: adl_pci7296_attach, - detach: adl_pci7296_detach, - - board_name: &adl_pci7296_boards[0].name, - offset: sizeof(adl_pci7296_board), - num_names: sizeof(adl_pci7296_boards) / sizeof(adl_pci7296_board), +static int adl_pci7296_attach(comedi_device * dev, comedi_devconfig * it); +static int adl_pci7296_detach(comedi_device * dev); +static comedi_driver driver_adl_pci7296 = { + driver_name:"adl_pci7296", + module:THIS_MODULE, + attach:adl_pci7296_attach, + detach:adl_pci7296_detach, + + board_name:&adl_pci7296_boards[0].name, + offset:sizeof(adl_pci7296_board), + num_names:sizeof(adl_pci7296_boards) / sizeof(adl_pci7296_board), }; - -static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it) +static int adl_pci7296_attach(comedi_device * dev, comedi_devconfig * it) { struct pci_dev *pcidev; comedi_subdevice *s; printk("comedi: attempt to attach...\n"); - printk("comedi%d: adl_pci7432: board=%s\n",dev->minor, thisboard->name); + printk("comedi%d: adl_pci7432: board=%s\n", dev->minor, + thisboard->name); - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(adl_pci7296_private))<0) + if (alloc_private(dev, sizeof(adl_pci7296_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK && - pcidev->device == PCI_DEVICE_ID_PCI7296 ) { + if (pcidev->vendor == PCI_VENDOR_ID_ADLINK && + pcidev->device == PCI_DEVICE_ID_PCI7296) { devpriv->pci_dev = pcidev; if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) { - printk("comedi%d: Failed to enable PCI device and request regions\n", - dev->minor); + printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); return -EIO; } - dev->iobase = pci_resource_start ( pcidev, 2 ); - printk ( "comedi: base addr %4lx\n", dev->iobase ); + dev->iobase = pci_resource_start(pcidev, 2); + printk("comedi: base addr %4lx\n", dev->iobase); dev->board_ptr = adl_pci7296_boards + 0; // four 8255 digital io subdevices s = dev->subdevices + 0; - subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase)); + subdev_8255_init(dev, s, NULL, + (unsigned long)(dev->iobase)); s = dev->subdevices + 1; - subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT2A)); + subdev_8255_init(dev, s, NULL, + (unsigned long)(dev->iobase + PORT2A)); s = dev->subdevices + 2; - subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT3A)); + subdev_8255_init(dev, s, NULL, + (unsigned long)(dev->iobase + PORT3A)); s = dev->subdevices + 3; - subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT4A)); + subdev_8255_init(dev, s, NULL, + (unsigned long)(dev->iobase + PORT4A)); break; - } + } } printk("attached\n"); @@ -142,10 +145,9 @@ static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it) return 1; } - -static int adl_pci7296_detach(comedi_device *dev) +static int adl_pci7296_detach(comedi_device * dev) { - printk("comedi%d: pci7432: remove\n",dev->minor); + printk("comedi%d: pci7432: remove\n", dev->minor); if (devpriv && devpriv->pci_dev) { if (dev->iobase) { @@ -153,10 +155,8 @@ static int adl_pci7296_detach(comedi_device *dev) } pci_dev_put(devpriv->pci_dev); } - // detach four 8255 digital io subdevices - if(dev->subdevices) - { + if (dev->subdevices) { subdev_8255_cleanup(dev, dev->subdevices + 0); subdev_8255_cleanup(dev, dev->subdevices + 1); subdev_8255_cleanup(dev, dev->subdevices + 2); @@ -168,5 +168,3 @@ static int adl_pci7296_detach(comedi_device *dev) } COMEDI_INITCLEANUP(driver_adl_pci7296); - - diff --git a/comedi/drivers/adl_pci7432.c b/comedi/drivers/adl_pci7432.c index c6a4c227..c00d8e6d 100644 --- a/comedi/drivers/adl_pci7432.c +++ b/comedi/drivers/adl_pci7432.c @@ -41,86 +41,90 @@ Configuration Options: typedef struct { const char *name; - int vendor_id; - int device_id; + int vendor_id; + int device_id; } adl_pci7432_board; static const adl_pci7432_board adl_pci7432_boards[] = { - { "pci7432", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432 }, + {"pci7432", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432}, }; static struct pci_device_id adl_pci7432_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432, PCI_ANY_ID, PCI_ANY_ID, 0, + 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table); #define thisboard ((const adl_pci7432_board *)dev->board_ptr) -typedef struct{ +typedef struct { int data; struct pci_dev *pci_dev; } adl_pci7432_private; #define devpriv ((adl_pci7432_private *)dev->private) -static int adl_pci7432_attach(comedi_device *dev,comedi_devconfig *it); -static int adl_pci7432_detach(comedi_device *dev); -static comedi_driver driver_adl_pci7432={ - driver_name: "adl_pci7432", - module: THIS_MODULE, - attach: adl_pci7432_attach, - detach: adl_pci7432_detach, - num_names: 1, - board_name: &adl_pci7432_boards[0].name, - offset: sizeof(adl_pci7432_board), +static int adl_pci7432_attach(comedi_device * dev, comedi_devconfig * it); +static int adl_pci7432_detach(comedi_device * dev); +static comedi_driver driver_adl_pci7432 = { + driver_name:"adl_pci7432", + module:THIS_MODULE, + attach:adl_pci7432_attach, + detach:adl_pci7432_detach, + num_names:1, + board_name:&adl_pci7432_boards[0].name, + offset:sizeof(adl_pci7432_board), }; /* Digital IO */ -static int adl_pci7432_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int adl_pci7432_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci7432_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int adl_pci7432_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* */ -static int adl_pci7432_attach(comedi_device *dev,comedi_devconfig *it) +static int adl_pci7432_attach(comedi_device * dev, comedi_devconfig * it) { struct pci_dev *pcidev; comedi_subdevice *s; printk("comedi: attempt to attach...\n"); - printk("comedi%d: adl_pci7432: board=%s\n",dev->minor, thisboard->name); + printk("comedi%d: adl_pci7432: board=%s\n", dev->minor, + thisboard->name); - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(adl_pci7432_private))<0) + if (alloc_private(dev, sizeof(adl_pci7432_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK && - pcidev->device == PCI_DEVICE_ID_PCI7432 ) { + if (pcidev->vendor == PCI_VENDOR_ID_ADLINK && + pcidev->device == PCI_DEVICE_ID_PCI7432) { devpriv->pci_dev = pcidev; if (comedi_pci_enable(pcidev, "adl_pci7432") < 0) { printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); return -EIO; } - dev->iobase = pci_resource_start ( pcidev, 2 ); - printk ( "comedi: base addr %4lx\n", dev->iobase ); + dev->iobase = pci_resource_start(pcidev, 2); + printk("comedi: base addr %4lx\n", dev->iobase); dev->board_ptr = adl_pci7432_boards + 0; - s=dev->subdevices+0; + s = dev->subdevices + 0; s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = + SDF_READABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 32; s->maxdata = 1; s->len_chanlist = 32; @@ -128,15 +132,16 @@ static int adl_pci7432_attach(comedi_device *dev,comedi_devconfig *it) s->range_table = &range_digital; s->insn_bits = adl_pci7432_di_insn_bits; - s=dev->subdevices+1; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; - s->n_chan = 32; - s->maxdata = 1 ; - s->len_chanlist = 32; + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = + SDF_WRITABLE | SDF_GROUND | SDF_COMMON; + s->n_chan = 32; + s->maxdata = 1; + s->len_chanlist = 32; s->io_bits = 0xffffffff; - s->range_table = &range_digital; - s->insn_bits = adl_pci7432_do_insn_bits; + s->range_table = &range_digital; + s->insn_bits = adl_pci7432_do_insn_bits; break; } @@ -147,10 +152,9 @@ static int adl_pci7432_attach(comedi_device *dev,comedi_devconfig *it) return 1; } - -static int adl_pci7432_detach(comedi_device *dev) +static int adl_pci7432_detach(comedi_device * dev) { - printk("comedi%d: pci7432: remove\n",dev->minor); + printk("comedi%d: pci7432: remove\n", dev->minor); if (devpriv && devpriv->pci_dev) { if (dev->iobase) { @@ -162,33 +166,37 @@ static int adl_pci7432_detach(comedi_device *dev) return 0; } - -static int adl_pci7432_do_insn_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int adl_pci7432_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - printk ( "comedi: pci7432_do_insn_bits called\n" ); - printk ( "comedi: data0: %8x data1: %8x\n", data[0], data[1] ); + printk("comedi: pci7432_do_insn_bits called\n"); + printk("comedi: data0: %8x data1: %8x\n", data[0], data[1]); - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); - printk ( "comedi: out: %8x on iobase %4lx\n", s->state, dev->iobase + PCI7432_DO); + printk("comedi: out: %8x on iobase %4lx\n", s->state, + dev->iobase + PCI7432_DO); outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO); } return 2; } -static int adl_pci7432_di_insn_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int adl_pci7432_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - printk ( "comedi: pci7432_di_insn_bits called\n" ); - printk ( "comedi: data0: %8x data1: %8x\n", data[0], data[1] ); + printk("comedi: pci7432_di_insn_bits called\n"); + printk("comedi: data0: %8x data1: %8x\n", data[0], data[1]); - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff; - printk ( "comedi: data1 %8x\n", data[1] ); + printk("comedi: data1 %8x\n", data[1]); return 2; } diff --git a/comedi/drivers/adl_pci8164.c b/comedi/drivers/adl_pci8164.c index 391e2298..43b24b4f 100644 --- a/comedi/drivers/adl_pci8164.c +++ b/comedi/drivers/adl_pci8164.c @@ -53,92 +53,103 @@ Configuration Options: typedef struct { const char *name; - int vendor_id; - int device_id; + int vendor_id; + int device_id; } adl_pci8164_board; static const adl_pci8164_board adl_pci8164_boards[] = { - { "pci8164", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164 }, + {"pci8164", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164}, }; static struct pci_device_id adl_pci8164_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164, PCI_ANY_ID, PCI_ANY_ID, 0, + 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table); #define thisboard ((const adl_pci8164_board *)dev->board_ptr) -typedef struct{ +typedef struct { int data; struct pci_dev *pci_dev; } adl_pci8164_private; #define devpriv ((adl_pci8164_private *)dev->private) -static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it); -static int adl_pci8164_detach(comedi_device *dev); -static comedi_driver driver_adl_pci8164={ - driver_name: "adl_pci8164", - module: THIS_MODULE, - attach: adl_pci8164_attach, - detach: adl_pci8164_detach, - num_names: 1, - board_name: &adl_pci8164_boards[0].name, - offset: sizeof(adl_pci8164_board), +static int adl_pci8164_attach(comedi_device * dev, comedi_devconfig * it); +static int adl_pci8164_detach(comedi_device * dev); +static comedi_driver driver_adl_pci8164 = { + driver_name:"adl_pci8164", + module:THIS_MODULE, + attach:adl_pci8164_attach, + detach:adl_pci8164_detach, + num_names:1, + board_name:&adl_pci8164_boards[0].name, + offset:sizeof(adl_pci8164_board), }; -static int adl_pci8164_insn_read_msts(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_read_msts(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_read_ssts(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_read_ssts(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_read_buf0(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_read_buf0(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_read_buf1(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_read_buf1(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_write_cmd(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_write_cmd(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_write_otp(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_write_otp(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_write_buf0(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_write_buf0(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_insn_write_buf1(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data); +static int adl_pci8164_insn_write_buf1(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it) +static int adl_pci8164_attach(comedi_device * dev, comedi_devconfig * it) { struct pci_dev *pcidev; comedi_subdevice *s; printk("comedi: attempt to attach...\n"); - printk("comedi%d: adl_pci8164: board=%s\n",dev->minor, thisboard->name); + printk("comedi%d: adl_pci8164: board=%s\n", dev->minor, + thisboard->name); - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(adl_pci8164_private))<0) + if (alloc_private(dev, sizeof(adl_pci8164_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK && - pcidev->device == PCI_DEVICE_ID_PCI8164 ) { + if (pcidev->vendor == PCI_VENDOR_ID_ADLINK && + pcidev->device == PCI_DEVICE_ID_PCI8164) { devpriv->pci_dev = pcidev; if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) { printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); return -EIO; } - dev->iobase = pci_resource_start ( pcidev, 2 ); - printk ( "comedi: base addr %4lx\n", dev->iobase ); + dev->iobase = pci_resource_start(pcidev, 2); + printk("comedi: base addr %4lx\n", dev->iobase); dev->board_ptr = adl_pci8164_boards + 0; - s=dev->subdevices+0; + s = dev->subdevices + 0; s->type = COMEDI_SUBD_PROC; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 4; s->maxdata = 0xffff; s->len_chanlist = 4; @@ -146,9 +157,9 @@ static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it) s->insn_read = adl_pci8164_insn_read_msts; s->insn_write = adl_pci8164_insn_write_cmd; - s=dev->subdevices+1; + s = dev->subdevices + 1; s->type = COMEDI_SUBD_PROC; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 4; s->maxdata = 0xffff; s->len_chanlist = 4; @@ -156,9 +167,9 @@ static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it) s->insn_read = adl_pci8164_insn_read_ssts; s->insn_write = adl_pci8164_insn_write_otp; - s=dev->subdevices+2; + s = dev->subdevices + 2; s->type = COMEDI_SUBD_PROC; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 4; s->maxdata = 0xffff; s->len_chanlist = 4; @@ -166,9 +177,9 @@ static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it) s->insn_read = adl_pci8164_insn_read_buf0; s->insn_write = adl_pci8164_insn_write_buf0; - s=dev->subdevices+3; + s = dev->subdevices + 3; s->type = COMEDI_SUBD_PROC; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 4; s->maxdata = 0xffff; s->len_chanlist = 4; @@ -185,10 +196,9 @@ static int adl_pci8164_attach(comedi_device *dev,comedi_devconfig *it) return 1; } - -static int adl_pci8164_detach(comedi_device *dev) +static int adl_pci8164_detach(comedi_device * dev) { - printk("comedi%d: pci8164: remove\n",dev->minor); + printk("comedi%d: pci8164: remove\n", dev->minor); if (devpriv && devpriv->pci_dev) { if (dev->iobase) { @@ -200,100 +210,119 @@ static int adl_pci8164_detach(comedi_device *dev) return 0; } -static int adl_pci8164_insn_read_msts(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_read_msts(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int axis, axis_reg; - char *axisname; + int axis, axis_reg; + char *axisname; axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } data[0] = inw(dev->iobase + axis_reg + PCI8164_MSTS); - printk("comedi: pci8164 MSTS read -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 MSTS read -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_read_ssts(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_read_ssts(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; char *axisname; axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } data[0] = inw(dev->iobase + axis_reg + PCI8164_SSTS); - printk("comedi: pci8164 SSTS read -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 SSTS read -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_read_buf0(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_read_buf0(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; char *axisname; axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 read -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 BUF0 read -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_read_buf1(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_read_buf1(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; @@ -301,31 +330,37 @@ static int adl_pci8164_insn_read_buf1(comedi_device *dev,comedi_subdevice *s,com axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 read -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 BUF1 read -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_write_cmd(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_write_cmd(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int axis, axis_reg; @@ -333,31 +368,37 @@ static int adl_pci8164_insn_write_cmd(comedi_device *dev,comedi_subdevice *s,com axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } - outw(data[0], dev->iobase + axis_reg + PCI8164_CMD); - printk("comedi: pci8164 CMD write -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + outw(data[0], dev->iobase + axis_reg + PCI8164_CMD); + printk("comedi: pci8164 CMD write -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_write_otp(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_write_otp(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; @@ -365,31 +406,37 @@ static int adl_pci8164_insn_write_otp(comedi_device *dev,comedi_subdevice *s,com axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } outw(data[0], dev->iobase + axis_reg + PCI8164_OTP); - printk("comedi: pci8164 OTP write -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 OTP write -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } -static int adl_pci8164_insn_write_buf0(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_write_buf0(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; @@ -397,31 +444,37 @@ static int adl_pci8164_insn_write_buf0(comedi_device *dev,comedi_subdevice *s,co axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } outw(data[0], dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 write -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + printk("comedi: pci8164 BUF0 write -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); - return 2; + return 2; } -static int adl_pci8164_insn_write_buf1(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn, lsampl_t *data) +static int adl_pci8164_insn_write_buf1(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int axis, axis_reg; @@ -429,26 +482,31 @@ static int adl_pci8164_insn_write_buf1(comedi_device *dev,comedi_subdevice *s,co axis = CR_CHAN(insn->chanspec); - switch (axis) - { - case 0: axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: axis_reg = PCI8164_AXIS_X; - axisname = "X"; + switch (axis) { + case 0: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; + break; + case 1: + axis_reg = PCI8164_AXIS_Y; + axisname = "Y"; + break; + case 2: + axis_reg = PCI8164_AXIS_Z; + axisname = "Z"; + break; + case 3: + axis_reg = PCI8164_AXIS_U; + axisname = "U"; + break; + default: + axis_reg = PCI8164_AXIS_X; + axisname = "X"; } - outw(data[0], dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 write -> %04X:%04X on axis %s\n", data[0], data[1], axisname); + outw(data[0], dev->iobase + axis_reg + PCI8164_BUF1); + printk("comedi: pci8164 BUF1 write -> %04X:%04X on axis %s\n", data[0], + data[1], axisname); return 2; } diff --git a/comedi/drivers/adl_pci9111.c b/comedi/drivers/adl_pci9111.c index f76b0589..24bf0075 100644 --- a/comedi/drivers/adl_pci9111.c +++ b/comedi/drivers/adl_pci9111.c @@ -133,11 +133,11 @@ TODO: /* IO address map */ -#define PCI9111_REGISTER_AD_FIFO_VALUE 0x00 // AD Data stored in FIFO +#define PCI9111_REGISTER_AD_FIFO_VALUE 0x00 // AD Data stored in FIFO #define PCI9111_REGISTER_DA_OUTPUT 0x00 #define PCI9111_REGISTER_DIGITAL_IO 0x02 #define PCI9111_REGISTER_EXTENDED_IO_PORTS 0x04 -#define PCI9111_REGISTER_AD_CHANNEL_CONTROL 0x06 // Channel selection +#define PCI9111_REGISTER_AD_CHANNEL_CONTROL 0x06 // Channel selection #define PCI9111_REGISTER_AD_CHANNEL_READBACK 0x06 #define PCI9111_REGISTER_INPUT_SIGNAL_RANGE 0x08 #define PCI9111_REGISTER_RANGE_STATUS_READBACK 0x08 @@ -265,28 +265,29 @@ TODO: // Function prototypes // -static int pci9111_attach (comedi_device *dev,comedi_devconfig *it); -static int pci9111_detach (comedi_device *dev); -static void pci9111_ai_munge(comedi_device *dev, comedi_subdevice *s, void *data, - unsigned int num_bytes, unsigned int start_chan_index ); +static int pci9111_attach(comedi_device * dev, comedi_devconfig * it); +static int pci9111_detach(comedi_device * dev); +static void pci9111_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *data, unsigned int num_bytes, unsigned int start_chan_index); -static const comedi_lrange pci9111_hr_ai_range= -{ - 5, - { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625) - } +static const comedi_lrange pci9111_hr_ai_range = { + 5, + { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625) + } }; static struct pci_device_id pci9111_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, + 0, 0}, //{ PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {0} }; + MODULE_DEVICE_TABLE(pci, pci9111_pci_table); // @@ -294,83 +295,77 @@ MODULE_DEVICE_TABLE(pci, pci9111_pci_table); // typedef struct { - const char *name; // driver name - int device_id; - int ai_channel_nbr; // num of A/D chans - int ao_channel_nbr; // num of D/A chans - int ai_resolution; // resolution of A/D - int ai_resolution_mask; - int ao_resolution; // resolution of D/A - int ao_resolution_mask; - const comedi_lrange *ai_range_list; // rangelist for A/D - const comedi_lrange *ao_range_list; // rangelist for D/A - unsigned int ai_acquisition_period_min_ns; + const char *name; // driver name + int device_id; + int ai_channel_nbr; // num of A/D chans + int ao_channel_nbr; // num of D/A chans + int ai_resolution; // resolution of A/D + int ai_resolution_mask; + int ao_resolution; // resolution of D/A + int ao_resolution_mask; + const comedi_lrange *ai_range_list; // rangelist for A/D + const comedi_lrange *ao_range_list; // rangelist for D/A + unsigned int ai_acquisition_period_min_ns; } pci9111_board_struct; - -static const pci9111_board_struct pci9111_boards[] = -{ - { - name: "pci9111_hr", - device_id: PCI9111_HR_DEVICE_ID, - ai_channel_nbr: PCI9111_AI_CHANNEL_NBR, - ao_channel_nbr: PCI9111_AO_CHANNEL_NBR, - ai_resolution: PCI9111_HR_AI_RESOLUTION, - ai_resolution_mask: PCI9111_HR_AI_RESOLUTION_MASK, - ao_resolution: PCI9111_AO_RESOLUTION, - ao_resolution_mask: PCI9111_AO_RESOLUTION_MASK, - ai_range_list: &pci9111_hr_ai_range, - ao_range_list: &range_bipolar10, - ai_acquisition_period_min_ns: PCI9111_AI_ACQUISITION_PERIOD_MIN_NS - } +static const pci9111_board_struct pci9111_boards[] = { + { + name: "pci9111_hr", + device_id:PCI9111_HR_DEVICE_ID, + ai_channel_nbr:PCI9111_AI_CHANNEL_NBR, + ao_channel_nbr:PCI9111_AO_CHANNEL_NBR, + ai_resolution:PCI9111_HR_AI_RESOLUTION, + ai_resolution_mask:PCI9111_HR_AI_RESOLUTION_MASK, + ao_resolution:PCI9111_AO_RESOLUTION, + ao_resolution_mask:PCI9111_AO_RESOLUTION_MASK, + ai_range_list:&pci9111_hr_ai_range, + ao_range_list:&range_bipolar10, + ai_acquisition_period_min_ns:PCI9111_AI_ACQUISITION_PERIOD_MIN_NS} }; #define pci9111_board_nbr \ (sizeof(pci9111_boards)/sizeof(pci9111_board_struct)) -static comedi_driver pci9111_driver= -{ - driver_name: PCI9111_DRIVER_NAME, - module: THIS_MODULE, - attach: pci9111_attach, - detach: pci9111_detach, - num_names: pci9111_board_nbr, - board_name: &pci9111_boards[0].name, - offset: sizeof(pci9111_board_struct), +static comedi_driver pci9111_driver = { + driver_name:PCI9111_DRIVER_NAME, + module:THIS_MODULE, + attach:pci9111_attach, + detach:pci9111_detach, + num_names:pci9111_board_nbr, + board_name:&pci9111_boards[0].name, + offset:sizeof(pci9111_board_struct), }; + COMEDI_INITCLEANUP(pci9111_driver); // // Private data structure // -typedef struct -{ - struct pci_dev* pci_device; - unsigned long io_range; // PCI6503 io range +typedef struct { + struct pci_dev *pci_device; + unsigned long io_range; // PCI6503 io range - unsigned long lcr_io_base; // Local configuration register base address - unsigned long lcr_io_range; + unsigned long lcr_io_base; // Local configuration register base address + unsigned long lcr_io_range; - int stop_counter; - int stop_is_none; + int stop_counter; + int stop_is_none; - unsigned int scan_delay; - unsigned int chanlist_len; - unsigned int chunk_counter; - unsigned int chunk_num_samples; + unsigned int scan_delay; + unsigned int chanlist_len; + unsigned int chunk_counter; + unsigned int chunk_num_samples; - int ao_readback; // Last written analog output data + int ao_readback; // Last written analog output data - int timer_divisor_1; // Divisor values for the 8254 timer pacer - int timer_divisor_2; + int timer_divisor_1; // Divisor values for the 8254 timer pacer + int timer_divisor_2; - int is_valid; // Is device valid + int is_valid; // Is device valid sampl_t ai_bounce_buffer[2 * PCI9111_FIFO_HALF_SIZE]; -} -pci9111_private_data_struct; - +} pci9111_private_data_struct; #define dev_private ((pci9111_private_data_struct *)dev->private) @@ -391,23 +386,26 @@ pci9111_private_data_struct; #define PLX9050_PCI_INTERRUPT_ENABLE (1 << 6) #define PLX9050_SOFTWARE_INTERRUPT (1 << 7) -static void plx9050_interrupt_control (unsigned long io_base, - bool LINTi1_enable, - bool LINTi1_active_high, - bool LINTi2_enable, - bool LINTi2_active_high, - bool interrupt_enable) +static void plx9050_interrupt_control(unsigned long io_base, + bool LINTi1_enable, + bool LINTi1_active_high, + bool LINTi2_enable, bool LINTi2_active_high, bool interrupt_enable) { - int flags = 0; + int flags = 0; - if (LINTi1_enable) flags |= PLX9050_LINTI1_ENABLE; - if (LINTi1_active_high) flags |= PLX9050_LINTI1_ACTIVE_HIGH; - if (LINTi2_enable) flags |= PLX9050_LINTI2_ENABLE; - if (LINTi2_active_high) flags |= PLX9050_LINTI2_ACTIVE_HIGH; + if (LINTi1_enable) + flags |= PLX9050_LINTI1_ENABLE; + if (LINTi1_active_high) + flags |= PLX9050_LINTI1_ACTIVE_HIGH; + if (LINTi2_enable) + flags |= PLX9050_LINTI2_ENABLE; + if (LINTi2_active_high) + flags |= PLX9050_LINTI2_ACTIVE_HIGH; - if (interrupt_enable) flags |= PLX9050_PCI_INTERRUPT_ENABLE; + if (interrupt_enable) + flags |= PLX9050_PCI_INTERRUPT_ENABLE; - outb (flags, io_base + PLX9050_REGISTER_INTERRUPT_CONTROL); + outb(flags, io_base + PLX9050_REGISTER_INTERRUPT_CONTROL); } // ------------------------------------------------------------------ @@ -420,115 +418,104 @@ static void plx9050_interrupt_control (unsigned long io_base, // 8254 timer // -static void pci9111_timer_set ( comedi_device * dev) +static void pci9111_timer_set(comedi_device * dev) { - pci9111_8254_control_set ( PCI9111_8254_COUNTER_0| - PCI9111_8254_READ_LOAD_LSB_MSB| - PCI9111_8254_MODE_0| - PCI9111_8254_BINARY_COUNTER); + pci9111_8254_control_set(PCI9111_8254_COUNTER_0 | + PCI9111_8254_READ_LOAD_LSB_MSB | + PCI9111_8254_MODE_0 | PCI9111_8254_BINARY_COUNTER); - pci9111_8254_control_set ( PCI9111_8254_COUNTER_1| - PCI9111_8254_READ_LOAD_LSB_MSB| - PCI9111_8254_MODE_2| - PCI9111_8254_BINARY_COUNTER); + pci9111_8254_control_set(PCI9111_8254_COUNTER_1 | + PCI9111_8254_READ_LOAD_LSB_MSB | + PCI9111_8254_MODE_2 | PCI9111_8254_BINARY_COUNTER); - pci9111_8254_control_set ( PCI9111_8254_COUNTER_2| - PCI9111_8254_READ_LOAD_LSB_MSB| - PCI9111_8254_MODE_2| - PCI9111_8254_BINARY_COUNTER); + pci9111_8254_control_set(PCI9111_8254_COUNTER_2 | + PCI9111_8254_READ_LOAD_LSB_MSB | + PCI9111_8254_MODE_2 | PCI9111_8254_BINARY_COUNTER); - comedi_udelay(1); + comedi_udelay(1); - pci9111_8254_counter_2_set (dev_private->timer_divisor_2); - pci9111_8254_counter_1_set (dev_private->timer_divisor_1); + pci9111_8254_counter_2_set(dev_private->timer_divisor_2); + pci9111_8254_counter_1_set(dev_private->timer_divisor_1); } -typedef enum -{ - software, - timer_pacer, - external -} -pci9111_trigger_sources; +typedef enum { + software, + timer_pacer, + external +} pci9111_trigger_sources; -static void pci9111_trigger_source_set (comedi_device *dev, - pci9111_trigger_sources source) +static void pci9111_trigger_source_set(comedi_device * dev, + pci9111_trigger_sources source) { - int flags; + int flags; - flags = pci9111_trigger_and_autoscan_get() & 0x09; + flags = pci9111_trigger_and_autoscan_get() & 0x09; - switch (source) - { - case software : - flags |= PCI9111_EITS_INTERNAL | PCI9111_TPST_SOFTWARE_TRIGGER; - break; + switch (source) { + case software: + flags |= PCI9111_EITS_INTERNAL | PCI9111_TPST_SOFTWARE_TRIGGER; + break; - case timer_pacer : - flags |= PCI9111_EITS_INTERNAL | PCI9111_TPST_TIMER_PACER; - break; + case timer_pacer: + flags |= PCI9111_EITS_INTERNAL | PCI9111_TPST_TIMER_PACER; + break; - case external : - flags |= PCI9111_EITS_EXTERNAL; - break; - } + case external: + flags |= PCI9111_EITS_EXTERNAL; + break; + } - pci9111_trigger_and_autoscan_set (flags); + pci9111_trigger_and_autoscan_set(flags); } -static void pci9111_pretrigger_set (comedi_device *dev, - bool pretrigger) +static void pci9111_pretrigger_set(comedi_device * dev, bool pretrigger) { - int flags; + int flags; - flags = pci9111_trigger_and_autoscan_get () & 0x07; + flags = pci9111_trigger_and_autoscan_get() & 0x07; - if (pretrigger) flags |= PCI9111_PTRG_ON; + if (pretrigger) + flags |= PCI9111_PTRG_ON; - pci9111_trigger_and_autoscan_set (flags); + pci9111_trigger_and_autoscan_set(flags); } -static void pci9111_autoscan_set (comedi_device *dev, - bool autoscan) +static void pci9111_autoscan_set(comedi_device * dev, bool autoscan) { - int flags; + int flags; - flags = pci9111_trigger_and_autoscan_get() & 0x0e; + flags = pci9111_trigger_and_autoscan_get() & 0x0e; - if (autoscan) flags |= PCI9111_ASCAN_ON; + if (autoscan) + flags |= PCI9111_ASCAN_ON; - pci9111_trigger_and_autoscan_set (flags); + pci9111_trigger_and_autoscan_set(flags); } -typedef enum -{ - irq_on_eoc, - irq_on_fifo_half_full -} -pci9111_ISC0_sources; +typedef enum { + irq_on_eoc, + irq_on_fifo_half_full +} pci9111_ISC0_sources; -typedef enum -{ - irq_on_timer_tick, - irq_on_external_trigger -} -pci9111_ISC1_sources; +typedef enum { + irq_on_timer_tick, + irq_on_external_trigger +} pci9111_ISC1_sources; -static void pci9111_interrupt_source_set (comedi_device *dev, - pci9111_ISC0_sources irq_0_source, - pci9111_ISC1_sources irq_1_source) +static void pci9111_interrupt_source_set(comedi_device * dev, + pci9111_ISC0_sources irq_0_source, pci9111_ISC1_sources irq_1_source) { - int flags; + int flags; - flags = pci9111_interrupt_and_fifo_get() & 0x04; + flags = pci9111_interrupt_and_fifo_get() & 0x04; - if (irq_0_source == irq_on_fifo_half_full) - flags |= PCI9111_ISC0_SET_IRQ_ON_FIFO_HALF_FULL; + if (irq_0_source == irq_on_fifo_half_full) + flags |= PCI9111_ISC0_SET_IRQ_ON_FIFO_HALF_FULL; - if (irq_1_source == irq_on_external_trigger) - flags |= PCI9111_ISC1_SET_IRQ_ON_EXT_TRG; + if (irq_1_source == irq_on_external_trigger) + flags |= PCI9111_ISC1_SET_IRQ_ON_EXT_TRG; - pci9111_interrupt_and_fifo_set (flags); + pci9111_interrupt_and_fifo_set(flags); } // ------------------------------------------------------------------ @@ -543,24 +530,24 @@ static void pci9111_interrupt_source_set (comedi_device *dev, #undef AI_DO_CMD_DEBUG -static int pci9111_ai_cancel ( comedi_device *dev, - comedi_subdevice *s) +static int pci9111_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - // Disable interrupts + // Disable interrupts - plx9050_interrupt_control (dev_private->lcr_io_base, true, true, true, true, false); + plx9050_interrupt_control(dev_private->lcr_io_base, true, true, true, + true, false); - pci9111_trigger_source_set (dev, software); + pci9111_trigger_source_set(dev, software); - pci9111_autoscan_set (dev, false); + pci9111_autoscan_set(dev, false); - pci9111_fifo_reset(); + pci9111_fifo_reset(); #ifdef AI_DO_CMD_DEBUG - printk (PCI9111_DRIVER_NAME ": ai_cancel\n"); + printk(PCI9111_DRIVER_NAME ": ai_cancel\n"); #endif - return 0; + return 0; } // @@ -573,149 +560,133 @@ static int pci9111_ai_cancel ( comedi_device *dev, if (!src || tmp != src) error++ static int -pci9111_ai_do_cmd_test ( comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +pci9111_ai_do_cmd_test(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - int tmp; - int error=0; - int range, reference; - int i; - pci9111_board_struct* board= (pci9111_board_struct*) dev->board_ptr; - - // Step 1 : check if trigger are trivialy valid - - pci9111_check_trigger_src (cmd->start_src, TRIG_NOW); - pci9111_check_trigger_src (cmd->scan_begin_src, TRIG_TIMER|TRIG_FOLLOW|TRIG_EXT); - pci9111_check_trigger_src (cmd->convert_src, TRIG_TIMER|TRIG_EXT); - pci9111_check_trigger_src (cmd->scan_end_src, TRIG_COUNT); - pci9111_check_trigger_src (cmd->stop_src, TRIG_COUNT|TRIG_NONE); - - if (error) return 1; - - // step 2 : make sure trigger sources are unique and mutually compatible - - if (cmd->start_src != TRIG_NOW) error++; - - if ((cmd->scan_begin_src != TRIG_TIMER) && - (cmd->scan_begin_src != TRIG_FOLLOW) && - (cmd->scan_begin_src != TRIG_EXT)) error++; - - if ((cmd->convert_src != TRIG_TIMER) && - (cmd->convert_src != TRIG_EXT)) - { - error++; - } - if ((cmd->convert_src == TRIG_TIMER) && - !((cmd->scan_begin_src == TRIG_TIMER) || - (cmd->scan_begin_src == TRIG_FOLLOW))) - { - error++; - } - if ((cmd->convert_src == TRIG_EXT) && - !((cmd->scan_begin_src == TRIG_EXT) || - (cmd->scan_begin_src == TRIG_FOLLOW))) - { - error++; - } - - if (cmd->scan_end_src != TRIG_COUNT) error++; - if ( (cmd->stop_src != TRIG_COUNT) && - (cmd->stop_src != TRIG_NONE)) error++; - - if (error) return 2; - - // Step 3 : make sure arguments are trivialy compatible - - if (cmd->chanlist_len<1) - { - cmd->chanlist_len=1; - error++; - } - - if (cmd->chanlist_len>board->ai_channel_nbr) - { - cmd->chanlist_len=board->ai_channel_nbr; - error++; - } - - if ((cmd->start_src == TRIG_NOW) && - (cmd->start_arg!=0)) { - cmd->start_arg=0; - error++; - } - - if ((cmd->convert_src == TRIG_TIMER) && - (cmd->convert_argai_acquisition_period_min_ns)) - { - cmd->convert_arg=board->ai_acquisition_period_min_ns; - error++; - } - if ((cmd->convert_src == TRIG_EXT) && - (cmd->convert_arg != 0)) - { - cmd->convert_arg = 0; - error++; - } - - if ((cmd->scan_begin_src == TRIG_TIMER) && - (cmd->scan_begin_arg < board->ai_acquisition_period_min_ns)) - { - cmd->scan_begin_arg = board->ai_acquisition_period_min_ns; - error++; - } - if ((cmd->scan_begin_src == TRIG_FOLLOW) && - (cmd->scan_begin_arg != 0)) - { - cmd->scan_begin_arg = 0; - error++; - } - if ((cmd->scan_begin_src == TRIG_EXT) && - (cmd->scan_begin_arg != 0)) - { - cmd->scan_begin_arg = 0; - error++; - } - - if ((cmd->scan_end_src == TRIG_COUNT) && - (cmd->scan_end_arg != cmd->chanlist_len)) - { - cmd->scan_end_arg=cmd->chanlist_len; - error++; - } - - if ((cmd->stop_src == TRIG_COUNT) && - (cmd->stop_arg < 1)) - { - cmd->stop_arg=1; - error++; - } - if ((cmd->stop_src == TRIG_NONE) && - (cmd->stop_arg !=0)) - { - cmd->stop_arg=0; - error++; - } - - if (error) return 3; - - // Step 4 : fix up any arguments - - if (cmd->convert_src == TRIG_TIMER) - { - tmp = cmd->convert_arg; - i8253_cascade_ns_to_timer_2div (PCI9111_8254_CLOCK_PERIOD_NS, - &(dev_private->timer_divisor_1), - &(dev_private->timer_divisor_2), - &(cmd->convert_arg), - cmd->flags & TRIG_ROUND_MASK); - if (tmp != cmd->convert_arg) error++; - } - - // There's only one timer on this card, so the scan_begin timer must - // be a multiple of chanlist_len*convert_arg - - if (cmd->scan_begin_src == TRIG_TIMER) { + int tmp; + int error = 0; + int range, reference; + int i; + pci9111_board_struct *board = (pci9111_board_struct *) dev->board_ptr; + + // Step 1 : check if trigger are trivialy valid + + pci9111_check_trigger_src(cmd->start_src, TRIG_NOW); + pci9111_check_trigger_src(cmd->scan_begin_src, + TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT); + pci9111_check_trigger_src(cmd->convert_src, TRIG_TIMER | TRIG_EXT); + pci9111_check_trigger_src(cmd->scan_end_src, TRIG_COUNT); + pci9111_check_trigger_src(cmd->stop_src, TRIG_COUNT | TRIG_NONE); + + if (error) + return 1; + + // step 2 : make sure trigger sources are unique and mutually compatible + + if (cmd->start_src != TRIG_NOW) + error++; + + if ((cmd->scan_begin_src != TRIG_TIMER) && + (cmd->scan_begin_src != TRIG_FOLLOW) && + (cmd->scan_begin_src != TRIG_EXT)) + error++; + + if ((cmd->convert_src != TRIG_TIMER) && (cmd->convert_src != TRIG_EXT)) { + error++; + } + if ((cmd->convert_src == TRIG_TIMER) && + !((cmd->scan_begin_src == TRIG_TIMER) || + (cmd->scan_begin_src == TRIG_FOLLOW))) { + error++; + } + if ((cmd->convert_src == TRIG_EXT) && + !((cmd->scan_begin_src == TRIG_EXT) || + (cmd->scan_begin_src == TRIG_FOLLOW))) { + error++; + } + + if (cmd->scan_end_src != TRIG_COUNT) + error++; + if ((cmd->stop_src != TRIG_COUNT) && (cmd->stop_src != TRIG_NONE)) + error++; + + if (error) + return 2; + + // Step 3 : make sure arguments are trivialy compatible + + if (cmd->chanlist_len < 1) { + cmd->chanlist_len = 1; + error++; + } + + if (cmd->chanlist_len > board->ai_channel_nbr) { + cmd->chanlist_len = board->ai_channel_nbr; + error++; + } + + if ((cmd->start_src == TRIG_NOW) && (cmd->start_arg != 0)) { + cmd->start_arg = 0; + error++; + } + + if ((cmd->convert_src == TRIG_TIMER) && + (cmd->convert_arg < board->ai_acquisition_period_min_ns)) { + cmd->convert_arg = board->ai_acquisition_period_min_ns; + error++; + } + if ((cmd->convert_src == TRIG_EXT) && (cmd->convert_arg != 0)) { + cmd->convert_arg = 0; + error++; + } + + if ((cmd->scan_begin_src == TRIG_TIMER) && + (cmd->scan_begin_arg < board->ai_acquisition_period_min_ns)) { + cmd->scan_begin_arg = board->ai_acquisition_period_min_ns; + error++; + } + if ((cmd->scan_begin_src == TRIG_FOLLOW) && (cmd->scan_begin_arg != 0)) { + cmd->scan_begin_arg = 0; + error++; + } + if ((cmd->scan_begin_src == TRIG_EXT) && (cmd->scan_begin_arg != 0)) { + cmd->scan_begin_arg = 0; + error++; + } + + if ((cmd->scan_end_src == TRIG_COUNT) && + (cmd->scan_end_arg != cmd->chanlist_len)) { + cmd->scan_end_arg = cmd->chanlist_len; + error++; + } + + if ((cmd->stop_src == TRIG_COUNT) && (cmd->stop_arg < 1)) { + cmd->stop_arg = 1; + error++; + } + if ((cmd->stop_src == TRIG_NONE) && (cmd->stop_arg != 0)) { + cmd->stop_arg = 0; + error++; + } + + if (error) + return 3; + + // Step 4 : fix up any arguments + + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer_2div(PCI9111_8254_CLOCK_PERIOD_NS, + &(dev_private->timer_divisor_1), + &(dev_private->timer_divisor_2), + &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + error++; + } + // There's only one timer on this card, so the scan_begin timer must + // be a multiple of chanlist_len*convert_arg + + if (cmd->scan_begin_src == TRIG_TIMER) { unsigned int scan_begin_min; unsigned int scan_begin_arg; @@ -725,7 +696,8 @@ pci9111_ai_do_cmd_test ( comedi_device *dev, if (cmd->scan_begin_arg != scan_begin_min) { if (scan_begin_min < cmd->scan_begin_arg) { - scan_factor = cmd->scan_begin_arg / scan_begin_min; + scan_factor = + cmd->scan_begin_arg / scan_begin_min; scan_begin_arg = scan_factor * scan_begin_min; if (cmd->scan_begin_arg != scan_begin_arg) { cmd->scan_begin_arg = scan_begin_arg; @@ -735,203 +707,200 @@ pci9111_ai_do_cmd_test ( comedi_device *dev, cmd->scan_begin_arg = scan_begin_min; error++; } - } - } + } + } - if (error) return 4; + if (error) + return 4; - // Step 5 : check channel list + // Step 5 : check channel list - if (cmd->chanlist) { + if (cmd->chanlist) { - range=CR_RANGE(cmd->chanlist[0]); - reference=CR_AREF(cmd->chanlist[0]); + range = CR_RANGE(cmd->chanlist[0]); + reference = CR_AREF(cmd->chanlist[0]); - if (cmd->chanlist_len > 1) { - for (i=0;ichanlist_len;i++) - { - if (CR_CHAN(cmd->chanlist[i]) != i) - { - comedi_error (dev, - "entries in chanlist must be consecutive " - "channels,counting upwards from 0\n"); - error++; - } - if (CR_RANGE(cmd->chanlist[i]) != range) - { - comedi_error (dev, - "entries in chanlist must all have the same gain\n"); - error++; - } - if (CR_AREF(cmd->chanlist[i]) != reference) - { - comedi_error (dev, - "entries in chanlist must all have the same reference\n"); - error++; + if (cmd->chanlist_len > 1) { + for (i = 0; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != i) { + comedi_error(dev, + "entries in chanlist must be consecutive " + "channels,counting upwards from 0\n"); + error++; + } + if (CR_RANGE(cmd->chanlist[i]) != range) { + comedi_error(dev, + "entries in chanlist must all have the same gain\n"); + error++; + } + if (CR_AREF(cmd->chanlist[i]) != reference) { + comedi_error(dev, + "entries in chanlist must all have the same reference\n"); + error++; + } + } + } else { + if ((CR_CHAN(cmd->chanlist[0]) > + (board->ai_channel_nbr - 1)) + || (CR_CHAN(cmd->chanlist[0]) < 0)) { + comedi_error(dev, + "channel number is out of limits\n"); + error++; + } + } } - } - } - else - { - if ((CR_CHAN (cmd->chanlist[0]) > (board->ai_channel_nbr -1)) || - (CR_CHAN (cmd->chanlist[0]) < 0)) - { - comedi_error (dev, - "channel number is out of limits\n"); - error++; - } - } - } - - if (error) return 5; - - return 0; -} + if (error) + return 5; + return 0; + +} // // Analog input command // -static int pci9111_ai_do_cmd ( comedi_device *dev, - comedi_subdevice *subdevice) +static int pci9111_ai_do_cmd(comedi_device * dev, comedi_subdevice * subdevice) { - comedi_cmd *async_cmd=&subdevice->async->cmd; - - if (!dev->irq) - { - comedi_error (dev, "no irq assigned for PCI9111, cannot do hardware conversion"); - return -1; - } - - // Set channel scan limit - // - // PCI9111 allows only scanning from channel 0 to channel n - // - // TODO: handle the case of an external multiplexer - // - - if (async_cmd->chanlist_len > 1) - { - pci9111_ai_channel_set ((async_cmd->chanlist_len)-1); - pci9111_autoscan_set (dev, true); - } - else - { - pci9111_ai_channel_set (CR_CHAN (async_cmd->chanlist[0])); - pci9111_autoscan_set (dev, false); - } - - // Set gain - // - // This is the same gain on every channel - // - - pci9111_ai_range_set (CR_RANGE(async_cmd->chanlist[0])); - - /* Set counter */ - - switch (async_cmd->stop_src) - { - case TRIG_COUNT: - dev_private->stop_counter = async_cmd->stop_arg * async_cmd->chanlist_len; - dev_private->stop_is_none = 0; - break; - - case TRIG_NONE: - dev_private->stop_counter = 0; - dev_private->stop_is_none = 1; - break; - - default: - comedi_error(dev, "Invalid stop trigger"); - return -1; + comedi_cmd *async_cmd = &subdevice->async->cmd; + + if (!dev->irq) { + comedi_error(dev, + "no irq assigned for PCI9111, cannot do hardware conversion"); + return -1; } + // Set channel scan limit + // + // PCI9111 allows only scanning from channel 0 to channel n + // + // TODO: handle the case of an external multiplexer + // - // Set timer pacer - - dev_private->scan_delay = 0; - switch (async_cmd->convert_src) - { - case TRIG_TIMER: - i8253_cascade_ns_to_timer_2div (PCI9111_8254_CLOCK_PERIOD_NS, - &(dev_private->timer_divisor_1), - &(dev_private->timer_divisor_2), - &(async_cmd->convert_arg), - async_cmd->flags & TRIG_ROUND_MASK); + if (async_cmd->chanlist_len > 1) { + pci9111_ai_channel_set((async_cmd->chanlist_len) - 1); + pci9111_autoscan_set(dev, true); + } else { + pci9111_ai_channel_set(CR_CHAN(async_cmd->chanlist[0])); + pci9111_autoscan_set(dev, false); + } + + // Set gain + // + // This is the same gain on every channel + // + + pci9111_ai_range_set(CR_RANGE(async_cmd->chanlist[0])); + + /* Set counter */ + + switch (async_cmd->stop_src) { + case TRIG_COUNT: + dev_private->stop_counter = + async_cmd->stop_arg * async_cmd->chanlist_len; + dev_private->stop_is_none = 0; + break; + + case TRIG_NONE: + dev_private->stop_counter = 0; + dev_private->stop_is_none = 1; + break; + + default: + comedi_error(dev, "Invalid stop trigger"); + return -1; + } + + // Set timer pacer + + dev_private->scan_delay = 0; + switch (async_cmd->convert_src) { + case TRIG_TIMER: + i8253_cascade_ns_to_timer_2div(PCI9111_8254_CLOCK_PERIOD_NS, + &(dev_private->timer_divisor_1), + &(dev_private->timer_divisor_2), + &(async_cmd->convert_arg), + async_cmd->flags & TRIG_ROUND_MASK); #ifdef AI_DO_CMD_DEBUG - printk (PCI9111_DRIVER_NAME ": divisors = %d, %d\n", - dev_private->timer_divisor_1,dev_private->timer_divisor_2); + printk(PCI9111_DRIVER_NAME ": divisors = %d, %d\n", + dev_private->timer_divisor_1, + dev_private->timer_divisor_2); #endif + pci9111_trigger_source_set(dev, software); + pci9111_timer_set(dev); + pci9111_fifo_reset(); + pci9111_interrupt_source_set(dev, irq_on_fifo_half_full, + irq_on_timer_tick); + pci9111_trigger_source_set(dev, timer_pacer); + plx9050_interrupt_control(dev_private->lcr_io_base, true, true, + false, true, true); - pci9111_trigger_source_set (dev,software); - pci9111_timer_set (dev); - pci9111_fifo_reset (); - pci9111_interrupt_source_set (dev,irq_on_fifo_half_full, - irq_on_timer_tick); - pci9111_trigger_source_set (dev,timer_pacer); - plx9050_interrupt_control (dev_private->lcr_io_base, true, true, false, true, true); + dev_private->scan_delay = + (async_cmd->scan_begin_arg / (async_cmd->convert_arg * + async_cmd->chanlist_len)) - 1; - dev_private->scan_delay = - (async_cmd->scan_begin_arg / (async_cmd->convert_arg * async_cmd->chanlist_len)) - 1; + break; - break; + case TRIG_EXT: - case TRIG_EXT : + pci9111_trigger_source_set(dev, external); + pci9111_fifo_reset(); + pci9111_interrupt_source_set(dev, irq_on_fifo_half_full, + irq_on_timer_tick); + plx9050_interrupt_control(dev_private->lcr_io_base, true, true, + false, true, true); - pci9111_trigger_source_set (dev, external); - pci9111_fifo_reset (); - pci9111_interrupt_source_set (dev, irq_on_fifo_half_full, - irq_on_timer_tick); - plx9050_interrupt_control (dev_private->lcr_io_base, true, true, false, true, true); + break; - break; - - default : - comedi_error (dev, "Invalid convert trigger"); - return -1; - } + default: + comedi_error(dev, "Invalid convert trigger"); + return -1; + } dev_private->stop_counter *= (1 + dev_private->scan_delay); - dev_private->chanlist_len = async_cmd->chanlist_len; + dev_private->chanlist_len = async_cmd->chanlist_len; dev_private->chunk_counter = 0; - dev_private->chunk_num_samples = dev_private->chanlist_len * (1 + dev_private->scan_delay); + dev_private->chunk_num_samples = + dev_private->chanlist_len * (1 + dev_private->scan_delay); #ifdef AI_DO_CMD_DEBUG - printk (PCI9111_DRIVER_NAME ": start interruptions!\n"); - printk (PCI9111_DRIVER_NAME ": trigger source = %2x\n", + printk(PCI9111_DRIVER_NAME ": start interruptions!\n"); + printk(PCI9111_DRIVER_NAME ": trigger source = %2x\n", pci9111_trigger_and_autoscan_get()); - printk (PCI9111_DRIVER_NAME ": irq source = %2x\n", + printk(PCI9111_DRIVER_NAME ": irq source = %2x\n", pci9111_interrupt_and_fifo_get()); - printk (PCI9111_DRIVER_NAME ": ai_do_cmd\n"); - printk (PCI9111_DRIVER_NAME ": stop counter = %d\n", + printk(PCI9111_DRIVER_NAME ": ai_do_cmd\n"); + printk(PCI9111_DRIVER_NAME ": stop counter = %d\n", dev_private->stop_counter); - printk (PCI9111_DRIVER_NAME ": scan delay = %d\n", + printk(PCI9111_DRIVER_NAME ": scan delay = %d\n", dev_private->scan_delay); - printk (PCI9111_DRIVER_NAME ": chanlist_len = %d\n", + printk(PCI9111_DRIVER_NAME ": chanlist_len = %d\n", dev_private->chanlist_len); - printk (PCI9111_DRIVER_NAME ": chunk num samples = %d\n", + printk(PCI9111_DRIVER_NAME ": chunk num samples = %d\n", dev_private->chunk_num_samples); #endif - return 0; + return 0; } -static void pci9111_ai_munge(comedi_device *dev, comedi_subdevice *s, void *data, - unsigned int num_bytes, unsigned int start_chan_index ) +static void pci9111_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *data, unsigned int num_bytes, unsigned int start_chan_index) { unsigned int i, num_samples = num_bytes / sizeof(sampl_t); sampl_t *array = data; - int resolution = ((pci9111_board_struct *) dev->board_ptr)->ai_resolution; - - for(i = 0; i < num_samples; i++) - { - if(resolution == PCI9111_HR_AI_RESOLUTION) - array[i] = (array[i] & PCI9111_HR_AI_RESOLUTION_MASK) ^ PCI9111_HR_AI_RESOLUTION_2_CMP_BIT; + int resolution = + ((pci9111_board_struct *) dev->board_ptr)->ai_resolution; + + for (i = 0; i < num_samples; i++) { + if (resolution == PCI9111_HR_AI_RESOLUTION) + array[i] = + (array[i] & PCI9111_HR_AI_RESOLUTION_MASK) ^ + PCI9111_HR_AI_RESOLUTION_2_CMP_BIT; else - array[i] = ((array[i] >> 4) & PCI9111_AI_RESOLUTION_MASK) ^ PCI9111_AI_RESOLUTION_2_CMP_BIT; + array[i] = + ((array[i] >> 4) & PCI9111_AI_RESOLUTION_MASK) ^ + PCI9111_AI_RESOLUTION_2_CMP_BIT; } } @@ -943,17 +912,15 @@ static void pci9111_ai_munge(comedi_device *dev, comedi_subdevice *s, void *data #undef INTERRUPT_DEBUG -static irqreturn_t -pci9111_interrupt (int irq, void *p_device PT_REGS_ARG) +static irqreturn_t pci9111_interrupt(int irq, void *p_device PT_REGS_ARG) { - comedi_device *dev=p_device; + comedi_device *dev = p_device; comedi_subdevice *subdevice = dev->read_subdev; comedi_async *async; unsigned long irq_flags; unsigned char intcsr; - if (!dev->attached) - { + if (!dev->attached) { // Ignore interrupt before device fully attached. // Might not even have allocated subdevices yet! return IRQ_NONE; @@ -961,62 +928,63 @@ pci9111_interrupt (int irq, void *p_device PT_REGS_ARG) async = subdevice->async; - comedi_spin_lock_irqsave (&dev->spinlock, irq_flags); + comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); // Check if we are source of interrupt - intcsr = inb (dev_private->lcr_io_base + PLX9050_REGISTER_INTERRUPT_CONTROL); - if (!(((intcsr & PLX9050_PCI_INTERRUPT_ENABLE) != 0) && - (((intcsr & (PLX9050_LINTI1_ENABLE | - PLX9050_LINTI1_STATUS)) == - (PLX9050_LINTI1_ENABLE | - PLX9050_LINTI1_STATUS)) || - ((intcsr & (PLX9050_LINTI2_ENABLE | - PLX9050_LINTI2_STATUS)) == - (PLX9050_LINTI2_ENABLE | - PLX9050_LINTI2_STATUS))))) - { + intcsr = inb(dev_private->lcr_io_base + + PLX9050_REGISTER_INTERRUPT_CONTROL); + if (!(((intcsr & PLX9050_PCI_INTERRUPT_ENABLE) != 0) + && (((intcsr & (PLX9050_LINTI1_ENABLE | + PLX9050_LINTI1_STATUS)) + == + (PLX9050_LINTI1_ENABLE | + PLX9050_LINTI1_STATUS)) + || ((intcsr & (PLX9050_LINTI2_ENABLE | + PLX9050_LINTI2_STATUS)) + == + (PLX9050_LINTI2_ENABLE | + PLX9050_LINTI2_STATUS))))) { // Not the source of the interrupt. // (N.B. not using PLX9050_SOFTWARE_INTERRUPT) - comedi_spin_unlock_irqrestore (&dev->spinlock, irq_flags); + comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); return IRQ_NONE; } if ((intcsr & (PLX9050_LINTI1_ENABLE | PLX9050_LINTI1_STATUS)) == - (PLX9050_LINTI1_ENABLE | PLX9050_LINTI1_STATUS)) - { + (PLX9050_LINTI1_ENABLE | PLX9050_LINTI1_STATUS)) { // Interrupt comes from fifo_half-full signal - if (pci9111_is_fifo_full()) - { - comedi_spin_unlock_irqrestore (&dev->spinlock, irq_flags); - comedi_error (dev, PCI9111_DRIVER_NAME " fifo overflow"); + if (pci9111_is_fifo_full()) { + comedi_spin_unlock_irqrestore(&dev->spinlock, + irq_flags); + comedi_error(dev, PCI9111_DRIVER_NAME " fifo overflow"); pci9111_interrupt_clear(); - pci9111_ai_cancel (dev, subdevice); + pci9111_ai_cancel(dev, subdevice); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; - comedi_event (dev, subdevice); + comedi_event(dev, subdevice); return IRQ_HANDLED; } - if (pci9111_is_fifo_half_full()) - { + if (pci9111_is_fifo_half_full()) { unsigned int num_samples; unsigned int bytes_written = 0; #ifdef INTERRUPT_DEBUG - printk (PCI9111_DRIVER_NAME ": fifo is half full\n"); + printk(PCI9111_DRIVER_NAME ": fifo is half full\n"); #endif - num_samples = PCI9111_FIFO_HALF_SIZE > dev_private->stop_counter && - !dev_private->stop_is_none ? - dev_private->stop_counter : - PCI9111_FIFO_HALF_SIZE; - insw (PCI9111_IO_BASE + PCI9111_REGISTER_AD_FIFO_VALUE, - dev_private->ai_bounce_buffer, - num_samples); + num_samples = + PCI9111_FIFO_HALF_SIZE > + dev_private->stop_counter + && !dev_private->stop_is_none ? dev_private-> + stop_counter : PCI9111_FIFO_HALF_SIZE; + insw(PCI9111_IO_BASE + PCI9111_REGISTER_AD_FIFO_VALUE, + dev_private->ai_bounce_buffer, num_samples); if (dev_private->scan_delay < 1) { - bytes_written = cfc_write_array_to_buffer (subdevice, + bytes_written = + cfc_write_array_to_buffer(subdevice, dev_private->ai_bounce_buffer, num_samples * sizeof(sampl_t)); } else { @@ -1024,39 +992,62 @@ pci9111_interrupt (int irq, void *p_device PT_REGS_ARG) int to_read; while (position < num_samples) { - if (dev_private->chunk_counter < dev_private->chanlist_len) { - to_read = dev_private->chanlist_len - dev_private->chunk_counter; - - if (to_read > num_samples - position) - to_read = num_samples - position; - - bytes_written += cfc_write_array_to_buffer (subdevice, - dev_private->ai_bounce_buffer + position, - to_read * sizeof(sampl_t)); + if (dev_private->chunk_counter < + dev_private->chanlist_len) { + to_read = + dev_private-> + chanlist_len - + dev_private-> + chunk_counter; + + if (to_read > + num_samples - position) + to_read = + num_samples - + position; + + bytes_written += + cfc_write_array_to_buffer + (subdevice, + dev_private-> + ai_bounce_buffer + + position, + to_read * + sizeof(sampl_t)); } else { - to_read = dev_private->chunk_num_samples - dev_private->chunk_counter; - if (to_read > num_samples - position) - to_read = num_samples - position; - - bytes_written += sizeof(sampl_t) * to_read; + to_read = + dev_private-> + chunk_num_samples - + dev_private-> + chunk_counter; + if (to_read > + num_samples - position) + to_read = + num_samples - + position; + + bytes_written += + sizeof(sampl_t) * + to_read; } position += to_read; dev_private->chunk_counter += to_read; - if (dev_private->chunk_counter >= dev_private->chunk_num_samples) + if (dev_private->chunk_counter >= + dev_private->chunk_num_samples) dev_private->chunk_counter = 0; } } - dev_private->stop_counter -= bytes_written / sizeof(sampl_t); + dev_private->stop_counter -= + bytes_written / sizeof(sampl_t); } } - if ((dev_private->stop_counter == 0) && (!dev_private->stop_is_none)) - { + if ((dev_private->stop_counter == 0) && (!dev_private->stop_is_none)) { async->events |= COMEDI_CB_EOA; - pci9111_ai_cancel (dev, subdevice); + pci9111_ai_cancel(dev, subdevice); } /* Very important, otherwise another interrupt request will be inserted @@ -1064,9 +1055,9 @@ pci9111_interrupt (int irq, void *p_device PT_REGS_ARG) pci9111_interrupt_clear(); - comedi_spin_unlock_irqrestore (&dev->spinlock, irq_flags); + comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); - comedi_event (dev, subdevice); + comedi_event(dev, subdevice); return IRQ_HANDLED; } @@ -1083,66 +1074,59 @@ pci9111_interrupt (int irq, void *p_device PT_REGS_ARG) #undef AI_INSN_DEBUG -static int pci9111_ai_insn_read ( comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data ) +static int pci9111_ai_insn_read(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data) { - int resolution = ((pci9111_board_struct *) dev->board_ptr)->ai_resolution; + int resolution = + ((pci9111_board_struct *) dev->board_ptr)->ai_resolution; - int timeout,i; + int timeout, i; #ifdef AI_INSN_DEBUG - printk (PCI9111_DRIVER_NAME ": ai_insn set c/r/n = %2x/%2x/%2x\n", - CR_CHAN((&insn->chanspec)[0]), - CR_RANGE((&insn->chanspec)[0]), - insn->n); + printk(PCI9111_DRIVER_NAME ": ai_insn set c/r/n = %2x/%2x/%2x\n", + CR_CHAN((&insn->chanspec)[0]), + CR_RANGE((&insn->chanspec)[0]), insn->n); #endif - pci9111_ai_channel_set(CR_CHAN((&insn->chanspec)[0])); + pci9111_ai_channel_set(CR_CHAN((&insn->chanspec)[0])); - if ((pci9111_ai_range_get()) != CR_RANGE((&insn->chanspec)[0])) - { - pci9111_ai_range_set(CR_RANGE((&insn->chanspec)[0])); - } + if ((pci9111_ai_range_get()) != CR_RANGE((&insn->chanspec)[0])) { + pci9111_ai_range_set(CR_RANGE((&insn->chanspec)[0])); + } - pci9111_fifo_reset(); + pci9111_fifo_reset(); - for (i=0;in;i++) - { - pci9111_software_trigger(); + for (i = 0; i < insn->n; i++) { + pci9111_software_trigger(); - timeout=PCI9111_AI_INSTANT_READ_TIMEOUT; + timeout = PCI9111_AI_INSTANT_READ_TIMEOUT; - while (timeout--) { - if (!pci9111_is_fifo_empty()) goto conversion_done; - } + while (timeout--) { + if (!pci9111_is_fifo_empty()) + goto conversion_done; + } - comedi_error(dev,"A/D read timeout"); - data[i]=0; - pci9111_fifo_reset(); - return -ETIME; + comedi_error(dev, "A/D read timeout"); + data[i] = 0; + pci9111_fifo_reset(); + return -ETIME; -conversion_done: + conversion_done: - if (resolution==PCI9111_HR_AI_RESOLUTION) - { - data[i] = pci9111_hr_ai_get_data(); - } - else - { - data[i] = pci9111_ai_get_data(); - } - } + if (resolution == PCI9111_HR_AI_RESOLUTION) { + data[i] = pci9111_hr_ai_get_data(); + } else { + data[i] = pci9111_ai_get_data(); + } + } #ifdef AI_INSN_DEBUG - printk (PCI9111_DRIVER_NAME ": ai_insn get c/r/t = %2x/%2x/%2x\n", - pci9111_ai_channel_get(), - pci9111_ai_range_get(), - pci9111_trigger_and_autoscan_get()); + printk(PCI9111_DRIVER_NAME ": ai_insn get c/r/t = %2x/%2x/%2x\n", + pci9111_ai_channel_get(), + pci9111_ai_range_get(), pci9111_trigger_and_autoscan_get()); #endif - return i; + return i; } // @@ -1150,16 +1134,14 @@ conversion_done: // static int -pci9111_ao_insn_write ( comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data ) +pci9111_ao_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int i; - for (i=0; in; i++) { + for (i = 0; i < insn->n; i++) { pci9111_ao_set_data(data[i]); - dev_private->ao_readback=data[i]; + dev_private->ao_readback = data[i]; } return i; @@ -1169,18 +1151,16 @@ pci9111_ao_insn_write ( comedi_device *dev, // Analog output readback // -static int pci9111_ao_insn_read ( comedi_device * dev, - comedi_subdevice * s, - comedi_insn *insn, - lsampl_t *data) +static int pci9111_ao_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i; + int i; - for (i=0; in; i++) { - data[i]=dev_private->ao_readback & PCI9111_AO_RESOLUTION_MASK; - } + for (i = 0; i < insn->n; i++) { + data[i] = dev_private->ao_readback & PCI9111_AO_RESOLUTION_MASK; + } - return i; + return i; } // ------------------------------------------------------------------ @@ -1193,49 +1173,44 @@ static int pci9111_ao_insn_read ( comedi_device * dev, // Digital inputs // -static int pci9111_di_insn_bits ( comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data) +static int pci9111_di_insn_bits(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data) { - lsampl_t bits; + lsampl_t bits; - bits = pci9111_di_get_bits(); - data[1] = bits; + bits = pci9111_di_get_bits(); + data[1] = bits; - return 2; + return 2; } // // Digital outputs // -static int pci9111_do_insn_bits ( comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data) +static int pci9111_do_insn_bits(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data) { - lsampl_t bits; + lsampl_t bits; - // Only set bits that have been masked - // data[0] = mask - // data[1] = bit state + // Only set bits that have been masked + // data[0] = mask + // data[1] = bit state - data[0] &= PCI9111_DO_MASK; + data[0] &= PCI9111_DO_MASK; - bits = subdevice->state; - bits &= ~data[0]; - bits |= data[0] & data[1]; - subdevice->state = bits; + bits = subdevice->state; + bits &= ~data[0]; + bits |= data[0] & data[1]; + subdevice->state = bits; - pci9111_do_set_bits(bits); + pci9111_do_set_bits(bits); - data[1] = bits; + data[1] = bits; - return 2; + return 2; } - // ------------------------------------------------------------------ // // INITIALISATION SECTION @@ -1246,73 +1221,75 @@ static int pci9111_do_insn_bits ( comedi_device *dev, // Reset device // -static int pci9111_reset (comedi_device *dev) +static int pci9111_reset(comedi_device * dev) { - // Set trigger source to software + // Set trigger source to software - plx9050_interrupt_control (dev_private->lcr_io_base, true, true, true, true, false); + plx9050_interrupt_control(dev_private->lcr_io_base, true, true, true, + true, false); - pci9111_trigger_source_set (dev, software); - pci9111_pretrigger_set (dev, false); - pci9111_autoscan_set (dev,false); + pci9111_trigger_source_set(dev, software); + pci9111_pretrigger_set(dev, false); + pci9111_autoscan_set(dev, false); - // Reset 8254 chip + // Reset 8254 chip - dev_private->timer_divisor_1=0; - dev_private->timer_divisor_2=0; + dev_private->timer_divisor_1 = 0; + dev_private->timer_divisor_2 = 0; - pci9111_timer_set (dev); + pci9111_timer_set(dev); - return 0; + return 0; } // // Attach // -// - Register PCI device -// - Declare device driver capability +// - Register PCI device +// - Declare device driver capability // -static int pci9111_attach(comedi_device *dev,comedi_devconfig *it) +static int pci9111_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *subdevice; unsigned long io_base, io_range, lcr_io_base, lcr_io_range; - struct pci_dev* pci_device; - int error,i; - const pci9111_board_struct* board; + struct pci_dev *pci_device; + int error, i; + const pci9111_board_struct *board; - if(alloc_private(dev, sizeof(pci9111_private_data_struct)) < 0) - { + if (alloc_private(dev, sizeof(pci9111_private_data_struct)) < 0) { return -ENOMEM; } // // Probe the device to determine what device in the series it is. // - printk("comedi%d: " PCI9111_DRIVER_NAME " driver\n",dev->minor); + printk("comedi%d: " PCI9111_DRIVER_NAME " driver\n", dev->minor); - for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) - { - if (pci_device->vendor == PCI_VENDOR_ID_ADLINK) - { - for (i= 0; i< pci9111_board_nbr; i++) - { - if(pci9111_boards[i].device_id == pci_device->device) - { + for (pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_device != NULL; + pci_device = + pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { + if (pci_device->vendor == PCI_VENDOR_ID_ADLINK) { + for (i = 0; i < pci9111_board_nbr; i++) { + if (pci9111_boards[i].device_id == + pci_device->device) { // was a particular bus/slot requested? - if((it->options[0] != 0) || (it->options[1] != 0)) - { + if ((it->options[0] != 0) + || (it->options[1] != 0)) { // are we on the wrong bus/slot? - if(pci_device->bus->number != it->options[0] || - PCI_SLOT(pci_device->devfn) != it->options[1]) - { + if (pci_device->bus->number != + it->options[0] + || PCI_SLOT(pci_device-> + devfn) != + it->options[1]) { continue; } } dev->board_ptr = pci9111_boards + i; - board = (pci9111_board_struct *) dev->board_ptr; + board = (pci9111_board_struct *) dev-> + board_ptr; dev_private->pci_device = pci_device; goto found; } @@ -1320,74 +1297,62 @@ static int pci9111_attach(comedi_device *dev,comedi_devconfig *it) } } - printk ("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", - dev->minor,it->options[0], it->options[1]); + printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", + dev->minor, it->options[0], it->options[1]); return -EIO; -found: + found: printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n", dev->minor, pci9111_boards[i].name, pci_device->bus->number, PCI_SLOT(pci_device->devfn), - PCI_FUNC(pci_device->devfn), - pci_device->irq); + PCI_FUNC(pci_device->devfn), pci_device->irq); // TODO: Warn about non-tested boards. - switch(board->device_id) - { + switch (board->device_id) { }; // Read local configuration register base address [PCI_BASE_ADDRESS #1]. - lcr_io_base = pci_resource_start (pci_device, 1); - lcr_io_range = pci_resource_len (pci_device, 1); + lcr_io_base = pci_resource_start(pci_device, 1); + lcr_io_range = pci_resource_len(pci_device, 1); - printk ("comedi%d: local configuration registers at address 0x%4lx [0x%4lx]\n", - dev->minor, - lcr_io_base, - lcr_io_range); + printk("comedi%d: local configuration registers at address 0x%4lx [0x%4lx]\n", dev->minor, lcr_io_base, lcr_io_range); // Enable PCI device and request regions - if(comedi_pci_enable (pci_device, PCI9111_DRIVER_NAME) < 0) - { + if (comedi_pci_enable(pci_device, PCI9111_DRIVER_NAME) < 0) { printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); return -EIO; } - // Read PCI6308 register base address [PCI_BASE_ADDRESS #2]. - io_base = pci_resource_start (pci_device, 2); - io_range = pci_resource_len (pci_device, 2); + io_base = pci_resource_start(pci_device, 2); + io_range = pci_resource_len(pci_device, 2); - printk ("comedi%d: 6503 registers at address 0x%4lx [0x%4lx]\n", - dev->minor, - io_base, - io_range); + printk("comedi%d: 6503 registers at address 0x%4lx [0x%4lx]\n", + dev->minor, io_base, io_range); - dev->iobase=io_base; + dev->iobase = io_base; dev->board_name = board->name; dev_private->io_range = io_range; - dev_private->is_valid=0; - dev_private->lcr_io_base=lcr_io_base; - dev_private->lcr_io_range=lcr_io_range; + dev_private->is_valid = 0; + dev_private->lcr_io_base = lcr_io_base; + dev_private->lcr_io_range = lcr_io_range; pci9111_reset(dev); // Irq setup - dev->irq=0; - if (pci_device->irq>0) - { - if (comedi_request_irq (pci_device->irq, - pci9111_interrupt, - IRQF_SHARED, - PCI9111_DRIVER_NAME, - dev)!=0) - { - printk ("comedi%d: unable to allocate irq %u\n", dev->minor, pci_device->irq); + dev->irq = 0; + if (pci_device->irq > 0) { + if (comedi_request_irq(pci_device->irq, + pci9111_interrupt, + IRQF_SHARED, PCI9111_DRIVER_NAME, dev) != 0) { + printk("comedi%d: unable to allocate irq %u\n", + dev->minor, pci_device->irq); return -EINVAL; } } @@ -1397,14 +1362,14 @@ found: // TODO: Add external multiplexer setup (according to option[2]). // - if((error=alloc_subdevices(dev, 4))<0) - return error; + if ((error = alloc_subdevices(dev, 4)) < 0) + return error; - subdevice = dev->subdevices + 0; + subdevice = dev->subdevices + 0; dev->read_subdev = subdevice; - subdevice->type = COMEDI_SUBD_AI; - subdevice->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_CMD_READ; + subdevice->type = COMEDI_SUBD_AI; + subdevice->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_CMD_READ; // // TODO: Add external multiplexer data @@ -1413,73 +1378,68 @@ found: // else { subdevice->n_chan = this_board->n_aichan; } // - subdevice->n_chan = board->ai_channel_nbr; - subdevice->maxdata = board->ai_resolution_mask; - subdevice->len_chanlist = board->ai_channel_nbr; - subdevice->range_table = board->ai_range_list; - subdevice->cancel = pci9111_ai_cancel; - subdevice->insn_read = pci9111_ai_insn_read; - subdevice->do_cmdtest = pci9111_ai_do_cmd_test; - subdevice->do_cmd = pci9111_ai_do_cmd; - subdevice->munge = pci9111_ai_munge; - - subdevice = dev->subdevices + 1; - subdevice->type = COMEDI_SUBD_AO; - subdevice->subdev_flags = SDF_WRITABLE|SDF_COMMON; - subdevice->n_chan = board->ao_channel_nbr; - subdevice->maxdata = board->ao_resolution_mask; - subdevice->len_chanlist = board->ao_channel_nbr; - subdevice->range_table = board->ao_range_list; - subdevice->insn_write = pci9111_ao_insn_write; - subdevice->insn_read = pci9111_ao_insn_read; - - subdevice = dev->subdevices + 2; - subdevice->type = COMEDI_SUBD_DI; - subdevice->subdev_flags = SDF_READABLE; - subdevice->n_chan = PCI9111_DI_CHANNEL_NBR; - subdevice->maxdata = 1; - subdevice->range_table = &range_digital; - subdevice->insn_bits = pci9111_di_insn_bits; - - subdevice = dev->subdevices + 3; - subdevice->type = COMEDI_SUBD_DO; - subdevice->subdev_flags = SDF_READABLE|SDF_WRITABLE; - subdevice->n_chan = PCI9111_DO_CHANNEL_NBR; - subdevice->maxdata = 1; - subdevice->range_table = &range_digital; - subdevice->insn_bits = pci9111_do_insn_bits; - - dev_private->is_valid = 1; + subdevice->n_chan = board->ai_channel_nbr; + subdevice->maxdata = board->ai_resolution_mask; + subdevice->len_chanlist = board->ai_channel_nbr; + subdevice->range_table = board->ai_range_list; + subdevice->cancel = pci9111_ai_cancel; + subdevice->insn_read = pci9111_ai_insn_read; + subdevice->do_cmdtest = pci9111_ai_do_cmd_test; + subdevice->do_cmd = pci9111_ai_do_cmd; + subdevice->munge = pci9111_ai_munge; + + subdevice = dev->subdevices + 1; + subdevice->type = COMEDI_SUBD_AO; + subdevice->subdev_flags = SDF_WRITABLE | SDF_COMMON; + subdevice->n_chan = board->ao_channel_nbr; + subdevice->maxdata = board->ao_resolution_mask; + subdevice->len_chanlist = board->ao_channel_nbr; + subdevice->range_table = board->ao_range_list; + subdevice->insn_write = pci9111_ao_insn_write; + subdevice->insn_read = pci9111_ao_insn_read; + + subdevice = dev->subdevices + 2; + subdevice->type = COMEDI_SUBD_DI; + subdevice->subdev_flags = SDF_READABLE; + subdevice->n_chan = PCI9111_DI_CHANNEL_NBR; + subdevice->maxdata = 1; + subdevice->range_table = &range_digital; + subdevice->insn_bits = pci9111_di_insn_bits; + + subdevice = dev->subdevices + 3; + subdevice->type = COMEDI_SUBD_DO; + subdevice->subdev_flags = SDF_READABLE | SDF_WRITABLE; + subdevice->n_chan = PCI9111_DO_CHANNEL_NBR; + subdevice->maxdata = 1; + subdevice->range_table = &range_digital; + subdevice->insn_bits = pci9111_do_insn_bits; + + dev_private->is_valid = 1; return 0; } - // // Detach // -static int pci9111_detach(comedi_device *dev) +static int pci9111_detach(comedi_device * dev) { // Reset device - if (dev->private!=0) - { - if (dev_private->is_valid) pci9111_reset(dev); + if (dev->private != 0) { + if (dev_private->is_valid) + pci9111_reset(dev); } - // Release previously allocated irq - if (dev->irq!=0) - { - comedi_free_irq(dev->irq,dev); + if (dev->irq != 0) { + comedi_free_irq(dev->irq, dev); } - if (dev_private!=0 && dev_private->pci_device!=0) - { - if(dev->iobase) - { + if (dev_private != 0 && dev_private->pci_device != 0) { + if (dev->iobase) { comedi_pci_disable(dev_private->pci_device); } pci_dev_put(dev_private->pci_device); @@ -1487,5 +1447,3 @@ static int pci9111_detach(comedi_device *dev) return 0; } - - diff --git a/comedi/drivers/adl_pci9118.c b/comedi/drivers/adl_pci9118.c index 582df2a2..3b728a3b 100644 --- a/comedi/drivers/adl_pci9118.c +++ b/comedi/drivers/adl_pci9118.c @@ -72,7 +72,7 @@ Configuration options: #include "comedi_fc.h" /* paranoid checks are broken */ -#undef PCI9118_PARANOIDCHECK /* if defined, then is used code which control correct channel number on every 12 bit sample */ +#undef PCI9118_PARANOIDCHECK /* if defined, then is used code which control correct channel number on every 12 bit sample */ #undef PCI9118_EXTDEBUG /* if defined then driver prints a lot of messages */ @@ -83,39 +83,38 @@ Configuration options: #define DPRINTK(fmt, args...) #endif +#define IORANGE_9118 64 /* I hope */ +#define PCI9118_CHANLEN 255 /* len of chanlist, some source say 256, but reality looks like 255 :-( */ -#define IORANGE_9118 64 /* I hope */ -#define PCI9118_CHANLEN 255 /* len of chanlist, some source say 256, but reality looks like 255 :-( */ - -#define PCI9118_CNT0 0x00 /* R/W: 8254 couter 0 */ -#define PCI9118_CNT1 0x04 /* R/W: 8254 couter 0 */ -#define PCI9118_CNT2 0x08 /* R/W: 8254 couter 0 */ -#define PCI9118_CNTCTRL 0x0c /* W: 8254 counter control */ -#define PCI9118_AD_DATA 0x10 /* R: A/D data */ -#define PCI9118_DA1 0x10 /* W: D/A registers */ +#define PCI9118_CNT0 0x00 /* R/W: 8254 couter 0 */ +#define PCI9118_CNT1 0x04 /* R/W: 8254 couter 0 */ +#define PCI9118_CNT2 0x08 /* R/W: 8254 couter 0 */ +#define PCI9118_CNTCTRL 0x0c /* W: 8254 counter control */ +#define PCI9118_AD_DATA 0x10 /* R: A/D data */ +#define PCI9118_DA1 0x10 /* W: D/A registers */ #define PCI9118_DA2 0x14 -#define PCI9118_ADSTAT 0x18 /* R: A/D status register */ -#define PCI9118_ADCNTRL 0x18 /* W: A/D control register */ -#define PCI9118_DI 0x1c /* R: digi input register */ -#define PCI9118_DO 0x1c /* W: digi output register */ -#define PCI9118_SOFTTRG 0x20 /* W: soft trigger for A/D */ -#define PCI9118_GAIN 0x24 /* W: A/D gain/channel register */ -#define PCI9118_BURST 0x28 /* W: A/D burst number register */ -#define PCI9118_SCANMOD 0x2c /* W: A/D auto scan mode */ -#define PCI9118_ADFUNC 0x30 /* W: A/D function register */ -#define PCI9118_DELFIFO 0x34 /* W: A/D data FIFO reset */ -#define PCI9118_INTSRC 0x38 /* R: interrupt reason register */ -#define PCI9118_INTCTRL 0x38 /* W: interrupt control register */ +#define PCI9118_ADSTAT 0x18 /* R: A/D status register */ +#define PCI9118_ADCNTRL 0x18 /* W: A/D control register */ +#define PCI9118_DI 0x1c /* R: digi input register */ +#define PCI9118_DO 0x1c /* W: digi output register */ +#define PCI9118_SOFTTRG 0x20 /* W: soft trigger for A/D */ +#define PCI9118_GAIN 0x24 /* W: A/D gain/channel register */ +#define PCI9118_BURST 0x28 /* W: A/D burst number register */ +#define PCI9118_SCANMOD 0x2c /* W: A/D auto scan mode */ +#define PCI9118_ADFUNC 0x30 /* W: A/D function register */ +#define PCI9118_DELFIFO 0x34 /* W: A/D data FIFO reset */ +#define PCI9118_INTSRC 0x38 /* R: interrupt reason register */ +#define PCI9118_INTCTRL 0x38 /* W: interrupt control register */ // bits from A/D control register (PCI9118_ADCNTRL) -#define AdControl_UniP 0x80 /* 1=bipolar, 0=unipolar */ -#define AdControl_Diff 0x40 /* 1=differential, 0= single end inputs */ -#define AdControl_SoftG 0x20 /* 1=8254 counter works, 0=counter stops */ -#define AdControl_ExtG 0x10 /* 1=8254 countrol controlled by TGIN(pin 46), 0=controled by SoftG */ -#define AdControl_ExtM 0x08 /* 1=external hardware trigger (pin 44), 0=internal trigger */ -#define AdControl_TmrTr 0x04 /* 1=8254 is iternal trigger source, 0=software trigger is source (register PCI9118_SOFTTRG) */ -#define AdControl_Int 0x02 /* 1=enable INT, 0=disable */ -#define AdControl_Dma 0x01 /* 1=enable DMA, 0=disable */ +#define AdControl_UniP 0x80 /* 1=bipolar, 0=unipolar */ +#define AdControl_Diff 0x40 /* 1=differential, 0= single end inputs */ +#define AdControl_SoftG 0x20 /* 1=8254 counter works, 0=counter stops */ +#define AdControl_ExtG 0x10 /* 1=8254 countrol controlled by TGIN(pin 46), 0=controled by SoftG */ +#define AdControl_ExtM 0x08 /* 1=external hardware trigger (pin 44), 0=internal trigger */ +#define AdControl_TmrTr 0x04 /* 1=8254 is iternal trigger source, 0=software trigger is source (register PCI9118_SOFTTRG) */ +#define AdControl_Int 0x02 /* 1=enable INT, 0=disable */ +#define AdControl_Dma 0x01 /* 1=enable DMA, 0=disable */ // bits from A/D function register (PCI9118_ADFUNC) #define AdFunction_PDTrg 0x80 /* 1=positive, 0=negative digital trigger (only positive is correct) */ @@ -128,177 +127,178 @@ Configuration options: #define AdFunction_Start 0x01 /* 1=trigger start, 0=trigger stop */ // bits from A/D status register (PCI9118_ADSTAT) -#define AdStatus_nFull 0x100 /* 0=FIFO full (fatal), 1=not full */ -#define AdStatus_nHfull 0x080 /* 0=FIFO half full, 1=FIFO not half full */ -#define AdStatus_nEpty 0x040 /* 0=FIFO empty, 1=FIFO not empty */ -#define AdStatus_Acmp 0x020 /* */ -#define AdStatus_DTH 0x010 /* 1=external digital trigger */ -#define AdStatus_Bover 0x008 /* 1=burst mode overrun (fatal) */ -#define AdStatus_ADOS 0x004 /* 1=A/D over speed (warning) */ -#define AdStatus_ADOR 0x002 /* 1=A/D overrun (fatal) */ -#define AdStatus_ADrdy 0x001 /* 1=A/D already ready, 0=not ready */ +#define AdStatus_nFull 0x100 /* 0=FIFO full (fatal), 1=not full */ +#define AdStatus_nHfull 0x080 /* 0=FIFO half full, 1=FIFO not half full */ +#define AdStatus_nEpty 0x040 /* 0=FIFO empty, 1=FIFO not empty */ +#define AdStatus_Acmp 0x020 /* */ +#define AdStatus_DTH 0x010 /* 1=external digital trigger */ +#define AdStatus_Bover 0x008 /* 1=burst mode overrun (fatal) */ +#define AdStatus_ADOS 0x004 /* 1=A/D over speed (warning) */ +#define AdStatus_ADOR 0x002 /* 1=A/D overrun (fatal) */ +#define AdStatus_ADrdy 0x001 /* 1=A/D already ready, 0=not ready */ // bits for interrupt reason and control (PCI9118_INTSRC, PCI9118_INTCTRL) // 1=interrupt occur, enable source, 0=interrupt not occur, disable source -#define Int_Timer 0x08 /* timer interrupt */ -#define Int_About 0x04 /* about trigger complete */ -#define Int_Hfull 0x02 /* A/D FIFO hlaf full */ -#define Int_DTrg 0x01 /* external digital trigger */ - -#define START_AI_EXT 0x01 /* start measure on external trigger */ -#define STOP_AI_EXT 0x02 /* stop measure on external trigger */ -#define START_AI_INT 0x04 /* start measure on internal trigger */ -#define STOP_AI_INT 0x08 /* stop measure on internal trigger */ - -#define EXTTRG_AI 0 /* ext trg is used by AI */ - -static const comedi_lrange range_pci9118dg_hr={ 8, { - 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) +#define Int_Timer 0x08 /* timer interrupt */ +#define Int_About 0x04 /* about trigger complete */ +#define Int_Hfull 0x02 /* A/D FIFO hlaf full */ +#define Int_DTrg 0x01 /* external digital trigger */ + +#define START_AI_EXT 0x01 /* start measure on external trigger */ +#define STOP_AI_EXT 0x02 /* stop measure on external trigger */ +#define START_AI_INT 0x04 /* start measure on internal trigger */ +#define STOP_AI_INT 0x08 /* stop measure on internal trigger */ + +#define EXTTRG_AI 0 /* ext trg is used by AI */ + +static const comedi_lrange range_pci9118dg_hr = { 8, { + 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 const comedi_lrange range_pci9118hg={ 8, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01) +static const comedi_lrange range_pci9118hg = { 8, { + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01) } }; #define PCI9118_BIPOLAR_RANGES 4 /* used for test on mixture of BIP/UNI ranges */ -static int pci9118_attach(comedi_device *dev,comedi_devconfig *it); -static int pci9118_detach(comedi_device *dev); +static int pci9118_attach(comedi_device * dev, comedi_devconfig * it); +static int pci9118_detach(comedi_device * dev); typedef struct { - const char *name; // board name - int vendor_id; // PCI vendor a device ID of card - int device_id; - int iorange_amcc; // iorange for own S5933 region - int iorange_9118; // pass thru card region size - int n_aichan; // num of A/D chans - int n_aichand; // num of A/D chans in diff mode - int mux_aichan; // num of A/D chans with external multiplexor - int n_aichanlist; // len of chanlist - int n_aochan; // num of D/A chans - int ai_maxdata; // resolution of A/D - int ao_maxdata; // resolution of D/A - const comedi_lrange *rangelist_ai; // rangelist for A/D - const comedi_lrange *rangelist_ao; // rangelist for D/A - unsigned int ai_ns_min; // max sample speed of card v ns - unsigned int ai_pacer_min; // minimal pacer value (c1*c2 or c1 in burst) - int half_fifo_size; // size of FIFO/2 + const char *name; // board name + int vendor_id; // PCI vendor a device ID of card + int device_id; + int iorange_amcc; // iorange for own S5933 region + int iorange_9118; // pass thru card region size + int n_aichan; // num of A/D chans + int n_aichand; // num of A/D chans in diff mode + int mux_aichan; // num of A/D chans with external multiplexor + int n_aichanlist; // len of chanlist + int n_aochan; // num of D/A chans + int ai_maxdata; // resolution of A/D + int ao_maxdata; // resolution of D/A + const comedi_lrange *rangelist_ai; // rangelist for A/D + const comedi_lrange *rangelist_ao; // rangelist for D/A + unsigned int ai_ns_min; // max sample speed of card v ns + unsigned int ai_pacer_min; // minimal pacer value (c1*c2 or c1 in burst) + int half_fifo_size; // size of FIFO/2 } boardtype; static struct pci_device_id pci9118_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMCC, 0x80d9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_AMCC, 0x80d9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci9118_pci_table); -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"pci9118dg", PCI_VENDOR_ID_AMCC, 0x80d9, - AMCC_OP_REG_SIZE, IORANGE_9118, - 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff, - &range_pci9118dg_hr, &range_bipolar10, - 3000, 12, 512 }, + AMCC_OP_REG_SIZE, IORANGE_9118, + 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff, + &range_pci9118dg_hr, &range_bipolar10, + 3000, 12, 512}, {"pci9118hg", PCI_VENDOR_ID_AMCC, 0x80d9, - AMCC_OP_REG_SIZE, IORANGE_9118, - 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff, - &range_pci9118hg, &range_bipolar10, - 3000, 12, 512 }, + AMCC_OP_REG_SIZE, IORANGE_9118, + 16, 8, 256, PCI9118_CHANLEN, 2, 0x0fff, 0x0fff, + &range_pci9118hg, &range_bipolar10, + 3000, 12, 512}, {"pci9118hr", PCI_VENDOR_ID_AMCC, 0x80d9, - AMCC_OP_REG_SIZE, IORANGE_9118, - 16, 8, 256, PCI9118_CHANLEN, 2, 0xffff, 0x0fff, - &range_pci9118dg_hr, &range_bipolar10, - 10000, 40, 512 }, + AMCC_OP_REG_SIZE, IORANGE_9118, + 16, 8, 256, PCI9118_CHANLEN, 2, 0xffff, 0x0fff, + &range_pci9118dg_hr, &range_bipolar10, + 10000, 40, 512}, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -static comedi_driver driver_pci9118={ - driver_name: "adl_pci9118", - module: THIS_MODULE, - attach: pci9118_attach, - detach: pci9118_detach, - num_names: n_boardtypes, - board_name: &boardtypes[0].name, - offset: sizeof(boardtype), +static comedi_driver driver_pci9118 = { + driver_name:"adl_pci9118", + module:THIS_MODULE, + attach:pci9118_attach, + detach:pci9118_detach, + num_names:n_boardtypes, + board_name:&boardtypes[0].name, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pci9118); -typedef struct{ - unsigned long iobase_a; // base+size for AMCC chip - unsigned int master; // master capable - struct pci_dev *pcidev; // ptr to actual pcidev - unsigned int usemux; // we want to use external multiplexor! +typedef struct { + unsigned long iobase_a; // base+size for AMCC chip + unsigned int master; // master capable + struct pci_dev *pcidev; // ptr to actual pcidev + unsigned int usemux; // we want to use external multiplexor! #ifdef PCI9118_PARANOIDCHECK - unsigned short chanlist[PCI9118_CHANLEN+1]; // list of scaned channel - unsigned char chanlistlen; // number of scanlist + unsigned short chanlist[PCI9118_CHANLEN + 1]; // list of scaned channel + unsigned char chanlistlen; // number of scanlist #endif - unsigned char AdControlReg; // A/D control register - unsigned char IntControlReg; // Interrupt control register - unsigned char AdFunctionReg; // A/D function register - char valid; // driver is ok - char ai_neverending; // we do unlimited AI - unsigned int i8254_osc_base; // frequence of onboard oscilator - unsigned int ai_do; // what do AI? 0=nothing, 1 to 4 mode - unsigned int ai_act_scan;// how many scans we finished - unsigned int ai_buf_ptr; // data buffer ptr in samples - unsigned int ai_n_chan;// how many channels is measured - unsigned int ai_n_scanlen;// len of actual scanlist - unsigned int ai_n_realscanlen;// what we must transfer for one outgoing scan include front/back adds - unsigned int ai_act_dmapos; // position in actual real stream - unsigned int ai_add_front; // how many channels we must add before scan to satisfy S&H? - unsigned int ai_add_back; // how many channels we must add before scan to satisfy DMA? - unsigned int *ai_chanlist;// actaul chanlist - unsigned int ai_timer1; - unsigned int ai_timer2; - unsigned int ai_flags; - char ai12_startstop; // measure can start/stop on external trigger - unsigned int ai_divisor1,ai_divisor2; // divisors for start of measure on external start - unsigned int ai_data_len; - sampl_t *ai_data; - sampl_t ao_data[2]; // data output buffer - unsigned int ai_scans; // number of scans to do - char dma_doublebuf; // we can use double buffring - unsigned int dma_actbuf; // which buffer is used now - sampl_t *dmabuf_virt[2]; // pointers to begin of DMA buffer - unsigned long dmabuf_hw[2]; // hw address of DMA buff - unsigned int dmabuf_size[2]; // size of dma buffer in bytes - unsigned int dmabuf_use_size[2]; // which size we may now used for transfer - unsigned int dmabuf_used_size[2]; // which size was trully used - unsigned int dmabuf_panic_size[2]; - unsigned int dmabuf_samples[2]; // size in samples - int dmabuf_pages[2]; // number of pages in buffer - unsigned char cnt0_users; // bit field of 8254 CNT0 users (0-unused, 1-AO, 2-DI, 3-DO) - unsigned char exttrg_users; // bit field of external trigger users (0-AI, 1-AO, 2-DI, 3-DO) - unsigned int cnt0_divisor; // actual CNT0 divisor - void (*int_ai_func)(comedi_device *, comedi_subdevice *,unsigned short, unsigned int, unsigned short); // ptr to actual interrupt AI function - unsigned char ai16bits; // =1 16 bit card - unsigned char usedma; // =1 use DMA transfer and not INT - unsigned char useeoshandle; // =1 change WAKE_EOS DMA transfer to fit on every second - unsigned char usessh; // =1 turn on S&H support - int softsshdelay; // >0 use software S&H, numer is requested delay in ns - unsigned char softsshsample; // polarity of S&H signal in sample state - unsigned char softsshhold; // polarity of S&H signal in hold state - unsigned int ai_maskerr; // which warning was printed - unsigned int ai_maskharderr; // on which error bits stops - unsigned int ai_inttrig_start;// TRIG_INT for start -}pci9118_private; + unsigned char AdControlReg; // A/D control register + unsigned char IntControlReg; // Interrupt control register + unsigned char AdFunctionReg; // A/D function register + char valid; // driver is ok + char ai_neverending; // we do unlimited AI + unsigned int i8254_osc_base; // frequence of onboard oscilator + unsigned int ai_do; // what do AI? 0=nothing, 1 to 4 mode + unsigned int ai_act_scan; // how many scans we finished + unsigned int ai_buf_ptr; // data buffer ptr in samples + unsigned int ai_n_chan; // how many channels is measured + unsigned int ai_n_scanlen; // len of actual scanlist + unsigned int ai_n_realscanlen; // what we must transfer for one outgoing scan include front/back adds + unsigned int ai_act_dmapos; // position in actual real stream + unsigned int ai_add_front; // how many channels we must add before scan to satisfy S&H? + unsigned int ai_add_back; // how many channels we must add before scan to satisfy DMA? + unsigned int *ai_chanlist; // actaul chanlist + unsigned int ai_timer1; + unsigned int ai_timer2; + unsigned int ai_flags; + char ai12_startstop; // measure can start/stop on external trigger + unsigned int ai_divisor1, ai_divisor2; // divisors for start of measure on external start + unsigned int ai_data_len; + sampl_t *ai_data; + sampl_t ao_data[2]; // data output buffer + unsigned int ai_scans; // number of scans to do + char dma_doublebuf; // we can use double buffring + unsigned int dma_actbuf; // which buffer is used now + sampl_t *dmabuf_virt[2]; // pointers to begin of DMA buffer + unsigned long dmabuf_hw[2]; // hw address of DMA buff + unsigned int dmabuf_size[2]; // size of dma buffer in bytes + unsigned int dmabuf_use_size[2]; // which size we may now used for transfer + unsigned int dmabuf_used_size[2]; // which size was trully used + unsigned int dmabuf_panic_size[2]; + unsigned int dmabuf_samples[2]; // size in samples + int dmabuf_pages[2]; // number of pages in buffer + unsigned char cnt0_users; // bit field of 8254 CNT0 users (0-unused, 1-AO, 2-DI, 3-DO) + unsigned char exttrg_users; // bit field of external trigger users (0-AI, 1-AO, 2-DI, 3-DO) + unsigned int cnt0_divisor; // actual CNT0 divisor + void (*int_ai_func) (comedi_device *, comedi_subdevice *, unsigned short, unsigned int, unsigned short); // ptr to actual interrupt AI function + unsigned char ai16bits; // =1 16 bit card + unsigned char usedma; // =1 use DMA transfer and not INT + unsigned char useeoshandle; // =1 change WAKE_EOS DMA transfer to fit on every second + unsigned char usessh; // =1 turn on S&H support + int softsshdelay; // >0 use software S&H, numer is requested delay in ns + unsigned char softsshsample; // polarity of S&H signal in sample state + unsigned char softsshhold; // polarity of S&H signal in hold state + unsigned int ai_maskerr; // which warning was printed + unsigned int ai_maskharderr; // on which error bits stops + unsigned int ai_inttrig_start; // TRIG_INT for start +} pci9118_private; #define devpriv ((pci9118_private *)dev->private) #define this_board ((boardtype *)dev->board_ptr) @@ -309,57 +309,66 @@ typedef struct{ static int check_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist, int frontadd, int backadd); -static int setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, - unsigned int *chanlist,int rot, int frontadd, int backadd, int usedma, char eoshandle); -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2); -static int pci9118_reset(comedi_device *dev); +static int setup_channel_list(comedi_device * dev, comedi_subdevice * s, + int n_chan, unsigned int *chanlist, int rot, int frontadd, int backadd, + int usedma, char eoshandle); +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2); +static int pci9118_reset(comedi_device * dev); static int pci9118_exttrg_add(comedi_device * dev, unsigned char source); static int pci9118_exttrg_del(comedi_device * dev, unsigned char source); static int pci9118_ai_cancel(comedi_device * dev, comedi_subdevice * s); -static void pci9118_calc_divisors(char mode, comedi_device * dev, comedi_subdevice * s, - unsigned int *tim1, unsigned int *tim2, unsigned int flags, - int chans, unsigned int *div1, unsigned int *div2, +static void pci9118_calc_divisors(char mode, comedi_device * dev, + comedi_subdevice * s, unsigned int *tim1, unsigned int *tim2, + unsigned int flags, int chans, unsigned int *div1, unsigned int *div2, char usessh, unsigned int chnsshfront); /* ============================================================================== */ -static int pci9118_insn_read_ai(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci9118_insn_read_ai(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,timeout; + int n, timeout; - devpriv->AdControlReg=AdControl_Int & 0xff; - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC);// positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop + devpriv->AdControlReg = AdControl_Int & 0xff; + devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop - if (!setup_channel_list(dev,s,1,&insn->chanspec, 0, 0, 0, 0, 0)) return -EINVAL; + if (!setup_channel_list(dev, s, 1, &insn->chanspec, 0, 0, 0, 0, 0)) + return -EINVAL; - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO - for (n=0; nn; n++) { - outw(0, dev->iobase+PCI9118_SOFTTRG); /* start conversion */ + for (n = 0; n < insn->n; n++) { + outw(0, dev->iobase + PCI9118_SOFTTRG); /* start conversion */ comedi_udelay(2); - timeout=100; - while (timeout--) { - if (inl(dev->iobase+PCI9118_ADSTAT) & AdStatus_ADrdy) goto conv_finish; + timeout = 100; + while (timeout--) { + if (inl(dev->iobase + PCI9118_ADSTAT) & AdStatus_ADrdy) + goto conv_finish; comedi_udelay(1); - } + } - comedi_error(dev,"A/D insn timeout"); - data[n]=0; - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO - return -ETIME; + comedi_error(dev, "A/D insn timeout"); + data[n] = 0; + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO + return -ETIME; -conv_finish: + conv_finish: if (devpriv->ai16bits) { - data[n] = (inl(dev->iobase+PCI9118_AD_DATA) & 0xffff) ^ 0x8000; + data[n] = + (inl(dev->iobase + + PCI9118_AD_DATA) & 0xffff) ^ 0x8000; } else { - data[n] = (inw(dev->iobase+PCI9118_AD_DATA)>>4) & 0xfff; + data[n] = + (inw(dev->iobase + + PCI9118_AD_DATA) >> 4) & 0xfff; } } - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO return n; } @@ -367,17 +376,21 @@ conv_finish: /* ============================================================================== */ -static int pci9118_insn_write_ao(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci9118_insn_write_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,chanreg,ch; + int n, chanreg, ch; - ch=CR_CHAN(insn->chanspec); - if (ch) { chanreg=PCI9118_DA2;} - else { chanreg=PCI9118_DA1; } + ch = CR_CHAN(insn->chanspec); + if (ch) { + chanreg = PCI9118_DA2; + } else { + chanreg = PCI9118_DA1; + } - for (n=0; nn; n++) { + for (n = 0; n < insn->n; n++) { outl(data[n], dev->iobase + chanreg); - devpriv->ao_data[ch]=data[n]; + devpriv->ao_data[ch] = data[n]; } return n; @@ -386,13 +399,14 @@ static int pci9118_insn_write_ao(comedi_device *dev,comedi_subdevice *s, comedi_ /* ============================================================================== */ -static int pci9118_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int pci9118_insn_read_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,chan; + int n, chan; - chan=CR_CHAN(insn->chanspec); - for (n=0; nn; n++) - data[n]=devpriv->ao_data[chan]; + chan = CR_CHAN(insn->chanspec); + for (n = 0; n < insn->n; n++) + data[n] = devpriv->ao_data[chan]; return n; } @@ -400,7 +414,8 @@ static int pci9118_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comed /* ============================================================================== */ -static int pci9118_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci9118_insn_bits_di(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[1] = inl(dev->iobase + PCI9118_DI) & 0xf; @@ -410,11 +425,12 @@ static int pci9118_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi_i /* ============================================================================== */ -static int pci9118_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci9118_insn_bits_do(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); outl(s->state & 0x0f, dev->iobase + PCI9118_DO); } data[1] = s->state; @@ -425,19 +441,22 @@ static int pci9118_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi_i /* ============================================================================== */ -static void interrupt_pci9118_ai_mode4_switch(comedi_device *dev) +static void interrupt_pci9118_ai_mode4_switch(comedi_device * dev) { - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg|AdFunction_AM; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); + devpriv->AdFunctionReg = + AdFunction_PDTrg | AdFunction_PETrg | AdFunction_AM; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); outl(0x30, dev->iobase + PCI9118_CNTCTRL); - outl((devpriv->dmabuf_hw[1-devpriv->dma_actbuf]>>1)&0xff, dev->iobase + PCI9118_CNT0); - outl((devpriv->dmabuf_hw[1-devpriv->dma_actbuf]>>9)&0xff, dev->iobase + PCI9118_CNT0); - devpriv->AdFunctionReg|=AdFunction_Start; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); + outl((devpriv->dmabuf_hw[1 - devpriv->dma_actbuf] >> 1) & 0xff, + dev->iobase + PCI9118_CNT0); + outl((devpriv->dmabuf_hw[1 - devpriv->dma_actbuf] >> 9) & 0xff, + dev->iobase + PCI9118_CNT0); + devpriv->AdFunctionReg |= AdFunction_Start; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); } -static unsigned int defragment_dma_buffer(comedi_device *dev, comedi_subdevice *s, - sampl_t *dma_buffer, unsigned int num_samples) +static unsigned int defragment_dma_buffer(comedi_device * dev, + comedi_subdevice * s, sampl_t * dma_buffer, unsigned int num_samples) { unsigned int i = 0, j = 0; unsigned int start_pos = devpriv->ai_add_front, @@ -445,16 +464,14 @@ static unsigned int defragment_dma_buffer(comedi_device *dev, comedi_subdevice * unsigned int raw_scanlen = devpriv->ai_add_front + devpriv->ai_n_chan + devpriv->ai_add_back; - for(i = 0; i < num_samples; i++) - { - if(devpriv->ai_act_dmapos >= start_pos && - devpriv->ai_act_dmapos < stop_pos) - { + for (i = 0; i < num_samples; i++) { + if (devpriv->ai_act_dmapos >= start_pos && + devpriv->ai_act_dmapos < stop_pos) { dma_buffer[j++] = dma_buffer[i]; } devpriv->ai_act_dmapos++; devpriv->ai_act_dmapos %= raw_scanlen; - } + } return j; } @@ -462,17 +479,20 @@ static unsigned int defragment_dma_buffer(comedi_device *dev, comedi_subdevice * /* ============================================================================== */ -static unsigned int move_block_from_dma(comedi_device *dev, comedi_subdevice *s, - sampl_t *dma_buffer, unsigned int num_samples) +static unsigned int move_block_from_dma(comedi_device * dev, + comedi_subdevice * s, sampl_t * dma_buffer, unsigned int num_samples) { unsigned int num_bytes; num_samples = defragment_dma_buffer(dev, s, dma_buffer, num_samples); - devpriv->ai_act_scan += (s->async->cur_chan + num_samples) / devpriv->ai_n_scanlen; + devpriv->ai_act_scan += + (s->async->cur_chan + num_samples) / devpriv->ai_n_scanlen; s->async->cur_chan += num_samples; s->async->cur_chan %= devpriv->ai_n_scanlen; - num_bytes = cfc_write_array_to_buffer(s, dma_buffer, num_samples * sizeof(sampl_t)); - if(num_bytes < num_samples * sizeof(sampl_t)) + num_bytes = + cfc_write_array_to_buffer(s, dma_buffer, + num_samples * sizeof(sampl_t)); + if (num_bytes < num_samples * sizeof(sampl_t)) return -1; return 0; } @@ -480,27 +500,29 @@ static unsigned int move_block_from_dma(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static char pci9118_decode_error_status(comedi_device *dev,comedi_subdevice *s,unsigned char m) +static char pci9118_decode_error_status(comedi_device * dev, + comedi_subdevice * s, unsigned char m) { if (m & 0x100) { - comedi_error(dev,"A/D FIFO Full status (Fatal Error!)"); - devpriv->ai_maskerr&=~0x100L; + comedi_error(dev, "A/D FIFO Full status (Fatal Error!)"); + devpriv->ai_maskerr &= ~0x100L; } if (m & 0x008) { - comedi_error(dev,"A/D Burst Mode Overrun Status (Fatal Error!)"); - devpriv->ai_maskerr&=~0x008L; + comedi_error(dev, + "A/D Burst Mode Overrun Status (Fatal Error!)"); + devpriv->ai_maskerr &= ~0x008L; } if (m & 0x004) { - comedi_error(dev,"A/D Over Speed Status (Warning!)"); - devpriv->ai_maskerr&=~0x004L; + comedi_error(dev, "A/D Over Speed Status (Warning!)"); + devpriv->ai_maskerr &= ~0x004L; } if (m & 0x002) { - comedi_error(dev,"A/D Overrun Status (Fatal Error!)"); - devpriv->ai_maskerr&=~0x002L; + comedi_error(dev, "A/D Overrun Status (Fatal Error!)"); + devpriv->ai_maskerr &= ~0x002L; } if (m & devpriv->ai_maskharderr) { - s->async->events|=COMEDI_CB_ERROR|COMEDI_CB_EOA; - pci9118_ai_cancel(dev,s); + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + pci9118_ai_cancel(dev, s); comedi_event(dev, s); return 1; } @@ -508,14 +530,14 @@ static char pci9118_decode_error_status(comedi_device *dev,comedi_subdevice *s,u return 0; } -static void pci9118_ai_munge(comedi_device *dev, comedi_subdevice *s, void *data, - unsigned int num_bytes, unsigned int start_chan_index ) +static void pci9118_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *data, unsigned int num_bytes, unsigned int start_chan_index) { unsigned int i, num_samples = num_bytes / sizeof(sampl_t); sampl_t *array = data; for (i = 0; i < num_samples; i++) { - if(devpriv->usedma) + if (devpriv->usedma) array[i] = be16_to_cpu(array[i]); if (devpriv->ai16bits) { array[i] ^= 0x8000; @@ -528,25 +550,29 @@ static void pci9118_ai_munge(comedi_device *dev, comedi_subdevice *s, void *data /* ============================================================================== */ -static void interrupt_pci9118_ai_onesample(comedi_device *dev,comedi_subdevice *s, - unsigned short int_adstat, unsigned int int_amcc, unsigned short int_daq) +static void interrupt_pci9118_ai_onesample(comedi_device * dev, + comedi_subdevice * s, unsigned short int_adstat, unsigned int int_amcc, + unsigned short int_daq) { register sampl_t sampl; - s->async->events=0; + s->async->events = 0; if (int_adstat & devpriv->ai_maskerr) - if (pci9118_decode_error_status(dev,s,int_adstat)) + if (pci9118_decode_error_status(dev, s, int_adstat)) return; - sampl=inw(dev->iobase+PCI9118_AD_DATA); + sampl = inw(dev->iobase + PCI9118_AD_DATA); #ifdef PCI9118_PARANOIDCHECK if (devpriv->ai16bits == 0) { - if ((sampl & 0x000f)!=devpriv->chanlist[s->async->cur_chan]) { // data dropout! - rt_printk("comedi: A/D SAMPL - data dropout: received channel %d, expected %d!\n",sampl & 0x000f, devpriv->chanlist[s->async->cur_chan]); - s->async->events|=COMEDI_CB_ERROR|COMEDI_CB_EOA; - pci9118_ai_cancel(dev,s); + if ((sampl & 0x000f) != devpriv->chanlist[s->async->cur_chan]) { // data dropout! + rt_printk + ("comedi: A/D SAMPL - data dropout: received channel %d, expected %d!\n", + sampl & 0x000f, + devpriv->chanlist[s->async->cur_chan]); + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + pci9118_ai_cancel(dev, s); comedi_event(dev, s); return; } @@ -559,7 +585,7 @@ static void interrupt_pci9118_ai_onesample(comedi_device *dev,comedi_subdevice * devpriv->ai_act_scan++; if (!(devpriv->ai_neverending)) if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ - pci9118_ai_cancel(dev,s); + pci9118_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; } } @@ -571,66 +597,73 @@ static void interrupt_pci9118_ai_onesample(comedi_device *dev,comedi_subdevice * /* ============================================================================== */ -static void interrupt_pci9118_ai_dma(comedi_device *dev,comedi_subdevice *s, - unsigned short int_adstat, unsigned int int_amcc, unsigned short int_daq) +static void interrupt_pci9118_ai_dma(comedi_device * dev, comedi_subdevice * s, + unsigned short int_adstat, unsigned int int_amcc, + unsigned short int_daq) { - unsigned int next_dma_buf, samplesinbuf, sampls, m; + unsigned int next_dma_buf, samplesinbuf, sampls, m; - if (int_amcc&MASTER_ABORT_INT) { - comedi_error(dev,"AMCC IRQ - MASTER DMA ABORT!"); - s->async->events|=COMEDI_CB_ERROR|COMEDI_CB_EOA; - pci9118_ai_cancel(dev,s); + if (int_amcc & MASTER_ABORT_INT) { + comedi_error(dev, "AMCC IRQ - MASTER DMA ABORT!"); + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + pci9118_ai_cancel(dev, s); comedi_event(dev, s); return; } - if (int_amcc&TARGET_ABORT_INT) { - comedi_error(dev,"AMCC IRQ - TARGET DMA ABORT!"); - s->async->events|=COMEDI_CB_ERROR|COMEDI_CB_EOA; - pci9118_ai_cancel(dev,s); + if (int_amcc & TARGET_ABORT_INT) { + comedi_error(dev, "AMCC IRQ - TARGET DMA ABORT!"); + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + pci9118_ai_cancel(dev, s); comedi_event(dev, s); return; } if (int_adstat & devpriv->ai_maskerr) -// if (int_adstat & 0x106) - if (pci9118_decode_error_status(dev,s,int_adstat)) +// if (int_adstat & 0x106) + if (pci9118_decode_error_status(dev, s, int_adstat)) return; - samplesinbuf=devpriv->dmabuf_use_size[devpriv->dma_actbuf]>>1; // number of received real samples -// DPRINTK("dma_actbuf=%d\n",devpriv->dma_actbuf); + samplesinbuf = devpriv->dmabuf_use_size[devpriv->dma_actbuf] >> 1; // number of received real samples +// DPRINTK("dma_actbuf=%d\n",devpriv->dma_actbuf); if (devpriv->dma_doublebuf) { // switch DMA buffers if is used double buffering - next_dma_buf=1-devpriv->dma_actbuf; - outl(devpriv->dmabuf_hw[next_dma_buf], devpriv->iobase_a+AMCC_OP_REG_MWAR); - outl(devpriv->dmabuf_use_size[next_dma_buf], devpriv->iobase_a+AMCC_OP_REG_MWTC); - devpriv->dmabuf_used_size[next_dma_buf]=devpriv->dmabuf_use_size[next_dma_buf]; - if (devpriv->ai_do==4) + next_dma_buf = 1 - devpriv->dma_actbuf; + outl(devpriv->dmabuf_hw[next_dma_buf], + devpriv->iobase_a + AMCC_OP_REG_MWAR); + outl(devpriv->dmabuf_use_size[next_dma_buf], + devpriv->iobase_a + AMCC_OP_REG_MWTC); + devpriv->dmabuf_used_size[next_dma_buf] = + devpriv->dmabuf_use_size[next_dma_buf]; + if (devpriv->ai_do == 4) interrupt_pci9118_ai_mode4_switch(dev); } if (samplesinbuf) { - m = devpriv->ai_data_len >> 1; // how many samples is to end of buffer -// DPRINTK("samps=%d m=%d %d %d\n",samplesinbuf,m,s->async->buf_int_count,s->async->buf_int_ptr); - sampls=m; - move_block_from_dma(dev, s, devpriv->dmabuf_virt[devpriv->dma_actbuf], samplesinbuf); - m=m-sampls; // m= how many samples was transfered + m = devpriv->ai_data_len >> 1; // how many samples is to end of buffer +// DPRINTK("samps=%d m=%d %d %d\n",samplesinbuf,m,s->async->buf_int_count,s->async->buf_int_ptr); + sampls = m; + move_block_from_dma(dev, s, + devpriv->dmabuf_virt[devpriv->dma_actbuf], + samplesinbuf); + m = m - sampls; // m= how many samples was transfered } -// DPRINTK("YYY\n"); +// DPRINTK("YYY\n"); if (!devpriv->ai_neverending) - if ( devpriv->ai_act_scan>=devpriv->ai_scans ) { /* all data sampled */ - pci9118_ai_cancel(dev,s); - s->async->events|=COMEDI_CB_EOA; + if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ + pci9118_ai_cancel(dev, s); + s->async->events |= COMEDI_CB_EOA; } - - if (devpriv->dma_doublebuf) { // switch dma buffers - devpriv->dma_actbuf=1-devpriv->dma_actbuf; - } else { // restart DMA if is not used double buffering - outl(devpriv->dmabuf_hw[0], devpriv->iobase_a+AMCC_OP_REG_MWAR); - outl(devpriv->dmabuf_use_size[0], devpriv->iobase_a+AMCC_OP_REG_MWTC); - if (devpriv->ai_do==4) + if (devpriv->dma_doublebuf) { // switch dma buffers + devpriv->dma_actbuf = 1 - devpriv->dma_actbuf; + } else { // restart DMA if is not used double buffering + outl(devpriv->dmabuf_hw[0], + devpriv->iobase_a + AMCC_OP_REG_MWAR); + outl(devpriv->dmabuf_use_size[0], + devpriv->iobase_a + AMCC_OP_REG_MWTC); + if (devpriv->ai_do == 4) interrupt_pci9118_ai_mode4_switch(dev); } @@ -643,42 +676,48 @@ static void interrupt_pci9118_ai_dma(comedi_device *dev,comedi_subdevice *s, static irqreturn_t interrupt_pci9118(int irq, void *d PT_REGS_ARG) { comedi_device *dev = d; - unsigned int int_daq=0,int_amcc,int_adstat; + unsigned int int_daq = 0, int_amcc, int_adstat; if (!dev->attached) return IRQ_NONE; // not fully initialized - int_daq=inl(dev->iobase+PCI9118_INTSRC) & 0xf; // get IRQ reasons from card - int_amcc=inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR); // get INT register from AMCC chip + int_daq = inl(dev->iobase + PCI9118_INTSRC) & 0xf; // get IRQ reasons from card + int_amcc = inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR); // get INT register from AMCC chip -// DPRINTK("INT daq=0x%01x amcc=0x%08x MWAR=0x%08x MWTC=0x%08x ADSTAT=0x%02x ai_do=%d\n", int_daq, int_amcc, inl(devpriv->iobase_a+AMCC_OP_REG_MWAR), inl(devpriv->iobase_a+AMCC_OP_REG_MWTC), inw(dev->iobase+PCI9118_ADSTAT)&0x1ff,devpriv->ai_do); +// DPRINTK("INT daq=0x%01x amcc=0x%08x MWAR=0x%08x MWTC=0x%08x ADSTAT=0x%02x ai_do=%d\n", int_daq, int_amcc, inl(devpriv->iobase_a+AMCC_OP_REG_MWAR), inl(devpriv->iobase_a+AMCC_OP_REG_MWTC), inw(dev->iobase+PCI9118_ADSTAT)&0x1ff,devpriv->ai_do); - if ((!int_daq)&&(!(int_amcc&ANY_S593X_INT))) + if ((!int_daq) && (!(int_amcc & ANY_S593X_INT))) return IRQ_NONE; // interrupt from other source - outl(int_amcc|0x00ff0000, devpriv->iobase_a+AMCC_OP_REG_INTCSR); // shutdown IRQ reasons in AMCC + outl(int_amcc | 0x00ff0000, devpriv->iobase_a + AMCC_OP_REG_INTCSR); // shutdown IRQ reasons in AMCC - int_adstat=inw(dev->iobase+PCI9118_ADSTAT)&0x1ff; // get STATUS register + int_adstat = inw(dev->iobase + PCI9118_ADSTAT) & 0x1ff; // get STATUS register if (devpriv->ai_do) { if (devpriv->ai12_startstop) - if ((int_adstat&AdStatus_DTH)&&(int_daq&Int_DTrg)) { // start stop of measure - if (devpriv->ai12_startstop&START_AI_EXT) { - devpriv->ai12_startstop&=~START_AI_EXT; - if (!(devpriv->ai12_startstop&STOP_AI_EXT)) - pci9118_exttrg_del(dev,EXTTRG_AI); // deactivate EXT trigger + if ((int_adstat & AdStatus_DTH) && (int_daq & Int_DTrg)) { // start stop of measure + if (devpriv->ai12_startstop & START_AI_EXT) { + devpriv->ai12_startstop &= + ~START_AI_EXT; + if (!(devpriv->ai12_startstop & + STOP_AI_EXT)) + pci9118_exttrg_del(dev, EXTTRG_AI); // deactivate EXT trigger start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, devpriv->ai_divisor2); // start pacer - outl(devpriv->AdControlReg, dev->iobase+PCI9118_ADCNTRL); + outl(devpriv->AdControlReg, + dev->iobase + PCI9118_ADCNTRL); } else { - if (devpriv->ai12_startstop&STOP_AI_EXT) { - devpriv->ai12_startstop&=~STOP_AI_EXT; - pci9118_exttrg_del(dev,EXTTRG_AI); // deactivate EXT trigger - devpriv->ai_neverending=0; //well, on next interrupt from DMA/EOC measure will stop + if (devpriv-> + ai12_startstop & STOP_AI_EXT) { + devpriv->ai12_startstop &= + ~STOP_AI_EXT; + pci9118_exttrg_del(dev, EXTTRG_AI); // deactivate EXT trigger + devpriv->ai_neverending = 0; //well, on next interrupt from DMA/EOC measure will stop } } } - (devpriv->int_ai_func)(dev,dev->subdevices + 0,int_adstat,int_amcc,int_daq); + (devpriv->int_ai_func) (dev, dev->subdevices + 0, int_adstat, + int_amcc, int_daq); } return IRQ_HANDLED; @@ -687,21 +726,23 @@ static irqreturn_t interrupt_pci9118(int irq, void *d PT_REGS_ARG) /* ============================================================================== */ -static int pci9118_ai_inttrig(comedi_device *dev,comedi_subdevice *s, +static int pci9118_ai_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { - if (trignum!=devpriv->ai_inttrig_start) return -EINVAL; + if (trignum != devpriv->ai_inttrig_start) + return -EINVAL; - devpriv->ai12_startstop&=~START_AI_INT; - s->async->inttrig=NULL; + devpriv->ai12_startstop &= ~START_AI_INT; + s->async->inttrig = NULL; - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); - if (devpriv->ai_do!=3) { - start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, devpriv->ai_divisor2); - devpriv->AdControlReg|=AdControl_SoftG; + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); + if (devpriv->ai_do != 3) { + start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, + devpriv->ai_divisor2); + devpriv->AdControlReg |= AdControl_SoftG; } - outl(devpriv->AdControlReg, dev->iobase+PCI9118_ADCNTRL); + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); return 1; } @@ -709,237 +750,257 @@ static int pci9118_ai_inttrig(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static int pci9118_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int pci9118_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; - int tmp,divisor1,divisor2; + int err = 0; + int tmp, divisor1, divisor2; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_EXT|TRIG_INT; - if (!cmd->start_src || tmp!=cmd->start_src) err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_EXT | TRIG_INT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; if (devpriv->master) { - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT|TRIG_FOLLOW; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW; } else { cmd->scan_begin_src &= TRIG_FOLLOW; } - if (!cmd->scan_begin_src || tmp!=cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; if (devpriv->master) { - cmd->convert_src &= TRIG_TIMER|TRIG_EXT|TRIG_NOW; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT | TRIG_NOW; } else { - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; } - if (!cmd->convert_src || tmp!=cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp!=cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE|TRIG_EXT; - if (!cmd->stop_src || tmp!=cmd->stop_src) err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE | TRIG_EXT; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if (err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if (cmd->start_src!=TRIG_NOW && - cmd->start_src!=TRIG_INT && - cmd->start_src!=TRIG_EXT) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src != TRIG_NOW && + cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT) { + cmd->start_src = TRIG_NOW; err++; } - if (cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT && - cmd->scan_begin_src!=TRIG_INT && - cmd->scan_begin_src!=TRIG_FOLLOW) { - cmd->scan_begin_src=TRIG_FOLLOW; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_INT && + cmd->scan_begin_src != TRIG_FOLLOW) { + cmd->scan_begin_src = TRIG_FOLLOW; err++; } - if (cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT && - cmd->convert_src!=TRIG_NOW) { - cmd->convert_src=TRIG_TIMER; + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) { + cmd->convert_src = TRIG_TIMER; err++; } - if (cmd->scan_end_src!=TRIG_COUNT) { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - if (cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_INT && - cmd->stop_src!=TRIG_EXT) { - cmd->stop_src=TRIG_COUNT; + if (cmd->stop_src != TRIG_NONE && + cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_INT && cmd->stop_src != TRIG_EXT) { + cmd->stop_src = TRIG_COUNT; err++; } - if (cmd->start_src==TRIG_EXT && - cmd->scan_begin_src==TRIG_EXT) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT) { + cmd->start_src = TRIG_NOW; err++; } - if (cmd->start_src==TRIG_INT && - cmd->scan_begin_src==TRIG_INT) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src == TRIG_INT && cmd->scan_begin_src == TRIG_INT) { + cmd->start_src = TRIG_NOW; err++; } - if ((cmd->scan_begin_src&(TRIG_TIMER|TRIG_EXT)) && - (!(cmd->convert_src&(TRIG_TIMER|TRIG_NOW)))) { - cmd->convert_src=TRIG_TIMER; + if ((cmd->scan_begin_src & (TRIG_TIMER | TRIG_EXT)) && + (!(cmd->convert_src & (TRIG_TIMER | TRIG_NOW)))) { + cmd->convert_src = TRIG_TIMER; err++; } - if ((cmd->scan_begin_src==TRIG_FOLLOW) && - (!(cmd->convert_src&(TRIG_TIMER|TRIG_EXT)))) { - cmd->convert_src=TRIG_TIMER; + if ((cmd->scan_begin_src == TRIG_FOLLOW) && + (!(cmd->convert_src & (TRIG_TIMER | TRIG_EXT)))) { + cmd->convert_src = TRIG_TIMER; err++; } - if (cmd->stop_src==TRIG_EXT && - cmd->scan_begin_src==TRIG_EXT) { - cmd->stop_src=TRIG_COUNT; + if (cmd->stop_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT) { + cmd->stop_src = TRIG_COUNT; err++; } - if (err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if (cmd->start_src&(TRIG_NOW|TRIG_EXT)) - if (cmd->start_arg!=0) { - cmd->start_arg=0; + if (cmd->start_src & (TRIG_NOW | TRIG_EXT)) + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if (cmd->scan_begin_src&(TRIG_FOLLOW|TRIG_EXT)) - if (cmd->scan_begin_arg!=0) { - cmd->scan_begin_arg=0; + if (cmd->scan_begin_src & (TRIG_FOLLOW | TRIG_EXT)) + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - if ((cmd->scan_begin_src==TRIG_TIMER) && - (cmd->convert_src==TRIG_TIMER) && - (cmd->scan_end_arg==1)) { - cmd->scan_begin_src=TRIG_FOLLOW; - cmd->convert_arg=cmd->scan_begin_arg; - cmd->scan_begin_arg=0; + if ((cmd->scan_begin_src == TRIG_TIMER) && + (cmd->convert_src == TRIG_TIMER) && (cmd->scan_end_arg == 1)) { + cmd->scan_begin_src = TRIG_FOLLOW; + cmd->convert_arg = cmd->scan_begin_arg; + cmd->scan_begin_arg = 0; } - if (cmd->scan_begin_src==TRIG_TIMER) - if (cmd->scan_begin_argai_ns_min) { - cmd->scan_begin_arg=this_board->ai_ns_min; + if (cmd->scan_begin_src == TRIG_TIMER) + if (cmd->scan_begin_arg < this_board->ai_ns_min) { + cmd->scan_begin_arg = this_board->ai_ns_min; err++; } - if (cmd->scan_begin_src==TRIG_EXT) + if (cmd->scan_begin_src == TRIG_EXT) if (cmd->scan_begin_arg) { - cmd->scan_begin_arg=0; - err++; - if (cmd->scan_end_arg>65535) { - cmd->scan_end_arg=65535; + cmd->scan_begin_arg = 0; err++; + if (cmd->scan_end_arg > 65535) { + cmd->scan_end_arg = 65535; + err++; } } - if (cmd->convert_src&(TRIG_TIMER|TRIG_NOW)) - if (cmd->convert_argai_ns_min) { - cmd->convert_arg=this_board->ai_ns_min; + if (cmd->convert_src & (TRIG_TIMER | TRIG_NOW)) + if (cmd->convert_arg < this_board->ai_ns_min) { + cmd->convert_arg = this_board->ai_ns_min; err++; } - if (cmd->convert_src==TRIG_EXT) + if (cmd->convert_src == TRIG_EXT) if (cmd->convert_arg) { - cmd->convert_arg=0; + cmd->convert_arg = 0; err++; } - if (cmd->stop_src==TRIG_COUNT) { + if (cmd->stop_src == TRIG_COUNT) { if (!cmd->stop_arg) { - cmd->stop_arg=1; + cmd->stop_arg = 1; err++; } - } else { /* TRIG_NONE */ - if (cmd->stop_arg!=0) { - cmd->stop_arg=0; + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } if (!cmd->chanlist_len) { - cmd->chanlist_len=1; + cmd->chanlist_len = 1; err++; } - if (cmd->chanlist_len>this_board->n_aichanlist) { - cmd->chanlist_len=this_board->n_aichanlist; + if (cmd->chanlist_len > this_board->n_aichanlist) { + cmd->chanlist_len = this_board->n_aichanlist; err++; } - if (cmd->scan_end_argchanlist_len) { - cmd->scan_end_arg=cmd->chanlist_len; + if (cmd->scan_end_arg < cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; err++; } if ((cmd->scan_end_arg % cmd->chanlist_len)) { - cmd->scan_end_arg=cmd->chanlist_len*(cmd->scan_end_arg/cmd->chanlist_len); + cmd->scan_end_arg = + cmd->chanlist_len * (cmd->scan_end_arg / + cmd->chanlist_len); err++; } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if (cmd->scan_begin_src==TRIG_TIMER) { - tmp=cmd->scan_begin_arg; -// rt_printk("S1 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); - i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,&divisor1,&divisor2,&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); -// rt_printk("S2 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); - if(cmd->scan_begin_argai_ns_min) - cmd->scan_begin_arg=this_board->ai_ns_min; - if(tmp!=cmd->scan_begin_arg)err++; - } - - if (cmd->convert_src&(TRIG_TIMER|TRIG_NOW)) { - tmp=cmd->convert_arg; - i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,&divisor1,&divisor2,&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); -// rt_printk("s1 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); - if (cmd->convert_argai_ns_min) - cmd->convert_arg=this_board->ai_ns_min; - if (tmp!=cmd->convert_arg) err++; - if (cmd->scan_begin_src==TRIG_TIMER && cmd->convert_src==TRIG_NOW) { - if (cmd->convert_arg==0) { - if (cmd->scan_begin_argai_ns_min*(cmd->scan_end_arg+2)) { - cmd->scan_begin_arg=this_board->ai_ns_min*(cmd->scan_end_arg+2); -// rt_printk("s2 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; +// rt_printk("S1 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); + i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1, + &divisor2, &cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); +// rt_printk("S2 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); + if (cmd->scan_begin_arg < this_board->ai_ns_min) + cmd->scan_begin_arg = this_board->ai_ns_min; + if (tmp != cmd->scan_begin_arg) + err++; + } + + if (cmd->convert_src & (TRIG_TIMER | TRIG_NOW)) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); +// rt_printk("s1 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + if (tmp != cmd->convert_arg) + err++; + if (cmd->scan_begin_src == TRIG_TIMER + && cmd->convert_src == TRIG_NOW) { + if (cmd->convert_arg == 0) { + if (cmd->scan_begin_arg < + this_board->ai_ns_min * + (cmd->scan_end_arg + 2)) { + cmd->scan_begin_arg = + this_board->ai_ns_min * + (cmd->scan_end_arg + 2); +// rt_printk("s2 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); err++; } } else { - if (cmd->scan_begin_argconvert_arg*cmd->chanlist_len) { - cmd->scan_begin_arg=cmd->convert_arg*cmd->chanlist_len; -// rt_printk("s3 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); + if (cmd->scan_begin_arg < + cmd->convert_arg * cmd->chanlist_len) { + cmd->scan_begin_arg = + cmd->convert_arg * + cmd->chanlist_len; +// rt_printk("s3 timer1=%u timer2=%u\n",cmd->scan_begin_arg,cmd->convert_arg); err++; } } } } - if (err) return 4; + if (err) + return 4; if (cmd->chanlist) if (!check_channel_list(dev, s, cmd->chanlist_len, - cmd->chanlist,0,0)) return 5; // incorrect channels list + cmd->chanlist, 0, 0)) + return 5; // incorrect channels list return 0; } @@ -947,82 +1008,112 @@ static int pci9118_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd /* ============================================================================== */ -static int Compute_and_setup_dma(comedi_device *dev) +static int Compute_and_setup_dma(comedi_device * dev) { - unsigned int dmalen0,dmalen1,i; + unsigned int dmalen0, dmalen1, i; DPRINTK("adl_pci9118 EDBG: BGN: Compute_and_setup_dma()\n"); - dmalen0=devpriv->dmabuf_size[0]; - dmalen1=devpriv->dmabuf_size[1]; - DPRINTK("1 dmalen0=%d dmalen1=%d ai_data_len=%d\n", dmalen0, dmalen1, devpriv->ai_data_len); + dmalen0 = devpriv->dmabuf_size[0]; + dmalen1 = devpriv->dmabuf_size[1]; + DPRINTK("1 dmalen0=%d dmalen1=%d ai_data_len=%d\n", dmalen0, dmalen1, + devpriv->ai_data_len); // isn't output buff smaller that our DMA buff? - if (dmalen0>(devpriv->ai_data_len)) { - dmalen0=devpriv->ai_data_len&~3L; // allign to 32bit down + if (dmalen0 > (devpriv->ai_data_len)) { + dmalen0 = devpriv->ai_data_len & ~3L; // allign to 32bit down } - if (dmalen1>(devpriv->ai_data_len)) { - dmalen1=devpriv->ai_data_len&~3L; // allign to 32bit down + if (dmalen1 > (devpriv->ai_data_len)) { + dmalen1 = devpriv->ai_data_len & ~3L; // allign to 32bit down } DPRINTK("2 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); // we want wake up every scan? if (devpriv->ai_flags & TRIG_WAKE_EOS) { - if (dmalen0<(devpriv->ai_n_realscanlen<<1)) { + if (dmalen0 < (devpriv->ai_n_realscanlen << 1)) { // uff, too short DMA buffer, disable EOS support! - devpriv->ai_flags&=(~TRIG_WAKE_EOS); - rt_printk("comedi%d: WAR: DMA0 buf too short, cann't support TRIG_WAKE_EOS (%d<%d)\n",dev->minor,dmalen0,devpriv->ai_n_realscanlen<<1); + devpriv->ai_flags &= (~TRIG_WAKE_EOS); + rt_printk + ("comedi%d: WAR: DMA0 buf too short, cann't support TRIG_WAKE_EOS (%d<%d)\n", + dev->minor, dmalen0, + devpriv->ai_n_realscanlen << 1); } else { // short first DMA buffer to one scan - dmalen0=devpriv->ai_n_realscanlen<<1; - DPRINTK("21 dmalen0=%d ai_n_realscanlen=%d useeoshandle=%d\n", dmalen0, devpriv->ai_n_realscanlen,devpriv->useeoshandle); - if (devpriv->useeoshandle) dmalen0+=2; - if (dmalen0<4) { - rt_printk("comedi%d: ERR: DMA0 buf len bug? (%d<4)\n",dev->minor,dmalen0); - dmalen0=4; + dmalen0 = devpriv->ai_n_realscanlen << 1; + DPRINTK("21 dmalen0=%d ai_n_realscanlen=%d useeoshandle=%d\n", dmalen0, devpriv->ai_n_realscanlen, devpriv->useeoshandle); + if (devpriv->useeoshandle) + dmalen0 += 2; + if (dmalen0 < 4) { + rt_printk + ("comedi%d: ERR: DMA0 buf len bug? (%d<4)\n", + dev->minor, dmalen0); + dmalen0 = 4; } } } if (devpriv->ai_flags & TRIG_WAKE_EOS) { - if (dmalen1<(devpriv->ai_n_realscanlen<<1)) { + if (dmalen1 < (devpriv->ai_n_realscanlen << 1)) { // uff, too short DMA buffer, disable EOS support! - devpriv->ai_flags&=(~TRIG_WAKE_EOS); - rt_printk("comedi%d: WAR: DMA1 buf too short, cann't support TRIG_WAKE_EOS (%d<%d)\n",dev->minor,dmalen1,devpriv->ai_n_realscanlen<<1); + devpriv->ai_flags &= (~TRIG_WAKE_EOS); + rt_printk + ("comedi%d: WAR: DMA1 buf too short, cann't support TRIG_WAKE_EOS (%d<%d)\n", + dev->minor, dmalen1, + devpriv->ai_n_realscanlen << 1); } else { // short second DMA buffer to one scan - dmalen1=devpriv->ai_n_realscanlen<<1; - DPRINTK("22 dmalen1=%d ai_n_realscanlen=%d useeoshandle=%d\n", dmalen1, devpriv->ai_n_realscanlen,devpriv->useeoshandle); - if (devpriv->useeoshandle) dmalen1-=2; - if (dmalen1<4) { - rt_printk("comedi%d: ERR: DMA1 buf len bug? (%d<4)\n",dev->minor,dmalen1); - dmalen1=4; + dmalen1 = devpriv->ai_n_realscanlen << 1; + DPRINTK("22 dmalen1=%d ai_n_realscanlen=%d useeoshandle=%d\n", dmalen1, devpriv->ai_n_realscanlen, devpriv->useeoshandle); + if (devpriv->useeoshandle) + dmalen1 -= 2; + if (dmalen1 < 4) { + rt_printk + ("comedi%d: ERR: DMA1 buf len bug? (%d<4)\n", + dev->minor, dmalen1); + dmalen1 = 4; } } } DPRINTK("3 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); // transfer without TRIG_WAKE_EOS - if (!(devpriv->ai_flags&TRIG_WAKE_EOS)) { + if (!(devpriv->ai_flags & TRIG_WAKE_EOS)) { // if it's possible then allign DMA buffers to length of scan - i=dmalen0; - dmalen0=(dmalen0/(devpriv->ai_n_realscanlen<<1))*(devpriv->ai_n_realscanlen<<1); - dmalen0&=~3L; - if (!dmalen0) dmalen0=i; // uff. very long scan? - i=dmalen1; - dmalen1=(dmalen1/(devpriv->ai_n_realscanlen<<1))*(devpriv->ai_n_realscanlen<<1); - dmalen1&=~3L; - if (!dmalen1) dmalen1=i; // uff. very long scan? + i = dmalen0; + dmalen0 = + (dmalen0 / (devpriv->ai_n_realscanlen << 1)) * + (devpriv->ai_n_realscanlen << 1); + dmalen0 &= ~3L; + if (!dmalen0) + dmalen0 = i; // uff. very long scan? + i = dmalen1; + dmalen1 = + (dmalen1 / (devpriv->ai_n_realscanlen << 1)) * + (devpriv->ai_n_realscanlen << 1); + dmalen1 &= ~3L; + if (!dmalen1) + dmalen1 = i; // uff. very long scan? // if measure isn't neverending then test, if it whole fits into one or two DMA buffers if (!devpriv->ai_neverending) { // fits whole measure into one DMA buffer? - if (dmalen0>((devpriv->ai_n_realscanlen<<1)*devpriv->ai_scans)) { + if (dmalen0 > + ((devpriv->ai_n_realscanlen << 1) * + devpriv->ai_scans)) { DPRINTK("3.0 ai_n_realscanlen=%d ai_scans=%d \n", devpriv->ai_n_realscanlen, devpriv->ai_scans); - dmalen0=(devpriv->ai_n_realscanlen<<1)*devpriv->ai_scans; - DPRINTK("3.1 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); - dmalen0&=~3L; - } else { // fits whole measure into two DMA buffer? - if (dmalen1>((devpriv->ai_n_realscanlen<<1)*devpriv->ai_scans-dmalen0)) - dmalen1=(devpriv->ai_n_realscanlen<<1)*devpriv->ai_scans-dmalen0; - DPRINTK("3.2 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); - dmalen1&=~3L; + dmalen0 = + (devpriv->ai_n_realscanlen << 1) * + devpriv->ai_scans; + DPRINTK("3.1 dmalen0=%d dmalen1=%d \n", dmalen0, + dmalen1); + dmalen0 &= ~3L; + } else { // fits whole measure into two DMA buffer? + if (dmalen1 > + ((devpriv->ai_n_realscanlen << 1) * + devpriv->ai_scans - dmalen0)) + dmalen1 = + (devpriv-> + ai_n_realscanlen << 1) * + devpriv->ai_scans - dmalen0; + DPRINTK("3.2 dmalen0=%d dmalen1=%d \n", dmalen0, + dmalen1); + dmalen1 &= ~3L; } } } @@ -1030,30 +1121,39 @@ static int Compute_and_setup_dma(comedi_device *dev) DPRINTK("4 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); // these DMA buffer size we'll be used - devpriv->dma_actbuf=0; - devpriv->dmabuf_use_size[0]=dmalen0; - devpriv->dmabuf_use_size[1]=dmalen1; + devpriv->dma_actbuf = 0; + devpriv->dmabuf_use_size[0] = dmalen0; + devpriv->dmabuf_use_size[1] = dmalen1; DPRINTK("5 dmalen0=%d dmalen1=%d \n", dmalen0, dmalen1); #if 0 - if (devpriv->ai_n_scanlenhalf_fifo_size) { - devpriv->dmabuf_panic_size[0]=(this_board->half_fifo_size/devpriv->ai_n_scanlen+1)*devpriv->ai_n_scanlen*sizeof(sampl_t); - devpriv->dmabuf_panic_size[1]=(this_board->half_fifo_size/devpriv->ai_n_scanlen+1)*devpriv->ai_n_scanlen*sizeof(sampl_t); + if (devpriv->ai_n_scanlen < this_board->half_fifo_size) { + devpriv->dmabuf_panic_size[0] = + (this_board->half_fifo_size / devpriv->ai_n_scanlen + + 1) * devpriv->ai_n_scanlen * sizeof(sampl_t); + devpriv->dmabuf_panic_size[1] = + (this_board->half_fifo_size / devpriv->ai_n_scanlen + + 1) * devpriv->ai_n_scanlen * sizeof(sampl_t); } else { - devpriv->dmabuf_panic_size[0]=(devpriv->ai_n_scanlen<<1)%devpriv->dmabuf_size[0]; - devpriv->dmabuf_panic_size[1]=(devpriv->ai_n_scanlen<<1)%devpriv->dmabuf_size[1]; + devpriv->dmabuf_panic_size[0] = + (devpriv->ai_n_scanlen << 1) % devpriv->dmabuf_size[0]; + devpriv->dmabuf_panic_size[1] = + (devpriv->ai_n_scanlen << 1) % devpriv->dmabuf_size[1]; } #endif - outl(inl(devpriv->iobase_a+AMCC_OP_REG_MCSR)&(~EN_A2P_TRANSFERS), devpriv->iobase_a+AMCC_OP_REG_MCSR); // stop DMA - outl(devpriv->dmabuf_hw[0], devpriv->iobase_a+AMCC_OP_REG_MWAR); - outl(devpriv->dmabuf_use_size[0], devpriv->iobase_a+AMCC_OP_REG_MWTC); + outl(inl(devpriv->iobase_a + AMCC_OP_REG_MCSR) & (~EN_A2P_TRANSFERS), devpriv->iobase_a + AMCC_OP_REG_MCSR); // stop DMA + outl(devpriv->dmabuf_hw[0], devpriv->iobase_a + AMCC_OP_REG_MWAR); + outl(devpriv->dmabuf_use_size[0], devpriv->iobase_a + AMCC_OP_REG_MWTC); // init DMA transfer - outl(0x00000000|AINT_WRITE_COMPL, devpriv->iobase_a+AMCC_OP_REG_INTCSR); -// outl(0x02000000|AINT_WRITE_COMPL, devpriv->iobase_a+AMCC_OP_REG_INTCSR); + outl(0x00000000 | AINT_WRITE_COMPL, + devpriv->iobase_a + AMCC_OP_REG_INTCSR); +// outl(0x02000000|AINT_WRITE_COMPL, devpriv->iobase_a+AMCC_OP_REG_INTCSR); - outl(inl(devpriv->iobase_a+AMCC_OP_REG_MCSR)|RESET_A2P_FLAGS|A2P_HI_PRIORITY|EN_A2P_TRANSFERS, devpriv->iobase_a+AMCC_OP_REG_MCSR); - outl(inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR)|EN_A2P_TRANSFERS, devpriv->iobase_a+AMCC_OP_REG_INTCSR); // allow bus mastering + outl(inl(devpriv->iobase_a + + AMCC_OP_REG_MCSR) | RESET_A2P_FLAGS | A2P_HI_PRIORITY | + EN_A2P_TRANSFERS, devpriv->iobase_a + AMCC_OP_REG_MCSR); + outl(inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR) | EN_A2P_TRANSFERS, devpriv->iobase_a + AMCC_OP_REG_INTCSR); // allow bus mastering DPRINTK("adl_pci9118 EDBG: END: Compute_and_setup_dma()\n"); return 0; @@ -1064,48 +1164,50 @@ static int Compute_and_setup_dma(comedi_device *dev) */ static int pci9118_ai_docmd_sampl(comedi_device * dev, comedi_subdevice * s) { - DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_docmd_sampl(%d,) [%d]\n",dev->minor,devpriv->ai_do); - switch (devpriv->ai_do) { + DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_docmd_sampl(%d,) [%d]\n", + dev->minor, devpriv->ai_do); + switch (devpriv->ai_do) { case 1: - devpriv->AdControlReg|=AdControl_TmrTr; + devpriv->AdControlReg |= AdControl_TmrTr; break; case 2: - comedi_error(dev,"pci9118_ai_docmd_sampl() mode 2 bug!\n"); + comedi_error(dev, "pci9118_ai_docmd_sampl() mode 2 bug!\n"); return -EIO; case 3: - devpriv->AdControlReg|=AdControl_ExtM; + devpriv->AdControlReg |= AdControl_ExtM; break; case 4: - comedi_error(dev,"pci9118_ai_docmd_sampl() mode 4 bug!\n"); + comedi_error(dev, "pci9118_ai_docmd_sampl() mode 4 bug!\n"); return -EIO; default: - comedi_error(dev,"pci9118_ai_docmd_sampl() mode number bug!\n"); + comedi_error(dev, + "pci9118_ai_docmd_sampl() mode number bug!\n"); return -EIO; }; - devpriv->int_ai_func=interrupt_pci9118_ai_onesample; //transfer function + devpriv->int_ai_func = interrupt_pci9118_ai_onesample; //transfer function if (devpriv->ai12_startstop) - pci9118_exttrg_add(dev,EXTTRG_AI); // activate EXT trigger + pci9118_exttrg_add(dev, EXTTRG_AI); // activate EXT trigger - if ((devpriv->ai_do==1)||(devpriv->ai_do==2)) - devpriv->IntControlReg|=Int_Timer; + if ((devpriv->ai_do == 1) || (devpriv->ai_do == 2)) + devpriv->IntControlReg |= Int_Timer; - devpriv->AdControlReg|=AdControl_Int; + devpriv->AdControlReg |= AdControl_Int; - outl(inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR)|0x1f00, devpriv->iobase_a+AMCC_OP_REG_INTCSR); // allow INT in AMCC + outl(inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR) | 0x1f00, devpriv->iobase_a + AMCC_OP_REG_INTCSR); // allow INT in AMCC - if (!(devpriv->ai12_startstop&(START_AI_EXT|START_AI_INT))) { - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); - if (devpriv->ai_do!=3) { - start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, devpriv->ai_divisor2); - devpriv->AdControlReg|=AdControl_SoftG; + if (!(devpriv->ai12_startstop & (START_AI_EXT | START_AI_INT))) { + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); + if (devpriv->ai_do != 3) { + start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, + devpriv->ai_divisor2); + devpriv->AdControlReg |= AdControl_SoftG; } - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); } - DPRINTK("adl_pci9118 EDBG: END: pci9118_ai_docmd_sampl()\n"); return 0; } @@ -1115,54 +1217,66 @@ static int pci9118_ai_docmd_sampl(comedi_device * dev, comedi_subdevice * s) */ static int pci9118_ai_docmd_dma(comedi_device * dev, comedi_subdevice * s) { - DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_docmd_dma(%d,) [%d,%d]\n",dev->minor,devpriv->ai_do,devpriv->usedma); + DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_docmd_dma(%d,) [%d,%d]\n", + dev->minor, devpriv->ai_do, devpriv->usedma); Compute_and_setup_dma(dev); switch (devpriv->ai_do) { case 1: - devpriv->AdControlReg|=((AdControl_TmrTr|AdControl_Dma) & 0xff); + devpriv->AdControlReg |= + ((AdControl_TmrTr | AdControl_Dma) & 0xff); break; case 2: - devpriv->AdControlReg|=((AdControl_TmrTr|AdControl_Dma) & 0xff); - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg|AdFunction_BM|AdFunction_BS; - if (devpriv->usessh&&(!devpriv->softsshdelay)) - devpriv->AdFunctionReg|=AdFunction_BSSH; - outl(devpriv->ai_n_realscanlen, dev->iobase+PCI9118_BURST); + devpriv->AdControlReg |= + ((AdControl_TmrTr | AdControl_Dma) & 0xff); + devpriv->AdFunctionReg = + AdFunction_PDTrg | AdFunction_PETrg | AdFunction_BM | + AdFunction_BS; + if (devpriv->usessh && (!devpriv->softsshdelay)) + devpriv->AdFunctionReg |= AdFunction_BSSH; + outl(devpriv->ai_n_realscanlen, dev->iobase + PCI9118_BURST); break; case 3: - devpriv->AdControlReg|=((AdControl_ExtM|AdControl_Dma) & 0xff); - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg; + devpriv->AdControlReg |= + ((AdControl_ExtM | AdControl_Dma) & 0xff); + devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg; break; case 4: - devpriv->AdControlReg|=((AdControl_TmrTr|AdControl_Dma) & 0xff); - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg|AdFunction_AM; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); + devpriv->AdControlReg |= + ((AdControl_TmrTr | AdControl_Dma) & 0xff); + devpriv->AdFunctionReg = + AdFunction_PDTrg | AdFunction_PETrg | AdFunction_AM; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); outl(0x30, dev->iobase + PCI9118_CNTCTRL); - outl((devpriv->dmabuf_hw[0]>>1)&0xff, dev->iobase + PCI9118_CNT0); - outl((devpriv->dmabuf_hw[0]>>9)&0xff, dev->iobase + PCI9118_CNT0); - devpriv->AdFunctionReg|=AdFunction_Start; + outl((devpriv->dmabuf_hw[0] >> 1) & 0xff, + dev->iobase + PCI9118_CNT0); + outl((devpriv->dmabuf_hw[0] >> 9) & 0xff, + dev->iobase + PCI9118_CNT0); + devpriv->AdFunctionReg |= AdFunction_Start; break; default: - comedi_error(dev,"pci9118_ai_docmd_dma() mode number bug!\n"); + comedi_error(dev, "pci9118_ai_docmd_dma() mode number bug!\n"); return -EIO; }; if (devpriv->ai12_startstop) { - pci9118_exttrg_add(dev,EXTTRG_AI); // activate EXT trigger + pci9118_exttrg_add(dev, EXTTRG_AI); // activate EXT trigger } - devpriv->int_ai_func=interrupt_pci9118_ai_dma; //transfer function + devpriv->int_ai_func = interrupt_pci9118_ai_dma; //transfer function - outl(0x02000000|AINT_WRITE_COMPL, devpriv->iobase_a+AMCC_OP_REG_INTCSR); + outl(0x02000000 | AINT_WRITE_COMPL, + devpriv->iobase_a + AMCC_OP_REG_INTCSR); - if (!(devpriv->ai12_startstop&(START_AI_EXT|START_AI_INT))) { - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); - if (devpriv->ai_do!=3) { - start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, devpriv->ai_divisor2); - devpriv->AdControlReg|=AdControl_SoftG; + if (!(devpriv->ai12_startstop & (START_AI_EXT | START_AI_INT))) { + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); + if (devpriv->ai_do != 3) { + start_pacer(dev, devpriv->ai_do, devpriv->ai_divisor1, + devpriv->ai_divisor2); + devpriv->AdControlReg |= AdControl_SoftG; } - outl(devpriv->AdControlReg, dev->iobase+PCI9118_ADCNTRL); + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); } DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_docmd_dma()\n"); @@ -1172,176 +1286,200 @@ static int pci9118_ai_docmd_dma(comedi_device * dev, comedi_subdevice * s) /* ============================================================================== */ -static int pci9118_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int pci9118_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; - unsigned int addchans=0; - int ret=0; - - DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_cmd(%d,)\n",dev->minor); - devpriv->ai12_startstop=0; - devpriv->ai_flags=cmd->flags; - devpriv->ai_n_chan=cmd->chanlist_len; - devpriv->ai_n_scanlen=cmd->scan_end_arg; - devpriv->ai_chanlist=cmd->chanlist; - devpriv->ai_data=s->async->prealloc_buf; - devpriv->ai_data_len=s->async->prealloc_bufsz; - devpriv->ai_timer1=0; - devpriv->ai_timer2=0; - devpriv->ai_add_front=0; - devpriv->ai_add_back=0; - devpriv->ai_maskerr=0x10e; + comedi_cmd *cmd = &s->async->cmd; + unsigned int addchans = 0; + int ret = 0; + + DPRINTK("adl_pci9118 EDBG: BGN: pci9118_ai_cmd(%d,)\n", dev->minor); + devpriv->ai12_startstop = 0; + devpriv->ai_flags = cmd->flags; + devpriv->ai_n_chan = cmd->chanlist_len; + devpriv->ai_n_scanlen = cmd->scan_end_arg; + devpriv->ai_chanlist = cmd->chanlist; + devpriv->ai_data = s->async->prealloc_buf; + devpriv->ai_data_len = s->async->prealloc_bufsz; + devpriv->ai_timer1 = 0; + devpriv->ai_timer2 = 0; + devpriv->ai_add_front = 0; + devpriv->ai_add_back = 0; + devpriv->ai_maskerr = 0x10e; // prepare for start/stop conditions - if (cmd->start_src==TRIG_EXT) devpriv->ai12_startstop|=START_AI_EXT; - if (cmd->stop_src==TRIG_EXT) { - devpriv->ai_neverending=1; - devpriv->ai12_startstop|=STOP_AI_EXT; + if (cmd->start_src == TRIG_EXT) + devpriv->ai12_startstop |= START_AI_EXT; + if (cmd->stop_src == TRIG_EXT) { + devpriv->ai_neverending = 1; + devpriv->ai12_startstop |= STOP_AI_EXT; } - if (cmd->start_src==TRIG_INT) { - devpriv->ai12_startstop|=START_AI_INT; - devpriv->ai_inttrig_start=cmd->start_arg; - s->async->inttrig=pci9118_ai_inttrig; + if (cmd->start_src == TRIG_INT) { + devpriv->ai12_startstop |= START_AI_INT; + devpriv->ai_inttrig_start = cmd->start_arg; + s->async->inttrig = pci9118_ai_inttrig; } #if 0 - if (cmd->stop_src==TRIG_INT) { - devpriv->ai_neverending=1; - devpriv->ai12_startstop|=STOP_AI_INT; + if (cmd->stop_src == TRIG_INT) { + devpriv->ai_neverending = 1; + devpriv->ai12_startstop |= STOP_AI_INT; } #endif - if (cmd->stop_src==TRIG_NONE) devpriv->ai_neverending=1; - if (cmd->stop_src==TRIG_COUNT) { devpriv->ai_scans=cmd->stop_arg; devpriv->ai_neverending=0; } - else { devpriv->ai_scans=0; } + if (cmd->stop_src == TRIG_NONE) + devpriv->ai_neverending = 1; + if (cmd->stop_src == TRIG_COUNT) { + devpriv->ai_scans = cmd->stop_arg; + devpriv->ai_neverending = 0; + } else { + devpriv->ai_scans = 0; + } - // use sample&hold signal? - if (cmd->convert_src==TRIG_NOW) { devpriv->usessh=1; } // yes - else { devpriv->usessh=0; } // no + // use sample&hold signal? + if (cmd->convert_src == TRIG_NOW) { + devpriv->usessh = 1; + } // yes + else { + devpriv->usessh = 0; + } // no DPRINTK("1 neverending=%d scans=%u usessh=%d ai_startstop=0x%2x\n", - devpriv->ai_neverending, devpriv->ai_scans, devpriv->usessh, devpriv->ai12_startstop); + devpriv->ai_neverending, devpriv->ai_scans, devpriv->usessh, + devpriv->ai12_startstop); // use additional sample at end of every scan to satisty DMA 32 bit transfer? - devpriv->ai_add_front=0; - devpriv->ai_add_back=0; - devpriv->useeoshandle=0; + devpriv->ai_add_front = 0; + devpriv->ai_add_back = 0; + devpriv->useeoshandle = 0; if (devpriv->master) { - devpriv->usedma=1; - if ((cmd->flags&TRIG_WAKE_EOS) && - (devpriv->ai_n_scanlen==1)) { - if (cmd->convert_src==TRIG_NOW) { - devpriv->ai_add_back=1; + devpriv->usedma = 1; + if ((cmd->flags & TRIG_WAKE_EOS) && + (devpriv->ai_n_scanlen == 1)) { + if (cmd->convert_src == TRIG_NOW) { + devpriv->ai_add_back = 1; } - if (cmd->convert_src==TRIG_TIMER) { - devpriv->usedma=0; // use INT transfer if scanlist have only one channel + if (cmd->convert_src == TRIG_TIMER) { + devpriv->usedma = 0; // use INT transfer if scanlist have only one channel } } - if ((cmd->flags&TRIG_WAKE_EOS) && - (devpriv->ai_n_scanlen&1) && - (devpriv->ai_n_scanlen>1)) { - if (cmd->scan_begin_src==TRIG_FOLLOW) { - //vpriv->useeoshandle=1; // change DMA transfer block to fit EOS on every second call - devpriv->usedma=0; // XXX maybe can be corrected to use 16 bit DMA - } else { // well, we must insert one sample to end of EOS to meet 32 bit transfer - devpriv->ai_add_back=1; - } + if ((cmd->flags & TRIG_WAKE_EOS) && + (devpriv->ai_n_scanlen & 1) && + (devpriv->ai_n_scanlen > 1)) { + if (cmd->scan_begin_src == TRIG_FOLLOW) { + //vpriv->useeoshandle=1; // change DMA transfer block to fit EOS on every second call + devpriv->usedma = 0; // XXX maybe can be corrected to use 16 bit DMA + } else { // well, we must insert one sample to end of EOS to meet 32 bit transfer + devpriv->ai_add_back = 1; + } } - } else { // interrupt transfer don't need any correction - devpriv->usedma=0; + } else { // interrupt transfer don't need any correction + devpriv->usedma = 0; } // we need software S&H signal? It add two samples before every scan as minimum - if (devpriv->usessh&&devpriv->softsshdelay) { - devpriv->ai_add_front=2; - if ((devpriv->usedma==1)&&(devpriv->ai_add_back==1)) {// move it to front + if (devpriv->usessh && devpriv->softsshdelay) { + devpriv->ai_add_front = 2; + if ((devpriv->usedma == 1) && (devpriv->ai_add_back == 1)) { // move it to front devpriv->ai_add_front++; - devpriv->ai_add_back=0; + devpriv->ai_add_back = 0; } - if (cmd->convert_argai_ns_min) cmd->convert_arg=this_board->ai_ns_min; - addchans=devpriv->softsshdelay/cmd->convert_arg; - if (devpriv->softsshdelay%cmd->convert_arg) addchans++; - if (addchans>(devpriv->ai_add_front-1)) { // uff, still short :-( - devpriv->ai_add_front=addchans+1; - if (devpriv->usedma==1) - if ((devpriv->ai_add_front+devpriv->ai_n_chan+devpriv->ai_add_back)&1) devpriv->ai_add_front++; // round up to 32 bit + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + addchans = devpriv->softsshdelay / cmd->convert_arg; + if (devpriv->softsshdelay % cmd->convert_arg) + addchans++; + if (addchans > (devpriv->ai_add_front - 1)) { // uff, still short :-( + devpriv->ai_add_front = addchans + 1; + if (devpriv->usedma == 1) + if ((devpriv->ai_add_front + + devpriv->ai_n_chan + + devpriv->ai_add_back) & 1) + devpriv->ai_add_front++; // round up to 32 bit } - } // well, we now know what must be all added + } // well, we now know what must be all added - devpriv->ai_n_realscanlen= // what we must take from card in real to have ai_n_scanlen on output? - (devpriv->ai_add_front+devpriv->ai_n_chan+devpriv->ai_add_back)* - (devpriv->ai_n_scanlen / devpriv->ai_n_chan); + devpriv->ai_n_realscanlen = // what we must take from card in real to have ai_n_scanlen on output? + (devpriv->ai_add_front + devpriv->ai_n_chan + + devpriv->ai_add_back) * (devpriv->ai_n_scanlen / + devpriv->ai_n_chan); DPRINTK("2 usedma=%d realscan=%d af=%u n_chan=%d ab=%d n_scanlen=%d\n", devpriv->usedma, - devpriv->ai_n_realscanlen, devpriv->ai_add_front, devpriv->ai_n_chan, - devpriv->ai_add_back, devpriv->ai_n_scanlen); + devpriv->ai_n_realscanlen, devpriv->ai_add_front, + devpriv->ai_n_chan, devpriv->ai_add_back, + devpriv->ai_n_scanlen); // check and setup channel list - if (!check_channel_list(dev, s, devpriv->ai_n_chan, devpriv->ai_chanlist, - devpriv->ai_add_front, devpriv->ai_add_back)) return -EINVAL; - if (!setup_channel_list(dev, s, devpriv->ai_n_chan, devpriv->ai_chanlist, - 0, devpriv->ai_add_front, devpriv->ai_add_back, devpriv->usedma, - devpriv->useeoshandle)) return -EINVAL; - + if (!check_channel_list(dev, s, devpriv->ai_n_chan, + devpriv->ai_chanlist, devpriv->ai_add_front, + devpriv->ai_add_back)) + return -EINVAL; + if (!setup_channel_list(dev, s, devpriv->ai_n_chan, + devpriv->ai_chanlist, 0, devpriv->ai_add_front, + devpriv->ai_add_back, devpriv->usedma, + devpriv->useeoshandle)) + return -EINVAL; // compute timers settings // simplest way, fr=4Mhz/(tim1*tim2), channel manipulation without timers effect - if (((cmd->scan_begin_src==TRIG_FOLLOW)||(cmd->scan_begin_src==TRIG_EXT)||(cmd->scan_begin_src==TRIG_INT))&&(cmd->convert_src==TRIG_TIMER)) { // both timer is used for one time - if (cmd->scan_begin_src==TRIG_EXT) { - devpriv->ai_do=4; + if (((cmd->scan_begin_src == TRIG_FOLLOW) || (cmd->scan_begin_src == TRIG_EXT) || (cmd->scan_begin_src == TRIG_INT)) && (cmd->convert_src == TRIG_TIMER)) { // both timer is used for one time + if (cmd->scan_begin_src == TRIG_EXT) { + devpriv->ai_do = 4; } else { - devpriv->ai_do=1; + devpriv->ai_do = 1; } pci9118_calc_divisors(devpriv->ai_do, dev, s, - &cmd->scan_begin_arg, &cmd->convert_arg, devpriv->ai_flags, - devpriv->ai_n_realscanlen, &devpriv->ai_divisor1, &devpriv->ai_divisor2, + &cmd->scan_begin_arg, &cmd->convert_arg, + devpriv->ai_flags, devpriv->ai_n_realscanlen, + &devpriv->ai_divisor1, &devpriv->ai_divisor2, devpriv->usessh, devpriv->ai_add_front); - devpriv->ai_timer2=cmd->convert_arg; + devpriv->ai_timer2 = cmd->convert_arg; } - if ((cmd->scan_begin_src==TRIG_TIMER)&&((cmd->convert_src==TRIG_TIMER)||(cmd->convert_src==TRIG_NOW))) { // double timed action + if ((cmd->scan_begin_src == TRIG_TIMER) && ((cmd->convert_src == TRIG_TIMER) || (cmd->convert_src == TRIG_NOW))) { // double timed action if (!devpriv->usedma) { - comedi_error(dev,"cmd->scan_begin_src=TRIG_TIMER works only with bus mastering!"); + comedi_error(dev, + "cmd->scan_begin_src=TRIG_TIMER works only with bus mastering!"); return -EIO; } - devpriv->ai_do=2; + devpriv->ai_do = 2; pci9118_calc_divisors(devpriv->ai_do, dev, s, - &cmd->scan_begin_arg, &cmd->convert_arg, devpriv->ai_flags, - devpriv->ai_n_realscanlen, &devpriv->ai_divisor1, &devpriv->ai_divisor2, + &cmd->scan_begin_arg, &cmd->convert_arg, + devpriv->ai_flags, devpriv->ai_n_realscanlen, + &devpriv->ai_divisor1, &devpriv->ai_divisor2, devpriv->usessh, devpriv->ai_add_front); - devpriv->ai_timer1=cmd->scan_begin_arg; - devpriv->ai_timer2=cmd->convert_arg; + devpriv->ai_timer1 = cmd->scan_begin_arg; + devpriv->ai_timer2 = cmd->convert_arg; } - if ((cmd->scan_begin_src==TRIG_FOLLOW)&&(cmd->convert_src==TRIG_EXT)) { - devpriv->ai_do=3; + if ((cmd->scan_begin_src == TRIG_FOLLOW) + && (cmd->convert_src == TRIG_EXT)) { + devpriv->ai_do = 3; } + start_pacer(dev, -1, 0, 0); // stop pacer - start_pacer(dev, -1, 0, 0); // stop pacer - - devpriv->AdControlReg=0; // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable DMA - outl(devpriv->AdControlReg,dev->iobase+PCI9118_ADCNTRL); - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg; // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC); + devpriv->AdControlReg = 0; // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable DMA + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); + devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg; // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); comedi_udelay(1); - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO - inl(dev->iobase+PCI9118_ADSTAT); // flush A/D and INT status register - inl(dev->iobase+PCI9118_INTSRC); + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO + inl(dev->iobase + PCI9118_ADSTAT); // flush A/D and INT status register + inl(dev->iobase + PCI9118_INTSRC); - devpriv->ai_act_scan=0; - devpriv->ai_act_dmapos=0; - s->async->cur_chan=0; - devpriv->ai_buf_ptr=0; + devpriv->ai_act_scan = 0; + devpriv->ai_act_dmapos = 0; + s->async->cur_chan = 0; + devpriv->ai_buf_ptr = 0; if (devpriv->usedma) { - ret=pci9118_ai_docmd_dma(dev, s); + ret = pci9118_ai_docmd_dma(dev, s); } else { - ret=pci9118_ai_docmd_sampl(dev, s); + ret = pci9118_ai_docmd_sampl(dev, s); } DPRINTK("adl_pci9118 EDBG: END: pci9118_ai_cmd()\n"); - return ret; + return ret; } /* @@ -1350,34 +1488,44 @@ static int pci9118_ai_cmd(comedi_device *dev,comedi_subdevice *s) static int check_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist, int frontadd, int backadd) { - unsigned int i, differencial=0, bipolar=0; + unsigned int i, differencial = 0, bipolar = 0; /* correct channel and range number check itself comedi/range.c */ - if (n_chan<1) { - comedi_error(dev,"range/channel list is empty!"); + if (n_chan < 1) { + comedi_error(dev, "range/channel list is empty!"); return 0; - } - if ((frontadd+n_chan+backadd)>s->len_chanlist) { - rt_printk("comedi%d: range/channel list is too long for actual configuration (%d>%d)!",dev->minor,n_chan,s->len_chanlist-frontadd-backadd); + } + if ((frontadd + n_chan + backadd) > s->len_chanlist) { + rt_printk + ("comedi%d: range/channel list is too long for actual configuration (%d>%d)!", + dev->minor, n_chan, + s->len_chanlist - frontadd - backadd); return 0; } - if (CR_AREF(chanlist[0])==AREF_DIFF) - differencial=1; // all input must be diff - if (CR_RANGE(chanlist[0]) 1) - for (i=1 ; i 1) + for (i = 1; i < n_chan; i++) { // check S.E/diff + if ((CR_AREF(chanlist[i]) == AREF_DIFF) != + (differencial)) { + comedi_error(dev, + "Differencial and single ended inputs cann't be mixtured!"); return 0; } - if ((CR_RANGE(chanlist[i])usemux)&(differencial)&(CR_CHAN(chanlist[i])>=this_board->n_aichand)) { - comedi_error(dev,"If AREF_DIFF is used then is available only first 8 channels!"); + if ((!devpriv->usemux) & (differencial) & + (CR_CHAN(chanlist[i]) >= + this_board->n_aichand)) { + comedi_error(dev, + "If AREF_DIFF is used then is available only first 8 channels!"); return 0; } } @@ -1388,154 +1536,170 @@ static int check_channel_list(comedi_device * dev, comedi_subdevice * s, /* ============================================================================== */ -static int setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, - unsigned int *chanlist,int rot, int frontadd, int backadd, int usedma, char useeos) +static int setup_channel_list(comedi_device * dev, comedi_subdevice * s, + int n_chan, unsigned int *chanlist, int rot, int frontadd, int backadd, + int usedma, char useeos) { - unsigned int i, differencial=0, bipolar=0; - unsigned int scanquad, gain,ssh=0x00; + unsigned int i, differencial = 0, bipolar = 0; + unsigned int scanquad, gain, ssh = 0x00; - DPRINTK("adl_pci9118 EDBG: BGN: setup_channel_list(%d,.,%d,.,%d,%d,%d,%d)\n", - dev->minor, n_chan, rot, frontadd, backadd, usedma); + DPRINTK("adl_pci9118 EDBG: BGN: setup_channel_list(%d,.,%d,.,%d,%d,%d,%d)\n", dev->minor, n_chan, rot, frontadd, backadd, usedma); - if (usedma==1) { rot=8; usedma=0; } + if (usedma == 1) { + rot = 8; + usedma = 0; + } - if (CR_AREF(chanlist[0])==AREF_DIFF) - differencial=1; // all input must be diff - if (CR_RANGE(chanlist[0])AdControlReg|=AdControl_UniP; // set unibipolar + devpriv->AdControlReg |= AdControl_UniP; // set unibipolar } else { - devpriv->AdControlReg&=((~AdControl_UniP)&0xff); // enable bipolar + devpriv->AdControlReg &= ((~AdControl_UniP) & 0xff); // enable bipolar } if (differencial) { - devpriv->AdControlReg|=AdControl_Diff; // enable diff inputs + devpriv->AdControlReg |= AdControl_Diff; // enable diff inputs } else { - devpriv->AdControlReg&=((~AdControl_Diff)&0xff); // set single ended inputs + devpriv->AdControlReg &= ((~AdControl_Diff) & 0xff); // set single ended inputs } - outl(devpriv->AdControlReg, dev->iobase+PCI9118_ADCNTRL); // setup mode + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); // setup mode - outl(2,dev->iobase+PCI9118_SCANMOD); // gods know why this sequence! - outl(0,dev->iobase+PCI9118_SCANMOD); - outl(1,dev->iobase+PCI9118_SCANMOD); + outl(2, dev->iobase + PCI9118_SCANMOD); // gods know why this sequence! + outl(0, dev->iobase + PCI9118_SCANMOD); + outl(1, dev->iobase + PCI9118_SCANMOD); #ifdef PCI9118_PARANOIDCHECK - devpriv->chanlistlen=n_chan; - for (i=0; i<(PCI9118_CHANLEN+1); i++) devpriv->chanlist[i]=0x55aa; + devpriv->chanlistlen = n_chan; + for (i = 0; i < (PCI9118_CHANLEN + 1); i++) + devpriv->chanlist[i] = 0x55aa; #endif - if (frontadd) { // insert channels for S&H - ssh=devpriv->softsshsample; - DPRINTK("FA: %04x: ",ssh); - for (i=0; iiobase+PCI9118_GAIN); - DPRINTK("%02x ",scanquad|ssh); - ssh=devpriv->softsshhold; + if (frontadd) { // insert channels for S&H + ssh = devpriv->softsshsample; + DPRINTK("FA: %04x: ", ssh); + for (i = 0; i < frontadd; i++) { // store range list to card + scanquad = CR_CHAN(chanlist[0]); // get channel number; + gain = CR_RANGE(chanlist[0]); // get gain number + scanquad |= ((gain & 0x03) << 8); + outl(scanquad | ssh, dev->iobase + PCI9118_GAIN); + DPRINTK("%02x ", scanquad | ssh); + ssh = devpriv->softsshhold; } DPRINTK("\n "); } - DPRINTK("SL: ",ssh); - for (i=0; ichanlist[i^usedma]=(scanquad & 0xf)<chanlist[i ^ usedma] = (scanquad & 0xf) << rot; #endif - gain=CR_RANGE(chanlist[i]); // get gain number - scanquad|=((gain & 0x03)<<8); - outl(scanquad|ssh,dev->iobase+PCI9118_GAIN); - DPRINTK("%02x ",scanquad|ssh); + gain = CR_RANGE(chanlist[i]); // get gain number + scanquad |= ((gain & 0x03) << 8); + outl(scanquad | ssh, dev->iobase + PCI9118_GAIN); + DPRINTK("%02x ", scanquad | ssh); } DPRINTK("\n "); - if (backadd) { // insert channels for fit onto 32bit DMA - DPRINTK("BA: %04x: ",ssh); - for (i=0; iiobase+PCI9118_GAIN); - DPRINTK("%02x ",scanquad|ssh); + if (backadd) { // insert channels for fit onto 32bit DMA + DPRINTK("BA: %04x: ", ssh); + for (i = 0; i < backadd; i++) { // store range list to card + scanquad = CR_CHAN(chanlist[0]); // get channel number; + gain = CR_RANGE(chanlist[0]); // get gain number + scanquad |= ((gain & 0x03) << 8); + outl(scanquad | ssh, dev->iobase + PCI9118_GAIN); + DPRINTK("%02x ", scanquad | ssh); } DPRINTK("\n "); } - #ifdef PCI9118_PARANOIDCHECK - devpriv->chanlist[n_chan^usedma]=devpriv->chanlist[0^usedma]; // for 32bit oerations + devpriv->chanlist[n_chan ^ usedma] = devpriv->chanlist[0 ^ usedma]; // for 32bit oerations if (useeos) { - for (i=1; ichanlist[(n_chan+i)^usedma]= - (CR_CHAN(chanlist[i]) & 0xf)<chanlist[(n_chan + i) ^ usedma] = + (CR_CHAN(chanlist[i]) & 0xf) << rot; } - devpriv->chanlist[(2*n_chan)^usedma]=devpriv->chanlist[0^usedma]; // for 32bit oerations - useeos=2; + devpriv->chanlist[(2 * n_chan) ^ usedma] = devpriv->chanlist[0 ^ usedma]; // for 32bit oerations + useeos = 2; } else { - useeos=1; + useeos = 1; } #ifdef PCI9118_EXTDEBUG DPRINTK("CHL: "); - for (i=0; i<=(useeos*n_chan); i++) { - DPRINTK("%04x ",devpriv->chanlist[i]); + for (i = 0; i <= (useeos * n_chan); i++) { + DPRINTK("%04x ", devpriv->chanlist[i]); } DPRINTK("\n "); #endif #endif - outl(0,dev->iobase+PCI9118_SCANMOD); // close scan queue -// comedi_udelay(100); // important delay, or first sample will be cripled + outl(0, dev->iobase + PCI9118_SCANMOD); // close scan queue +// comedi_udelay(100); // important delay, or first sample will be cripled DPRINTK("adl_pci9118 EDBG: END: setup_channel_list()\n"); - return 1; // we can serve this with scan logic + return 1; // we can serve this with scan logic } /* ============================================================================== calculate 8254 divisors if they are used for dual timing */ -static void pci9118_calc_divisors(char mode, comedi_device * dev, comedi_subdevice * s, - unsigned int *tim1, unsigned int *tim2, unsigned int flags, - int chans, unsigned int *div1, unsigned int *div2, +static void pci9118_calc_divisors(char mode, comedi_device * dev, + comedi_subdevice * s, unsigned int *tim1, unsigned int *tim2, + unsigned int flags, int chans, unsigned int *div1, unsigned int *div2, char usessh, unsigned int chnsshfront) { - DPRINTK("adl_pci9118 EDBG: BGN: pci9118_calc_divisors(%d,%d,.,%u,%u,%u,%d,.,.,,%u,%u)\n", - mode, dev->minor, *tim1, *tim2, flags, chans, usessh, chnsshfront); - switch (mode) { + DPRINTK("adl_pci9118 EDBG: BGN: pci9118_calc_divisors(%d,%d,.,%u,%u,%u,%d,.,.,,%u,%u)\n", mode, dev->minor, *tim1, *tim2, flags, chans, usessh, chnsshfront); + switch (mode) { case 1: case 4: - if (*tim2ai_ns_min) *tim2=this_board->ai_ns_min; - i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,div1,div2,tim2,flags&TRIG_ROUND_NEAREST); - DPRINTK("OSC base=%u div1=%u div2=%u timer1=%u\n",devpriv->i8254_osc_base,*div1,*div2,*tim1); + if (*tim2 < this_board->ai_ns_min) + *tim2 = this_board->ai_ns_min; + i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, div1, div2, + tim2, flags & TRIG_ROUND_NEAREST); + DPRINTK("OSC base=%u div1=%u div2=%u timer1=%u\n", + devpriv->i8254_osc_base, *div1, *div2, *tim1); break; case 2: - if (*tim2ai_ns_min) *tim2=this_board->ai_ns_min; - DPRINTK("1 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - *div1=*tim2/devpriv->i8254_osc_base; // convert timer (burst) - DPRINTK("2 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - if (*div1ai_pacer_min) *div1=this_board->ai_pacer_min; - DPRINTK("3 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - *div2=*tim1/devpriv->i8254_osc_base; // scan timer - DPRINTK("4 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - *div2=*div2/ *div1; // major timer is c1*c2 - DPRINTK("5 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - if (*div2i8254_osc_base; // real convert timer - - if (usessh & (chnsshfront==0)) // use BSSH signal - if (*div2<(chans+2)) - *div2=chans+2; - - DPRINTK("7 div1=%u div2=%u timer1=%u timer2=%u\n",*div1,*div2,*tim1,*tim2); - *tim1= *div1 * *div2 * devpriv->i8254_osc_base; - DPRINTK("OSC base=%u div1=%u div2=%u timer1=%u timer2=%u\n",devpriv->i8254_osc_base,*div1,*div2,*tim1,*tim2); + if (*tim2 < this_board->ai_ns_min) + *tim2 = this_board->ai_ns_min; + DPRINTK("1 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + *div1 = *tim2 / devpriv->i8254_osc_base; // convert timer (burst) + DPRINTK("2 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + if (*div1 < this_board->ai_pacer_min) + *div1 = this_board->ai_pacer_min; + DPRINTK("3 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + *div2 = *tim1 / devpriv->i8254_osc_base; // scan timer + DPRINTK("4 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + *div2 = *div2 / *div1; // major timer is c1*c2 + DPRINTK("5 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + if (*div2 < chans) + *div2 = chans; + DPRINTK("6 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + + *tim2 = *div1 * devpriv->i8254_osc_base; // real convert timer + + if (usessh & (chnsshfront == 0)) // use BSSH signal + if (*div2 < (chans + 2)) + *div2 = chans + 2; + + DPRINTK("7 div1=%u div2=%u timer1=%u timer2=%u\n", *div1, *div2, + *tim1, *tim2); + *tim1 = *div1 * *div2 * devpriv->i8254_osc_base; + DPRINTK("OSC base=%u div1=%u div2=%u timer1=%u timer2=%u\n", + devpriv->i8254_osc_base, *div1, *div2, *tim1, *tim2); break; } DPRINTK("adl_pci9118 EDBG: END: pci9118_calc_divisors(%u,%u)\n", @@ -1545,19 +1709,20 @@ static void pci9118_calc_divisors(char mode, comedi_device * dev, comedi_subdevi /* ============================================================================== */ -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2) +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2) { - outl(0x74, dev->iobase + PCI9118_CNTCTRL); - outl(0xb4, dev->iobase + PCI9118_CNTCTRL); -// outl(0x30, dev->iobase + PCI9118_CNTCTRL); - comedi_udelay(1); + outl(0x74, dev->iobase + PCI9118_CNTCTRL); + outl(0xb4, dev->iobase + PCI9118_CNTCTRL); +// outl(0x30, dev->iobase + PCI9118_CNTCTRL); + comedi_udelay(1); - if ((mode==1)||(mode==2)||(mode==4)) { + if ((mode == 1) || (mode == 2) || (mode == 4)) { outl(divisor2 & 0xff, dev->iobase + PCI9118_CNT2); outl((divisor2 >> 8) & 0xff, dev->iobase + PCI9118_CNT2); - outl(divisor1 & 0xff, dev->iobase + PCI9118_CNT1); + outl(divisor1 & 0xff, dev->iobase + PCI9118_CNT1); outl((divisor1 >> 8) & 0xff, dev->iobase + PCI9118_CNT1); - } + } } /* @@ -1565,11 +1730,12 @@ static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, un */ static int pci9118_exttrg_add(comedi_device * dev, unsigned char source) { - if (source>3) return -1; // incorrect source - devpriv->exttrg_users|=(1<IntControlReg|=Int_DTrg; - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); - outl(inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR)|0x1f00, devpriv->iobase_a+AMCC_OP_REG_INTCSR); // allow INT in AMCC + if (source > 3) + return -1; // incorrect source + devpriv->exttrg_users |= (1 << source); + devpriv->IntControlReg |= Int_DTrg; + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); + outl(inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR) | 0x1f00, devpriv->iobase_a + AMCC_OP_REG_INTCSR); // allow INT in AMCC return 0; } @@ -1578,13 +1744,14 @@ static int pci9118_exttrg_add(comedi_device * dev, unsigned char source) */ static int pci9118_exttrg_del(comedi_device * dev, unsigned char source) { - if (source>3) return -1; // incorrect source - devpriv->exttrg_users&=~(1<exttrg_users) { // shutdown ext trg intterrupts - devpriv->IntControlReg&=~Int_DTrg; - if (!devpriv->IntControlReg) // all IRQ disabled - outl(inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR)&(~0x00001f00), devpriv->iobase_a+AMCC_OP_REG_INTCSR); // disable int in AMCC - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL); + if (source > 3) + return -1; // incorrect source + devpriv->exttrg_users &= ~(1 << source); + if (!devpriv->exttrg_users) { // shutdown ext trg intterrupts + devpriv->IntControlReg &= ~Int_DTrg; + if (!devpriv->IntControlReg) // all IRQ disabled + outl(inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR) & (~0x00001f00), devpriv->iobase_a + AMCC_OP_REG_INTCSR); // disable int in AMCC + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); } return 0; } @@ -1595,31 +1762,31 @@ static int pci9118_exttrg_del(comedi_device * dev, unsigned char source) static int pci9118_ai_cancel(comedi_device * dev, comedi_subdevice * s) { if (devpriv->usedma) - outl(inl(devpriv->iobase_a+AMCC_OP_REG_MCSR)&(~EN_A2P_TRANSFERS), devpriv->iobase_a+AMCC_OP_REG_MCSR); // stop DMA - pci9118_exttrg_del(dev,EXTTRG_AI); - start_pacer(dev,0,0,0); // stop 8254 counters - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC);// positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop - devpriv->AdControlReg=0x00; - outl(devpriv->AdControlReg,dev->iobase+PCI9118_ADCNTRL);// bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA - outl(0,dev->iobase+PCI9118_BURST); - outl(1,dev->iobase+PCI9118_SCANMOD); - outl(2,dev->iobase+PCI9118_SCANMOD);// reset scan queue - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO - - devpriv->ai_do=0; - devpriv->usedma=0; - - devpriv->ai_act_scan=0; - devpriv->ai_act_dmapos=0; - s->async->cur_chan=0; - s->async->inttrig=NULL; - devpriv->ai_buf_ptr=0; - devpriv->ai_neverending=0; - devpriv->dma_actbuf=0; + outl(inl(devpriv->iobase_a + AMCC_OP_REG_MCSR) & (~EN_A2P_TRANSFERS), devpriv->iobase_a + AMCC_OP_REG_MCSR); // stop DMA + pci9118_exttrg_del(dev, EXTTRG_AI); + start_pacer(dev, 0, 0, 0); // stop 8254 counters + devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop + devpriv->AdControlReg = 0x00; + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA + outl(0, dev->iobase + PCI9118_BURST); + outl(1, dev->iobase + PCI9118_SCANMOD); + outl(2, dev->iobase + PCI9118_SCANMOD); // reset scan queue + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO + + devpriv->ai_do = 0; + devpriv->usedma = 0; + + devpriv->ai_act_scan = 0; + devpriv->ai_act_dmapos = 0; + s->async->cur_chan = 0; + s->async->inttrig = NULL; + devpriv->ai_buf_ptr = 0; + devpriv->ai_neverending = 0; + devpriv->dma_actbuf = 0; if (!devpriv->IntControlReg) - outl(inl(devpriv->iobase_a+AMCC_OP_REG_INTCSR)|0x1f00, devpriv->iobase_a+AMCC_OP_REG_INTCSR); // allow INT in AMCC + outl(inl(devpriv->iobase_a + AMCC_OP_REG_INTCSR) | 0x1f00, devpriv->iobase_a + AMCC_OP_REG_INTCSR); // allow INT in AMCC return 0; } @@ -1627,39 +1794,39 @@ static int pci9118_ai_cancel(comedi_device * dev, comedi_subdevice * s) /* ============================================================================== */ -static int pci9118_reset(comedi_device *dev) +static int pci9118_reset(comedi_device * dev) { - devpriv->IntControlReg=0; - devpriv->exttrg_users=0; - inl(dev->iobase+PCI9118_INTCTRL); - outl(devpriv->IntControlReg,dev->iobase+PCI9118_INTCTRL);// disable interrupts source + devpriv->IntControlReg = 0; + devpriv->exttrg_users = 0; + inl(dev->iobase + PCI9118_INTCTRL); + outl(devpriv->IntControlReg, dev->iobase + PCI9118_INTCTRL); // disable interrupts source outl(0x30, dev->iobase + PCI9118_CNTCTRL); // outl(0xb4, dev->iobase + PCI9118_CNTCTRL); - start_pacer(dev,0,0,0); // stop 8254 counters - devpriv->AdControlReg=0; - outl(devpriv->AdControlReg,dev->iobase+PCI9118_ADCNTRL);// bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA - outl(0,dev->iobase+PCI9118_BURST); - outl(1,dev->iobase+PCI9118_SCANMOD); - outl(2,dev->iobase+PCI9118_SCANMOD);// reset scan queue - devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg; - outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC);// positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop - - devpriv->ao_data[0]=2047; - devpriv->ao_data[1]=2047; - outl(devpriv->ao_data[0],dev->iobase+PCI9118_DA1);// reset A/D outs to 0V - outl(devpriv->ao_data[1],dev->iobase+PCI9118_DA2); - outl(0,dev->iobase+PCI9118_DO); // reset digi outs to L + start_pacer(dev, 0, 0, 0); // stop 8254 counters + devpriv->AdControlReg = 0; + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA + outl(0, dev->iobase + PCI9118_BURST); + outl(1, dev->iobase + PCI9118_SCANMOD); + outl(2, dev->iobase + PCI9118_SCANMOD); // reset scan queue + devpriv->AdFunctionReg = AdFunction_PDTrg | AdFunction_PETrg; + outl(devpriv->AdFunctionReg, dev->iobase + PCI9118_ADFUNC); // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop + + devpriv->ao_data[0] = 2047; + devpriv->ao_data[1] = 2047; + outl(devpriv->ao_data[0], dev->iobase + PCI9118_DA1); // reset A/D outs to 0V + outl(devpriv->ao_data[1], dev->iobase + PCI9118_DA2); + outl(0, dev->iobase + PCI9118_DO); // reset digi outs to L comedi_udelay(10); - inl(dev->iobase+PCI9118_AD_DATA); - outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO - outl(0,dev->iobase+PCI9118_INTSRC); // remove INT requests - inl(dev->iobase+PCI9118_ADSTAT); // flush A/D status register - inl(dev->iobase+PCI9118_INTSRC); // flush INT requests - devpriv->AdControlReg=0; - outl(devpriv->AdControlReg,dev->iobase+PCI9118_ADCNTRL);// bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA + inl(dev->iobase + PCI9118_AD_DATA); + outl(0, dev->iobase + PCI9118_DELFIFO); // flush FIFO + outl(0, dev->iobase + PCI9118_INTSRC); // remove INT requests + inl(dev->iobase + PCI9118_ADSTAT); // flush A/D status register + inl(dev->iobase + PCI9118_INTSRC); // flush INT requests + devpriv->AdControlReg = 0; + outl(devpriv->AdControlReg, dev->iobase + PCI9118_ADCNTRL); // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable INT and DMA - devpriv->cnt0_users=0; - devpriv->exttrg_users=0; + devpriv->cnt0_users = 0; + devpriv->exttrg_users = 0; return 0; } @@ -1667,30 +1834,31 @@ static int pci9118_reset(comedi_device *dev) /* ============================================================================== */ -static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) +static int pci9118_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int ret,pages,i; + int ret, pages, i; unsigned short master; unsigned int irq; - unsigned long iobase_a,iobase_9; + unsigned long iobase_a, iobase_9; struct pci_dev *pcidev; int opt_bus, opt_slot; const char *errstr; - unsigned char pci_bus,pci_slot,pci_func; + unsigned char pci_bus, pci_slot, pci_func; u16 u16w; - rt_printk("comedi%d: adl_pci9118: board=%s",dev->minor,this_board->name); + rt_printk("comedi%d: adl_pci9118: board=%s", dev->minor, + this_board->name); opt_bus = it->options[0]; opt_slot = it->options[1]; - if (it->options[3]&1) { - master=0; // user don't want use bus master + if (it->options[3] & 1) { + master = 0; // user don't want use bus master } else { - master=1; + master = 1; } - if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) { + if ((ret = alloc_private(dev, sizeof(pci9118_private))) < 0) { rt_printk(" - Allocation failed!\n"); return -ENOMEM; } @@ -1699,12 +1867,12 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) errstr = "not found!"; pcidev = NULL; while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_AMCC, - this_board->device_id, pcidev))) { + this_board->device_id, pcidev))) { /* Found matching vendor/device. */ if (opt_bus || opt_slot) { /* Check bus/slot. */ if (opt_bus != pcidev->bus->number - || opt_slot != PCI_SLOT(pcidev->devfn)) + || opt_slot != PCI_SLOT(pcidev->devfn)) continue; /* no match */ } /* @@ -1721,7 +1889,7 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) if (!pcidev) { if (opt_bus || opt_slot) { rt_printk(" - Card at b:s %d:%d %s\n", - opt_bus, opt_slot, errstr); + opt_bus, opt_slot, errstr); } else { rt_printk(" - Card %s\n", errstr); } @@ -1739,167 +1907,188 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) iobase_a = pci_resource_start(pcidev, 0); iobase_9 = pci_resource_start(pcidev, 2); - rt_printk(", b:s:f=%d:%d:%d, io=0x%4lx, 0x%4lx",pci_bus,pci_slot,pci_func,iobase_9,iobase_a); + rt_printk(", b:s:f=%d:%d:%d, io=0x%4lx, 0x%4lx", pci_bus, pci_slot, + pci_func, iobase_9, iobase_a); - dev->iobase=iobase_9; + dev->iobase = iobase_9; dev->board_name = this_board->name; - - devpriv->pcidev=pcidev; - devpriv->iobase_a=iobase_a; + devpriv->pcidev = pcidev; + devpriv->iobase_a = iobase_a; pci9118_reset(dev); - if (it->options[3]&2) irq=0; // user don't want use IRQ - if (irq>0) { - if (comedi_request_irq(irq, interrupt_pci9118, IRQF_SHARED, "ADLink PCI-9118", dev)) { - rt_printk(", unable to allocate IRQ %d, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ + if (it->options[3] & 2) + irq = 0; // user don't want use IRQ + if (irq > 0) { + if (comedi_request_irq(irq, interrupt_pci9118, IRQF_SHARED, + "ADLink PCI-9118", dev)) { + rt_printk(", unable to allocate IRQ %d, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ } else { rt_printk(", irq=%u", irq); } } else { - rt_printk(", IRQ disabled"); + rt_printk(", IRQ disabled"); } - dev->irq = irq; + dev->irq = irq; - if (master) { // alloc DMA buffers - devpriv->dma_doublebuf=0; - for (i=0; i<2; i++) { - for (pages=4; pages>=0; pages--) - if ((devpriv->dmabuf_virt[i]=(sampl_t *)__get_free_pages(GFP_KERNEL,pages))) + if (master) { // alloc DMA buffers + devpriv->dma_doublebuf = 0; + for (i = 0; i < 2; i++) { + for (pages = 4; pages >= 0; pages--) + if ((devpriv->dmabuf_virt[i] = (sampl_t *) + __get_free_pages(GFP_KERNEL, + pages))) break; if (devpriv->dmabuf_virt[i]) { - devpriv->dmabuf_pages[i]=pages; - devpriv->dmabuf_size[i]=PAGE_SIZE*pages; - devpriv->dmabuf_samples[i]=devpriv->dmabuf_size[i]>>1; - devpriv->dmabuf_hw[i]=virt_to_bus((void *)devpriv->dmabuf_virt[i]); + devpriv->dmabuf_pages[i] = pages; + devpriv->dmabuf_size[i] = PAGE_SIZE * pages; + devpriv->dmabuf_samples[i] = + devpriv->dmabuf_size[i] >> 1; + devpriv->dmabuf_hw[i] = + virt_to_bus((void *)devpriv-> + dmabuf_virt[i]); } } if (!devpriv->dmabuf_virt[0]) { rt_printk(", Can't allocate DMA buffer, DMA disabled!"); - master=0; + master = 0; } if (devpriv->dmabuf_virt[1]) - devpriv->dma_doublebuf=1; + devpriv->dma_doublebuf = 1; } - if ((devpriv->master=master)) { + if ((devpriv->master = master)) { rt_printk(", bus master"); } else { rt_printk(", no bus master"); } - devpriv->usemux=0; - if (it->options[2]>0) { - devpriv->usemux=it->options[2]; - if (devpriv->usemux>256) devpriv->usemux=256; // max 256 channels! - if (it->options[4]>0) - if (devpriv->usemux>128) { - devpriv->usemux=128; // max 128 channels with softare S&H! + devpriv->usemux = 0; + if (it->options[2] > 0) { + devpriv->usemux = it->options[2]; + if (devpriv->usemux > 256) + devpriv->usemux = 256; // max 256 channels! + if (it->options[4] > 0) + if (devpriv->usemux > 128) { + devpriv->usemux = 128; // max 128 channels with softare S&H! } - rt_printk(", ext. mux %d channels",devpriv->usemux); + rt_printk(", ext. mux %d channels", devpriv->usemux); } - devpriv->softsshdelay=it->options[4]; - if (devpriv->softsshdelay<0) { // select sample&hold signal polarity - devpriv->softsshdelay=-devpriv->softsshdelay; - devpriv->softsshsample=0x80; - devpriv->softsshhold=0x00; + devpriv->softsshdelay = it->options[4]; + if (devpriv->softsshdelay < 0) { // select sample&hold signal polarity + devpriv->softsshdelay = -devpriv->softsshdelay; + devpriv->softsshsample = 0x80; + devpriv->softsshhold = 0x00; } else { - devpriv->softsshsample=0x00; - devpriv->softsshhold=0x80; + devpriv->softsshsample = 0x00; + devpriv->softsshhold = 0x80; } rt_printk(".\n"); pci_read_config_word(devpriv->pcidev, PCI_COMMAND, &u16w); - pci_write_config_word(devpriv->pcidev, PCI_COMMAND, u16w|64); // Enable parity check for parity error + pci_write_config_word(devpriv->pcidev, PCI_COMMAND, u16w | 64); // Enable parity check for parity error - if((ret=alloc_subdevices(dev, 4))<0) - return ret; + if ((ret = alloc_subdevices(dev, 4)) < 0) + return ret; s = dev->subdevices + 0; dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_COMMON|SDF_GROUND|SDF_DIFF; - if (devpriv->usemux) { s->n_chan = devpriv->usemux; } - else { s->n_chan = this_board->n_aichan; } + s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; + if (devpriv->usemux) { + s->n_chan = devpriv->usemux; + } else { + s->n_chan = this_board->n_aichan; + } s->maxdata = this_board->ai_maxdata; s->len_chanlist = this_board->n_aichanlist; s->range_table = this_board->rangelist_ai; - s->cancel=pci9118_ai_cancel; - s->insn_read=pci9118_insn_read_ai; + s->cancel = pci9118_ai_cancel; + s->insn_read = pci9118_insn_read_ai; if (dev->irq) { s->subdev_flags |= SDF_CMD_READ; - s->do_cmdtest=pci9118_ai_cmdtest; - s->do_cmd=pci9118_ai_cmd; - s->munge=pci9118_ai_munge; + s->do_cmdtest = pci9118_ai_cmdtest; + s->do_cmd = pci9118_ai_cmd; + s->munge = pci9118_ai_munge; } s = dev->subdevices + 1; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_aochan; s->maxdata = this_board->ao_maxdata; s->len_chanlist = this_board->n_aochan; s->range_table = this_board->rangelist_ao; - s->insn_write=pci9118_insn_write_ao; - s->insn_read=pci9118_insn_read_ao; + s->insn_write = pci9118_insn_write_ao; + s->insn_read = pci9118_insn_read_ao; s = dev->subdevices + 2; s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 4; s->maxdata = 1; s->len_chanlist = 4; s->range_table = &range_digital; - s->io_bits=0; /* all bits input */ - s->insn_bits=pci9118_insn_bits_di; + s->io_bits = 0; /* all bits input */ + s->insn_bits = pci9118_insn_bits_di; s = dev->subdevices + 3; s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 4; s->maxdata = 1; s->len_chanlist = 4; s->range_table = &range_digital; - s->io_bits=0xf; /* all bits output */ - s->insn_bits=pci9118_insn_bits_do; + s->io_bits = 0xf; /* all bits output */ + s->insn_bits = pci9118_insn_bits_do; - devpriv->valid=1; - devpriv->i8254_osc_base=250; // 250ns=4MHz - devpriv->ai_maskharderr=0x10a; // default measure crash condition - if (it->options[5]) // disable some requested - devpriv->ai_maskharderr&=~it->options[5]; + devpriv->valid = 1; + devpriv->i8254_osc_base = 250; // 250ns=4MHz + devpriv->ai_maskharderr = 0x10a; // default measure crash condition + if (it->options[5]) // disable some requested + devpriv->ai_maskharderr &= ~it->options[5]; switch (this_board->ai_maxdata) { - case 0xffff: devpriv->ai16bits=1; break; - default: devpriv->ai16bits=0; break; + case 0xffff: + devpriv->ai16bits = 1; + break; + default: + devpriv->ai16bits = 0; + break; } return 0; } - /* ============================================================================== */ -static int pci9118_detach(comedi_device *dev) +static int pci9118_detach(comedi_device * dev) { if (dev->private) { - if (devpriv->valid) pci9118_reset(dev); - if(dev->irq) comedi_free_irq(dev->irq,dev); + if (devpriv->valid) + pci9118_reset(dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); if (devpriv->pcidev) { if (dev->iobase) { comedi_pci_disable(devpriv->pcidev); } pci_dev_put(devpriv->pcidev); } - if (devpriv->dmabuf_virt[0]) free_pages((unsigned long)devpriv->dmabuf_virt[0],devpriv->dmabuf_pages[0]); - if (devpriv->dmabuf_virt[1]) free_pages((unsigned long)devpriv->dmabuf_virt[1],devpriv->dmabuf_pages[1]); + if (devpriv->dmabuf_virt[0]) + free_pages((unsigned long)devpriv->dmabuf_virt[0], + devpriv->dmabuf_pages[0]); + if (devpriv->dmabuf_virt[1]) + free_pages((unsigned long)devpriv->dmabuf_virt[1], + devpriv->dmabuf_pages[1]); } return 0; @@ -1908,4 +2097,3 @@ static int pci9118_detach(comedi_device *dev) /* ============================================================================== */ - diff --git a/comedi/drivers/adv_pci1710.c b/comedi/drivers/adv_pci1710.c index 74e2efed..58a0bb58 100644 --- a/comedi/drivers/adv_pci1710.c +++ b/comedi/drivers/adv_pci1710.c @@ -48,8 +48,7 @@ Configuration options: #include "8253.h" #include "amcc_s5933.h" - -#define PCI171x_PARANOIDCHECK /* if defined, then is used code which control correct channel number on every 12 bit sample */ +#define PCI171x_PARANOIDCHECK /* if defined, then is used code which control correct channel number on every 12 bit sample */ #undef PCI171X_EXTDEBUG @@ -68,226 +67,230 @@ Configuration options: #define IORANGE_171x 32 #define IORANGE_1720 16 -#define PCI171x_AD_DATA 0 /* R: A/D data */ -#define PCI171x_SOFTTRG 0 /* W: soft trigger for A/D */ -#define PCI171x_RANGE 2 /* W: A/D gain/range register */ -#define PCI171x_MUX 4 /* W: A/D multiplexor control */ -#define PCI171x_STATUS 6 /* R: status register */ -#define PCI171x_CONTROL 6 /* W: control register */ -#define PCI171x_CLRINT 8 /* W: clear interrupts request */ -#define PCI171x_CLRFIFO 9 /* W: clear FIFO */ -#define PCI171x_DA1 10 /* W: D/A register */ -#define PCI171x_DA2 12 /* W: D/A register */ -#define PCI171x_DAREF 14 /* W: D/A reference control */ -#define PCI171x_DI 16 /* R: digi inputs */ -#define PCI171x_DO 16 /* R: digi inputs */ -#define PCI171x_CNT0 24 /* R/W: 8254 couter 0 */ -#define PCI171x_CNT1 26 /* R/W: 8254 couter 1 */ -#define PCI171x_CNT2 28 /* R/W: 8254 couter 2 */ -#define PCI171x_CNTCTRL 30 /* W: 8254 counter control */ +#define PCI171x_AD_DATA 0 /* R: A/D data */ +#define PCI171x_SOFTTRG 0 /* W: soft trigger for A/D */ +#define PCI171x_RANGE 2 /* W: A/D gain/range register */ +#define PCI171x_MUX 4 /* W: A/D multiplexor control */ +#define PCI171x_STATUS 6 /* R: status register */ +#define PCI171x_CONTROL 6 /* W: control register */ +#define PCI171x_CLRINT 8 /* W: clear interrupts request */ +#define PCI171x_CLRFIFO 9 /* W: clear FIFO */ +#define PCI171x_DA1 10 /* W: D/A register */ +#define PCI171x_DA2 12 /* W: D/A register */ +#define PCI171x_DAREF 14 /* W: D/A reference control */ +#define PCI171x_DI 16 /* R: digi inputs */ +#define PCI171x_DO 16 /* R: digi inputs */ +#define PCI171x_CNT0 24 /* R/W: 8254 couter 0 */ +#define PCI171x_CNT1 26 /* R/W: 8254 couter 1 */ +#define PCI171x_CNT2 28 /* R/W: 8254 couter 2 */ +#define PCI171x_CNTCTRL 30 /* W: 8254 counter control */ // upper bits from status register (PCI171x_STATUS) (lower is same woth control reg) -#define Status_FE 0x0100 /* 1=FIFO is empty */ -#define Status_FH 0x0200 /* 1=FIFO is half full */ -#define Status_FF 0x0400 /* 1=FIFO is full, fatal error */ -#define Status_IRQ 0x0800 /* 1=IRQ occured */ +#define Status_FE 0x0100 /* 1=FIFO is empty */ +#define Status_FH 0x0200 /* 1=FIFO is half full */ +#define Status_FF 0x0400 /* 1=FIFO is full, fatal error */ +#define Status_IRQ 0x0800 /* 1=IRQ occured */ // bits from control register (PCI171x_CONTROL) -#define Control_CNT0 0x0040 /* 1=CNT0 have external source, 0=have internal 100kHz source */ -#define Control_ONEFH 0x0020 /* 1=IRQ on FIFO is half full, 0=every sample */ -#define Control_IRQEN 0x0010 /* 1=enable IRQ */ -#define Control_GATE 0x0008 /* 1=enable external trigger GATE (8254?) */ -#define Control_EXT 0x0004 /* 1=external trigger source */ -#define Control_PACER 0x0002 /* 1=enable internal 8254 trigger source */ -#define Control_SW 0x0001 /* 1=enable software trigger source */ +#define Control_CNT0 0x0040 /* 1=CNT0 have external source, 0=have internal 100kHz source */ +#define Control_ONEFH 0x0020 /* 1=IRQ on FIFO is half full, 0=every sample */ +#define Control_IRQEN 0x0010 /* 1=enable IRQ */ +#define Control_GATE 0x0008 /* 1=enable external trigger GATE (8254?) */ +#define Control_EXT 0x0004 /* 1=external trigger source */ +#define Control_PACER 0x0002 /* 1=enable internal 8254 trigger source */ +#define Control_SW 0x0001 /* 1=enable software trigger source */ // bits from counter control register (PCI171x_CNTCTRL) -#define Counter_BCD 0x0001 /* 0 = binary counter, 1 = BCD counter */ -#define Counter_M0 0x0002 /* M0-M2 select modes 0-5 */ -#define Counter_M1 0x0004 /* 000 = mode 0, 010 = mode 2 ... */ +#define Counter_BCD 0x0001 /* 0 = binary counter, 1 = BCD counter */ +#define Counter_M0 0x0002 /* M0-M2 select modes 0-5 */ +#define Counter_M1 0x0004 /* 000 = mode 0, 010 = mode 2 ... */ #define Counter_M2 0x0008 -#define Counter_RW0 0x0010 /* RW0/RW1 select read/write mode */ +#define Counter_RW0 0x0010 /* RW0/RW1 select read/write mode */ #define Counter_RW1 0x0020 -#define Counter_SC0 0x0040 /* Select Counter. Only 00 or 11 may */ -#define Counter_SC1 0x0080 /* be used, 00 for CNT0, 11 for read-back command */ +#define Counter_SC0 0x0040 /* Select Counter. Only 00 or 11 may */ +#define Counter_SC1 0x0080 /* be used, 00 for CNT0, 11 for read-back command */ -#define PCI1720_DA0 0 /* W: D/A register 0 */ -#define PCI1720_DA1 2 /* W: D/A register 1 */ -#define PCI1720_DA2 4 /* W: D/A register 2 */ -#define PCI1720_DA3 6 /* W: D/A register 3 */ -#define PCI1720_RANGE 8 /* R/W: D/A range register */ -#define PCI1720_SYNCOUT 9 /* W: D/A synchronized output register */ -#define PCI1720_SYNCONT 15 /* R/W: D/A synchronized control */ +#define PCI1720_DA0 0 /* W: D/A register 0 */ +#define PCI1720_DA1 2 /* W: D/A register 1 */ +#define PCI1720_DA2 4 /* W: D/A register 2 */ +#define PCI1720_DA3 6 /* W: D/A register 3 */ +#define PCI1720_RANGE 8 /* R/W: D/A range register */ +#define PCI1720_SYNCOUT 9 /* W: D/A synchronized output register */ +#define PCI1720_SYNCONT 15 /* R/W: D/A synchronized control */ // D/A synchronized control (PCI1720_SYNCONT) -#define Syncont_SC0 1 /* set synchronous output mode */ - - -static const comedi_lrange range_pci1710_3={ 9, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), - BIP_RANGE(10), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) +#define Syncont_SC0 1 /* set synchronous output mode */ + +static const comedi_lrange range_pci1710_3 = { 9, { + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + BIP_RANGE(10), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25) } }; -static const char range_codes_pci1710_3[]={0x00, 0x01, 0x02, 0x03, 0x04, 0x10, 0x11, 0x12, 0x13 }; - -static const comedi_lrange range_pci1710hg={ 12, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), - BIP_RANGE(10), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.01), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01) +static const char range_codes_pci1710_3[] = + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x10, 0x11, 0x12, 0x13 }; + +static const comedi_lrange range_pci1710hg = { 12, { + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01) } }; -static const char range_codes_pci1710hg[]={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13 }; +static const char range_codes_pci1710hg[] = + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, + 0x13 }; -static const comedi_lrange range_pci17x1={ 5, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625) +static const comedi_lrange range_pci17x1 = { 5, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625) } }; -static const char range_codes_pci17x1[]={0x00, 0x01, 0x02, 0x03, 0x04 }; +static const char range_codes_pci17x1[] = { 0x00, 0x01, 0x02, 0x03, 0x04 }; -static const comedi_lrange range_pci1720={ 4, { - UNI_RANGE(5), - UNI_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(10) +static const comedi_lrange range_pci1720 = { 4, { + UNI_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(10) } }; -static const comedi_lrange range_pci171x_da={ 2, { - UNI_RANGE(5), - UNI_RANGE(10), +static const comedi_lrange range_pci171x_da = { 2, { + UNI_RANGE(5), + UNI_RANGE(10), } }; -static int pci1710_attach(comedi_device *dev,comedi_devconfig *it); -static int pci1710_detach(comedi_device *dev); +static int pci1710_attach(comedi_device * dev, comedi_devconfig * it); +static int pci1710_detach(comedi_device * dev); typedef struct { - const char *name; // board name - int device_id; - int iorange; // I/O range len - char have_irq; // 1=card support IRQ - char cardtype; // 0=1710& co. 2=1713, ... - int n_aichan; // num of A/D chans - int n_aichand; // num of A/D chans in diff mode - int n_aochan; // num of D/A chans - int n_dichan; // num of DI chans - int n_dochan; // num of DO chans - int n_counter; // num of counters - int ai_maxdata; // resolution of A/D - int ao_maxdata; // resolution of D/A - const comedi_lrange *rangelist_ai; // rangelist for A/D - const char *rangecode_ai; // range codes for programming - const comedi_lrange *rangelist_ao; // rangelist for D/A - unsigned int ai_ns_min; // max sample speed of card v ns - unsigned int fifo_half_size; // size of FIFO/2 + const char *name; // board name + int device_id; + int iorange; // I/O range len + char have_irq; // 1=card support IRQ + char cardtype; // 0=1710& co. 2=1713, ... + int n_aichan; // num of A/D chans + int n_aichand; // num of A/D chans in diff mode + int n_aochan; // num of D/A chans + int n_dichan; // num of DI chans + int n_dochan; // num of DO chans + int n_counter; // num of counters + int ai_maxdata; // resolution of A/D + int ao_maxdata; // resolution of D/A + const comedi_lrange *rangelist_ai; // rangelist for A/D + const char *rangecode_ai; // range codes for programming + const comedi_lrange *rangelist_ao; // rangelist for D/A + unsigned int ai_ns_min; // max sample speed of card v ns + unsigned int fifo_half_size; // size of FIFO/2 } boardtype; static struct pci_device_id pci1710_pci_table[] = __devinitdata { - { PCI_VENDOR_ID_ADVANTECH, 0x1710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1711, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1713, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1720, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1731, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADVANTECH, 0x1710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1711, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1713, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1720, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1731, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci1710_pci_table); -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"pci1710", 0x1710, - IORANGE_171x, 1, TYPE_PCI171X, - 16, 8, 2, 16, 16, 1, 0x0fff, 0x0fff, - &range_pci1710_3, range_codes_pci1710_3, &range_pci171x_da, - 10000, 2048 }, + IORANGE_171x, 1, TYPE_PCI171X, + 16, 8, 2, 16, 16, 1, 0x0fff, 0x0fff, + &range_pci1710_3, range_codes_pci1710_3, + &range_pci171x_da, + 10000, 2048}, {"pci1710hg", 0x1710, - IORANGE_171x, 1, TYPE_PCI171X, - 16, 8, 2, 16, 16, 1, 0x0fff, 0x0fff, - &range_pci1710hg, range_codes_pci1710hg, &range_pci171x_da, - 10000, 2048 }, + IORANGE_171x, 1, TYPE_PCI171X, + 16, 8, 2, 16, 16, 1, 0x0fff, 0x0fff, + &range_pci1710hg, range_codes_pci1710hg, + &range_pci171x_da, + 10000, 2048}, {"pci1711", 0x1711, - IORANGE_171x, 1, TYPE_PCI171X, - 16, 0, 2, 16, 16, 1, 0x0fff, 0x0fff, - &range_pci17x1, range_codes_pci17x1, &range_pci171x_da, - 10000, 512 }, + IORANGE_171x, 1, TYPE_PCI171X, + 16, 0, 2, 16, 16, 1, 0x0fff, 0x0fff, + &range_pci17x1, range_codes_pci17x1, &range_pci171x_da, + 10000, 512}, {"pci1713", 0x1713, - IORANGE_171x, 1, TYPE_PCI1713, - 32,16, 0, 0, 0, 0, 0x0fff, 0x0000, - &range_pci1710_3, range_codes_pci1710_3, NULL, - 10000, 2048 }, + IORANGE_171x, 1, TYPE_PCI1713, + 32, 16, 0, 0, 0, 0, 0x0fff, 0x0000, + &range_pci1710_3, range_codes_pci1710_3, NULL, + 10000, 2048}, {"pci1720", 0x1720, - IORANGE_1720, 0, TYPE_PCI1720, - 0, 0, 4, 0, 0, 0, 0x0000, 0x0fff, - NULL, NULL, &range_pci1720, - 0, 0 }, + IORANGE_1720, 0, TYPE_PCI1720, + 0, 0, 4, 0, 0, 0, 0x0000, 0x0fff, + NULL, NULL, &range_pci1720, + 0, 0}, {"pci1731", 0x1731, - IORANGE_171x, 1, TYPE_PCI171X, - 16, 0, 0, 16, 16, 0, 0x0fff, 0x0000, - &range_pci17x1, range_codes_pci17x1, NULL, - 10000, 512 }, + IORANGE_171x, 1, TYPE_PCI171X, + 16, 0, 0, 16, 16, 0, 0x0fff, 0x0000, + &range_pci17x1, range_codes_pci17x1, NULL, + 10000, 512}, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -static comedi_driver driver_pci1710={ - driver_name: "adv_pci1710", - module: THIS_MODULE, - attach: pci1710_attach, - detach: pci1710_detach, - num_names: n_boardtypes, - board_name: &boardtypes[0].name, - offset: sizeof(boardtype), +static comedi_driver driver_pci1710 = { + driver_name:"adv_pci1710", + module:THIS_MODULE, + attach:pci1710_attach, + detach:pci1710_detach, + num_names:n_boardtypes, + board_name:&boardtypes[0].name, + offset:sizeof(boardtype), }; -typedef struct{ - struct pci_dev *pcidev; // ptr to PCI device - char valid; // card is usable - char neverending_ai; // we do unlimited AI - unsigned int CntrlReg; // Control register - unsigned int i8254_osc_base; // frequence of onboard oscilator - unsigned int ai_do; // what do AI? 0=nothing, 1 to 4 mode - unsigned int ai_act_scan;// how many scans we finished - unsigned int ai_act_chan;// actual position in actual scan - unsigned int ai_buf_ptr; // data buffer ptr in samples - unsigned char ai_eos; // 1=EOS wake up - unsigned char ai_et; - unsigned int ai_et_CntrlReg; - unsigned int ai_et_MuxVal; - unsigned int ai_et_div1, ai_et_div2; - unsigned int act_chanlist[32];// list of scaned channel - unsigned char act_chanlist_len;// len of scanlist - unsigned char act_chanlist_pos;// actual position in MUX list - unsigned char da_ranges; // copy of D/A outpit range register - unsigned int ai_scans; // len of scanlist - unsigned int ai_n_chan; // how many channels is measured - unsigned int *ai_chanlist; // actaul chanlist - unsigned int ai_flags; // flaglist - unsigned int ai_data_len; // len of data buffer - sampl_t *ai_data; // data buffer - unsigned int ai_timer1; // timers - unsigned int ai_timer2; - sampl_t ao_data[4]; // data output buffer - unsigned int cnt0_write_wait; // after a write, wait for update of the internal state +typedef struct { + struct pci_dev *pcidev; // ptr to PCI device + char valid; // card is usable + char neverending_ai; // we do unlimited AI + unsigned int CntrlReg; // Control register + unsigned int i8254_osc_base; // frequence of onboard oscilator + unsigned int ai_do; // what do AI? 0=nothing, 1 to 4 mode + unsigned int ai_act_scan; // how many scans we finished + unsigned int ai_act_chan; // actual position in actual scan + unsigned int ai_buf_ptr; // data buffer ptr in samples + unsigned char ai_eos; // 1=EOS wake up + unsigned char ai_et; + unsigned int ai_et_CntrlReg; + unsigned int ai_et_MuxVal; + unsigned int ai_et_div1, ai_et_div2; + unsigned int act_chanlist[32]; // list of scaned channel + unsigned char act_chanlist_len; // len of scanlist + unsigned char act_chanlist_pos; // actual position in MUX list + unsigned char da_ranges; // copy of D/A outpit range register + unsigned int ai_scans; // len of scanlist + unsigned int ai_n_chan; // how many channels is measured + unsigned int *ai_chanlist; // actaul chanlist + unsigned int ai_flags; // flaglist + unsigned int ai_data_len; // len of data buffer + sampl_t *ai_data; // data buffer + unsigned int ai_timer1; // timers + unsigned int ai_timer2; + sampl_t ao_data[4]; // data output buffer + unsigned int cnt0_write_wait; // after a write, wait for update of the internal state } pci1710_private; #define devpriv ((pci1710_private *)dev->private) @@ -297,104 +300,115 @@ typedef struct{ ============================================================================== */ -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan); -static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan, unsigned int seglen); -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2); -static int pci1710_reset(comedi_device *dev); +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan); +static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan, unsigned int seglen); +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2); +static int pci1710_reset(comedi_device * dev); static int pci171x_ai_cancel(comedi_device * dev, comedi_subdevice * s); -static const unsigned int muxonechan[] ={ 0x0000, 0x0101, 0x0202, 0x0303, 0x0404, 0x0505, 0x0606, 0x0707, // used for gain list programming - 0x0808, 0x0909, 0x0a0a, 0x0b0b, 0x0c0c, 0x0d0d, 0x0e0e, 0x0f0f, - 0x1010, 0x1111, 0x1212, 0x1313, 0x1414, 0x1515, 0x1616, 0x1717, - 0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f}; - +static const unsigned int muxonechan[] = { 0x0000, 0x0101, 0x0202, 0x0303, 0x0404, 0x0505, 0x0606, 0x0707, // used for gain list programming + 0x0808, 0x0909, 0x0a0a, 0x0b0b, 0x0c0c, 0x0d0d, 0x0e0e, 0x0f0f, + 0x1010, 0x1111, 0x1212, 0x1313, 0x1414, 0x1515, 0x1616, 0x1717, + 0x1818, 0x1919, 0x1a1a, 0x1b1b, 0x1c1c, 0x1d1d, 0x1e1e, 0x1f1f +}; /* ============================================================================== */ -static int pci171x_insn_read_ai(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int pci171x_insn_read_ai(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,timeout; + int n, timeout; #ifdef PCI171x_PARANOIDCHECK unsigned int idata; #endif DPRINTK("adv_pci1710 EDBG: BGN: pci171x_insn_read_ai(...)\n"); - devpriv->CntrlReg&=Control_CNT0; - devpriv->CntrlReg|=Control_SW; // set software trigger - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); - outb(0,dev->iobase + PCI171x_CLRFIFO); - outb(0,dev->iobase + PCI171x_CLRINT); - - setup_channel_list(dev,s,&insn->chanspec, 1, 1); - - DPRINTK("adv_pci1710 A ST=%4x IO=%x\n",inw(dev->iobase+PCI171x_STATUS), dev->iobase+PCI171x_STATUS); - for (n=0; nn; n++) { - outw(0, dev->iobase+PCI171x_SOFTTRG); /* start conversion */ - DPRINTK("adv_pci1710 B n=%d ST=%4x\n",n,inw(dev->iobase+PCI171x_STATUS)); + devpriv->CntrlReg &= Control_CNT0; + devpriv->CntrlReg |= Control_SW; // set software trigger + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + outb(0, dev->iobase + PCI171x_CLRFIFO); + outb(0, dev->iobase + PCI171x_CLRINT); + + setup_channel_list(dev, s, &insn->chanspec, 1, 1); + + DPRINTK("adv_pci1710 A ST=%4x IO=%x\n", + inw(dev->iobase + PCI171x_STATUS), + dev->iobase + PCI171x_STATUS); + for (n = 0; n < insn->n; n++) { + outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */ + DPRINTK("adv_pci1710 B n=%d ST=%4x\n", n, + inw(dev->iobase + PCI171x_STATUS)); //comedi_udelay(1); - DPRINTK("adv_pci1710 C n=%d ST=%4x\n",n,inw(dev->iobase+PCI171x_STATUS)); - timeout=100; - while (timeout--) { - if (!(inw(dev->iobase+PCI171x_STATUS) & Status_FE)) goto conv_finish; - if (!(timeout%10)) - DPRINTK("adv_pci1710 D n=%d tm=%d ST=%4x\n",n,timeout,inw(dev->iobase+PCI171x_STATUS)); - } - comedi_error(dev,"A/D insn timeout"); - outb(0,dev->iobase + PCI171x_CLRFIFO); - outb(0,dev->iobase + PCI171x_CLRINT); - data[n]=0; - DPRINTK("adv_pci1710 EDBG: END: pci171x_insn_read_ai(...) n=%d\n",n); - return -ETIME; - -conv_finish: + DPRINTK("adv_pci1710 C n=%d ST=%4x\n", n, + inw(dev->iobase + PCI171x_STATUS)); + timeout = 100; + while (timeout--) { + if (!(inw(dev->iobase + PCI171x_STATUS) & Status_FE)) + goto conv_finish; + if (!(timeout % 10)) + DPRINTK("adv_pci1710 D n=%d tm=%d ST=%4x\n", n, + timeout, + inw(dev->iobase + PCI171x_STATUS)); + } + comedi_error(dev, "A/D insn timeout"); + outb(0, dev->iobase + PCI171x_CLRFIFO); + outb(0, dev->iobase + PCI171x_CLRINT); + data[n] = 0; + DPRINTK("adv_pci1710 EDBG: END: pci171x_insn_read_ai(...) n=%d\n", n); + return -ETIME; + + conv_finish: #ifdef PCI171x_PARANOIDCHECK - idata=inw(dev->iobase+PCI171x_AD_DATA); - if (this_board->cardtype!=TYPE_PCI1713) - if ((idata & 0xf000)!=devpriv->act_chanlist[0]) { - comedi_error(dev,"A/D insn data droput!"); + idata = inw(dev->iobase + PCI171x_AD_DATA); + if (this_board->cardtype != TYPE_PCI1713) + if ((idata & 0xf000) != devpriv->act_chanlist[0]) { + comedi_error(dev, "A/D insn data droput!"); return -ETIME; } data[n] = idata & 0x0fff; #else - data[n] = inw(dev->iobase+PCI171x_AD_DATA) & 0x0fff; + data[n] = inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff; #endif } - outb(0,dev->iobase + PCI171x_CLRFIFO); - outb(0,dev->iobase + PCI171x_CLRINT); + outb(0, dev->iobase + PCI171x_CLRFIFO); + outb(0, dev->iobase + PCI171x_CLRINT); - DPRINTK("adv_pci1710 EDBG: END: pci171x_insn_read_ai(...) n=%d\n",n); + DPRINTK("adv_pci1710 EDBG: END: pci171x_insn_read_ai(...) n=%d\n", n); return n; } /* ============================================================================== */ -static int pci171x_insn_write_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int pci171x_insn_write_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,chan,range,ofs; + int n, chan, range, ofs; - chan=CR_CHAN(insn->chanspec); - range=CR_RANGE(insn->chanspec); + chan = CR_CHAN(insn->chanspec); + range = CR_RANGE(insn->chanspec); if (chan) { - devpriv->da_ranges&=0xfb; - devpriv->da_ranges|=(range<<2); - outw(devpriv->da_ranges, dev->iobase+PCI171x_DAREF); - ofs=PCI171x_DA2; + devpriv->da_ranges &= 0xfb; + devpriv->da_ranges |= (range << 2); + outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); + ofs = PCI171x_DA2; } else { - devpriv->da_ranges&=0xfe; - devpriv->da_ranges|=range; - outw(devpriv->da_ranges, dev->iobase+PCI171x_DAREF); - ofs=PCI171x_DA1; + devpriv->da_ranges &= 0xfe; + devpriv->da_ranges |= range; + outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); + ofs = PCI171x_DA1; } - for (n=0; nn; n++) + for (n = 0; n < insn->n; n++) outw(data[n], dev->iobase + ofs); - devpriv->ao_data[chan]=data[n]; + devpriv->ao_data[chan] = data[n]; return n; @@ -403,13 +417,14 @@ static int pci171x_insn_write_ao(comedi_device * dev, comedi_subdevice * s, come /* ============================================================================== */ -static int pci171x_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int pci171x_insn_read_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,chan; + int n, chan; - chan=CR_CHAN(insn->chanspec); - for (n=0; nn; n++) - data[n]=devpriv->ao_data[chan]; + chan = CR_CHAN(insn->chanspec); + for (n = 0; n < insn->n; n++) + data[n] = devpriv->ao_data[chan]; return n; } @@ -417,7 +432,8 @@ static int pci171x_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comed /* ============================================================================== */ -static int pci171x_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci171x_insn_bits_di(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[1] = inw(dev->iobase + PCI171x_DI); @@ -427,11 +443,12 @@ static int pci171x_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi_i /* ============================================================================== */ -static int pci171x_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci171x_insn_bits_do(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); outw(s->state, dev->iobase + PCI171x_DO); } data[1] = s->state; @@ -442,17 +459,18 @@ static int pci171x_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi_i /* ============================================================================== */ -static int pci171x_insn_counter_read(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci171x_insn_counter_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int msb, lsb, ccntrl; int i; - ccntrl = 0xD2; /* count only */ - for (i=0; in; i++) { - outw(ccntrl, dev->iobase+PCI171x_CNTCTRL); + ccntrl = 0xD2; /* count only */ + for (i = 0; i < insn->n; i++) { + outw(ccntrl, dev->iobase + PCI171x_CNTCTRL); - lsb = inw(dev->iobase+PCI171x_CNT0) & 0xFF; - msb = inw(dev->iobase+PCI171x_CNT0) & 0xFF; + lsb = inw(dev->iobase + PCI171x_CNT0) & 0xFF; + msb = inw(dev->iobase + PCI171x_CNT0) & 0xFF; data[0] = lsb | (msb << 8); } @@ -463,7 +481,8 @@ static int pci171x_insn_counter_read(comedi_device *dev,comedi_subdevice *s, com /* ============================================================================== */ -static int pci171x_insn_counter_write(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci171x_insn_counter_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { uint msb, lsb, ccntrl, status; @@ -471,15 +490,15 @@ static int pci171x_insn_counter_write(comedi_device *dev,comedi_subdevice *s, co msb = (data[0] & 0xFF00) >> 8; /* write lsb, then msb */ - outw(lsb, dev->iobase+PCI171x_CNT0); - outw(msb, dev->iobase+PCI171x_CNT0); + outw(lsb, dev->iobase + PCI171x_CNT0); + outw(msb, dev->iobase + PCI171x_CNT0); - if ( devpriv->cnt0_write_wait ) { + if (devpriv->cnt0_write_wait) { /* wait for the new count to be loaded */ ccntrl = 0xE2; do { - outw(ccntrl, dev->iobase+PCI171x_CNTCTRL); - status = inw(dev->iobase+PCI171x_CNT0) & 0xFF; + outw(ccntrl, dev->iobase + PCI171x_CNTCTRL); + status = inw(dev->iobase + PCI171x_CNT0) & 0xFF; } while (status & 0x40); } @@ -489,7 +508,8 @@ static int pci171x_insn_counter_write(comedi_device *dev,comedi_subdevice *s, co /* ============================================================================== */ -static int pci171x_insn_counter_config(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int pci171x_insn_counter_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { #ifdef unused /* This doesn't work like a normal Comedi counter config */ @@ -498,20 +518,24 @@ static int pci171x_insn_counter_config(comedi_device *dev,comedi_subdevice *s, c devpriv->cnt0_write_wait = data[0] & 0x20; /* internal or external clock? */ - if ( ! (data[0] & 0x10) ) { /* internal */ + if (!(data[0] & 0x10)) { /* internal */ devpriv->CntrlReg &= ~Control_CNT0; } else { devpriv->CntrlReg |= Control_CNT0; } - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); - - if ( data[0] & 0x01 ) ccntrl |= Counter_M0; - if ( data[0] & 0x02 ) ccntrl |= Counter_M1; - if ( data[0] & 0x04 ) ccntrl |= Counter_M2; - if ( data[0] & 0x08 ) ccntrl |= Counter_BCD; - ccntrl |= Counter_RW0; /* set read/write mode */ + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + + if (data[0] & 0x01) + ccntrl |= Counter_M0; + if (data[0] & 0x02) + ccntrl |= Counter_M1; + if (data[0] & 0x04) + ccntrl |= Counter_M2; + if (data[0] & 0x08) + ccntrl |= Counter_BCD; + ccntrl |= Counter_RW0; /* set read/write mode */ ccntrl |= Counter_RW1; - outw(ccntrl, dev->iobase+PCI171x_CNTCTRL); + outw(ccntrl, dev->iobase + PCI171x_CNTCTRL); #endif return 1; @@ -520,24 +544,25 @@ static int pci171x_insn_counter_config(comedi_device *dev,comedi_subdevice *s, c /* ============================================================================== */ -static int pci1720_insn_write_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int pci1720_insn_write_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,rangereg,chan; - - chan=CR_CHAN(insn->chanspec); - rangereg=devpriv->da_ranges & (~(0x03<<(chan<<1))); - rangereg|=(CR_RANGE(insn->chanspec)<<(chan<<1)); - if (rangereg!=devpriv->da_ranges) { - outb(rangereg, dev->iobase+PCI1720_RANGE); - devpriv->da_ranges=rangereg; + int n, rangereg, chan; + + chan = CR_CHAN(insn->chanspec); + rangereg = devpriv->da_ranges & (~(0x03 << (chan << 1))); + rangereg |= (CR_RANGE(insn->chanspec) << (chan << 1)); + if (rangereg != devpriv->da_ranges) { + outb(rangereg, dev->iobase + PCI1720_RANGE); + devpriv->da_ranges = rangereg; } - for (n=0; nn; n++) { - outw(data[n], dev->iobase+PCI1720_DA0+(chan<<1)); - outb(0, dev->iobase + PCI1720_SYNCOUT); // update outputs + for (n = 0; n < insn->n; n++) { + outw(data[n], dev->iobase + PCI1720_DA0 + (chan << 1)); + outb(0, dev->iobase + PCI1720_SYNCOUT); // update outputs } - devpriv->ao_data[chan]=data[n]; + devpriv->ao_data[chan] = data[n]; return n; } @@ -547,62 +572,73 @@ static int pci1720_insn_write_ao(comedi_device * dev, comedi_subdevice * s, come */ static void interrupt_pci1710_every_sample(void *d) { - comedi_device *dev = d; + comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; - int m; + int m; #ifdef PCI171x_PARANOIDCHECK sampl_t sampl; #endif DPRINTK("adv_pci1710 EDBG: BGN: interrupt_pci1710_every_sample(...)\n"); - m=inw(dev->iobase+PCI171x_STATUS); + m = inw(dev->iobase + PCI171x_STATUS); if (m & Status_FE) { rt_printk("comedi%d: A/D FIFO empty (%4x)\n", dev->minor, m); - pci171x_ai_cancel(dev,s); + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return; } if (m & Status_FF) { - rt_printk("comedi%d: A/D FIFO Full status (Fatal Error!) (%4x)\n", dev->minor, m); - pci171x_ai_cancel(dev,s); + rt_printk + ("comedi%d: A/D FIFO Full status (Fatal Error!) (%4x)\n", + dev->minor, m); + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return; } - outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request + outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request DPRINTK("FOR "); - for (;!(inw(dev->iobase+PCI171x_STATUS)&Status_FE);) { + for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) { #ifdef PCI171x_PARANOIDCHECK - sampl=inw(dev->iobase+PCI171x_AD_DATA); - DPRINTK("%04x:",sampl); - if (this_board->cardtype!=TYPE_PCI1713) - if ((sampl & 0xf000)!=devpriv->act_chanlist[s->async->cur_chan]) { - rt_printk("comedi: A/D data dropout: received data from channel %d, expected %d!\n",(sampl & 0xf000)>>12,(devpriv->act_chanlist[s->async->cur_chan] & 0xf000)>>12); - pci171x_ai_cancel(dev,s); - s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; + sampl = inw(dev->iobase + PCI171x_AD_DATA); + DPRINTK("%04x:", sampl); + if (this_board->cardtype != TYPE_PCI1713) + if ((sampl & 0xf000) != + devpriv->act_chanlist[s->async->cur_chan]) { + rt_printk + ("comedi: A/D data dropout: received data from channel %d, expected %d!\n", + (sampl & 0xf000) >> 12, + (devpriv->act_chanlist[s->async-> + cur_chan] & 0xf000) >> + 12); + pci171x_ai_cancel(dev, s); + s->async->events |= + COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return; } - DPRINTK("%8d %2d %8d~",s->async->buf_int_ptr,s->async->cur_chan,s->async->buf_int_count); - comedi_buf_put( s->async, sampl & 0x0fff); + DPRINTK("%8d %2d %8d~", s->async->buf_int_ptr, + s->async->cur_chan, s->async->buf_int_count); + comedi_buf_put(s->async, sampl & 0x0fff); #else - comedi_buf_put( s->async, inw(dev->iobase+PCI171x_AD_DATA) & 0x0fff); + comedi_buf_put(s->async, + inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff); #endif ++s->async->cur_chan; - if(s->async->cur_chan>=devpriv->ai_n_chan){ - s->async->cur_chan=0; + if (s->async->cur_chan >= devpriv->ai_n_chan) { + s->async->cur_chan = 0; } - if(s->async->cur_chan == 0){ // one scan done - devpriv->ai_act_scan++; - DPRINTK("adv_pci1710 EDBG: EOS1 bic %d bip %d buc %d bup %d\n",s->async->buf_int_count,s->async->buf_int_ptr, s->async->buf_user_count, s->async->buf_user_ptr); - DPRINTK("adv_pci1710 EDBG: EOS2\n"); - if ((!devpriv->neverending_ai)&&(devpriv->ai_act_scan>=devpriv->ai_scans)) { // all data sampled - pci171x_ai_cancel(dev,s); + if (s->async->cur_chan == 0) { // one scan done + devpriv->ai_act_scan++; + DPRINTK("adv_pci1710 EDBG: EOS1 bic %d bip %d buc %d bup %d\n", s->async->buf_int_count, s->async->buf_int_ptr, s->async->buf_user_count, s->async->buf_user_ptr); + DPRINTK("adv_pci1710 EDBG: EOS2\n"); + if ((!devpriv->neverending_ai) && (devpriv->ai_act_scan >= devpriv->ai_scans)) { // all data sampled + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); return; @@ -610,7 +646,7 @@ static void interrupt_pci1710_every_sample(void *d) } } - outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request + outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request DPRINTK("adv_pci1710 EDBG: END: interrupt_pci1710_every_sample(...)\n"); comedi_event(dev, s); @@ -619,34 +655,43 @@ static void interrupt_pci1710_every_sample(void *d) /* ============================================================================== */ -static int move_block_from_fifo(comedi_device *dev,comedi_subdevice *s, int n, int turn) +static int move_block_from_fifo(comedi_device * dev, comedi_subdevice * s, + int n, int turn) { - int i,j; + int i, j; #ifdef PCI171x_PARANOIDCHECK int sampl; #endif - DPRINTK("adv_pci1710 EDBG: BGN: move_block_from_fifo(...,%d,%d)\n",n,turn); - j=s->async->cur_chan; - for(i=0;iasync->cur_chan; + for (i = 0; i < n; i++) { #ifdef PCI171x_PARANOIDCHECK - sampl=inw(dev->iobase+PCI171x_AD_DATA); - if (this_board->cardtype!=TYPE_PCI1713) - if ((sampl & 0xf000)!=devpriv->act_chanlist[j]) { - rt_printk("comedi%d: A/D FIFO data dropout: received data from channel %d, expected %d! (%d/%d/%d/%d/%d/%4x)\n", - dev->minor, (sampl & 0xf000)>>12,(devpriv->act_chanlist[j] & 0xf000)>>12, i, j, devpriv->ai_act_scan, n, turn, sampl); - pci171x_ai_cancel(dev,s); - s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; + sampl = inw(dev->iobase + PCI171x_AD_DATA); + if (this_board->cardtype != TYPE_PCI1713) + if ((sampl & 0xf000) != devpriv->act_chanlist[j]) { + rt_printk + ("comedi%d: A/D FIFO data dropout: received data from channel %d, expected %d! (%d/%d/%d/%d/%d/%4x)\n", + dev->minor, (sampl & 0xf000) >> 12, + (devpriv-> + act_chanlist[j] & 0xf000) >> 12, + i, j, devpriv->ai_act_scan, n, turn, + sampl); + pci171x_ai_cancel(dev, s); + s->async->events |= + COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return 1; } - comedi_buf_put( s->async, sampl & 0x0fff ); + comedi_buf_put(s->async, sampl & 0x0fff); #else - comedi_buf_put( s->async, inw(dev->iobase+PCI171x_AD_DATA) & 0x0fff ); + comedi_buf_put(s->async, + inw(dev->iobase + PCI171x_AD_DATA) & 0x0fff); #endif j++; - if(j>=devpriv->ai_n_chan){ - j=0; - devpriv->ai_act_scan++; + if (j >= devpriv->ai_n_chan) { + j = 0; + devpriv->ai_act_scan++; } } DPRINTK("adv_pci1710 EDBG: END: move_block_from_fifo(...)\n"); @@ -658,48 +703,51 @@ static int move_block_from_fifo(comedi_device *dev,comedi_subdevice *s, int n, i */ static void interrupt_pci1710_half_fifo(void *d) { - comedi_device *dev = d; + comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; - int m,samplesinbuf; + int m, samplesinbuf; DPRINTK("adv_pci1710 EDBG: BGN: interrupt_pci1710_half_fifo(...)\n"); - m=inw(dev->iobase+PCI171x_STATUS); + m = inw(dev->iobase + PCI171x_STATUS); if (!(m & Status_FH)) { - rt_printk("comedi%d: A/D FIFO not half full! (%4x)\n", dev->minor, m); - pci171x_ai_cancel(dev,s); + rt_printk("comedi%d: A/D FIFO not half full! (%4x)\n", + dev->minor, m); + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return; } if (m & Status_FF) { - rt_printk("comedi%d: A/D FIFO Full status (Fatal Error!) (%4x)\n", dev->minor, m); - pci171x_ai_cancel(dev,s); + rt_printk + ("comedi%d: A/D FIFO Full status (Fatal Error!) (%4x)\n", + dev->minor, m); + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return; } - samplesinbuf=this_board->fifo_half_size; - if(samplesinbuf*sizeof(sampl_t)>=devpriv->ai_data_len){ - m=devpriv->ai_data_len/sizeof(sampl_t); - if (move_block_from_fifo(dev,s,m,0)) + samplesinbuf = this_board->fifo_half_size; + if (samplesinbuf * sizeof(sampl_t) >= devpriv->ai_data_len) { + m = devpriv->ai_data_len / sizeof(sampl_t); + if (move_block_from_fifo(dev, s, m, 0)) return; - samplesinbuf-=m; + samplesinbuf -= m; } if (samplesinbuf) { - if (move_block_from_fifo(dev,s,samplesinbuf,1)) + if (move_block_from_fifo(dev, s, samplesinbuf, 1)) return; } if (!devpriv->neverending_ai) - if ( devpriv->ai_act_scan>=devpriv->ai_scans ) { /* all data sampled */ - pci171x_ai_cancel(dev,s); + if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ + pci171x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); return; } - outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request + outb(0, dev->iobase + PCI171x_CLRINT); // clear our INT request DPRINTK("adv_pci1710 EDBG: END: interrupt_pci1710_half_fifo(...)\n"); comedi_event(dev, s); @@ -712,30 +760,32 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d PT_REGS_ARG) { comedi_device *dev = d; - DPRINTK("adv_pci1710 EDBG: BGN: interrupt_service_pci1710(%d,...)\n",irq); + DPRINTK("adv_pci1710 EDBG: BGN: interrupt_service_pci1710(%d,...)\n", + irq); if (!dev->attached) // is device attached? - return IRQ_NONE; // no, exit + return IRQ_NONE; // no, exit - if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ)) // is this interrupt from our board? - return IRQ_NONE; // no, exit + if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ)) // is this interrupt from our board? + return IRQ_NONE; // no, exit - DPRINTK("adv_pci1710 EDBG: interrupt_service_pci1710() ST: %4x\n",inw(dev->iobase + PCI171x_STATUS)); + DPRINTK("adv_pci1710 EDBG: interrupt_service_pci1710() ST: %4x\n", + inw(dev->iobase + PCI171x_STATUS)); if (devpriv->ai_et) { // Switch from initial TRIG_EXT to TRIG_xxx. devpriv->ai_et = 0; - devpriv->CntrlReg&=Control_CNT0; - devpriv->CntrlReg|=Control_SW; // set software trigger - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); - devpriv->CntrlReg=devpriv->ai_et_CntrlReg; - outb(0,dev->iobase + PCI171x_CLRFIFO); - outb(0,dev->iobase + PCI171x_CLRINT); - outw(devpriv->ai_et_MuxVal, dev->iobase+PCI171x_MUX); - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); + devpriv->CntrlReg &= Control_CNT0; + devpriv->CntrlReg |= Control_SW; // set software trigger + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); + devpriv->CntrlReg = devpriv->ai_et_CntrlReg; + outb(0, dev->iobase + PCI171x_CLRFIFO); + outb(0, dev->iobase + PCI171x_CLRINT); + outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); // start pacer start_pacer(dev, 1, devpriv->ai_et_div1, devpriv->ai_et_div2); return IRQ_HANDLED; } - if (devpriv->ai_eos) { // We use FIFO half full INT or not? + if (devpriv->ai_eos) { // We use FIFO half full INT or not? interrupt_pci1710_every_sample(d); } else { interrupt_pci1710_half_fifo(d); @@ -747,56 +797,67 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d PT_REGS_ARG) /* ============================================================================== */ -static int pci171x_ai_docmd_and_mode(int mode, comedi_device * dev, comedi_subdevice * s) +static int pci171x_ai_docmd_and_mode(int mode, comedi_device * dev, + comedi_subdevice * s) { - unsigned int divisor1, divisor2; + unsigned int divisor1, divisor2; unsigned int seglen; - DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_docmd_and_mode(%d,...)\n",mode); - start_pacer(dev, -1, 0, 0); // stop pacer + DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_docmd_and_mode(%d,...)\n", + mode); + start_pacer(dev, -1, 0, 0); // stop pacer - seglen = check_channel_list(dev, s, devpriv->ai_chanlist, + seglen = check_channel_list(dev, s, devpriv->ai_chanlist, devpriv->ai_n_chan); - if(seglen<1)return -EINVAL; - setup_channel_list(dev, s, devpriv->ai_chanlist, - devpriv->ai_n_chan,seglen); + if (seglen < 1) + return -EINVAL; + setup_channel_list(dev, s, devpriv->ai_chanlist, + devpriv->ai_n_chan, seglen); outb(0, dev->iobase + PCI171x_CLRFIFO); outb(0, dev->iobase + PCI171x_CLRINT); - devpriv->ai_do=mode; + devpriv->ai_do = mode; - devpriv->ai_act_scan=0; - s->async->cur_chan=0; - devpriv->ai_buf_ptr=0; - devpriv->neverending_ai=0; + devpriv->ai_act_scan = 0; + s->async->cur_chan = 0; + devpriv->ai_buf_ptr = 0; + devpriv->neverending_ai = 0; - devpriv->CntrlReg&=Control_CNT0; - if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? devpriv->ai_eos=1; - devpriv->ai_eos=1; + devpriv->CntrlReg &= Control_CNT0; + if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? devpriv->ai_eos=1; + devpriv->ai_eos = 1; } else { - devpriv->CntrlReg|=Control_ONEFH; - devpriv->ai_eos=0; + devpriv->CntrlReg |= Control_ONEFH; + devpriv->ai_eos = 0; } - if ((devpriv->ai_scans==0)||(devpriv->ai_scans==-1)) { devpriv->neverending_ai=1; } //well, user want neverending - else { devpriv->neverending_ai=0; } + if ((devpriv->ai_scans == 0) || (devpriv->ai_scans == -1)) { + devpriv->neverending_ai = 1; + } //well, user want neverending + else { + devpriv->neverending_ai = 0; + } switch (mode) { case 1: case 2: - if (devpriv->ai_timer1ai_ns_min) devpriv->ai_timer1=this_board->ai_ns_min; - devpriv->CntrlReg|=Control_PACER|Control_IRQEN; + if (devpriv->ai_timer1 < this_board->ai_ns_min) + devpriv->ai_timer1 = this_board->ai_ns_min; + devpriv->CntrlReg |= Control_PACER | Control_IRQEN; if (mode == 2) { - devpriv->ai_et_CntrlReg=devpriv->CntrlReg; - devpriv->CntrlReg&=~(Control_PACER|Control_ONEFH|Control_GATE); - devpriv->CntrlReg|=Control_EXT; - devpriv->ai_et=1; + devpriv->ai_et_CntrlReg = devpriv->CntrlReg; + devpriv->CntrlReg &= + ~(Control_PACER | Control_ONEFH | Control_GATE); + devpriv->CntrlReg |= Control_EXT; + devpriv->ai_et = 1; } else { - devpriv->ai_et=0; + devpriv->ai_et = 0; } - i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,&divisor1,&divisor2,&devpriv->ai_timer1,devpriv->ai_flags&TRIG_ROUND_MASK); - DPRINTK("adv_pci1710 EDBG: OSC base=%u div1=%u div2=%u timer=%u\n",devpriv->i8254_osc_base,divisor1,divisor2,devpriv->ai_timer1); - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); + i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1, + &divisor2, &devpriv->ai_timer1, + devpriv->ai_flags & TRIG_ROUND_MASK); + DPRINTK("adv_pci1710 EDBG: OSC base=%u div1=%u div2=%u timer=%u\n", devpriv->i8254_osc_base, divisor1, divisor2, devpriv->ai_timer1); + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); if (mode != 2) { // start pacer start_pacer(dev, mode, divisor1, divisor2); @@ -806,36 +867,40 @@ static int pci171x_ai_docmd_and_mode(int mode, comedi_device * dev, comedi_subde } break; case 3: - devpriv->CntrlReg|=Control_EXT|Control_IRQEN; - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); + devpriv->CntrlReg |= Control_EXT | Control_IRQEN; + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); break; } - DPRINTK("adv_pci1710 EDBG: END: pci171x_ai_docmd_and_mode(...)\n"); return 0; } - #ifdef PCI171X_EXTDEBUG /* ============================================================================== */ -static void pci171x_cmdtest_out(int e,comedi_cmd *cmd) { - rt_printk("adv_pci1710 e=%d startsrc=%x scansrc=%x convsrc=%x\n",e,cmd->start_src,cmd->scan_begin_src,cmd->convert_src); - rt_printk("adv_pci1710 e=%d startarg=%d scanarg=%d convarg=%d\n",e,cmd->start_arg,cmd->scan_begin_arg,cmd->convert_arg); - rt_printk("adv_pci1710 e=%d stopsrc=%x scanend=%x\n",e,cmd->stop_src,cmd->scan_end_src); - rt_printk("adv_pci1710 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n",e,cmd->stop_arg,cmd->scan_end_arg,cmd->chanlist_len); +static void pci171x_cmdtest_out(int e, comedi_cmd * cmd) +{ + rt_printk("adv_pci1710 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e, + cmd->start_src, cmd->scan_begin_src, cmd->convert_src); + rt_printk("adv_pci1710 e=%d startarg=%d scanarg=%d convarg=%d\n", e, + cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg); + rt_printk("adv_pci1710 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src, + cmd->scan_end_src); + rt_printk("adv_pci1710 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", + e, cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len); } #endif /* ============================================================================== */ -static int pci171x_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int pci171x_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; - int tmp,divisor1,divisor2; + int err = 0; + int tmp, divisor1, divisor2; DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...)\n"); #ifdef PCI171X_EXTDEBUG @@ -843,141 +908,150 @@ static int pci171x_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd #endif /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_EXT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) { + if (err) { #ifdef PCI171X_EXTDEBUG pci171x_cmdtest_out(1, cmd); #endif - DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=1\n",err); + DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=1\n", err); return 1; } /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src!=TRIG_NOW&&cmd->start_src!=TRIG_EXT) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) { + cmd->start_src = TRIG_NOW; err++; } - if(cmd->scan_begin_src!=TRIG_FOLLOW) { - cmd->scan_begin_src=TRIG_FOLLOW; + if (cmd->scan_begin_src != TRIG_FOLLOW) { + cmd->scan_begin_src = TRIG_FOLLOW; err++; } - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT) err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; - if(cmd->scan_end_src!=TRIG_COUNT) { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT) err++; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; - if(err) { + if (err) { #ifdef PCI171X_EXTDEBUG pci171x_cmdtest_out(2, cmd); #endif - DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=2\n",err); + DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=2\n", err); return 2; } /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argai_ns_min){ - cmd->convert_arg=this_board->ai_ns_min; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_ns_min) { + cmd->convert_arg = this_board->ai_ns_min; err++; } - } else { /* TRIG_FOLLOW */ - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + } else { /* TRIG_FOLLOW */ + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } } - if(!cmd->chanlist_len){ - cmd->chanlist_len=1; + if (!cmd->chanlist_len) { + cmd->chanlist_len = 1; err++; } - if(cmd->chanlist_len>this_board->n_aichan){ - cmd->chanlist_len=this_board->n_aichan; + if (cmd->chanlist_len > this_board->n_aichan) { + cmd->chanlist_len = this_board->n_aichan; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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){ - cmd->stop_arg=1; + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { + cmd->stop_arg = 1; err++; } - } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err) { + if (err) { #ifdef PCI171X_EXTDEBUG pci171x_cmdtest_out(3, cmd); #endif - DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=3\n",err); + DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=3\n", err); return 3; } /* step 4: fix up any arguments */ - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - i8253_cascade_ns_to_timer(devpriv->i8254_osc_base,&divisor1,&divisor2,&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(cmd->convert_argai_ns_min) - cmd->convert_arg=this_board->ai_ns_min; - if(tmp!=cmd->convert_arg)err++; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer(devpriv->i8254_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + if (tmp != cmd->convert_arg) + err++; } - if(err) { - DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=4\n",err); + if (err) { + DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=4\n", err); return 4; } /* step 5: complain about special chanlist considerations */ - if (cmd->chanlist){ + if (cmd->chanlist) { if (!check_channel_list(dev, s, cmd->chanlist, - cmd->chanlist_len)) return 5; // incorrect channels list + cmd->chanlist_len)) + return 5; // incorrect channels list } DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) ret=0\n"); @@ -987,29 +1061,33 @@ static int pci171x_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd /* ============================================================================== */ -static int pci171x_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int pci171x_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; DPRINTK("adv_pci1710 EDBG: BGN: pci171x_ai_cmd(...)\n"); - devpriv->ai_n_chan=cmd->chanlist_len; - devpriv->ai_chanlist=cmd->chanlist; - devpriv->ai_flags=cmd->flags; - devpriv->ai_data_len=s->async->prealloc_bufsz; - devpriv->ai_data=s->async->prealloc_buf; - devpriv->ai_timer1=0; - devpriv->ai_timer2=0; - - if (cmd->stop_src==TRIG_COUNT) { devpriv->ai_scans=cmd->stop_arg; } - else { devpriv->ai_scans=0; } - - if(cmd->scan_begin_src==TRIG_FOLLOW){ // mode 1, 2, 3 - if (cmd->convert_src==TRIG_TIMER) { // mode 1 and 2 - devpriv->ai_timer1=cmd->convert_arg; - return pci171x_ai_docmd_and_mode(cmd->start_src==TRIG_EXT?2:1,dev,s); + devpriv->ai_n_chan = cmd->chanlist_len; + devpriv->ai_chanlist = cmd->chanlist; + devpriv->ai_flags = cmd->flags; + devpriv->ai_data_len = s->async->prealloc_bufsz; + devpriv->ai_data = s->async->prealloc_buf; + devpriv->ai_timer1 = 0; + devpriv->ai_timer2 = 0; + + if (cmd->stop_src == TRIG_COUNT) { + devpriv->ai_scans = cmd->stop_arg; + } else { + devpriv->ai_scans = 0; + } + + if (cmd->scan_begin_src == TRIG_FOLLOW) { // mode 1, 2, 3 + if (cmd->convert_src == TRIG_TIMER) { // mode 1 and 2 + devpriv->ai_timer1 = cmd->convert_arg; + return pci171x_ai_docmd_and_mode(cmd->start_src == + TRIG_EXT ? 2 : 1, dev, s); } - if (cmd->convert_src==TRIG_EXT) { // mode 3 - return pci171x_ai_docmd_and_mode(3,dev,s); + if (cmd->convert_src == TRIG_EXT) { // mode 3 + return pci171x_ai_docmd_and_mode(3, dev, s); } } @@ -1022,96 +1100,116 @@ static int pci171x_ai_cmd(comedi_device *dev,comedi_subdevice *s) If it's ok, then program scan/gain logic. This works for all cards. */ -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan) +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan) { - unsigned int chansegment[32]; - unsigned int i, nowmustbechan, seglen, segpos; + unsigned int chansegment[32]; + unsigned int i, nowmustbechan, seglen, segpos; - DPRINTK("adv_pci1710 EDBG: check_channel_list(...,%d)\n",n_chan); - /* correct channel and range number check itself comedi/range.c */ - if (n_chan<1) { - comedi_error(dev,"range/channel list is empty!"); + DPRINTK("adv_pci1710 EDBG: check_channel_list(...,%d)\n", n_chan); + /* correct channel and range number check itself comedi/range.c */ + if (n_chan < 1) { + comedi_error(dev, "range/channel list is empty!"); return 0; - } + } - if (n_chan > 1) { - chansegment[0]=chanlist[0]; // first channel is everytime ok - for (i=1, seglen=1; i 1) { + chansegment[0] = chanlist[0]; // first channel is everytime ok + for (i = 1, seglen = 1; i < n_chan; i++, seglen++) { // build part of chanlist // rt_printk("%d. %d %d\n",i,CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i])); - if (chanlist[0]==chanlist[i]) break; // we detect loop, this must by finish - if (CR_CHAN(chanlist[i]) & 1) // odd channel cann't by differencial - if (CR_AREF(chanlist[i])==AREF_DIFF) { - comedi_error(dev,"Odd channel can't be differential input!\n"); + if (chanlist[0] == chanlist[i]) + break; // we detect loop, this must by finish + if (CR_CHAN(chanlist[i]) & 1) // odd channel cann't by differencial + if (CR_AREF(chanlist[i]) == AREF_DIFF) { + comedi_error(dev, + "Odd channel can't be differential input!\n"); return 0; } - nowmustbechan=(CR_CHAN(chansegment[i-1])+1) % s->n_chan; - if (CR_AREF(chansegment[i-1])==AREF_DIFF) - nowmustbechan=(nowmustbechan+1) % s->n_chan; - if (nowmustbechan!=CR_CHAN(chanlist[i])) { // channel list isn't continous :-( - rt_printk("channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", - i,CR_CHAN(chanlist[i]),nowmustbechan,CR_CHAN(chanlist[0]) ); + nowmustbechan = + (CR_CHAN(chansegment[i - 1]) + 1) % s->n_chan; + if (CR_AREF(chansegment[i - 1]) == AREF_DIFF) + nowmustbechan = (nowmustbechan + 1) % s->n_chan; + if (nowmustbechan != CR_CHAN(chanlist[i])) { // channel list isn't continous :-( + rt_printk + ("channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", + i, CR_CHAN(chanlist[i]), nowmustbechan, + CR_CHAN(chanlist[0])); return 0; } - chansegment[i]=chanlist[i]; // well, this is next correct channel in list + chansegment[i] = chanlist[i]; // well, this is next correct channel in list } - for (i=0, segpos=0; iact_chanlist_len=seglen; - devpriv->act_chanlist_pos=0; + DPRINTK("adv_pci1710 EDBG: setup_channel_list(...,%d,%d)\n", n_chan, + seglen); + devpriv->act_chanlist_len = seglen; + devpriv->act_chanlist_pos = 0; DPRINTK("SegLen: %d\n", seglen); - for (i=0; iiobase+PCI171x_MUX); /* select channel */ - range=this_board->rangecode_ai[CR_RANGE(chanlist[i])]; - if (CR_AREF(chanlist[i])==AREF_DIFF) range|=0x0020; - outw(range, dev->iobase+PCI171x_RANGE); /* select gain */ + for (i = 0; i < seglen; i++) { // store range list to card + chanprog = muxonechan[CR_CHAN(chanlist[i])]; + outw(chanprog, dev->iobase + PCI171x_MUX); /* select channel */ + range = this_board->rangecode_ai[CR_RANGE(chanlist[i])]; + if (CR_AREF(chanlist[i]) == AREF_DIFF) + range |= 0x0020; + outw(range, dev->iobase + PCI171x_RANGE); /* select gain */ #ifdef PCI171x_PARANOIDCHECK - devpriv->act_chanlist[i]=(CR_CHAN(chanlist[i])<<12) & 0xf000; + devpriv->act_chanlist[i] = + (CR_CHAN(chanlist[i]) << 12) & 0xf000; #endif - DPRINTK("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range, devpriv->act_chanlist[i]); + DPRINTK("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range, + devpriv->act_chanlist[i]); } devpriv->ai_et_MuxVal = - CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen-1]) << 8); - outw(devpriv->ai_et_MuxVal, dev->iobase+PCI171x_MUX); /* select channel interval to scan */ - DPRINTK("MUX: %4x L%4x.H%4x\n", CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen-1]) << 8), CR_CHAN(chanlist[0]), CR_CHAN(chanlist[seglen-1])); + CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8); + outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX); /* select channel interval to scan */ + DPRINTK("MUX: %4x L%4x.H%4x\n", + CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen - 1]) << 8), + CR_CHAN(chanlist[0]), CR_CHAN(chanlist[seglen - 1])); } /* ============================================================================== */ -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2) +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2) { - DPRINTK("adv_pci1710 EDBG: BGN: start_pacer(%d,%u,%u)\n",mode,divisor1,divisor2); - outw(0xb4, dev->iobase + PCI171x_CNTCTRL); - outw(0x74, dev->iobase + PCI171x_CNTCTRL); + DPRINTK("adv_pci1710 EDBG: BGN: start_pacer(%d,%u,%u)\n", mode, + divisor1, divisor2); + outw(0xb4, dev->iobase + PCI171x_CNTCTRL); + outw(0x74, dev->iobase + PCI171x_CNTCTRL); - if (mode==1) { + if (mode == 1) { outw(divisor2 & 0xff, dev->iobase + PCI171x_CNT2); outw((divisor2 >> 8) & 0xff, dev->iobase + PCI171x_CNT2); - outw(divisor1 & 0xff, dev->iobase + PCI171x_CNT1); + outw(divisor1 & 0xff, dev->iobase + PCI171x_CNT1); outw((divisor1 >> 8) & 0xff, dev->iobase + PCI171x_CNT1); - } + } DPRINTK("adv_pci1710 EDBG: END: start_pacer(...)\n"); } @@ -1124,21 +1222,21 @@ static int pci171x_ai_cancel(comedi_device * dev, comedi_subdevice * s) switch (this_board->cardtype) { default: - devpriv->CntrlReg&=Control_CNT0; - devpriv->CntrlReg|=Control_SW; + devpriv->CntrlReg &= Control_CNT0; + devpriv->CntrlReg |= Control_SW; - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); // reset any operations - start_pacer(dev,-1,0,0); - outb(0,dev->iobase + PCI171x_CLRFIFO); - outb(0,dev->iobase + PCI171x_CLRINT); + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); // reset any operations + start_pacer(dev, -1, 0, 0); + outb(0, dev->iobase + PCI171x_CLRFIFO); + outb(0, dev->iobase + PCI171x_CLRINT); break; } - devpriv->ai_do=0; - devpriv->ai_act_scan=0; - s->async->cur_chan=0; - devpriv->ai_buf_ptr=0; - devpriv->neverending_ai=0; + devpriv->ai_do = 0; + devpriv->ai_act_scan = 0; + s->async->cur_chan = 0; + devpriv->ai_buf_ptr = 0; + devpriv->neverending_ai = 0; DPRINTK("adv_pci1710 EDBG: END: pci171x_ai_cancel(...)\n"); return 0; @@ -1147,28 +1245,28 @@ static int pci171x_ai_cancel(comedi_device * dev, comedi_subdevice * s) /* ============================================================================== */ -static int pci171x_reset(comedi_device *dev) +static int pci171x_reset(comedi_device * dev) { DPRINTK("adv_pci1710 EDBG: BGN: pci171x_reset(...)\n"); outw(0x30, dev->iobase + PCI171x_CNTCTRL); - devpriv->CntrlReg=Control_SW | Control_CNT0; // Software trigger, CNT0=external - outw(devpriv->CntrlReg, dev->iobase+PCI171x_CONTROL); // reset any operations - outb(0, dev->iobase + PCI171x_CLRFIFO); // clear FIFO - outb(0, dev->iobase + PCI171x_CLRINT); // clear INT request - start_pacer(dev,-1,0,0); // stop 8254 - devpriv->da_ranges=0; + devpriv->CntrlReg = Control_SW | Control_CNT0; // Software trigger, CNT0=external + outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL); // reset any operations + outb(0, dev->iobase + PCI171x_CLRFIFO); // clear FIFO + outb(0, dev->iobase + PCI171x_CLRINT); // clear INT request + start_pacer(dev, -1, 0, 0); // stop 8254 + devpriv->da_ranges = 0; if (this_board->n_aochan) { - outb(devpriv->da_ranges, dev->iobase+PCI171x_DAREF); // set DACs to 0..5V - outw(0, dev->iobase+PCI171x_DA1); // set DA outputs to 0V - devpriv->ao_data[0]=0x0000; - if (this_board->n_aochan>1) { - outw(0, dev->iobase+PCI171x_DA2); - devpriv->ao_data[1]=0x0000; + outb(devpriv->da_ranges, dev->iobase + PCI171x_DAREF); // set DACs to 0..5V + outw(0, dev->iobase + PCI171x_DA1); // set DA outputs to 0V + devpriv->ao_data[0] = 0x0000; + if (this_board->n_aochan > 1) { + outw(0, dev->iobase + PCI171x_DA2); + devpriv->ao_data[1] = 0x0000; } } - outw(0, dev->iobase + PCI171x_DO); // digital outputs to 0 - outb(0, dev->iobase + PCI171x_CLRFIFO); // clear FIFO - outb(0, dev->iobase + PCI171x_CLRINT); // clear INT request + outw(0, dev->iobase + PCI171x_DO); // digital outputs to 0 + outb(0, dev->iobase + PCI171x_CLRFIFO); // clear FIFO + outb(0, dev->iobase + PCI171x_CLRINT); // clear INT request DPRINTK("adv_pci1710 EDBG: END: pci171x_reset(...)\n"); return 0; @@ -1177,19 +1275,21 @@ static int pci171x_reset(comedi_device *dev) /* ============================================================================== */ -static int pci1720_reset(comedi_device *dev) +static int pci1720_reset(comedi_device * dev) { DPRINTK("adv_pci1710 EDBG: BGN: pci1720_reset(...)\n"); - outb(Syncont_SC0, dev->iobase + PCI1720_SYNCONT); // set synchronous output mode - devpriv->da_ranges=0xAA; - outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE); // set all ranges to +/-5V + outb(Syncont_SC0, dev->iobase + PCI1720_SYNCONT); // set synchronous output mode + devpriv->da_ranges = 0xAA; + outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE); // set all ranges to +/-5V outw(0x0800, dev->iobase + PCI1720_DA0); // set outputs to 0V outw(0x0800, dev->iobase + PCI1720_DA1); outw(0x0800, dev->iobase + PCI1720_DA2); outw(0x0800, dev->iobase + PCI1720_DA3); - outb(0, dev->iobase + PCI1720_SYNCOUT); // update outputs - devpriv->ao_data[0]=0x0800; devpriv->ao_data[1]=0x0800; - devpriv->ao_data[2]=0x0800; devpriv->ao_data[3]=0x0800; + outb(0, dev->iobase + PCI1720_SYNCOUT); // update outputs + devpriv->ao_data[0] = 0x0800; + devpriv->ao_data[1] = 0x0800; + devpriv->ao_data[2] = 0x0800; + devpriv->ao_data[3] = 0x0800; DPRINTK("adv_pci1710 EDBG: END: pci1720_reset(...)\n"); return 0; } @@ -1197,10 +1297,10 @@ static int pci1720_reset(comedi_device *dev) /* ============================================================================== */ -static int pci1710_reset(comedi_device *dev) +static int pci1710_reset(comedi_device * dev) { DPRINTK("adv_pci1710 EDBG: BGN: pci1710_reset(...)\n"); - switch (this_board->cardtype) { + switch (this_board->cardtype) { case TYPE_PCI1720: return pci1720_reset(dev); default: @@ -1212,23 +1312,24 @@ static int pci1710_reset(comedi_device *dev) /* ============================================================================== */ -static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) +static int pci1710_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int ret,subdev,n_subdevices; + int ret, subdev, n_subdevices; unsigned int irq; - unsigned long iobase; + unsigned long iobase; struct pci_dev *pcidev; int opt_bus, opt_slot; const char *errstr; - unsigned char pci_bus,pci_slot,pci_func; + unsigned char pci_bus, pci_slot, pci_func; - rt_printk("comedi%d: adv_pci1710: board=%s",dev->minor,this_board->name); + rt_printk("comedi%d: adv_pci1710: board=%s", dev->minor, + this_board->name); opt_bus = it->options[0]; opt_slot = it->options[1]; - if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) { + if ((ret = alloc_private(dev, sizeof(pci1710_private))) < 0) { rt_printk(" - Allocation failed!\n"); return -ENOMEM; } @@ -1237,12 +1338,12 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) errstr = "not found!"; pcidev = NULL; while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH, - this_board->device_id, pcidev))) { + this_board->device_id, pcidev))) { /* Found matching vendor/device. */ if (opt_bus || opt_slot) { /* Check bus/slot. */ if (opt_bus != pcidev->bus->number - || opt_slot != PCI_SLOT(pcidev->devfn)) + || opt_slot != PCI_SLOT(pcidev->devfn)) continue; /* no match */ } /* @@ -1259,7 +1360,7 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) if (!pcidev) { if (opt_bus || opt_slot) { rt_printk(" - Card at b:s %d:%d %s\n", - opt_bus, opt_slot, errstr); + opt_bus, opt_slot, errstr); } else { rt_printk(" - Card %s\n", errstr); } @@ -1272,32 +1373,42 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) irq = pcidev->irq; iobase = pci_resource_start(pcidev, 2); - rt_printk(", b:s:f=%d:%d:%d, io=0x%4lx",pci_bus,pci_slot,pci_func,iobase); + rt_printk(", b:s:f=%d:%d:%d, io=0x%4lx", pci_bus, pci_slot, pci_func, + iobase); - dev->iobase=iobase; + dev->iobase = iobase; dev->board_name = this_board->name; devpriv->pcidev = pcidev; - n_subdevices = 0; - if (this_board->n_aichan) n_subdevices++; - if (this_board->n_aochan) n_subdevices++; - if (this_board->n_dichan) n_subdevices++; - if (this_board->n_dochan) n_subdevices++; - if (this_board->n_counter) n_subdevices++; - - if((ret=alloc_subdevices(dev, n_subdevices))<0) { + n_subdevices = 0; + if (this_board->n_aichan) + n_subdevices++; + if (this_board->n_aochan) + n_subdevices++; + if (this_board->n_dichan) + n_subdevices++; + if (this_board->n_dochan) + n_subdevices++; + if (this_board->n_counter) + n_subdevices++; + + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) { rt_printk(" - Allocation failed!\n"); - return ret; + return ret; } pci1710_reset(dev); if (this_board->have_irq) { - if (irq) { - if (comedi_request_irq(irq, interrupt_service_pci1710, IRQF_SHARED, "Advantech PCI-1710", dev)) { - rt_printk(", unable to allocate IRQ %d, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ + if (irq) { + if (comedi_request_irq(irq, interrupt_service_pci1710, + IRQF_SHARED, "Advantech PCI-1710", + dev)) { + rt_printk + (", unable to allocate IRQ %d, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ } else { rt_printk(", irq=%u", irq); } @@ -1305,90 +1416,91 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) rt_printk(", IRQ disabled"); } } else { - irq=0; + irq = 0; } - dev->irq = irq; + dev->irq = irq; printk(".\n"); - subdev=0; + subdev = 0; if (this_board->n_aichan) { s = dev->subdevices + subdev; dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_COMMON|SDF_GROUND; - if (this_board->n_aichand) s->subdev_flags |= SDF_DIFF; + s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND; + if (this_board->n_aichand) + s->subdev_flags |= SDF_DIFF; s->n_chan = this_board->n_aichan; s->maxdata = this_board->ai_maxdata; s->len_chanlist = this_board->n_aichan; s->range_table = this_board->rangelist_ai; - s->cancel=pci171x_ai_cancel; - s->insn_read=pci171x_insn_read_ai; + s->cancel = pci171x_ai_cancel; + s->insn_read = pci171x_insn_read_ai; if (irq) { s->subdev_flags |= SDF_CMD_READ; - s->do_cmdtest=pci171x_ai_cmdtest; - s->do_cmd=pci171x_ai_cmd; + s->do_cmdtest = pci171x_ai_cmdtest; + s->do_cmd = pci171x_ai_cmd; } - devpriv->i8254_osc_base=100; // 100ns=10MHz + devpriv->i8254_osc_base = 100; // 100ns=10MHz subdev++; } if (this_board->n_aochan) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_aochan; s->maxdata = this_board->ao_maxdata; s->len_chanlist = this_board->n_aochan; s->range_table = this_board->rangelist_ao; - switch (this_board->cardtype) { + switch (this_board->cardtype) { case TYPE_PCI1720: - s->insn_write=pci1720_insn_write_ao; + s->insn_write = pci1720_insn_write_ao; break; default: - s->insn_write=pci171x_insn_write_ao; + s->insn_write = pci171x_insn_write_ao; break; } - s->insn_read=pci171x_insn_read_ao; + s->insn_read = pci171x_insn_read_ao; subdev++; } if (this_board->n_dichan) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_dichan; s->maxdata = 1; s->len_chanlist = this_board->n_dichan; s->range_table = &range_digital; - s->io_bits=0; /* all bits input */ - s->insn_bits=pci171x_insn_bits_di; + s->io_bits = 0; /* all bits input */ + s->insn_bits = pci171x_insn_bits_di; subdev++; } if (this_board->n_dochan) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_dochan; s->maxdata = 1; s->len_chanlist = this_board->n_dochan; s->range_table = &range_digital; - s->io_bits=(1 << this_board->n_dochan)-1; /* all bits output */ - s->state=0; - s->insn_bits=pci171x_insn_bits_do; + s->io_bits = (1 << this_board->n_dochan) - 1; /* all bits output */ + s->state = 0; + s->insn_bits = pci171x_insn_bits_do; subdev++; } if (this_board->n_counter) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=this_board->n_counter; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = this_board->n_counter; s->len_chanlist = this_board->n_counter; - s->maxdata=0xffff; + s->maxdata = 0xffff; s->range_table = &range_unknown; s->insn_read = pci171x_insn_counter_read; s->insn_write = pci171x_insn_counter_write; @@ -1396,7 +1508,7 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) subdev++; } - devpriv->valid=1; + devpriv->valid = 1; return 0; } @@ -1404,12 +1516,14 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) /* ============================================================================== */ -static int pci1710_detach(comedi_device *dev) +static int pci1710_detach(comedi_device * dev) { if (dev->private) { - if (devpriv->valid) pci1710_reset(dev); - if (dev->irq) comedi_free_irq(dev->irq,dev); + if (devpriv->valid) + pci1710_reset(dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); if (devpriv->pcidev) { if (dev->iobase) { comedi_pci_disable(devpriv->pcidev); @@ -1418,7 +1532,6 @@ static int pci1710_detach(comedi_device *dev) } } - return 0; } @@ -1429,4 +1542,3 @@ COMEDI_INITCLEANUP(driver_pci1710); /* ============================================================================== */ - diff --git a/comedi/drivers/adv_pci_dio.c b/comedi/drivers/adv_pci_dio.c index 858937a3..4a34d22d 100644 --- a/comedi/drivers/adv_pci_dio.c +++ b/comedi/drivers/adv_pci_dio.c @@ -35,7 +35,7 @@ Configuration options: #include "comedi_pci.h" #include "8255.h" -#undef PCI_DIO_EXTDEBUG /* if defined, enable extensive debug logging */ +#undef PCI_DIO_EXTDEBUG /* if defined, enable extensive debug logging */ #undef DPRINTK #ifdef PCI_DIO_EXTDEBUG @@ -67,74 +67,73 @@ typedef enum { #define SIZE_8255 4 /* 8255 IO space length */ -#define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */ +#define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */ /* Register offset definitions */ // Advantech PCI-1730/3/4 -#define PCI1730_IDI 0 /* R: Isolated digital input 0-15 */ -#define PCI1730_IDO 0 /* W: Isolated digital output 0-15 */ -#define PCI1730_DI 2 /* R: Digital input 0-15 */ -#define PCI1730_DO 2 /* W: Digital output 0-15 */ -#define PCI1733_IDI 0 /* R: Isolated digital input 0-31 */ +#define PCI1730_IDI 0 /* R: Isolated digital input 0-15 */ +#define PCI1730_IDO 0 /* W: Isolated digital output 0-15 */ +#define PCI1730_DI 2 /* R: Digital input 0-15 */ +#define PCI1730_DO 2 /* W: Digital output 0-15 */ +#define PCI1733_IDI 0 /* R: Isolated digital input 0-31 */ #define PCI1730_3_INT_EN 0x08 /* R/W: enable/disable interrupts */ #define PCI1730_3_INT_RF 0x0c /* R/W: set falling/raising edge for interrupts */ #define PCI1730_3_INT_CLR 0x10 /* R/W: clear interrupts */ -#define PCI1734_IDO 0 /* W: Isolated digital output 0-31 */ -#define PCI173x_BOARDID 4 /* R: Board I/D switch for 1730/3/4 */ +#define PCI1734_IDO 0 /* W: Isolated digital output 0-31 */ +#define PCI173x_BOARDID 4 /* R: Board I/D switch for 1730/3/4 */ // Advantech PCI-1750 -#define PCI1750_IDI 0 /* R: Isolated digital input 0-15 */ -#define PCI1750_IDO 0 /* W: Isolated digital output 0-15 */ -#define PCI1750_ICR 32 /* W: Interrupt control register */ -#define PCI1750_ISR 32 /* R: Interrupt status register */ +#define PCI1750_IDI 0 /* R: Isolated digital input 0-15 */ +#define PCI1750_IDO 0 /* W: Isolated digital output 0-15 */ +#define PCI1750_ICR 32 /* W: Interrupt control register */ +#define PCI1750_ISR 32 /* R: Interrupt status register */ // Advantech PCI-1751/3/3E -#define PCI1751_DIO 0 /* R/W: begin of 8255 registers block */ -#define PCI1751_ICR 32 /* W: Interrupt control register */ -#define PCI1751_ISR 32 /* R: Interrupt status register */ -#define PCI1753_DIO 0 /* R/W: begin of 8255 registers block */ -#define PCI1753_ICR0 16 /* R/W: Interrupt control register group 0 */ -#define PCI1753_ICR1 17 /* R/W: Interrupt control register group 1 */ -#define PCI1753_ICR2 18 /* R/W: Interrupt control register group 2 */ -#define PCI1753_ICR3 19 /* R/W: Interrupt control register group 3 */ -#define PCI1753E_DIO 32 /* R/W: begin of 8255 registers block */ -#define PCI1753E_ICR0 48 /* R/W: Interrupt control register group 0 */ -#define PCI1753E_ICR1 49 /* R/W: Interrupt control register group 1 */ -#define PCI1753E_ICR2 50 /* R/W: Interrupt control register group 2 */ -#define PCI1753E_ICR3 51 /* R/W: Interrupt control register group 3 */ - +#define PCI1751_DIO 0 /* R/W: begin of 8255 registers block */ +#define PCI1751_ICR 32 /* W: Interrupt control register */ +#define PCI1751_ISR 32 /* R: Interrupt status register */ +#define PCI1753_DIO 0 /* R/W: begin of 8255 registers block */ +#define PCI1753_ICR0 16 /* R/W: Interrupt control register group 0 */ +#define PCI1753_ICR1 17 /* R/W: Interrupt control register group 1 */ +#define PCI1753_ICR2 18 /* R/W: Interrupt control register group 2 */ +#define PCI1753_ICR3 19 /* R/W: Interrupt control register group 3 */ +#define PCI1753E_DIO 32 /* R/W: begin of 8255 registers block */ +#define PCI1753E_ICR0 48 /* R/W: Interrupt control register group 0 */ +#define PCI1753E_ICR1 49 /* R/W: Interrupt control register group 1 */ +#define PCI1753E_ICR2 50 /* R/W: Interrupt control register group 2 */ +#define PCI1753E_ICR3 51 /* R/W: Interrupt control register group 3 */ // Advantech PCI-1752/4/6 -#define PCI1752_IDO 0 /* R/W: Digital output 0-31 */ -#define PCI1752_IDO2 4 /* R/W: Digital output 32-63 */ -#define PCI1754_IDI 0 /* R: Digital input 0-31 */ -#define PCI1754_IDI2 4 /* R: Digital input 32-64 */ -#define PCI1756_IDI 0 /* R: Digital input 0-31 */ -#define PCI1756_IDO 4 /* R/W: Digital output 0-31 */ -#define PCI1754_6_ICR0 0x08 /* R/W: Interrupt control register group 0 */ -#define PCI1754_6_ICR1 0x0a /* R/W: Interrupt control register group 1 */ -#define PCI1754_ICR2 0x0c /* R/W: Interrupt control register group 2 */ -#define PCI1754_ICR3 0x0e /* R/W: Interrupt control register group 3 */ -#define PCI1752_6_CFC 0x12 /* R/W: set/read channel freeze function */ -#define PCI175x_BOARDID 0x10 /* R: Board I/D switch for 1752/4/6 */ +#define PCI1752_IDO 0 /* R/W: Digital output 0-31 */ +#define PCI1752_IDO2 4 /* R/W: Digital output 32-63 */ +#define PCI1754_IDI 0 /* R: Digital input 0-31 */ +#define PCI1754_IDI2 4 /* R: Digital input 32-64 */ +#define PCI1756_IDI 0 /* R: Digital input 0-31 */ +#define PCI1756_IDO 4 /* R/W: Digital output 0-31 */ +#define PCI1754_6_ICR0 0x08 /* R/W: Interrupt control register group 0 */ +#define PCI1754_6_ICR1 0x0a /* R/W: Interrupt control register group 1 */ +#define PCI1754_ICR2 0x0c /* R/W: Interrupt control register group 2 */ +#define PCI1754_ICR3 0x0e /* R/W: Interrupt control register group 3 */ +#define PCI1752_6_CFC 0x12 /* R/W: set/read channel freeze function */ +#define PCI175x_BOARDID 0x10 /* R: Board I/D switch for 1752/4/6 */ // Advantech PCI-1762 registers -#define PCI1762_RO 0 /* R/W: Relays status/output */ -#define PCI1762_IDI 0 /* R: Isolated input status */ -#define PCI1762_BOARDID 4 /* R: Board I/D switch */ -#define PCI1762_ICR 6 /* W: Interrupt control register */ -#define PCI1762_ISR 6 /* R: Interrupt status register */ +#define PCI1762_RO 0 /* R/W: Relays status/output */ +#define PCI1762_IDI 0 /* R: Isolated input status */ +#define PCI1762_BOARDID 4 /* R: Board I/D switch */ +#define PCI1762_ICR 6 /* W: Interrupt control register */ +#define PCI1762_ISR 6 /* R: Interrupt status register */ // Advantech PCI-1760 registers -#define OMB0 0x0c /* W: Mailbox outgoing registers */ +#define OMB0 0x0c /* W: Mailbox outgoing registers */ #define OMB1 0x0d #define OMB2 0x0e #define OMB3 0x0f -#define IMB0 0x1c /* R: Mailbox incoming registers */ +#define IMB0 0x1c /* R: Mailbox incoming registers */ #define IMB1 0x1d #define IMB2 0x1e #define IMB3 0x1f -#define INTCSR0 0x38 /* R/W: Interrupt control registers */ +#define INTCSR0 0x38 /* R/W: Interrupt control registers */ #define INTCSR1 0x39 #define INTCSR2 0x3a #define INTCSR3 0x3b @@ -172,180 +171,169 @@ typedef enum { #define CMD_SetIDI6CntMatchValue 0x4e /* Set IDI6 Counter Match Value 256*OMB1+OMB0 */ #define CMD_SetIDI7CntMatchValue 0x4f /* Set IDI7 Counter Match Value 256*OMB1+OMB0 */ -#define OMBCMD_RETRY 0x03 /* 3 times try request before error */ +#define OMBCMD_RETRY 0x03 /* 3 times try request before error */ -static int pci_dio_attach(comedi_device *dev,comedi_devconfig *it); -static int pci_dio_detach(comedi_device *dev); +static int pci_dio_attach(comedi_device * dev, comedi_devconfig * it); +static int pci_dio_detach(comedi_device * dev); typedef struct { - int chans; // num of chans - int addr; // PCI address ofset - int regs; // number of registers to read or 8255 subdevices - unsigned int specflags; // addon subdevice flags + int chans; // num of chans + int addr; // PCI address ofset + int regs; // number of registers to read or 8255 subdevices + unsigned int specflags; // addon subdevice flags } diosubd_data; typedef struct { - const char *name; // board name - int vendor_id; // vendor/device PCI ID - int device_id; - int main_pci_region;// main I/O OCI region - hw_cards_id cardtype; // {enum hw_cards_id_enum} - diosubd_data sdi[MAX_DI_SUBDEVS]; // DI chans - diosubd_data sdo[MAX_DO_SUBDEVS]; // DO chans - diosubd_data sdio[MAX_DIO_SUBDEVG]; // DIO 8255 chans - diosubd_data boardid; // card supports board ID switch - hw_io_access io_access; // {enum hw_io_access_enum} + const char *name; // board name + int vendor_id; // vendor/device PCI ID + int device_id; + int main_pci_region; // main I/O OCI region + hw_cards_id cardtype; // {enum hw_cards_id_enum} + diosubd_data sdi[MAX_DI_SUBDEVS]; // DI chans + diosubd_data sdo[MAX_DO_SUBDEVS]; // DO chans + diosubd_data sdio[MAX_DIO_SUBDEVG]; // DIO 8255 chans + diosubd_data boardid; // card supports board ID switch + hw_io_access io_access; // {enum hw_io_access_enum} } boardtype; static struct pci_device_id pci_dio_pci_table[] = __devinitdata { - { PCI_VENDOR_ID_ADVANTECH, 0x1730, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1733, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1734, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1750, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1751, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1752, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1753, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1754, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1756, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_ADVANTECH, 0x1762, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_ADVANTECH, 0x1730, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1733, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1734, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1750, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1751, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1752, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1753, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1754, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1756, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_ADVANTECH, 0x1762, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci_dio_pci_table); -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"pci1730", PCI_VENDOR_ID_ADVANTECH, 0x1730, PCIDIO_MAINREG, - TYPE_PCI1730, - {{16, PCI1730_DI, 2, 0}, {16, PCI1730_IDI, 2, 0}}, - {{16, PCI1730_DO, 2, 0}, {16, PCI1730_IDO, 2, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI173x_BOARDID, 1, SDF_INTERNAL}, - IO_8b, - }, + TYPE_PCI1730, + {{16, PCI1730_DI, 2, 0}, {16, PCI1730_IDI, 2, 0}}, + {{16, PCI1730_DO, 2, 0}, {16, PCI1730_IDO, 2, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI173x_BOARDID, 1, SDF_INTERNAL}, + IO_8b, + }, {"pci1733", PCI_VENDOR_ID_ADVANTECH, 0x1733, PCIDIO_MAINREG, - TYPE_PCI1733, - {{ 0, 0, 0, 0}, {32, PCI1733_IDI, 4, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI173x_BOARDID, 1, SDF_INTERNAL}, - IO_8b - }, + TYPE_PCI1733, + {{0, 0, 0, 0}, {32, PCI1733_IDI, 4, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI173x_BOARDID, 1, SDF_INTERNAL}, + IO_8b}, {"pci1734", PCI_VENDOR_ID_ADVANTECH, 0x1734, PCIDIO_MAINREG, - TYPE_PCI1734, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, {32, PCI1734_IDO, 4, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI173x_BOARDID, 1, SDF_INTERNAL}, - IO_8b - }, + TYPE_PCI1734, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {32, PCI1734_IDO, 4, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI173x_BOARDID, 1, SDF_INTERNAL}, + IO_8b}, {"pci1750", PCI_VENDOR_ID_ADVANTECH, 0x1750, PCIDIO_MAINREG, - TYPE_PCI1750, - {{ 0, 0, 0, 0}, {16, PCI1750_IDI, 2, 0}}, - {{ 0, 0, 0, 0}, {16, PCI1750_IDO, 2, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 0, 0, 0, 0}, - IO_8b - }, + TYPE_PCI1750, + {{0, 0, 0, 0}, {16, PCI1750_IDI, 2, 0}}, + {{0, 0, 0, 0}, {16, PCI1750_IDO, 2, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {0, 0, 0, 0}, + IO_8b}, {"pci1751", PCI_VENDOR_ID_ADVANTECH, 0x1751, PCIDIO_MAINREG, - TYPE_PCI1751, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{48, PCI1751_DIO, 2, 0}, { 0, 0, 0, 0}}, - { 0, 0, 0, 0}, - IO_8b - }, + TYPE_PCI1751, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{48, PCI1751_DIO, 2, 0}, {0, 0, 0, 0}}, + {0, 0, 0, 0}, + IO_8b}, {"pci1752", PCI_VENDOR_ID_ADVANTECH, 0x1752, PCIDIO_MAINREG, - TYPE_PCI1752, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{32, PCI1752_IDO, 2, 0}, {32, PCI1752_IDO2, 2, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI175x_BOARDID, 1, SDF_INTERNAL}, - IO_16b - }, + TYPE_PCI1752, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{32, PCI1752_IDO, 2, 0}, {32, PCI1752_IDO2, 2, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI175x_BOARDID, 1, SDF_INTERNAL}, + IO_16b}, {"pci1753", PCI_VENDOR_ID_ADVANTECH, 0x1753, PCIDIO_MAINREG, - TYPE_PCI1753, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{96, PCI1753_DIO, 4, 0}, { 0, 0, 0, 0}}, - { 0, 0, 0, 0}, - IO_8b - }, + TYPE_PCI1753, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{96, PCI1753_DIO, 4, 0}, {0, 0, 0, 0}}, + {0, 0, 0, 0}, + IO_8b}, {"pci1753e", PCI_VENDOR_ID_ADVANTECH, 0x1753, PCIDIO_MAINREG, - TYPE_PCI1753E, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{96, PCI1753_DIO, 4, 0}, {96, PCI1753E_DIO, 4, 0}}, - { 0, 0, 0, 0}, - IO_8b - }, + TYPE_PCI1753E, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{96, PCI1753_DIO, 4, 0}, {96, PCI1753E_DIO, 4, 0}}, + {0, 0, 0, 0}, + IO_8b}, {"pci1754", PCI_VENDOR_ID_ADVANTECH, 0x1754, PCIDIO_MAINREG, - TYPE_PCI1754, - {{32, PCI1754_IDI, 2, 0}, {32, PCI1754_IDI2, 2, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI175x_BOARDID, 1, SDF_INTERNAL}, - IO_16b - }, + TYPE_PCI1754, + {{32, PCI1754_IDI, 2, 0}, {32, PCI1754_IDI2, 2, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI175x_BOARDID, 1, SDF_INTERNAL}, + IO_16b}, {"pci1756", PCI_VENDOR_ID_ADVANTECH, 0x1756, PCIDIO_MAINREG, - TYPE_PCI1756, - {{ 0, 0, 0, 0}, {32, PCI1756_IDI, 2, 0}}, - {{ 0, 0, 0, 0}, {32, PCI1756_IDO, 2, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI175x_BOARDID, 1, SDF_INTERNAL}, - IO_16b - }, + TYPE_PCI1756, + {{0, 0, 0, 0}, {32, PCI1756_IDI, 2, 0}}, + {{0, 0, 0, 0}, {32, PCI1756_IDO, 2, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI175x_BOARDID, 1, SDF_INTERNAL}, + IO_16b}, {"pci1760", PCI_VENDOR_ID_ADVANTECH, 0x1760, 0, - TYPE_PCI1760, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, // This card have own setup work - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 0, 0, 0, 0}, - IO_8b - }, + TYPE_PCI1760, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, // This card have own setup work + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {0, 0, 0, 0}, + IO_8b}, {"pci1762", PCI_VENDOR_ID_ADVANTECH, 0x1762, PCIDIO_MAINREG, - TYPE_PCI1762, - {{ 0, 0, 0, 0}, {16, PCI1762_IDI, 1, 0}}, - {{ 0, 0, 0, 0}, {16, PCI1762_RO, 1, 0}}, - {{ 0, 0, 0, 0}, { 0, 0, 0, 0}}, - { 4, PCI1762_BOARDID, 1, SDF_INTERNAL}, - IO_16b - } + TYPE_PCI1762, + {{0, 0, 0, 0}, {16, PCI1762_IDI, 1, 0}}, + {{0, 0, 0, 0}, {16, PCI1762_RO, 1, 0}}, + {{0, 0, 0, 0}, {0, 0, 0, 0}}, + {4, PCI1762_BOARDID, 1, SDF_INTERNAL}, + IO_16b} }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -static comedi_driver driver_pci_dio={ - driver_name: "adv_pci_dio", - module: THIS_MODULE, - attach: pci_dio_attach, - detach: pci_dio_detach, - num_names: n_boardtypes, - board_name: &boardtypes[0].name, - offset: sizeof(boardtype), +static comedi_driver driver_pci_dio = { + driver_name:"adv_pci_dio", + module:THIS_MODULE, + attach:pci_dio_attach, + detach:pci_dio_detach, + num_names:n_boardtypes, + board_name:&boardtypes[0].name, + offset:sizeof(boardtype), }; typedef struct pci_dio_private_st pci_dio_private; struct pci_dio_private_st { - pci_dio_private *prev; // previous private struct - pci_dio_private *next; // next private struct - struct pci_dev *pcidev; // pointer to board's pci_dev - char valid; // card is usable - char GlobalIrqEnabled;// 1= any IRQ source is enabled + pci_dio_private *prev; // previous private struct + pci_dio_private *next; // next private struct + struct pci_dev *pcidev; // pointer to board's pci_dev + char valid; // card is usable + char GlobalIrqEnabled; // 1= any IRQ source is enabled // PCI-1760 specific data - unsigned char IDICntEnable; // counter's counting enable status - unsigned char IDICntOverEnable;// counter's overflow interrupts enable status - unsigned char IDICntMatchEnable;// counter's match interrupts enable status - unsigned char IDICntEdge; // counter's count edge value (bit=0 - rising, =1 - falling) - unsigned short CntResValue[8]; // counters' reset value - unsigned short CntMatchValue[8];// counters' match interrupt value - unsigned char IDIFiltersEn; // IDI's digital filters enable status - unsigned char IDIPatMatchEn; // IDI's pattern match enable status - unsigned char IDIPatMatchValue;// IDI's pattern match value - unsigned short IDIFiltrLow[8]; // IDI's filter value low signal - unsigned short IDIFiltrHigh[8];// IDI's filter value high signal + unsigned char IDICntEnable; // counter's counting enable status + unsigned char IDICntOverEnable; // counter's overflow interrupts enable status + unsigned char IDICntMatchEnable; // counter's match interrupts enable status + unsigned char IDICntEdge; // counter's count edge value (bit=0 - rising, =1 - falling) + unsigned short CntResValue[8]; // counters' reset value + unsigned short CntMatchValue[8]; // counters' match interrupt value + unsigned char IDIFiltersEn; // IDI's digital filters enable status + unsigned char IDIPatMatchEn; // IDI's pattern match enable status + unsigned char IDIPatMatchValue; // IDI's pattern match value + unsigned short IDIFiltrLow[8]; // IDI's filter value low signal + unsigned short IDIFiltrHigh[8]; // IDI's filter value high signal }; -static pci_dio_private *pci_priv=NULL; /* list of allocated cards */ +static pci_dio_private *pci_priv = NULL; /* list of allocated cards */ #define devpriv ((pci_dio_private *)dev->private) #define this_board ((const boardtype *)dev->board_ptr) @@ -353,15 +341,15 @@ static pci_dio_private *pci_priv=NULL; /* list of allocated cards */ /* ============================================================================== */ -static int pci_dio_insn_bits_di_b(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci_dio_insn_bits_di_b(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - const diosubd_data *d=(const diosubd_data *)s->private; + const diosubd_data *d = (const diosubd_data *)s->private; int i; - data[1]=0; - for (i=0; iregs;i++) { - data[1]|=inb(dev->iobase+d->addr+i)<<(8*i); + data[1] = 0; + for (i = 0; i < d->regs; i++) { + data[1] |= inb(dev->iobase + d->addr + i) << (8 * i); } return 2; @@ -370,15 +358,15 @@ static int pci_dio_insn_bits_di_b(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci_dio_insn_bits_di_w(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci_dio_insn_bits_di_w(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - const diosubd_data *d=(const diosubd_data *)s->private; + const diosubd_data *d = (const diosubd_data *)s->private; int i; - data[1]=0; - for (i=0; iregs; i++) - data[1]|=inw(dev->iobase+d->addr+2*i)<<(16*i); + data[1] = 0; + for (i = 0; i < d->regs; i++) + data[1] |= inw(dev->iobase + d->addr + 2 * i) << (16 * i); return 2; } @@ -386,17 +374,18 @@ static int pci_dio_insn_bits_di_w(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci_dio_insn_bits_do_b(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci_dio_insn_bits_do_b(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - const diosubd_data *d=(const diosubd_data *)s->private; + const diosubd_data *d = (const diosubd_data *)s->private; int i; if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - for (i=0; iregs; i++) - outb((s->state>>(8*i))&0xff, dev->iobase+d->addr+i); + s->state |= (data[0] & data[1]); + for (i = 0; i < d->regs; i++) + outb((s->state >> (8 * i)) & 0xff, + dev->iobase + d->addr + i); } data[1] = s->state; @@ -406,77 +395,78 @@ static int pci_dio_insn_bits_do_b(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci_dio_insn_bits_do_w(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pci_dio_insn_bits_do_w(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - const diosubd_data *d=(const diosubd_data *)s->private; + const diosubd_data *d = (const diosubd_data *)s->private; int i; if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - for (i=0; iregs; i++) - outw((s->state>>(16*i))&0xffff, dev->iobase+d->addr+2*i); + s->state |= (data[0] & data[1]); + for (i = 0; i < d->regs; i++) + outw((s->state >> (16 * i)) & 0xffff, + dev->iobase + d->addr + 2 * i); } data[1] = s->state; return 2; } - /* ============================================================================== */ -static int pci1760_unchecked_mbxrequest(comedi_device *dev, - unsigned char *omb, unsigned char *imb, - int repeats) +static int pci1760_unchecked_mbxrequest(comedi_device * dev, + unsigned char *omb, unsigned char *imb, int repeats) { - int cnt, tout, ok=0; - - for (cnt=0; cntiobase+OMB0); - outb(omb[1], dev->iobase+OMB1); - outb(omb[2], dev->iobase+OMB2); - outb(omb[3], dev->iobase+OMB3); - for(tout=0; tout<251; tout++) { - if ((imb[2]=inb(dev->iobase+IMB2))==omb[2]) { - imb[0]=inb(dev->iobase+IMB0); - imb[1]=inb(dev->iobase+IMB1); - imb[3]=inb(dev->iobase+IMB3); - ok=1; + int cnt, tout, ok = 0; + + for (cnt = 0; cnt < repeats; cnt++) { + outb(omb[0], dev->iobase + OMB0); + outb(omb[1], dev->iobase + OMB1); + outb(omb[2], dev->iobase + OMB2); + outb(omb[3], dev->iobase + OMB3); + for (tout = 0; tout < 251; tout++) { + if ((imb[2] = inb(dev->iobase + IMB2)) == omb[2]) { + imb[0] = inb(dev->iobase + IMB0); + imb[1] = inb(dev->iobase + IMB1); + imb[3] = inb(dev->iobase + IMB3); + ok = 1; break; } comedi_udelay(1); } - if (ok) return 0; + if (ok) + return 0; } comedi_error(dev, "PCI-1760 mailbox request timeout!"); return -ETIME; } -static int pci1760_clear_imb2(comedi_device *dev) +static int pci1760_clear_imb2(comedi_device * dev) { - unsigned char omb[4] = {0x0, 0x0, CMD_ClearIMB2, 0x0}; + unsigned char omb[4] = { 0x0, 0x0, CMD_ClearIMB2, 0x0 }; unsigned char imb[4]; /* check if imb2 is already clear */ - if(inb(dev->iobase + IMB2) == CMD_ClearIMB2) return 0; + if (inb(dev->iobase + IMB2) == CMD_ClearIMB2) + return 0; return pci1760_unchecked_mbxrequest(dev, omb, imb, OMBCMD_RETRY); } -static int pci1760_mbxrequest(comedi_device *dev, +static int pci1760_mbxrequest(comedi_device * dev, unsigned char *omb, unsigned char *imb) { - if(omb[2] == CMD_ClearIMB2) - { - comedi_error(dev, "bug! this function should not be used for CMD_ClearIMB2 command"); + if (omb[2] == CMD_ClearIMB2) { + comedi_error(dev, + "bug! this function should not be used for CMD_ClearIMB2 command"); return -EINVAL; } - if(inb(dev->iobase + IMB2) == omb[2]) - { + if (inb(dev->iobase + IMB2) == omb[2]) { int retval; retval = pci1760_clear_imb2(dev); - if(retval < 0) return retval; + if (retval < 0) + return retval; } return pci1760_unchecked_mbxrequest(dev, omb, imb, OMBCMD_RETRY); } @@ -484,10 +474,10 @@ static int pci1760_mbxrequest(comedi_device *dev, /* ============================================================================== */ -static int pci1760_insn_bits_di(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci1760_insn_bits_di(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[1]=inb(dev->iobase + IMB3); + data[1] = inb(dev->iobase + IMB3); return 2; } @@ -495,22 +485,23 @@ static int pci1760_insn_bits_di(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci1760_insn_bits_do(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci1760_insn_bits_do(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int ret; - unsigned char omb[4]={ + unsigned char omb[4] = { 0x00, 0x00, CMD_SetRelaysOutput, - 0x00}; + 0x00 + }; unsigned char imb[4]; if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); omb[0] = s->state; - if (!(ret=pci1760_mbxrequest(dev, omb, imb))) + if (!(ret = pci1760_mbxrequest(dev, omb, imb))) return ret; } data[1] = s->state; @@ -521,21 +512,22 @@ static int pci1760_insn_bits_do(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci1760_insn_cnt_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci1760_insn_cnt_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int ret, n; - unsigned char omb[4]={ - CR_CHAN(insn->chanspec)&0x07, + unsigned char omb[4] = { + CR_CHAN(insn->chanspec) & 0x07, 0x00, CMD_GetIDICntCurValue, - 0x00}; + 0x00 + }; unsigned char imb[4]; - for (n=0; nn; n++) { - if (!(ret=pci1760_mbxrequest(dev, omb, imb))) + for (n = 0; n < insn->n; n++) { + if (!(ret = pci1760_mbxrequest(dev, omb, imb))) return ret; - data[n] = (imb[1]<<8) + imb[0]; + data[n] = (imb[1] << 8) + imb[0]; } return n; @@ -544,34 +536,35 @@ static int pci1760_insn_cnt_read(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci1760_insn_cnt_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci1760_insn_cnt_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int ret; - unsigned char chan=CR_CHAN(insn->chanspec)&0x07; - unsigned char bitmask=1<>8)&0xff, - CMD_SetIDI0CntResetValue+chan, - 0x00}; + unsigned char chan = CR_CHAN(insn->chanspec) & 0x07; + unsigned char bitmask = 1 << chan; + unsigned char omb[4] = { + data[0] & 0xff, + (data[0] >> 8) & 0xff, + CMD_SetIDI0CntResetValue + chan, + 0x00 + }; unsigned char imb[4]; - if (devpriv->CntResValue[chan] != (data[0]&0xffff)) { // Set reset value if different - if (!(ret=pci1760_mbxrequest(dev, omb, imb))) + if (devpriv->CntResValue[chan] != (data[0] & 0xffff)) { // Set reset value if different + if (!(ret = pci1760_mbxrequest(dev, omb, imb))) return ret; - devpriv->CntResValue[chan] = data[0]&0xffff; + devpriv->CntResValue[chan] = data[0] & 0xffff; } omb[0] = bitmask; // reset counter to it reset value omb[2] = CMD_ResetIDICounters; - if (!(ret=pci1760_mbxrequest(dev, omb, imb))) + if (!(ret = pci1760_mbxrequest(dev, omb, imb))) return ret; if (!(bitmask & devpriv->IDICntEnable)) { // start counter if it don't run omb[0] = bitmask; omb[2] = CMD_EnableIDICounters; - if (!(ret=pci1760_mbxrequest(dev, omb, imb))) + if (!(ret = pci1760_mbxrequest(dev, omb, imb))) return ret; devpriv->IDICntEnable |= bitmask; } @@ -581,16 +574,16 @@ static int pci1760_insn_cnt_write(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci1760_reset(comedi_device *dev) +static int pci1760_reset(comedi_device * dev) { int i; - unsigned char omb[4]={0x00, 0x00, 0x00, 0x00 }; + unsigned char omb[4] = { 0x00, 0x00, 0x00, 0x00 }; unsigned char imb[4]; - outb(0, dev->iobase+INTCSR0); // disable IRQ - outb(0, dev->iobase+INTCSR1); - outb(0, dev->iobase+INTCSR2); - outb(0, dev->iobase+INTCSR3); + outb(0, dev->iobase + INTCSR0); // disable IRQ + outb(0, dev->iobase + INTCSR1); + outb(0, dev->iobase + INTCSR2); + outb(0, dev->iobase + INTCSR3); devpriv->GlobalIrqEnabled = 0; omb[0] = 0x00; @@ -614,16 +607,16 @@ static int pci1760_reset(comedi_device *dev) omb[0] = 0x00; omb[1] = 0x80; - for (i=0; i<8; i++) { // set IDI up counters match value - omb[2] = CMD_SetIDI0CntMatchValue+i; + for (i = 0; i < 8; i++) { // set IDI up counters match value + omb[2] = CMD_SetIDI0CntMatchValue + i; pci1760_mbxrequest(dev, omb, imb); devpriv->CntMatchValue[i] = 0x8000; } omb[0] = 0x00; omb[1] = 0x00; - for (i=0; i<8; i++) { // set IDI up counters reset value - omb[2] = CMD_SetIDI0CntResetValue+i; + for (i = 0; i < 8; i++) { // set IDI up counters reset value + omb[2] = CMD_SetIDI0CntResetValue + i; pci1760_mbxrequest(dev, omb, imb); devpriv->CntResValue[i] = 0x0000; } @@ -658,69 +651,69 @@ static int pci1760_reset(comedi_device *dev) /* ============================================================================== */ -static int pci_dio_reset(comedi_device *dev) +static int pci_dio_reset(comedi_device * dev) { DPRINTK("adv_pci_dio EDBG: BGN: pci171x_reset(...)\n"); switch (this_board->cardtype) { case TYPE_PCI1730: - outb(0, dev->iobase+PCI1730_DO); // clear outputs - outb(0, dev->iobase+PCI1730_DO+1); - outb(0, dev->iobase+PCI1730_IDO); - outb(0, dev->iobase+PCI1730_IDO+1); + outb(0, dev->iobase + PCI1730_DO); // clear outputs + outb(0, dev->iobase + PCI1730_DO + 1); + outb(0, dev->iobase + PCI1730_IDO); + outb(0, dev->iobase + PCI1730_IDO + 1); /* NO break there! */ case TYPE_PCI1733: - outb(0, dev->iobase+PCI1730_3_INT_EN); // disable interrupts - outb(0x0f, dev->iobase+PCI1730_3_INT_CLR);// clear interrupts - outb(0, dev->iobase+PCI1730_3_INT_RF); // set rising edge trigger + outb(0, dev->iobase + PCI1730_3_INT_EN); // disable interrupts + outb(0x0f, dev->iobase + PCI1730_3_INT_CLR); // clear interrupts + outb(0, dev->iobase + PCI1730_3_INT_RF); // set rising edge trigger break; case TYPE_PCI1734: - outb(0, dev->iobase+PCI1734_IDO); // clear outputs - outb(0, dev->iobase+PCI1734_IDO+1); - outb(0, dev->iobase+PCI1734_IDO+2); - outb(0, dev->iobase+PCI1734_IDO+3); + outb(0, dev->iobase + PCI1734_IDO); // clear outputs + outb(0, dev->iobase + PCI1734_IDO + 1); + outb(0, dev->iobase + PCI1734_IDO + 2); + outb(0, dev->iobase + PCI1734_IDO + 3); break; case TYPE_PCI1750: case TYPE_PCI1751: - outb(0x88, dev->iobase+PCI1750_ICR); // disable & clear interrupts + outb(0x88, dev->iobase + PCI1750_ICR); // disable & clear interrupts break; case TYPE_PCI1752: - outw(0, dev->iobase+PCI1752_6_CFC); // disable channel freeze function - outw(0, dev->iobase+PCI1752_IDO); // clear outputs - outw(0, dev->iobase+PCI1752_IDO+2); - outw(0, dev->iobase+PCI1752_IDO2); - outw(0, dev->iobase+PCI1752_IDO2+2); + outw(0, dev->iobase + PCI1752_6_CFC); // disable channel freeze function + outw(0, dev->iobase + PCI1752_IDO); // clear outputs + outw(0, dev->iobase + PCI1752_IDO + 2); + outw(0, dev->iobase + PCI1752_IDO2); + outw(0, dev->iobase + PCI1752_IDO2 + 2); break; case TYPE_PCI1753E: - outb(0x88, dev->iobase+PCI1753E_ICR0); // disable & clear interrupts - outb(0x80, dev->iobase+PCI1753E_ICR1); - outb(0x80, dev->iobase+PCI1753E_ICR2); - outb(0x80, dev->iobase+PCI1753E_ICR3); + outb(0x88, dev->iobase + PCI1753E_ICR0); // disable & clear interrupts + outb(0x80, dev->iobase + PCI1753E_ICR1); + outb(0x80, dev->iobase + PCI1753E_ICR2); + outb(0x80, dev->iobase + PCI1753E_ICR3); /* NO break there! */ case TYPE_PCI1753: - outb(0x88, dev->iobase+PCI1753_ICR0); // disable & clear interrupts - outb(0x80, dev->iobase+PCI1753_ICR1); - outb(0x80, dev->iobase+PCI1753_ICR2); - outb(0x80, dev->iobase+PCI1753_ICR3); + outb(0x88, dev->iobase + PCI1753_ICR0); // disable & clear interrupts + outb(0x80, dev->iobase + PCI1753_ICR1); + outb(0x80, dev->iobase + PCI1753_ICR2); + outb(0x80, dev->iobase + PCI1753_ICR3); break; case TYPE_PCI1754: - outw(0x08, dev->iobase+PCI1754_6_ICR0); // disable and clear interrupts - outw(0x08, dev->iobase+PCI1754_6_ICR1); - outw(0x08, dev->iobase+PCI1754_ICR2); - outw(0x08, dev->iobase+PCI1754_ICR3); + outw(0x08, dev->iobase + PCI1754_6_ICR0); // disable and clear interrupts + outw(0x08, dev->iobase + PCI1754_6_ICR1); + outw(0x08, dev->iobase + PCI1754_ICR2); + outw(0x08, dev->iobase + PCI1754_ICR3); break; case TYPE_PCI1756: - outw(0, dev->iobase+PCI1752_6_CFC); // disable channel freeze function - outw(0x08, dev->iobase+PCI1754_6_ICR0); // disable and clear interrupts - outw(0x08, dev->iobase+PCI1754_6_ICR1); - outw(0, dev->iobase+PCI1756_IDO); // clear outputs - outw(0, dev->iobase+PCI1756_IDO+2); + outw(0, dev->iobase + PCI1752_6_CFC); // disable channel freeze function + outw(0x08, dev->iobase + PCI1754_6_ICR0); // disable and clear interrupts + outw(0x08, dev->iobase + PCI1754_6_ICR1); + outw(0, dev->iobase + PCI1756_IDO); // clear outputs + outw(0, dev->iobase + PCI1756_IDO + 2); break; case TYPE_PCI1760: pci1760_reset(dev); break; case TYPE_PCI1762: - outw(0x0101, dev->iobase+PCI1762_ICR); // disable & clear interrupts + outw(0x0101, dev->iobase + PCI1762_ICR); // disable & clear interrupts break; } @@ -732,50 +725,50 @@ static int pci_dio_reset(comedi_device *dev) /* ============================================================================== */ -static int pci1760_attach(comedi_device *dev, comedi_devconfig *it) +static int pci1760_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int subdev=0; + int subdev = 0; s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 8; s->maxdata = 1; s->len_chanlist = 8; s->range_table = &range_digital; - s->insn_bits=pci1760_insn_bits_di; + s->insn_bits = pci1760_insn_bits_di; subdev++; s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = 8; s->maxdata = 1; s->len_chanlist = 8; s->range_table = &range_digital; - s->state=0; - s->insn_bits=pci1760_insn_bits_do; + s->state = 0; + s->insn_bits = pci1760_insn_bits_do; subdev++; s = dev->subdevices + subdev; s->type = COMEDI_SUBD_TIMER; - s->subdev_flags = SDF_WRITABLE|SDF_LSAMPL; + s->subdev_flags = SDF_WRITABLE | SDF_LSAMPL; s->n_chan = 2; s->maxdata = 0xffffffff; s->len_chanlist = 2; -// s->insn_config=pci1760_insn_pwm_cfg; +// s->insn_config=pci1760_insn_pwm_cfg; subdev++; s = dev->subdevices + subdev; s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->n_chan = 8; s->maxdata = 0xffff; s->len_chanlist = 8; - s->insn_read=pci1760_insn_cnt_read; - s->insn_write=pci1760_insn_cnt_write; -// s->insn_config=pci1760_insn_cnt_cfg; + s->insn_read = pci1760_insn_cnt_read; + s->insn_write = pci1760_insn_cnt_write; +// s->insn_config=pci1760_insn_cnt_cfg; subdev++; return 0; @@ -784,25 +777,26 @@ static int pci1760_attach(comedi_device *dev, comedi_devconfig *it) /* ============================================================================== */ -static int pci_dio_add_di(comedi_device *dev, comedi_subdevice *s, - const diosubd_data *d, int subdev) +static int pci_dio_add_di(comedi_device * dev, comedi_subdevice * s, + const diosubd_data * d, int subdev) { s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_COMMON|d->specflags; - if (d->chans>16) s->subdev_flags |= SDF_LSAMPL; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | d->specflags; + if (d->chans > 16) + s->subdev_flags |= SDF_LSAMPL; s->n_chan = d->chans; s->maxdata = 1; s->len_chanlist = d->chans; s->range_table = &range_digital; switch (this_board->io_access) { case IO_8b: - s->insn_bits=pci_dio_insn_bits_di_b; + s->insn_bits = pci_dio_insn_bits_di_b; break; case IO_16b: - s->insn_bits=pci_dio_insn_bits_di_w; + s->insn_bits = pci_dio_insn_bits_di_w; break; } - s->private=(void *)d; + s->private = (void *)d; return 0; } @@ -810,26 +804,27 @@ static int pci_dio_add_di(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int pci_dio_add_do(comedi_device *dev, comedi_subdevice *s, - const diosubd_data *d, int subdev) +static int pci_dio_add_do(comedi_device * dev, comedi_subdevice * s, + const diosubd_data * d, int subdev) { s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; - if (d->chans>16) s->subdev_flags |= SDF_LSAMPL; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; + if (d->chans > 16) + s->subdev_flags |= SDF_LSAMPL; s->n_chan = d->chans; s->maxdata = 1; s->len_chanlist = d->chans; s->range_table = &range_digital; - s->state=0; + s->state = 0; switch (this_board->io_access) { case IO_8b: - s->insn_bits=pci_dio_insn_bits_do_b; + s->insn_bits = pci_dio_insn_bits_do_b; break; case IO_16b: - s->insn_bits=pci_dio_insn_bits_do_w; + s->insn_bits = pci_dio_insn_bits_do_w; break; } - s->private=(void *)d; + s->private = (void *)d; return 0; } @@ -837,17 +832,19 @@ static int pci_dio_add_do(comedi_device *dev, comedi_subdevice *s, /* ============================================================================== */ -static int CheckAndAllocCard(comedi_device *dev, comedi_devconfig *it, - struct pci_dev* pcidev) +static int CheckAndAllocCard(comedi_device * dev, comedi_devconfig * it, + struct pci_dev *pcidev) { - pci_dio_private *pr, *prev; - - for (pr=pci_priv, prev=NULL; pr!=NULL; prev=pr, pr=pr->next) { - if (pr->pcidev==pcidev) { - if (it->options[0]||it->options[1]) { - if ((pr->pcidev->bus->number==it->options[0])&& - (PCI_SLOT(pr->pcidev->devfn)==it->options[1])) { - rt_printk(", Error: Card on requested position is used!\n"); + pci_dio_private *pr, *prev; + + for (pr = pci_priv, prev = NULL; pr != NULL; prev = pr, pr = pr->next) { + if (pr->pcidev == pcidev) { + if (it->options[0] || it->options[1]) { + if ((pr->pcidev->bus->number == it->options[0]) + && (PCI_SLOT(pr->pcidev->devfn) == + it->options[1])) { + rt_printk + (", Error: Card on requested position is used!\n"); return 2; } } @@ -856,7 +853,7 @@ static int CheckAndAllocCard(comedi_device *dev, comedi_devconfig *it, } if (prev) { - devpriv->prev=prev; + devpriv->prev = prev; prev->next = devpriv; } else { pci_priv = devpriv; @@ -870,97 +867,107 @@ static int CheckAndAllocCard(comedi_device *dev, comedi_devconfig *it, /* ============================================================================== */ -static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) +static int pci_dio_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int ret, subdev, n_subdevices, i, j, found=0; + int ret, subdev, n_subdevices, i, j, found = 0; unsigned long iobase; - struct pci_dev* pcidev; + struct pci_dev *pcidev; rt_printk("comedi%d: adv_pci_dio: board=%s", dev->minor, this_board->name); - if ((ret=alloc_private(dev,sizeof(pci_dio_private)))<0) { + if ((ret = alloc_private(dev, sizeof(pci_dio_private))) < 0) { rt_printk(", Error: Cann't allocate private memory!\n"); return -ENOMEM; } - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if ((pcidev->vendor!=this_board->vendor_id)|| - (pcidev->device!=this_board->device_id)) + if ((pcidev->vendor != this_board->vendor_id) + || (pcidev->device != this_board->device_id)) continue; - if (it->options[0]||it->options[1]) { - if ((pcidev->bus->number!=it->options[0])|| - (PCI_SLOT(pcidev->devfn)!=it->options[1])) { + if (it->options[0] || it->options[1]) { + if ((pcidev->bus->number != it->options[0]) || + (PCI_SLOT(pcidev->devfn) != it->options[1])) { continue; } } - ret=CheckAndAllocCard(dev, it, pcidev); - if (ret==1) { found=1; break; } - if (ret>1) { + ret = CheckAndAllocCard(dev, it, pcidev); + if (ret == 1) { + found = 1; + break; + } + if (ret > 1) { return -EIO; } } if (!found) { - rt_printk(", Error: Requested type of the card was not found!\n"); + rt_printk + (", Error: Requested type of the card was not found!\n"); return -EIO; } if (comedi_pci_enable(pcidev, driver_pci_dio.driver_name)) { - rt_printk(", Error: Can't enable PCI device and request regions!\n"); + rt_printk + (", Error: Can't enable PCI device and request regions!\n"); return -EIO; } - iobase=pci_resource_start(pcidev, this_board->main_pci_region); + iobase = pci_resource_start(pcidev, this_board->main_pci_region); rt_printk(", b:s:f=%d:%d:%d, io=0x%4lx", - pcidev->bus->number, PCI_SLOT(pcidev->devfn), PCI_FUNC(pcidev->devfn), - iobase); + pcidev->bus->number, PCI_SLOT(pcidev->devfn), + PCI_FUNC(pcidev->devfn), iobase); - dev->iobase=iobase; - dev->board_name=this_board->name; + dev->iobase = iobase; + dev->board_name = this_board->name; - if (this_board->cardtype==TYPE_PCI1760) { - n_subdevices=4; // 8 IDI, 8 IDO, 2 PWM, 8 CNT + if (this_board->cardtype == TYPE_PCI1760) { + n_subdevices = 4; // 8 IDI, 8 IDO, 2 PWM, 8 CNT } else { - n_subdevices=0; - for (i=0; isdi[i].chans) n_subdevices++; - for (i=0; isdo[i].chans) n_subdevices++; - for (i=0; isdio[i].regs; - if (this_board->boardid.chans) n_subdevices++; + n_subdevices = 0; + for (i = 0; i < MAX_DI_SUBDEVS; i++) + if (this_board->sdi[i].chans) + n_subdevices++; + for (i = 0; i < MAX_DO_SUBDEVS; i++) + if (this_board->sdo[i].chans) + n_subdevices++; + for (i = 0; i < MAX_DIO_SUBDEVG; i++) + n_subdevices += this_board->sdio[i].regs; + if (this_board->boardid.chans) + n_subdevices++; } - if((ret=alloc_subdevices(dev, n_subdevices))<0) { + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) { rt_printk(", Error: Cann't allocate subdevice memory!\n"); - return ret; + return ret; } rt_printk(".\n"); - subdev=0; + subdev = 0; - for (i=0; isdi[i].chans) { s = dev->subdevices + subdev; pci_dio_add_di(dev, s, &this_board->sdi[i], subdev); subdev++; } - for (i=0; isdo[i].chans) { s = dev->subdevices + subdev; pci_dio_add_do(dev, s, &this_board->sdo[i], subdev); subdev++; } - for (i=0; isdio[i].regs; j++) { + for (i = 0; i < MAX_DIO_SUBDEVG; i++) + for (j = 0; j < this_board->sdio[i].regs; j++) { s = dev->subdevices + subdev; subdev_8255_init(dev, s, NULL, - dev->iobase+this_board->sdio[i].addr+SIZE_8255*j); + dev->iobase + this_board->sdio[i].addr + + SIZE_8255 * j); subdev++; } @@ -971,10 +978,10 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) subdev++; } - if (this_board->cardtype==TYPE_PCI1760) + if (this_board->cardtype == TYPE_PCI1760) pci1760_attach(dev, it); - devpriv->valid=1; + devpriv->valid = 1; pci_dio_reset(dev); @@ -984,7 +991,7 @@ static int pci_dio_attach(comedi_device *dev, comedi_devconfig *it) /* ============================================================================== */ -static int pci_dio_detach(comedi_device *dev) +static int pci_dio_detach(comedi_device * dev) { int i, j; comedi_subdevice *s; @@ -998,27 +1005,27 @@ static int pci_dio_detach(comedi_device *dev) /* This shows the silliness of using this kind of * scheme for numbering subdevices. Don't do it. --ds */ subdev = 0; - for (i=0; isdi[i].chans) { subdev++; } } - for (i=0; isdo[i].chans) { subdev++; } } - for (i=0; isdio[i].regs; j++) { + for (i = 0; i < MAX_DIO_SUBDEVG; i++) { + for (j = 0; j < this_board->sdio[i].regs; j++) { s = dev->subdevices + subdev; subdev_8255_cleanup(dev, s); subdev++; } } - for (i=0; in_subdevices; i++) { - s=dev->subdevices+i; - s->private=NULL; + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; + s->private = NULL; } if (devpriv->pcidev) { @@ -1029,12 +1036,12 @@ static int pci_dio_detach(comedi_device *dev) } if (devpriv->prev) { - devpriv->prev->next=devpriv->next; + devpriv->prev->next = devpriv->next; } else { - pci_priv=devpriv->next; + pci_priv = devpriv->next; } if (devpriv->next) { - devpriv->next->prev=devpriv->prev; + devpriv->next->prev = devpriv->prev; } } diff --git a/comedi/drivers/aio_aio12_8.c b/comedi/drivers/aio_aio12_8.c index 556003ea..2f430b90 100644 --- a/comedi/drivers/aio_aio12_8.c +++ b/comedi/drivers/aio_aio12_8.c @@ -38,12 +38,10 @@ Notes: */ - #include #include #include "8255.h" - #define AIO12_8_STATUS 0x00 #define AIO12_8_INTERRUPT 0x01 #define AIO12_8_ADC 0x02 @@ -73,67 +71,59 @@ Notes: #define DAC_ENABLE 0x18 -typedef struct -{ +typedef struct { const char *name; } board_type; -static const board_type board_types[] = -{ +static const board_type board_types[] = { { - name: "aio_aio12_8" - }, + name: "aio_aio12_8"}, }; #define thisboard ((const board_type *) dev->board_ptr) -typedef struct -{ +typedef struct { lsampl_t ao_readback[4]; } aio12_8_private; #define devpriv ((aio12_8_private *) dev->private) -static int aio_aio12_8_ai_read (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int aio_aio12_8_ai_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; unsigned char control = ADC_MODE_NORMAL | - (CR_RANGE(insn->chanspec) << 3) | - CR_CHAN(insn->chanspec); + (CR_RANGE(insn->chanspec) << 3) | CR_CHAN(insn->chanspec); //read status to clear EOC latch - inb (dev->iobase + AIO12_8_STATUS); + inb(dev->iobase + AIO12_8_STATUS); - for (n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { int timeout = 5; // Setup and start conversion - outb (control, dev->iobase + AIO12_8_ADC); + outb(control, dev->iobase + AIO12_8_ADC); // Wait for conversion to complete while (timeout && - ! (inb (dev->iobase + AIO12_8_STATUS) & STATUS_ADC_EOC)) - { + !(inb(dev->iobase + AIO12_8_STATUS) & STATUS_ADC_EOC)) { timeout--; - printk ("timeout %d\n", timeout); - comedi_udelay (1); + printk("timeout %d\n", timeout); + comedi_udelay(1); } - if (timeout == 0) - { - comedi_error (dev, "ADC timeout"); + if (timeout == 0) { + comedi_error(dev, "ADC timeout"); return -EIO; } - data[n] = inw (dev->iobase + AIO12_8_ADC) & 0x0FFF; + data[n] = inw(dev->iobase + AIO12_8_ADC) & 0x0FFF; } return n; } -static int aio_aio12_8_ao_read (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int aio_aio12_8_ao_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int val = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; @@ -143,8 +133,8 @@ static int aio_aio12_8_ao_read (comedi_device *dev, comedi_subdevice *s, return insn->n; } -static int aio_aio12_8_ao_write (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int aio_aio12_8_ao_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); @@ -153,35 +143,32 @@ static int aio_aio12_8_ao_write (comedi_device *dev, comedi_subdevice *s, //enable DACs outb(0x01, dev->iobase + DAC_ENABLE); - for (i = 0; i < insn->n; i++) - { - outb (data[i] & 0xFF, port); // LSB - outb ((data[i] >> 8) & 0x0F, port + 1); // MSB + for (i = 0; i < insn->n; i++) { + outb(data[i] & 0xFF, port); // LSB + outb((data[i] >> 8) & 0x0F, port + 1); // MSB devpriv->ao_readback[chan] = data[i]; } return insn->n; } -static const comedi_lrange range_aio_aio12_8 = -{ +static const comedi_lrange range_aio_aio12_8 = { 4, { - UNI_RANGE(5), - BIP_RANGE(5), - UNI_RANGE(10), - BIP_RANGE(10), - } + UNI_RANGE(5), + BIP_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(10), + } }; -static int aio_aio12_8_attach (comedi_device *dev, comedi_devconfig *it) +static int aio_aio12_8_attach(comedi_device * dev, comedi_devconfig * it) { int iobase; comedi_subdevice *s; iobase = it->options[0]; - if (! request_region (iobase, 24, "aio_aio12_8")) - { - printk ("I/O port conflict"); + if (!request_region(iobase, 24, "aio_aio12_8")) { + printk("I/O port conflict"); return -EIO; } @@ -189,10 +176,10 @@ static int aio_aio12_8_attach (comedi_device *dev, comedi_devconfig *it) dev->iobase = iobase; - if (alloc_private (dev, sizeof (aio12_8_private)) < 0) + if (alloc_private(dev, sizeof(aio12_8_private)) < 0) return -ENOMEM; - if (alloc_subdevices (dev, 3) < 0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; s = &dev->subdevices[0]; @@ -213,28 +200,27 @@ static int aio_aio12_8_attach (comedi_device *dev, comedi_devconfig *it) s->insn_write = aio_aio12_8_ao_write; s = &dev->subdevices[2]; - subdev_8255_init (dev, s, NULL, dev->iobase + AIO12_8_DIO_0); + subdev_8255_init(dev, s, NULL, dev->iobase + AIO12_8_DIO_0); return 0; } -static int aio_aio12_8_detach (comedi_device *dev) +static int aio_aio12_8_detach(comedi_device * dev) { - subdev_8255_cleanup (dev, &dev->subdevices[2]); + subdev_8255_cleanup(dev, &dev->subdevices[2]); if (dev->iobase) - release_region (dev->iobase, 24); + release_region(dev->iobase, 24); return 0; } -static comedi_driver driver_aio_aio12_8 = -{ - driver_name: "aio_aio12_8", - module: THIS_MODULE, - attach: aio_aio12_8_attach, - detach: aio_aio12_8_detach, - board_name: &board_types[0].name, - num_names: 1, - offset: sizeof (board_type), +static comedi_driver driver_aio_aio12_8 = { + driver_name:"aio_aio12_8", + module:THIS_MODULE, + attach:aio_aio12_8_attach, + detach:aio_aio12_8_detach, + board_name:&board_types[0].name, + num_names:1, + offset:sizeof(board_type), }; COMEDI_INITCLEANUP(driver_aio_aio12_8); diff --git a/comedi/drivers/aio_iiro_16.c b/comedi/drivers/aio_iiro_16.c index ef19dc4e..bdbf9e50 100644 --- a/comedi/drivers/aio_iiro_16.c +++ b/comedi/drivers/aio_iiro_16.c @@ -44,82 +44,71 @@ Configuration Options: #define AIO_IIRO_16_RELAY_8_15 0x04 #define AIO_IIRO_16_INPUT_8_15 0x05 - -typedef struct aio_iiro_16_board_struct -{ +typedef struct aio_iiro_16_board_struct { const char *name; int do_; int di; } aio_iiro_16_board; -static const aio_iiro_16_board aio_iiro_16_boards[] = -{ +static const aio_iiro_16_board aio_iiro_16_boards[] = { { - name: "aio_iiro_16", - di: 16, - do_: 16 - }, + name: "aio_iiro_16", + di: 16, + do_: 16}, }; #define thisboard ((const aio_iiro_16_board *) dev->board_ptr) -typedef struct -{ +typedef struct { int data; struct pci_dev *pci_dev; lsampl_t ao_readback[2]; } aio_iiro_16_private; - #define devpriv ((aio_iiro_16_private *) dev->private) -static int aio_iiro_16_attach (comedi_device *dev, comedi_devconfig *it); +static int aio_iiro_16_attach(comedi_device * dev, comedi_devconfig * it); -static int aio_iiro_16_detach (comedi_device *dev); +static int aio_iiro_16_detach(comedi_device * dev); -static comedi_driver driver_aio_iiro_16 = -{ - driver_name: "aio_iiro_16", - module: THIS_MODULE, - attach: aio_iiro_16_attach, - detach: aio_iiro_16_detach, - board_name: &aio_iiro_16_boards[0].name, - offset: sizeof (aio_iiro_16_board), - num_names: sizeof (aio_iiro_16_boards) / - sizeof (aio_iiro_16_board), +static comedi_driver driver_aio_iiro_16 = { + driver_name:"aio_iiro_16", + module:THIS_MODULE, + attach:aio_iiro_16_attach, + detach:aio_iiro_16_detach, + board_name:&aio_iiro_16_boards[0].name, + offset:sizeof(aio_iiro_16_board), + num_names:sizeof(aio_iiro_16_boards) / sizeof(aio_iiro_16_board), }; -static int aio_iiro_16_dio_insn_bits_read (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static int aio_iiro_16_dio_insn_bits_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int aio_iiro_16_dio_insn_bits_write (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static int aio_iiro_16_dio_insn_bits_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int aio_iiro_16_attach (comedi_device *dev, comedi_devconfig *it) +static int aio_iiro_16_attach(comedi_device * dev, comedi_devconfig * it) { int iobase; comedi_subdevice *s; - printk ("comedi%d: aio_iiro_16: ", dev->minor); + printk("comedi%d: aio_iiro_16: ", dev->minor); dev->board_name = thisboard->name; iobase = it->options[0]; - if (! request_region (iobase, AIO_IIRO_16_SIZE, dev->board_name)) - { - printk ("I/O port conflict"); + if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) { + printk("I/O port conflict"); return -EIO; } dev->iobase = iobase; - if (alloc_private (dev, sizeof (aio_iiro_16_private)) < 0) + if (alloc_private(dev, sizeof(aio_iiro_16_private)) < 0) return -ENOMEM; - if (alloc_subdevices (dev, 2) < 0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; s = dev->subdevices + 0; @@ -138,34 +127,33 @@ static int aio_iiro_16_attach (comedi_device *dev, comedi_devconfig *it) s->range_table = &range_digital; s->insn_bits = aio_iiro_16_dio_insn_bits_read; - printk ("attached\n"); + printk("attached\n"); return 1; } -static int aio_iiro_16_detach (comedi_device *dev) +static int aio_iiro_16_detach(comedi_device * dev) { - printk ("comedi%d: aio_iiro_16: remove\n", dev->minor); + printk("comedi%d: aio_iiro_16: remove\n", dev->minor); - if (dev->iobase) release_region (dev->iobase, AIO_IIRO_16_SIZE); + if (dev->iobase) + release_region(dev->iobase, AIO_IIRO_16_SIZE); return 0; } -static int aio_iiro_16_dio_insn_bits_write (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int aio_iiro_16_dio_insn_bits_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { if (insn->n != 2) return -EINVAL; - if (data[0]) - { + if (data[0]) { s->state &= ~data[0]; s->state |= data[0] & data[1]; - outb (s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7); - outb ((s->state >> 8) & 0xff, - dev->iobase + AIO_IIRO_16_RELAY_8_15); + outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7); + outb((s->state >> 8) & 0xff, + dev->iobase + AIO_IIRO_16_RELAY_8_15); } data[1] = s->state; @@ -173,16 +161,15 @@ static int aio_iiro_16_dio_insn_bits_write (comedi_device *dev, return 2; } -static int aio_iiro_16_dio_insn_bits_read (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int aio_iiro_16_dio_insn_bits_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { if (insn->n != 2) return -EINVAL; data[1] = 0; - data[1] |= inb (dev->iobase + AIO_IIRO_16_INPUT_0_7); - data[1] |= inb (dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8; + data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7); + data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8; return 2; } diff --git a/comedi/drivers/am9513.h b/comedi/drivers/am9513.h index c57d2c05..f533cf16 100644 --- a/comedi/drivers/am9513.h +++ b/comedi/drivers/am9513.h @@ -77,4 +77,3 @@ #endif #endif - diff --git a/comedi/drivers/amcc_s5933.h b/comedi/drivers/amcc_s5933.h index 86b211a9..12e48595 100644 --- a/comedi/drivers/amcc_s5933.h +++ b/comedi/drivers/amcc_s5933.h @@ -15,7 +15,6 @@ #ifndef _AMCC_S5933_H_ #define _AMCC_S5933_H_ - /****************************************************************************/ /* AMCC Operation Register Offsets - PCI */ /****************************************************************************/ @@ -35,11 +34,11 @@ #define AMCC_OP_REG_MRTC 0x30 #define AMCC_OP_REG_MBEF 0x34 #define AMCC_OP_REG_INTCSR 0x38 -#define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2) /* INT source */ -#define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3) /* FIFO ctrl */ +#define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2) /* INT source */ +#define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3) /* FIFO ctrl */ #define AMCC_OP_REG_MCSR 0x3c -#define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2) /* Data in byte 2 */ -#define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3) /* Command in byte 3 */ +#define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2) /* Data in byte 2 */ +#define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3) /* Command in byte 3 */ #define AMCC_FIFO_DEPTH_DWORD 8 #define AMCC_FIFO_DEPTH_BYTES (8 * sizeof (u32)) @@ -53,7 +52,7 @@ #define INTCSR_INBOX_BYTE(x) (((x) & 0x3) << 8) #define INTCSR_INBOX_SELECT(x) (((x) & 0x3) << 10) #define INTCSR_INBOX_FULL_INT 0x1000 // enable inbox full interrupt -#define INTCSR_INBOX_INTR_STATUS 0x20000 // read, or write clear inbox full interrupt +#define INTCSR_INBOX_INTR_STATUS 0x20000 // read, or write clear inbox full interrupt #define INTCSR_INTR_ASSERTED 0x800000 // read only, interrupt asserted /****************************************************************************/ diff --git a/comedi/drivers/amplc_dio200.c b/comedi/drivers/amplc_dio200.c index 588a14a9..a2d5d67a 100644 --- a/comedi/drivers/amplc_dio200.c +++ b/comedi/drivers/amplc_dio200.c @@ -45,7 +45,6 @@ Configuration options - PCI215, PCI272: Passing a zero for an option is the same as leaving it unspecified. - SUBDEVICES PC218E PC212E PC215E/PCI215 @@ -67,7 +66,6 @@ SUBDEVICES 2 CTR-Z1* PPI-Z 3 INTERRUPT* INTERRUPT - Each PPI is a 8255 chip providing 24 DIO channels. The DIO channels are configurable as inputs or outputs in four groups: @@ -152,7 +150,6 @@ channels matches the number of interrupt sources. The PC214E does not have an interrupt status register; see notes on 'INTERRUPT SOURCES' below. - INTERRUPT SOURCES PC218E PC212E PC215E/PCI215 @@ -195,7 +192,6 @@ interrupt status register; its 'INTERRUPT' subdevice has a single channel and its interrupt source is selected by the position of jumper J5. - COMMANDS The driver supports a read streaming acquisition command on the @@ -247,21 +243,21 @@ order they appear in the channel list. * Periods of the internal clock sources in nanoseconds. */ static const unsigned clock_period[8] = { - 0, /* dedicated clock input/output pin */ - 100, /* 10 MHz */ - 1000, /* 1 MHz */ - 10000, /* 100 kHz */ - 100000, /* 10 kHz */ - 1000000, /* 1 kHz */ - 0, /* OUT N-1 */ - 0 /* group clock input pin */ + 0, /* dedicated clock input/output pin */ + 100, /* 10 MHz */ + 1000, /* 1 MHz */ + 10000, /* 100 kHz */ + 100000, /* 10 kHz */ + 1000000, /* 1 kHz */ + 0, /* OUT N-1 */ + 0 /* group clock input pin */ }; /* * Board descriptions. */ -enum dio200_bustype { isa_bustype, pci_bustype }; +enum dio200_bustype { isa_bustype, pci_bustype }; enum dio200_model { pc212e_model, @@ -288,47 +284,47 @@ typedef struct dio200_board_struct { static const dio200_board dio200_boards[] = { { - name: "pc212e", - bustype: isa_bustype, - model: pc212e_model, - layout: pc212_layout, - }, + name: "pc212e", + bustype: isa_bustype, + model: pc212e_model, + layout: pc212_layout, + }, { - name: "pc214e", - bustype: isa_bustype, - model: pc214e_model, - layout: pc214_layout, - }, + name: "pc214e", + bustype: isa_bustype, + model: pc214e_model, + layout: pc214_layout, + }, { - name: "pc215e", - bustype: isa_bustype, - model: pc215e_model, - layout: pc215_layout, - }, + name: "pc215e", + bustype: isa_bustype, + model: pc215e_model, + layout: pc215_layout, + }, { - name: "pci215", - bustype: pci_bustype, - model: pci215_model, - layout: pc215_layout, - }, + name: "pci215", + bustype: pci_bustype, + model: pci215_model, + layout: pc215_layout, + }, { - name: "pc218e", - bustype: isa_bustype, - model: pc218e_model, - layout: pc218_layout, - }, + name: "pc218e", + bustype: isa_bustype, + model: pc218e_model, + layout: pc218_layout, + }, { - name: "pc272e", - bustype: isa_bustype, - model: pc272e_model, - layout: pc272_layout, - }, + name: "pc272e", + bustype: isa_bustype, + model: pc272e_model, + layout: pc272_layout, + }, { - name: "pci272", - bustype: pci_bustype, - model: pci272_model, - layout: pc272_layout, - }, + name: "pci272", + bustype: pci_bustype, + model: pci272_model, + layout: pc272_layout, + }, }; /* @@ -336,55 +332,66 @@ static const dio200_board dio200_boards[] = { * layout. */ -enum dio200_sdtype { sd_none, sd_intr, sd_8255, sd_8254 }; +enum dio200_sdtype { sd_none, sd_intr, sd_8255, sd_8254 }; #define DIO200_MAX_SUBDEVS 7 #define DIO200_MAX_ISNS 6 typedef struct dio200_layout_struct { unsigned short n_subdevs; /* number of subdevices */ - unsigned char sdtype[DIO200_MAX_SUBDEVS]; /* enum dio200_sdtype */ - unsigned char sdinfo[DIO200_MAX_SUBDEVS]; /* depends on sdtype */ - char has_int_sce; /* has interrupt enable/status register */ - char has_clk_gat_sce; /* has clock/gate selection registers */ + unsigned char sdtype[DIO200_MAX_SUBDEVS]; /* enum dio200_sdtype */ + unsigned char sdinfo[DIO200_MAX_SUBDEVS]; /* depends on sdtype */ + char has_int_sce; /* has interrupt enable/status register */ + char has_clk_gat_sce; /* has clock/gate selection registers */ } dio200_layout; static const dio200_layout dio200_layouts[] = { [pc212_layout] = { - n_subdevs: 6, - sdtype: { sd_8255, sd_8254, sd_8254, sd_8254, sd_8254, sd_intr }, - sdinfo: { 0x00, 0x08, 0x0C, 0x10, 0x14, 0x3F }, - has_int_sce: 1, - has_clk_gat_sce: 1, - }, + n_subdevs:6, + sdtype: {sd_8255, sd_8254, sd_8254, sd_8254, + sd_8254, + sd_intr}, + sdinfo: {0x00, 0x08, 0x0C, 0x10, 0x14, + 0x3F}, + has_int_sce:1, + has_clk_gat_sce:1, + }, [pc214_layout] = { - n_subdevs: 4, - sdtype: { sd_8255, sd_8255, sd_8254, sd_intr }, - sdinfo: { 0x00, 0x08, 0x10, 0x01 }, - has_int_sce: 0, - has_clk_gat_sce: 0, - }, + n_subdevs:4, + sdtype: {sd_8255, sd_8255, sd_8254, + sd_intr}, + sdinfo: {0x00, 0x08, 0x10, 0x01}, + has_int_sce:0, + has_clk_gat_sce:0, + }, [pc215_layout] = { - n_subdevs: 5, - sdtype: { sd_8255, sd_8255, sd_8254, sd_8254, sd_intr }, - sdinfo: { 0x00, 0x08, 0x10, 0x14, 0x3F }, - has_int_sce: 1, - has_clk_gat_sce: 1, - }, + n_subdevs:5, + sdtype: {sd_8255, sd_8255, sd_8254, + sd_8254, + sd_intr}, + sdinfo: {0x00, 0x08, 0x10, 0x14, 0x3F}, + has_int_sce:1, + has_clk_gat_sce:1, + }, [pc218_layout] = { - n_subdevs: 7, - sdtype: { sd_8254, sd_8254, sd_8255, sd_8254, sd_8254, sd_intr }, - sdinfo: { 0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x3F }, - has_int_sce: 1, - has_clk_gat_sce: 1, - }, + n_subdevs:7, + sdtype: {sd_8254, sd_8254, sd_8255, sd_8254, + sd_8254, + sd_intr}, + sdinfo: {0x00, 0x04, 0x08, 0x0C, 0x10, + 0x14, + 0x3F}, + has_int_sce:1, + has_clk_gat_sce:1, + }, [pc272_layout] = { - n_subdevs: 4, - sdtype: { sd_8255, sd_8255, sd_8255, sd_intr }, - sdinfo: { 0x00, 0x08, 0x10, 0x3F }, - has_int_sce: 1, - has_clk_gat_sce: 0, - }, + n_subdevs:4, + sdtype: {sd_8255, sd_8255, sd_8255, + sd_intr}, + sdinfo: {0x00, 0x08, 0x10, 0x3F}, + has_int_sce:1, + has_clk_gat_sce:0, + }, }; /* @@ -392,12 +399,13 @@ static const dio200_layout dio200_layouts[] = { */ static struct pci_device_id dio200_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci215_model }, - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci272_model }, - { 0 } + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci215_model}, + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci272_model}, + {0} }; + MODULE_DEVICE_TABLE(pci, dio200_pci_table); /* @@ -417,13 +425,13 @@ typedef struct { #define devpriv ((dio200_private *)dev->private) typedef struct { - unsigned long iobase; /* Counter base address */ + unsigned long iobase; /* Counter base address */ unsigned long clk_sce_iobase; /* CLK_SCE base address */ unsigned long gat_sce_iobase; /* GAT_SCE base address */ - int which; /* Bit 5 of CLK_SCE or GAT_SCE */ + int which; /* Bit 5 of CLK_SCE or GAT_SCE */ int has_clk_gat_sce; - unsigned clock_src[3]; /* Current clock sources */ - unsigned gate_src[3]; /* Current gate sources */ + unsigned clock_src[3]; /* Current clock sources */ + unsigned gate_src[3]; /* Current gate sources */ } dio200_subdev_8254; typedef struct { @@ -437,24 +445,24 @@ typedef struct { int continuous; } dio200_subdev_intr; - /* * The comedi_driver structure tells the Comedi core module * which functions to call to configure/deconfigure (attach/detach) * the board, and also about the kernel module that contains * the device code. */ -static int dio200_attach(comedi_device *dev,comedi_devconfig *it); -static int dio200_detach(comedi_device *dev); +static int dio200_attach(comedi_device * dev, comedi_devconfig * it); +static int dio200_detach(comedi_device * dev); static comedi_driver driver_amplc_dio200 = { - driver_name: DIO200_DRIVER_NAME, - module: THIS_MODULE, - attach: dio200_attach, - detach: dio200_detach, - board_name: &dio200_boards[0].name, - offset: sizeof(dio200_board), - num_names: sizeof(dio200_boards) / sizeof(dio200_board), + driver_name:DIO200_DRIVER_NAME, + module:THIS_MODULE, + attach:dio200_attach, + detach:dio200_detach, + board_name:&dio200_boards[0].name, + offset:sizeof(dio200_board), + num_names:sizeof(dio200_boards) / sizeof(dio200_board), }; + COMEDI_INITCLEANUP(driver_amplc_dio200); /* @@ -462,8 +470,8 @@ COMEDI_INITCLEANUP(driver_amplc_dio200); * bus and slot. */ static int -dio200_find_pci(comedi_device *dev, int bus, int slot, - struct pci_dev **pci_dev_p) +dio200_find_pci(comedi_device * dev, int bus, int slot, + struct pci_dev **pci_dev_p) { struct pci_dev *pci_dev = NULL; struct pci_device_id *pci_id; @@ -476,20 +484,21 @@ dio200_find_pci(comedi_device *dev, int bus, int slot, break; } if (pci_id->vendor == 0) { - printk(KERN_ERR "comedi%d: %s: BUG! cannot determine board type!\n", - dev->minor, DIO200_DRIVER_NAME); + printk(KERN_ERR + "comedi%d: %s: BUG! cannot determine board type!\n", + dev->minor, DIO200_DRIVER_NAME); return -EINVAL; } /* Look for matching PCI device. */ - for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); - pci_dev != NULL ; - pci_dev = pci_get_device(pci_id->vendor, - pci_id->device, pci_dev)) { + for (pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); + pci_dev != NULL; + pci_dev = pci_get_device(pci_id->vendor, + pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { if (bus != pci_dev->bus->number - || slot != PCI_SLOT(pci_dev->devfn)) + || slot != PCI_SLOT(pci_dev->devfn)) continue; } #if 0 @@ -502,7 +511,8 @@ dio200_find_pci(comedi_device *dev, int bus, int slot, continue; } #endif - if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != 0) + if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != + 0) continue; /* Found a match. */ @@ -511,12 +521,12 @@ dio200_find_pci(comedi_device *dev, int bus, int slot, } /* No match found. */ if (bus || slot) { - printk(KERN_ERR "comedi%d: error! no %s found at pci %02x:%02x!\n", - dev->minor, thisboard->name, - bus, slot); + printk(KERN_ERR + "comedi%d: error! no %s found at pci %02x:%02x!\n", + dev->minor, thisboard->name, bus, slot); } else { printk(KERN_ERR "comedi%d: error! no %s found!\n", - dev->minor, thisboard->name); + dev->minor, thisboard->name); } return -EIO; } @@ -530,7 +540,7 @@ dio200_request_region(unsigned minor, unsigned long from, unsigned long extent) { if (!from || !request_region(from, extent, DIO200_DRIVER_NAME)) { printk(KERN_ERR "comedi%d: I/O port conflict (%#lx,%lu)!\n", - minor, from, extent); + minor, from, extent); return -EIO; } return 0; @@ -540,8 +550,8 @@ dio200_request_region(unsigned minor, unsigned long from, unsigned long extent) * 'insn_bits' function for an 'INTERRUPT' subdevice. */ static int -dio200_subdev_intr_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +dio200_subdev_intr_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { dio200_subdev_intr *subpriv = s->private; @@ -559,8 +569,7 @@ dio200_subdev_intr_insn_bits(comedi_device *dev, comedi_subdevice *s, /* * Called to stop acquisition for an 'INTERRUPT' subdevice. */ -static void -dio200_stop_intr(comedi_device *dev, comedi_subdevice *s) +static void dio200_stop_intr(comedi_device * dev, comedi_subdevice * s) { dio200_subdev_intr *subpriv = s->private; @@ -575,8 +584,7 @@ dio200_stop_intr(comedi_device *dev, comedi_subdevice *s) /* * Called to start acquisition for an 'INTERRUPT' subdevice. */ -static int -dio200_start_intr(comedi_device *dev, comedi_subdevice *s) +static int dio200_start_intr(comedi_device * dev, comedi_subdevice * s) { unsigned int n; unsigned isn_bits; @@ -612,14 +620,15 @@ dio200_start_intr(comedi_device *dev, comedi_subdevice *s) * Internal trigger function to start acquisition for an 'INTERRUPT' subdevice. */ static int -dio200_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, - unsigned int trignum) +dio200_inttrig_start_intr(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) { dio200_subdev_intr *subpriv; unsigned long flags; int event = 0; - if (trignum != 0) return -EINVAL; + if (trignum != 0) + return -EINVAL; subpriv = s->private; @@ -641,8 +650,7 @@ dio200_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, * This is called from the interrupt service routine to handle a read * scan on an 'INTERRUPT' subdevice. */ -static int -dio200_handle_read_intr(comedi_device *dev, comedi_subdevice *s) +static int dio200_handle_read_intr(comedi_device * dev, comedi_subdevice * s) { dio200_subdev_intr *subpriv = s->private; unsigned triggered; @@ -668,7 +676,7 @@ dio200_handle_read_intr(comedi_device *dev, comedi_subdevice *s) */ cur_enabled = subpriv->enabled_isns; while ((intstat = (inb(subpriv->iobase) & subpriv->valid_isns - & ~triggered)) != 0) { + & ~triggered)) != 0) { triggered |= intstat; cur_enabled &= ~triggered; outb(cur_enabled, subpriv->iobase); @@ -717,7 +725,7 @@ dio200_handle_read_intr(comedi_device *dev, comedi_subdevice *s) /* Write the scan to the buffer. */ if (comedi_buf_put(s->async, val)) { s->async->events |= (COMEDI_CB_BLOCK | - COMEDI_CB_EOS); + COMEDI_CB_EOS); } else { /* Error! Stop acquisition. */ dio200_stop_intr(dev, s); @@ -731,7 +739,8 @@ dio200_handle_read_intr(comedi_device *dev, comedi_subdevice *s) if (subpriv->stopcount == 0) { s->async->events |= COMEDI_CB_EOA; - dio200_stop_intr(dev, s); + dio200_stop_intr(dev, + s); } } } @@ -750,8 +759,7 @@ dio200_handle_read_intr(comedi_device *dev, comedi_subdevice *s) /* * 'cancel' function for an 'INTERRUPT' subdevice. */ -static int -dio200_subdev_intr_cancel(comedi_device *dev, comedi_subdevice *s) +static int dio200_subdev_intr_cancel(comedi_device * dev, comedi_subdevice * s) { dio200_subdev_intr *subpriv = s->private; unsigned long flags; @@ -769,8 +777,8 @@ dio200_subdev_intr_cancel(comedi_device *dev, comedi_subdevice *s) * 'do_cmdtest' function for an 'INTERRUPT' subdevice. */ static int -dio200_subdev_intr_cmdtest(comedi_device *dev, comedi_subdevice *s, - comedi_cmd *cmd) +dio200_subdev_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; unsigned int tmp; @@ -779,36 +787,48 @@ dio200_subdev_intr_cmdtest(comedi_device *dev, comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= (TRIG_NOW | TRIG_INT); - if (!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if (!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= (TRIG_COUNT | TRIG_NONE); - if (!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if (err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* these tests are true if more than one _src bit is set */ - if ((cmd->start_src & (cmd->start_src - 1)) != 0) err++; - if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) err++; - if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) err++; - if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) err++; - if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) err++; + if ((cmd->start_src & (cmd->start_src - 1)) != 0) + err++; + if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) + err++; + if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) + err++; + if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) + err++; + if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) + err++; - if (err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ @@ -850,7 +870,8 @@ dio200_subdev_intr_cmdtest(comedi_device *dev, comedi_subdevice *s, break; } - if (err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ @@ -862,8 +883,7 @@ dio200_subdev_intr_cmdtest(comedi_device *dev, comedi_subdevice *s, /* * 'do_cmd' function for an 'INTERRUPT' subdevice. */ -static int -dio200_subdev_intr_cmd(comedi_device *dev, comedi_subdevice *s) +static int dio200_subdev_intr_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; dio200_subdev_intr *subpriv = s->private; @@ -909,14 +929,15 @@ dio200_subdev_intr_cmd(comedi_device *dev, comedi_subdevice *s) * This function initializes an 'INTERRUPT' subdevice. */ static int -dio200_subdev_intr_init(comedi_device *dev, comedi_subdevice *s, - unsigned long iobase, unsigned valid_isns, int has_int_sce) +dio200_subdev_intr_init(comedi_device * dev, comedi_subdevice * s, + unsigned long iobase, unsigned valid_isns, int has_int_sce) { dio200_subdev_intr *subpriv; subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); if (!subpriv) { - printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor); + printk(KERN_ERR "comedi%d: error! out of memory!\n", + dev->minor); return -ENOMEM; } subpriv->iobase = iobase; @@ -953,7 +974,7 @@ dio200_subdev_intr_init(comedi_device *dev, comedi_subdevice *s, * This function cleans up an 'INTERRUPT' subdevice. */ static void -dio200_subdev_intr_cleanup(comedi_device *dev, comedi_subdevice *s) +dio200_subdev_intr_cleanup(comedi_device * dev, comedi_subdevice * s) { dio200_subdev_intr *subpriv = s->private; @@ -965,10 +986,9 @@ dio200_subdev_intr_cleanup(comedi_device *dev, comedi_subdevice *s) /* * Interrupt service routine. */ -static irqreturn_t -dio200_interrupt(int irq, void *d PT_REGS_ARG) +static irqreturn_t dio200_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; + comedi_device *dev = d; int handled; if (!dev->attached) { @@ -977,7 +997,7 @@ dio200_interrupt(int irq, void *d PT_REGS_ARG) if (devpriv->intr_sd >= 0) { handled = dio200_handle_read_intr(dev, - dev->subdevices + devpriv->intr_sd); + dev->subdevices + devpriv->intr_sd); } else { handled = 0; } @@ -989,8 +1009,8 @@ dio200_interrupt(int irq, void *d PT_REGS_ARG) * Handle 'insn_read' for an '8254' counter subdevice. */ static int -dio200_subdev_8254_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +dio200_subdev_8254_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { dio200_subdev_8254 *subpriv = s->private; int chan = CR_CHAN(insn->chanspec); @@ -1004,8 +1024,8 @@ dio200_subdev_8254_read(comedi_device *dev, comedi_subdevice *s, * Handle 'insn_write' for an '8254' counter subdevice. */ static int -dio200_subdev_8254_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +dio200_subdev_8254_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { dio200_subdev_8254 *subpriv = s->private; int chan = CR_CHAN(insn->chanspec); @@ -1019,14 +1039,17 @@ dio200_subdev_8254_write(comedi_device *dev, comedi_subdevice *s, * Set gate source for an '8254' counter subdevice channel. */ static int -dio200_set_gate_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, - unsigned int gate_src) +dio200_set_gate_src(dio200_subdev_8254 * subpriv, unsigned int counter_number, + unsigned int gate_src) { unsigned char byte; - if (!subpriv->has_clk_gat_sce) return -1; - if (counter_number > 2) return -1; - if (gate_src > 7) return -1; + if (!subpriv->has_clk_gat_sce) + return -1; + if (counter_number > 2) + return -1; + if (gate_src > 7) + return -1; subpriv->gate_src[counter_number] = gate_src; byte = GAT_SCE(subpriv->which, counter_number, gate_src); @@ -1039,10 +1062,12 @@ dio200_set_gate_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, * Get gate source for an '8254' counter subdevice channel. */ static int -dio200_get_gate_src(dio200_subdev_8254 *subpriv, unsigned int counter_number) +dio200_get_gate_src(dio200_subdev_8254 * subpriv, unsigned int counter_number) { - if (!subpriv->has_clk_gat_sce) return -1; - if (counter_number > 2) return -1; + if (!subpriv->has_clk_gat_sce) + return -1; + if (counter_number > 2) + return -1; return subpriv->gate_src[counter_number]; } @@ -1051,14 +1076,17 @@ dio200_get_gate_src(dio200_subdev_8254 *subpriv, unsigned int counter_number) * Set clock source for an '8254' counter subdevice channel. */ static int -dio200_set_clock_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, - unsigned int clock_src) +dio200_set_clock_src(dio200_subdev_8254 * subpriv, unsigned int counter_number, + unsigned int clock_src) { unsigned char byte; - if (!subpriv->has_clk_gat_sce) return -1; - if (counter_number > 2) return -1; - if (clock_src > 7) return -1; + if (!subpriv->has_clk_gat_sce) + return -1; + if (counter_number > 2) + return -1; + if (clock_src > 7) + return -1; subpriv->clock_src[counter_number] = clock_src; byte = CLK_SCE(subpriv->which, counter_number, clock_src); @@ -1071,13 +1099,15 @@ dio200_set_clock_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, * Get clock source for an '8254' counter subdevice channel. */ static int -dio200_get_clock_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, - lsampl_t *period_ns) +dio200_get_clock_src(dio200_subdev_8254 * subpriv, unsigned int counter_number, + lsampl_t * period_ns) { unsigned clock_src; - if (!subpriv->has_clk_gat_sce) return -1; - if (counter_number > 2) return -1; + if (!subpriv->has_clk_gat_sce) + return -1; + if (counter_number > 2) + return -1; clock_src = subpriv->clock_src[counter_number]; *period_ns = clock_period[clock_src]; @@ -1088,8 +1118,8 @@ dio200_get_clock_src(dio200_subdev_8254 *subpriv, unsigned int counter_number, * Handle 'insn_config' for an '8254' counter subdevice. */ static int -dio200_subdev_8254_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +dio200_subdev_8254_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { dio200_subdev_8254 *subpriv = s->private; int ret; @@ -1098,27 +1128,32 @@ dio200_subdev_8254_config(comedi_device *dev, comedi_subdevice *s, switch (data[0]) { case INSN_CONFIG_8254_SET_MODE: ret = i8254_set_mode(subpriv->iobase, 0, chan, data[1]); - if (ret < 0) return -EINVAL; + if (ret < 0) + return -EINVAL; break; case INSN_CONFIG_8254_READ_STATUS: data[1] = i8254_status(subpriv->iobase, 0, chan); break; case INSN_CONFIG_SET_GATE_SRC: ret = dio200_set_gate_src(subpriv, chan, data[2]); - if (ret < 0) return -EINVAL; + if (ret < 0) + return -EINVAL; break; case INSN_CONFIG_GET_GATE_SRC: ret = dio200_get_gate_src(subpriv, chan); - if (ret < 0) return -EINVAL; + if (ret < 0) + return -EINVAL; data[2] = ret; break; case INSN_CONFIG_SET_CLOCK_SRC: ret = dio200_set_clock_src(subpriv, chan, data[1]); - if (ret < 0) return -EINVAL; + if (ret < 0) + return -EINVAL; break; case INSN_CONFIG_GET_CLOCK_SRC: ret = dio200_get_clock_src(subpriv, chan, &data[2]); - if (ret < 0) return -EINVAL; + if (ret < 0) + return -EINVAL; data[1] = ret; break; default: @@ -1135,15 +1170,16 @@ dio200_subdev_8254_config(comedi_device *dev, comedi_subdevice *s, * offset is the offset to the 8254 chip. */ static int -dio200_subdev_8254_init(comedi_device *dev, comedi_subdevice *s, - unsigned long iobase, unsigned offset, int has_clk_gat_sce) +dio200_subdev_8254_init(comedi_device * dev, comedi_subdevice * s, + unsigned long iobase, unsigned offset, int has_clk_gat_sce) { dio200_subdev_8254 *subpriv; unsigned int chan; subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); if (!subpriv) { - printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor); + printk(KERN_ERR "comedi%d: error! out of memory!\n", + dev->minor); return -ENOMEM; } @@ -1171,7 +1207,7 @@ dio200_subdev_8254_init(comedi_device *dev, comedi_subdevice *s, /* Initialize channels. */ for (chan = 0; chan < 3; chan++) { i8254_set_mode(subpriv->iobase, 0, chan, - I8254_MODE0 | I8254_BINARY); + I8254_MODE0 | I8254_BINARY); if (subpriv->has_clk_gat_sce) { /* Gate source 0 is VCC (logic 1). */ dio200_set_gate_src(subpriv, chan, 0); @@ -1187,7 +1223,7 @@ dio200_subdev_8254_init(comedi_device *dev, comedi_subdevice *s, * This function cleans up an '8254' counter subdevice. */ static void -dio200_subdev_8254_cleanup(comedi_device *dev, comedi_subdevice *s) +dio200_subdev_8254_cleanup(comedi_device * dev, comedi_subdevice * s) { dio200_subdev_intr *subpriv = s->private; @@ -1202,8 +1238,7 @@ dio200_subdev_8254_cleanup(comedi_device *dev, comedi_subdevice *s) * in the driver structure, dev->board_ptr contains that * address. */ -static int -dio200_attach(comedi_device *dev,comedi_devconfig *it) +static int dio200_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; struct pci_dev *pci_dev = NULL; @@ -1217,10 +1252,11 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) int ret; printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, - DIO200_DRIVER_NAME); + DIO200_DRIVER_NAME); - if ((ret=alloc_private(dev,sizeof(dio200_private))) < 0) { - printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor); + if ((ret = alloc_private(dev, sizeof(dio200_private))) < 0) { + printk(KERN_ERR "comedi%d: error! out of memory!\n", + dev->minor); return ret; } @@ -1236,13 +1272,14 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) slot = it->options[1]; share_irq = 1; - if ((ret=dio200_find_pci(dev, bus, slot, &pci_dev)) < 0) + if ((ret = dio200_find_pci(dev, bus, slot, &pci_dev)) < 0) return ret; devpriv->pci_dev = pci_dev; break; default: - printk(KERN_ERR "comedi%d: %s: BUG! cannot determine board type!\n", - dev->minor, DIO200_DRIVER_NAME); + printk(KERN_ERR + "comedi%d: %s: BUG! cannot determine board type!\n", + dev->minor, DIO200_DRIVER_NAME); return -EINVAL; break; } @@ -1253,8 +1290,9 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) if (pci_dev) { ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME); if (ret < 0) { - printk(KERN_ERR "comedi%d: error! cannot enable PCI device and request regions!\n", - dev->minor); + printk(KERN_ERR + "comedi%d: error! cannot enable PCI device and request regions!\n", + dev->minor); return ret; } iobase = pci_resource_start(pci_dev, 2); @@ -1268,8 +1306,9 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase = iobase; layout = thislayout; - if ((ret=alloc_subdevices(dev, layout->n_subdevs)) < 0) { - printk(KERN_ERR "comedi%d: error! out of memory!\n", dev->minor); + if ((ret = alloc_subdevices(dev, layout->n_subdevs)) < 0) { + printk(KERN_ERR "comedi%d: error! out of memory!\n", + dev->minor); return ret; } @@ -1279,8 +1318,7 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) case sd_8254: /* counter subdevice (8254) */ ret = dio200_subdev_8254_init(dev, s, iobase, - layout->sdinfo[n], - layout->has_clk_gat_sce); + layout->sdinfo[n], layout->has_clk_gat_sce); if (ret < 0) { return ret; } @@ -1288,7 +1326,7 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) case sd_8255: /* digital i/o subdevice (8255) */ ret = subdev_8255_init(dev, s, 0, - iobase + layout->sdinfo[n]); + iobase + layout->sdinfo[n]); if (ret < 0) { return ret; } @@ -1297,9 +1335,8 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) /* 'INTERRUPT' subdevice */ if (irq) { ret = dio200_subdev_intr_init(dev, s, - iobase + DIO200_INT_SCE, - layout->sdinfo[n], - layout->has_int_sce); + iobase + DIO200_INT_SCE, + layout->sdinfo[n], layout->has_int_sce); if (ret < 0) { return ret; } @@ -1325,11 +1362,12 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) unsigned long flags = share_irq ? IRQF_SHARED : 0; if (comedi_request_irq(irq, dio200_interrupt, flags, - DIO200_DRIVER_NAME, dev) >= 0) { + DIO200_DRIVER_NAME, dev) >= 0) { dev->irq = irq; } else { - printk(KERN_WARNING "comedi%d: warning! irq %u unavailable!\n", - dev->minor, irq); + printk(KERN_WARNING + "comedi%d: warning! irq %u unavailable!\n", + dev->minor, irq); } } @@ -1358,14 +1396,13 @@ dio200_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int -dio200_detach(comedi_device *dev) +static int dio200_detach(comedi_device * dev) { const dio200_layout *layout; unsigned n; printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor, - DIO200_DRIVER_NAME); + DIO200_DRIVER_NAME); if (dev->irq) { comedi_free_irq(dev->irq, dev); @@ -1391,8 +1428,7 @@ dio200_detach(comedi_device *dev) } if (devpriv) { if (devpriv->pci_dev) { - if(dev->iobase) - { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -1402,9 +1438,8 @@ dio200_detach(comedi_device *dev) } if (dev->board_name) { printk(KERN_INFO "comedi%d: %s removed\n", - dev->minor, dev->board_name); + dev->minor, dev->board_name); } return 0; } - diff --git a/comedi/drivers/amplc_pc236.c b/comedi/drivers/amplc_pc236.c index dc762726..a46c6f46 100644 --- a/comedi/drivers/amplc_pc236.c +++ b/comedi/drivers/amplc_pc236.c @@ -65,7 +65,6 @@ unused. #define PCI_VENDOR_ID_AMPLICON 0x14dc #define PCI_DEVICE_ID_AMPLICON_PCI236 0x0009 - /* PC36AT / PCI236 registers */ #define PC236_IO_SIZE 4 @@ -93,34 +92,36 @@ unused. * Board descriptions for Amplicon PC36AT and PCI236. */ -enum pc236_bustype {isa_bustype, pci_bustype}; -enum pc236_model {pc36at_model, pci236_model}; +enum pc236_bustype { isa_bustype, pci_bustype }; +enum pc236_model { pc36at_model, pci236_model }; -typedef struct pc236_board_struct{ +typedef struct pc236_board_struct { const char *name; const char *fancy_name; enum pc236_bustype bustype; enum pc236_model model; -}pc236_board; +} pc236_board; static const pc236_board pc236_boards[] = { { - name: "pc36at", - fancy_name: "PC36AT", - bustype: isa_bustype, - model: pc36at_model, - }, + name: "pc36at", + fancy_name:"PC36AT", + bustype: isa_bustype, + model: pc36at_model, + }, { - name: "pci236", - fancy_name: "PCI236", - bustype: pci_bustype, - model: pci236_model, - }, + name: "pci236", + fancy_name:"PCI236", + bustype: pci_bustype, + model: pci236_model, + }, }; static struct pci_device_id pc236_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI236, PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci236_model }, - { 0 } + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI236, PCI_ANY_ID, + PCI_ANY_ID, 0, 0, pci236_model}, + {0} }; + MODULE_DEVICE_TABLE(pci, pc236_pci_table); /* @@ -131,12 +132,12 @@ MODULE_DEVICE_TABLE(pci, pc236_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ +typedef struct { /* PCI device */ struct pci_dev *pci_dev; unsigned long lcr_iobase; /* PLX PCI9052 config registers in PCIBAR1 */ int enable_irq; -}pc236_private; +} pc236_private; #define devpriv ((pc236_private *)dev->private) @@ -146,31 +147,31 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int pc236_attach(comedi_device *dev,comedi_devconfig *it); -static int pc236_detach(comedi_device *dev); -static comedi_driver driver_amplc_pc236={ - driver_name: PC236_DRIVER_NAME, - module: THIS_MODULE, - attach: pc236_attach, - detach: pc236_detach, - board_name: &pc236_boards[0].name, - offset: sizeof(pc236_board), - num_names: sizeof(pc236_boards) / sizeof(pc236_board), +static int pc236_attach(comedi_device * dev, comedi_devconfig * it); +static int pc236_detach(comedi_device * dev); +static comedi_driver driver_amplc_pc236 = { + driver_name:PC236_DRIVER_NAME, + module:THIS_MODULE, + attach:pc236_attach, + detach:pc236_detach, + board_name:&pc236_boards[0].name, + offset:sizeof(pc236_board), + num_names:sizeof(pc236_boards) / sizeof(pc236_board), }; -COMEDI_INITCLEANUP(driver_amplc_pc236); +COMEDI_INITCLEANUP(driver_amplc_pc236); static int pc236_request_region(unsigned long from, unsigned long extent); -static void pc236_intr_disable(comedi_device *dev); -static void pc236_intr_enable(comedi_device *dev); -static int pc236_intr_check(comedi_device *dev); -static int pc236_intr_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pc236_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int pc236_intr_cmd(comedi_device *dev,comedi_subdevice *s); -static int pc236_intr_cancel(comedi_device *dev,comedi_subdevice *s); -static irqreturn_t pc236_interrupt(int irq,void *d PT_REGS_ARG); +static void pc236_intr_disable(comedi_device * dev); +static void pc236_intr_enable(comedi_device * dev); +static int pc236_intr_check(comedi_device * dev); +static int pc236_intr_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pc236_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int pc236_intr_cmd(comedi_device * dev, comedi_subdevice * s); +static int pc236_intr_cancel(comedi_device * dev, comedi_subdevice * s); +static irqreturn_t pc236_interrupt(int irq, void *d PT_REGS_ARG); /* * Attach is called by the Comedi core to configure the driver @@ -178,7 +179,7 @@ static irqreturn_t pc236_interrupt(int irq,void *d PT_REGS_ARG); * in the driver structure, dev->board_ptr contains that * address. */ -static int pc236_attach(comedi_device *dev,comedi_devconfig *it) +static int pc236_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; struct pci_dev *pci_dev = NULL; @@ -189,12 +190,12 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) int share_irq = 0; int ret; - printk("comedi%d: %s: ",dev->minor, PC236_DRIVER_NAME); + printk("comedi%d: %s: ", dev->minor, PC236_DRIVER_NAME); /* * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if ((ret=alloc_private(dev,sizeof(pc236_private))) < 0) { + if ((ret = alloc_private(dev, sizeof(pc236_private))) < 0) { printk("out of memory!\n"); return ret; } @@ -221,27 +222,30 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) } /* Look for matching PCI device. */ - for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, - NULL); pci_dev != NULL; - pci_dev = pci_get_device(pci_id->vendor, - pci_id->device, pci_dev)) { + for (pci_dev = pci_get_device(pci_id->vendor, pci_id->device, + NULL); pci_dev != NULL; + pci_dev = pci_get_device(pci_id->vendor, + pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { if (bus != pci_dev->bus->number - || slot != PCI_SLOT(pci_dev->devfn)) + || slot != PCI_SLOT(pci_dev->devfn)) continue; } #if 0 if (pci_id->subvendor != PCI_ANY_ID) { - if (pci_dev->subsystem_vendor != pci_id->subvendor) + if (pci_dev->subsystem_vendor != + pci_id->subvendor) continue; } if (pci_id->subdevice != PCI_ANY_ID) { - if (pci_dev->subsystem_device != pci_id->subdevice) + if (pci_dev->subsystem_device != + pci_id->subdevice) continue; } #endif - if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != 0) + if (((pci_dev->class ^ pci_id->class) & pci_id-> + class_mask) != 0) continue; /* Found a match. */ devpriv->pci_dev = pci_dev; @@ -266,7 +270,7 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) /* Enable device and reserve I/O spaces. */ if (pci_dev) { - if ((ret=comedi_pci_enable(pci_dev, PC236_DRIVER_NAME)) < 0) { + if ((ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME)) < 0) { printk("error enabling PCI device and requesting regions!\n"); return ret; } @@ -274,7 +278,7 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) iobase = pci_resource_start(pci_dev, 2); irq = pci_dev->irq; } else { - if ((ret=pc236_request_region(iobase, PC236_IO_SIZE)) < 0) { + if ((ret = pc236_request_region(iobase, PC236_IO_SIZE)) < 0) { return ret; } } @@ -284,18 +288,18 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if ((ret=alloc_subdevices(dev, 2)) < 0) { + if ((ret = alloc_subdevices(dev, 2)) < 0) { printk("out of memory!\n"); return ret; } - s = dev->subdevices+0; + s = dev->subdevices + 0; /* digital i/o subdevice (8255) */ - if ((ret=subdev_8255_init(dev, s, NULL, iobase)) < 0) { + if ((ret = subdev_8255_init(dev, s, NULL, iobase)) < 0) { printk("out of memory!\n"); return ret; } - s = dev->subdevices+1; + s = dev->subdevices + 1; dev->read_subdev = s; s->type = COMEDI_SUBD_UNUSED; pc236_intr_disable(dev); @@ -303,7 +307,7 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) unsigned long flags = share_irq ? IRQF_SHARED : 0; if (comedi_request_irq(irq, pc236_interrupt, flags, - PC236_DRIVER_NAME, dev) >= 0) { + PC236_DRIVER_NAME, dev) >= 0) { dev->irq = irq; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; @@ -332,7 +336,6 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -341,20 +344,20 @@ static int pc236_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pc236_detach(comedi_device *dev) +static int pc236_detach(comedi_device * dev) { printk("comedi%d: %s: remove\n", dev->minor, PC236_DRIVER_NAME); if (devpriv) { pc236_intr_disable(dev); } - if (dev->irq) comedi_free_irq(dev->irq, dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); if (dev->subdevices) { - subdev_8255_cleanup(dev, dev->subdevices+0); + subdev_8255_cleanup(dev, dev->subdevices + 0); } if (devpriv) { if (devpriv->pci_dev) { - if(dev->iobase) - { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -383,14 +386,14 @@ static int pc236_request_region(unsigned long from, unsigned long extent) * configured on subdevice 1) and to physically disable the interrupt * (not possible on the PC36AT, except by removing the IRQ jumper!). */ -static void pc236_intr_disable(comedi_device *dev) +static void pc236_intr_disable(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->enable_irq = 0; if (devpriv->lcr_iobase) - outl(PCI236_INTR_DISABLE, devpriv->lcr_iobase+PLX9052_INTCSR); + outl(PCI236_INTR_DISABLE, devpriv->lcr_iobase + PLX9052_INTCSR); comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } @@ -399,14 +402,14 @@ static void pc236_intr_disable(comedi_device *dev) * configured on subdevice 1) and to physically enable the interrupt * (not possible on the PC36AT, except by (re)connecting the IRQ jumper!). */ -static void pc236_intr_enable(comedi_device *dev) +static void pc236_intr_enable(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->enable_irq = 1; if (devpriv->lcr_iobase) - outl(PCI236_INTR_ENABLE, devpriv->lcr_iobase+PLX9052_INTCSR); + outl(PCI236_INTR_ENABLE, devpriv->lcr_iobase + PLX9052_INTCSR); comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } @@ -417,7 +420,7 @@ static void pc236_intr_enable(comedi_device *dev) * interrupt. * Returns 0 if the interrupt should be ignored. */ -static int pc236_intr_check(comedi_device *dev) +static int pc236_intr_check(comedi_device * dev) { int retval = 0; unsigned long flags; @@ -426,13 +429,14 @@ static int pc236_intr_check(comedi_device *dev) if (devpriv->enable_irq) { retval = 1; if (devpriv->lcr_iobase) { - if ((inl(devpriv->lcr_iobase+PLX9052_INTCSR) - & PLX9052_INTCSR_LI1STAT_MASK) - == PLX9052_INTCSR_LI1STAT_INACTIVE) { + if ((inl(devpriv->lcr_iobase + PLX9052_INTCSR) + & PLX9052_INTCSR_LI1STAT_MASK) + == PLX9052_INTCSR_LI1STAT_INACTIVE) { retval = 0; } else { /* Clear interrupt and keep it enabled. */ - outl(PCI236_INTR_ENABLE, devpriv->lcr_iobase+PLX9052_INTCSR); + outl(PCI236_INTR_ENABLE, + devpriv->lcr_iobase + PLX9052_INTCSR); } } } @@ -445,8 +449,8 @@ static int pc236_intr_check(comedi_device *dev) * Input from subdevice 1. * Copied from the comedi_parport driver. */ -static int pc236_intr_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pc236_intr_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[1] = 0; return 2; @@ -456,68 +460,77 @@ static int pc236_intr_insn(comedi_device *dev,comedi_subdevice *s, * Subdevice 1 command test. * Copied from the comedi_parport driver. */ -static int pc236_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int pc236_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1 */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_FOLLOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: ignored */ - if(err)return 2; + if (err) + return 2; /* step 3: */ - if(cmd->start_arg!=0){ + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=1){ + if (cmd->scan_end_arg != 1) { cmd->scan_end_arg = 1; err++; } - if(cmd->stop_arg!=0){ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } - if(err)return 3; + if (err) + return 3; /* step 4: ignored */ - if(err)return 4; + if (err) + return 4; return 0; } @@ -525,7 +538,7 @@ static int pc236_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, /* * Subdevice 1 command. */ -static int pc236_intr_cmd(comedi_device *dev,comedi_subdevice *s) +static int pc236_intr_cmd(comedi_device * dev, comedi_subdevice * s) { pc236_intr_enable(dev); @@ -535,7 +548,7 @@ static int pc236_intr_cmd(comedi_device *dev,comedi_subdevice *s) /* * Subdevice 1 cancel command. */ -static int pc236_intr_cancel(comedi_device *dev,comedi_subdevice *s) +static int pc236_intr_cancel(comedi_device * dev, comedi_subdevice * s) { pc236_intr_disable(dev); @@ -546,18 +559,17 @@ static int pc236_intr_cancel(comedi_device *dev,comedi_subdevice *s) * Interrupt service routine. * Based on the comedi_parport driver. */ -static irqreturn_t pc236_interrupt(int irq,void *d PT_REGS_ARG) +static irqreturn_t pc236_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; - comedi_subdevice *s=dev->subdevices+1; + comedi_device *dev = d; + comedi_subdevice *s = dev->subdevices + 1; int handled; handled = pc236_intr_check(dev); if (dev->attached && handled) { - comedi_buf_put(s->async,0); + comedi_buf_put(s->async, 0); s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; comedi_event(dev, s); } return IRQ_RETVAL(handled); } - diff --git a/comedi/drivers/amplc_pc263.c b/comedi/drivers/amplc_pc263.c index ab85aa88..22e6de6d 100644 --- a/comedi/drivers/amplc_pc263.c +++ b/comedi/drivers/amplc_pc263.c @@ -54,43 +54,43 @@ The state of the outputs can be read. #define PCI_VENDOR_ID_AMPLICON 0x14dc #define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c - /* PC263 / PCI263 registers */ #define PC263_IO_SIZE 2 - /* * Board descriptions for Amplicon PC263 / PCI263. */ -enum pc263_bustype {isa_bustype, pci_bustype}; -enum pc263_model {pc263_model, pci263_model}; +enum pc263_bustype { isa_bustype, pci_bustype }; +enum pc263_model { pc263_model, pci263_model }; -typedef struct pc263_board_struct{ +typedef struct pc263_board_struct { const char *name; const char *fancy_name; enum pc263_bustype bustype; enum pc263_model model; -}pc263_board; +} pc263_board; static const pc263_board pc263_boards[] = { { - name: "pc263", - fancy_name: "PC263", - bustype: isa_bustype, - model: pc263_model, - }, + name: "pc263", + fancy_name:"PC263", + bustype: isa_bustype, + model: pc263_model, + }, { - name: "pci263", - fancy_name: "PCI263", - bustype: pci_bustype, - model: pci263_model, - }, + name: "pci263", + fancy_name:"PCI263", + bustype: pci_bustype, + model: pci263_model, + }, }; static struct pci_device_id pc263_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci263_model }, - { 0 } + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263, PCI_ANY_ID, + PCI_ANY_ID, 0, 0, pci263_model}, + {0} }; + MODULE_DEVICE_TABLE(pci, pc263_pci_table); /* @@ -101,10 +101,10 @@ MODULE_DEVICE_TABLE(pci, pc263_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ +typedef struct { /* PCI device. */ struct pci_dev *pci_dev; -}pc263_private; +} pc263_private; #define devpriv ((pc263_private *)dev->private) @@ -114,23 +114,23 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int pc263_attach(comedi_device *dev,comedi_devconfig *it); -static int pc263_detach(comedi_device *dev); -static comedi_driver driver_amplc_pc263={ - driver_name: PC263_DRIVER_NAME, - module: THIS_MODULE, - attach: pc263_attach, - detach: pc263_detach, - board_name: &pc263_boards[0].name, - offset: sizeof(pc263_board), - num_names: sizeof(pc263_boards) / sizeof(pc263_board), +static int pc263_attach(comedi_device * dev, comedi_devconfig * it); +static int pc263_detach(comedi_device * dev); +static comedi_driver driver_amplc_pc263 = { + driver_name:PC263_DRIVER_NAME, + module:THIS_MODULE, + attach:pc263_attach, + detach:pc263_detach, + board_name:&pc263_boards[0].name, + offset:sizeof(pc263_board), + num_names:sizeof(pc263_boards) / sizeof(pc263_board), }; static int pc263_request_region(unsigned long from, unsigned long extent); -static int pc263_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pc263_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int pc263_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pc263_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* * Attach is called by the Comedi core to configure the driver @@ -138,7 +138,7 @@ static int pc263_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * in the driver structure, dev->board_ptr contains that * address. */ -static int pc263_attach(comedi_device *dev,comedi_devconfig *it) +static int pc263_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; struct pci_dev *pci_dev = NULL; @@ -147,12 +147,12 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) struct pci_device_id *pci_id; int ret; - printk("comedi%d: %s: ",dev->minor, PC263_DRIVER_NAME); + printk("comedi%d: %s: ", dev->minor, PC263_DRIVER_NAME); /* * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if ((ret=alloc_private(dev,sizeof(pc263_private))) < 0) { + if ((ret = alloc_private(dev, sizeof(pc263_private))) < 0) { printk("out of memory!\n"); return ret; } @@ -176,27 +176,30 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) } /* Look for matching PCI device. */ - for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, - NULL); pci_dev != NULL; - pci_dev = pci_get_device(pci_id->vendor, - pci_id->device, pci_dev)) { + for (pci_dev = pci_get_device(pci_id->vendor, pci_id->device, + NULL); pci_dev != NULL; + pci_dev = pci_get_device(pci_id->vendor, + pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { if (bus != pci_dev->bus->number - || slot != PCI_SLOT(pci_dev->devfn)) + || slot != PCI_SLOT(pci_dev->devfn)) continue; } #if 0 if (pci_id->subvendor != PCI_ANY_ID) { - if (pci_dev->subsystem_vendor != pci_id->subvendor) + if (pci_dev->subsystem_vendor != + pci_id->subvendor) continue; } if (pci_id->subdevice != PCI_ANY_ID) { - if (pci_dev->subsystem_device != pci_id->subdevice) + if (pci_dev->subsystem_device != + pci_id->subdevice) continue; } #endif - if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != 0) + if (((pci_dev->class ^ pci_id->class) & pci_id-> + class_mask) != 0) continue; /* Found a match. */ devpriv->pci_dev = pci_dev; @@ -221,13 +224,13 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) /* Enable device and reserve I/O spaces. */ if (pci_dev) { - if ((ret=comedi_pci_enable(pci_dev, PC263_DRIVER_NAME)) < 0) { + if ((ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME)) < 0) { printk("error enabling PCI device and requesting regions!\n"); return ret; } iobase = pci_resource_start(pci_dev, 2); } else { - if ((ret=pc263_request_region(iobase, PC263_IO_SIZE)) < 0) { + if ((ret = pc263_request_region(iobase, PC263_IO_SIZE)) < 0) { return ret; } } @@ -237,15 +240,15 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if ((ret=alloc_subdevices(dev, 1)) < 0) { + if ((ret = alloc_subdevices(dev, 1)) < 0) { printk("out of memory!\n"); return -ENOMEM; } - s = dev->subdevices+0; + s = dev->subdevices + 0; /* digital i/o subdevice */ s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE|SDF_RT; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_RT; s->n_chan = 16; s->maxdata = 1; s->range_table = &range_digital; @@ -268,7 +271,6 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -277,14 +279,13 @@ static int pc263_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pc263_detach(comedi_device *dev) +static int pc263_detach(comedi_device * dev) { printk("comedi%d: %s: remove\n", dev->minor, PC263_DRIVER_NAME); if (devpriv) { if (devpriv->pci_dev) { - if(dev->iobase) - { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -314,16 +315,17 @@ static int pc263_request_region(unsigned long from, unsigned long extent) * 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 pc263_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pc263_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; /* Write out the new digital output lines */ outb(s->state & 0xFF, dev->iobase); outb(s->state >> 8, dev->iobase + 1); @@ -333,15 +335,16 @@ static int pc263_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, * input and output lines. */ /* or we could just return the software copy of the output values if * it was a purely digital output subdevice */ - data[1]=s->state; + data[1] = s->state; return 2; } -static int pc263_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pc263_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=1)return -EINVAL; + if (insn->n != 1) + return -EINVAL; return 1; } @@ -350,4 +353,3 @@ static int pc263_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * as necessary. */ COMEDI_INITCLEANUP(driver_amplc_pc263); - diff --git a/comedi/drivers/amplc_pci224.c b/comedi/drivers/amplc_pci224.c index 4b5548d9..096805c0 100644 --- a/comedi/drivers/amplc_pci224.c +++ b/comedi/drivers/amplc_pci224.c @@ -155,7 +155,7 @@ Caveats: /* (r/w) Polarity (PCI224 only, PCI234 always bipolar!). */ #define PCI224_DACCON_POLAR_MASK (1 << 3) #define PCI224_DACCON_POLAR_UNI (0 << 3) /* range [0,Vref] */ -#define PCI224_DACCON_POLAR_BI (1 << 3) /* range [-Vref,+Vref]*/ +#define PCI224_DACCON_POLAR_BI (1 << 3) /* range [-Vref,+Vref] */ /* (r/w) Internal Vref (PCI224 only, when LK1 in position 1-2). */ #define PCI224_DACCON_VREF_MASK (3 << 4) #define PCI224_DACCON_VREF_1_25 (0 << 4) /* Vref = 1.25V */ @@ -275,15 +275,15 @@ Caveats: static const comedi_lrange range_pci224_internal = { 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } }; static const unsigned short hwrange_pci224_internal[8] = { @@ -301,9 +301,9 @@ static const unsigned short hwrange_pci224_internal[8] = { static const comedi_lrange range_pci224_external = { 2, { - RANGE_ext(-1, 1), /* bipolar [-Vref,+Vref] */ - RANGE_ext(0, 1), /* unipolar [0,+Vref] */ - } + RANGE_ext(-1, 1), /* bipolar [-Vref,+Vref] */ + RANGE_ext(0, 1), /* unipolar [0,+Vref] */ + } }; static const unsigned short hwrange_pci224_external[2] = { @@ -316,8 +316,8 @@ static const unsigned short hwrange_pci224_external[2] = { static const comedi_lrange range_pci234_ext2 = { 1, { - RANGE_ext(-2, 2), - } + RANGE_ext(-2, 2), + } }; /* The hardware selectable Vref external range for PCI234 @@ -325,21 +325,20 @@ static const comedi_lrange range_pci234_ext2 = { static const comedi_lrange range_pci234_ext = { 1, { - RANGE_ext(-1, 1), - } + RANGE_ext(-1, 1), + } }; /* This serves for all the PCI234 ranges. */ static const unsigned short hwrange_pci234[1] = { - PCI224_DACCON_POLAR_BI, /* bipolar - hardware ignores it! */ + PCI224_DACCON_POLAR_BI, /* bipolar - hardware ignores it! */ }; - /* * Board descriptions. */ -enum pci224_model { pci224_model, pci234_model }; +enum pci224_model { pci224_model, pci234_model }; typedef struct pci224_board_struct { const char *name; @@ -350,17 +349,17 @@ typedef struct pci224_board_struct { static const pci224_board pci224_boards[] = { { - name: "pci224", - model: pci224_model, - ao_chans: 16, - ao_bits: 12, - }, + name: "pci224", + model: pci224_model, + ao_chans:16, + ao_bits: 12, + }, { - name: "pci234", - model: pci234_model, - ao_chans: 4, - ao_bits: 16, - }, + name: "pci234", + model: pci234_model, + ao_chans:4, + ao_bits: 16, + }, }; /* @@ -368,12 +367,13 @@ static const pci224_board pci224_boards[] = { */ static struct pci_device_id pci224_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci224_model }, - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci234_model }, - { 0 } + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci224_model}, + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, pci234_model}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci224_pci_table); /* @@ -412,24 +412,25 @@ typedef struct { * the board, and also about the kernel module that contains * the device code. */ -static int pci224_attach(comedi_device *dev,comedi_devconfig *it); -static int pci224_detach(comedi_device *dev); +static int pci224_attach(comedi_device * dev, comedi_devconfig * it); +static int pci224_detach(comedi_device * dev); static comedi_driver driver_amplc_pci224 = { - driver_name: DRIVER_NAME, - module: THIS_MODULE, - attach: pci224_attach, - detach: pci224_detach, - board_name: &pci224_boards[0].name, - offset: sizeof(pci224_board), - num_names: sizeof(pci224_boards) / sizeof(pci224_board), + driver_name:DRIVER_NAME, + module:THIS_MODULE, + attach:pci224_attach, + detach:pci224_detach, + board_name:&pci224_boards[0].name, + offset:sizeof(pci224_board), + num_names:sizeof(pci224_boards) / sizeof(pci224_board), }; + COMEDI_INITCLEANUP(driver_amplc_pci224); /* * Called from the 'insn_write' function to perform a single write. */ static void -pci224_ao_set_data(comedi_device *dev, int chan, int range, lsampl_t data) +pci224_ao_set_data(comedi_device * dev, int chan, int range, lsampl_t data) { unsigned short mangled; @@ -439,9 +440,9 @@ pci224_ao_set_data(comedi_device *dev, int chan, int range, lsampl_t data) outw(1 << chan, dev->iobase + PCI224_DACCEN); /* Set range and reset FIFO. */ devpriv->daccon = COMBINE(devpriv->daccon, devpriv->hwrange[range], - (PCI224_DACCON_POLAR_MASK | PCI224_DACCON_VREF_MASK)); + (PCI224_DACCON_POLAR_MASK | PCI224_DACCON_VREF_MASK)); outw(devpriv->daccon | PCI224_DACCON_FIFORESET, - dev->iobase + PCI224_DACCON); + dev->iobase + PCI224_DACCON); /* * Mangle the data. The hardware expects: * - bipolar: 16-bit 2's complement @@ -449,7 +450,7 @@ pci224_ao_set_data(comedi_device *dev, int chan, int range, lsampl_t data) */ mangled = (unsigned short)data << (16 - thisboard->ao_bits); if ((devpriv->daccon & PCI224_DACCON_POLAR_MASK) == - PCI224_DACCON_POLAR_BI) { + PCI224_DACCON_POLAR_BI) { mangled ^= 0x8000; } /* Write mangled data to the FIFO. */ @@ -462,8 +463,8 @@ pci224_ao_set_data(comedi_device *dev, int chan, int range, lsampl_t data) * 'insn_write' function for AO subdevice. */ static int -pci224_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +pci224_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int retval; int i; @@ -495,8 +496,8 @@ pci224_ao_insn_write(comedi_device *dev, comedi_subdevice *s, * command. */ static int -pci224_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +pci224_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan; @@ -515,7 +516,7 @@ pci224_ao_insn_read(comedi_device *dev, comedi_subdevice *s, */ static void pci224_cascade_ns_to_timer(int osc_base, unsigned int *d1, unsigned int *d2, - unsigned int *nanosec, int round_mode) + unsigned int *nanosec, int round_mode) { i8253_cascade_ns_to_timer(osc_base, d1, d2, nanosec, round_mode); } @@ -523,8 +524,7 @@ pci224_cascade_ns_to_timer(int osc_base, unsigned int *d1, unsigned int *d2, /* * Kills a command running on the AO subdevice. */ -static void -pci224_ao_stop(comedi_device *dev, comedi_subdevice *s) +static void pci224_ao_stop(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; @@ -545,8 +545,7 @@ pci224_ao_stop(comedi_device *dev, comedi_subdevice *s) * finish, unless we appear to have been called via the interrupt * routine. */ - while (devpriv->intr_running && - devpriv->intr_cpuid != THISCPU) { + while (devpriv->intr_running && devpriv->intr_cpuid != THISCPU) { comedi_spin_unlock_irqrestore(&devpriv->ao_spinlock, flags); comedi_spin_lock_irqsave(&devpriv->ao_spinlock, flags); } @@ -554,10 +553,10 @@ pci224_ao_stop(comedi_device *dev, comedi_subdevice *s) /* Reconfigure DAC for insn_write usage. */ outw(0, dev->iobase + PCI224_DACCEN); /* Disable channels. */ devpriv->daccon = COMBINE(devpriv->daccon, - PCI224_DACCON_TRIG_SW | PCI224_DACCON_FIFOINTR_EMPTY, - PCI224_DACCON_TRIG_MASK | PCI224_DACCON_FIFOINTR_MASK); + PCI224_DACCON_TRIG_SW | PCI224_DACCON_FIFOINTR_EMPTY, + PCI224_DACCON_TRIG_MASK | PCI224_DACCON_FIFOINTR_MASK); outw(devpriv->daccon | PCI224_DACCON_FIFORESET, - dev->iobase + PCI224_DACCON); + dev->iobase + PCI224_DACCON); /* No longer running AO command. */ devpriv->ao_cmd_running = 0; } @@ -565,8 +564,7 @@ pci224_ao_stop(comedi_device *dev, comedi_subdevice *s) /* * Handles start of acquisition for the AO subdevice. */ -static void -pci224_ao_start(comedi_device *dev, comedi_subdevice *s) +static void pci224_ao_start(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned long flags; @@ -592,8 +590,7 @@ pci224_ao_start(comedi_device *dev, comedi_subdevice *s) /* * Handles interrupts from the DAC FIFO. */ -static void -pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) +static void pci224_ao_handle_fifo(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned int num_scans; @@ -622,8 +619,7 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) switch (dacstat & PCI224_DACCON_FIFOFL_MASK) { case PCI224_DACCON_FIFOFL_EMPTY: room = PCI224_FIFO_ROOM_EMPTY; - if (!devpriv->ao_stop_continuous && - devpriv->ao_stop_count == 0) { + if (!devpriv->ao_stop_continuous && devpriv->ao_stop_count == 0) { /* FIFO empty at end of counted acquisition. */ pci224_ao_stop(dev, s); s->async->events |= COMEDI_CB_EOA; @@ -647,8 +643,7 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) pci224_ao_stop(dev, s); s->async->events |= COMEDI_CB_OVERFLOW; rt_printk(KERN_ERR "comedi%d: " - "AO buffer underrun\n", - dev->minor); + "AO buffer underrun\n", dev->minor); } } /* Determine how many new scans can be put in the FIFO. */ @@ -662,10 +657,11 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) /* Process scans. */ for (n = 0; n < num_scans; n++) { cfc_read_array_from_buffer(s, &devpriv->ao_scan_vals[0], - bytes_per_scan); + bytes_per_scan); for (i = 0; i < cmd->chanlist_len; i++) { - outw(devpriv->ao_scan_vals[devpriv->ao_scan_order[i]], - dev->iobase + PCI224_DACDATA); + outw(devpriv->ao_scan_vals[devpriv-> + ao_scan_order[i]], + dev->iobase + PCI224_DACDATA); } } if (!devpriv->ao_stop_continuous) { @@ -676,14 +672,14 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) * until FIFO is empty. */ devpriv->daccon = COMBINE(devpriv->daccon, - PCI224_DACCON_FIFOINTR_EMPTY, - PCI224_DACCON_FIFOINTR_MASK); + PCI224_DACCON_FIFOINTR_EMPTY, + PCI224_DACCON_FIFOINTR_MASK); outw(devpriv->daccon, - dev->iobase + PCI224_DACCON); + dev->iobase + PCI224_DACCON); } } if ((devpriv->daccon & PCI224_DACCON_TRIG_MASK) == - PCI224_DACCON_TRIG_NONE) { + PCI224_DACCON_TRIG_NONE) { unsigned short trig; /* @@ -709,7 +705,7 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) } } devpriv->daccon = COMBINE(devpriv->daccon, trig, - PCI224_DACCON_TRIG_MASK); + PCI224_DACCON_TRIG_MASK); outw(devpriv->daccon, dev->iobase + PCI224_DACCON); } } @@ -722,12 +718,13 @@ pci224_ao_handle_fifo(comedi_device *dev, comedi_subdevice *s) * Internal trigger function to start acquisition on AO subdevice. */ static int -pci224_ao_inttrig_start(comedi_device *dev, comedi_subdevice *s, - unsigned int trignum) +pci224_ao_inttrig_start(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) { unsigned long flags; - if (trignum != 0) return -EINVAL; + if (trignum != 0) + return -EINVAL; comedi_spin_lock_irqsave(&devpriv->ao_spinlock, flags); if (s->async->inttrig) { @@ -751,7 +748,7 @@ pci224_ao_inttrig_start(comedi_device *dev, comedi_subdevice *s, * 'do_cmdtest' function for AO subdevice. */ static int -pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) +pci224_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, comedi_cmd * cmd) { int err = 0; unsigned int tmp; @@ -760,45 +757,61 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) tmp = cmd->start_src; cmd->start_src &= TRIG_INT | TRIG_EXT; - if (!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT | TRIG_TIMER; - if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if (!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE; - if (!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if (err) return 1; + if (err) + return 1; /* Step 2: make sure trigger sources are unique and mutually * compatible. */ /* these tests are true if more than one _src bit is set */ - if ((cmd->start_src & (cmd->start_src - 1)) != 0) err++; - if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) err++; - if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) err++; - if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) err++; - if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) err++; + if ((cmd->start_src & (cmd->start_src - 1)) != 0) + err++; + if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) + err++; + if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) + err++; + if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) + err++; + if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) + err++; /* There's only one external trigger signal (which makes these * tests easier). Only one thing can use it. */ tmp = 0; - if (cmd->start_src & TRIG_EXT) tmp++; - if (cmd->scan_begin_src & TRIG_EXT) tmp++; - if (cmd->stop_src & TRIG_EXT) tmp++; - if (tmp > 1) err++; + if (cmd->start_src & TRIG_EXT) + tmp++; + if (cmd->scan_begin_src & TRIG_EXT) + tmp++; + if (cmd->stop_src & TRIG_EXT) + tmp++; + if (tmp > 1) + err++; - if (err) return 2; + if (err) + return 2; /* Step 3: make sure arguments are trivially compatible. */ @@ -813,13 +826,13 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) /* Force to external trigger 0. */ if ((cmd->start_arg & ~CR_FLAGS_MASK) != 0) { cmd->start_arg = COMBINE(cmd->start_arg, 0, - ~CR_FLAGS_MASK); + ~CR_FLAGS_MASK); err++; } /* The only flag allowed is CR_EDGE, which is ignored. */ if ((cmd->start_arg & CR_FLAGS_MASK & ~CR_EDGE) != 0) { cmd->start_arg = COMBINE(cmd->start_arg, 0, - CR_FLAGS_MASK & ~CR_EDGE); + CR_FLAGS_MASK & ~CR_EDGE); } break; } @@ -843,14 +856,14 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) /* Force to external trigger 0. */ if ((cmd->scan_begin_arg & ~CR_FLAGS_MASK) != 0) { cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0, - ~CR_FLAGS_MASK); + ~CR_FLAGS_MASK); err++; } /* Only allow flags CR_EDGE and CR_INVERT. Ignore CR_EDGE. */ if ((cmd->scan_begin_arg & CR_FLAGS_MASK & - ~(CR_EDGE | CR_INVERT)) != 0) { + ~(CR_EDGE | CR_INVERT)) != 0) { cmd->scan_begin_arg = COMBINE(cmd->scan_begin_arg, 0, - CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT)); + CR_FLAGS_MASK & ~(CR_EDGE | CR_INVERT)); } break; } @@ -875,13 +888,13 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) /* Force to external trigger 0. */ if ((cmd->stop_arg & ~CR_FLAGS_MASK) != 0) { cmd->stop_arg = COMBINE(cmd->stop_arg, 0, - ~CR_FLAGS_MASK); + ~CR_FLAGS_MASK); err++; } /* The only flag allowed is CR_EDGE, which is ignored. */ if ((cmd->stop_arg & CR_FLAGS_MASK & ~CR_EDGE) != 0) { cmd->stop_arg = COMBINE(cmd->stop_arg, 0, - CR_FLAGS_MASK & ~CR_EDGE); + CR_FLAGS_MASK & ~CR_EDGE); } break; case TRIG_NONE: @@ -892,7 +905,8 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) break; } - if (err) return 3; + if (err) + return 3; /* Step 4: fix up any arguments. */ @@ -920,10 +934,11 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) TIMEBASE_10MHZ; if (div2 <= 0x10000) { /* A single timer will suffice. */ - if (div2 < 2) div2 = 2; + if (div2 < 2) + div2 = 2; cmd->scan_begin_arg = div2 * TIMEBASE_10MHZ; if (cmd->scan_begin_arg < div2 || - cmd->scan_begin_arg < TIMEBASE_10MHZ) { + cmd->scan_begin_arg < TIMEBASE_10MHZ) { /* Overflow! */ cmd->scan_begin_arg = MAX_SCAN_PERIOD; } @@ -932,7 +947,7 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) div1 = devpriv->cached_div1; div2 = devpriv->cached_div2; pci224_cascade_ns_to_timer(TIMEBASE_10MHZ, &div1, &div2, - &cmd->scan_begin_arg, round_mode); + &cmd->scan_begin_arg, round_mode); devpriv->cached_div1 = div1; devpriv->cached_div2 = div2; } @@ -941,7 +956,8 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) } } - if (err) return 4; + if (err) + return 4; /* Step 5: check channel list. */ @@ -974,13 +990,11 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) if (errors) { if (errors & dupchan_err) { comedi_error(dev, "entries in chanlist must " - "contain no duplicate " - "channels\n"); + "contain no duplicate " "channels\n"); } if (errors & range_err) { comedi_error(dev, "entries in chanlist must " - "all have the same range " - "index\n"); + "all have the same range " "index\n"); } err++; } @@ -989,7 +1003,8 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) err++; } - if (err) return 5; + if (err) + return 5; return 0; } @@ -997,8 +1012,7 @@ pci224_ao_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) /* * 'do_cmd' function for AO subdevice. */ -static int -pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) +static int pci224_ao_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; int range; @@ -1044,12 +1058,12 @@ pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) * N.B. DAC FIFO interrupts are currently disabled. */ devpriv->daccon = COMBINE(devpriv->daccon, - (devpriv->hwrange[range] | PCI224_DACCON_TRIG_NONE | - PCI224_DACCON_FIFOINTR_NHALF), - (PCI224_DACCON_POLAR_MASK | PCI224_DACCON_VREF_MASK | - PCI224_DACCON_TRIG_MASK | PCI224_DACCON_FIFOINTR_MASK)); + (devpriv->hwrange[range] | PCI224_DACCON_TRIG_NONE | + PCI224_DACCON_FIFOINTR_NHALF), + (PCI224_DACCON_POLAR_MASK | PCI224_DACCON_VREF_MASK | + PCI224_DACCON_TRIG_MASK | PCI224_DACCON_FIFOINTR_MASK)); outw(devpriv->daccon | PCI224_DACCON_FIFORESET, - dev->iobase + PCI224_DACCON); + dev->iobase + PCI224_DACCON); if (cmd->scan_begin_src == TRIG_TIMER) { unsigned int div1, div2, round; @@ -1075,7 +1089,8 @@ pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) TIMEBASE_10MHZ; if (div2 <= 0x10000) { /* A single timer will suffice. */ - if (div2 < 2) div2 = 2; + if (div2 < 2) + div2 = 2; div2 &= 0xffff; div1 = 1; /* Flag that single timer to be used. */ } else { @@ -1083,7 +1098,7 @@ pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) div1 = devpriv->cached_div1; div2 = devpriv->cached_div2; pci224_cascade_ns_to_timer(TIMEBASE_10MHZ, &div1, &div2, - &ns, round_mode); + &ns, round_mode); } /* @@ -1092,25 +1107,25 @@ pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) */ /* Make sure Z2-0 is gated on. */ outb(GAT_CONFIG(0, GAT_VCC), - devpriv->iobase1 + PCI224_ZGAT_SCE); + devpriv->iobase1 + PCI224_ZGAT_SCE); if (div1 == 1) { /* Not cascading. Z2-0 needs 10 MHz clock. */ outb(CLK_CONFIG(0, CLK_10MHZ), - devpriv->iobase1 + PCI224_ZCLK_SCE); + devpriv->iobase1 + PCI224_ZCLK_SCE); } else { /* Cascading with Z2-2. */ /* Make sure Z2-2 is gated on. */ outb(GAT_CONFIG(2, GAT_VCC), - devpriv->iobase1 + PCI224_ZGAT_SCE); + devpriv->iobase1 + PCI224_ZGAT_SCE); /* Z2-2 needs 10 MHz clock. */ outb(CLK_CONFIG(2, CLK_10MHZ), - devpriv->iobase1 + PCI224_ZCLK_SCE); + devpriv->iobase1 + PCI224_ZCLK_SCE); /* Load Z2-2 mode (2) and counter (div1). */ i8254_load(devpriv->iobase1 + PCI224_Z2_CT0, 0, - 2, div1, 2); + 2, div1, 2); /* Z2-0 is clocked from Z2-2's output. */ outb(CLK_CONFIG(0, CLK_OUTNM1), - devpriv->iobase1 + PCI224_ZCLK_SCE); + devpriv->iobase1 + PCI224_ZCLK_SCE); } /* Load Z2-0 mode (2) and counter (div2). */ i8254_load(devpriv->iobase1 + PCI224_Z2_CT0, 0, 0, div2, 2); @@ -1156,8 +1171,7 @@ pci224_ao_cmd(comedi_device *dev, comedi_subdevice *s) /* * 'cancel' function for AO subdevice. */ -static int -pci224_ao_cancel(comedi_device *dev, comedi_subdevice *s) +static int pci224_ao_cancel(comedi_device * dev, comedi_subdevice * s) { if (devpriv->ao_cmd_running) { pci224_ao_stop(dev, s); @@ -1169,8 +1183,8 @@ pci224_ao_cancel(comedi_device *dev, comedi_subdevice *s) * 'munge' data for AO command. */ static void -pci224_ao_munge(comedi_device *dev, comedi_subdevice *s, void *data, - unsigned int num_bytes, unsigned int chan_index) +pci224_ao_munge(comedi_device * dev, comedi_subdevice * s, void *data, + unsigned int num_bytes, unsigned int chan_index) { comedi_async *async = s->async; sampl_t *array = data; @@ -1183,8 +1197,7 @@ pci224_ao_munge(comedi_device *dev, comedi_subdevice *s, void *data, shift = 16 - thisboard->ao_bits; /* Channels will be all bipolar or all unipolar. */ if ((devpriv->hwrange[CR_RANGE(async->cmd.chanlist[0])] & - PCI224_DACCON_POLAR_MASK) == - PCI224_DACCON_POLAR_UNI) { + PCI224_DACCON_POLAR_MASK) == PCI224_DACCON_POLAR_UNI) { /* Unipolar */ offset = 0; } else { @@ -1200,8 +1213,7 @@ pci224_ao_munge(comedi_device *dev, comedi_subdevice *s, void *data, /* * Interrupt handler. */ -static irqreturn_t -pci224_interrupt(int irq, void *d PT_REGS_ARG) +static irqreturn_t pci224_interrupt(int irq, void *d PT_REGS_ARG) { comedi_device *dev = d; comedi_subdevice *s = &dev->subdevices[0]; @@ -1239,7 +1251,8 @@ pci224_interrupt(int irq, void *d PT_REGS_ARG) /* Reenable interrupt sources. */ comedi_spin_lock_irqsave(&devpriv->ao_spinlock, flags); if (curenab != devpriv->intsce) { - outb(devpriv->intsce, devpriv->iobase1 + PCI224_INT_SCE); + outb(devpriv->intsce, + devpriv->iobase1 + PCI224_INT_SCE); } devpriv->intr_running = 0; comedi_spin_unlock_irqrestore(&devpriv->ao_spinlock, flags); @@ -1252,8 +1265,8 @@ pci224_interrupt(int irq, void *d PT_REGS_ARG) * bus and slot. */ static int -pci224_find_pci(comedi_device *dev, int bus, int slot, - struct pci_dev **pci_dev_p) +pci224_find_pci(comedi_device * dev, int bus, int slot, + struct pci_dev **pci_dev_p) { struct pci_dev *pci_dev = NULL; struct pci_device_id *pci_id; @@ -1267,20 +1280,20 @@ pci224_find_pci(comedi_device *dev, int bus, int slot, } if (pci_id->vendor == 0) { printk(KERN_ERR "comedi%d: %s: BUG! " - "cannot determine board type!\n", - dev->minor, DRIVER_NAME); + "cannot determine board type!\n", + dev->minor, DRIVER_NAME); return -EINVAL; } /* Look for matching PCI device. */ - for(pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); - pci_dev != NULL ; - pci_dev = pci_get_device(pci_id->vendor, - pci_id->device, pci_dev)) { + for (pci_dev = pci_get_device(pci_id->vendor, pci_id->device, NULL); + pci_dev != NULL; + pci_dev = pci_get_device(pci_id->vendor, + pci_id->device, pci_dev)) { /* If bus/slot specified, check them. */ if (bus || slot) { if (bus != pci_dev->bus->number - || slot != PCI_SLOT(pci_dev->devfn)) + || slot != PCI_SLOT(pci_dev->devfn)) continue; } #if 0 @@ -1293,7 +1306,8 @@ pci224_find_pci(comedi_device *dev, int bus, int slot, continue; } #endif - if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != 0) + if (((pci_dev->class ^ pci_id->class) & pci_id->class_mask) != + 0) continue; /* Found a match. */ @@ -1303,12 +1317,11 @@ pci224_find_pci(comedi_device *dev, int bus, int slot, /* No match found. */ if (bus || slot) { printk(KERN_ERR "comedi%d: error! " - "no %s found at pci %02x:%02x!\n", - dev->minor, thisboard->name, - bus, slot); + "no %s found at pci %02x:%02x!\n", + dev->minor, thisboard->name, bus, slot); } else { printk(KERN_ERR "comedi%d: error! no %s found!\n", - dev->minor, thisboard->name); + dev->minor, thisboard->name); } return -EIO; } @@ -1319,8 +1332,7 @@ pci224_find_pci(comedi_device *dev, int bus, int slot, * in the driver structure, dev->board_ptr contains that * address. */ -static int -pci224_attach(comedi_device *dev,comedi_devconfig *it) +static int pci224_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; struct pci_dev *pci_dev; @@ -1329,23 +1341,23 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it) unsigned n; int ret; - printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, - DRIVER_NAME); + printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, DRIVER_NAME); bus = it->options[0]; slot = it->options[1]; - if ((ret=alloc_private(dev,sizeof(pci224_private))) < 0) { + if ((ret = alloc_private(dev, sizeof(pci224_private))) < 0) { printk(KERN_ERR "comedi%d: error! out of memory!\n", - dev->minor); + dev->minor); return ret; } - if ((ret=pci224_find_pci(dev, bus, slot, &pci_dev)) < 0) + if ((ret = pci224_find_pci(dev, bus, slot, &pci_dev)) < 0) return ret; devpriv->pci_dev = pci_dev; - if ((ret=comedi_pci_enable(pci_dev, DRIVER_NAME)) < 0) { - printk(KERN_ERR "comedi%d: error! cannot enable PCI device and request regions!\n", - dev->minor); + if ((ret = comedi_pci_enable(pci_dev, DRIVER_NAME)) < 0) { + printk(KERN_ERR + "comedi%d: error! cannot enable PCI device and request regions!\n", + dev->minor); return ret; } spin_lock_init(&devpriv->ao_spinlock); @@ -1356,21 +1368,21 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it) /* Allocate readback buffer for AO channels. */ devpriv->ao_readback = kmalloc(sizeof(devpriv->ao_readback[0]) * - thisboard->ao_chans, GFP_KERNEL); + thisboard->ao_chans, GFP_KERNEL); if (!devpriv->ao_readback) { return -ENOMEM; } /* Allocate buffer to hold values for AO channel scan. */ devpriv->ao_scan_vals = kmalloc(sizeof(devpriv->ao_scan_vals[0]) * - thisboard->ao_chans, GFP_KERNEL); + thisboard->ao_chans, GFP_KERNEL); if (!devpriv->ao_scan_vals) { return -ENOMEM; } /* Allocate buffer to hold AO channel scan order. */ devpriv->ao_scan_order = kmalloc(sizeof(devpriv->ao_scan_order[0]) * - thisboard->ao_chans, GFP_KERNEL); + thisboard->ao_chans, GFP_KERNEL); if (!devpriv->ao_scan_order) { return -ENOMEM; } @@ -1384,14 +1396,14 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it) outw(0, dev->iobase + PCI224_DACCEN); outw(0, dev->iobase + PCI224_FIFOSIZ); devpriv->daccon = (PCI224_DACCON_TRIG_SW | PCI224_DACCON_POLAR_BI | - PCI224_DACCON_FIFOENAB | PCI224_DACCON_FIFOINTR_EMPTY); + PCI224_DACCON_FIFOENAB | PCI224_DACCON_FIFOINTR_EMPTY); outw(devpriv->daccon | PCI224_DACCON_FIFORESET, - dev->iobase + PCI224_DACCON); + dev->iobase + PCI224_DACCON); /* Allocate subdevices. There is only one! */ - if ((ret=alloc_subdevices(dev, 1)) < 0) { + if ((ret = alloc_subdevices(dev, 1)) < 0) { printk(KERN_ERR "comedi%d: error! out of memory!\n", - dev->minor); + dev->minor); return ret; } @@ -1411,72 +1423,68 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it) s->cancel = &pci224_ao_cancel; s->munge = &pci224_ao_munge; - /* Sort out channel range options. */ - if (thisboard->model == pci234_model) { - /* PCI234 range options. */ + /* Sort out channel range options. */ + if (thisboard->model == pci234_model) { + /* PCI234 range options. */ const comedi_lrange **range_table_list; - s->range_table_list = range_table_list = kmalloc( - sizeof(comedi_lrange *) * s->n_chan, - GFP_KERNEL); - if (!s->range_table_list) { - return -ENOMEM; - } + s->range_table_list = range_table_list = + kmalloc(sizeof(comedi_lrange *) * s->n_chan, + GFP_KERNEL); + if (!s->range_table_list) { + return -ENOMEM; + } for (n = 2; n < 3 + s->n_chan; n++) { if (it->options[n] < 0 || it->options[n] > 1) { printk(KERN_WARNING "comedi%d: %s: warning! " - "bad options[%u]=%d\n", - dev->minor, DRIVER_NAME, n, - it->options[n]); + "bad options[%u]=%d\n", + dev->minor, DRIVER_NAME, n, + it->options[n]); + } + } + for (n = 0; n < s->n_chan; n++) { + if (n < COMEDI_NDEVCONFOPTS - 3 && + it->options[3 + n] == 1) { + if (it->options[2] == 1) { + range_table_list[n] = &range_pci234_ext; + } else { + range_table_list[n] = &range_bipolar5; + } + } else { + if (it->options[2] == 1) { + range_table_list[n] = + &range_pci234_ext2; + } else { + range_table_list[n] = &range_bipolar10; + } } } - for (n = 0; n < s->n_chan; n++) { - if (n < COMEDI_NDEVCONFOPTS - 3 && - it->options[3+n] == 1) { - if (it->options[2] == 1) { - range_table_list[n] = - &range_pci234_ext; - } else { - range_table_list[n] = - &range_bipolar5; - } - } else { - if (it->options[2] == 1) { - range_table_list[n] = - &range_pci234_ext2; - } else { - range_table_list[n] = - &range_bipolar10; - } - } - } - devpriv->hwrange = hwrange_pci234; - } else { - /* PCI224 range options. */ - if (it->options[2] == 1) { - s->range_table = &range_pci224_external; - devpriv->hwrange = hwrange_pci224_external; - } else { + devpriv->hwrange = hwrange_pci234; + } else { + /* PCI224 range options. */ + if (it->options[2] == 1) { + s->range_table = &range_pci224_external; + devpriv->hwrange = hwrange_pci224_external; + } else { if (it->options[2] != 0) { printk(KERN_WARNING "comedi%d: %s: warning! " - "bad options[2]=%d\n", - dev->minor, DRIVER_NAME, - it->options[2]); + "bad options[2]=%d\n", + dev->minor, DRIVER_NAME, + it->options[2]); } - s->range_table = &range_pci224_internal; - devpriv->hwrange = hwrange_pci224_internal; - } - } + s->range_table = &range_pci224_internal; + devpriv->hwrange = hwrange_pci224_internal; + } + } dev->board_name = thisboard->name; if (irq) { ret = comedi_request_irq(irq, pci224_interrupt, IRQF_SHARED, - DRIVER_NAME, dev); + DRIVER_NAME, dev); if (ret < 0) { printk(KERN_ERR "comedi%d: error! " - "unable to allocate irq %u\n", - dev->minor, irq); + "unable to allocate irq %u\n", dev->minor, irq); return ret; } else { dev->irq = irq; @@ -1504,23 +1512,22 @@ pci224_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int -pci224_detach(comedi_device *dev) +static int pci224_detach(comedi_device * dev) { printk(KERN_DEBUG "comedi%d: %s: detach\n", dev->minor, DRIVER_NAME); if (dev->irq) { comedi_free_irq(dev->irq, dev); } - if (dev->subdevices) { - comedi_subdevice *s; - - s = dev->subdevices + 0; - /* AO subdevice */ - if (s->range_table_list) { - kfree(s->range_table_list); - } - } + if (dev->subdevices) { + comedi_subdevice *s; + + s = dev->subdevices + 0; + /* AO subdevice */ + if (s->range_table_list) { + kfree(s->range_table_list); + } + } if (devpriv) { if (devpriv->ao_readback) { kfree(devpriv->ao_readback); @@ -1532,8 +1539,7 @@ pci224_detach(comedi_device *dev) kfree(devpriv->ao_scan_order); } if (devpriv->pci_dev) { - if(dev->iobase) - { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -1541,9 +1547,8 @@ pci224_detach(comedi_device *dev) } if (dev->board_name) { printk(KERN_INFO "comedi%d: %s removed\n", - dev->minor, dev->board_name); + dev->minor, dev->board_name); } return 0; } - diff --git a/comedi/drivers/amplc_pci230.c b/comedi/drivers/amplc_pci230.c index 2ca26dd0..9bc860ae 100644 --- a/comedi/drivers/amplc_pci230.c +++ b/comedi/drivers/amplc_pci230.c @@ -20,7 +20,7 @@ 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: amplc_pci230 Description: Amplicom PCI230, PCI260 Multifunction I/O boards @@ -47,28 +47,27 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples #include "8253.h" #include "8255.h" - /* PCI230 PCI configuration register information */ #define PCI_VENDOR_ID_AMPLICON 0x14dc #define PCI_DEVICE_ID_PCI230 0x0000 #define PCI_DEVICE_ID_PCI260 0x0006 #define PCI_DEVICE_ID_INVALID 0xffff -#define PCI230_IO1_SIZE 32 /* Size of I/O space 1 */ -#define PCI230_IO2_SIZE 16 /* Size of I/O space 2 */ +#define PCI230_IO1_SIZE 32 /* Size of I/O space 1 */ +#define PCI230_IO2_SIZE 16 /* Size of I/O space 2 */ /* PCI230 i/o space 1 registers. */ -#define PCI230_PPI_X_A 0x00 /* User PPI port A */ -#define PCI230_PPI_X_B 0x01 /* User PPI port B */ -#define PCI230_PPI_X_C 0x02 /* User PPI port C */ -#define PCI230_PPI_X_CMD 0x03 /* User PPI control word */ -#define PCI230_Z2_CT0 0x14 /* 82C54 counter/timer 0 */ -#define PCI230_Z2_CT1 0x15 /* 82C54 counter/timer 1 */ -#define PCI230_Z2_CT2 0x16 /* 82C54 counter/timer 2 */ -#define PCI230_Z2_CTC 0x17 /* 82C54 counter/timer control word */ -#define PCI230_ZCLK_SCE 0x1A /* Group Z Clock Configuration Register */ -#define PCI230_ZGAT_SCE 0x1D /* Group Z Gate Configuration Register */ -#define PCI230_INT_SCE 0x1E /* ISR Interrupt source mask register/Interrupt status */ +#define PCI230_PPI_X_A 0x00 /* User PPI port A */ +#define PCI230_PPI_X_B 0x01 /* User PPI port B */ +#define PCI230_PPI_X_C 0x02 /* User PPI port C */ +#define PCI230_PPI_X_CMD 0x03 /* User PPI control word */ +#define PCI230_Z2_CT0 0x14 /* 82C54 counter/timer 0 */ +#define PCI230_Z2_CT1 0x15 /* 82C54 counter/timer 1 */ +#define PCI230_Z2_CT2 0x16 /* 82C54 counter/timer 2 */ +#define PCI230_Z2_CTC 0x17 /* 82C54 counter/timer control word */ +#define PCI230_ZCLK_SCE 0x1A /* Group Z Clock Configuration Register */ +#define PCI230_ZGAT_SCE 0x1D /* Group Z Gate Configuration Register */ +#define PCI230_INT_SCE 0x1E /* ISR Interrupt source mask register/Interrupt status */ /* PCI230 i/o space 2 registers. */ #define PCI230_DACCON 0x00 @@ -90,8 +89,8 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples #define PCI230P_HWVER 0x1E /* Hardware version (r) */ /* Convertor related constants. */ -#define PCI230_DAC_SETTLE 5 /* Analogue output settling time in µs (DAC itself is 1µs nominally). */ -#define PCI230_ADC_SETTLE 1 /* Analogue input settling time in µs (ADC itself is 1.6µs nominally but we poll anyway). */ +#define PCI230_DAC_SETTLE 5 /* Analogue output settling time in µs (DAC itself is 1µs nominally). */ +#define PCI230_ADC_SETTLE 1 /* Analogue input settling time in µs (ADC itself is 1.6µs nominally but we poll anyway). */ #define PCI230_MUX_SETTLE 10 /* ADC MUX settling time in µS - 10µs for se, 20µs de. */ /* DACCON values. */ @@ -119,7 +118,7 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples #define PCI230_ADC_INT_FIFO_FULL (5<<9) #define PCI230_ADC_FIFO_RESET (1<<12) #define PCI230_ADC_GLOB_RESET (1<<13) -#define PCI230_ADC_CONV 0xffff /* Value to write to ADCDATA to trigger ADC conversion in sotware trigger mode */ +#define PCI230_ADC_CONV 0xffff /* Value to write to ADCDATA to trigger ADC conversion in sotware trigger mode */ /* ADCCON read values. */ #define PCI230_ADC_BUSY_BIT 15 @@ -135,32 +134,30 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples #define PCI230_ZCLK_CT1 8 #define PCI230_ZCLK_CT2 16 #define PCI230_ZCLK_RES 24 -#define PCI230_ZCLK_SRC_PPCN 0 /* The counter/timer's CLK input from the SK1 connector. */ -#define PCI230_ZCLK_SRC_10MHZ 1 /* The internal 10MHz clock. */ -#define PCI230_ZCLK_SRC_1MHZ 2 /* The internal 1MHz clock. */ -#define PCI230_ZCLK_SRC_100KHZ 3 /* The internal 100kHz clock. */ -#define PCI230_ZCLK_SRC_10KHZ 4 /* The internal 10kHz clock. */ -#define PCI230_ZCLK_SRC_1KHZ 5 /* The internal 1kHz clock. */ -#define PCI230_ZCLK_SRC_OUTNM1 6 /* The output of the preceding counter/timer channel (OUT n-1). */ -#define PCI230_ZCLK_SRC_EXTCLK 7 /* The dedicated external clock input for the group (X1/X2, Y1/Y2, Z1/Z2). */ +#define PCI230_ZCLK_SRC_PPCN 0 /* The counter/timer's CLK input from the SK1 connector. */ +#define PCI230_ZCLK_SRC_10MHZ 1 /* The internal 10MHz clock. */ +#define PCI230_ZCLK_SRC_1MHZ 2 /* The internal 1MHz clock. */ +#define PCI230_ZCLK_SRC_100KHZ 3 /* The internal 100kHz clock. */ +#define PCI230_ZCLK_SRC_10KHZ 4 /* The internal 10kHz clock. */ +#define PCI230_ZCLK_SRC_1KHZ 5 /* The internal 1kHz clock. */ +#define PCI230_ZCLK_SRC_OUTNM1 6 /* The output of the preceding counter/timer channel (OUT n-1). */ +#define PCI230_ZCLK_SRC_EXTCLK 7 /* The dedicated external clock input for the group (X1/X2, Y1/Y2, Z1/Z2). */ /* Group Z gate configuration register values. */ #define PCI230_ZGAT_CT0 0 #define PCI230_ZGAT_CT1 8 #define PCI230_ZGAT_CT2 16 #define PCI230_ZGAT_RES 24 -#define PCI230_ZGAT_SRC_VCC 0 /* The counter/timer's GAT input is VCC (ie enabled) */ -#define PCI230_ZGAT_SRC_GND 1 /* GAT input is GND (ie disabled) */ -#define PCI230_ZGAT_SRC_PPCN 2 /* GAT input is DIO port Cn, where n is the number of the counter/timer */ -#define PCI230_ZGAT_SRC_OUTNP1 3 /* GAT input is the output of the next counter/timer channel (OUT n+1) */ - - -#define PCI230_TIMEBASE_10MHZ 100 /* 10MHz => 100ns. */ -#define PCI230_TIMEBASE_1MHZ 1000 /* 1MHz => 1000ns. */ -#define PCI230_TIMEBASE_100KHZ 10000 /* 100kHz => 10000ns. */ -#define PCI230_TIMEBASE_10KHZ 100000 /* 10kHz => 100000ns. */ -#define PCI230_TIMEBASE_1KHZ 1000000 /* 1kHz => 1000000ns. */ +#define PCI230_ZGAT_SRC_VCC 0 /* The counter/timer's GAT input is VCC (ie enabled) */ +#define PCI230_ZGAT_SRC_GND 1 /* GAT input is GND (ie disabled) */ +#define PCI230_ZGAT_SRC_PPCN 2 /* GAT input is DIO port Cn, where n is the number of the counter/timer */ +#define PCI230_ZGAT_SRC_OUTNP1 3 /* GAT input is the output of the next counter/timer channel (OUT n+1) */ +#define PCI230_TIMEBASE_10MHZ 100 /* 10MHz => 100ns. */ +#define PCI230_TIMEBASE_1MHZ 1000 /* 1MHz => 1000ns. */ +#define PCI230_TIMEBASE_100KHZ 10000 /* 100kHz => 10000ns. */ +#define PCI230_TIMEBASE_10KHZ 100000 /* 10kHz => 100000ns. */ +#define PCI230_TIMEBASE_1KHZ 1000000 /* 1kHz => 1000000ns. */ /* Interrupt enables/status register values. */ #define PCI230_INT_DISABLE 0 @@ -175,7 +172,7 @@ extra triggered scan functionality, interrupt bug-fix added by Steve Sharples * Board descriptions for the two boards supported. */ -typedef struct pci230_board_struct{ +typedef struct pci230_board_struct { const char *name; unsigned short id; int ai_chans; @@ -184,61 +181,64 @@ typedef struct pci230_board_struct{ int ao_bits; int have_dio; unsigned int min_hwver; /* Minimum hardware version supported. */ -}pci230_board; +} pci230_board; static const pci230_board pci230_boards[] = { { - name: "pci230", - id: PCI_DEVICE_ID_PCI230, - ai_chans: 16, - ai_bits: 12, - ao_chans: 2, - ao_bits: 12, - have_dio: 1, - }, + name: "pci230", + id: PCI_DEVICE_ID_PCI230, + ai_chans:16, + ai_bits: 12, + ao_chans:2, + ao_bits: 12, + have_dio:1, + }, { - name: "pci260", - id: PCI_DEVICE_ID_PCI260, - ai_chans: 16, - ai_bits: 12, - ao_chans: 0, - ao_bits: 0, - have_dio: 0, - }, + name: "pci260", + id: PCI_DEVICE_ID_PCI260, + ai_chans:16, + ai_bits: 12, + ao_chans:0, + ao_bits: 0, + have_dio:0, + }, { - name: "amplc_pci230", /* Legacy name matches any above */ - id: PCI_DEVICE_ID_INVALID, - }, + name: "amplc_pci230", /* Legacy name matches any above */ + id: PCI_DEVICE_ID_INVALID, + }, /* * The '+' versions of the above models have the same PCI device ID. * They are backwards compatible with the above models. */ { - name: "pci230+", - id: PCI_DEVICE_ID_PCI230, - ai_chans: 16, - ai_bits: 16, - ao_chans: 2, - ao_bits: 12, - have_dio: 1, - min_hwver: 1, - }, + name: "pci230+", + id: PCI_DEVICE_ID_PCI230, + ai_chans:16, + ai_bits: 16, + ao_chans:2, + ao_bits: 12, + have_dio:1, + min_hwver:1, + }, { - name: "pci260+", - id: PCI_DEVICE_ID_PCI260, - ai_chans: 16, - ai_bits: 16, - ao_chans: 0, - ao_bits: 0, - have_dio: 0, - min_hwver: 1, - }, + name: "pci260+", + id: PCI_DEVICE_ID_PCI260, + ai_chans:16, + ai_bits: 16, + ao_chans:0, + ao_bits: 0, + have_dio:0, + min_hwver:1, + }, }; static struct pci_device_id pci230_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230, PCI_ANY_ID, PCI_ANY_ID, + 0, 0, 0}, + {PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260, PCI_ANY_ID, PCI_ANY_ID, + 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pci230_pci_table); /* * Useful for shorthand access to the particular board structure @@ -249,46 +249,48 @@ MODULE_DEVICE_TABLE(pci, pci230_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -struct pci230_private{ +struct pci230_private { struct pci_dev *pci_dev; - lsampl_t ao_readback[2]; /* Used for AO readback */ + lsampl_t ao_readback[2]; /* Used for AO readback */ unsigned long pci_iobase; /* PCI230's I/O space 1 */ /* Divisors for 8254 counter/timer. */ - unsigned int clk_src0; /* which clock to use for the counter/timers: 10MHz, 1MHz, 100kHz etc */ + unsigned int clk_src0; /* which clock to use for the counter/timers: 10MHz, 1MHz, 100kHz etc */ unsigned int clk_src1; unsigned int clk_src2; unsigned int divisor0; unsigned int divisor1; unsigned int divisor2; - unsigned int int_en; /* Interrupt enables bits. */ - unsigned int ai_count; /* Number of analogue input samples remaining. */ - unsigned int ao_count; /* Number of analogue output samples remaining. */ - unsigned int ai_stop; /* Flag set when cmd->stop_src == TRIG_NONE - user chooses to stop continuous conversion by cancelation. */ - unsigned int ao_stop; /* Flag set when cmd->stop_src == TRIG_NONE - user chooses to stop continuous conversion by cancelation. */ + unsigned int int_en; /* Interrupt enables bits. */ + unsigned int ai_count; /* Number of analogue input samples remaining. */ + unsigned int ao_count; /* Number of analogue output samples remaining. */ + unsigned int ai_stop; /* Flag set when cmd->stop_src == TRIG_NONE - user chooses to stop continuous conversion by cancelation. */ + unsigned int ao_stop; /* Flag set when cmd->stop_src == TRIG_NONE - user chooses to stop continuous conversion by cancelation. */ unsigned int ai_bipolar; /* Set if bipolar input range so we know to mangle it. */ unsigned int ao_bipolar; /* Set if bipolar output range so we know to mangle it. */ - unsigned int ier; /* Copy of interrupt enables/status register. */ - unsigned int hwver; /* Hardware version (for '+' models). */ + unsigned int ier; /* Copy of interrupt enables/status register. */ + unsigned int hwver; /* Hardware version (for '+' models). */ }; #define devpriv ((struct pci230_private *)dev->private) /* PCI230 analogue input range table */ static const comedi_lrange pci230_ai_range = { 7, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5) -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5) + } +}; /* PCI230 analogue output range table */ static const comedi_lrange pci230_ao_range = { 2, { - UNI_RANGE(10), - BIP_RANGE(10) -}}; + UNI_RANGE(10), + BIP_RANGE(10) + } +}; /* * The comedi_driver structure tells the Comedi core module @@ -296,53 +298,65 @@ static const comedi_lrange pci230_ao_range = { 2, { * the board, and also about the kernel module that contains * the device code. */ -static int pci230_attach(comedi_device *dev,comedi_devconfig *it); -static int pci230_detach(comedi_device *dev); -static comedi_driver driver_amplc_pci230={ - driver_name: "amplc_pci230", - module: THIS_MODULE, - attach: pci230_attach, - detach: pci230_detach, - board_name: &pci230_boards[0].name, - offset: sizeof(pci230_boards[0]), - num_names: sizeof(pci230_boards) / sizeof(pci230_boards[0]), +static int pci230_attach(comedi_device * dev, comedi_devconfig * it); +static int pci230_detach(comedi_device * dev); +static comedi_driver driver_amplc_pci230 = { + driver_name:"amplc_pci230", + module:THIS_MODULE, + attach:pci230_attach, + detach:pci230_detach, + board_name:&pci230_boards[0].name, + offset:sizeof(pci230_boards[0]), + num_names:sizeof(pci230_boards) / sizeof(pci230_boards[0]), }; + COMEDI_INITCLEANUP(driver_amplc_pci230); -static int pci230_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int pci230_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int pci230_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int pci230_ct_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int pci230_ct_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int pci230_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci230_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci230_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci230_ct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci230_ct_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); #if 0 -static void pci230_ns_to_timer(unsigned int *ns,int round); +static void pci230_ns_to_timer(unsigned int *ns, int round); #endif -static void pci230_ns_to_single_timer(unsigned int *ns,int round); -static void i8253_single_ns_to_timer(unsigned int i8253_osc_base, unsigned int *d, unsigned int *nanosec, int round_mode); -static void pci230_setup_monostable_ct0(comedi_device *dev, unsigned int ns, unsigned int n_chan); +static void pci230_ns_to_single_timer(unsigned int *ns, int round); +static void i8253_single_ns_to_timer(unsigned int i8253_osc_base, + unsigned int *d, unsigned int *nanosec, int round_mode); +static void pci230_setup_monostable_ct0(comedi_device * dev, unsigned int ns, + unsigned int n_chan); #if 0 -static void pci230_z2_ct0(comedi_device *dev, unsigned int *ns,int round); +static void pci230_z2_ct0(comedi_device * dev, unsigned int *ns, int round); #endif -static void pci230_z2_ct1(comedi_device *dev, unsigned int *ns,int round); -static void pci230_z2_ct2(comedi_device *dev, unsigned int *ns,int round); +static void pci230_z2_ct1(comedi_device * dev, unsigned int *ns, int round); +static void pci230_z2_ct2(comedi_device * dev, unsigned int *ns, int round); #if 0 -static void pci230_cancel_ct0(comedi_device *dev); +static void pci230_cancel_ct0(comedi_device * dev); #endif -static void pci230_cancel_ct1(comedi_device *dev); -static void pci230_cancel_ct2(comedi_device *dev); +static void pci230_cancel_ct1(comedi_device * dev); +static void pci230_cancel_ct2(comedi_device * dev); static irqreturn_t pci230_interrupt(int irq, void *d PT_REGS_ARG); -static int pci230_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); -static int pci230_ao_cmd(comedi_device *dev, comedi_subdevice *s); -static int pci230_ao_cancel(comedi_device *dev, comedi_subdevice *s); -static void pci230_handle_ao(comedi_device *dev, comedi_subdevice *s); -static int pci230_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); -static int pci230_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int pci230_ai_cancel(comedi_device *dev, comedi_subdevice *s); -static void pci230_handle_ai(comedi_device *dev, comedi_subdevice *s); -static void pci230_handle_fifo_half_full(comedi_device *dev, comedi_subdevice *s); -static void pci230_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice *s); - -static sampl_t pci230_ai_read(comedi_device *dev) +static int pci230_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int pci230_ao_cmd(comedi_device * dev, comedi_subdevice * s); +static int pci230_ao_cancel(comedi_device * dev, comedi_subdevice * s); +static void pci230_handle_ao(comedi_device * dev, comedi_subdevice * s); +static int pci230_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int pci230_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int pci230_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static void pci230_handle_ai(comedi_device * dev, comedi_subdevice * s); +static void pci230_handle_fifo_half_full(comedi_device * dev, + comedi_subdevice * s); +static void pci230_handle_fifo_not_empty(comedi_device * dev, + comedi_subdevice * s); + +static sampl_t pci230_ai_read(comedi_device * dev) { /* Read sample. */ sampl_t data = (sampl_t) inw(dev->iobase + PCI230_ADCDATA); @@ -353,16 +367,16 @@ static sampl_t pci230_ai_read(comedi_device *dev) /* If a bipolar range was specified, mangle it (twos complement->straight binary). */ if (devpriv->ai_bipolar) { - data ^= 1<<(thisboard->ai_bits-1); + data ^= 1 << (thisboard->ai_bits - 1); } return data; } -static void pci230_ao_write(comedi_device *dev, sampl_t data, int chan) +static void pci230_ao_write(comedi_device * dev, sampl_t data, int chan) { /* If a bipolar range was specified, mangle it (straight binary->twos complement). */ if (devpriv->ao_bipolar) { - data ^= 1<<(thisboard->ao_bits-1); + data ^= 1 << (thisboard->ao_bits - 1); } /* PCI230 is 12 bit - stored in upper bits of 16 bit register (lower four bits reserved for expansion). */ @@ -370,7 +384,9 @@ static void pci230_ao_write(comedi_device *dev, sampl_t data, int chan) data = data << (16 - thisboard->ao_bits); /* Write data. */ - outw((unsigned int) data, dev->iobase + (((chan) == 0) ? PCI230_DACOUT1 : PCI230_DACOUT2)); + outw((unsigned int)data, + dev->iobase + (((chan) == + 0) ? PCI230_DACOUT1 : PCI230_DACOUT2)); } /* @@ -379,55 +395,57 @@ static void pci230_ao_write(comedi_device *dev, sampl_t data, int chan) * in the driver structure, dev->board_ptr contains that * address. */ -static int pci230_attach(comedi_device *dev,comedi_devconfig *it) +static int pci230_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - unsigned long pci_iobase, iobase; /* PCI230's I/O spaces 1 and 2 respectively. */ + unsigned long pci_iobase, iobase; /* PCI230's I/O spaces 1 and 2 respectively. */ struct pci_dev *pci_dev; - int i=0,irq_hdl,rc; + int i = 0, irq_hdl, rc; printk("comedi%d: amplc_pci230: attach %s %d,%d\n", dev->minor, - thisboard->name, it->options[0], it->options[1]); + thisboard->name, it->options[0], it->options[1]); /* Allocate the private structure area using alloc_private(). * Macro defined in comedidev.h - memsets struct fields to 0. */ - if((alloc_private(dev,sizeof(struct pci230_private)))<0){ + if ((alloc_private(dev, sizeof(struct pci230_private))) < 0) { return -ENOMEM; } /* Find card */ - for(pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_dev != NULL ; + for (pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_dev != NULL; pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) { - if(it->options[0] || it->options[1]){ + if (it->options[0] || it->options[1]) { /* Match against bus/slot options. */ - if(it->options[0] != pci_dev->bus->number || - it->options[1] != PCI_SLOT(pci_dev->devfn)) + if (it->options[0] != pci_dev->bus->number || + it->options[1] != PCI_SLOT(pci_dev->devfn)) continue; } - if(pci_dev->vendor != PCI_VENDOR_ID_AMPLICON) + if (pci_dev->vendor != PCI_VENDOR_ID_AMPLICON) continue; - if(thisboard->id == PCI_DEVICE_ID_INVALID){ + if (thisboard->id == PCI_DEVICE_ID_INVALID) { /* The name was specified as "amplc_pci230" which is * used to match any supported device. Replace the * current dev->board_ptr with one that matches the * PCI device ID. */ - for(i=0;idevice == pci230_boards[i].id){ + for (i = 0; i < n_pci230_boards; i++) { + if (pci_dev->device == pci230_boards[i].id) { /* Change board_ptr to matched board */ dev->board_ptr = &pci230_boards[i]; break; } } - if(iboard_ptr is correct. Check * whether it matches the PCI device ID. */ - if(thisboard->id == pci_dev->device){ + if (thisboard->id == pci_dev->device) { /* Check minimum hardware version. */ - if(thisboard->min_hwver > 0){ + if (thisboard->min_hwver > 0) { /* Looking for a '+' model. First * check length of registers. */ - if(pci_resource_len(pci_dev, 3) < 32){ + if (pci_resource_len(pci_dev, 3) < 32) { /* Not a '+' model. */ continue; } @@ -436,14 +454,15 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) * register. For now, assume it's * okay. */ break; - }else{ + } else { break; } } } } - if(!pci_dev){ - printk("comedi%d: No %s card found\n",dev->minor, thisboard->name); + if (!pci_dev) { + printk("comedi%d: No %s card found\n", dev->minor, + thisboard->name); return -EIO; } devpriv->pci_dev = pci_dev; @@ -454,8 +473,8 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = thisboard->name; /* Enable PCI device and reserve I/O spaces. */ - if(comedi_pci_enable(pci_dev, "amplc_pci230")<0){ - printk("comedi%d: failed to enable PCI device and request regions\n",dev->minor); + if (comedi_pci_enable(pci_dev, "amplc_pci230") < 0) { + printk("comedi%d: failed to enable PCI device and request regions\n", dev->minor); return -EIO; } @@ -464,25 +483,23 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) iobase = pci_resource_start(pci_dev, 3); printk("comedi%d: %s I/O region 1 0x%04lx I/O region 2 0x%04lx\n", - dev->minor, dev->board_name, pci_iobase, iobase); + dev->minor, dev->board_name, pci_iobase, iobase); devpriv->pci_iobase = pci_iobase; dev->iobase = iobase; /* Read hardware version register and set extended function register * if they exist. */ - if(pci_resource_len(pci_dev, 3) >= 32){ + if (pci_resource_len(pci_dev, 3) >= 32) { unsigned short extfunc = 0; devpriv->hwver = inw(dev->iobase + PCI230P_HWVER); - if(devpriv->hwver < thisboard->min_hwver){ - printk("comedi%d: %s - bad hardware version - got %u, need %u\n", - dev->minor, dev->board_name, - devpriv->hwver, thisboard->min_hwver); + if (devpriv->hwver < thisboard->min_hwver) { + printk("comedi%d: %s - bad hardware version - got %u, need %u\n", dev->minor, dev->board_name, devpriv->hwver, thisboard->min_hwver); return -EIO; } - if(devpriv->hwver > 0){ - if(!thisboard->have_dio){ + if (devpriv->hwver > 0) { + if (!thisboard->have_dio) { /* No DIO ports. Route counters' external gates * to the EXTTRIG signal (PCI260+ pin 17). * (Otherwise, they would be routed to DIO @@ -498,88 +515,91 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) outb(0, devpriv->pci_iobase + PCI230_INT_SCE); /* Register the interrupt handler. */ - irq_hdl = comedi_request_irq(devpriv->pci_dev->irq, pci230_interrupt, IRQF_SHARED, "amplc_pci230", dev); - if(irq_hdl<0) { + irq_hdl = + comedi_request_irq(devpriv->pci_dev->irq, pci230_interrupt, + IRQF_SHARED, "amplc_pci230", dev); + if (irq_hdl < 0) { printk("comedi%d: unable to register irq, commands will not be available %d\n", dev->minor, devpriv->pci_dev->irq); - } - else { + } else { dev->irq = devpriv->pci_dev->irq; - printk("comedi%d: registered irq %u\n", dev->minor, devpriv->pci_dev->irq); + printk("comedi%d: registered irq %u\n", dev->minor, + devpriv->pci_dev->irq); } /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_DIFF|SDF_GROUND; - s->n_chan=thisboard->ai_chans; - s->maxdata=(1<ai_bits)-1; - s->range_table=&pci230_ai_range; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_GROUND; + s->n_chan = thisboard->ai_chans; + s->maxdata = (1 << thisboard->ai_bits) - 1; + s->range_table = &pci230_ai_range; s->insn_read = &pci230_ai_rinsn; s->len_chanlist = thisboard->ai_chans; /* Only register commands if the interrupt handler is installed. */ - if(irq_hdl==0) { - dev->read_subdev=s; + if (irq_hdl == 0) { + dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; s->do_cmd = &pci230_ai_cmd; s->do_cmdtest = &pci230_ai_cmdtest; s->cancel = pci230_ai_cancel; } - s=dev->subdevices+1; + s = dev->subdevices + 1; /* analog output subdevice */ - if(thisboard->ao_chans > 0) { - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=thisboard->ao_chans;; - s->maxdata=(1<ao_bits)-1; - s->range_table=&pci230_ao_range; + if (thisboard->ao_chans > 0) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->ao_chans;; + s->maxdata = (1 << thisboard->ao_bits) - 1; + s->range_table = &pci230_ao_range; s->insn_write = &pci230_ao_winsn; s->insn_read = &pci230_ao_rinsn; s->len_chanlist = thisboard->ao_chans; /* Only register commands if the interrupt handler is installed. */ - if(irq_hdl==0) { - dev->write_subdev=s; + if (irq_hdl == 0) { + dev->write_subdev = s; s->subdev_flags |= SDF_CMD_WRITE; s->do_cmd = &pci230_ao_cmd; s->do_cmdtest = &pci230_ao_cmdtest; s->cancel = pci230_ao_cancel; } } else { - s->type=COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+2; + s = dev->subdevices + 2; /* digital i/o subdevice */ - if(thisboard->have_dio){ - rc = subdev_8255_init(dev,s,NULL,(devpriv->pci_iobase + PCI230_PPI_X_A)); - if(rc < 0) return rc; - }else{ + if (thisboard->have_dio) { + rc = subdev_8255_init(dev, s, NULL, + (devpriv->pci_iobase + PCI230_PPI_X_A)); + if (rc < 0) + return rc; + } else { s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+3; + s = dev->subdevices + 3; /* timer subdevice */ - s->type=COMEDI_SUBD_TIMER; - s->subdev_flags=SDF_READABLE; - s->n_chan=1; - s->maxdata=0xffff; - s->range_table=&range_digital; + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_READABLE; + s->n_chan = 1; + s->maxdata = 0xffff; + s->range_table = &range_digital; s->insn_config = pci230_ct_insn_config; s->insn_read = &pci230_ct_rinsn; - printk("comedi%d: attached\n",dev->minor); + printk("comedi%d: attached\n", dev->minor); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -588,20 +608,19 @@ static int pci230_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pci230_detach(comedi_device *dev) +static int pci230_detach(comedi_device * dev) { - printk("comedi%d: amplc_pci230: remove\n",dev->minor); + printk("comedi%d: amplc_pci230: remove\n", dev->minor); - if(dev->subdevices && thisboard->have_dio) - subdev_8255_cleanup(dev,dev->subdevices + 2); /* Clean up dio subdevice. */ + if (dev->subdevices && thisboard->have_dio) + subdev_8255_cleanup(dev, dev->subdevices + 2); /* Clean up dio subdevice. */ - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(devpriv){ - if(devpriv->pci_dev){ - if(dev->iobase) - { + if (devpriv) { + if (devpriv->pci_dev) { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -614,9 +633,10 @@ static int pci230_detach(comedi_device *dev) /* * COMEDI_SUBD_AI instruction; */ -static int pci230_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int pci230_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; int chan, range, aref; unsigned int status; unsigned int adccon, adcen, adcg; @@ -629,30 +649,28 @@ static int pci230_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *i /* If bit 2 of range unset, range is referring to bipolar element in range table */ adccon = PCI230_ADC_TRIG_SW | PCI230_ADC_FIFO_RESET; devpriv->ai_bipolar = !PCI230_TEST_BIT(range, 2); - if (aref==AREF_DIFF) { + if (aref == AREF_DIFF) { /* Differential. */ - adcen = 3<<2*chan; + adcen = 3 << 2 * chan; adccon |= PCI230_ADC_IM_DIF; if (devpriv->ai_bipolar) { adccon |= PCI230_ADC_IR_BIP; - adcg = range<<(2*chan-2*chan%2); - } - else { + adcg = range << (2 * chan - 2 * chan % 2); + } else { adccon |= PCI230_ADC_IR_UNI; - adcg = ((range&(~4))+1)<<(2*chan-2*chan%2); + adcg = ((range & (~4)) + 1) << (2 * chan - + 2 * chan % 2); } - } - else { + } else { /* Single ended. */ - adcen = 1<ai_bipolar) { adccon |= PCI230_ADC_IR_BIP; - adcg = range<<(chan-chan%2); - } - else { + adcg = range << (chan - chan % 2); + } else { adccon |= PCI230_ADC_IR_UNI; - adcg = ((range&(~4))+1)<<(chan-chan%2); + adcg = ((range & (~4)) + 1) << (chan - chan % 2); } } @@ -666,17 +684,18 @@ static int pci230_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *i outw_p(adccon, dev->iobase + PCI230_ADCCON); /* Convert n samples */ - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* trigger conversion */ - outw_p(PCI230_ADC_CONV,dev->iobase + PCI230_ADCDATA); + outw_p(PCI230_ADC_CONV, dev->iobase + PCI230_ADCDATA); #define TIMEOUT 100 /* wait for conversion to end */ - for(i=0;iiobase + PCI230_ADCCON); - if(!PCI230_TEST_BIT(status, PCI230_ADC_BUSY_BIT)) break; + if (!PCI230_TEST_BIT(status, PCI230_ADC_BUSY_BIT)) + break; } - if(i==TIMEOUT){ + if (i == TIMEOUT) { /* rt_printk() should be used instead of printk() * whenever the code can be called from real-time. */ rt_printk("timeout\n"); @@ -694,7 +713,8 @@ static int pci230_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *i /* * COMEDI_SUBD_AO instructions; */ -static int pci230_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int pci230_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan, range; @@ -709,7 +729,7 @@ static int pci230_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *i /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { /* Store the value to be written to the DAC in our pci230_private struct before mangling it. */ devpriv->ao_readback[chan] = data[i]; @@ -723,12 +743,13 @@ static int pci230_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *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 pci230_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int pci230_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -742,19 +763,19 @@ static int pci230_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *i * * rinsn returns counter/timer's actual period in ns. */ -static int pci230_ct_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pci230_ct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int ns; - if(insn->n!=1)return -EINVAL; + if (insn->n != 1) + return -EINVAL; ns = data[0]; if (ns == 0) { //Stop counter/timer 2. pci230_cancel_ct2(dev); - } - else { + } else { //Start conter/timer 2 with period ns. pci230_z2_ct2(dev, &ns, TRIG_ROUND_MASK); } @@ -762,19 +783,21 @@ static int pci230_ct_insn_config(comedi_device *dev,comedi_subdevice *s, return 1; } -static int pci230_ct_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int pci230_ct_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=1)return -EINVAL; + if (insn->n != 1) + return -EINVAL; /* Return the actual period set in ns. */ - data[0] = PCI230_TIMEBASE_10MHZ*devpriv->divisor1*devpriv->divisor2; + data[0] = PCI230_TIMEBASE_10MHZ * devpriv->divisor1 * devpriv->divisor2; return 1; } -static int pci230_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int pci230_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -788,117 +811,126 @@ static int pci230_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, * "invalid source" returned by comedilib to user mode process * if this fails. */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* Step 2: make sure trigger sources are unique and mutually compatible * "source conflict" returned by comedilib to user mode process * if this fails. */ - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* Step 3: make sure arguments are trivially compatible. * "invalid argument" returned by comedilib to user mode process * if this fails. */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SPEED 3200 /* 3200ns => 312.5kHz */ +#define MAX_SPEED 3200 /* 3200ns => 312.5kHz */ #define MIN_SPEED 4294967295u /* 4294967295ns = 4.29s - Comedi limit due to unsigned int cmd. Driver limit = 2^16 (16bit counter) * 1000000ns (1kHz onboard clock) = 65.536s */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } - if(cmd->scan_begin_arg>MIN_SPEED){ - cmd->scan_begin_arg=MIN_SPEED; + if (cmd->scan_begin_arg > MIN_SPEED) { + cmd->scan_begin_arg = MIN_SPEED; err++; } } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + if (cmd->scan_end_arg != cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src==TRIG_NONE){ + if (cmd->stop_src == TRIG_NONE) { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* Step 4: fix up any arguments. * "argument conflict" returned by comedilib to user mode process * if this fails. */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; - pci230_ns_to_single_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + pci230_ns_to_single_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(err)return 4; + if (err) + return 4; return 0; } -static int pci230_ao_inttrig(comedi_device *dev,comedi_subdevice *s, - unsigned int trig_num) +static int pci230_ao_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trig_num) { - if(trig_num != 0) + if (trig_num != 0) return -EINVAL; /* Enable DAC interrupt. */ devpriv->ier |= PCI230_INT_ZCLK_CT1; outb(devpriv->ier, devpriv->pci_iobase + PCI230_INT_SCE); - s->async->inttrig=NULL; + s->async->inttrig = NULL; return 1; } -static int pci230_ao_cmd(comedi_device *dev,comedi_subdevice *s) +static int pci230_ao_cmd(comedi_device * dev, comedi_subdevice * s) { int range; /* Get the command. */ - comedi_cmd *cmd=&s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; /* Calculate number of conversions required. */ - if(cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_src == TRIG_COUNT) { devpriv->ao_count = cmd->stop_arg * cmd->chanlist_len; devpriv->ao_stop = 0; - } - else { + } else { /* TRIG_NONE, user calls cancel. */ devpriv->ao_count = 0; devpriv->ao_stop = 1; @@ -923,15 +955,15 @@ static int pci230_ao_cmd(comedi_device *dev,comedi_subdevice *s) */ pci230_z2_ct1(dev, &cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); /* cmd->convert_arg is sampling period in ns */ - s->async->inttrig=pci230_ao_inttrig; + s->async->inttrig = pci230_ao_inttrig; return 0; } -static int pci230_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int pci230_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -945,47 +977,54 @@ static int pci230_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, * "invalid source" returned by comedilib to user mode process * if this fails. */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; /* Unfortunately, we cannot trigger a scan off an external source * on the PCI260 board, since it uses the PPI0 (DIO) input, which * isn't present on the PCI260 */ - if(thisboard->have_dio){ + if (thisboard->have_dio) { cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_EXT; - } - else{ + } else { cmd->scan_begin_src &= TRIG_FOLLOW; - } - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + } + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* Step 2: make sure trigger sources are unique and mutually compatible * "source conflict" returned by comedilib to user mode process * if this fails. */ - if(cmd->start_src!=TRIG_NOW)err++; - if(cmd->scan_begin_src!=TRIG_FOLLOW && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->start_src != TRIG_NOW) + err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; /* Although the scan and convert triggers come from different sources, the * driver relies on the knowledge of convert rate to trigger the correct number @@ -993,83 +1032,86 @@ static int pci230_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, * scan trigger will not work correctly. * The convert trigger is the input into the "EXT TRIG" line (pin 25), whilst * the scan trigger is "PPC0" (pin 49). */ - if(cmd->scan_begin_src==TRIG_EXT && - cmd->convert_src==TRIG_EXT)err++; + if (cmd->scan_begin_src == TRIG_EXT && cmd->convert_src == TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* Step 3: make sure arguments are trivially compatible. * "invalid argument" returned by comedilib to user mode process * if this fails. */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SPEED 3200 /* 3200ns => 312.5kHz */ +#define MAX_SPEED 3200 /* 3200ns => 312.5kHz */ #define MIN_SPEED 4294967295u /* 4294967295ns = 4.29s - Comedi limit due to unsigned int cmd. Driver limit = 2^16 (16bit counter) * 1000000ns (1kHz onboard clock) = 65.536s */ - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argconvert_arg=MAX_SPEED; + 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; + if (cmd->convert_arg > MIN_SPEED) { + cmd->convert_arg = MIN_SPEED; err++; } - }else{ + } else { /* external trigger */ /* convert_arg == 0 => trigger on -ve edge. */ /* convert_arg == 1 => trigger on +ve edge. */ - if(cmd->convert_arg>1){ - cmd->convert_arg=1; /* Default to trigger on +ve edge. */ + if (cmd->convert_arg > 1) { + cmd->convert_arg = 1; /* Default to trigger on +ve edge. */ err++; } } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + if (cmd->scan_end_arg != cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src==TRIG_NONE){ + if (cmd->stop_src == TRIG_NONE) { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - - if(cmd->scan_begin_src==TRIG_EXT){ + if (cmd->scan_begin_src == TRIG_EXT) { /* external "trigger" to begin each scan * * scan_begin_arg==0 => use PPC0 input -> gate of CT0 -> gate of CT2 * - * (sample convert trigger is CT2) */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; /* default option, so you can monitor CT2 (only CT with an external output) */ + * (sample convert trigger is CT2) */ + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; /* default option, so you can monitor CT2 (only CT with an external output) */ err++; } } - if(err)return 3; + if (err) + return 3; /* Step 4: fix up any arguments. * "argument conflict" returned by comedilib to user mode process * if this fails. */ - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - pci230_ns_to_single_timer(&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + pci230_ns_to_single_timer(&cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err++; } - if(err)return 4; + if (err) + return 4; return 0; } -static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int pci230_ai_cmd(comedi_device * dev, comedi_subdevice * s) { int i, chan, range, diff; unsigned int adccon, adcen, adcg; @@ -1080,11 +1122,10 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) comedi_cmd *cmd = &async->cmd; /* Calculate number of conversions required. */ - if(cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_src == TRIG_COUNT) { devpriv->ai_count = cmd->stop_arg * cmd->chanlist_len; devpriv->ai_stop = 0; - } - else { + } else { /* TRIG_NONE, user calls cancel. */ devpriv->ai_count = 0; devpriv->ai_stop = 1; @@ -1105,12 +1146,11 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->ier &= ~PCI230_INT_ADC; outb(devpriv->ier, devpriv->pci_iobase + PCI230_INT_SCE); - if (CR_AREF(cmd->chanlist[0])==AREF_DIFF) { + if (CR_AREF(cmd->chanlist[0]) == AREF_DIFF) { /* Differential - all channels must be differential. */ diff = 1; adccon = PCI230_ADC_IM_DIF; - } - else { + } else { /* Single ended - all channels must be single-ended. */ diff = 0; adccon = PCI230_ADC_IM_SE; @@ -1130,27 +1170,26 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) chan = CR_CHAN(cmd->chanlist[i]); range = CR_RANGE(cmd->chanlist[i]); if (diff) { - adcg |= range<<(2*chan-2*chan%2); - adcen |= 3<<2*chan; - } - else { - adcg |= range<<(chan-chan%2); - adcen |= 1<chanlist_len; i++) { chan = CR_CHAN(cmd->chanlist[i]); range = CR_RANGE(cmd->chanlist[i]); if (diff) { - adcg |= ((range&(~4))+1)<<(2*chan-2*chan%2); - adcen |= 3<<2*chan; - } - else { - adcg |= ((range&(~4))+1)<<(chan-chan%2); - adcen |= 1<iobase + PCI230_ADCG); /* Enable and reset FIFO, specify FIFO trigger level full, specify uni/bip, se/diff, and start conversion source to none. */ - outw(adccon | PCI230_ADC_INT_FIFO_FULL | PCI230_ADC_TRIG_NONE, dev->iobase + PCI230_ADCCON); + outw(adccon | PCI230_ADC_INT_FIFO_FULL | PCI230_ADC_TRIG_NONE, + dev->iobase + PCI230_ADCCON); /* Delay */ /* Failure to include this will result in the first few channels'-worth of data being corrupt, @@ -1177,7 +1217,7 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) outb(devpriv->ier, devpriv->pci_iobase + PCI230_INT_SCE); /* Set up the scan_begin_src (if it's NOT set to TRIG_FOLLOW) */ - if(cmd->scan_begin_src == TRIG_EXT){ + if (cmd->scan_begin_src == TRIG_EXT) { /* use PPC0 -> gate of CT0 (as monostable) -> gate of CT2 * * Note that the PCI230 card does not support "native" triggered scans, @@ -1213,7 +1253,8 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) zgat = PCI230_ZGAT_CT2 | PCI230_ZGAT_SRC_GND; outb(zgat, devpriv->pci_iobase + PCI230_ZGAT_SCE); - pci230_setup_monostable_ct0(dev, cmd->convert_arg, cmd->chanlist_len); + pci230_setup_monostable_ct0(dev, cmd->convert_arg, + cmd->chanlist_len); /* now set the gates up so that we can begin triggering */ zgat = PCI230_ZGAT_CT0 | PCI230_ZGAT_SRC_PPCN; @@ -1221,43 +1262,37 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) zgat = PCI230_ZGAT_CT2 | PCI230_ZGAT_SRC_OUTNP1; outb(zgat, devpriv->pci_iobase + PCI230_ZGAT_SCE); - } - else{ /* must be using "TRIG_FOLLOW", so need to "ungate" CT2 */ + } else { /* must be using "TRIG_FOLLOW", so need to "ungate" CT2 */ zgat = PCI230_ZGAT_CT2 | PCI230_ZGAT_SRC_VCC; outb(zgat, devpriv->pci_iobase + PCI230_ZGAT_SCE); } /* Set start conversion source. */ - if(cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_src == TRIG_TIMER) { /* Onboard counter/timer 2. */ adccon = adccon | PCI230_ADC_TRIG_Z2CT2; /* Set the counter timers to the specified sampling frequency. */ pci230_z2_ct2(dev, &cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); /* cmd->convert_arg is sampling period in ns */ - } - else { + } else { /* TRIG_EXT - external trigger. */ if (cmd->convert_arg) { /* Trigger on +ve edge. */ adccon = adccon | PCI230_ADC_TRIG_EXTP; - } - else { + } else { /* Trigger on -ve edge. */ adccon = adccon | PCI230_ADC_TRIG_EXTN; } } - /* Set FIFO interrupt trigger level. */ - if(cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_src == TRIG_COUNT) { if (devpriv->ai_count < 2048) { adccon = adccon | PCI230_ADC_INT_FIFO_NEMPTY; - } - else { + } else { adccon = adccon | PCI230_ADC_INT_FIFO_HALF; } - } - else { + } else { /* TRIG_NONE - trigger on half-full FIFO. */ adccon = adccon | PCI230_ADC_INT_FIFO_HALF; } @@ -1268,22 +1303,21 @@ static int pci230_ai_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } - #if 0 /* This function doesn't require a particular form, this is just * what happens to be used in some of the drivers. It should * convert ns nanoseconds to a counter value suitable for programming * the device. Also, it should adjust ns so that it cooresponds to * the actual time that the device will use. */ -static void pci230_ns_to_timer(unsigned int *ns,int round) +static void pci230_ns_to_timer(unsigned int *ns, int round) { unsigned int divisor0, divisor1; - i8253_cascade_ns_to_timer_2div(PCI230_TIMEBASE_10MHZ, &divisor0, &divisor1, ns, TRIG_ROUND_MASK); + i8253_cascade_ns_to_timer_2div(PCI230_TIMEBASE_10MHZ, &divisor0, + &divisor1, ns, TRIG_ROUND_MASK); return; } #endif - /* This function is used for analogue input. Only one counter/timer can be used, * because for the triggered scan functionality to work, 2 counters with * identical clock inputs and divide ratios are required, so that the @@ -1291,64 +1325,68 @@ static void pci230_ns_to_timer(unsigned int *ns,int round) * This is a very "noddy" way of doing this... apologies. (sds) */ static unsigned int pci230_choose_clk_src(unsigned int ns) { - unsigned int clk_src=0; - - if(ns < 6553600) clk_src=PCI230_TIMEBASE_10MHZ; - if(ns >= 6553600 && ns < 65536000) clk_src=PCI230_TIMEBASE_1MHZ; - if(ns >= 65536000 && ns < 655360000) clk_src=PCI230_TIMEBASE_100KHZ; - if(ns >=655360000 && ns <4294967295u) clk_src=PCI230_TIMEBASE_10KHZ; /* maximum limited by comedi = 4.29s */ - - if(clk_src == 0){ + unsigned int clk_src = 0; + + if (ns < 6553600) + clk_src = PCI230_TIMEBASE_10MHZ; + if (ns >= 6553600 && ns < 65536000) + clk_src = PCI230_TIMEBASE_1MHZ; + if (ns >= 65536000 && ns < 655360000) + clk_src = PCI230_TIMEBASE_100KHZ; + if (ns >= 655360000 && ns < 4294967295u) + clk_src = PCI230_TIMEBASE_10KHZ; /* maximum limited by comedi = 4.29s */ + + if (clk_src == 0) { printk("comedi: dodgy clock source chosen, using 10MHz\n"); - clk_src=PCI230_TIMEBASE_10MHZ; - } + clk_src = PCI230_TIMEBASE_10MHZ; + } return clk_src; } -static void pci230_ns_to_single_timer(unsigned int *ns,int round) +static void pci230_ns_to_single_timer(unsigned int *ns, int round) { unsigned int divisor; unsigned int clk_src; - clk_src=pci230_choose_clk_src(*ns); + clk_src = pci230_choose_clk_src(*ns); i8253_single_ns_to_timer(clk_src, &divisor, ns, TRIG_ROUND_MASK); return; } -static void i8253_single_ns_to_timer(unsigned int i8253_osc_base, unsigned int *d, unsigned int *nanosec, int round_mode) +static void i8253_single_ns_to_timer(unsigned int i8253_osc_base, + unsigned int *d, unsigned int *nanosec, int round_mode) { - unsigned int div; + unsigned int div; - /* exit early if everything is already correct (this can save time - * since this function may be called repeatedly during command tests - * and execution) */ - if(*d * i8253_osc_base == *nanosec && - *d > 1 && *d < 0x10000) - { - return; - } + /* exit early if everything is already correct (this can save time + * since this function may be called repeatedly during command tests + * and execution) */ + if (*d * i8253_osc_base == *nanosec && *d > 1 && *d < 0x10000) { + return; + } round_mode &= TRIG_ROUND_MASK; switch (round_mode) { case TRIG_ROUND_NEAREST: default: - div=(*nanosec + i8253_osc_base / 2) / i8253_osc_base; + div = (*nanosec + i8253_osc_base / 2) / i8253_osc_base; break; case TRIG_ROUND_UP: - div=(*nanosec) / i8253_osc_base; + div = (*nanosec) / i8253_osc_base; break; case TRIG_ROUND_DOWN: - div=(*nanosec + i8253_osc_base + 1 ) / i8253_osc_base; + div = (*nanosec + i8253_osc_base + 1) / i8253_osc_base; break; } *nanosec = div * i8253_osc_base; - *d = div & 0xffff; // masking is done since counter maps zero to 0x10000 + *d = div & 0xffff; // masking is done since counter maps zero to 0x10000 return; } -static void pci230_setup_monostable_ct0(comedi_device *dev, unsigned int ns, unsigned int n_chan) +static void pci230_setup_monostable_ct0(comedi_device * dev, unsigned int ns, + unsigned int n_chan) { /* ns is the convert period, n_chan is the no of channels per scan. * We must make the output of the counter equal in time to the amount of time @@ -1356,10 +1394,10 @@ static void pci230_setup_monostable_ct0(comedi_device *dev, unsigned int ns, uns unsigned int pulse_duration; - pulse_duration = ns*n_chan; - devpriv->clk_src0=pci230_choose_clk_src(pulse_duration); /* let's hope that if devpriv->clk_src0 != devpriv->clk_src2, then one is divided down from the other! */ + pulse_duration = ns * n_chan; + devpriv->clk_src0 = pci230_choose_clk_src(pulse_duration); /* let's hope that if devpriv->clk_src0 != devpriv->clk_src2, then one is divided down from the other! */ - devpriv->divisor0=pulse_duration/devpriv->clk_src0; + devpriv->divisor0 = pulse_duration / devpriv->clk_src0; i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, 0, devpriv->divisor0, 1); /* Counter 1, mode 1 */ @@ -1386,15 +1424,15 @@ static void pci230_setup_monostable_ct0(comedi_device *dev, unsigned int ns, uns return; } - #if 0 /* * Set ZCLK_CT0 to square wave mode with period of ns. */ -static void pci230_z2_ct0(comedi_device *dev, unsigned int *ns,int round) +static void pci230_z2_ct0(comedi_device * dev, unsigned int *ns, int round) { - devpriv->clk_src0=pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ - i8253_single_ns_to_timer(devpriv->clk_src0, &devpriv->divisor0, ns, TRIG_ROUND_MASK); + devpriv->clk_src0 = pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ + i8253_single_ns_to_timer(devpriv->clk_src0, &devpriv->divisor0, ns, + TRIG_ROUND_MASK); /* Generic i8254_load calls; program counters' divide ratios. */ i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, devpriv->divisor0, 3); /* Counter 0, divisor0, square wave (8254 mode 3). */ @@ -1423,7 +1461,7 @@ static void pci230_z2_ct0(comedi_device *dev, unsigned int *ns,int round) #endif #if 0 -static void pci230_cancel_ct0(comedi_device *dev) +static void pci230_cancel_ct0(comedi_device * dev) { devpriv->divisor0 = 0; i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, devpriv->divisor0, 0); /* Counter 0, divisor0, 8254 mode 0. */ @@ -1434,10 +1472,11 @@ static void pci230_cancel_ct0(comedi_device *dev) * Set ZCLK_CT1 to square wave mode with period of ns. * Default clk source for DAC. */ -static void pci230_z2_ct1(comedi_device *dev, unsigned int *ns,int round) +static void pci230_z2_ct1(comedi_device * dev, unsigned int *ns, int round) { - devpriv->clk_src1=pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ - i8253_single_ns_to_timer(devpriv->clk_src1, &devpriv->divisor1, ns, TRIG_ROUND_MASK); + devpriv->clk_src1 = pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ + i8253_single_ns_to_timer(devpriv->clk_src1, &devpriv->divisor1, ns, + TRIG_ROUND_MASK); /* Generic i8254_load calls; program counters' divide ratios. */ i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, 1, devpriv->divisor1, 3); /* Counter 1, divisor1, square wave (8254 mode 3). */ @@ -1464,7 +1503,7 @@ static void pci230_z2_ct1(comedi_device *dev, unsigned int *ns,int round) return; } -static void pci230_cancel_ct1(comedi_device *dev) +static void pci230_cancel_ct1(comedi_device * dev) { devpriv->divisor1 = 0; i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, 1, devpriv->divisor1, 0); /* Counter 1, divisor1, 8254 mode 0. */ @@ -1474,10 +1513,11 @@ static void pci230_cancel_ct1(comedi_device *dev) * Set ZCLK_CT2 to square wave mode with period of ns. * Default clk source for ADC. */ -static void pci230_z2_ct2(comedi_device *dev, unsigned int *ns,int round) +static void pci230_z2_ct2(comedi_device * dev, unsigned int *ns, int round) { - devpriv->clk_src2=pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ - i8253_single_ns_to_timer(devpriv->clk_src2, &devpriv->divisor2, ns, TRIG_ROUND_MASK); + devpriv->clk_src2 = pci230_choose_clk_src(*ns); /* choose a suitable clock source from the range available, given the desired period in ns */ + i8253_single_ns_to_timer(devpriv->clk_src2, &devpriv->divisor2, ns, + TRIG_ROUND_MASK); /* Generic i8254_load calls; program counters' divide ratios. */ i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, 2, devpriv->divisor2, 3); /* Counter 2, divisor2, square wave (8254 mode 3). */ @@ -1504,7 +1544,7 @@ static void pci230_z2_ct2(comedi_device *dev, unsigned int *ns,int round) return; } -static void pci230_cancel_ct2(comedi_device *dev) +static void pci230_cancel_ct2(comedi_device * dev) { devpriv->divisor2 = 0; i8254_load(devpriv->pci_iobase + PCI230_Z2_CT0, 0, 2, devpriv->divisor2, 0); /* Counter 2, divisor2, 8254 mode 0. */ @@ -1514,7 +1554,7 @@ static void pci230_cancel_ct2(comedi_device *dev) static irqreturn_t pci230_interrupt(int irq, void *d PT_REGS_ARG) { int status_int; - comedi_device *dev = (comedi_device*) d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s; /* Read interrupt status/enable register. */ @@ -1555,7 +1595,8 @@ static irqreturn_t pci230_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static void pci230_handle_ao(comedi_device *dev, comedi_subdevice *s) { +static void pci230_handle_ao(comedi_device * dev, comedi_subdevice * s) +{ sampl_t data; int i, ret; comedi_async *async = s->async; @@ -1564,25 +1605,26 @@ static void pci230_handle_ao(comedi_device *dev, comedi_subdevice *s) { for (i = 0; i < cmd->chanlist_len; i++) { /* Read sample from Comedi's circular buffer. */ ret = comedi_buf_get(s->async, &data); - if(ret < 0) { + if (ret < 0) { comedi_error(dev, "buffer underrun"); - return; // XXX does comedi_buf_get set s->async->events with appropriate flags in this instance? + return; // XXX does comedi_buf_get set s->async->events with appropriate flags in this instance? } /* Write value to DAC. */ pci230_ao_write(dev, data, cmd->chanlist[i]); - if(async->cmd.stop_src == TRIG_COUNT) { - if(devpriv->ao_count > 0) devpriv->ao_count--; - if(devpriv->ao_count == 0) break; + if (async->cmd.stop_src == TRIG_COUNT) { + if (devpriv->ao_count > 0) + devpriv->ao_count--; + if (devpriv->ao_count == 0) + break; } } - if(devpriv->ao_count == 0 && devpriv->ao_stop == 0) { + if (devpriv->ao_count == 0 && devpriv->ao_stop == 0) { /* End of DAC. */ async->events |= COMEDI_CB_EOA; pci230_ao_cancel(dev, s); - } - else { + } else { /* More samples required, tell Comedi to block. */ async->events |= COMEDI_CB_BLOCK; /* Enable DAC (conversion complete) interrupt (and leave any other enabled interrupts as they are). */ @@ -1592,7 +1634,8 @@ static void pci230_handle_ao(comedi_device *dev, comedi_subdevice *s) { return; } -static void pci230_handle_ai(comedi_device *dev, comedi_subdevice *s) { +static void pci230_handle_ai(comedi_device * dev, comedi_subdevice * s) +{ int error = 0; int status_fifo; @@ -1603,16 +1646,13 @@ static void pci230_handle_ai(comedi_device *dev, comedi_subdevice *s) { /* Report error otherwise FIFO overruns will go unnoticed by the caller. */ comedi_error(dev, "FIFO overrun"); error++; - } - else if (status_fifo & PCI230_ADC_FIFO_HALF) { + } else if (status_fifo & PCI230_ADC_FIFO_HALF) { /* FIFO is at least half full. */ pci230_handle_fifo_half_full(dev, s); - } - else if (status_fifo & PCI230_ADC_FIFO_EMPTY) { + } else if (status_fifo & PCI230_ADC_FIFO_EMPTY) { /* FIFO empty but we got an interrupt. */ - printk("comedi%d: amplc_pci230::pci230_handle_ai FIFO empty - spurious interrupt\n",dev->minor); - } - else { + printk("comedi%d: amplc_pci230::pci230_handle_ai FIFO empty - spurious interrupt\n", dev->minor); + } else { /* FIFO is less than half full, but not empty. */ pci230_handle_fifo_not_empty(dev, s); } @@ -1621,11 +1661,11 @@ static void pci230_handle_ai(comedi_device *dev, comedi_subdevice *s) { /* Cancel sampled conversion. */ s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; pci230_ai_cancel(dev, s); - }else if(devpriv->ai_count == 0 && devpriv->ai_stop == 0) { + } else if (devpriv->ai_count == 0 && devpriv->ai_stop == 0) { /* Acquisition complete. */ s->async->events |= COMEDI_CB_EOA; - pci230_ai_cancel(dev, s); /* disable hardware conversions */ - }else { + pci230_ai_cancel(dev, s); /* disable hardware conversions */ + } else { /* More samples required, tell Comedi to block. */ s->async->events |= COMEDI_CB_BLOCK; @@ -1636,16 +1676,17 @@ static void pci230_handle_ai(comedi_device *dev, comedi_subdevice *s) { return; } -static void pci230_handle_fifo_half_full(comedi_device *dev, comedi_subdevice *s) { +static void pci230_handle_fifo_half_full(comedi_device * dev, + comedi_subdevice * s) +{ int i; for (i = 0; i < 2048; i++) { /* Read sample and store in Comedi's circular buffer. */ comedi_buf_put(s->async, pci230_ai_read(dev)); - if(s->async->cmd.stop_src == TRIG_COUNT) - { - if(--devpriv->ai_count == 0) { + if (s->async->cmd.stop_src == TRIG_COUNT) { + if (--devpriv->ai_count == 0) { /* Acquisition complete. */ return; } @@ -1655,7 +1696,9 @@ static void pci230_handle_fifo_half_full(comedi_device *dev, comedi_subdevice *s return; } -static void pci230_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice *s) { +static void pci230_handle_fifo_not_empty(comedi_device * dev, + comedi_subdevice * s) +{ while (devpriv->ai_count != 0) { if (inw(dev->iobase + PCI230_ADCCON) & PCI230_ADC_FIFO_EMPTY) { /* The FIFO is empty, block. */ @@ -1664,14 +1707,15 @@ static void pci230_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice *s /* There are sample(s) to read from FIFO, read one and store in Comedi's circular buffer. */ comedi_buf_put(s->async, pci230_ai_read(dev)); - if(devpriv->ai_count > 0) devpriv->ai_count--; + if (devpriv->ai_count > 0) + devpriv->ai_count--; } /* Acquisition complete. */ return; } - -static int pci230_ao_cancel(comedi_device *dev, comedi_subdevice *s) { +static int pci230_ao_cancel(comedi_device * dev, comedi_subdevice * s) +{ devpriv->ao_count = 0; devpriv->ao_stop = 0; @@ -1685,7 +1729,8 @@ static int pci230_ao_cancel(comedi_device *dev, comedi_subdevice *s) { return 0; } -static int pci230_ai_cancel(comedi_device *dev, comedi_subdevice *s) { +static int pci230_ai_cancel(comedi_device * dev, comedi_subdevice * s) +{ devpriv->ai_count = 0; devpriv->ai_stop = 0; @@ -1697,7 +1742,8 @@ static int pci230_ai_cancel(comedi_device *dev, comedi_subdevice *s) { outb(devpriv->ier, devpriv->pci_iobase + PCI230_INT_SCE); /* Reset FIFO and set start conversion source to none. */ - outw(PCI230_ADC_FIFO_RESET | PCI230_ADC_TRIG_NONE, dev->iobase + PCI230_ADCCON); + outw(PCI230_ADC_FIFO_RESET | PCI230_ADC_TRIG_NONE, + dev->iobase + PCI230_ADCCON); /* Clear channel scan list. */ outw(0x0000, dev->iobase + PCI230_ADCEN); @@ -1707,5 +1753,3 @@ static int pci230_ai_cancel(comedi_device *dev, comedi_subdevice *s) { return 0; } - - diff --git a/comedi/drivers/c6xdigio.c b/comedi/drivers/c6xdigio.c index b375c2b8..eca626dc 100644 --- a/comedi/drivers/c6xdigio.c +++ b/comedi/drivers/c6xdigio.c @@ -51,14 +51,15 @@ http://robot0.ge.uiuc.edu/~spong/mecha/ static u8 ReadByteFromHwPort(unsigned long addr) { - u8 result = inb(addr); - return result; + u8 result = inb(addr); + return result; } static void WriteByteToHwPort(unsigned long addr, u8 val) { - outb_p(val, addr); + outb_p(val, addr); } + #define C6XDIGIO_SIZE 3 /* @@ -68,149 +69,152 @@ static void WriteByteToHwPort(unsigned long addr, u8 val) #define C6XDIGIO_PARALLEL_STATUS 1 #define C6XDIGIO_PARALLEL_CONTROL 2 struct pwmbitstype { - unsigned sb0: 2; - unsigned sb1: 2; - unsigned sb2: 2; - unsigned sb3: 2; - unsigned sb4: 2; + unsigned sb0:2; + unsigned sb1:2; + unsigned sb2:2; + unsigned sb3:2; + unsigned sb4:2; }; union pwmcmdtype { - unsigned cmd; // assuming here that int is 32bit + unsigned cmd; // assuming here that int is 32bit struct pwmbitstype bits; }; struct encbitstype { - unsigned sb0: 3; - unsigned sb1: 3; - unsigned sb2: 3; - unsigned sb3: 3; - unsigned sb4: 3; - unsigned sb5: 3; - unsigned sb6: 3; - unsigned sb7: 3; + unsigned sb0:3; + unsigned sb1:3; + unsigned sb2:3; + unsigned sb3:3; + unsigned sb4:3; + unsigned sb5:3; + unsigned sb6:3; + unsigned sb7:3; }; union encvaluetype { - unsigned value; - struct encbitstype bits; + unsigned value; + struct encbitstype bits; }; #define C6XDIGIO_TIME_OUT 20 -static int c6xdigio_attach(comedi_device *dev,comedi_devconfig *it); -static int c6xdigio_detach(comedi_device *dev); -comedi_driver driver_c6xdigio={ - driver_name: "c6xdigio", - module: THIS_MODULE, - attach: c6xdigio_attach, - detach: c6xdigio_detach, +static int c6xdigio_attach(comedi_device * dev, comedi_devconfig * it); +static int c6xdigio_detach(comedi_device * dev); +comedi_driver driver_c6xdigio = { + driver_name:"c6xdigio", + module:THIS_MODULE, + attach:c6xdigio_attach, + detach:c6xdigio_detach, }; -static void C6X_pwmInit( unsigned long baseAddr ) { - int timeout=0; +static void C6X_pwmInit(unsigned long baseAddr) +{ + int timeout = 0; //printk("Inside C6X_pwmInit\n"); - WriteByteToHwPort(baseAddr,0x70); - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x70); + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - WriteByteToHwPort(baseAddr,0x74); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x74); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - - WriteByteToHwPort(baseAddr,0x70); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT) ) { + + WriteByteToHwPort(baseAddr, 0x70); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x0) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - - WriteByteToHwPort(baseAddr,0x0); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { + + WriteByteToHwPort(baseAddr, 0x0); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - + } -static void C6X_pwmOutput( unsigned long baseAddr, unsigned channel, int value ) +static void C6X_pwmOutput(unsigned long baseAddr, unsigned channel, int value) { unsigned ppcmd; union pwmcmdtype pwm; - int timeout=0; - unsigned tmp; - + int timeout = 0; + unsigned tmp; //printk("Inside C6X_pwmOutput\n"); pwm.cmd = value; if (pwm.cmd > 498) - pwm.cmd = 498; + pwm.cmd = 498; if (pwm.cmd < 2) - pwm.cmd = 2; + pwm.cmd = 2; if (channel == 0) { ppcmd = 0x28; - } else { // if channel == 1 + } else { // if channel == 1 ppcmd = 0x30; - } /* endif */ + } /* endif */ - WriteByteToHwPort(baseAddr,ppcmd+pwm.bits.sb0); - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + WriteByteToHwPort(baseAddr, ppcmd + pwm.bits.sb0); + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - - WriteByteToHwPort(baseAddr,ppcmd+pwm.bits.sb1+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + + WriteByteToHwPort(baseAddr, ppcmd + pwm.bits.sb1 + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - - WriteByteToHwPort(baseAddr,ppcmd+pwm.bits.sb2); - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + + WriteByteToHwPort(baseAddr, ppcmd + pwm.bits.sb2); + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - - WriteByteToHwPort(baseAddr,ppcmd+pwm.bits.sb3+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + + WriteByteToHwPort(baseAddr, ppcmd + pwm.bits.sb3 + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - - WriteByteToHwPort(baseAddr,ppcmd+pwm.bits.sb4); - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + + WriteByteToHwPort(baseAddr, ppcmd + pwm.bits.sb4); + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - - WriteByteToHwPort(baseAddr,0x0); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + + WriteByteToHwPort(baseAddr, 0x0); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - + } -static int C6X_encInput( unsigned long baseAddr, unsigned channel) +static int C6X_encInput(unsigned long baseAddr, unsigned channel) { unsigned ppcmd; union encvaluetype enc; - int timeout=0; + int timeout = 0; int tmp; - //printk("Inside C6X_encInput\n"); enc.value = 0; @@ -219,156 +223,154 @@ static int C6X_encInput( unsigned long baseAddr, unsigned channel) } else { ppcmd = 0x50; } - WriteByteToHwPort(baseAddr,ppcmd); - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + WriteByteToHwPort(baseAddr, ppcmd); + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb0 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb0 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb1 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb1 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb2 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb2 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb3 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb3 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb4 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb4 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb5 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb5 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb6 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd+0x4); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb6 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd + 0x4); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - enc.bits.sb7 = ((ReadByteFromHwPort(baseAddr+1) >> 3) & 0x7); - WriteByteToHwPort(baseAddr,ppcmd); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + enc.bits.sb7 = ((ReadByteFromHwPort(baseAddr + 1) >> 3) & 0x7); + WriteByteToHwPort(baseAddr, ppcmd); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - WriteByteToHwPort(baseAddr,0x0); - timeout=0; - tmp = ReadByteFromHwPort(baseAddr+1); - while ( ((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { - tmp = ReadByteFromHwPort(baseAddr+1); + WriteByteToHwPort(baseAddr, 0x0); + timeout = 0; + tmp = ReadByteFromHwPort(baseAddr + 1); + while (((tmp & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT)) { + tmp = ReadByteFromHwPort(baseAddr + 1); timeout++; } - return(enc.value ^ 0x800000); + return (enc.value ^ 0x800000); } -static void C6X_encResetAll( unsigned long baseAddr ) +static void C6X_encResetAll(unsigned long baseAddr) { - unsigned timeout=0; + unsigned timeout = 0; //printk("Inside C6X_encResetAll\n"); - WriteByteToHwPort(baseAddr,0x68); - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x68); + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - WriteByteToHwPort(baseAddr,0x6C); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x6C); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - WriteByteToHwPort(baseAddr,0x68); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x0) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x68); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x0) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } - WriteByteToHwPort(baseAddr,0x0); - timeout=0; - while ( ((ReadByteFromHwPort(baseAddr+1) & 0x80) == 0x80) && (timeout < C6XDIGIO_TIME_OUT) ) { + WriteByteToHwPort(baseAddr, 0x0); + timeout = 0; + while (((ReadByteFromHwPort(baseAddr + 1) & 0x80) == 0x80) + && (timeout < C6XDIGIO_TIME_OUT)) { timeout++; } } - -static int c6xdigio_pwmo_insn_read(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int c6xdigio_pwmo_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - printk("c6xdigio_pwmo_insn_read %x\n", insn->n); - return insn->n; + printk("c6xdigio_pwmo_insn_read %x\n", insn->n); + return insn->n; } -static int c6xdigio_pwmo_insn_write(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int c6xdigio_pwmo_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); - - // printk("c6xdigio_pwmo_insn_write %x\n", insn->n); - for(i=0;in;i++){ - C6X_pwmOutput(dev->iobase, chan, data[i]); - /* devpriv->ao_readback[chan] = data[i];*/ - } - return i; -} + int i; + int chan = CR_CHAN(insn->chanspec); + // printk("c6xdigio_pwmo_insn_write %x\n", insn->n); + for (i = 0; i < insn->n; i++) { + C6X_pwmOutput(dev->iobase, chan, data[i]); + /* devpriv->ao_readback[chan] = data[i]; */ + } + return i; +} //static int c6xdigio_ei_init_insn_read(comedi_device *dev, -// comedi_subdevice *s, -// comedi_insn *insn, -// lsampl_t *data) +// comedi_subdevice *s, +// comedi_insn *insn, +// lsampl_t *data) //{ // printk("c6xdigio_ei_init_insn_read %x\n", insn->n); // return insn->n; //} //static int c6xdigio_ei_init_insn_write(comedi_device *dev, -// comedi_subdevice *s, -// comedi_insn *insn, -// lsampl_t *data) +// comedi_subdevice *s, +// comedi_insn *insn, +// lsampl_t *data) //{ // int i; // int chan = CR_CHAN(insn->chanspec); @@ -378,30 +380,28 @@ static int c6xdigio_pwmo_insn_write(comedi_device *dev, // return insn->n; //} -static int c6xdigio_ei_insn_read(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int c6xdigio_ei_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - // printk("c6xdigio_ei__insn_read %x\n", insn->n); - int n; - int chan = CR_CHAN(insn->chanspec); + // printk("c6xdigio_ei__insn_read %x\n", insn->n); + int n; + int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ - data[n] = (C6X_encInput(dev->iobase,chan) & 0xffffff); - } + for (n = 0; n < insn->n; n++) { + data[n] = (C6X_encInput(dev->iobase, chan) & 0xffffff); + } - return n; + return n; } +static void board_init(comedi_device * dev) +{ -static void board_init(comedi_device *dev) { + //printk("Inside board_init\n"); - //printk("Inside board_init\n"); + C6X_pwmInit(dev->iobase); + C6X_encResetAll(dev->iobase); - C6X_pwmInit(dev->iobase); - C6X_encResetAll(dev->iobase); - } //static void board_halt(comedi_device *dev) { @@ -415,103 +415,102 @@ static void board_init(comedi_device *dev) { */ static const struct pnp_device_id c6xdigio_pnp_tbl[] = { - /* Standard LPT Printer Port */ - {.id = "PNP0400", .driver_data = 0}, - /* ECP Printer Port */ - {.id = "PNP0401", .driver_data = 0}, - { } + /* Standard LPT Printer Port */ + {.id = "PNP0400",.driver_data = 0}, + /* ECP Printer Port */ + {.id = "PNP0401",.driver_data = 0}, + {} }; static struct pnp_driver c6xdigio_pnp_driver = { - .name = "c6xdigio", - .id_table = c6xdigio_pnp_tbl, + .name = "c6xdigio", + .id_table = c6xdigio_pnp_tbl, }; static int c6xdigio_attach(comedi_device * dev, comedi_devconfig * it) { - int result = 0; - unsigned long iobase; - unsigned int irq; - comedi_subdevice *s; - - iobase = it->options[0]; - printk("comedi%d: c6xdigio: 0x%04lx\n", dev->minor, iobase); - if (!request_region(iobase, C6XDIGIO_SIZE, "c6xdigio")) { - printk("comedi%d: I/O port conflict\n", dev->minor); - return -EIO; - } - dev->iobase = iobase; - dev->board_name = "c6xdigio"; - - result = alloc_subdevices(dev, 2); // 3 with encoder_init write - if(result<0)return result; - - // Make sure that PnP ports gets activated - pnp_register_driver (&c6xdigio_pnp_driver); - - - irq = it->options[1]; - if (irq > 0) { - printk("comedi%d: irq = %u ignored\n", dev->minor, irq); - } else if(irq == 0) { - printk("comedi%d: no irq\n", dev->minor); - } - - - s = dev->subdevices + 0; - /* pwm output subdevice */ - s->type = COMEDI_SUBD_AO; // Not sure what to put here - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 2; - /* s->trig[0] = c6xdigio_pwmo;*/ - s->insn_read = c6xdigio_pwmo_insn_read; - s->insn_write = c6xdigio_pwmo_insn_write; - s->maxdata = 500; - s->range_table = &range_bipolar10; // A suitable lie - - s = dev->subdevices + 1; - /* encoder (counter) subdevice */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_LSAMPL; - s->n_chan = 2; - /* s->trig[0] = c6xdigio_ei;*/ - s->insn_read = c6xdigio_ei_insn_read; - s->maxdata = 0xffffff; - s->range_table = &range_unknown; - - // s = dev->subdevices + 2; - // /* pwm output subdevice */ - // s->type = COMEDI_SUBD_COUNTER; // Not sure what to put here - // s->subdev_flags = SDF_WRITEABLE; - // s->n_chan = 1; - // /* s->trig[0] = c6xdigio_ei_init; */ - // s->insn_read = c6xdigio_ei_init_insn_read; - // s->insn_write = c6xdigio_ei_init_insn_write; - // s->maxdata = 0xFFFF; // Really just a don't care - // s->range_table = &range_unknown; // Not sure what to put here - - // I will call this init anyway but more than likely the DSP board will not be connect - // when device driver is loaded. - board_init(dev); - - - return 0; -} + int result = 0; + unsigned long iobase; + unsigned int irq; + comedi_subdevice *s; + + iobase = it->options[0]; + printk("comedi%d: c6xdigio: 0x%04lx\n", dev->minor, iobase); + if (!request_region(iobase, C6XDIGIO_SIZE, "c6xdigio")) { + printk("comedi%d: I/O port conflict\n", dev->minor); + return -EIO; + } + dev->iobase = iobase; + dev->board_name = "c6xdigio"; + + result = alloc_subdevices(dev, 2); // 3 with encoder_init write + if (result < 0) + return result; + // Make sure that PnP ports gets activated + pnp_register_driver(&c6xdigio_pnp_driver); + + irq = it->options[1]; + if (irq > 0) { + printk("comedi%d: irq = %u ignored\n", dev->minor, irq); + } else if (irq == 0) { + printk("comedi%d: no irq\n", dev->minor); + } + + s = dev->subdevices + 0; + /* pwm output subdevice */ + s->type = COMEDI_SUBD_AO; // Not sure what to put here + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + /* s->trig[0] = c6xdigio_pwmo; */ + s->insn_read = c6xdigio_pwmo_insn_read; + s->insn_write = c6xdigio_pwmo_insn_write; + s->maxdata = 500; + s->range_table = &range_bipolar10; // A suitable lie + + s = dev->subdevices + 1; + /* encoder (counter) subdevice */ + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_LSAMPL; + s->n_chan = 2; + /* s->trig[0] = c6xdigio_ei; */ + s->insn_read = c6xdigio_ei_insn_read; + s->maxdata = 0xffffff; + s->range_table = &range_unknown; + + // s = dev->subdevices + 2; + // /* pwm output subdevice */ + // s->type = COMEDI_SUBD_COUNTER; // Not sure what to put here + // s->subdev_flags = SDF_WRITEABLE; + // s->n_chan = 1; + // /* s->trig[0] = c6xdigio_ei_init; */ + // s->insn_read = c6xdigio_ei_init_insn_read; + // s->insn_write = c6xdigio_ei_init_insn_write; + // s->maxdata = 0xFFFF; // Really just a don't care + // s->range_table = &range_unknown; // Not sure what to put here + + // I will call this init anyway but more than likely the DSP board will not be connect + // when device driver is loaded. + board_init(dev); + + return 0; +} static int c6xdigio_detach(comedi_device * dev) { // board_halt(dev); // may not need this - printk("comedi%d: c6xdigio: remove\n", dev->minor); + printk("comedi%d: c6xdigio: remove\n", dev->minor); - if (dev->iobase) { release_region(dev->iobase, C6XDIGIO_SIZE); } - if (dev->irq) { free_irq(dev->irq,dev); } // Not using IRQ so I am not sure if I need this - pnp_unregister_driver (&c6xdigio_pnp_driver); + if (dev->iobase) { + release_region(dev->iobase, C6XDIGIO_SIZE); + } + if (dev->irq) { + free_irq(dev->irq, dev); + } // Not using IRQ so I am not sure if I need this + pnp_unregister_driver(&c6xdigio_pnp_driver); - return 0; + return 0; } COMEDI_INITCLEANUP(driver_c6xdigio); - - diff --git a/comedi/drivers/cb_das16_cs.c b/comedi/drivers/cb_das16_cs.c index 74063645..3f4b4ab0 100644 --- a/comedi/drivers/cb_das16_cs.c +++ b/comedi/drivers/cb_das16_cs.c @@ -54,80 +54,80 @@ Status: experimental #define DAS16CS_CTR_CONTROL 14 #define DAS16CS_DIO 16 - -typedef struct das16cs_board_struct{ +typedef struct das16cs_board_struct { const char *name; int device_id; int n_ao_chans; -}das16cs_board; +} das16cs_board; static const das16cs_board das16cs_boards[] = { { - device_id: 0x0000, /* unknown */ - name: "PC-CARD DAS16/16", - n_ao_chans: 0, - }, + device_id:0x0000,/* unknown */ + name: "PC-CARD DAS16/16", + n_ao_chans:0, + }, { - device_id: 0x0039, - name: "PC-CARD DAS16/16-AO", - n_ao_chans: 2, - }, + device_id:0x0039, + name: "PC-CARD DAS16/16-AO", + n_ao_chans:2, + }, { - device_id: 0x4009, - name: "PCM-DAS16s/16", - n_ao_chans: 0, - }, + device_id:0x4009, + name: "PCM-DAS16s/16", + n_ao_chans:0, + }, }; + #define n_boards (sizeof(das16cs_boards)/sizeof(das16cs_boards[0])) #define thisboard ((const das16cs_board *)dev->board_ptr) -typedef struct{ +typedef struct { struct pcmcia_device *link; lsampl_t ao_readback[2]; unsigned short status1; unsigned short status2; -}das16cs_private; +} das16cs_private; #define devpriv ((das16cs_private *)dev->private) -static int das16cs_attach(comedi_device *dev,comedi_devconfig *it); -static int das16cs_detach(comedi_device *dev); -static comedi_driver driver_das16cs={ - driver_name: "cb_das16_cs", - module: THIS_MODULE, - attach: das16cs_attach, - detach: das16cs_detach, +static int das16cs_attach(comedi_device * dev, comedi_devconfig * it); +static int das16cs_detach(comedi_device * dev); +static comedi_driver driver_das16cs = { + driver_name:"cb_das16_cs", + module:THIS_MODULE, + attach:das16cs_attach, + detach:das16cs_detach, }; static struct pcmcia_device *cur_dev = NULL; static const comedi_lrange das16cs_ai_range = { 4, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ), -}}; - + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + } +}; static irqreturn_t das16cs_interrupt(int irq, void *d PT_REGS_ARG); -static int das16cs_ai_rinsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_ai_cmd(comedi_device *dev,comedi_subdevice *s); -static int das16cs_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_ao_rinsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_timer_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int das16cs_timer_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - -static int get_prodid(comedi_device *dev, struct pcmcia_device *link) +static int das16cs_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int das16cs_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int das16cs_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_timer_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16cs_timer_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int get_prodid(comedi_device * dev, struct pcmcia_device *link) { tuple_t tuple; u_short buf[128]; @@ -138,23 +138,24 @@ static int get_prodid(comedi_device *dev, struct pcmcia_device *link) tuple.TupleDataMax = 255; tuple.DesiredTuple = CISTPL_MANFID; tuple.Attributes = TUPLE_RETURN_COMMON; - if((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && - (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)){ + if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && + (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) { prodid = le16_to_cpu(buf[1]); } return prodid; } -static const das16cs_board *das16cs_probe(comedi_device *dev, struct pcmcia_device *link) +static const das16cs_board *das16cs_probe(comedi_device * dev, + struct pcmcia_device *link) { int id; int i; - id = get_prodid(dev,link); + id = get_prodid(dev, link); - for(i=0;iminor); + printk("comedi%d: cb_das16_cs: ", dev->minor); - link = cur_dev; /* XXX hack */ - if(!link)return -EIO; + link = cur_dev; /* XXX hack */ + if (!link) + return -EIO; dev->iobase = link->io.BasePort1; - printk("I/O base=0x%04lx ",dev->iobase); + printk("I/O base=0x%04lx ", dev->iobase); printk("fingerprint:\n"); - for(i=0;i<48;i+=2){ - printk("%04x ",inw(dev->iobase + i)); + for (i = 0; i < 48; i += 2) { + printk("%04x ", inw(dev->iobase + i)); } printk("\n"); ret = comedi_request_irq(link->irq.AssignedIRQ, das16cs_interrupt, IRQF_SHARED, "cb_das16_cs", dev); - if(ret<0){ + if (ret < 0) { return ret; } dev->irq = link->irq.AssignedIRQ; - printk("irq=%u ",dev->irq); + printk("irq=%u ", dev->irq); dev->board_ptr = das16cs_probe(dev, link); - if(!dev->board_ptr)return -EIO; + if (!dev->board_ptr) + return -EIO; dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(das16cs_private))<0) + if (alloc_private(dev, sizeof(das16cs_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - s=dev->subdevices+0; - dev->read_subdev=s; + s = dev->subdevices + 0; + dev->read_subdev = s; /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - s->n_chan=16; - s->maxdata=0xffff; - s->range_table=&das16cs_ai_range; - s->len_chanlist=16; + s->n_chan = 16; + s->maxdata = 0xffff; + s->range_table = &das16cs_ai_range; + s->len_chanlist = 16; s->insn_read = das16cs_ai_rinsn; s->do_cmd = das16cs_ai_cmd; s->do_cmdtest = das16cs_ai_cmdtest; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* analog output subdevice */ - if(thisboard->n_ao_chans){ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=thisboard->n_ao_chans; - s->maxdata=0xffff; + if (thisboard->n_ao_chans) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->n_ao_chans; + s->maxdata = 0xffff; s->range_table = &range_bipolar10; s->insn_write = &das16cs_ao_winsn; s->insn_read = &das16cs_ao_rinsn; } - s=dev->subdevices+2; + s = dev->subdevices + 2; /* digital i/o subdevice */ - if(1){ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; + if (1) { + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = das16cs_dio_insn_bits; s->insn_config = das16cs_dio_insn_config; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+3; + s = dev->subdevices + 3; /* timer subdevice */ - if(0){ - s->type=COMEDI_SUBD_TIMER; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=1; - s->maxdata=0xff; + if (0) { + s->type = COMEDI_SUBD_TIMER; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 1; + s->maxdata = 0xff; s->range_table = &range_unknown; s->insn_read = das16cs_timer_insn_read; s->insn_config = das16cs_timer_insn_config; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -262,18 +265,17 @@ static int das16cs_attach(comedi_device *dev,comedi_devconfig *it) return 1; } -static int das16cs_detach(comedi_device *dev) +static int das16cs_detach(comedi_device * dev) { - printk("comedi%d: das16cs: remove\n",dev->minor); + printk("comedi%d: das16cs: remove\n", dev->minor); - if(dev->irq){ + if (dev->irq) { comedi_free_irq(dev->irq, dev); } return 0; } - static irqreturn_t das16cs_interrupt(int irq, void *d PT_REGS_ARG) { //comedi_device *dev = d; @@ -284,7 +286,8 @@ static irqreturn_t das16cs_interrupt(int irq, void *d PT_REGS_ARG) * "instructions" read/write data in "one-shot" or "software-triggered" * mode. */ -static int das16cs_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16cs_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int to; @@ -300,21 +303,22 @@ static int das16cs_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * outw(chan, dev->iobase + 2); devpriv->status1 &= ~0xf320; - devpriv->status1 |= (aref==AREF_DIFF)?0:0x0020; + devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020; outw(devpriv->status1, dev->iobase + 4); devpriv->status2 &= ~0xff00; devpriv->status2 |= range_bits[range]; outw(devpriv->status2, dev->iobase + 6); - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { outw(0, dev->iobase); #define TIMEOUT 1000 - for(to=0;toiobase + 4) & 0x0080)break; + for (to = 0; to < TIMEOUT; to++) { + if (inw(dev->iobase + 4) & 0x0080) + break; } - if(to==TIMEOUT){ + if (to == TIMEOUT) { printk("cb_das16_cs: ai timeout\n"); return -ETIME; } @@ -324,15 +328,15 @@ static int das16cs_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * return i; } -static int das16cs_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int das16cs_ai_cmd(comedi_device * dev, comedi_subdevice * s) { return -EINVAL; } -static int das16cs_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int das16cs_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -344,135 +348,149 @@ static int das16cs_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SPEED 10000 /* in nanoseconds */ +#define MAX_SPEED 10000 /* in nanoseconds */ #define MIN_SPEED 1000000000 /* in nanoseconds */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } - if(cmd->scan_begin_arg>MIN_SPEED){ - cmd->scan_begin_arg=MIN_SPEED; + if (cmd->scan_begin_arg > MIN_SPEED) { + cmd->scan_begin_arg = MIN_SPEED; err++; } - }else{ + } 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; + if (cmd->scan_begin_arg > 9) { + cmd->scan_begin_arg = 9; err++; } } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argconvert_arg=MAX_SPEED; + 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; + if (cmd->convert_arg > MIN_SPEED) { + cmd->convert_arg = MIN_SPEED; err++; } - }else{ + } else { /* external trigger */ /* see above */ - if(cmd->convert_arg>9){ - cmd->convert_arg=9; + 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; + 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; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0x00ffffff) { + cmd->stop_arg = 0x00ffffff; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { unsigned int div1, div2; - tmp=cmd->scan_begin_arg; + 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++; + &cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(cmd->convert_src==TRIG_TIMER){ + if (cmd->convert_src == TRIG_TIMER) { unsigned int div1, div2; - tmp=cmd->convert_arg; + 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_argconvert_arg*cmd->scan_end_arg){ - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; + &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; + if (err) + return 4; return 0; } -static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +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); @@ -480,7 +498,7 @@ static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * unsigned short d; int bit; - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { devpriv->ao_readback[chan] = data[i]; d = data[i]; @@ -488,14 +506,16 @@ static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * comedi_udelay(1); status1 = devpriv->status1 & ~0xf; - if(chan) status1 |= 0x0001; - else status1 |= 0x0008; + if (chan) + status1 |= 0x0001; + else + status1 |= 0x0008; /* printk("0x%04x\n",status1);*/ outw(status1, dev->iobase + 4); comedi_udelay(1); - for(bit=15;bit>=0;bit--){ + for (bit = 15; bit >= 0; bit--) { int b = (d >> bit) & 0x1; b <<= 1; /* printk("0x%04x\n",status1 | b | 0x0000);*/ @@ -515,12 +535,13 @@ static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * /* 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) +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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -531,36 +552,38 @@ static int das16cs_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * * 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) +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 (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; - outw(s->state,dev->iobase + 16); + 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); + 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) +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 chan = CR_CHAN(insn->chanspec); int bits; - if(chan<4)bits=0x0f; - else bits=0xf0; + if (chan < 4) + bits = 0x0f; + else + bits = 0xf0; - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: s->io_bits |= bits; break; @@ -568,7 +591,9 @@ static int das16cs_dio_insn_config(comedi_device *dev,comedi_subdevice *s, s->io_bits &= bits; break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: @@ -577,29 +602,26 @@ static int das16cs_dio_insn_config(comedi_device *dev,comedi_subdevice *s, } devpriv->status2 &= ~0x00c0; - devpriv->status2 |= (s->io_bits&0xf0)?0x0080:0; - devpriv->status2 |= (s->io_bits&0x0f)?0x0040:0; + devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0; + devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0; - outw(devpriv->status2,dev->iobase + 6); + outw(devpriv->status2, dev->iobase + 6); return insn->n; } -static int das16cs_timer_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +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) +static int das16cs_timer_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { return -EINVAL; } - - - /* PCMCIA stuff */ /*====================================================================== @@ -627,7 +649,7 @@ static int pc_debug = PCMCIA_DEBUG; module_param(pc_debug, int, 0644); #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)"; + "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 @@ -664,10 +686,10 @@ static void das16cs_pcmcia_detach(struct pcmcia_device *); static dev_info_t dev_info = "cb_das16_cs"; typedef struct local_info_t { - struct pcmcia_device *link; - dev_node_t node; - int stop; - struct bus_operations *bus; + struct pcmcia_device *link; + dev_node_t node; + int stop; + struct bus_operations *bus; } local_info_t; /*====================================================================== @@ -684,45 +706,45 @@ typedef struct local_info_t { static int das16cs_pcmcia_attach(struct pcmcia_device *link) { - local_info_t *local; + local_info_t *local; - DEBUG(0, "das16cs_pcmcia_attach()\n"); + DEBUG(0, "das16cs_pcmcia_attach()\n"); - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return -ENOMEM; - local->link = link; - link->priv = local; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; - /* Initialize the pcmcia_device structure */ - /* Interrupt setup */ - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; - link->irq.IRQInfo1 = IRQ_LEVEL_ID; - link->irq.Handler = NULL; + /* Initialize the pcmcia_device structure */ + /* Interrupt setup */ + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; + link->irq.IRQInfo1 = IRQ_LEVEL_ID; + link->irq.Handler = NULL; - link->conf.Attributes = 0; - link->conf.IntType = INT_MEMORY_AND_IO; + link->conf.Attributes = 0; + link->conf.IntType = INT_MEMORY_AND_IO; - cur_dev = link; + cur_dev = link; - das16cs_pcmcia_config(link); + das16cs_pcmcia_config(link); - return 0; -} /* das16cs_pcmcia_attach */ + return 0; +} /* das16cs_pcmcia_attach */ static void das16cs_pcmcia_detach(struct pcmcia_device *link) { DEBUG(0, "das16cs_pcmcia_detach(0x%p)\n", link); - if(link->dev_node) - { - ((local_info_t *)link->priv)->stop = 1; + if (link->dev_node) { + ((local_info_t *) link->priv)->stop = 1; das16cs_pcmcia_release(link); } /* This points to the parent local_info_t struct */ - if(link->priv) + if (link->priv) kfree(link->priv); -} /* das16cs_pcmcia_detach */ +} /* das16cs_pcmcia_detach */ static void das16cs_pcmcia_config(struct pcmcia_device *link) { @@ -736,108 +758,119 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link) DEBUG(0, "das16cs_pcmcia_config(0x%p)\n", link); /* - This reads the card's CONFIG tuple to find its configuration - registers. - */ + This reads the card's CONFIG tuple to find its configuration + registers. + */ tuple.DesiredTuple = CISTPL_CONFIG; tuple.Attributes = 0; tuple.TupleData = buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 0; last_fn = GetFirstTuple; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) + goto cs_failed; last_fn = GetTupleData; - if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) + goto cs_failed; last_fn = ParseTuple; - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) goto cs_failed; + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) + goto cs_failed; link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; /* - In this loop, we scan the CIS for configuration table entries, - each of which describes a valid card configuration, including - voltage, IO window, memory window, and interrupt settings. - - We make no assumptions about the card to be configured: we use - just the information available in the CIS. In an ideal world, - this would work for any PCMCIA card, but it requires a complete - and accurate CIS. In practice, a driver usually "knows" most of - these things without consulting the CIS, and most client drivers - will only use the CIS to fill in implementation-defined details. - */ + In this loop, we scan the CIS for configuration table entries, + each of which describes a valid card configuration, including + voltage, IO window, memory window, and interrupt settings. + + We make no assumptions about the card to be configured: we use + just the information available in the CIS. In an ideal world, + this would work for any PCMCIA card, but it requires a complete + and accurate CIS. In practice, a driver usually "knows" most of + these things without consulting the CIS, and most client drivers + will only use the CIS to fill in implementation-defined details. + */ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; last_fn = GetFirstTuple; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) + goto cs_failed; while (1) { - cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); - if(pcmcia_get_tuple_data(link, &tuple)) goto next_entry; - if(pcmcia_parse_tuple(link, &tuple, &parse)) goto next_entry; - - if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; - if (cfg->index == 0) goto next_entry; - link->conf.ConfigIndex = cfg->index; - - /* Does this card need audio output? */ + cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); + if (pcmcia_get_tuple_data(link, &tuple)) + goto next_entry; + if (pcmcia_parse_tuple(link, &tuple, &parse)) + goto next_entry; + + if (cfg->flags & CISTPL_CFTABLE_DEFAULT) + dflt = *cfg; + if (cfg->index == 0) + goto next_entry; + link->conf.ConfigIndex = cfg->index; + + /* Does this card need audio output? */ /* if (cfg->flags & CISTPL_CFTABLE_AUDIO) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } */ - /* Do we need to allocate an interrupt? */ - if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) - link->conf.Attributes |= CONF_ENABLE_IRQ; - - /* IO window settings */ - link->io.NumPorts1 = link->io.NumPorts2 = 0; - if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { - cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; - link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; - if (!(io->flags & CISTPL_IO_8BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; - if (!(io->flags & CISTPL_IO_16BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; - link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; - link->io.BasePort1 = io->win[0].base; - link->io.NumPorts1 = io->win[0].len; - if (io->nwin > 1) { - link->io.Attributes2 = link->io.Attributes1; - link->io.BasePort2 = io->win[1].base; - link->io.NumPorts2 = io->win[1].len; + /* Do we need to allocate an interrupt? */ + if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) + link->conf.Attributes |= CONF_ENABLE_IRQ; + + /* IO window settings */ + link->io.NumPorts1 = link->io.NumPorts2 = 0; + if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { + cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; + if (!(io->flags & CISTPL_IO_8BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; + if (!(io->flags & CISTPL_IO_16BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; + link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; + link->io.BasePort1 = io->win[0].base; + link->io.NumPorts1 = io->win[0].len; + if (io->nwin > 1) { + link->io.Attributes2 = link->io.Attributes1; + link->io.BasePort2 = io->win[1].base; + link->io.NumPorts2 = io->win[1].len; + } + /* This reserves IO space but doesn't actually enable it */ + if (pcmcia_request_io(link, &link->io)) + goto next_entry; } - /* This reserves IO space but doesn't actually enable it */ - if(pcmcia_request_io(link, &link->io)) goto next_entry; - } - /* If we got this far, we're cool! */ - break; + /* If we got this far, we're cool! */ + break; - next_entry: - last_fn = GetNextTuple; - if((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) goto cs_failed; + next_entry: + last_fn = GetNextTuple; + if ((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) + goto cs_failed; } /* - Allocate an interrupt line. Note that this does not assign a - handler to the interrupt, unless the 'Handler' member of the - irq structure is initialized. - */ - if (link->conf.Attributes & CONF_ENABLE_IRQ) - { + Allocate an interrupt line. Note that this does not assign a + handler to the interrupt, unless the 'Handler' member of the + irq structure is initialized. + */ + if (link->conf.Attributes & CONF_ENABLE_IRQ) { last_fn = RequestIRQ; - if((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) goto cs_failed; + if ((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) + goto cs_failed; } /* - This actually configures the PCMCIA socket -- setting up - the I/O windows and the interrupt mapping, and putting the - card and host interface into "Memory and IO" mode. - */ + This actually configures the PCMCIA socket -- setting up + the I/O windows and the interrupt mapping, and putting the + card and host interface into "Memory and IO" mode. + */ last_fn = RequestConfiguration; - if((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) goto cs_failed; + if ((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) + goto cs_failed; /* - At this point, the dev_node_t structure(s) need to be - initialized and arranged in a linked list at link->dev. - */ + At this point, the dev_node_t structure(s) need to be + initialized and arranged in a linked list at link->dev. + */ sprintf(dev->node.dev_name, "cb_das16_cs"); dev->node.major = dev->node.minor = 0; link->dev_node = &dev->node; @@ -849,24 +882,24 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link) printk(", irq %u", link->irq.AssignedIRQ); if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, - link->io.BasePort1+link->io.NumPorts1-1); + link->io.BasePort1 + link->io.NumPorts1 - 1); if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, - link->io.BasePort2+link->io.NumPorts2-1); + link->io.BasePort2 + link->io.NumPorts2 - 1); printk("\n"); return; -cs_failed: + cs_failed: cs_error(link, last_fn, last_ret); das16cs_pcmcia_release(link); -} /* das16cs_pcmcia_config */ +} /* das16cs_pcmcia_config */ static void das16cs_pcmcia_release(struct pcmcia_device *link) { DEBUG(0, "das16cs_pcmcia_release(0x%p)\n", link); pcmcia_disable_device(link); -} /* das16cs_pcmcia_release */ +} /* das16cs_pcmcia_release */ static int das16cs_pcmcia_suspend(struct pcmcia_device *link) { @@ -876,7 +909,7 @@ static int das16cs_pcmcia_suspend(struct pcmcia_device *link) local->stop = 1; return 0; -} /* das16cs_pcmcia_suspend */ +} /* das16cs_pcmcia_suspend */ static int das16cs_pcmcia_resume(struct pcmcia_device *link) { @@ -884,20 +917,19 @@ static int das16cs_pcmcia_resume(struct pcmcia_device *link) local->stop = 0; return 0; -} /* das16cs_pcmcia_resume */ +} /* das16cs_pcmcia_resume */ /*====================================================================*/ -static struct pcmcia_device_id das16cs_id_table[] = -{ +static struct pcmcia_device_id das16cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039), PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009), PCMCIA_DEVICE_NULL }; + MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table); -struct pcmcia_driver das16cs_driver = -{ +struct pcmcia_driver das16cs_driver = { .probe = das16cs_pcmcia_attach, .remove = das16cs_pcmcia_detach, .suspend = das16cs_pcmcia_suspend, @@ -905,8 +937,8 @@ struct pcmcia_driver das16cs_driver = .id_table = das16cs_id_table, .owner = THIS_MODULE, .drv = { - .name = dev_info, - }, + .name = dev_info, + }, }; static int __init init_das16cs_pcmcia_cs(void) @@ -927,7 +959,7 @@ int __init init_module(void) int ret; ret = init_das16cs_pcmcia_cs(); - if(ret < 0) + if (ret < 0) return ret; return comedi_driver_register(&driver_das16cs); diff --git a/comedi/drivers/cb_pcidas.c b/comedi/drivers/cb_pcidas.c index cae0fe09..c38d0410 100644 --- a/comedi/drivers/cb_pcidas.c +++ b/comedi/drivers/cb_pcidas.c @@ -70,12 +70,12 @@ analog triggering on 1602 series #include "comedi_pci.h" #include "comedi_fc.h" -#undef CB_PCIDAS_DEBUG // disable debugging code -//#define CB_PCIDAS_DEBUG // enable debugging code +#undef CB_PCIDAS_DEBUG // disable debugging code +//#define CB_PCIDAS_DEBUG // enable debugging code // PCI vendor number of ComputerBoards/MeasurementComputing #define PCI_VENDOR_ID_CB 0x1307 -#define TIMER_BASE 100 // 10MHz master clock +#define TIMER_BASE 100 // 10MHz master clock #define AI_BUFFER_SIZE 1024 // maximum fifo size of any supported board #define AO_BUFFER_SIZE 1024 // maximum fifo size of any supported board #define NUM_CHANNELS_8800 8 @@ -99,44 +99,44 @@ analog triggering on 1602 series /* Control/Status registers */ #define INT_ADCFIFO 0 // INTERRUPT / ADC FIFO register -#define INT_EOS 0x1 // interrupt end of scan -#define INT_FHF 0x2 // interrupt fifo half full -#define INT_FNE 0x3 // interrupt fifo not empty -#define INT_MASK 0x3 // mask of interrupt select bits -#define INTE 0x4 // interrupt enable -#define DAHFIE 0x8 // dac half full interrupt enable -#define EOAIE 0x10 // end of aquisition interrupt enable -#define DAHFI 0x20 // dac half full read status / write interrupt clear -#define EOAI 0x40 // read end of acq. interrupt status / write clear -#define INT 0x80 // read interrupt status / write clear -#define EOBI 0x200 // read end of burst interrupt status -#define ADHFI 0x400 // read half-full interrupt status -#define ADNEI 0x800 // read fifo not empty interrupt latch status -#define ADNE 0x1000 // read, fifo not empty (realtime, not latched) status +#define INT_EOS 0x1 // interrupt end of scan +#define INT_FHF 0x2 // interrupt fifo half full +#define INT_FNE 0x3 // interrupt fifo not empty +#define INT_MASK 0x3 // mask of interrupt select bits +#define INTE 0x4 // interrupt enable +#define DAHFIE 0x8 // dac half full interrupt enable +#define EOAIE 0x10 // end of aquisition interrupt enable +#define DAHFI 0x20 // dac half full read status / write interrupt clear +#define EOAI 0x40 // read end of acq. interrupt status / write clear +#define INT 0x80 // read interrupt status / write clear +#define EOBI 0x200 // read end of burst interrupt status +#define ADHFI 0x400 // read half-full interrupt status +#define ADNEI 0x800 // read fifo not empty interrupt latch status +#define ADNE 0x1000 // read, fifo not empty (realtime, not latched) status #define DAEMIE 0x1000 // write, dac empty interrupt enable -#define LADFUL 0x2000 // read fifo overflow / write clear -#define DAEMI 0x4000 // dac fifo empty interrupt status / write clear +#define LADFUL 0x2000 // read fifo overflow / write clear +#define DAEMI 0x4000 // dac fifo empty interrupt status / write clear #define ADCMUX_CONT 2 // ADC CHANNEL MUX AND CONTROL register #define BEGIN_SCAN(x) ((x) & 0xf) #define END_SCAN(x) (((x) & 0xf) << 4) #define GAIN_BITS(x) (((x) & 0x3) << 8) -#define UNIP 0x800 // Analog front-end unipolar for range -#define SE 0x400 // Inputs in single-ended mode +#define UNIP 0x800 // Analog front-end unipolar for range +#define SE 0x400 // Inputs in single-ended mode #define PACER_MASK 0x3000 // pacer source bits #define PACER_INT 0x1000 // internal pacer #define PACER_EXT_FALL 0x2000 // external falling edge #define PACER_EXT_RISE 0x3000 // external rising edge -#define EOC 0x4000 // adc not busy +#define EOC 0x4000 // adc not busy -#define TRIG_CONTSTAT 4 // TRIGGER CONTROL/STATUS register +#define TRIG_CONTSTAT 4 // TRIGGER CONTROL/STATUS register #define SW_TRIGGER 0x1 // software start trigger #define EXT_TRIGGER 0x2 // external start trigger #define ANALOG_TRIGGER 0x3 // external analog trigger #define TRIGGER_MASK 0x3 // mask of bits that determine start trigger -#define TGEN 0x10 // enable external start trigger -#define BURSTE 0x20 // burst mode enable -#define XTRCL 0x80 // clear external trigger +#define TGEN 0x10 // enable external start trigger +#define BURSTE 0x20 // burst mode enable +#define XTRCL 0x80 // clear external trigger #define CALIBRATION_REG 6 // CALIBRATION register #define SELECT_8800_BIT 0x100 // select 8800 caldac @@ -146,23 +146,22 @@ analog triggering on 1602 series #define CAL_EN_BIT 0x4000 // read calibration source instead of analog input channel 0 #define SERIAL_DATA_IN_BIT 0x8000 // serial data stream going to 8800 and 7376 -#define DAC_CSR 0x8 // dac control and status register -enum dac_csr_bits -{ - DACEN = 0x2, // dac enable +#define DAC_CSR 0x8 // dac control and status register +enum dac_csr_bits { + DACEN = 0x2, // dac enable DAC_MODE_UPDATE_BOTH = 0x80, // update both dacs when dac0 is written }; -static inline unsigned int DAC_RANGE( unsigned int channel, unsigned int range) +static inline unsigned int DAC_RANGE(unsigned int channel, unsigned int range) { - return ( range & 0x3 ) << ( 8 + 2 * ( channel & 0x1 ) ); + return (range & 0x3) << (8 + 2 * (channel & 0x1)); } -static inline unsigned int DAC_RANGE_MASK( unsigned int channel ) +static inline unsigned int DAC_RANGE_MASK(unsigned int channel) { - return 0x3 << ( 8 + 2 * ( channel & 0x1 ) ); + return 0x3 << (8 + 2 * (channel & 0x1)); }; + // bits for 1602 series only -enum dac_csr_bits_1602 -{ +enum dac_csr_bits_1602 { DAC_EMPTY = 0x1, // dac fifo empty, read, write clear DAC_START = 0x4, // start/arm dac fifo operations DAC_PACER_MASK = 0x18, // bits that set dac pacer source @@ -170,13 +169,13 @@ enum dac_csr_bits_1602 DAC_PACER_EXT_FALL = 0x10, // dac external pacing, falling edge DAC_PACER_EXT_RISE = 0x18, // dac external pacing, rising edge }; -static inline unsigned int DAC_CHAN_EN( unsigned int channel ) +static inline unsigned int DAC_CHAN_EN(unsigned int channel) { - return 1 << ( 5 + ( channel & 0x1 ) ); // enable channel 0 or 1 + return 1 << (5 + (channel & 0x1)); // enable channel 0 or 1 }; /* analog input fifo */ -#define ADCDATA 0 // ADC DATA register +#define ADCDATA 0 // ADC DATA register #define ADCFIFOCLR 2 // ADC FIFO CLEAR // pacer, counter, dio registers @@ -185,214 +184,211 @@ static inline unsigned int DAC_CHAN_EN( unsigned int channel ) #define DAC8254 8 // analog output registers for 100x, 1200 series -static inline unsigned int DAC_DATA_REG( unsigned int channel ) +static inline unsigned int DAC_DATA_REG(unsigned int channel) { - return 2 * ( channel & 0x1 ); + return 2 * (channel & 0x1); } + /* analog output registers for 1602 series*/ -#define DACDATA 0 // DAC DATA register +#define DACDATA 0 // DAC DATA register #define DACFIFOCLR 2 // DAC FIFO CLEAR // bit in hexadecimal representation of range index that indicates unipolar input range #define IS_UNIPOLAR 0x4 // analog input ranges for most boards -static const comedi_lrange cb_pcidas_ranges = -{ +static const comedi_lrange cb_pcidas_ranges = { 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25) + } }; // pci-das1001 input ranges -static const comedi_lrange cb_pcidas_alt_ranges = -{ +static const comedi_lrange cb_pcidas_alt_ranges = { 8, { - BIP_RANGE(10), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.01), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01) - } + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01) + } }; // analog output ranges -static const comedi_lrange cb_pcidas_ao_ranges = -{ +static const comedi_lrange cb_pcidas_ao_ranges = { 4, { - BIP_RANGE(5), - BIP_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(10), - } + BIP_RANGE(5), + BIP_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(10), + } }; -enum trimpot_model -{ +enum trimpot_model { AD7376, AD8402, }; -typedef struct cb_pcidas_board_struct -{ +typedef struct cb_pcidas_board_struct { const char *name; unsigned short device_id; int ai_se_chans; // Inputs in single-ended mode int ai_diff_chans; // Inputs in differential mode - int ai_bits; // analog input resolution - int ai_speed; // fastest conversion period in ns - int ao_nchan; // number of analog out channels + int ai_bits; // analog input resolution + int ai_speed; // fastest conversion period in ns + int ao_nchan; // number of analog out channels int has_ao_fifo; // analog output has fifo int ao_scan_speed; // analog output speed for 1602 series (for a scan, not conversion) - int fifo_size; // number of samples fifo can hold + int fifo_size; // number of samples fifo can hold const comedi_lrange *ranges; enum trimpot_model trimpot; - unsigned has_dac08 : 1; + unsigned has_dac08:1; } cb_pcidas_board; -static const cb_pcidas_board cb_pcidas_boards[] = -{ +static const cb_pcidas_board cb_pcidas_boards[] = { { - name: "pci-das1602/16", - device_id: 0x1, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 2, - has_ao_fifo: 1, - ao_scan_speed: 10000, - fifo_size: 512, - ranges: &cb_pcidas_ranges, - trimpot: AD8402, - has_dac08: 1, - }, + name: "pci-das1602/16", + device_id:0x1, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 16, + ai_speed:5000, + ao_nchan:2, + has_ao_fifo:1, + ao_scan_speed:10000, + fifo_size:512, + ranges: &cb_pcidas_ranges, + trimpot: AD8402, + has_dac08:1, + }, { - name: "pci-das1200", - device_id: 0xF, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 3200, - ao_nchan: 2, - has_ao_fifo: 0, - fifo_size: 1024, - ranges: &cb_pcidas_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1200", + device_id:0xF, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:3200, + ao_nchan:2, + has_ao_fifo:0, + fifo_size:1024, + ranges: &cb_pcidas_ranges, + trimpot: AD7376, + has_dac08:0, + }, { - name: "pci-das1602/12", - device_id: 0x10, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 3200, - ao_nchan: 2, - has_ao_fifo: 1, - ao_scan_speed: 4000, - fifo_size: 1024, - ranges: &cb_pcidas_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1602/12", + device_id:0x10, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:3200, + ao_nchan:2, + has_ao_fifo:1, + ao_scan_speed:4000, + fifo_size:1024, + ranges: &cb_pcidas_ranges, + trimpot: AD7376, + has_dac08:0, + }, { - name: "pci-das1200/jr", - device_id: 0x19, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 3200, - ao_nchan: 0, - has_ao_fifo: 0, - fifo_size: 1024, - ranges: &cb_pcidas_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1200/jr", + device_id:0x19, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:3200, + ao_nchan:0, + has_ao_fifo:0, + fifo_size:1024, + ranges: &cb_pcidas_ranges, + trimpot: AD7376, + has_dac08:0, + }, { - name: "pci-das1602/16/jr", - device_id: 0x1C, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 0, - has_ao_fifo: 0, - fifo_size: 512, - ranges: &cb_pcidas_ranges, - trimpot: AD8402, - has_dac08: 1, - }, + name: "pci-das1602/16/jr", + device_id:0x1C, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 16, + ai_speed:5000, + ao_nchan:0, + has_ao_fifo:0, + fifo_size:512, + ranges: &cb_pcidas_ranges, + trimpot: AD8402, + has_dac08:1, + }, { - name: "pci-das1000", - device_id: 0x4C, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 4000, - ao_nchan: 0, - has_ao_fifo: 0, - fifo_size: 1024, - ranges: &cb_pcidas_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1000", + device_id:0x4C, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:4000, + ao_nchan:0, + has_ao_fifo:0, + fifo_size:1024, + ranges: &cb_pcidas_ranges, + trimpot: AD7376, + has_dac08:0, + }, { - name: "pci-das1001", - device_id: 0x1a, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 6800, - ao_nchan: 2, - has_ao_fifo: 0, - fifo_size: 1024, - ranges: &cb_pcidas_alt_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1001", + device_id:0x1a, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:6800, + ao_nchan:2, + has_ao_fifo:0, + fifo_size:1024, + ranges: &cb_pcidas_alt_ranges, + trimpot: AD7376, + has_dac08:0, + }, { - name: "pci-das1002", - device_id: 0x1b, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 12, - ai_speed: 6800, - ao_nchan: 2, - has_ao_fifo: 0, - fifo_size: 1024, - ranges: &cb_pcidas_ranges, - trimpot: AD7376, - has_dac08: 0, - }, + name: "pci-das1002", + device_id:0x1b, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 12, + ai_speed:6800, + ao_nchan:2, + has_ao_fifo:0, + fifo_size:1024, + ranges: &cb_pcidas_ranges, + trimpot: AD7376, + has_dac08:0, + }, }; + // Number of boards in cb_pcidas_boards #define N_BOARDS (sizeof(cb_pcidas_boards) / sizeof(cb_pcidas_board)) static struct pci_device_id cb_pcidas_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_CB, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x000f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x001c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x004c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x001a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x001b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_CB, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x000f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0019, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x001c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x004c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x001a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x001b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table); /* @@ -403,8 +399,7 @@ MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct -{ +typedef struct { /* would be useful for a PCI device */ struct pci_dev *pci_dev; // base addresses @@ -420,15 +415,15 @@ typedef struct volatile unsigned int adc_fifo_bits; // bits to write to interupt/adcfifo register volatile unsigned int s5933_intcsr_bits; // bits to write to amcc s5933 interrupt control/status register volatile unsigned int ao_control_bits; // bits to write to ao control and status register - sampl_t ai_buffer[ AI_BUFFER_SIZE ]; - sampl_t ao_buffer[ AO_BUFFER_SIZE ]; + sampl_t ai_buffer[AI_BUFFER_SIZE]; + sampl_t ao_buffer[AO_BUFFER_SIZE]; // divisors of master clock for analog output pacing unsigned int ao_divisor1; unsigned int ao_divisor2; volatile unsigned int ao_count; // number of analog output samples remaining int ao_value[2]; // remember what the analog outputs are set to, to allow readback - unsigned int caldac_value[ NUM_CHANNELS_8800 ]; // for readback of caldac - unsigned int trimpot_value[ NUM_CHANNELS_8402 ]; // for readback of trimpot + unsigned int caldac_value[NUM_CHANNELS_8800]; // for readback of caldac + unsigned int trimpot_value[NUM_CHANNELS_8402]; // for readback of trimpot unsigned int dac08_value; unsigned int calibration_source; } cb_pcidas_private; @@ -445,76 +440,86 @@ typedef struct * the board, and also about the kernel module that contains * the device code. */ -static int cb_pcidas_attach(comedi_device *dev,comedi_devconfig *it); -static int cb_pcidas_detach(comedi_device *dev); -static comedi_driver driver_cb_pcidas={ - driver_name: "cb_pcidas", - module: THIS_MODULE, - attach: cb_pcidas_attach, - detach: cb_pcidas_detach, +static int cb_pcidas_attach(comedi_device * dev, comedi_devconfig * it); +static int cb_pcidas_detach(comedi_device * dev); +static comedi_driver driver_cb_pcidas = { + driver_name:"cb_pcidas", + module:THIS_MODULE, + attach:cb_pcidas_attach, + detach:cb_pcidas_detach, }; -static int cb_pcidas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ai_config_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcidas_ao_nofifo_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcidas_ao_fifo_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcidas_ao_readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcidas_ai_cmd(comedi_device *dev,comedi_subdevice *s); -static int cb_pcidas_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int cb_pcidas_ao_cmd(comedi_device *dev,comedi_subdevice *s); -static int cb_pcidas_ao_inttrig(comedi_device *dev, comedi_subdevice *subdev, unsigned int trig_num); -static int cb_pcidas_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); +static int cb_pcidas_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ai_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcidas_ao_nofifo_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcidas_ao_fifo_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcidas_ao_readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcidas_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int cb_pcidas_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int cb_pcidas_ao_cmd(comedi_device * dev, comedi_subdevice * s); +static int cb_pcidas_ao_inttrig(comedi_device * dev, comedi_subdevice * subdev, + unsigned int trig_num); +static int cb_pcidas_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); static irqreturn_t cb_pcidas_interrupt(int irq, void *d PT_REGS_ARG); -static void handle_ao_interrupt(comedi_device *dev, unsigned int status); -static int cb_pcidas_cancel(comedi_device *dev, comedi_subdevice *s); -static int cb_pcidas_ao_cancel(comedi_device *dev, comedi_subdevice *s); -static void cb_pcidas_load_counters(comedi_device *dev, unsigned int *ns, int round_flags); -static int eeprom_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int caldac_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int caldac_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int trimpot_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int cb_pcidas_trimpot_write( comedi_device *dev, - unsigned int channel, lsampl_t value ); -static int trimpot_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int dac08_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int dac08_write( comedi_device *dev, lsampl_t value ); -static int dac08_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ); -static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t value); -static int trimpot_7376_write(comedi_device *dev, uint8_t value); -static int trimpot_8402_write(comedi_device *dev, unsigned int channel, uint8_t value); -static int nvram_read( comedi_device *dev, unsigned int address, uint8_t *data ); - -static inline unsigned int cal_enable_bits( comedi_device *dev ) +static void handle_ao_interrupt(comedi_device * dev, unsigned int status); +static int cb_pcidas_cancel(comedi_device * dev, comedi_subdevice * s); +static int cb_pcidas_ao_cancel(comedi_device * dev, comedi_subdevice * s); +static void cb_pcidas_load_counters(comedi_device * dev, unsigned int *ns, + int round_flags); +static int eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int caldac_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int caldac_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int trimpot_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcidas_trimpot_write(comedi_device * dev, unsigned int channel, + lsampl_t value); +static int trimpot_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dac08_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dac08_write(comedi_device * dev, lsampl_t value); +static int dac08_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int caldac_8800_write(comedi_device * dev, unsigned int address, + uint8_t value); +static int trimpot_7376_write(comedi_device * dev, uint8_t value); +static int trimpot_8402_write(comedi_device * dev, unsigned int channel, + uint8_t value); +static int nvram_read(comedi_device * dev, unsigned int address, + uint8_t * data); + +static inline unsigned int cal_enable_bits(comedi_device * dev) { - return CAL_EN_BIT | CAL_SRC_BITS( devpriv->calibration_source ); + return CAL_EN_BIT | CAL_SRC_BITS(devpriv->calibration_source); } /* * Attach is called by the Comedi core to configure the driver * for a particular board. */ -static int cb_pcidas_attach(comedi_device *dev, comedi_devconfig *it) +static int cb_pcidas_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - struct pci_dev* pcidev; + struct pci_dev *pcidev; int index; int i; - printk("comedi%d: cb_pcidas: ",dev->minor); + printk("comedi%d: cb_pcidas: ", dev->minor); /* * Allocate the private structure area. */ - if(alloc_private(dev,sizeof(cb_pcidas_private))<0) + if (alloc_private(dev, sizeof(cb_pcidas_private)) < 0) return -ENOMEM; /* @@ -522,24 +527,22 @@ static int cb_pcidas_attach(comedi_device *dev, comedi_devconfig *it) */ printk("\n"); - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? - if(pcidev->vendor != PCI_VENDOR_ID_CB) + if (pcidev->vendor != PCI_VENDOR_ID_CB) continue; // loop through cards supported by this driver - for(index = 0; index < N_BOARDS; index++) - { - if(cb_pcidas_boards[index].device_id != pcidev->device) + for (index = 0; index < N_BOARDS; index++) { + if (cb_pcidas_boards[index].device_id != pcidev->device) continue; // was a particular bus/slot requested? - if(it->options[0] || it->options[1]) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if(pcidev->bus->number != it->options[0] || - PCI_SLOT(pcidev->devfn) != it->options[1]) - { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } @@ -553,7 +556,7 @@ static int cb_pcidas_attach(comedi_device *dev, comedi_devconfig *it) "requested position\n"); return -EIO; -found: + found: printk("Found %s on bus %i, slot %i\n", cb_pcidas_boards[index].name, pcidev->bus->number, PCI_SLOT(pcidev->devfn)); @@ -561,8 +564,7 @@ found: /* * Enable PCI device and reserve I/O ports. */ - if(comedi_pci_enable(pcidev, "cb_pcidas")) - { + if (comedi_pci_enable(pcidev, "cb_pcidas")) { printk(" Failed to enable PCI device and request regions\n"); return -EIO; } @@ -570,21 +572,25 @@ found: * Initialize devpriv->control_status and devpriv->adc_fifo to point to * their base address. */ - devpriv->s5933_config = pci_resource_start(devpriv->pci_dev, S5933_BADRINDEX); - devpriv->control_status = pci_resource_start(devpriv->pci_dev, CONT_STAT_BADRINDEX); - devpriv->adc_fifo = pci_resource_start(devpriv->pci_dev, ADC_FIFO_BADRINDEX); - devpriv->pacer_counter_dio = pci_resource_start(devpriv->pci_dev, PACER_BADRINDEX); - if(thisboard->ao_nchan) - { - devpriv->ao_registers = pci_resource_start(devpriv->pci_dev, AO_BADRINDEX); + devpriv->s5933_config = + pci_resource_start(devpriv->pci_dev, S5933_BADRINDEX); + devpriv->control_status = + pci_resource_start(devpriv->pci_dev, CONT_STAT_BADRINDEX); + devpriv->adc_fifo = + pci_resource_start(devpriv->pci_dev, ADC_FIFO_BADRINDEX); + devpriv->pacer_counter_dio = + pci_resource_start(devpriv->pci_dev, PACER_BADRINDEX); + if (thisboard->ao_nchan) { + devpriv->ao_registers = + pci_resource_start(devpriv->pci_dev, AO_BADRINDEX); } - // disable and clear interrupts on amcc s5933 - outl(INTCSR_INBOX_INTR_STATUS, devpriv->s5933_config + AMCC_OP_REG_INTCSR); + outl(INTCSR_INBOX_INTR_STATUS, + devpriv->s5933_config + AMCC_OP_REG_INTCSR); // get irq - if(comedi_request_irq(devpriv->pci_dev->irq, cb_pcidas_interrupt, IRQF_SHARED, "cb_pcidas", dev )) - { + if (comedi_request_irq(devpriv->pci_dev->irq, cb_pcidas_interrupt, + IRQF_SHARED, "cb_pcidas", dev)) { printk(" unable to allocate irq %d\n", devpriv->pci_dev->irq); return -EINVAL; } @@ -596,7 +602,7 @@ found: /* * Allocate the subdevice structures. */ - if(alloc_subdevices(dev, 7) < 0) + if (alloc_subdevices(dev, 7) < 0) return -ENOMEM; s = dev->subdevices + 0; @@ -617,8 +623,7 @@ found: /* analog output subdevice */ s = dev->subdevices + 1; - if(thisboard->ao_nchan) - { + if (thisboard->ao_nchan) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; s->n_chan = thisboard->ao_nchan; @@ -626,20 +631,17 @@ found: s->maxdata = (1 << thisboard->ai_bits) - 1; s->range_table = &cb_pcidas_ao_ranges; s->insn_read = cb_pcidas_ao_readback_insn; - if(thisboard->has_ao_fifo) - { + if (thisboard->has_ao_fifo) { dev->write_subdev = s; s->subdev_flags |= SDF_CMD_WRITE; s->insn_write = cb_pcidas_ao_fifo_winsn; s->do_cmdtest = cb_pcidas_ao_cmdtest; s->do_cmd = cb_pcidas_ao_cmd; s->cancel = cb_pcidas_ao_cancel; - }else - { + } else { s->insn_write = cb_pcidas_ao_nofifo_winsn; } - }else - { + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -663,52 +665,51 @@ found: s->maxdata = 0xff; s->insn_read = caldac_read_insn; s->insn_write = caldac_write_insn; - for( i = 0; i < s->n_chan; i++ ) - caldac_8800_write( dev, i, s->maxdata / 2 ); + for (i = 0; i < s->n_chan; i++) + caldac_8800_write(dev, i, s->maxdata / 2); // trim potentiometer s = dev->subdevices + 5; s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; - if( thisboard->trimpot == AD7376 ) - { + if (thisboard->trimpot == AD7376) { s->n_chan = NUM_CHANNELS_7376; s->maxdata = 0x7f; - }else - { + } else { s->n_chan = NUM_CHANNELS_8402; s->maxdata = 0xff; } s->insn_read = trimpot_read_insn; s->insn_write = trimpot_write_insn; - for( i = 0; i < s->n_chan; i++ ) - cb_pcidas_trimpot_write( dev, i, s->maxdata / 2 ); + for (i = 0; i < s->n_chan; i++) + cb_pcidas_trimpot_write(dev, i, s->maxdata / 2); // dac08 caldac s = dev->subdevices + 6; - if( thisboard->has_dac08 ) - { + if (thisboard->has_dac08) { s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = NUM_CHANNELS_DAC08; s->insn_read = dac08_read_insn; s->insn_write = dac08_write_insn; s->maxdata = 0xff; - dac08_write( dev, s->maxdata / 2 ); - }else + dac08_write(dev, s->maxdata / 2); + } else s->type = COMEDI_SUBD_UNUSED; // make sure mailbox 4 is empty - inl(devpriv->s5933_config + AMCC_OP_REG_IMB4 ); + inl(devpriv->s5933_config + AMCC_OP_REG_IMB4); /* Set bits to enable incoming mailbox interrupts on amcc s5933. */ - devpriv->s5933_intcsr_bits = INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) | INTCSR_INBOX_FULL_INT; + devpriv->s5933_intcsr_bits = + INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) | + INTCSR_INBOX_FULL_INT; // clear and enable interrupt on amcc s5933 - outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, devpriv->s5933_config + AMCC_OP_REG_INTCSR); + outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, + devpriv->s5933_config + AMCC_OP_REG_INTCSR); return 1; } - /* * cb_pcidas_detach is called to deconfigure a device. It should deallocate * resources. @@ -717,29 +718,28 @@ found: * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int cb_pcidas_detach(comedi_device *dev) +static int cb_pcidas_detach(comedi_device * dev) { - printk("comedi%d: cb_pcidas: remove\n",dev->minor); + printk("comedi%d: cb_pcidas: remove\n", dev->minor); - if(devpriv) - { - if(devpriv->s5933_config) - { + if (devpriv) { + if (devpriv->s5933_config) { // disable and clear interrupts on amcc s5933 - outl(INTCSR_INBOX_INTR_STATUS, devpriv->s5933_config + AMCC_OP_REG_INTCSR); + outl(INTCSR_INBOX_INTR_STATUS, + devpriv->s5933_config + AMCC_OP_REG_INTCSR); #ifdef CB_PCIDAS_DEBUG - rt_printk("detaching, incsr is 0x%x\n", inl(devpriv->s5933_config + AMCC_OP_REG_INTCSR)); + rt_printk("detaching, incsr is 0x%x\n", + inl(devpriv->s5933_config + + AMCC_OP_REG_INTCSR)); #endif } } - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 2); - if(devpriv && devpriv->pci_dev) - { - if(devpriv->s5933_config) - { + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 2); + if (devpriv && devpriv->pci_dev) { + if (devpriv->s5933_config) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -752,33 +752,30 @@ static int cb_pcidas_detach(comedi_device *dev) * "instructions" read/write data in "one-shot" or "software-triggered" * mode. */ -static int cb_pcidas_ai_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int cb_pcidas_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; unsigned int bits; static const int timeout = 10000; int channel; // enable calibration input if appropriate - if( insn->chanspec & CR_ALT_SOURCE ) - { - outw( cal_enable_bits( dev ), + if (insn->chanspec & CR_ALT_SOURCE) { + outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); channel = 0; - }else - { - outw( 0, devpriv->control_status + CALIBRATION_REG); + } else { + outw(0, devpriv->control_status + CALIBRATION_REG); channel = CR_CHAN(insn->chanspec); } // set mux limits and gain bits = BEGIN_SCAN(channel) | - END_SCAN(channel) | - GAIN_BITS(CR_RANGE(insn->chanspec)); + END_SCAN(channel) | GAIN_BITS(CR_RANGE(insn->chanspec)); // set unipolar/bipolar - if(CR_RANGE(insn->chanspec) & IS_UNIPOLAR) + if (CR_RANGE(insn->chanspec) & IS_UNIPOLAR) bits |= UNIP; // set singleended/differential - if(CR_AREF(insn->chanspec) != AREF_DIFF) + if (CR_AREF(insn->chanspec) != AREF_DIFF) bits |= SE; outw(bits, devpriv->control_status + ADCMUX_CONT); @@ -786,19 +783,17 @@ static int cb_pcidas_ai_rinsn(comedi_device *dev, comedi_subdevice *s, outw(0, devpriv->adc_fifo + ADCFIFOCLR); /* convert n samples */ - for (n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* trigger conversion */ outw(0, devpriv->adc_fifo + ADCDATA); /* wait for conversion to end */ /* return -ETIMEDOUT if there is a timeout */ - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { if (inw(devpriv->control_status + ADCMUX_CONT) & EOC) break; } - if(i == timeout) + if (i == timeout) return -ETIMEDOUT; /* read data */ @@ -809,14 +804,13 @@ static int cb_pcidas_ai_rinsn(comedi_device *dev, comedi_subdevice *s, return n; } -static int ai_config_calibration_source( comedi_device *dev, lsampl_t *data ) +static int ai_config_calibration_source(comedi_device * dev, lsampl_t * data) { static const int num_calibration_sources = 8; lsampl_t source = data[1]; - if(source >= num_calibration_sources) - { - printk( "invalid calibration source: %i\n", source ); + if (source >= num_calibration_sources) { + printk("invalid calibration source: %i\n", source); return -EINVAL; } @@ -825,37 +819,38 @@ static int ai_config_calibration_source( comedi_device *dev, lsampl_t *data ) return 2; } -static int ai_config_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ai_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int id = data[0]; - switch( id ) - { - case INSN_CONFIG_ALT_SOURCE: - return ai_config_calibration_source( dev, data ); - break; - default: - return -EINVAL; - break; + switch (id) { + case INSN_CONFIG_ALT_SOURCE: + return ai_config_calibration_source(dev, data); + break; + default: + return -EINVAL; + break; } return -EINVAL; } // analog output insn for pcidas-1000 and 1200 series -static int cb_pcidas_ao_nofifo_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int cb_pcidas_ao_nofifo_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel; unsigned long flags; // set channel and range channel = CR_CHAN(insn->chanspec); - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - devpriv->ao_control_bits &= ~DAC_MODE_UPDATE_BOTH & ~DAC_RANGE_MASK(channel); - devpriv->ao_control_bits |= DACEN | DAC_RANGE(channel, CR_RANGE(insn->chanspec)); - outw( devpriv->ao_control_bits, devpriv->control_status + DAC_CSR ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + devpriv->ao_control_bits &= + ~DAC_MODE_UPDATE_BOTH & ~DAC_RANGE_MASK(channel); + devpriv->ao_control_bits |= + DACEN | DAC_RANGE(channel, CR_RANGE(insn->chanspec)); + outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // remember value for readback devpriv->ao_value[channel] = data[0]; @@ -866,8 +861,8 @@ static int cb_pcidas_ao_nofifo_winsn(comedi_device *dev, comedi_subdevice *s, } // analog output insn for pcidas-1602 series -static int cb_pcidas_ao_fifo_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int cb_pcidas_ao_fifo_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel; unsigned long flags; @@ -878,12 +873,14 @@ static int cb_pcidas_ao_fifo_winsn(comedi_device *dev, comedi_subdevice *s, // set channel and range channel = CR_CHAN(insn->chanspec); comedi_spin_lock_irqsave(&dev->spinlock, flags); - devpriv->ao_control_bits &= ~DAC_CHAN_EN(0) & ~DAC_CHAN_EN(1) & ~DAC_RANGE_MASK(channel) & + devpriv->ao_control_bits &= + ~DAC_CHAN_EN(0) & ~DAC_CHAN_EN(1) & ~DAC_RANGE_MASK(channel) & ~DAC_PACER_MASK; - devpriv->ao_control_bits |= DACEN | DAC_RANGE(channel, CR_RANGE(insn->chanspec)) | - DAC_CHAN_EN(channel) | DAC_START; + devpriv->ao_control_bits |= + DACEN | DAC_RANGE(channel, + CR_RANGE(insn->chanspec)) | DAC_CHAN_EN(channel) | DAC_START; outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // remember value for readback devpriv->ao_value[channel] = data[0]; @@ -895,121 +892,125 @@ static int cb_pcidas_ao_fifo_winsn(comedi_device *dev, comedi_subdevice *s, // analog output readback insn // XXX loses track of analog output value back after an analog ouput command is executed -static int cb_pcidas_ao_readback_insn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int cb_pcidas_ao_readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->ao_value[CR_CHAN(insn->chanspec)]; return 1; } -static int eeprom_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { uint8_t nvram_data; int retval; - retval = nvram_read( dev, CR_CHAN( insn->chanspec ), &nvram_data ); - if( retval < 0 ) + retval = nvram_read(dev, CR_CHAN(insn->chanspec), &nvram_data); + if (retval < 0) return retval; - data[ 0 ] = nvram_data; + data[0] = nvram_data; return 1; } -static int caldac_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int caldac_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - const unsigned int channel = CR_CHAN( insn->chanspec ); + const unsigned int channel = CR_CHAN(insn->chanspec); - return caldac_8800_write( dev, channel, data[0] ); + return caldac_8800_write(dev, channel, data[0]); } -static int caldac_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int caldac_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[ 0 ] = devpriv->caldac_value[ CR_CHAN( insn->chanspec ) ]; + data[0] = devpriv->caldac_value[CR_CHAN(insn->chanspec)]; return 1; } /* 1602/16 pregain offset */ -static int dac08_write( comedi_device *dev, lsampl_t value ) +static int dac08_write(comedi_device * dev, lsampl_t value) { - if( devpriv->dac08_value == value ) return 1; + if (devpriv->dac08_value == value) + return 1; devpriv->dac08_value = value; - outw( cal_enable_bits( dev ) | ( value & 0xff ), devpriv->control_status + CALIBRATION_REG ); - comedi_udelay( 1 ); - outw( cal_enable_bits( dev ) | SELECT_DAC08_BIT | ( value & 0xff ), devpriv->control_status + CALIBRATION_REG ); - comedi_udelay( 1 ); - outw( cal_enable_bits( dev ) | ( value & 0xff ), devpriv->control_status + CALIBRATION_REG ); - comedi_udelay( 1 ); + outw(cal_enable_bits(dev) | (value & 0xff), + devpriv->control_status + CALIBRATION_REG); + comedi_udelay(1); + outw(cal_enable_bits(dev) | SELECT_DAC08_BIT | (value & 0xff), + devpriv->control_status + CALIBRATION_REG); + comedi_udelay(1); + outw(cal_enable_bits(dev) | (value & 0xff), + devpriv->control_status + CALIBRATION_REG); + comedi_udelay(1); return 1; } -static int dac08_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int dac08_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - return dac08_write( dev, data[ 0 ] ); + return dac08_write(dev, data[0]); } -static int dac08_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int dac08_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[ 0 ] = devpriv->dac08_value; + data[0] = devpriv->dac08_value; return 1; } -static int cb_pcidas_trimpot_write( comedi_device *dev, - unsigned int channel, lsampl_t value ) +static int cb_pcidas_trimpot_write(comedi_device * dev, + unsigned int channel, lsampl_t value) { - if( devpriv->trimpot_value[ channel ] == value ) return 1; - - devpriv->trimpot_value[ channel ] = value; - switch( thisboard->trimpot ) - { - case AD7376: - trimpot_7376_write( dev, value ); - break; - case AD8402: - trimpot_8402_write( dev, channel, value ); - break; - default: - comedi_error( dev, "driver bug?" ); - return -1; - break; + if (devpriv->trimpot_value[channel] == value) + return 1; + + devpriv->trimpot_value[channel] = value; + switch (thisboard->trimpot) { + case AD7376: + trimpot_7376_write(dev, value); + break; + case AD8402: + trimpot_8402_write(dev, channel, value); + break; + default: + comedi_error(dev, "driver bug?"); + return -1; + break; } return 1; } -static int trimpot_write_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int trimpot_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - unsigned int channel = CR_CHAN( insn->chanspec ); + unsigned int channel = CR_CHAN(insn->chanspec); - return cb_pcidas_trimpot_write( dev, channel, data[ 0 ] ); + return cb_pcidas_trimpot_write(dev, channel, data[0]); } -static int trimpot_read_insn( comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data ) +static int trimpot_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - unsigned int channel = CR_CHAN( insn->chanspec ); + unsigned int channel = CR_CHAN(insn->chanspec); - data[ 0 ] = devpriv->trimpot_value[ channel ]; + data[0] = devpriv->trimpot_value[channel]; return 1; } -static int cb_pcidas_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int cb_pcidas_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; int i, gain, start_chan; @@ -1024,151 +1025,144 @@ static int cb_pcidas_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) + if (!cmd->start_src || tmp != cmd->start_src) err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_NOW | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) + if (!cmd->convert_src || tmp != cmd->convert_src) err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) + if (!cmd->stop_src || tmp != cmd->stop_src) err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) err++; - if(cmd->scan_begin_src != TRIG_FOLLOW && + if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT && - cmd->convert_src != TRIG_NOW) + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) err++; - if(cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) err++; // make sure trigger sources are compatible with each other - if(cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_NOW) + if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW) err++; - if(cmd->scan_begin_src != TRIG_FOLLOW && - cmd->convert_src != TRIG_NOW) + if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->convert_src != TRIG_NOW) err++; - if(cmd->start_src == TRIG_EXT && - (cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT)) + if (cmd->start_src == TRIG_EXT && + (cmd->convert_src == TRIG_EXT + || cmd->scan_begin_src == TRIG_EXT)) err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0) - { - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if (cmd->scan_begin_src == TRIG_TIMER) - { - if (cmd->scan_begin_arg < thisboard->ai_speed * cmd->chanlist_len) - { - cmd->scan_begin_arg = thisboard->ai_speed * cmd->chanlist_len; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < + thisboard->ai_speed * cmd->chanlist_len) { + cmd->scan_begin_arg = + thisboard->ai_speed * cmd->chanlist_len; err++; } } - if (cmd->convert_src == TRIG_TIMER) - { - if (cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src == TRIG_NONE) - { + if (cmd->stop_src == TRIG_NONE) { /* TRIG_NONE */ - if (cmd->stop_arg != 0) - { - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->scan_begin_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->scan_begin_arg) + if (tmp != cmd->scan_begin_arg) err++; } - if(cmd->convert_src == TRIG_TIMER) - { - tmp=cmd->convert_arg; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->convert_arg) + if (tmp != cmd->convert_arg) err++; } - if(err) return 4; + if (err) + return 4; // check channel/gain list against card's limitations - if(cmd->chanlist) - { + if (cmd->chanlist) { gain = CR_RANGE(cmd->chanlist[0]); start_chan = CR_CHAN(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++) - { - if(CR_CHAN(cmd->chanlist[i]) != (start_chan + i) % s->n_chan) - { - comedi_error(dev, "entries in chanlist must be consecutive channels, counting upwards\n"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != + (start_chan + i) % s->n_chan) { + comedi_error(dev, + "entries in chanlist must be consecutive channels, counting upwards\n"); err++; } - if(CR_RANGE(cmd->chanlist[i]) != gain) - { - comedi_error(dev, "entries in chanlist must all have the same gain\n"); + if (CR_RANGE(cmd->chanlist[i]) != gain) { + comedi_error(dev, + "entries in chanlist must all have the same gain\n"); err++; } } } - if(err) return 5; + if (err) + return 5; return 0; } -static int cb_pcidas_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int cb_pcidas_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -1187,13 +1181,13 @@ static int cb_pcidas_ai_cmd(comedi_device *dev,comedi_subdevice *s) END_SCAN(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])) | GAIN_BITS(CR_RANGE(cmd->chanlist[0])); // set unipolar/bipolar - if(CR_RANGE(cmd->chanlist[0]) & IS_UNIPOLAR) + if (CR_RANGE(cmd->chanlist[0]) & IS_UNIPOLAR) bits |= UNIP; // set singleended/differential - if(CR_AREF(cmd->chanlist[0]) != AREF_DIFF) + if (CR_AREF(cmd->chanlist[0]) != AREF_DIFF) bits |= SE; // set pacer source - if(cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT) + if (cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT) bits |= PACER_EXT_RISE; else bits |= PACER_INT; @@ -1204,50 +1198,48 @@ static int cb_pcidas_ai_cmd(comedi_device *dev,comedi_subdevice *s) #endif // load counters - if(cmd->convert_src == TRIG_TIMER) - cb_pcidas_load_counters(dev, &cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); - else if(cmd->scan_begin_src == TRIG_TIMER) - cb_pcidas_load_counters(dev, &cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); + if (cmd->convert_src == TRIG_TIMER) + cb_pcidas_load_counters(dev, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + else if (cmd->scan_begin_src == TRIG_TIMER) + cb_pcidas_load_counters(dev, &cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); // set number of conversions - if(cmd->stop_src == TRIG_COUNT) - { + if (cmd->stop_src == TRIG_COUNT) { devpriv->count = cmd->chanlist_len * cmd->stop_arg; } - // enable interrupts - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->adc_fifo_bits |= INTE; devpriv->adc_fifo_bits &= ~INT_MASK; - if(cmd->flags & TRIG_WAKE_EOS) - { - if(cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) + if (cmd->flags & TRIG_WAKE_EOS) { + if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) devpriv->adc_fifo_bits |= INT_EOS; // interrupt end of burst else devpriv->adc_fifo_bits |= INT_FNE; // interrupt fifo not empty - }else - { + } else { devpriv->adc_fifo_bits |= INT_FHF; //interrupt fifo half full } #ifdef CB_PCIDAS_DEBUG rt_printk("comedi: adc_fifo_bits are 0x%x\n", devpriv->adc_fifo_bits); #endif // enable (and clear) interrupts - outw(devpriv->adc_fifo_bits | EOAI | INT | LADFUL, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + outw(devpriv->adc_fifo_bits | EOAI | INT | LADFUL, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // set start trigger and burst mode bits = 0; - if(cmd->start_src == TRIG_NOW) + if (cmd->start_src == TRIG_NOW) bits |= SW_TRIGGER; - else if(cmd->start_src == TRIG_EXT) + else if (cmd->start_src == TRIG_EXT) bits |= EXT_TRIGGER | TGEN | XTRCL; - else - { + else { comedi_error(dev, "bug!"); return -1; } - if(cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) + if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) bits |= BURSTE; outw(bits, devpriv->control_status + TRIG_CONTSTAT); #ifdef CB_PCIDAS_DEBUG @@ -1257,10 +1249,10 @@ static int cb_pcidas_ai_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int cb_pcidas_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int cb_pcidas_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -1274,107 +1266,103 @@ static int cb_pcidas_ao_cmdtest(comedi_device *dev,comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= TRIG_INT; - if(!cmd->start_src || tmp != cmd->start_src) + if (!cmd->start_src || tmp != cmd->start_src) err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp != cmd->convert_src) + if (!cmd->convert_src || tmp != cmd->convert_src) err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) + if (!cmd->stop_src || tmp != cmd->stop_src) err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0) - { - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if (cmd->scan_begin_src == TRIG_TIMER) - { - if (cmd->scan_begin_arg < thisboard->ao_scan_speed) - { + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < thisboard->ao_scan_speed) { cmd->scan_begin_arg = thisboard->ao_scan_speed; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src == TRIG_NONE) - { + if (cmd->stop_src == TRIG_NONE) { /* TRIG_NONE */ - if (cmd->stop_arg != 0) - { - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->ao_divisor1), &(devpriv->ao_divisor2), &(cmd->scan_begin_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->scan_begin_arg) + if (tmp != cmd->scan_begin_arg) err++; } - if(err) return 4; + if (err) + return 4; // check channel/gain list against card's limitations - if(cmd->chanlist && - cmd->chanlist_len > 1) - { - if(CR_CHAN(cmd->chanlist[0]) != 0 || - CR_CHAN(cmd->chanlist[1]) != 1) - { - comedi_error(dev, "channels must be ordered channel 0, channel 1 in chanlist\n"); + if (cmd->chanlist && cmd->chanlist_len > 1) { + if (CR_CHAN(cmd->chanlist[0]) != 0 || + CR_CHAN(cmd->chanlist[1]) != 1) { + comedi_error(dev, + "channels must be ordered channel 0, channel 1 in chanlist\n"); err++; } } - if(err) return 5; + if (err) + return 5; return 0; } -static int cb_pcidas_ao_cmd(comedi_device *dev,comedi_subdevice *s) +static int cb_pcidas_ao_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -1382,107 +1370,104 @@ static int cb_pcidas_ao_cmd(comedi_device *dev,comedi_subdevice *s) unsigned long flags; // set channel limits, gain - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - for(i = 0; i < cmd->chanlist_len; i++) - { + comedi_spin_lock_irqsave(&dev->spinlock, flags); + for (i = 0; i < cmd->chanlist_len; i++) { // enable channel - devpriv->ao_control_bits |= DAC_CHAN_EN(CR_CHAN(cmd->chanlist[i])); + devpriv->ao_control_bits |= + DAC_CHAN_EN(CR_CHAN(cmd->chanlist[i])); // set range devpriv->ao_control_bits |= DAC_RANGE(CR_CHAN(cmd->chanlist[i]), CR_RANGE(cmd->chanlist[i])); } // disable analog out before settings pacer source and count values - outw( devpriv->ao_control_bits, devpriv->control_status + DAC_CSR ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // clear fifo outw(0, devpriv->ao_registers + DACFIFOCLR); // load counters - if(cmd->scan_begin_src == TRIG_TIMER) - { - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->ao_divisor1), - &(devpriv->ao_divisor2), &(cmd->scan_begin_arg), - cmd->flags); + if (cmd->scan_begin_src == TRIG_TIMER) { + i8253_cascade_ns_to_timer_2div(TIMER_BASE, + &(devpriv->ao_divisor1), &(devpriv->ao_divisor2), + &(cmd->scan_begin_arg), cmd->flags); /* Write the values of ctr1 and ctr2 into counters 1 and 2 */ - i8254_load(devpriv->pacer_counter_dio + DAC8254, 0, 1, devpriv->ao_divisor1, 2); - i8254_load(devpriv->pacer_counter_dio + DAC8254, 0, 2, devpriv->ao_divisor2, 2); + i8254_load(devpriv->pacer_counter_dio + DAC8254, 0, 1, + devpriv->ao_divisor1, 2); + i8254_load(devpriv->pacer_counter_dio + DAC8254, 0, 2, + devpriv->ao_divisor2, 2); } - // set number of conversions - if(cmd->stop_src == TRIG_COUNT) - { + if (cmd->stop_src == TRIG_COUNT) { devpriv->ao_count = cmd->chanlist_len * cmd->stop_arg; } - // set pacer source - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - switch(cmd->scan_begin_src) - { - case TRIG_TIMER: - devpriv->ao_control_bits |= DAC_PACER_INT; - break; - case TRIG_EXT: - devpriv->ao_control_bits |= DAC_PACER_EXT_RISE; - break; - default: - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); - comedi_error(dev, "error setting dac pacer source"); - return -1; - break; + comedi_spin_lock_irqsave(&dev->spinlock, flags); + switch (cmd->scan_begin_src) { + case TRIG_TIMER: + devpriv->ao_control_bits |= DAC_PACER_INT; + break; + case TRIG_EXT: + devpriv->ao_control_bits |= DAC_PACER_EXT_RISE; + break; + default: + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + comedi_error(dev, "error setting dac pacer source"); + return -1; + break; } - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); async->inttrig = cb_pcidas_ao_inttrig; return 0; } -static int cb_pcidas_ao_inttrig(comedi_device *dev, comedi_subdevice *s, unsigned int trig_num) +static int cb_pcidas_ao_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trig_num) { unsigned int num_bytes, num_points = thisboard->fifo_size; comedi_async *async = s->async; comedi_cmd *cmd = &s->async->cmd; unsigned long flags; - if(trig_num != 0) + if (trig_num != 0) return -EINVAL; // load up fifo - if( cmd->stop_src == TRIG_COUNT && - devpriv->ao_count < num_points - ) + if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count < num_points) num_points = devpriv->ao_count; - num_bytes = cfc_read_array_from_buffer( s, devpriv->ao_buffer, - num_points * sizeof( sampl_t ) ); - num_points = num_bytes / sizeof( sampl_t ); + num_bytes = cfc_read_array_from_buffer(s, devpriv->ao_buffer, + num_points * sizeof(sampl_t)); + num_points = num_bytes / sizeof(sampl_t); - if(cmd->stop_src == TRIG_COUNT) - { + if (cmd->stop_src == TRIG_COUNT) { devpriv->ao_count -= num_points; } // write data to board's fifo - outsw( devpriv->ao_registers + DACDATA, devpriv->ao_buffer, num_bytes ); + outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, num_bytes); // enable dac half-full and empty interrupts - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->adc_fifo_bits |= DAEMIE | DAHFIE; #ifdef CB_PCIDAS_DEBUG rt_printk("comedi: adc_fifo_bits are 0x%x\n", devpriv->adc_fifo_bits); #endif // enable and clear interrupts - outw(devpriv->adc_fifo_bits | DAEMI | DAHFI, devpriv->control_status + INT_ADCFIFO); + outw(devpriv->adc_fifo_bits | DAEMI | DAHFI, + devpriv->control_status + INT_ADCFIFO); // start dac devpriv->ao_control_bits |= DAC_START | DACEN | DAC_EMPTY; outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); #ifdef CB_PCIDAS_DEBUG - rt_printk("comedi: sent 0x%x to dac control\n", devpriv->ao_control_bits); + rt_printk("comedi: sent 0x%x to dac control\n", + devpriv->ao_control_bits); #endif - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); async->inttrig = NULL; @@ -1491,7 +1476,7 @@ static int cb_pcidas_ao_inttrig(comedi_device *dev, comedi_subdevice *s, unsigne static irqreturn_t cb_pcidas_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev = (comedi_device*) d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->read_subdev; comedi_async *async; int status, s5933_status; @@ -1500,8 +1485,7 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d PT_REGS_ARG) static const int timeout = 10000; unsigned long flags; - if(dev->attached == 0) - { + if (dev->attached == 0) { return IRQ_NONE; } @@ -1514,89 +1498,85 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d PT_REGS_ARG) rt_printk("mbef 0x%x\n", inl(devpriv->s5933_config + AMCC_OP_REG_MBEF)); #endif - if( ( INTCSR_INTR_ASSERTED & s5933_status ) == 0 ) + if ((INTCSR_INTR_ASSERTED & s5933_status) == 0) return IRQ_NONE; // make sure mailbox 4 is empty inl_p(devpriv->s5933_config + AMCC_OP_REG_IMB4); // clear interrupt on amcc s5933 - outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, devpriv->s5933_config + AMCC_OP_REG_INTCSR); + outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, + devpriv->s5933_config + AMCC_OP_REG_INTCSR); status = inw(devpriv->control_status + INT_ADCFIFO); #ifdef CB_PCIDAS_DEBUG - if((status & (INT | EOAI | LADFUL | DAHFI | DAEMI)) == 0) - { + if ((status & (INT | EOAI | LADFUL | DAHFI | DAEMI)) == 0) { comedi_error(dev, "spurious interrupt"); } #endif // check for analog output interrupt - if(status & (DAHFI | DAEMI)) - { + if (status & (DAHFI | DAEMI)) { handle_ao_interrupt(dev, status); } - // check for analog input interrupts // if fifo half-full - if(status & ADHFI) - { + if (status & ADHFI) { // read data num_samples = half_fifo; - if(async->cmd.stop_src == TRIG_COUNT && - num_samples > devpriv->count) - { + if (async->cmd.stop_src == TRIG_COUNT && + num_samples > devpriv->count) { num_samples = devpriv->count; } - insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer, num_samples); - cfc_write_array_to_buffer( s, devpriv->ai_buffer, num_samples * sizeof( sampl_t ) ); + insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer, + num_samples); + cfc_write_array_to_buffer(s, devpriv->ai_buffer, + num_samples * sizeof(sampl_t)); devpriv->count -= num_samples; - if(async->cmd.stop_src == TRIG_COUNT && - devpriv->count == 0) - { + if (async->cmd.stop_src == TRIG_COUNT && devpriv->count == 0) { async->events |= COMEDI_CB_EOA; cb_pcidas_cancel(dev, s); } // clear half-full interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | INT, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); - // else if fifo not empty - }else if(status & (ADNEI | EOBI)) - { - for(i = 0; i < timeout; i++) - { + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | INT, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + // else if fifo not empty + } else if (status & (ADNEI | EOBI)) { + for (i = 0; i < timeout; i++) { // break if fifo is empty - if((ADNE & inw(devpriv->control_status + INT_ADCFIFO)) == 0) + if ((ADNE & inw(devpriv->control_status + + INT_ADCFIFO)) == 0) break; - cfc_write_to_buffer( s, inw( devpriv->adc_fifo ) ); - if(async->cmd.stop_src == TRIG_COUNT && - --devpriv->count == 0) - { /* end of acquisition */ + cfc_write_to_buffer(s, inw(devpriv->adc_fifo)); + if (async->cmd.stop_src == TRIG_COUNT && --devpriv->count == 0) { /* end of acquisition */ cb_pcidas_cancel(dev, s); async->events |= COMEDI_CB_EOA; break; } } // clear not-empty interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | INT, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); - }else if(status & EOAI) - { - comedi_error(dev, "bug! encountered end of aquisition interrupt?"); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | INT, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + } else if (status & EOAI) { + comedi_error(dev, + "bug! encountered end of aquisition interrupt?"); // clear EOA interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | EOAI, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | EOAI, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } //check for fifo overflow - if(status & LADFUL) - { + if (status & LADFUL) { comedi_error(dev, "fifo overflow"); // clear overflow interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | LADFUL, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | LADFUL, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); cb_pcidas_cancel(dev, s); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; } @@ -1606,7 +1586,7 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static void handle_ao_interrupt(comedi_device *dev, unsigned int status) +static void handle_ao_interrupt(comedi_device * dev, unsigned int status) { comedi_subdevice *s = dev->write_subdev; comedi_async *async = s->async; @@ -1617,76 +1597,76 @@ static void handle_ao_interrupt(comedi_device *dev, unsigned int status) async->events = 0; - if(status & DAEMI) - { + if (status & DAEMI) { // clear dac empty interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | DAEMI, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); - if(inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) - { - if(cmd->stop_src == TRIG_NONE || - (cmd->stop_src == TRIG_COUNT && devpriv->ao_count)) - { + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | DAEMI, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + if (inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) { + if (cmd->stop_src == TRIG_NONE || + (cmd->stop_src == TRIG_COUNT + && devpriv->ao_count)) { comedi_error(dev, "dac fifo underflow"); cb_pcidas_ao_cancel(dev, s); async->events |= COMEDI_CB_ERROR; } async->events |= COMEDI_CB_EOA; } - }else if(status & DAHFI) - { + } else if (status & DAHFI) { unsigned int num_bytes; // figure out how many points we are writing to fifo num_points = half_fifo; - if(cmd->stop_src == TRIG_COUNT && + if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count < num_points) num_points = devpriv->ao_count; - num_bytes = cfc_read_array_from_buffer( s, devpriv->ao_buffer, num_points * sizeof( sampl_t ) ); - num_points = num_bytes / sizeof( sampl_t ); + num_bytes = + cfc_read_array_from_buffer(s, devpriv->ao_buffer, + num_points * sizeof(sampl_t)); + num_points = num_bytes / sizeof(sampl_t); - if(async->cmd.stop_src == TRIG_COUNT) - { + if (async->cmd.stop_src == TRIG_COUNT) { devpriv->ao_count -= num_points; } // write data to board's fifo - outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, num_points); + outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, + num_points); // clear half-full interrupt latch - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - outw(devpriv->adc_fifo_bits | DAHFI, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + outw(devpriv->adc_fifo_bits | DAHFI, + devpriv->control_status + INT_ADCFIFO); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } comedi_event(dev, s); } // cancel analog input command -static int cb_pcidas_cancel(comedi_device *dev, comedi_subdevice *s) +static int cb_pcidas_cancel(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); // disable interrupts devpriv->adc_fifo_bits &= ~INTE & ~EOAIE; outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // disable start trigger source and burst mode outw(0, devpriv->control_status + TRIG_CONTSTAT); // software pacer source outw(0, devpriv->control_status + ADCMUX_CONT); - return 0; } // cancel analog output command -static int cb_pcidas_ao_cancel(comedi_device *dev, comedi_subdevice *s) +static int cb_pcidas_ao_cancel(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); // disable interrupts devpriv->adc_fifo_bits &= ~DAHFIE & ~DAEMIE; outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO); @@ -1694,80 +1674,87 @@ static int cb_pcidas_ao_cancel(comedi_device *dev, comedi_subdevice *s) // disable output devpriv->ao_control_bits &= ~DACEN & ~DAC_PACER_MASK; outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } -static void cb_pcidas_load_counters(comedi_device *dev, unsigned int *ns, int rounding_flags) +static void cb_pcidas_load_counters(comedi_device * dev, unsigned int *ns, + int rounding_flags) { i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), ns, rounding_flags & TRIG_ROUND_MASK); /* Write the values of ctr1 and ctr2 into counters 1 and 2 */ - i8254_load(devpriv->pacer_counter_dio + ADC8254, 0, 1, devpriv->divisor1, 2); - i8254_load(devpriv->pacer_counter_dio + ADC8254, 0, 2, devpriv->divisor2, 2); + i8254_load(devpriv->pacer_counter_dio + ADC8254, 0, 1, + devpriv->divisor1, 2); + i8254_load(devpriv->pacer_counter_dio + ADC8254, 0, 2, + devpriv->divisor2, 2); } -static void write_calibration_bitstream( comedi_device *dev, unsigned int register_bits, - unsigned int bitstream, unsigned int bitstream_length ) +static void write_calibration_bitstream(comedi_device * dev, + unsigned int register_bits, unsigned int bitstream, + unsigned int bitstream_length) { static const int write_delay = 1; unsigned int bit; - for( bit = 1 << (bitstream_length - 1); bit; bit >>= 1) - { - if(bitstream & bit) + for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) { + if (bitstream & bit) register_bits |= SERIAL_DATA_IN_BIT; else register_bits &= ~SERIAL_DATA_IN_BIT; - comedi_udelay( write_delay ); - outw( register_bits, devpriv->control_status + CALIBRATION_REG); + comedi_udelay(write_delay); + outw(register_bits, devpriv->control_status + CALIBRATION_REG); } } -static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t value) +static int caldac_8800_write(comedi_device * dev, unsigned int address, + uint8_t value) { static const int num_caldac_channels = 8; static const int bitstream_length = 11; unsigned int bitstream = ((address & 0x7) << 8) | value; static const int caldac_8800_comedi_udelay = 1; - if(address >= num_caldac_channels) - { + if (address >= num_caldac_channels) { comedi_error(dev, "illegal caldac channel"); return -1; } - if( value == devpriv->caldac_value[ address ] ) return 1; + if (value == devpriv->caldac_value[address]) + return 1; - devpriv->caldac_value[ address ] = value; + devpriv->caldac_value[address] = value; - write_calibration_bitstream( dev, cal_enable_bits( dev ), bitstream, bitstream_length ); + write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream, + bitstream_length); comedi_udelay(caldac_8800_comedi_udelay); - outw( cal_enable_bits( dev ) | SELECT_8800_BIT, devpriv->control_status + CALIBRATION_REG); + outw(cal_enable_bits(dev) | SELECT_8800_BIT, + devpriv->control_status + CALIBRATION_REG); comedi_udelay(caldac_8800_comedi_udelay); - outw( cal_enable_bits( dev ), devpriv->control_status + CALIBRATION_REG); + outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); return 1; } -static int trimpot_7376_write(comedi_device *dev, uint8_t value) +static int trimpot_7376_write(comedi_device * dev, uint8_t value) { static const int bitstream_length = 7; unsigned int bitstream = value & 0x7f; unsigned int register_bits; static const int ad7376_comedi_udelay = 1; - register_bits = cal_enable_bits( dev ) | SELECT_TRIMPOT_BIT; - comedi_udelay( ad7376_comedi_udelay ); - outw( register_bits, devpriv->control_status + CALIBRATION_REG); + register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT; + comedi_udelay(ad7376_comedi_udelay); + outw(register_bits, devpriv->control_status + CALIBRATION_REG); - write_calibration_bitstream( dev, register_bits, bitstream, bitstream_length ); + write_calibration_bitstream(dev, register_bits, bitstream, + bitstream_length); comedi_udelay(ad7376_comedi_udelay); - outw( cal_enable_bits( dev ), devpriv->control_status + CALIBRATION_REG); + outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); return 0; } @@ -1775,56 +1762,61 @@ static int trimpot_7376_write(comedi_device *dev, uint8_t value) /* For 1602/16 only * ch 0 : adc gain * ch 1 : adc postgain offset */ -static int trimpot_8402_write(comedi_device *dev, unsigned int channel, uint8_t value) +static int trimpot_8402_write(comedi_device * dev, unsigned int channel, + uint8_t value) { static const int bitstream_length = 10; - unsigned int bitstream = ( ( channel & 0x3 ) << 8 ) | ( value & 0xff ); + unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff); unsigned int register_bits; static const int ad8402_comedi_udelay = 1; - register_bits = cal_enable_bits( dev ) | SELECT_TRIMPOT_BIT; - comedi_udelay( ad8402_comedi_udelay ); - outw( register_bits, devpriv->control_status + CALIBRATION_REG); + register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT; + comedi_udelay(ad8402_comedi_udelay); + outw(register_bits, devpriv->control_status + CALIBRATION_REG); - write_calibration_bitstream( dev, register_bits, bitstream, bitstream_length ); + write_calibration_bitstream(dev, register_bits, bitstream, + bitstream_length); comedi_udelay(ad8402_comedi_udelay); - outw( cal_enable_bits( dev ), devpriv->control_status + CALIBRATION_REG); + outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); return 0; } -static int wait_for_nvram_ready( unsigned long s5933_base_addr ) +static int wait_for_nvram_ready(unsigned long s5933_base_addr) { static const int timeout = 1000; unsigned int i; - for( i = 0; i < timeout; i++) - { - if( ( inb( s5933_base_addr + AMCC_OP_REG_MCSR_NVCMD ) & MCSR_NV_BUSY ) == 0 ) + for (i = 0; i < timeout; i++) { + if ((inb(s5933_base_addr + + AMCC_OP_REG_MCSR_NVCMD) & MCSR_NV_BUSY) + == 0) return 0; - comedi_udelay( 1 ); + comedi_udelay(1); } return -1; } -static int nvram_read( comedi_device *dev, unsigned int address, uint8_t *data ) +static int nvram_read(comedi_device * dev, unsigned int address, uint8_t * data) { unsigned long iobase = devpriv->s5933_config; - if( wait_for_nvram_ready( iobase ) < 0 ) + if (wait_for_nvram_ready(iobase) < 0) return -ETIMEDOUT; - outb( MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR, iobase + AMCC_OP_REG_MCSR_NVCMD ); - outb( address & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA ); - outb( MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR, iobase + AMCC_OP_REG_MCSR_NVCMD ); - outb( ( address >> 8 ) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA ); - outb( MCSR_NV_ENABLE | MCSR_NV_READ, iobase + AMCC_OP_REG_MCSR_NVCMD ); + outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR, + iobase + AMCC_OP_REG_MCSR_NVCMD); + outb(address & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA); + outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR, + iobase + AMCC_OP_REG_MCSR_NVCMD); + outb((address >> 8) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA); + outb(MCSR_NV_ENABLE | MCSR_NV_READ, iobase + AMCC_OP_REG_MCSR_NVCMD); - if( wait_for_nvram_ready( iobase ) < 0 ) + if (wait_for_nvram_ready(iobase) < 0) return -ETIMEDOUT; - *data = inb( iobase + AMCC_OP_REG_MCSR_NVDATA ); + *data = inb(iobase + AMCC_OP_REG_MCSR_NVDATA); return 0; } @@ -1834,4 +1826,3 @@ static int nvram_read( comedi_device *dev, unsigned int address, uint8_t *data ) * as necessary. */ COMEDI_INITCLEANUP(driver_cb_pcidas); - diff --git a/comedi/drivers/cb_pcidas64.c b/comedi/drivers/cb_pcidas64.c index 96f07bdd..3824efdf 100644 --- a/comedi/drivers/cb_pcidas64.c +++ b/comedi/drivers/cb_pcidas64.c @@ -93,8 +93,8 @@ TODO: #include "plx9080.h" #include "comedi_fc.h" -#undef PCIDAS64_DEBUG // disable debugging code -//#define PCIDAS64_DEBUG // enable debugging code +#undef PCIDAS64_DEBUG // disable debugging code +//#define PCIDAS64_DEBUG // enable debugging code #ifdef PCIDAS64_DEBUG #define DEBUG_PRINT(format, args...) rt_printk(format , ## args ) @@ -102,7 +102,7 @@ TODO: #define DEBUG_PRINT(format, args...) #endif -#define TIMER_BASE 25 // 40MHz master clock +#define TIMER_BASE 25 // 40MHz master clock #define PRESCALED_TIMER_BASE 10000 // 100kHz 'prescaled' clock for slow aquisition, maybe I'll support this someday #define DMA_BUFFER_SIZE 0x1000 @@ -112,16 +112,14 @@ static const int max_counter_value = 0xffffff; /* PCI-DAS64xxx base addresses */ // indices of base address regions -enum base_address_regions -{ +enum base_address_regions { PLX9080_BADDRINDEX = 0, MAIN_BADDRINDEX = 2, DIO_COUNTER_BADDRINDEX = 3, }; // priv(dev)->main_iobase registers -enum write_only_registers -{ +enum write_only_registers { INTR_ENABLE_REG = 0x0, // interrupt enable register HW_CONFIG_REG = 0x2, // hardware config register DAQ_SYNC_REG = 0xc, @@ -149,21 +147,20 @@ enum write_only_registers DAC_START_REG = 0x64, DAC_BUFFER_CLEAR_REG = 0x66, // clear dac buffer }; -static inline unsigned int dac_convert_reg( unsigned int channel ) +static inline unsigned int dac_convert_reg(unsigned int channel) { - return 0x70 + ( 2 * ( channel & 0x1 ) ); + return 0x70 + (2 * (channel & 0x1)); } -static inline unsigned int dac_lsb_4020_reg( unsigned int channel ) +static inline unsigned int dac_lsb_4020_reg(unsigned int channel) { - return 0x70 + ( 4 * ( channel & 0x1 ) ); + return 0x70 + (4 * (channel & 0x1)); } -static inline unsigned int dac_msb_4020_reg( unsigned int channel ) +static inline unsigned int dac_msb_4020_reg(unsigned int channel) { - return 0x72 + ( 4 * ( channel & 0x1 ) ); + return 0x72 + (4 * (channel & 0x1)); } -enum read_only_registers -{ +enum read_only_registers { HW_STATUS_REG = 0x0, // hardware status register, reading this apparently clears pending interrupts as well PIPE1_READ_REG = 0x4, ADC_READ_PNTR_REG = 0x8, @@ -172,17 +169,15 @@ enum read_only_registers PREPOST_REG = 0x14, }; -enum read_write_registers -{ +enum read_write_registers { I8255_4020_REG = 0x48, // 8255 offset, for 4020 only ADC_QUEUE_FIFO_REG = 0x100, // external channel/gain queue, uses same bits as ADC_QUEUE_LOAD_REG ADC_FIFO_REG = 0x200, /* adc data fifo */ - DAC_FIFO_REG = 0x300, /* dac data fifo, has weird interactions with external channel queue */ + DAC_FIFO_REG = 0x300, /* dac data fifo, has weird interactions with external channel queue */ }; // priv(dev)->dio_counter_iobase registers -enum dio_counter_registers -{ +enum dio_counter_registers { DIO_8255_OFFSET = 0x0, DO_REG = 0x20, DI_REG = 0x28, @@ -192,8 +187,7 @@ enum dio_counter_registers // bit definitions for write-only registers -enum intr_enable_contents -{ +enum intr_enable_contents { ADC_INTR_SRC_MASK = 0x3, // bits that set adc interrupt source ADC_INTR_QFULL_BITS = 0x0, // interrupt fifo quater full ADC_INTR_EOC_BITS = 0x1, // interrupt end of conversion @@ -213,8 +207,7 @@ enum intr_enable_contents EN_ADC_OVERRUN_BIT = 0x8000, // enable adc overrun status bit }; -enum hw_config_contents -{ +enum hw_config_contents { MASTER_CLOCK_4020_MASK = 0x3, // bits that specify master clock source for 4020 INTERNAL_CLOCK_4020_BITS = 0x1, // use 40 MHz internal master clock for 4020 BNC_CLOCK_4020_BITS = 0x2, // use BNC input for master clock @@ -229,19 +222,17 @@ enum hw_config_contents }; #define DAC_FIFO_SIZE 0x2000 -enum daq_atrig_low_4020_contents -{ +enum daq_atrig_low_4020_contents { EXT_AGATE_BNC_BIT = 0x8000, // use trig/ext clk bnc input for analog gate signal EXT_STOP_TRIG_BNC_BIT = 0x4000, // use trig/ext clk bnc input for external stop trigger signal EXT_START_TRIG_BNC_BIT = 0x2000, // use trig/ext clk bnc input for external start trigger signal }; -static inline uint16_t analog_trig_low_threshold_bits( uint16_t threshold ) +static inline uint16_t analog_trig_low_threshold_bits(uint16_t threshold) { return threshold & 0xfff; } -enum adc_control0_contents -{ +enum adc_control0_contents { ADC_GATE_SRC_MASK = 0x3, // bits that select gate ADC_SOFT_GATE_BITS = 0x1, // software gate ADC_EXT_GATE_BITS = 0x2, // external digital gate @@ -259,8 +250,7 @@ enum adc_control0_contents ADC_ENABLE_BIT = 0x8000, // master adc enable }; -enum adc_control1_contents -{ +enum adc_control1_contents { ADC_QUEUE_CONFIG_BIT = 0x1, // should be set for boards with > 16 channels CONVERT_POLARITY_BIT = 0x10, EOC_POLARITY_BIT = 0x20, @@ -269,26 +259,25 @@ enum adc_control1_contents RETRIGGER_BIT = 0x800, ADC_LO_CHANNEL_4020_MASK = 0x300, ADC_HI_CHANNEL_4020_MASK = 0xc00, - TWO_CHANNEL_4020_BITS = 0x1000, // two channel mode for 4020 + TWO_CHANNEL_4020_BITS = 0x1000, // two channel mode for 4020 FOUR_CHANNEL_4020_BITS = 0x2000, // four channel mode for 4020 CHANNEL_MODE_4020_MASK = 0x3000, ADC_MODE_MASK = 0xf000, }; -static inline uint16_t adc_lo_chan_4020_bits( unsigned int channel ) +static inline uint16_t adc_lo_chan_4020_bits(unsigned int channel) { - return ( channel & 0x3 ) << 8; + return (channel & 0x3) << 8; }; -static inline uint16_t adc_hi_chan_4020_bits( unsigned int channel ) +static inline uint16_t adc_hi_chan_4020_bits(unsigned int channel) { - return ( channel & 0x3 ) << 10; + return (channel & 0x3) << 10; }; -static inline uint16_t adc_mode_bits( unsigned int mode ) +static inline uint16_t adc_mode_bits(unsigned int mode) { - return ( mode & 0xf ) << 12; + return (mode & 0xf) << 12; }; -enum calibration_contents -{ +enum calibration_contents { SELECT_8800_BIT = 0x1, SELECT_8402_64XX_BIT = 0x2, SELECT_1590_60XX_BIT = 0x2, @@ -308,31 +297,29 @@ enum calibration_contents * 6 : dac channel 0 * 7 : dac channel 1 */ -static inline uint16_t adc_src_bits( unsigned int source ) +static inline uint16_t adc_src_bits(unsigned int source) { - return ( source & 0xf ) << 3; + return (source & 0xf) << 3; }; -static inline uint16_t adc_convert_chan_4020_bits( unsigned int channel ) +static inline uint16_t adc_convert_chan_4020_bits(unsigned int channel) { - return ( channel & 0x3 ) << 8; + return (channel & 0x3) << 8; }; -enum adc_queue_load_contents -{ +enum adc_queue_load_contents { UNIP_BIT = 0x800, // unipolar/bipolar bit ADC_SE_DIFF_BIT = 0x1000, // single-ended/ differential bit ADC_COMMON_BIT = 0x2000, // non-referenced single-ended (common-mode input) QUEUE_EOSEQ_BIT = 0x4000, // queue end of sequence QUEUE_EOSCAN_BIT = 0x8000, // queue end of scan }; -static inline uint16_t adc_chan_bits( unsigned int channel ) +static inline uint16_t adc_chan_bits(unsigned int channel) { return channel & 0x3f; }; -enum dac_control0_contents -{ +enum dac_control0_contents { DAC_ENABLE_BIT = 0x8000, // dac controller enable bit DAC_CYCLIC_STOP_BIT = 0x4000, DAC_WAVEFORM_MODE_BIT = 0x100, @@ -349,21 +336,19 @@ enum dac_control0_contents WAVEFORM_GATE_SELECT_BIT = 0x1, }; -enum dac_control1_contents -{ - DAC_WRITE_POLARITY_BIT = 0x800, /* board-dependent setting */ +enum dac_control1_contents { + DAC_WRITE_POLARITY_BIT = 0x800, /* board-dependent setting */ DAC1_EXT_REF_BIT = 0x200, DAC0_EXT_REF_BIT = 0x100, DAC_OUTPUT_ENABLE_BIT = 0x80, // dac output enable bit - DAC_UPDATE_POLARITY_BIT = 0x40, /* board-dependent setting */ + DAC_UPDATE_POLARITY_BIT = 0x40, /* board-dependent setting */ DAC_SW_GATE_BIT = 0x20, DAC1_UNIPOLAR_BIT = 0x8, DAC0_UNIPOLAR_BIT = 0x2, }; // bit definitions for read-only registers -enum hw_status_contents -{ +enum hw_status_contents { DAC_UNDERRUN_BIT = 0x1, ADC_OVERRUN_BIT = 0x2, DAC_ACTIVE_BIT = 0x4, @@ -375,244 +360,223 @@ enum hw_status_contents EXT_INTR_PENDING_BIT = 0x100, ADC_STOP_BIT = 0x200, }; -static inline uint16_t pipe_full_bits( uint16_t hw_status_bits ) +static inline uint16_t pipe_full_bits(uint16_t hw_status_bits) { - return ( hw_status_bits >> 10) & 0x3; + return (hw_status_bits >> 10) & 0x3; }; -static inline unsigned int dma_chain_flag_bits( uint16_t prepost_bits ) +static inline unsigned int dma_chain_flag_bits(uint16_t prepost_bits) { - return ( prepost_bits >> 6 ) & 0x3; + return (prepost_bits >> 6) & 0x3; } -static inline unsigned int adc_upper_read_ptr_code( uint16_t prepost_bits ) +static inline unsigned int adc_upper_read_ptr_code(uint16_t prepost_bits) { - return ( prepost_bits >> 12 ) & 0x3; + return (prepost_bits >> 12) & 0x3; } -static inline unsigned int adc_upper_write_ptr_code( uint16_t prepost_bits ) +static inline unsigned int adc_upper_write_ptr_code(uint16_t prepost_bits) { - return ( prepost_bits >> 14 ) & 0x3; + return (prepost_bits >> 14) & 0x3; } // I2C addresses for 4020 -enum i2c_addresses -{ +enum i2c_addresses { RANGE_CAL_I2C_ADDR = 0x20, CALDAC0_I2C_ADDR = 0xc, CALDAC1_I2C_ADDR = 0xd, }; -enum range_cal_i2c_contents -{ +enum range_cal_i2c_contents { ADC_SRC_4020_MASK = 0x70, // bits that set what source the adc converter measures BNC_TRIG_THRESHOLD_0V_BIT = 0x80, // make bnc trig/ext clock threshold 0V instead of 2.5V }; -static inline uint8_t adc_src_4020_bits( unsigned int source ) +static inline uint8_t adc_src_4020_bits(unsigned int source) { - return ( source << 4 ) & ADC_SRC_4020_MASK; + return (source << 4) & ADC_SRC_4020_MASK; }; -static inline uint8_t attenuate_bit( unsigned int channel ) +static inline uint8_t attenuate_bit(unsigned int channel) { // attenuate channel (+-5V input range) - return 1 << ( channel & 0x3 ); + return 1 << (channel & 0x3); }; // analog input ranges for 64xx boards -static const comedi_lrange ai_ranges_64xx = -{ +static const comedi_lrange ai_ranges_64xx = { 8, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25) + } }; /* analog input ranges for 60xx boards */ -static const comedi_lrange ai_ranges_60xx = -{ +static const comedi_lrange ai_ranges_60xx = { 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + } }; /* analog input ranges for 6030, etc boards */ -static const comedi_lrange ai_ranges_6030 = -{ +static const comedi_lrange ai_ranges_6030 = { 14, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2), - BIP_RANGE(1), - BIP_RANGE(0.5), - BIP_RANGE(0.2), - BIP_RANGE(0.1), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1), - UNI_RANGE(0.5), - UNI_RANGE(0.2), - UNI_RANGE(0.1), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2), + BIP_RANGE(1), + BIP_RANGE(0.5), + BIP_RANGE(0.2), + BIP_RANGE(0.1), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1), + UNI_RANGE(0.5), + UNI_RANGE(0.2), + UNI_RANGE(0.1), + } }; /* analog input ranges for 6052, etc boards */ -static const comedi_lrange ai_ranges_6052 = -{ +static const comedi_lrange ai_ranges_6052 = { 15, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1), - BIP_RANGE(0.5), - BIP_RANGE(0.25), - BIP_RANGE(0.1), - BIP_RANGE(0.05), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1), - UNI_RANGE(0.5), - UNI_RANGE(0.2), - UNI_RANGE(0.1), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1), + BIP_RANGE(0.5), + BIP_RANGE(0.25), + BIP_RANGE(0.1), + BIP_RANGE(0.05), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1), + UNI_RANGE(0.5), + UNI_RANGE(0.2), + UNI_RANGE(0.1), + } }; // analog input ranges for 4020 board -static const comedi_lrange ai_ranges_4020 = -{ +static const comedi_lrange ai_ranges_4020 = { 2, { - BIP_RANGE(5), - BIP_RANGE(1), - } + BIP_RANGE(5), + BIP_RANGE(1), + } }; // analog output ranges -static const comedi_lrange ao_ranges_64xx = -{ +static const comedi_lrange ao_ranges_64xx = { 4, { - BIP_RANGE(5), - BIP_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(10), - } + BIP_RANGE(5), + BIP_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(10), + } }; -static const int ao_range_code_64xx[] = -{ +static const int ao_range_code_64xx[] = { 0x0, 0x1, 0x2, 0x3, }; -static const comedi_lrange ao_ranges_60xx = -{ +static const comedi_lrange ao_ranges_60xx = { 1, { - BIP_RANGE(10), - } + BIP_RANGE(10), + } }; -static const int ao_range_code_60xx[] = -{ +static const int ao_range_code_60xx[] = { 0x0, }; -static const comedi_lrange ao_ranges_6030 = -{ +static const comedi_lrange ao_ranges_6030 = { 2, { - BIP_RANGE(10), - UNI_RANGE(10), - } + BIP_RANGE(10), + UNI_RANGE(10), + } }; -static const int ao_range_code_6030[] = -{ +static const int ao_range_code_6030[] = { 0x0, 0x2, }; -static const comedi_lrange ao_ranges_4020 = -{ +static const comedi_lrange ao_ranges_4020 = { 2, { - BIP_RANGE(5), - BIP_RANGE(10), - } + BIP_RANGE(5), + BIP_RANGE(10), + } }; -static const int ao_range_code_4020[] = -{ +static const int ao_range_code_4020[] = { 0x1, 0x0, }; -enum register_layout -{ +enum register_layout { LAYOUT_60XX, LAYOUT_64XX, LAYOUT_4020, }; -typedef struct hw_fifo_info_struct -{ +typedef struct hw_fifo_info_struct { unsigned int num_segments; unsigned int max_segment_length; unsigned int sample_packing_ratio; uint16_t fifo_size_reg_mask; } hw_fifo_info_t; -typedef struct pcidas64_board_struct -{ +typedef struct pcidas64_board_struct { const char *name; - int device_id; // pci device id + int device_id; // pci device id int ai_se_chans; // number of ai inputs in single-ended mode - int ai_bits; // analog input resolution - int ai_speed; // fastest conversion period in ns + int ai_bits; // analog input resolution + int ai_speed; // fastest conversion period in ns const comedi_lrange *ai_range_table; - int ao_nchan; // number of analog out channels - int ao_bits; // analog output resolution + int ao_nchan; // number of analog out channels + int ao_bits; // analog output resolution int ao_scan_speed; // analog output speed (for a scan, not conversion) const comedi_lrange *ao_range_table; const int *ao_range_code; const hw_fifo_info_t *const ai_fifo; enum register_layout layout; // different board families have slightly different registers - unsigned has_8255 : 1; + unsigned has_8255:1; } pcidas64_board; -static const hw_fifo_info_t ai_fifo_4020 = -{ - num_segments: 2, - max_segment_length: 0x8000, - sample_packing_ratio: 2, - fifo_size_reg_mask: 0x7f, +static const hw_fifo_info_t ai_fifo_4020 = { + num_segments:2, + max_segment_length:0x8000, + sample_packing_ratio:2, + fifo_size_reg_mask:0x7f, }; -static const hw_fifo_info_t ai_fifo_64xx = -{ - num_segments: 4, - max_segment_length: 0x800, - sample_packing_ratio: 1, - fifo_size_reg_mask: 0x3f, +static const hw_fifo_info_t ai_fifo_64xx = { + num_segments:4, + max_segment_length:0x800, + sample_packing_ratio:1, + fifo_size_reg_mask:0x3f, }; -static const hw_fifo_info_t ai_fifo_60xx = -{ - num_segments: 4, - max_segment_length: 0x800, - sample_packing_ratio: 1, - fifo_size_reg_mask: 0x7f, +static const hw_fifo_info_t ai_fifo_60xx = { + num_segments:4, + max_segment_length:0x800, + sample_packing_ratio:1, + fifo_size_reg_mask:0x7f, }; /* maximum number of dma transfers we will chain together into a ring @@ -620,9 +584,9 @@ static const hw_fifo_info_t ai_fifo_60xx = #define MAX_AI_DMA_RING_COUNT (0x80000 / DMA_BUFFER_SIZE) #define MIN_AI_DMA_RING_COUNT (0x10000 / DMA_BUFFER_SIZE) #define AO_DMA_RING_COUNT (0x10000 / DMA_BUFFER_SIZE) -static inline unsigned int ai_dma_ring_count(pcidas64_board *board) +static inline unsigned int ai_dma_ring_count(pcidas64_board * board) { - if(board->layout == LAYOUT_4020) + if (board->layout == LAYOUT_4020) return MAX_AI_DMA_RING_COUNT; else return MIN_AI_DMA_RING_COUNT; @@ -630,462 +594,462 @@ static inline unsigned int ai_dma_ring_count(pcidas64_board *board) static const int bytes_in_sample = 2; -static const pcidas64_board pcidas64_boards[] = -{ - { - name: "pci-das6402/16", - device_id: 0x1d, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ao_range_table: &ao_ranges_64xx, - ao_range_code: ao_range_code_64xx, - ai_fifo: &ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das6402/12", // XXX check - device_id: 0x1e, - ai_se_chans: 64, - ai_bits: 12, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ao_range_table: &ao_ranges_64xx, - ao_range_code: ao_range_code_64xx, - ai_fifo: &ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m1/16", - device_id: 0x35, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 1000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ao_range_table: &ao_ranges_64xx, - ao_range_code: ao_range_code_64xx, - ai_fifo: &ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m2/16", - device_id: 0x36, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 500, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ao_range_table: &ao_ranges_64xx, - ao_range_code: ao_range_code_64xx, - ai_fifo: &ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m3/16", - device_id: 0x37, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 333, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ao_range_table: &ao_ranges_64xx, - ao_range_code: ao_range_code_64xx, - ai_fifo: &ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das6014", - device_id: 0x79, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 100000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ao_range_table: &ao_ranges_60xx, - ao_range_code: ao_range_code_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6023", - device_id: 0x5d, - ai_se_chans: 16, - ai_bits: 12, - ai_speed: 5000, - ao_nchan: 0, - ao_scan_speed: 100000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ao_range_table: &ao_ranges_60xx, - ao_range_code: ao_range_code_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 1, - }, - { - name: "pci-das6025", - device_id: 0x5e, - ai_se_chans: 16, - ai_bits: 12, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 100000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ao_range_table: &ao_ranges_60xx, - ao_range_code: ao_range_code_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 1, - }, - { - name: "pci-das6030", - device_id: 0x5f, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 10000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6030, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6031", - device_id: 0x60, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 10000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 10000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6030, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6032", - device_id: 0x61, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 10000, - ao_nchan: 0, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6033", - device_id: 0x62, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 10000, - ao_nchan: 0, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6034", - device_id: 0x63, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 0, - ao_scan_speed: 0, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6035", - device_id: 0x64, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 100000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ao_range_table: &ao_ranges_60xx, - ao_range_code: ao_range_code_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6036", - device_id: 0x6f, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 100000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_60xx, - ao_range_table: &ao_ranges_60xx, - ao_range_code: ao_range_code_60xx, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6040", - device_id: 0x65, - ai_se_chans: 16, - ai_bits: 12, - ai_speed: 2000, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 1000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6052, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6052", - device_id: 0x66, - ai_se_chans: 16, - ai_bits: 16, - ai_speed: 3333, - ao_nchan: 2, - ao_bits: 16, - ao_scan_speed: 3333, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6052, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6070", - device_id: 0x67, - ai_se_chans: 16, - ai_bits: 12, - ai_speed: 800, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 1000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6052, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das6071", - device_id: 0x68, - ai_se_chans: 64, - ai_bits: 12, - ai_speed: 800, - ao_nchan: 2, - ao_bits: 12, - ao_scan_speed: 1000, - layout: LAYOUT_60XX, - ai_range_table: &ai_ranges_6052, - ao_range_table: &ao_ranges_6030, - ao_range_code: ao_range_code_6030, - ai_fifo: &ai_fifo_60xx, - has_8255 : 0, - }, - { - name: "pci-das4020/12", - device_id: 0x52, - ai_se_chans: 4, - ai_bits: 12, - ai_speed: 50, - ao_bits: 12, - ao_nchan: 2, - ao_scan_speed: 0, // no hardware pacing on ao - layout: LAYOUT_4020, - ai_range_table: &ai_ranges_4020, - ao_range_table: &ao_ranges_4020, - ao_range_code: ao_range_code_4020, - ai_fifo: &ai_fifo_4020, - has_8255 : 1, - }, +static const pcidas64_board pcidas64_boards[] = { + { + name: "pci-das6402/16", + device_id:0x1d, + ai_se_chans:64, + ai_bits: 16, + ai_speed:5000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ao_range_table:&ao_ranges_64xx, + ao_range_code:ao_range_code_64xx, + ai_fifo: &ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das6402/12", // XXX check + device_id:0x1e, + ai_se_chans:64, + ai_bits: 12, + ai_speed:5000, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ao_range_table:&ao_ranges_64xx, + ao_range_code:ao_range_code_64xx, + ai_fifo: &ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m1/16", + device_id:0x35, + ai_se_chans:64, + ai_bits: 16, + ai_speed:1000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ao_range_table:&ao_ranges_64xx, + ao_range_code:ao_range_code_64xx, + ai_fifo: &ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m2/16", + device_id:0x36, + ai_se_chans:64, + ai_bits: 16, + ai_speed:500, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ao_range_table:&ao_ranges_64xx, + ao_range_code:ao_range_code_64xx, + ai_fifo: &ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m3/16", + device_id:0x37, + ai_se_chans:64, + ai_bits: 16, + ai_speed:333, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ao_range_table:&ao_ranges_64xx, + ao_range_code:ao_range_code_64xx, + ai_fifo: &ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das6014", + device_id:0x79, + ai_se_chans:16, + ai_bits: 16, + ai_speed:5000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:100000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ao_range_table:&ao_ranges_60xx, + ao_range_code:ao_range_code_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6023", + device_id:0x5d, + ai_se_chans:16, + ai_bits: 12, + ai_speed:5000, + ao_nchan:0, + ao_scan_speed:100000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ao_range_table:&ao_ranges_60xx, + ao_range_code:ao_range_code_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:1, + }, + { + name: "pci-das6025", + device_id:0x5e, + ai_se_chans:16, + ai_bits: 12, + ai_speed:5000, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:100000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ao_range_table:&ao_ranges_60xx, + ao_range_code:ao_range_code_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:1, + }, + { + name: "pci-das6030", + device_id:0x5f, + ai_se_chans:16, + ai_bits: 16, + ai_speed:10000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6030, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6031", + device_id:0x60, + ai_se_chans:64, + ai_bits: 16, + ai_speed:10000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:10000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6030, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6032", + device_id:0x61, + ai_se_chans:16, + ai_bits: 16, + ai_speed:10000, + ao_nchan:0, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6033", + device_id:0x62, + ai_se_chans:64, + ai_bits: 16, + ai_speed:10000, + ao_nchan:0, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6034", + device_id:0x63, + ai_se_chans:16, + ai_bits: 16, + ai_speed:5000, + ao_nchan:0, + ao_scan_speed:0, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6035", + device_id:0x64, + ai_se_chans:16, + ai_bits: 16, + ai_speed:5000, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:100000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ao_range_table:&ao_ranges_60xx, + ao_range_code:ao_range_code_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6036", + device_id:0x6f, + ai_se_chans:16, + ai_bits: 16, + ai_speed:5000, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:100000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_60xx, + ao_range_table:&ao_ranges_60xx, + ao_range_code:ao_range_code_60xx, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6040", + device_id:0x65, + ai_se_chans:16, + ai_bits: 12, + ai_speed:2000, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:1000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6052, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6052", + device_id:0x66, + ai_se_chans:16, + ai_bits: 16, + ai_speed:3333, + ao_nchan:2, + ao_bits: 16, + ao_scan_speed:3333, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6052, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6070", + device_id:0x67, + ai_se_chans:16, + ai_bits: 12, + ai_speed:800, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:1000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6052, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das6071", + device_id:0x68, + ai_se_chans:64, + ai_bits: 12, + ai_speed:800, + ao_nchan:2, + ao_bits: 12, + ao_scan_speed:1000, + layout: LAYOUT_60XX, + ai_range_table:&ai_ranges_6052, + ao_range_table:&ao_ranges_6030, + ao_range_code:ao_range_code_6030, + ai_fifo: &ai_fifo_60xx, + has_8255:0, + }, + { + name: "pci-das4020/12", + device_id:0x52, + ai_se_chans:4, + ai_bits: 12, + ai_speed:50, + ao_bits: 12, + ao_nchan:2, + ao_scan_speed:0, // no hardware pacing on ao + layout: LAYOUT_4020, + ai_range_table:&ai_ranges_4020, + ao_range_table:&ao_ranges_4020, + ao_range_code:ao_range_code_4020, + ai_fifo: &ai_fifo_4020, + has_8255:1, + }, #if 0 { - name: "pci-das6402/16/jr", - device_id: 0 // XXX, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 5000, - ao_nchan: 0, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m1/16/jr", - device_id: 0 // XXX, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 1000, - ao_nchan: 0, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m2/16/jr", - device_id: 0 // XXX, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 500, - ao_nchan: 0, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m3/16/jr", - device_id: 0 // XXX, - ai_se_chans: 64, - ai_bits: 16, - ai_speed: 333, - ao_nchan: 0, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m1/14", - device_id: 0, // XXX - ai_se_chans: 64, - ai_bits: 14, - ai_speed: 1000, - ao_nchan: 2, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m2/14", - device_id: 0, // XXX - ai_se_chans: 64, - ai_bits: 14, - ai_speed: 500, - ao_nchan: 2, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, - { - name: "pci-das64/m3/14", - device_id: 0, // XXX - ai_se_chans: 64, - ai_bits: 14, - ai_speed: 333, - ao_nchan: 2, - ao_scan_speed: 10000, - layout: LAYOUT_64XX, - ai_range_table: &ai_ranges_64xx, - ai_fifo: ai_fifo_64xx, - has_8255 : 1, - }, + name: "pci-das6402/16/jr", + device_id:0 // XXX, + ai_se_chans:64, + ai_bits: 16, + ai_speed:5000, + ao_nchan:0, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m1/16/jr", + device_id:0 // XXX, + ai_se_chans:64, + ai_bits: 16, + ai_speed:1000, + ao_nchan:0, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m2/16/jr", + device_id:0 // XXX, + ai_se_chans:64, + ai_bits: 16, + ai_speed:500, + ao_nchan:0, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m3/16/jr", + device_id:0 // XXX, + ai_se_chans:64, + ai_bits: 16, + ai_speed:333, + ao_nchan:0, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m1/14", + device_id:0, // XXX + ai_se_chans:64, + ai_bits: 14, + ai_speed:1000, + ao_nchan:2, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m2/14", + device_id:0, // XXX + ai_se_chans:64, + ai_bits: 14, + ai_speed:500, + ao_nchan:2, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, + { + name: "pci-das64/m3/14", + device_id:0, // XXX + ai_se_chans:64, + ai_bits: 14, + ai_speed:333, + ao_nchan:2, + ao_scan_speed:10000, + layout: LAYOUT_64XX, + ai_range_table:&ai_ranges_64xx, + ai_fifo: ai_fifo_64xx, + has_8255:1, + }, #endif }; + // Number of boards in cb_pcidas_boards -static inline unsigned int num_boards( void ) +static inline unsigned int num_boards(void) { - return sizeof( pcidas64_boards ) / sizeof( pcidas64_board ); + return sizeof(pcidas64_boards) / sizeof(pcidas64_board); } static struct pci_device_id pcidas64_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x001d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x001e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x005d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x005e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x005f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0061, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0062, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0063, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0066, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0067, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0068, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x006f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0079, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x001d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x001e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x005d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x005e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x005f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0061, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0062, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0063, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0066, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0067, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0068, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x006f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0079, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, pcidas64_pci_table); -static inline pcidas64_board* board( const comedi_device *dev ) +static inline pcidas64_board *board(const comedi_device * dev) { - return (pcidas64_board *)dev->board_ptr; + return (pcidas64_board *) dev->board_ptr; } -static inline unsigned short se_diff_bit_6xxx(comedi_device *dev, int use_differential) +static inline unsigned short se_diff_bit_6xxx(comedi_device * dev, + int use_differential) { - if((board(dev)->layout == LAYOUT_64XX && !use_differential) || + if ((board(dev)->layout == LAYOUT_64XX && !use_differential) || (board(dev)->layout == LAYOUT_60XX && use_differential)) return ADC_SE_DIFF_BIT; else return 0; }; -struct ext_clock_info -{ +struct ext_clock_info { unsigned int divisor; // master clock divisor to use for scans with external master clock unsigned int chanspec; // chanspec for master clock input when used as scan begin src }; /* this structure is for data unique to this hardware driver. */ -typedef struct -{ +typedef struct { struct pci_dev *hw_dev; // pointer to board's pci_dev struct // base addresses (physical) resource_size_t plx9080_phys_iobase; @@ -1134,7 +1098,7 @@ typedef struct /* inline function that makes it easier to * access the private structure. */ -static inline pcidas64_private* priv(comedi_device *dev) +static inline pcidas64_private *priv(comedi_device * dev) { return dev->private; } @@ -1145,151 +1109,192 @@ static inline pcidas64_private* priv(comedi_device *dev) * the board, and also about the kernel module that contains * the device code. */ -static int attach(comedi_device *dev,comedi_devconfig *it); -static int detach(comedi_device *dev); -static comedi_driver driver_cb_pcidas={ - driver_name: "cb_pcidas64", - module: THIS_MODULE, - attach: attach, - detach: detach, +static int attach(comedi_device * dev, comedi_devconfig * it); +static int detach(comedi_device * dev); +static comedi_driver driver_cb_pcidas = { + driver_name:"cb_pcidas64", + module:THIS_MODULE, + attach:attach, + detach:detach, }; -static int ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ai_config_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ao_readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ai_cmd(comedi_device *dev,comedi_subdevice *s); -static int ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); -static int ao_cmd(comedi_device *dev,comedi_subdevice *s); -static int ao_inttrig(comedi_device *dev, comedi_subdevice *subdev, unsigned int trig_num); -static int ao_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); +static int ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ai_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ao_readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int ao_cmd(comedi_device * dev, comedi_subdevice * s); +static int ao_inttrig(comedi_device * dev, comedi_subdevice * subdev, + unsigned int trig_num); +static int ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG); -static int ai_cancel(comedi_device *dev, comedi_subdevice *s); -static int ao_cancel(comedi_device *dev, comedi_subdevice *s); +static int ai_cancel(comedi_device * dev, comedi_subdevice * s); +static int ao_cancel(comedi_device * dev, comedi_subdevice * s); static int dio_callback(int dir, int port, int data, unsigned long arg); static int dio_callback_4020(int dir, int port, int data, unsigned long arg); -static int di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int dio_60xx_config_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int dio_60xx_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int calib_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int calib_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int ad8402_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static void ad8402_write( comedi_device *dev, unsigned int channel, unsigned int value ); -static int ad8402_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int eeprom_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static void check_adc_timing( comedi_device *dev, comedi_cmd *cmd); +static int di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dio_60xx_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dio_60xx_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int calib_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int calib_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ad8402_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static void ad8402_write(comedi_device * dev, unsigned int channel, + unsigned int value); +static int ad8402_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static void check_adc_timing(comedi_device * dev, comedi_cmd * cmd); static unsigned int get_divisor(unsigned int ns, unsigned int flags); -static void i2c_write(comedi_device *dev, unsigned int address, const uint8_t *data, unsigned int length); -static void caldac_write( comedi_device *dev, unsigned int channel, unsigned int value ); -static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t value); +static void i2c_write(comedi_device * dev, unsigned int address, + const uint8_t * data, unsigned int length); +static void caldac_write(comedi_device * dev, unsigned int channel, + unsigned int value); +static int caldac_8800_write(comedi_device * dev, unsigned int address, + uint8_t value); //static int dac_1590_write(comedi_device *dev, unsigned int dac_a, unsigned int dac_b); -static int caldac_i2c_write(comedi_device *dev, unsigned int caldac_channel, unsigned int value); -static void abort_dma(comedi_device *dev, unsigned int channel); -static void disable_plx_interrupts( comedi_device *dev ); -static int set_ai_fifo_size( comedi_device *dev, unsigned int num_samples ); -static unsigned int ai_fifo_size( comedi_device *dev ); -static int set_ai_fifo_segment_length( comedi_device *dev, unsigned int num_entries ); -static void disable_ai_pacing( comedi_device *dev ); -static void disable_ai_interrupts( comedi_device *dev ); -static void enable_ai_interrupts( comedi_device *dev, const comedi_cmd *cmd ); +static int caldac_i2c_write(comedi_device * dev, unsigned int caldac_channel, + unsigned int value); +static void abort_dma(comedi_device * dev, unsigned int channel); +static void disable_plx_interrupts(comedi_device * dev); +static int set_ai_fifo_size(comedi_device * dev, unsigned int num_samples); +static unsigned int ai_fifo_size(comedi_device * dev); +static int set_ai_fifo_segment_length(comedi_device * dev, + unsigned int num_entries); +static void disable_ai_pacing(comedi_device * dev); +static void disable_ai_interrupts(comedi_device * dev); +static void enable_ai_interrupts(comedi_device * dev, const comedi_cmd * cmd); static unsigned int get_ao_divisor(unsigned int ns, unsigned int flags); -static void load_ao_dma(comedi_device *dev, const comedi_cmd *cmd); +static void load_ao_dma(comedi_device * dev, const comedi_cmd * cmd); COMEDI_INITCLEANUP(driver_cb_pcidas); -static unsigned int ai_range_bits_6xxx( const comedi_device *dev, unsigned int range_index ) +static unsigned int ai_range_bits_6xxx(const comedi_device * dev, + unsigned int range_index) { - const comedi_krange *range = &board( dev )->ai_range_table->range[ range_index ]; + const comedi_krange *range = + &board(dev)->ai_range_table->range[range_index]; unsigned int bits = 0; - switch( range->max ) - { - case 10000000: - bits = 0x000; - break; - case 5000000: - bits = 0x100; - break; - case 2000000: - case 2500000: - bits = 0x200; - break; - case 1000000: - case 1250000: - bits = 0x300; - break; - case 500000: - bits = 0x400; - break; - case 200000: - case 250000: - bits = 0x500; - break; - case 100000: - bits = 0x600; - break; - case 50000: - bits = 0x700; - break; - default: - comedi_error( dev, "bug! in ai_range_bits_6xxx" ); - break; + switch (range->max) { + case 10000000: + bits = 0x000; + break; + case 5000000: + bits = 0x100; + break; + case 2000000: + case 2500000: + bits = 0x200; + break; + case 1000000: + case 1250000: + bits = 0x300; + break; + case 500000: + bits = 0x400; + break; + case 200000: + case 250000: + bits = 0x500; + break; + case 100000: + bits = 0x600; + break; + case 50000: + bits = 0x700; + break; + default: + comedi_error(dev, "bug! in ai_range_bits_6xxx"); + break; } - if( range->min == 0 ) bits += 0x900; + if (range->min == 0) + bits += 0x900; return bits; } -static unsigned int hw_revision( const comedi_device *dev, uint16_t hw_status_bits ) +static unsigned int hw_revision(const comedi_device * dev, + uint16_t hw_status_bits) { - if( board(dev)->layout == LAYOUT_4020) - return ( hw_status_bits >> 13 ) & 0x7; + if (board(dev)->layout == LAYOUT_4020) + return (hw_status_bits >> 13) & 0x7; - return ( hw_status_bits >> 12) & 0xf; + return (hw_status_bits >> 12) & 0xf; } -static void set_dac_range_bits(comedi_device *dev, volatile uint16_t *bits, +static void set_dac_range_bits(comedi_device * dev, volatile uint16_t * bits, unsigned int channel, unsigned int range) { - unsigned int code = board(dev)->ao_range_code[ range ]; + unsigned int code = board(dev)->ao_range_code[range]; - if(channel > 1) comedi_error(dev, "bug! bad channel?"); - if(code & ~0x3) comedi_error(dev, "bug! bad range code?"); + if (channel > 1) + comedi_error(dev, "bug! bad channel?"); + if (code & ~0x3) + comedi_error(dev, "bug! bad range code?"); *bits &= ~(0x3 << (2 * channel)); *bits |= code << (2 * channel); }; -static inline int ao_cmd_is_supported(const pcidas64_board *board) +static inline int ao_cmd_is_supported(const pcidas64_board * board) { return board->ao_nchan && board->layout != LAYOUT_4020; } // initialize plx9080 chip -static void init_plx9080(comedi_device *dev) +static void init_plx9080(comedi_device * dev) { uint32_t bits; void *plx_iobase = priv(dev)->plx9080_iobase; - priv(dev)->plx_control_bits = readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG); + priv(dev)->plx_control_bits = + readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG); // plx9080 dump - DEBUG_PRINT(" plx interrupt status 0x%x\n", readl(plx_iobase + PLX_INTRCS_REG)); + DEBUG_PRINT(" plx interrupt status 0x%x\n", + readl(plx_iobase + PLX_INTRCS_REG)); DEBUG_PRINT(" plx id bits 0x%x\n", readl(plx_iobase + PLX_ID_REG)); DEBUG_PRINT(" plx control reg 0x%x\n", priv(dev)->plx_control_bits); - DEBUG_PRINT(" plx mode/arbitration reg 0x%x\n", readl(plx_iobase + PLX_MARB_REG)); - DEBUG_PRINT(" plx region0 reg 0x%x\n", readl(plx_iobase + PLX_REGION0_REG)); - DEBUG_PRINT(" plx region1 reg 0x%x\n", readl(plx_iobase + PLX_REGION1_REG)); - - DEBUG_PRINT(" plx revision 0x%x\n", readl(plx_iobase + PLX_REVISION_REG)); - DEBUG_PRINT(" plx dma channel 0 mode 0x%x\n", readl(plx_iobase + PLX_DMA0_MODE_REG)); - DEBUG_PRINT(" plx dma channel 1 mode 0x%x\n", readl(plx_iobase + PLX_DMA1_MODE_REG)); - DEBUG_PRINT(" plx dma channel 0 pci address 0x%x\n", readl(plx_iobase + PLX_DMA0_PCI_ADDRESS_REG)); - DEBUG_PRINT(" plx dma channel 0 local address 0x%x\n", readl(plx_iobase + PLX_DMA0_LOCAL_ADDRESS_REG)); - DEBUG_PRINT(" plx dma channel 0 transfer size 0x%x\n", readl(plx_iobase + PLX_DMA0_TRANSFER_SIZE_REG)); - DEBUG_PRINT(" plx dma channel 0 descriptor 0x%x\n", readl(plx_iobase + PLX_DMA0_DESCRIPTOR_REG)); - DEBUG_PRINT(" plx dma channel 0 command status 0x%x\n", readb(plx_iobase + PLX_DMA0_CS_REG)); - DEBUG_PRINT(" plx dma channel 0 threshold 0x%x\n", readl(plx_iobase + PLX_DMA0_THRESHOLD_REG)); + DEBUG_PRINT(" plx mode/arbitration reg 0x%x\n", + readl(plx_iobase + PLX_MARB_REG)); + DEBUG_PRINT(" plx region0 reg 0x%x\n", + readl(plx_iobase + PLX_REGION0_REG)); + DEBUG_PRINT(" plx region1 reg 0x%x\n", + readl(plx_iobase + PLX_REGION1_REG)); + + DEBUG_PRINT(" plx revision 0x%x\n", + readl(plx_iobase + PLX_REVISION_REG)); + DEBUG_PRINT(" plx dma channel 0 mode 0x%x\n", + readl(plx_iobase + PLX_DMA0_MODE_REG)); + DEBUG_PRINT(" plx dma channel 1 mode 0x%x\n", + readl(plx_iobase + PLX_DMA1_MODE_REG)); + DEBUG_PRINT(" plx dma channel 0 pci address 0x%x\n", + readl(plx_iobase + PLX_DMA0_PCI_ADDRESS_REG)); + DEBUG_PRINT(" plx dma channel 0 local address 0x%x\n", + readl(plx_iobase + PLX_DMA0_LOCAL_ADDRESS_REG)); + DEBUG_PRINT(" plx dma channel 0 transfer size 0x%x\n", + readl(plx_iobase + PLX_DMA0_TRANSFER_SIZE_REG)); + DEBUG_PRINT(" plx dma channel 0 descriptor 0x%x\n", + readl(plx_iobase + PLX_DMA0_DESCRIPTOR_REG)); + DEBUG_PRINT(" plx dma channel 0 command status 0x%x\n", + readb(plx_iobase + PLX_DMA0_CS_REG)); + DEBUG_PRINT(" plx dma channel 0 threshold 0x%x\n", + readl(plx_iobase + PLX_DMA0_THRESHOLD_REG)); DEBUG_PRINT(" plx bigend 0x%x\n", readl(plx_iobase + PLX_BIGEND_REG)); #ifdef __BIG_ENDIAN @@ -1299,7 +1304,7 @@ static void init_plx9080(comedi_device *dev) #endif writel(bits, priv(dev)->plx9080_iobase + PLX_BIGEND_REG); - disable_plx_interrupts( dev ); + disable_plx_interrupts(dev); abort_dma(dev, 0); abort_dma(dev, 1); @@ -1323,32 +1328,32 @@ static void init_plx9080(comedi_device *dev) // enable local burst mode bits |= PLX_DMA_LOCAL_BURST_EN_BIT; // 4020 uses 32 bit dma - if(board(dev)->layout == LAYOUT_4020) - { + if (board(dev)->layout == LAYOUT_4020) { bits |= PLX_LOCAL_BUS_32_WIDE_BITS; - }else - { // localspace0 bus is 16 bits wide + } else { // localspace0 bus is 16 bits wide bits |= PLX_LOCAL_BUS_16_WIDE_BITS; } writel(bits, plx_iobase + PLX_DMA1_MODE_REG); - if(ao_cmd_is_supported(board(dev))) + if (ao_cmd_is_supported(board(dev))) writel(bits, plx_iobase + PLX_DMA0_MODE_REG); // enable interrupts on plx 9080 - priv(dev)->plx_intcsr_bits |= ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | - ICS_LIE | ICS_DMA0_E | ICS_DMA1_E; - writel(priv(dev)->plx_intcsr_bits, priv(dev)->plx9080_iobase + PLX_INTRCS_REG); + priv(dev)->plx_intcsr_bits |= + ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | ICS_LIE | + ICS_DMA0_E | ICS_DMA1_E; + writel(priv(dev)->plx_intcsr_bits, + priv(dev)->plx9080_iobase + PLX_INTRCS_REG); } /* Allocate and initialize the subdevice structures. */ -static int setup_subdevices(comedi_device *dev) +static int setup_subdevices(comedi_device * dev) { comedi_subdevice *s; void *dio_8255_iobase; int i; - if( alloc_subdevices( dev, 10 ) < 0 ) + if (alloc_subdevices(dev, 10) < 0) return -ENOMEM; s = dev->subdevices + 0; @@ -1356,9 +1361,9 @@ static int setup_subdevices(comedi_device *dev) dev->read_subdev = s; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DITHER | SDF_CMD_READ; - if(board(dev)->layout == LAYOUT_60XX) + if (board(dev)->layout == LAYOUT_60XX) s->subdev_flags |= SDF_COMMON | SDF_DIFF; - else if(board(dev)->layout == LAYOUT_64XX) + else if (board(dev)->layout == LAYOUT_64XX) s->subdev_flags |= SDF_DIFF; /* XXX Number of inputs in differential mode is ignored */ s->n_chan = board(dev)->ai_se_chans; @@ -1370,47 +1375,44 @@ static int setup_subdevices(comedi_device *dev) s->do_cmd = ai_cmd; s->do_cmdtest = ai_cmdtest; s->cancel = ai_cancel; - if(board(dev)->layout == LAYOUT_4020) - { + if (board(dev)->layout == LAYOUT_4020) { unsigned int i; uint8_t data; // set adc to read from inputs (not internal calibration sources) - priv(dev)->i2c_cal_range_bits = adc_src_4020_bits( 4 ); + priv(dev)->i2c_cal_range_bits = adc_src_4020_bits(4); // set channels to +-5 volt input ranges - for( i = 0; i < s->n_chan; i++) - priv(dev)->i2c_cal_range_bits |= attenuate_bit( i ); + for (i = 0; i < s->n_chan; i++) + priv(dev)->i2c_cal_range_bits |= attenuate_bit(i); data = priv(dev)->i2c_cal_range_bits; i2c_write(dev, RANGE_CAL_I2C_ADDR, &data, sizeof(data)); } /* analog output subdevice */ s = dev->subdevices + 1; - if(board(dev)->ao_nchan) - { + if (board(dev)->ao_nchan) { s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE; + s->subdev_flags = + SDF_READABLE | SDF_WRITABLE | SDF_GROUND | + SDF_CMD_WRITE; s->n_chan = board(dev)->ao_nchan; s->maxdata = (1 << board(dev)->ao_bits) - 1; s->range_table = board(dev)->ao_range_table; s->insn_read = ao_readback_insn; s->insn_write = ao_winsn; - if(ao_cmd_is_supported(board(dev))) - { + if (ao_cmd_is_supported(board(dev))) { dev->write_subdev = s; s->do_cmdtest = ao_cmdtest; s->do_cmd = ao_cmd; s->len_chanlist = board(dev)->ao_nchan; s->cancel = ao_cancel; } - } else - { + } else { s->type = COMEDI_SUBD_UNUSED; } // digital input s = dev->subdevices + 2; - if(board(dev)->layout == LAYOUT_64XX) - { + if (board(dev)->layout == LAYOUT_64XX) { s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 4; @@ -1421,8 +1423,7 @@ static int setup_subdevices(comedi_device *dev) s->type = COMEDI_SUBD_UNUSED; // digital output - if(board(dev)->layout == LAYOUT_64XX) - { + if (board(dev)->layout == LAYOUT_64XX) { s = dev->subdevices + 3; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; @@ -1435,24 +1436,24 @@ static int setup_subdevices(comedi_device *dev) /* 8255 */ s = dev->subdevices + 4; - if( board(dev)->has_8255 ) - { - if(board(dev)->layout == LAYOUT_4020) - { - dio_8255_iobase = priv(dev)->main_iobase + I8255_4020_REG; - subdev_8255_init(dev, s, dio_callback_4020, (unsigned long) dio_8255_iobase); - } else - { - dio_8255_iobase = priv(dev)->dio_counter_iobase + DIO_8255_OFFSET; - subdev_8255_init(dev, s, dio_callback, (unsigned long) dio_8255_iobase); + if (board(dev)->has_8255) { + if (board(dev)->layout == LAYOUT_4020) { + dio_8255_iobase = + priv(dev)->main_iobase + I8255_4020_REG; + subdev_8255_init(dev, s, dio_callback_4020, + (unsigned long)dio_8255_iobase); + } else { + dio_8255_iobase = + priv(dev)->dio_counter_iobase + DIO_8255_OFFSET; + subdev_8255_init(dev, s, dio_callback, + (unsigned long)dio_8255_iobase); } - }else + } else s->type = COMEDI_SUBD_UNUSED; // 8 channel dio for 60xx s = dev->subdevices + 5; - if(board(dev)->layout == LAYOUT_60XX) - { + if (board(dev)->layout == LAYOUT_60XX) { s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 8; @@ -1465,37 +1466,35 @@ static int setup_subdevices(comedi_device *dev) // caldac s = dev->subdevices + 6; - s->type=COMEDI_SUBD_CALIB; + s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 8; - if(board(dev)->layout == LAYOUT_4020) + if (board(dev)->layout == LAYOUT_4020) s->maxdata = 0xfff; else s->maxdata = 0xff; s->insn_read = calib_read_insn; s->insn_write = calib_write_insn; - for( i = 0; i < s->n_chan; i++ ) - caldac_write( dev, i, s->maxdata / 2 ); + for (i = 0; i < s->n_chan; i++) + caldac_write(dev, i, s->maxdata / 2); // 2 channel ad8402 potentiometer s = dev->subdevices + 7; - if(board(dev)->layout == LAYOUT_64XX) - { + if (board(dev)->layout == LAYOUT_64XX) { s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 2; s->insn_read = ad8402_read_insn; s->insn_write = ad8402_write_insn; s->maxdata = 0xff; - for( i = 0; i < s->n_chan; i++ ) - ad8402_write( dev, i, s->maxdata / 2 ); + for (i = 0; i < s->n_chan; i++) + ad8402_write(dev, i, s->maxdata / 2); } else s->type = COMEDI_SUBD_UNUSED; //serial EEPROM, if present s = dev->subdevices + 8; - if(readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG) & CTL_EECHK) - { + if (readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG) & CTL_EECHK) { s->type = COMEDI_SUBD_MEMORY; s->subdev_flags = SDF_READABLE | SDF_INTERNAL; s->n_chan = 128; @@ -1511,171 +1510,188 @@ static int setup_subdevices(comedi_device *dev) return 0; } -static void disable_plx_interrupts( comedi_device *dev ) +static void disable_plx_interrupts(comedi_device * dev) { priv(dev)->plx_intcsr_bits = 0; - writel(priv(dev)->plx_intcsr_bits, priv(dev)->plx9080_iobase + PLX_INTRCS_REG); + writel(priv(dev)->plx_intcsr_bits, + priv(dev)->plx9080_iobase + PLX_INTRCS_REG); } -static void init_stc_registers( comedi_device *dev ) +static void init_stc_registers(comedi_device * dev) { uint16_t bits; unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); // bit should be set for 6025, although docs say boards with <= 16 chans should be cleared XXX - if(1) + if (1) priv(dev)->adc_control1_bits |= ADC_QUEUE_CONFIG_BIT; - writew( priv(dev)->adc_control1_bits, priv(dev)->main_iobase + ADC_CONTROL1_REG ); + writew(priv(dev)->adc_control1_bits, + priv(dev)->main_iobase + ADC_CONTROL1_REG); // 6402/16 manual says this register must be initialized to 0xff? writew(0xff, priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_UPPER_REG); bits = SLOW_DAC_BIT | DMA_CH_SELECT_BIT; - if(board(dev)->layout == LAYOUT_4020) + if (board(dev)->layout == LAYOUT_4020) bits |= INTERNAL_CLOCK_4020_BITS; priv(dev)->hw_config_bits |= bits; - writew(priv(dev)->hw_config_bits, priv(dev)->main_iobase + HW_CONFIG_REG); + writew(priv(dev)->hw_config_bits, + priv(dev)->main_iobase + HW_CONFIG_REG); writew(0, priv(dev)->main_iobase + DAQ_SYNC_REG); writew(0, priv(dev)->main_iobase + CALIBRATION_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // set fifos to maximum size priv(dev)->fifo_size_bits |= DAC_FIFO_BITS; - set_ai_fifo_segment_length( dev, board(dev)->ai_fifo->max_segment_length ); + set_ai_fifo_segment_length(dev, + board(dev)->ai_fifo->max_segment_length); priv(dev)->dac_control1_bits = DAC_OUTPUT_ENABLE_BIT; - priv(dev)->intr_enable_bits =/* EN_DAC_INTR_SRC_BIT | DAC_INTR_QEMPTY_BITS |*/ + priv(dev)->intr_enable_bits = /* EN_DAC_INTR_SRC_BIT | DAC_INTR_QEMPTY_BITS | */ EN_DAC_DONE_INTR_BIT | EN_DAC_UNDERRUN_BIT; - writew( priv(dev)->intr_enable_bits, priv(dev)->main_iobase + INTR_ENABLE_REG ); + writew(priv(dev)->intr_enable_bits, + priv(dev)->main_iobase + INTR_ENABLE_REG); disable_ai_pacing(dev); }; -int alloc_and_init_dma_members(comedi_device *dev) +int alloc_and_init_dma_members(comedi_device * dev) { int i; // alocate pci dma buffers - for(i = 0; i < ai_dma_ring_count(board(dev)); i++) - { + for (i = 0; i < ai_dma_ring_count(board(dev)); i++) { priv(dev)->ai_buffer[i] = - pci_alloc_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, &priv(dev)->ai_buffer_bus_addr[i]); - if(priv(dev)->ai_buffer[i] == NULL) - { + pci_alloc_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, + &priv(dev)->ai_buffer_bus_addr[i]); + if (priv(dev)->ai_buffer[i] == NULL) { return -ENOMEM; } } - for(i = 0; i < AO_DMA_RING_COUNT; i++) - { - if(ao_cmd_is_supported(board(dev))) - { + for (i = 0; i < AO_DMA_RING_COUNT; i++) { + if (ao_cmd_is_supported(board(dev))) { priv(dev)->ao_buffer[i] = - pci_alloc_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, &priv(dev)->ao_buffer_bus_addr[i]); - if(priv(dev)->ao_buffer[i] == NULL) - { + pci_alloc_consistent(priv(dev)->hw_dev, + DMA_BUFFER_SIZE, + &priv(dev)->ao_buffer_bus_addr[i]); + if (priv(dev)->ao_buffer[i] == NULL) { return -ENOMEM; } } } // allocate dma descriptors priv(dev)->ai_dma_desc = - pci_alloc_consistent(priv(dev)->hw_dev, sizeof(struct plx_dma_desc) * ai_dma_ring_count(board(dev)), + pci_alloc_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * ai_dma_ring_count(board(dev)), &priv(dev)->ai_dma_desc_bus_addr); - if(priv(dev)->ai_dma_desc == NULL) - { + if (priv(dev)->ai_dma_desc == NULL) { return -ENOMEM; } DEBUG_PRINT("ai dma descriptors start at bus addr 0x%x\n", priv(dev)->ai_dma_desc_bus_addr); - if(ao_cmd_is_supported(board(dev))) - { + if (ao_cmd_is_supported(board(dev))) { priv(dev)->ao_dma_desc = - pci_alloc_consistent(priv(dev)->hw_dev, sizeof(struct plx_dma_desc) * AO_DMA_RING_COUNT, + pci_alloc_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * AO_DMA_RING_COUNT, &priv(dev)->ao_dma_desc_bus_addr); - if(priv(dev)->ao_dma_desc == NULL) - { + if (priv(dev)->ao_dma_desc == NULL) { return -ENOMEM; } DEBUG_PRINT("ao dma descriptors start at bus addr 0x%x\n", priv(dev)->ao_dma_desc_bus_addr); } // initialize dma descriptors - for(i = 0; i < ai_dma_ring_count(board(dev)); i++) - { - priv(dev)->ai_dma_desc[i].pci_start_addr = cpu_to_le32(priv(dev)->ai_buffer_bus_addr[i]); - if(board(dev)->layout == LAYOUT_4020) - priv(dev)->ai_dma_desc[i].local_start_addr = cpu_to_le32(priv(dev)->local1_iobase + ADC_FIFO_REG); + for (i = 0; i < ai_dma_ring_count(board(dev)); i++) { + priv(dev)->ai_dma_desc[i].pci_start_addr = + cpu_to_le32(priv(dev)->ai_buffer_bus_addr[i]); + if (board(dev)->layout == LAYOUT_4020) + priv(dev)->ai_dma_desc[i].local_start_addr = + cpu_to_le32(priv(dev)->local1_iobase + + ADC_FIFO_REG); else - priv(dev)->ai_dma_desc[i].local_start_addr = cpu_to_le32(priv(dev)->local0_iobase + ADC_FIFO_REG); + priv(dev)->ai_dma_desc[i].local_start_addr = + cpu_to_le32(priv(dev)->local0_iobase + + ADC_FIFO_REG); priv(dev)->ai_dma_desc[i].transfer_size = cpu_to_le32(0); - priv(dev)->ai_dma_desc[i].next = cpu_to_le32((priv(dev)->ai_dma_desc_bus_addr + ((i + 1) % ai_dma_ring_count(board(dev))) * sizeof(priv(dev)->ai_dma_desc[0])) | - PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI); + priv(dev)->ai_dma_desc[i].next = + cpu_to_le32((priv(dev)->ai_dma_desc_bus_addr + ((i + + 1) % + ai_dma_ring_count(board(dev))) * + sizeof(priv(dev)-> + ai_dma_desc[0])) | PLX_DESC_IN_PCI_BIT | + PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI); } - if(ao_cmd_is_supported(board(dev))) - { - for(i = 0; i < AO_DMA_RING_COUNT; i++) - { - priv(dev)->ao_dma_desc[i].pci_start_addr = cpu_to_le32(priv(dev)->ao_buffer_bus_addr[i]); - priv(dev)->ao_dma_desc[i].local_start_addr = cpu_to_le32(priv(dev)->local0_iobase + DAC_FIFO_REG); - priv(dev)->ao_dma_desc[i].transfer_size = cpu_to_le32(0); - priv(dev)->ao_dma_desc[i].next = cpu_to_le32((priv(dev)->ao_dma_desc_bus_addr + ((i + 1) % (AO_DMA_RING_COUNT)) * sizeof(priv(dev)->ao_dma_desc[0])) | + if (ao_cmd_is_supported(board(dev))) { + for (i = 0; i < AO_DMA_RING_COUNT; i++) { + priv(dev)->ao_dma_desc[i].pci_start_addr = + cpu_to_le32(priv(dev)->ao_buffer_bus_addr[i]); + priv(dev)->ao_dma_desc[i].local_start_addr = + cpu_to_le32(priv(dev)->local0_iobase + + DAC_FIFO_REG); + priv(dev)->ao_dma_desc[i].transfer_size = + cpu_to_le32(0); + priv(dev)->ao_dma_desc[i].next = + cpu_to_le32((priv(dev)->ao_dma_desc_bus_addr + + ((i + 1) % (AO_DMA_RING_COUNT)) * + sizeof(priv(dev)-> + ao_dma_desc[0])) | PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT); } } return 0; } -static inline void warn_external_queue(comedi_device *dev) +static inline void warn_external_queue(comedi_device * dev) { - comedi_error(dev, "AO command and AI external channel queue cannot be used simultaneously."); - comedi_error(dev, "Use internal AI channel queue (channels must be consecutive and use same range/aref)"); + comedi_error(dev, + "AO command and AI external channel queue cannot be used simultaneously."); + comedi_error(dev, + "Use internal AI channel queue (channels must be consecutive and use same range/aref)"); } /* * Attach is called by the Comedi core to configure the driver * for a particular board. */ -static int attach(comedi_device *dev, comedi_devconfig *it) +static int attach(comedi_device * dev, comedi_devconfig * it) { - struct pci_dev* pcidev; + struct pci_dev *pcidev; int index; uint32_t local_range, local_decode; int retval; - printk("comedi%d: cb_pcidas64\n",dev->minor); + printk("comedi%d: cb_pcidas64\n", dev->minor); /* * Allocate the private structure area. */ - if(alloc_private(dev,sizeof(pcidas64_private)) < 0) + if (alloc_private(dev, sizeof(pcidas64_private)) < 0) return -ENOMEM; /* * Probe the device to determine what device in the series it is. */ - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? - if( pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS ) + if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) continue; // loop through cards supported by this driver - for(index = 0; index < num_boards(); index++) - { - if( pcidas64_boards[index].device_id != pcidev->device ) + for (index = 0; index < num_boards(); index++) { + if (pcidas64_boards[index].device_id != pcidev->device) continue; // was a particular bus/slot requested? - if( it->options[0] || it->options[1] ) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if( pcidev->bus->number != it->options[0] || - PCI_SLOT( pcidev->devfn ) != it->options[1] ) - { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } @@ -1683,11 +1699,11 @@ static int attach(comedi_device *dev, comedi_devconfig *it) dev->board_ptr = pcidas64_boards + index; break; } - if( dev->board_ptr ) break; + if (dev->board_ptr) + break; } - if( dev->board_ptr == NULL ) - { + if (dev->board_ptr == NULL) { printk("No supported ComputerBoards/MeasurementComputing card found\n"); return -EIO; } @@ -1695,59 +1711,78 @@ static int attach(comedi_device *dev, comedi_devconfig *it) printk("Found %s on bus %i, slot %i\n", board(dev)->name, pcidev->bus->number, PCI_SLOT(pcidev->devfn)); - if( comedi_pci_enable( pcidev, driver_cb_pcidas.driver_name ) ) - { - printk(KERN_WARNING " failed to enable PCI device and request regions\n"); + if (comedi_pci_enable(pcidev, driver_cb_pcidas.driver_name)) { + printk(KERN_WARNING + " failed to enable PCI device and request regions\n"); return -EIO; } - pci_set_master( pcidev ); + pci_set_master(pcidev); //Initialize dev->board_name dev->board_name = board(dev)->name; - priv(dev)->plx9080_phys_iobase = pci_resource_start(pcidev, PLX9080_BADDRINDEX); - priv(dev)->main_phys_iobase = pci_resource_start(pcidev, MAIN_BADDRINDEX); - priv(dev)->dio_counter_phys_iobase = pci_resource_start(pcidev, DIO_COUNTER_BADDRINDEX); + priv(dev)->plx9080_phys_iobase = + pci_resource_start(pcidev, PLX9080_BADDRINDEX); + priv(dev)->main_phys_iobase = + pci_resource_start(pcidev, MAIN_BADDRINDEX); + priv(dev)->dio_counter_phys_iobase = + pci_resource_start(pcidev, DIO_COUNTER_BADDRINDEX); // remap, won't work with 2.0 kernels but who cares priv(dev)->plx9080_iobase = ioremap(priv(dev)->plx9080_phys_iobase, pci_resource_len(pcidev, PLX9080_BADDRINDEX)); priv(dev)->main_iobase = ioremap(priv(dev)->main_phys_iobase, pci_resource_len(pcidev, MAIN_BADDRINDEX)); - priv(dev)->dio_counter_iobase = ioremap(priv(dev)->dio_counter_phys_iobase, + priv(dev)->dio_counter_iobase = + ioremap(priv(dev)->dio_counter_phys_iobase, pci_resource_len(pcidev, DIO_COUNTER_BADDRINDEX)); - if (!priv(dev)->plx9080_iobase || !priv(dev)->main_iobase || !priv(dev)->dio_counter_iobase) - { + if (!priv(dev)->plx9080_iobase || !priv(dev)->main_iobase + || !priv(dev)->dio_counter_iobase) { printk(" failed to remap io memory\n"); return -ENOMEM; } DEBUG_PRINT(" plx9080 remapped to 0x%p\n", priv(dev)->plx9080_iobase); DEBUG_PRINT(" main remapped to 0x%p\n", priv(dev)->main_iobase); - DEBUG_PRINT(" diocounter remapped to 0x%p\n", priv(dev)->dio_counter_iobase); + DEBUG_PRINT(" diocounter remapped to 0x%p\n", + priv(dev)->dio_counter_iobase); // figure out what local addresses are - local_range = readl(priv(dev)->plx9080_iobase + PLX_LAS0RNG_REG) & LRNG_MEM_MASK; - local_decode = readl(priv(dev)->plx9080_iobase + PLX_LAS0MAP_REG) & local_range & LMAP_MEM_MASK ; - priv(dev)->local0_iobase = ((uint32_t)priv(dev)->main_phys_iobase & ~local_range) | local_decode; - local_range = readl(priv(dev)->plx9080_iobase + PLX_LAS1RNG_REG) & LRNG_MEM_MASK; - local_decode = readl(priv(dev)->plx9080_iobase + PLX_LAS1MAP_REG) & local_range & LMAP_MEM_MASK ; - priv(dev)->local1_iobase = ((uint32_t)priv(dev)->dio_counter_phys_iobase & ~local_range) | local_decode; + local_range = + readl(priv(dev)->plx9080_iobase + + PLX_LAS0RNG_REG) & LRNG_MEM_MASK; + local_decode = + readl(priv(dev)->plx9080_iobase + + PLX_LAS0MAP_REG) & local_range & LMAP_MEM_MASK; + priv(dev)->local0_iobase = + ((uint32_t) priv(dev)-> + main_phys_iobase & ~local_range) | local_decode; + local_range = + readl(priv(dev)->plx9080_iobase + + PLX_LAS1RNG_REG) & LRNG_MEM_MASK; + local_decode = + readl(priv(dev)->plx9080_iobase + + PLX_LAS1MAP_REG) & local_range & LMAP_MEM_MASK; + priv(dev)->local1_iobase = + ((uint32_t) priv(dev)-> + dio_counter_phys_iobase & ~local_range) | local_decode; DEBUG_PRINT(" local 0 io addr 0x%x\n", priv(dev)->local0_iobase); DEBUG_PRINT(" local 1 io addr 0x%x\n", priv(dev)->local1_iobase); retval = alloc_and_init_dma_members(dev); - if(retval < 0) return retval; + if (retval < 0) + return retval; - priv(dev)->hw_revision = hw_revision( dev, readw(priv(dev)->main_iobase + HW_STATUS_REG ) ); + priv(dev)->hw_revision = + hw_revision(dev, readw(priv(dev)->main_iobase + HW_STATUS_REG)); printk(" stc hardware revision %i\n", priv(dev)->hw_revision); init_plx9080(dev); - init_stc_registers( dev ); + init_stc_registers(dev); // get irq - if(comedi_request_irq(pcidev->irq, handle_interrupt, IRQF_SHARED, "cb_pcidas64", dev )) - { + if (comedi_request_irq(pcidev->irq, handle_interrupt, IRQF_SHARED, + "cb_pcidas64", dev)) { printk(" unable to allocate irq %u\n", pcidev->irq); return -EINVAL; } @@ -1755,8 +1790,7 @@ static int attach(comedi_device *dev, comedi_devconfig *it) printk(" irq %u\n", dev->irq); retval = setup_subdevices(dev); - if(retval < 0) - { + if (retval < 0) { return retval; } @@ -1771,61 +1805,68 @@ static int attach(comedi_device *dev, comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int detach(comedi_device *dev) +static int detach(comedi_device * dev) { unsigned int i; - printk("comedi%d: cb_pcidas: remove\n",dev->minor); + printk("comedi%d: cb_pcidas: remove\n", dev->minor); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(priv(dev)) - { - if( priv(dev)->hw_dev ) - { - if(priv(dev)->plx9080_iobase) - { - disable_plx_interrupts( dev ); - iounmap((void*)priv(dev)->plx9080_iobase); + if (priv(dev)) { + if (priv(dev)->hw_dev) { + if (priv(dev)->plx9080_iobase) { + disable_plx_interrupts(dev); + iounmap((void *)priv(dev)->plx9080_iobase); } - if(priv(dev)->main_iobase) - iounmap((void*)priv(dev)->main_iobase); - if(priv(dev)->dio_counter_iobase) - iounmap((void*)priv(dev)->dio_counter_iobase); + if (priv(dev)->main_iobase) + iounmap((void *)priv(dev)->main_iobase); + if (priv(dev)->dio_counter_iobase) + iounmap((void *)priv(dev)->dio_counter_iobase); // free pci dma buffers - for(i = 0; i < ai_dma_ring_count(board(dev)); i++) - { - if( priv(dev)->ai_buffer[i] ) - pci_free_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, - priv(dev)->ai_buffer[i], priv(dev)->ai_buffer_bus_addr[i]); + for (i = 0; i < ai_dma_ring_count(board(dev)); i++) { + if (priv(dev)->ai_buffer[i]) + pci_free_consistent(priv(dev)->hw_dev, + DMA_BUFFER_SIZE, + priv(dev)->ai_buffer[i], + priv(dev)-> + ai_buffer_bus_addr[i]); } - for(i = 0; i < AO_DMA_RING_COUNT; i++) - { - if( priv(dev)->ao_buffer[i] ) - pci_free_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, - priv(dev)->ao_buffer[i], priv(dev)->ao_buffer_bus_addr[i]); + for (i = 0; i < AO_DMA_RING_COUNT; i++) { + if (priv(dev)->ao_buffer[i]) + pci_free_consistent(priv(dev)->hw_dev, + DMA_BUFFER_SIZE, + priv(dev)->ao_buffer[i], + priv(dev)-> + ao_buffer_bus_addr[i]); } // free dma descriptors - if(priv(dev)->ai_dma_desc) - pci_free_consistent(priv(dev)->hw_dev, sizeof(struct plx_dma_desc) * ai_dma_ring_count(board(dev)), - priv(dev)->ai_dma_desc, priv(dev)->ai_dma_desc_bus_addr); - if(priv(dev)->ao_dma_desc) - pci_free_consistent(priv(dev)->hw_dev, sizeof(struct plx_dma_desc) * AO_DMA_RING_COUNT, - priv(dev)->ao_dma_desc, priv(dev)->ao_dma_desc_bus_addr ); - if(priv(dev)->main_phys_iobase) - { + if (priv(dev)->ai_dma_desc) + pci_free_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * + ai_dma_ring_count(board(dev)), + priv(dev)->ai_dma_desc, + priv(dev)->ai_dma_desc_bus_addr); + if (priv(dev)->ao_dma_desc) + pci_free_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * + AO_DMA_RING_COUNT, + priv(dev)->ao_dma_desc, + priv(dev)->ao_dma_desc_bus_addr); + if (priv(dev)->main_phys_iobase) { comedi_pci_disable(priv(dev)->hw_dev); } pci_dev_put(priv(dev)->hw_dev); } } - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 4); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 4); return 0; } -static int ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int bits = 0, n, i; unsigned int channel, range, aref; @@ -1839,138 +1880,139 @@ static int ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsa // disable card's analog input interrupt sources and pacing // 4020 generates dac done interrupts even though they are disabled - disable_ai_pacing( dev ); + disable_ai_pacing(dev); - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - if( insn->chanspec & CR_ALT_FILTER ) + comedi_spin_lock_irqsave(&dev->spinlock, flags); + if (insn->chanspec & CR_ALT_FILTER) priv(dev)->adc_control1_bits |= ADC_DITHER_BIT; else priv(dev)->adc_control1_bits &= ~ADC_DITHER_BIT; - writew( priv(dev)->adc_control1_bits, priv(dev)->main_iobase + ADC_CONTROL1_REG ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + writew(priv(dev)->adc_control1_bits, + priv(dev)->main_iobase + ADC_CONTROL1_REG); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - if(board(dev)->layout != LAYOUT_4020) - { + if (board(dev)->layout != LAYOUT_4020) { // use internal queue priv(dev)->hw_config_bits &= ~EXT_QUEUE_BIT; - writew(priv(dev)->hw_config_bits, priv(dev)->main_iobase + HW_CONFIG_REG); + writew(priv(dev)->hw_config_bits, + priv(dev)->main_iobase + HW_CONFIG_REG); // ALT_SOURCE is internal calibration reference - if(insn->chanspec & CR_ALT_SOURCE) - { + if (insn->chanspec & CR_ALT_SOURCE) { unsigned int cal_en_bit; DEBUG_PRINT("reading calibration source\n"); - if( board(dev)->layout == LAYOUT_60XX) + if (board(dev)->layout == LAYOUT_60XX) cal_en_bit = CAL_EN_60XX_BIT; else cal_en_bit = CAL_EN_64XX_BIT; // select internal reference source to connect to channel 0 - writew(cal_en_bit | adc_src_bits( priv(dev)->calibration_source ), + writew(cal_en_bit | adc_src_bits(priv(dev)-> + calibration_source), priv(dev)->main_iobase + CALIBRATION_REG); - } else - { + } else { // make sure internal calibration source is turned off writew(0, priv(dev)->main_iobase + CALIBRATION_REG); } // load internal queue bits = 0; // set gain - bits |= ai_range_bits_6xxx( dev, CR_RANGE(insn->chanspec) ); + bits |= ai_range_bits_6xxx(dev, CR_RANGE(insn->chanspec)); // set single-ended / differential bits |= se_diff_bit_6xxx(dev, aref == AREF_DIFF); - if(aref == AREF_COMMON) + if (aref == AREF_COMMON) bits |= ADC_COMMON_BIT; - bits |= adc_chan_bits( channel ); + bits |= adc_chan_bits(channel); // set stop channel - writew( adc_chan_bits( channel ), priv(dev)->main_iobase + ADC_QUEUE_HIGH_REG ); + writew(adc_chan_bits(channel), + priv(dev)->main_iobase + ADC_QUEUE_HIGH_REG); // set start channel, and rest of settings writew(bits, priv(dev)->main_iobase + ADC_QUEUE_LOAD_REG); - }else - { + } else { uint8_t old_cal_range_bits = priv(dev)->i2c_cal_range_bits; priv(dev)->i2c_cal_range_bits &= ~ADC_SRC_4020_MASK; - if(insn->chanspec & CR_ALT_SOURCE) - { + if (insn->chanspec & CR_ALT_SOURCE) { DEBUG_PRINT("reading calibration source\n"); - priv(dev)->i2c_cal_range_bits |= adc_src_4020_bits( priv(dev)->calibration_source ); - } else - { //select BNC inputs - priv(dev)->i2c_cal_range_bits |= adc_src_4020_bits( 4 ); + priv(dev)->i2c_cal_range_bits |= + adc_src_4020_bits(priv(dev)-> + calibration_source); + } else { //select BNC inputs + priv(dev)->i2c_cal_range_bits |= adc_src_4020_bits(4); } // select range - if(range == 0) - priv(dev)->i2c_cal_range_bits |= attenuate_bit( channel ); + if (range == 0) + priv(dev)->i2c_cal_range_bits |= attenuate_bit(channel); else - priv(dev)->i2c_cal_range_bits &= ~attenuate_bit( channel ); + priv(dev)->i2c_cal_range_bits &= + ~attenuate_bit(channel); // update calibration/range i2c register only if necessary, as it is very slow - if(old_cal_range_bits != priv(dev)->i2c_cal_range_bits) - { + if (old_cal_range_bits != priv(dev)->i2c_cal_range_bits) { uint8_t i2c_data = priv(dev)->i2c_cal_range_bits; - i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, sizeof(i2c_data)); + i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, + sizeof(i2c_data)); } /* 4020 manual asks that sample interval register to be set before writing to convert register. * Using somewhat arbitrary setting of 4 master clock ticks = 0.1 usec */ - writew(0, priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_UPPER_REG); - writew(2, priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_LOWER_REG); + writew(0, + priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_UPPER_REG); + writew(2, + priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_LOWER_REG); } - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { // clear adc buffer (inside loop for 4020 sake) writew(0, priv(dev)->main_iobase + ADC_BUFFER_CLEAR_REG); /* trigger conversion, bits sent only matter for 4020 */ - writew( adc_convert_chan_4020_bits( CR_CHAN( insn->chanspec ) ), - priv(dev)->main_iobase + ADC_CONVERT_REG ); + writew(adc_convert_chan_4020_bits(CR_CHAN(insn->chanspec)), + priv(dev)->main_iobase + ADC_CONVERT_REG); // wait for data - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { bits = readw(priv(dev)->main_iobase + HW_STATUS_REG); - DEBUG_PRINT(" pipe bits 0x%x\n", pipe_full_bits( bits ) ); - if(board(dev)->layout == LAYOUT_4020) - { - if( readw( priv(dev)->main_iobase + ADC_WRITE_PNTR_REG ) ) + DEBUG_PRINT(" pipe bits 0x%x\n", pipe_full_bits(bits)); + if (board(dev)->layout == LAYOUT_4020) { + if (readw(priv(dev)->main_iobase + + ADC_WRITE_PNTR_REG)) break; - }else - { - if( pipe_full_bits( bits ) ) + } else { + if (pipe_full_bits(bits)) break; } comedi_udelay(1); } DEBUG_PRINT(" looped %i times waiting for data\n", i); - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, " analog input read insn timed out"); rt_printk(" status 0x%x\n", bits); return -ETIME; } - if(board(dev)->layout == LAYOUT_4020) - data[n] = readl(priv(dev)->dio_counter_iobase + ADC_FIFO_REG) & 0xffff; + if (board(dev)->layout == LAYOUT_4020) + data[n] = + readl(priv(dev)->dio_counter_iobase + + ADC_FIFO_REG) & 0xffff; else - data[n] = readw(priv(dev)->main_iobase + PIPE1_READ_REG); + data[n] = + readw(priv(dev)->main_iobase + PIPE1_READ_REG); } return n; } -static int ai_config_calibration_source( comedi_device *dev, lsampl_t *data ) +static int ai_config_calibration_source(comedi_device * dev, lsampl_t * data) { lsampl_t source = data[1]; int num_calibration_sources; - if( board(dev)->layout == LAYOUT_60XX) + if (board(dev)->layout == LAYOUT_60XX) num_calibration_sources = 16; else num_calibration_sources = 8; - if(source >= num_calibration_sources) - { - printk( "invalid calibration source: %i\n", source ); + if (source >= num_calibration_sources) { + printk("invalid calibration source: %i\n", source); return -EINVAL; } @@ -1980,51 +2022,51 @@ static int ai_config_calibration_source( comedi_device *dev, lsampl_t *data ) return 2; } -static int ai_config_block_size( comedi_device *dev, lsampl_t *data ) +static int ai_config_block_size(comedi_device * dev, lsampl_t * data) { int fifo_size; const hw_fifo_info_t *const fifo = board(dev)->ai_fifo; unsigned int block_size, requested_block_size; int retval; - requested_block_size = data[ 1 ]; + requested_block_size = data[1]; - if( requested_block_size ) - { - fifo_size = requested_block_size * fifo->num_segments / bytes_in_sample; + if (requested_block_size) { + fifo_size = + requested_block_size * fifo->num_segments / + bytes_in_sample; - retval = set_ai_fifo_size( dev, fifo_size ); - if( retval < 0 ) return retval; + retval = set_ai_fifo_size(dev, fifo_size); + if (retval < 0) + return retval; } - block_size = ai_fifo_size( dev ) / fifo->num_segments * bytes_in_sample; + block_size = ai_fifo_size(dev) / fifo->num_segments * bytes_in_sample; - data[ 1 ] = block_size; + data[1] = block_size; return 2; } -static int ai_config_master_clock_4020( comedi_device *dev, lsampl_t *data ) +static int ai_config_master_clock_4020(comedi_device * dev, lsampl_t * data) { unsigned int divisor = data[4]; int retval = 0; - if( divisor < 2 ) - { + if (divisor < 2) { divisor = 2; retval = -EAGAIN; } - switch( data[1] ) - { - case COMEDI_EV_SCAN_BEGIN: - priv(dev)->ext_clock.divisor = divisor; - priv(dev)->ext_clock.chanspec = data[2]; - break; - default: - return -EINVAL; - break; + switch (data[1]) { + case COMEDI_EV_SCAN_BEGIN: + priv(dev)->ext_clock.divisor = divisor; + priv(dev)->ext_clock.chanspec = data[2]; + break; + default: + return -EINVAL; + break; } data[4] = divisor; @@ -2033,45 +2075,45 @@ static int ai_config_master_clock_4020( comedi_device *dev, lsampl_t *data ) } // XXX could add support for 60xx series -static int ai_config_master_clock( comedi_device *dev, lsampl_t *data ) +static int ai_config_master_clock(comedi_device * dev, lsampl_t * data) { - switch( board(dev)->layout ) - { - case LAYOUT_4020: - return ai_config_master_clock_4020( dev, data ); - break; - default: - return -EINVAL; - break; + switch (board(dev)->layout) { + case LAYOUT_4020: + return ai_config_master_clock_4020(dev, data); + break; + default: + return -EINVAL; + break; } return -EINVAL; } -static int ai_config_insn( comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ai_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int id = data[0]; - switch( id ) - { - case INSN_CONFIG_ALT_SOURCE: - return ai_config_calibration_source( dev, data ); - break; - case INSN_CONFIG_BLOCK_SIZE: - return ai_config_block_size( dev, data ); - break; - case INSN_CONFIG_TIMER_1: - return ai_config_master_clock( dev, data ); - break; - default: - return -EINVAL; - break; + switch (id) { + case INSN_CONFIG_ALT_SOURCE: + return ai_config_calibration_source(dev, data); + break; + case INSN_CONFIG_BLOCK_SIZE: + return ai_config_block_size(dev, data); + break; + case INSN_CONFIG_TIMER_1: + return ai_config_master_clock(dev, data); + break; + default: + return -EINVAL; + break; } return -EINVAL; } -static int ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) +static int ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -2084,287 +2126,287 @@ static int ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; triggers = TRIG_TIMER; - if(board(dev)->layout == LAYOUT_4020) + if (board(dev)->layout == LAYOUT_4020) triggers |= TRIG_OTHER; else triggers |= TRIG_FOLLOW; cmd->scan_begin_src &= triggers; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; triggers = TRIG_TIMER; - if(board(dev)->layout == LAYOUT_4020) + if (board(dev)->layout == LAYOUT_4020) triggers |= TRIG_NOW; else triggers |= TRIG_EXT; cmd->convert_src &= triggers; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ // uniqueness check - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_OTHER && - cmd->scan_begin_src != TRIG_FOLLOW) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT && - cmd->convert_src != TRIG_NOW ) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE && - cmd->stop_src != TRIG_EXT) err++; + cmd->scan_begin_src != TRIG_FOLLOW) + err++; + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT) + err++; // compatibility check - if(cmd->convert_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER) + if (cmd->convert_src == TRIG_EXT && cmd->scan_begin_src == TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE && - cmd->stop_src != TRIG_EXT) err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->convert_src == TRIG_TIMER) - { - if(board(dev)->layout == LAYOUT_4020) - { - if( cmd->convert_arg ) - { + if (cmd->convert_src == TRIG_TIMER) { + if (board(dev)->layout == LAYOUT_4020) { + if (cmd->convert_arg) { cmd->convert_arg = 0; err++; } - }else - { - if(cmd->convert_arg < board(dev)->ai_speed) - { + } else { + if (cmd->convert_arg < board(dev)->ai_speed) { cmd->convert_arg = board(dev)->ai_speed; err++; } - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { // if scans are timed faster than conversion rate allows - if(cmd->convert_arg * cmd->chanlist_len > cmd->scan_begin_arg) - { - cmd->scan_begin_arg = cmd->convert_arg * cmd->chanlist_len; + if (cmd->convert_arg * cmd->chanlist_len > + cmd->scan_begin_arg) { + cmd->scan_begin_arg = + cmd->convert_arg * + cmd->chanlist_len; err++; } } } } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - switch(cmd->stop_src) - { - case TRIG_EXT: - break; - case TRIG_COUNT: - if(!cmd->stop_arg) - { - cmd->stop_arg = 1; - err++; - } - break; - case TRIG_NONE: - if(cmd->stop_arg != 0) - { - cmd->stop_arg = 0; - err++; - } - break; - default: - break; + switch (cmd->stop_src) { + case TRIG_EXT: + break; + case TRIG_COUNT: + if (!cmd->stop_arg) { + cmd->stop_arg = 1; + err++; + } + break; + case TRIG_NONE: + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; + err++; + } + break; + default: + break; } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { tmp_arg = cmd->convert_arg; tmp_arg2 = cmd->scan_begin_arg; - check_adc_timing( dev, cmd); - if(tmp_arg != cmd->convert_arg) err++; - if(tmp_arg2 != cmd->scan_begin_arg) err++; + check_adc_timing(dev, cmd); + if (tmp_arg != cmd->convert_arg) + err++; + if (tmp_arg2 != cmd->scan_begin_arg) + err++; } - if(err) return 4; + if (err) + return 4; // make sure user is doesn't change analog reference mid chanlist - if(cmd->chanlist) - { + if (cmd->chanlist) { aref = CR_AREF(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++) - { - if(aref != CR_AREF(cmd->chanlist[i])) - { - comedi_error(dev, "all elements in chanlist must use the same analog reference"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (aref != CR_AREF(cmd->chanlist[i])) { + comedi_error(dev, + "all elements in chanlist must use the same analog reference"); err++; break; } } // check 4020 chanlist - if( board(dev)->layout == LAYOUT_4020 ) - { - unsigned int first_channel = CR_CHAN( cmd->chanlist[0] ); - for( i = 1; i < cmd->chanlist_len; i++ ) - { - if( CR_CHAN( cmd->chanlist[ i ] ) != first_channel + i ) - { - comedi_error( dev, "chanlist must use consecutive channels" ); + if (board(dev)->layout == LAYOUT_4020) { + unsigned int first_channel = CR_CHAN(cmd->chanlist[0]); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != + first_channel + i) { + comedi_error(dev, + "chanlist must use consecutive channels"); err++; break; } } - if( cmd->chanlist_len == 3 ) - { - comedi_error( dev, "chanlist cannot be 3 channels long, use 1, 2, or 4 channels" ); + if (cmd->chanlist_len == 3) { + comedi_error(dev, + "chanlist cannot be 3 channels long, use 1, 2, or 4 channels"); err++; } } } - if(err) return 5; + if (err) + return 5; return 0; } -static int use_hw_sample_counter( comedi_cmd *cmd ) +static int use_hw_sample_counter(comedi_cmd * cmd) { // disable for now until I work out a race -return 0; + return 0; - if( cmd->stop_src == TRIG_COUNT && - cmd->stop_arg <= max_counter_value ) + if (cmd->stop_src == TRIG_COUNT && cmd->stop_arg <= max_counter_value) return 1; else return 0; } -static void setup_sample_counters( comedi_device *dev, comedi_cmd *cmd ) +static void setup_sample_counters(comedi_device * dev, comedi_cmd * cmd) { - if( cmd->stop_src == TRIG_COUNT ) - { + if (cmd->stop_src == TRIG_COUNT) { // set software count priv(dev)->ai_count = cmd->stop_arg * cmd->chanlist_len; } - // load hardware conversion counter - if( use_hw_sample_counter( cmd ) ) - { - writew( cmd->stop_arg & 0xffff, priv(dev)->main_iobase + ADC_COUNT_LOWER_REG); - writew( ( cmd->stop_arg >> 16 ) & 0xff, + if (use_hw_sample_counter(cmd)) { + writew(cmd->stop_arg & 0xffff, + priv(dev)->main_iobase + ADC_COUNT_LOWER_REG); + writew((cmd->stop_arg >> 16) & 0xff, priv(dev)->main_iobase + ADC_COUNT_UPPER_REG); - } else - { - writew( 1, priv(dev)->main_iobase + ADC_COUNT_LOWER_REG); + } else { + writew(1, priv(dev)->main_iobase + ADC_COUNT_LOWER_REG); } } -static inline unsigned int dma_transfer_size( comedi_device *dev ) +static inline unsigned int dma_transfer_size(comedi_device * dev) { unsigned int num_samples; - num_samples = priv(dev)->ai_fifo_segment_length * board(dev)->ai_fifo->sample_packing_ratio; - if( num_samples > DMA_BUFFER_SIZE / sizeof( uint16_t ) ) - num_samples = DMA_BUFFER_SIZE / sizeof( uint16_t ); + num_samples = + priv(dev)->ai_fifo_segment_length * + board(dev)->ai_fifo->sample_packing_ratio; + if (num_samples > DMA_BUFFER_SIZE / sizeof(uint16_t)) + num_samples = DMA_BUFFER_SIZE / sizeof(uint16_t); return num_samples; } -static void disable_ai_pacing( comedi_device *dev ) +static void disable_ai_pacing(comedi_device * dev) { unsigned long flags; - disable_ai_interrupts( dev ); + disable_ai_interrupts(dev); - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); priv(dev)->adc_control1_bits &= ~ADC_SW_GATE_BIT; - writew( priv(dev)->adc_control1_bits, priv(dev)->main_iobase + ADC_CONTROL1_REG ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + writew(priv(dev)->adc_control1_bits, + priv(dev)->main_iobase + ADC_CONTROL1_REG); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); /* disable pacing, triggering, etc */ - writew( ADC_DMA_DISABLE_BIT | ADC_SOFT_GATE_BITS | ADC_GATE_LEVEL_BIT, - priv(dev)->main_iobase + ADC_CONTROL0_REG ); + writew(ADC_DMA_DISABLE_BIT | ADC_SOFT_GATE_BITS | ADC_GATE_LEVEL_BIT, + priv(dev)->main_iobase + ADC_CONTROL0_REG); } -static void disable_ai_interrupts( comedi_device *dev ) +static void disable_ai_interrupts(comedi_device * dev) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); priv(dev)->intr_enable_bits &= - ~EN_ADC_INTR_SRC_BIT & ~EN_ADC_DONE_INTR_BIT & ~EN_ADC_ACTIVE_INTR_BIT - & ~EN_ADC_STOP_INTR_BIT & ~EN_ADC_OVERRUN_BIT & ~ADC_INTR_SRC_MASK; - writew( priv(dev)->intr_enable_bits, priv(dev)->main_iobase + INTR_ENABLE_REG ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); - - DEBUG_PRINT( "intr enable bits 0x%x\n", priv(dev)->intr_enable_bits ); + ~EN_ADC_INTR_SRC_BIT & ~EN_ADC_DONE_INTR_BIT & + ~EN_ADC_ACTIVE_INTR_BIT & ~EN_ADC_STOP_INTR_BIT & + ~EN_ADC_OVERRUN_BIT & ~ADC_INTR_SRC_MASK; + writew(priv(dev)->intr_enable_bits, + priv(dev)->main_iobase + INTR_ENABLE_REG); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + + DEBUG_PRINT("intr enable bits 0x%x\n", priv(dev)->intr_enable_bits); } -static void enable_ai_interrupts( comedi_device *dev, const comedi_cmd *cmd ) +static void enable_ai_interrupts(comedi_device * dev, const comedi_cmd * cmd) { uint32_t bits; unsigned long flags; - bits = EN_ADC_OVERRUN_BIT | EN_ADC_DONE_INTR_BIT | EN_ADC_ACTIVE_INTR_BIT | EN_ADC_STOP_INTR_BIT; // Use pio transfer and interrupt on end of conversion if TRIG_WAKE_EOS flag is set. - if( cmd->flags & TRIG_WAKE_EOS ) - { + if (cmd->flags & TRIG_WAKE_EOS) { // 4020 doesn't support pio transfers except for fifo dregs - if( board(dev)->layout != LAYOUT_4020 ) + if (board(dev)->layout != LAYOUT_4020) bits |= ADC_INTR_EOSCAN_BITS | EN_ADC_INTR_SRC_BIT; } - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); priv(dev)->intr_enable_bits |= bits; - writew( priv(dev)->intr_enable_bits, priv(dev)->main_iobase + INTR_ENABLE_REG ); - DEBUG_PRINT( "intr enable bits 0x%x\n", priv(dev)->intr_enable_bits ); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + writew(priv(dev)->intr_enable_bits, + priv(dev)->main_iobase + INTR_ENABLE_REG); + DEBUG_PRINT("intr enable bits 0x%x\n", priv(dev)->intr_enable_bits); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } -static uint32_t ai_convert_counter_6xxx( const comedi_device *dev, const comedi_cmd *cmd ) +static uint32_t ai_convert_counter_6xxx(const comedi_device * dev, + const comedi_cmd * cmd) { // supposed to load counter with desired divisor minus 3 - return cmd->convert_arg / TIMER_BASE - 3; + return cmd->convert_arg / TIMER_BASE - 3; } -static uint32_t ai_scan_counter_6xxx( comedi_device *dev, comedi_cmd *cmd ) +static uint32_t ai_scan_counter_6xxx(comedi_device * dev, comedi_cmd * cmd) { uint32_t count; // figure out how long we need to delay at end of scan - switch( cmd->scan_begin_src ) - { + switch (cmd->scan_begin_src) { case TRIG_TIMER: - count = (cmd->scan_begin_arg - (cmd->convert_arg * (cmd->chanlist_len - 1))) + count = (cmd->scan_begin_arg - + (cmd->convert_arg * (cmd->chanlist_len - 1))) / TIMER_BASE; break; case TRIG_FOLLOW: @@ -2377,20 +2419,19 @@ static uint32_t ai_scan_counter_6xxx( comedi_device *dev, comedi_cmd *cmd ) return count - 3; } -static uint32_t ai_convert_counter_4020( comedi_device *dev, comedi_cmd *cmd ) +static uint32_t ai_convert_counter_4020(comedi_device * dev, comedi_cmd * cmd) { unsigned int divisor; - switch( cmd->scan_begin_src ) - { + switch (cmd->scan_begin_src) { case TRIG_TIMER: divisor = cmd->scan_begin_arg / TIMER_BASE; break; case TRIG_OTHER: divisor = priv(dev)->ext_clock.divisor; break; - default: // should never happen - comedi_error( dev, "bug! failed to set ai pacing!" ); + default: // should never happen + comedi_error(dev, "bug! failed to set ai pacing!"); divisor = 1000; break; } @@ -2399,153 +2440,166 @@ static uint32_t ai_convert_counter_4020( comedi_device *dev, comedi_cmd *cmd ) return divisor - 2; } -static void select_master_clock_4020( comedi_device *dev, const comedi_cmd *cmd ) +static void select_master_clock_4020(comedi_device * dev, + const comedi_cmd * cmd) { // select internal/external master clock priv(dev)->hw_config_bits &= ~MASTER_CLOCK_4020_MASK; - if( cmd->scan_begin_src == TRIG_OTHER ) - { + if (cmd->scan_begin_src == TRIG_OTHER) { int chanspec = priv(dev)->ext_clock.chanspec; - if( CR_CHAN( chanspec ) ) + if (CR_CHAN(chanspec)) priv(dev)->hw_config_bits |= BNC_CLOCK_4020_BITS; else priv(dev)->hw_config_bits |= EXT_CLOCK_4020_BITS; - }else - { + } else { priv(dev)->hw_config_bits |= INTERNAL_CLOCK_4020_BITS; } - writew(priv(dev)->hw_config_bits, priv(dev)->main_iobase + HW_CONFIG_REG); + writew(priv(dev)->hw_config_bits, + priv(dev)->main_iobase + HW_CONFIG_REG); } -static void select_master_clock( comedi_device *dev, const comedi_cmd *cmd ) +static void select_master_clock(comedi_device * dev, const comedi_cmd * cmd) { - switch( board(dev)->layout ) - { - case LAYOUT_4020: - select_master_clock_4020( dev, cmd ); - break; - default: - break; + switch (board(dev)->layout) { + case LAYOUT_4020: + select_master_clock_4020(dev, cmd); + break; + default: + break; } } -static inline void dma_start_sync(comedi_device *dev, unsigned int channel) +static inline void dma_start_sync(comedi_device * dev, unsigned int channel) { unsigned long flags; // spinlock for plx dma control/status reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - if(channel) - writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | PLX_CLEAR_DMA_INTR_BIT, + comedi_spin_lock_irqsave(&dev->spinlock, flags); + if (channel) + writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | + PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); else - writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | PLX_CLEAR_DMA_INTR_BIT, + writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | + PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } -static void set_ai_pacing( comedi_device *dev, comedi_cmd *cmd ) +static void set_ai_pacing(comedi_device * dev, comedi_cmd * cmd) { uint32_t convert_counter = 0, scan_counter = 0; - check_adc_timing( dev, cmd ); + check_adc_timing(dev, cmd); - select_master_clock( dev, cmd ); + select_master_clock(dev, cmd); - if( board(dev)->layout == LAYOUT_4020 ) - { - convert_counter = ai_convert_counter_4020( dev, cmd ); - }else - { - convert_counter = ai_convert_counter_6xxx( dev, cmd ); - scan_counter = ai_scan_counter_6xxx( dev, cmd ); + if (board(dev)->layout == LAYOUT_4020) { + convert_counter = ai_convert_counter_4020(dev, cmd); + } else { + convert_counter = ai_convert_counter_6xxx(dev, cmd); + scan_counter = ai_scan_counter_6xxx(dev, cmd); } // load lower 16 bits of convert interval - writew( convert_counter & 0xffff, priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_LOWER_REG ); - DEBUG_PRINT("convert counter 0x%x\n", convert_counter ); + writew(convert_counter & 0xffff, + priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_LOWER_REG); + DEBUG_PRINT("convert counter 0x%x\n", convert_counter); // load upper 8 bits of convert interval - writew( ( convert_counter >> 16 ) & 0xff, - priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_UPPER_REG ); + writew((convert_counter >> 16) & 0xff, + priv(dev)->main_iobase + ADC_SAMPLE_INTERVAL_UPPER_REG); // load lower 16 bits of scan delay - writew( scan_counter & 0xffff, priv(dev)->main_iobase + ADC_DELAY_INTERVAL_LOWER_REG ); + writew(scan_counter & 0xffff, + priv(dev)->main_iobase + ADC_DELAY_INTERVAL_LOWER_REG); // load upper 8 bits of scan delay - writew( ( scan_counter >> 16 ) & 0xff, - priv(dev)->main_iobase + ADC_DELAY_INTERVAL_UPPER_REG ); - DEBUG_PRINT("scan counter 0x%x\n", scan_counter ); + writew((scan_counter >> 16) & 0xff, + priv(dev)->main_iobase + ADC_DELAY_INTERVAL_UPPER_REG); + DEBUG_PRINT("scan counter 0x%x\n", scan_counter); } -static int use_internal_queue_6xxx(const comedi_cmd *cmd) +static int use_internal_queue_6xxx(const comedi_cmd * cmd) { int i; - for(i = 0; i + 1 < cmd->chanlist_len; i++) - { - if(CR_CHAN(cmd->chanlist[i + 1]) != CR_CHAN(cmd->chanlist[i]) + 1) + for (i = 0; i + 1 < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i + 1]) != + CR_CHAN(cmd->chanlist[i]) + 1) return 0; - if(CR_RANGE(cmd->chanlist[i + 1]) != CR_RANGE(cmd->chanlist[i])) + if (CR_RANGE(cmd->chanlist[i + 1]) != + CR_RANGE(cmd->chanlist[i])) return 0; - if(CR_AREF(cmd->chanlist[i + 1]) != CR_AREF(cmd->chanlist[i])) + if (CR_AREF(cmd->chanlist[i + 1]) != CR_AREF(cmd->chanlist[i])) return 0; } return 1; } -static int setup_channel_queue(comedi_device *dev, const comedi_cmd *cmd) +static int setup_channel_queue(comedi_device * dev, const comedi_cmd * cmd) { unsigned short bits; int i; - if(board(dev)->layout != LAYOUT_4020) - { - if(use_internal_queue_6xxx(cmd)) - { + if (board(dev)->layout != LAYOUT_4020) { + if (use_internal_queue_6xxx(cmd)) { priv(dev)->hw_config_bits &= ~EXT_QUEUE_BIT; - writew(priv(dev)->hw_config_bits, priv(dev)->main_iobase + HW_CONFIG_REG); + writew(priv(dev)->hw_config_bits, + priv(dev)->main_iobase + HW_CONFIG_REG); bits = 0; // set channel bits |= adc_chan_bits(CR_CHAN(cmd->chanlist[0])); // set gain - bits |= ai_range_bits_6xxx(dev, CR_RANGE(cmd->chanlist[0])); + bits |= ai_range_bits_6xxx(dev, + CR_RANGE(cmd->chanlist[0])); // set single-ended / differential - bits |= se_diff_bit_6xxx(dev, CR_AREF(cmd->chanlist[0]) == AREF_DIFF); - if(CR_AREF(cmd->chanlist[0]) == AREF_COMMON) + bits |= se_diff_bit_6xxx(dev, + CR_AREF(cmd->chanlist[0]) == AREF_DIFF); + if (CR_AREF(cmd->chanlist[0]) == AREF_COMMON) bits |= ADC_COMMON_BIT; // set stop channel - writew(adc_chan_bits(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])), priv(dev)->main_iobase + ADC_QUEUE_HIGH_REG); + writew(adc_chan_bits(CR_CHAN(cmd->chanlist[cmd-> + chanlist_len - 1])), + priv(dev)->main_iobase + ADC_QUEUE_HIGH_REG); // set start channel, and rest of settings - writew(bits, priv(dev)->main_iobase + ADC_QUEUE_LOAD_REG); - }else - { + writew(bits, + priv(dev)->main_iobase + ADC_QUEUE_LOAD_REG); + } else { // use external queue - if(dev->write_subdev && dev->write_subdev->busy) - { + if (dev->write_subdev && dev->write_subdev->busy) { warn_external_queue(dev); return -EBUSY; } priv(dev)->hw_config_bits |= EXT_QUEUE_BIT; - writew(priv(dev)->hw_config_bits, priv(dev)->main_iobase + HW_CONFIG_REG); + writew(priv(dev)->hw_config_bits, + priv(dev)->main_iobase + HW_CONFIG_REG); // clear DAC buffer to prevent weird interactions - writew(0, priv(dev)->main_iobase + DAC_BUFFER_CLEAR_REG); + writew(0, + priv(dev)->main_iobase + DAC_BUFFER_CLEAR_REG); // clear queue pointer writew(0, priv(dev)->main_iobase + ADC_QUEUE_CLEAR_REG); // load external queue - for(i = 0; i < cmd->chanlist_len; i++) - { + for (i = 0; i < cmd->chanlist_len; i++) { bits = 0; // set channel - bits |= adc_chan_bits(CR_CHAN(cmd->chanlist[i])); + bits |= adc_chan_bits(CR_CHAN(cmd-> + chanlist[i])); // set gain - bits |= ai_range_bits_6xxx(dev, CR_RANGE(cmd->chanlist[i])); + bits |= ai_range_bits_6xxx(dev, + CR_RANGE(cmd->chanlist[i])); // set single-ended / differential - bits |= se_diff_bit_6xxx(dev, CR_AREF(cmd->chanlist[i]) == AREF_DIFF); - if(CR_AREF(cmd->chanlist[i]) == AREF_COMMON) + bits |= se_diff_bit_6xxx(dev, + CR_AREF(cmd->chanlist[i]) == AREF_DIFF); + if (CR_AREF(cmd->chanlist[i]) == AREF_COMMON) bits |= ADC_COMMON_BIT; // mark end of queue - if(i == cmd->chanlist_len - 1) - bits |= QUEUE_EOSCAN_BIT | QUEUE_EOSEQ_BIT; - writew(bits, priv(dev)->main_iobase + ADC_QUEUE_FIFO_REG); - DEBUG_PRINT("wrote 0x%x to external channel queue\n", bits); + if (i == cmd->chanlist_len - 1) + bits |= QUEUE_EOSCAN_BIT | + QUEUE_EOSEQ_BIT; + writew(bits, + priv(dev)->main_iobase + + ADC_QUEUE_FIFO_REG); + DEBUG_PRINT + ("wrote 0x%x to external channel queue\n", + bits); } /* doing a queue clear is not specified in board docs, * but required for reliable operation */ @@ -2553,58 +2607,63 @@ static int setup_channel_queue(comedi_device *dev, const comedi_cmd *cmd) // prime queue holding register writew(0, priv(dev)->main_iobase + ADC_QUEUE_LOAD_REG); } - }else - { - unsigned short old_cal_range_bits = priv(dev)->i2c_cal_range_bits; + } else { + unsigned short old_cal_range_bits = + priv(dev)->i2c_cal_range_bits; priv(dev)->i2c_cal_range_bits &= ~ADC_SRC_4020_MASK; //select BNC inputs priv(dev)->i2c_cal_range_bits |= adc_src_4020_bits(4); // select ranges - for(i = 0; i < cmd->chanlist_len; i++) - { + for (i = 0; i < cmd->chanlist_len; i++) { unsigned int channel = CR_CHAN(cmd->chanlist[i]); unsigned int range = CR_RANGE(cmd->chanlist[i]); - if(range == 0) - priv(dev)->i2c_cal_range_bits |= attenuate_bit(channel); + if (range == 0) + priv(dev)->i2c_cal_range_bits |= + attenuate_bit(channel); else - priv(dev)->i2c_cal_range_bits &= ~attenuate_bit(channel); + priv(dev)->i2c_cal_range_bits &= + ~attenuate_bit(channel); } // update calibration/range i2c register only if necessary, as it is very slow - if(old_cal_range_bits != priv(dev)->i2c_cal_range_bits) - { + if (old_cal_range_bits != priv(dev)->i2c_cal_range_bits) { uint8_t i2c_data = priv(dev)->i2c_cal_range_bits; - i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, sizeof(i2c_data)); + i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, + sizeof(i2c_data)); } } return 0; } -static inline void load_first_dma_descriptor(comedi_device *dev, unsigned int dma_channel, - unsigned int descriptor_bits) +static inline void load_first_dma_descriptor(comedi_device * dev, + unsigned int dma_channel, unsigned int descriptor_bits) { /* The transfer size, pci address, and local address registers * are supposedly unused during chained dma, * but I have found that left over values from last operation * occasionally cause problems with transfer of first dma * block. Initializing them to zero seems to fix the problem. */ - if(dma_channel) - { - writel(0, priv(dev)->plx9080_iobase + PLX_DMA1_TRANSFER_SIZE_REG); + if (dma_channel) { + writel(0, + priv(dev)->plx9080_iobase + PLX_DMA1_TRANSFER_SIZE_REG); writel(0, priv(dev)->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG); - writel(0, priv(dev)->plx9080_iobase + PLX_DMA1_LOCAL_ADDRESS_REG); - writel(descriptor_bits, priv(dev)->plx9080_iobase + PLX_DMA1_DESCRIPTOR_REG); - }else - { - writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_TRANSFER_SIZE_REG); + writel(0, + priv(dev)->plx9080_iobase + PLX_DMA1_LOCAL_ADDRESS_REG); + writel(descriptor_bits, + priv(dev)->plx9080_iobase + PLX_DMA1_DESCRIPTOR_REG); + } else { + writel(0, + priv(dev)->plx9080_iobase + PLX_DMA0_TRANSFER_SIZE_REG); writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); - writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_LOCAL_ADDRESS_REG); - writel(descriptor_bits, priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); + writel(0, + priv(dev)->plx9080_iobase + PLX_DMA0_LOCAL_ADDRESS_REG); + writel(descriptor_bits, + priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); } } -static int ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -2613,107 +2672,107 @@ static int ai_cmd(comedi_device *dev,comedi_subdevice *s) unsigned long flags; int retval; - disable_ai_pacing( dev ); + disable_ai_pacing(dev); abort_dma(dev, 1); retval = setup_channel_queue(dev, cmd); - if(retval < 0) + if (retval < 0) return retval; // make sure internal calibration source is turned off writew(0, priv(dev)->main_iobase + CALIBRATION_REG); - set_ai_pacing( dev, cmd ); + set_ai_pacing(dev, cmd); - setup_sample_counters( dev, cmd ); + setup_sample_counters(dev, cmd); - enable_ai_interrupts( dev, cmd ); + enable_ai_interrupts(dev, cmd); - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); /* set mode, allow conversions through software gate */ priv(dev)->adc_control1_bits |= ADC_SW_GATE_BIT; priv(dev)->adc_control1_bits &= ~ADC_DITHER_BIT; - if(board(dev)->layout != LAYOUT_4020) - { + if (board(dev)->layout != LAYOUT_4020) { priv(dev)->adc_control1_bits &= ~ADC_MODE_MASK; - if( cmd->convert_src == TRIG_EXT ) - priv(dev)->adc_control1_bits |= adc_mode_bits( 13 ); // good old mode 13 + if (cmd->convert_src == TRIG_EXT) + priv(dev)->adc_control1_bits |= adc_mode_bits(13); // good old mode 13 else priv(dev)->adc_control1_bits |= adc_mode_bits(8); // mode 8. What else could you need? - } else - { + } else { priv(dev)->adc_control1_bits &= ~CHANNEL_MODE_4020_MASK; - if( cmd->chanlist_len == 4 ) + if (cmd->chanlist_len == 4) priv(dev)->adc_control1_bits |= FOUR_CHANNEL_4020_BITS; - else if( cmd->chanlist_len == 2 ) + else if (cmd->chanlist_len == 2) priv(dev)->adc_control1_bits |= TWO_CHANNEL_4020_BITS; priv(dev)->adc_control1_bits &= ~ADC_LO_CHANNEL_4020_MASK; - priv(dev)->adc_control1_bits |= adc_lo_chan_4020_bits( CR_CHAN( cmd->chanlist[0] ) ); + priv(dev)->adc_control1_bits |= + adc_lo_chan_4020_bits(CR_CHAN(cmd->chanlist[0])); priv(dev)->adc_control1_bits &= ~ADC_HI_CHANNEL_4020_MASK; - priv(dev)->adc_control1_bits |= adc_hi_chan_4020_bits( CR_CHAN( cmd->chanlist[ cmd->chanlist_len - 1 ] ) ); + priv(dev)->adc_control1_bits |= + adc_hi_chan_4020_bits(CR_CHAN(cmd->chanlist[cmd-> + chanlist_len - 1])); } - writew( priv(dev)->adc_control1_bits, priv(dev)->main_iobase + ADC_CONTROL1_REG ); + writew(priv(dev)->adc_control1_bits, + priv(dev)->main_iobase + ADC_CONTROL1_REG); DEBUG_PRINT("control1 bits 0x%x\n", priv(dev)->adc_control1_bits); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // clear adc buffer writew(0, priv(dev)->main_iobase + ADC_BUFFER_CLEAR_REG); - if((cmd->flags & TRIG_WAKE_EOS) == 0 || - board(dev)->layout == LAYOUT_4020) - { + if ((cmd->flags & TRIG_WAKE_EOS) == 0 || + board(dev)->layout == LAYOUT_4020) { priv(dev)->ai_dma_index = 0; // set dma transfer size - for(i = 0; i < ai_dma_ring_count(board(dev)); i++) - priv(dev)->ai_dma_desc[i].transfer_size = cpu_to_le32(dma_transfer_size(dev) * sizeof(uint16_t)); + for (i = 0; i < ai_dma_ring_count(board(dev)); i++) + priv(dev)->ai_dma_desc[i].transfer_size = + cpu_to_le32(dma_transfer_size(dev) * + sizeof(uint16_t)); // give location of first dma descriptor - load_first_dma_descriptor(dev, 1, priv(dev)->ai_dma_desc_bus_addr | - PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI); + load_first_dma_descriptor(dev, 1, + priv(dev)-> + ai_dma_desc_bus_addr | PLX_DESC_IN_PCI_BIT | + PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI); dma_start_sync(dev, 1); } - if( board(dev)->layout == LAYOUT_4020 ) - { + if (board(dev)->layout == LAYOUT_4020) { /* set source for external triggers */ bits = 0; - if( cmd->start_src == TRIG_EXT && - CR_CHAN( cmd->start_arg ) ) + if (cmd->start_src == TRIG_EXT && CR_CHAN(cmd->start_arg)) bits |= EXT_START_TRIG_BNC_BIT; - if( cmd->stop_src == TRIG_EXT && - CR_CHAN( cmd->stop_arg ) ) + if (cmd->stop_src == TRIG_EXT && CR_CHAN(cmd->stop_arg)) bits |= EXT_STOP_TRIG_BNC_BIT; - writew( bits, priv(dev)->main_iobase + DAQ_ATRIG_LOW_4020_REG ); + writew(bits, priv(dev)->main_iobase + DAQ_ATRIG_LOW_4020_REG); } - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); /* enable pacing, triggering, etc */ bits = ADC_ENABLE_BIT | ADC_SOFT_GATE_BITS | ADC_GATE_LEVEL_BIT; - if(cmd->flags & TRIG_WAKE_EOS) + if (cmd->flags & TRIG_WAKE_EOS) bits |= ADC_DMA_DISABLE_BIT; // set start trigger - if( cmd->start_src == TRIG_EXT ) - { + if (cmd->start_src == TRIG_EXT) { bits |= ADC_START_TRIG_EXT_BITS; - if( cmd->start_arg & CR_INVERT ) + if (cmd->start_arg & CR_INVERT) bits |= ADC_START_TRIG_FALLING_BIT; - }else if( cmd->start_src == TRIG_NOW ) + } else if (cmd->start_src == TRIG_NOW) bits |= ADC_START_TRIG_SOFT_BITS; - if( use_hw_sample_counter( cmd ) ) + if (use_hw_sample_counter(cmd)) bits |= ADC_SAMPLE_COUNTER_EN_BIT; writew(bits, priv(dev)->main_iobase + ADC_CONTROL0_REG); DEBUG_PRINT("control0 bits 0x%x\n", bits); priv(dev)->ai_cmd_running = 1; - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // start aquisition - if( cmd->start_src == TRIG_NOW ) - { + if (cmd->start_src == TRIG_NOW) { writew(0, priv(dev)->main_iobase + ADC_START_REG); DEBUG_PRINT("soft trig\n"); } @@ -2722,7 +2781,7 @@ static int ai_cmd(comedi_device *dev,comedi_subdevice *s) } // read num_samples from 16 bit wide ai fifo -static void pio_drain_ai_fifo_16(comedi_device *dev) +static void pio_drain_ai_fifo_16(comedi_device * dev) { comedi_subdevice *s = dev->read_subdev; comedi_async *async = s->async; @@ -2732,11 +2791,14 @@ static void pio_drain_ai_fifo_16(comedi_device *dev) int read_segment, read_index, write_segment, write_index; int num_samples; - do - { + do { // get least significant 15 bits - read_index = readw(priv(dev)->main_iobase + ADC_READ_PNTR_REG) & 0x7fff; - write_index = readw(priv(dev)->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff; + read_index = + readw(priv(dev)->main_iobase + + ADC_READ_PNTR_REG) & 0x7fff; + write_index = + readw(priv(dev)->main_iobase + + ADC_WRITE_PNTR_REG) & 0x7fff; /* Get most significant bits (grey code). Different boards use different code * so use a scheme that doesn't depend on encoding. This read must * occur after reading least significant 15 bits to avoid race @@ -2744,39 +2806,38 @@ static void pio_drain_ai_fifo_16(comedi_device *dev) prepost_bits = readw(priv(dev)->main_iobase + PREPOST_REG); /* if read and write pointers are not on the same fifo segment, read to the - * end of the read segment */ - read_segment = adc_upper_read_ptr_code( prepost_bits ); - write_segment = adc_upper_write_ptr_code( prepost_bits ); + * end of the read segment */ + read_segment = adc_upper_read_ptr_code(prepost_bits); + write_segment = adc_upper_write_ptr_code(prepost_bits); - DEBUG_PRINT( " rd seg %i, wrt seg %i, rd idx %i, wrt idx %i\n", - read_segment, write_segment, read_index, write_index ); + DEBUG_PRINT(" rd seg %i, wrt seg %i, rd idx %i, wrt idx %i\n", + read_segment, write_segment, read_index, write_index); - if(read_segment != write_segment) - num_samples = priv(dev)->ai_fifo_segment_length - read_index; + if (read_segment != write_segment) + num_samples = + priv(dev)->ai_fifo_segment_length - read_index; else num_samples = write_index - read_index; - if(cmd->stop_src == TRIG_COUNT) - { - if(priv(dev)->ai_count == 0) break; - if(num_samples > priv(dev)->ai_count) - { + if (cmd->stop_src == TRIG_COUNT) { + if (priv(dev)->ai_count == 0) + break; + if (num_samples > priv(dev)->ai_count) { num_samples = priv(dev)->ai_count; } priv(dev)->ai_count -= num_samples; } - if(num_samples < 0) - { + if (num_samples < 0) { rt_printk(" cb_pcidas64: bug! num_samples < 0\n"); break; } DEBUG_PRINT(" read %i samples from fifo\n", num_samples); - for(i = 0; i < num_samples; i++) - { - cfc_write_to_buffer( s, readw(priv(dev)->main_iobase + ADC_FIFO_REG)); + for (i = 0; i < num_samples; i++) { + cfc_write_to_buffer(s, + readw(priv(dev)->main_iobase + ADC_FIFO_REG)); } } while (read_segment != write_segment); @@ -2787,7 +2848,7 @@ static void pio_drain_ai_fifo_16(comedi_device *dev) * dma transfers (it only supports the use of pio for draining the last remaining * points from the fifo when a data aquisition operation has completed). */ -static void pio_drain_ai_fifo_32(comedi_device *dev) +static void pio_drain_ai_fifo_32(comedi_device * dev) { comedi_subdevice *s = dev->read_subdev; comedi_async *async = s->async; @@ -2795,42 +2856,41 @@ static void pio_drain_ai_fifo_32(comedi_device *dev) unsigned int i; unsigned int max_transfer = 100000; uint32_t fifo_data; - int write_code = readw(priv(dev)->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff; - int read_code = readw(priv(dev)->main_iobase + ADC_READ_PNTR_REG) & 0x7fff; + int write_code = + readw(priv(dev)->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff; + int read_code = + readw(priv(dev)->main_iobase + ADC_READ_PNTR_REG) & 0x7fff; - if(cmd->stop_src == TRIG_COUNT) - { - if(max_transfer > priv(dev)->ai_count) - { + if (cmd->stop_src == TRIG_COUNT) { + if (max_transfer > priv(dev)->ai_count) { max_transfer = priv(dev)->ai_count; } } - for(i = 0; read_code != write_code && i < max_transfer; ) - { + for (i = 0; read_code != write_code && i < max_transfer;) { fifo_data = readl(priv(dev)->dio_counter_iobase + ADC_FIFO_REG); - cfc_write_to_buffer( s, fifo_data & 0xffff); + cfc_write_to_buffer(s, fifo_data & 0xffff); i++; - if(i < max_transfer) - { - cfc_write_to_buffer( s, (fifo_data >> 16) & 0xffff); + if (i < max_transfer) { + cfc_write_to_buffer(s, (fifo_data >> 16) & 0xffff); i++; } - read_code = readw(priv(dev)->main_iobase + ADC_READ_PNTR_REG) & 0x7fff; + read_code = + readw(priv(dev)->main_iobase + + ADC_READ_PNTR_REG) & 0x7fff; } priv(dev)->ai_count -= i; } // empty fifo -static void pio_drain_ai_fifo(comedi_device *dev) +static void pio_drain_ai_fifo(comedi_device * dev) { - if(board(dev)->layout == LAYOUT_4020) - { + if (board(dev)->layout == LAYOUT_4020) { pio_drain_ai_fifo_32(dev); - }else + } else pio_drain_ai_fifo_16(dev); } -static void drain_dma_buffers(comedi_device *dev, unsigned int channel) +static void drain_dma_buffers(comedi_device * dev, unsigned int channel) { comedi_async *async = dev->read_subdev->async; uint32_t next_transfer_addr; @@ -2838,38 +2898,45 @@ static void drain_dma_buffers(comedi_device *dev, unsigned int channel) int num_samples = 0; void *pci_addr_reg; - if(channel) - pci_addr_reg = priv(dev)->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG; + if (channel) + pci_addr_reg = + priv(dev)->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG; else - pci_addr_reg = priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; + pci_addr_reg = + priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; // loop until we have read all the full buffers - for(j = 0, next_transfer_addr = readl(pci_addr_reg); - (next_transfer_addr < priv(dev)->ai_buffer_bus_addr[priv(dev)->ai_dma_index] || - next_transfer_addr >= priv(dev)->ai_buffer_bus_addr[priv(dev)->ai_dma_index] + DMA_BUFFER_SIZE) && - j < ai_dma_ring_count(board(dev)); - j++ ) - { + for (j = 0, next_transfer_addr = readl(pci_addr_reg); + (next_transfer_addr < + priv(dev)->ai_buffer_bus_addr[priv(dev)->ai_dma_index] + || next_transfer_addr >= + priv(dev)->ai_buffer_bus_addr[priv(dev)->ai_dma_index] + + DMA_BUFFER_SIZE) && j < ai_dma_ring_count(board(dev)); + j++) { // transfer data from dma buffer to comedi buffer - num_samples = dma_transfer_size( dev ); - if(async->cmd.stop_src == TRIG_COUNT) - { - if(num_samples > priv(dev)->ai_count) + num_samples = dma_transfer_size(dev); + if (async->cmd.stop_src == TRIG_COUNT) { + if (num_samples > priv(dev)->ai_count) num_samples = priv(dev)->ai_count; priv(dev)->ai_count -= num_samples; } - cfc_write_array_to_buffer( dev->read_subdev, - priv(dev)->ai_buffer[ priv(dev)->ai_dma_index ], num_samples * sizeof( uint16_t ) ); - priv(dev)->ai_dma_index = (priv(dev)->ai_dma_index + 1) % ai_dma_ring_count(board(dev)); - - DEBUG_PRINT("next buffer addr 0x%lx\n", (unsigned long) priv(dev)->ai_buffer_bus_addr[priv(dev)->ai_dma_index]); + cfc_write_array_to_buffer(dev->read_subdev, + priv(dev)->ai_buffer[priv(dev)->ai_dma_index], + num_samples * sizeof(uint16_t)); + priv(dev)->ai_dma_index = + (priv(dev)->ai_dma_index + + 1) % ai_dma_ring_count(board(dev)); + + DEBUG_PRINT("next buffer addr 0x%lx\n", + (unsigned long)priv(dev)->ai_buffer_bus_addr[priv(dev)-> + ai_dma_index]); DEBUG_PRINT("pci addr reg 0x%x\n", next_transfer_addr); } /* XXX check for dma ring buffer overrun (use end-of-chain bit to mark last * unused buffer) */ } -void handle_ai_interrupt(comedi_device *dev, unsigned short status, +void handle_ai_interrupt(comedi_device * dev, unsigned short status, unsigned int plx_status) { comedi_subdevice *s = dev->read_subdev; @@ -2879,69 +2946,62 @@ void handle_ai_interrupt(comedi_device *dev, unsigned short status, unsigned long flags; // check for fifo overrun - if(status & ADC_OVERRUN_BIT) - { + if (status & ADC_OVERRUN_BIT) { comedi_error(dev, "fifo overrun"); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; } - // spin lock makes sure noone else changes plx dma control reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); dma1_status = readb(priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); - if(plx_status & ICS_DMA1_A) - { // dma chan 1 interrupt - writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); + if (plx_status & ICS_DMA1_A) { // dma chan 1 interrupt + writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); DEBUG_PRINT("dma1 status 0x%x\n", dma1_status); - if(dma1_status & PLX_DMA_EN_BIT) - { + if (dma1_status & PLX_DMA_EN_BIT) { drain_dma_buffers(dev, 1); } DEBUG_PRINT(" cleared dma ch1 interrupt\n"); } - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - if( status & ADC_DONE_BIT ) + if (status & ADC_DONE_BIT) DEBUG_PRINT("adc done interrupt\n"); // drain fifo with pio - if( ( status & ADC_DONE_BIT ) || - ( ( cmd->flags & TRIG_WAKE_EOS ) && - ( status & ADC_INTR_PENDING_BIT ) && - ( board(dev)->layout != LAYOUT_4020 ) ) ) - { + if ((status & ADC_DONE_BIT) || + ((cmd->flags & TRIG_WAKE_EOS) && + (status & ADC_INTR_PENDING_BIT) && + (board(dev)->layout != LAYOUT_4020))) { DEBUG_PRINT("pio fifo drain\n"); - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - if( priv(dev)->ai_cmd_running ) - { - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + if (priv(dev)->ai_cmd_running) { + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); pio_drain_ai_fifo(dev); - }else - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + } else + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } - // if we are have all the data, then quit - if((cmd->stop_src == TRIG_COUNT && priv(dev)->ai_count <= 0) || - (cmd->stop_src == TRIG_EXT && (status & ADC_STOP_BIT))) - { + if ((cmd->stop_src == TRIG_COUNT && priv(dev)->ai_count <= 0) || + (cmd->stop_src == TRIG_EXT && (status & ADC_STOP_BIT))) { async->events |= COMEDI_CB_EOA; } - cfc_handle_events( dev, s ); + cfc_handle_events(dev, s); } -static inline unsigned int prev_ao_dma_index(comedi_device *dev) +static inline unsigned int prev_ao_dma_index(comedi_device * dev) { unsigned int buffer_index; - if(priv(dev)->ao_dma_index == 0) + if (priv(dev)->ao_dma_index == 0) buffer_index = AO_DMA_RING_COUNT - 1; else buffer_index = priv(dev)->ao_dma_index - 1; return buffer_index; } -static int last_ao_dma_load_completed(comedi_device *dev) +static int last_ao_dma_load_completed(comedi_device * dev) { unsigned int buffer_index; unsigned int transfer_address; @@ -2949,40 +3009,48 @@ static int last_ao_dma_load_completed(comedi_device *dev) buffer_index = prev_ao_dma_index(dev); dma_status = readb(priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - if((dma_status & PLX_DMA_DONE_BIT) == 0) return 0; + if ((dma_status & PLX_DMA_DONE_BIT) == 0) + return 0; - transfer_address = readl(priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); - if(transfer_address != priv(dev)->ao_buffer_bus_addr[buffer_index]) + transfer_address = + readl(priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); + if (transfer_address != priv(dev)->ao_buffer_bus_addr[buffer_index]) return 0; return 1; } -static int ao_stopped_by_error(comedi_device *dev, const comedi_cmd *cmd) +static int ao_stopped_by_error(comedi_device * dev, const comedi_cmd * cmd) { - if(cmd->stop_src == TRIG_NONE) return 1; - if(cmd->stop_src == TRIG_COUNT) - { - if(priv(dev)->ao_count) return 1; - if(last_ao_dma_load_completed(dev) == 0) return 1; + if (cmd->stop_src == TRIG_NONE) + return 1; + if (cmd->stop_src == TRIG_COUNT) { + if (priv(dev)->ao_count) + return 1; + if (last_ao_dma_load_completed(dev) == 0) + return 1; } return 0; } -static inline int ao_dma_needs_restart(comedi_device *dev, unsigned short dma_status) +static inline int ao_dma_needs_restart(comedi_device * dev, + unsigned short dma_status) { - if((dma_status & PLX_DMA_DONE_BIT) == 0 || - (dma_status & PLX_DMA_EN_BIT) == 0) return 0; - if(last_ao_dma_load_completed(dev)) return 0; + if ((dma_status & PLX_DMA_DONE_BIT) == 0 || + (dma_status & PLX_DMA_EN_BIT) == 0) + return 0; + if (last_ao_dma_load_completed(dev)) + return 0; return 1; } -static void restart_ao_dma(comedi_device *dev) +static void restart_ao_dma(comedi_device * dev) { unsigned int dma_desc_bits; - dma_desc_bits = readl(priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); + dma_desc_bits = + readl(priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); dma_desc_bits &= ~PLX_END_OF_CHAIN_BIT; DEBUG_PRINT("restarting ao dma, descriptor reg 0x%x\n", dma_desc_bits); load_first_dma_descriptor(dev, 0, dma_desc_bits); @@ -2990,7 +3058,7 @@ static void restart_ao_dma(comedi_device *dev) dma_start_sync(dev, 0); } -static void handle_ao_interrupt(comedi_device *dev, unsigned short status, +static void handle_ao_interrupt(comedi_device * dev, unsigned short status, unsigned int plx_status) { comedi_subdevice *s = dev->write_subdev; @@ -3000,41 +3068,46 @@ static void handle_ao_interrupt(comedi_device *dev, unsigned short status, unsigned long flags; /* board might not support ao, in which case write_subdev is NULL */ - if(s == NULL) return; + if (s == NULL) + return; async = s->async; cmd = &async->cmd; // spin lock makes sure noone else changes plx dma control reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); dma0_status = readb(priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - if(plx_status & ICS_DMA0_A) - { // dma chan 0 interrupt - if((dma0_status & PLX_DMA_EN_BIT) && !(dma0_status & PLX_DMA_DONE_BIT)) - writeb(PLX_DMA_EN_BIT | PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); + if (plx_status & ICS_DMA0_A) { // dma chan 0 interrupt + if ((dma0_status & PLX_DMA_EN_BIT) + && !(dma0_status & PLX_DMA_DONE_BIT)) + writeb(PLX_DMA_EN_BIT | PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); else - writeb(PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + writeb(PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); DEBUG_PRINT("dma0 status 0x%x\n", dma0_status); - if(dma0_status & PLX_DMA_EN_BIT) - { + if (dma0_status & PLX_DMA_EN_BIT) { load_ao_dma(dev, cmd); /* try to recover from dma end-of-chain event */ - if(ao_dma_needs_restart(dev, dma0_status)) + if (ao_dma_needs_restart(dev, dma0_status)) restart_ao_dma(dev); } DEBUG_PRINT(" cleared dma ch0 interrupt\n"); - }else - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + } else + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - if((status & DAC_DONE_BIT)) - { + if ((status & DAC_DONE_BIT)) { async->events |= COMEDI_CB_EOA; - if(ao_stopped_by_error(dev, cmd)) + if (ao_stopped_by_error(dev, cmd)) async->events |= COMEDI_CB_ERROR; - DEBUG_PRINT("plx dma0 desc reg 0x%x\n", readl(priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG)); - DEBUG_PRINT("plx dma0 address reg 0x%x\n", readl(priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG)); + DEBUG_PRINT("plx dma0 desc reg 0x%x\n", + readl(priv(dev)->plx9080_iobase + + PLX_DMA0_DESCRIPTOR_REG)); + DEBUG_PRINT("plx dma0 address reg 0x%x\n", + readl(priv(dev)->plx9080_iobase + + PLX_DMA0_PCI_ADDRESS_REG)); } - cfc_handle_events( dev, s ); + cfc_handle_events(dev, s); } static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG) @@ -3053,17 +3126,16 @@ static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG) /* an interrupt before all the postconfig stuff gets done could * cause a NULL dereference if we continue through the * interrupt handler */ - if(dev->attached == 0) - { - DEBUG_PRINT("cb_pcidas64: premature interrupt, ignoring", status); + if (dev->attached == 0) { + DEBUG_PRINT("cb_pcidas64: premature interrupt, ignoring", + status); return IRQ_HANDLED; } handle_ai_interrupt(dev, status, plx_status); handle_ao_interrupt(dev, status, plx_status); // clear possible plx9080 interrupt sources - if(plx_status & ICS_LDIA) - { // clear local doorbell interrupt + if (plx_status & ICS_LDIA) { // clear local doorbell interrupt plx_bits = readl(priv(dev)->plx9080_iobase + PLX_DBR_OUT_REG); writel(plx_bits, priv(dev)->plx9080_iobase + PLX_DBR_OUT_REG); DEBUG_PRINT(" cleared local doorbell bits 0x%x\n", plx_bits); @@ -3074,32 +3146,31 @@ static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -void abort_dma(comedi_device *dev, unsigned int channel) +void abort_dma(comedi_device * dev, unsigned int channel) { unsigned long flags; // spinlock for plx dma control/status reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); - plx9080_abort_dma( priv( dev )->plx9080_iobase, channel ); + plx9080_abort_dma(priv(dev)->plx9080_iobase, channel); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } -static int ai_cancel(comedi_device *dev, comedi_subdevice *s) +static int ai_cancel(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); - if( priv(dev)->ai_cmd_running == 0 ) - { - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); + if (priv(dev)->ai_cmd_running == 0) { + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } priv(dev)->ai_cmd_running = 0; - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - disable_ai_pacing( dev ); + disable_ai_pacing(dev); abort_dma(dev, 1); @@ -3107,8 +3178,8 @@ static int ai_cancel(comedi_device *dev, comedi_subdevice *s) return 0; } -static int ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); int range = CR_RANGE(insn->chanspec); @@ -3117,16 +3188,17 @@ static int ao_winsn(comedi_device *dev, comedi_subdevice *s, writew(0, priv(dev)->main_iobase + DAC_CONTROL0_REG); // set range - set_dac_range_bits( dev, &priv(dev)->dac_control1_bits, chan, range ); - writew(priv(dev)->dac_control1_bits, priv(dev)->main_iobase + DAC_CONTROL1_REG); + set_dac_range_bits(dev, &priv(dev)->dac_control1_bits, chan, range); + writew(priv(dev)->dac_control1_bits, + priv(dev)->main_iobase + DAC_CONTROL1_REG); // write to channel - if( board(dev)->layout == LAYOUT_4020 ) - { - writew( data[0] & 0xff , priv(dev)->main_iobase + dac_lsb_4020_reg( chan ) ); - writew( (data[0] >> 8) & 0xf , priv(dev)->main_iobase + dac_msb_4020_reg( chan ) ); - }else - { + if (board(dev)->layout == LAYOUT_4020) { + writew(data[0] & 0xff, + priv(dev)->main_iobase + dac_lsb_4020_reg(chan)); + writew((data[0] >> 8) & 0xf, + priv(dev)->main_iobase + dac_msb_4020_reg(chan)); + } else { writew(data[0], priv(dev)->main_iobase + dac_convert_reg(chan)); } @@ -3136,60 +3208,59 @@ static int ao_winsn(comedi_device *dev, comedi_subdevice *s, return 1; } -static int ao_readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ao_readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = priv(dev)->ao_value[CR_CHAN(insn->chanspec)]; return 1; } -static void set_dac_control0_reg(comedi_device *dev, const comedi_cmd *cmd) +static void set_dac_control0_reg(comedi_device * dev, const comedi_cmd * cmd) { unsigned int bits = DAC_ENABLE_BIT | WAVEFORM_GATE_LEVEL_BIT | WAVEFORM_GATE_ENABLE_BIT | WAVEFORM_GATE_SELECT_BIT; - if(cmd->start_src == TRIG_EXT) - { + if (cmd->start_src == TRIG_EXT) { bits |= WAVEFORM_TRIG_EXT_BITS; - if(cmd->start_arg & CR_INVERT) + if (cmd->start_arg & CR_INVERT) bits |= WAVEFORM_TRIG_FALLING_BIT; - }else - { + } else { bits |= WAVEFORM_TRIG_SOFT_BITS; } - if(cmd->scan_begin_src == TRIG_EXT) - { + if (cmd->scan_begin_src == TRIG_EXT) { bits |= DAC_EXT_UPDATE_ENABLE_BIT; - if(cmd->scan_begin_arg & CR_INVERT) + if (cmd->scan_begin_arg & CR_INVERT) bits |= DAC_EXT_UPDATE_FALLING_BIT; } writew(bits, priv(dev)->main_iobase + DAC_CONTROL0_REG); } -static void set_dac_control1_reg(comedi_device *dev, const comedi_cmd *cmd) +static void set_dac_control1_reg(comedi_device * dev, const comedi_cmd * cmd) { int i; - for(i = 0; i < cmd->chanlist_len; i++) - { + for (i = 0; i < cmd->chanlist_len; i++) { int channel, range; channel = CR_CHAN(cmd->chanlist[i]); range = CR_RANGE(cmd->chanlist[i]); - set_dac_range_bits(dev, &priv(dev)->dac_control1_bits, channel, range); + set_dac_range_bits(dev, &priv(dev)->dac_control1_bits, channel, + range); } priv(dev)->dac_control1_bits |= DAC_SW_GATE_BIT; - writew(priv(dev)->dac_control1_bits, priv(dev)->main_iobase + DAC_CONTROL1_REG); + writew(priv(dev)->dac_control1_bits, + priv(dev)->main_iobase + DAC_CONTROL1_REG); } -static void set_dac_select_reg(comedi_device *dev, const comedi_cmd *cmd) +static void set_dac_select_reg(comedi_device * dev, const comedi_cmd * cmd) { uint16_t bits; unsigned int first_channel, last_channel; first_channel = CR_CHAN(cmd->chanlist[0]); last_channel = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]); - if(last_channel < first_channel) + if (last_channel < first_channel) comedi_error(dev, "bug! last ao channel < first ao channel"); bits = (first_channel & 0x7) | (last_channel & 0x7) << 3; @@ -3197,23 +3268,26 @@ static void set_dac_select_reg(comedi_device *dev, const comedi_cmd *cmd) writew(bits, priv(dev)->main_iobase + DAC_SELECT_REG); } -static void set_dac_interval_regs(comedi_device *dev, const comedi_cmd *cmd) +static void set_dac_interval_regs(comedi_device * dev, const comedi_cmd * cmd) { unsigned int divisor; - if(cmd->scan_begin_src != TRIG_TIMER) return; + if (cmd->scan_begin_src != TRIG_TIMER) + return; divisor = get_ao_divisor(cmd->scan_begin_arg, cmd->flags); - if(divisor > max_counter_value) - { + if (divisor > max_counter_value) { comedi_error(dev, "bug! ao divisor too big"); divisor = max_counter_value; } - writew(divisor & 0xffff, priv(dev)->main_iobase + DAC_SAMPLE_INTERVAL_LOWER_REG); - writew((divisor >> 16) & 0xff, priv(dev)->main_iobase + DAC_SAMPLE_INTERVAL_UPPER_REG); + writew(divisor & 0xffff, + priv(dev)->main_iobase + DAC_SAMPLE_INTERVAL_LOWER_REG); + writew((divisor >> 16) & 0xff, + priv(dev)->main_iobase + DAC_SAMPLE_INTERVAL_UPPER_REG); } -static unsigned int load_ao_dma_buffer(comedi_device *dev, const comedi_cmd *cmd) +static unsigned int load_ao_dma_buffer(comedi_device * dev, + const comedi_cmd * cmd) { unsigned int num_bytes, buffer_index, prev_buffer_index; unsigned int next_bits; @@ -3225,18 +3299,21 @@ static unsigned int load_ao_dma_buffer(comedi_device *dev, const comedi_cmd *cmd priv(dev)->ao_buffer_bus_addr[buffer_index]); num_bytes = comedi_buf_read_n_available(dev->write_subdev->async); - if(num_bytes > DMA_BUFFER_SIZE) num_bytes = DMA_BUFFER_SIZE; - if(cmd->stop_src == TRIG_COUNT && num_bytes > priv(dev)->ao_count) + if (num_bytes > DMA_BUFFER_SIZE) + num_bytes = DMA_BUFFER_SIZE; + if (cmd->stop_src == TRIG_COUNT && num_bytes > priv(dev)->ao_count) num_bytes = priv(dev)->ao_count; num_bytes -= num_bytes % bytes_in_sample; - if(num_bytes == 0) return 0; + if (num_bytes == 0) + return 0; DEBUG_PRINT("loading %i bytes\n", num_bytes); num_bytes = cfc_read_array_from_buffer(dev->write_subdev, priv(dev)->ao_buffer[buffer_index], num_bytes); - priv(dev)->ao_dma_desc[buffer_index].transfer_size = cpu_to_le32(num_bytes); + priv(dev)->ao_dma_desc[buffer_index].transfer_size = + cpu_to_le32(num_bytes); /* set end of chain bit so we catch underruns */ next_bits = le32_to_cpu(priv(dev)->ao_dma_desc[buffer_index].next); next_bits |= PLX_END_OF_CHAIN_BIT; @@ -3253,26 +3330,29 @@ static unsigned int load_ao_dma_buffer(comedi_device *dev, const comedi_cmd *cmd return num_bytes; } -static void load_ao_dma(comedi_device *dev, const comedi_cmd *cmd) +static void load_ao_dma(comedi_device * dev, const comedi_cmd * cmd) { unsigned int num_bytes; unsigned int next_transfer_addr; - void *pci_addr_reg = priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; + void *pci_addr_reg = + priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; unsigned int buffer_index; - do - { + do { buffer_index = priv(dev)->ao_dma_index; /* don't overwrite data that hasn't been transferred yet */ next_transfer_addr = readl(pci_addr_reg); - if(next_transfer_addr >= priv(dev)->ao_buffer_bus_addr[buffer_index] && - next_transfer_addr < priv(dev)->ao_buffer_bus_addr[buffer_index] + DMA_BUFFER_SIZE) + if (next_transfer_addr >= + priv(dev)->ao_buffer_bus_addr[buffer_index] + && next_transfer_addr < + priv(dev)->ao_buffer_bus_addr[buffer_index] + + DMA_BUFFER_SIZE) return; num_bytes = load_ao_dma_buffer(dev, cmd); - }while(num_bytes >= DMA_BUFFER_SIZE); + } while (num_bytes >= DMA_BUFFER_SIZE); } -static int prep_ao_dma(comedi_device *dev, const comedi_cmd *cmd) +static int prep_ao_dma(comedi_device * dev, const comedi_cmd * cmd) { unsigned int num_bytes; int i; @@ -3283,46 +3363,45 @@ static int prep_ao_dma(comedi_device *dev, const comedi_cmd *cmd) writew(0, priv(dev)->main_iobase + DAC_BUFFER_CLEAR_REG); num_bytes = (DAC_FIFO_SIZE / 2) * bytes_in_sample; - if(cmd->stop_src == TRIG_COUNT && + if (cmd->stop_src == TRIG_COUNT && num_bytes / bytes_in_sample > priv(dev)->ao_count) num_bytes = priv(dev)->ao_count * bytes_in_sample; num_bytes = cfc_read_array_from_buffer(dev->write_subdev, priv(dev)->ao_bounce_buffer, num_bytes); - for(i = 0; i < num_bytes / bytes_in_sample; i++) - { - writew(priv(dev)->ao_bounce_buffer[i], priv(dev)->main_iobase + DAC_FIFO_REG); + for (i = 0; i < num_bytes / bytes_in_sample; i++) { + writew(priv(dev)->ao_bounce_buffer[i], + priv(dev)->main_iobase + DAC_FIFO_REG); } priv(dev)->ao_count -= num_bytes / bytes_in_sample; - if(cmd->stop_src == TRIG_COUNT && - priv(dev)->ao_count == 0) + if (cmd->stop_src == TRIG_COUNT && priv(dev)->ao_count == 0) return 0; num_bytes = load_ao_dma_buffer(dev, cmd); - if(num_bytes == 0) return -1; - if(num_bytes >= DMA_BUFFER_SIZE); - load_ao_dma(dev, cmd); + if (num_bytes == 0) + return -1; + if (num_bytes >= DMA_BUFFER_SIZE) ; + load_ao_dma(dev, cmd); dma_start_sync(dev, 0); return 0; } -static inline int external_ai_queue_in_use(comedi_device *dev) +static inline int external_ai_queue_in_use(comedi_device * dev) { - if(dev->read_subdev->busy) + if (dev->read_subdev->busy) return 0; - if(board(dev)->layout == LAYOUT_4020) + if (board(dev)->layout == LAYOUT_4020) return 0; - else if(use_internal_queue_6xxx(&dev->read_subdev->async->cmd)) + else if (use_internal_queue_6xxx(&dev->read_subdev->async->cmd)) return 0; return 1; } -static int ao_cmd(comedi_device *dev,comedi_subdevice *s) +static int ao_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; - if(external_ai_queue_in_use(dev)) - { + if (external_ai_queue_in_use(dev)) { warn_external_queue(dev); return -EBUSY; } @@ -3343,27 +3422,31 @@ static int ao_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int ao_inttrig(comedi_device *dev, comedi_subdevice *s, unsigned int trig_num) +static int ao_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trig_num) { comedi_cmd *cmd = &s->async->cmd; int retval; - if(trig_num!=0)return -EINVAL; + if (trig_num != 0) + return -EINVAL; retval = prep_ao_dma(dev, cmd); - if(retval < 0) return -EPIPE; + if (retval < 0) + return -EPIPE; set_dac_control0_reg(dev, cmd); - if(cmd->start_src == TRIG_INT) + if (cmd->start_src == TRIG_INT) writew(0, priv(dev)->main_iobase + DAC_START_REG); - s->async->inttrig=NULL; + s->async->inttrig = NULL; return 0; } -static int ao_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) +static int ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -3374,104 +3457,111 @@ static int ao_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) tmp = cmd->start_src; cmd->start_src &= TRIG_INT | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ // uniqueness check - if(cmd->start_src != TRIG_INT && - cmd->start_src != TRIG_EXT) err++; - if(cmd->scan_begin_src != TRIG_TIMER && - cmd->scan_begin_src != TRIG_EXT) err++; + if (cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; // compatibility check - if(cmd->convert_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER) + if (cmd->convert_src == TRIG_EXT && cmd->scan_begin_src == TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE && - cmd->stop_src != TRIG_EXT) err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->scan_begin_src == TRIG_TIMER) - { - if(cmd->scan_begin_arg < board(dev)->ao_scan_speed) - { + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < board(dev)->ao_scan_speed) { cmd->scan_begin_arg = board(dev)->ao_scan_speed; err++; } - if(get_ao_divisor(cmd->scan_begin_arg, cmd->flags) > max_counter_value) - { - cmd->scan_begin_arg = (max_counter_value + 2) * TIMER_BASE; + if (get_ao_divisor(cmd->scan_begin_arg, + cmd->flags) > max_counter_value) { + cmd->scan_begin_arg = + (max_counter_value + 2) * TIMER_BASE; err++; } } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp_arg = cmd->scan_begin_arg; - cmd->scan_begin_arg = get_divisor(cmd->scan_begin_arg, cmd->flags) * TIMER_BASE; - if(tmp_arg != cmd->scan_begin_arg) err++; + cmd->scan_begin_arg = + get_divisor(cmd->scan_begin_arg, + cmd->flags) * TIMER_BASE; + if (tmp_arg != cmd->scan_begin_arg) + err++; } - if(err) return 4; + if (err) + return 4; - if(cmd->chanlist) - { - unsigned int first_channel = CR_CHAN( cmd->chanlist[0] ); - for( i = 1; i < cmd->chanlist_len; i++ ) - { - if( CR_CHAN( cmd->chanlist[ i ] ) != first_channel + i ) - { - comedi_error( dev, "chanlist must use consecutive channels" ); + if (cmd->chanlist) { + unsigned int first_channel = CR_CHAN(cmd->chanlist[0]); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != first_channel + i) { + comedi_error(dev, + "chanlist must use consecutive channels"); err++; break; } } } - if(err) return 5; + if (err) + return 5; return 0; } -static int ao_cancel(comedi_device *dev, comedi_subdevice *s) +static int ao_cancel(comedi_device * dev, comedi_subdevice * s) { writew(0x0, priv(dev)->main_iobase + DAC_CONTROL0_REG); abort_dma(dev, 0); @@ -3480,30 +3570,27 @@ static int ao_cancel(comedi_device *dev, comedi_subdevice *s) static int dio_callback(int dir, int port, int data, unsigned long iobase) { - if(dir) - { - writeb(data, (void*) (iobase + port)); + if (dir) { + writeb(data, (void *)(iobase + port)); DEBUG_PRINT("wrote 0x%x to port %i\n", data, port); return 0; - }else - { - return readb((void*)(iobase + port)); + } else { + return readb((void *)(iobase + port)); } } static int dio_callback_4020(int dir, int port, int data, unsigned long iobase) { - if(dir) - { - writew(data, (void*)(iobase + 2 * port)); + if (dir) { + writew(data, (void *)(iobase + 2 * port)); return 0; - }else - { - return readw((void*)(iobase + 2 * port)); + } else { + return readw((void *)(iobase + 2 * port)); } } -static int di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t bits; @@ -3515,7 +3602,8 @@ static int di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, return 2; } -static int do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] &= 0xf; // zero bits we are going to change @@ -3530,79 +3618,83 @@ static int do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, return 2; } -static int dio_60xx_config_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int dio_60xx_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int mask; mask = 1 << CR_CHAN(insn->chanspec); - switch(data[0]) - { - case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~mask; - break; - case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= mask; - break; - case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; - return 2; - default: - return -EINVAL; + switch (data[0]) { + case INSN_CONFIG_DIO_INPUT: + s->io_bits &= ~mask; + break; + case INSN_CONFIG_DIO_OUTPUT: + s->io_bits |= mask; + break; + case INSN_CONFIG_DIO_QUERY: + data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; + return 2; + default: + return -EINVAL; } - writeb(s->io_bits, priv(dev)->dio_counter_iobase + DIO_DIRECTION_60XX_REG); + writeb(s->io_bits, + priv(dev)->dio_counter_iobase + DIO_DIRECTION_60XX_REG); return 1; } -static int dio_60xx_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int dio_60xx_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]) - { + if (data[0]) { s->state &= ~data[0]; s->state |= (data[0] & data[1]); - writeb(s->state, priv(dev)->dio_counter_iobase + DIO_DATA_60XX_REG); + writeb(s->state, + priv(dev)->dio_counter_iobase + DIO_DATA_60XX_REG); } - data[1] = readb( priv(dev)->dio_counter_iobase + DIO_DATA_60XX_REG ); + data[1] = readb(priv(dev)->dio_counter_iobase + DIO_DATA_60XX_REG); return 2; } -static void caldac_write( comedi_device *dev, unsigned int channel, unsigned int value ) +static void caldac_write(comedi_device * dev, unsigned int channel, + unsigned int value) { priv(dev)->caldac_state[channel] = value; - switch(board(dev)->layout) - { - case LAYOUT_60XX: - case LAYOUT_64XX: - caldac_8800_write(dev, channel, value); - break; - case LAYOUT_4020: - caldac_i2c_write(dev, channel, value); - break; - default: - break; + switch (board(dev)->layout) { + case LAYOUT_60XX: + case LAYOUT_64XX: + caldac_8800_write(dev, channel, value); + break; + case LAYOUT_4020: + caldac_i2c_write(dev, channel, value); + break; + default: + break; } } -static int calib_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int calib_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel = CR_CHAN(insn->chanspec); /* return immediately if setting hasn't changed, since * programming these things is slow */ - if( priv(dev)->caldac_state[channel] == data[0] ) + if (priv(dev)->caldac_state[channel] == data[0]) return 1; - caldac_write( dev, channel, data[0] ); + caldac_write(dev, channel, data[0]); return 1; } -static int calib_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int calib_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int channel = CR_CHAN(insn->chanspec); @@ -3611,68 +3703,72 @@ static int calib_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn return 1; } -static void ad8402_write( comedi_device *dev, unsigned int channel, unsigned int value ) +static void ad8402_write(comedi_device * dev, unsigned int channel, + unsigned int value) { static const int bitstream_length = 10; unsigned int bit, register_bits; - unsigned int bitstream = ( ( channel & 0x3 ) << 8 ) | ( value & 0xff ); + unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff); static const int ad8402_comedi_udelay = 1; - priv(dev)->ad8402_state[ channel ] = value; + priv(dev)->ad8402_state[channel] = value; register_bits = SELECT_8402_64XX_BIT; - comedi_udelay( ad8402_comedi_udelay ); - writew( register_bits, priv(dev)->main_iobase + CALIBRATION_REG ); + comedi_udelay(ad8402_comedi_udelay); + writew(register_bits, priv(dev)->main_iobase + CALIBRATION_REG); - for( bit = 1 << ( bitstream_length - 1 ); bit; bit >>= 1 ) - { - if( bitstream & bit ) + for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) { + if (bitstream & bit) register_bits |= SERIAL_DATA_IN_BIT; else register_bits &= ~SERIAL_DATA_IN_BIT; - comedi_udelay( ad8402_comedi_udelay ); - writew( register_bits, priv(dev)->main_iobase + CALIBRATION_REG ); - comedi_udelay( ad8402_comedi_udelay ); - writew( register_bits | SERIAL_CLOCK_BIT, priv(dev)->main_iobase + CALIBRATION_REG ); + comedi_udelay(ad8402_comedi_udelay); + writew(register_bits, priv(dev)->main_iobase + CALIBRATION_REG); + comedi_udelay(ad8402_comedi_udelay); + writew(register_bits | SERIAL_CLOCK_BIT, + priv(dev)->main_iobase + CALIBRATION_REG); } - comedi_udelay( ad8402_comedi_udelay ); - writew( 0, priv(dev)->main_iobase + CALIBRATION_REG ); + comedi_udelay(ad8402_comedi_udelay); + writew(0, priv(dev)->main_iobase + CALIBRATION_REG); } /* for pci-das6402/16, channel 0 is analog input gain and channel 1 is offset */ -static int ad8402_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ad8402_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel = CR_CHAN(insn->chanspec); /* return immediately if setting hasn't changed, since * programming these things is slow */ - if( priv(dev)->ad8402_state[channel] == data[0] ) + if (priv(dev)->ad8402_state[channel] == data[0]) return 1; priv(dev)->ad8402_state[channel] = data[0]; - ad8402_write( dev, channel, data[ 0 ] ); + ad8402_write(dev, channel, data[0]); return 1; } -static int ad8402_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ad8402_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int channel = CR_CHAN(insn->chanspec); data[0] = priv(dev)->ad8402_state[channel]; - return 1; + return 1; } -static uint16_t read_eeprom(comedi_device *dev, uint8_t address) +static uint16_t read_eeprom(comedi_device * dev, uint8_t address) { static const int bitstream_length = 11; static const int read_command = 0x6; unsigned int bitstream = (read_command << 8) | address; unsigned int bit; - void * const plx_control_addr = priv(dev)->plx9080_iobase + PLX_CONTROL_REG; + void *const plx_control_addr = + priv(dev)->plx9080_iobase + PLX_CONTROL_REG; uint16_t value; static const int value_length = 16; static const int eeprom_comedi_udelay = 1; @@ -3688,11 +3784,10 @@ static uint16_t read_eeprom(comedi_device *dev, uint8_t address) writel(priv(dev)->plx_control_bits, plx_control_addr); // write read command and desired memory address - for(bit = 1 << (bitstream_length - 1); bit; bit >>= 1) - { + for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) { // set bit to be written comedi_udelay(eeprom_comedi_udelay); - if(bitstream & bit) + if (bitstream & bit) priv(dev)->plx_control_bits |= CTL_EE_W; else priv(dev)->plx_control_bits &= ~CTL_EE_W; @@ -3707,8 +3802,7 @@ static uint16_t read_eeprom(comedi_device *dev, uint8_t address) } // read back value from eeprom memory location value = 0; - for(bit = 1 << (value_length - 1); bit; bit >>= 1) - { + for (bit = 1 << (value_length - 1); bit; bit >>= 1) { // clock out bit comedi_udelay(eeprom_comedi_udelay); priv(dev)->plx_control_bits |= CTL_EE_CLK; @@ -3717,7 +3811,7 @@ static uint16_t read_eeprom(comedi_device *dev, uint8_t address) priv(dev)->plx_control_bits &= ~CTL_EE_CLK; writel(priv(dev)->plx_control_bits, plx_control_addr); comedi_udelay(eeprom_comedi_udelay); - if(readl(plx_control_addr) & CTL_EE_R) + if (readl(plx_control_addr) & CTL_EE_R) value |= bit; } @@ -3729,56 +3823,58 @@ static uint16_t read_eeprom(comedi_device *dev, uint8_t address) return value; } -static int eeprom_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[0] = read_eeprom(dev, CR_CHAN(insn->chanspec)); + data[0] = read_eeprom(dev, CR_CHAN(insn->chanspec)); - return 1; + return 1; } /* utility function that rounds desired timing to an achievable time, and * sets cmd members appropriately. * adc paces conversions from master clock by dividing by (x + 3) where x is 24 bit number */ -static void check_adc_timing( comedi_device *dev, comedi_cmd *cmd) +static void check_adc_timing(comedi_device * dev, comedi_cmd * cmd) { unsigned int convert_divisor = 0, scan_divisor; static const int min_convert_divisor = 3; - static const int max_convert_divisor = max_counter_value + min_convert_divisor; + static const int max_convert_divisor = + max_counter_value + min_convert_divisor; static const int min_scan_divisor_4020 = 2; unsigned long long max_scan_divisor, min_scan_divisor; - if(cmd->convert_src == TRIG_TIMER) - { - if( board(dev)->layout == LAYOUT_4020 ) - { + if (cmd->convert_src == TRIG_TIMER) { + if (board(dev)->layout == LAYOUT_4020) { cmd->convert_arg = 0; - }else - { - convert_divisor = get_divisor(cmd->convert_arg, cmd->flags); - if(convert_divisor > max_convert_divisor) convert_divisor = max_convert_divisor; - if(convert_divisor < min_convert_divisor) convert_divisor = min_convert_divisor; + } else { + convert_divisor = + get_divisor(cmd->convert_arg, cmd->flags); + if (convert_divisor > max_convert_divisor) + convert_divisor = max_convert_divisor; + if (convert_divisor < min_convert_divisor) + convert_divisor = min_convert_divisor; cmd->convert_arg = convert_divisor * TIMER_BASE; } - }else if(cmd->convert_src == TRIG_NOW) + } else if (cmd->convert_src == TRIG_NOW) cmd->convert_arg = 0; - - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { scan_divisor = get_divisor(cmd->scan_begin_arg, cmd->flags); - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { // XXX check for integer overflows min_scan_divisor = convert_divisor * cmd->chanlist_len; - max_scan_divisor = (convert_divisor * cmd->chanlist_len - 1) + max_counter_value; - }else - { + max_scan_divisor = + (convert_divisor * cmd->chanlist_len - 1) + + max_counter_value; + } else { min_scan_divisor = min_scan_divisor_4020; max_scan_divisor = max_counter_value + min_scan_divisor; } - if(scan_divisor > max_scan_divisor) scan_divisor = max_scan_divisor; - if(scan_divisor < min_scan_divisor) scan_divisor = min_scan_divisor; + if (scan_divisor > max_scan_divisor) + scan_divisor = max_scan_divisor; + if (scan_divisor < min_scan_divisor) + scan_divisor = min_scan_divisor; cmd->scan_begin_arg = scan_divisor * TIMER_BASE; } @@ -3792,18 +3888,17 @@ static unsigned int get_divisor(unsigned int ns, unsigned int flags) { unsigned int divisor; - switch(flags & TRIG_ROUND_MASK) - { - case TRIG_ROUND_UP: - divisor = (ns + TIMER_BASE - 1) / TIMER_BASE; - break; - case TRIG_ROUND_DOWN: - divisor = ns / TIMER_BASE; - break; - case TRIG_ROUND_NEAREST: - default: - divisor = (ns + TIMER_BASE / 2) / TIMER_BASE; - break; + switch (flags & TRIG_ROUND_MASK) { + case TRIG_ROUND_UP: + divisor = (ns + TIMER_BASE - 1) / TIMER_BASE; + break; + case TRIG_ROUND_DOWN: + divisor = ns / TIMER_BASE; + break; + case TRIG_ROUND_NEAREST: + default: + divisor = (ns + TIMER_BASE / 2) / TIMER_BASE; + break; } return divisor; } @@ -3814,7 +3909,7 @@ static unsigned int get_ao_divisor(unsigned int ns, unsigned int flags) } // adjusts the size of hardware fifo (which determines block size for dma xfers) -static int set_ai_fifo_size( comedi_device *dev, unsigned int num_samples ) +static int set_ai_fifo_size(comedi_device * dev, unsigned int num_samples) { unsigned int num_fifo_entries; int retval; @@ -3822,49 +3917,56 @@ static int set_ai_fifo_size( comedi_device *dev, unsigned int num_samples ) num_fifo_entries = num_samples / fifo->sample_packing_ratio; - retval = set_ai_fifo_segment_length( dev, num_fifo_entries / fifo->num_segments ); - if( retval < 0 ) return retval; + retval = set_ai_fifo_segment_length(dev, + num_fifo_entries / fifo->num_segments); + if (retval < 0) + return retval; num_samples = retval * fifo->num_segments * fifo->sample_packing_ratio; - DEBUG_PRINT( "set hardware fifo size to %i\n", num_samples ); + DEBUG_PRINT("set hardware fifo size to %i\n", num_samples); return num_samples; } // query length of fifo -static unsigned int ai_fifo_size( comedi_device *dev ) +static unsigned int ai_fifo_size(comedi_device * dev) { - return priv(dev)->ai_fifo_segment_length * board(dev)->ai_fifo->num_segments * + return priv(dev)->ai_fifo_segment_length * + board(dev)->ai_fifo->num_segments * board(dev)->ai_fifo->sample_packing_ratio; } -static int set_ai_fifo_segment_length( comedi_device *dev, unsigned int num_entries ) +static int set_ai_fifo_segment_length(comedi_device * dev, + unsigned int num_entries) { static const int increment_size = 0x100; const hw_fifo_info_t *const fifo = board(dev)->ai_fifo; unsigned int num_increments; uint16_t bits; - if( num_entries < increment_size ) num_entries = increment_size; - if( num_entries > fifo->max_segment_length ) num_entries = fifo->max_segment_length; + if (num_entries < increment_size) + num_entries = increment_size; + if (num_entries > fifo->max_segment_length) + num_entries = fifo->max_segment_length; // 1 == 256 entries, 2 == 512 entries, etc - num_increments = ( num_entries + increment_size / 2 ) / increment_size; + num_increments = (num_entries + increment_size / 2) / increment_size; bits = (~(num_increments - 1)) & fifo->fifo_size_reg_mask; priv(dev)->fifo_size_bits &= ~fifo->fifo_size_reg_mask; priv(dev)->fifo_size_bits |= bits; - writew( priv(dev)->fifo_size_bits, priv(dev)->main_iobase + FIFO_SIZE_REG ); + writew(priv(dev)->fifo_size_bits, + priv(dev)->main_iobase + FIFO_SIZE_REG); priv(dev)->ai_fifo_segment_length = num_increments * increment_size; - DEBUG_PRINT( "set hardware fifo segment length to %i\n", priv(dev)->ai_fifo_segment_length ); + DEBUG_PRINT("set hardware fifo segment length to %i\n", + priv(dev)->ai_fifo_segment_length); return priv(dev)->ai_fifo_segment_length; } - /* pci-6025 8800 caldac: * address 0 == dac channel 0 offset * address 1 == dac channel 0 gain @@ -3886,7 +3988,8 @@ static int set_ai_fifo_segment_length( comedi_device *dev, unsigned int num_entr * address 7 == dac channel 1 fine offset */ -static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t value) +static int caldac_8800_write(comedi_device * dev, unsigned int address, + uint8_t value) { static const int num_caldac_channels = 8; static const int bitstream_length = 11; @@ -3894,15 +3997,13 @@ static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t v unsigned int bit, register_bits; static const int caldac_8800_udelay = 1; - if(address >= num_caldac_channels) - { + if (address >= num_caldac_channels) { comedi_error(dev, "illegal caldac channel"); return -1; } - for(bit = 1 << (bitstream_length - 1); bit; bit >>= 1) - { + for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) { register_bits = 0; - if(bitstream & bit) + if (bitstream & bit) register_bits |= SERIAL_DATA_IN_BIT; comedi_udelay(caldac_8800_udelay); writew(register_bits, priv(dev)->main_iobase + CALIBRATION_REG); @@ -3919,61 +4020,59 @@ static int caldac_8800_write(comedi_device *dev, unsigned int address, uint8_t v } // 4020 caldacs -static int caldac_i2c_write(comedi_device *dev, unsigned int caldac_channel, unsigned int value) +static int caldac_i2c_write(comedi_device * dev, unsigned int caldac_channel, + unsigned int value) { uint8_t serial_bytes[3]; uint8_t i2c_addr; - enum pointer_bits - { + enum pointer_bits { // manual has gain and offset bits switched OFFSET_0_2 = 0x1, GAIN_0_2 = 0x2, OFFSET_1_3 = 0x4, GAIN_1_3 = 0x8, }; - enum data_bits - { + enum data_bits { NOT_CLEAR_REGISTERS = 0x20, }; - switch(caldac_channel) - { - case 0: // chan 0 offset - i2c_addr = CALDAC0_I2C_ADDR; - serial_bytes[0] = OFFSET_0_2; - break; - case 1: // chan 1 offset - i2c_addr = CALDAC0_I2C_ADDR; - serial_bytes[0] = OFFSET_1_3; - break; - case 2: // chan 2 offset - i2c_addr = CALDAC1_I2C_ADDR; - serial_bytes[0] = OFFSET_0_2; - break; - case 3: // chan 3 offset - i2c_addr = CALDAC1_I2C_ADDR; - serial_bytes[0] = OFFSET_1_3; - break; - case 4: // chan 0 gain - i2c_addr = CALDAC0_I2C_ADDR; - serial_bytes[0] = GAIN_0_2; - break; - case 5: // chan 1 gain - i2c_addr = CALDAC0_I2C_ADDR; - serial_bytes[0] = GAIN_1_3; - break; - case 6: // chan 2 gain - i2c_addr = CALDAC1_I2C_ADDR; - serial_bytes[0] = GAIN_0_2; - break; - case 7: // chan 3 gain - i2c_addr = CALDAC1_I2C_ADDR; - serial_bytes[0] = GAIN_1_3; - break; - default: - comedi_error(dev, "invalid caldac channel\n"); - return -1; - break; + switch (caldac_channel) { + case 0: // chan 0 offset + i2c_addr = CALDAC0_I2C_ADDR; + serial_bytes[0] = OFFSET_0_2; + break; + case 1: // chan 1 offset + i2c_addr = CALDAC0_I2C_ADDR; + serial_bytes[0] = OFFSET_1_3; + break; + case 2: // chan 2 offset + i2c_addr = CALDAC1_I2C_ADDR; + serial_bytes[0] = OFFSET_0_2; + break; + case 3: // chan 3 offset + i2c_addr = CALDAC1_I2C_ADDR; + serial_bytes[0] = OFFSET_1_3; + break; + case 4: // chan 0 gain + i2c_addr = CALDAC0_I2C_ADDR; + serial_bytes[0] = GAIN_0_2; + break; + case 5: // chan 1 gain + i2c_addr = CALDAC0_I2C_ADDR; + serial_bytes[0] = GAIN_1_3; + break; + case 6: // chan 2 gain + i2c_addr = CALDAC1_I2C_ADDR; + serial_bytes[0] = GAIN_0_2; + break; + case 7: // chan 3 gain + i2c_addr = CALDAC1_I2C_ADDR; + serial_bytes[0] = GAIN_1_3; + break; + default: + comedi_error(dev, "invalid caldac channel\n"); + return -1; + break; } serial_bytes[1] = NOT_CLEAR_REGISTERS | ((value >> 8) & 0xf); serial_bytes[2] = value & 0xff; @@ -3986,18 +4085,17 @@ static const int i2c_high_comedi_udelay = 1000; static const int i2c_low_comedi_udelay = 10; // set i2c data line high or low -static void i2c_set_sda(comedi_device *dev, int state) +static void i2c_set_sda(comedi_device * dev, int state) { static const int data_bit = CTL_EE_W; void *plx_control_addr = priv(dev)->plx9080_iobase + PLX_CONTROL_REG; - if(state) - { + if (state) { // set data line high priv(dev)->plx_control_bits &= ~data_bit; writel(priv(dev)->plx_control_bits, plx_control_addr); comedi_udelay(i2c_high_comedi_udelay); - }else // set data line low + } else // set data line low { priv(dev)->plx_control_bits |= data_bit; writel(priv(dev)->plx_control_bits, plx_control_addr); @@ -4006,18 +4104,17 @@ static void i2c_set_sda(comedi_device *dev, int state) } // set i2c clock line high or low -static void i2c_set_scl(comedi_device *dev, int state) +static void i2c_set_scl(comedi_device * dev, int state) { static const int clock_bit = CTL_USERO; void *plx_control_addr = priv(dev)->plx9080_iobase + PLX_CONTROL_REG; - if(state) - { + if (state) { // set clock line high priv(dev)->plx_control_bits &= ~clock_bit; writel(priv(dev)->plx_control_bits, plx_control_addr); comedi_udelay(i2c_high_comedi_udelay); - }else // set clock line low + } else // set clock line low { priv(dev)->plx_control_bits |= clock_bit; writel(priv(dev)->plx_control_bits, plx_control_addr); @@ -4025,17 +4122,16 @@ static void i2c_set_scl(comedi_device *dev, int state) } } -static void i2c_write_byte(comedi_device *dev, uint8_t byte) +static void i2c_write_byte(comedi_device * dev, uint8_t byte) { uint8_t bit; unsigned int num_bits = 8; DEBUG_PRINT("writing to i2c byte 0x%x\n", byte); - for(bit = 1 << (num_bits - 1); bit; bit >>= 1) - { + for (bit = 1 << (num_bits - 1); bit; bit >>= 1) { i2c_set_scl(dev, 0); - if((byte & bit)) + if ((byte & bit)) i2c_set_sda(dev, 1); else i2c_set_sda(dev, 0); @@ -4044,17 +4140,17 @@ static void i2c_write_byte(comedi_device *dev, uint8_t byte) } // we can't really read the lines, so fake it -static int i2c_read_ack(comedi_device *dev) +static int i2c_read_ack(comedi_device * dev) { i2c_set_scl(dev, 0); i2c_set_sda(dev, 1); i2c_set_scl(dev, 1); - return 0; // return fake acknowledge bit + return 0; // return fake acknowledge bit } // send start bit -static void i2c_start(comedi_device *dev) +static void i2c_start(comedi_device * dev) { i2c_set_scl(dev, 1); i2c_set_sda(dev, 1); @@ -4062,7 +4158,7 @@ static void i2c_start(comedi_device *dev) } // send stop bit -static void i2c_stop(comedi_device *dev) +static void i2c_stop(comedi_device * dev) { i2c_set_scl(dev, 0); i2c_set_sda(dev, 0); @@ -4070,7 +4166,8 @@ static void i2c_stop(comedi_device *dev) i2c_set_sda(dev, 1); } -static void i2c_write(comedi_device *dev, unsigned int address, const uint8_t *data, unsigned int length) +static void i2c_write(comedi_device * dev, unsigned int address, + const uint8_t * data, unsigned int length) { unsigned int i; uint8_t bitstream; @@ -4089,19 +4186,15 @@ static void i2c_write(comedi_device *dev, unsigned int address, const uint8_t *d i2c_write_byte(dev, bitstream); // get acknowledge - if(i2c_read_ack(dev) != 0) - { + if (i2c_read_ack(dev) != 0) { comedi_error(dev, "i2c write failed: no acknowledge"); i2c_stop(dev); return; } - // write data bytes - for(i = 0; i < length; i++) - { + for (i = 0; i < length; i++) { i2c_write_byte(dev, data[i]); - if(i2c_read_ack(dev) != 0) - { + if (i2c_read_ack(dev) != 0) { comedi_error(dev, "i2c write failed: no acknowledge"); i2c_stop(dev); return; @@ -4109,4 +4202,3 @@ static void i2c_write(comedi_device *dev, unsigned int address, const uint8_t *d } i2c_stop(dev); } - diff --git a/comedi/drivers/cb_pcidda.c b/comedi/drivers/cb_pcidda.c index 2b16a28e..1104e681 100644 --- a/comedi/drivers/cb_pcidda.c +++ b/comedi/drivers/cb_pcidda.c @@ -65,33 +65,33 @@ Please report sucess/failure with other different cards to // DAC is pci_dev->resource[3] /* Digital I/O registers */ -#define PORT1A 0 // PORT 1A DATA +#define PORT1A 0 // PORT 1A DATA -#define PORT1B 1 // PORT 1B DATA +#define PORT1B 1 // PORT 1B DATA -#define PORT1C 2 // PORT 1C DATA +#define PORT1C 2 // PORT 1C DATA -#define CONTROL1 3 // CONTROL REGISTER 1 +#define CONTROL1 3 // CONTROL REGISTER 1 -#define PORT2A 4 // PORT 2A DATA +#define PORT2A 4 // PORT 2A DATA -#define PORT2B 5 // PORT 2B DATA +#define PORT2B 5 // PORT 2B DATA -#define PORT2C 6 // PORT 2C DATA +#define PORT2C 6 // PORT 2C DATA -#define CONTROL2 7 // CONTROL REGISTER 2 +#define CONTROL2 7 // CONTROL REGISTER 2 /* DAC registers */ #define DACONTROL 0 // D/A CONTROL REGISTER -#define SU 0000001 // Simultaneous update enabled -#define NOSU 0000000 // Simultaneous update disabled +#define SU 0000001 // Simultaneous update enabled +#define NOSU 0000000 // Simultaneous update disabled #define ENABLEDAC 0000002 // Enable specified DAC #define DISABLEDAC 0000000 // Disable specified DAC #define RANGE2V5 0000000 // 2.5V -#define RANGE5V 0000200 // 5V +#define RANGE5V 0000200 // 5V #define RANGE10V 0000300 // 10V -#define UNIP 0000400 // Unipolar outputs -#define BIP 0000000 // Bipolar outputs +#define UNIP 0000400 // Unipolar outputs +#define BIP 0000000 // Bipolar outputs #define DACALIBRATION1 4 // D/A CALIBRATION REGISTER 1 //write bits @@ -104,25 +104,24 @@ Please report sucess/failure with other different cards to #define AO_BELOW_REF_BIT 0x40 // analog output is less than reference dac voltage #define SERIAL_OUT_BIT 0x80 // serial data out, for reading from eeprom -#define DACALIBRATION2 6 // D/A CALIBRATION REGISTER 2 +#define DACALIBRATION2 6 // D/A CALIBRATION REGISTER 2 #define SELECT_EEPROM_BIT 0x1 // send serial data in to eeprom #define DESELECT_REF_DAC_BIT 0x2 // don't send serial data to MAX542 reference dac #define DESELECT_CALDAC_BIT(n) (0x4 << (n)) // don't send serial data to caldac n #define DUMMY_BIT 0x40 // manual says to set this bit with no explanation -#define DADATA 8 // FIRST D/A DATA REGISTER (0) +#define DADATA 8 // FIRST D/A DATA REGISTER (0) -static const comedi_lrange cb_pcidda_ranges = -{ +static const comedi_lrange cb_pcidda_ranges = { 6, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + } }; /* @@ -130,79 +129,78 @@ static const comedi_lrange cb_pcidda_ranges = * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct cb_pcidda_board_struct -{ +typedef struct cb_pcidda_board_struct { const char *name; char status; // Driver status: - // 0 - tested - // 1 - manual read, not tested - // 2 - manual not read + // 0 - tested + // 1 - manual read, not tested + // 2 - manual not read unsigned short device_id; int ao_chans; int ao_bits; const comedi_lrange *ranges; } cb_pcidda_board; -static const cb_pcidda_board cb_pcidda_boards[] = -{ +static const cb_pcidda_board cb_pcidda_boards[] = { { - name: "pci-dda02/12", - status: 1, - device_id: 0x20, - ao_chans: 2, - ao_bits: 12, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda02/12", + status: 1, + device_id:0x20, + ao_chans:2, + ao_bits: 12, + ranges: &cb_pcidda_ranges, + }, { - name: "pci-dda04/12", - status: 1, - device_id: 0x21, - ao_chans: 4, - ao_bits: 12, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda04/12", + status: 1, + device_id:0x21, + ao_chans:4, + ao_bits: 12, + ranges: &cb_pcidda_ranges, + }, { - name: "pci-dda08/12", - status: 0, - device_id: 0x22, - ao_chans: 8, - ao_bits: 12, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda08/12", + status: 0, + device_id:0x22, + ao_chans:8, + ao_bits: 12, + ranges: &cb_pcidda_ranges, + }, { - name: "pci-dda02/16", - status: 2, - device_id: 0x23, - ao_chans: 2, - ao_bits: 16, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda02/16", + status: 2, + device_id:0x23, + ao_chans:2, + ao_bits: 16, + ranges: &cb_pcidda_ranges, + }, { - name: "pci-dda04/16", - status: 2, - device_id: 0x24, - ao_chans: 4, - ao_bits: 16, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda04/16", + status: 2, + device_id:0x24, + ao_chans:4, + ao_bits: 16, + ranges: &cb_pcidda_ranges, + }, { - name: "pci-dda08/16", - status: 0, - device_id: 0x25, - ao_chans: 8, - ao_bits: 16, - ranges: &cb_pcidda_ranges, - }, + name: "pci-dda08/16", + status: 0, + device_id:0x25, + ao_chans:8, + ao_bits: 16, + ranges: &cb_pcidda_ranges, + }, }; static struct pci_device_id cb_pcidda_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_CB, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0023, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0025, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_CB, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0023, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0025, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table); /* @@ -213,8 +211,7 @@ MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct -{ +typedef struct { int data; /* would be useful for a PCI device */ @@ -235,17 +232,21 @@ typedef struct */ #define devpriv ((cb_pcidda_private *)dev->private) -static int cb_pcidda_attach(comedi_device *dev,comedi_devconfig *it); -static int cb_pcidda_detach(comedi_device *dev); +static int cb_pcidda_attach(comedi_device * dev, comedi_devconfig * it); +static int cb_pcidda_detach(comedi_device * dev); //static int cb_pcidda_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcidda_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int cb_pcidda_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //static int cb_pcidda_ai_cmd(comedi_device *dev,comedi_subdevice *s); //static int cb_pcidda_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); //static int cb_pcidda_ns_to_timer(unsigned int *ns,int round); -static unsigned int cb_pcidda_serial_in(comedi_device *dev); -static void cb_pcidda_serial_out(comedi_device *dev, unsigned int value, unsigned int num_bits); -static unsigned int cb_pcidda_read_eeprom(comedi_device *dev, unsigned int address); -static void cb_pcidda_calibrate(comedi_device *dev, unsigned int channel, unsigned int range); +static unsigned int cb_pcidda_serial_in(comedi_device * dev); +static void cb_pcidda_serial_out(comedi_device * dev, unsigned int value, + unsigned int num_bits); +static unsigned int cb_pcidda_read_eeprom(comedi_device * dev, + unsigned int address); +static void cb_pcidda_calibrate(comedi_device * dev, unsigned int channel, + unsigned int range); /* * The comedi_driver structure tells the Comedi core module @@ -253,29 +254,29 @@ static void cb_pcidda_calibrate(comedi_device *dev, unsigned int channel, unsign * the board, and also about the kernel module that contains * the device code. */ -static comedi_driver driver_cb_pcidda={ - driver_name: "cb_pcidda", - module: THIS_MODULE, - attach: cb_pcidda_attach, - detach: cb_pcidda_detach, +static comedi_driver driver_cb_pcidda = { + driver_name:"cb_pcidda", + module:THIS_MODULE, + attach:cb_pcidda_attach, + detach:cb_pcidda_detach, }; /* * Attach is called by the Comedi core to configure the driver * for a particular board. */ -static int cb_pcidda_attach(comedi_device *dev, comedi_devconfig *it) +static int cb_pcidda_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - struct pci_dev* pcidev; + struct pci_dev *pcidev; int index; - printk("comedi%d: cb_pcidda: ",dev->minor); + printk("comedi%d: cb_pcidda: ", dev->minor); /* * Allocate the private structure area. */ - if(alloc_private(dev,sizeof(cb_pcidda_private))<0) + if (alloc_private(dev, sizeof(cb_pcidda_private)) < 0) return -ENOMEM; /* @@ -283,37 +284,39 @@ static int cb_pcidda_attach(comedi_device *dev, comedi_devconfig *it) */ printk("\n"); - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if(pcidev->vendor==PCI_VENDOR_ID_CB){ - if(it->options[0] || it->options[1]){ - if(pcidev->bus->number != it->options[0] || - PCI_SLOT(pcidev->devfn) != it->options[1]){ + if (pcidev->vendor == PCI_VENDOR_ID_CB) { + if (it->options[0] || it->options[1]) { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } - for(index=0;indexdevice){ + for (index = 0; index < N_BOARDS; index++) { + if (cb_pcidda_boards[index].device_id == + pcidev->device) { goto found; } } } } - if(!pcidev){ + if (!pcidev) { printk("Not a ComputerBoards/MeasurementComputing card on requested position\n"); return -EIO; } -found: + found: devpriv->pci_dev = pcidev; - dev->board_ptr = cb_pcidda_boards+index; + dev->board_ptr = cb_pcidda_boards + index; // "thisboard" macro can be used from here. - printk("Found %s at requested position\n",thisboard->name); + printk("Found %s at requested position\n", thisboard->name); /* * Enable PCI device and request regions. */ - if (comedi_pci_enable(pcidev, thisboard->name)) - { + if (comedi_pci_enable(pcidev, thisboard->name)) { printk("cb_pcidda: failed to enable PCI device and request regions\n"); return -EIO; } @@ -321,16 +324,15 @@ found: /* * Allocate the I/O ports. */ - devpriv->digitalio = pci_resource_start(devpriv->pci_dev, DIGITALIO_BADRINDEX); + devpriv->digitalio = + pci_resource_start(devpriv->pci_dev, DIGITALIO_BADRINDEX); devpriv->dac = pci_resource_start(devpriv->pci_dev, DAC_BADRINDEX); /* * Warn about the status of the driver. */ if (thisboard->status == 2) - printk("WARNING: DRIVER FOR THIS BOARD NOT CHECKED WITH MANUAL. " - "WORKS ASSUMING FULL COMPATIBILITY WITH PCI-DDA08/12. " - "PLEASE REPORT USAGE TO .\n"); + printk("WARNING: DRIVER FOR THIS BOARD NOT CHECKED WITH MANUAL. " "WORKS ASSUMING FULL COMPATIBILITY WITH PCI-DDA08/12. " "PLEASE REPORT USAGE TO .\n"); /* * Initialize dev->board_name. @@ -340,7 +342,7 @@ found: /* * Allocate the subdevice structures. */ - if(alloc_subdevices( dev, 3 ) < 0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; s = dev->subdevices + 0; @@ -351,9 +353,9 @@ found: s->maxdata = (1 << thisboard->ao_bits) - 1; s->range_table = thisboard->ranges; s->insn_write = cb_pcidda_ao_winsn; -// s->subdev_flags |= SDF_CMD_READ; -// s->do_cmd = cb_pcidda_ai_cmd; -// s->do_cmdtest = cb_pcidda_ai_cmdtest; +// s->subdev_flags |= SDF_CMD_READ; +// s->do_cmd = cb_pcidda_ai_cmd; +// s->do_cmdtest = cb_pcidda_ai_cmdtest; // two 8255 digital io subdevices s = dev->subdevices + 1; @@ -362,21 +364,19 @@ found: subdev_8255_init(dev, s, NULL, devpriv->digitalio + PORT2A); printk(" eeprom:"); - for(index = 0; index < EEPROM_SIZE; index++) - { + for (index = 0; index < EEPROM_SIZE; index++) { devpriv->eeprom_data[index] = cb_pcidda_read_eeprom(dev, index); printk(" %i:0x%x ", index, devpriv->eeprom_data[index]); } printk("\n"); // set calibrations dacs - for(index = 0; index < thisboard->ao_chans; index++) + for (index = 0; index < thisboard->ao_chans; index++) cb_pcidda_calibrate(dev, index, devpriv->ao_range[index]); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -385,40 +385,35 @@ found: * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int cb_pcidda_detach(comedi_device *dev) +static int cb_pcidda_detach(comedi_device * dev) { /* * Deallocate the I/O ports. */ - if(devpriv) - { - if(devpriv->pci_dev) - { - if(devpriv->dac) - { + if (devpriv) { + if (devpriv->pci_dev) { + if (devpriv->dac) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } } // cleanup 8255 - if(dev->subdevices) - { + if (dev->subdevices) { subdev_8255_cleanup(dev, dev->subdevices + 1); subdev_8255_cleanup(dev, dev->subdevices + 2); } - printk("comedi%d: cb_pcidda: remove\n",dev->minor); + printk("comedi%d: cb_pcidda: remove\n", dev->minor); return 0; } - /* * I will program this later... ;-) */ #if 0 -static int cb_pcidda_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int cb_pcidda_ai_cmd(comedi_device * dev, comedi_subdevice * s) { printk("cb_pcidda_ai_cmd\n"); printk("subdev: %d\n", cmd->subdev); @@ -437,10 +432,10 @@ static int cb_pcidda_ai_cmd(comedi_device *dev,comedi_subdevice *s) #endif #if 0 -static int cb_pcidda_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int cb_pcidda_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -454,151 +449,137 @@ static int cb_pcidda_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp != cmd->start_src) + if (!cmd->start_src || tmp != cmd->start_src) err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) + if (!cmd->convert_src || tmp != cmd->convert_src) err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) + if (!cmd->stop_src || tmp != cmd->stop_src) err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_EXT) + if (cmd->scan_begin_src != TRIG_TIMER + && cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT) + if (cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT) err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0) - { - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SPEED 10000 /* in nanoseconds */ +#define MAX_SPEED 10000 /* in nanoseconds */ #define MIN_SPEED 1000000000 /* in nanoseconds */ - if (cmd->scan_begin_src == TRIG_TIMER) - { - if (cmd->scan_begin_arg < MAX_SPEED) - { + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { cmd->scan_begin_arg = MAX_SPEED; err++; } - if (cmd->scan_begin_arg > MIN_SPEED) - { + if (cmd->scan_begin_arg > MIN_SPEED) { cmd->scan_begin_arg = MIN_SPEED; err++; } - } - else - { + } else { /* external trigger */ /* should be level/edge, hi/lo specification here */ /* should specify multiple external triggers */ - if (cmd->scan_begin_arg > 9) - { + if (cmd->scan_begin_arg > 9) { cmd->scan_begin_arg = 9; err++; } } - if (cmd->convert_src == TRIG_TIMER) - { - if (cmd->convert_arg < MAX_SPEED) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < MAX_SPEED) { cmd->convert_arg = MAX_SPEED; err++; } - if (cmd->convert_arg>MIN_SPEED) - { + if (cmd->convert_arg > MIN_SPEED) { cmd->convert_arg = MIN_SPEED; err++; } - } - else - { + } else { /* external trigger */ /* see above */ - if (cmd->convert_arg > 9) - { + if (cmd->convert_arg > 9) { cmd->convert_arg = 9; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + 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) - { + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0x00ffffff) { cmd->stop_arg = 0x00ffffff; err++; } - } - else - { + } else { /* TRIG_NONE */ - if (cmd->stop_arg != 0) - { - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; - cb_pcidda_ns_to_timer(&cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->scan_begin_arg) + cb_pcidda_ns_to_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) err++; } - if(cmd->convert_src == TRIG_TIMER) - { - tmp=cmd->convert_arg; - cb_pcidda_ns_to_timer(&cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->convert_arg) + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + cb_pcidda_ns_to_timer(&cmd->convert_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; + 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; + if (err) + return 4; return 0; } @@ -610,14 +591,15 @@ static int cb_pcidda_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, * the device. Also, it should adjust ns so that it cooresponds to * the actual time that the device will use. */ #if 0 -static int cb_pcidda_ns_to_timer(unsigned int *ns,int round) +static int cb_pcidda_ns_to_timer(unsigned int *ns, int round) { /* trivial timer */ return *ns; } #endif -static int cb_pcidda_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int cb_pcidda_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int command; unsigned int channel, range; @@ -626,33 +608,32 @@ static int cb_pcidda_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn range = CR_RANGE(insn->chanspec); // adjust calibration dacs if range has changed - if(range != devpriv->ao_range[channel]) + if (range != devpriv->ao_range[channel]) cb_pcidda_calibrate(dev, channel, range); /* output channel configuration */ command = NOSU | ENABLEDAC; /* output channel range */ - switch (range) - { - case 0: - command |= BIP | RANGE10V; - break; - case 1: - command |= BIP | RANGE5V; - break; - case 2: - command |= BIP | RANGE2V5; - break; - case 3: - command |= UNIP | RANGE10V; - break; - case 4: - command |= UNIP | RANGE5V; - break; - case 5: - command |= UNIP | RANGE2V5; - break; + switch (range) { + case 0: + command |= BIP | RANGE10V; + break; + case 1: + command |= BIP | RANGE5V; + break; + case 2: + command |= BIP | RANGE2V5; + break; + case 3: + command |= UNIP | RANGE10V; + break; + case 4: + command |= UNIP | RANGE5V; + break; + case 5: + command |= UNIP | RANGE2V5; + break; }; /* output channel specification */ @@ -667,17 +648,15 @@ static int cb_pcidda_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn } // lowlevel read from eeprom -static unsigned int cb_pcidda_serial_in(comedi_device *dev) +static unsigned int cb_pcidda_serial_in(comedi_device * dev) { unsigned int value = 0; int i; const int value_width = 16; // number of bits wide values are - for(i = 1; i <= value_width; i++) - { + for (i = 1; i <= value_width; i++) { // read bits most significant bit first - if(inw_p(devpriv->dac + DACALIBRATION1) & SERIAL_OUT_BIT) - { + if (inw_p(devpriv->dac + DACALIBRATION1) & SERIAL_OUT_BIT) { value |= 1 << (value_width - i); } } @@ -686,14 +665,14 @@ static unsigned int cb_pcidda_serial_in(comedi_device *dev) } // lowlevel write to eeprom/dac -static void cb_pcidda_serial_out(comedi_device *dev, unsigned int value, unsigned int num_bits) +static void cb_pcidda_serial_out(comedi_device * dev, unsigned int value, + unsigned int num_bits) { int i; - for(i = 1; i <= num_bits; i++) - { + for (i = 1; i <= num_bits; i++) { // send bits most significant bit first - if(value & (1 << (num_bits - i))) + if (value & (1 << (num_bits - i))) devpriv->dac_cal1_bits |= SERIAL_IN_BIT; else devpriv->dac_cal1_bits &= ~SERIAL_IN_BIT; @@ -701,9 +680,9 @@ static void cb_pcidda_serial_out(comedi_device *dev, unsigned int value, unsigne } } - // reads a 16 bit value from board's eeprom -static unsigned int cb_pcidda_read_eeprom(comedi_device *dev, unsigned int address) +static unsigned int cb_pcidda_read_eeprom(comedi_device * dev, + unsigned int address) { unsigned int i; unsigned int cal2_bits; @@ -716,8 +695,7 @@ static unsigned int cb_pcidda_read_eeprom(comedi_device *dev, unsigned int addre // send serial output stream to eeprom cal2_bits = SELECT_EEPROM_BIT | DESELECT_REF_DAC_BIT | DUMMY_BIT; // deactivate caldacs (one caldac for every two channels) - for(i = 0; i < max_num_caldacs; i++) - { + for (i = 0; i < max_num_caldacs; i++) { cal2_bits |= DESELECT_CALDAC_BIT(i); } outw_p(cal2_bits, devpriv->dac + DACALIBRATION2); @@ -737,7 +715,7 @@ static unsigned int cb_pcidda_read_eeprom(comedi_device *dev, unsigned int addre } // writes to 8 bit calibration dacs -static void cb_pcidda_write_caldac(comedi_device *dev, unsigned int caldac, +static void cb_pcidda_write_caldac(comedi_device * dev, unsigned int caldac, unsigned int channel, unsigned int value) { unsigned int cal2_bits; @@ -755,8 +733,7 @@ static void cb_pcidda_write_caldac(comedi_device *dev, unsigned int caldac, // deselect reference dac cal2_bits = DESELECT_REF_DAC_BIT | DUMMY_BIT; // deactivate caldacs (one caldac for every two channels) - for(i = 0; i < max_num_caldacs; i++) - { + for (i = 0; i < max_num_caldacs; i++) { cal2_bits |= DESELECT_CALDAC_BIT(i); } // activate the caldac we want @@ -778,6 +755,7 @@ static unsigned int fine_gain_channel(unsigned int ao_channel) { return 4 * (ao_channel % 2); } + // returns caldac channel that provides coarse gain for given ao channel static unsigned int coarse_gain_channel(unsigned int ao_channel) { @@ -797,13 +775,15 @@ static unsigned int fine_offset_channel(unsigned int ao_channel) } // returns eeprom address that provides offset for given ao channel and range -static unsigned int offset_eeprom_address(unsigned int ao_channel, unsigned int range) +static unsigned int offset_eeprom_address(unsigned int ao_channel, + unsigned int range) { return 0x7 + 2 * range + 12 * ao_channel; } // returns eeprom address that provides gain calibration for given ao channel and range -static unsigned int gain_eeprom_address(unsigned int ao_channel, unsigned int range) +static unsigned int gain_eeprom_address(unsigned int ao_channel, + unsigned int range) { return 0x8 + 2 * range + 12 * ao_channel; } @@ -821,7 +801,8 @@ static unsigned int eeprom_fine_byte(unsigned int word) } // set caldacs to eeprom values for given channel and range -static void cb_pcidda_calibrate(comedi_device *dev, unsigned int channel, unsigned int range) +static void cb_pcidda_calibrate(comedi_device * dev, unsigned int channel, + unsigned int range) { unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain; @@ -829,16 +810,28 @@ static void cb_pcidda_calibrate(comedi_device *dev, unsigned int channel, unsign devpriv->ao_range[channel] = range; // get values from eeprom data - coarse_offset = eeprom_coarse_byte(devpriv->eeprom_data[offset_eeprom_address(channel, range)]); - fine_offset = eeprom_fine_byte(devpriv->eeprom_data[offset_eeprom_address(channel, range)]); - coarse_gain = eeprom_coarse_byte(devpriv->eeprom_data[gain_eeprom_address(channel, range)]); - fine_gain = eeprom_fine_byte(devpriv->eeprom_data[gain_eeprom_address(channel, range)]); + coarse_offset = + eeprom_coarse_byte(devpriv-> + eeprom_data[offset_eeprom_address(channel, range)]); + fine_offset = + eeprom_fine_byte(devpriv-> + eeprom_data[offset_eeprom_address(channel, range)]); + coarse_gain = + eeprom_coarse_byte(devpriv-> + eeprom_data[gain_eeprom_address(channel, range)]); + fine_gain = + eeprom_fine_byte(devpriv-> + eeprom_data[gain_eeprom_address(channel, range)]); // set caldacs - cb_pcidda_write_caldac(dev, caldac_number(channel), coarse_offset_channel(channel), coarse_offset); - cb_pcidda_write_caldac(dev, caldac_number(channel), fine_offset_channel(channel), fine_offset); - cb_pcidda_write_caldac(dev, caldac_number(channel), coarse_gain_channel(channel), coarse_gain); - cb_pcidda_write_caldac(dev, caldac_number(channel), fine_gain_channel(channel), fine_gain); + cb_pcidda_write_caldac(dev, caldac_number(channel), + coarse_offset_channel(channel), coarse_offset); + cb_pcidda_write_caldac(dev, caldac_number(channel), + fine_offset_channel(channel), fine_offset); + cb_pcidda_write_caldac(dev, caldac_number(channel), + coarse_gain_channel(channel), coarse_gain); + cb_pcidda_write_caldac(dev, caldac_number(channel), + fine_gain_channel(channel), fine_gain); } /* @@ -846,4 +839,3 @@ static void cb_pcidda_calibrate(comedi_device *dev, unsigned int channel, unsign * as necessary. */ COMEDI_INITCLEANUP(driver_cb_pcidda); - diff --git a/comedi/drivers/cb_pcidio.c b/comedi/drivers/cb_pcidio.c index 53ccf7d9..11a77153 100644 --- a/comedi/drivers/cb_pcidio.c +++ b/comedi/drivers/cb_pcidio.c @@ -44,7 +44,6 @@ Passing a zero for an option is the same as leaving it unspecified. #include "comedi_pci.h" #include "8255.h" - /*-------------------------- MACROS and DATATYPES -----------------------------*/ #define PCI_VENDOR_ID_CB 0x1307 @@ -53,8 +52,8 @@ Passing a zero for an option is the same as leaving it unspecified. * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct pcidio_board_struct{ - const char *name; // anme of the board +typedef struct pcidio_board_struct { + const char *name; // anme of the board int n_8255; // number of 8255 chips on board // indices of base address regions @@ -62,57 +61,50 @@ typedef struct pcidio_board_struct{ int dioregs_badrindex; } pcidio_board; - - static const pcidio_board pcidio_boards[] = { { - name: "pci-dio24", - n_8255: 1, - pcicontroler_badrindex: 1, - dioregs_badrindex: 2, - }, + name: "pci-dio24", + n_8255: 1, + pcicontroler_badrindex:1, + dioregs_badrindex:2, + }, { - name: "pci-dio24h", - n_8255: 1, - pcicontroler_badrindex: 1, - dioregs_badrindex: 2, - }, + name: "pci-dio24h", + n_8255: 1, + pcicontroler_badrindex:1, + dioregs_badrindex:2, + }, { - name: "pci-dio48h", - n_8255: 2, - pcicontroler_badrindex: 0, - dioregs_badrindex: 1, - }, + name: "pci-dio48h", + n_8255: 2, + pcicontroler_badrindex:0, + dioregs_badrindex:1, + }, }; - - /* This is used by modprobe to translate PCI IDs to drivers. Should * only be used for PCI and ISA-PnP devices */ /* Please add your PCI vendor ID to comedidev.h, and it will be forwarded * upstream. */ static struct pci_device_id pcidio_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_CB, 0x0028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x0014, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_CB, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_CB, 0x0028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x0014, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_CB, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; -MODULE_DEVICE_TABLE(pci, pcidio_pci_table); - +MODULE_DEVICE_TABLE(pci, pcidio_pci_table); /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const pcidio_board *)dev->board_ptr) - - /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ - int data; // curently unused +typedef struct { + int data; // curently unused /* would be useful for a PCI device */ struct pci_dev *pci_dev; @@ -120,32 +112,28 @@ typedef struct{ /* used for DO readback, curently unused */ lsampl_t do_readback[4]; /* up to 4 lsampl_t suffice to hold 96 bits for PCI-DIO96 */ - unsigned long dio_reg_base; // address of port A of the first 8255 chip on board + unsigned long dio_reg_base; // address of port A of the first 8255 chip on board } pcidio_private; - - /* * most drivers define the following macro to make it easy to * access the private structure. */ #define devpriv ((pcidio_private *)dev->private) - - /* * The comedi_driver structure tells the Comedi core module * which functions to call to configure/deconfigure (attach/detach) * the board, and also about the kernel module that contains * the device code. */ -static int pcidio_attach(comedi_device *dev,comedi_devconfig *it); -static int pcidio_detach(comedi_device *dev); -static comedi_driver driver_cb_pcidio={ - driver_name: "cb_pcidio", - module: THIS_MODULE, - attach: pcidio_attach, - detach: pcidio_detach, +static int pcidio_attach(comedi_device * dev, comedi_devconfig * it); +static int pcidio_detach(comedi_device * dev); +static comedi_driver driver_cb_pcidio = { + driver_name:"cb_pcidio", + module:THIS_MODULE, + attach:pcidio_attach, + detach:pcidio_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -165,13 +153,11 @@ static comedi_driver driver_cb_pcidio={ * devices are such boards. */ // The following fields should NOT be initialized if you are dealing with PCI devices -// board_name: pcidio_boards, -// offset: sizeof(pcidio_board), -// num_names: sizeof(pcidio_boards) / sizeof(pcidio_board), +// board_name: pcidio_boards, +// offset: sizeof(pcidio_board), +// num_names: sizeof(pcidio_boards) / sizeof(pcidio_board), }; - - /*------------------------------- FUNCTIONS -----------------------------------*/ /* @@ -180,9 +166,9 @@ static comedi_driver driver_cb_pcidio={ * in the driver structure, dev->board_ptr contains that * address. */ -static int pcidio_attach(comedi_device *dev, comedi_devconfig *it) +static int pcidio_attach(comedi_device * dev, comedi_devconfig * it) { - struct pci_dev* pcidev = NULL; + struct pci_dev *pcidev = NULL; int index; int i; @@ -192,7 +178,7 @@ static int pcidio_attach(comedi_device *dev, comedi_devconfig *it) * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if(alloc_private(dev, sizeof(pcidio_private)) < 0) + if (alloc_private(dev, sizeof(pcidio_private)) < 0) return -ENOMEM; /* * If you can probe the device to determine what device in a series @@ -203,25 +189,25 @@ static int pcidio_attach(comedi_device *dev, comedi_devconfig *it) * Probe the device to determine what device in the series it is. */ - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? - if(pcidev->vendor != PCI_VENDOR_ID_CB) + if (pcidev->vendor != PCI_VENDOR_ID_CB) continue; // loop through cards supported by this driver - for(index = 0; index < sizeof pcidio_boards / sizeof(pcidio_board); index++) - { - if(pcidio_pci_table[index].device != pcidev->device) + for (index = 0; + index < sizeof pcidio_boards / sizeof(pcidio_board); + index++) { + if (pcidio_pci_table[index].device != pcidev->device) continue; // was a particular bus/slot requested? - if(it->options[0] || it->options[1]) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if(pcidev->bus->number != it->options[0] || - PCI_SLOT(pcidev->devfn) != it->options[1]) - { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } @@ -234,7 +220,7 @@ static int pcidio_attach(comedi_device *dev, comedi_devconfig *it) "requested position\n"); return -EIO; -found: + found: /* * Initialize dev->board_name. Note that we can use the "thisboard" @@ -244,26 +230,29 @@ found: devpriv->pci_dev = pcidev; printk("Found %s on bus %i, slot %i\n", thisboard->name, - devpriv->pci_dev->bus->number, PCI_SLOT(devpriv->pci_dev->devfn)); - if(comedi_pci_enable(pcidev, thisboard->name)) { + devpriv->pci_dev->bus->number, + PCI_SLOT(devpriv->pci_dev->devfn)); + if (comedi_pci_enable(pcidev, thisboard->name)) { printk("cb_pcidio: failed to enable PCI device and request regions\n"); return -EIO; } devpriv->dio_reg_base - = pci_resource_start(devpriv->pci_dev, pcidio_boards[index].dioregs_badrindex); + = + pci_resource_start(devpriv->pci_dev, + pcidio_boards[index].dioregs_badrindex); /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, thisboard->n_8255) < 0) + if (alloc_subdevices(dev, thisboard->n_8255) < 0) return -ENOMEM; - for(i = 0; i < thisboard->n_8255; i++) - { + for (i = 0; i < thisboard->n_8255; i++) { subdev_8255_init(dev, dev->subdevices + i, NULL, devpriv->dio_reg_base + i * 4); - printk(" subdev %d: base = 0x%lx\n", i, devpriv->dio_reg_base + i * 4); + printk(" subdev %d: base = 0x%lx\n", i, + devpriv->dio_reg_base + i * 4); } printk("attached\n"); @@ -278,18 +267,18 @@ found: * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pcidio_detach(comedi_device *dev) +static int pcidio_detach(comedi_device * dev) { - printk("comedi%d: cb_pcidio: remove\n",dev->minor); - if(devpriv) { - if(devpriv->pci_dev) { - if(devpriv->dio_reg_base) { + printk("comedi%d: cb_pcidio: remove\n", dev->minor); + if (devpriv) { + if (devpriv->pci_dev) { + if (devpriv->dio_reg_base) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } } - if(dev->subdevices) { + if (dev->subdevices) { int i; for (i = 0; i < thisboard->n_8255; i++) { subdev_8255_cleanup(dev, dev->subdevices + i); @@ -303,4 +292,3 @@ static int pcidio_detach(comedi_device *dev) * as necessary. */ COMEDI_INITCLEANUP(driver_cb_pcidio); - diff --git a/comedi/drivers/cb_pcimdas.c b/comedi/drivers/cb_pcimdas.c index 39bba14f..9f024950 100644 --- a/comedi/drivers/cb_pcimdas.c +++ b/comedi/drivers/cb_pcimdas.c @@ -54,7 +54,7 @@ See http://www.measurementcomputing.com/PDFManuals/pcim-das1602_16.pdf for more /* Registers for the PCIM-DAS1602/16 */ // sizes of io regions (bytes) -#define BADR0_SIZE 2 //?? +#define BADR0_SIZE 2 //?? #define BADR1_SIZE 4 #define BADR2_SIZE 6 #define BADR3_SIZE 16 @@ -83,53 +83,53 @@ See http://www.measurementcomputing.com/PDFManuals/pcim-das1602_16.pdf for more #define RESID_COUNT_L 14 /* Board description */ -typedef struct cb_pcimdas_board_struct -{ +typedef struct cb_pcimdas_board_struct { const char *name; unsigned short device_id; int ai_se_chans; // Inputs in single-ended mode int ai_diff_chans; // Inputs in differential mode - int ai_bits; // analog input resolution - int ai_speed; // fastest conversion period in ns - int ao_nchan; // number of analog out channels - int ao_bits; // analogue output resolution + int ai_bits; // analog input resolution + int ai_speed; // fastest conversion period in ns + int ao_nchan; // number of analog out channels + int ao_bits; // analogue output resolution int has_ao_fifo; // analog output has fifo int ao_scan_speed; // analog output speed for 1602 series (for a scan, not conversion) - int fifo_size; // number of samples fifo can hold - int dio_bits; // number of dio bits - int has_dio; // has DIO + int fifo_size; // number of samples fifo can hold + int dio_bits; // number of dio bits + int has_dio; // has DIO const comedi_lrange *ranges; } cb_pcimdas_board; -static const cb_pcimdas_board cb_pcimdas_boards[] = -{ +static const cb_pcimdas_board cb_pcimdas_boards[] = { { - name: "PCIM-DAS1602/16", - device_id: 0x56, - ai_se_chans: 16, - ai_diff_chans: 8, - ai_bits: 16, - ai_speed: 10000, //?? - ao_nchan: 2, - ao_bits: 12, - has_ao_fifo: 0, //?? - ao_scan_speed: 10000, //?? - fifo_size: 1024, - dio_bits: 24, - has_dio: 1, -// ranges: &cb_pcimdas_ranges, - }, + name: "PCIM-DAS1602/16", + device_id:0x56, + ai_se_chans:16, + ai_diff_chans:8, + ai_bits: 16, + ai_speed:10000, //?? + ao_nchan:2, + ao_bits: 12, + has_ao_fifo:0, //?? + ao_scan_speed:10000, + //?? + fifo_size:1024, + dio_bits:24, + has_dio: 1, +// ranges: &cb_pcimdas_ranges, + }, }; /* This is used by modprobe to translate PCI IDs to drivers. Should * only be used for PCI and ISA-PnP devices */ static struct pci_device_id cb_pcimdas_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_COMPUTERBOARDS, 0x0056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_COMPUTERBOARDS, 0x0056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table); -#define N_BOARDS 1 // Max number of boards supported +#define N_BOARDS 1 // Max number of boards supported /* * Useful for shorthand access to the particular board structure @@ -139,7 +139,7 @@ MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ +typedef struct { int data; // would be useful for a PCI device @@ -156,12 +156,12 @@ typedef struct{ lsampl_t ao_readback[2]; // Used for DIO - unsigned short int port_a; // copy of BADR4+0 - unsigned short int port_b; // copy of BADR4+1 - unsigned short int port_c; // copy of BADR4+2 - unsigned short int dio_mode; // copy of BADR4+3 + unsigned short int port_a; // copy of BADR4+0 + unsigned short int port_b; // copy of BADR4+1 + unsigned short int port_c; // copy of BADR4+2 + unsigned short int dio_mode; // copy of BADR4+3 -}cb_pcimdas_private; +} cb_pcimdas_private; /* * most drivers define the following macro to make it easy to @@ -175,18 +175,21 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int cb_pcimdas_attach(comedi_device *dev,comedi_devconfig *it); -static int cb_pcimdas_detach(comedi_device *dev); -static comedi_driver driver_cb_pcimdas={ - driver_name: "cb_pcimdas", - module: THIS_MODULE, - attach: cb_pcimdas_attach, - detach: cb_pcimdas_detach, +static int cb_pcimdas_attach(comedi_device * dev, comedi_devconfig * it); +static int cb_pcimdas_detach(comedi_device * dev); +static comedi_driver driver_cb_pcimdas = { + driver_name:"cb_pcimdas", + module:THIS_MODULE, + attach:cb_pcimdas_attach, + detach:cb_pcimdas_detach, }; -static int cb_pcimdas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcimdas_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int cb_pcimdas_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int cb_pcimdas_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcimdas_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int cb_pcimdas_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* * Attach is called by the Comedi core to configure the driver @@ -194,19 +197,19 @@ static int cb_pcimdas_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_ins * in the driver structure, dev->board_ptr contains that * address. */ -static int cb_pcimdas_attach(comedi_device *dev,comedi_devconfig *it) +static int cb_pcimdas_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - struct pci_dev* pcidev; + struct pci_dev *pcidev; int index; //int i; - printk("comedi%d: cb_pcimdas: ",dev->minor); + printk("comedi%d: cb_pcimdas: ", dev->minor); /* * Allocate the private structure area. */ - if(alloc_private(dev,sizeof(cb_pcimdas_private))<0) + if (alloc_private(dev, sizeof(cb_pcimdas_private)) < 0) return -ENOMEM; /* @@ -214,24 +217,23 @@ static int cb_pcimdas_attach(comedi_device *dev,comedi_devconfig *it) */ printk("\n"); - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? - if(pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) + if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) continue; // loop through cards supported by this driver - for(index = 0; index < N_BOARDS; index++) - { - if(cb_pcimdas_boards[index].device_id != pcidev->device) + for (index = 0; index < N_BOARDS; index++) { + if (cb_pcimdas_boards[index].device_id != + pcidev->device) continue; // was a particular bus/slot requested? - if(it->options[0] || it->options[1]) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if(pcidev->bus->number != it->options[0] || - PCI_SLOT(pcidev->devfn) != it->options[1]) - { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } @@ -245,23 +247,21 @@ static int cb_pcimdas_attach(comedi_device *dev,comedi_devconfig *it) "requested position\n"); return -EIO; -found: + found: printk("Found %s on bus %i, slot %i\n", cb_pcimdas_boards[index].name, pcidev->bus->number, PCI_SLOT(pcidev->devfn)); // Warn about non-tested features - switch(thisboard->device_id) - { - case 0x56: - break; - default: - printk( "THIS CARD IS UNSUPPORTED.\n" - "PLEASE REPORT USAGE TO \n"); + switch (thisboard->device_id) { + case 0x56: + break; + default: + printk("THIS CARD IS UNSUPPORTED.\n" + "PLEASE REPORT USAGE TO \n"); }; - if(comedi_pci_enable(pcidev, "cb_pcimdas")) - { + if (comedi_pci_enable(pcidev, "cb_pcimdas")) { printk(" Failed to enable PCI device and request regions\n"); return -EIO; } @@ -273,61 +273,59 @@ found: devpriv->BADR4 = pci_resource_start(devpriv->pci_dev, 4); #ifdef CBPCIMDAS_DEBUG - printk("devpriv->BADR0 = 0x%lx\n",devpriv->BADR0); - printk("devpriv->BADR1 = 0x%lx\n",devpriv->BADR1); - printk("devpriv->BADR2 = 0x%lx\n",devpriv->BADR2); - printk("devpriv->BADR3 = 0x%lx\n",devpriv->BADR3); - printk("devpriv->BADR4 = 0x%lx\n",devpriv->BADR4); + printk("devpriv->BADR0 = 0x%lx\n", devpriv->BADR0); + printk("devpriv->BADR1 = 0x%lx\n", devpriv->BADR1); + printk("devpriv->BADR2 = 0x%lx\n", devpriv->BADR2); + printk("devpriv->BADR3 = 0x%lx\n", devpriv->BADR3); + printk("devpriv->BADR4 = 0x%lx\n", devpriv->BADR4); #endif - // Dont support IRQ yet -// // get irq -// if(comedi_request_irq(devpriv->pci_dev->irq, cb_pcimdas_interrupt, IRQF_SHARED, "cb_pcimdas", dev )) -// { -// printk(" unable to allocate irq %u\n", devpriv->pci_dev->irq); -// return -EINVAL; -// } -// dev->irq = devpriv->pci_dev->irq; +// // get irq +// if(comedi_request_irq(devpriv->pci_dev->irq, cb_pcimdas_interrupt, IRQF_SHARED, "cb_pcimdas", dev )) +// { +// printk(" unable to allocate irq %u\n", devpriv->pci_dev->irq); +// return -EINVAL; +// } +// dev->irq = devpriv->pci_dev->irq; //Initialize dev->board_name dev->board_name = thisboard->name; - /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 3)<0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; //dev->read_subdev=s; // analog input subdevice - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; - s->n_chan=thisboard->ai_se_chans; - s->maxdata=(1<ai_bits)-1; - s->range_table=&range_unknown; - s->len_chanlist=1; // This is the maximum chanlist length that - // the board can handle + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = thisboard->ai_se_chans; + s->maxdata = (1 << thisboard->ai_bits) - 1; + s->range_table = &range_unknown; + s->len_chanlist = 1; // This is the maximum chanlist length that + // the board can handle s->insn_read = cb_pcimdas_ai_rinsn; - s=dev->subdevices+1; + s = dev->subdevices + 1; // analog output subdevice - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=thisboard->ao_nchan; - s->maxdata=1<ao_bits; - s->range_table=&range_unknown; //ranges are hardware settable, but not software readable. + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->ao_nchan; + s->maxdata = 1 << thisboard->ao_bits; + s->range_table = &range_unknown; //ranges are hardware settable, but not software readable. s->insn_write = &cb_pcimdas_ao_winsn; s->insn_read = &cb_pcimdas_ao_rinsn; s = dev->subdevices + 2; /* digital i/o subdevice */ - if(thisboard->has_dio){ + if (thisboard->has_dio) { subdev_8255_init(dev, s, NULL, devpriv->BADR4); - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -336,7 +334,6 @@ found: return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -345,27 +342,23 @@ found: * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int cb_pcimdas_detach(comedi_device *dev) +static int cb_pcimdas_detach(comedi_device * dev) { #ifdef CBPCIMDAS_DEBUG - if(devpriv) - { - printk("devpriv->BADR0 = 0x%lx\n",devpriv->BADR0); - printk("devpriv->BADR1 = 0x%lx\n",devpriv->BADR1); - printk("devpriv->BADR2 = 0x%lx\n",devpriv->BADR2); - printk("devpriv->BADR3 = 0x%lx\n",devpriv->BADR3); - printk("devpriv->BADR4 = 0x%lx\n",devpriv->BADR4); + if (devpriv) { + printk("devpriv->BADR0 = 0x%lx\n", devpriv->BADR0); + printk("devpriv->BADR1 = 0x%lx\n", devpriv->BADR1); + printk("devpriv->BADR2 = 0x%lx\n", devpriv->BADR2); + printk("devpriv->BADR3 = 0x%lx\n", devpriv->BADR3); + printk("devpriv->BADR4 = 0x%lx\n", devpriv->BADR4); } #endif - printk("comedi%d: cb_pcimdas: remove\n",dev->minor); - if(dev->irq) + printk("comedi%d: cb_pcimdas: remove\n", dev->minor); + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(devpriv) - { - if(devpriv->pci_dev) - { - if(devpriv->BADR0) - { + if (devpriv) { + if (devpriv->pci_dev) { + if (devpriv->BADR0) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -379,9 +372,10 @@ static int cb_pcimdas_detach(comedi_device *dev) * "instructions" read/write data in "one-shot" or "software-triggered" * mode. */ -static int cb_pcimdas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int cb_pcimdas_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; unsigned int d; unsigned int busy; int chan = CR_CHAN(insn->chanspec); @@ -391,46 +385,47 @@ static int cb_pcimdas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_ins // only support sw initiated reads from a single channel //check channel number - if ((inb(devpriv->BADR3+2) & 0x20)==0) //differential mode - maxchans=thisboard->ai_diff_chans; + if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) //differential mode + maxchans = thisboard->ai_diff_chans; else - maxchans=thisboard->ai_se_chans; + maxchans = thisboard->ai_se_chans; - if (chan>(maxchans-1)) - return -ETIMEDOUT; //*** Wrong error code. Fixme. + if (chan > (maxchans - 1)) + return -ETIMEDOUT; //*** Wrong error code. Fixme. //configure for sw initiated read - d=inb(devpriv->BADR3+5); - if ((d & 0x03)>0) { //only reset if needed. - d=d & 0xfd; - outb(d,devpriv->BADR3+5); + d = inb(devpriv->BADR3 + 5); + if ((d & 0x03) > 0) { //only reset if needed. + d = d & 0xfd; + outb(d, devpriv->BADR3 + 5); } - outb(0x01,devpriv->BADR3+6); //set bursting off, conversions on - outb(0x00,devpriv->BADR3+7); //set range to 10V. UP/BP is controlled by a switch on the board + outb(0x01, devpriv->BADR3 + 6); //set bursting off, conversions on + outb(0x00, devpriv->BADR3 + 7); //set range to 10V. UP/BP is controlled by a switch on the board // write channel limits to multiplexer, set Low (bits 0-3) and High (bits 4-7) channels to chan. - chanlims=chan | (chan<<4); - outb(chanlims,devpriv->BADR3+0); + chanlims = chan | (chan << 4); + outb(chanlims, devpriv->BADR3 + 0); /* convert n samples */ - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* trigger conversion */ - outw(0,devpriv->BADR2+0); + outw(0, devpriv->BADR2 + 0); -#define TIMEOUT 1000 //typically takes 5 loops on a lightly loaded Pentium 100MHz, - //this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. +#define TIMEOUT 1000 //typically takes 5 loops on a lightly loaded Pentium 100MHz, + //this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. /* wait for conversion to end */ - for(i=0;iBADR3+2)&0x80; - if(!busy)break; + for (i = 0; i < TIMEOUT; i++) { + busy = inb(devpriv->BADR3 + 2) & 0x80; + if (!busy) + break; } - if(i==TIMEOUT){ + if (i == TIMEOUT) { printk("timeout\n"); return -ETIMEDOUT; } /* read data */ - d = inw(devpriv->BADR2+0); + d = inw(devpriv->BADR2 + 0); /* mangle the data as necessary */ //d ^= 1<<(thisboard->ai_bits-1); // 16 bit data from ADC, so no mangle needed. @@ -442,21 +437,21 @@ static int cb_pcimdas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_ins return n; } - -static int cb_pcimdas_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int cb_pcimdas_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ - switch ( chan ) { + for (i = 0; i < insn->n; i++) { + switch (chan) { case 0: - outw(data[i] & 0x0FFF,devpriv->BADR2+DAC0_OFFSET); + outw(data[i] & 0x0FFF, devpriv->BADR2 + DAC0_OFFSET); break; case 1: - outw(data[i] & 0x0FFF,devpriv->BADR2+DAC1_OFFSET); + outw(data[i] & 0x0FFF, devpriv->BADR2 + DAC1_OFFSET); break; default: return -1; @@ -470,22 +465,20 @@ static int cb_pcimdas_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_ins /* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */ -static int cb_pcimdas_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int cb_pcimdas_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; } - /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. */ COMEDI_INITCLEANUP(driver_cb_pcimdas); - - diff --git a/comedi/drivers/cb_pcimdda.c b/comedi/drivers/cb_pcimdda.c index 635a8bd2..96f6e4f1 100644 --- a/comedi/drivers/cb_pcimdda.c +++ b/comedi/drivers/cb_pcimdda.c @@ -57,7 +57,6 @@ output modes on the board: then issue one comedi_data_read() on any channel on the AO subdevice to initiate the simultaneous XFER. - Configuration Options: [0] PCI bus (optional) (unimplemented) [1] PCI slot (optional) (unimplemented) @@ -91,7 +90,6 @@ Configuration Options: #include "8255.h" - /* device ids of the cards we support -- currently only 1 card supported */ #define PCI_ID_PCIM_DDA06_16 0x0053 @@ -100,36 +98,36 @@ Configuration Options: * will someday support more than 1 board... */ typedef struct board_struct { - const char *name; - unsigned short device_id; - int ao_chans; - int ao_bits; + const char *name; + unsigned short device_id; + int ao_chans; + int ao_bits; int dio_chans; - int dio_method; - int dio_offset; /* how many bytes into the BADR are the DIO ports */ - int regs_badrindex; /* IO Region for the control, analog output, - and DIO registers */ - int reg_sz; /* number of bytes of registers in io region */ + int dio_method; + int dio_offset; /* how many bytes into the BADR are the DIO ports */ + int regs_badrindex; /* IO Region for the control, analog output, + and DIO registers */ + int reg_sz; /* number of bytes of registers in io region */ } board; enum DIO_METHODS { - DIO_NONE = 0, - DIO_8255, - DIO_INTERNAL /* unimplemented */ + DIO_NONE = 0, + DIO_8255, + DIO_INTERNAL /* unimplemented */ }; static const board boards[] = { - { - name: "cb_pcimdda06-16", - device_id: PCI_ID_PCIM_DDA06_16, - ao_chans: 6, - ao_bits: 16, - dio_chans: 24, - dio_method: DIO_8255, - dio_offset: 12, - regs_badrindex: 3, - reg_sz: 16, - } + { + name: "cb_pcimdda06-16", + device_id:PCI_ID_PCIM_DDA06_16, + ao_chans:6, + ao_bits: 16, + dio_chans:24, + dio_method:DIO_8255, + dio_offset:12, + regs_badrindex:3, + reg_sz: 16, + } }; /* @@ -147,26 +145,27 @@ static const board boards[] = { /* Please add your PCI vendor ID to comedidev.h, and it will be forwarded * upstream. */ static struct pci_device_id pci_table[] __devinitdata = { - { PCI_VENDOR_ID_COMPUTERBOARDS, PCI_ID_PCIM_DDA06_16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_COMPUTERBOARDS, PCI_ID_PCIM_DDA06_16, PCI_ANY_ID, + PCI_ANY_ID, 0, 0, 0}, + {0} }; -MODULE_DEVICE_TABLE(pci, pci_table); +MODULE_DEVICE_TABLE(pci, pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ typedef struct { - unsigned long registers; /* set by probe */ - unsigned long dio_registers; - char attached_to_8255; /* boolean */ - char attached_successfully; /* boolean */ - /* would be useful for a PCI device */ - struct pci_dev *pci_dev; + unsigned long registers; /* set by probe */ + unsigned long dio_registers; + char attached_to_8255; /* boolean */ + char attached_successfully; /* boolean */ + /* would be useful for a PCI device */ + struct pci_dev *pci_dev; #define MAX_AO_READBACK_CHANNELS 6 - /* Used for AO readback */ - lsampl_t ao_readback[MAX_AO_READBACK_CHANNELS]; + /* Used for AO readback */ + lsampl_t ao_readback[MAX_AO_READBACK_CHANNELS]; } private; @@ -182,27 +181,26 @@ typedef struct { * the board, and also about the kernel module that contains * the device code. */ -static int attach(comedi_device *dev,comedi_devconfig *it); -static int detach(comedi_device *dev); +static int attach(comedi_device * dev, comedi_devconfig * it); +static int detach(comedi_device * dev); static comedi_driver cb_pcimdda_driver = { - driver_name: "cb_pcimdda", - module: THIS_MODULE, - attach: attach, - detach: detach, + driver_name:"cb_pcimdda", + module:THIS_MODULE, + attach:attach, + detach:detach, }; + MODULE_AUTHOR("Calin A. Culianu "); MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA " - "series. Currently only supports PCIM-DDA06-16 (which " - "also happens to be the only board in this series. :) ) "); + "series. Currently only supports PCIM-DDA06-16 (which " + "also happens to be the only board in this series. :) ) "); MODULE_LICENSE("GPL"); COMEDI_INITCLEANUP_NOMODULE(cb_pcimdda_driver); - -static int ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /*--------------------------------------------------------------------------- HELPER FUNCTION DECLARATIONS @@ -211,7 +209,7 @@ static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, /* returns a maxdata value for a given n_bits */ static inline lsampl_t figure_out_maxdata(int bits) { - return (((lsampl_t)1 << bits) - 1); + return (((lsampl_t) 1 << bits) - 1); } /* @@ -228,8 +226,7 @@ static inline lsampl_t figure_out_maxdata(int bits) * * Otherwise, returns a -errno on error */ -static int probe(comedi_device *dev, const comedi_devconfig *it); - +static int probe(comedi_device * dev, const comedi_devconfig * it); /*--------------------------------------------------------------------------- FUNCTION DEFINITIONS @@ -241,7 +238,7 @@ static int probe(comedi_device *dev, const comedi_devconfig *it); * in the driver structure, dev->board_ptr contains that * address. */ -static int attach(comedi_device *dev,comedi_devconfig *it) +static int attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int err; @@ -252,7 +249,7 @@ static int attach(comedi_device *dev,comedi_devconfig *it) * if this function fails (returns negative) then the private area is * kfree'd by comedi */ - if (alloc_private(dev,sizeof(private))<0) + if (alloc_private(dev, sizeof(private)) < 0) return -ENOMEM; /* @@ -260,12 +257,11 @@ static int attach(comedi_device *dev,comedi_devconfig *it) * it is, this is the place to do it. Otherwise, dev->board_ptr * should already be initialized. */ - if ( (err = probe(dev, it)) ) return err; - + if ((err = probe(dev, it))) + return err; /* Output some info */ - printk("comedi%d: %s: ",dev->minor, thisboard->name); - + printk("comedi%d: %s: ", dev->minor, thisboard->name); /* * Initialize dev->board_name. Note that we can use the "thisboard" @@ -277,10 +273,10 @@ static int attach(comedi_device *dev,comedi_devconfig *it) * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - s = dev->subdevices+0; + s = dev->subdevices + 0; /* analog output subdevice */ s->type = COMEDI_SUBD_AO; @@ -288,40 +284,39 @@ static int attach(comedi_device *dev,comedi_devconfig *it) s->n_chan = thisboard->ao_chans; s->maxdata = figure_out_maxdata(thisboard->ao_bits); /* this is hard-coded here */ - if(it->options[2]){ + if (it->options[2]) { s->range_table = &range_bipolar10; - }else{ + } else { s->range_table = &range_bipolar5; } s->insn_write = &ao_winsn; s->insn_read = &ao_rinsn; - s = dev->subdevices+1; + s = dev->subdevices + 1; /* digital i/o subdevice */ - if(thisboard->dio_chans) { - switch(thisboard->dio_method) { - case DIO_8255: - /* this is a straight 8255, so register us with the 8255 driver */ - subdev_8255_init(dev, s, NULL, devpriv->dio_registers); - devpriv->attached_to_8255 = 1; - break; - case DIO_INTERNAL: - default: - printk("DIO_INTERNAL not implemented yet!\n"); - return -ENXIO; - break; - } - } else { - s->type = COMEDI_SUBD_UNUSED; - } - - devpriv->attached_successfully = 1; - - printk("attached\n"); - - return 1; -} + if (thisboard->dio_chans) { + switch (thisboard->dio_method) { + case DIO_8255: + /* this is a straight 8255, so register us with the 8255 driver */ + subdev_8255_init(dev, s, NULL, devpriv->dio_registers); + devpriv->attached_to_8255 = 1; + break; + case DIO_INTERNAL: + default: + printk("DIO_INTERNAL not implemented yet!\n"); + return -ENXIO; + break; + } + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + devpriv->attached_successfully = 1; + printk("attached\n"); + + return 1; +} /* * _detach is called to deconfigure a device. It should deallocate @@ -331,60 +326,58 @@ static int attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int detach(comedi_device *dev) +static int detach(comedi_device * dev) { if (devpriv) { if (dev->subdevices && devpriv->attached_to_8255) { /* de-register us from the 8255 driver */ - subdev_8255_cleanup(dev,dev->subdevices + 2); + subdev_8255_cleanup(dev, dev->subdevices + 2); devpriv->attached_to_8255 = 0; } if (devpriv->pci_dev) { - if(devpriv->registers) - { + if (devpriv->registers) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } if (devpriv->attached_successfully && thisboard) - printk("comedi%d: %s: detached\n", dev->minor, thisboard->name); + printk("comedi%d: %s: detached\n", dev->minor, + thisboard->name); } return 0; } - - -static int ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, - lsampl_t *data) +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); - unsigned long offset = devpriv->registers + chan*2; + int i; + int chan = CR_CHAN(insn->chanspec); + unsigned long offset = devpriv->registers + chan * 2; /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++) { - /* first, load the low byte */ - outb((char)(data[i] & 0x00ff), offset); - /* next, write the high byte -- only after this is written is - the channel voltage updated in the DAC, unless - we're in simultaneous xfer mode (jumper on card) - then a rinsn is necessary to actually update the DAC -- - see ao_rinsn() below... */ - outb((char)(data[i]>>8 & 0x00ff), offset + 1); - - /* for testing only.. the actual rinsn SHOULD do an inw! - (see the stuff about simultaneous XFER mode on this board) */ - devpriv->ao_readback[chan] = data[i]; - } - - /* return the number of samples read/written */ - return i; + for (i = 0; i < insn->n; i++) { + /* first, load the low byte */ + outb((char)(data[i] & 0x00ff), offset); + /* next, write the high byte -- only after this is written is + the channel voltage updated in the DAC, unless + we're in simultaneous xfer mode (jumper on card) + then a rinsn is necessary to actually update the DAC -- + see ao_rinsn() below... */ + outb((char)(data[i] >> 8 & 0x00ff), offset + 1); + + /* for testing only.. the actual rinsn SHOULD do an inw! + (see the stuff about simultaneous XFER mode on this board) */ + devpriv->ao_readback[chan] = data[i]; + } + + /* return the number of samples read/written */ + return i; } /* AO subdevices should have a read insn as well as a write insn. @@ -398,29 +391,26 @@ static int ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, all AO channels update simultaneously. This is useful for some control applications, I would imagine. */ -static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, - lsampl_t *data) +static int 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;in;i++) { - inw(devpriv->registers + chan*2); - /* should I set data[i] to the result of the actual read on the register - or the cached lsampl_t in devpriv->ao_readback[]? */ - data[i] = devpriv->ao_readback[chan]; - } + int i; + int chan = CR_CHAN(insn->chanspec); + + for (i = 0; i < insn->n; i++) { + inw(devpriv->registers + chan * 2); + /* should I set data[i] to the result of the actual read on the register + or the cached lsampl_t in devpriv->ao_readback[]? */ + data[i] = devpriv->ao_readback[chan]; + } - return i; + return i; } - /*--------------------------------------------------------------------------- HELPER FUNCTION DEFINITIONS -----------------------------------------------------------------------------*/ - /* * Probes for a supported device. * @@ -435,30 +425,28 @@ static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, * * Otherwise, returns a -errno on error */ -static int probe(comedi_device *dev, const comedi_devconfig *it) +static int probe(comedi_device * dev, const comedi_devconfig * it) { struct pci_dev *pcidev; int index; unsigned long registers; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; - pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) - { + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; + pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { // is it not a computer boards card? - if(pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) + if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) continue; // loop through cards supported by this driver - for(index = 0; index < N_BOARDS; index++) - { - if(boards[index].device_id != pcidev->device) + for (index = 0; index < N_BOARDS; index++) { + if (boards[index].device_id != pcidev->device) continue; // was a particular bus/slot requested? - if(it->options[0] || it->options[1]) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if(pcidev->bus->number != it->options[0] || - PCI_SLOT(pcidev->devfn) != it->options[1]) - { + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } @@ -466,24 +454,21 @@ static int probe(comedi_device *dev, const comedi_devconfig *it) devpriv->pci_dev = pcidev; dev->board_ptr = boards + index; - if (comedi_pci_enable(pcidev, thisboard->name)) - { + if (comedi_pci_enable(pcidev, thisboard->name)) { printk("cb_pcimdda: Failed to enable PCI device and request regions\n"); return -EIO; } - registers = pci_resource_start(devpriv->pci_dev, REGS_BADRINDEX); + registers = + pci_resource_start(devpriv->pci_dev, + REGS_BADRINDEX); devpriv->registers = registers; devpriv->dio_registers - = devpriv->registers + thisboard->dio_offset; + = devpriv->registers + thisboard->dio_offset; return 0; } } - printk("cb_pcimdda: No supported ComputerBoards/MeasurementComputing " - "card found at the requested position\n"); + printk("cb_pcimdda: No supported ComputerBoards/MeasurementComputing " + "card found at the requested position\n"); return -ENODEV; } - - - - diff --git a/comedi/drivers/comedi_bond.c b/comedi/drivers/comedi_bond.c index c439f5cb..d7bae245 100644 --- a/comedi/drivers/comedi_bond.c +++ b/comedi/drivers/comedi_bond.c @@ -95,7 +95,7 @@ Configuration Options: #define MODULE_NAME "comedi_bond" #ifdef MODULE_LICENSE - MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL"); #endif #ifndef STR # define STR1(x) #x @@ -104,30 +104,31 @@ Configuration Options: int debug = 0; module_param(debug, int, 0644); -MODULE_PARM_DESC(debug, "If true, print extra cryptic debugging output useful only to developers probably."); +MODULE_PARM_DESC(debug, + "If true, print extra cryptic debugging output useful only to developers probably."); #define LOG_MSG(x...) printk(KERN_INFO MODULE_NAME": "x) #define DEBUG(x...) do { if(debug) printk(KERN_DEBUG MODULE_NAME": DEBUG: "x); } while(0) #define WARNING(x...) printk(KERN_WARNING MODULE_NAME ": WARNING: "x) #define ERROR(x...) printk(KERN_ERR MODULE_NAME ": INTERNAL ERROR: "x) MODULE_AUTHOR("Calin A. Culianu"); -MODULE_DESCRIPTION(MODULE_NAME ": A driver for COMEDI to bond multiple COMEDI devices together as one. In the words of John Lennon: 'And the world will live as one...'"); +MODULE_DESCRIPTION(MODULE_NAME + ": A driver for COMEDI to bond multiple COMEDI devices together as one. In the words of John Lennon: 'And the world will live as one...'"); /* * Board descriptions for two imaginary boards. Describing the * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -struct BondingBoard -{ +struct BondingBoard { const char *name; }; typedef struct BondingBoard BondingBoard; static const BondingBoard bondingBoards[] = { - { - name: MODULE_NAME, - }, + { + name: MODULE_NAME, + }, }; /* @@ -135,33 +136,30 @@ static const BondingBoard bondingBoards[] = { */ #define thisboard ((const BondingBoard *)dev->board_ptr) -struct BondedDevice -{ - comedi_t *dev; - unsigned minor; - unsigned subdev; - unsigned subdev_type; - unsigned nchans; - unsigned chanid_offset; /* The offset into our unified linear channel-id's - of chanid 0 on this subdevice. */ +struct BondedDevice { + comedi_t *dev; + unsigned minor; + unsigned subdev; + unsigned subdev_type; + unsigned nchans; + unsigned chanid_offset; /* The offset into our unified linear channel-id's + of chanid 0 on this subdevice. */ }; typedef struct BondedDevice BondedDevice; /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -struct Private -{ +struct Private { # define MAX_BOARD_NAME 256 - char name[MAX_BOARD_NAME]; - struct BondedDevice **devs; - unsigned ndevs; - struct BondedDevice *chanIdDevMap[MAX_CHANS]; - unsigned nchans; + char name[MAX_BOARD_NAME]; + struct BondedDevice **devs; + unsigned ndevs; + struct BondedDevice *chanIdDevMap[MAX_CHANS]; + unsigned nchans; }; typedef struct Private Private; - /* * most drivers define the following macro to make it easy to * access the private structure. @@ -174,21 +172,21 @@ typedef struct Private Private; * the board, and also about the kernel module that contains * the device code. */ -static int bonding_attach(comedi_device *dev, comedi_devconfig *it); -static int bonding_detach(comedi_device *dev); +static int bonding_attach(comedi_device * dev, comedi_devconfig * it); +static int bonding_detach(comedi_device * dev); /** Build Private array of all devices.. */ -static int doDevConfig(comedi_device *dev, comedi_devconfig *it); -static void doDevUnconfig(comedi_device *dev); +static int doDevConfig(comedi_device * dev, comedi_devconfig * it); +static void doDevUnconfig(comedi_device * dev); /* Ugly implementation of realloc that always copies memory around -- I'm lazy, what can I say? I like to do wasteful memcopies.. :) */ static void *Realloc(const void *ptr, size_t len, size_t old_len); static comedi_driver driver_bonding = { - driver_name: MODULE_NAME, - module: THIS_MODULE, - attach: bonding_attach, - detach: bonding_detach, - /* It is not necessary to implement the following members if you are - * writing a driver for a ISA PnP or PCI card */ + driver_name:MODULE_NAME, + module:THIS_MODULE, + attach:bonding_attach, + detach:bonding_detach, + /* It is not necessary to implement the following members if you are + * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by * having an array of board structures. These were defined * in skel_boards[] above. Note that the element 'name' @@ -205,15 +203,15 @@ static comedi_driver driver_bonding = { * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &bondingBoards[0].name, - offset: sizeof(BondingBoard), - num_names: sizeof(bondingBoards) / sizeof(BondingBoard), + board_name:&bondingBoards[0].name, + offset:sizeof(BondingBoard), + num_names:sizeof(bondingBoards) / sizeof(BondingBoard), }; -static int bonding_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int bonding_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* * Attach is called by the Comedi core to configure the driver @@ -221,7 +219,7 @@ static int bonding_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * in the driver structure, dev->board_ptr contains that * address. */ -static int bonding_attach(comedi_device *dev, comedi_devconfig *it) +static int bonding_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; @@ -231,15 +229,14 @@ static int bonding_attach(comedi_device *dev, comedi_devconfig *it) * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if ( alloc_private(dev, sizeof(Private)) < 0 ) - return -ENOMEM; + if (alloc_private(dev, sizeof(Private)) < 0) + return -ENOMEM; /* * Setup our bonding from config params.. sets up our Private struct.. */ - if ( !doDevConfig(dev, it) ) - return -EINVAL; - + if (!doDevConfig(dev, it)) + return -EINVAL; /* * Initialize dev->board_name. Note that we can use the "thisboard" @@ -247,29 +244,27 @@ static int bonding_attach(comedi_device *dev, comedi_devconfig *it) */ dev->board_name = devpriv->name; - /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if ( alloc_subdevices(dev, 1) < 0 ) - return -ENOMEM; - - s = dev->subdevices+0; - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->n_chan = devpriv->nchans; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = bonding_dio_insn_bits; - s->insn_config = bonding_dio_insn_config; + if (alloc_subdevices(dev, 1) < 0) + return -ENOMEM; + + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = devpriv->nchans; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = bonding_dio_insn_bits; + s->insn_config = bonding_dio_insn_config; LOG_MSG("attached with %u DIO channels coming from %u different subdevices all bonded together. John Lennon would be proud!\n", devpriv->nchans, devpriv->ndevs); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -278,9 +273,9 @@ static int bonding_attach(comedi_device *dev, comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int bonding_detach(comedi_device *dev) +static int bonding_detach(comedi_device * dev) { - LOG_MSG("comedi%d: remove\n", dev->minor); + LOG_MSG("comedi%d: remove\n", dev->minor); doDevUnconfig(dev); return 0; } @@ -290,220 +285,237 @@ static int bonding_detach(comedi_device *dev) * 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 bonding_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int bonding_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { #define LSAMPL_BITS (sizeof(lsampl_t)*8) - unsigned nchans = LSAMPL_BITS, num_done = 0, i; - if(insn->n != 2) return -EINVAL; - - if (devpriv->nchans < nchans) nchans = devpriv->nchans; - - /* The insn data is a mask in data[0] and the new data - * in data[1], each channel cooresponding to a bit. */ - for (i = 0; num_done < nchans && i < devpriv->ndevs; ++i) { - BondedDevice *bdev = devpriv->devs[i]; - /* Grab the channel mask and data of only the bits corresponding - to this subdevice.. need to shift them to zero position of - course. */ - lsampl_t subdevMask = ((1<nchans)-1); /* Bits corresponding - to this subdev. */ - lsampl_t writeMask, dataBits; - - /* Argh, we have >= LSAMPL_BITS chans.. take all bits */ - if (bdev->nchans >= LSAMPL_BITS) subdevMask = (lsampl_t)(-1); - - writeMask = (data[0]>>num_done) & subdevMask; - dataBits = (data[1]>>num_done) & subdevMask; - - /* Read/Write the new digital lines */ - if ( comedi_dio_bitfield(bdev->dev, bdev->subdev, writeMask, &dataBits) != 2 ) - return -EINVAL; - - /* Make room for the new bits in data[1], the return value */ - data[1] &= ~(subdevMask << num_done); - /* Put the bits in the return value */ - data[1] |= (dataBits & subdevMask) << num_done; - /* Save the new bits to the saved state.. */ - s->state = data[1]; - - num_done += bdev->nchans; - } + unsigned nchans = LSAMPL_BITS, num_done = 0, i; + if (insn->n != 2) + return -EINVAL; + + if (devpriv->nchans < nchans) + nchans = devpriv->nchans; + + /* The insn data is a mask in data[0] and the new data + * in data[1], each channel cooresponding to a bit. */ + for (i = 0; num_done < nchans && i < devpriv->ndevs; ++i) { + BondedDevice *bdev = devpriv->devs[i]; + /* Grab the channel mask and data of only the bits corresponding + to this subdevice.. need to shift them to zero position of + course. */ + lsampl_t subdevMask = ((1 << bdev->nchans) - 1); /* Bits corresponding + to this subdev. */ + lsampl_t writeMask, dataBits; + + /* Argh, we have >= LSAMPL_BITS chans.. take all bits */ + if (bdev->nchans >= LSAMPL_BITS) + subdevMask = (lsampl_t) (-1); + + writeMask = (data[0] >> num_done) & subdevMask; + dataBits = (data[1] >> num_done) & subdevMask; + + /* Read/Write the new digital lines */ + if (comedi_dio_bitfield(bdev->dev, bdev->subdev, writeMask, + &dataBits) != 2) + return -EINVAL; + + /* Make room for the new bits in data[1], the return value */ + data[1] &= ~(subdevMask << num_done); + /* Put the bits in the return value */ + data[1] |= (dataBits & subdevMask) << num_done; + /* Save the new bits to the saved state.. */ + s->state = data[1]; + + num_done += bdev->nchans; + } return insn->n; } -static int bonding_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int bonding_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan = CR_CHAN(insn->chanspec), ret, io_bits = s->io_bits; - unsigned int io; - BondedDevice *bdev; + int chan = CR_CHAN(insn->chanspec), ret, io_bits = s->io_bits; + unsigned int io; + BondedDevice *bdev; - if (chan < 0 || chan >= devpriv->nchans) return -EINVAL; - bdev = devpriv->chanIdDevMap[chan]; + if (chan < 0 || chan >= devpriv->nchans) + return -EINVAL; + bdev = devpriv->chanIdDevMap[chan]; /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - io = COMEDI_OUTPUT; /* is this really necessary? */ - io_bits |= 1<n; break; default: return -EINVAL; break; } - chan -= bdev->chanid_offset; /* 'real' channel id for this subdev.. */ - ret = comedi_dio_config(bdev->dev, bdev->subdev, chan, io); - if (ret != 1) return -EINVAL; - /* Finally, save the new io_bits values since we didn't get - an error above. */ - s->io_bits = io_bits; + chan -= bdev->chanid_offset; /* 'real' channel id for this subdev.. */ + ret = comedi_dio_config(bdev->dev, bdev->subdev, chan, io); + if (ret != 1) + return -EINVAL; + /* Finally, save the new io_bits values since we didn't get + an error above. */ + s->io_bits = io_bits; return insn->n; } static void *Realloc(const void *oldmem, size_t newlen, size_t oldlen) { #define MIN(a,b) (a < b ? a : b) - void *newmem = kmalloc(newlen, GFP_KERNEL); - if (newmem && oldmem) memcpy(newmem, oldmem, MIN(oldlen, newlen)); - if (oldmem) kfree(oldmem); - return newmem; + void *newmem = kmalloc(newlen, GFP_KERNEL); + if (newmem && oldmem) + memcpy(newmem, oldmem, MIN(oldlen, newlen)); + if (oldmem) + kfree(oldmem); + return newmem; } -static int doDevConfig(comedi_device *dev, comedi_devconfig *it) +static int doDevConfig(comedi_device * dev, comedi_devconfig * it) { - int i; - comedi_t *devs_opened[COMEDI_NDEVICES]; - - memset(devs_opened, 0, sizeof(devs_opened)); - devpriv->name[0] = 0;; - /* Loop through all comedi devices specified on the command-line, - building our device list */ - for (i = 0; i < COMEDI_NDEVCONFOPTS && (!i || it->options[i]); ++i) { - char file[] = "/dev/comediXXXXXX"; - int minor = it->options[i]; - comedi_t *d; - int sdev = -1, nchans, tmp; - BondedDevice *bdev = 0; - - if (minor < 0 || minor > COMEDI_NDEVICES) { - ERROR("Minor %d is invalid!\n", minor); - return 0; - } - if (minor == dev->minor) { - ERROR("Cannot bond this driver to itself!\n"); - return 0; - } - if (devs_opened[minor]) { - ERROR("Minor %d specified more than once!\n", minor); - return 0; - } - - snprintf(file, sizeof(file), "/dev/comedi%u", minor); - file[sizeof(file)-1] = 0; - - d = devs_opened[minor] = comedi_open(file); - - if (!d) { - ERROR("Minor %u could not be opened\n", minor); - return 0; - } - - /* Do DIO, as that's all we support now.. */ - while ( (sdev = comedi_find_subdevice_by_type(d, COMEDI_SUBD_DIO, sdev+1)) > -1 ) { - if ( (nchans = comedi_get_n_channels(d, sdev)) <= 0) { - ERROR("comedi_get_n_channels() returned %d on minor %u subdev %d!\n", nchans, minor, sdev); - return 0; - } - bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); - if (!bdev) { - ERROR("Out of memory.\n"); - return 0; - } - bdev->dev = d; - bdev->minor = minor; - bdev->subdev = sdev; - bdev->subdev_type = COMEDI_SUBD_DIO; - bdev->nchans = nchans; - bdev->chanid_offset = devpriv->nchans; - - /* map channel id's to BondedDevice * pointer.. */ - while(nchans--) devpriv->chanIdDevMap[devpriv->nchans++] = bdev; - - /* Now put bdev pointer at end of devpriv->devs array list.. */ - - /* ergh.. ugly.. we need to realloc :( */ - tmp = devpriv->ndevs * sizeof(bdev); - devpriv->devs = Realloc(devpriv->devs, ++devpriv->ndevs * sizeof(bdev), tmp); - if (!devpriv->devs) { - ERROR("Could not allocate memory. Out of memory?"); - return 0; - } - - devpriv->devs[devpriv->ndevs-1] = bdev; - { /** Append dev:subdev to devpriv->name */ - char buf[20]; - int left = MAX_BOARD_NAME - strlen(devpriv->name) - 1; - snprintf(buf, sizeof(buf), "%d:%d ", dev->minor, bdev->subdev); - buf[sizeof(buf)-1] = 0; - strncat(devpriv->name, buf, left); - } - - } - } - - if (!devpriv->nchans) { - ERROR("No channels found!\n"); - return 0; - } - - return 1; + int i; + comedi_t *devs_opened[COMEDI_NDEVICES]; + + memset(devs_opened, 0, sizeof(devs_opened)); + devpriv->name[0] = 0;; + /* Loop through all comedi devices specified on the command-line, + building our device list */ + for (i = 0; i < COMEDI_NDEVCONFOPTS && (!i || it->options[i]); ++i) { + char file[] = "/dev/comediXXXXXX"; + int minor = it->options[i]; + comedi_t *d; + int sdev = -1, nchans, tmp; + BondedDevice *bdev = 0; + + if (minor < 0 || minor > COMEDI_NDEVICES) { + ERROR("Minor %d is invalid!\n", minor); + return 0; + } + if (minor == dev->minor) { + ERROR("Cannot bond this driver to itself!\n"); + return 0; + } + if (devs_opened[minor]) { + ERROR("Minor %d specified more than once!\n", minor); + return 0; + } + + snprintf(file, sizeof(file), "/dev/comedi%u", minor); + file[sizeof(file) - 1] = 0; + + d = devs_opened[minor] = comedi_open(file); + + if (!d) { + ERROR("Minor %u could not be opened\n", minor); + return 0; + } + + /* Do DIO, as that's all we support now.. */ + while ((sdev = comedi_find_subdevice_by_type(d, COMEDI_SUBD_DIO, + sdev + 1)) > -1) { + if ((nchans = comedi_get_n_channels(d, sdev)) <= 0) { + ERROR("comedi_get_n_channels() returned %d on minor %u subdev %d!\n", nchans, minor, sdev); + return 0; + } + bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); + if (!bdev) { + ERROR("Out of memory.\n"); + return 0; + } + bdev->dev = d; + bdev->minor = minor; + bdev->subdev = sdev; + bdev->subdev_type = COMEDI_SUBD_DIO; + bdev->nchans = nchans; + bdev->chanid_offset = devpriv->nchans; + + /* map channel id's to BondedDevice * pointer.. */ + while (nchans--) + devpriv->chanIdDevMap[devpriv->nchans++] = bdev; + + /* Now put bdev pointer at end of devpriv->devs array list.. */ + + /* ergh.. ugly.. we need to realloc :( */ + tmp = devpriv->ndevs * sizeof(bdev); + devpriv->devs = + Realloc(devpriv->devs, + ++devpriv->ndevs * sizeof(bdev), tmp); + if (!devpriv->devs) { + ERROR("Could not allocate memory. Out of memory?"); + return 0; + } + + devpriv->devs[devpriv->ndevs - 1] = bdev; + { + /** Append dev:subdev to devpriv->name */ + char buf[20]; + int left = + MAX_BOARD_NAME - strlen(devpriv->name) - + 1; + snprintf(buf, sizeof(buf), "%d:%d ", dev->minor, + bdev->subdev); + buf[sizeof(buf) - 1] = 0; + strncat(devpriv->name, buf, left); + } + + } + } + + if (!devpriv->nchans) { + ERROR("No channels found!\n"); + return 0; + } + + return 1; } -static void doDevUnconfig(comedi_device *dev) +static void doDevUnconfig(comedi_device * dev) { - unsigned long devs_closed = 0; - - if (devpriv) { - while(devpriv->ndevs-- && devpriv->devs) { - BondedDevice *bdev = devpriv->devs[devpriv->ndevs]; - if (!bdev) continue; - if (! (devs_closed & (0x1<minor)) ) { - comedi_close(bdev->dev); - devs_closed |= (0x1<minor); - } - kfree(bdev); - } - if (devpriv->devs) { - kfree(devpriv->devs); - devpriv->devs = 0; - } - kfree(devpriv); - dev->private = 0; - } + unsigned long devs_closed = 0; + + if (devpriv) { + while (devpriv->ndevs-- && devpriv->devs) { + BondedDevice *bdev = devpriv->devs[devpriv->ndevs]; + if (!bdev) + continue; + if (!(devs_closed & (0x1 << bdev->minor))) { + comedi_close(bdev->dev); + devs_closed |= (0x1 << bdev->minor); + } + kfree(bdev); + } + if (devpriv->devs) { + kfree(devpriv->devs); + devpriv->devs = 0; + } + kfree(devpriv); + dev->private = 0; + } } int __init init(void) { - return comedi_driver_register(&driver_bonding); + return comedi_driver_register(&driver_bonding); } void __exit cleanup(void) { - comedi_driver_unregister(&driver_bonding); + comedi_driver_unregister(&driver_bonding); } module_init(init); diff --git a/comedi/drivers/comedi_counter_unstable.h b/comedi/drivers/comedi_counter_unstable.h index a1e67fae..3ba5c6ce 100644 --- a/comedi/drivers/comedi_counter_unstable.h +++ b/comedi/drivers/comedi_counter_unstable.h @@ -91,14 +91,13 @@ static inline int comedi_counter_trigger_bits(unsigned int input_num, int flags) static const int bits_per_channel = 3; int bits = valid_bit; - if(flags & CR_EDGE) + if (flags & CR_EDGE) bits |= edge_bit; - if(flags & CR_INVERT) + if (flags & CR_INVERT) bits |= low_bit; return bits << (input_num * bits_per_channel); } -enum comedi_counter_actions -{ +enum comedi_counter_actions { COMEDI_INC_ACCUMULATOR, COMEDI_DEC_ACCUMULATOR, COMEDI_RESET_ACCUMULATOR, diff --git a/comedi/drivers/comedi_fc.c b/comedi/drivers/comedi_fc.c index e38b05d7..af5fa498 100644 --- a/comedi/drivers/comedi_fc.c +++ b/comedi/drivers/comedi_fc.c @@ -28,68 +28,70 @@ #include "comedi_fc.h" -static void increment_scan_progress( comedi_subdevice *subd, unsigned int num_bytes ) +static void increment_scan_progress(comedi_subdevice * subd, + unsigned int num_bytes) { comedi_async *async = subd->async; unsigned int scan_length = cfc_bytes_per_scan(subd); async->scan_progress += num_bytes; - if( async->scan_progress >= scan_length ) - { + if (async->scan_progress >= scan_length) { async->scan_progress %= scan_length; async->events |= COMEDI_CB_EOS; } } /* Writes an array of data points to comedi's buffer */ -unsigned int cfc_write_array_to_buffer( comedi_subdevice *subd, void *data, - unsigned int num_bytes ) +unsigned int cfc_write_array_to_buffer(comedi_subdevice * subd, void *data, + unsigned int num_bytes) { comedi_async *async = subd->async; unsigned int retval; - if( num_bytes == 0 ) return 0; + if (num_bytes == 0) + return 0; - retval = comedi_buf_write_alloc( async, num_bytes ); - if( retval != num_bytes ) - { - rt_printk( "comedi: buffer overrun\n" ); + retval = comedi_buf_write_alloc(async, num_bytes); + if (retval != num_bytes) { + rt_printk("comedi: buffer overrun\n"); async->events |= COMEDI_CB_OVERFLOW; return 0; } - comedi_buf_memcpy_to( async, 0, data, num_bytes); - comedi_buf_write_free( async, num_bytes ); - increment_scan_progress( subd, num_bytes ); + comedi_buf_memcpy_to(async, 0, data, num_bytes); + comedi_buf_write_free(async, num_bytes); + increment_scan_progress(subd, num_bytes); async->events |= COMEDI_CB_BLOCK; return num_bytes; } -unsigned int cfc_read_array_from_buffer( comedi_subdevice *subd, void *data, - unsigned int num_bytes ) +unsigned int cfc_read_array_from_buffer(comedi_subdevice * subd, void *data, + unsigned int num_bytes) { comedi_async *async = subd->async; - if( num_bytes == 0 ) return 0; + if (num_bytes == 0) + return 0; num_bytes = comedi_buf_read_alloc(async, num_bytes); - comedi_buf_memcpy_from( async, 0, data, num_bytes); - comedi_buf_read_free( async, num_bytes ); - increment_scan_progress( subd, num_bytes ); + comedi_buf_memcpy_from(async, 0, data, num_bytes); + comedi_buf_read_free(async, num_bytes); + increment_scan_progress(subd, num_bytes); async->events |= COMEDI_CB_BLOCK; return num_bytes; } -unsigned int cfc_handle_events( comedi_device *dev, comedi_subdevice *subd ) +unsigned int cfc_handle_events(comedi_device * dev, comedi_subdevice * subd) { unsigned int events = subd->async->events; - if( events == 0 ) return events; + if (events == 0) + return events; - if( events & ( COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW ) ) - subd->cancel( dev, subd ); + if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) + subd->cancel(dev, subd); comedi_event(dev, subd); @@ -107,9 +109,10 @@ static int __init comedi_fc_init_module(void) static void __exit comedi_fc_cleanup_module(void) { } + module_init(comedi_fc_init_module); module_exit(comedi_fc_cleanup_module); -EXPORT_SYMBOL( cfc_write_array_to_buffer ); -EXPORT_SYMBOL( cfc_read_array_from_buffer ); -EXPORT_SYMBOL( cfc_handle_events ); +EXPORT_SYMBOL(cfc_write_array_to_buffer); +EXPORT_SYMBOL(cfc_read_array_from_buffer); +EXPORT_SYMBOL(cfc_handle_events); diff --git a/comedi/drivers/comedi_fc.h b/comedi/drivers/comedi_fc.h index 5763a9fa..299f4011 100644 --- a/comedi/drivers/comedi_fc.h +++ b/comedi/drivers/comedi_fc.h @@ -5,8 +5,6 @@ two or more drivers. These functions are meant to be used only by drivers, they are NOT part of the kcomedilib API! - - Author: Frank Mori Hess Copyright (C) 2002 Frank Mori Hess @@ -32,42 +30,46 @@ #include /* Writes an array of data points to comedi's buffer */ -extern unsigned int cfc_write_array_to_buffer( comedi_subdevice *subd, void *data, - unsigned int num_bytes ); +extern unsigned int cfc_write_array_to_buffer(comedi_subdevice * subd, + void *data, unsigned int num_bytes); -static inline unsigned int cfc_write_to_buffer( comedi_subdevice *subd, sampl_t data ) +static inline unsigned int cfc_write_to_buffer(comedi_subdevice * subd, + sampl_t data) { - return cfc_write_array_to_buffer( subd, &data, sizeof( data ) ); + return cfc_write_array_to_buffer(subd, &data, sizeof(data)); }; -static inline unsigned int cfc_write_long_to_buffer( comedi_subdevice *subd, lsampl_t data ) +static inline unsigned int cfc_write_long_to_buffer(comedi_subdevice * subd, + lsampl_t data) { - return cfc_write_array_to_buffer( subd, &data, sizeof( data ) ); + return cfc_write_array_to_buffer(subd, &data, sizeof(data)); }; -extern unsigned int cfc_read_array_from_buffer( comedi_subdevice *subd, void *data, - unsigned int num_bytes ); +extern unsigned int cfc_read_array_from_buffer(comedi_subdevice * subd, + void *data, unsigned int num_bytes); -extern unsigned int cfc_handle_events( comedi_device *dev, comedi_subdevice *subd ); +extern unsigned int cfc_handle_events(comedi_device * dev, + comedi_subdevice * subd); -inline unsigned int cfc_bytes_per_scan(comedi_subdevice *subd) +inline unsigned int cfc_bytes_per_scan(comedi_subdevice * subd) { int num_samples; int bits_per_sample; - switch(subd->type) - { - case COMEDI_SUBD_DI: - case COMEDI_SUBD_DO: - case COMEDI_SUBD_DIO: - bits_per_sample = 8 * bytes_per_sample(subd); - num_samples = (subd->async->cmd.chanlist_len + bits_per_sample - 1) / bits_per_sample; - break; - default: - num_samples = subd->async->cmd.chanlist_len; - break; + switch (subd->type) { + case COMEDI_SUBD_DI: + case COMEDI_SUBD_DO: + case COMEDI_SUBD_DIO: + bits_per_sample = 8 * bytes_per_sample(subd); + num_samples = + (subd->async->cmd.chanlist_len + bits_per_sample - + 1) / bits_per_sample; + break; + default: + num_samples = subd->async->cmd.chanlist_len; + break; } return num_samples * bytes_per_sample(subd); } -#endif /* _COMEDI_FC_H */ +#endif /* _COMEDI_FC_H */ diff --git a/comedi/drivers/comedi_parport.c b/comedi/drivers/comedi_parport.c index c2fcda26..7acbfcf8 100644 --- a/comedi/drivers/comedi_parport.c +++ b/comedi/drivers/comedi_parport.c @@ -84,39 +84,38 @@ pin, which can be used to wake up tasks. #include #include - #define PARPORT_SIZE 3 #define PARPORT_A 0 #define PARPORT_B 1 #define PARPORT_C 2 -static int parport_attach(comedi_device *dev,comedi_devconfig *it); -static int parport_detach(comedi_device *dev); -static comedi_driver driver_parport={ - driver_name: "comedi_parport", - module: THIS_MODULE, - attach: parport_attach, - detach: parport_detach, +static int parport_attach(comedi_device * dev, comedi_devconfig * it); +static int parport_detach(comedi_device * dev); +static comedi_driver driver_parport = { + driver_name:"comedi_parport", + module:THIS_MODULE, + attach:parport_attach, + detach:parport_detach, }; -COMEDI_INITCLEANUP(driver_parport); +COMEDI_INITCLEANUP(driver_parport); -typedef struct parport_private_struct{ +typedef struct parport_private_struct { unsigned int a_data; unsigned int c_data; int enable_irq; -}parport_private; +} parport_private; #define devpriv ((parport_private *)(dev->private)) -static int parport_insn_a(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int parport_insn_a(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { devpriv->a_data &= ~data[0]; - devpriv->a_data |= (data[0]&data[1]); + devpriv->a_data |= (data[0] & data[1]); - outb(devpriv->a_data,dev->iobase+PARPORT_A); + outb(devpriv->a_data, dev->iobase + PARPORT_A); } data[1] = inb(dev->iobase + PARPORT_A); @@ -124,42 +123,42 @@ static int parport_insn_a(comedi_device *dev,comedi_subdevice *s, return 2; } -static int parport_insn_config_a(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int parport_insn_config_a(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { s->io_bits = 0xff; - devpriv->c_data &= ~(1<<5); - }else{ + devpriv->c_data &= ~(1 << 5); + } else { s->io_bits = 0; - devpriv->c_data |= (1<<5); + devpriv->c_data |= (1 << 5); } - outb(devpriv->c_data,dev->iobase+PARPORT_C); + outb(devpriv->c_data, dev->iobase + PARPORT_C); return 1; } -static int parport_insn_b(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int parport_insn_b(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { // should writes be ignored? } - data[1] = (inb(dev->iobase+PARPORT_B)>>3); + data[1] = (inb(dev->iobase + PARPORT_B) >> 3); return 2; } -static int parport_insn_c(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int parport_insn_c(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] &= 0x0f; - if(data[0]){ + if (data[0]) { devpriv->c_data &= ~data[0]; - devpriv->c_data |= (data[0]&data[1]); + devpriv->c_data |= (data[0] & data[1]); - outb(devpriv->c_data,dev->iobase+PARPORT_C); + outb(devpriv->c_data, dev->iobase + PARPORT_C); } data[1] = devpriv->c_data & 0xf; @@ -167,212 +166,222 @@ static int parport_insn_c(comedi_device *dev,comedi_subdevice *s, return 2; } -static int parport_intr_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int parport_intr_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n<1)return -EINVAL; + if (insn->n < 1) + return -EINVAL; data[1] = 0; return 2; } -static int parport_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int parport_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1 */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_FOLLOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: ignored */ - if(err)return 2; + if (err) + return 2; /* step 3: */ - if(cmd->start_arg!=0){ + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=1){ + if (cmd->scan_end_arg != 1) { cmd->scan_end_arg = 1; err++; } - if(cmd->stop_arg!=0){ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } - if(err)return 3; + if (err) + return 3; /* step 4: ignored */ - if(err)return 4; + if (err) + return 4; return 0; } -static int parport_intr_cmd(comedi_device *dev,comedi_subdevice *s) +static int parport_intr_cmd(comedi_device * dev, comedi_subdevice * s) { devpriv->c_data |= 0x10; - outb(devpriv->c_data,dev->iobase+PARPORT_C); + outb(devpriv->c_data, dev->iobase + PARPORT_C); devpriv->enable_irq = 1; return 0; } -static int parport_intr_cancel(comedi_device *dev,comedi_subdevice *s) +static int parport_intr_cancel(comedi_device * dev, comedi_subdevice * s) { printk("parport_intr_cancel()\n"); devpriv->c_data &= ~0x10; - outb(devpriv->c_data,dev->iobase+PARPORT_C); + outb(devpriv->c_data, dev->iobase + PARPORT_C); devpriv->enable_irq = 0; return 0; } -static irqreturn_t parport_interrupt(int irq,void *d PT_REGS_ARG) +static irqreturn_t parport_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; - comedi_subdevice *s=dev->subdevices+3; + comedi_device *dev = d; + comedi_subdevice *s = dev->subdevices + 3; - if(!devpriv->enable_irq){ + if (!devpriv->enable_irq) { printk("comedi_parport: bogus irq, ignored\n"); return IRQ_NONE; } - comedi_buf_put( s->async, 0 ); + comedi_buf_put(s->async, 0); s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; comedi_event(dev, s); return IRQ_HANDLED; } -static int parport_attach(comedi_device *dev,comedi_devconfig *it) +static int parport_attach(comedi_device * dev, comedi_devconfig * it) { int ret; unsigned int irq; unsigned long iobase; comedi_subdevice *s; - iobase=it->options[0]; - printk("comedi%d: parport: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,PARPORT_SIZE,"parport (comedi)")){ + iobase = it->options[0]; + printk("comedi%d: parport: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, PARPORT_SIZE, "parport (comedi)")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; - - irq=it->options[1]; - if(irq){ - printk(" irq=%u",irq); - ret = comedi_request_irq(irq,parport_interrupt,0, - "comedi_parport",dev); - if(ret<0){ + dev->iobase = iobase; + + irq = it->options[1]; + if (irq) { + printk(" irq=%u", irq); + ret = comedi_request_irq(irq, parport_interrupt, 0, + "comedi_parport", dev); + if (ret < 0) { printk(" irq not available\n"); return -EINVAL; } - dev->irq=irq; + dev->irq = irq; } - dev->board_name="parport"; + dev->board_name = "parport"; - if((ret=alloc_subdevices(dev, 4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(parport_private)))<0) + if ((ret = alloc_private(dev, sizeof(parport_private))) < 0) return ret; - s=dev->subdevices+0; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = parport_insn_a; s->insn_config = parport_insn_config_a; - s=dev->subdevices+1; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->n_chan=5; - s->maxdata=1; - s->range_table=&range_digital; + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 5; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = parport_insn_b; - s=dev->subdevices+2; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=4; - s->maxdata=1; - s->range_table=&range_digital; + s = dev->subdevices + 2; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 4; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = parport_insn_c; - s=dev->subdevices+3; - if(irq){ - dev->read_subdev=s; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE | SDF_CMD_READ; - s->n_chan=1; - s->maxdata=1; - s->range_table=&range_digital; + s = dev->subdevices + 3; + if (irq) { + dev->read_subdev = s; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_CMD_READ; + s->n_chan = 1; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = parport_intr_insn; s->do_cmdtest = parport_intr_cmdtest; s->do_cmd = parport_intr_cmd; s->cancel = parport_intr_cancel; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } devpriv->a_data = 0; - outb(devpriv->a_data,dev->iobase+PARPORT_A); + outb(devpriv->a_data, dev->iobase + PARPORT_A); devpriv->c_data = 0; - outb(devpriv->c_data,dev->iobase+PARPORT_C); + outb(devpriv->c_data, dev->iobase + PARPORT_C); printk("\n"); return 1; } - -static int parport_detach(comedi_device *dev) +static int parport_detach(comedi_device * dev) { - printk("comedi%d: parport: remove\n",dev->minor); + printk("comedi%d: parport: remove\n", dev->minor); - if(dev->iobase)release_region(dev->iobase,PARPORT_SIZE); + if (dev->iobase) + release_region(dev->iobase, PARPORT_SIZE); - if(dev->irq)comedi_free_irq(dev->irq,dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); return 0; } - diff --git a/comedi/drivers/comedi_rt_timer.c b/comedi/drivers/comedi_rt_timer.c index cbd7f205..71e95089 100644 --- a/comedi/drivers/comedi_rt_timer.c +++ b/comedi/drivers/comedi_rt_timer.c @@ -21,7 +21,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - ************************************************************************** */ /* @@ -52,7 +51,6 @@ TODO: What happens if device we are emulating for is de-configured? */ - #include #include @@ -68,7 +66,6 @@ TODO: #include #include - #ifndef RTLINUX_VERSION_CODE #define RTLINUX_VERSION_CODE 0 #endif @@ -84,6 +81,7 @@ static inline RTIME nano2count(long long ns) do_div(ns, 838); return ns; } + #ifdef rt_get_time() #undef rt_get_time() #endif @@ -121,35 +119,36 @@ static inline RTIME nano2count(long long ns) #endif - /* This defines the fastest speed we will emulate. Note that * without a watchdog (like in RTAI), we could easily overrun our * task period because analog input tends to be slow. */ #define SPEED_LIMIT 100000 /* in nanoseconds */ -static int timer_attach(comedi_device *dev,comedi_devconfig *it); -static int timer_detach(comedi_device *dev); -static int timer_inttrig(comedi_device *dev, comedi_subdevice *s, unsigned int trig_num); -static int timer_start_cmd(comedi_device *dev, comedi_subdevice *s); - -static comedi_driver driver_timer={ - module: THIS_MODULE, - driver_name: "comedi_rt_timer", - attach: timer_attach, - detach: timer_detach, -// open: timer_open, +static int timer_attach(comedi_device * dev, comedi_devconfig * it); +static int timer_detach(comedi_device * dev); +static int timer_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trig_num); +static int timer_start_cmd(comedi_device * dev, comedi_subdevice * s); + +static comedi_driver driver_timer = { + module:THIS_MODULE, + driver_name:"comedi_rt_timer", + attach:timer_attach, + detach:timer_detach, +// open: timer_open, }; -COMEDI_INITCLEANUP(driver_timer); +COMEDI_INITCLEANUP(driver_timer); -typedef struct{ +typedef struct { comedi_t *device; // device we are emulating commands for int subd; // subdevice we are emulating commands for RT_TASK *rt_task; // rt task that starts scans RT_TASK *scan_task; // rt task that controls conversion timing in a scan /* io_function can point to either an input or output function * depending on what kind of subdevice we are emulating for */ - int (*io_function)(comedi_device *dev, comedi_cmd *cmd, unsigned int index); + int (*io_function) (comedi_device * dev, comedi_cmd * cmd, + unsigned int index); // RTIME has units of 1 = 838 nanoseconds // time at which first scan started, used to check scan timing RTIME start; @@ -161,11 +160,11 @@ typedef struct{ volatile int stop; // indicates we should stop volatile int rt_task_active; // indicates rt_task is servicing a comedi_cmd volatile int scan_task_active; // indicates scan_task is servicing a comedi_cmd - unsigned timer_running : 1; -}timer_private; + unsigned timer_running:1; +} timer_private; #define devpriv ((timer_private *)dev->private) -static int timer_cancel(comedi_device *dev,comedi_subdevice *s) +static int timer_cancel(comedi_device * dev, comedi_subdevice * s) { devpriv->stop = 1; @@ -173,14 +172,14 @@ static int timer_cancel(comedi_device *dev,comedi_subdevice *s) } // checks for scan timing error -inline static int check_scan_timing(comedi_device *dev, +inline static int check_scan_timing(comedi_device * dev, unsigned long long scan) { RTIME now, timing_error; now = rt_get_time(); timing_error = now - (devpriv->start + scan * devpriv->scan_period); - if(timing_error > devpriv->scan_period){ + if (timing_error > devpriv->scan_period) { comedi_error(dev, "timing error"); rt_printk("scan started %i ns late\n", timing_error * 838); return -1; @@ -190,16 +189,18 @@ inline static int check_scan_timing(comedi_device *dev, } // checks for conversion timing error -inline static int check_conversion_timing(comedi_device *dev, +inline static int check_conversion_timing(comedi_device * dev, RTIME scan_start, unsigned int conversion) { RTIME now, timing_error; now = rt_get_time(); - timing_error = now - (scan_start + conversion * devpriv->convert_period); - if(timing_error > devpriv->convert_period){ + timing_error = + now - (scan_start + conversion * devpriv->convert_period); + if (timing_error > devpriv->convert_period) { comedi_error(dev, "timing error"); - rt_printk("conversion started %i ns late\n", timing_error * 838); + rt_printk("conversion started %i ns late\n", + timing_error * 838); return -1; } @@ -207,7 +208,7 @@ inline static int check_conversion_timing(comedi_device *dev, } // devpriv->io_function for an input subdevice -static int timer_data_read(comedi_device *dev, comedi_cmd *cmd, +static int timer_data_read(comedi_device * dev, comedi_cmd * cmd, unsigned int index) { comedi_subdevice *s = dev->read_subdev; @@ -217,23 +218,22 @@ static int timer_data_read(comedi_device *dev, comedi_cmd *cmd, ret = comedi_data_read(devpriv->device, devpriv->subd, CR_CHAN(cmd->chanlist[index]), CR_RANGE(cmd->chanlist[index]), - CR_AREF(cmd->chanlist[index]), - &data); - if(ret<0){ + CR_AREF(cmd->chanlist[index]), &data); + if (ret < 0) { comedi_error(dev, "read error"); return -EIO; } - if( s->flags & SDF_LSAMPL ){ - cfc_write_long_to_buffer( s, data ); - }else{ - comedi_buf_put( s->async, data ); + if (s->flags & SDF_LSAMPL) { + cfc_write_long_to_buffer(s, data); + } else { + comedi_buf_put(s->async, data); } return 0; } // devpriv->io_function for an output subdevice -static int timer_data_write(comedi_device *dev, comedi_cmd *cmd, +static int timer_data_write(comedi_device * dev, comedi_cmd * cmd, unsigned int index) { comedi_subdevice *s = dev->write_subdev; @@ -242,24 +242,24 @@ static int timer_data_write(comedi_device *dev, comedi_cmd *cmd, lsampl_t long_data; int ret; - if( s->flags & SDF_LSAMPL ) { - num_bytes = cfc_read_array_from_buffer( s, &long_data, sizeof( long_data ) ); - }else{ - num_bytes = cfc_read_array_from_buffer( s, &data, sizeof( data ) ); + if (s->flags & SDF_LSAMPL) { + num_bytes = + cfc_read_array_from_buffer(s, &long_data, + sizeof(long_data)); + } else { + num_bytes = cfc_read_array_from_buffer(s, &data, sizeof(data)); long_data = data; } - if(num_bytes == 0) - { + if (num_bytes == 0) { comedi_error(dev, "buffer underrun"); return -EAGAIN; } ret = comedi_data_write(devpriv->device, devpriv->subd, CR_CHAN(cmd->chanlist[index]), CR_RANGE(cmd->chanlist[index]), - CR_AREF(cmd->chanlist[index]), - long_data); - if(ret<0){ + CR_AREF(cmd->chanlist[index]), long_data); + if (ret < 0) { comedi_error(dev, "write error"); return -EIO; } @@ -268,7 +268,7 @@ static int timer_data_write(comedi_device *dev, comedi_cmd *cmd, } // devpriv->io_function for DIO subdevices -static int timer_dio_read(comedi_device *dev, comedi_cmd *cmd, +static int timer_dio_read(comedi_device * dev, comedi_cmd * cmd, unsigned int index) { comedi_subdevice *s = dev->read_subdev; @@ -276,15 +276,15 @@ static int timer_dio_read(comedi_device *dev, comedi_cmd *cmd, lsampl_t data; ret = comedi_dio_bitfield(devpriv->device, devpriv->subd, 0, &data); - if(ret<0){ + if (ret < 0) { comedi_error(dev, "read error"); return -EIO; } - if( s->flags & SDF_LSAMPL ) - cfc_write_long_to_buffer( s, data ); + if (s->flags & SDF_LSAMPL) + cfc_write_long_to_buffer(s, data); else - cfc_write_to_buffer( s, data ); + cfc_write_to_buffer(s, data); return 0; } @@ -292,7 +292,7 @@ static int timer_dio_read(comedi_device *dev, comedi_cmd *cmd, // performs scans static void scan_task_func(comedi_rt_task_context_t d) { - comedi_device *dev=(comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + 0; comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -301,52 +301,56 @@ static void scan_task_func(comedi_rt_task_context_t d) RTIME scan_start; // every comedi_cmd causes one execution of while loop - while(1){ + while (1) { devpriv->scan_task_active = 1; // each for loop completes one scan - for(n = 0; n < cmd->stop_arg || cmd->stop_src == TRIG_NONE; n++){ - if(n){ + for (n = 0; n < cmd->stop_arg || cmd->stop_src == TRIG_NONE; + n++) { + if (n) { // suspend task until next scan ret = rt_task_suspend(devpriv->scan_task); - if(ret < 0){ - comedi_error(dev, "error suspending scan task"); + if (ret < 0) { + comedi_error(dev, + "error suspending scan task"); async->events |= COMEDI_CB_ERROR; goto cleanup; } } // check if stop flag was set (by timer_cancel()) - if(devpriv->stop) + if (devpriv->stop) goto cleanup; ret = check_scan_timing(dev, n); - if(ret < 0){ + if (ret < 0) { async->events |= COMEDI_CB_ERROR; goto cleanup; } scan_start = rt_get_time(); - for(i = 0; i < cmd->scan_end_arg; i++){ + for (i = 0; i < cmd->scan_end_arg; i++) { // conversion timing - if(cmd->convert_src == TRIG_TIMER && i){ + if (cmd->convert_src == TRIG_TIMER && i) { rt_task_wait_period(); - ret = check_conversion_timing(dev, scan_start, i); - if(ret < 0){ - async->events |= COMEDI_CB_ERROR; + ret = check_conversion_timing(dev, + scan_start, i); + if (ret < 0) { + async->events |= + COMEDI_CB_ERROR; goto cleanup; } } ret = devpriv->io_function(dev, cmd, i); - if(ret < 0){ + if (ret < 0) { async->events |= COMEDI_CB_ERROR; goto cleanup; } } s->async->events |= COMEDI_CB_BLOCK; - comedi_event(dev,s); + comedi_event(dev, s); s->async->events = 0; } -cleanup: + cleanup: - comedi_unlock(devpriv->device,devpriv->subd); + comedi_unlock(devpriv->device, devpriv->subd); async->events |= COMEDI_CB_EOA; comedi_event(dev, s); async->events = 0; @@ -358,34 +362,35 @@ cleanup: static void timer_task_func(comedi_rt_task_context_t d) { - comedi_device *dev=(comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + 0; - comedi_cmd *cmd=&s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; int ret; unsigned long long n; // every comedi_cmd causes one execution of while loop - while(1){ + while (1) { devpriv->rt_task_active = 1; devpriv->scan_task_active = 1; devpriv->start = rt_get_time(); - for(n = 0; n < cmd->stop_arg || cmd->stop_src == TRIG_NONE; n++){ + for (n = 0; n < cmd->stop_arg || cmd->stop_src == TRIG_NONE; + n++) { // scan timing - if(n) + if (n) rt_task_wait_period(); - if(devpriv->scan_task_active == 0){ + if (devpriv->scan_task_active == 0) { goto cleanup; } ret = rt_task_make_periodic(devpriv->scan_task, devpriv->start + devpriv->scan_period * n, devpriv->convert_period); - if(ret < 0){ + if (ret < 0) { comedi_error(dev, "bug!"); } } -cleanup: + cleanup: devpriv->rt_task_active = 0; // suspend until next comedi_cmd @@ -393,120 +398,127 @@ cleanup: } } -static int timer_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int timer_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { comedi_insn xinsn = *insn; xinsn.data = data; xinsn.subdev = devpriv->subd; - return comedi_do_insn(devpriv->device,&xinsn); + return comedi_do_insn(devpriv->device, &xinsn); } -static int cmdtest_helper(comedi_cmd *cmd, +static int cmdtest_helper(comedi_cmd * cmd, unsigned int start_src, unsigned int scan_begin_src, unsigned int convert_src, - unsigned int scan_end_src, - unsigned int stop_src) + unsigned int scan_end_src, unsigned int stop_src) { int err = 0; int tmp; tmp = cmd->start_src; cmd->start_src &= start_src; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= scan_begin_src; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= convert_src; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= scan_end_src; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= stop_src; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; return err; } -static int timer_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int timer_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; unsigned int start_src = 0; - if(s->type == COMEDI_SUBD_AO) + if (s->type == COMEDI_SUBD_AO) start_src = TRIG_INT; else start_src = TRIG_NOW; - err = cmdtest_helper(cmd, - start_src, /* start_src */ + err = cmdtest_helper(cmd, start_src, /* start_src */ TRIG_TIMER | TRIG_FOLLOW, /* scan_begin_src */ TRIG_NOW | TRIG_TIMER, /* convert_src */ TRIG_COUNT, /* scan_end_src */ TRIG_COUNT | TRIG_NONE); /* stop_src */ - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually * compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_INT) + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_INT) err++; - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_FOLLOW) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_NOW) + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_NOW) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) err++; - if(cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src != TRIG_TIMER) + if (cmd->scan_begin_src == TRIG_FOLLOW + && cmd->convert_src != TRIG_TIMER) err++; - if(cmd->convert_src == TRIG_NOW && cmd->scan_begin_src != TRIG_TIMER) + if (cmd->convert_src == TRIG_NOW && cmd->scan_begin_src != TRIG_TIMER) err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ // limit frequency, this is fairly arbitrary - if(cmd->scan_begin_src == TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=SPEED_LIMIT; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < SPEED_LIMIT) { + cmd->scan_begin_arg = SPEED_LIMIT; err++; } } - if(cmd->convert_src == TRIG_TIMER){ - if(cmd->convert_argconvert_arg=SPEED_LIMIT; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < SPEED_LIMIT) { + cmd->convert_arg = SPEED_LIMIT; err++; } } // make sure conversion and scan frequencies are compatible - if(cmd->convert_src == TRIG_TIMER && cmd->scan_begin_src == TRIG_TIMER){ - if(cmd->convert_arg * cmd->scan_end_arg > cmd->scan_begin_arg){ - cmd->scan_begin_arg = cmd->convert_arg * cmd->scan_end_arg; + if (cmd->convert_src == TRIG_TIMER && cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->convert_arg * cmd->scan_end_arg > cmd->scan_begin_arg) { + cmd->scan_begin_arg = + cmd->convert_arg * cmd->scan_end_arg; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up and arguments */ - if(err)return 4; + if (err) + return 4; return 0; } -static int timer_cmd(comedi_device *dev,comedi_subdevice *s) +static int timer_cmd(comedi_device * dev, comedi_subdevice * s) { int ret; comedi_cmd *cmd = &s->async->cmd; @@ -515,41 +527,41 @@ static int timer_cmd(comedi_device *dev,comedi_subdevice *s) dev->rt = 1; // make sure tasks have finished cleanup of last comedi_cmd - if(devpriv->rt_task_active || devpriv->scan_task_active) + if (devpriv->rt_task_active || devpriv->scan_task_active) return -EBUSY; - ret = comedi_lock(devpriv->device,devpriv->subd); - if(ret<0) - { + ret = comedi_lock(devpriv->device, devpriv->subd); + if (ret < 0) { comedi_error(dev, "failed to obtain lock"); return ret; } - switch(cmd->scan_begin_src){ - case TRIG_TIMER: - devpriv->scan_period = nano2count(cmd->scan_begin_arg); - break; - case TRIG_FOLLOW: - devpriv->scan_period = nano2count(cmd->convert_arg * cmd->scan_end_arg); - break; - default: - comedi_error(dev, "bug setting scan period!"); - return -1; - break; + switch (cmd->scan_begin_src) { + case TRIG_TIMER: + devpriv->scan_period = nano2count(cmd->scan_begin_arg); + break; + case TRIG_FOLLOW: + devpriv->scan_period = + nano2count(cmd->convert_arg * cmd->scan_end_arg); + break; + default: + comedi_error(dev, "bug setting scan period!"); + return -1; + break; } - switch(cmd->convert_src){ - case TRIG_TIMER: - devpriv->convert_period = nano2count(cmd->convert_arg); - break; - case TRIG_NOW: - devpriv->convert_period = 1; - break; - default: - comedi_error(dev, "bug setting conversion period!"); - return -1; - break; + switch (cmd->convert_src) { + case TRIG_TIMER: + devpriv->convert_period = nano2count(cmd->convert_arg); + break; + case TRIG_NOW: + devpriv->convert_period = 1; + break; + default: + comedi_error(dev, "bug setting conversion period!"); + return -1; + break; } - if(cmd->start_src == TRIG_NOW) + if (cmd->start_src == TRIG_NOW) return timer_start_cmd(dev, s); s->async->inttrig = timer_inttrig; @@ -557,9 +569,10 @@ static int timer_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int timer_inttrig(comedi_device *dev, comedi_subdevice *s, unsigned int trig_num) +static int timer_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trig_num) { - if(trig_num != 0) + if (trig_num != 0) return -EINVAL; s->async->inttrig = NULL; @@ -567,7 +580,7 @@ static int timer_inttrig(comedi_device *dev, comedi_subdevice *s, unsigned int t return timer_start_cmd(dev, s); } -static int timer_start_cmd(comedi_device *dev, comedi_subdevice *s) +static int timer_start_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -577,29 +590,26 @@ static int timer_start_cmd(comedi_device *dev, comedi_subdevice *s) devpriv->stop = 0; s->async->events = 0; - - if(cmd->start_src == TRIG_NOW) + if (cmd->start_src == TRIG_NOW) delay = nano2count(cmd->start_arg); else delay = 0; - now=rt_get_time(); + now = rt_get_time(); /* Using 'period' this way gets around some weird bug in gcc-2.95.2 * that generates the compile error 'internal error--unrecognizable insn' * when rt_task_make_period() is called (observed with rtlinux-3.1, linux-2.2.19). * - fmhess */ period = devpriv->scan_period; - ret = rt_task_make_periodic(devpriv->rt_task, now - + delay, period); - if(ret < 0) - { + ret = rt_task_make_periodic(devpriv->rt_task, now + delay, period); + if (ret < 0) { comedi_error(dev, "error starting rt_task"); return ret; } return 0; } -static int timer_attach(comedi_device *dev,comedi_devconfig *it) +static int timer_attach(comedi_device * dev, comedi_devconfig * it) { int ret; comedi_subdevice *s, *emul_s; @@ -609,54 +619,55 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it) const int scan_priority = timer_priority + 1; char path[20]; - printk("comedi%d: timer: ",dev->minor); + printk("comedi%d: timer: ", dev->minor); - dev->board_name="timer"; + dev->board_name = "timer"; - if((ret=alloc_subdevices(dev, 1))<0) + if ((ret = alloc_subdevices(dev, 1)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(timer_private)))<0) + if ((ret = alloc_private(dev, sizeof(timer_private))) < 0) return ret; - sprintf(path,"/dev/comedi%d",it->options[0]); + sprintf(path, "/dev/comedi%d", it->options[0]); devpriv->device = comedi_open(path); - devpriv->subd=it->options[1]; + devpriv->subd = it->options[1]; - printk("emulating commands for minor %i, subdevice %d\n", it->options[0], devpriv->subd); + printk("emulating commands for minor %i, subdevice %d\n", + it->options[0], devpriv->subd); emul_dev = devpriv->device; - emul_s = emul_dev->subdevices+devpriv->subd; + emul_s = emul_dev->subdevices + devpriv->subd; // input or output subdevice - s=dev->subdevices+0; - s->type=emul_s->type; - s->subdev_flags = emul_s->subdev_flags; /* SDF_GROUND (to fool check_driver) */ - s->n_chan=emul_s->n_chan; - s->len_chanlist=1024; - s->do_cmd=timer_cmd; - s->do_cmdtest=timer_cmdtest; - s->cancel=timer_cancel; - s->maxdata=emul_s->maxdata; - s->range_table=emul_s->range_table; - s->range_table_list=emul_s->range_table_list; - switch(emul_s->type){ + s = dev->subdevices + 0; + s->type = emul_s->type; + s->subdev_flags = emul_s->subdev_flags; /* SDF_GROUND (to fool check_driver) */ + s->n_chan = emul_s->n_chan; + s->len_chanlist = 1024; + s->do_cmd = timer_cmd; + s->do_cmdtest = timer_cmdtest; + s->cancel = timer_cancel; + s->maxdata = emul_s->maxdata; + s->range_table = emul_s->range_table; + s->range_table_list = emul_s->range_table_list; + switch (emul_s->type) { case COMEDI_SUBD_AI: - s->insn_read=timer_insn; + s->insn_read = timer_insn; dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; devpriv->io_function = timer_data_read; break; case COMEDI_SUBD_AO: - s->insn_write=timer_insn; - s->insn_read=timer_insn; + s->insn_write = timer_insn; + s->insn_read = timer_insn; dev->write_subdev = s; s->subdev_flags |= SDF_CMD_WRITE; devpriv->io_function = timer_data_write; break; case COMEDI_SUBD_DIO: - s->insn_write=timer_insn; - s->insn_read=timer_insn; - s->insn_bits=timer_insn; + s->insn_write = timer_insn; + s->insn_read = timer_insn; + s->insn_bits = timer_insn; dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; devpriv->io_function = timer_dio_read; @@ -667,26 +678,26 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it) } rt_set_oneshot_mode(); - start_rt_timer( 1 ); + start_rt_timer(1); devpriv->timer_running = 1; - devpriv->rt_task = kzalloc(sizeof(RT_TASK),GFP_KERNEL); + devpriv->rt_task = kzalloc(sizeof(RT_TASK), GFP_KERNEL); // initialize real-time tasks ret = rt_task_init(devpriv->rt_task, timer_task_func, - (comedi_rt_task_context_t)dev, 3000, timer_priority, 0, 0); - if(ret < 0) { + (comedi_rt_task_context_t) dev, 3000, timer_priority, 0, 0); + if (ret < 0) { comedi_error(dev, "error initalizing rt_task"); kfree(devpriv->rt_task); devpriv->rt_task = 0; return ret; } - devpriv->scan_task = kzalloc(sizeof(RT_TASK),GFP_KERNEL); + devpriv->scan_task = kzalloc(sizeof(RT_TASK), GFP_KERNEL); ret = rt_task_init(devpriv->scan_task, scan_task_func, - (comedi_rt_task_context_t)dev, 3000, scan_priority, 0, 0); - if(ret < 0){ + (comedi_rt_task_context_t) dev, 3000, scan_priority, 0, 0); + if (ret < 0) { comedi_error(dev, "error initalizing scan_task"); kfree(devpriv->scan_task); devpriv->scan_task = 0; @@ -697,25 +708,23 @@ static int timer_attach(comedi_device *dev,comedi_devconfig *it) } // free allocated resources -static int timer_detach(comedi_device *dev) +static int timer_detach(comedi_device * dev) { - printk("comedi%d: timer: remove\n",dev->minor); + printk("comedi%d: timer: remove\n", dev->minor); - if(devpriv){ - if(devpriv->rt_task){ + if (devpriv) { + if (devpriv->rt_task) { rt_task_delete(devpriv->rt_task); kfree(devpriv->rt_task); } - if(devpriv->scan_task){ + if (devpriv->scan_task) { rt_task_delete(devpriv->scan_task); kfree(devpriv->scan_task); } - if(devpriv->timer_running) + if (devpriv->timer_running) stop_rt_timer(); - if(devpriv->device) + if (devpriv->device) comedi_close(devpriv->device); } return 0; } - - diff --git a/comedi/drivers/comedi_test.c b/comedi/drivers/comedi_test.c index 5f2bf581..8321dc4e 100644 --- a/comedi/drivers/comedi_test.c +++ b/comedi/drivers/comedi_test.c @@ -56,9 +56,8 @@ zero volts). #include "comedi_fc.h" - /* Board descriptions */ -typedef struct waveform_board_struct{ +typedef struct waveform_board_struct { const char *name; int ai_chans; int ai_bits; @@ -69,18 +68,19 @@ typedef struct waveform_board_struct{ static const waveform_board waveform_boards[] = { { - name: "comedi_test", - ai_chans: N_CHANS, - ai_bits: 16, - have_dio: 0, - }, + name: "comedi_test", + ai_chans:N_CHANS, + ai_bits: 16, + have_dio:0, + }, }; + #define thisboard ((const waveform_board *)dev->board_ptr) /* Data unique to this driver */ -typedef struct{ +typedef struct { struct timer_list timer; - struct timeval last; // time at which last timer interrupt occured + struct timeval last; // time at which last timer interrupt occured unsigned int uvolt_amplitude; // waveform amplitude in microvolts unsigned long usec_period; // waveform period in microseconds volatile unsigned long usec_current; // current time (modulo waveform period) @@ -88,46 +88,51 @@ typedef struct{ volatile unsigned long ai_count; // number of conversions remaining unsigned int scan_period; // scan period in usec unsigned int convert_period; // conversion period in usec - volatile unsigned timer_running : 1; + volatile unsigned timer_running:1; volatile lsampl_t ao_loopbacks[N_CHANS]; } waveform_private; #define devpriv ((waveform_private *)dev->private) -static int waveform_attach(comedi_device *dev,comedi_devconfig *it); -static int waveform_detach(comedi_device *dev); -static comedi_driver driver_waveform={ - driver_name: "comedi_test", - module: THIS_MODULE, - attach: waveform_attach, - detach: waveform_detach, - board_name: &waveform_boards[0].name, - offset: sizeof(waveform_board), - num_names: sizeof(waveform_boards) / sizeof(waveform_board), +static int waveform_attach(comedi_device * dev, comedi_devconfig * it); +static int waveform_detach(comedi_device * dev); +static comedi_driver driver_waveform = { + driver_name:"comedi_test", + module:THIS_MODULE, + attach:waveform_attach, + detach:waveform_detach, + board_name:&waveform_boards[0].name, + offset:sizeof(waveform_board), + num_names:sizeof(waveform_boards) / sizeof(waveform_board), }; + COMEDI_INITCLEANUP(driver_waveform); -static int waveform_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int waveform_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int waveform_ai_cancel(comedi_device *dev, comedi_subdevice *s); -static int waveform_ai_insn_read(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int waveform_ao_insn_write(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static sampl_t fake_sawtooth(comedi_device *dev, unsigned int range, unsigned long current_time); -static sampl_t fake_squarewave(comedi_device *dev, unsigned int range, unsigned long current_time); -static sampl_t fake_flatline(comedi_device *dev, unsigned int range, unsigned long current_time); -static sampl_t fake_waveform(comedi_device *dev, unsigned int channel, +static int waveform_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int waveform_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int waveform_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static int waveform_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int waveform_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static sampl_t fake_sawtooth(comedi_device * dev, unsigned int range, + unsigned long current_time); +static sampl_t fake_squarewave(comedi_device * dev, unsigned int range, + unsigned long current_time); +static sampl_t fake_flatline(comedi_device * dev, unsigned int range, + unsigned long current_time); +static sampl_t fake_waveform(comedi_device * dev, unsigned int channel, unsigned int range, unsigned long current_time); static const int nano_per_micro = 1000; // 1000 nanosec in a microsec // fake analog input ranges -static const comedi_lrange waveform_ai_ranges = -{ +static const comedi_lrange waveform_ai_ranges = { 2, { - BIP_RANGE(10), - BIP_RANGE(5), - } + BIP_RANGE(10), + BIP_RANGE(5), + } }; /* @@ -137,7 +142,7 @@ static const comedi_lrange waveform_ai_ranges = */ static void waveform_ai_interrupt(unsigned long arg) { - comedi_device *dev = (comedi_device*) arg; + comedi_device *dev = (comedi_device *) arg; comedi_async *async = dev->read_subdev->async; comedi_cmd *cmd = &async->cmd; unsigned int i, j; @@ -148,23 +153,28 @@ static void waveform_ai_interrupt(unsigned long arg) do_gettimeofday(&now); - elapsed_time = 1000000 * (now.tv_sec - devpriv->last.tv_sec) + now.tv_usec - devpriv->last.tv_usec; + elapsed_time = + 1000000 * (now.tv_sec - devpriv->last.tv_sec) + now.tv_usec - + devpriv->last.tv_usec; devpriv->last = now; - num_scans = (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period; - devpriv->usec_remainder = (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; + num_scans = + (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period; + devpriv->usec_remainder = + (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; async->events = 0; - for(i = 0; i < num_scans; i++) - { - for( j = 0; j < cmd->chanlist_len; j++) - { - cfc_write_to_buffer( dev->read_subdev, - fake_waveform(dev, CR_CHAN(cmd->chanlist[j]), CR_RANGE(cmd->chanlist[j]), - devpriv->usec_current + i * devpriv->scan_period + j * devpriv->convert_period)); + for (i = 0; i < num_scans; i++) { + for (j = 0; j < cmd->chanlist_len; j++) { + cfc_write_to_buffer(dev->read_subdev, + fake_waveform(dev, CR_CHAN(cmd->chanlist[j]), + CR_RANGE(cmd->chanlist[j]), + devpriv->usec_current + + i * devpriv->scan_period + + j * devpriv->convert_period)); } devpriv->ai_count++; - if(cmd->stop_src == TRIG_COUNT && devpriv->ai_count >= cmd->stop_arg) - { + if (cmd->stop_src == TRIG_COUNT + && devpriv->ai_count >= cmd->stop_arg) { async->events |= COMEDI_CB_EOA; break; } @@ -173,7 +183,7 @@ static void waveform_ai_interrupt(unsigned long arg) devpriv->usec_current += elapsed_time; devpriv->usec_current %= devpriv->usec_period; - if((async->events & COMEDI_CB_EOA) == 0 && devpriv->timer_running) + if ((async->events & COMEDI_CB_EOA) == 0 && devpriv->timer_running) mod_timer(&devpriv->timer, jiffies + 1); else del_timer(&devpriv->timer); @@ -181,7 +191,7 @@ static void waveform_ai_interrupt(unsigned long arg) comedi_event(dev, dev->read_subdev); } -static int waveform_attach(comedi_device *dev,comedi_devconfig *it) +static int waveform_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int amplitude = it->options[0]; @@ -191,21 +201,23 @@ static int waveform_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = thisboard->name; - if(alloc_private(dev, sizeof(waveform_private)) < 0) + if (alloc_private(dev, sizeof(waveform_private)) < 0) return -ENOMEM; // set default amplitude and period - if(amplitude <=0) + if (amplitude <= 0) amplitude = 1000000; // 1 volt - if(period <= 0) + if (period <= 0) period = 100000; // 0.1 sec devpriv->uvolt_amplitude = amplitude; devpriv->usec_period = period; - printk("%i microvolt, %li microsecond waveform ", devpriv->uvolt_amplitude, devpriv->usec_period); + printk("%i microvolt, %li microsecond waveform ", + devpriv->uvolt_amplitude, devpriv->usec_period); dev->n_subdevices = 2; - if(alloc_subdevices(dev, dev->n_subdevices) < 0) return -ENOMEM; + if (alloc_subdevices(dev, dev->n_subdevices) < 0) + return -ENOMEM; s = dev->subdevices + 0; dev->read_subdev = s; @@ -243,27 +255,26 @@ static int waveform_attach(comedi_device *dev,comedi_devconfig *it) init_timer(&(devpriv->timer)); devpriv->timer.function = waveform_ai_interrupt; - devpriv->timer.data = (unsigned long) dev; + devpriv->timer.data = (unsigned long)dev; printk("attached\n"); return 1; } -static int waveform_detach(comedi_device *dev) +static int waveform_detach(comedi_device * dev) { - printk("comedi%d: comedi_test: remove\n",dev->minor); + printk("comedi%d: comedi_test: remove\n", dev->minor); - if(dev->private) - { + if (dev->private) { waveform_ai_cancel(dev, dev->read_subdev); } return 0; } -static int waveform_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int waveform_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -272,125 +283,126 @@ static int waveform_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW | TRIG_TIMER; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->convert_src != TRIG_NOW && - cmd->convert_src != TRIG_TIMER) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) err++; + if (cmd->convert_src != TRIG_NOW && cmd->convert_src != TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg != 0) - { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->convert_src == TRIG_NOW) - { - if(cmd->convert_arg != 0) - { + if (cmd->convert_src == TRIG_NOW) { + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } } - if(cmd->scan_begin_src == TRIG_TIMER) - { - if(cmd->scan_begin_arg < nano_per_micro) - { + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < nano_per_micro) { cmd->scan_begin_arg = nano_per_micro; err++; } - if(cmd->convert_src == TRIG_TIMER && - cmd->scan_begin_arg < cmd->convert_arg * cmd->chanlist_len) - { - cmd->scan_begin_arg = cmd->convert_arg * cmd->chanlist_len; + if (cmd->convert_src == TRIG_TIMER && + cmd->scan_begin_arg < + cmd->convert_arg * cmd->chanlist_len) { + cmd->scan_begin_arg = + cmd->convert_arg * cmd->chanlist_len; err++; } } - - // XXX these checks are generic and should go in core if not there already - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + 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) - { + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { cmd->stop_arg = 1; err++; } - } else - { /* TRIG_NONE */ - if(cmd->stop_arg != 0) - { + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; // round to nearest microsec - cmd->scan_begin_arg = nano_per_micro * ((tmp + (nano_per_micro / 2)) / nano_per_micro); - if(tmp != cmd->scan_begin_arg) err++; + cmd->scan_begin_arg = + nano_per_micro * ((tmp + + (nano_per_micro / 2)) / nano_per_micro); + if (tmp != cmd->scan_begin_arg) + err++; } - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { tmp = cmd->convert_arg; // round to nearest microsec - cmd->convert_arg = nano_per_micro * ((tmp + (nano_per_micro / 2)) / nano_per_micro); - if(tmp != cmd->convert_arg) err++; + cmd->convert_arg = + nano_per_micro * ((tmp + + (nano_per_micro / 2)) / nano_per_micro); + if (tmp != cmd->convert_arg) + err++; } - if(err) return 4; + if (err) + return 4; return 0; } -static int waveform_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int waveform_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; - if( cmd->flags & TRIG_RT ) - { - comedi_error( dev, "commands at RT priority not supported in this driver" ); + if (cmd->flags & TRIG_RT) { + comedi_error(dev, + "commands at RT priority not supported in this driver"); return -1; } @@ -398,12 +410,11 @@ static int waveform_ai_cmd(comedi_device *dev, comedi_subdevice *s) devpriv->ai_count = 0; devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro; - if(cmd->convert_src == TRIG_NOW) + if (cmd->convert_src == TRIG_NOW) devpriv->convert_period = 0; - else if( cmd->convert_src == TRIG_TIMER) + else if (cmd->convert_src == TRIG_TIMER) devpriv->convert_period = cmd->convert_arg / nano_per_micro; - else - { + else { comedi_error(dev, "bug setting conversion period"); return -1; } @@ -417,14 +428,15 @@ static int waveform_ai_cmd(comedi_device *dev, comedi_subdevice *s) return 0; } -static int waveform_ai_cancel(comedi_device *dev, comedi_subdevice *s) +static int waveform_ai_cancel(comedi_device * dev, comedi_subdevice * s) { devpriv->timer_running = 0; del_timer(&devpriv->timer); return 0; } -static sampl_t fake_sawtooth(comedi_device *dev, unsigned int range_index, unsigned long current_time) +static sampl_t fake_sawtooth(comedi_device * dev, unsigned int range_index, + unsigned long current_time) { comedi_subdevice *s = dev->read_subdev; unsigned int offset = s->maxdata / 2; @@ -444,7 +456,8 @@ static sampl_t fake_sawtooth(comedi_device *dev, unsigned int range_index, unsig return offset + value; } -static sampl_t fake_squarewave(comedi_device *dev, unsigned int range_index, unsigned long current_time) +static sampl_t fake_squarewave(comedi_device * dev, unsigned int range_index, + unsigned long current_time) { comedi_subdevice *s = dev->read_subdev; unsigned int offset = s->maxdata / 2; @@ -456,56 +469,57 @@ static sampl_t fake_squarewave(comedi_device *dev, unsigned int range_index, uns value *= devpriv->uvolt_amplitude; do_div(value, krange->max - krange->min); - if(current_time < devpriv->usec_period / 2) + if (current_time < devpriv->usec_period / 2) value *= -1; return offset + value; } -static sampl_t fake_flatline(comedi_device *dev, unsigned int range_index, unsigned long current_time) +static sampl_t fake_flatline(comedi_device * dev, unsigned int range_index, + unsigned long current_time) { return dev->read_subdev->maxdata / 2; } // generates a different waveform depending on what channel is read -static sampl_t fake_waveform(comedi_device *dev, unsigned int channel, +static sampl_t fake_waveform(comedi_device * dev, unsigned int channel, unsigned int range, unsigned long current_time) { - enum - { + enum { SAWTOOTH_CHAN, SQUARE_CHAN, }; - switch(channel) - { - case SAWTOOTH_CHAN: - return fake_sawtooth(dev, range, current_time); - break; - case SQUARE_CHAN: - return fake_squarewave(dev, range, current_time); - break; - default: - break; + switch (channel) { + case SAWTOOTH_CHAN: + return fake_sawtooth(dev, range, current_time); + break; + case SQUARE_CHAN: + return fake_squarewave(dev, range, current_time); + break; + default: + break; } return fake_flatline(dev, range, current_time); } -static int waveform_ai_insn_read(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int waveform_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i, chan = CR_CHAN(insn->chanspec); - for(i = 0; i < insn->n; i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_loopbacks[chan]; return insn->n; } -static int waveform_ao_insn_write(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int waveform_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i, chan = CR_CHAN(insn->chanspec); - for(i = 0; i < insn->n; i++) + for (i = 0; i < insn->n; i++) devpriv->ao_loopbacks[chan] = data[i]; return insn->n; diff --git a/comedi/drivers/contec_pci_dio.c b/comedi/drivers/contec_pci_dio.c index 138cf85e..c6d7423f 100644 --- a/comedi/drivers/contec_pci_dio.c +++ b/comedi/drivers/contec_pci_dio.c @@ -39,32 +39,34 @@ Configuration Options: #include "comedi_pci.h" typedef enum contec_model { - PIO1616L =0, + PIO1616L = 0, } contec_model; typedef struct contec_board { const char *name; - int model; - int in_ports; - int out_ports; - int in_offs; - int out_offs; - int out_boffs; + int model; + int in_ports; + int out_ports; + int in_offs; + int out_offs; + int out_boffs; } contec_board; static const contec_board contec_boards[] = { - { "PIO1616L", PIO1616L, 16, 16, 0, 2, 10 }, + {"PIO1616L", PIO1616L, 16, 16, 0, 2, 10}, }; #define PCI_DEVICE_ID_PIO1616L 0x8172 static struct pci_device_id contec_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PIO1616L }, - { 0 } + {PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L, PCI_ANY_ID, PCI_ANY_ID, + 0, 0, PIO1616L}, + {0} }; + MODULE_DEVICE_TABLE(pci, contec_pci_table); #define thisboard ((const contec_board *)dev->board_ptr) -typedef struct{ +typedef struct { int data; struct pci_dev *pci_dev; @@ -73,53 +75,54 @@ typedef struct{ #define devpriv ((contec_private *)dev->private) -static int contec_attach(comedi_device *dev,comedi_devconfig *it); -static int contec_detach(comedi_device *dev); -static comedi_driver driver_contec={ - driver_name: "contec_pci_dio", - module: THIS_MODULE, - attach: contec_attach, - detach: contec_detach, +static int contec_attach(comedi_device * dev, comedi_devconfig * it); +static int contec_detach(comedi_device * dev); +static comedi_driver driver_contec = { + driver_name:"contec_pci_dio", + module:THIS_MODULE, + attach:contec_attach, + detach:contec_detach, }; /* Classic digital IO */ -static int contec_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int contec_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int contec_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int contec_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); #if 0 -static int contec_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); +static int contec_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); -static int contec_ns_to_timer(unsigned int *ns,int round); +static int contec_ns_to_timer(unsigned int *ns, int round); #endif -static int contec_attach(comedi_device *dev,comedi_devconfig *it) +static int contec_attach(comedi_device * dev, comedi_devconfig * it) { struct pci_dev *pcidev; comedi_subdevice *s; - printk("comedi%d: contec: ",dev->minor); - + printk("comedi%d: contec: ", dev->minor); + dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(contec_private))<0) + if (alloc_private(dev, sizeof(contec_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - - if ( pcidev->vendor == PCI_VENDOR_ID_CONTEC && - pcidev->device == PCI_DEVICE_ID_PIO1616L ) { + + if (pcidev->vendor == PCI_VENDOR_ID_CONTEC && + pcidev->device == PCI_DEVICE_ID_PIO1616L) { if (it->options[0] || it->options[1]) { /* Check bus and slot. */ if (it->options[0] != pcidev->bus->number || - it->options[1] != - PCI_SLOT(pcidev->devfn)) { + it->options[1] != + PCI_SLOT(pcidev->devfn)) { continue; } } @@ -128,12 +131,12 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) printk("error enabling PCI device and request regions!\n"); return -EIO; } - dev->iobase = pci_resource_start ( pcidev, 0 ); - printk ( " base addr %lx ", dev->iobase ); + dev->iobase = pci_resource_start(pcidev, 0); + printk(" base addr %lx ", dev->iobase); dev->board_ptr = contec_boards + 0; - s=dev->subdevices+0; + s = dev->subdevices + 0; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; @@ -142,13 +145,13 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) s->range_table = &range_digital; s->insn_bits = contec_di_insn_bits; - s=dev->subdevices+1; + s = dev->subdevices + 1; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE; s->n_chan = 16; s->maxdata = 1; s->range_table = &range_digital; - s->insn_bits = contec_do_insn_bits; + s->insn_bits = contec_do_insn_bits; printk("attached\n"); @@ -161,67 +164,67 @@ static int contec_attach(comedi_device *dev,comedi_devconfig *it) return -EIO; } - -static int contec_detach(comedi_device *dev) +static int contec_detach(comedi_device * dev) { - printk("comedi%d: contec: remove\n",dev->minor); + printk("comedi%d: contec: remove\n", dev->minor); if (devpriv && devpriv->pci_dev) { - if(dev->iobase) - { + if (dev->iobase) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } - + return 0; } #if 0 -static int contec_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int contec_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - printk ( "contec_cmdtest called\n" ); + printk("contec_cmdtest called\n"); return 0; } -static int contec_ns_to_timer(unsigned int *ns,int round) +static int contec_ns_to_timer(unsigned int *ns, int round) { return *ns; } #endif -static int contec_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int contec_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - printk ( "contec_do_insn_bits called\n" ); - printk ( " data: %d %d\n", data[0], data[1] ); - - if(insn->n!=2)return -EINVAL; + printk("contec_do_insn_bits called\n"); + printk(" data: %d %d\n", data[0], data[1]); + + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; - rt_printk ( " out: %d on %lx\n", s->state, dev->iobase + thisboard->out_offs ); - outw(s->state, dev->iobase + thisboard->out_offs ); + s->state |= data[0] & data[1]; + rt_printk(" out: %d on %lx\n", s->state, + dev->iobase + thisboard->out_offs); + outw(s->state, dev->iobase + thisboard->out_offs); } return 2; } -static int contec_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int contec_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - rt_printk ( "contec_di_insn_bits called\n" ); - rt_printk ( " data: %d %d\n", data[0], data[1] ); - - if(insn->n!=2)return -EINVAL; + rt_printk("contec_di_insn_bits called\n"); + rt_printk(" data: %d %d\n", data[0], data[1]); - data[1] = inw(dev->iobase + thisboard->in_offs ); + if (insn->n != 2) + return -EINVAL; + + data[1] = inw(dev->iobase + thisboard->in_offs); return 2; } COMEDI_INITCLEANUP(driver_contec); - diff --git a/comedi/drivers/daqboard2000.c b/comedi/drivers/daqboard2000.c index 550b597a..97ab488b 100644 --- a/comedi/drivers/daqboard2000.c +++ b/comedi/drivers/daqboard2000.c @@ -119,8 +119,8 @@ Configuration options: #include "comedi_pci.h" #include "8255.h" -#define DAQBOARD2000_SUBSYSTEM_IDS2 0x00021616 /* Daqboard/2000 - 2 Dacs */ -#define DAQBOARD2000_SUBSYSTEM_IDS4 0x00041616 /* Daqboard/2000 - 4 Dacs */ +#define DAQBOARD2000_SUBSYSTEM_IDS2 0x00021616 /* Daqboard/2000 - 2 Dacs */ +#define DAQBOARD2000_SUBSYSTEM_IDS4 0x00041616 /* Daqboard/2000 - 4 Dacs */ #define DAQBOARD2000_DAQ_SIZE 0x1002 #define DAQBOARD2000_PLX_SIZE 0x100 @@ -142,73 +142,75 @@ Configuration options: // Available ranges static const comedi_lrange range_daqboard2000_ai = { 13, { - RANGE(-10, 10), - RANGE(-5, 5), - RANGE(-2.5, 2.5), - RANGE(-1.25, 1.25), - RANGE(-0.625, 0.625), - RANGE(-0.3125, 0.3125), - RANGE(-0.156, 0.156), - RANGE(0, 10), - RANGE(0, 5), - RANGE(0, 2.5), - RANGE(0, 1.25), - RANGE(0, 0.625), - RANGE(0, 0.3125) -}}; + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + RANGE(-0.625, 0.625), + RANGE(-0.3125, 0.3125), + RANGE(-0.156, 0.156), + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25), + RANGE(0, 0.625), + RANGE(0, 0.3125) + } +}; static const comedi_lrange range_daqboard2000_ao = { 1, { - RANGE(-10, 10) -}}; + RANGE(-10, 10) + } +}; typedef struct daqboard2000_hw { - volatile u16 acqControl; // 0x00 - volatile u16 acqScanListFIFO; // 0x02 - volatile u32 acqPacerClockDivLow; // 0x04 - - volatile u16 acqScanCounter; // 0x08 - volatile u16 acqPacerClockDivHigh; // 0x0a - volatile u16 acqTriggerCount; // 0x0c - volatile u16 fill2; // 0x0e - volatile u16 acqResultsFIFO; // 0x10 - volatile u16 fill3; // 0x12 - volatile u16 acqResultsShadow; // 0x14 - volatile u16 fill4; // 0x16 - volatile u16 acqAdcResult; // 0x18 - volatile u16 fill5; // 0x1a - volatile u16 dacScanCounter; // 0x1c - volatile u16 fill6; // 0x1e - - volatile u16 dacControl; // 0x20 - volatile u16 fill7; // 0x22 - volatile s16 dacFIFO; // 0x24 - volatile u16 fill8[2]; // 0x26 - volatile u16 dacPacerClockDiv; // 0x2a - volatile u16 refDacs; // 0x2c - volatile u16 fill9; // 0x2e - - volatile u16 dioControl; // 0x30 - volatile s16 dioP3hsioData; // 0x32 - volatile u16 dioP3Control; // 0x34 - volatile u16 calEepromControl; // 0x36 - volatile s16 dacSetting[4]; // 0x38 - volatile s16 dioP2ExpansionIO8Bit[32]; // 0x40 - - volatile u16 ctrTmrControl; // 0x80 - volatile u16 fill10[3]; // 0x82 - volatile s16 ctrInput[4]; // 0x88 - volatile u16 fill11[8]; // 0x90 - volatile u16 timerDivisor[2]; // 0xa0 - volatile u16 fill12[6]; // 0xa4 - - volatile u16 dmaControl; // 0xb0 - volatile u16 trigControl; // 0xb2 - volatile u16 fill13[2]; // 0xb4 - volatile u16 calEeprom; // 0xb8 - volatile u16 acqDigitalMark; // 0xba - volatile u16 trigDacs; // 0xbc - volatile u16 fill14; // 0xbe - volatile s16 dioP2ExpansionIO16Bit[32];// 0xc0 + volatile u16 acqControl; // 0x00 + volatile u16 acqScanListFIFO; // 0x02 + volatile u32 acqPacerClockDivLow; // 0x04 + + volatile u16 acqScanCounter; // 0x08 + volatile u16 acqPacerClockDivHigh; // 0x0a + volatile u16 acqTriggerCount; // 0x0c + volatile u16 fill2; // 0x0e + volatile u16 acqResultsFIFO; // 0x10 + volatile u16 fill3; // 0x12 + volatile u16 acqResultsShadow; // 0x14 + volatile u16 fill4; // 0x16 + volatile u16 acqAdcResult; // 0x18 + volatile u16 fill5; // 0x1a + volatile u16 dacScanCounter; // 0x1c + volatile u16 fill6; // 0x1e + + volatile u16 dacControl; // 0x20 + volatile u16 fill7; // 0x22 + volatile s16 dacFIFO; // 0x24 + volatile u16 fill8[2]; // 0x26 + volatile u16 dacPacerClockDiv; // 0x2a + volatile u16 refDacs; // 0x2c + volatile u16 fill9; // 0x2e + + volatile u16 dioControl; // 0x30 + volatile s16 dioP3hsioData; // 0x32 + volatile u16 dioP3Control; // 0x34 + volatile u16 calEepromControl; // 0x36 + volatile s16 dacSetting[4]; // 0x38 + volatile s16 dioP2ExpansionIO8Bit[32]; // 0x40 + + volatile u16 ctrTmrControl; // 0x80 + volatile u16 fill10[3]; // 0x82 + volatile s16 ctrInput[4]; // 0x88 + volatile u16 fill11[8]; // 0x90 + volatile u16 timerDivisor[2]; // 0xa0 + volatile u16 fill12[6]; // 0xa4 + + volatile u16 dmaControl; // 0xb0 + volatile u16 trigControl; // 0xb2 + volatile u16 fill13[2]; // 0xb4 + volatile u16 calEeprom; // 0xb8 + volatile u16 acqDigitalMark; // 0xba + volatile u16 trigDacs; // 0xbc + volatile u16 fill14; // 0xbe + volatile s16 dioP2ExpansionIO16Bit[32]; // 0xc0 } daqboard2000_hw; /* Scan Sequencer programming */ @@ -290,373 +292,402 @@ typedef struct daqboard2000_hw { #define DAQBOARD2000_PosRefDacSelect 0x0100 #define DAQBOARD2000_NegRefDacSelect 0x0000 - - -static int daqboard2000_attach(comedi_device *dev,comedi_devconfig *it); -static int daqboard2000_detach(comedi_device *dev); +static int daqboard2000_attach(comedi_device * dev, comedi_devconfig * it); +static int daqboard2000_detach(comedi_device * dev); static comedi_driver driver_daqboard2000 = { - driver_name: "daqboard2000", - module: THIS_MODULE, - attach: daqboard2000_attach, - detach: daqboard2000_detach, + driver_name:"daqboard2000", + module:THIS_MODULE, + attach:daqboard2000_attach, + detach:daqboard2000_detach, }; typedef struct { const char *name; int id; -}boardtype; -static const boardtype boardtypes[]={ - { "ids2", DAQBOARD2000_SUBSYSTEM_IDS2 }, - { "ids4", DAQBOARD2000_SUBSYSTEM_IDS4 }, +} boardtype; +static const boardtype boardtypes[] = { + {"ids2", DAQBOARD2000_SUBSYSTEM_IDS2}, + {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4}, }; + #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) static struct pci_device_id daqboard2000_pci_table[] __devinitdata = { - { 0x1616, 0x0409, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {0x1616, 0x0409, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table); typedef struct { - enum { - card_daqboard_2000 - } card; - struct pci_dev *pci_dev; - void *daq; - void *plx; - int got_regions; - lsampl_t ao_readback[2]; + enum { + card_daqboard_2000 + } card; + struct pci_dev *pci_dev; + void *daq; + void *plx; + int got_regions; + lsampl_t ao_readback[2]; } daqboard2000_private; #define devpriv ((daqboard2000_private*)dev->private) -static void writeAcqScanListEntry(comedi_device *dev, u16 entry) +static void writeAcqScanListEntry(comedi_device * dev, u16 entry) { - daqboard2000_hw *fpga = devpriv->daq; + daqboard2000_hw *fpga = devpriv->daq; // comedi_udelay(4); - fpga->acqScanListFIFO = entry & 0x00ff; + fpga->acqScanListFIFO = entry & 0x00ff; // comedi_udelay(4); - fpga->acqScanListFIFO = (entry >> 8) & 0x00ff; + fpga->acqScanListFIFO = (entry >> 8) & 0x00ff; } -static void setup_sampling(comedi_device *dev, int chan, int gain) +static void setup_sampling(comedi_device * dev, int chan, int gain) { - u16 word0, word1, word2, word3; - - /* Channel 0-7 diff, channel 8-23 single ended */ - word0 = 0; - word1 = 0x0004; /* Last scan */ - word2 = (chan<<6) & 0x00c0; - switch (chan / 4) { - case 0: word3 = 0x0001; break; - case 1: word3 = 0x0002; break; - case 2: word3 = 0x0005; break; - case 3: word3 = 0x0006; break; - case 4: word3 = 0x0041; break; - case 5: word3 = 0x0042; break; - default: word3 = 0; break; - } + u16 word0, word1, word2, word3; + + /* Channel 0-7 diff, channel 8-23 single ended */ + word0 = 0; + word1 = 0x0004; /* Last scan */ + word2 = (chan << 6) & 0x00c0; + switch (chan / 4) { + case 0: + word3 = 0x0001; + break; + case 1: + word3 = 0x0002; + break; + case 2: + word3 = 0x0005; + break; + case 3: + word3 = 0x0006; + break; + case 4: + word3 = 0x0041; + break; + case 5: + word3 = 0x0042; + break; + default: + word3 = 0; + break; + } /* dev->eeprom.correctionDACSE[i][j][k].offset = 0x800; dev->eeprom.correctionDACSE[i][j][k].gain = 0xc00; */ - /* These should be read from EEPROM */ - word2 |= 0x0800; - word3 |= 0xc000; + /* These should be read from EEPROM */ + word2 |= 0x0800; + word3 |= 0xc000; /* printk("%d %4.4x %4.4x %4.4x %4.4x\n", chan, word0, word1, word2, word3);*/ - writeAcqScanListEntry(dev, word0); - writeAcqScanListEntry(dev, word1); - writeAcqScanListEntry(dev, word2); - writeAcqScanListEntry(dev, word3); + writeAcqScanListEntry(dev, word0); + writeAcqScanListEntry(dev, word1); + writeAcqScanListEntry(dev, word2); + writeAcqScanListEntry(dev, word3); } - -static int daqboard2000_ai_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int daqboard2000_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - daqboard2000_hw *fpga = devpriv->daq; - int gain, chan, timeout; - - fpga->acqControl = - DAQBOARD2000_AcqResetScanListFifo | - DAQBOARD2000_AcqResetResultsFifo | - DAQBOARD2000_AcqResetConfigPipe; - - /* If pacer clock is not set to some high value (> 10 us), we - risk multiple samples to be put into the result FIFO. */ - fpga->acqPacerClockDivLow = 1000000; /* 1 second, should be long enough */ - fpga->acqPacerClockDivHigh = 0; - - gain = CR_RANGE(insn->chanspec); - chan = CR_CHAN(insn->chanspec); - - /* This doesn't look efficient. I decided to take the conservative - * approach when I did the insn conversion. Perhaps it would be - * better to have broken it completely, then someone would have been - * forced to fix it. --ds */ - for(i=0;in;i++){ - setup_sampling(dev, chan, gain); - /* Enable reading from the scanlist FIFO */ - fpga->acqControl = DAQBOARD2000_SeqStartScanList; - for (timeout = 0 ; timeout < 20 ; timeout++) { - if (fpga->acqControl & DAQBOARD2000_AcqConfigPipeFull) { break; } - //comedi_udelay(2); - } - fpga->acqControl = DAQBOARD2000_AdcPacerEnable; - for (timeout = 0 ; timeout < 20 ; timeout++) { - if (fpga->acqControl & DAQBOARD2000_AcqLogicScanning) { break; } - //comedi_udelay(2); - } - for (timeout = 0 ; timeout < 20 ; timeout++) { - if (fpga->acqControl & DAQBOARD2000_AcqResultsFIFOHasValidData) { break;} - //comedi_udelay(2); - } - data[i] = fpga->acqResultsFIFO; - fpga->acqControl = DAQBOARD2000_AdcPacerDisable; - fpga->acqControl = DAQBOARD2000_SeqStopScanList; - } - - return i; -} + int i; + daqboard2000_hw *fpga = devpriv->daq; + int gain, chan, timeout; + + fpga->acqControl = + DAQBOARD2000_AcqResetScanListFifo | + DAQBOARD2000_AcqResetResultsFifo | + DAQBOARD2000_AcqResetConfigPipe; + + /* If pacer clock is not set to some high value (> 10 us), we + risk multiple samples to be put into the result FIFO. */ + fpga->acqPacerClockDivLow = 1000000; /* 1 second, should be long enough */ + fpga->acqPacerClockDivHigh = 0; + + gain = CR_RANGE(insn->chanspec); + chan = CR_CHAN(insn->chanspec); + + /* This doesn't look efficient. I decided to take the conservative + * approach when I did the insn conversion. Perhaps it would be + * better to have broken it completely, then someone would have been + * forced to fix it. --ds */ + for (i = 0; i < insn->n; i++) { + setup_sampling(dev, chan, gain); + /* Enable reading from the scanlist FIFO */ + fpga->acqControl = DAQBOARD2000_SeqStartScanList; + for (timeout = 0; timeout < 20; timeout++) { + if (fpga->acqControl & DAQBOARD2000_AcqConfigPipeFull) { + break; + } + //comedi_udelay(2); + } + fpga->acqControl = DAQBOARD2000_AdcPacerEnable; + for (timeout = 0; timeout < 20; timeout++) { + if (fpga->acqControl & DAQBOARD2000_AcqLogicScanning) { + break; + } + //comedi_udelay(2); + } + for (timeout = 0; timeout < 20; timeout++) { + if (fpga-> + acqControl & + DAQBOARD2000_AcqResultsFIFOHasValidData) { + break; + } + //comedi_udelay(2); + } + data[i] = fpga->acqResultsFIFO; + fpga->acqControl = DAQBOARD2000_AdcPacerDisable; + fpga->acqControl = DAQBOARD2000_SeqStopScanList; + } + return i; +} -static int daqboard2000_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int daqboard2000_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); + int i; + int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[chan]; - } + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[chan]; + } - return i; + return i; } -static int daqboard2000_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int daqboard2000_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); - daqboard2000_hw *fpga = devpriv->daq; - int timeout; - - for(i=0;in;i++){ - /* - * OK, since it works OK without enabling the DAC's, let's keep - * it as simple as possible... - */ - //fpga->dacControl = (chan + 2) * 0x0010 | 0x0001; comedi_udelay(1000); - fpga->dacSetting[chan] = data[i]; - for (timeout = 0 ; timeout < 20 ; timeout++) { - if ((fpga->dacControl & ((chan + 1) * 0x0010)) == 0) { break; } - //comedi_udelay(2); - } - devpriv->ao_readback[chan] = data[i]; - /* - * Since we never enabled the DAC's, we don't need to disable it... - * fpga->dacControl = (chan + 2) * 0x0010 | 0x0000; comedi_udelay(1000); - */ - } - - return i; + int i; + int chan = CR_CHAN(insn->chanspec); + daqboard2000_hw *fpga = devpriv->daq; + int timeout; + + for (i = 0; i < insn->n; i++) { + /* + * OK, since it works OK without enabling the DAC's, let's keep + * it as simple as possible... + */ + //fpga->dacControl = (chan + 2) * 0x0010 | 0x0001; comedi_udelay(1000); + fpga->dacSetting[chan] = data[i]; + for (timeout = 0; timeout < 20; timeout++) { + if ((fpga->dacControl & ((chan + 1) * 0x0010)) == 0) { + break; + } + //comedi_udelay(2); + } + devpriv->ao_readback[chan] = data[i]; + /* + * Since we never enabled the DAC's, we don't need to disable it... + * fpga->dacControl = (chan + 2) * 0x0010 | 0x0000; comedi_udelay(1000); + */ + } + + return i; } -static void daqboard2000_resetLocalBus(comedi_device *dev) +static void daqboard2000_resetLocalBus(comedi_device * dev) { - printk("daqboard2000_resetLocalBus\n"); - writel(DAQBOARD2000_SECRLocalBusHi, devpriv->plx + 0x6c); - comedi_udelay(10000); - writel(DAQBOARD2000_SECRLocalBusLo, devpriv->plx + 0x6c); - comedi_udelay(10000); + printk("daqboard2000_resetLocalBus\n"); + writel(DAQBOARD2000_SECRLocalBusHi, devpriv->plx + 0x6c); + comedi_udelay(10000); + writel(DAQBOARD2000_SECRLocalBusLo, devpriv->plx + 0x6c); + comedi_udelay(10000); } -static void daqboard2000_reloadPLX(comedi_device *dev) +static void daqboard2000_reloadPLX(comedi_device * dev) { - printk("daqboard2000_reloadPLX\n"); - writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); - comedi_udelay(10000); - writel(DAQBOARD2000_SECRReloadHi, devpriv->plx + 0x6c); - comedi_udelay(10000); - writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); - comedi_udelay(10000); + printk("daqboard2000_reloadPLX\n"); + writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); + comedi_udelay(10000); + writel(DAQBOARD2000_SECRReloadHi, devpriv->plx + 0x6c); + comedi_udelay(10000); + writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); + comedi_udelay(10000); } -static void daqboard2000_pulseProgPin(comedi_device *dev) +static void daqboard2000_pulseProgPin(comedi_device * dev) { - printk("daqboard2000_pulseProgPin 1\n"); - writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c); - comedi_udelay(10000); - writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c); - comedi_udelay(10000); /* Not in the original code, but I like symmetry... */ + printk("daqboard2000_pulseProgPin 1\n"); + writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c); + comedi_udelay(10000); + writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c); + comedi_udelay(10000); /* Not in the original code, but I like symmetry... */ } -static int daqboard2000_pollCPLD(comedi_device *dev, int mask) { - int result = 0; - int i; - int cpld; - - /* timeout after 50 tries -> 5ms */ - for (i = 0 ; i < 50 ; i++) { - cpld = readw(devpriv->daq + 0x1000); - if ((cpld & mask) == mask){ - result=1; - break; - } - comedi_udelay(100); - } - comedi_udelay(5); - return result; +static int daqboard2000_pollCPLD(comedi_device * dev, int mask) +{ + int result = 0; + int i; + int cpld; + + /* timeout after 50 tries -> 5ms */ + for (i = 0; i < 50; i++) { + cpld = readw(devpriv->daq + 0x1000); + if ((cpld & mask) == mask) { + result = 1; + break; + } + comedi_udelay(100); + } + comedi_udelay(5); + return result; } -static int daqboard2000_writeCPLD(comedi_device *dev, int data) +static int daqboard2000_writeCPLD(comedi_device * dev, int data) { - int result = 0; - - comedi_udelay(10); - writew(data, devpriv->daq + 0x1000); - if ((readw(devpriv->daq + 0x1000) & DAQBOARD2000_CPLD_INIT) == - DAQBOARD2000_CPLD_INIT) { - result = 1; - } - return result; + int result = 0; + + comedi_udelay(10); + writew(data, devpriv->daq + 0x1000); + if ((readw(devpriv->daq + 0x1000) & DAQBOARD2000_CPLD_INIT) == + DAQBOARD2000_CPLD_INIT) { + result = 1; + } + return result; } -static int initialize_daqboard2000(comedi_device *dev, - unsigned char *cpld_array,int len) +static int initialize_daqboard2000(comedi_device * dev, + unsigned char *cpld_array, int len) { - int result = -EIO; - /* Read the serial EEPROM control register */ - int secr; - int retry; - int i; - - /* Check to make sure the serial eeprom is present on the board */ - secr = readl(devpriv->plx + 0x6c); - if (!(secr & DAQBOARD2000_EEPROM_PRESENT)) { + int result = -EIO; + /* Read the serial EEPROM control register */ + int secr; + int retry; + int i; + + /* Check to make sure the serial eeprom is present on the board */ + secr = readl(devpriv->plx + 0x6c); + if (!(secr & DAQBOARD2000_EEPROM_PRESENT)) { #ifdef DEBUG_EEPROM - printk("no serial eeprom\n"); + printk("no serial eeprom\n"); #endif - return -EIO; - } + return -EIO; + } - for (retry = 0 ; retry < 3 ; retry++) { + for (retry = 0; retry < 3; retry++) { #ifdef DEBUG_EEPROM - printk("Programming EEPROM try %x\n", retry); + printk("Programming EEPROM try %x\n", retry); #endif - daqboard2000_resetLocalBus(dev); - daqboard2000_reloadPLX(dev); - daqboard2000_pulseProgPin(dev); - if(daqboard2000_pollCPLD(dev, DAQBOARD2000_CPLD_INIT)) { - for (i = 0 ; i < len ; i++) { - if (cpld_array[i] == 0xff && cpld_array[i+1] == 0x20) { + daqboard2000_resetLocalBus(dev); + daqboard2000_reloadPLX(dev); + daqboard2000_pulseProgPin(dev); + if (daqboard2000_pollCPLD(dev, DAQBOARD2000_CPLD_INIT)) { + for (i = 0; i < len; i++) { + if (cpld_array[i] == 0xff + && cpld_array[i + 1] == 0x20) { #ifdef DEBUG_EEPROM - printk("Preamble found at %d\n", i); + printk("Preamble found at %d\n", i); #endif - break; - } - } - for ( ; i < len ; i += 2) { - int data = (cpld_array[i]<<8) + cpld_array[i+1]; - if (!daqboard2000_writeCPLD(dev, data)) { - break; - } - } - if (i >= len) { + break; + } + } + for (; i < len; i += 2) { + int data = + (cpld_array[i] << 8) + cpld_array[i + + 1]; + if (!daqboard2000_writeCPLD(dev, data)) { + break; + } + } + if (i >= len) { #ifdef DEBUG_EEPROM - printk("Programmed\n"); + printk("Programmed\n"); #endif - daqboard2000_resetLocalBus(dev); - daqboard2000_reloadPLX(dev); - result = 0; - break; - } - } - } - return result; + daqboard2000_resetLocalBus(dev); + daqboard2000_reloadPLX(dev); + result = 0; + break; + } + } + } + return result; } - -static void daqboard2000_adcStopDmaTransfer(comedi_device *dev) +static void daqboard2000_adcStopDmaTransfer(comedi_device * dev) { /* printk("Implement: daqboard2000_adcStopDmaTransfer\n");*/ } -static void daqboard2000_adcDisarm(comedi_device *dev) +static void daqboard2000_adcDisarm(comedi_device * dev) { - daqboard2000_hw *fpga = devpriv->daq; + daqboard2000_hw *fpga = devpriv->daq; - /* Disable hardware triggers */ - comedi_udelay(2); - fpga->trigControl = DAQBOARD2000_TrigAnalog | DAQBOARD2000_TrigDisable; - comedi_udelay(2); - fpga->trigControl = DAQBOARD2000_TrigTTL | DAQBOARD2000_TrigDisable; + /* Disable hardware triggers */ + comedi_udelay(2); + fpga->trigControl = DAQBOARD2000_TrigAnalog | DAQBOARD2000_TrigDisable; + comedi_udelay(2); + fpga->trigControl = DAQBOARD2000_TrigTTL | DAQBOARD2000_TrigDisable; - /* Stop the scan list FIFO from loading the configuration pipe */ - comedi_udelay(2); - fpga->acqControl = DAQBOARD2000_SeqStopScanList; + /* Stop the scan list FIFO from loading the configuration pipe */ + comedi_udelay(2); + fpga->acqControl = DAQBOARD2000_SeqStopScanList; - /* Stop the pacer clock */ - comedi_udelay(2); - fpga->acqControl = DAQBOARD2000_AdcPacerDisable; - - /* Stop the input dma (abort channel 1) */ - daqboard2000_adcStopDmaTransfer(dev); + /* Stop the pacer clock */ + comedi_udelay(2); + fpga->acqControl = DAQBOARD2000_AdcPacerDisable; + + /* Stop the input dma (abort channel 1) */ + daqboard2000_adcStopDmaTransfer(dev); } -static void daqboard2000_activateReferenceDacs(comedi_device *dev) +static void daqboard2000_activateReferenceDacs(comedi_device * dev) { - daqboard2000_hw *fpga = devpriv->daq; - int timeout; - - // Set the + reference dac value in the FPGA - fpga->refDacs = 0x80 | DAQBOARD2000_PosRefDacSelect; - for (timeout = 0 ; timeout < 20 ; timeout++) { - if ((fpga->dacControl & DAQBOARD2000_RefBusy) == 0) { break; } - comedi_udelay(2); - } + daqboard2000_hw *fpga = devpriv->daq; + int timeout; + + // Set the + reference dac value in the FPGA + fpga->refDacs = 0x80 | DAQBOARD2000_PosRefDacSelect; + for (timeout = 0; timeout < 20; timeout++) { + if ((fpga->dacControl & DAQBOARD2000_RefBusy) == 0) { + break; + } + comedi_udelay(2); + } /* printk("DAQBOARD2000_PosRefDacSelect %d\n", timeout);*/ - // Set the - reference dac value in the FPGA - fpga->refDacs = 0x80 | DAQBOARD2000_NegRefDacSelect; - for (timeout = 0 ; timeout < 20 ; timeout++) { - if ((fpga->dacControl & DAQBOARD2000_RefBusy) == 0) { break; } - comedi_udelay(2); - } + // Set the - reference dac value in the FPGA + fpga->refDacs = 0x80 | DAQBOARD2000_NegRefDacSelect; + for (timeout = 0; timeout < 20; timeout++) { + if ((fpga->dacControl & DAQBOARD2000_RefBusy) == 0) { + break; + } + comedi_udelay(2); + } /* printk("DAQBOARD2000_NegRefDacSelect %d\n", timeout);*/ } -static void daqboard2000_initializeCtrs(comedi_device *dev) +static void daqboard2000_initializeCtrs(comedi_device * dev) { /* printk("Implement: daqboard2000_initializeCtrs\n");*/ } -static void daqboard2000_initializeTmrs(comedi_device *dev) +static void daqboard2000_initializeTmrs(comedi_device * dev) { /* printk("Implement: daqboard2000_initializeTmrs\n");*/ } -static void daqboard2000_dacDisarm(comedi_device *dev) +static void daqboard2000_dacDisarm(comedi_device * dev) { /* printk("Implement: daqboard2000_dacDisarm\n");*/ } -static void daqboard2000_initializeAdc(comedi_device *dev) +static void daqboard2000_initializeAdc(comedi_device * dev) { - daqboard2000_adcDisarm(dev); - daqboard2000_activateReferenceDacs(dev); - daqboard2000_initializeCtrs(dev); - daqboard2000_initializeTmrs(dev); + daqboard2000_adcDisarm(dev); + daqboard2000_activateReferenceDacs(dev); + daqboard2000_initializeCtrs(dev); + daqboard2000_initializeTmrs(dev); } -static void daqboard2000_initializeDac(comedi_device *dev) +static void daqboard2000_initializeDac(comedi_device * dev) { - daqboard2000_dacDisarm(dev); + daqboard2000_dacDisarm(dev); } /* @@ -665,153 +696,155 @@ The test command, REMOVE!!: rmmod daqboard2000 ; rmmod comedi; make install ; modprobe daqboard2000; /usr/sbin/comedi_config /dev/comedi0 daqboard/2000 ; tail -40 /var/log/messages */ -static int daqboard2000_8255_cb(int dir, int port, int data, unsigned long ioaddr) +static int daqboard2000_8255_cb(int dir, int port, int data, + unsigned long ioaddr) { - int result = 0; - if(dir){ - writew(data,((void*)ioaddr)+port*2); - result = 0; - }else{ - result = readw(((void*)ioaddr)+port*2); - } + int result = 0; + if (dir) { + writew(data, ((void *)ioaddr) + port * 2); + result = 0; + } else { + result = readw(((void *)ioaddr) + port * 2); + } /* printk("daqboard2000_8255_cb %x %d %d %2.2x -> %2.2x\n", arg, dir, port, data, result); */ - return result; + return result; } -static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) +static int daqboard2000_attach(comedi_device * dev, comedi_devconfig * it) { int result = 0; comedi_subdevice *s; struct pci_dev *card = NULL; void *aux_data; unsigned int aux_len; - + printk("comedi%d: daqboard2000:", dev->minor); - - result = alloc_private(dev,sizeof(daqboard2000_private)); - if(result < 0){ + + result = alloc_private(dev, sizeof(daqboard2000_private)); + if (result < 0) { return -ENOMEM; } /* FIXME: we should handle multiple cards, have to make David decide - how, so we will be consistent among all PCI card drivers... */ + how, so we will be consistent among all PCI card drivers... */ card = pci_get_device(0x1616, 0x0409, NULL); if (!card) { printk(" no daqboard2000 found\n"); return -EIO; - }else{ + } else { u32 id; int i; devpriv->pci_dev = card; - id = ((u32)card->subsystem_device << 16) | card->subsystem_vendor; - for(i=0;iboard_ptr=boardtypes+i; + id = ((u32) card->subsystem_device << 16) | card-> + subsystem_vendor; + for (i = 0; i < n_boardtypes; i++) { + if (boardtypes[i].id == id) { + printk(" %s", boardtypes[i].name); + dev->board_ptr = boardtypes + i; } } - if(!dev->board_ptr){ - printk(" unknown subsystem id %08x (pretend it is an ids2)",id); - dev->board_ptr=boardtypes; + if (!dev->board_ptr) { + printk(" unknown subsystem id %08x (pretend it is an ids2)", id); + dev->board_ptr = boardtypes; } } - - if((result = comedi_pci_enable(card, "daqboard2000")) < 0) { + if ((result = comedi_pci_enable(card, "daqboard2000")) < 0) { printk(" failed to enable PCI device and request regions\n"); - return -EIO; + return -EIO; } devpriv->got_regions = 1; - devpriv->plx = ioremap(pci_resource_start(card,0), DAQBOARD2000_PLX_SIZE); - devpriv->daq = ioremap(pci_resource_start(card,2), DAQBOARD2000_DAQ_SIZE); - if(!devpriv->plx || !devpriv->daq){ + devpriv->plx = + ioremap(pci_resource_start(card, 0), DAQBOARD2000_PLX_SIZE); + devpriv->daq = + ioremap(pci_resource_start(card, 2), DAQBOARD2000_DAQ_SIZE); + if (!devpriv->plx || !devpriv->daq) { return -ENOMEM; } result = alloc_subdevices(dev, 3); - if(result<0)goto out; - + if (result < 0) + goto out; + readl(devpriv->plx + 0x6c); - /* - u8 interrupt; - Windows code does restore interrupts, but since we don't use them... - pci_read_config_byte(card, PCI_INTERRUPT_LINE, &interrupt); - printk("Interrupt before is: %x\n", interrupt); - */ - - aux_data = comedi_aux_data(it->options, 0); - aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; - - if(aux_data && aux_len){ - result = initialize_daqboard2000(dev, aux_data, aux_len); - }else{ - printk("no FPGA initialization code, aborting\n"); - result=-EIO; - } - if(result<0)goto out; - daqboard2000_initializeAdc(dev); - daqboard2000_initializeDac(dev); - /* - Windows code does restore interrupts, but since we don't use them... - pci_read_config_byte(card, PCI_INTERRUPT_LINE, &interrupt); - printk("Interrupt after is: %x\n", interrupt); - */ - - dev->iobase = (unsigned long)devpriv->daq; - - dev->board_name = this_board->name; - - s = dev->subdevices + 0; - /* ai subdevice */ - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_GROUND; - s->n_chan = 24; - s->maxdata = 0xffff; - s->insn_read = daqboard2000_ai_insn_read; - s->range_table = &range_daqboard2000_ai; - - s = dev->subdevices + 1; - /* ao subdevice */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 2; - s->maxdata = 0xffff; - s->insn_read = daqboard2000_ao_insn_read; - s->insn_write = daqboard2000_ao_insn_write; - s->range_table = &range_daqboard2000_ao; - - s = dev->subdevices + 2; - result = subdev_8255_init(dev,s,daqboard2000_8255_cb, - (unsigned long)(dev->iobase+0x40)); - - printk("\n"); -out: - return result; + /* + u8 interrupt; + Windows code does restore interrupts, but since we don't use them... + pci_read_config_byte(card, PCI_INTERRUPT_LINE, &interrupt); + printk("Interrupt before is: %x\n", interrupt); + */ + + aux_data = comedi_aux_data(it->options, 0); + aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + + if (aux_data && aux_len) { + result = initialize_daqboard2000(dev, aux_data, aux_len); + } else { + printk("no FPGA initialization code, aborting\n"); + result = -EIO; + } + if (result < 0) + goto out; + daqboard2000_initializeAdc(dev); + daqboard2000_initializeDac(dev); + /* + Windows code does restore interrupts, but since we don't use them... + pci_read_config_byte(card, PCI_INTERRUPT_LINE, &interrupt); + printk("Interrupt after is: %x\n", interrupt); + */ + + dev->iobase = (unsigned long)devpriv->daq; + + dev->board_name = this_board->name; + + s = dev->subdevices + 0; + /* ai subdevice */ + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 24; + s->maxdata = 0xffff; + s->insn_read = daqboard2000_ai_insn_read; + s->range_table = &range_daqboard2000_ai; + + s = dev->subdevices + 1; + /* ao subdevice */ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->maxdata = 0xffff; + s->insn_read = daqboard2000_ao_insn_read; + s->insn_write = daqboard2000_ao_insn_write; + s->range_table = &range_daqboard2000_ao; + + s = dev->subdevices + 2; + result = subdev_8255_init(dev, s, daqboard2000_8255_cb, + (unsigned long)(dev->iobase + 0x40)); + + printk("\n"); + out: + return result; } static int daqboard2000_detach(comedi_device * dev) { printk("comedi%d: daqboard2000: remove\n", dev->minor); - - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices+2); - + + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 2); + if (dev->irq) { free_irq(dev->irq, dev); } - if(devpriv) - { - if(devpriv->daq) + if (devpriv) { + if (devpriv->daq) iounmap(devpriv->daq); - if(devpriv->plx) + if (devpriv->plx) iounmap(devpriv->plx); - if(devpriv->pci_dev) - { - if(devpriv->got_regions) - { + if (devpriv->pci_dev) { + if (devpriv->got_regions) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); @@ -821,4 +854,3 @@ static int daqboard2000_detach(comedi_device * dev) } COMEDI_INITCLEANUP(driver_daqboard2000); - diff --git a/comedi/drivers/das08.c b/comedi/drivers/das08.c index 9623127c..1041e237 100644 --- a/comedi/drivers/das08.c +++ b/comedi/drivers/das08.c @@ -46,7 +46,6 @@ Options (for pci-das08): [1] = slot (optional) Use the name 'pci-das08' for the pci-das08, NOT 'das08'. - The das08 driver doesn't support asynchronous commands, since the cheap das08 hardware doesn't really support them. The comedi_rt_timer driver can be used to emulate commands for this @@ -75,7 +74,6 @@ driver. #define CNTRL_DIR 0x2 #define CNTRL_INTR 0x4 - /* cio-das08.pdf @@ -155,67 +153,78 @@ driver. /* 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); -static void i8254_set_mode_low(unsigned int base, int channel, unsigned int mode); +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); +static void i8254_set_mode_low(unsigned int base, int channel, + unsigned int mode); static const 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) -}}; + 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 const 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), -}}; + 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 const 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 + 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" + "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 + 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 -*/ + */ -static const comedi_lrange * const das08_ai_lranges[]={ +static const comedi_lrange *const das08_ai_lranges[] = { &range_unknown, &range_bipolar5, &range_das08_pgh, @@ -223,11 +232,12 @@ static const comedi_lrange * const das08_ai_lranges[]={ &range_das08_pgm, }; -static const int das08_pgh_gainlist[] = { 8, 0, 10, 2, 12, 4, 14, 6, 1, 3, 5, 7 }; +static const int das08_pgh_gainlist[] = + { 8, 0, 10, 2, 12, 4, 14, 6, 1, 3, 5, 7 }; static const int das08_pgl_gainlist[] = { 8, 0, 2, 4, 6, 1, 3, 5, 7 }; static const int das08_pgm_gainlist[] = { 8, 0, 10, 12, 14, 9, 11, 13, 15 }; -static const int * const das08_gainlists[] = { +static const int *const das08_gainlists[] = { NULL, NULL, das08_pgh_gainlist, @@ -235,257 +245,259 @@ static const int * const das08_gainlists[] = { das08_pgm_gainlist, }; -static const struct das08_board_struct das08_boards[]={ +static const 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", // 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-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-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-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-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-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-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: "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: "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, - }, + 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, + }, { - 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 - }, + 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: "das08/f", + }, { - name: "das08jr", - }, + 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 - }, + 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 { - name: "das48-pga", // cio-das48-pga.pdf - }, + name: "das48-pga", // cio-das48-pga.pdf + }, { - name: "das08-pga-g2", // a KM board - }, + name: "das08-pga-g2", // a KM board + }, #endif }; -struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS]={ +struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS] = { { - 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, - }, + 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, + }, // duplicate so driver name can be used also { - name: "das08_cs", - 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, - }, + name: "das08_cs", + 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, + }, }; static struct pci_device_id das08_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_COMPUTERBOARDS, PCI_DEVICE_ID_PCIDAS08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_COMPUTERBOARDS, PCI_DEVICE_ID_PCIDAS08, PCI_ANY_ID, + PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, das08_pci_table); #define devpriv ((struct das08_private_struct *)dev->private) @@ -493,63 +505,65 @@ MODULE_DEVICE_TABLE(pci, das08_pci_table); #define TIMEOUT 100000 -static int das08_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das08_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,n; + int i, n; int chan; int range; - int lsb,msb; + int lsb, msb; chan = CR_CHAN(insn->chanspec); range = CR_RANGE(insn->chanspec); /* clear crap */ - inb(dev->iobase+DAS08_LSB); - inb(dev->iobase+DAS08_MSB); + inb(dev->iobase + DAS08_LSB); + inb(dev->iobase + DAS08_MSB); /* set multiplexer */ spin_lock(&dev->spinlock); // lock to prevent race with digital output devpriv->do_mux_bits &= ~DAS08_MUX_MASK; devpriv->do_mux_bits |= DAS08_MUX(chan); - outb(devpriv->do_mux_bits,dev->iobase+DAS08_CONTROL); + outb(devpriv->do_mux_bits, dev->iobase + DAS08_CONTROL); spin_unlock(&dev->spinlock); - if(s->range_table->length > 1){ + if (s->range_table->length > 1) { /* set gain/range */ range = CR_RANGE(insn->chanspec); - outb(devpriv->pg_gainlist[range],dev->iobase+DAS08AO_GAIN_CONTROL); + outb(devpriv->pg_gainlist[range], + dev->iobase + DAS08AO_GAIN_CONTROL); } - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* clear over-range bits for 16-bit boards */ if (thisboard->ai_nbits == 16) if (inb(dev->iobase + DAS08_MSB) & 0x80) rt_printk("das08: over-range\n"); /* trigger conversion */ - outb_p(0,dev->iobase+DAS08_TRIG_12BIT); + outb_p(0, dev->iobase + DAS08_TRIG_12BIT); - for(i=0;iiobase+DAS08_STATUS)&DAS08_EOC)) + for (i = 0; i < TIMEOUT; i++) { + if (!(inb(dev->iobase + DAS08_STATUS) & DAS08_EOC)) break; } - if(i==TIMEOUT){ + if (i == TIMEOUT) { rt_printk("das08: timeout\n"); return -ETIME; } msb = inb(dev->iobase + DAS08_MSB); lsb = inb(dev->iobase + DAS08_LSB); - if(thisboard->ai_encoding == das08_encode12){ - data[n] = (lsb>>4) | (msb << 4); - }else if(thisboard->ai_encoding == das08_pcm_encode12){ + if (thisboard->ai_encoding == das08_encode12) { + data[n] = (lsb >> 4) | (msb << 4); + } else if (thisboard->ai_encoding == das08_pcm_encode12) { data[n] = (msb << 8) + lsb; - }else if(thisboard->ai_encoding == das08_encode16){ + } else if (thisboard->ai_encoding == das08_encode16) { /* FPOS 16-bit boards are sign-magnitude */ if (msb & 0x80) data[n] = (1 << 15) | lsb | ((msb & 0x7f) << 8); else data[n] = (1 << 15) - (lsb | (msb & 0x7f) << 8); - }else{ + } else { comedi_error(dev, "bug! unknown ai encoding"); return -1; } @@ -558,15 +572,17 @@ static int das08_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return n; } -static int das08_di_rbits(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) { data[0] = 0; - data[1] = DAS08_IP(inb(dev->iobase+DAS08_STATUS)); + data[1] = DAS08_IP(inb(dev->iobase + DAS08_STATUS)); return 2; } -static int das08_do_wbits(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) { int wbits; @@ -588,7 +604,8 @@ static int das08_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return 2; } -static int das08jr_di_rbits(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) { data[0] = 0; data[1] = inb(dev->iobase + DAS08JR_DIO); @@ -596,7 +613,8 @@ static int das08jr_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn * return 2; } -static int das08jr_do_wbits(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) { // null bits we are going to set devpriv->do_bits &= ~data[0]; @@ -609,28 +627,29 @@ static int das08jr_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn * return 2; } -static int das08jr_ao_winsn(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) { int n; - int lsb,msb; + int lsb, msb; int chan; - lsb=data[0]&0xff; - msb=(data[0]>>8)&0xf; + lsb = data[0] & 0xff; + msb = (data[0] >> 8) & 0xf; - chan=CR_CHAN(insn->chanspec); + chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { #if 0 - outb(lsb,dev->iobase+devpriv->ao_offset_lsb[chan]); - outb(msb,dev->iobase+devpriv->ao_offset_msb[chan]); + outb(lsb, dev->iobase + devpriv->ao_offset_lsb[chan]); + outb(msb, dev->iobase + devpriv->ao_offset_msb[chan]); #else - outb(lsb,dev->iobase+DAS08JR_AO_LSB(chan)); - outb(msb,dev->iobase+DAS08JR_AO_MSB(chan)); + outb(lsb, dev->iobase + DAS08JR_AO_LSB(chan)); + outb(msb, dev->iobase + DAS08JR_AO_MSB(chan)); #endif /* load DACs */ - inb(dev->iobase+DAS08JR_DIO); + inb(dev->iobase + DAS08JR_DIO); } return n; @@ -642,149 +661,157 @@ static int das08jr_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * * a different method to force an update. * */ -static int das08ao_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) { int n; - int lsb,msb; + int lsb, msb; int chan; - lsb=data[0]&0xff; - msb=(data[0]>>8)&0xf; + lsb = data[0] & 0xff; + msb = (data[0] >> 8) & 0xf; - chan=CR_CHAN(insn->chanspec); + chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { #if 0 - outb(lsb,dev->iobase+devpriv->ao_offset_lsb[chan]); - outb(msb,dev->iobase+devpriv->ao_offset_msb[chan]); + outb(lsb, dev->iobase + devpriv->ao_offset_lsb[chan]); + outb(msb, dev->iobase + devpriv->ao_offset_msb[chan]); #else - outb(lsb,dev->iobase+DAS08AO_AO_LSB(chan)); - outb(msb,dev->iobase+DAS08AO_AO_MSB(chan)); + outb(lsb, dev->iobase + DAS08AO_AO_LSB(chan)); + outb(msb, dev->iobase + DAS08AO_AO_MSB(chan)); #endif /* load DACs */ - inb(dev->iobase+DAS08AO_AO_UPDATE); + inb(dev->iobase + DAS08AO_AO_UPDATE); } return n; } - static unsigned int i8254_read_channel_low(unsigned int base, int chan) { unsigned int msb, lsb; - /* The following instructions must be in order. - We must avoid other process reading the counter's value in the - middle. - The spin_lock isn't needed since ioctl calls grab the big kernel - lock automatically */ - /*spin_lock(sp);*/ - outb(chan<<6,base+I8254_CTRL); - base+=chan; - lsb=inb(base); - msb=inb(base); - /*spin_unlock(sp);*/ - - return lsb | (msb<<8); + /* The following instructions must be in order. + We must avoid other process reading the counter's value in the + middle. + The spin_lock isn't needed since ioctl calls grab the big kernel + lock automatically */ + /*spin_lock(sp); */ + outb(chan << 6, base + I8254_CTRL); + base += chan; + lsb = inb(base); + msb = inb(base); + /*spin_unlock(sp); */ + + return lsb | (msb << 8); } -static void i8254_write_channel_low(unsigned int base, int chan, unsigned int value) +static void i8254_write_channel_low(unsigned int base, int chan, + unsigned int value) { unsigned int msb, lsb; - lsb=value & 0xFF; - msb=value>>8; + lsb = value & 0xFF; + msb = value >> 8; /* write lsb, then msb */ - base+=chan; - /* See comments in i8254_read_channel_low */ - /*spin_lock(sp);*/ - outb(lsb,base); - outb(msb,base); - /*spin_unlock(sp);*/ + base += chan; + /* See comments in i8254_read_channel_low */ + /*spin_lock(sp); */ + outb(lsb, base); + outb(msb, base); + /*spin_unlock(sp); */ } static unsigned int i8254_read_channel(struct i8254_struct *st, int channel) { - int chan=st->logic2phys[channel]; + int chan = st->logic2phys[channel]; - return i8254_read_channel_low(st->iobase,chan); + return i8254_read_channel_low(st->iobase, chan); } -static void i8254_write_channel(struct i8254_struct *st, int channel, unsigned int value) +static void i8254_write_channel(struct i8254_struct *st, int channel, + unsigned int value) { - int chan=st->logic2phys[channel]; + int chan = st->logic2phys[channel]; - i8254_write_channel_low(st->iobase,chan,value); + i8254_write_channel_low(st->iobase, chan, value); } static void i8254_initialize(struct i8254_struct *st) { int i; - for(i = 0 ; i < 3; ++i) + for (i = 0; i < 3; ++i) i8254_set_mode_low(st->iobase, i, st->mode[i]); } -static void i8254_set_mode_low(unsigned int base, int channel, unsigned int mode) +static void i8254_set_mode_low(unsigned int base, int channel, + unsigned int mode) { - outb((channel<<6) | 0x30 | (mode & 0x0F),base+I8254_CTRL); + outb((channel << 6) | 0x30 | (mode & 0x0F), base + I8254_CTRL); } -static void i8254_set_mode(struct i8254_struct *st, int channel, unsigned int mode) +static void i8254_set_mode(struct i8254_struct *st, int channel, + unsigned int mode) { - int chan=st->logic2phys[channel]; + int chan = st->logic2phys[channel]; - st->mode[chan]=mode; - return i8254_set_mode_low(st->iobase,chan,mode); + st->mode[chan] = mode; + return i8254_set_mode_low(st->iobase, chan, mode); } static unsigned int i8254_read_status_low(unsigned int base, int channel) { - outb(0xE0 | (2<logic2phys[channel]; + int chan = st->logic2phys[channel]; - return i8254_read_status_low(st->iobase,chan); + return i8254_read_status_low(st->iobase, chan); } -static int das08_counter_read(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int das08_counter_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=insn->chanspec; + int chan = insn->chanspec; - //printk("Reading counter channel %d ",chan); - data[0]=i8254_read_channel(&devpriv->i8254,chan); - //printk("=> 0x%08X\n",data[0]); + //printk("Reading counter channel %d ",chan); + data[0] = i8254_read_channel(&devpriv->i8254, chan); + //printk("=> 0x%08X\n",data[0]); return 1; } -static int das08_counter_write(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int das08_counter_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=insn->chanspec; + int chan = insn->chanspec; - //printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); - i8254_write_channel(&devpriv->i8254,chan,data[0]); + //printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); + i8254_write_channel(&devpriv->i8254, chan, data[0]); return 1; } -static int das08_counter_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das08_counter_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=insn->chanspec; + int chan = insn->chanspec; - if(insn->n != 2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - switch (data[0]){ + switch (data[0]) { case INSN_CONFIG_SET_COUNTER_MODE: - i8254_set_mode(&devpriv->i8254,chan,data[1]); + i8254_set_mode(&devpriv->i8254, chan, data[1]); break; case INSN_CONFIG_8254_READ_STATUS: - data[1]=i8254_read_status(&devpriv->i8254,chan); + data[1] = i8254_read_status(&devpriv->i8254, chan); break; default: return -EINVAL; @@ -793,28 +820,28 @@ static int das08_counter_config(comedi_device *dev,comedi_subdevice *s,comedi_in return 2; } -static int das08_attach(comedi_device *dev,comedi_devconfig *it); - -static comedi_driver driver_das08={ - driver_name: "das08", - module: THIS_MODULE, - attach: das08_attach, - detach: das08_common_detach, - board_name: &das08_boards[0].name, - num_names: sizeof(das08_boards)/sizeof(struct das08_board_struct), - offset: sizeof(struct das08_board_struct), +static int das08_attach(comedi_device * dev, comedi_devconfig * it); + +static comedi_driver driver_das08 = { + driver_name:"das08", + module:THIS_MODULE, + attach:das08_attach, + detach:das08_common_detach, + board_name:&das08_boards[0].name, + num_names:sizeof(das08_boards) / + sizeof(struct das08_board_struct), + offset:sizeof(struct das08_board_struct), }; -int das08_common_attach(comedi_device *dev, unsigned long iobase ) +int das08_common_attach(comedi_device * dev, unsigned long iobase) { comedi_subdevice *s; int ret; // allocate ioports for non-pcmcia, non-pci boards - if((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) - { + if ((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) { printk(" iobase 0x%lx\n", iobase); - if(!request_region(iobase, thisboard->iosize,"das08")){ + if (!request_region(iobase, thisboard->iosize, "das08")) { printk(" I/O port conflict\n"); return -EIO; } @@ -823,77 +850,77 @@ int das08_common_attach(comedi_device *dev, unsigned long iobase ) dev->board_name = thisboard->name; - if((ret=alloc_subdevices(dev, 6))<0) + if ((ret = alloc_subdevices(dev, 6)) < 0) return ret; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* ai */ - if(thisboard->ai){ - s->type=COMEDI_SUBD_AI; - /* XXX some boards actually have differential inputs instead of single ended. - * The driver does nothing with arefs though, so it's no big deal. */ + if (thisboard->ai) { + s->type = COMEDI_SUBD_AI; + /* XXX some boards actually have differential inputs instead of single ended. + * The driver does nothing with arefs though, so it's no big deal. */ s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = 8; - s->maxdata = (1<ai_nbits)-1; + s->maxdata = (1 << thisboard->ai_nbits) - 1; s->range_table = das08_ai_lranges[thisboard->ai_pg]; s->insn_read = thisboard->ai; devpriv->pg_gainlist = das08_gainlists[thisboard->ai_pg]; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+1; + s = dev->subdevices + 1; /* ao */ - if(thisboard->ao){ - s->type=COMEDI_SUBD_AO; + if (thisboard->ao) { + s->type = COMEDI_SUBD_AO; // XXX lacks read-back insn s->subdev_flags = SDF_WRITABLE; s->n_chan = 2; - s->maxdata = (1<ao_nbits)-1; + s->maxdata = (1 << thisboard->ao_nbits) - 1; s->range_table = &range_bipolar5; s->insn_write = thisboard->ao; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+2; + s = dev->subdevices + 2; /* di */ - if(thisboard->di){ - s->type=COMEDI_SUBD_DI; + if (thisboard->di) { + s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; - s->n_chan = (thisboard->di==das08_di_rbits)?3:8; + s->n_chan = (thisboard->di == das08_di_rbits) ? 3 : 8; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = thisboard->di; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+3; + s = dev->subdevices + 3; /* do */ - if(thisboard->do_){ - s->type=COMEDI_SUBD_DO; + if (thisboard->do_) { + s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = thisboard->do_nchan; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = thisboard->do_; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+4; + s = dev->subdevices + 4; /* 8255 */ - if(thisboard->i8255_offset!=0){ - subdev_8255_init(dev,s,NULL,(unsigned long)(dev->iobase+ - thisboard->i8255_offset)); - }else{ - s->type=COMEDI_SUBD_UNUSED; + if (thisboard->i8255_offset != 0) { + subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + + thisboard->i8255_offset)); + } else { + s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices+5; + s = dev->subdevices + 5; /* 8254 */ - if(thisboard->i8254_offset!=0){ + if (thisboard->i8254_offset != 0) { s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 3; @@ -901,63 +928,64 @@ int das08_common_attach(comedi_device *dev, unsigned long iobase ) s->insn_read = das08_counter_read; s->insn_write = das08_counter_write; s->insn_config = das08_counter_config; - /* Set-up the 8254 structure */ - devpriv->i8254.channels=3; - devpriv->i8254.logic2phys[0]=0; - devpriv->i8254.logic2phys[1]=1; - devpriv->i8254.logic2phys[2]=2; - devpriv->i8254.iobase=iobase+thisboard->i8254_offset; - devpriv->i8254.mode[0]= - devpriv->i8254.mode[1]= - devpriv->i8254.mode[2]=I8254_MODE0 | I8254_BINARY; - i8254_initialize(&devpriv->i8254); - }else{ - s->type=COMEDI_SUBD_UNUSED; + /* Set-up the 8254 structure */ + devpriv->i8254.channels = 3; + devpriv->i8254.logic2phys[0] = 0; + devpriv->i8254.logic2phys[1] = 1; + devpriv->i8254.logic2phys[2] = 2; + devpriv->i8254.iobase = iobase + thisboard->i8254_offset; + devpriv->i8254.mode[0] = + devpriv->i8254.mode[1] = + devpriv->i8254.mode[2] = I8254_MODE0 | I8254_BINARY; + i8254_initialize(&devpriv->i8254); + } else { + s->type = COMEDI_SUBD_UNUSED; } return 0; } -static int das08_attach(comedi_device *dev,comedi_devconfig *it) +static int das08_attach(comedi_device * dev, comedi_devconfig * it) { int ret; unsigned long iobase, pci_iobase = 0; struct pci_dev *pdev; - if((ret=alloc_private(dev,sizeof(struct das08_private_struct)))<0) + if ((ret = alloc_private(dev, sizeof(struct das08_private_struct))) < 0) return ret; printk("comedi%d: das08: ", dev->minor); // deal with a pci board - if(thisboard->bustype == pci) - { - if(it->options[0] || it->options[1]){ + if (thisboard->bustype == pci) { + if (it->options[0] || it->options[1]) { printk("bus %i slot %i ", it->options[0], it->options[1]); } printk("\n"); // find card - for(pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pdev != NULL ; + for (pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pdev != NULL; pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) { - if(pdev->vendor == PCI_VENDOR_ID_COMPUTERBOARDS && - pdev->device == PCI_DEVICE_ID_PCIDAS08){ - if(it->options[0] || it->options[1]){ - if(pdev->bus->number == it->options[0] && - PCI_SLOT(pdev->devfn) == it->options[1]){ + if (pdev->vendor == PCI_VENDOR_ID_COMPUTERBOARDS + && pdev->device == PCI_DEVICE_ID_PCIDAS08) { + if (it->options[0] || it->options[1]) { + if (pdev->bus->number == it->options[0] + && PCI_SLOT(pdev->devfn) == + it->options[1]) { break; } - }else{ + } else { break; } } } - if(!pdev){ + if (!pdev) { printk("No pci das08 cards found\n"); return -EIO; } devpriv->pdev = pdev; // enable PCI device and reserve I/O spaces - if(comedi_pci_enable(pdev, "das08")){ + if (comedi_pci_enable(pdev, "das08")) { printk(" Error enabling PCI device and requesting regions\n"); return -EIO; } @@ -975,34 +1003,32 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it) /* set source of interrupt trigger to counter2 output */ outb(CNTRL_INTR | CNTRL_DIR, pci_iobase + CNTRL); /* Enable local interrupt 1 and pci interrupt */ - outw(INTR1_ENABLE | PCI_INTR_ENABLE, pci_iobase + INTCSR ); + outw(INTR1_ENABLE | PCI_INTR_ENABLE, pci_iobase + INTCSR); #endif - }else{ + } else { iobase = it->options[0]; } printk("\n"); - return das08_common_attach( dev, iobase ); + return das08_common_attach(dev, iobase); } -int das08_common_detach(comedi_device *dev) +int das08_common_detach(comedi_device * dev) { - printk(KERN_INFO "comedi%d: das08: remove\n",dev->minor); + printk(KERN_INFO "comedi%d: das08: remove\n", dev->minor); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices+4); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 4); // deallocate ioports for non-pcmcia, non-pci boards - if((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) - { - if(dev->iobase) + if ((thisboard->bustype != pcmcia) && (thisboard->bustype != pci)) { + if (dev->iobase) release_region(dev->iobase, thisboard->iosize); } - if(devpriv){ - if(devpriv->pdev){ - if(devpriv->pci_iobase) - { + if (devpriv) { + if (devpriv->pdev) { + if (devpriv->pci_iobase) { comedi_pci_disable(devpriv->pdev); } pci_dev_put(devpriv->pdev); @@ -1014,7 +1040,6 @@ int das08_common_detach(comedi_device *dev) COMEDI_INITCLEANUP(driver_das08); -EXPORT_SYMBOL_GPL( das08_common_attach ); -EXPORT_SYMBOL_GPL( das08_common_detach ); -EXPORT_SYMBOL_GPL( das08_cs_boards ); - +EXPORT_SYMBOL_GPL(das08_common_attach); +EXPORT_SYMBOL_GPL(das08_common_detach); +EXPORT_SYMBOL_GPL(das08_cs_boards); diff --git a/comedi/drivers/das08.h b/comedi/drivers/das08.h index 34721282..6342fbaf 100644 --- a/comedi/drivers/das08.h +++ b/comedi/drivers/das08.h @@ -24,35 +24,35 @@ #ifndef _DAS08_H #define _DAS08_H -enum das08_bustype {isa, pci, pcmcia, pc104}; +enum das08_bustype { isa, pci, pcmcia, pc104 }; // different ways ai data is encoded in first two registers -enum das08_ai_encoding {das08_encode12, das08_encode16, das08_pcm_encode12}; -enum das08_lrange {das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, das08_pgm}; +enum das08_ai_encoding { das08_encode12, das08_encode16, das08_pcm_encode12 }; +enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, + das08_pgm }; -typedef struct das08_board_struct{ - const 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 +typedef struct das08_board_struct { + const 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; -struct i8254_struct -{ - int channels; // available channels. Some could be used internally. - int logic2phys[3]; // to know which physical channel is. - int mode[3]; // the index is the real counter. - unsigned int iobase; +struct i8254_struct { + int channels; // available channels. Some could be used internally. + int logic2phys[3]; // to know which physical channel is. + int mode[3]; // the index is the real counter. + unsigned int iobase; }; #define I8254_CNT0 0 @@ -60,19 +60,19 @@ struct i8254_struct #define I8254_CNT2 2 #define I8254_CTRL 3 -struct das08_private_struct{ - unsigned int do_mux_bits; // bits for do/mux register on boards without seperate do register - unsigned int do_bits; // bits for do register on boards with register dedicated to digital out only +struct das08_private_struct { + unsigned int do_mux_bits; // bits for do/mux register on boards without seperate do register + unsigned int do_bits; // bits for do register on boards with register dedicated to digital out only const unsigned int *pg_gainlist; struct pci_dev *pdev; // struct for pci-das08 - unsigned int pci_iobase; // additional base address for pci-das08 - struct i8254_struct i8254; + unsigned int pci_iobase; // additional base address for pci-das08 + struct i8254_struct i8254; }; #define NUM_DAS08_CS_BOARDS 2 extern struct das08_board_struct das08_cs_boards[NUM_DAS08_CS_BOARDS]; -int das08_common_attach(comedi_device *dev, unsigned long iobase ); -int das08_common_detach(comedi_device *dev); +int das08_common_attach(comedi_device * dev, unsigned long iobase); +int das08_common_detach(comedi_device * dev); -#endif /* _DAS08_H */ +#endif /* _DAS08_H */ diff --git a/comedi/drivers/das08_cs.c b/comedi/drivers/das08_cs.c index db72bfea..93fca06c 100644 --- a/comedi/drivers/das08_cs.c +++ b/comedi/drivers/das08_cs.c @@ -57,47 +57,45 @@ static struct pcmcia_device *cur_dev = NULL; #define thisboard ((const struct das08_board_struct *)dev->board_ptr) -static int das08_cs_attach(comedi_device *dev,comedi_devconfig *it); - -static comedi_driver driver_das08_cs = -{ - driver_name: "das08_cs", - module: THIS_MODULE, - attach: das08_cs_attach, - detach: das08_common_detach, - board_name: &das08_cs_boards[0].name, - num_names: sizeof(das08_cs_boards) / sizeof(struct das08_board_struct), - offset: sizeof(struct das08_board_struct), +static int das08_cs_attach(comedi_device * dev, comedi_devconfig * it); + +static comedi_driver driver_das08_cs = { + driver_name:"das08_cs", + module:THIS_MODULE, + attach:das08_cs_attach, + detach:das08_common_detach, + board_name:&das08_cs_boards[0].name, + num_names:sizeof(das08_cs_boards) / + sizeof(struct das08_board_struct), + offset:sizeof(struct das08_board_struct), }; -static int das08_cs_attach(comedi_device *dev,comedi_devconfig *it) +static int das08_cs_attach(comedi_device * dev, comedi_devconfig * it) { int ret; unsigned long iobase; struct pcmcia_device *link = cur_dev; // XXX hack - if((ret=alloc_private(dev,sizeof(struct das08_private_struct)))<0) + if ((ret = alloc_private(dev, sizeof(struct das08_private_struct))) < 0) return ret; printk("comedi%d: das08_cs: ", dev->minor); // deal with a pci board - if(thisboard->bustype == pcmcia) - { - if(link == NULL) - { + if (thisboard->bustype == pcmcia) { + if (link == NULL) { printk(" no pcmcia cards found\n"); return -EIO; } iobase = link->io.BasePort1; - }else{ + } else { printk(" bug! board does not have PCMCIA bustype\n"); return -EINVAL; } printk("\n"); - return das08_common_attach( dev, iobase ); + return das08_common_attach(dev, iobase); } /*====================================================================== @@ -124,7 +122,7 @@ static int pc_debug = PCMCIA_DEBUG; module_param(pc_debug, int, 0644); #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) static const char *version = -"das08.c pcmcia code (Frank Hess), modified from dummy_cs.c 1.31 2001/08/24 12:13:13 (David Hinds)"; + "das08.c pcmcia code (Frank Hess), modified from dummy_cs.c 1.31 2001/08/24 12:13:13 (David Hinds)"; #else #define DEBUG(n, args...) #endif @@ -160,10 +158,10 @@ static void das08_pcmcia_detach(struct pcmcia_device *); static const dev_info_t dev_info = "pcm-das08"; typedef struct local_info_t { - struct pcmcia_device *link; - dev_node_t node; - int stop; - struct bus_operations *bus; + struct pcmcia_device *link; + dev_node_t node; + int stop; + struct bus_operations *bus; } local_info_t; /*====================================================================== @@ -180,37 +178,38 @@ typedef struct local_info_t { static int das08_pcmcia_attach(struct pcmcia_device *link) { - local_info_t *local; + local_info_t *local; - DEBUG(0, "das08_pcmcia_attach()\n"); + DEBUG(0, "das08_pcmcia_attach()\n"); - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return -ENOMEM; - local->link = link; - link->priv = local; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; - /* Interrupt setup */ - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; - link->irq.IRQInfo1 = IRQ_LEVEL_ID; - link->irq.Handler = NULL; + /* Interrupt setup */ + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; + link->irq.IRQInfo1 = IRQ_LEVEL_ID; + 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.IntType = INT_MEMORY_AND_IO; + /* + 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.IntType = INT_MEMORY_AND_IO; - cur_dev = link; + cur_dev = link; - das08_pcmcia_config(link); + das08_pcmcia_config(link); - return 0; -} /* das08_pcmcia_attach */ + return 0; +} /* das08_pcmcia_attach */ /*====================================================================== @@ -226,17 +225,16 @@ static void das08_pcmcia_detach(struct pcmcia_device *link) DEBUG(0, "das08_pcmcia_detach(0x%p)\n", link); - if(link->dev_node) - { - ((local_info_t *)link->priv)->stop = 1; + if (link->dev_node) { + ((local_info_t *) link->priv)->stop = 1; das08_pcmcia_release(link); } /* This points to the parent local_info_t struct */ - if(link->priv) + if (link->priv) kfree(link->priv); -} /* das08_pcmcia_detach */ +} /* das08_pcmcia_detach */ /*====================================================================== @@ -258,104 +256,115 @@ static void das08_pcmcia_config(struct pcmcia_device *link) DEBUG(0, "das08_pcmcia_config(0x%p)\n", link); /* - This reads the card's CONFIG tuple to find its configuration - registers. - */ + This reads the card's CONFIG tuple to find its configuration + registers. + */ tuple.DesiredTuple = CISTPL_CONFIG; tuple.Attributes = 0; tuple.TupleData = buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 0; last_fn = GetFirstTuple; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) + goto cs_failed; last_fn = GetTupleData; - if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) + goto cs_failed; last_fn = ParseTuple; - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) goto cs_failed; + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) + goto cs_failed; link->conf.ConfigBase = parse.config.base; link->conf.Present = parse.config.rmask[0]; /* - In this loop, we scan the CIS for configuration table entries, - each of which describes a valid card configuration, including - voltage, IO window, memory window, and interrupt settings. - - We make no assumptions about the card to be configured: we use - just the information available in the CIS. In an ideal world, - this would work for any PCMCIA card, but it requires a complete - and accurate CIS. In practice, a driver usually "knows" most of - these things without consulting the CIS, and most client drivers - will only use the CIS to fill in implementation-defined details. - */ + In this loop, we scan the CIS for configuration table entries, + each of which describes a valid card configuration, including + voltage, IO window, memory window, and interrupt settings. + + We make no assumptions about the card to be configured: we use + just the information available in the CIS. In an ideal world, + this would work for any PCMCIA card, but it requires a complete + and accurate CIS. In practice, a driver usually "knows" most of + these things without consulting the CIS, and most client drivers + will only use the CIS to fill in implementation-defined details. + */ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; last_fn = GetFirstTuple; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) + goto cs_failed; while (1) { - cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); - if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) goto next_entry; - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) goto next_entry; - - if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; - if (cfg->index == 0) goto next_entry; - link->conf.ConfigIndex = cfg->index; - - /* Does this card need audio output? */ + cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); + if ((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) + goto next_entry; + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) + goto next_entry; + + if (cfg->flags & CISTPL_CFTABLE_DEFAULT) + dflt = *cfg; + if (cfg->index == 0) + goto next_entry; + link->conf.ConfigIndex = cfg->index; + + /* Does this card need audio output? */ /* if (cfg->flags & CISTPL_CFTABLE_AUDIO) { link->conf.Attributes |= CONF_ENABLE_SPKR; link->conf.Status = CCSR_AUDIO_ENA; } */ - /* Do we need to allocate an interrupt? */ - if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) - link->conf.Attributes |= CONF_ENABLE_IRQ; - - /* IO window settings */ - link->io.NumPorts1 = link->io.NumPorts2 = 0; - if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { - cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; - link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; - if (!(io->flags & CISTPL_IO_8BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; - if (!(io->flags & CISTPL_IO_16BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; - link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; - link->io.BasePort1 = io->win[0].base; - link->io.NumPorts1 = io->win[0].len; - if (io->nwin > 1) { - link->io.Attributes2 = link->io.Attributes1; - link->io.BasePort2 = io->win[1].base; - link->io.NumPorts2 = io->win[1].len; + /* Do we need to allocate an interrupt? */ + if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) + link->conf.Attributes |= CONF_ENABLE_IRQ; + + /* IO window settings */ + link->io.NumPorts1 = link->io.NumPorts2 = 0; + if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { + cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; + if (!(io->flags & CISTPL_IO_8BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; + if (!(io->flags & CISTPL_IO_16BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; + link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; + link->io.BasePort1 = io->win[0].base; + link->io.NumPorts1 = io->win[0].len; + if (io->nwin > 1) { + link->io.Attributes2 = link->io.Attributes1; + link->io.BasePort2 = io->win[1].base; + link->io.NumPorts2 = io->win[1].len; + } + /* This reserves IO space but doesn't actually enable it */ + if (pcmcia_request_io(link, &link->io) != 0) + goto next_entry; } - /* This reserves IO space but doesn't actually enable it */ - if(pcmcia_request_io(link, &link->io) != 0) goto next_entry; - } - /* If we got this far, we're cool! */ - break; + /* If we got this far, we're cool! */ + break; - next_entry: - last_fn = GetNextTuple; - if((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) goto cs_failed; + next_entry: + last_fn = GetNextTuple; + if ((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) + goto cs_failed; } - if (link->conf.Attributes & CONF_ENABLE_IRQ) - { + if (link->conf.Attributes & CONF_ENABLE_IRQ) { last_fn = RequestIRQ; - if((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) goto cs_failed; + if ((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) + goto cs_failed; } /* - This actually configures the PCMCIA socket -- setting up - the I/O windows and the interrupt mapping, and putting the - card and host interface into "Memory and IO" mode. - */ + This actually configures the PCMCIA socket -- setting up + the I/O windows and the interrupt mapping, and putting the + card and host interface into "Memory and IO" mode. + */ last_fn = RequestConfiguration; - if((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) goto cs_failed; + if ((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) + goto cs_failed; /* - At this point, the dev_node_t structure(s) need to be - initialized and arranged in a linked list at link->dev. - */ + At this point, the dev_node_t structure(s) need to be + initialized and arranged in a linked list at link->dev. + */ sprintf(dev->node.dev_name, "pcm-das08"); dev->node.major = dev->node.minor = 0; link->dev_node = &dev->node; @@ -367,19 +376,19 @@ static void das08_pcmcia_config(struct pcmcia_device *link) printk(", irq %u", link->irq.AssignedIRQ); if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, - link->io.BasePort1+link->io.NumPorts1-1); + link->io.BasePort1 + link->io.NumPorts1 - 1); if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, - link->io.BasePort2+link->io.NumPorts2-1); + link->io.BasePort2 + link->io.NumPorts2 - 1); printk("\n"); return; -cs_failed: + cs_failed: cs_error(link, last_fn, last_ret); das08_pcmcia_release(link); -} /* das08_pcmcia_config */ +} /* das08_pcmcia_config */ /*====================================================================== @@ -393,7 +402,7 @@ static void das08_pcmcia_release(struct pcmcia_device *link) { DEBUG(0, "das08_pcmcia_release(0x%p)\n", link); pcmcia_disable_device(link); -} /* das08_pcmcia_release */ +} /* das08_pcmcia_release */ /*====================================================================== @@ -414,27 +423,26 @@ static int das08_pcmcia_suspend(struct pcmcia_device *link) local->stop = 1; return 0; -} /* das08_pcmcia_suspend */ +} /* das08_pcmcia_suspend */ static int das08_pcmcia_resume(struct pcmcia_device *link) { local_info_t *local = link->priv; - + local->stop = 0; return 0; -} /* das08_pcmcia_resume */ +} /* das08_pcmcia_resume */ /*====================================================================*/ -static struct pcmcia_device_id das08_cs_id_table[] = -{ +static struct pcmcia_device_id das08_cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4001), PCMCIA_DEVICE_NULL }; + MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table); -struct pcmcia_driver das08_cs_driver = -{ +struct pcmcia_driver das08_cs_driver = { .probe = das08_pcmcia_attach, .remove = das08_pcmcia_detach, .suspend = das08_pcmcia_suspend, @@ -442,8 +450,8 @@ struct pcmcia_driver das08_cs_driver = .id_table = das08_cs_id_table, .owner = THIS_MODULE, .drv = { - .name = dev_info, - }, + .name = dev_info, + }, }; static int __init init_das08_pcmcia_cs(void) @@ -464,7 +472,7 @@ static int __init das08_cs_init_module(void) int ret; ret = init_das08_pcmcia_cs(); - if(ret < 0) + if (ret < 0) return ret; return comedi_driver_register(&driver_das08_cs); @@ -477,6 +485,5 @@ static void __exit das08_cs_exit_module(void) } MODULE_LICENSE("GPL"); -module_init( das08_cs_init_module ); -module_exit( das08_cs_exit_module ); - +module_init(das08_cs_init_module); +module_exit(das08_cs_exit_module); diff --git a/comedi/drivers/das16.c b/comedi/drivers/das16.c index 2132791b..c1ad4cfd 100644 --- a/comedi/drivers/das16.c +++ b/comedi/drivers/das16.c @@ -95,8 +95,8 @@ Computer boards manuals also available from their website www.measurementcomputi #define DEBUG_PRINT(format, args...) #endif -#define DAS16_SIZE 20 // number of ioports -#define DAS16_DMA_SIZE 0xff00 // size in bytes of allocated dma buffer +#define DAS16_SIZE 20 // number of ioports +#define DAS16_DMA_SIZE 0xff00 // size in bytes of allocated dma buffer /* cio-das16.pdf @@ -237,51 +237,57 @@ static const int sample_size = 2; // size in bytes of a sample from board #define DAS1600_CLK_10MHZ 0x01 static const comedi_lrange range_das1x01_bip = { 4, { - BIP_RANGE( 10 ), - BIP_RANGE( 1 ), - BIP_RANGE( 0.1 ), - BIP_RANGE( 0.01 ), -}}; + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01), + } +}; static const comedi_lrange range_das1x01_unip = { 4, { - UNI_RANGE( 10 ), - UNI_RANGE( 1 ), - UNI_RANGE( 0.1 ), - UNI_RANGE( 0.01 ), -}}; + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01), + } +}; static const comedi_lrange range_das1x02_bip = { 4, { - BIP_RANGE( 10 ), - BIP_RANGE( 5 ), - BIP_RANGE( 2.5 ), - BIP_RANGE( 1.25 ), -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + } +}; static const comedi_lrange range_das1x02_unip = { 4, { - UNI_RANGE( 10 ), - UNI_RANGE( 5 ), - UNI_RANGE( 2.5 ), - UNI_RANGE( 1.25 ), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } +}; static const comedi_lrange range_das16jr = { 9, { - // also used by 16/330 - 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 ), -}}; + // also used by 16/330 + 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 const comedi_lrange range_das16jr_16 = { 8, { - BIP_RANGE( 10 ), - BIP_RANGE( 5 ), - BIP_RANGE( 2.5 ), - BIP_RANGE( 1.25 ), - UNI_RANGE( 10 ), - UNI_RANGE( 5 ), - UNI_RANGE( 2.5 ), - UNI_RANGE( 1.25 ), -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } +}; static const int das16jr_gainlist[] = { 8, 0, 1, 2, 3, 4, 5, 6, 7 }; static const int das16jr_16_gainlist[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; @@ -293,21 +299,21 @@ enum { das16_pg_1601, das16_pg_1602, }; -static const int * const das16_gainlists[] = { +static const int *const das16_gainlists[] = { NULL, das16jr_gainlist, das16jr_16_gainlist, das1600_gainlist, das1600_gainlist, }; -static const comedi_lrange * const das16_ai_uni_lranges[]={ +static const comedi_lrange *const das16_ai_uni_lranges[] = { &range_unknown, &range_das16jr, &range_das16jr_16, &range_das1x01_unip, &range_das1x02_unip, }; -static const comedi_lrange *const das16_ai_bip_lranges[]={ +static const comedi_lrange *const das16_ai_bip_lranges[] = { &range_unknown, &range_das16jr, &range_das16jr_16, @@ -315,395 +321,393 @@ static const comedi_lrange *const das16_ai_bip_lranges[]={ &range_das1x02_bip, }; -struct munge_info -{ +struct munge_info { uint8_t byte; - unsigned have_byte : 1; + unsigned have_byte:1; }; -static int das16_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int das16_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int das16_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int das16_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - -static int das16_cmd_test(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s); -static int das16_cancel(comedi_device *dev, comedi_subdevice *s); -static void das16_ai_munge(comedi_device *dev, comedi_subdevice *s, void *array, - unsigned int num_bytes, unsigned int start_chan_index); - -static void das16_reset(comedi_device *dev); +static int das16_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int das16_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int das16_cmd_exec(comedi_device * dev, comedi_subdevice * s); +static int das16_cancel(comedi_device * dev, comedi_subdevice * s); +static void das16_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *array, unsigned int num_bytes, unsigned int start_chan_index); + +static void das16_reset(comedi_device * dev); static irqreturn_t das16_dma_interrupt(int irq, void *d PT_REGS_ARG); static void das16_timer_interrupt(unsigned long arg); -static void das16_interrupt(comedi_device *dev); - -static unsigned int das16_set_pacer(comedi_device *dev, unsigned int ns, int flags); -static int das1600_mode_detect(comedi_device *dev); -static unsigned int das16_suggest_transfer_size(comedi_device *dev, comedi_cmd cmd); +static void das16_interrupt(comedi_device * dev); + +static unsigned int das16_set_pacer(comedi_device * dev, unsigned int ns, + int flags); +static int das1600_mode_detect(comedi_device * dev); +static unsigned int das16_suggest_transfer_size(comedi_device * dev, + comedi_cmd cmd); + +static void reg_dump(comedi_device * dev); + +typedef struct das16_board_struct { + const char *name; + void *ai; + unsigned int ai_nbits; + unsigned int ai_speed; // max conversion speed in nanosec + unsigned int ai_pg; + void *ao; + unsigned int ao_nbits; + void *di; + void *do_; + + unsigned int i8255_offset; + unsigned int i8254_offset; -static void reg_dump(comedi_device *dev); - -typedef struct das16_board_struct{ - const char *name; - void *ai; - unsigned int ai_nbits; - unsigned int ai_speed; // max conversion speed in nanosec - unsigned int ai_pg; - void *ao; - unsigned int ao_nbits; - void *di; - void *do_; - - unsigned int i8255_offset; - unsigned int i8254_offset; - - unsigned int size; + unsigned int size; unsigned int id; } das16_board; -static const struct das16_board_struct das16_boards[]={ - { - name: "das-16", - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 15000, - ai_pg: das16_pg_none, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x10, - i8254_offset: 0x0c, - size: 0x14, - id: 0x00, - }, - { - name: "das-16g", - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 15000, - ai_pg: das16_pg_none, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x10, - i8254_offset: 0x0c, - size: 0x14, - id: 0x00, - }, - { - name: "das-16f", - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 8500, - ai_pg: das16_pg_none, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x10, - i8254_offset: 0x0c, - size: 0x14, - id: 0x00, - }, - { - name: "cio-das16", // cio-das16.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 20000, - ai_pg: das16_pg_none, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x10, - i8254_offset: 0x0c, - size: 0x14, - id: 0x80, - }, - { - name: "cio-das16/f", // das16.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_none, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x10, - i8254_offset: 0x0c, - size: 0x14, - id: 0x80, - }, - { - name: "cio-das16/jr", // cio-das16jr.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 7692, - ai_pg: das16_pg_16jr, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x10, - id: 0x00, - }, - { - name: "pc104-das16jr", // pc104-das16jr_xx.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 3300, - ai_pg: das16_pg_16jr, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x10, - id: 0x00, - }, - { - name: "cio-das16jr/16", // cio-das16jr_16.pdf - ai: das16_ai_rinsn, - ai_nbits: 16, - ai_speed: 10000, - ai_pg: das16_pg_16jr_16, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x10, - id: 0x00, - }, - { - name: "pc104-das16jr/16", // pc104-das16jr_xx.pdf - ai: das16_ai_rinsn, - ai_nbits: 16, - ai_speed: 10000, - ai_pg: das16_pg_16jr_16, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x10, - id: 0x00, - }, - { - name: "das-1201", // 4924.pdf (keithley user's manual) - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 20000, - ai_pg: das16_pg_none, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0x20, - }, - { - name: "das-1202", // 4924.pdf (keithley user's manual) - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_none, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0x20, - }, - { - name: "das-1401", // 4919.pdf and 4922.pdf (keithley user's manual) - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_1601, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x0, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 // 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 - }, - { - name: "das-1402", // 4919.pdf and 4922.pdf (keithley user's manual) - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_1602, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x0, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 // 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 - }, - { - name: "das-1601", // 4919.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_1601, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "das-1602", // 4919.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_1602, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1401/12", // cio-das1400_series.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 6250, - ai_pg: das16_pg_1601, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1402/12", // cio-das1400_series.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 6250, - ai_pg: das16_pg_1602, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1402/16", // cio-das1400_series.pdf - ai: das16_ai_rinsn, - ai_nbits: 16, - ai_speed: 10000, - ai_pg: das16_pg_1602, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1601/12", // cio-das160x-1x.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 6250, - ai_pg: das16_pg_1601, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1602/12", // cio-das160x-1x.pdf - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 10000, - ai_pg: das16_pg_1602, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das1602/16", // cio-das160x-1x.pdf - ai: das16_ai_rinsn, - ai_nbits: 16, - ai_speed: 10000, - ai_pg: das16_pg_1602, - ao: das16_ao_winsn, - ao_nbits: 12, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0x400, - i8254_offset: 0x0c, - size: 0x408, - id: 0xc0 - }, - { - name: "cio-das16/330", // ? - ai: das16_ai_rinsn, - ai_nbits: 12, - ai_speed: 3030, - ai_pg: das16_pg_16jr, - ao: NULL, - di: das16_di_rbits, - do_: das16_do_wbits, - i8255_offset: 0, - i8254_offset: 0x0c, - size: 0x14, - id: 0xf0 - }, +static const struct das16_board_struct das16_boards[] = { + { + name: "das-16", + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:15000, + ai_pg: das16_pg_none, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x10, + i8254_offset:0x0c, + size: 0x14, + id: 0x00, + }, + { + name: "das-16g", + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:15000, + ai_pg: das16_pg_none, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x10, + i8254_offset:0x0c, + size: 0x14, + id: 0x00, + }, + { + name: "das-16f", + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:8500, + ai_pg: das16_pg_none, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x10, + i8254_offset:0x0c, + size: 0x14, + id: 0x00, + }, + { + name: "cio-das16", // cio-das16.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:20000, + ai_pg: das16_pg_none, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x10, + i8254_offset:0x0c, + size: 0x14, + id: 0x80, + }, + { + name: "cio-das16/f", // das16.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_none, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x10, + i8254_offset:0x0c, + size: 0x14, + id: 0x80, + }, + { + name: "cio-das16/jr", // cio-das16jr.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:7692, + ai_pg: das16_pg_16jr, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x10, + id: 0x00, + }, + { + name: "pc104-das16jr", // pc104-das16jr_xx.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:3300, + ai_pg: das16_pg_16jr, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x10, + id: 0x00, + }, + { + name: "cio-das16jr/16", // cio-das16jr_16.pdf + ai: das16_ai_rinsn, + ai_nbits:16, + ai_speed:10000, + ai_pg: das16_pg_16jr_16, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x10, + id: 0x00, + }, + { + name: "pc104-das16jr/16", // pc104-das16jr_xx.pdf + ai: das16_ai_rinsn, + ai_nbits:16, + ai_speed:10000, + ai_pg: das16_pg_16jr_16, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x10, + id: 0x00, + }, + { + name: "das-1201", // 4924.pdf (keithley user's manual) + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:20000, + ai_pg: das16_pg_none, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0x20, + }, + { + name: "das-1202", // 4924.pdf (keithley user's manual) + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_none, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0x20, + }, + { + name: "das-1401", // 4919.pdf and 4922.pdf (keithley user's manual) + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_1601, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x0, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0 // 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 + }, + { + name: "das-1402", // 4919.pdf and 4922.pdf (keithley user's manual) + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_1602, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x0, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0 // 4919.pdf says id bits are 0xe0, 4922.pdf says 0xc0 + }, + { + name: "das-1601", // 4919.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_1601, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "das-1602", // 4919.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_1602, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1401/12", // cio-das1400_series.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:6250, + ai_pg: das16_pg_1601, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1402/12", // cio-das1400_series.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:6250, + ai_pg: das16_pg_1602, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1402/16", // cio-das1400_series.pdf + ai: das16_ai_rinsn, + ai_nbits:16, + ai_speed:10000, + ai_pg: das16_pg_1602, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1601/12", // cio-das160x-1x.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:6250, + ai_pg: das16_pg_1601, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1602/12", // cio-das160x-1x.pdf + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:10000, + ai_pg: das16_pg_1602, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das1602/16", // cio-das160x-1x.pdf + ai: das16_ai_rinsn, + ai_nbits:16, + ai_speed:10000, + ai_pg: das16_pg_1602, + ao: das16_ao_winsn, + ao_nbits:12, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0x400, + i8254_offset:0x0c, + size: 0x408, + id: 0xc0}, + { + name: "cio-das16/330", // ? + ai: das16_ai_rinsn, + ai_nbits:12, + ai_speed:3030, + ai_pg: das16_pg_16jr, + ao: NULL, + di: das16_di_rbits, + do_: das16_do_wbits, + i8255_offset:0, + i8254_offset:0x0c, + size: 0x14, + id: 0xf0}, #if 0 { - name: "das16/330i", // ? - }, + name: "das16/330i", // ? + }, { - name: "das16/jr/ctr5", // ? - }, + name: "das16/jr/ctr5", // ? + }, { - name: "cio-das16/m1/16", // cio-das16_m1_16.pdf, this board is a bit quirky, no dma - }, + name: "cio-das16/m1/16", // cio-das16_m1_16.pdf, this board is a bit quirky, no dma + }, #endif }; + #define n_das16_boards ((sizeof(das16_boards))/(sizeof(das16_board))) -static int das16_attach(comedi_device *dev,comedi_devconfig *it); -static int das16_detach(comedi_device *dev); -static comedi_driver driver_das16={ - driver_name: "das16", - module: THIS_MODULE, - attach: das16_attach, - detach: das16_detach, - board_name: &das16_boards[0].name, - num_names: n_das16_boards, - offset: sizeof(das16_boards[0]), +static int das16_attach(comedi_device * dev, comedi_devconfig * it); +static int das16_detach(comedi_device * dev); +static comedi_driver driver_das16 = { + driver_name:"das16", + module:THIS_MODULE, + attach:das16_attach, + detach:das16_detach, + board_name:&das16_boards[0].name, + num_names:n_das16_boards, + offset:sizeof(das16_boards[0]), }; #define DAS16_TIMEOUT 1000 @@ -714,13 +718,12 @@ static inline int timer_period(void) { return HZ / 20; } -struct das16_private_struct -{ - unsigned int ai_unipolar; // unipolar flag - unsigned int ai_singleended; // single ended flag - unsigned int clockbase; // master clock speed in ns - volatile unsigned int control_state; // dma, interrupt and trigger control bits - volatile unsigned long adc_byte_count; // number of bytes remaining +struct das16_private_struct { + unsigned int ai_unipolar; // unipolar flag + unsigned int ai_singleended; // single ended flag + unsigned int clockbase; // master clock speed in ns + volatile unsigned int control_state; // dma, interrupt and trigger control bits + volatile unsigned long adc_byte_count; // number of bytes remaining unsigned int divisor1; // divisor dividing master clock to get conversion frequency unsigned int divisor2; // divisor dividing master clock to get conversion frequency unsigned int dma_chan; // dma channel @@ -732,164 +735,165 @@ struct das16_private_struct comedi_lrange *user_ai_range_table; comedi_lrange *user_ao_range_table; - struct timer_list timer; // for timed interrupt + struct timer_list timer; // for timed interrupt volatile short timer_running; - volatile short timer_mode; // true if using timer mode + volatile short timer_mode; // true if using timer mode }; #define devpriv ((struct das16_private_struct *)(dev->private)) #define thisboard ((struct das16_board_struct *)(dev->board_ptr)) -static int das16_cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) +static int das16_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0, tmp; + int err = 0, tmp; int gain, start_chan, i; int mask; /* make sure triggers are valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; mask = TRIG_FOLLOW; // if board supports burst mode - if(thisboard->size > 0x400) + if (thisboard->size > 0x400) mask |= TRIG_TIMER | TRIG_EXT; cmd->scan_begin_src &= mask; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; mask = TRIG_TIMER | TRIG_EXT; // if board supports burst mode - if(thisboard->size > 0x400) + if (thisboard->size > 0x400) mask |= TRIG_NOW; cmd->convert_src &= mask; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_EXT && - cmd->scan_begin_src != TRIG_FOLLOW) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT && - cmd->convert_src != TRIG_NOW) err++; - if(cmd->stop_src != TRIG_NONE && - cmd->stop_src != TRIG_COUNT) err++; + cmd->scan_begin_src != TRIG_FOLLOW) + err++; + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; // make sure scan_begin_src and convert_src dont conflict - if(cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_NOW) err++; - if(cmd->scan_begin_src != TRIG_FOLLOW && - cmd->convert_src != TRIG_NOW) err++; + if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW) + err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->convert_src != TRIG_NOW) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0) - { - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_FOLLOW) - { + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg!=0) - { - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - // check against maximum frequency - if(cmd->scan_begin_src == TRIG_TIMER) - { - if(cmd->scan_begin_arg < thisboard->ai_speed * cmd->chanlist_len) - { - cmd->scan_begin_arg = thisboard->ai_speed * cmd->chanlist_len; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < + thisboard->ai_speed * cmd->chanlist_len) { + cmd->scan_begin_arg = + thisboard->ai_speed * cmd->chanlist_len; err++; } } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(cmd->stop_src == TRIG_NONE) - { - if(cmd->stop_arg != 0) - { + if (cmd->stop_src == TRIG_NONE) { + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; // step 4: fix up arguments - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { unsigned int tmp = cmd->scan_begin_arg; // set divisors, correct timing arguments i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->scan_begin_arg), cmd->flags & TRIG_ROUND_MASK); - err += (tmp!=cmd->scan_begin_arg); + err += (tmp != cmd->scan_begin_arg); } - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { unsigned int tmp = cmd->convert_arg; // set divisors, correct timing arguments i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); - err += (tmp!=cmd->convert_arg); + err += (tmp != cmd->convert_arg); } - if(err)return 4; + if (err) + return 4; // check channel/gain list against card's limitations - if(cmd->chanlist){ + if (cmd->chanlist) { gain = CR_RANGE(cmd->chanlist[0]); start_chan = CR_CHAN(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++) - { - if(CR_CHAN(cmd->chanlist[i]) != (start_chan + i) % s->n_chan) - { - comedi_error(dev, "entries in chanlist must be consecutive channels, counting upwards\n"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != + (start_chan + i) % s->n_chan) { + comedi_error(dev, + "entries in chanlist must be consecutive channels, counting upwards\n"); err++; } - if(CR_RANGE(cmd->chanlist[i]) != gain) - { - comedi_error(dev, "entries in chanlist must all have the same gain\n"); + if (CR_RANGE(cmd->chanlist[i]) != gain) { + comedi_error(dev, + "entries in chanlist must all have the same gain\n"); err++; } } } - if(err)return 5; + if (err) + return 5; return 0; } -static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) +static int das16_cmd_exec(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -897,25 +901,25 @@ static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) unsigned long flags; int range; - if(devpriv->dma_chan == 0 || (dev->irq == 0 && devpriv->timer_mode == 0)) - { - comedi_error(dev, "irq (or use of 'timer mode') dma required to execute comedi_cmd"); + if (devpriv->dma_chan == 0 || (dev->irq == 0 + && devpriv->timer_mode == 0)) { + comedi_error(dev, + "irq (or use of 'timer mode') dma required to execute comedi_cmd"); return -1; } - if(cmd->flags & TRIG_RT) - { - comedi_error(dev, "isa dma transfers cannot be performed with TRIG_RT, aborting"); + if (cmd->flags & TRIG_RT) { + comedi_error(dev, + "isa dma transfers cannot be performed with TRIG_RT, aborting"); return -1; } - devpriv->adc_byte_count = cmd->stop_arg * cmd->chanlist_len * sizeof( uint16_t ); + devpriv->adc_byte_count = + cmd->stop_arg * cmd->chanlist_len * sizeof(uint16_t); // disable conversions for das1600 mode - if(thisboard->size > 0x400) - { + if (thisboard->size > 0x400) { outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV); } - // set scan limits byte = CR_CHAN(cmd->chanlist[0]); byte |= CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]) << 4; @@ -923,34 +927,32 @@ static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) /* set gain (this is also burst rate register but according to * computer boards manual, burst rate does nothing, even on keithley cards) */ - if(thisboard->ai_pg != das16_pg_none){ + if (thisboard->ai_pg != das16_pg_none) { range = CR_RANGE(cmd->chanlist[0]); outb((das16_gainlists[thisboard->ai_pg])[range], - dev->iobase+DAS16_GAIN); + dev->iobase + DAS16_GAIN); } /* set counter mode and counts */ - cmd->convert_arg = das16_set_pacer(dev, cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); + cmd->convert_arg = + das16_set_pacer(dev, cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); DEBUG_PRINT("pacer period: %d ns\n", cmd->convert_arg); /* enable counters */ byte = 0; /* Enable burst mode if appropriate. */ - if(thisboard->size > 0x400) - { - if(cmd->convert_src == TRIG_NOW) - { + if (thisboard->size > 0x400) { + if (cmd->convert_src == TRIG_NOW) { outb(DAS1600_BURST_VAL, dev->iobase + DAS1600_BURST); // set burst length byte |= BURST_LEN_BITS(cmd->chanlist_len - 1); - }else - { + } else { outb(0, dev->iobase + DAS1600_BURST); } } outb(byte, dev->iobase + DAS16_PACER); - // set up dma transfer flags = claim_dma_lock(); disable_dma(devpriv->dma_chan); @@ -958,8 +960,8 @@ static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) * count and address get set correctly */ clear_dma_ff(devpriv->dma_chan); devpriv->current_buffer = 0; - set_dma_addr( devpriv->dma_chan, - devpriv->dma_buffer_addr[ devpriv->current_buffer ] ); + set_dma_addr(devpriv->dma_chan, + devpriv->dma_buffer_addr[devpriv->current_buffer]); // set appropriate size of transfer devpriv->dma_transfer_size = das16_suggest_transfer_size(dev, *cmd); set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size); @@ -967,14 +969,12 @@ static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) release_dma_lock(flags); // set up interrupt - if( devpriv->timer_mode ) - { + if (devpriv->timer_mode) { devpriv->timer_running = 1; devpriv->timer.expires = jiffies + timer_period(); add_timer(&devpriv->timer); devpriv->control_state &= ~DAS16_INTE; - }else - { + } else { /* clear interrupt bit */ outb(0x00, dev->iobase + DAS16_STATUS); /* enable interrupts */ @@ -982,51 +982,48 @@ static int das16_cmd_exec(comedi_device *dev,comedi_subdevice *s) } devpriv->control_state |= DMA_ENABLE; devpriv->control_state &= ~PACING_MASK; - if(cmd->convert_src == TRIG_EXT) + if (cmd->convert_src == TRIG_EXT) devpriv->control_state |= EXT_PACER; else devpriv->control_state |= INT_PACER; outb(devpriv->control_state, dev->iobase + DAS16_CONTROL); /* Enable conversions if using das1600 mode */ - if(thisboard->size > 0x400) - { + if (thisboard->size > 0x400) { outb(0, dev->iobase + DAS1600_CONV); } return 0; } -static int das16_cancel(comedi_device *dev, comedi_subdevice *s) +static int das16_cancel(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); /* disable interrupts, dma and pacer clocked conversions */ devpriv->control_state &= ~DAS16_INTE & ~PACING_MASK & ~DMA_ENABLE; outb(devpriv->control_state, dev->iobase + DAS16_CONTROL); - if(devpriv->dma_chan) + if (devpriv->dma_chan) disable_dma(devpriv->dma_chan); // disable SW timer - if( devpriv->timer_mode && devpriv->timer_running ) - { + if (devpriv->timer_mode && devpriv->timer_running) { devpriv->timer_running = 0; del_timer(&devpriv->timer); } /* disable burst mode */ - if(thisboard->size > 0x400) - { + if (thisboard->size > 0x400) { outb(0, dev->iobase + DAS1600_BURST); } - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } -static void das16_reset(comedi_device *dev) +static void das16_reset(comedi_device * dev) { outb(0, dev->iobase + DAS16_STATUS); outb(0, dev->iobase + DAS16_CONTROL); @@ -1034,12 +1031,13 @@ static void das16_reset(comedi_device *dev) outb(0, dev->iobase + DAS16_CNTR_CONTROL); } -static int das16_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,n; + int i, n; int range; int chan; - int msb,lsb; + int msb, lsb; // disable interrupts and pacing devpriv->control_state &= ~DAS16_INTE & ~DMA_ENABLE & ~PACING_MASK; @@ -1051,33 +1049,29 @@ static int das16_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *in outb(chan, dev->iobase + DAS16_MUX); /* set gain */ - if(thisboard->ai_pg != das16_pg_none) - { + if (thisboard->ai_pg != das16_pg_none) { range = CR_RANGE(insn->chanspec); outb((das16_gainlists[thisboard->ai_pg])[range], - dev->iobase+DAS16_GAIN); + dev->iobase + DAS16_GAIN); } - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* trigger conversion */ outb_p(0, dev->iobase + DAS16_TRIG); - for(i = 0; i < DAS16_TIMEOUT; i++) - { - if(!(inb(dev->iobase + DAS16_STATUS) & BUSY)) + for (i = 0; i < DAS16_TIMEOUT; i++) { + if (!(inb(dev->iobase + DAS16_STATUS) & BUSY)) break; } - if(i == DAS16_TIMEOUT) - { + if (i == DAS16_TIMEOUT) { rt_printk("das16: timeout\n"); return -ETIME; } msb = inb(dev->iobase + DAS16_AI_MSB); lsb = inb(dev->iobase + DAS16_AI_LSB); - if(thisboard->ai_nbits == 12){ + if (thisboard->ai_nbits == 12) { data[n] = ((lsb >> 4) & 0xf) | (msb << 4); - }else{ + } else { data[n] = lsb | (msb << 8); } } @@ -1085,7 +1079,8 @@ static int das16_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return n; } -static int das16_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t bits; @@ -1096,7 +1091,8 @@ static int das16_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return 2; } -static int das16_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t wbits; @@ -1115,33 +1111,30 @@ static int das16_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return 2; } -static int das16_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; - int lsb,msb; + int lsb, msb; int chan; chan = CR_CHAN(insn->chanspec); - for(i = 0; i < insn->n; i++) - { - if(thisboard->ao_nbits == 12) - { + for (i = 0; i < insn->n; i++) { + if (thisboard->ao_nbits == 12) { lsb = (data[i] << 4) & 0xff; msb = (data[i] >> 4) & 0xff; - }else - { + } else { lsb = data[i] & 0xff; msb = (data[i] >> 8) & 0xff; } - outb(lsb,dev->iobase+DAS16_AO_LSB(chan)); - outb(msb,dev->iobase+DAS16_AO_MSB(chan)); + outb(lsb, dev->iobase + DAS16_AO_LSB(chan)); + outb(msb, dev->iobase + DAS16_AO_MSB(chan)); } return i; } - static irqreturn_t das16_dma_interrupt(int irq, void *d PT_REGS_ARG) { int status; @@ -1149,9 +1142,8 @@ static irqreturn_t das16_dma_interrupt(int irq, void *d PT_REGS_ARG) status = inb(dev->iobase + DAS16_STATUS); - if((status & DAS16_INT ) == 0) - { - DEBUG_PRINT( "spurious interrupt\n" ); + if ((status & DAS16_INT) == 0) { + DEBUG_PRINT("spurious interrupt\n"); return IRQ_NONE; } @@ -1163,11 +1155,11 @@ static irqreturn_t das16_dma_interrupt(int irq, void *d PT_REGS_ARG) static void das16_timer_interrupt(unsigned long arg) { - comedi_device *dev = (comedi_device*) arg; + comedi_device *dev = (comedi_device *) arg; das16_interrupt(dev); - if(devpriv->timer_running) + if (devpriv->timer_running) mod_timer(&devpriv->timer, jiffies + timer_period()); } @@ -1177,7 +1169,7 @@ static void das16_timer_interrupt(unsigned long arg) an even transfer count after disabling dma channel. */ -static int disable_dma_on_even(comedi_device *dev) +static int disable_dma_on_even(comedi_device * dev) { int residue; int i; @@ -1185,28 +1177,27 @@ static int disable_dma_on_even(comedi_device *dev) static const int enable_timeout = 100; disable_dma(devpriv->dma_chan); residue = get_dma_residue(devpriv->dma_chan); - for(i = 0; i < disable_limit && (residue % 2); ++i) - { + for (i = 0; i < disable_limit && (residue % 2); ++i) { int j; enable_dma(devpriv->dma_chan); - for(j = 0; j < enable_timeout; ++j) - { + for (j = 0; j < enable_timeout; ++j) { int new_residue; comedi_udelay(2); new_residue = get_dma_residue(devpriv->dma_chan); - if(new_residue != residue) break; + if (new_residue != residue) + break; } disable_dma(devpriv->dma_chan); residue = get_dma_residue(devpriv->dma_chan); } - if(i == disable_limit) - { - comedi_error(dev, "failed to get an even dma transfer, could be trouble."); + if (i == disable_limit) { + comedi_error(dev, + "failed to get an even dma transfer, could be trouble."); } return residue; } -static void das16_interrupt( comedi_device *dev ) +static void das16_interrupt(comedi_device * dev) { unsigned long dma_flags, spin_flags; comedi_subdevice *s = dev->read_subdev; @@ -1215,8 +1206,7 @@ static void das16_interrupt( comedi_device *dev ) int num_bytes, residue; int buffer_index; - if(dev->attached == 0) - { + if (dev->attached == 0) { comedi_error(dev, "premature interrupt"); return; } @@ -1224,17 +1214,15 @@ static void das16_interrupt( comedi_device *dev ) async = s->async; cmd = &async->cmd; - if( devpriv->dma_chan == 0 ) - { + if (devpriv->dma_chan == 0) { comedi_error(dev, "interrupt with no dma channel?"); return; } - comedi_spin_lock_irqsave( &dev->spinlock, spin_flags ); - if( ( devpriv->control_state & DMA_ENABLE ) == 0 ) - { - comedi_spin_unlock_irqrestore( &dev->spinlock, spin_flags ); - DEBUG_PRINT( "interrupt while dma disabled?\n" ); + comedi_spin_lock_irqsave(&dev->spinlock, spin_flags); + if ((devpriv->control_state & DMA_ENABLE) == 0) { + comedi_spin_unlock_irqrestore(&dev->spinlock, spin_flags); + DEBUG_PRINT("interrupt while dma disabled?\n"); return; } @@ -1243,54 +1231,50 @@ static void das16_interrupt( comedi_device *dev ) residue = disable_dma_on_even(dev); // figure out how many points to read - if(residue > devpriv->dma_transfer_size) - { + if (residue > devpriv->dma_transfer_size) { comedi_error(dev, "residue > transfer size!\n"); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; num_bytes = 0; - }else + } else num_bytes = devpriv->dma_transfer_size - residue; - if(cmd->stop_src == TRIG_COUNT && - num_bytes >= devpriv->adc_byte_count) - { + if (cmd->stop_src == TRIG_COUNT && num_bytes >= devpriv->adc_byte_count) { num_bytes = devpriv->adc_byte_count; async->events |= COMEDI_CB_EOA; } buffer_index = devpriv->current_buffer; - devpriv->current_buffer = ( devpriv->current_buffer + 1 ) % 2; + devpriv->current_buffer = (devpriv->current_buffer + 1) % 2; devpriv->adc_byte_count -= num_bytes; // figure out how many bytes for next transfer - if(cmd->stop_src == TRIG_COUNT && devpriv->timer_mode == 0 && - devpriv->dma_transfer_size > devpriv->adc_byte_count ) + if (cmd->stop_src == TRIG_COUNT && devpriv->timer_mode == 0 && + devpriv->dma_transfer_size > devpriv->adc_byte_count) devpriv->dma_transfer_size = devpriv->adc_byte_count; // re-enable dma - if(( async->events & COMEDI_CB_EOA ) == 0) - { - set_dma_addr( devpriv->dma_chan, - devpriv->dma_buffer_addr[ devpriv->current_buffer ] ); - set_dma_count( devpriv->dma_chan, devpriv->dma_transfer_size ); + if ((async->events & COMEDI_CB_EOA) == 0) { + set_dma_addr(devpriv->dma_chan, + devpriv->dma_buffer_addr[devpriv->current_buffer]); + set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size); enable_dma(devpriv->dma_chan); /* reenable conversions for das1600 mode, (stupid hardware) */ - if(thisboard->size > 0x400 && devpriv->timer_mode == 0) - { + if (thisboard->size > 0x400 && devpriv->timer_mode == 0) { outb(0x00, dev->iobase + DAS1600_CONV); } } release_dma_lock(dma_flags); - comedi_spin_unlock_irqrestore( &dev->spinlock, spin_flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, spin_flags); - cfc_write_array_to_buffer( s, - devpriv->dma_buffer[ buffer_index ], num_bytes ); + cfc_write_array_to_buffer(s, + devpriv->dma_buffer[buffer_index], num_bytes); - cfc_handle_events( dev, s ); + cfc_handle_events(dev, s); } -static unsigned int das16_set_pacer(comedi_device *dev, unsigned int ns, int rounding_flags) +static unsigned int das16_set_pacer(comedi_device * dev, unsigned int ns, + int rounding_flags) { i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1), &(devpriv->divisor2), &ns, rounding_flags & TRIG_ROUND_MASK); @@ -1302,23 +1286,25 @@ static unsigned int das16_set_pacer(comedi_device *dev, unsigned int ns, int rou return ns; } -static void reg_dump(comedi_device *dev) +static void reg_dump(comedi_device * dev) { DEBUG_PRINT("********DAS1600 REGISTER DUMP********\n"); - DEBUG_PRINT("DAS16_MUX: %x\n", inb(dev->iobase+DAS16_MUX) ); - DEBUG_PRINT("DAS16_DIO: %x\n", inb(dev->iobase+DAS16_DIO) ); - DEBUG_PRINT("DAS16_STATUS: %x\n", inb(dev->iobase+DAS16_STATUS) ); - DEBUG_PRINT("DAS16_CONTROL: %x\n", inb(dev->iobase+DAS16_CONTROL) ); - DEBUG_PRINT("DAS16_PACER: %x\n", inb(dev->iobase+DAS16_PACER) ); - DEBUG_PRINT("DAS16_GAIN: %x\n", inb(dev->iobase+DAS16_GAIN) ); - DEBUG_PRINT("DAS16_CNTR_CONTROL: %x\n", inb(dev->iobase+DAS16_CNTR_CONTROL) ); - DEBUG_PRINT("DAS1600_CONV: %x\n", inb(dev->iobase+DAS1600_CONV) ); - DEBUG_PRINT("DAS1600_BURST: %x\n", inb(dev->iobase+DAS1600_BURST) ); - DEBUG_PRINT("DAS1600_ENABLE: %x\n", inb(dev->iobase+DAS1600_ENABLE) ); - DEBUG_PRINT("DAS1600_STATUS_B: %x\n", inb(dev->iobase+DAS1600_STATUS_B) ); + DEBUG_PRINT("DAS16_MUX: %x\n", inb(dev->iobase + DAS16_MUX)); + DEBUG_PRINT("DAS16_DIO: %x\n", inb(dev->iobase + DAS16_DIO)); + DEBUG_PRINT("DAS16_STATUS: %x\n", inb(dev->iobase + DAS16_STATUS)); + DEBUG_PRINT("DAS16_CONTROL: %x\n", inb(dev->iobase + DAS16_CONTROL)); + DEBUG_PRINT("DAS16_PACER: %x\n", inb(dev->iobase + DAS16_PACER)); + DEBUG_PRINT("DAS16_GAIN: %x\n", inb(dev->iobase + DAS16_GAIN)); + DEBUG_PRINT("DAS16_CNTR_CONTROL: %x\n", + inb(dev->iobase + DAS16_CNTR_CONTROL)); + DEBUG_PRINT("DAS1600_CONV: %x\n", inb(dev->iobase + DAS1600_CONV)); + DEBUG_PRINT("DAS1600_BURST: %x\n", inb(dev->iobase + DAS1600_BURST)); + DEBUG_PRINT("DAS1600_ENABLE: %x\n", inb(dev->iobase + DAS1600_ENABLE)); + DEBUG_PRINT("DAS1600_STATUS_B: %x\n", + inb(dev->iobase + DAS1600_STATUS_B)); } -static int das16_probe(comedi_device *dev, comedi_devconfig *it) +static int das16_probe(comedi_device * dev, comedi_devconfig * it) { int status; int diobits; @@ -1327,15 +1313,15 @@ static int das16_probe(comedi_device *dev, comedi_devconfig *it) status = inb(dev->iobase + DAS16_STATUS); - if((status & UNIPOLAR)){ + if ((status & UNIPOLAR)) { devpriv->ai_unipolar = 1; - }else{ + } else { devpriv->ai_unipolar = 0; } - if((status & DAS16_MUXBIT)){ + if ((status & DAS16_MUXBIT)) { devpriv->ai_singleended = 1; - }else{ + } else { devpriv->ai_singleended = 0; } @@ -1343,22 +1329,22 @@ static int das16_probe(comedi_device *dev, comedi_devconfig *it) diobits = inb(dev->iobase + DAS16_DIO) & 0xf0; - printk(" id bits are 0x%02x\n",diobits); - if(thisboard->id != diobits) - { - printk(" requested board's id bits are 0x%x (ignore)\n", thisboard->id); + printk(" id bits are 0x%02x\n", diobits); + if (thisboard->id != diobits) { + printk(" requested board's id bits are 0x%x (ignore)\n", + thisboard->id); } return 0; } -static int das1600_mode_detect(comedi_device *dev) +static int das1600_mode_detect(comedi_device * dev) { - int status=0; + int status = 0; status = inb(dev->iobase + DAS1600_STATUS_B); - if(status & DAS1600_CLK_10MHZ) { + if (status & DAS1600_CLK_10MHZ) { devpriv->clockbase = 100; printk(" 10MHz pacer clock\n"); } else { @@ -1371,7 +1357,6 @@ static int das1600_mode_detect(comedi_device *dev) return 0; } - /* * * Options list: @@ -1381,7 +1366,7 @@ static int das1600_mode_detect(comedi_device *dev) * 3 Clock speed (in MHz) */ -static int das16_attach(comedi_device *dev, comedi_devconfig *it) +static int das16_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int ret; @@ -1401,45 +1386,45 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) * waiting for dma done interrupt (due to hardware limitations) */ irq = 0; timer_mode = 1; - if( timer_mode ) irq = 0; + if (timer_mode) + irq = 0; - printk("comedi%d: das16:",dev->minor); + printk("comedi%d: das16:", dev->minor); // check that clock setting is valid - if(it->options[3]) - { - if(it->options[3] != 0 && - it->options[3] != 1 && - it->options[3] != 10) - { + if (it->options[3]) { + if (it->options[3] != 0 && + it->options[3] != 1 && it->options[3] != 10) { printk("\n Invalid option. Master clock must be set to 1 or 10 (MHz)\n"); return -EINVAL; } } - if((ret=alloc_private(dev,sizeof(struct das16_private_struct)))<0) + if ((ret = alloc_private(dev, sizeof(struct das16_private_struct))) < 0) return ret; - if(thisboard->size<0x400){ - printk(" 0x%04lx-0x%04lx\n", iobase, iobase+thisboard->size); - if(!request_region(iobase,thisboard->size,"das16")){ + if (thisboard->size < 0x400) { + printk(" 0x%04lx-0x%04lx\n", iobase, iobase + thisboard->size); + if (!request_region(iobase, thisboard->size, "das16")) { printk(" I/O port conflict\n"); return -EIO; } - }else{ + } else { printk(" 0x%04lx-0x%04lx 0x%04lx-0x%04lx\n", - iobase,iobase+0x0f, - iobase+0x400,iobase+0x400+(thisboard->size&0x3ff)); - if(!request_region(iobase,0x10,"das16")){ + iobase, iobase + 0x0f, + iobase + 0x400, + iobase + 0x400 + (thisboard->size & 0x3ff)); + if (!request_region(iobase, 0x10, "das16")) { printk(" I/O port conflict: 0x%04lx-0x%04lx\n", - iobase,iobase+0x0f); + iobase, iobase + 0x0f); return -EIO; } - if(!request_region(iobase+0x400,thisboard->size&0x3ff,"das16")){ + if (!request_region(iobase + 0x400, thisboard->size & 0x3ff, + "das16")) { release_region(iobase, 0x10); printk(" I/O port conflict: 0x%04lx-0x%04lx\n", - iobase+0x400, - iobase+0x400+(thisboard->size&0x3ff)); + iobase + 0x400, + iobase + 0x400 + (thisboard->size & 0x3ff)); return -EIO; } } @@ -1447,56 +1432,50 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) dev->iobase = iobase; // probe id bits to make sure they are consistent - if(das16_probe(dev, it)) - { + if (das16_probe(dev, it)) { printk(" id bits do not match selected board, aborting\n"); return -EINVAL; } dev->board_name = thisboard->name; // get master clock speed - if(thisboard->size < 0x400) - { - if(it->options[3]) + if (thisboard->size < 0x400) { + if (it->options[3]) devpriv->clockbase = 1000 / it->options[3]; else devpriv->clockbase = 1000; // 1 MHz default - }else - { + } else { das1600_mode_detect(dev); } /* now for the irq */ - if( irq > 1 && irq < 8 ) - { - if((ret=comedi_request_irq(irq, das16_dma_interrupt, 0, "das16",dev)) < 0) + if (irq > 1 && irq < 8) { + if ((ret = comedi_request_irq(irq, das16_dma_interrupt, 0, + "das16", dev)) < 0) return ret; dev->irq = irq; - printk(" ( irq = %u )",irq); - }else if(irq == 0){ + printk(" ( irq = %u )", irq); + } else if (irq == 0) { printk(" ( no irq )"); - }else - { + } else { printk(" invalid irq\n"); return -EINVAL; } // initialize dma dma_chan = it->options[2]; - if(dma_chan == 1 || dma_chan == 3) - { + if (dma_chan == 1 || dma_chan == 3) { // allocate dma buffers int i; - for( i = 0; i < 2; i++) - { - devpriv->dma_buffer[i] = pci_alloc_consistent( NULL, - DAS16_DMA_SIZE, &devpriv->dma_buffer_addr[i] ); - if( devpriv->dma_buffer[i] == NULL ) + for (i = 0; i < 2; i++) { + devpriv->dma_buffer[i] = pci_alloc_consistent(NULL, + DAS16_DMA_SIZE, &devpriv->dma_buffer_addr[i]); + if (devpriv->dma_buffer[i] == NULL) return -ENOMEM; } - if(request_dma(dma_chan, "das16")) - { - printk(" failed to allocate dma channel %i\n", dma_chan); + if (request_dma(dma_chan, "das16")) { + printk(" failed to allocate dma channel %i\n", + dma_chan); return -EINVAL; } devpriv->dma_chan = dma_chan; @@ -1505,21 +1484,20 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) set_dma_mode(devpriv->dma_chan, DMA_MODE_READ); release_dma_lock(flags); printk(" ( dma = %u)\n", dma_chan); - }else if(dma_chan == 0){ + } else if (dma_chan == 0) { printk(" ( no dma )\n"); - }else - { + } else { printk(" invalid dma channel\n"); return -EINVAL; } // get any user-defined input range - if(thisboard->ai_pg == das16_pg_none && - (it->options[4] || it->options[5])) - { + if (thisboard->ai_pg == das16_pg_none && + (it->options[4] || it->options[5])) { // allocate single-range range table devpriv->user_ai_range_table = - kmalloc(sizeof(comedi_lrange) + sizeof(comedi_krange), GFP_KERNEL); + kmalloc(sizeof(comedi_lrange) + sizeof(comedi_krange), + GFP_KERNEL); // initialize ai range devpriv->user_ai_range_table->length = 1; user_ai_range = devpriv->user_ai_range_table->range; @@ -1528,11 +1506,11 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) user_ai_range->flags = UNIT_volt; } // get any user-defined output range - if(it->options[6] || it->options[7]) - { + if (it->options[6] || it->options[7]) { // allocate single-range range table devpriv->user_ao_range_table = - kmalloc(sizeof(comedi_lrange) + sizeof(comedi_krange), GFP_KERNEL); + kmalloc(sizeof(comedi_lrange) + sizeof(comedi_krange), + GFP_KERNEL); // initialize ao range devpriv->user_ao_range_table->length = 1; user_ao_range = devpriv->user_ao_range_table->range; @@ -1541,39 +1519,37 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) user_ao_range->flags = UNIT_volt; } - if(timer_mode) - { + if (timer_mode) { init_timer(&(devpriv->timer)); devpriv->timer.function = das16_timer_interrupt; - devpriv->timer.data = (unsigned long) dev; + devpriv->timer.data = (unsigned long)dev; } devpriv->timer_mode = timer_mode ? 1 : 0; - if((ret=alloc_subdevices(dev, 5))<0) + if ((ret = alloc_subdevices(dev, 5)) < 0) return ret; - s=dev->subdevices+0; - dev->read_subdev=s; + s = dev->subdevices + 0; + dev->read_subdev = s; /* ai */ - if(thisboard->ai){ + if (thisboard->ai) { s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; - if(devpriv->ai_singleended){ + if (devpriv->ai_singleended) { s->n_chan = 16; s->len_chanlist = 16; s->subdev_flags |= SDF_GROUND; - }else{ + } else { s->n_chan = 8; s->len_chanlist = 8; s->subdev_flags |= SDF_DIFF; } s->maxdata = (1 << thisboard->ai_nbits) - 1; - if(devpriv->user_ai_range_table) - { // user defined ai range + if (devpriv->user_ai_range_table) { // user defined ai range s->range_table = devpriv->user_ai_range_table; - }else if(devpriv->ai_unipolar){ + } else if (devpriv->ai_unipolar) { s->range_table = das16_ai_uni_lranges[thisboard->ai_pg]; - }else{ + } else { s->range_table = das16_ai_bip_lranges[thisboard->ai_pg]; } s->insn_read = thisboard->ai; @@ -1581,45 +1557,43 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) s->do_cmd = das16_cmd_exec; s->cancel = das16_cancel; s->munge = das16_ai_munge; - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } s = dev->subdevices + 1; /* ao */ - if(thisboard->ao){ + if (thisboard->ao) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE; s->n_chan = 2; s->maxdata = (1 << thisboard->ao_nbits) - 1; - if(devpriv->user_ao_range_table) - { // user defined ao range + if (devpriv->user_ao_range_table) { // user defined ao range s->range_table = devpriv->user_ao_range_table; - }else - { + } else { s->range_table = &range_unknown; } s->insn_write = thisboard->ao; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } s = dev->subdevices + 2; /* di */ - if(thisboard->di){ + if (thisboard->di) { s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 4; s->maxdata = 1; s->range_table = &range_digital; s->insn_bits = thisboard->di; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } s = dev->subdevices + 3; /* do */ - if(thisboard->do_){ + if (thisboard->do_) { s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 4; @@ -1628,16 +1602,16 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) s->insn_bits = thisboard->do_; // initialize digital output lines outb(s->state, dev->iobase + DAS16_DIO); - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } s = dev->subdevices + 4; /* 8255 */ - if(thisboard->i8255_offset!=0){ - subdev_8255_init(dev,s,NULL,(dev->iobase+ - thisboard->i8255_offset)); - }else{ + if (thisboard->i8255_offset != 0) { + subdev_8255_init(dev, s, NULL, (dev->iobase + + thisboard->i8255_offset)); + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -1647,8 +1621,7 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) outb(devpriv->control_state, dev->iobase + DAS16_CONTROL); // turn on das1600 mode if available - if(thisboard->size > 0x400) - { + if (thisboard->size > 0x400) { outb(DAS1600_ENABLE_VAL, dev->iobase + DAS1600_ENABLE); outb(0, dev->iobase + DAS1600_CONV); outb(0, dev->iobase + DAS1600_BURST); @@ -1657,43 +1630,41 @@ static int das16_attach(comedi_device *dev, comedi_devconfig *it) return 0; } - -static int das16_detach(comedi_device *dev) +static int das16_detach(comedi_device * dev) { printk("comedi%d: das16: remove\n", dev->minor); das16_reset(dev); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices+4); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 4); - if(devpriv) - { + if (devpriv) { int i; - for( i = 0; i < 2; i++ ) - { - if( devpriv->dma_buffer[i] ) - pci_free_consistent( NULL, DAS16_DMA_SIZE, devpriv->dma_buffer[i], - devpriv->dma_buffer_addr[i] ); + for (i = 0; i < 2; i++) { + if (devpriv->dma_buffer[i]) + pci_free_consistent(NULL, DAS16_DMA_SIZE, + devpriv->dma_buffer[i], + devpriv->dma_buffer_addr[i]); } - if(devpriv->dma_chan) + if (devpriv->dma_chan) free_dma(devpriv->dma_chan); - if(devpriv->user_ai_range_table) + if (devpriv->user_ai_range_table) kfree(devpriv->user_ai_range_table); - if(devpriv->user_ao_range_table) + if (devpriv->user_ao_range_table) kfree(devpriv->user_ao_range_table); } - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if( dev->iobase ) - { - if(thisboard->size < 0x400){ + if (dev->iobase) { + if (thisboard->size < 0x400) { release_region(dev->iobase, thisboard->size); - }else{ + } else { release_region(dev->iobase, 0x10); - release_region(dev->iobase + 0x400, thisboard->size&0x3ff); + release_region(dev->iobase + 0x400, + thisboard->size & 0x3ff); } } @@ -1703,7 +1674,8 @@ static int das16_detach(comedi_device *dev) COMEDI_INITCLEANUP(driver_das16); // utility function that suggests a dma transfer size in bytes -static unsigned int das16_suggest_transfer_size(comedi_device *dev, comedi_cmd cmd) +static unsigned int das16_suggest_transfer_size(comedi_device * dev, + comedi_cmd cmd) { unsigned int size; unsigned int freq; @@ -1711,53 +1683,48 @@ static unsigned int das16_suggest_transfer_size(comedi_device *dev, comedi_cmd c /* if we are using timer interrupt, we don't care how long it * will take to complete transfer since it will be interrupted * by timer interrupt */ - if(devpriv->timer_mode) return DAS16_DMA_SIZE; + if (devpriv->timer_mode) + return DAS16_DMA_SIZE; /* otherwise, we are relying on dma terminal count interrupt, * so pick a reasonable size */ - if(cmd.convert_src == TRIG_TIMER) + if (cmd.convert_src == TRIG_TIMER) freq = 1000000000 / cmd.convert_arg; - else if(cmd.scan_begin_src == TRIG_TIMER) + else if (cmd.scan_begin_src == TRIG_TIMER) freq = (1000000000 / cmd.scan_begin_arg) * cmd.chanlist_len; // return some default value else freq = 0xffffffff; - if(cmd.flags & TRIG_WAKE_EOS) - { + if (cmd.flags & TRIG_WAKE_EOS) { size = sample_size * cmd.chanlist_len; - }else - { + } else { // make buffer fill in no more than 1/3 second size = (freq / 3) * sample_size; } // set a minimum and maximum size allowed - if(size > DAS16_DMA_SIZE) + if (size > DAS16_DMA_SIZE) size = DAS16_DMA_SIZE - DAS16_DMA_SIZE % sample_size; - else if(size < sample_size) + else if (size < sample_size) size = sample_size; - if( cmd.stop_src == TRIG_COUNT && size > devpriv->adc_byte_count ) + if (cmd.stop_src == TRIG_COUNT && size > devpriv->adc_byte_count) size = devpriv->adc_byte_count; return size; } -static void das16_ai_munge(comedi_device *dev, comedi_subdevice *s, void *array, - unsigned int num_bytes, unsigned int start_chan_index) +static void das16_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *array, unsigned int num_bytes, unsigned int start_chan_index) { unsigned int i, num_samples = num_bytes / sizeof(sampl_t); sampl_t *data = array; - for(i = 0; i < num_samples; i++) - { + for (i = 0; i < num_samples; i++) { data[i] = le16_to_cpu(data[i]); - if( thisboard->ai_nbits == 12 ) - { + if (thisboard->ai_nbits == 12) { data[i] = (data[i] >> 4) & 0xfff; } } } - - diff --git a/comedi/drivers/das16m1.c b/comedi/drivers/das16m1.c index a68c8e44..f8a1e68c 100644 --- a/comedi/drivers/das16m1.c +++ b/comedi/drivers/das16m1.c @@ -70,7 +70,7 @@ irq can be omitted, although the cmd interface will not work without it. #define DAS16M1_XTAL 100 //10 MHz master clock -#define FIFO_SIZE 1024 // 1024 sample fifo +#define FIFO_SIZE 1024 // 1024 sample fifo /* CIO-DAS16_M1.pdf @@ -117,71 +117,75 @@ irq can be omitted, although the cmd interface will not work without it. #define DAS16M1_82C55 0x400 #define DAS16M1_8254_THIRD 0x404 -static const comedi_lrange range_das16m1 = -{ 9, +static const comedi_lrange range_das16m1 = { 9, { - 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), - 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), + BIP_RANGE(10), + } }; -static int das16m1_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int das16m1_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int das16m1_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int das16m1_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16m1_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das16m1_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int das16m1_cmd_test(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int das16m1_cmd_exec(comedi_device *dev,comedi_subdevice *s); -static int das16m1_cancel(comedi_device *dev, comedi_subdevice *s); +static int das16m1_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int das16m1_cmd_exec(comedi_device * dev, comedi_subdevice * s); +static int das16m1_cancel(comedi_device * dev, comedi_subdevice * s); -static int das16m1_poll(comedi_device *dev, comedi_subdevice *s); +static int das16m1_poll(comedi_device * dev, comedi_subdevice * s); static irqreturn_t das16m1_interrupt(int irq, void *d PT_REGS_ARG); -static void das16m1_handler(comedi_device *dev, unsigned int status); +static void das16m1_handler(comedi_device * dev, unsigned int status); -static unsigned int das16m1_set_pacer(comedi_device *dev, unsigned int ns, int round_flag); +static unsigned int das16m1_set_pacer(comedi_device * dev, unsigned int ns, + int round_flag); static int das16m1_irq_bits(unsigned int irq); -typedef struct das16m1_board_struct{ +typedef struct das16m1_board_struct { const char *name; unsigned int ai_speed; -}das16m1_board; +} das16m1_board; -static const das16m1_board das16m1_boards[]={ +static const das16m1_board das16m1_boards[] = { { - name: "cio-das16/m1", // CIO-DAS16_M1.pdf - ai_speed: 1000, // 1MHz max speed - }, + name: "cio-das16/m1", // CIO-DAS16_M1.pdf + ai_speed:1000, // 1MHz max speed + }, }; #define das16m1_num_boards ((sizeof(das16m1_boards)) / (sizeof(das16m1_boards[0]))) -static int das16m1_attach(comedi_device *dev, comedi_devconfig *it); -static int das16m1_detach(comedi_device *dev); -static comedi_driver driver_das16m1={ - driver_name: "das16m1", - module: THIS_MODULE, - attach: das16m1_attach, - detach: das16m1_detach, - board_name: &das16m1_boards[0].name, - num_names: das16m1_num_boards, - offset: sizeof(das16m1_boards[0]), +static int das16m1_attach(comedi_device * dev, comedi_devconfig * it); +static int das16m1_detach(comedi_device * dev); +static comedi_driver driver_das16m1 = { + driver_name:"das16m1", + module:THIS_MODULE, + attach:das16m1_attach, + detach:das16m1_detach, + board_name:&das16m1_boards[0].name, + num_names:das16m1_num_boards, + offset:sizeof(das16m1_boards[0]), }; struct das16m1_private_struct { - unsigned int control_state; - volatile unsigned int adc_count; // number of samples completed + unsigned int control_state; + volatile unsigned int adc_count; // number of samples completed /* initial value in lower half of hardware conversion counter, * needed to keep track of whether new count has been loaded into * counter yet (loaded by first sample conversion) */ u16 initial_hw_count; - sampl_t ai_buffer[ FIFO_SIZE ]; + sampl_t ai_buffer[FIFO_SIZE]; unsigned int do_bits; // saves status of digital output bits unsigned int divisor1; // divides master clock to obtain conversion speed unsigned int divisor2; // divides master clock to obtain conversion speed @@ -191,134 +195,140 @@ struct das16m1_private_struct { COMEDI_INITCLEANUP(driver_das16m1); -static inline sampl_t munge_sample( sampl_t data ) +static inline sampl_t munge_sample(sampl_t data) { - return ( data >> 4 ) & 0xfff; + return (data >> 4) & 0xfff; } -static int das16m1_cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) +static int das16m1_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - unsigned int err=0, tmp, i; + unsigned int err = 0, tmp, i; /* make sure triggers are valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) err++; - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT) err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg != 0){ + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src == TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg != 0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len){ + 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_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err) return 3; + if (err) + return 3; /* step 4: fix up arguments */ - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { tmp = cmd->convert_arg; /* calculate counter values that give desired timing */ - i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, &(devpriv->divisor1), - &(devpriv->divisor2), &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->convert_arg) err++; + i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, + &(devpriv->divisor1), &(devpriv->divisor2), + &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err++; } - if(err) return 4; + if (err) + return 4; // check chanlist against board's peculiarities - if(cmd->chanlist && cmd->chanlist_len > 1) - { - for(i = 0; i < cmd->chanlist_len; i++) - { + if (cmd->chanlist && cmd->chanlist_len > 1) { + for (i = 0; i < cmd->chanlist_len; i++) { // even/odd channels must go into even/odd queue addresses - if((i % 2) != (CR_CHAN(cmd->chanlist[i]) % 2)) - { + if ((i % 2) != (CR_CHAN(cmd->chanlist[i]) % 2)) { comedi_error(dev, "bad chanlist:\n" " even/odd channels must go have even/odd chanlist indices"); err++; } } - if((cmd->chanlist_len % 2) != 0) - { - comedi_error(dev, "chanlist must be of even length or length 1"); + if ((cmd->chanlist_len % 2) != 0) { + comedi_error(dev, + "chanlist must be of even length or length 1"); err++; } } - if(err) return 5; + if (err) + return 5; return 0; } -static int das16m1_cmd_exec(comedi_device *dev,comedi_subdevice *s) +static int das16m1_cmd_exec(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; unsigned int byte, i; - if(dev->irq == 0) - { + if (dev->irq == 0) { comedi_error(dev, "irq required to execute comedi_cmd"); return -1; } @@ -335,24 +345,27 @@ static int das16m1_cmd_exec(comedi_device *dev,comedi_subdevice *s) i8254_load(dev->iobase + DAS16M1_8254_FIRST, 0, 1, 0, 2); /* remember current reading of counter so we know when counter has * actually been loaded */ - devpriv->initial_hw_count = i8254_read(dev->iobase + DAS16M1_8254_FIRST, 0, 1); + devpriv->initial_hw_count = + i8254_read(dev->iobase + DAS16M1_8254_FIRST, 0, 1); /* setup channel/gain queue */ - for(i = 0; i < cmd->chanlist_len; i++) - { + for (i = 0; i < cmd->chanlist_len; i++) { outb(i, dev->iobase + DAS16M1_QUEUE_ADDR); - byte = Q_CHAN(CR_CHAN(cmd->chanlist[i])) | Q_RANGE(CR_RANGE(cmd->chanlist[i])); + byte = Q_CHAN(CR_CHAN(cmd-> + chanlist[i])) | Q_RANGE(CR_RANGE(cmd-> + chanlist[i])); outb(byte, dev->iobase + DAS16M1_QUEUE_DATA); } /* set counter mode and counts */ - cmd->convert_arg = das16m1_set_pacer(dev, cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); + cmd->convert_arg = + das16m1_set_pacer(dev, cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); // set control & status register byte = 0; /* if we are using external start trigger (also board dislikes having * both start and conversion triggers external simultaneously) */ - if(cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT) - { + if (cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT) { byte |= EXT_TRIG_BIT; } outb(byte, dev->iobase + DAS16M1_CS); @@ -361,11 +374,9 @@ static int das16m1_cmd_exec(comedi_device *dev,comedi_subdevice *s) /* enable interrupts and internal pacer */ devpriv->control_state &= ~PACER_MASK; - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { devpriv->control_state |= INT_PACER; - }else - { + } else { devpriv->control_state |= EXT_PACER; } devpriv->control_state |= INTE; @@ -374,7 +385,7 @@ static int das16m1_cmd_exec(comedi_device *dev,comedi_subdevice *s) return 0; } -static int das16m1_cancel(comedi_device *dev, comedi_subdevice *s) +static int das16m1_cancel(comedi_device * dev, comedi_subdevice * s) { devpriv->control_state &= ~INTE & ~PACER_MASK; outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL); @@ -382,7 +393,8 @@ static int das16m1_cancel(comedi_device *dev, comedi_subdevice *s) return 0; } -static int das16m1_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16m1_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i, n; int byte; @@ -394,33 +406,32 @@ static int das16m1_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * /* setup channel/gain queue */ outb(0, dev->iobase + DAS16M1_QUEUE_ADDR); - byte = Q_CHAN(CR_CHAN(insn->chanspec)) | Q_RANGE(CR_RANGE(insn->chanspec)); + byte = Q_CHAN(CR_CHAN(insn->chanspec)) | Q_RANGE(CR_RANGE(insn-> + chanspec)); outb(byte, dev->iobase + DAS16M1_QUEUE_DATA); - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* clear IRQDATA bit */ outb(0, dev->iobase + DAS16M1_CLEAR_INTR); /* trigger conversion */ outb(0, dev->iobase); - for(i = 0; i < timeout; i++) - { - if(inb(dev->iobase + DAS16M1_CS) & IRQDATA) + for (i = 0; i < timeout; i++) { + if (inb(dev->iobase + DAS16M1_CS) & IRQDATA) break; } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } - data[n] = munge_sample( inw( dev->iobase ) ); + data[n] = munge_sample(inw(dev->iobase)); } return n; } -static int das16m1_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16m1_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t bits; @@ -431,7 +442,8 @@ static int das16m1_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn * return 2; } -static int das16m1_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int das16m1_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t wbits; @@ -450,7 +462,7 @@ static int das16m1_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn * return 2; } -static int das16m1_poll(comedi_device *dev, comedi_subdevice *s) +static int das16m1_poll(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; unsigned int status; @@ -469,19 +481,16 @@ static irqreturn_t das16m1_interrupt(int irq, void *d PT_REGS_ARG) int status; comedi_device *dev = d; - if(dev->attached == 0) - { + if (dev->attached == 0) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } - // prevent race with comedi_poll() spin_lock(&dev->spinlock); status = inb(dev->iobase + DAS16M1_CS); - if((status & (IRQDATA | OVRUN)) == 0) - { + if ((status & (IRQDATA | OVRUN)) == 0) { comedi_error(dev, "spurious interrupt"); spin_unlock(&dev->spinlock); return IRQ_NONE; @@ -496,17 +505,16 @@ static irqreturn_t das16m1_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static void munge_sample_array( sampl_t *array, unsigned int num_elements ) +static void munge_sample_array(sampl_t * array, unsigned int num_elements) { unsigned int i; - for(i = 0; i < num_elements; i++) - { - array[i] = munge_sample( array[i] ); + for (i = 0; i < num_elements; i++) { + array[i] = munge_sample(array[i]); } } -static void das16m1_handler(comedi_device *dev, unsigned int status) +static void das16m1_handler(comedi_device * dev, unsigned int status) { comedi_subdevice *s; comedi_async *async; @@ -523,46 +531,41 @@ static void das16m1_handler(comedi_device *dev, unsigned int status) hw_counter = i8254_read(dev->iobase + DAS16M1_8254_FIRST, 0, 1); /* make sure hardware counter reading is not bogus due to initial value * not having been loaded yet */ - if(devpriv->adc_count == 0 && hw_counter == devpriv->initial_hw_count) - { + if (devpriv->adc_count == 0 && hw_counter == devpriv->initial_hw_count) { num_samples = 0; - }else - { + } else { /* The calculation of num_samples looks odd, but it uses the following facts. * 16 bit hardware counter is initialized with value of zero (which really * means 0x1000). The counter decrements by one on each conversion * (when the counter decrements from zero it goes to 0xffff). num_samples * is a 16 bit variable, so it will roll over in a similar fashion to the * hardware counter. Work it out, and this is what you get. */ - num_samples = - hw_counter - devpriv->adc_count; + num_samples = -hw_counter - devpriv->adc_count; } // check if we only need some of the points - if(cmd->stop_src == TRIG_COUNT) - { - if(num_samples > cmd->stop_arg * cmd->chanlist_len) + if (cmd->stop_src == TRIG_COUNT) { + if (num_samples > cmd->stop_arg * cmd->chanlist_len) num_samples = cmd->stop_arg * cmd->chanlist_len; } // make sure we dont try to get too many points if fifo has overrun - if(num_samples > FIFO_SIZE) + if (num_samples > FIFO_SIZE) num_samples = FIFO_SIZE; - insw( dev->iobase, devpriv->ai_buffer, num_samples ); - munge_sample_array( devpriv->ai_buffer, num_samples ); - cfc_write_array_to_buffer( s, devpriv->ai_buffer, num_samples * sizeof( sampl_t ) ); + insw(dev->iobase, devpriv->ai_buffer, num_samples); + munge_sample_array(devpriv->ai_buffer, num_samples); + cfc_write_array_to_buffer(s, devpriv->ai_buffer, + num_samples * sizeof(sampl_t)); devpriv->adc_count += num_samples; - if(cmd->stop_src == TRIG_COUNT) - { - if(devpriv->adc_count >= cmd->stop_arg * cmd->chanlist_len) - { /* end of acquisition */ - das16m1_cancel(dev, s); - async->events |= COMEDI_CB_EOA; + if (cmd->stop_src == TRIG_COUNT) { + if (devpriv->adc_count >= cmd->stop_arg * cmd->chanlist_len) { /* end of acquisition */ + das16m1_cancel(dev, s); + async->events |= COMEDI_CB_EOA; } } /* this probably won't catch overruns since the card doesn't generate * overrun interrupts, but we might as well try */ - if(status & OVRUN) - { + if (status & OVRUN) { das16m1_cancel(dev, s); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_error(dev, "fifo overflow"); @@ -575,14 +578,17 @@ static void das16m1_handler(comedi_device *dev, unsigned int status) /* This function takes a time in nanoseconds and sets the * * 2 pacer clocks to the closest frequency possible. It also * * returns the actual sampling period. */ -static unsigned int das16m1_set_pacer(comedi_device *dev, unsigned int ns, int rounding_flags) +static unsigned int das16m1_set_pacer(comedi_device * dev, unsigned int ns, + int rounding_flags) { i8253_cascade_ns_to_timer_2div(DAS16M1_XTAL, &(devpriv->divisor1), &(devpriv->divisor2), &ns, rounding_flags & TRIG_ROUND_MASK); /* Write the values of ctr1 and ctr2 into counters 1 and 2 */ - i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 1, devpriv->divisor1, 2); - i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 2, devpriv->divisor2, 2); + i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 1, devpriv->divisor1, + 2); + i8254_load(dev->iobase + DAS16M1_8254_SECOND, 0, 2, devpriv->divisor2, + 2); return ns; } @@ -591,35 +597,34 @@ static int das16m1_irq_bits(unsigned int irq) { int ret; - switch(irq) - { - case 10: - ret = 0x0; - break; - case 11: - ret = 0x1; - break; - case 12: - ret = 0x2; - break; - case 15: - ret = 0x3; - break; - case 2: - ret = 0x4; - break; - case 3: - ret = 0x5; - break; - case 5: - ret = 0x6; - break; - case 7: - ret = 0x7; - break; - default: - return -1; - break; + switch (irq) { + case 10: + ret = 0x0; + break; + case 11: + ret = 0x1; + break; + case 12: + ret = 0x2; + break; + case 15: + ret = 0x3; + break; + case 2: + ret = 0x4; + break; + case 3: + ret = 0x5; + break; + case 5: + ret = 0x6; + break; + case 7: + ret = 0x7; + break; + default: + return -1; + break; } return (ret << 4); } @@ -630,7 +635,7 @@ static int das16m1_irq_bits(unsigned int irq) * 1 IRQ */ -static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) +static int das16m1_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int ret; @@ -641,20 +646,22 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) printk("comedi%d: das16m1:", dev->minor); - if((ret = alloc_private(dev, sizeof(struct das16m1_private_struct))) < 0) + if ((ret = alloc_private(dev, + sizeof(struct das16m1_private_struct))) < 0) return ret; dev->board_name = thisboard->name; printk(" io 0x%lx-0x%lx 0x%lx-0x%lx", - iobase, iobase + DAS16M1_SIZE, - iobase + DAS16M1_82C55, iobase + DAS16M1_82C55 + DAS16M1_SIZE2); - if(!request_region(iobase, DAS16M1_SIZE, driver_das16m1.driver_name)) { + iobase, iobase + DAS16M1_SIZE, + iobase + DAS16M1_82C55, iobase + DAS16M1_82C55 + DAS16M1_SIZE2); + if (!request_region(iobase, DAS16M1_SIZE, driver_das16m1.driver_name)) { printk(" I/O port conflict\n"); return -EIO; } - if(!request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2, driver_das16m1.driver_name)) { - release_region(iobase , DAS16M1_SIZE); + if (!request_region(iobase + DAS16M1_82C55, DAS16M1_SIZE2, + driver_das16m1.driver_name)) { + release_region(iobase, DAS16M1_SIZE); printk(" I/O port conflict\n"); return -EIO; } @@ -663,26 +670,24 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) /* now for the irq */ irq = it->options[1]; // make sure it is valid - if(das16m1_irq_bits(irq) >= 0) - { + if (das16m1_irq_bits(irq) >= 0) { ret = comedi_request_irq(irq, das16m1_interrupt, 0, driver_das16m1.driver_name, dev); - if(ret < 0) - { + if (ret < 0) { printk(", irq unavailable\n"); return ret; } dev->irq = irq; printk(", irq %u\n", irq); - }else if(irq == 0){ + } else if (irq == 0) { printk(", no irq\n"); - }else { + } else { printk(", invalid irq\n" " valid irqs are 2, 3, 5, 7, 10, 11, 12, or 15\n"); return -EINVAL; } - if((ret = alloc_subdevices(dev, 4)) < 0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; s = dev->subdevices + 0; @@ -730,7 +735,7 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) outb(devpriv->do_bits, dev->iobase + DAS16M1_DIO); /* set the interrupt level */ - if(dev->irq) + if (dev->irq) devpriv->control_state = das16m1_irq_bits(dev->irq); else devpriv->control_state = 0; @@ -739,25 +744,22 @@ static int das16m1_attach(comedi_device *dev, comedi_devconfig *it) return 0; } - -static int das16m1_detach(comedi_device *dev) +static int das16m1_detach(comedi_device * dev) { printk("comedi%d: das16m1: remove\n", dev->minor); -// das16m1_reset(dev); +// das16m1_reset(dev); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 3); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 3); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(dev->iobase){ - release_region(dev->iobase , DAS16M1_SIZE); + if (dev->iobase) { + release_region(dev->iobase, DAS16M1_SIZE); release_region(dev->iobase + DAS16M1_82C55, DAS16M1_SIZE2); } return 0; } - - diff --git a/comedi/drivers/das1800.c b/comedi/drivers/das1800.c index 532f42bf..d35b67e5 100644 --- a/comedi/drivers/das1800.c +++ b/comedi/drivers/das1800.c @@ -173,291 +173,301 @@ TODO: #define IOBASE2 0x400 //offset of additional ioports used on 'ao' cards -enum{ - das1701st, das1701st_da, das1702st, das1702st_da, das1702hr, das1702hr_da, +enum { + das1701st, das1701st_da, das1702st, das1702st_da, das1702hr, + das1702hr_da, das1701ao, das1702ao, das1801st, das1801st_da, das1802st, das1802st_da, das1802hr, das1802hr_da, das1801hc, das1802hc, das1801ao, das1802ao }; -static int das1800_attach(comedi_device *dev, comedi_devconfig *it); -static int das1800_detach(comedi_device *dev); -static int das1800_probe(comedi_device *dev); -static int das1800_cancel(comedi_device *dev, comedi_subdevice *s); +static int das1800_attach(comedi_device * dev, comedi_devconfig * it); +static int das1800_detach(comedi_device * dev); +static int das1800_probe(comedi_device * dev); +static int das1800_cancel(comedi_device * dev, comedi_subdevice * s); static irqreturn_t das1800_interrupt(int irq, void *d PT_REGS_ARG); -static int das1800_ai_poll(comedi_device *dev,comedi_subdevice *s); -static void das1800_ai_handler(comedi_device *dev); -static void das1800_handle_dma(comedi_device *dev, comedi_subdevice *s, unsigned int status); -static void das1800_flush_dma(comedi_device *dev, comedi_subdevice *s); -static void das1800_flush_dma_channel(comedi_device *dev, comedi_subdevice *s, unsigned int channel, uint16_t *buffer); -static void das1800_handle_fifo_half_full(comedi_device *dev, comedi_subdevice *s); -static void das1800_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice *s); -static int das1800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int das1800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s); -static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das1800_ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das1800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das1800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); - -static int das1800_set_frequency(comedi_device *dev); +static int das1800_ai_poll(comedi_device * dev, comedi_subdevice * s); +static void das1800_ai_handler(comedi_device * dev); +static void das1800_handle_dma(comedi_device * dev, comedi_subdevice * s, + unsigned int status); +static void das1800_flush_dma(comedi_device * dev, comedi_subdevice * s); +static void das1800_flush_dma_channel(comedi_device * dev, comedi_subdevice * s, + unsigned int channel, uint16_t * buffer); +static void das1800_handle_fifo_half_full(comedi_device * dev, + comedi_subdevice * s); +static void das1800_handle_fifo_not_empty(comedi_device * dev, + comedi_subdevice * s); +static int das1800_ai_do_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int das1800_ai_do_cmd(comedi_device * dev, comedi_subdevice * s); +static int das1800_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das1800_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das1800_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das1800_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int das1800_set_frequency(comedi_device * dev); static unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode); -static unsigned int suggest_transfer_size(comedi_cmd *cmd); +static unsigned int suggest_transfer_size(comedi_cmd * cmd); // analog input ranges static const comedi_lrange range_ai_das1801 = { 8, { - RANGE( -5, 5 ), - RANGE( -1, 1 ), - RANGE( -0.1, 0.1 ), - RANGE( -0.02, 0.02 ), - RANGE( 0, 5 ), - RANGE( 0, 1 ), - RANGE( 0, 0.1 ), - RANGE( 0, 0.02 ), - } + RANGE(-5, 5), + RANGE(-1, 1), + RANGE(-0.1, 0.1), + RANGE(-0.02, 0.02), + RANGE(0, 5), + RANGE(0, 1), + RANGE(0, 0.1), + RANGE(0, 0.02), + } }; static const comedi_lrange range_ai_das1802 = { 8, { - RANGE(-10, 10), - RANGE(-5, 5), - RANGE(-2.5, 2.5), - RANGE(-1.25, 1.25), - RANGE(0, 10), - RANGE(0, 5), - RANGE(0, 2.5), - RANGE(0, 1.25), - } + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25), + } }; -typedef struct das1800_board_struct{ +typedef struct das1800_board_struct { const char *name; - int ai_speed; /* max conversion period in nanoseconds */ - int resolution; /* bits of ai resolution */ - int qram_len; /* length of card's channel / gain queue */ - int common; /* supports AREF_COMMON flag */ - int do_n_chan; /* number of digital output channels */ - int ao_ability; /* 0 == no analog out, 1 == basic analog out, 2 == waveform analog out */ - int ao_n_chan; /* number of analog out channels */ + int ai_speed; /* max conversion period in nanoseconds */ + int resolution; /* bits of ai resolution */ + int qram_len; /* length of card's channel / gain queue */ + int common; /* supports AREF_COMMON flag */ + int do_n_chan; /* number of digital output channels */ + int ao_ability; /* 0 == no analog out, 1 == basic analog out, 2 == waveform analog out */ + int ao_n_chan; /* number of analog out channels */ const comedi_lrange *range_ai; /* available input ranges */ -}das1800_board; +} das1800_board; /* Warning: the maximum conversion speeds listed below are * not always achievable depending on board setup (see * user manual.) */ -static const das1800_board das1800_boards[] = -{ - { - name: "das-1701st", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1801, - }, - { - name: "das-1701st-da", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 1, - ao_n_chan: 4, - range_ai: &range_ai_das1801, - }, - { - name: "das-1702st", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1802, - }, - { - name: "das-1702st-da", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 1, - ao_n_chan: 4, - range_ai: &range_ai_das1802, - }, - { - name: "das-1702hr", - ai_speed: 20000, - resolution: 16, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1802, - }, - { - name: "das-1702hr-da", - ai_speed: 20000, - resolution: 16, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 1, - ao_n_chan: 2, - range_ai: &range_ai_das1802, - }, - { - name: "das-1701ao", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 2, - ao_n_chan: 2, - range_ai: &range_ai_das1801, - }, - { - name: "das-1702ao", - ai_speed: 6250, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 2, - ao_n_chan: 2, - range_ai: &range_ai_das1802, - }, - { - name: "das-1801st", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1801, - }, - { - name: "das-1801st-da", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 4, - range_ai: &range_ai_das1801, - }, - { - name: "das-1802st", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1802, - }, - { - name: "das-1802st-da", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 1, - ao_n_chan: 4, - range_ai: &range_ai_das1802, - }, - { - name: "das-1802hr", - ai_speed: 10000, - resolution: 16, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 0, - ao_n_chan: 0, - range_ai: &range_ai_das1802, - }, - { - name: "das-1802hr-da", - ai_speed: 10000, - resolution: 16, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 1, - ao_n_chan: 2, - range_ai: &range_ai_das1802, - }, - { - name: "das-1801hc", - ai_speed: 3000, - resolution: 12, - qram_len: 64, - common: 0, - do_n_chan: 8, - ao_ability: 1, - ao_n_chan: 2, - range_ai: &range_ai_das1801, - }, - { - name: "das-1802hc", - ai_speed: 3000, - resolution: 12, - qram_len: 64, - common: 0, - do_n_chan: 8, - ao_ability: 1, - ao_n_chan: 2, - range_ai: &range_ai_das1802, - }, - { - name: "das-1801ao", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 2, - ao_n_chan: 2, - range_ai: &range_ai_das1801, - }, - { - name: "das-1802ao", - ai_speed: 3000, - resolution: 12, - qram_len: 256, - common: 1, - do_n_chan: 4, - ao_ability: 2, - ao_n_chan: 2, - range_ai: &range_ai_das1802, - }, +static const das1800_board das1800_boards[] = { + { + name: "das-1701st", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1801, + }, + { + name: "das-1701st-da", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:1, + ao_n_chan:4, + range_ai:&range_ai_das1801, + }, + { + name: "das-1702st", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1802, + }, + { + name: "das-1702st-da", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:1, + ao_n_chan:4, + range_ai:&range_ai_das1802, + }, + { + name: "das-1702hr", + ai_speed:20000, + resolution:16, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1802, + }, + { + name: "das-1702hr-da", + ai_speed:20000, + resolution:16, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:1, + ao_n_chan:2, + range_ai:&range_ai_das1802, + }, + { + name: "das-1701ao", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:2, + ao_n_chan:2, + range_ai:&range_ai_das1801, + }, + { + name: "das-1702ao", + ai_speed:6250, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:2, + ao_n_chan:2, + range_ai:&range_ai_das1802, + }, + { + name: "das-1801st", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1801, + }, + { + name: "das-1801st-da", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:4, + range_ai:&range_ai_das1801, + }, + { + name: "das-1802st", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1802, + }, + { + name: "das-1802st-da", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:1, + ao_n_chan:4, + range_ai:&range_ai_das1802, + }, + { + name: "das-1802hr", + ai_speed:10000, + resolution:16, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:0, + ao_n_chan:0, + range_ai:&range_ai_das1802, + }, + { + name: "das-1802hr-da", + ai_speed:10000, + resolution:16, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:1, + ao_n_chan:2, + range_ai:&range_ai_das1802, + }, + { + name: "das-1801hc", + ai_speed:3000, + resolution:12, + qram_len:64, + common: 0, + do_n_chan:8, + ao_ability:1, + ao_n_chan:2, + range_ai:&range_ai_das1801, + }, + { + name: "das-1802hc", + ai_speed:3000, + resolution:12, + qram_len:64, + common: 0, + do_n_chan:8, + ao_ability:1, + ao_n_chan:2, + range_ai:&range_ai_das1802, + }, + { + name: "das-1801ao", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:2, + ao_n_chan:2, + range_ai:&range_ai_das1801, + }, + { + name: "das-1802ao", + ai_speed:3000, + resolution:12, + qram_len:256, + common: 1, + do_n_chan:4, + ao_ability:2, + ao_n_chan:2, + range_ai:&range_ai_das1802, + }, }; + /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const das1800_board *)dev->board_ptr) -typedef struct{ - volatile unsigned int count; /* number of data points left to be taken */ +typedef struct { + volatile unsigned int count; /* number of data points left to be taken */ unsigned int divisor1; /* value to load into board's counter 1 for timed conversions */ - unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */ - int do_bits; /* digital output bits */ + unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */ + int do_bits; /* digital output bits */ int irq_dma_bits; /* bits for control register b */ /* dma bits for control register b, stored so that dma can be * turned on and off */ @@ -470,8 +480,8 @@ typedef struct{ uint16_t *dma_current_buf; /* pointer to dma buffer currently being used */ unsigned int dma_transfer_size; /* size of transfer currently used, in bytes */ unsigned long iobase2; /* secondary io address used for analog out on 'ao' boards */ - short ao_update_bits; /* remembers the last write to the 'update' dac */ -}das1800_private; + short ao_update_bits; /* remembers the last write to the 'update' dac */ +} das1800_private; #define devpriv ((das1800_private *)dev->private) @@ -479,8 +489,8 @@ typedef struct{ static const comedi_lrange range_ao_1 = { 1, { - RANGE(-10, 10), - } + RANGE(-10, 10), + } }; // analog out range for 'ao' boards @@ -494,14 +504,14 @@ static const comedi_lrange range_ao_2 = { }; */ -static comedi_driver driver_das1800={ - driver_name: "das1800", - module: THIS_MODULE, - attach: das1800_attach, - detach: das1800_detach, - num_names: sizeof(das1800_boards) / sizeof(das1800_board), - board_name: &das1800_boards[0].name, - offset: sizeof(das1800_board), +static comedi_driver driver_das1800 = { + driver_name:"das1800", + module:THIS_MODULE, + attach:das1800_attach, + detach:das1800_detach, + num_names:sizeof(das1800_boards) / sizeof(das1800_board), + board_name:&das1800_boards[0].name, + offset:sizeof(das1800_board), }; /* @@ -510,72 +520,68 @@ static comedi_driver driver_das1800={ */ COMEDI_INITCLEANUP(driver_das1800); -static int das1800_init_dma( comedi_device *dev, unsigned int dma0, unsigned int dma1 ) +static int das1800_init_dma(comedi_device * dev, unsigned int dma0, + unsigned int dma1) { unsigned long flags; // need an irq to do dma - if( dev->irq && dma0 ) - { + if (dev->irq && dma0) { //encode dma0 and dma1 into 2 digit hexadecimal for switch - switch((dma0 & 0x7) | (dma1 << 4)) - { - case 0x5: // dma0 == 5 - devpriv->dma_bits |= DMA_CH5; - break; - case 0x6: // dma0 == 6 - devpriv->dma_bits |= DMA_CH6; - break; - case 0x7: // dma0 == 7 - devpriv->dma_bits |= DMA_CH7; - break; - case 0x65: // dma0 == 5, dma1 == 6 - devpriv->dma_bits |= DMA_CH5_CH6; - break; - case 0x76: // dma0 == 6, dma1 == 7 - devpriv->dma_bits |= DMA_CH6_CH7; - break; - case 0x57: // dma0 == 7, dma1 == 5 - devpriv->dma_bits |= DMA_CH7_CH5; - break; - default: - printk(" only supports dma channels 5 through 7\n" - " Dual dma only allows the following combinations:\n" - " dma 5,6 / 6,7 / or 7,5\n"); - return -EINVAL; - break; + switch ((dma0 & 0x7) | (dma1 << 4)) { + case 0x5: // dma0 == 5 + devpriv->dma_bits |= DMA_CH5; + break; + case 0x6: // dma0 == 6 + devpriv->dma_bits |= DMA_CH6; + break; + case 0x7: // dma0 == 7 + devpriv->dma_bits |= DMA_CH7; + break; + case 0x65: // dma0 == 5, dma1 == 6 + devpriv->dma_bits |= DMA_CH5_CH6; + break; + case 0x76: // dma0 == 6, dma1 == 7 + devpriv->dma_bits |= DMA_CH6_CH7; + break; + case 0x57: // dma0 == 7, dma1 == 5 + devpriv->dma_bits |= DMA_CH7_CH5; + break; + default: + printk(" only supports dma channels 5 through 7\n" + " Dual dma only allows the following combinations:\n" + " dma 5,6 / 6,7 / or 7,5\n"); + return -EINVAL; + break; } - if( request_dma( dma0, driver_das1800.driver_name ) ) - { - printk( " failed to allocate dma channel %i\n", dma0 ); + if (request_dma(dma0, driver_das1800.driver_name)) { + printk(" failed to allocate dma channel %i\n", dma0); return -EINVAL; } devpriv->dma0 = dma0; devpriv->dma_current = dma0; - if( dma1 ) - { - if( request_dma( dma1, driver_das1800.driver_name ) ) - { - printk( " failed to allocate dma channel %i\n", dma1 ); + if (dma1) { + if (request_dma(dma1, driver_das1800.driver_name)) { + printk(" failed to allocate dma channel %i\n", + dma1); return -EINVAL; } devpriv->dma1 = dma1; } devpriv->ai_buf0 = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA); - if(devpriv->ai_buf0 == NULL) + if (devpriv->ai_buf0 == NULL) return -ENOMEM; devpriv->dma_current_buf = devpriv->ai_buf0; - if( dma1 ) - { - devpriv->ai_buf1 = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA); - if(devpriv->ai_buf1 == NULL) + if (dma1) { + devpriv->ai_buf1 = + kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA); + if (devpriv->ai_buf1 == NULL) return -ENOMEM; } flags = claim_dma_lock(); disable_dma(devpriv->dma0); set_dma_mode(devpriv->dma0, DMA_MODE_READ); - if( dma1 ) - { + if (dma1) { disable_dma(devpriv->dma1); set_dma_mode(devpriv->dma1, DMA_MODE_READ); } @@ -584,7 +590,7 @@ static int das1800_init_dma( comedi_device *dev, unsigned int dma0, unsigned int return 0; } -static int das1800_attach(comedi_device *dev, comedi_devconfig *it) +static int das1800_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase = it->options[0]; @@ -596,39 +602,35 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) int retval; /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(das1800_private)) < 0) + if (alloc_private(dev, sizeof(das1800_private)) < 0) return -ENOMEM; - printk("comedi%d: %s: io 0x%lx", dev->minor, driver_das1800.driver_name, iobase); - if(irq) - { + printk("comedi%d: %s: io 0x%lx", dev->minor, driver_das1800.driver_name, + iobase); + if (irq) { printk(", irq %u", irq); - if(dma0) - { + if (dma0) { printk(", dma %u", dma0); - if(dma1) printk(" and %u", dma1); + if (dma1) + printk(" and %u", dma1); } } printk("\n"); - if(iobase == 0) - { + if (iobase == 0) { printk(" io base address required\n"); return -EINVAL; } /* check if io addresses are available */ - if(!request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name)) - { - printk(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", - iobase, iobase + DAS1800_SIZE - 1); + if (!request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name)) { + printk(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", iobase, iobase + DAS1800_SIZE - 1); return -EIO; } dev->iobase = iobase; board = das1800_probe(dev); - if(board < 0) - { + if (board < 0) { printk(" unable to determine board type\n"); return -ENODEV; } @@ -637,23 +639,20 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; // if it is an 'ao' board with fancy analog out then we need extra io ports - if(thisboard->ao_ability == 2) - { + if (thisboard->ao_ability == 2) { iobase2 = iobase + IOBASE2; - if(!request_region(iobase2, DAS1800_SIZE, driver_das1800.driver_name)) - { - printk(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", - iobase2, iobase2 + DAS1800_SIZE - 1); + if (!request_region(iobase2, DAS1800_SIZE, + driver_das1800.driver_name)) { + printk(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", iobase2, iobase2 + DAS1800_SIZE - 1); return -EIO; } devpriv->iobase2 = iobase2; } /* grab our IRQ */ - if(irq) - { - if(comedi_request_irq( irq, das1800_interrupt, 0, driver_das1800.driver_name, dev )) - { + if (irq) { + if (comedi_request_irq(irq, das1800_interrupt, 0, + driver_das1800.driver_name, dev)) { printk(" unable to allocate irq %u\n", irq); return -EINVAL; } @@ -661,45 +660,45 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) dev->irq = irq; // set bits that tell card which irq to use - switch(irq) - { - case 0: - break; - case 3: - devpriv->irq_dma_bits |= 0x8; - break; - case 5: - devpriv->irq_dma_bits |= 0x10; - break; - case 7: - devpriv->irq_dma_bits |= 0x18; - break; - case 10: - devpriv->irq_dma_bits |= 0x28; - break; - case 11: - devpriv->irq_dma_bits |= 0x30; - break; - case 15: - devpriv->irq_dma_bits |= 0x38; - break; - default: - printk(" irq out of range\n"); - return -EINVAL; - break; + switch (irq) { + case 0: + break; + case 3: + devpriv->irq_dma_bits |= 0x8; + break; + case 5: + devpriv->irq_dma_bits |= 0x10; + break; + case 7: + devpriv->irq_dma_bits |= 0x18; + break; + case 10: + devpriv->irq_dma_bits |= 0x28; + break; + case 11: + devpriv->irq_dma_bits |= 0x30; + break; + case 15: + devpriv->irq_dma_bits |= 0x38; + break; + default: + printk(" irq out of range\n"); + return -EINVAL; + break; } - retval = das1800_init_dma( dev, dma0, dma1 ); - if( retval < 0 ) return retval; + retval = das1800_init_dma(dev, dma0, dma1); + if (retval < 0) + return retval; - if( devpriv->ai_buf0 == NULL ) - { - devpriv->ai_buf0 = kmalloc( FIFO_SIZE * sizeof( uint16_t ), GFP_KERNEL ); - if(devpriv->ai_buf0 == NULL) + if (devpriv->ai_buf0 == NULL) { + devpriv->ai_buf0 = + kmalloc(FIFO_SIZE * sizeof(uint16_t), GFP_KERNEL); + if (devpriv->ai_buf0 == NULL) return -ENOMEM; } - if(alloc_subdevices(dev, 4) < 0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; /* analog input subdevice */ @@ -707,7 +706,7 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) dev->read_subdev = s; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_GROUND | SDF_CMD_READ; - if(thisboard->common) + if (thisboard->common) s->subdev_flags |= SDF_COMMON; s->n_chan = thisboard->qram_len; s->len_chanlist = thisboard->qram_len; @@ -721,17 +720,14 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) /* analog out */ s = dev->subdevices + 1; - if(thisboard->ao_ability == 1) - { + if (thisboard->ao_ability == 1) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE; s->n_chan = thisboard->ao_n_chan; s->maxdata = (1 << thisboard->resolution) - 1; s->range_table = &range_ao_1; s->insn_write = das1800_ao_winsn; - } - else - { + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -759,120 +755,119 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) outb(devpriv->do_bits, dev->iobase + DAS1800_DIGITAL); // initialize analog out channels - if(thisboard->ao_ability == 1) - { + if (thisboard->ao_ability == 1) { // select 'update' dac channel for baseAddress + 0x0 - outb(DAC(thisboard->ao_n_chan - 1), dev->iobase + DAS1800_SELECT); + outb(DAC(thisboard->ao_n_chan - 1), + dev->iobase + DAS1800_SELECT); outw(devpriv->ao_update_bits, dev->iobase + DAS1800_DAC); } return 0; }; -static int das1800_detach(comedi_device *dev) +static int das1800_detach(comedi_device * dev) { /* only free stuff if it has been allocated by _attach */ - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, DAS1800_SIZE); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(dev->private) - { - if(devpriv->iobase2) + if (dev->private) { + if (devpriv->iobase2) release_region(devpriv->iobase2, DAS1800_SIZE); - if(devpriv->dma0) + if (devpriv->dma0) free_dma(devpriv->dma0); - if(devpriv->dma1) + if (devpriv->dma1) free_dma(devpriv->dma1); - if(devpriv->ai_buf0) + if (devpriv->ai_buf0) kfree(devpriv->ai_buf0); - if(devpriv->ai_buf1) + if (devpriv->ai_buf1) kfree(devpriv->ai_buf1); } - printk("comedi%d: %s: remove\n", dev->minor, driver_das1800.driver_name); + printk("comedi%d: %s: remove\n", dev->minor, + driver_das1800.driver_name); return 0; }; /* probes and checks das-1800 series board type */ -static int das1800_probe(comedi_device *dev) +static int das1800_probe(comedi_device * dev) { int id; int board; - id = (inb(dev->iobase + DAS1800_DIGITAL) >> 4) & 0xf; /* get id bits */ - board = ((das1800_board *)dev->board_ptr) - das1800_boards; + id = (inb(dev->iobase + DAS1800_DIGITAL) >> 4) & 0xf; /* get id bits */ + board = ((das1800_board *) dev->board_ptr) - das1800_boards; - switch(id) - { - case 0x3: - if(board == das1801st_da || board == das1802st_da || - board == das1701st_da || board == das1702st_da) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1800st-da series\n"); - return das1801st; - break; - case 0x4: - if(board == das1802hr_da || board == das1702hr_da) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1802hr-da\n"); - return das1802hr; - break; - case 0x5: - if(board == das1801ao || board == das1802ao || - board == das1701ao || board == das1702ao) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1800ao series\n"); - return das1801ao; - break; - case 0x6: - if(board == das1802hr || board == das1702hr) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1802hr\n"); - return das1802hr; - break; - case 0x7: - if(board == das1801st || board == das1802st || - board == das1701st || board == das1702st) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1800st series\n"); - return das1801st; - break; - case 0x8: - if(board == das1801hc || board == das1802hc) - { - printk(" Board model: %s\n", das1800_boards[board].name); - return board; - } - printk(" Board model (probed, not recommended): das-1800hc series\n"); - return das1801hc; - break; - default : - printk(" Board model: probe returned 0x%x (unknown, please report)\n", id); + switch (id) { + case 0x3: + if (board == das1801st_da || board == das1802st_da || + board == das1701st_da || board == das1702st_da) { + printk(" Board model: %s\n", + das1800_boards[board].name); return board; - break; + } + printk(" Board model (probed, not recommended): das-1800st-da series\n"); + return das1801st; + break; + case 0x4: + if (board == das1802hr_da || board == das1702hr_da) { + printk(" Board model: %s\n", + das1800_boards[board].name); + return board; + } + printk(" Board model (probed, not recommended): das-1802hr-da\n"); + return das1802hr; + break; + case 0x5: + if (board == das1801ao || board == das1802ao || + board == das1701ao || board == das1702ao) { + printk(" Board model: %s\n", + das1800_boards[board].name); + return board; + } + printk(" Board model (probed, not recommended): das-1800ao series\n"); + return das1801ao; + break; + case 0x6: + if (board == das1802hr || board == das1702hr) { + printk(" Board model: %s\n", + das1800_boards[board].name); + return board; + } + printk(" Board model (probed, not recommended): das-1802hr\n"); + return das1802hr; + break; + case 0x7: + if (board == das1801st || board == das1802st || + board == das1701st || board == das1702st) { + printk(" Board model: %s\n", + das1800_boards[board].name); + return board; + } + printk(" Board model (probed, not recommended): das-1800st series\n"); + return das1801st; + break; + case 0x8: + if (board == das1801hc || board == das1802hc) { + printk(" Board model: %s\n", + das1800_boards[board].name); + return board; + } + printk(" Board model (probed, not recommended): das-1800hc series\n"); + return das1801hc; + break; + default: + printk(" Board model: probe returned 0x%x (unknown, please report)\n", id); + return board; + break; } return -1; } -static int das1800_ai_poll(comedi_device *dev,comedi_subdevice *s) +static int das1800_ai_poll(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; @@ -889,8 +884,7 @@ static irqreturn_t das1800_interrupt(int irq, void *d PT_REGS_ARG) comedi_device *dev = d; unsigned int status; - if(dev->attached == 0) - { + if (dev->attached == 0) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } @@ -901,12 +895,11 @@ static irqreturn_t das1800_interrupt(int irq, void *d PT_REGS_ARG) status = inb(dev->iobase + DAS1800_STATUS); /* if interrupt was not caused by das-1800 */ - if(!(status & INT)) - { + if (!(status & INT)) { spin_unlock(&dev->spinlock); return IRQ_NONE; } - /* clear the interrupt status bit INT*/ + /* clear the interrupt status bit INT */ outb(CLEAR_INTR_MASK & ~INT, dev->iobase + DAS1800_STATUS); // handle interrupt das1800_ai_handler(dev); @@ -916,7 +909,7 @@ static irqreturn_t das1800_interrupt(int irq, void *d PT_REGS_ARG) } // the guts of the interrupt handler, that is shared with das1800_ai_poll -static void das1800_ai_handler(comedi_device *dev) +static void das1800_ai_handler(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + 0; /* analog input subdevice */ comedi_async *async = s->async; @@ -927,22 +920,18 @@ static void das1800_ai_handler(comedi_device *dev) // select adc for base address + 0 outb(ADC, dev->iobase + DAS1800_SELECT); // dma buffer full - if(devpriv->irq_dma_bits & DMA_ENABLED) - { + if (devpriv->irq_dma_bits & DMA_ENABLED) { // look for data from dma transfer even if dma terminal count hasn't happened yet das1800_handle_dma(dev, s, status); - }else if(status & FHF) - { // if fifo half full + } else if (status & FHF) { // if fifo half full das1800_handle_fifo_half_full(dev, s); - }else if(status & FNE) - { // if fifo not empty + } else if (status & FNE) { // if fifo not empty das1800_handle_fifo_not_empty(dev, s); } async->events |= COMEDI_CB_BLOCK; /* if the card's fifo has overflowed */ - if(status & OVF) - { + if (status & OVF) { // clear OVF interrupt bit outb(CLEAR_INTR_MASK & ~OVF, dev->iobase + DAS1800_STATUS); comedi_error(dev, "DAS1800 FIFO overflow"); @@ -951,23 +940,20 @@ static void das1800_ai_handler(comedi_device *dev) comedi_event(dev, s); return; } - // stop taking data if appropriate /* stop_src TRIG_EXT */ - if(status & CT0TC) - { + if (status & CT0TC) { // clear CT0TC interrupt bit outb(CLEAR_INTR_MASK & ~CT0TC, dev->iobase + DAS1800_STATUS); // make sure we get all remaining data from board before quitting - if(devpriv->irq_dma_bits & DMA_ENABLED) + if (devpriv->irq_dma_bits & DMA_ENABLED) das1800_flush_dma(dev, s); else das1800_handle_fifo_not_empty(dev, s); - das1800_cancel(dev, s); /* disable hardware conversions */ + das1800_cancel(dev, s); /* disable hardware conversions */ async->events |= COMEDI_CB_EOA; - }else if(cmd->stop_src == TRIG_COUNT && devpriv->count == 0) - { // stop_src TRIG_COUNT - das1800_cancel(dev, s); /* disable hardware conversions */ + } else if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0) { // stop_src TRIG_COUNT + das1800_cancel(dev, s); /* disable hardware conversions */ async->events |= COMEDI_CB_EOA; } @@ -976,34 +962,32 @@ static void das1800_ai_handler(comedi_device *dev) return; } -static void das1800_handle_dma(comedi_device *dev, comedi_subdevice *s, unsigned int status) +static void das1800_handle_dma(comedi_device * dev, comedi_subdevice * s, + unsigned int status) { unsigned long flags; const int dual_dma = devpriv->irq_dma_bits & DMA_DUAL; flags = claim_dma_lock(); - das1800_flush_dma_channel(dev, s, devpriv->dma_current, devpriv->dma_current_buf); + das1800_flush_dma_channel(dev, s, devpriv->dma_current, + devpriv->dma_current_buf); // re-enable dma channel - set_dma_addr(devpriv->dma_current, virt_to_bus(devpriv->dma_current_buf)); + set_dma_addr(devpriv->dma_current, + virt_to_bus(devpriv->dma_current_buf)); set_dma_count(devpriv->dma_current, devpriv->dma_transfer_size); enable_dma(devpriv->dma_current); release_dma_lock(flags); - if(status & DMATC) - { + if (status & DMATC) { // clear DMATC interrupt bit outb(CLEAR_INTR_MASK & ~DMATC, dev->iobase + DAS1800_STATUS); // switch dma channels for next time, if appropriate - if(dual_dma) - { + if (dual_dma) { // read data from the other channel next time - if(devpriv->dma_current == devpriv->dma0) - { + if (devpriv->dma_current == devpriv->dma0) { devpriv->dma_current = devpriv->dma1; devpriv->dma_current_buf = devpriv->ai_buf1; - } - else - { + } else { devpriv->dma_current = devpriv->dma0; devpriv->dma_current_buf = devpriv->ai_buf0; } @@ -1013,33 +997,34 @@ static void das1800_handle_dma(comedi_device *dev, comedi_subdevice *s, unsigned return; } -static inline uint16_t munge_bipolar_sample( const comedi_device *dev, uint16_t sample ) +static inline uint16_t munge_bipolar_sample(const comedi_device * dev, + uint16_t sample) { - sample += 1 << ( thisboard->resolution - 1 ); + sample += 1 << (thisboard->resolution - 1); return sample; } -static void munge_data( comedi_device *dev, uint16_t *array, unsigned int num_elements ) +static void munge_data(comedi_device * dev, uint16_t * array, + unsigned int num_elements) { unsigned int i; int unipolar; /* see if card is using a unipolar or bipolar range so we can munge data correctly */ - unipolar = inb( dev->iobase + DAS1800_CONTROL_C ) & UB; + unipolar = inb(dev->iobase + DAS1800_CONTROL_C) & UB; /* convert to unsigned type if we are in a bipolar mode */ - if( !unipolar ) - { - for( i = 0; i < num_elements; i++ ) - { - array[i] = munge_bipolar_sample( dev, array[i] ); + if (!unipolar) { + for (i = 0; i < num_elements; i++) { + array[i] = munge_bipolar_sample(dev, array[i]); } } } /* Utility function used by das1800_flush_dma() and das1800_handle_dma(). * Assumes dma lock is held */ -static void das1800_flush_dma_channel(comedi_device *dev, comedi_subdevice *s, unsigned int channel, uint16_t *buffer) +static void das1800_flush_dma_channel(comedi_device * dev, comedi_subdevice * s, + unsigned int channel, uint16_t * buffer) { unsigned int num_bytes, num_samples; comedi_cmd *cmd = &s->async->cmd; @@ -1051,16 +1036,16 @@ static void das1800_flush_dma_channel(comedi_device *dev, comedi_subdevice *s, u clear_dma_ff(channel); // figure out how many points to read - num_bytes = devpriv->dma_transfer_size - get_dma_residue( channel ); - num_samples = num_bytes / sizeof( sampl_t ); + num_bytes = devpriv->dma_transfer_size - get_dma_residue(channel); + num_samples = num_bytes / sizeof(sampl_t); /* if we only need some of the points */ - if( cmd->stop_src == TRIG_COUNT && devpriv->count < num_samples ) + if (cmd->stop_src == TRIG_COUNT && devpriv->count < num_samples) num_samples = devpriv->count; - munge_data( dev, buffer, num_samples ); - cfc_write_array_to_buffer( s, buffer, num_bytes ); - if(s->async->cmd.stop_src == TRIG_COUNT) + munge_data(dev, buffer, num_samples); + cfc_write_array_to_buffer(s, buffer, num_bytes); + if (s->async->cmd.stop_src == TRIG_COUNT) devpriv->count -= num_samples; return; @@ -1068,28 +1053,26 @@ static void das1800_flush_dma_channel(comedi_device *dev, comedi_subdevice *s, u /* flushes remaining data from board when external trigger has stopped aquisition * and we are using dma transfers */ -static void das1800_flush_dma(comedi_device *dev, comedi_subdevice *s) +static void das1800_flush_dma(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; const int dual_dma = devpriv->irq_dma_bits & DMA_DUAL; flags = claim_dma_lock(); - das1800_flush_dma_channel(dev, s, devpriv->dma_current, devpriv->dma_current_buf); + das1800_flush_dma_channel(dev, s, devpriv->dma_current, + devpriv->dma_current_buf); - if(dual_dma) - { + if (dual_dma) { // switch to other channel and flush it - if(devpriv->dma_current == devpriv->dma0) - { + if (devpriv->dma_current == devpriv->dma0) { devpriv->dma_current = devpriv->dma1; devpriv->dma_current_buf = devpriv->ai_buf1; - } - else - { + } else { devpriv->dma_current = devpriv->dma0; devpriv->dma_current_buf = devpriv->ai_buf0; } - das1800_flush_dma_channel(dev, s, devpriv->dma_current, devpriv->dma_current_buf); + das1800_flush_dma_channel(dev, s, devpriv->dma_current, + devpriv->dma_current_buf); } release_dma_lock(flags); @@ -1100,24 +1083,27 @@ static void das1800_flush_dma(comedi_device *dev, comedi_subdevice *s) return; } -static void das1800_handle_fifo_half_full(comedi_device *dev, comedi_subdevice *s) +static void das1800_handle_fifo_half_full(comedi_device * dev, + comedi_subdevice * s) { int numPoints = 0; /* number of points to read */ comedi_cmd *cmd = &s->async->cmd; numPoints = FIFO_SIZE / 2; /* if we only need some of the points */ - if(cmd->stop_src == TRIG_COUNT && devpriv->count < numPoints) + if (cmd->stop_src == TRIG_COUNT && devpriv->count < numPoints) numPoints = devpriv->count; insw(dev->iobase + DAS1800_FIFO, devpriv->ai_buf0, numPoints); - munge_data( dev, devpriv->ai_buf0, numPoints ); - cfc_write_array_to_buffer( s, devpriv->ai_buf0, numPoints * sizeof( devpriv->ai_buf0[0] ) ); - if( cmd->stop_src == TRIG_COUNT ) + munge_data(dev, devpriv->ai_buf0, numPoints); + cfc_write_array_to_buffer(s, devpriv->ai_buf0, + numPoints * sizeof(devpriv->ai_buf0[0])); + if (cmd->stop_src == TRIG_COUNT) devpriv->count -= numPoints; return; } -static void das1800_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice *s) +static void das1800_handle_fifo_not_empty(comedi_device * dev, + comedi_subdevice * s) { sampl_t dpnt; int unipolar; @@ -1125,33 +1111,36 @@ static void das1800_handle_fifo_not_empty(comedi_device *dev, comedi_subdevice * unipolar = inb(dev->iobase + DAS1800_CONTROL_C) & UB; - while( inb( dev->iobase + DAS1800_STATUS ) & FNE ) - { - if(cmd->stop_src == TRIG_COUNT && devpriv->count == 0) + while (inb(dev->iobase + DAS1800_STATUS) & FNE) { + if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0) break; - dpnt = inw( dev->iobase + DAS1800_FIFO ); + dpnt = inw(dev->iobase + DAS1800_FIFO); /* convert to unsigned type if we are in a bipolar mode */ - if(!unipolar); - dpnt = munge_bipolar_sample( dev, dpnt ); - cfc_write_to_buffer( s, dpnt ); - if(cmd->stop_src == TRIG_COUNT) devpriv->count--; + if (!unipolar) ; + dpnt = munge_bipolar_sample(dev, dpnt); + cfc_write_to_buffer(s, dpnt); + if (cmd->stop_src == TRIG_COUNT) + devpriv->count--; } return; } -static int das1800_cancel(comedi_device *dev, comedi_subdevice *s) +static int das1800_cancel(comedi_device * dev, comedi_subdevice * s) { outb(0x0, dev->iobase + DAS1800_STATUS); /* disable conversions */ outb(0x0, dev->iobase + DAS1800_CONTROL_B); /* disable interrupts and dma */ outb(0x0, dev->iobase + DAS1800_CONTROL_A); /* disable and clear fifo and stop triggering */ - if(devpriv->dma0) disable_dma(devpriv->dma0); - if(devpriv->dma1) disable_dma(devpriv->dma1); + if (devpriv->dma0) + disable_dma(devpriv->dma0); + if (devpriv->dma1) + disable_dma(devpriv->dma1); return 0; } /* test analog input cmd */ -static int das1800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int das1800_ai_do_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -1163,147 +1152,159 @@ static int das1800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_c tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ // uniqueness check - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->scan_begin_src != TRIG_FOLLOW && + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->scan_begin_src != TRIG_TIMER && - cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE && - cmd->stop_src != TRIG_EXT) err++; + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT) + err++; //compatibility check - if(cmd->scan_begin_src != TRIG_FOLLOW && - cmd->convert_src != TRIG_TIMER) err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->convert_src != TRIG_TIMER) + err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg != 0) - { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - switch(cmd->stop_src) - { - case TRIG_COUNT: - if(!cmd->stop_arg) - { - cmd->stop_arg = 1; - err++; - } - break; - case TRIG_NONE: - if(cmd->stop_arg != 0) - { - cmd->stop_arg = 0; - err++; - } - break; - default: - break; + switch (cmd->stop_src) { + case TRIG_COUNT: + if (!cmd->stop_arg) { + cmd->stop_arg = 1; + err++; + } + break; + case TRIG_NONE: + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; + err++; + } + break; + default: + break; } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { // if we are not in burst mode - if(cmd->scan_begin_src == TRIG_FOLLOW) - { + if (cmd->scan_begin_src == TRIG_FOLLOW) { tmp_arg = cmd->convert_arg; /* calculate counter values that give desired timing */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp_arg != cmd->convert_arg) err++; + i8253_cascade_ns_to_timer_2div(TIMER_BASE, + &(devpriv->divisor1), &(devpriv->divisor2), + &(cmd->convert_arg), + cmd->flags & TRIG_ROUND_MASK); + if (tmp_arg != cmd->convert_arg) + err++; } // if we are in burst mode - else - { + else { // check that convert_arg is compatible tmp_arg = cmd->convert_arg; - cmd->convert_arg = burst_convert_arg(cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); - if(tmp_arg != cmd->convert_arg) err++; + cmd->convert_arg = + burst_convert_arg(cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp_arg != cmd->convert_arg) + err++; - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { // if scans are timed faster than conversion rate allows - if(cmd->convert_arg * cmd->chanlist_len > cmd->scan_begin_arg) - { - cmd->scan_begin_arg = cmd->convert_arg * cmd->chanlist_len; + if (cmd->convert_arg * cmd->chanlist_len > + cmd->scan_begin_arg) { + cmd->scan_begin_arg = + cmd->convert_arg * + cmd->chanlist_len; err++; } tmp_arg = cmd->scan_begin_arg; /* calculate counter values that give desired timing */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->scan_begin_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp_arg != cmd->scan_begin_arg) err++; + i8253_cascade_ns_to_timer_2div(TIMER_BASE, + &(devpriv->divisor1), + &(devpriv->divisor2), + &(cmd->scan_begin_arg), + cmd->flags & TRIG_ROUND_MASK); + if (tmp_arg != cmd->scan_begin_arg) + err++; } } } - if(err) return 4; + if (err) + return 4; // make sure user is not trying to mix unipolar and bipolar ranges - if(cmd->chanlist) - { + if (cmd->chanlist) { unipolar = CR_RANGE(cmd->chanlist[0]) & UNIPOLAR; - for(i = 1; i < cmd->chanlist_len; i++) - { - if(unipolar != (CR_RANGE(cmd->chanlist[i]) & UNIPOLAR)) - { - comedi_error(dev, "unipolar and bipolar ranges cannot be mixed in the chanlist"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (unipolar != (CR_RANGE(cmd->chanlist[i]) & UNIPOLAR)) { + comedi_error(dev, + "unipolar and bipolar ranges cannot be mixed in the chanlist"); err++; break; } } } - if(err) return 5; + if (err) + return 5; return 0; } @@ -1318,20 +1319,18 @@ static int control_a_bits(comedi_cmd cmd) int control_a; control_a = FFEN; //enable fifo - if(cmd.stop_src == TRIG_EXT) - { + if (cmd.stop_src == TRIG_EXT) { control_a |= ATEN; } - switch(cmd.start_src) - { - case TRIG_EXT: - control_a |= TGEN | CGSL; - break; - case TRIG_NOW: - control_a |= CGEN; - break; - default: - break; + switch (cmd.start_src) { + case TRIG_EXT: + control_a |= TGEN | CGSL; + break; + case TRIG_NOW: + control_a |= CGEN; + break; + default: + break; } return control_a; @@ -1348,79 +1347,75 @@ static int control_c_bits(comedi_cmd cmd) */ aref = CR_AREF(cmd.chanlist[0]); control_c = UQEN; //enable upper qram addresses - if(aref != AREF_DIFF) + if (aref != AREF_DIFF) control_c |= SD; - if(aref == AREF_COMMON) + if (aref == AREF_COMMON) control_c |= CMEN; /* if a unipolar range was selected */ - if(CR_RANGE(cmd.chanlist[0]) & UNIPOLAR) + if (CR_RANGE(cmd.chanlist[0]) & UNIPOLAR) control_c |= UB; - switch(cmd.scan_begin_src) - { - case TRIG_FOLLOW: // not in burst mode - switch(cmd.convert_src) - { - case TRIG_TIMER: - /* trig on cascaded counters */ - control_c |= IPCLK; - break; - case TRIG_EXT: - /* trig on falling edge of external trigger */ - control_c |= XPCLK; - break; - default: - break; - } - break; + switch (cmd.scan_begin_src) { + case TRIG_FOLLOW: // not in burst mode + switch (cmd.convert_src) { case TRIG_TIMER: - // burst mode with internal pacer clock - control_c |= BMDE | IPCLK; + /* trig on cascaded counters */ + control_c |= IPCLK; break; case TRIG_EXT: - // burst mode with external trigger - control_c |= BMDE | XPCLK; + /* trig on falling edge of external trigger */ + control_c |= XPCLK; break; default: break; + } + break; + case TRIG_TIMER: + // burst mode with internal pacer clock + control_c |= BMDE | IPCLK; + break; + case TRIG_EXT: + // burst mode with external trigger + control_c |= BMDE | XPCLK; + break; + default: + break; } return control_c; } // sets up counters -static int setup_counters(comedi_device *dev, comedi_cmd cmd) +static int setup_counters(comedi_device * dev, comedi_cmd cmd) { // setup cascaded counters for conversion/scan frequency - switch(cmd.scan_begin_src) - { - case TRIG_FOLLOW: // not in burst mode - if(cmd.convert_src == TRIG_TIMER) - { - /* set conversion frequency */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), - &(cmd.convert_arg), cmd.flags & TRIG_ROUND_MASK); - if(das1800_set_frequency(dev) < 0) - { - return -1; - } - } - break; - case TRIG_TIMER: // in burst mode - /* set scan frequency */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), - &(cmd.scan_begin_arg), cmd.flags & TRIG_ROUND_MASK); - if(das1800_set_frequency(dev) < 0) - { + switch (cmd.scan_begin_src) { + case TRIG_FOLLOW: // not in burst mode + if (cmd.convert_src == TRIG_TIMER) { + /* set conversion frequency */ + i8253_cascade_ns_to_timer_2div(TIMER_BASE, + &(devpriv->divisor1), &(devpriv->divisor2), + &(cmd.convert_arg), + cmd.flags & TRIG_ROUND_MASK); + if (das1800_set_frequency(dev) < 0) { return -1; } - break; - default: - break; + } + break; + case TRIG_TIMER: // in burst mode + /* set scan frequency */ + i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), + &(devpriv->divisor2), &(cmd.scan_begin_arg), + cmd.flags & TRIG_ROUND_MASK); + if (das1800_set_frequency(dev) < 0) { + return -1; + } + break; + default: + break; } // setup counter 0 for 'about triggering' - if(cmd.stop_src == TRIG_EXT) - { + if (cmd.stop_src == TRIG_EXT) { // load counter 0 in mode 0 i8254_load(dev->iobase + DAS1800_COUNTER, 0, 0, 1, 0); } @@ -1429,12 +1424,12 @@ static int setup_counters(comedi_device *dev, comedi_cmd cmd) } // sets up dma -static void setup_dma(comedi_device *dev, comedi_cmd cmd) +static void setup_dma(comedi_device * dev, comedi_cmd cmd) { unsigned long lock_flags; const int dual_dma = devpriv->irq_dma_bits & DMA_DUAL; - if((devpriv->irq_dma_bits & DMA_ENABLED) == 0) + if ((devpriv->irq_dma_bits & DMA_ENABLED) == 0) return; /* determine a reasonable dma transfer size */ @@ -1451,8 +1446,7 @@ static void setup_dma(comedi_device *dev, comedi_cmd cmd) devpriv->dma_current_buf = devpriv->ai_buf0; enable_dma(devpriv->dma0); // set up dual dma if appropriate - if(dual_dma) - { + if (dual_dma) { disable_dma(devpriv->dma1); /* clear flip-flop to make sure 2-byte registers for * count and address get set correctly */ @@ -1468,22 +1462,24 @@ static void setup_dma(comedi_device *dev, comedi_cmd cmd) } // programs channel/gain list into card -static void program_chanlist(comedi_device *dev, comedi_cmd cmd) +static void program_chanlist(comedi_device * dev, comedi_cmd cmd) { int i, n, chan_range; unsigned long irq_flags; - const int range_mask = 0x3; //masks unipolar/bipolar bit off range + const int range_mask = 0x3; //masks unipolar/bipolar bit off range const int range_bitshift = 8; n = cmd.chanlist_len; // spinlock protects indirect addressing comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); - outb(QRAM, dev->iobase + DAS1800_SELECT); /* select QRAM for baseAddress + 0x0 */ + outb(QRAM, dev->iobase + DAS1800_SELECT); /* select QRAM for baseAddress + 0x0 */ outb(n - 1, dev->iobase + DAS1800_QRAM_ADDRESS); /*set QRAM address start */ /* make channel / gain list */ - for(i = 0; i < n; i++) - { - chan_range = CR_CHAN(cmd.chanlist[i]) | ((CR_RANGE(cmd.chanlist[i]) & range_mask) << range_bitshift); + for (i = 0; i < n; i++) { + chan_range = + CR_CHAN(cmd.chanlist[i]) | ((CR_RANGE(cmd. + chanlist[i]) & range_mask) << + range_bitshift); outw(chan_range, dev->iobase + DAS1800_QRAM); } outb(n - 1, dev->iobase + DAS1800_QRAM_ADDRESS); /*finish write to QRAM */ @@ -1493,41 +1489,36 @@ static void program_chanlist(comedi_device *dev, comedi_cmd cmd) } // analog input do_cmd -static int das1800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) +static int das1800_ai_do_cmd(comedi_device * dev, comedi_subdevice * s) { int ret; int control_a, control_c; comedi_async *async = s->async; comedi_cmd cmd = async->cmd; - if(!dev->irq) - { - comedi_error(dev, "no irq assigned for das-1800, cannot do hardware conversions"); + if (!dev->irq) { + comedi_error(dev, + "no irq assigned for das-1800, cannot do hardware conversions"); return -1; } /* disable dma on TRIG_WAKE_EOS, or TRIG_RT * (because dma in handler is unsafe at hard real-time priority) */ - if(cmd.flags & (TRIG_WAKE_EOS | TRIG_RT)) - { + if (cmd.flags & (TRIG_WAKE_EOS | TRIG_RT)) { devpriv->irq_dma_bits &= ~DMA_ENABLED; - }else - { + } else { devpriv->irq_dma_bits |= devpriv->dma_bits; } // interrupt on end of conversion for TRIG_WAKE_EOS - if(cmd.flags & TRIG_WAKE_EOS) - { + if (cmd.flags & TRIG_WAKE_EOS) { // interrupt fifo not empty devpriv->irq_dma_bits &= ~FIMD; - }else - { + } else { // interrupt fifo half full devpriv->irq_dma_bits |= FIMD; } // determine how many conversions we need - if(cmd.stop_src == TRIG_COUNT) - { + if (cmd.stop_src == TRIG_COUNT) { devpriv->count = cmd.stop_arg * cmd.chanlist_len; } @@ -1540,21 +1531,20 @@ static int das1800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) /* setup card and start */ program_chanlist(dev, cmd); ret = setup_counters(dev, cmd); - if(ret < 0) - { + if (ret < 0) { comedi_error(dev, "Error setting up counters"); return ret; } setup_dma(dev, cmd); outb(control_c, dev->iobase + DAS1800_CONTROL_C); // set conversion rate and length for burst mode - if(control_c & BMDE) - { + if (control_c & BMDE) { // program conversion period with number of microseconds minus 1 - outb(cmd.convert_arg / 1000 - 1, dev->iobase + DAS1800_BURST_RATE); + outb(cmd.convert_arg / 1000 - 1, + dev->iobase + DAS1800_BURST_RATE); outb(cmd.chanlist_len - 1, dev->iobase + DAS1800_BURST_LENGTH); } - outb(devpriv->irq_dma_bits, dev->iobase + DAS1800_CONTROL_B); // enable irq/dma + outb(devpriv->irq_dma_bits, dev->iobase + DAS1800_CONTROL_B); // enable irq/dma outb(control_a, dev->iobase + DAS1800_CONTROL_A); /* enable fifo and triggering */ outb(CVEN, dev->iobase + DAS1800_STATUS); /* enable conversions */ @@ -1562,9 +1552,10 @@ static int das1800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) } /* read analog input */ -static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das1800_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i, n; + int i, n; int chan, range, aref, chan_range; int timeout = 1000; short dpnt; @@ -1574,12 +1565,12 @@ static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn /* set up analog reference and unipolar / bipolar mode */ aref = CR_AREF(insn->chanspec); conv_flags |= UQEN; - if(aref != AREF_DIFF) + if (aref != AREF_DIFF) conv_flags |= SD; - if(aref == AREF_COMMON) + if (aref == AREF_COMMON) conv_flags |= CMEN; /* if a unipolar range was selected */ - if(CR_RANGE(insn->chanspec) & UNIPOLAR) + if (CR_RANGE(insn->chanspec) & UNIPOLAR) conv_flags |= UB; outb(conv_flags, dev->iobase + DAS1800_CONTROL_C); /* software conversion enabled */ @@ -1587,7 +1578,6 @@ static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn outb(0x0, dev->iobase + DAS1800_CONTROL_A); /* reset fifo */ outb(FFEN, dev->iobase + DAS1800_CONTROL_A); - chan = CR_CHAN(insn->chanspec); /* mask of unipolar/bipolar bit from range */ range = CR_RANGE(insn->chanspec) & 0x3; @@ -1599,23 +1589,20 @@ static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn outb(0x0, dev->iobase + DAS1800_QRAM_ADDRESS); /*finish write to QRAM */ outb(ADC, dev->iobase + DAS1800_SELECT); /* select ADC for baseAddress + 0x0 */ - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* trigger conversion */ outb(0, dev->iobase + DAS1800_FIFO); - for(i = 0; i < timeout; i++) - { - if(inb(dev->iobase + DAS1800_STATUS) & FNE) + for (i = 0; i < timeout; i++) { + if (inb(dev->iobase + DAS1800_STATUS) & FNE) break; } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } dpnt = inw(dev->iobase + DAS1800_FIFO); /* shift data to offset binary for bipolar ranges */ - if((conv_flags & UB) == 0) + if ((conv_flags & UB) == 0) dpnt += 1 << (thisboard->resolution - 1); data[n] = dpnt; } @@ -1625,10 +1612,11 @@ static int das1800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn } /* writes to an analog output channel */ -static int das1800_ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das1800_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); -// int range = CR_RANGE(insn->chanspec); +// int range = CR_RANGE(insn->chanspec); int update_chan = thisboard->ao_n_chan - 1; short output; unsigned long irq_flags; @@ -1636,16 +1624,15 @@ static int das1800_ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn // card expects two's complement data output = data[0] - (1 << (thisboard->resolution - 1)); // if the write is to the 'update' channel, we need to remember its value - if(chan == update_chan) + if (chan == update_chan) devpriv->ao_update_bits = output; // write to channel comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); - outb(DAC(chan), dev->iobase + DAS1800_SELECT); /* select dac channel for baseAddress + 0x0 */ + outb(DAC(chan), dev->iobase + DAS1800_SELECT); /* select dac channel for baseAddress + 0x0 */ outw(output, dev->iobase + DAS1800_DAC); // now we need to write to 'update' channel to update all dac channels - if(chan != update_chan) - { - outb(DAC(update_chan), dev->iobase + DAS1800_SELECT); /* select 'update' channel for baseAddress + 0x0 */ + if (chan != update_chan) { + outb(DAC(update_chan), dev->iobase + DAS1800_SELECT); /* select 'update' channel for baseAddress + 0x0 */ outw(devpriv->ao_update_bits, dev->iobase + DAS1800_DAC); } comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); @@ -1654,7 +1641,8 @@ static int das1800_ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn } /* reads from digital input channels */ -static int das1800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das1800_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[1] = inb(dev->iobase + DAS1800_DIGITAL) & 0xf; @@ -1664,7 +1652,8 @@ static int das1800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn } /* writes to digital output channels */ -static int das1800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das1800_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t wbits; @@ -1683,15 +1672,19 @@ static int das1800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn } /* loads counters with divisor1, divisor2 from private structure */ -static int das1800_set_frequency(comedi_device *dev) +static int das1800_set_frequency(comedi_device * dev) { int err = 0; // counter 1, mode 2 - if(i8254_load(dev->iobase + DAS1800_COUNTER, 0, 1, devpriv->divisor1, 2)) err++; + if (i8254_load(dev->iobase + DAS1800_COUNTER, 0, 1, devpriv->divisor1, + 2)) + err++; // counter 2, mode 2 - if(i8254_load(dev->iobase + DAS1800_COUNTER, 0, 2, devpriv->divisor2, 2)) err++; - if(err) + if (i8254_load(dev->iobase + DAS1800_COUNTER, 0, 2, devpriv->divisor2, + 2)) + err++; + if (err) return -1; return 0; @@ -1705,22 +1698,21 @@ static unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode) unsigned int micro_sec; // in burst mode, the maximum conversion time is 64 microseconds - if(convert_arg > 64000) + if (convert_arg > 64000) convert_arg = 64000; // the conversion time must be an integral number of microseconds - switch(round_mode) - { - case TRIG_ROUND_NEAREST: - default: - micro_sec = (convert_arg + 500) / 1000; - break; - case TRIG_ROUND_DOWN: - micro_sec = convert_arg / 1000; - break; - case TRIG_ROUND_UP: - micro_sec = (convert_arg - 1) / 1000 + 1; - break; + switch (round_mode) { + case TRIG_ROUND_NEAREST: + default: + micro_sec = (convert_arg + 500) / 1000; + break; + case TRIG_ROUND_DOWN: + micro_sec = convert_arg / 1000; + break; + case TRIG_ROUND_UP: + micro_sec = (convert_arg - 1) / 1000 + 1; + break; } // return number of nanoseconds @@ -1728,7 +1720,7 @@ static unsigned int burst_convert_arg(unsigned int convert_arg, int round_mode) } // utility function that suggests a dma transfer size based on the conversion period 'ns' -static unsigned int suggest_transfer_size(comedi_cmd *cmd) +static unsigned int suggest_transfer_size(comedi_cmd * cmd) { unsigned int size = DMA_BUF_SIZE; static const int sample_size = 2; // size in bytes of one sample from board @@ -1736,30 +1728,30 @@ static unsigned int suggest_transfer_size(comedi_cmd *cmd) unsigned int max_size; // maximum size we will allow for a transfer // make dma buffer fill in 0.3 seconds for timed modes - switch(cmd->scan_begin_src) - { - case TRIG_FOLLOW: // not in burst mode - if(cmd->convert_src == TRIG_TIMER) - size = (fill_time / cmd->convert_arg) * sample_size; - break; - case TRIG_TIMER: - size = (fill_time / (cmd->scan_begin_arg * cmd->chanlist_len)) * sample_size; - break; - default: - size = DMA_BUF_SIZE; - break; + switch (cmd->scan_begin_src) { + case TRIG_FOLLOW: // not in burst mode + if (cmd->convert_src == TRIG_TIMER) + size = (fill_time / cmd->convert_arg) * sample_size; + break; + case TRIG_TIMER: + size = (fill_time / (cmd->scan_begin_arg * cmd->chanlist_len)) * + sample_size; + break; + default: + size = DMA_BUF_SIZE; + break; } // set a minimum and maximum size allowed max_size = DMA_BUF_SIZE; // if we are taking limited number of conversions, limit transfer size to that - if(cmd->stop_src == TRIG_COUNT && + if (cmd->stop_src == TRIG_COUNT && cmd->stop_arg * cmd->chanlist_len * sample_size < max_size) max_size = cmd->stop_arg * cmd->chanlist_len * sample_size; - if(size > max_size) + if (size > max_size) size = max_size; - if(size < sample_size) + if (size < sample_size) size = sample_size; return size; diff --git a/comedi/drivers/das6402.c b/comedi/drivers/das6402.c index c9ffb5cd..03de652a 100644 --- a/comedi/drivers/das6402.c +++ b/comedi/drivers/das6402.c @@ -5,7 +5,6 @@ - ignoreirq creates a race condition. It needs to be fixed. - */ /* @@ -50,7 +49,6 @@ This driver has suffered bitrot. #define STOP 0 #define START 1 - #define SCANL 0x3f00 #define BYTE unsigned char #define WORD unsigned short @@ -60,26 +58,26 @@ This driver has suffered bitrot. #define CLRXTR 0x02 #define CLRXIN 0x04 #define EXTEND 0x10 -#define ARMED 0x20 /* enable conting of post sample conv */ +#define ARMED 0x20 /* enable conting of post sample conv */ #define POSTMODE 0x40 -#define MHZ 0x80 /* 10 MHz clock */ +#define MHZ 0x80 /* 10 MHz clock */ /*---------------------*/ /*----- register 9 ----*/ -#define IRQ (0x04 << 4) /* these two are */ -#define IRQV 10 /* dependent on each other */ +#define IRQ (0x04 << 4) /* these two are */ +#define IRQV 10 /* dependent on each other */ -#define CONVSRC 0x03 /* trig src is Intarnal pacer */ -#define BURSTEN 0x04 /* enable burst */ -#define XINTE 0x08 /* use external int. trig */ -#define INTE 0x80 /* enable analog interrupts */ +#define CONVSRC 0x03 /* trig src is Intarnal pacer */ +#define BURSTEN 0x04 /* enable burst */ +#define XINTE 0x08 /* use external int. trig */ +#define INTE 0x80 /* enable analog interrupts */ /*---------------------*/ /*----- register 10 ---*/ -#define TGEN 0x01 /* Use pin DI1 for externl trigging? */ -#define TGSEL 0x02 /* Use edge triggering */ -#define TGPOL 0x04 /* active edge is falling */ -#define PRETRIG 0x08 /* pretrig */ +#define TGEN 0x01 /* Use pin DI1 for externl trigging? */ +#define TGSEL 0x02 /* Use edge triggering */ +#define TGPOL 0x04 /* active edge is falling */ +#define PRETRIG 0x08 /* pretrig */ /*---------------------*/ /*----- register 11 ---*/ @@ -100,254 +98,257 @@ This driver has suffered bitrot. #define C2 0x80 #define RWLH 0x30 -static int das6402_attach(comedi_device *dev,comedi_devconfig *it); -static int das6402_detach(comedi_device *dev); -static comedi_driver driver_das6402={ - driver_name: "das6402", - module: THIS_MODULE, - attach: das6402_attach, - detach: das6402_detach, +static int das6402_attach(comedi_device * dev, comedi_devconfig * it); +static int das6402_detach(comedi_device * dev); +static comedi_driver driver_das6402 = { + driver_name:"das6402", + module:THIS_MODULE, + attach:das6402_attach, + detach:das6402_detach, }; + COMEDI_INITCLEANUP(driver_das6402); -typedef struct{ +typedef struct { int ai_bytes_to_read; int das6402_ignoreirq; -}das6402_private; +} das6402_private; #define devpriv ((das6402_private *)dev->private) +static void das6402_ai_fifo_dregs(comedi_device * dev, comedi_subdevice * s); -static void das6402_ai_fifo_dregs(comedi_device *dev,comedi_subdevice *s); - -static void das6402_setcounter(comedi_device *dev) +static void das6402_setcounter(comedi_device * dev) { BYTE p; unsigned short ctrlwrd; /* set up counter0 first, mode 0 */ - p=M0|C0|RWLH; - outb_p(p,dev->iobase+15); - ctrlwrd=2000; - p=(BYTE) (0xff & ctrlwrd); - outb_p(p,dev->iobase+12); - p=(BYTE) (0xff & (ctrlwrd >> 8)); - outb_p(p,dev->iobase+12); + p = M0 | C0 | RWLH; + outb_p(p, dev->iobase + 15); + ctrlwrd = 2000; + p = (BYTE) (0xff & ctrlwrd); + outb_p(p, dev->iobase + 12); + p = (BYTE) (0xff & (ctrlwrd >> 8)); + outb_p(p, dev->iobase + 12); /* set up counter1, mode 2 */ - p=M2|C1|RWLH; - outb_p(p,dev->iobase+15); - ctrlwrd=10; - p=(BYTE) (0xff & ctrlwrd); - outb_p(p,dev->iobase+13); - p=(BYTE) (0xff & (ctrlwrd >> 8)); - outb_p(p,dev->iobase+13); + p = M2 | C1 | RWLH; + outb_p(p, dev->iobase + 15); + ctrlwrd = 10; + p = (BYTE) (0xff & ctrlwrd); + outb_p(p, dev->iobase + 13); + p = (BYTE) (0xff & (ctrlwrd >> 8)); + outb_p(p, dev->iobase + 13); /* set up counter1, mode 2 */ - p=M2|C2|RWLH; - outb_p(p,dev->iobase+15); - ctrlwrd=1000; - p=(BYTE) (0xff & ctrlwrd); - outb_p(p,dev->iobase+14); - p=(BYTE) (0xff & (ctrlwrd >> 8)); - outb_p(p,dev->iobase+14); + p = M2 | C2 | RWLH; + outb_p(p, dev->iobase + 15); + ctrlwrd = 1000; + p = (BYTE) (0xff & ctrlwrd); + outb_p(p, dev->iobase + 14); + p = (BYTE) (0xff & (ctrlwrd >> 8)); + outb_p(p, dev->iobase + 14); } -static irqreturn_t intr_handler(int irq,void *d PT_REGS_ARG) +static irqreturn_t intr_handler(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; - comedi_subdevice *s=dev->subdevices; + comedi_device *dev = d; + comedi_subdevice *s = dev->subdevices; - if (!dev->attached || devpriv->das6402_ignoreirq){ + if (!dev->attached || devpriv->das6402_ignoreirq) { printk("das6402: BUG: spurious interrupt\n"); return IRQ_HANDLED; } - #ifdef DEBUG - printk("das6402: interrupt! das6402_irqcount=%i\n",devpriv->das6402_irqcount); - printk("das6402: iobase+2=%i\n",inw_p(dev->iobase+2)); + printk("das6402: interrupt! das6402_irqcount=%i\n", + devpriv->das6402_irqcount); + printk("das6402: iobase+2=%i\n", inw_p(dev->iobase + 2)); #endif - das6402_ai_fifo_dregs(dev,s); + das6402_ai_fifo_dregs(dev, s); - if(s->async->buf_write_count >= devpriv->ai_bytes_to_read){ - outw_p(SCANL,dev->iobase+2); /* clears the fifo */ - outb(0x07,dev->iobase+8); /* clears all flip-flops */ + if (s->async->buf_write_count >= devpriv->ai_bytes_to_read) { + outw_p(SCANL, dev->iobase + 2); /* clears the fifo */ + outb(0x07, dev->iobase + 8); /* clears all flip-flops */ #ifdef DEBUG - printk("das6402: Got %i samples\n\n",devpriv->das6402_wordsread-diff); + printk("das6402: Got %i samples\n\n", + devpriv->das6402_wordsread - diff); #endif s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); } - outb(0x01,dev->iobase+8); /* clear only the interrupt flip-flop */ + outb(0x01, dev->iobase + 8); /* clear only the interrupt flip-flop */ comedi_event(dev, s); return IRQ_HANDLED; } #if 0 -static void das6402_ai_fifo_read(comedi_device *dev,sampl_t *data,int n) +static void das6402_ai_fifo_read(comedi_device * dev, sampl_t * data, int n) { int i; - for(i=0;iiobase); + for (i = 0; i < n; i++) + data[i] = inw(dev->iobase); } #endif - -static void das6402_ai_fifo_dregs(comedi_device *dev,comedi_subdevice *s) +static void das6402_ai_fifo_dregs(comedi_device * dev, comedi_subdevice * s) { - while(1){ - if(!(inb(dev->iobase+8)&0x01)) + while (1) { + if (!(inb(dev->iobase + 8) & 0x01)) return; - comedi_buf_put( s->async, inw(dev->iobase) ); + comedi_buf_put(s->async, inw(dev->iobase)); } } -static int das6402_ai_cancel(comedi_device *dev,comedi_subdevice *s) +static int das6402_ai_cancel(comedi_device * dev, comedi_subdevice * s) { /* * This function should reset the board from whatever condition it * is in (i.e., acquiring data), to a non-active state. */ - devpriv->das6402_ignoreirq=1; + devpriv->das6402_ignoreirq = 1; #ifdef DEBUG printk("das6402: Stopping acquisition\n"); #endif - devpriv->das6402_ignoreirq=1; - outb_p(0x02,dev->iobase+10); /* disable external trigging */ - outw_p(SCANL,dev->iobase+2); /* resets the card fifo */ - outb_p(0,dev->iobase+9); /* disables interrupts */ + devpriv->das6402_ignoreirq = 1; + outb_p(0x02, dev->iobase + 10); /* disable external trigging */ + outw_p(SCANL, dev->iobase + 2); /* resets the card fifo */ + outb_p(0, dev->iobase + 9); /* disables interrupts */ - outw_p(SCANL,dev->iobase+2); + outw_p(SCANL, dev->iobase + 2); return 0; } #ifdef unused -static int das6402_ai_mode2(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) +static int das6402_ai_mode2(comedi_device * dev, comedi_subdevice * s, + comedi_trig * it) { - devpriv->das6402_ignoreirq=1; + devpriv->das6402_ignoreirq = 1; #ifdef DEBUG printk("das6402: Starting acquisition\n"); #endif - outb_p(0x03,dev->iobase+10); /* enable external trigging */ - outw_p(SCANL,dev->iobase+2); /* resets the card fifo */ - outb_p(IRQ|CONVSRC|BURSTEN|INTE,dev->iobase+9); + outb_p(0x03, dev->iobase + 10); /* enable external trigging */ + outw_p(SCANL, dev->iobase + 2); /* resets the card fifo */ + outb_p(IRQ | CONVSRC | BURSTEN | INTE, dev->iobase + 9); - devpriv->ai_bytes_to_read=it->n*sizeof(sampl_t); + devpriv->ai_bytes_to_read = it->n * sizeof(sampl_t); /* um... ignoreirq is a nasty race condition */ - devpriv->das6402_ignoreirq=0; + devpriv->das6402_ignoreirq = 0; - outw_p(SCANL,dev->iobase+2); + outw_p(SCANL, dev->iobase + 2); return 0; } #endif - -static int board_init(comedi_device *dev) +static int board_init(comedi_device * dev) { BYTE b; - devpriv->das6402_ignoreirq=1; + devpriv->das6402_ignoreirq = 1; - outb(0x07,dev->iobase+8); + outb(0x07, dev->iobase + 8); /* register 11 */ - outb_p(MODE,dev->iobase+11); - b=BIP|SEM|MODE|GAIN|FIFOHFULL; - outb_p(b, dev->iobase+11); + outb_p(MODE, dev->iobase + 11); + b = BIP | SEM | MODE | GAIN | FIFOHFULL; + outb_p(b, dev->iobase + 11); /* register 8 */ - outb_p(EXTEND,dev->iobase+8); - b=EXTEND|MHZ; - outb_p(b,dev->iobase+8); - b= MHZ|CLRINT|CLRXTR|CLRXIN; - outb_p(b,dev->iobase+8); + outb_p(EXTEND, dev->iobase + 8); + b = EXTEND | MHZ; + outb_p(b, dev->iobase + 8); + b = MHZ | CLRINT | CLRXTR | CLRXIN; + outb_p(b, dev->iobase + 8); /* register 9 */ - b=IRQ|CONVSRC|BURSTEN|INTE; - outb_p(b,dev->iobase+9); + b = IRQ | CONVSRC | BURSTEN | INTE; + outb_p(b, dev->iobase + 9); /* register 10 */ - b=TGSEL|TGEN; - outb_p(b,dev->iobase+10); + b = TGSEL | TGEN; + outb_p(b, dev->iobase + 10); - b=0x07; - outb_p(b,dev->iobase+8); + b = 0x07; + outb_p(b, dev->iobase + 8); das6402_setcounter(dev); - outw_p(SCANL,dev->iobase+2); /* reset card fifo */ + outw_p(SCANL, dev->iobase + 2); /* reset card fifo */ - devpriv->das6402_ignoreirq=0; + devpriv->das6402_ignoreirq = 0; - return 0; + return 0; } -static int das6402_detach(comedi_device *dev) +static int das6402_detach(comedi_device * dev) { - if(dev->irq)comedi_free_irq(dev->irq,dev); - if(dev->iobase)release_region(dev->iobase,DAS6402_SIZE); + if (dev->irq) + comedi_free_irq(dev->irq, dev); + if (dev->iobase) + release_region(dev->iobase, DAS6402_SIZE); return 0; } -static int das6402_attach(comedi_device *dev,comedi_devconfig *it) +static int das6402_attach(comedi_device * dev, comedi_devconfig * it) { unsigned int irq; unsigned long iobase; int ret; comedi_subdevice *s; - dev->board_name="das6402"; + dev->board_name = "das6402"; - iobase=it->options[0]; - if(iobase==0)iobase=0x300; + iobase = it->options[0]; + if (iobase == 0) + iobase = 0x300; - printk("comedi%d: das6402: 0x%04lx",dev->minor,iobase); + printk("comedi%d: das6402: 0x%04lx", dev->minor, iobase); - if(!request_region(iobase,DAS6402_SIZE,"das6402")){ + if (!request_region(iobase, DAS6402_SIZE, "das6402")) { printk(" I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; /* should do a probe here */ - irq=it->options[0]; + irq = it->options[0]; printk(" ( irq = %u )", irq); - ret=comedi_request_irq(irq, intr_handler, 0, "das6402", dev); - if(ret<0){ + ret = comedi_request_irq(irq, intr_handler, 0, "das6402", dev); + if (ret < 0) { printk("irq conflict\n"); return ret; } - dev->irq=irq; + dev->irq = irq; - if((ret=alloc_private(dev,sizeof(das6402_private)))<0) + if ((ret = alloc_private(dev, sizeof(das6402_private))) < 0) return ret; - if((ret=alloc_subdevices(dev, 1))<0) + if ((ret = alloc_subdevices(dev, 1)) < 0) return ret; /* ai subdevice */ - s=dev->subdevices+0; - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; - s->n_chan=8; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 8; //s->trig[2]=das6402_ai_mode2; - s->cancel=das6402_ai_cancel; - s->maxdata=(1<<12)-1; - s->len_chanlist=16; /* ? */ + s->cancel = das6402_ai_cancel; + s->maxdata = (1 << 12) - 1; + s->len_chanlist = 16; /* ? */ s->range_table = &range_unknown; board_init(dev); return 0; } - diff --git a/comedi/drivers/das800.c b/comedi/drivers/das800.c index 729742af..1d3b873b 100644 --- a/comedi/drivers/das800.c +++ b/comedi/drivers/das800.c @@ -106,169 +106,173 @@ cmd triggers supported: #define STATUS2_INTE 0X20 #define DAS800_ID 7 -typedef struct das800_board_struct{ +typedef struct das800_board_struct { const char *name; int ai_speed; const comedi_lrange *ai_range; int resolution; -}das800_board; +} das800_board; //analog input ranges static const comedi_lrange range_das800_ai = { 1, { - RANGE( -5, 5 ), - } + RANGE(-5, 5), + } }; static const comedi_lrange range_das801_ai = { 9, { - RANGE(-5, 5), - RANGE(-10, 10), - RANGE(0, 10), - RANGE(-0.5, 0.5), - RANGE(0, 1), - RANGE(-0.05, 0.05), - RANGE(0, 0.1), - RANGE(-0.01, 0.01), - RANGE(0, 0.02), - } + RANGE(-5, 5), + RANGE(-10, 10), + RANGE(0, 10), + RANGE(-0.5, 0.5), + RANGE(0, 1), + RANGE(-0.05, 0.05), + RANGE(0, 0.1), + RANGE(-0.01, 0.01), + RANGE(0, 0.02), + } }; static const comedi_lrange range_cio_das801_ai = { 9, { - RANGE(-5, 5), - RANGE(-10, 10), - RANGE(0, 10), - RANGE(-0.5, 0.5), - RANGE(0, 1), - RANGE(-0.05, 0.05), - RANGE(0, 0.1), - RANGE(-0.005, 0.005), - RANGE(0, 0.01), - } + RANGE(-5, 5), + RANGE(-10, 10), + RANGE(0, 10), + RANGE(-0.5, 0.5), + RANGE(0, 1), + RANGE(-0.05, 0.05), + RANGE(0, 0.1), + RANGE(-0.005, 0.005), + RANGE(0, 0.01), + } }; static const comedi_lrange range_das802_ai = { 9, { - RANGE(-5, 5), - RANGE(-10, 10), - RANGE(0, 10), - RANGE(-2.5, 2.5), - RANGE(0, 5), - RANGE(-1.25, 1.25), - RANGE(0, 2.5), - RANGE(-0.625, 0.625), - RANGE(0, 1.25), - } + RANGE(-5, 5), + RANGE(-10, 10), + RANGE(0, 10), + RANGE(-2.5, 2.5), + RANGE(0, 5), + RANGE(-1.25, 1.25), + RANGE(0, 2.5), + RANGE(-0.625, 0.625), + RANGE(0, 1.25), + } }; static const comedi_lrange range_das80216_ai = { 8, { - RANGE(-10, 10), - RANGE(0, 10), - RANGE(-5, 5), - RANGE(0, 5), - RANGE(-2.5, 2.5), - RANGE(0, 2.5), - RANGE(-1.25, 1.25), - RANGE(0, 1.25), - } + RANGE(-10, 10), + RANGE(0, 10), + RANGE(-5, 5), + RANGE(0, 5), + RANGE(-2.5, 2.5), + RANGE(0, 2.5), + RANGE(-1.25, 1.25), + RANGE(0, 1.25), + } }; -enum{das800, ciodas800, das801, ciodas801, das802, ciodas802, ciodas80216}; - -static const das800_board das800_boards[] = -{ - { - name: "das-800", - ai_speed: 25000, - ai_range: &range_das800_ai, - resolution: 12, - }, - { - name: "cio-das800", - ai_speed: 20000, - ai_range: &range_das800_ai, - resolution: 12, - }, - { - name: "das-801", - ai_speed: 25000, - ai_range: &range_das801_ai, - resolution: 12, - }, - { - name: "cio-das801", - ai_speed: 20000, - ai_range: &range_cio_das801_ai, - resolution: 12, - }, - { - name: "das-802", - ai_speed: 25000, - ai_range: &range_das802_ai, - resolution: 12, - }, - { - name: "cio-das802", - ai_speed: 20000, - ai_range: &range_das802_ai, - resolution: 12, - }, - { - name: "cio-das802/16", - ai_speed: 10000, - ai_range: &range_das80216_ai, - resolution: 16, - }, +enum { das800, ciodas800, das801, ciodas801, das802, ciodas802, ciodas80216 }; + +static const das800_board das800_boards[] = { + { + name: "das-800", + ai_speed:25000, + ai_range:&range_das800_ai, + resolution:12, + }, + { + name: "cio-das800", + ai_speed:20000, + ai_range:&range_das800_ai, + resolution:12, + }, + { + name: "das-801", + ai_speed:25000, + ai_range:&range_das801_ai, + resolution:12, + }, + { + name: "cio-das801", + ai_speed:20000, + ai_range:&range_cio_das801_ai, + resolution:12, + }, + { + name: "das-802", + ai_speed:25000, + ai_range:&range_das802_ai, + resolution:12, + }, + { + name: "cio-das802", + ai_speed:20000, + ai_range:&range_das802_ai, + resolution:12, + }, + { + name: "cio-das802/16", + ai_speed:10000, + ai_range:&range_das80216_ai, + resolution:16, + }, }; + /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const das800_board *)dev->board_ptr) -typedef struct{ - volatile unsigned int count; /* number of data points left to be taken */ - volatile int forever; /* flag indicating whether we should take data forever */ +typedef struct { + volatile unsigned int count; /* number of data points left to be taken */ + volatile int forever; /* flag indicating whether we should take data forever */ unsigned int divisor1; /* value to load into board's counter 1 for timed conversions */ - unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */ + unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */ volatile int do_bits; /* digital output bits */ -}das800_private; +} das800_private; #define devpriv ((das800_private *)dev->private) -static int das800_attach(comedi_device *dev,comedi_devconfig *it); -static int das800_detach(comedi_device *dev); -static int das800_cancel(comedi_device *dev, comedi_subdevice *s); - -static comedi_driver driver_das800={ - driver_name: "das800", - module: THIS_MODULE, - attach: das800_attach, - detach: das800_detach, - num_names: sizeof(das800_boards) / sizeof(das800_board), - board_name: &das800_boards[0].name, - offset: sizeof(das800_board), +static int das800_attach(comedi_device * dev, comedi_devconfig * it); +static int das800_detach(comedi_device * dev); +static int das800_cancel(comedi_device * dev, comedi_subdevice * s); + +static comedi_driver driver_das800 = { + driver_name:"das800", + module:THIS_MODULE, + attach:das800_attach, + detach:das800_detach, + num_names:sizeof(das800_boards) / sizeof(das800_board), + board_name:&das800_boards[0].name, + offset:sizeof(das800_board), }; static irqreturn_t das800_interrupt(int irq, void *d PT_REGS_ARG); -static void enable_das800(comedi_device *dev); -static void disable_das800(comedi_device *dev); -static int das800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int das800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s); -static int das800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int das800_probe(comedi_device *dev); -static int das800_set_frequency(comedi_device *dev); +static void enable_das800(comedi_device * dev); +static void disable_das800(comedi_device * dev); +static int das800_ai_do_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int das800_ai_do_cmd(comedi_device * dev, comedi_subdevice * s); +static int das800_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das800_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das800_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int das800_probe(comedi_device * dev); +static int das800_set_frequency(comedi_device * dev); /* checks and probes das-800 series board type */ -static int das800_probe(comedi_device *dev) +static int das800_probe(comedi_device * dev) { int id_bits; unsigned long irq_flags; @@ -277,64 +281,57 @@ static int das800_probe(comedi_device *dev) // 'comedi spin lock irqsave' disables even rt interrupts, we use them to protect indirect addressing comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); outb(ID, dev->iobase + DAS800_GAIN); /* select base address + 7 to be ID register */ - id_bits = inb(dev->iobase + DAS800_ID) & 0x3; /* get id bits */ + id_bits = inb(dev->iobase + DAS800_ID) & 0x3; /* get id bits */ comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); board = thisboard - das800_boards; - switch(id_bits) - { - case 0x0: - if(board == das800) - { - printk(" Board model: DAS-800\n"); - return board; - } - if(board == ciodas800) - { - printk(" Board model: CIO-DAS800\n"); - return board; - } - printk(" Board model (probed): DAS-800\n"); - return das800; - break; - case 0x2: - if(board == das801) - { - printk(" Board model: DAS-801\n"); - return board; - } - if(board == ciodas801) - { - printk(" Board model: CIO-DAS801\n"); - return board; - } - printk(" Board model (probed): DAS-801\n"); - return das801; - break; - case 0x3: - if(board == das802) - { - printk(" Board model: DAS-802\n"); - return board; - } - if(board == ciodas802) - { - printk(" Board model: CIO-DAS802\n"); - return board; - } - if(board == ciodas80216) - { - printk(" Board model: CIO-DAS802/16\n"); - return board; - } - printk(" Board model (probed): DAS-802\n"); - return das802; - break; - default : - printk(" Board model: probe returned 0x%x (unknown)\n", id_bits); + switch (id_bits) { + case 0x0: + if (board == das800) { + printk(" Board model: DAS-800\n"); return board; - break; + } + if (board == ciodas800) { + printk(" Board model: CIO-DAS800\n"); + return board; + } + printk(" Board model (probed): DAS-800\n"); + return das800; + break; + case 0x2: + if (board == das801) { + printk(" Board model: DAS-801\n"); + return board; + } + if (board == ciodas801) { + printk(" Board model: CIO-DAS801\n"); + return board; + } + printk(" Board model (probed): DAS-801\n"); + return das801; + break; + case 0x3: + if (board == das802) { + printk(" Board model: DAS-802\n"); + return board; + } + if (board == ciodas802) { + printk(" Board model: CIO-DAS802\n"); + return board; + } + if (board == ciodas80216) { + printk(" Board model: CIO-DAS802/16\n"); + return board; + } + printk(" Board model (probed): DAS-802\n"); + return das802; + break; + default: + printk(" Board model: probe returned 0x%x (unknown)\n", + id_bits); + return board; + break; } return -1; } @@ -362,9 +359,9 @@ static irqreturn_t das800_interrupt(int irq, void *d PT_REGS_ARG) status = inb(dev->iobase + DAS800_STATUS); /* if interrupt was not generated by board or driver not attached, quit */ - if(!(status & IRQ) ) + if (!(status & IRQ)) return IRQ_NONE; - if(!(dev->attached)) + if (!(dev->attached)) return IRQ_HANDLED; /* wait until here to initialize async, since we will get null dereference @@ -377,54 +374,47 @@ static irqreturn_t das800_interrupt(int irq, void *d PT_REGS_ARG) outb(CONTROL1, dev->iobase + DAS800_GAIN); /* select base address + 7 to be STATUS2 register */ status = inb(dev->iobase + DAS800_STATUS2) & STATUS2_HCEN; /* don't release spinlock yet since we want to make sure noone else disables hardware conversions */ - if(status == 0) - { + if (status == 0) { comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); return IRQ_HANDLED; } /* loop while card's fifo is not empty (and limit to half fifo for cio-das802/16) */ - for(i = 0; i < max_loops; i++) - { + for (i = 0; i < max_loops; i++) { /* read 16 bits from dev->iobase and dev->iobase + 1 */ dataPoint = inb(dev->iobase + DAS800_LSB); dataPoint += inb(dev->iobase + DAS800_MSB) << 8; - if(thisboard->resolution == 12) - { + if (thisboard->resolution == 12) { fifo_empty = dataPoint & FIFO_EMPTY; fifo_overflow = dataPoint & FIFO_OVF; - if(fifo_overflow) break; - }else - { + if (fifo_overflow) + break; + } else { fifo_empty = 0; // cio-das802/16 has no fifo empty status bit } - if(fifo_empty) - { + if (fifo_empty) { break; } - /* strip off extraneous bits for 12 bit cards*/ - if(thisboard->resolution == 12) + /* strip off extraneous bits for 12 bit cards */ + if (thisboard->resolution == 12) dataPoint = (dataPoint >> 4) & 0xfff; /* if there are more data points to collect */ - if(devpriv->count > 0 || devpriv->forever == 1) - { + if (devpriv->count > 0 || devpriv->forever == 1) { /* write data point to buffer */ - cfc_write_to_buffer( s, dataPoint); - if(devpriv->count > 0) devpriv->count--; + cfc_write_to_buffer(s, dataPoint); + if (devpriv->count > 0) + devpriv->count--; } } async->events |= COMEDI_CB_BLOCK; /* check for fifo overflow */ - if(thisboard->resolution == 12) - { + if (thisboard->resolution == 12) { fifo_overflow = dataPoint & FIFO_OVF; - // else cio-das802/16 - }else - { + // else cio-das802/16 + } else { fifo_overflow = inb(dev->iobase + DAS800_GAIN) & CIO_FFOV; } - if(fifo_overflow) - { + if (fifo_overflow) { comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); comedi_error(dev, "DAS800 FIFO overflow"); das800_cancel(dev, dev->subdevices + 0); @@ -433,18 +423,17 @@ static irqreturn_t das800_interrupt(int irq, void *d PT_REGS_ARG) async->events = 0; return IRQ_HANDLED; } - if(devpriv->count > 0 || devpriv->forever == 1) - { + if (devpriv->count > 0 || devpriv->forever == 1) { /* Re-enable card's interrupt. * We already have spinlock, so indirect addressing is safe */ outb(CONTROL1, dev->iobase + DAS800_GAIN); /* select dev->iobase + 2 to be control register 1 */ - outb(CONTROL1_INTE | devpriv->do_bits, dev->iobase + DAS800_CONTROL1); + outb(CONTROL1_INTE | devpriv->do_bits, + dev->iobase + DAS800_CONTROL1); comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); - /* otherwise, stop taking data */ - } else - { + /* otherwise, stop taking data */ + } else { comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); - disable_das800(dev); /* diable hardware triggered conversions */ + disable_das800(dev); /* diable hardware triggered conversions */ async->events |= COMEDI_CB_EOA; } comedi_event(dev, s); @@ -452,7 +441,7 @@ static irqreturn_t das800_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static int das800_attach(comedi_device *dev, comedi_devconfig *it) +static int das800_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase = it->options[0]; @@ -461,49 +450,42 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) int board; printk("comedi%d: das800: io 0x%lx", dev->minor, iobase); - if(irq) - { + if (irq) { printk(", irq %u", irq); } printk("\n"); /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(das800_private)) < 0) + if (alloc_private(dev, sizeof(das800_private)) < 0) return -ENOMEM; - if(iobase == 0) - { + if (iobase == 0) { printk("io base address required for das800\n"); return -EINVAL; } /* check if io addresses are available */ - if(!request_region(iobase, DAS800_SIZE, "das800")) - { + if (!request_region(iobase, DAS800_SIZE, "das800")) { printk("I/O port conflict\n"); return -EIO; } dev->iobase = iobase; board = das800_probe(dev); - if(board < 0) - { + if (board < 0) { printk("unable to determine board type\n"); return -ENODEV; } dev->board_ptr = das800_boards + board; /* grab our IRQ */ - if(irq == 1 || irq > 7) - { + if (irq == 1 || irq > 7) { printk("irq out of range\n"); return -EINVAL; } - if(irq) - { - if(comedi_request_irq( irq, das800_interrupt, 0, "das800", dev )) - { - printk( "unable to allocate irq %u\n", irq); + if (irq) { + if (comedi_request_irq(irq, das800_interrupt, 0, "das800", dev)) { + printk("unable to allocate irq %u\n", irq); return -EINVAL; } } @@ -511,7 +493,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; - if(alloc_subdevices(dev, 3) < 0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; /* analog input subdevice */ @@ -530,7 +512,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) /* di */ s = dev->subdevices + 1; - s->type=COMEDI_SUBD_DI; + s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = 3; s->maxdata = 1; @@ -539,7 +521,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) /* do */ s = dev->subdevices + 2; - s->type=COMEDI_SUBD_DO; + s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 4; s->maxdata = 1; @@ -557,19 +539,19 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) return 0; }; -static int das800_detach(comedi_device *dev) +static int das800_detach(comedi_device * dev) { printk("comedi%d: das800: remove\n", dev->minor); /* only free stuff if it has been allocated by _attach */ - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, DAS800_SIZE); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); return 0; }; -static int das800_cancel(comedi_device *dev, comedi_subdevice *s) +static int das800_cancel(comedi_device * dev, comedi_subdevice * s) { devpriv->forever = 0; devpriv->count = 0; @@ -578,12 +560,12 @@ static int das800_cancel(comedi_device *dev, comedi_subdevice *s) } /* enable_das800 makes the card start taking hardware triggered conversions */ -static void enable_das800(comedi_device *dev) +static void enable_das800(comedi_device * dev) { unsigned long irq_flags; comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); // enable fifo-half full interrupts for cio-das802/16 - if(thisboard->resolution == 16) + if (thisboard->resolution == 16) outb(CIO_ENHF, dev->iobase + DAS800_GAIN); outb(CONV_CONTROL, dev->iobase + DAS800_GAIN); /* select dev->iobase + 2 to be conversion control register */ outb(CONV_HCEN, dev->iobase + DAS800_CONV_CONTROL); /* enable hardware triggering */ @@ -593,7 +575,7 @@ static void enable_das800(comedi_device *dev) } /* disable_das800 stops hardware triggered conversions */ -static void disable_das800(comedi_device *dev) +static void disable_das800(comedi_device * dev) { unsigned long irq_flags; comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); @@ -602,7 +584,8 @@ static void disable_das800(comedi_device *dev) comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); } -static int das800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int das800_ai_do_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -613,127 +596,129 @@ static int das800_ai_do_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cm tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) err++; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg != 0) - { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + 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) - { + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { cmd->stop_arg = 1; err++; } - } else - { /* TRIG_NONE */ - if(cmd->stop_arg != 0) - { + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->convert_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER) { tmp = cmd->convert_arg; /* calculate counter values that give desired timing */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(cmd->convert_arg), cmd->flags & TRIG_ROUND_MASK); - if(tmp != cmd->convert_arg) err++; + i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), + &(devpriv->divisor2), &(cmd->convert_arg), + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err++; } - if(err)return 4; + if (err) + return 4; // check channel/gain list against card's limitations - if(cmd->chanlist) - { + if (cmd->chanlist) { gain = CR_RANGE(cmd->chanlist[0]); startChan = CR_CHAN(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++) - { - if(CR_CHAN(cmd->chanlist[i]) != (startChan + i) % N_CHAN_AI) - { - comedi_error(dev, "entries in chanlist must be consecutive channels, counting upwards\n"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != + (startChan + i) % N_CHAN_AI) { + comedi_error(dev, + "entries in chanlist must be consecutive channels, counting upwards\n"); err++; } - if(CR_RANGE(cmd->chanlist[i]) != gain) - { - comedi_error(dev, "entries in chanlist must all have the same gain\n"); + if (CR_RANGE(cmd->chanlist[i]) != gain) { + comedi_error(dev, + "entries in chanlist must all have the same gain\n"); err++; } } } - if(err)return 5; + if (err) + return 5; return 0; } -static int das800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) +static int das800_ai_do_cmd(comedi_device * dev, comedi_subdevice * s) { int startChan, endChan, scan, gain; int conv_bits; unsigned long irq_flags; comedi_async *async = s->async; - if(!dev->irq) - { - comedi_error(dev, "no irq assigned for das-800, cannot do hardware conversions"); + if (!dev->irq) { + comedi_error(dev, + "no irq assigned for das-800, cannot do hardware conversions"); return -1; } @@ -746,28 +731,27 @@ static int das800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); outb(SCAN_LIMITS, dev->iobase + DAS800_GAIN); /* select base address + 2 to be scan limits register */ - outb(scan, dev->iobase + DAS800_SCAN_LIMITS); /* set scan limits */ + outb(scan, dev->iobase + DAS800_SCAN_LIMITS); /* set scan limits */ comedi_spin_unlock_irqrestore(&dev->spinlock, irq_flags); /* set gain */ gain = CR_RANGE(async->cmd.chanlist[0]); - if( thisboard->resolution == 12 && gain > 0) + if (thisboard->resolution == 12 && gain > 0) gain += 0x7; gain &= 0xf; outb(gain, dev->iobase + DAS800_GAIN); - switch(async->cmd.stop_src) - { - case TRIG_COUNT: - devpriv->count = async->cmd.stop_arg * async->cmd.chanlist_len; - devpriv->forever = 0; - break; - case TRIG_NONE: - devpriv->forever = 1; - devpriv->count = 0; - break; - default : - break; + switch (async->cmd.stop_src) { + case TRIG_COUNT: + devpriv->count = async->cmd.stop_arg * async->cmd.chanlist_len; + devpriv->forever = 0; + break; + case TRIG_NONE: + devpriv->forever = 1; + devpriv->count = 0; + break; + default: + break; } /* enable auto channel scan, send interrupts on end of conversion @@ -775,24 +759,24 @@ static int das800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) */ conv_bits = 0; conv_bits |= EACS | IEOC; - if(async->cmd.start_src == TRIG_EXT) + if (async->cmd.start_src == TRIG_EXT) conv_bits |= DTEN; - switch(async->cmd.convert_src) - { - case TRIG_TIMER: - conv_bits |= CASC | ITE; - /* set conversion frequency */ - i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), &(devpriv->divisor2), &(async->cmd.convert_arg), async->cmd.flags & TRIG_ROUND_MASK); - if(das800_set_frequency(dev) < 0) - { - comedi_error(dev, "Error setting up counters"); - return -1; - } - break; - case TRIG_EXT: - break; - default: - break; + switch (async->cmd.convert_src) { + case TRIG_TIMER: + conv_bits |= CASC | ITE; + /* set conversion frequency */ + i8253_cascade_ns_to_timer_2div(TIMER_BASE, &(devpriv->divisor1), + &(devpriv->divisor2), &(async->cmd.convert_arg), + async->cmd.flags & TRIG_ROUND_MASK); + if (das800_set_frequency(dev) < 0) { + comedi_error(dev, "Error setting up counters"); + return -1; + } + break; + case TRIG_EXT: + break; + default: + break; } comedi_spin_lock_irqsave(&dev->spinlock, irq_flags); @@ -804,9 +788,10 @@ static int das800_ai_do_cmd(comedi_device *dev, comedi_subdevice *s) return 0; } -static int das800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das800_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i, n; + int i, n; int chan; int range; int lsb, msb; @@ -825,36 +810,31 @@ static int das800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn /* set gain / range */ range = CR_RANGE(insn->chanspec); - if(thisboard->resolution == 12 && range) + if (thisboard->resolution == 12 && range) range += 0x7; range &= 0xf; outb(range, dev->iobase + DAS800_GAIN); comedi_udelay(5); - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* trigger conversion */ outb_p(0, dev->iobase + DAS800_MSB); - for(i = 0; i < timeout; i++) - { - if(!(inb(dev->iobase + DAS800_STATUS) & BUSY)) + for (i = 0; i < timeout; i++) { + if (!(inb(dev->iobase + DAS800_STATUS) & BUSY)) break; } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } lsb = inb(dev->iobase + DAS800_LSB); msb = inb(dev->iobase + DAS800_MSB); - if(thisboard->resolution == 12) - { + if (thisboard->resolution == 12) { data[n] = (lsb >> 4) & 0xff; data[n] |= (msb << 4); - }else - { + } else { data[n] = (msb << 8) | lsb; } } @@ -862,7 +842,8 @@ static int das800_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn return n; } -static int das800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das800_di_rbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { lsampl_t bits; @@ -874,12 +855,12 @@ static int das800_di_rbits(comedi_device *dev, comedi_subdevice *s, comedi_insn return 2; } -static int das800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int das800_do_wbits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int wbits; unsigned long irq_flags; - // only set bits that have been masked data[0] &= 0xf; wbits = devpriv->do_bits >> 4; @@ -898,13 +879,15 @@ static int das800_do_wbits(comedi_device *dev, comedi_subdevice *s, comedi_insn } /* loads counters with divisor1, divisor2 from private structure */ -static int das800_set_frequency(comedi_device *dev) +static int das800_set_frequency(comedi_device * dev) { int err = 0; - if(i8254_load(dev->iobase + DAS800_8254, 0, 1, devpriv->divisor1, 2)) err++; - if(i8254_load(dev->iobase + DAS800_8254, 0, 2, devpriv->divisor2, 2)) err++; - if(err) + if (i8254_load(dev->iobase + DAS800_8254, 0, 1, devpriv->divisor1, 2)) + err++; + if (i8254_load(dev->iobase + DAS800_8254, 0, 2, devpriv->divisor2, 2)) + err++; + if (err) return -1; return 0; diff --git a/comedi/drivers/dmm32at.c b/comedi/drivers/dmm32at.c index 730bdb55..dfa4398d 100644 --- a/comedi/drivers/dmm32at.c +++ b/comedi/drivers/dmm32at.c @@ -77,8 +77,6 @@ Configuration Options: #include #include - - /* Board register addresses */ #define DMM32AT_MEMSIZE 0x10 @@ -119,7 +117,6 @@ Configuration Options: #define dmm_inb(cdev,reg) inb((cdev->iobase)+reg) #define dmm_outb(cdev,reg,valu) outb(valu,(cdev->iobase)+reg) - /* Board register values. */ /* DMM32AT_DACSTAT 0x04 */ @@ -145,7 +142,6 @@ Configuration Options: /* DMM32AT_CNTRDIO 0x0a */ #define DMM32AT_FREQ12 0x80 - /* DMM32AT_AICONF 0x0b */ #define DMM32AT_RANGE_U10 0x0c #define DMM32AT_RANGE_U5 0x0d @@ -157,8 +153,8 @@ Configuration Options: #define DMM32AT_SCINT_5 0x30 /* DMM32AT_CLKCT 0x0f */ -#define DMM32AT_CLKCT1 0x56 /* mode3 counter 1 - write low byte only */ -#define DMM32AT_CLKCT2 0xb6 /* mode3 counter 2 - write high and low byte */ +#define DMM32AT_CLKCT1 0x56 /* mode3 counter 1 - write low byte only */ +#define DMM32AT_CLKCT2 0xb6 /* mode3 counter 2 - write high and low byte */ /* DMM32AT_DIOCONF 0x0f */ #define DMM32AT_DIENABLE 0x80 @@ -168,18 +164,16 @@ Configuration Options: #define DMM32AT_DIRCH 0x08 /* board AI ranges in comedi structure */ -static const comedi_lrange dmm32at_airanges = -{ - 4, - { - UNI_RANGE(10), - UNI_RANGE(5), - BIP_RANGE(10), - BIP_RANGE(5), - } +static const comedi_lrange dmm32at_airanges = { + 4, + { + UNI_RANGE(10), + UNI_RANGE(5), + BIP_RANGE(10), + BIP_RANGE(5), + } }; - /* register values for above ranges */ static const unsigned char dmm32at_rangebits[] = { DMM32AT_RANGE_U10, @@ -191,15 +185,14 @@ static const unsigned char dmm32at_rangebits[] = { /* only one of these ranges is valid, as set by a jumper on the * board. The application should only use the range set by the jumper */ -static const comedi_lrange dmm32at_aoranges = -{ - 4, - { - UNI_RANGE(10), - UNI_RANGE(5), - BIP_RANGE(10), - BIP_RANGE(5), - } +static const comedi_lrange dmm32at_aoranges = { + 4, + { + UNI_RANGE(10), + UNI_RANGE(5), + BIP_RANGE(10), + BIP_RANGE(5), + } }; /* @@ -207,7 +200,7 @@ static const comedi_lrange dmm32at_aoranges = * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct dmm32at_board_struct{ +typedef struct dmm32at_board_struct { const char *name; int ai_chans; int ai_bits; @@ -217,22 +210,21 @@ typedef struct dmm32at_board_struct{ const comedi_lrange *ao_ranges; int have_dio; int dio_chans; -}dmm32at_board; +} dmm32at_board; static const dmm32at_board dmm32at_boards[] = { { - name: "dmm32at", - ai_chans: 32, - ai_bits: 16, - ai_ranges: &dmm32at_airanges, - ao_chans: 4, - ao_bits: 12, - ao_ranges: &dmm32at_aoranges, - have_dio: 1, - dio_chans: 24, - }, + name: "dmm32at", + ai_chans:32, + ai_bits: 16, + ai_ranges:&dmm32at_airanges, + ao_chans:4, + ao_bits: 12, + ao_ranges:&dmm32at_aoranges, + have_dio:1, + dio_chans:24, + }, }; - /* * Useful for shorthand access to the particular board structure */ @@ -252,7 +244,6 @@ typedef struct { lsampl_t ao_readback[4]; unsigned char dio_config; - } dmm32at_private; /* @@ -261,20 +252,19 @@ typedef struct { */ #define devpriv ((dmm32at_private *)dev->private) - /* * The comedi_driver structure tells the Comedi core module * which functions to call to configure/deconfigure (attach/detach) * the board, and also about the kernel module that contains * the device code. */ -static int dmm32at_attach(comedi_device *dev,comedi_devconfig *it); -static int dmm32at_detach(comedi_device *dev); -static comedi_driver driver_dmm32at={ - driver_name: "dmm32at", - module: THIS_MODULE, - attach: dmm32at_attach, - detach: dmm32at_detach, +static int dmm32at_attach(comedi_device * dev, comedi_devconfig * it); +static int dmm32at_detach(comedi_device * dev); +static comedi_driver driver_dmm32at = { + driver_name:"dmm32at", + module:THIS_MODULE, + attach:dmm32at_attach, + detach:dmm32at_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -293,28 +283,29 @@ static comedi_driver driver_dmm32at={ * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &dmm32at_boards[0].name, - offset: sizeof(dmm32at_board), - num_names: sizeof(dmm32at_boards) / sizeof(dmm32at_board), + board_name:&dmm32at_boards[0].name, + offset:sizeof(dmm32at_board), + num_names:sizeof(dmm32at_boards) / sizeof(dmm32at_board), }; - /* prototypes for driver functions below */ -static int dmm32at_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int dmm32at_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int dmm32at_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int dmm32at_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dmm32at_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dmm32at_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int dmm32at_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int dmm32at_ai_cancel(comedi_device *dev,comedi_subdevice *s); -static int dmm32at_ns_to_timer(unsigned int *ns,int round); -static irqreturn_t dmm32at_isr(int irq,void *d PT_REGS_ARG); -void dmm32at_setaitimer(comedi_device *dev,unsigned int nansec); - +static int dmm32at_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dmm32at_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dmm32at_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dmm32at_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dmm32at_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dmm32at_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int dmm32at_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int dmm32at_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static int dmm32at_ns_to_timer(unsigned int *ns, int round); +static irqreturn_t dmm32at_isr(int irq, void *d PT_REGS_ARG); +void dmm32at_setaitimer(comedi_device * dev, unsigned int nansec); /* * Attach is called by the Comedi core to configure the driver @@ -322,85 +313,82 @@ void dmm32at_setaitimer(comedi_device *dev,unsigned int nansec); * in the driver structure, dev->board_ptr contains that * address. */ -static int dmm32at_attach(comedi_device *dev,comedi_devconfig *it) +static int dmm32at_attach(comedi_device * dev, comedi_devconfig * it) { int ret; comedi_subdevice *s; - unsigned char aihi,ailo,fifostat,aistat,intstat,airback; + unsigned char aihi, ailo, fifostat, aistat, intstat, airback; unsigned long iobase; unsigned int irq; iobase = it->options[0]; irq = it->options[1]; - printk("comedi%d: dmm32at: attaching\n",dev->minor); - printk("dmm32at: probing at address 0x%04lx, irq %u\n", - iobase, irq); + printk("comedi%d: dmm32at: attaching\n", dev->minor); + printk("dmm32at: probing at address 0x%04lx, irq %u\n", iobase, irq); /* register address space */ - if (!request_region(iobase,DMM32AT_MEMSIZE,thisboard->name)) { + if (!request_region(iobase, DMM32AT_MEMSIZE, thisboard->name)) { printk("I/O port conflict\n"); return -EIO; } dev->iobase = iobase; - /* the following just makes sure the board is there and gets it to a known state */ /* reset the board */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_RESET); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_RESET); /* allow a millisecond to reset */ udelay(1000); /* zero scan and fifo control */ - dmm_outb(dev,DMM32AT_FIFOCNTRL,0x0); + dmm_outb(dev, DMM32AT_FIFOCNTRL, 0x0); /* zero interrupt and clock control */ - dmm_outb(dev,DMM32AT_INTCLOCK,0x0); + dmm_outb(dev, DMM32AT_INTCLOCK, 0x0); /* write a test channel range, the high 3 bits should drop */ - dmm_outb(dev,DMM32AT_AILOW,0x80); - dmm_outb(dev,DMM32AT_AIHIGH,0xff); + dmm_outb(dev, DMM32AT_AILOW, 0x80); + dmm_outb(dev, DMM32AT_AIHIGH, 0xff); /* set the range at 10v unipolar */ - dmm_outb(dev,DMM32AT_AICONF,DMM32AT_RANGE_U10); + dmm_outb(dev, DMM32AT_AICONF, DMM32AT_RANGE_U10); /* should take 10 us to settle, here's a hundred */ udelay(100); /* read back the values */ - ailo = dmm_inb(dev,DMM32AT_AILOW); - aihi = dmm_inb(dev,DMM32AT_AIHIGH); - fifostat = dmm_inb(dev,DMM32AT_FIFOSTAT); - aistat = dmm_inb(dev,DMM32AT_AISTAT); - intstat = dmm_inb(dev,DMM32AT_INTCLOCK); - airback = dmm_inb(dev,DMM32AT_AIRBACK); + ailo = dmm_inb(dev, DMM32AT_AILOW); + aihi = dmm_inb(dev, DMM32AT_AIHIGH); + fifostat = dmm_inb(dev, DMM32AT_FIFOSTAT); + aistat = dmm_inb(dev, DMM32AT_AISTAT); + intstat = dmm_inb(dev, DMM32AT_INTCLOCK); + airback = dmm_inb(dev, DMM32AT_AIRBACK); printk("dmm32at: lo=0x%02x hi=0x%02x fifostat=0x%02x\n", - ailo,aihi,fifostat); + ailo, aihi, fifostat); printk("dmm32at: aistat=0x%02x intstat=0x%02x airback=0x%02x\n", - aistat,intstat,airback); + aistat, intstat, airback); - if( (ailo != 0x00) || (aihi != 0x1f) || (fifostat != 0x80) || - (aistat != 0x60 || (intstat != 0x00) || airback != 0x0c) ){ + if ((ailo != 0x00) || (aihi != 0x1f) || (fifostat != 0x80) || + (aistat != 0x60 || (intstat != 0x00) || airback != 0x0c)) { printk("dmmat32: board detection failed\n"); return -EIO; } /* board is there, register interrupt */ if (irq) { - ret=comedi_request_irq(irq, dmm32at_isr,0,thisboard->name,dev); - if(ret<0){ + ret = comedi_request_irq(irq, dmm32at_isr, 0, thisboard->name, + dev); + if (ret < 0) { printk("irq conflict\n"); return ret; } dev->irq = irq; } - - /* * If you can probe the device to determine what device in a series * it is, this is the place to do it. Otherwise, dev->board_ptr @@ -418,74 +406,73 @@ static int dmm32at_attach(comedi_device *dev,comedi_devconfig *it) * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if(alloc_private(dev,sizeof(dmm32at_private))<0) + if (alloc_private(dev, sizeof(dmm32at_private)) < 0) return -ENOMEM; /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 3)<0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; - s=dev->subdevices+0; - dev->read_subdev=s; + s = dev->subdevices + 0; + dev->read_subdev = s; /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; /* we support single-ended (ground) and differential */ s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - s->n_chan=thisboard->ai_chans; - s->maxdata=(1<ai_bits)-1; - s->range_table=thisboard->ai_ranges; - s->len_chanlist=32; /* This is the maximum chanlist length that - the board can handle */ + s->n_chan = thisboard->ai_chans; + s->maxdata = (1 << thisboard->ai_bits) - 1; + s->range_table = thisboard->ai_ranges; + s->len_chanlist = 32; /* This is the maximum chanlist length that + the board can handle */ s->insn_read = dmm32at_ai_rinsn; s->do_cmd = dmm32at_ai_cmd; s->do_cmdtest = dmm32at_ai_cmdtest; s->cancel = dmm32at_ai_cancel; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=thisboard->ao_chans; - s->maxdata=(1<ao_bits)-1; - s->range_table=thisboard->ao_ranges; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->ao_chans; + s->maxdata = (1 << thisboard->ao_bits) - 1; + s->range_table = thisboard->ao_ranges; s->insn_write = dmm32at_ao_winsn; s->insn_read = dmm32at_ao_rinsn; - s=dev->subdevices+2; + s = dev->subdevices + 2; /* digital i/o subdevice */ - if(thisboard->have_dio){ + if (thisboard->have_dio) { /* get access to the DIO regs */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_DIOACC); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_DIOACC); /* set the DIO's to the defualt input setting */ - devpriv->dio_config = DMM32AT_DIRA|DMM32AT_DIRB| - DMM32AT_DIRCL|DMM32AT_DIRCH|DMM32AT_DIENABLE; - dmm_outb(dev,DMM32AT_DIOCONF,devpriv->dio_config); + devpriv->dio_config = DMM32AT_DIRA | DMM32AT_DIRB | + DMM32AT_DIRCL | DMM32AT_DIRCH | DMM32AT_DIENABLE; + dmm_outb(dev, DMM32AT_DIOCONF, devpriv->dio_config); /* set up the subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=thisboard->dio_chans; - s->maxdata=1; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = thisboard->dio_chans; + s->maxdata = 1; s->state = 0; - s->range_table=&range_digital; + s->range_table = &range_digital; s->insn_bits = dmm32at_dio_insn_bits; s->insn_config = dmm32at_dio_insn_config; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } /* success */ - printk("comedi%d: dmm32at: attached\n",dev->minor); + printk("comedi%d: dmm32at: attached\n", dev->minor); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -494,11 +481,13 @@ static int dmm32at_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int dmm32at_detach(comedi_device *dev) +static int dmm32at_detach(comedi_device * dev) { - printk("comedi%d: dmm32at: remove\n",dev->minor); - if(dev->irq)comedi_free_irq(dev->irq,dev); - if(dev->iobase)release_region(dev->iobase,DMM32AT_MEMSIZE); + printk("comedi%d: dmm32at: remove\n", dev->minor); + if (dev->irq) + comedi_free_irq(dev->irq, dev); + if (dev->iobase) + release_region(dev->iobase, DMM32AT_MEMSIZE); return 0; } @@ -508,10 +497,10 @@ static int dmm32at_detach(comedi_device *dev) * mode. */ - -static int dmm32at_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int dmm32at_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; unsigned int d; unsigned char status; unsigned short msb, lsb; @@ -520,51 +509,49 @@ static int dmm32at_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * /* get the channel and range number */ - chan = CR_CHAN(insn->chanspec)&(s->n_chan-1); + chan = CR_CHAN(insn->chanspec) & (s->n_chan - 1); range = CR_RANGE(insn->chanspec); //printk("channel=0x%02x, range=%d\n",chan,range); - /* zero scan and fifo control and reset fifo*/ - dmm_outb(dev,DMM32AT_FIFOCNTRL,DMM32AT_FIFORESET); + /* zero scan and fifo control and reset fifo */ + dmm_outb(dev, DMM32AT_FIFOCNTRL, DMM32AT_FIFORESET); /* write the ai channel range regs */ - dmm_outb(dev,DMM32AT_AILOW,chan); - dmm_outb(dev,DMM32AT_AIHIGH,chan); + dmm_outb(dev, DMM32AT_AILOW, chan); + dmm_outb(dev, DMM32AT_AIHIGH, chan); /* set the range bits */ - dmm_outb(dev,DMM32AT_AICONF,dmm32at_rangebits[range]); - + dmm_outb(dev, DMM32AT_AICONF, dmm32at_rangebits[range]); /* wait for circuit to settle */ - for(i=0;i<40000;i++){ - status = dmm_inb(dev,DMM32AT_AIRBACK); - if( (status & DMM32AT_STATUS ) == 0) + for (i = 0; i < 40000; i++) { + status = dmm_inb(dev, DMM32AT_AIRBACK); + if ((status & DMM32AT_STATUS) == 0) break; } - if(i==40000){ + if (i == 40000) { printk("timeout\n"); return -ETIMEDOUT; } - /* convert n samples */ - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* trigger conversion */ - dmm_outb(dev,DMM32AT_CONV,0xff); + dmm_outb(dev, DMM32AT_CONV, 0xff); /* wait for conversion to end */ - for(i=0;i<40000;i++){ - status = dmm_inb(dev,DMM32AT_AISTAT); - if( (status & DMM32AT_STATUS ) == 0) + for (i = 0; i < 40000; i++) { + status = dmm_inb(dev, DMM32AT_AISTAT); + if ((status & DMM32AT_STATUS) == 0) break; } - if(i==40000){ + if (i == 40000) { printk("timeout\n"); return -ETIMEDOUT; } /* read data */ - lsb = dmm_inb(dev,DMM32AT_AILSB); - msb = dmm_inb(dev,DMM32AT_AIMSB); + lsb = dmm_inb(dev, DMM32AT_AILSB); + msb = dmm_inb(dev, DMM32AT_AIMSB); /* invert sign bit to make range unsigned, this is an idiosyncracy of the diamond board, it return @@ -572,9 +559,7 @@ static int dmm32at_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * 32767, flipping the bit and interpreting it as signed gives you a range of 0 to 65535 which is used by comedi */ - d = ((msb^0x0080)<<8) + lsb; - - + d = ((msb ^ 0x0080) << 8) + lsb; data[n] = d; } @@ -583,12 +568,12 @@ static int dmm32at_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * return n; } -static int dmm32at_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int dmm32at_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; - int start_chan,gain,i; + int start_chan, gain, i; //printk("dmmat32 in command test\n"); @@ -601,224 +586,230 @@ static int dmm32at_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER /*| TRIG_EXT */ ; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER /*| TRIG_EXT */ ; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; - - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT | TRIG_NONE ; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - if(err)return 1; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; - + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SCAN_SPEED 1000000 /* in nanoseconds */ +#define MAX_SCAN_SPEED 1000000 /* in nanoseconds */ #define MIN_SCAN_SPEED 1000000000 /* in nanoseconds */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SCAN_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SCAN_SPEED) { + cmd->scan_begin_arg = MAX_SCAN_SPEED; err++; } - if(cmd->scan_begin_arg>MIN_SCAN_SPEED){ - cmd->scan_begin_arg=MIN_SCAN_SPEED; + if (cmd->scan_begin_arg > MIN_SCAN_SPEED) { + cmd->scan_begin_arg = MIN_SCAN_SPEED; err++; } - }else{ + } 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; + if (cmd->scan_begin_arg > 9) { + cmd->scan_begin_arg = 9; err++; } } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_arg >= 17500) - cmd->convert_arg=20000; - else if(cmd->convert_arg >= 12500) - cmd->convert_arg=15000; - else if(cmd->convert_arg >= 7500) - cmd->convert_arg=10000; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg >= 17500) + cmd->convert_arg = 20000; + else if (cmd->convert_arg >= 12500) + cmd->convert_arg = 15000; + else if (cmd->convert_arg >= 7500) + cmd->convert_arg = 10000; else - cmd->convert_arg=5000; + cmd->convert_arg = 5000; - }else{ + } else { /* external trigger */ /* see above */ - if(cmd->convert_arg>9){ - cmd->convert_arg=9; + 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; + 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>0xfffffff0){ - cmd->stop_arg=0xfffffff0; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0xfffffff0) { + cmd->stop_arg = 0xfffffff0; err++; } - if(cmd->stop_arg == 0){ - cmd->stop_arg=1; + if (cmd->stop_arg == 0) { + cmd->stop_arg = 1; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; - + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; - dmm32at_ns_to_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + dmm32at_ns_to_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - dmm32at_ns_to_timer(&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg){ - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + dmm32at_ns_to_timer(&cmd->convert_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; - + if (err) + return 4; /* step 5 check the channel list, the channel list for this board must be consecutive and gains must be the same */ - if(cmd->chanlist){ - gain = CR_RANGE(cmd->chanlist[0]); - start_chan = CR_CHAN(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++){ - if(CR_CHAN(cmd->chanlist[i]) != (start_chan + i) % s->n_chan) - { - comedi_error(dev, "entries in chanlist must be consecutive channels, counting upwards\n"); - err++; - } - if(CR_RANGE(cmd->chanlist[i]) != gain) - { - comedi_error(dev, "entries in chanlist must all have the same gain\n"); - err++; - } - } - } - - - if(err)return 5; + if (cmd->chanlist) { + gain = CR_RANGE(cmd->chanlist[0]); + start_chan = CR_CHAN(cmd->chanlist[0]); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != + (start_chan + i) % s->n_chan) { + comedi_error(dev, + "entries in chanlist must be consecutive channels, counting upwards\n"); + err++; + } + if (CR_RANGE(cmd->chanlist[i]) != gain) { + comedi_error(dev, + "entries in chanlist must all have the same gain\n"); + err++; + } + } + } + if (err) + return 5; return 0; } -static int dmm32at_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int dmm32at_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd = &s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; int i, range; - unsigned char chanlo,chanhi,status; + unsigned char chanlo, chanhi, status; - if(!cmd->chanlist) + if (!cmd->chanlist) return -EINVAL; /* get the channel list and range */ - chanlo = CR_CHAN(cmd->chanlist[0])&(s->n_chan-1); + chanlo = CR_CHAN(cmd->chanlist[0]) & (s->n_chan - 1); chanhi = chanlo + cmd->chanlist_len - 1; - if(chanhi >= s->n_chan) + if (chanhi >= s->n_chan) return -EINVAL; range = CR_RANGE(cmd->chanlist[0]); - /* reset fifo*/ - dmm_outb(dev,DMM32AT_FIFOCNTRL,DMM32AT_FIFORESET); + /* reset fifo */ + dmm_outb(dev, DMM32AT_FIFOCNTRL, DMM32AT_FIFORESET); /* set scan enable */ - dmm_outb(dev,DMM32AT_FIFOCNTRL,DMM32AT_SCANENABLE); + dmm_outb(dev, DMM32AT_FIFOCNTRL, DMM32AT_SCANENABLE); /* write the ai channel range regs */ - dmm_outb(dev,DMM32AT_AILOW,chanlo); - dmm_outb(dev,DMM32AT_AIHIGH,chanhi); + dmm_outb(dev, DMM32AT_AILOW, chanlo); + dmm_outb(dev, DMM32AT_AIHIGH, chanhi); /* set the range bits */ - dmm_outb(dev,DMM32AT_AICONF,dmm32at_rangebits[range]); + dmm_outb(dev, DMM32AT_AICONF, dmm32at_rangebits[range]); /* reset the interrupt just in case */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_INTRESET); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_INTRESET); - if(cmd->stop_src==TRIG_COUNT) + if (cmd->stop_src == TRIG_COUNT) devpriv->ai_scans_left = cmd->stop_arg; - else { /* TRIG_NONE */ - devpriv->ai_scans_left = 0xffffffff; /* indicates TRIG_NONE to isr */ + else { /* TRIG_NONE */ + devpriv->ai_scans_left = 0xffffffff; /* indicates TRIG_NONE to isr */ } /* wait for circuit to settle */ - for(i=0;i<40000;i++){ - status = dmm_inb(dev,DMM32AT_AIRBACK); - if( (status & DMM32AT_STATUS ) == 0) + for (i = 0; i < 40000; i++) { + status = dmm_inb(dev, DMM32AT_AIRBACK); + if ((status & DMM32AT_STATUS) == 0) break; } - if(i==40000){ + if (i == 40000) { printk("timeout\n"); return -ETIMEDOUT; } - - - if(devpriv->ai_scans_left > 1){ + if (devpriv->ai_scans_left > 1) { /* start the clock and enable the interrupts */ - dmm32at_setaitimer(dev,cmd->scan_begin_arg); - } - else { + dmm32at_setaitimer(dev, cmd->scan_begin_arg); + } else { /* start the interrups and initiate a single scan */ - dmm_outb(dev,DMM32AT_INTCLOCK,DMM32AT_ADINT); - dmm_outb(dev,DMM32AT_CONV,0xff); + dmm_outb(dev, DMM32AT_INTCLOCK, DMM32AT_ADINT); + dmm_outb(dev, DMM32AT_CONV, 0xff); } - /* printk("dmmat32 in command\n"); */ /* for(i=0;ichanlist_len;i++) */ @@ -831,46 +822,46 @@ static int dmm32at_ai_cmd(comedi_device *dev, comedi_subdevice *s) } - -static int dmm32at_ai_cancel(comedi_device *dev,comedi_subdevice *s){ +static int dmm32at_ai_cancel(comedi_device * dev, comedi_subdevice * s) +{ devpriv->ai_scans_left = 1; return 0; } -static irqreturn_t dmm32at_isr(int irq,void *d PT_REGS_ARG){ +static irqreturn_t dmm32at_isr(int irq, void *d PT_REGS_ARG) +{ unsigned char intstat; unsigned int samp; unsigned short msb, lsb; int i; - comedi_device *dev=d; + comedi_device *dev = d; - if (!dev->attached) - { + if (!dev->attached) { comedi_error(dev, "spurious interrupt"); return IRQ_HANDLED; } - intstat = dmm_inb(dev,DMM32AT_INTCLOCK); + intstat = dmm_inb(dev, DMM32AT_INTCLOCK); - if(intstat & DMM32AT_ADINT){ - comedi_subdevice *s=dev->read_subdev; + if (intstat & DMM32AT_ADINT) { + comedi_subdevice *s = dev->read_subdev; comedi_cmd *cmd = &s->async->cmd; - for(i=0;ichanlist_len;i++){ + for (i = 0; i < cmd->chanlist_len; i++) { /* read data */ - lsb = dmm_inb(dev,DMM32AT_AILSB); - msb = dmm_inb(dev,DMM32AT_AIMSB); + lsb = dmm_inb(dev, DMM32AT_AILSB); + msb = dmm_inb(dev, DMM32AT_AIMSB); /* invert sign bit to make range unsigned */ - samp = ((msb^0x0080)<<8) + lsb; - comedi_buf_put(s->async,samp); + samp = ((msb ^ 0x0080) << 8) + lsb; + comedi_buf_put(s->async, samp); } - if(devpriv->ai_scans_left != 0xffffffff){ /* TRIG_COUNT */ + if (devpriv->ai_scans_left != 0xffffffff) { /* TRIG_COUNT */ devpriv->ai_scans_left--; - if(devpriv->ai_scans_left == 0){ + if (devpriv->ai_scans_left == 0) { /* disable further interrupts and clocks */ - dmm_outb(dev,DMM32AT_INTCLOCK,0x0); + dmm_outb(dev, DMM32AT_INTCLOCK, 0x0); /* set the buffer to be flushed with an EOF */ s->async->events |= COMEDI_CB_EOA; } @@ -881,17 +872,16 @@ static irqreturn_t dmm32at_isr(int irq,void *d PT_REGS_ARG){ } /* reset the interrupt */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_INTRESET); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_INTRESET); return IRQ_HANDLED; } - /* This function doesn't require a particular form, this is just * what happens to be used in some of the drivers. It should * convert ns nanoseconds to a counter value suitable for programming * the device. Also, it should adjust ns so that it cooresponds to * the actual time that the device will use. */ -static int dmm32at_ns_to_timer(unsigned int *ns,int round) +static int dmm32at_ns_to_timer(unsigned int *ns, int round) { /* trivial timer */ /* if your timing is done through two cascaded timers, the @@ -903,40 +893,40 @@ static int dmm32at_ns_to_timer(unsigned int *ns,int round) return *ns; } - -static int dmm32at_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int dmm32at_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); - unsigned char hi,lo,status; + unsigned char hi, lo, status; /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { devpriv->ao_readback[chan] = data[i]; /* get the low byte */ - lo = data[i]&0x00ff; + lo = data[i] & 0x00ff; /* high byte also contains channel number */ - hi = (data[i]>>8) + chan*(1<<6); + hi = (data[i] >> 8) + chan * (1 << 6); //printk("writing 0x%02x 0x%02x\n",hi,lo); /* write the low and high values to the board */ - dmm_outb(dev,DMM32AT_DACLSB,lo); - dmm_outb(dev,DMM32AT_DACMSB,hi); + dmm_outb(dev, DMM32AT_DACLSB, lo); + dmm_outb(dev, DMM32AT_DACMSB, hi); /* wait for circuit to settle */ - for(i=0;i<40000;i++){ - status = dmm_inb(dev,DMM32AT_DACSTAT); - if( (status & DMM32AT_DACBUSY ) == 0) + for (i = 0; i < 40000; i++) { + status = dmm_inb(dev, DMM32AT_DACSTAT); + if ((status & DMM32AT_DACBUSY) == 0) break; } - if(i==40000){ + if (i == 40000) { printk("timeout\n"); return -ETIMEDOUT; } /* dummy read to update trigger the output */ - status = dmm_inb(dev,DMM32AT_DACMSB); + status = dmm_inb(dev, DMM32AT_DACMSB); } @@ -946,12 +936,13 @@ static int dmm32at_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * /* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */ -static int dmm32at_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int dmm32at_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -962,52 +953,48 @@ static int dmm32at_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * * 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 dmm32at_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dmm32at_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned char diobits; - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; /* Write out the new digital output lines */ //outw(s->state,dev->iobase + DMM32AT_DIO); } /* get access to the DIO regs */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_DIOACC); - - - + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_DIOACC); /* if either part of dio is set for output */ - if( ((devpriv->dio_config&DMM32AT_DIRCL) == 0) || - ((devpriv->dio_config&DMM32AT_DIRCH) == 0) ){ - diobits = (s->state&0x00ff0000)>>16; - dmm_outb(dev,DMM32AT_DIOC,diobits); + if (((devpriv->dio_config & DMM32AT_DIRCL) == 0) || + ((devpriv->dio_config & DMM32AT_DIRCH) == 0)) { + diobits = (s->state & 0x00ff0000) >> 16; + dmm_outb(dev, DMM32AT_DIOC, diobits); } - if((devpriv->dio_config&DMM32AT_DIRB) == 0){ - diobits = (s->state&0x0000ff00)>>8; - dmm_outb(dev,DMM32AT_DIOB,diobits); + if ((devpriv->dio_config & DMM32AT_DIRB) == 0) { + diobits = (s->state & 0x0000ff00) >> 8; + dmm_outb(dev, DMM32AT_DIOB, diobits); } - if((devpriv->dio_config&DMM32AT_DIRA) == 0){ - diobits = (s->state&0x000000ff); - dmm_outb(dev,DMM32AT_DIOA,diobits); + if ((devpriv->dio_config & DMM32AT_DIRA) == 0) { + diobits = (s->state & 0x000000ff); + dmm_outb(dev, DMM32AT_DIOA, diobits); } /* now read the state back in */ - s->state = dmm_inb(dev,DMM32AT_DIOC); + s->state = dmm_inb(dev, DMM32AT_DIOC); s->state <<= 8; - s->state |= dmm_inb(dev,DMM32AT_DIOB); + s->state |= dmm_inb(dev, DMM32AT_DIOB); s->state <<= 8; - s->state |= dmm_inb(dev,DMM32AT_DIOA); - data[1]=s->state; - - + s->state |= dmm_inb(dev, DMM32AT_DIOA); + data[1] = s->state; /* on return, data[1] contains the value of the digital * input and output lines. */ @@ -1019,79 +1006,76 @@ static int dmm32at_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int dmm32at_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dmm32at_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned char chanbit; - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); - if(insn->n!=1)return -EINVAL; + if (insn->n != 1) + return -EINVAL; - if(chan < 8) + if (chan < 8) chanbit = DMM32AT_DIRA; - else if(chan < 16) + else if (chan < 16) chanbit = DMM32AT_DIRB; - else if(chan < 20) + else if (chan < 20) chanbit = DMM32AT_DIRCL; else chanbit = DMM32AT_DIRCH; - /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ /* if output clear the bit, otherwise set it */ - if(data[0]==COMEDI_OUTPUT){ + if (data[0] == COMEDI_OUTPUT) { devpriv->dio_config &= ~chanbit; - }else{ + } else { devpriv->dio_config |= chanbit; } /* get access to the DIO regs */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_DIOACC); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_DIOACC); /* set the DIO's to the new configuration setting */ - dmm_outb(dev,DMM32AT_DIOCONF,devpriv->dio_config); + dmm_outb(dev, DMM32AT_DIOCONF, devpriv->dio_config); return 1; } -void dmm32at_setaitimer(comedi_device *dev,unsigned int nansec){ +void dmm32at_setaitimer(comedi_device * dev, unsigned int nansec) +{ unsigned char lo1, lo2, hi2; unsigned short both2; /* based on 10mhz clock */ - lo1=200; - both2 = nansec/20000; - hi2 = (both2&0xff00)>>8; - lo2 = both2&0x00ff; - - /* set the counter frequency to 10mhz*/ - dmm_outb(dev,DMM32AT_CNTRDIO,0); + lo1 = 200; + both2 = nansec / 20000; + hi2 = (both2 & 0xff00) >> 8; + lo2 = both2 & 0x00ff; + /* set the counter frequency to 10mhz */ + dmm_outb(dev, DMM32AT_CNTRDIO, 0); /* get access to the clock regs */ - dmm_outb(dev,DMM32AT_CNTRL,DMM32AT_CLKACC); + dmm_outb(dev, DMM32AT_CNTRL, DMM32AT_CLKACC); - /* write the counter 1 control word and low byte to counter*/ - dmm_outb(dev,DMM32AT_CLKCT,DMM32AT_CLKCT1); - dmm_outb(dev,DMM32AT_CLK1,lo1); + /* write the counter 1 control word and low byte to counter */ + dmm_outb(dev, DMM32AT_CLKCT, DMM32AT_CLKCT1); + dmm_outb(dev, DMM32AT_CLK1, lo1); - /* write the counter 2 control word and low byte then to counter*/ - dmm_outb(dev,DMM32AT_CLKCT,DMM32AT_CLKCT2); - dmm_outb(dev,DMM32AT_CLK2,lo2); - dmm_outb(dev,DMM32AT_CLK2,hi2); + /* write the counter 2 control word and low byte then to counter */ + dmm_outb(dev, DMM32AT_CLKCT, DMM32AT_CLKCT2); + dmm_outb(dev, DMM32AT_CLK2, lo2); + dmm_outb(dev, DMM32AT_CLK2, hi2); /* enable the ai conversion interrupt and the clock to start scans */ - dmm_outb(dev,DMM32AT_INTCLOCK,DMM32AT_ADINT|DMM32AT_CLKSEL); - + dmm_outb(dev, DMM32AT_INTCLOCK, DMM32AT_ADINT | DMM32AT_CLKSEL); } - /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. */ COMEDI_INITCLEANUP(driver_dmm32at); - diff --git a/comedi/drivers/dt2801.c b/comedi/drivers/dt2801.c index d517e990..15a53eb4 100644 --- a/comedi/drivers/dt2801.c +++ b/comedi/drivers/dt2801.c @@ -33,10 +33,8 @@ Configuration options: #include #include - #define DT2801_TIMEOUT 1000 - /* Hardware Configuration */ /* ====================== */ @@ -45,7 +43,6 @@ Configuration options: /* Ports */ #define DT2801_IOSIZE 2 - /* define's & typedef's */ /* ====================== */ @@ -86,54 +83,59 @@ Configuration options: #define DT_S_COMMAND (1<<3) #define DT_S_COMPOSITE_ERROR (1<<7) - /* registers */ #define DT2801_DATA 0 #define DT2801_STATUS 1 #define DT2801_CMD 1 -static int dt2801_attach(comedi_device *dev,comedi_devconfig *it); -static int dt2801_detach(comedi_device *dev); -static comedi_driver driver_dt2801={ - driver_name: "dt2801", - module: THIS_MODULE, - attach: dt2801_attach, - detach: dt2801_detach, +static int dt2801_attach(comedi_device * dev, comedi_devconfig * it); +static int dt2801_detach(comedi_device * dev); +static comedi_driver driver_dt2801 = { + driver_name:"dt2801", + module:THIS_MODULE, + attach:dt2801_attach, + detach:dt2801_detach, }; + COMEDI_INITCLEANUP(driver_dt2801); #if 0 // ignore 'defined but not used' warning -static const comedi_lrange range_dt2801_ai_pgh_bipolar={ 4, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ), -}}; +static const comedi_lrange range_dt2801_ai_pgh_bipolar = { 4, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + } +}; #endif -static const comedi_lrange range_dt2801_ai_pgl_bipolar={ 4, { - RANGE( -10, 10 ), - RANGE( -1, 1 ), - RANGE( -0.1, 0.1 ), - RANGE( -0.02, 0.02 ), -}}; +static const comedi_lrange range_dt2801_ai_pgl_bipolar = { 4, { + RANGE(-10, 10), + RANGE(-1, 1), + RANGE(-0.1, 0.1), + RANGE(-0.02, 0.02), + } +}; + #if 0 // ignore 'defined but not used' warning -static const comedi_lrange range_dt2801_ai_pgh_unipolar={ 4, { - RANGE( 0, 10 ), - RANGE( 0, 5 ), - RANGE( 0, 2.5 ), - RANGE( 0, 1.25 ), -}}; +static const comedi_lrange range_dt2801_ai_pgh_unipolar = { 4, { + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25), + } +}; #endif -static const comedi_lrange range_dt2801_ai_pgl_unipolar={ 4, { - RANGE( 0, 10 ), - RANGE( 0, 1 ), - RANGE( 0, 0.1 ), - RANGE( 0, 0.02 ), -}}; - -typedef struct{ +static const comedi_lrange range_dt2801_ai_pgl_unipolar = { 4, { + RANGE(0, 10), + RANGE(0, 1), + RANGE(0, 0.1), + RANGE(0, 0.02), + } +}; + +typedef struct { const char *name; int boardcode; int ad_diff; @@ -146,101 +148,92 @@ typedef struct{ /* Typeid's for the different boards of the DT2801-series (taken from the test-software, that comes with the board) */ -static const boardtype_t boardtypes[] = -{ +static const boardtype_t boardtypes[] = { { - name: "dt2801", - boardcode: 0x09, - ad_diff: 2, - ad_chan: 16, - adbits: 12, - adrangetype: 0, - dabits: 12 - }, + name: "dt2801", + boardcode:0x09, + ad_diff: 2, + ad_chan: 16, + adbits: 12, + adrangetype:0, + dabits: 12}, { - name: "dt2801-a", - boardcode: 0x52, - ad_diff: 2, - ad_chan: 16, - adbits: 12, - adrangetype: 0, - dabits: 12 - }, + name: "dt2801-a", + boardcode:0x52, + ad_diff: 2, + ad_chan: 16, + adbits: 12, + adrangetype:0, + dabits: 12}, { - name: "dt2801/5716a", - boardcode: 0x82, - ad_diff: 1, - ad_chan: 16, - adbits: 16, - adrangetype: 1, - dabits: 12 - }, + name: "dt2801/5716a", + boardcode:0x82, + ad_diff: 1, + ad_chan: 16, + adbits: 16, + adrangetype:1, + dabits: 12}, { - name: "dt2805", - boardcode: 0x12, - ad_diff: 1, - ad_chan: 16, - adbits: 12, - adrangetype: 0, - dabits: 12 - }, + name: "dt2805", + boardcode:0x12, + ad_diff: 1, + ad_chan: 16, + adbits: 12, + adrangetype:0, + dabits: 12}, { - name: "dt2805/5716a", - boardcode: 0x92, - ad_diff: 1, - ad_chan: 16, - adbits: 16, - adrangetype: 1, - dabits: 12 - }, + name: "dt2805/5716a", + boardcode:0x92, + ad_diff: 1, + ad_chan: 16, + adbits: 16, + adrangetype:1, + dabits: 12}, { - name: "dt2808", - boardcode: 0x20, - ad_diff: 0, - ad_chan: 16, - adbits: 12, - adrangetype: 2, - dabits: 8 - }, + name: "dt2808", + boardcode:0x20, + ad_diff: 0, + ad_chan: 16, + adbits: 12, + adrangetype:2, + dabits: 8}, { - name: "dt2818", - boardcode: 0xa2, - ad_diff: 0, - ad_chan: 4, - adbits: 12, - adrangetype: 0, - dabits: 12 - }, + name: "dt2818", + boardcode:0xa2, + ad_diff: 0, + ad_chan: 4, + adbits: 12, + adrangetype:0, + dabits: 12}, { - name: "dt2809", - boardcode: 0xb0, - ad_diff: 0, - ad_chan: 8, - adbits: 12, - adrangetype: 1, - dabits: 12 - }, + name: "dt2809", + boardcode:0xb0, + ad_diff: 0, + ad_chan: 8, + adbits: 12, + adrangetype:1, + dabits: 12}, }; + #define n_boardtypes ((sizeof(boardtypes))/(sizeof(boardtypes[0]))) #define boardtype (*(const boardtype_t *)dev->board_ptr) - -typedef struct{ +typedef struct { const comedi_lrange *dac_range_types[2]; lsampl_t ao_readback[2]; -}dt2801_private; +} dt2801_private; #define devpriv ((dt2801_private *)dev->private) -static int dt2801_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2801_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2801_ao_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2801_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2801_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int dt2801_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2801_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2801_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2801_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2801_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* These are the low-level routines: writecommand: write a command to the board @@ -251,97 +244,100 @@ static int dt2801_dio_insn_config(comedi_device *dev,comedi_subdevice *s, /* Only checks DataOutReady-flag, not the Ready-flag as it is done in the examples of the manual. I don't see why this should be necessary. */ -static int dt2801_readdata(comedi_device *dev, int* data) +static int dt2801_readdata(comedi_device * dev, int *data) { int stat = 0; int timeout = DT2801_TIMEOUT; - do{ - stat = inb_p(dev->iobase+DT2801_STATUS); + do { + stat = inb_p(dev->iobase + DT2801_STATUS); if (stat & (DT_S_COMPOSITE_ERROR | DT_S_READY)) { return stat; } - if(stat & DT_S_DATA_OUT_READY){ - *data = inb_p(dev->iobase+DT2801_DATA); + if (stat & DT_S_DATA_OUT_READY) { + *data = inb_p(dev->iobase + DT2801_DATA); return 0; } - }while(--timeout>0); + } while (--timeout > 0); return -ETIME; } - -static int dt2801_readdata2(comedi_device *dev, int *data) +static int dt2801_readdata2(comedi_device * dev, int *data) { int lb, hb; int ret; - ret=dt2801_readdata(dev, &lb); - if(ret)return ret; - ret=dt2801_readdata(dev, &hb); - if(ret)return ret; + ret = dt2801_readdata(dev, &lb); + if (ret) + return ret; + ret = dt2801_readdata(dev, &hb); + if (ret) + return ret; - *data = (hb<<8)+lb; + *data = (hb << 8) + lb; return 0; } -static int dt2801_writedata(comedi_device *dev, unsigned int data) +static int dt2801_writedata(comedi_device * dev, unsigned int data) { int stat = 0; int timeout = DT2801_TIMEOUT; - do{ - stat = inb_p(dev->iobase+DT2801_STATUS); + do { + stat = inb_p(dev->iobase + DT2801_STATUS); if (stat & DT_S_COMPOSITE_ERROR) { - return stat; + return stat; } if (!(stat & DT_S_DATA_IN_FULL)) { - outb_p(data & 0xff, dev->iobase+DT2801_DATA); + outb_p(data & 0xff, dev->iobase + DT2801_DATA); return 0; } #if 0 - if(stat & DT_S_READY){ + if (stat & DT_S_READY) { printk("dt2801: ready flag set (bad!) in dt2801_writedata()\n"); return -EIO; } #endif - }while(--timeout>0); + } while (--timeout > 0); return -ETIME; } -static int dt2801_writedata2(comedi_device *dev, unsigned int data) +static int dt2801_writedata2(comedi_device * dev, unsigned int data) { int ret; - ret=dt2801_writedata(dev, data & 0xff); - if(ret<0)return ret; - ret=dt2801_writedata(dev, (data >> 8) ); - if(ret<0)return ret; + ret = dt2801_writedata(dev, data & 0xff); + if (ret < 0) + return ret; + ret = dt2801_writedata(dev, (data >> 8)); + if (ret < 0) + return ret; return 0; } -static int dt2801_wait_for_ready(comedi_device *dev) +static int dt2801_wait_for_ready(comedi_device * dev) { int timeout = DT2801_TIMEOUT; int stat; - stat = inb_p(dev->iobase+DT2801_STATUS); - if(stat & DT_S_READY){ + stat = inb_p(dev->iobase + DT2801_STATUS); + if (stat & DT_S_READY) { return 0; } - do{ - stat = inb_p(dev->iobase+DT2801_STATUS); + do { + stat = inb_p(dev->iobase + DT2801_STATUS); if (stat & DT_S_COMPOSITE_ERROR) { - return stat; + return stat; } - if(stat & DT_S_READY){ + if (stat & DT_S_READY) { return 0; } - }while(--timeout>0); + } while (--timeout > 0); return -ETIME; } @@ -352,87 +348,89 @@ static int dt2801_writecmd(comedi_device * dev, int command) dt2801_wait_for_ready(dev); - stat = inb_p(dev->iobase+DT2801_STATUS); + stat = inb_p(dev->iobase + DT2801_STATUS); if (stat & DT_S_COMPOSITE_ERROR) { - printk("dt2801: composite-error in dt2801_writecmd(), ignoring\n"); + printk("dt2801: composite-error in dt2801_writecmd(), ignoring\n"); } if (!(stat & DT_S_READY)) { - printk("dt2801: !ready in dt2801_writecmd(), ignoring\n"); + printk("dt2801: !ready in dt2801_writecmd(), ignoring\n"); } - outb_p(command, dev->iobase+DT2801_CMD); + outb_p(command, dev->iobase + DT2801_CMD); return 0; } - -static int dt2801_reset(comedi_device *dev) +static int dt2801_reset(comedi_device * dev) { - int board_code=0; + int board_code = 0; unsigned int stat; int timeout; DPRINTK("dt2801: resetting board...\n"); - DPRINTK("fingerprint: 0x%02x 0x%02x\n",inb_p(dev->iobase),inb_p(dev->iobase+1)); + DPRINTK("fingerprint: 0x%02x 0x%02x\n", inb_p(dev->iobase), + inb_p(dev->iobase + 1)); /* pull random data from data port */ - inb_p(dev->iobase+DT2801_DATA); - inb_p(dev->iobase+DT2801_DATA); - inb_p(dev->iobase+DT2801_DATA); - inb_p(dev->iobase+DT2801_DATA); + inb_p(dev->iobase + DT2801_DATA); + inb_p(dev->iobase + DT2801_DATA); + inb_p(dev->iobase + DT2801_DATA); + inb_p(dev->iobase + DT2801_DATA); DPRINTK("dt2801: stop\n"); //dt2801_writecmd(dev,DT_C_STOP); - outb_p(DT_C_STOP, dev->iobase+DT2801_CMD); + outb_p(DT_C_STOP, dev->iobase + DT2801_CMD); //dt2801_wait_for_ready(dev); comedi_udelay(100); - timeout=10000; - do{ - stat = inb_p(dev->iobase+DT2801_STATUS); - if(stat & DT_S_READY)break; - }while(timeout--); - if(!timeout){ - printk("dt2801: timeout 1 status=0x%02x\n",stat); + timeout = 10000; + do { + stat = inb_p(dev->iobase + DT2801_STATUS); + if (stat & DT_S_READY) + break; + } while (timeout--); + if (!timeout) { + printk("dt2801: timeout 1 status=0x%02x\n", stat); } - //printk("dt2801: reading dummy\n"); //dt2801_readdata(dev,&board_code); DPRINTK("dt2801: reset\n"); - outb_p(DT_C_RESET, dev->iobase+DT2801_CMD); + outb_p(DT_C_RESET, dev->iobase + DT2801_CMD); //dt2801_writecmd(dev,DT_C_RESET); comedi_udelay(100); - timeout=10000; - do{ - stat = inb_p(dev->iobase+DT2801_STATUS); - if(stat & DT_S_READY)break; - }while(timeout--); - if(!timeout){ - printk("dt2801: timeout 2 status=0x%02x\n",stat); + timeout = 10000; + do { + stat = inb_p(dev->iobase + DT2801_STATUS); + if (stat & DT_S_READY) + break; + } while (timeout--); + if (!timeout) { + printk("dt2801: timeout 2 status=0x%02x\n", stat); } DPRINTK("dt2801: reading code\n"); - dt2801_readdata(dev,&board_code); + dt2801_readdata(dev, &board_code); - DPRINTK("dt2801: ok. code=0x%02x\n",board_code); + DPRINTK("dt2801: ok. code=0x%02x\n", board_code); return board_code; } -static int probe_number_of_ai_chans(comedi_device *dev) +static int probe_number_of_ai_chans(comedi_device * dev) { int n_chans; int stat; int data; - for(n_chans=0;n_chans<16;n_chans++){ - stat = dt2801_writecmd(dev, DT_C_READ_ADIM); - dt2801_writedata(dev, 0); - dt2801_writedata(dev, n_chans); - stat = dt2801_readdata2(dev, &data); + for (n_chans = 0; n_chans < 16; n_chans++) { + stat = dt2801_writecmd(dev, DT_C_READ_ADIM); + dt2801_writedata(dev, 0); + dt2801_writedata(dev, n_chans); + stat = dt2801_readdata2(dev, &data); - if(stat)break; + if (stat) + break; } dt2801_reset(dev); @@ -441,8 +439,7 @@ static int probe_number_of_ai_chans(comedi_device *dev) return n_chans; } - -static const comedi_lrange *dac_range_table[]={ +static const comedi_lrange *dac_range_table[] = { &range_bipolar10, &range_bipolar5, &range_bipolar2_5, @@ -452,29 +449,26 @@ static const comedi_lrange *dac_range_table[]={ static const comedi_lrange *dac_range_lkup(int opt) { - if(opt<0 || opt>5)return &range_unknown; + if (opt < 0 || opt > 5) + return &range_unknown; return dac_range_table[opt]; } -static const comedi_lrange *ai_range_lkup(int type,int opt) +static const comedi_lrange *ai_range_lkup(int type, int opt) { - switch(type){ + switch (type) { case 0: - return (opt)? - &range_dt2801_ai_pgl_unipolar: + return (opt) ? + &range_dt2801_ai_pgl_unipolar : &range_dt2801_ai_pgl_bipolar; case 1: - return (opt)? - &range_unipolar10: - &range_bipolar10; + return (opt) ? &range_unipolar10 : &range_bipolar10; case 2: return &range_unipolar5; } return &range_unknown; } - - /* options: [0] - i/o base @@ -484,122 +478,126 @@ static const comedi_lrange *ai_range_lkup(int type,int opt) [4] - dac0 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5] [5] - dac1 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5] */ -static int dt2801_attach(comedi_device *dev,comedi_devconfig *it) +static int dt2801_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; - int board_code,type; - int ret=0; + int board_code, type; + int ret = 0; int n_ai_chans; - iobase=it->options[0]; - if(!request_region(iobase, DT2801_IOSIZE, "dt2801")){ - comedi_error(dev,"I/O port conflict"); + iobase = it->options[0]; + if (!request_region(iobase, DT2801_IOSIZE, "dt2801")) { + comedi_error(dev, "I/O port conflict"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; /* do some checking */ - board_code=dt2801_reset(dev); + board_code = dt2801_reset(dev); /* heh. if it didn't work, try it again. */ - if(!board_code)board_code=dt2801_reset(dev); + if (!board_code) + board_code = dt2801_reset(dev); - for(type=0;typeboard_ptr = boardtypes+type; - printk("dt2801: %s at port 0x%lx",boardtype.name,iobase); + havetype: + dev->board_ptr = boardtypes + type; + printk("dt2801: %s at port 0x%lx", boardtype.name, iobase); - n_ai_chans=probe_number_of_ai_chans(dev); - printk(" (ai channels = %d)",n_ai_chans); + n_ai_chans = probe_number_of_ai_chans(dev); + printk(" (ai channels = %d)", n_ai_chans); - if((ret=alloc_subdevices(dev, 4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) goto out; - if((ret=alloc_private(dev,sizeof(dt2801_private)))<0) + if ((ret = alloc_private(dev, sizeof(dt2801_private))) < 0) goto out; dev->board_name = boardtype.name; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* ai subdevice */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; #if 1 - s->n_chan=n_ai_chans; + s->n_chan = n_ai_chans; #else - if(it->options[2])s->n_chan=boardtype.ad_chan; - else s->n_chan=boardtype.ad_chan/2; + if (it->options[2]) + s->n_chan = boardtype.ad_chan; + else + s->n_chan = boardtype.ad_chan / 2; #endif - s->maxdata=(1<range_table=ai_range_lkup(boardtype.adrangetype,it->options[3]); - s->insn_read=dt2801_ai_insn_read; + s->maxdata = (1 << boardtype.adbits) - 1; + s->range_table = ai_range_lkup(boardtype.adrangetype, it->options[3]); + s->insn_read = dt2801_ai_insn_read; s++; /* ao subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=2; - s->maxdata=(1<range_table_list=devpriv->dac_range_types; - devpriv->dac_range_types[0]=dac_range_lkup(it->options[4]); - devpriv->dac_range_types[1]=dac_range_lkup(it->options[5]); - s->insn_read=dt2801_ao_insn_read; - s->insn_write=dt2801_ao_insn_write; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->maxdata = (1 << boardtype.dabits) - 1; + s->range_table_list = devpriv->dac_range_types; + devpriv->dac_range_types[0] = dac_range_lkup(it->options[4]); + devpriv->dac_range_types[1] = dac_range_lkup(it->options[5]); + s->insn_read = dt2801_ao_insn_read; + s->insn_write = dt2801_ao_insn_write; s++; /* 1st digital subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; - s->insn_bits=dt2801_dio_insn_bits; - s->insn_config=dt2801_dio_insn_config; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = dt2801_dio_insn_bits; + s->insn_config = dt2801_dio_insn_config; s++; /* 2nd digital subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; - s->insn_bits=dt2801_dio_insn_bits; - s->insn_config=dt2801_dio_insn_config; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = dt2801_dio_insn_bits; + s->insn_config = dt2801_dio_insn_config; ret = 0; -out: + out: printk("\n"); return ret; } -static int dt2801_detach(comedi_device *dev) +static int dt2801_detach(comedi_device * dev) { - if(dev->iobase) - release_region(dev->iobase,DT2801_IOSIZE); + if (dev->iobase) + release_region(dev->iobase, DT2801_IOSIZE); return 0; } -static int dt2801_error(comedi_device *dev,int stat) +static int dt2801_error(comedi_device * dev, int stat) { - if(stat<0){ - if(stat==-ETIME){ + if (stat < 0) { + if (stat == -ETIME) { printk("dt2801: timeout\n"); - }else{ - printk("dt2801: error %d\n",stat); + } else { + printk("dt2801: error %d\n", stat); } return stat; } - printk("dt2801: error status 0x%02x, resetting...\n",stat); + printk("dt2801: error status 0x%02x, resetting...\n", stat); dt2801_reset(dev); dt2801_reset(dev); @@ -607,86 +605,89 @@ static int dt2801_error(comedi_device *dev,int stat) return -EIO; } -static int dt2801_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2801_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int d; - int stat; + int d; + int stat; int i; - for(i=0;in;i++){ - stat = dt2801_writecmd(dev, DT_C_READ_ADIM); - dt2801_writedata(dev, CR_RANGE(insn->chanspec)); - dt2801_writedata(dev, CR_CHAN(insn->chanspec)); - stat = dt2801_readdata2(dev, &d); + for (i = 0; i < insn->n; i++) { + stat = dt2801_writecmd(dev, DT_C_READ_ADIM); + dt2801_writedata(dev, CR_RANGE(insn->chanspec)); + dt2801_writedata(dev, CR_CHAN(insn->chanspec)); + stat = dt2801_readdata2(dev, &d); - if (stat != 0) return dt2801_error(dev,stat); + if (stat != 0) + return dt2801_error(dev, stat); - data[i]=d; + data[i] = d; } return i; } -static int dt2801_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2801_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[0]=devpriv->ao_readback[CR_CHAN(insn->chanspec)]; + data[0] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; return 1; } -static int dt2801_ao_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2801_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { dt2801_writecmd(dev, DT_C_WRITE_DAIM); dt2801_writedata(dev, CR_CHAN(insn->chanspec)); dt2801_writedata2(dev, data[0]); - devpriv->ao_readback[CR_CHAN(insn->chanspec)]=data[0]; + devpriv->ao_readback[CR_CHAN(insn->chanspec)] = data[0]; return 1; } -static int dt2801_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2801_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int which=0; + int which = 0; - if(s==dev->subdevices+4)which=1; + if (s == dev->subdevices + 4) + which = 1; - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); dt2801_writecmd(dev, DT_C_WRITE_DIG); dt2801_writedata(dev, which); dt2801_writedata(dev, s->state); } dt2801_writecmd(dev, DT_C_READ_DIG); dt2801_writedata(dev, which); - dt2801_readdata(dev, data+1); + dt2801_readdata(dev, data + 1); return 2; } -static int dt2801_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2801_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int which=0; + int which = 0; - if(s==dev->subdevices+4)which=1; + if (s == dev->subdevices + 4) + which = 1; /* configure */ - if(data[0]){ - s->io_bits=0xff; + if (data[0]) { + s->io_bits = 0xff; dt2801_writecmd(dev, DT_C_SET_DIGOUT); - }else{ - s->io_bits=0; + } else { + s->io_bits = 0; dt2801_writecmd(dev, DT_C_SET_DIGIN); } dt2801_writedata(dev, which); return 1; } - diff --git a/comedi/drivers/dt2811.c b/comedi/drivers/dt2811.c index 90510350..c914b24d 100644 --- a/comedi/drivers/dt2811.c +++ b/comedi/drivers/dt2811.c @@ -52,41 +52,47 @@ Configuration options: static const char *driver_name = "dt2811"; static const comedi_lrange range_dt2811_pgh_ai_5_unipolar = { 4, { - RANGE( 0, 5 ), - RANGE( 0, 2.5 ), - RANGE( 0, 1.25 ), - RANGE( 0, 0.625 ) -}}; + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25), + RANGE(0, 0.625) + } +}; static const comedi_lrange range_dt2811_pgh_ai_2_5_bipolar = { 4, { - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ), - RANGE( -0.625, 0.625 ), - RANGE( -0.3125, 0.3125 ) -}}; + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + RANGE(-0.625, 0.625), + RANGE(-0.3125, 0.3125) + } +}; static const comedi_lrange range_dt2811_pgh_ai_5_bipolar = { 4, { - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ), - RANGE( -0.625, 0.625 ) -}}; + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + RANGE(-0.625, 0.625) + } +}; static const comedi_lrange range_dt2811_pgl_ai_5_unipolar = { 4, { - RANGE( 0, 5 ), - RANGE( 0, 0.5 ), - RANGE( 0, 0.05 ), - RANGE( 0, 0.01 ) -}}; + RANGE(0, 5), + RANGE(0, 0.5), + RANGE(0, 0.05), + RANGE(0, 0.01) + } +}; static const comedi_lrange range_dt2811_pgl_ai_2_5_bipolar = { 4, { - RANGE( -2.5, 2.5 ), - RANGE( -0.25, 0.25 ), - RANGE( -0.025, 0.025 ), - RANGE( -0.005, 0.005 ) -}}; + RANGE(-2.5, 2.5), + RANGE(-0.25, 0.25), + RANGE(-0.025, 0.025), + RANGE(-0.005, 0.005) + } +}; static const comedi_lrange range_dt2811_pgl_ai_5_bipolar = { 4, { - RANGE( -5, 5 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.05, 0.05 ), - RANGE( -0.01, 0.01 ) -}}; + RANGE(-5, 5), + RANGE(-0.5, 0.5), + RANGE(-0.05, 0.05), + RANGE(-0.01, 0.01) + } +}; /* @@ -190,66 +196,67 @@ typedef struct { const comedi_lrange *bip_5; const comedi_lrange *bip_2_5; const comedi_lrange *unip_5; -}boardtype; -static const boardtype boardtypes[]={ - { "dt2811-pgh", - &range_dt2811_pgh_ai_5_bipolar, - &range_dt2811_pgh_ai_2_5_bipolar, - &range_dt2811_pgh_ai_5_unipolar, - }, - { "dt2811-pgl", - &range_dt2811_pgl_ai_5_bipolar, - &range_dt2811_pgl_ai_2_5_bipolar, - &range_dt2811_pgl_ai_5_unipolar, - }, +} boardtype; +static const boardtype boardtypes[] = { + {"dt2811-pgh", + &range_dt2811_pgh_ai_5_bipolar, + &range_dt2811_pgh_ai_2_5_bipolar, + &range_dt2811_pgh_ai_5_unipolar, + }, + {"dt2811-pgl", + &range_dt2811_pgl_ai_5_bipolar, + &range_dt2811_pgl_ai_2_5_bipolar, + &range_dt2811_pgl_ai_5_unipolar, + }, }; + #define this_board ((const boardtype *)dev->board_ptr) -static int dt2811_attach(comedi_device *dev,comedi_devconfig *it); -static int dt2811_detach(comedi_device *dev); -static comedi_driver driver_dt2811={ - driver_name: "dt2811", - module: THIS_MODULE, - attach: dt2811_attach, - detach: dt2811_detach, - board_name: &boardtypes[0].name, - num_names: sizeof(boardtypes)/sizeof(boardtype), - offset: sizeof(boardtype), +static int dt2811_attach(comedi_device * dev, comedi_devconfig * it); +static int dt2811_detach(comedi_device * dev); +static comedi_driver driver_dt2811 = { + driver_name:"dt2811", + module:THIS_MODULE, + attach:dt2811_attach, + detach:dt2811_detach, + board_name:&boardtypes[0].name, + num_names:sizeof(boardtypes) / sizeof(boardtype), + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_dt2811); -static int dt2811_ai_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2811_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2811_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2811_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int dt2811_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int dt2811_ai_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2811_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2811_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2811_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int dt2811_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); enum { card_2811_pgh, card_2811_pgl }; typedef struct { int ntrig; int curadchan; - enum { - adc_singleended, adc_diff, adc_pseudo_diff - } adc_mux; - enum { - dac_bipolar_5, dac_bipolar_2_5, dac_unipolar_5 + enum { + adc_singleended, adc_diff, adc_pseudo_diff + } adc_mux; + enum { + dac_bipolar_5, dac_bipolar_2_5, dac_unipolar_5 } dac_range[2]; - const comedi_lrange * range_type_list[2]; + const comedi_lrange *range_type_list[2]; lsampl_t ao_readback[2]; } dt2811_private; #define devpriv ((dt2811_private *)dev->private) -static const comedi_lrange *dac_range_types[] = -{ - &range_bipolar5, - &range_bipolar2_5, - &range_unipolar5 +static const comedi_lrange *dac_range_types[] = { + &range_bipolar5, + &range_bipolar2_5, + &range_unipolar5 }; #define DT2811_TIMEOUT 5 @@ -261,8 +268,7 @@ static irqreturn_t dt2811_interrupt(int irq, void *d PT_REGS_ARG) int data; comedi_device *dev = d; - if (!dev->attached) - { + if (!dev->attached) { comedi_error(dev, "spurious interrupt"); return IRQ_HANDLED; } @@ -337,7 +343,8 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) sti(); irqs = probe_irq_on(); - outb(DT2811_CLRERROR | DT2811_INTENB, dev->iobase + DT2811_ADCSR); + outb(DT2811_CLRERROR | DT2811_INTENB, + dev->iobase + DT2811_ADCSR); outb(0, dev->iobase + DT2811_ADGCR); comedi_udelay(100); @@ -355,8 +362,10 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) i = inb(dev->iobase + DT2811_ADDATLO); i = inb(dev->iobase + DT2811_ADDATHI); printk("(irq = %d)\n", irq); - ret = comedi_request_irq(irq, dt2811_interrupt, 0, driver_name, dev); - if(ret<0)return -EIO; + ret = comedi_request_irq(irq, dt2811_interrupt, 0, + driver_name, dev); + if (ret < 0) + return -EIO; dev->irq = irq; } else if (irq == 0) { printk("(no irq)\n"); @@ -371,42 +380,66 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) if ((ret = alloc_private(dev, sizeof(dt2811_private))) < 0) return ret; switch (it->options[2]) { - case 0: devpriv->adc_mux = adc_singleended; break; - case 1: devpriv->adc_mux = adc_diff; break; - case 2: devpriv->adc_mux = adc_pseudo_diff; break; - default:devpriv->adc_mux = adc_singleended; break; + case 0: + devpriv->adc_mux = adc_singleended; + break; + case 1: + devpriv->adc_mux = adc_diff; + break; + case 2: + devpriv->adc_mux = adc_pseudo_diff; + break; + default: + devpriv->adc_mux = adc_singleended; + break; } switch (it->options[4]) { - case 0: devpriv->dac_range[0] = dac_bipolar_5; break; - case 1: devpriv->dac_range[0] = dac_bipolar_2_5; break; - case 2: devpriv->dac_range[0] = dac_unipolar_5; break; - default:devpriv->dac_range[0] = dac_bipolar_5; break; + case 0: + devpriv->dac_range[0] = dac_bipolar_5; + break; + case 1: + devpriv->dac_range[0] = dac_bipolar_2_5; + break; + case 2: + devpriv->dac_range[0] = dac_unipolar_5; + break; + default: + devpriv->dac_range[0] = dac_bipolar_5; + break; } switch (it->options[5]) { - case 0: devpriv->dac_range[1] = dac_bipolar_5; break; - case 1: devpriv->dac_range[1] = dac_bipolar_2_5; break; - case 2: devpriv->dac_range[1] = dac_unipolar_5; break; - default:devpriv->dac_range[1] = dac_bipolar_5; break; + case 0: + devpriv->dac_range[1] = dac_bipolar_5; + break; + case 1: + devpriv->dac_range[1] = dac_bipolar_2_5; + break; + case 2: + devpriv->dac_range[1] = dac_unipolar_5; + break; + default: + devpriv->dac_range[1] = dac_bipolar_5; + break; } s = dev->subdevices + 0; /* initialize the ADC subdevice */ s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_GROUND; + s->subdev_flags = SDF_READABLE | SDF_GROUND; s->n_chan = devpriv->adc_mux == adc_diff ? 8 : 16; s->insn_read = dt2811_ai_insn; s->maxdata = 0xfff; - switch(it->options[3]){ - case 0: - default: - s->range_table = this_board->bip_5; - break; - case 1: - s->range_table = this_board->bip_2_5; - break; - case 2: - s->range_table = this_board->unip_5; - break; + switch (it->options[3]) { + case 0: + default: + s->range_table = this_board->bip_5; + break; + case 1: + s->range_table = this_board->bip_2_5; + break; + case 2: + s->range_table = this_board->unip_5; + break; } s = dev->subdevices + 1; @@ -417,9 +450,9 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) s->insn_write = dt2811_ao_insn; s->insn_read = dt2811_ao_insn_read; s->maxdata = 0xfff; - s->range_table_list = devpriv->range_type_list; - devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]]; - devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]]; + s->range_table_list = devpriv->range_type_list; + devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]]; + devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]]; s = dev->subdevices + 2; /* di subdevice */ @@ -443,7 +476,6 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) return 0; } - static int dt2811_detach(comedi_device * dev) { printk("comedi%d: dt2811: remove\n", dev->minor); @@ -451,37 +483,37 @@ static int dt2811_detach(comedi_device * dev) if (dev->irq) { comedi_free_irq(dev->irq, dev); } - if(dev->iobase){ + if (dev->iobase) { release_region(dev->iobase, DT2811_SIZE); } return 0; } - -static int dt2811_ai_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2811_ai_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); int timeout = DT2811_TIMEOUT; int i; - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { outb(chan, dev->iobase + DT2811_ADGCR); - while (timeout && inb(dev->iobase + DT2811_ADCSR) & DT2811_ADBUSY) + while (timeout + && inb(dev->iobase + DT2811_ADCSR) & DT2811_ADBUSY) timeout--; - if(!timeout)return -ETIME; + if (!timeout) + return -ETIME; data[i] = inb(dev->iobase + DT2811_ADDATLO); - data[i] |= inb(dev->iobase + DT2811_ADDATHI)<<8; - data[i]&=0xfff; + data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8; + data[i] &= 0xfff; } return i; } - #if 0 /* Wow. This is code from the Comedi stone age. But it hasn't been * replaced, so I'll let it stay. */ @@ -509,52 +541,55 @@ int dt2811_adtrig(kdev_t minor, comedi_adtrig * adtrig) } #endif -static int dt2811_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2811_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan; chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - outb(data[i]&0xff, dev->iobase + DT2811_DADAT0LO + 2*chan); - outb((data[i]>>8)&0xff, dev->iobase + DT2811_DADAT0HI + 2*chan); - devpriv->ao_readback[chan]=data[i]; + for (i = 0; i < insn->n; i++) { + outb(data[i] & 0xff, dev->iobase + DT2811_DADAT0LO + 2 * chan); + outb((data[i] >> 8) & 0xff, + dev->iobase + DT2811_DADAT0HI + 2 * chan); + devpriv->ao_readback[chan] = data[i]; } return i; } -static int dt2811_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2811_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan; chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[chan]; + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[chan]; } return i; } -static int dt2811_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2811_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + DT2811_DIO); return 2; } -static int dt2811_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2811_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; s->state &= ~data[0]; s->state |= data[0] & data[1]; @@ -564,4 +599,3 @@ static int dt2811_do_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } - diff --git a/comedi/drivers/dt2814.c b/comedi/drivers/dt2814.c index d41f157c..ab55d497 100644 --- a/comedi/drivers/dt2814.c +++ b/comedi/drivers/dt2814.c @@ -44,7 +44,6 @@ addition, the clock does not seem to be very accurate. #include #include - #define DT2814_SIZE 2 #define DT2814_CSR 0 @@ -60,70 +59,71 @@ addition, the clock does not seem to be very accurate. #define DT2814_ENB 0x10 #define DT2814_CHANMASK 0x0f -static int dt2814_attach(comedi_device *dev,comedi_devconfig *it); -static int dt2814_detach(comedi_device *dev); -static comedi_driver driver_dt2814={ - driver_name: "dt2814", - module: THIS_MODULE, - attach: dt2814_attach, - detach: dt2814_detach, +static int dt2814_attach(comedi_device * dev, comedi_devconfig * it); +static int dt2814_detach(comedi_device * dev); +static comedi_driver driver_dt2814 = { + driver_name:"dt2814", + module:THIS_MODULE, + attach:dt2814_attach, + detach:dt2814_detach, }; + COMEDI_INITCLEANUP(driver_dt2814); -static irqreturn_t dt2814_interrupt(int irq,void *dev PT_REGS_ARG); +static irqreturn_t dt2814_interrupt(int irq, void *dev PT_REGS_ARG); -typedef struct{ +typedef struct { int ntrig; int curadchan; -}dt2814_private; +} dt2814_private; #define devpriv ((dt2814_private *)dev->private) - #define DT2814_TIMEOUT 10 -#define DT2814_MAX_SPEED 100000 /* Arbitrary 10 khz limit */ +#define DT2814_MAX_SPEED 100000 /* Arbitrary 10 khz limit */ -static int dt2814_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt2814_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i,hi,lo; + int n, i, hi, lo; int chan; - int status=0; + int status = 0; - for(n=0;nn;n++){ - chan=CR_CHAN(insn->chanspec); + for (n = 0; n < insn->n; n++) { + chan = CR_CHAN(insn->chanspec); - outb(chan,dev->iobase+DT2814_CSR); - for(i=0;iiobase+DT2814_CSR); -printk("dt2814: status: %02x\n",status); -comedi_udelay(10); - if(status&DT2814_FINISH) + outb(chan, dev->iobase + DT2814_CSR); + for (i = 0; i < DT2814_TIMEOUT; i++) { + status = inb(dev->iobase + DT2814_CSR); + printk("dt2814: status: %02x\n", status); + comedi_udelay(10); + if (status & DT2814_FINISH) break; } - if(i>=DT2814_TIMEOUT){ - printk("dt2814: status: %02x\n",status); + if (i >= DT2814_TIMEOUT) { + printk("dt2814: status: %02x\n", status); return -ETIMEDOUT; } - hi=inb(dev->iobase+DT2814_DATA); - lo=inb(dev->iobase+DT2814_DATA); + hi = inb(dev->iobase + DT2814_DATA); + lo = inb(dev->iobase + DT2814_DATA); - data[n]=(hi<<4)|(lo>>4); + data[n] = (hi << 4) | (lo >> 4); } return n; } -static int dt2814_ns_to_timer(unsigned int *ns,unsigned int flags) +static int dt2814_ns_to_timer(unsigned int *ns, unsigned int flags) { int i; unsigned int f; /* XXX ignores flags */ - f = 10000; /* ns */ - for(i=0;i<8;i++){ - if((2*(*ns))<(f*11))break; + f = 10000; /* ns */ + for (i = 0; i < 8; i++) { + if ((2 * (*ns)) < (f * 11)) + break; f *= 10; } @@ -132,163 +132,174 @@ static int dt2814_ns_to_timer(unsigned int *ns,unsigned int flags) return i; } -static int dt2814_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int dt2814_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->stop_src!=TRIG_TIMER && - cmd->stop_src!=TRIG_EXT)err++; + if (cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg>1000000000){ - cmd->scan_begin_arg=1000000000; + if (cmd->scan_begin_arg > 1000000000) { + cmd->scan_begin_arg = 1000000000; err++; } - if(cmd->scan_begin_argscan_begin_arg=DT2814_MAX_SPEED; + if (cmd->scan_begin_arg < DT2814_MAX_SPEED) { + cmd->scan_begin_arg = DT2814_MAX_SPEED; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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<2){ - cmd->stop_arg=2; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg < 2) { + cmd->stop_arg = 2; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - tmp=cmd->scan_begin_arg; - dt2814_ns_to_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + tmp = cmd->scan_begin_arg; + dt2814_ns_to_timer(&cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; - if(err)return 4; + if (err) + return 4; return 0; } -static int dt2814_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int dt2814_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; int chan; int trigvar; - trigvar = dt2814_ns_to_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); + trigvar = + dt2814_ns_to_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); - chan=CR_CHAN(cmd->chanlist[0]); + chan = CR_CHAN(cmd->chanlist[0]); - devpriv->ntrig=cmd->stop_arg; - outb(chan|DT2814_ENB|(trigvar<<5), - dev->iobase+DT2814_CSR); + devpriv->ntrig = cmd->stop_arg; + outb(chan | DT2814_ENB | (trigvar << 5), dev->iobase + DT2814_CSR); return 0; } -static int dt2814_attach(comedi_device *dev,comedi_devconfig *it) +static int dt2814_attach(comedi_device * dev, comedi_devconfig * it) { - int i,irq; + int i, irq; int ret; comedi_subdevice *s; unsigned long iobase; - iobase=it->options[0]; - printk("comedi%d: dt2814: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,DT2814_SIZE,"dt2814")){ + iobase = it->options[0]; + printk("comedi%d: dt2814: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, DT2814_SIZE, "dt2814")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; dev->board_name = "dt2814"; - outb(0,dev->iobase+DT2814_CSR); + outb(0, dev->iobase + DT2814_CSR); comedi_udelay(100); - if(inb(dev->iobase+DT2814_CSR)&DT2814_ERR){ + if (inb(dev->iobase + DT2814_CSR) & DT2814_ERR) { printk("reset error (fatal)\n"); return -EIO; } - i=inb(dev->iobase+DT2814_DATA); - i=inb(dev->iobase+DT2814_DATA); + i = inb(dev->iobase + DT2814_DATA); + i = inb(dev->iobase + DT2814_DATA); - irq=it->options[1]; + irq = it->options[1]; #if 0 - if(irq<0){ + if (irq < 0) { save_flags(flags); sti(); - irqs=probe_irq_on(); + irqs = probe_irq_on(); - outb(0,dev->iobase+DT2814_CSR); + outb(0, dev->iobase + DT2814_CSR); comedi_udelay(100); - irq=probe_irq_off(irqs); + irq = probe_irq_off(irqs); restore_flags(flags); - if(inb(dev->iobase+DT2814_CSR)&DT2814_ERR){ + if (inb(dev->iobase + DT2814_CSR) & DT2814_ERR) { printk("error probing irq (bad) \n"); } - i=inb(dev->iobase+DT2814_DATA); - i=inb(dev->iobase+DT2814_DATA); + i = inb(dev->iobase + DT2814_DATA); + i = inb(dev->iobase + DT2814_DATA); } #endif - dev->irq=0; - if(irq>0){ - if(comedi_request_irq(irq,dt2814_interrupt,0,"dt2814",dev)){ + dev->irq = 0; + if (irq > 0) { + if (comedi_request_irq(irq, dt2814_interrupt, 0, "dt2814", dev)) { printk("(irq %d unavailable)\n", irq); - }else{ - printk("( irq = %d )\n",irq); - dev->irq=irq; + } else { + printk("( irq = %d )\n", irq); + dev->irq = irq; } - }else if(irq==0){ + } else if (irq == 0) { printk("(no irq)\n"); - }else{ + } else { #if 0 printk("(probe returned multiple irqs--bad)\n"); #else @@ -296,79 +307,75 @@ static int dt2814_attach(comedi_device *dev,comedi_devconfig *it) #endif } - if((ret=alloc_subdevices(dev, 1))<0) + if ((ret = alloc_subdevices(dev, 1)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(dt2814_private)))<0) + if ((ret = alloc_private(dev, sizeof(dt2814_private))) < 0) return ret; - s=dev->subdevices+0; + s = dev->subdevices + 0; dev->read_subdev = s; - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; - s->n_chan=16; /* XXX */ - s->len_chanlist=1; + s->n_chan = 16; /* XXX */ + s->len_chanlist = 1; s->insn_read = dt2814_ai_insn_read; s->do_cmd = dt2814_ai_cmd; s->do_cmdtest = dt2814_ai_cmdtest; - s->maxdata=0xfff; - s->range_table=&range_unknown; /* XXX */ + s->maxdata = 0xfff; + s->range_table = &range_unknown; /* XXX */ return 0; } - -static int dt2814_detach(comedi_device *dev) +static int dt2814_detach(comedi_device * dev) { - printk("comedi%d: dt2814: remove\n",dev->minor); + printk("comedi%d: dt2814: remove\n", dev->minor); - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } - if(dev->iobase){ - release_region(dev->iobase,DT2814_SIZE); + if (dev->iobase) { + release_region(dev->iobase, DT2814_SIZE); } return 0; } - -static irqreturn_t dt2814_interrupt(int irq,void *d PT_REGS_ARG) +static irqreturn_t dt2814_interrupt(int irq, void *d PT_REGS_ARG) { - int lo,hi; - comedi_device *dev=d; + int lo, hi; + comedi_device *dev = d; comedi_subdevice *s; int data; - if (!dev->attached) - { + if (!dev->attached) { comedi_error(dev, "spurious interrupt"); return IRQ_HANDLED; } s = dev->subdevices + 0; - hi=inb(dev->iobase+DT2814_DATA); - lo=inb(dev->iobase+DT2814_DATA); + hi = inb(dev->iobase + DT2814_DATA); + lo = inb(dev->iobase + DT2814_DATA); - data=(hi<<4)|(lo>>4); + data = (hi << 4) | (lo >> 4); - if(!(--devpriv->ntrig)){ + if (!(--devpriv->ntrig)) { int i; - outb(0,dev->iobase+DT2814_CSR); + outb(0, dev->iobase + DT2814_CSR); /* note: turning off timed mode triggers another - sample. */ + sample. */ - for(i=0;iiobase+DT2814_CSR)&DT2814_FINISH) + for (i = 0; i < DT2814_TIMEOUT; i++) { + if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH) break; } - inb(dev->iobase+DT2814_DATA); - inb(dev->iobase+DT2814_DATA); + inb(dev->iobase + DT2814_DATA); + inb(dev->iobase + DT2814_DATA); s->async->events |= COMEDI_CB_EOA; } comedi_event(dev, s); return IRQ_HANDLED; } - diff --git a/comedi/drivers/dt2815.c b/comedi/drivers/dt2815.c index 3c24ec9e..5def479b 100644 --- a/comedi/drivers/dt2815.c +++ b/comedi/drivers/dt2815.c @@ -61,92 +61,96 @@ Configuration options: #include #include - static const comedi_lrange range_dt2815_ao_32_current = { 1, { - RANGE_mA( 0, 32 ) -}}; + RANGE_mA(0, 32) + } +}; static const comedi_lrange range_dt2815_ao_20_current = { 1, { - RANGE_mA( 4, 20 ) -}}; + RANGE_mA(4, 20) + } +}; #define DT2815_SIZE 2 #define DT2815_DATA 0 #define DT2815_STATUS 1 -static int dt2815_attach(comedi_device *dev,comedi_devconfig *it); -static int dt2815_detach(comedi_device *dev); -static comedi_driver driver_dt2815={ - driver_name: "dt2815", - module: THIS_MODULE, - attach: dt2815_attach, - detach: dt2815_detach, +static int dt2815_attach(comedi_device * dev, comedi_devconfig * it); +static int dt2815_detach(comedi_device * dev); +static comedi_driver driver_dt2815 = { + driver_name:"dt2815", + module:THIS_MODULE, + attach:dt2815_attach, + detach:dt2815_detach, }; + COMEDI_INITCLEANUP(driver_dt2815); static void dt2815_free_resources(comedi_device * dev); typedef struct { - const comedi_lrange * range_type_list[8]; - lsampl_t ao_readback[8]; + const comedi_lrange *range_type_list[8]; + lsampl_t ao_readback[8]; } dt2815_private; #define devpriv ((dt2815_private *)dev->private) -static int dt2815_wait_for_status(comedi_device *dev,int status) +static int dt2815_wait_for_status(comedi_device * dev, int status) { int i; - for(i=0;i<100;i++){ - if(inb(dev->iobase + DT2815_STATUS)==status) + for (i = 0; i < 100; i++) { + if (inb(dev->iobase + DT2815_STATUS) == status) break; } return status; } -static int dt2815_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2815_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[chan]; + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[chan]; } return i; } -static int dt2815_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2815_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); - unsigned int status; - unsigned int lo, hi; - - for(i=0;in;i++){ - lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01; - hi = (data[i] & 0xff0) >> 4; - - status = dt2815_wait_for_status(dev,0x00); - if(status!=0){ - rt_printk("dt2815: failed to write low byte on %d reason %x\n", - chan, status); - return -EBUSY; - } - - outb(lo, dev->iobase + DT2815_DATA); - - status = dt2815_wait_for_status(dev,0x10); - if(status!=0x10){ - rt_printk("dt2815: failed to write high byte on %d reason %x\n", - chan, status); - return -EBUSY; - } - devpriv->ao_readback[chan] = data[i]; - } - return i; + int i; + int chan = CR_CHAN(insn->chanspec); + unsigned int status; + unsigned int lo, hi; + + for (i = 0; i < insn->n; i++) { + lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01; + hi = (data[i] & 0xff0) >> 4; + + status = dt2815_wait_for_status(dev, 0x00); + if (status != 0) { + rt_printk + ("dt2815: failed to write low byte on %d reason %x\n", + chan, status); + return -EBUSY; + } + + outb(lo, dev->iobase + DT2815_DATA); + + status = dt2815_wait_for_status(dev, 0x10); + if (status != 0x10) { + rt_printk + ("dt2815: failed to write high byte on %d reason %x\n", + chan, status); + return -EBUSY; + } + devpriv->ao_readback[chan] = data[i]; + } + return i; } /* @@ -175,88 +179,84 @@ static int dt2815_ao_insn(comedi_device *dev,comedi_subdevice *s, static int dt2815_attach(comedi_device * dev, comedi_devconfig * it) { - comedi_subdevice *s; - int i; - const comedi_lrange *current_range_type, *voltage_range_type; - unsigned long iobase; - - iobase = it->options[0]; - printk("comedi%d: dt2815: 0x%04lx ", dev->minor, iobase); - if (!request_region(iobase, DT2815_SIZE, "dt2815")) { - printk("I/O port conflict\n"); - return -EIO; - } - - dev->iobase = iobase; - dev->board_name = "dt2815"; - - if(alloc_subdevices(dev, 1)<0) - return -ENOMEM; - if(alloc_private(dev,sizeof(dt2815_private))<0) - return -ENOMEM; - - s=dev->subdevices; - /* ao subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=0xfff; - s->n_chan=8; - s->insn_write = dt2815_ao_insn; - s->insn_read = dt2815_ao_insn_read; - s->range_table_list=devpriv->range_type_list; - - current_range_type = (it->options[3]) - ? &range_dt2815_ao_20_current - : &range_dt2815_ao_32_current; - voltage_range_type = (it->options[2]) - ? &range_bipolar5 - : &range_unipolar5; - for (i = 0; i < 8; i++) { - devpriv->range_type_list[i] = (it->options[5+i]) - ? current_range_type - : voltage_range_type; - } - - /* Init the 2815 */ - outb(0x00, dev->iobase + DT2815_STATUS); - for (i = 0 ; i < 100 ; i++) { - /* This is incredibly slow (approx 20 ms) */ - unsigned int status; - - comedi_udelay(1000); - status = inb(dev->iobase + DT2815_STATUS); - if (status == 4) { - unsigned int program; - program = (it->options[4] & 0x3) << 3 | 0x7; - outb(program, dev->iobase + DT2815_DATA); - printk(", program: 0x%x (@t=%d)\n", program, i); - break; - } else if (status != 0x00) { - printk("dt2815: unexpected status 0x%x (@t=%d)\n", status, i); - if (status & 0x60) { - outb(0x00, dev->iobase + DT2815_STATUS); - } - } - } + comedi_subdevice *s; + int i; + const comedi_lrange *current_range_type, *voltage_range_type; + unsigned long iobase; + + iobase = it->options[0]; + printk("comedi%d: dt2815: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, DT2815_SIZE, "dt2815")) { + printk("I/O port conflict\n"); + return -EIO; + } + dev->iobase = iobase; + dev->board_name = "dt2815"; + + if (alloc_subdevices(dev, 1) < 0) + return -ENOMEM; + if (alloc_private(dev, sizeof(dt2815_private)) < 0) + return -ENOMEM; + + s = dev->subdevices; + /* ao subdevice */ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 0xfff; + s->n_chan = 8; + s->insn_write = dt2815_ao_insn; + s->insn_read = dt2815_ao_insn_read; + s->range_table_list = devpriv->range_type_list; + + current_range_type = (it->options[3]) + ? &range_dt2815_ao_20_current : &range_dt2815_ao_32_current; + voltage_range_type = (it->options[2]) + ? &range_bipolar5 : &range_unipolar5; + for (i = 0; i < 8; i++) { + devpriv->range_type_list[i] = (it->options[5 + i]) + ? current_range_type : voltage_range_type; + } - printk("\n"); + /* Init the 2815 */ + outb(0x00, dev->iobase + DT2815_STATUS); + for (i = 0; i < 100; i++) { + /* This is incredibly slow (approx 20 ms) */ + unsigned int status; + + comedi_udelay(1000); + status = inb(dev->iobase + DT2815_STATUS); + if (status == 4) { + unsigned int program; + program = (it->options[4] & 0x3) << 3 | 0x7; + outb(program, dev->iobase + DT2815_DATA); + printk(", program: 0x%x (@t=%d)\n", program, i); + break; + } else if (status != 0x00) { + printk("dt2815: unexpected status 0x%x (@t=%d)\n", + status, i); + if (status & 0x60) { + outb(0x00, dev->iobase + DT2815_STATUS); + } + } + } - return 0; + printk("\n"); + + return 0; } static void dt2815_free_resources(comedi_device * dev) { - if(dev->iobase) - release_region(dev->iobase, DT2815_SIZE); + if (dev->iobase) + release_region(dev->iobase, DT2815_SIZE); } static int dt2815_detach(comedi_device * dev) { - printk("comedi%d: dt2815: remove\n", dev->minor); + printk("comedi%d: dt2815: remove\n", dev->minor); - dt2815_free_resources(dev); + dt2815_free_resources(dev); - return 0; + return 0; } - diff --git a/comedi/drivers/dt2817.c b/comedi/drivers/dt2817.c index 742a58c2..fba8dfb3 100644 --- a/comedi/drivers/dt2817.c +++ b/comedi/drivers/dt2817.c @@ -42,57 +42,62 @@ Configuration options: #include - - #define DT2817_SIZE 5 #define DT2817_CR 0 #define DT2817_DATA 1 - -static int dt2817_attach(comedi_device *dev,comedi_devconfig *it); -static int dt2817_detach(comedi_device *dev); -static comedi_driver driver_dt2817={ - driver_name: "dt2817", - module: THIS_MODULE, - attach: dt2817_attach, - detach: dt2817_detach, +static int dt2817_attach(comedi_device * dev, comedi_devconfig * it); +static int dt2817_detach(comedi_device * dev); +static comedi_driver driver_dt2817 = { + driver_name:"dt2817", + module:THIS_MODULE, + attach:dt2817_attach, + detach:dt2817_detach, }; -COMEDI_INITCLEANUP(driver_dt2817); +COMEDI_INITCLEANUP(driver_dt2817); -static int dt2817_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2817_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int mask; int chan; - int oe=0; - - if(insn->n!=1)return -EINVAL; - - chan=CR_CHAN(insn->chanspec); - if(chan<8){ - mask=0xff; - }else if(chan<16){ - mask=0xff00; - }else if(chan<24){ - mask=0xff0000; - }else mask=0xff000000; - if(data[0])s->io_bits|=mask; - else s->io_bits&=~mask; - - if(s->io_bits&0x000000ff)oe|=0x1; - if(s->io_bits&0x0000ff00)oe|=0x2; - if(s->io_bits&0x00ff0000)oe|=0x4; - if(s->io_bits&0xff000000)oe|=0x8; - - outb(oe,dev->iobase + DT2817_CR); + int oe = 0; + + if (insn->n != 1) + return -EINVAL; + + chan = CR_CHAN(insn->chanspec); + if (chan < 8) { + mask = 0xff; + } else if (chan < 16) { + mask = 0xff00; + } else if (chan < 24) { + mask = 0xff0000; + } else + mask = 0xff000000; + if (data[0]) + s->io_bits |= mask; + else + s->io_bits &= ~mask; + + if (s->io_bits & 0x000000ff) + oe |= 0x1; + if (s->io_bits & 0x0000ff00) + oe |= 0x2; + if (s->io_bits & 0x00ff0000) + oe |= 0x4; + if (s->io_bits & 0xff000000) + oe |= 0x8; + + outb(oe, dev->iobase + DT2817_CR); return 1; } -static int dt2817_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt2817_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int changed; @@ -100,73 +105,74 @@ static int dt2817_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, * a driver like this to be deterministic or fast. * We choose fast. */ - if(data[0]){ + if (data[0]) { changed = s->state; s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); changed ^= s->state; changed &= s->io_bits; - if(changed&0x000000ff) - outb(s->state&0xff, dev->iobase + DT2817_DATA+0); - if(changed&0x0000ff00) - outb((s->state>>8)&0xff, dev->iobase + DT2817_DATA+1); - if(changed&0x00ff0000) - outb((s->state>>16)&0xff, dev->iobase + DT2817_DATA+2); - if(changed&0xff000000) - outb((s->state>>24)&0xff, dev->iobase + DT2817_DATA+3); + if (changed & 0x000000ff) + outb(s->state & 0xff, dev->iobase + DT2817_DATA + 0); + if (changed & 0x0000ff00) + outb((s->state >> 8) & 0xff, + dev->iobase + DT2817_DATA + 1); + if (changed & 0x00ff0000) + outb((s->state >> 16) & 0xff, + dev->iobase + DT2817_DATA + 2); + if (changed & 0xff000000) + outb((s->state >> 24) & 0xff, + dev->iobase + DT2817_DATA + 3); } data[1] = inb(dev->iobase + DT2817_DATA + 0); - data[1] |= (inb(dev->iobase + DT2817_DATA + 1)<<8); - data[1] |= (inb(dev->iobase + DT2817_DATA + 2)<<16); - data[1] |= (inb(dev->iobase + DT2817_DATA + 3)<<24); + data[1] |= (inb(dev->iobase + DT2817_DATA + 1) << 8); + data[1] |= (inb(dev->iobase + DT2817_DATA + 2) << 16); + data[1] |= (inb(dev->iobase + DT2817_DATA + 3) << 24); return 2; } -static int dt2817_attach(comedi_device *dev,comedi_devconfig *it) +static int dt2817_attach(comedi_device * dev, comedi_devconfig * it) { int ret; comedi_subdevice *s; unsigned long iobase; - iobase=it->options[0]; - printk("comedi%d: dt2817: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,DT2817_SIZE,"dt2817")){ + iobase = it->options[0]; + printk("comedi%d: dt2817: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, DT2817_SIZE, "dt2817")) { printk("I/O port conflict\n"); return -EIO; } dev->iobase = iobase; - dev->board_name="dt2817"; + dev->board_name = "dt2817"; - if((ret=alloc_subdevices(dev, 1))<0) + if ((ret = alloc_subdevices(dev, 1)) < 0) return ret; - s=dev->subdevices+0; + s = dev->subdevices + 0; - s->n_chan=32; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->range_table=&range_digital; - s->maxdata=1; - s->insn_bits=dt2817_dio_insn_bits; - s->insn_config=dt2817_dio_insn_config; + s->n_chan = 32; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->range_table = &range_digital; + s->maxdata = 1; + s->insn_bits = dt2817_dio_insn_bits; + s->insn_config = dt2817_dio_insn_config; - s->state=0; - outb(0,dev->iobase+DT2817_CR); + s->state = 0; + outb(0, dev->iobase + DT2817_CR); printk("\n"); return 0; } - -static int dt2817_detach(comedi_device *dev) +static int dt2817_detach(comedi_device * dev) { - printk("comedi%d: dt2817: remove\n",dev->minor); - - if(dev->iobase) - release_region(dev->iobase,DT2817_SIZE); + printk("comedi%d: dt2817: remove\n", dev->minor); + + if (dev->iobase) + release_region(dev->iobase, DT2817_SIZE); return 0; } - diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index 42454ec5..74f1f40f 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -155,42 +155,47 @@ Notes: #define DT2821_BDINIT 0x0001 /* (W) initialize board */ static const comedi_lrange range_dt282x_ai_lo_bipolar = { 4, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ) -}}; + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25) + } +}; static const comedi_lrange range_dt282x_ai_lo_unipolar = { 4, { - RANGE( 0, 10 ), - RANGE( 0, 5 ), - RANGE( 0, 2.5 ), - RANGE( 0, 1.25 ) -}}; + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25) + } +}; static const comedi_lrange range_dt282x_ai_5_bipolar = { 4, { - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ), - RANGE( -0.625, 0.625 ), -}}; + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25), + RANGE(-0.625, 0.625), + } +}; static const comedi_lrange range_dt282x_ai_5_unipolar = { 4, { - RANGE( 0, 5 ), - RANGE( 0, 2.5 ), - RANGE( 0, 1.25 ), - RANGE( 0, 0.625 ), -}}; + RANGE(0, 5), + RANGE(0, 2.5), + RANGE(0, 1.25), + RANGE(0, 0.625), + } +}; static const comedi_lrange range_dt282x_ai_hi_bipolar = { 4, { - RANGE( -10, 10 ), - RANGE( -1, 1 ), - RANGE( -0.1, 0.1 ), - RANGE( -0.02, 0.02 ) -}}; + RANGE(-10, 10), + RANGE(-1, 1), + RANGE(-0.1, 0.1), + RANGE(-0.02, 0.02) + } +}; static const comedi_lrange range_dt282x_ai_hi_unipolar = { 4, { - RANGE( 0, 10 ), - RANGE( 0, 1 ), - RANGE( 0, 0.1 ), - RANGE( 0, 0.02 ) -}}; - + RANGE(0, 10), + RANGE(0, 1), + RANGE(0, 0.1), + RANGE(0, 0.02) + } +}; typedef struct { const char *name; @@ -203,139 +208,138 @@ typedef struct { int dabits; } boardtype_t; -static const boardtype_t boardtypes[] = -{ - { name: "dt2821", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 20000, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt2821-f", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 6500, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt2821-g", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 4000, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt2823", - adbits: 16, - adchan_se: 0, - adchan_di: 4, - ai_speed: 10000, - ispgl: 0, - dachan: 2, - dabits: 16, - }, - { name: "dt2824-pgh", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 20000, - ispgl: 0, - dachan: 0, - dabits: 0, - }, - { name: "dt2824-pgl", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 20000, - ispgl: 1, - dachan: 0, - dabits: 0, - }, - { name: "dt2825", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 20000, - ispgl: 1, - dachan: 2, - dabits: 12, - }, - { name: "dt2827", - adbits: 16, - adchan_se: 0, - adchan_di: 4, - ai_speed: 10000, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt2828", - adbits: 12, - adchan_se: 4, - adchan_di: 0, - ai_speed: 10000, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt2829", - adbits: 16, - adchan_se: 8, - adchan_di: 0, - ai_speed: 33250, - ispgl: 0, - dachan: 2, - dabits: 16, - }, - { name: "dt21-ez", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 10000, - ispgl: 0, - dachan: 2, - dabits: 12, - }, - { name: "dt23-ez", - adbits: 16, - adchan_se: 16, - adchan_di: 8, - ai_speed: 10000, - ispgl: 0, - dachan: 0, - dabits: 0, - }, - { name: "dt24-ez", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 10000, - ispgl: 0, - dachan: 0, - dabits: 0, - }, - { name: "dt24-ez-pgl", - adbits: 12, - adchan_se: 16, - adchan_di: 8, - ai_speed: 10000, - ispgl: 1, - dachan: 0, - dabits: 0, - }, +static const boardtype_t boardtypes[] = { + {name:"dt2821", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:20000, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt2821-f", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:6500, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt2821-g", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:4000, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt2823", + adbits: 16, + adchan_se:0, + adchan_di:4, + ai_speed:10000, + ispgl: 0, + dachan: 2, + dabits: 16, + }, + {name:"dt2824-pgh", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:20000, + ispgl: 0, + dachan: 0, + dabits: 0, + }, + {name:"dt2824-pgl", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:20000, + ispgl: 1, + dachan: 0, + dabits: 0, + }, + {name:"dt2825", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:20000, + ispgl: 1, + dachan: 2, + dabits: 12, + }, + {name:"dt2827", + adbits: 16, + adchan_se:0, + adchan_di:4, + ai_speed:10000, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt2828", + adbits: 12, + adchan_se:4, + adchan_di:0, + ai_speed:10000, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt2829", + adbits: 16, + adchan_se:8, + adchan_di:0, + ai_speed:33250, + ispgl: 0, + dachan: 2, + dabits: 16, + }, + {name:"dt21-ez", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:10000, + ispgl: 0, + dachan: 2, + dabits: 12, + }, + {name:"dt23-ez", + adbits: 16, + adchan_se:16, + adchan_di:8, + ai_speed:10000, + ispgl: 0, + dachan: 0, + dabits: 0, + }, + {name:"dt24-ez", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:10000, + ispgl: 0, + dachan: 0, + dabits: 0, + }, + {name:"dt24-ez-pgl", + adbits: 12, + adchan_se:16, + adchan_di:8, + ai_speed:10000, + ispgl: 1, + dachan: 0, + dabits: 0, + }, }; + #define n_boardtypes sizeof(boardtypes)/sizeof(boardtype_t) #define this_board ((const boardtype_t *)dev->board_ptr) - typedef struct { int ad_2scomp; /* we have 2's comp jumper set */ int da0_2scomp; /* same, for DAC0 */ @@ -345,18 +349,18 @@ typedef struct { sampl_t ao[2]; - volatile int dacsr; /* software copies of registers */ + volatile int dacsr; /* software copies of registers */ volatile int adcsr; volatile int supcsr; volatile int ntrig; volatile int nread; - struct{ + struct { int chan; short *buf; /* DMA buffer */ volatile int size; /* size of current transfer */ - }dma[2]; + } dma[2]; int dma_maxsize; /* max size of DMA transfer (in bytes) */ int usedma; /* driver uses DMA */ volatile int current_dma_index; @@ -392,47 +396,47 @@ typedef struct { static int dt282x_attach(comedi_device * dev, comedi_devconfig * it); static int dt282x_detach(comedi_device * dev); -static comedi_driver driver_dt282x={ - driver_name: "dt282x", - module: THIS_MODULE, - attach: dt282x_attach, - detach: dt282x_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype_t), +static comedi_driver driver_dt282x = { + driver_name:"dt282x", + module:THIS_MODULE, + attach:dt282x_attach, + detach:dt282x_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype_t), }; + COMEDI_INITCLEANUP(driver_dt282x); -static void free_resources(comedi_device *dev); -static int prep_ai_dma(comedi_device * dev,int chan,int size); -static int prep_ao_dma(comedi_device * dev,int chan,int size); +static void free_resources(comedi_device * dev); +static int prep_ai_dma(comedi_device * dev, int chan, int size); +static int prep_ao_dma(comedi_device * dev, int chan, int size); static int dt282x_ai_cancel(comedi_device * dev, comedi_subdevice * s); static int dt282x_ao_cancel(comedi_device * dev, comedi_subdevice * s); -static int dt282x_ns_to_timer(int *nanosec,int round_mode); -static void dt282x_disable_dma(comedi_device *dev); - +static int dt282x_ns_to_timer(int *nanosec, int round_mode); +static void dt282x_disable_dma(comedi_device * dev); -static int dt282x_grab_dma(comedi_device *dev,int dma1,int dma2); +static int dt282x_grab_dma(comedi_device * dev, int dma1, int dma2); -static void dt282x_munge(comedi_device *dev,sampl_t *buf, +static void dt282x_munge(comedi_device * dev, sampl_t * buf, unsigned int nbytes) { unsigned int i; - unsigned short mask=(1<ad_2scomp){ - sign = 1<<(boardtype.adbits-1); - }else{ + if (devpriv->ad_2scomp) { + sign = 1 << (boardtype.adbits - 1); + } else { sign = 0; } - if( nbytes % 2 ) - comedi_error( dev, "bug! odd number of bytes from dma xfer" ); - n = nbytes/2; - for(i=0;isubdevices+1; + comedi_subdevice *s = dev->subdevices + 1; update_supcsr(DT2821_CLRDMADNE); - if(!s->async->prealloc_buf){ + if (!s->async->prealloc_buf) { printk("async->data disappeared. dang!\n"); return; } - i=devpriv->current_dma_index; - ptr=devpriv->dma[i].buf; + i = devpriv->current_dma_index; + ptr = devpriv->dma[i].buf; disable_dma(devpriv->dma[i].chan); - devpriv->current_dma_index=1-i; + devpriv->current_dma_index = 1 - i; size = cfc_read_array_from_buffer(s, ptr, devpriv->dma_maxsize); - if( size == 0){ + if (size == 0) { rt_printk("dt282x: AO underrun\n"); - dt282x_ao_cancel(dev,s); + dt282x_ao_cancel(dev, s); s->async->events |= COMEDI_CB_OVERFLOW; return; } - prep_ao_dma(dev,i,size); + prep_ao_dma(dev, i, size); return; } @@ -474,11 +478,11 @@ static void dt282x_ai_dma_interrupt(comedi_device * dev) int size; int i; int ret; - comedi_subdevice *s=dev->subdevices; + comedi_subdevice *s = dev->subdevices; update_supcsr(DT2821_CLRDMADNE); - if(!s->async->prealloc_buf){ + if (!s->async->prealloc_buf) { printk("async->data disappeared. dang!\n"); return; } @@ -489,60 +493,58 @@ static void dt282x_ai_dma_interrupt(comedi_device * dev) disable_dma(devpriv->dma[i].chan); - devpriv->current_dma_index = 1-i; + devpriv->current_dma_index = 1 - i; - dt282x_munge(dev, ptr, size ); - ret = cfc_write_array_to_buffer( s, ptr, size ); - if( ret != size ) - { - dt282x_ai_cancel(dev,s); + dt282x_munge(dev, ptr, size); + ret = cfc_write_array_to_buffer(s, ptr, size); + if (ret != size) { + dt282x_ai_cancel(dev, s); return; } - devpriv->nread-=size/2; + devpriv->nread -= size / 2; - if(devpriv->nread<0){ + if (devpriv->nread < 0) { printk("dt282x: off by one\n"); - devpriv->nread=0; + devpriv->nread = 0; } if (!devpriv->nread) { dt282x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; return; } - #if 0 /* clear the dual dma flag, making this the last dma segment */ /* XXX probably wrong */ - if(!devpriv->ntrig){ + if (!devpriv->ntrig) { devpriv->supcsr &= ~(DT2821_DDMA); update_supcsr(0); } #endif /* restart the channel */ - prep_ai_dma(dev,i,0); + prep_ai_dma(dev, i, 0); } -static int prep_ai_dma(comedi_device * dev,int dma_index,int n) +static int prep_ai_dma(comedi_device * dev, int dma_index, int n) { int dma_chan; unsigned long dma_ptr; unsigned long flags; - if(!devpriv->ntrig) + if (!devpriv->ntrig) return 0; - if(n==0) + if (n == 0) n = devpriv->dma_maxsize; - if (n > devpriv->ntrig*2) - n = devpriv->ntrig*2; - devpriv->ntrig -= n/2; + if (n > devpriv->ntrig * 2) + n = devpriv->ntrig * 2; + devpriv->ntrig -= n / 2; devpriv->dma[dma_index].size = n; dma_chan = devpriv->dma[dma_index].chan; dma_ptr = virt_to_bus(devpriv->dma[dma_index].buf); set_dma_mode(dma_chan, DMA_MODE_READ); - flags=claim_dma_lock(); + flags = claim_dma_lock(); clear_dma_ff(dma_chan); set_dma_addr(dma_chan, dma_ptr); set_dma_count(dma_chan, n); @@ -553,7 +555,7 @@ static int prep_ai_dma(comedi_device * dev,int dma_index,int n) return n; } -static int prep_ao_dma(comedi_device * dev,int dma_index,int n) +static int prep_ao_dma(comedi_device * dev, int dma_index, int n) { int dma_chan; unsigned long dma_ptr; @@ -564,10 +566,10 @@ static int prep_ao_dma(comedi_device * dev,int dma_index,int n) dma_ptr = virt_to_bus(devpriv->dma[dma_index].buf); set_dma_mode(dma_chan, DMA_MODE_WRITE); - flags=claim_dma_lock(); + flags = claim_dma_lock(); clear_dma_ff(dma_chan); set_dma_addr(dma_chan, dma_ptr); - set_dma_count(dma_chan, n ); + set_dma_count(dma_chan, n); release_dma_lock(flags); enable_dma(dma_chan); @@ -583,28 +585,27 @@ static irqreturn_t dt282x_interrupt(int irq, void *d PT_REGS_ARG) unsigned int supcsr, adcsr, dacsr; int handled = 0; - if (!dev->attached) - { + if (!dev->attached) { comedi_error(dev, "spurious interrupt"); return IRQ_HANDLED; } - s = dev->subdevices+0; - s_ao = dev->subdevices+1; + s = dev->subdevices + 0; + s_ao = dev->subdevices + 1; adcsr = inw(dev->iobase + DT2821_ADCSR); dacsr = inw(dev->iobase + DT2821_DACSR); supcsr = inw(dev->iobase + DT2821_SUPCSR); if (supcsr & DT2821_DMAD) { - if(devpriv->dma_dir==DMA_MODE_READ) + if (devpriv->dma_dir == DMA_MODE_READ) dt282x_ai_dma_interrupt(dev); else dt282x_ao_dma_interrupt(dev); handled = 1; } if (adcsr & DT2821_ADERR) { - if(devpriv->nread != 0 ){ + if (devpriv->nread != 0) { comedi_error(dev, "A/D error"); - dt282x_ai_cancel(dev,s); + dt282x_ai_cancel(dev, s); s->async->events |= COMEDI_CB_ERROR; } handled = 1; @@ -612,13 +613,13 @@ static irqreturn_t dt282x_interrupt(int irq, void *d PT_REGS_ARG) if (dacsr & DT2821_DAERR) { #if 0 static int warn = 5; - if(--warn<=0){ + if (--warn <= 0) { disable_irq(dev->irq); printk("disabling irq\n"); } #endif comedi_error(dev, "D/A error"); - dt282x_ao_cancel(dev,s_ao); + dt282x_ao_cancel(dev, s_ao); s->async->events |= COMEDI_CB_ERROR; handled = 1; } @@ -628,20 +629,20 @@ static irqreturn_t dt282x_interrupt(int irq, void *d PT_REGS_ARG) sampl_t data; data = (sampl_t) inw(dev->iobase + DT2821_ADDAT); - data&=(1<ad_2scomp){ - data^=1<<(boardtype.adbits-1); + data &= (1 << boardtype.adbits) - 1; + if (devpriv->ad_2scomp) { + data ^= 1 << (boardtype.adbits - 1); } - ret = comedi_buf_put( s->async, data ); - if(ret==0){ + ret = comedi_buf_put(s->async, data); + if (ret == 0) { s->async->events |= COMEDI_CB_OVERFLOW; } devpriv->nread--; - if(!devpriv->nread){ + if (!devpriv->nread) { s->async->events |= COMEDI_CB_EOA; - }else{ - if(supcsr&DT2821_SCDN) + } else { + if (supcsr & DT2821_SCDN) update_supcsr(DT2821_STRIG); } handled = 1; @@ -652,8 +653,8 @@ static irqreturn_t dt282x_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_RETVAL(handled); } - -static void dt282x_load_changain(comedi_device * dev, int n, unsigned int *chanlist) +static void dt282x_load_changain(comedi_device * dev, int n, + unsigned int *chanlist) { unsigned int i; unsigned int chan, range; @@ -667,15 +668,14 @@ static void dt282x_load_changain(comedi_device * dev, int n, unsigned int *chanl outw(n - 1, dev->iobase + DT2821_CHANCSR); } - /* * Performs a single A/D conversion. * - Put channel/gain into channel-gain list * - preload multiplexer * - trigger conversion and wait for it to finish */ -static int dt282x_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt282x_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; @@ -686,19 +686,19 @@ static int dt282x_ai_insn_read(comedi_device *dev,comedi_subdevice *s, dt282x_load_changain(dev, 1, &insn->chanspec); update_supcsr(DT2821_PRLD); - wait_for(!mux_busy(), - comedi_error(dev, "timeout\n"); - return -ETIME; - ); + wait_for(!mux_busy(), comedi_error(dev, "timeout\n"); + return -ETIME; + ); - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { update_supcsr(DT2821_STRIG); - wait_for(ad_done(), - comedi_error(dev, "timeout\n"); + wait_for(ad_done(), comedi_error(dev, "timeout\n"); return -ETIME; - ); + ); - data[i] = inw(dev->iobase + DT2821_ADDAT) & ((1<iobase + + DT2821_ADDAT) & ((1 << boardtype.adbits) - 1); if (devpriv->ad_2scomp) data[i] ^= (1 << (boardtype.adbits - 1)); } @@ -706,160 +706,172 @@ static int dt282x_ai_insn_read(comedi_device *dev,comedi_subdevice *s, return i; } -static int dt282x_ai_cmdtest(comedi_device * dev, comedi_subdevice * s,comedi_cmd *cmd) +static int dt282x_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_FOLLOW|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_FOLLOW && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - }else{ + } else { /* external trigger */ /* should be level/edge, hi/lo specification here */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->convert_arg<4000){ + if (cmd->convert_arg < 4000) { /* XXX board dependent */ - cmd->convert_arg=4000; + cmd->convert_arg = 4000; err++; } #define SLOWEST_TIMER (250*(1<<15)*255) - if(cmd->convert_arg>SLOWEST_TIMER){ - cmd->convert_arg=SLOWEST_TIMER; + if (cmd->convert_arg > SLOWEST_TIMER) { + cmd->convert_arg = SLOWEST_TIMER; err++; } - if(cmd->convert_arg < this_board->ai_speed ){ + if (cmd->convert_arg < this_board->ai_speed) { cmd->convert_arg = this_board->ai_speed; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - tmp=cmd->convert_arg; - dt282x_ns_to_timer(&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; + tmp = cmd->convert_arg; + dt282x_ns_to_timer(&cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err++; - if(err)return 4; + if (err) + return 4; return 0; } static int dt282x_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; int timer; - if(devpriv->usedma == 0){ - comedi_error(dev, "driver requires 2 dma channels to execute command"); + if (devpriv->usedma == 0) { + comedi_error(dev, + "driver requires 2 dma channels to execute command"); return -EIO; } dt282x_disable_dma(dev); - if(cmd->convert_arg < this_board->ai_speed ) + if (cmd->convert_arg < this_board->ai_speed) cmd->convert_arg = this_board->ai_speed; - timer=dt282x_ns_to_timer(&cmd->convert_arg,TRIG_ROUND_NEAREST); + timer = dt282x_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_NEAREST); outw(timer, dev->iobase + DT2821_TMRCTR); - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS0; - }else{ + } else { /* external trigger */ devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS0 | DT2821_DS1; } update_supcsr(DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_ADCINIT); - devpriv->ntrig=cmd->stop_arg*cmd->scan_end_arg; - devpriv->nread=devpriv->ntrig; + devpriv->ntrig = cmd->stop_arg * cmd->scan_end_arg; + devpriv->nread = devpriv->ntrig; - devpriv->dma_dir=DMA_MODE_READ; - devpriv->current_dma_index=0; - prep_ai_dma(dev,0,0); - if(devpriv->ntrig){ - prep_ai_dma(dev,1,0); + devpriv->dma_dir = DMA_MODE_READ; + devpriv->current_dma_index = 0; + prep_ai_dma(dev, 0, 0); + if (devpriv->ntrig) { + prep_ai_dma(dev, 1, 0); devpriv->supcsr |= DT2821_DDMA; update_supcsr(0); } devpriv->adcsr = 0; - dt282x_load_changain(dev,cmd->chanlist_len,cmd->chanlist); + dt282x_load_changain(dev, cmd->chanlist_len, cmd->chanlist); devpriv->adcsr = DT2821_ADCLK | DT2821_IADDONE; update_adcsr(0); update_supcsr(DT2821_PRLD); - wait_for(!mux_busy(), - comedi_error(dev, "timeout\n"); - return -ETIME; - ); + wait_for(!mux_busy(), comedi_error(dev, "timeout\n"); + return -ETIME; + ); - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { update_supcsr(DT2821_STRIG); - }else{ + } else { devpriv->supcsr |= DT2821_XTRIG; update_supcsr(0); } @@ -867,9 +879,9 @@ static int dt282x_ai_cmd(comedi_device * dev, comedi_subdevice * s) return 0; } -static void dt282x_disable_dma(comedi_device *dev) +static void dt282x_disable_dma(comedi_device * dev) { - if( devpriv->usedma ){ + if (devpriv->usedma) { disable_dma(devpriv->dma[0].chan); disable_dma(devpriv->dma[1].chan); } @@ -879,7 +891,7 @@ static int dt282x_ai_cancel(comedi_device * dev, comedi_subdevice * s) { dt282x_disable_dma(dev); - devpriv->adcsr=0; + devpriv->adcsr = 0; update_adcsr(0); devpriv->supcsr = 0; @@ -888,46 +900,45 @@ static int dt282x_ai_cancel(comedi_device * dev, comedi_subdevice * s) return 0; } - -static int dt282x_ns_to_timer(int *nanosec,int round_mode) +static int dt282x_ns_to_timer(int *nanosec, int round_mode) { - int prescale,base,divider; + int prescale, base, divider; - for(prescale=0;prescale<16;prescale++){ - if(prescale==1)continue; - base=250*(1<ao[CR_CHAN(insn->chanspec)]; @@ -935,14 +946,14 @@ static int dt282x_ao_insn_read(comedi_device *dev,comedi_subdevice *s, } static int dt282x_ao_insn_write(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { sampl_t d; unsigned int chan; chan = CR_CHAN(insn->chanspec); d = data[0]; - d &= (1<ao[chan] = d; devpriv->dacsr |= DT2821_SSEL; @@ -951,11 +962,11 @@ static int dt282x_ao_insn_write(comedi_device * dev, comedi_subdevice * s, /* select channel */ devpriv->dacsr |= DT2821_YSEL; if (devpriv->da0_2scomp) - d ^= (1<<(boardtype.dabits-1)); + d ^= (1 << (boardtype.dabits - 1)); } else { devpriv->dacsr &= ~DT2821_YSEL; if (devpriv->da1_2scomp) - d ^= (1<<(boardtype.dabits-1)); + d ^= (1 << (boardtype.dabits - 1)); } update_dacsr(0); @@ -967,120 +978,135 @@ static int dt282x_ao_insn_write(comedi_device * dev, comedi_subdevice * s, return 1; } -static int dt282x_ao_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int dt282x_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg < 5000 /* XXX unknown */){ + if (cmd->scan_begin_arg < 5000 /* XXX unknown */ ) { cmd->scan_begin_arg = 5000; err++; } - if(cmd->convert_arg != 0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg > 2){ + if (cmd->scan_end_arg > 2) { /* XXX chanlist stuff? */ cmd->scan_end_arg = 2; err++; } - if(cmd->stop_src==TRIG_COUNT){ + if (cmd->stop_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - tmp=cmd->scan_begin_arg; - dt282x_ns_to_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + tmp = cmd->scan_begin_arg; + dt282x_ns_to_timer(&cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; - if(err)return 4; + if (err) + return 4; return 0; } -static int dt282x_ao_inttrig(comedi_device *dev,comedi_subdevice *s, - unsigned int x) +static int dt282x_ao_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int x) { int size; - if(x!=0)return -EINVAL; + if (x != 0) + return -EINVAL; - size = cfc_read_array_from_buffer(s, devpriv->dma[0].buf, devpriv->dma_maxsize); - if( size == 0){ + size = cfc_read_array_from_buffer(s, devpriv->dma[0].buf, + devpriv->dma_maxsize); + if (size == 0) { rt_printk("dt282x: AO underrun\n"); return -EPIPE; } - prep_ao_dma(dev,0,size); + prep_ao_dma(dev, 0, size); - size = cfc_read_array_from_buffer(s, devpriv->dma[1].buf, devpriv->dma_maxsize); - if( size == 0){ + size = cfc_read_array_from_buffer(s, devpriv->dma[1].buf, + devpriv->dma_maxsize); + if (size == 0) { rt_printk("dt282x: AO underrun\n"); return -EPIPE; } - prep_ao_dma(dev,1,size); + prep_ao_dma(dev, 1, size); update_supcsr(DT2821_STRIG); - s->async->inttrig=NULL; + s->async->inttrig = NULL; return 1; } -static int dt282x_ao_cmd(comedi_device *dev,comedi_subdevice *s) +static int dt282x_ao_cmd(comedi_device * dev, comedi_subdevice * s) { int timer; - comedi_cmd *cmd=&s->async->cmd; + comedi_cmd *cmd = &s->async->cmd; - if(devpriv->usedma == 0){ - comedi_error(dev, "driver requires 2 dma channels to execute command"); + if (devpriv->usedma == 0) { + comedi_error(dev, + "driver requires 2 dma channels to execute command"); return -EIO; } @@ -1089,19 +1115,19 @@ static int dt282x_ao_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->supcsr = DT2821_ERRINTEN | DT2821_DS1 | DT2821_DDMA; update_supcsr(DT2821_CLRDMADNE | DT2821_BUFFB | DT2821_DACINIT); - devpriv->ntrig=cmd->stop_arg*cmd->chanlist_len; - devpriv->nread=devpriv->ntrig; + devpriv->ntrig = cmd->stop_arg * cmd->chanlist_len; + devpriv->nread = devpriv->ntrig; - devpriv->dma_dir=DMA_MODE_WRITE; - devpriv->current_dma_index=0; + devpriv->dma_dir = DMA_MODE_WRITE; + devpriv->current_dma_index = 0; - timer=dt282x_ns_to_timer(&cmd->scan_begin_arg,TRIG_ROUND_NEAREST); + timer = dt282x_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_NEAREST); outw(timer, dev->iobase + DT2821_TMRCTR); - devpriv->dacsr = DT2821_SSEL| DT2821_DACLK | DT2821_IDARDY; + devpriv->dacsr = DT2821_SSEL | DT2821_DACLK | DT2821_IDARDY; update_dacsr(0); - s->async->inttrig=dt282x_ao_inttrig; + s->async->inttrig = dt282x_ao_inttrig; return 0; } @@ -1110,7 +1136,7 @@ static int dt282x_ao_cancel(comedi_device * dev, comedi_subdevice * s) { dt282x_disable_dma(dev); - devpriv->dacsr=0; + devpriv->dacsr = 0; update_dacsr(0); devpriv->supcsr = 0; @@ -1119,12 +1145,12 @@ static int dt282x_ao_cancel(comedi_device * dev, comedi_subdevice * s) return 0; } -static int dt282x_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt282x_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); outw(s->state, dev->iobase + DT2821_DIODAT); } @@ -1133,63 +1159,73 @@ static int dt282x_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int dt282x_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt282x_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int mask; - mask=(CR_CHAN(insn->chanspec)<8)?0x00ff:0xff00; - if(data[0])s->io_bits|=mask; - else s->io_bits&=~mask; - - if(s->io_bits&0x00ff)devpriv->dacsr|=DT2821_LBOE; - else devpriv->dacsr&=~DT2821_LBOE; - if(s->io_bits&0xff00)devpriv->dacsr|=DT2821_HBOE; - else devpriv->dacsr&=~DT2821_HBOE; + mask = (CR_CHAN(insn->chanspec) < 8) ? 0x00ff : 0xff00; + if (data[0]) + s->io_bits |= mask; + else + s->io_bits &= ~mask; + + if (s->io_bits & 0x00ff) + devpriv->dacsr |= DT2821_LBOE; + else + devpriv->dacsr &= ~DT2821_LBOE; + if (s->io_bits & 0xff00) + devpriv->dacsr |= DT2821_HBOE; + else + devpriv->dacsr &= ~DT2821_HBOE; outw(devpriv->dacsr, dev->iobase + DT2821_DACSR); return 1; } - -static const comedi_lrange * const ai_range_table[]={ +static const comedi_lrange *const ai_range_table[] = { &range_dt282x_ai_lo_bipolar, &range_dt282x_ai_lo_unipolar, &range_dt282x_ai_5_bipolar, - &range_dt282x_ai_5_unipolar }; -static const comedi_lrange * const ai_range_pgl_table[]={ + &range_dt282x_ai_5_unipolar +}; +static const comedi_lrange *const ai_range_pgl_table[] = { &range_dt282x_ai_hi_bipolar, - &range_dt282x_ai_hi_unipolar }; -static const comedi_lrange *opt_ai_range_lkup(int ispgl,int x) + &range_dt282x_ai_hi_unipolar +}; +static const comedi_lrange *opt_ai_range_lkup(int ispgl, int x) { - if(ispgl){ - if(x<0 || x>=2)x=0; + if (ispgl) { + if (x < 0 || x >= 2) + x = 0; return ai_range_pgl_table[x]; - }else{ - if(x<0 || x>=4)x=0; + } else { + if (x < 0 || x >= 4) + x = 0; return ai_range_table[x]; } } -static const comedi_lrange * const ao_range_table[]={ +static const comedi_lrange *const ao_range_table[] = { &range_bipolar10, &range_unipolar10, &range_bipolar5, &range_unipolar5, - &range_bipolar2_5 }; + &range_bipolar2_5 +}; static const comedi_lrange *opt_ao_range_lkup(int x) { - if(x<0 || x>=5)x=0; + if (x < 0 || x >= 5) + x = 0; return ao_range_table[x]; } -enum{ opt_iobase=0, opt_irq, opt_dma1, opt_dma2, /* i/o base, irq, dma channels */ - opt_diff, /* differential */ - opt_ai_twos, opt_ao0_twos, opt_ao1_twos, /* twos comp */ +enum { opt_iobase = 0, opt_irq, opt_dma1, opt_dma2, /* i/o base, irq, dma channels */ + opt_diff, /* differential */ + opt_ai_twos, opt_ao0_twos, opt_ao1_twos, /* twos comp */ opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */ }; - /* options: 0 i/o base @@ -1214,7 +1250,8 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) dev->board_name = this_board->name; iobase = it->options[opt_iobase]; - if(!iobase)iobase = 0x240; + if (!iobase) + iobase = 0x240; printk("comedi%d: dt282x: 0x%04lx", dev->minor, iobase); if (!request_region(iobase, DT2821_SIZE, "dt282x")) { @@ -1227,24 +1264,23 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) i = inw(dev->iobase + DT2821_ADCSR); #ifdef DEBUG printk(" fingerprint=%x,%x,%x,%x,%x", - inw(dev->iobase + DT2821_ADCSR), - inw(dev->iobase + DT2821_CHANCSR), - inw(dev->iobase + DT2821_DACSR), - inw(dev->iobase + DT2821_SUPCSR), - inw(dev->iobase + DT2821_TMRCTR)); + inw(dev->iobase + DT2821_ADCSR), + inw(dev->iobase + DT2821_CHANCSR), + inw(dev->iobase + DT2821_DACSR), + inw(dev->iobase + DT2821_SUPCSR), + inw(dev->iobase + DT2821_TMRCTR)); #endif - if ( - ((inw(dev->iobase + DT2821_ADCSR) & DT2821_ADCSR_MASK) - != DT2821_ADCSR_VAL) || - ((inw(dev->iobase + DT2821_CHANCSR) & DT2821_CHANCSR_MASK) - != DT2821_CHANCSR_VAL) || - ((inw(dev->iobase + DT2821_DACSR) & DT2821_DACSR_MASK) - != DT2821_DACSR_VAL) || - ((inw(dev->iobase + DT2821_SUPCSR) & DT2821_SUPCSR_MASK) - != DT2821_SUPCSR_VAL) || - ((inw(dev->iobase + DT2821_TMRCTR) & DT2821_TMRCTR_MASK) - != DT2821_TMRCTR_VAL)) { + if (((inw(dev->iobase + DT2821_ADCSR) & DT2821_ADCSR_MASK) + != DT2821_ADCSR_VAL) || + ((inw(dev->iobase + DT2821_CHANCSR) & DT2821_CHANCSR_MASK) + != DT2821_CHANCSR_VAL) || + ((inw(dev->iobase + DT2821_DACSR) & DT2821_DACSR_MASK) + != DT2821_DACSR_VAL) || + ((inw(dev->iobase + DT2821_SUPCSR) & DT2821_SUPCSR_MASK) + != DT2821_SUPCSR_VAL) || + ((inw(dev->iobase + DT2821_TMRCTR) & DT2821_TMRCTR_MASK) + != DT2821_TMRCTR_VAL)) { printk(" board not found"); return -EIO; } @@ -1273,8 +1309,9 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) #endif if (irq > 0) { printk(" ( irq = %d )", irq); - ret = comedi_request_irq(irq, dt282x_interrupt, 0, "dt282x", dev); - if(ret<0) { + ret = comedi_request_irq(irq, dt282x_interrupt, 0, "dt282x", + dev); + if (ret < 0) { printk(" failed to get irq\n"); return -EIO; } @@ -1289,65 +1326,69 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) #endif } - if((ret=alloc_private(dev,sizeof(dt282x_private)))<0) + if ((ret = alloc_private(dev, sizeof(dt282x_private))) < 0) return ret; - ret=dt282x_grab_dma(dev,it->options[opt_dma1],it->options[opt_dma2]); - if(ret<0) + ret = dt282x_grab_dma(dev, it->options[opt_dma1], + it->options[opt_dma2]); + if (ret < 0) return ret; - if((ret=alloc_subdevices(dev, 3))<0) + if ((ret = alloc_subdevices(dev, 3)) < 0) return ret; - s=dev->subdevices+0; + s = dev->subdevices + 0; - dev->read_subdev=s; + dev->read_subdev = s; /* ai subdevice */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE | SDF_CMD_READ | - ((it->options[opt_diff])?SDF_DIFF:SDF_COMMON); - s->n_chan=(it->options[opt_diff])?boardtype.adchan_di:boardtype.adchan_se; - s->insn_read=dt282x_ai_insn_read; - s->do_cmdtest=dt282x_ai_cmdtest; - s->do_cmd=dt282x_ai_cmd; - s->cancel=dt282x_ai_cancel; - s->maxdata=(1<len_chanlist=16; - s->range_table = opt_ai_range_lkup(boardtype.ispgl,it->options[opt_ai_range]); - devpriv->ad_2scomp=it->options[opt_ai_twos]; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_CMD_READ | + ((it->options[opt_diff]) ? SDF_DIFF : SDF_COMMON); + s->n_chan = + (it->options[opt_diff]) ? boardtype.adchan_di : boardtype. + adchan_se; + s->insn_read = dt282x_ai_insn_read; + s->do_cmdtest = dt282x_ai_cmdtest; + s->do_cmd = dt282x_ai_cmd; + s->cancel = dt282x_ai_cancel; + s->maxdata = (1 << boardtype.adbits) - 1; + s->len_chanlist = 16; + s->range_table = + opt_ai_range_lkup(boardtype.ispgl, it->options[opt_ai_range]); + devpriv->ad_2scomp = it->options[opt_ai_twos]; s++; - if((s->n_chan=boardtype.dachan)){ + if ((s->n_chan = boardtype.dachan)) { /* ao subsystem */ - s->type=COMEDI_SUBD_AO; - dev->write_subdev=s; + s->type = COMEDI_SUBD_AO; + dev->write_subdev = s; s->subdev_flags = SDF_WRITABLE | SDF_CMD_WRITE; - s->insn_read=dt282x_ao_insn_read; - s->insn_write=dt282x_ao_insn_write; - s->do_cmdtest=dt282x_ao_cmdtest; - s->do_cmd=dt282x_ao_cmd; - s->cancel=dt282x_ao_cancel; - s->maxdata=(1<len_chanlist=2; - s->range_table_list=devpriv->darangelist; - devpriv->darangelist[0]= + s->insn_read = dt282x_ao_insn_read; + s->insn_write = dt282x_ao_insn_write; + s->do_cmdtest = dt282x_ao_cmdtest; + s->do_cmd = dt282x_ao_cmd; + s->cancel = dt282x_ao_cancel; + s->maxdata = (1 << boardtype.dabits) - 1; + s->len_chanlist = 2; + s->range_table_list = devpriv->darangelist; + devpriv->darangelist[0] = opt_ao_range_lkup(it->options[opt_ao0_range]); - devpriv->darangelist[1]= + devpriv->darangelist[1] = opt_ao_range_lkup(it->options[opt_ao1_range]); - devpriv->da0_2scomp=it->options[opt_ao0_twos]; - devpriv->da1_2scomp=it->options[opt_ao1_twos]; - }else{ - s->type=COMEDI_SUBD_UNUSED; + devpriv->da0_2scomp = it->options[opt_ao0_twos]; + devpriv->da1_2scomp = it->options[opt_ao1_twos]; + } else { + s->type = COMEDI_SUBD_UNUSED; } s++; /* dio subsystem */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=16; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 16; s->insn_bits = dt282x_dio_insn_bits; s->insn_config = dt282x_dio_insn_config; - s->maxdata=1; + s->maxdata = 1; s->range_table = &range_digital; printk("\n"); @@ -1355,23 +1396,22 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) return 0; } - -static void free_resources(comedi_device *dev) +static void free_resources(comedi_device * dev) { if (dev->irq) { comedi_free_irq(dev->irq, dev); } - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, DT2821_SIZE); - if(dev->private){ + if (dev->private) { if (devpriv->dma[0].chan) free_dma(devpriv->dma[0].chan); if (devpriv->dma[1].chan) free_dma(devpriv->dma[1].chan); if (devpriv->dma[0].buf) - free_page((unsigned long) devpriv->dma[0].buf); + free_page((unsigned long)devpriv->dma[0].buf); if (devpriv->dma[1].buf) - free_page((unsigned long) devpriv->dma[1].buf); + free_page((unsigned long)devpriv->dma[1].buf); } } @@ -1384,46 +1424,48 @@ static int dt282x_detach(comedi_device * dev) return 0; } -static int dt282x_grab_dma(comedi_device *dev,int dma1,int dma2) +static int dt282x_grab_dma(comedi_device * dev, int dma1, int dma2) { int ret; - devpriv->usedma=0; + devpriv->usedma = 0; - if(!dma1 && !dma2){ + if (!dma1 && !dma2) { printk(" (no dma)"); return 0; } - if(dma1==dma2 || dma1<5 || dma2<5 || dma1>7 || dma2>7) + if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7) return -EINVAL; - if(dma2dma[0].chan=dma1; + devpriv->dma[0].chan = dma1; ret = request_dma(dma2, "dt282x B"); if (ret) return -EBUSY; - devpriv->dma[1].chan=dma2; + devpriv->dma[1].chan = dma2; devpriv->dma_maxsize = PAGE_SIZE; - devpriv->dma[0].buf = (void *) __get_free_page(GFP_KERNEL | GFP_DMA); - devpriv->dma[1].buf = (void *) __get_free_page(GFP_KERNEL | GFP_DMA); + devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); + devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) { printk(" can't get DMA memory"); return -ENOMEM; } - printk(" (dma=%d,%d)",dma1,dma2); + printk(" (dma=%d,%d)", dma1, dma2); - devpriv->usedma=1; + devpriv->usedma = 1; return 0; } - diff --git a/comedi/drivers/dt3000.c b/comedi/drivers/dt3000.c index 78f14d71..f9e1f6e9 100644 --- a/comedi/drivers/dt3000.c +++ b/comedi/drivers/dt3000.c @@ -60,19 +60,21 @@ AO commands are not supported. #define PCI_VENDOR_ID_DT 0x1116 static const comedi_lrange range_dt3000_ai = { 4, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1.25, 1.25 ) -}}; + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1.25, 1.25) + } +}; static const comedi_lrange range_dt3000_ai_pgl = { 4, { - RANGE( -10, 10 ), - RANGE( -1, 1 ), - RANGE( -0.1, 0.1 ), - RANGE( -0.02, 0.02 ) -}}; + RANGE(-10, 10), + RANGE(-1, 1), + RANGE(-0.1, 0.1), + RANGE(-0.02, 0.02) + } +}; -typedef struct{ +typedef struct { const char *name; unsigned int device_id; int adchan; @@ -81,86 +83,88 @@ typedef struct{ const comedi_lrange *adrange; int dachan; int dabits; -}dt3k_boardtype; - -static const dt3k_boardtype dt3k_boardtypes[]={ - { name: "dt3001", - device_id: 0x22, - adchan: 16, - adbits: 12, - adrange: &range_dt3000_ai, - ai_speed: 3000, - dachan: 2, - dabits: 12, - }, - { name: "dt3001-pgl", - device_id: 0x27, - adchan: 16, - adbits: 12, - adrange: &range_dt3000_ai_pgl, - ai_speed: 3000, - dachan: 2, - dabits: 12, - }, - { name: "dt3002", - device_id: 0x23, - adchan: 32, - adbits: 12, - adrange: &range_dt3000_ai, - ai_speed: 3000, - dachan: 0, - dabits: 0, - }, - { name: "dt3003", - device_id: 0x24, - adchan: 64, - adbits: 12, - adrange: &range_dt3000_ai, - ai_speed: 3000, - dachan: 2, - dabits: 12, - }, - { name: "dt3003-pgl", - device_id: 0x28, - adchan: 64, - adbits: 12, - adrange: &range_dt3000_ai_pgl, - ai_speed: 3000, - dachan: 2, - dabits: 12, - }, - { name: "dt3004", - device_id: 0x25, - adchan: 16, - adbits: 16, - adrange: &range_dt3000_ai, - ai_speed: 10000, - dachan: 2, - dabits: 12, - }, - { name: "dt3005", /* a.k.a. 3004-200 */ - device_id: 0x26, - adchan: 16, - adbits: 16, - adrange: &range_dt3000_ai, - ai_speed: 5000, - dachan: 2, - dabits: 12, - }, +} dt3k_boardtype; + +static const dt3k_boardtype dt3k_boardtypes[] = { + {name:"dt3001", + device_id:0x22, + adchan: 16, + adbits: 12, + adrange: &range_dt3000_ai, + ai_speed:3000, + dachan: 2, + dabits: 12, + }, + {name:"dt3001-pgl", + device_id:0x27, + adchan: 16, + adbits: 12, + adrange: &range_dt3000_ai_pgl, + ai_speed:3000, + dachan: 2, + dabits: 12, + }, + {name:"dt3002", + device_id:0x23, + adchan: 32, + adbits: 12, + adrange: &range_dt3000_ai, + ai_speed:3000, + dachan: 0, + dabits: 0, + }, + {name:"dt3003", + device_id:0x24, + adchan: 64, + adbits: 12, + adrange: &range_dt3000_ai, + ai_speed:3000, + dachan: 2, + dabits: 12, + }, + {name:"dt3003-pgl", + device_id:0x28, + adchan: 64, + adbits: 12, + adrange: &range_dt3000_ai_pgl, + ai_speed:3000, + dachan: 2, + dabits: 12, + }, + {name:"dt3004", + device_id:0x25, + adchan: 16, + adbits: 16, + adrange: &range_dt3000_ai, + ai_speed:10000, + dachan: 2, + dabits: 12, + }, + {name:"dt3005", /* a.k.a. 3004-200 */ + device_id:0x26, + adchan: 16, + adbits: 16, + adrange: &range_dt3000_ai, + ai_speed:5000, + dachan: 2, + dabits: 12, + }, }; + #define n_dt3k_boards sizeof(dt3k_boardtypes)/sizeof(dt3k_boardtype) #define this_board ((const dt3k_boardtype *)dev->board_ptr) static struct pci_device_id dt3k_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_DT, 0x0022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0027, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0023, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0025, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_DT, 0x0026, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_DT, 0x0022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0027, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0023, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0025, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_DT, 0x0026, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, dt3k_pci_table); #define DT3000_SIZE (4*0x1000) @@ -235,7 +239,6 @@ MODULE_DEVICE_TABLE(pci, dt3k_pci_table); #define DT3000_ERROR 0xaa00 #define DT3000_NOTSUPPORTED 0xff00 - #define DT3000_EXTERNAL_CLOCK 1 #define DT3000_RISING_EDGE 2 @@ -250,7 +253,7 @@ MODULE_DEVICE_TABLE(pci, dt3k_pci_table); #define DT3000_CHANNEL_MODE_SE 0 #define DT3000_CHANNEL_MODE_DI 1 -typedef struct{ +typedef struct { struct pci_dev *pci_dev; resource_size_t phys_addr; void *io_addr; @@ -258,76 +261,75 @@ typedef struct{ lsampl_t ao_readback[2]; unsigned int ai_front; unsigned int ai_rear; -}dt3k_private; +} dt3k_private; #define devpriv ((dt3k_private *)dev->private) -static int dt3000_attach(comedi_device *dev,comedi_devconfig *it); -static int dt3000_detach(comedi_device *dev); -static comedi_driver driver_dt3000={ - driver_name: "dt3000", - module: THIS_MODULE, - attach: dt3000_attach, - detach: dt3000_detach, +static int dt3000_attach(comedi_device * dev, comedi_devconfig * it); +static int dt3000_detach(comedi_device * dev); +static comedi_driver driver_dt3000 = { + driver_name:"dt3000", + module:THIS_MODULE, + attach:dt3000_attach, + detach:dt3000_detach, }; -COMEDI_INITCLEANUP(driver_dt3000); +COMEDI_INITCLEANUP(driver_dt3000); -static void dt3k_ai_empty_fifo(comedi_device *dev,comedi_subdevice *s); +static void dt3k_ai_empty_fifo(comedi_device * dev, comedi_subdevice * s); static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *arg, unsigned int round_mode); -static int dt3k_ai_cancel(comedi_device *dev,comedi_subdevice *s); +static int dt3k_ai_cancel(comedi_device * dev, comedi_subdevice * s); #ifdef DEBUG static void debug_intr_flags(unsigned int flags); #endif - #define TIMEOUT 100 -static int dt3k_send_cmd(comedi_device *dev,unsigned int cmd) +static int dt3k_send_cmd(comedi_device * dev, unsigned int cmd) { int i; unsigned int status = 0; - writew(cmd,devpriv->io_addr+DPR_Command_Mbx); + writew(cmd, devpriv->io_addr + DPR_Command_Mbx); - for(i=0;iio_addr+DPR_Command_Mbx); - if((status&DT3000_COMPLETION_MASK)!=DT3000_NOTPROCESSED) + for (i = 0; i < TIMEOUT; i++) { + status = readw(devpriv->io_addr + DPR_Command_Mbx); + if ((status & DT3000_COMPLETION_MASK) != DT3000_NOTPROCESSED) break; comedi_udelay(1); } - if((status&DT3000_COMPLETION_MASK)==DT3000_NOERROR){ + if ((status & DT3000_COMPLETION_MASK) == DT3000_NOERROR) { return 0; } - printk("dt3k_send_cmd() timeout/error status=0x%04x\n",status); + printk("dt3k_send_cmd() timeout/error status=0x%04x\n", status); return -ETIME; } -static unsigned int dt3k_readsingle(comedi_device *dev,unsigned int subsys, - unsigned int chan,unsigned int gain) +static unsigned int dt3k_readsingle(comedi_device * dev, unsigned int subsys, + unsigned int chan, unsigned int gain) { - writew(subsys,devpriv->io_addr+DPR_SubSys); + writew(subsys, devpriv->io_addr + DPR_SubSys); - writew(chan,devpriv->io_addr+DPR_Params(0)); - writew(gain,devpriv->io_addr+DPR_Params(1)); + writew(chan, devpriv->io_addr + DPR_Params(0)); + writew(gain, devpriv->io_addr + DPR_Params(1)); - dt3k_send_cmd(dev,CMD_READSINGLE); + dt3k_send_cmd(dev, CMD_READSINGLE); - return readw(devpriv->io_addr+DPR_Params(2)); + return readw(devpriv->io_addr + DPR_Params(2)); } -static void dt3k_writesingle(comedi_device *dev,unsigned int subsys, - unsigned int chan,unsigned int data) +static void dt3k_writesingle(comedi_device * dev, unsigned int subsys, + unsigned int chan, unsigned int data) { - writew(subsys,devpriv->io_addr+DPR_SubSys); + writew(subsys, devpriv->io_addr + DPR_SubSys); - writew(chan,devpriv->io_addr+DPR_Params(0)); - writew(0,devpriv->io_addr+DPR_Params(1)); - writew(data,devpriv->io_addr+DPR_Params(2)); + writew(chan, devpriv->io_addr + DPR_Params(0)); + writew(0, devpriv->io_addr + DPR_Params(1)); + writew(data, devpriv->io_addr + DPR_Params(2)); - dt3k_send_cmd(dev,CMD_WRITESINGLE); + dt3k_send_cmd(dev, CMD_WRITESINGLE); } static int debug_n_ints = 0; @@ -340,29 +342,28 @@ static irqreturn_t dt3k_interrupt(int irq, void *d PT_REGS_ARG) comedi_subdevice *s; unsigned int status; - if (!dev->attached) - { + if (!dev->attached) { return IRQ_NONE; } s = dev->subdevices + 0; - status = readw(devpriv->io_addr+DPR_Intr_Flag); + status = readw(devpriv->io_addr + DPR_Intr_Flag); #ifdef DEBUG debug_intr_flags(status); #endif - if(status & DT3000_ADFULL){ - dt3k_ai_empty_fifo(dev,s); + if (status & DT3000_ADFULL) { + dt3k_ai_empty_fifo(dev, s); s->async->events |= COMEDI_CB_BLOCK; } - if(status & (DT3000_ADSWERR | DT3000_ADHWERR)){ + if (status & (DT3000_ADSWERR | DT3000_ADHWERR)) { s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; } debug_n_ints++; - if(debug_n_ints>=10){ - dt3k_ai_cancel(dev,s); + if (debug_n_ints >= 10) { + dt3k_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; } @@ -379,16 +380,16 @@ static void debug_intr_flags(unsigned int flags) { int i; printk("dt3k: intr_flags:"); - for(i=0;i<8;i++){ - if(flags & (1<io_addr + DPR_AD_Buf_Front); count = front - devpriv->ai_front; - if(count<0)count += AI_FIFO_DEPTH; + if (count < 0) + count += AI_FIFO_DEPTH; -printk("reading %d samples\n",count); + printk("reading %d samples\n", count); rear = devpriv->ai_rear; - for(i=0;iio_addr + DPR_ADC_buffer + rear); comedi_buf_put(s->async, data); rear++; - if(rear>=AI_FIFO_DEPTH)rear = 0; + if (rear >= AI_FIFO_DEPTH) + rear = 0; } devpriv->ai_rear = rear; - writew(rear,devpriv->io_addr + DPR_AD_Buf_Rear); + writew(rear, devpriv->io_addr + DPR_AD_Buf_Rear); } - -static int dt3k_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int dt3k_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_arg < this_board->ai_speed){ + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < this_board->ai_speed) { cmd->scan_begin_arg = this_board->ai_speed; err++; } - if(cmd->scan_begin_arg > 100*16*65535){ - cmd->scan_begin_arg = 100*16*65535; + if (cmd->scan_begin_arg > 100 * 16 * 65535) { + cmd->scan_begin_arg = 100 * 16 * 65535; err++; } - }else{ + } else { /* not supported */ } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_arg < this_board->ai_speed){ + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_speed) { cmd->convert_arg = this_board->ai_speed; err++; } - if(cmd->convert_arg > 50*16*65535){ - cmd->convert_arg = 50*16*65535; + if (cmd->convert_arg > 50 * 16 * 65535) { + cmd->convert_arg = 50 * 16 * 65535; err++; } - }else{ + } else { /* not supported */ } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0x00ffffff) { + cmd->stop_arg = 0x00ffffff; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; - dt3k_ns_to_timer(100,&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; - }else{ + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + dt3k_ns_to_timer(100, &cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; + } else { /* not supported */ } - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - dt3k_ns_to_timer(50,&cmd->convert_arg, - cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg){ - cmd->scan_begin_arg = cmd->convert_arg * cmd->scan_end_arg; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + dt3k_ns_to_timer(50, &cmd->convert_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++; } - }else{ + } else { /* not supported */ } - if(err)return 4; + if (err) + return 4; return 0; } - static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, unsigned int round_mode) { @@ -539,402 +553,407 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, /* This function needs improvment */ /* Don't know if divider==0 works. */ - for(prescale=0;prescale<16;prescale++){ - base = timer_base * (prescale+1); - switch(round_mode){ + for (prescale = 0; prescale < 16; prescale++) { + base = timer_base * (prescale + 1); + switch (round_mode) { case TRIG_ROUND_NEAREST: default: - divider = (*nanosec+base/2)/base; + divider = (*nanosec + base / 2) / base; break; case TRIG_ROUND_DOWN: - divider = (*nanosec)/base; + divider = (*nanosec) / base; break; case TRIG_ROUND_UP: - divider = (*nanosec)/base; + divider = (*nanosec) / base; break; } - if(divider<65536){ - *nanosec = divider*base; - return (prescale<<16)|(divider); + if (divider < 65536) { + *nanosec = divider * base; + return (prescale << 16) | (divider); } } prescale = 15; - base = timer_base * (1<async->cmd; int i; - unsigned int chan,range,aref; + unsigned int chan, range, aref; unsigned int divider; unsigned int tscandiv; int ret; unsigned int mode; -printk("dt3k_ai_cmd:\n"); - for(i=0;ichanlist_len;i++){ - chan=CR_CHAN(cmd->chanlist[i]); - range=CR_RANGE(cmd->chanlist[i]); + printk("dt3k_ai_cmd:\n"); + for (i = 0; i < cmd->chanlist_len; i++) { + chan = CR_CHAN(cmd->chanlist[i]); + range = CR_RANGE(cmd->chanlist[i]); - writew((range<<6)|chan,devpriv->io_addr+DPR_ADC_buffer+i); + writew((range << 6) | chan, + devpriv->io_addr + DPR_ADC_buffer + i); } - aref=CR_AREF(cmd->chanlist[0]); - - writew(cmd->scan_end_arg,devpriv->io_addr+DPR_Params(0)); -printk("param[0]=0x%04x\n",cmd->scan_end_arg); - - if(cmd->convert_src==TRIG_TIMER){ - divider = dt3k_ns_to_timer(50,&cmd->convert_arg, - cmd->flags&TRIG_ROUND_MASK); - writew((divider>>16),devpriv->io_addr+DPR_Params(1)); -printk("param[1]=0x%04x\n",divider>>16); - writew((divider&0xffff),devpriv->io_addr+DPR_Params(2)); -printk("param[2]=0x%04x\n",divider&0xffff); - }else{ + aref = CR_AREF(cmd->chanlist[0]); + + writew(cmd->scan_end_arg, devpriv->io_addr + DPR_Params(0)); + printk("param[0]=0x%04x\n", cmd->scan_end_arg); + + if (cmd->convert_src == TRIG_TIMER) { + divider = dt3k_ns_to_timer(50, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + writew((divider >> 16), devpriv->io_addr + DPR_Params(1)); + printk("param[1]=0x%04x\n", divider >> 16); + writew((divider & 0xffff), devpriv->io_addr + DPR_Params(2)); + printk("param[2]=0x%04x\n", divider & 0xffff); + } else { /* not supported */ } - if(cmd->scan_begin_src==TRIG_TIMER){ - tscandiv = dt3k_ns_to_timer(100,&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - writew((tscandiv>>16),devpriv->io_addr+DPR_Params(3)); -printk("param[3]=0x%04x\n",tscandiv>>16); - writew((tscandiv&0xffff),devpriv->io_addr+DPR_Params(4)); -printk("param[4]=0x%04x\n",tscandiv&0xffff); - }else{ + if (cmd->scan_begin_src == TRIG_TIMER) { + tscandiv = dt3k_ns_to_timer(100, &cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + writew((tscandiv >> 16), devpriv->io_addr + DPR_Params(3)); + printk("param[3]=0x%04x\n", tscandiv >> 16); + writew((tscandiv & 0xffff), devpriv->io_addr + DPR_Params(4)); + printk("param[4]=0x%04x\n", tscandiv & 0xffff); + } else { /* not supported */ } mode = DT3000_AD_RETRIG_INTERNAL | 0 | 0; - writew(mode,devpriv->io_addr+DPR_Params(5)); -printk("param[5]=0x%04x\n",mode); - writew(aref==AREF_DIFF,devpriv->io_addr+DPR_Params(6)); -printk("param[6]=0x%04x\n",aref==AREF_DIFF); + writew(mode, devpriv->io_addr + DPR_Params(5)); + printk("param[5]=0x%04x\n", mode); + writew(aref == AREF_DIFF, devpriv->io_addr + DPR_Params(6)); + printk("param[6]=0x%04x\n", aref == AREF_DIFF); - writew(AI_FIFO_DEPTH/2,devpriv->io_addr+DPR_Params(7)); -printk("param[7]=0x%04x\n",AI_FIFO_DEPTH/2); + writew(AI_FIFO_DEPTH / 2, devpriv->io_addr + DPR_Params(7)); + printk("param[7]=0x%04x\n", AI_FIFO_DEPTH / 2); - writew(SUBS_AI,devpriv->io_addr+DPR_SubSys); - ret = dt3k_send_cmd(dev,CMD_CONFIG); + writew(SUBS_AI, devpriv->io_addr + DPR_SubSys); + ret = dt3k_send_cmd(dev, CMD_CONFIG); writew(DT3000_ADFULL | DT3000_ADSWERR | DT3000_ADHWERR, devpriv->io_addr + DPR_Int_Mask); -debug_n_ints = 0; + debug_n_ints = 0; - writew(SUBS_AI,devpriv->io_addr+DPR_SubSys); - ret = dt3k_send_cmd(dev,CMD_START); + writew(SUBS_AI, devpriv->io_addr + DPR_SubSys); + ret = dt3k_send_cmd(dev, CMD_START); return 0; } -static int dt3k_ai_cancel(comedi_device *dev,comedi_subdevice *s) +static int dt3k_ai_cancel(comedi_device * dev, comedi_subdevice * s) { int ret; - writew(SUBS_AI,devpriv->io_addr+DPR_SubSys); - ret = dt3k_send_cmd(dev,CMD_STOP); + writew(SUBS_AI, devpriv->io_addr + DPR_SubSys); + ret = dt3k_send_cmd(dev, CMD_STOP); writew(0, devpriv->io_addr + DPR_Int_Mask); return 0; } -static int dt3k_ai_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_ai_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; - unsigned int chan,gain,aref; + unsigned int chan, gain, aref; - chan=CR_CHAN(insn->chanspec); - gain=CR_RANGE(insn->chanspec); + chan = CR_CHAN(insn->chanspec); + gain = CR_RANGE(insn->chanspec); /* XXX docs don't explain how to select aref */ - aref=CR_AREF(insn->chanspec); + aref = CR_AREF(insn->chanspec); - for(i=0;in;i++){ - data[i]=dt3k_readsingle(dev,SUBS_AI,chan,gain); + for (i = 0; i < insn->n; i++) { + data[i] = dt3k_readsingle(dev, SUBS_AI, chan, gain); } return i; } -static int dt3k_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; unsigned int chan; - chan=CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - dt3k_writesingle(dev,SUBS_AO,chan,data[i]); - devpriv->ao_readback[chan]=data[i]; + chan = CR_CHAN(insn->chanspec); + for (i = 0; i < insn->n; i++) { + dt3k_writesingle(dev, SUBS_AO, chan, data[i]); + devpriv->ao_readback[chan] = data[i]; } return i; } -static int dt3k_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; unsigned int chan; - chan=CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[chan]; + chan = CR_CHAN(insn->chanspec); + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[chan]; } return i; } -static void dt3k_dio_config(comedi_device *dev,int bits) +static void dt3k_dio_config(comedi_device * dev, int bits) { /* XXX */ - writew(SUBS_DOUT,devpriv->io_addr+DPR_SubSys); + writew(SUBS_DOUT, devpriv->io_addr + DPR_SubSys); - writew(bits,devpriv->io_addr+DPR_Params(0)); + writew(bits, devpriv->io_addr + DPR_Params(0)); #if 0 /* don't know */ - writew(0,devpriv->io_addr+DPR_Params(1)); - writew(0,devpriv->io_addr+DPR_Params(2)); + writew(0, devpriv->io_addr + DPR_Params(1)); + writew(0, devpriv->io_addr + DPR_Params(2)); #endif - dt3k_send_cmd(dev,CMD_CONFIG); + dt3k_send_cmd(dev, CMD_CONFIG); } -static int dt3k_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int mask; - mask=(CR_CHAN(insn->chanspec)<4)?0x0f:0xf0; + mask = (CR_CHAN(insn->chanspec) < 4) ? 0x0f : 0xf0; - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits|=mask; + s->io_bits |= mask; break; case INSN_CONFIG_DIO_INPUT: - s->io_bits&=~mask; + s->io_bits &= ~mask; break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1 << CR_CHAN(insn->chanspec))) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s->io_bits & (1 << CR_CHAN(insn-> + chanspec))) ? COMEDI_OUTPUT : + COMEDI_INPUT; return insn->n; break; default: return -EINVAL; break; } - mask=(s->io_bits&0x01)|((s->io_bits&0x10)>>3); - dt3k_dio_config(dev,mask); + mask = (s->io_bits & 0x01) | ((s->io_bits & 0x10) >> 3); + dt3k_dio_config(dev, mask); return insn->n; } -static int dt3k_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[1]&data[0]; - dt3k_writesingle(dev,SUBS_DOUT,0,s->state); + s->state |= data[1] & data[0]; + dt3k_writesingle(dev, SUBS_DOUT, 0, s->state); } - data[1]=dt3k_readsingle(dev,SUBS_DIN,0,0); + data[1] = dt3k_readsingle(dev, SUBS_DIN, 0, 0); return 2; } -static int dt3k_mem_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int dt3k_mem_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - unsigned int addr=CR_CHAN(insn->chanspec); + unsigned int addr = CR_CHAN(insn->chanspec); int i; - for(i=0;in;i++){ - writew(SUBS_MEM,devpriv->io_addr+DPR_SubSys); - writew(addr,devpriv->io_addr+DPR_Params(0)); - writew(1,devpriv->io_addr+DPR_Params(1)); + for (i = 0; i < insn->n; i++) { + writew(SUBS_MEM, devpriv->io_addr + DPR_SubSys); + writew(addr, devpriv->io_addr + DPR_Params(0)); + writew(1, devpriv->io_addr + DPR_Params(1)); - dt3k_send_cmd(dev,CMD_READCODE); + dt3k_send_cmd(dev, CMD_READCODE); - data[i]=readw(devpriv->io_addr+DPR_Params(2)); + data[i] = readw(devpriv->io_addr + DPR_Params(2)); } return i; } -static int dt_pci_probe(comedi_device *dev); +static int dt_pci_probe(comedi_device * dev); -static int dt3000_attach(comedi_device *dev,comedi_devconfig *it) +static int dt3000_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int ret=0; + int ret = 0; printk("dt3000:"); - if((ret=alloc_private(dev,sizeof(dt3k_private)))<0) + if ((ret = alloc_private(dev, sizeof(dt3k_private))) < 0) return ret; - ret=dt_pci_probe(dev); - if(ret<0)return ret; - if(ret==0){ + ret = dt_pci_probe(dev); + if (ret < 0) + return ret; + if (ret == 0) { printk(" no DT board found\n"); return -ENODEV; } dev->board_name = this_board->name; - if(comedi_request_irq(devpriv->pci_dev->irq, dt3k_interrupt, - IRQF_SHARED, "dt3000", dev)){ + if (comedi_request_irq(devpriv->pci_dev->irq, dt3k_interrupt, + IRQF_SHARED, "dt3000", dev)) { printk(" unable to allocate IRQ %u\n", devpriv->pci_dev->irq); return -EINVAL; } dev->irq = devpriv->pci_dev->irq; - if( (ret = alloc_subdevices(dev, 4)) <0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; - s=dev->subdevices; + s = dev->subdevices; dev->read_subdev = s; /* ai subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - s->n_chan=this_board->adchan; - s->insn_read=dt3k_ai_insn; - s->maxdata=(1<adbits)-1; - s->len_chanlist=512; - s->range_table=&range_dt3000_ai; /* XXX */ + s->n_chan = this_board->adchan; + s->insn_read = dt3k_ai_insn; + s->maxdata = (1 << this_board->adbits) - 1; + s->len_chanlist = 512; + s->range_table = &range_dt3000_ai; /* XXX */ s->do_cmd = dt3k_ai_cmd; s->do_cmdtest = dt3k_ai_cmdtest; s->cancel = dt3k_ai_cancel; s++; /* ao subsystem */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=2; - s->insn_read=dt3k_ao_insn_read; - s->insn_write=dt3k_ao_insn; - s->maxdata=(1<dabits)-1; - s->len_chanlist=1; - s->range_table=&range_bipolar10; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->insn_read = dt3k_ao_insn_read; + s->insn_write = dt3k_ao_insn; + s->maxdata = (1 << this_board->dabits) - 1; + s->len_chanlist = 1; + s->range_table = &range_bipolar10; s++; /* dio subsystem */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->insn_config=dt3k_dio_insn_config; - s->insn_bits=dt3k_dio_insn_bits; - s->maxdata=1; - s->len_chanlist=8; - s->range_table=&range_digital; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->insn_config = dt3k_dio_insn_config; + s->insn_bits = dt3k_dio_insn_bits; + s->maxdata = 1; + s->len_chanlist = 8; + s->range_table = &range_digital; s++; /* mem subsystem */ - s->type=COMEDI_SUBD_MEMORY; - s->subdev_flags=SDF_READABLE; - s->n_chan=0x1000; - s->insn_read=dt3k_mem_insn_read; - s->maxdata=0xff; - s->len_chanlist=1; - s->range_table=&range_unknown; + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE; + s->n_chan = 0x1000; + s->insn_read = dt3k_mem_insn_read; + s->maxdata = 0xff; + s->len_chanlist = 1; + s->range_table = &range_unknown; #if 0 s++; /* proc subsystem */ - s->type=COMEDI_SUBD_PROC; + s->type = COMEDI_SUBD_PROC; #endif return 0; } -static int dt3000_detach(comedi_device *dev) +static int dt3000_detach(comedi_device * dev) { - if(dev->irq)comedi_free_irq(dev->irq,dev); - - if(devpriv) - { - if(devpriv->pci_dev) - { - if(devpriv->phys_addr) - { + if (dev->irq) + comedi_free_irq(dev->irq, dev); + + if (devpriv) { + if (devpriv->pci_dev) { + if (devpriv->phys_addr) { comedi_pci_disable(devpriv->pci_dev); } pci_dev_put(devpriv->pci_dev); } - if(devpriv->io_addr) iounmap(devpriv->io_addr); + if (devpriv->io_addr) + iounmap(devpriv->io_addr); } /* XXX */ return 0; } +static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board); +static int setup_pci(comedi_device * dev); -static struct pci_dev *dt_pci_find_device(struct pci_dev *from,int *board); -static int setup_pci(comedi_device *dev); - -static int dt_pci_probe(comedi_device *dev) +static int dt_pci_probe(comedi_device * dev) { int board; int ret; - devpriv->pci_dev=dt_pci_find_device(NULL,&board); - if(board >= 0) - dev->board_ptr=dt3k_boardtypes+board; + devpriv->pci_dev = dt_pci_find_device(NULL, &board); + if (board >= 0) + dev->board_ptr = dt3k_boardtypes + board; - if(!devpriv->pci_dev) + if (!devpriv->pci_dev) return 0; - if ((ret=setup_pci(dev)) < 0) + if ((ret = setup_pci(dev)) < 0) return ret; return 1; } -static int setup_pci(comedi_device *dev) +static int setup_pci(comedi_device * dev) { - resource_size_t addr; + resource_size_t addr; int ret; ret = comedi_pci_enable(devpriv->pci_dev, "dt3000"); - if(ret<0)return ret; + if (ret < 0) + return ret; - addr=pci_resource_start(devpriv->pci_dev,0); - devpriv->phys_addr=addr; + addr = pci_resource_start(devpriv->pci_dev, 0); + devpriv->phys_addr = addr; devpriv->io_addr = ioremap(devpriv->phys_addr, DT3000_SIZE); - if(!devpriv->io_addr) return -ENOMEM; + if (!devpriv->io_addr) + return -ENOMEM; #if DEBUG - printk("0x%08llx mapped to %p, ",(unsigned long long)devpriv->phys_addr,devpriv->io_addr); + printk("0x%08llx mapped to %p, ", + (unsigned long long)devpriv->phys_addr, devpriv->io_addr); #endif return 0; } -static struct pci_dev *dt_pci_find_device(struct pci_dev *from,int *board) +static struct pci_dev *dt_pci_find_device(struct pci_dev *from, int *board) { int i; - for(from=pci_get_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from); from!=NULL; - from=pci_get_device(PCI_VENDOR_ID_DT,PCI_ANY_ID,from)){ - for(i=0;idevice == dt3k_boardtypes[i].device_id){ - *board=i; + for (from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from); + from != NULL; + from = pci_get_device(PCI_VENDOR_ID_DT, PCI_ANY_ID, from)) { + for (i = 0; i < n_dt3k_boards; i++) { + if (from->device == dt3k_boardtypes[i].device_id) { + *board = i; return from; } } - printk("unknown Data Translation PCI device found with device_id=0x%04x\n",from->device); + printk("unknown Data Translation PCI device found with device_id=0x%04x\n", from->device); } - *board=-1; + *board = -1; return from; } - diff --git a/comedi/drivers/dt9812.c b/comedi/drivers/dt9812.c index e83ebd49..24177068 100644 --- a/comedi/drivers/dt9812.c +++ b/comedi/drivers/dt9812.c @@ -58,65 +58,64 @@ for my needs. #include #include "dt9812.h" - #define DT9812_NUM_SLOTS 16 static DECLARE_MUTEX(dt9812_mutex); -static struct usb_device_id dt9812_table [] = { - { USB_DEVICE(0x0867, 0x9812) }, - { } /* Terminating entry */ +static struct usb_device_id dt9812_table[] = { + {USB_DEVICE(0x0867, 0x9812)}, + {} /* Terminating entry */ }; -MODULE_DEVICE_TABLE (usb, dt9812_table); +MODULE_DEVICE_TABLE(usb, dt9812_table); typedef struct usb_dt9812 { - struct slot_dt9812 *slot; - struct usb_device *udev; - struct usb_interface *interface; - u16 vendor; - u16 product; - u16 device; - u32 serial; - struct { - __u8 addr; - size_t size; - } message_pipe, command_write, command_read, write_stream, read_stream; - struct kref kref; - u16 analog_out_shadow[2]; - u8 digital_out_shadow; + struct slot_dt9812 *slot; + struct usb_device *udev; + struct usb_interface *interface; + u16 vendor; + u16 product; + u16 device; + u32 serial; + struct { + __u8 addr; + size_t size; + } message_pipe, command_write, command_read, write_stream, read_stream; + struct kref kref; + u16 analog_out_shadow[2]; + u8 digital_out_shadow; } usb_dt9812_t; typedef struct comedi_dt9812 { - struct slot_dt9812 *slot; - u32 serial; + struct slot_dt9812 *slot; + u32 serial; } comedi_dt9812_t; typedef struct slot_dt9812 { - struct semaphore mutex; - u32 serial; - usb_dt9812_t *usb; - comedi_dt9812_t *comedi; + struct semaphore mutex; + u32 serial; + usb_dt9812_t *usb; + comedi_dt9812_t *comedi; } slot_dt9812_t; -static const comedi_lrange dt9812_10_ain_range={ 1, { - BIP_RANGE(10), - } +static const comedi_lrange dt9812_10_ain_range = { 1, { + BIP_RANGE(10), + } }; -static const comedi_lrange dt9812_2pt5_ain_range={ 1, { - UNI_RANGE(2.5), - } +static const comedi_lrange dt9812_2pt5_ain_range = { 1, { + UNI_RANGE(2.5), + } }; -static const comedi_lrange dt9812_10_aout_range={ 1, { - BIP_RANGE(10), - } +static const comedi_lrange dt9812_10_aout_range = { 1, { + BIP_RANGE(10), + } }; -static const comedi_lrange dt9812_2pt5_aout_range={ 1, { - UNI_RANGE(2.5), - } +static const comedi_lrange dt9812_2pt5_aout_range = { 1, { + UNI_RANGE(2.5), + } }; static slot_dt9812_t dt9812[DT9812_NUM_SLOTS]; @@ -124,826 +123,836 @@ static slot_dt9812_t dt9812[DT9812_NUM_SLOTS]; // Useful shorthand access to private data #define devpriv ((comedi_dt9812_t *)dev->private) - -static inline usb_dt9812_t *to_dt9812_dev(struct kref *d) +static inline usb_dt9812_t *to_dt9812_dev(struct kref *d) { - return container_of(d, usb_dt9812_t, kref); + return container_of(d, usb_dt9812_t, kref); } static void dt9812_delete(struct kref *kref) -{ - usb_dt9812_t *dev = to_dt9812_dev(kref); +{ + usb_dt9812_t *dev = to_dt9812_dev(kref); - usb_put_dev(dev->udev); - kfree (dev); + usb_put_dev(dev->udev); + kfree(dev); } -static int dt9812_read_info(usb_dt9812_t *dev, - int offset, void *buf, size_t buf_size) -{ - dt9812_usb_cmd_t cmd; - int count, retval; - - cmd.cmd = cpu_to_le32(DT9812_R_FLASH_DATA); - cmd.u.flash_data_info.address = - cpu_to_le16(DT9812_DIAGS_BOARD_INFO_ADDR + offset); - cmd.u.flash_data_info.numbytes = cpu_to_le16(buf_size); - - count = 32; - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->command_write.addr), - &cmd, - 32, // DT9812 only responds to 32 byte writes!! - &count, HZ*1); - if (retval == 0) { - retval = usb_bulk_msg(dev->udev, - usb_rcvbulkpipe(dev->udev, dev->command_read.addr), - buf, - buf_size, - &count, HZ*1); - } - return retval; +static int dt9812_read_info(usb_dt9812_t * dev, + int offset, void *buf, size_t buf_size) +{ + dt9812_usb_cmd_t cmd; + int count, retval; + + cmd.cmd = cpu_to_le32(DT9812_R_FLASH_DATA); + cmd.u.flash_data_info.address = + cpu_to_le16(DT9812_DIAGS_BOARD_INFO_ADDR + offset); + cmd.u.flash_data_info.numbytes = cpu_to_le16(buf_size); + + count = 32; + retval = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->command_write.addr), &cmd, 32, // DT9812 only responds to 32 byte writes!! + &count, HZ * 1); + if (retval == 0) { + retval = usb_bulk_msg(dev->udev, + usb_rcvbulkpipe(dev->udev, dev->command_read.addr), + buf, buf_size, &count, HZ * 1); + } + return retval; } -static int dt9812_read_multiple_registers(usb_dt9812_t *dev, - int reg_count, - u8 *address, - u8 *value) +static int dt9812_read_multiple_registers(usb_dt9812_t * dev, + int reg_count, u8 * address, u8 * value) { - dt9812_usb_cmd_t cmd; - int i, count, retval; - - cmd.cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG); - cmd.u.read_multi_info.count = reg_count; - for (i = 0 ; i < reg_count ; i++) { - cmd.u.read_multi_info.address[i] = address[i]; - } - count = 32; - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->command_write.addr), - &cmd, - 32, // DT9812 only responds to 32 byte writes!! - &count, HZ*1); - if (retval == 0) { - retval = usb_bulk_msg(dev->udev, - usb_rcvbulkpipe(dev->udev, dev->command_read.addr), - value, - reg_count, - &count, HZ*1); - } - return retval; -} + dt9812_usb_cmd_t cmd; + int i, count, retval; -static int dt9812_write_multiple_registers(usb_dt9812_t *dev, - int reg_count, - u8 *address, - u8 *value) + cmd.cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG); + cmd.u.read_multi_info.count = reg_count; + for (i = 0; i < reg_count; i++) { + cmd.u.read_multi_info.address[i] = address[i]; + } + count = 32; + retval = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->command_write.addr), &cmd, 32, // DT9812 only responds to 32 byte writes!! + &count, HZ * 1); + if (retval == 0) { + retval = usb_bulk_msg(dev->udev, + usb_rcvbulkpipe(dev->udev, dev->command_read.addr), + value, reg_count, &count, HZ * 1); + } + return retval; +} +static int dt9812_write_multiple_registers(usb_dt9812_t * dev, + int reg_count, u8 * address, u8 * value) { - dt9812_usb_cmd_t cmd; - int i, count, retval; - - cmd.cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG); - cmd.u.read_multi_info.count = reg_count; - for (i = 0 ; i < reg_count ; i++) { - cmd.u.write_multi_info.write[i].address = address[i]; - cmd.u.write_multi_info.write[i].value = value[i]; - } - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->command_write.addr), - &cmd, - 32, // DT9812 only responds to 32 byte writes!! - &count, HZ*1); - return retval; + dt9812_usb_cmd_t cmd; + int i, count, retval; + + cmd.cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG); + cmd.u.read_multi_info.count = reg_count; + for (i = 0; i < reg_count; i++) { + cmd.u.write_multi_info.write[i].address = address[i]; + cmd.u.write_multi_info.write[i].value = value[i]; + } + retval = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->command_write.addr), &cmd, 32, // DT9812 only responds to 32 byte writes!! + &count, HZ * 1); + return retval; } - -static int dt9812_rmw_multiple_registers(usb_dt9812_t *dev, - int reg_count, - dt9812_rmw_byte_t rmw[]) + +static int dt9812_rmw_multiple_registers(usb_dt9812_t * dev, + int reg_count, dt9812_rmw_byte_t rmw[]) { - dt9812_usb_cmd_t cmd; - int i, count, retval; - - cmd.cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG); - cmd.u.rmw_multi_info.count = reg_count; - for (i = 0 ; i < reg_count ; i++) { - cmd.u.rmw_multi_info.rmw[i] = rmw[i]; - } - retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->command_write.addr), - &cmd, - 32, // DT9812 only responds to 32 byte writes!! - &count, HZ*1); - return retval; + dt9812_usb_cmd_t cmd; + int i, count, retval; + + cmd.cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG); + cmd.u.rmw_multi_info.count = reg_count; + for (i = 0; i < reg_count; i++) { + cmd.u.rmw_multi_info.rmw[i] = rmw[i]; + } + retval = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->command_write.addr), &cmd, 32, // DT9812 only responds to 32 byte writes!! + &count, HZ * 1); + return retval; } - -static int dt9812_digital_in(slot_dt9812_t *slot, u8 *bits) + +static int dt9812_digital_in(slot_dt9812_t * slot, u8 * bits) { - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 }; - u8 value[2]; - - result = dt9812_read_multiple_registers(slot->usb, 2, reg, value); - if (result == 0) { - // bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital input port - // bit 3 in F020_SFR_P1 is bit 7 in the digital input port - *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); + int result = -ENODEV; + + down(&slot->mutex); + if (slot->usb) { + u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 }; + u8 value[2]; + + result = dt9812_read_multiple_registers(slot->usb, 2, reg, + value); + if (result == 0) { + // bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital input port + // bit 3 in F020_SFR_P1 is bit 7 in the digital input port + *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); // printk("%2.2x, %2.2x -> %2.2x\n", value[0], value[1], *bits); - } - } - up(&slot->mutex); - - return result; + } + } + up(&slot->mutex); + + return result; } -static int dt9812_digital_out(slot_dt9812_t *slot, u8 bits) +static int dt9812_digital_out(slot_dt9812_t * slot, u8 bits) { - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - u8 reg[1]; - u8 value[1]; - - reg[0] = F020_SFR_P2; - value[0] = bits; - result = dt9812_write_multiple_registers(slot->usb, 1, reg, value); - slot->usb->digital_out_shadow = bits; - } - up(&slot->mutex); - return result; + int result = -ENODEV; + + down(&slot->mutex); + if (slot->usb) { + u8 reg[1]; + u8 value[1]; + + reg[0] = F020_SFR_P2; + value[0] = bits; + result = dt9812_write_multiple_registers(slot->usb, 1, reg, + value); + slot->usb->digital_out_shadow = bits; + } + up(&slot->mutex); + return result; } -static int dt9812_digital_out_shadow(slot_dt9812_t *slot, u8 *bits) +static int dt9812_digital_out_shadow(slot_dt9812_t * slot, u8 * bits) { - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - *bits = slot->usb->digital_out_shadow; - result = 0; - } - up(&slot->mutex); - return result; + int result = -ENODEV; + + down(&slot->mutex); + if (slot->usb) { + *bits = slot->usb->digital_out_shadow; + result = 0; + } + up(&slot->mutex); + return result; } -static void dt9812_configure_mux(usb_dt9812_t *dev, - dt9812_rmw_byte_t *rmw, - int channel) +static void dt9812_configure_mux(usb_dt9812_t * dev, + dt9812_rmw_byte_t * rmw, int channel) { - if (dev->device == DT9812_DEVID_DT9812_10) { - // In the DT9812/10V MUX is selected by P1.5-7 - rmw->address = F020_SFR_P1; - rmw->and_mask = 0xe0; - rmw->or_value = channel << 5; - } else { - // In the DT9812/2.5V, the internal mux is selected by bits 0:2 - rmw->address = F020_SFR_AMX0SL; - rmw->and_mask = 0xff; - rmw->or_value = channel & 0x07; - } + if (dev->device == DT9812_DEVID_DT9812_10) { + // In the DT9812/10V MUX is selected by P1.5-7 + rmw->address = F020_SFR_P1; + rmw->and_mask = 0xe0; + rmw->or_value = channel << 5; + } else { + // In the DT9812/2.5V, the internal mux is selected by bits 0:2 + rmw->address = F020_SFR_AMX0SL; + rmw->and_mask = 0xff; + rmw->or_value = channel & 0x07; + } } -static void dt9812_configure_gain(usb_dt9812_t *dev, - dt9812_rmw_byte_t *rmw, - dt9812_gain_t gain) +static void dt9812_configure_gain(usb_dt9812_t * dev, + dt9812_rmw_byte_t * rmw, dt9812_gain_t gain) { - if (dev->device == DT9812_DEVID_DT9812_10) { - // In the DT9812/10V, there is an external gain of 0.5 - gain <<= 1; - } - - rmw->address = F020_SFR_ADC0CF; - rmw->and_mask = - F020_MASK_ADC0CF_AMP0GN2 | - F020_MASK_ADC0CF_AMP0GN1 | - F020_MASK_ADC0CF_AMP0GN0; - switch (gain) { - // 000 -> Gain = 1 - // 001 -> Gain = 2 - // 010 -> Gain = 4 - // 011 -> Gain = 8 - // 10x -> Gain = 16 - // 11x -> Gain = 0.5 - case DT9812_GAIN_0PT5: { - rmw->or_value = F020_MASK_ADC0CF_AMP0GN2 || F020_MASK_ADC0CF_AMP0GN1; - } break; - case DT9812_GAIN_1: { - rmw->or_value = 0x00; - } break; - case DT9812_GAIN_2: { - rmw->or_value = F020_MASK_ADC0CF_AMP0GN0; - } break; - case DT9812_GAIN_4: { - rmw->or_value = F020_MASK_ADC0CF_AMP0GN1; - } break; - case DT9812_GAIN_8: { - rmw->or_value = F020_MASK_ADC0CF_AMP0GN1 || F020_MASK_ADC0CF_AMP0GN0; - } break; - case DT9812_GAIN_16: { - rmw->or_value = F020_MASK_ADC0CF_AMP0GN2; - } break; - default: { - err("Illegal gain %d\n", gain); - } - } + if (dev->device == DT9812_DEVID_DT9812_10) { + // In the DT9812/10V, there is an external gain of 0.5 + gain <<= 1; + } + + rmw->address = F020_SFR_ADC0CF; + rmw->and_mask = + F020_MASK_ADC0CF_AMP0GN2 | + F020_MASK_ADC0CF_AMP0GN1 | F020_MASK_ADC0CF_AMP0GN0; + switch (gain) { + // 000 -> Gain = 1 + // 001 -> Gain = 2 + // 010 -> Gain = 4 + // 011 -> Gain = 8 + // 10x -> Gain = 16 + // 11x -> Gain = 0.5 + case DT9812_GAIN_0PT5:{ + rmw->or_value = F020_MASK_ADC0CF_AMP0GN2 + || F020_MASK_ADC0CF_AMP0GN1; + } + break; + case DT9812_GAIN_1:{ + rmw->or_value = 0x00; + } + break; + case DT9812_GAIN_2:{ + rmw->or_value = F020_MASK_ADC0CF_AMP0GN0; + } + break; + case DT9812_GAIN_4:{ + rmw->or_value = F020_MASK_ADC0CF_AMP0GN1; + } + break; + case DT9812_GAIN_8:{ + rmw->or_value = F020_MASK_ADC0CF_AMP0GN1 + || F020_MASK_ADC0CF_AMP0GN0; + } + break; + case DT9812_GAIN_16:{ + rmw->or_value = F020_MASK_ADC0CF_AMP0GN2; + } + break; + default:{ + err("Illegal gain %d\n", gain); + } + } } -static int dt9812_analog_in(slot_dt9812_t *slot, - int channel, - u16 *value, - dt9812_gain_t gain) +static int dt9812_analog_in(slot_dt9812_t * slot, + int channel, u16 * value, dt9812_gain_t gain) { - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - dt9812_rmw_byte_t rmw[3]; - - // 1 select the gain - dt9812_configure_gain(slot->usb, &rmw[0], gain); - - // 2 set the MUX to select the channel - dt9812_configure_mux(slot->usb, &rmw[1], channel); - - // 3 start conversion - rmw[2].address = F020_SFR_ADC0CN; - rmw[2].and_mask = 0xff; - rmw[2].or_value = F020_MASK_ADC0CN_AD0EN | F020_MASK_ADC0CN_AD0BUSY; - - - result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); - if (result == 0) { - // read the status and ADC - u8 reg[3] = { F020_SFR_ADC0CN, F020_SFR_ADC0H, F020_SFR_ADC0L }; - u8 val[3]; - result = dt9812_read_multiple_registers(slot->usb, 3, reg, val); - if (result == 0) { - // An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us. - // Therefore, between the instant that AD0BUSY was set via - // dt9812_rmw_multiple_registers and the read of AD0BUSY via - // dt9812_read_multiple_registers, the conversion - // should be complete since these two operations require two USB - // transactions each taking at least a millisecond to complete. - // However, lets make sure that conversion is finished. - if ((val[0] & (F020_MASK_ADC0CN_AD0INT | F020_MASK_ADC0CN_AD0BUSY)) == - F020_MASK_ADC0CN_AD0INT) { - switch (slot->usb->device) { - case DT9812_DEVID_DT9812_10: { - // For DT9812-10V the personality module set the encoding to 2's - // complement. Hence, convert it before returning it - *value = ((val[1] << 8) | val[2]) + 0x800; - } break; - case DT9812_DEVID_DT9812_2PT5: { - *value = (val[1] << 8) | val[2]; - } break; - } - } - } - } - } - up(&slot->mutex); - return result; + int result = -ENODEV; + + down(&slot->mutex); + if (slot->usb) { + dt9812_rmw_byte_t rmw[3]; + + // 1 select the gain + dt9812_configure_gain(slot->usb, &rmw[0], gain); + + // 2 set the MUX to select the channel + dt9812_configure_mux(slot->usb, &rmw[1], channel); + + // 3 start conversion + rmw[2].address = F020_SFR_ADC0CN; + rmw[2].and_mask = 0xff; + rmw[2].or_value = + F020_MASK_ADC0CN_AD0EN | F020_MASK_ADC0CN_AD0BUSY; + + result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); + if (result == 0) { + // read the status and ADC + u8 reg[3] = { F020_SFR_ADC0CN, F020_SFR_ADC0H, + F020_SFR_ADC0L + }; + u8 val[3]; + result = dt9812_read_multiple_registers(slot->usb, 3, + reg, val); + if (result == 0) { + // An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us. + // Therefore, between the instant that AD0BUSY was set via + // dt9812_rmw_multiple_registers and the read of AD0BUSY via + // dt9812_read_multiple_registers, the conversion + // should be complete since these two operations require two USB + // transactions each taking at least a millisecond to complete. + // However, lets make sure that conversion is finished. + if ((val[0] & (F020_MASK_ADC0CN_AD0INT | + F020_MASK_ADC0CN_AD0BUSY)) + == F020_MASK_ADC0CN_AD0INT) { + switch (slot->usb->device) { + case DT9812_DEVID_DT9812_10:{ + // For DT9812-10V the personality module set the encoding to 2's + // complement. Hence, convert it before returning it + *value = ((val[1] << 8) + | val[2]) + + 0x800; + } + break; + case DT9812_DEVID_DT9812_2PT5:{ + *value = (val[1] << 8) | + val[2]; + } + break; + } + } + } + } + } + up(&slot->mutex); + return result; } -static int dt9812_analog_out_shadow(slot_dt9812_t *slot, int channel, - u16 *value) +static int dt9812_analog_out_shadow(slot_dt9812_t * slot, int channel, + u16 * value) { - int result = -ENODEV; + int result = -ENODEV; - down(&slot->mutex); - if (slot->usb) { - *value = slot->usb->analog_out_shadow[channel]; - result = 0; - } - up(&slot->mutex); + down(&slot->mutex); + if (slot->usb) { + *value = slot->usb->analog_out_shadow[channel]; + result = 0; + } + up(&slot->mutex); - return result; + return result; } -static int dt9812_analog_out(slot_dt9812_t *slot, int channel, u16 value) +static int dt9812_analog_out(slot_dt9812_t * slot, int channel, u16 value) { - int result = -ENODEV; - - down(&slot->mutex); - if (slot->usb) { - dt9812_rmw_byte_t rmw[3]; - - switch (channel) { - case 0: { - // 1. Set DAC mode - rmw[0].address = F020_SFR_DAC0CN; - rmw[0].and_mask = 0xff; - rmw[0].or_value = F020_MASK_DACxCN_DACxEN; - - // 2 load low byte of DAC value first - rmw[1].address = F020_SFR_DAC0L; - rmw[1].and_mask = 0xff; - rmw[1].or_value = value & 0xff; - - // 3 load high byte of DAC value next to latch the 12-bit value - rmw[2].address = F020_SFR_DAC0H; - rmw[2].and_mask = 0xff; - rmw[2].or_value = (value >> 8) & 0xf; - } break; - case 1: { - // 1. Set DAC mode - rmw[0].address = F020_SFR_DAC1CN; - rmw[0].and_mask = 0xff; - rmw[0].or_value = F020_MASK_DACxCN_DACxEN; - - // 2 load low byte of DAC value first - rmw[1].address = F020_SFR_DAC1L; - rmw[1].and_mask = 0xff; - rmw[1].or_value = value & 0xff; - - // 3 load high byte of DAC value next to latch the 12-bit value - rmw[2].address = F020_SFR_DAC1H; - rmw[2].and_mask = 0xff; - rmw[2].or_value = (value >> 8) & 0xf; - } break; - } - result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); - slot->usb->analog_out_shadow[channel] = value; - } - up(&slot->mutex); - - return result; + int result = -ENODEV; + + down(&slot->mutex); + if (slot->usb) { + dt9812_rmw_byte_t rmw[3]; + + switch (channel) { + case 0:{ + // 1. Set DAC mode + rmw[0].address = F020_SFR_DAC0CN; + rmw[0].and_mask = 0xff; + rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + + // 2 load low byte of DAC value first + rmw[1].address = F020_SFR_DAC0L; + rmw[1].and_mask = 0xff; + rmw[1].or_value = value & 0xff; + + // 3 load high byte of DAC value next to latch the 12-bit value + rmw[2].address = F020_SFR_DAC0H; + rmw[2].and_mask = 0xff; + rmw[2].or_value = (value >> 8) & 0xf; + } + break; + case 1:{ + // 1. Set DAC mode + rmw[0].address = F020_SFR_DAC1CN; + rmw[0].and_mask = 0xff; + rmw[0].or_value = F020_MASK_DACxCN_DACxEN; + + // 2 load low byte of DAC value first + rmw[1].address = F020_SFR_DAC1L; + rmw[1].and_mask = 0xff; + rmw[1].or_value = value & 0xff; + + // 3 load high byte of DAC value next to latch the 12-bit value + rmw[2].address = F020_SFR_DAC1H; + rmw[2].and_mask = 0xff; + rmw[2].or_value = (value >> 8) & 0xf; + } + break; + } + result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); + slot->usb->analog_out_shadow[channel] = value; + } + up(&slot->mutex); + + return result; } /* * USB framework functions */ -static int dt9812_probe(struct usb_interface *interface, - const struct usb_device_id *id) +static int dt9812_probe(struct usb_interface *interface, + const struct usb_device_id *id) { - int retval = -ENOMEM; - usb_dt9812_t *dev = NULL; - struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *endpoint; - int i; - u8 fw; - - // allocate memory for our device state and initialize it - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev == NULL) { - err("Out of memory"); - goto error; - } - KREF_INIT(&dev->kref, dt9812_delete); - - dev->udev = usb_get_dev(interface_to_usbdev(interface)); - dev->interface = interface; - - // Check endpoints - iface_desc = interface->cur_altsetting; - - if (iface_desc->desc.bNumEndpoints != 5) { - err("Wrong number of endpints."); - retval = -ENODEV; - goto error; - } - - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { - int direction = -1; - endpoint = &iface_desc->endpoint[i].desc; - switch (i) { - case 0: { - direction = USB_DIR_IN; - dev->message_pipe.addr = endpoint->bEndpointAddress; - dev->message_pipe.size = le16_to_cpu(endpoint->wMaxPacketSize); - } break; - case 1: { - direction = USB_DIR_OUT; - dev->command_write.addr = endpoint->bEndpointAddress; - dev->command_write.size = le16_to_cpu(endpoint->wMaxPacketSize); - } break; - case 2: { - direction = USB_DIR_IN; - dev->command_read.addr = endpoint->bEndpointAddress; - dev->command_read.size = le16_to_cpu(endpoint->wMaxPacketSize); - } break; - case 3: { - direction = USB_DIR_OUT; - dev->write_stream.addr = endpoint->bEndpointAddress; - dev->write_stream.size = le16_to_cpu(endpoint->wMaxPacketSize); - } break; - case 4: { - direction = USB_DIR_IN; - dev->read_stream.addr = endpoint->bEndpointAddress; - dev->read_stream.size = le16_to_cpu(endpoint->wMaxPacketSize); - } break; - } - if ((endpoint->bEndpointAddress & USB_DIR_IN) != direction) { - err("Endpoint has wrong direction."); - retval = -ENODEV; - goto error; - } - } - if (dt9812_read_info(dev, 0, &fw, sizeof(fw)) != 0) { - // Seems like a configuration reset is necessary if driver - // is reloaded while device is attached - int i; - - usb_reset_configuration(dev->udev); - for (i = 0 ; i < 10 ; i++) { - retval = dt9812_read_info(dev, 1, &fw, sizeof(fw)); - if (retval == 0){ - printk("usb_reset_configuration succeded after %d iterations\n", i); - break; - } - } - } - - if (dt9812_read_info(dev, 1, &dev->vendor, sizeof(dev->vendor)) != 0) { - err("Failed to read vendor."); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 3, &dev->product, sizeof(dev->product)) != 0) { - err("Failed to read product."); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 5, &dev->device, sizeof(dev->device)) != 0) { - err("Failed to read device."); - retval = -ENODEV; - goto error; - } - if (dt9812_read_info(dev, 7, &dev->serial, sizeof(dev->serial)) != 0) { - err("Failed to read serial."); - retval = -ENODEV; - goto error; - } - - dev->vendor = le16_to_cpu(dev->vendor); - dev->product = le16_to_cpu(dev->product); - dev->device = le16_to_cpu(dev->device); - dev->serial = le32_to_cpu(dev->serial); - switch (dev->device) { - case DT9812_DEVID_DT9812_10: { - dev->analog_out_shadow[0] = 0x0800; - dev->analog_out_shadow[1] = 0x800; - } break; - case DT9812_DEVID_DT9812_2PT5: { - dev->analog_out_shadow[0] = 0x0000; - dev->analog_out_shadow[1] = 0x0000; - } break; - } - dev->digital_out_shadow = 0; - - // save our data pointer in this interface device a - usb_set_intfdata(interface, dev); - - // let the user know what node this device is now attached to - info("USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x", - dev->vendor, dev->product, dev->device, dev->serial); - - down(&dt9812_mutex); - { - // Find a slot for the USB device - slot_dt9812_t *first = NULL; - slot_dt9812_t *best = NULL; - - for (i = 0 ; i < DT9812_NUM_SLOTS ; i++) { - if (!first && !dt9812[i].usb && dt9812[i].serial == 0) { - first = &dt9812[i]; - } - if (!best && dt9812[i].serial == dev->serial) { - best = &dt9812[i]; - } - } - - if (!best) { - best = first; - } - - if (best) { - down(&best->mutex); - best->usb = dev; - dev->slot = best; - up(&best->mutex); - } - } - up(&dt9812_mutex); - - return 0; - -error: - if (dev) { - KREF_PUT(&dev->kref, dt9812_delete); - } - return retval; + int retval = -ENOMEM; + usb_dt9812_t *dev = NULL; + struct usb_host_interface *iface_desc; + struct usb_endpoint_descriptor *endpoint; + int i; + u8 fw; + + // allocate memory for our device state and initialize it + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (dev == NULL) { + err("Out of memory"); + goto error; + } + KREF_INIT(&dev->kref, dt9812_delete); + + dev->udev = usb_get_dev(interface_to_usbdev(interface)); + dev->interface = interface; + + // Check endpoints + iface_desc = interface->cur_altsetting; + + if (iface_desc->desc.bNumEndpoints != 5) { + err("Wrong number of endpints."); + retval = -ENODEV; + goto error; + } + + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { + int direction = -1; + endpoint = &iface_desc->endpoint[i].desc; + switch (i) { + case 0:{ + direction = USB_DIR_IN; + dev->message_pipe.addr = + endpoint->bEndpointAddress; + dev->message_pipe.size = + le16_to_cpu(endpoint->wMaxPacketSize); + } + break; + case 1:{ + direction = USB_DIR_OUT; + dev->command_write.addr = + endpoint->bEndpointAddress; + dev->command_write.size = + le16_to_cpu(endpoint->wMaxPacketSize); + } + break; + case 2:{ + direction = USB_DIR_IN; + dev->command_read.addr = + endpoint->bEndpointAddress; + dev->command_read.size = + le16_to_cpu(endpoint->wMaxPacketSize); + } + break; + case 3:{ + direction = USB_DIR_OUT; + dev->write_stream.addr = + endpoint->bEndpointAddress; + dev->write_stream.size = + le16_to_cpu(endpoint->wMaxPacketSize); + } + break; + case 4:{ + direction = USB_DIR_IN; + dev->read_stream.addr = + endpoint->bEndpointAddress; + dev->read_stream.size = + le16_to_cpu(endpoint->wMaxPacketSize); + } + break; + } + if ((endpoint->bEndpointAddress & USB_DIR_IN) != direction) { + err("Endpoint has wrong direction."); + retval = -ENODEV; + goto error; + } + } + if (dt9812_read_info(dev, 0, &fw, sizeof(fw)) != 0) { + // Seems like a configuration reset is necessary if driver + // is reloaded while device is attached + int i; + + usb_reset_configuration(dev->udev); + for (i = 0; i < 10; i++) { + retval = dt9812_read_info(dev, 1, &fw, sizeof(fw)); + if (retval == 0) { + printk("usb_reset_configuration succeded after %d iterations\n", i); + break; + } + } + } + + if (dt9812_read_info(dev, 1, &dev->vendor, sizeof(dev->vendor)) != 0) { + err("Failed to read vendor."); + retval = -ENODEV; + goto error; + } + if (dt9812_read_info(dev, 3, &dev->product, sizeof(dev->product)) != 0) { + err("Failed to read product."); + retval = -ENODEV; + goto error; + } + if (dt9812_read_info(dev, 5, &dev->device, sizeof(dev->device)) != 0) { + err("Failed to read device."); + retval = -ENODEV; + goto error; + } + if (dt9812_read_info(dev, 7, &dev->serial, sizeof(dev->serial)) != 0) { + err("Failed to read serial."); + retval = -ENODEV; + goto error; + } + + dev->vendor = le16_to_cpu(dev->vendor); + dev->product = le16_to_cpu(dev->product); + dev->device = le16_to_cpu(dev->device); + dev->serial = le32_to_cpu(dev->serial); + switch (dev->device) { + case DT9812_DEVID_DT9812_10:{ + dev->analog_out_shadow[0] = 0x0800; + dev->analog_out_shadow[1] = 0x800; + } + break; + case DT9812_DEVID_DT9812_2PT5:{ + dev->analog_out_shadow[0] = 0x0000; + dev->analog_out_shadow[1] = 0x0000; + } + break; + } + dev->digital_out_shadow = 0; + + // save our data pointer in this interface device a + usb_set_intfdata(interface, dev); + + // let the user know what node this device is now attached to + info("USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x", + dev->vendor, dev->product, dev->device, dev->serial); + + down(&dt9812_mutex); + { + // Find a slot for the USB device + slot_dt9812_t *first = NULL; + slot_dt9812_t *best = NULL; + + for (i = 0; i < DT9812_NUM_SLOTS; i++) { + if (!first && !dt9812[i].usb && dt9812[i].serial == 0) { + first = &dt9812[i]; + } + if (!best && dt9812[i].serial == dev->serial) { + best = &dt9812[i]; + } + } + + if (!best) { + best = first; + } + + if (best) { + down(&best->mutex); + best->usb = dev; + dev->slot = best; + up(&best->mutex); + } + } + up(&dt9812_mutex); + + return 0; + + error: + if (dev) { + KREF_PUT(&dev->kref, dt9812_delete); + } + return retval; } static void dt9812_disconnect(struct usb_interface *interface) { - usb_dt9812_t *dev; - int minor = interface->minor; - - down(&dt9812_mutex); - dev = usb_get_intfdata(interface); - if (dev->slot) { - down(&dev->slot->mutex); - dev->slot->usb = NULL; - up(&dev->slot->mutex); - dev->slot = NULL; - } - usb_set_intfdata(interface, NULL); - up(&dt9812_mutex); - - /* queue final destruction */ - KREF_PUT(&dev->kref, dt9812_delete); - - info("USB Dt9812 #%d now disconnected", minor); + usb_dt9812_t *dev; + int minor = interface->minor; + + down(&dt9812_mutex); + dev = usb_get_intfdata(interface); + if (dev->slot) { + down(&dev->slot->mutex); + dev->slot->usb = NULL; + up(&dev->slot->mutex); + dev->slot = NULL; + } + usb_set_intfdata(interface, NULL); + up(&dt9812_mutex); + + /* queue final destruction */ + KREF_PUT(&dev->kref, dt9812_delete); + + info("USB Dt9812 #%d now disconnected", minor); } static struct usb_driver dt9812_usb_driver = { #ifdef COMEDI_HAVE_USB_DRIVER_OWNER - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .name = "dt9812", - .probe = dt9812_probe, - .disconnect = dt9812_disconnect, - .id_table = dt9812_table, + .name = "dt9812", + .probe = dt9812_probe, + .disconnect = dt9812_disconnect, + .id_table = dt9812_table, }; /* * Comedi functions */ -static void dt9812_comedi_open(comedi_device *dev) { - down(&devpriv->slot->mutex); - if (devpriv->slot->usb) { - // We have an attached device, fill in current range info - comedi_subdevice *s; - - s = &dev->subdevices[0]; - s->n_chan = 8; - s->maxdata = 1; - - s = &dev->subdevices[1]; - s->n_chan = 8; - s->maxdata = 1; - - s = &dev->subdevices[2]; - s->n_chan = 8; - switch (devpriv->slot->usb->device) { - case 0: { - s->maxdata = 4095; - s->range_table = &dt9812_10_ain_range; - } break; - case 1: { - s->maxdata = 4095; - s->range_table = &dt9812_2pt5_ain_range; - } break; - } - - s = &dev->subdevices[3]; - s->n_chan = 2; - switch (devpriv->slot->usb->device) { - case 0: { - s->maxdata = 4095; - s->range_table = &dt9812_10_aout_range; - } break; - case 1: { - s->maxdata = 4095; - s->range_table = &dt9812_2pt5_aout_range; - } break; - } - } - up(&devpriv->slot->mutex); +static void dt9812_comedi_open(comedi_device * dev) +{ + down(&devpriv->slot->mutex); + if (devpriv->slot->usb) { + // We have an attached device, fill in current range info + comedi_subdevice *s; + + s = &dev->subdevices[0]; + s->n_chan = 8; + s->maxdata = 1; + + s = &dev->subdevices[1]; + s->n_chan = 8; + s->maxdata = 1; + + s = &dev->subdevices[2]; + s->n_chan = 8; + switch (devpriv->slot->usb->device) { + case 0:{ + s->maxdata = 4095; + s->range_table = &dt9812_10_ain_range; + } + break; + case 1:{ + s->maxdata = 4095; + s->range_table = &dt9812_2pt5_ain_range; + } + break; + } + + s = &dev->subdevices[3]; + s->n_chan = 2; + switch (devpriv->slot->usb->device) { + case 0:{ + s->maxdata = 4095; + s->range_table = &dt9812_10_aout_range; + } + break; + case 1:{ + s->maxdata = 4095; + s->range_table = &dt9812_2pt5_aout_range; + } + break; + } + } + up(&devpriv->slot->mutex); } -static int dt9812_di_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt9812_di_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - u8 bits = 0; - - dt9812_digital_in(devpriv->slot, &bits); - for(n = 0 ; n < insn->n ; n++){ - data[n] = ((1<chanspec) & bits) != 0; - } - return n; + int n; + u8 bits = 0; + + dt9812_digital_in(devpriv->slot, &bits); + for (n = 0; n < insn->n; n++) { + data[n] = ((1 << insn->chanspec) & bits) != 0; + } + return n; } -static int dt9812_do_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt9812_do_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - u8 bits = 0; - - dt9812_digital_out_shadow(devpriv->slot, &bits); - for(n = 0 ; n < insn->n ; n++){ - u8 mask = 1<chanspec; - - bits &= ~mask; - if (data[n]) { - bits |= mask; - } - } - dt9812_digital_out(devpriv->slot, bits); - return n; -} + int n; + u8 bits = 0; + dt9812_digital_out_shadow(devpriv->slot, &bits); + for (n = 0; n < insn->n; n++) { + u8 mask = 1 << insn->chanspec; -static int dt9812_ai_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) -{ - int n; - - for(n = 0 ; n < insn->n ; n++){ - u16 value = 0; - - dt9812_analog_in(devpriv->slot, insn->chanspec, &value, DT9812_GAIN_1); - data[n] = value; - } - return n; + bits &= ~mask; + if (data[n]) { + bits |= mask; + } + } + dt9812_digital_out(devpriv->slot, bits); + return n; } - -static int dt9812_ao_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt9812_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; + int n; - for(n = 0 ; n < insn->n ; n++){ - u16 value = 0; + for (n = 0; n < insn->n; n++) { + u16 value = 0; - dt9812_analog_out_shadow(devpriv->slot, insn->chanspec, &value); - data[n] = value; - } - return n; + dt9812_analog_in(devpriv->slot, insn->chanspec, &value, + DT9812_GAIN_1); + data[n] = value; + } + return n; } - -static int dt9812_ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dt9812_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; + int n; - for(n = 0 ; n < insn->n ; n++){ - dt9812_analog_out(devpriv->slot, insn->chanspec, data[n]); - } - return n; + for (n = 0; n < insn->n; n++) { + u16 value = 0; + + dt9812_analog_out_shadow(devpriv->slot, insn->chanspec, &value); + data[n] = value; + } + return n; } +static int dt9812_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + int n; + + for (n = 0; n < insn->n; n++) { + dt9812_analog_out(devpriv->slot, insn->chanspec, data[n]); + } + return n; +} -static int dt9812_attach(comedi_device *dev, comedi_devconfig *it) +static int dt9812_attach(comedi_device * dev, comedi_devconfig * it) { - int i; - comedi_subdevice *s; - - dev->board_name = "dt9812"; - - if(alloc_private(dev,sizeof(comedi_dt9812_t)) < 0) { - return -ENOMEM; - } - - // Special open routine, since USB unit may be unattached at - // comedi_config time, hence range can not be determined - dev->open = dt9812_comedi_open; - - devpriv->serial = it->options[0]; - - // Allocate subdevices - if(alloc_subdevices(dev, 4) < 0) { - return -ENOMEM; - } - - /* digital input subdevice */ - s = dev->subdevices+0; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_read = &dt9812_di_rinsn; - - /* digital output subdevice */ - s = dev->subdevices+1; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_write = &dt9812_do_winsn; - - /* analog input subdevice */ - s=dev->subdevices+2; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_GROUND; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = 0; - s->insn_read = &dt9812_ai_rinsn; - - /* analog output subdevice */ - s=dev->subdevices+3; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = 0; - s->insn_write = &dt9812_ao_winsn; - s->insn_read = &dt9812_ao_rinsn; - - printk("comedi%d: successfully attached to dt9812.\n", - dev->minor); - - down(&dt9812_mutex); - // Find a slot for the comedi device - { - slot_dt9812_t *first = NULL; - slot_dt9812_t *best = NULL; - for (i = 0 ; i < DT9812_NUM_SLOTS ; i++) { - if (!first && !dt9812[i].comedi) { - // First free slot from comedi side - first = &dt9812[i]; - } - if (!best && - dt9812[i].usb && dt9812[i].usb->serial == devpriv->serial) { - // We have an attaced device with matching ID - best = &dt9812[i]; - } - } - if (!best) { - best = first; - } - if (best) { - down(&best->mutex); - best->comedi = devpriv; - best->serial = devpriv->serial; - devpriv->slot = best; - up(&best->mutex); - } - } - up(&dt9812_mutex); - - return 0; + int i; + comedi_subdevice *s; + + dev->board_name = "dt9812"; + + if (alloc_private(dev, sizeof(comedi_dt9812_t)) < 0) { + return -ENOMEM; + } + // Special open routine, since USB unit may be unattached at + // comedi_config time, hence range can not be determined + dev->open = dt9812_comedi_open; + + devpriv->serial = it->options[0]; + + // Allocate subdevices + if (alloc_subdevices(dev, 4) < 0) { + return -ENOMEM; + } + + /* digital input subdevice */ + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_read = &dt9812_di_rinsn; + + /* digital output subdevice */ + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_write = &dt9812_do_winsn; + + /* analog input subdevice */ + s = dev->subdevices + 2; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = 0; + s->insn_read = &dt9812_ai_rinsn; + + /* analog output subdevice */ + s = dev->subdevices + 3; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = 0; + s->insn_write = &dt9812_ao_winsn; + s->insn_read = &dt9812_ao_rinsn; + + printk("comedi%d: successfully attached to dt9812.\n", dev->minor); + + down(&dt9812_mutex); + // Find a slot for the comedi device + { + slot_dt9812_t *first = NULL; + slot_dt9812_t *best = NULL; + for (i = 0; i < DT9812_NUM_SLOTS; i++) { + if (!first && !dt9812[i].comedi) { + // First free slot from comedi side + first = &dt9812[i]; + } + if (!best && + dt9812[i].usb + && dt9812[i].usb->serial == devpriv->serial) { + // We have an attaced device with matching ID + best = &dt9812[i]; + } + } + if (!best) { + best = first; + } + if (best) { + down(&best->mutex); + best->comedi = devpriv; + best->serial = devpriv->serial; + devpriv->slot = best; + up(&best->mutex); + } + } + up(&dt9812_mutex); + + return 0; } -static int dt9812_detach(comedi_device *dev) +static int dt9812_detach(comedi_device * dev) { - return 0; + return 0; } static comedi_driver dt9812_comedi_driver = { - .module = THIS_MODULE, - .driver_name = "dt9812", - .attach = dt9812_attach, - .detach= dt9812_detach, + .module = THIS_MODULE, + .driver_name = "dt9812", + .attach = dt9812_attach, + .detach = dt9812_detach, }; static int __init usb_dt9812_init(void) { - int result, i; - - // Initialize all driver slots - for (i = 0 ; i < DT9812_NUM_SLOTS ; i++) { - init_MUTEX(&dt9812[i].mutex); - dt9812[i].serial = 0; - dt9812[i].usb = NULL; - dt9812[i].comedi = NULL; - } - dt9812[12].serial = 0x0; - - // register with the USB subsystem - result = usb_register(&dt9812_usb_driver); - if (result) { - err("usb_register failed. Error number %d", result); - } - - // register with comedi - result = comedi_driver_register(&dt9812_comedi_driver); - if (result) { - usb_deregister(&dt9812_usb_driver); - err("comedi_driver_register failed. Error number %d", result); - } - - return result; + int result, i; + + // Initialize all driver slots + for (i = 0; i < DT9812_NUM_SLOTS; i++) { + init_MUTEX(&dt9812[i].mutex); + dt9812[i].serial = 0; + dt9812[i].usb = NULL; + dt9812[i].comedi = NULL; + } + dt9812[12].serial = 0x0; + + // register with the USB subsystem + result = usb_register(&dt9812_usb_driver); + if (result) { + err("usb_register failed. Error number %d", result); + } + // register with comedi + result = comedi_driver_register(&dt9812_comedi_driver); + if (result) { + usb_deregister(&dt9812_usb_driver); + err("comedi_driver_register failed. Error number %d", result); + } + + return result; } static void __exit usb_dt9812_exit(void) { - // unregister with comedi - comedi_driver_unregister(&dt9812_comedi_driver); + // unregister with comedi + comedi_driver_unregister(&dt9812_comedi_driver); - /* deregister this driver with the USB subsystem */ - usb_deregister(&dt9812_usb_driver); + /* deregister this driver with the USB subsystem */ + usb_deregister(&dt9812_usb_driver); } -module_init (usb_dt9812_init); -module_exit (usb_dt9812_exit); +module_init(usb_dt9812_init); +module_exit(usb_dt9812_exit); MODULE_AUTHOR("Anders Blomdell "); MODULE_DESCRIPTION("Comedi DT9812 driver"); MODULE_LICENSE("GPL"); -#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) diff --git a/comedi/drivers/dt9812.h b/comedi/drivers/dt9812.h index 4584ecb4..df4ba22d 100644 --- a/comedi/drivers/dt9812.h +++ b/comedi/drivers/dt9812.h @@ -9,7 +9,7 @@ * See Silican Laboratories C8051F020/1/2/3 manual */ #define F020_SFR_P4 0x84 -#define F020_SFR_P1 0x90 +#define F020_SFR_P1 0x90 #define F020_SFR_P2 0xa0 #define F020_SFR_P3 0xb0 #define F020_SFR_AMX0CF 0xba @@ -25,7 +25,6 @@ #define F020_SFR_DAC1CN 0xd7 #define F020_SFR_ADC0CN 0xe8 - #define F020_MASK_ADC0CF_AMP0GN0 0x01 #define F020_MASK_ADC0CF_AMP0GN1 0x02 #define F020_MASK_ADC0CF_AMP0GN2 0x04 @@ -36,141 +35,141 @@ #define F020_MASK_DACxCN_DACxEN 0x80 -typedef enum { // A/D D/A DI DO CT - DT9812_DEVID_DT9812_10, // 8 2 8 8 1 +/- 10V - DT9812_DEVID_DT9812_2PT5, // 8 2 8 8 1 0-2.44V +typedef enum { // A/D D/A DI DO CT + DT9812_DEVID_DT9812_10, // 8 2 8 8 1 +/- 10V + DT9812_DEVID_DT9812_2PT5, // 8 2 8 8 1 0-2.44V #if 0 - DT9812_DEVID_DT9813, // 16 2 4 4 1 +/- 10V - DT9812_DEVID_DT9814 // 24 2 0 0 1 +/- 10V + DT9812_DEVID_DT9813, // 16 2 4 4 1 +/- 10V + DT9812_DEVID_DT9814 // 24 2 0 0 1 +/- 10V #endif } dt9812_devid_t; typedef enum { - DT9812_GAIN_0PT25 = 1, - DT9812_GAIN_0PT5 = 2, - DT9812_GAIN_1 = 4, - DT9812_GAIN_2 = 8, - DT9812_GAIN_4 = 16, - DT9812_GAIN_8 = 32, - DT9812_GAIN_16 = 64, + DT9812_GAIN_0PT25 = 1, + DT9812_GAIN_0PT5 = 2, + DT9812_GAIN_1 = 4, + DT9812_GAIN_2 = 8, + DT9812_GAIN_4 = 16, + DT9812_GAIN_8 = 32, + DT9812_GAIN_16 = 64, } dt9812_gain_t; typedef enum { - DT9812_LEAST_USB_FIRMWARE_CMD_CODE = 0, - DT9812_W_FLASH_DATA = 0, // Write Flash memory - DT9812_R_FLASH_DATA = 1, // Read Flash memory (misc config info) - - // Register read/write commands for processor - DT9812_R_SINGLE_BYTE_REG = 2, // Read a single byte of USB memory - DT9812_W_SINGLE_BYTE_REG = 3, // Write a single byte of USB memory - DT9812_R_MULTI_BYTE_REG = 4, // Multiple Reads of USB memory - DT9812_W_MULTI_BYTE_REG = 5, // Multiple Writes of USB memory - DT9812_RMW_SINGLE_BYTE_REG = 6, // Read, (AND) with mask, OR value, - // then write (single) - DT9812_RMW_MULTI_BYTE_REG = 7, // Read, (AND) with mask, OR value, - // then write (multiple) - - // Register read/write commands for SMBus - DT9812_R_SINGLE_BYTE_SMBUS = 8, // Read a single byte of SMBus - DT9812_W_SINGLE_BYTE_SMBUS = 9, // Write a single byte of SMBus - DT9812_R_MULTI_BYTE_SMBUS = 10, // Multiple Reads of SMBus - DT9812_W_MULTI_BYTE_SMBUS = 11, // Multiple Writes of SMBus - - // Register read/write commands for a device - DT9812_R_SINGLE_BYTE_DEV = 12, // Read a single byte of a device - DT9812_W_SINGLE_BYTE_DEV = 13, // Write a single byte of a device - DT9812_R_MULTI_BYTE_DEV = 14, // Multiple Reads of a device - DT9812_W_MULTI_BYTE_DEV = 15, // Multiple Writes of a device - - DT9812_W_DAC_THRESHOLD = 16, // Not sure if we'll need this - - DT9812_W_INT_ON_CHANGE_MASK = 17, // Set interrupt on change mask - - DT9812_W_CGL = 18, // Write (or Clear) the CGL for the ADC - DT9812_R_MULTI_BYTE_USBMEM = 19, // Multiple Reads of USB memory - DT9812_W_MULTI_BYTE_USBMEM = 20, // Multiple Writes to USB memory - - DT9812_START_SUBSYSTEM = 21, // Issue a start command to a - // given subsystem - DT9812_STOP_SUBSYSTEM = 22, // Issue a stop command to a - // given subsystem - - DT9812_CALIBRATE_POT = 23, //calibrate the board using CAL_POT_CMD - DT9812_W_DAC_FIFO_SIZE = 24, // set the DAC FIFO size - DT9812_W_CGL_DAC = 25, // Write (or Clear) the CGL for the DAC - DT9812_R_SINGLE_VALUE_CMD = 26, // Read a single value from a subsystem - DT9812_W_SINGLE_VALUE_CMD = 27, // Write a single value to a subsystem - DT9812_MAX_USB_FIRMWARE_CMD_CODE // Valid DT9812_USB_FIRMWARE_CMD_CODE's - // will be less than this number + DT9812_LEAST_USB_FIRMWARE_CMD_CODE = 0, + DT9812_W_FLASH_DATA = 0, // Write Flash memory + DT9812_R_FLASH_DATA = 1, // Read Flash memory (misc config info) + + // Register read/write commands for processor + DT9812_R_SINGLE_BYTE_REG = 2, // Read a single byte of USB memory + DT9812_W_SINGLE_BYTE_REG = 3, // Write a single byte of USB memory + DT9812_R_MULTI_BYTE_REG = 4, // Multiple Reads of USB memory + DT9812_W_MULTI_BYTE_REG = 5, // Multiple Writes of USB memory + DT9812_RMW_SINGLE_BYTE_REG = 6, // Read, (AND) with mask, OR value, + // then write (single) + DT9812_RMW_MULTI_BYTE_REG = 7, // Read, (AND) with mask, OR value, + // then write (multiple) + + // Register read/write commands for SMBus + DT9812_R_SINGLE_BYTE_SMBUS = 8, // Read a single byte of SMBus + DT9812_W_SINGLE_BYTE_SMBUS = 9, // Write a single byte of SMBus + DT9812_R_MULTI_BYTE_SMBUS = 10, // Multiple Reads of SMBus + DT9812_W_MULTI_BYTE_SMBUS = 11, // Multiple Writes of SMBus + + // Register read/write commands for a device + DT9812_R_SINGLE_BYTE_DEV = 12, // Read a single byte of a device + DT9812_W_SINGLE_BYTE_DEV = 13, // Write a single byte of a device + DT9812_R_MULTI_BYTE_DEV = 14, // Multiple Reads of a device + DT9812_W_MULTI_BYTE_DEV = 15, // Multiple Writes of a device + + DT9812_W_DAC_THRESHOLD = 16, // Not sure if we'll need this + + DT9812_W_INT_ON_CHANGE_MASK = 17, // Set interrupt on change mask + + DT9812_W_CGL = 18, // Write (or Clear) the CGL for the ADC + DT9812_R_MULTI_BYTE_USBMEM = 19, // Multiple Reads of USB memory + DT9812_W_MULTI_BYTE_USBMEM = 20, // Multiple Writes to USB memory + + DT9812_START_SUBSYSTEM = 21, // Issue a start command to a + // given subsystem + DT9812_STOP_SUBSYSTEM = 22, // Issue a stop command to a + // given subsystem + + DT9812_CALIBRATE_POT = 23, //calibrate the board using CAL_POT_CMD + DT9812_W_DAC_FIFO_SIZE = 24, // set the DAC FIFO size + DT9812_W_CGL_DAC = 25, // Write (or Clear) the CGL for the DAC + DT9812_R_SINGLE_VALUE_CMD = 26, // Read a single value from a subsystem + DT9812_W_SINGLE_VALUE_CMD = 27, // Write a single value to a subsystem + DT9812_MAX_USB_FIRMWARE_CMD_CODE // Valid DT9812_USB_FIRMWARE_CMD_CODE's + // will be less than this number } dt9812_usb_firmware_cmd_t; typedef struct { - u16 numbytes; - u16 address; + u16 numbytes; + u16 address; } dt9812_flash_data_t; #define DT9812_MAX_NUM_MULTI_BYTE_RDS \ ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(u8)) typedef struct { - u8 count; - u8 address[DT9812_MAX_NUM_MULTI_BYTE_RDS]; + u8 count; + u8 address[DT9812_MAX_NUM_MULTI_BYTE_RDS]; } dt9812_read_multi_t; typedef struct { - u8 address; - u8 value; + u8 address; + u8 value; } dt9812_write_byte_t; #define DT9812_MAX_NUM_MULTI_BYTE_WRTS \ ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(dt9812_write_byte_t)) typedef struct { - u8 count; - dt9812_write_byte_t write[DT9812_MAX_NUM_MULTI_BYTE_WRTS]; + u8 count; + dt9812_write_byte_t write[DT9812_MAX_NUM_MULTI_BYTE_WRTS]; } dt9812_write_multi_t; typedef struct { - u8 address; - u8 and_mask; - u8 or_value; + u8 address; + u8 and_mask; + u8 or_value; } dt9812_rmw_byte_t; #define DT9812_MAX_NUM_MULTI_BYTE_RMWS \ ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(dt9812_rmw_byte_t)) typedef struct { - u8 count; - dt9812_rmw_byte_t rmw[DT9812_MAX_NUM_MULTI_BYTE_RMWS]; + u8 count; + dt9812_rmw_byte_t rmw[DT9812_MAX_NUM_MULTI_BYTE_RMWS]; } dt9812_rmw_multi_t; typedef struct dt9812_usb_cmd { - u32 cmd; - union { - dt9812_flash_data_t flash_data_info; - dt9812_read_multi_t read_multi_info; - dt9812_write_multi_t write_multi_info; - dt9812_rmw_multi_t rmw_multi_info; - } u; + u32 cmd; + union { + dt9812_flash_data_t flash_data_info; + dt9812_read_multi_t read_multi_info; + dt9812_write_multi_t write_multi_info; + dt9812_rmw_multi_t rmw_multi_info; + } u; #if 0 - WRITE_BYTE_INFO WriteByteInfo; - READ_BYTE_INFO ReadByteInfo; - WRITE_MULTI_INFO WriteMultiInfo; - READ_MULTI_INFO ReadMultiInfo; - RMW_BYTE_INFO RMWByteInfo; - RMW_MULTI_INFO RMWMultiInfo; - DAC_THRESHOLD_INFO DacThresholdInfo; - INT_ON_CHANGE_MASK_INFO IntOnChangeMaskInfo; - CGL_INFO CglInfo; - SUBSYSTEM_INFO SubsystemInfo; - CAL_POT_CMD CalPotCmd; - WRITE_DEV_BYTE_INFO WriteDevByteInfo; - READ_DEV_BYTE_INFO ReadDevByteInfo; - WRITE_DEV_MULTI_INFO WriteDevMultiInfo; - READ_DEV_MULTI_INFO ReadDevMultiInfo; - READ_SINGLE_VALUE_INFO ReadSingleValueInfo; - WRITE_SINGLE_VALUE_INFO WriteSingleValueInfo; + WRITE_BYTE_INFO WriteByteInfo; + READ_BYTE_INFO ReadByteInfo; + WRITE_MULTI_INFO WriteMultiInfo; + READ_MULTI_INFO ReadMultiInfo; + RMW_BYTE_INFO RMWByteInfo; + RMW_MULTI_INFO RMWMultiInfo; + DAC_THRESHOLD_INFO DacThresholdInfo; + INT_ON_CHANGE_MASK_INFO IntOnChangeMaskInfo; + CGL_INFO CglInfo; + SUBSYSTEM_INFO SubsystemInfo; + CAL_POT_CMD CalPotCmd; + WRITE_DEV_BYTE_INFO WriteDevByteInfo; + READ_DEV_BYTE_INFO ReadDevByteInfo; + WRITE_DEV_MULTI_INFO WriteDevMultiInfo; + READ_DEV_MULTI_INFO ReadDevMultiInfo; + READ_SINGLE_VALUE_INFO ReadSingleValueInfo; + WRITE_SINGLE_VALUE_INFO WriteSingleValueInfo; #endif } dt9812_usb_cmd_t; diff --git a/comedi/drivers/fl512.c b/comedi/drivers/fl512.c index 60794041..d3434c66 100644 --- a/comedi/drivers/fl512.c +++ b/comedi/drivers/fl512.c @@ -23,174 +23,162 @@ Configuration options: #include #include -#define FL512_SIZE 16 /* the size of the used memory */ +#define FL512_SIZE 16 /* the size of the used memory */ typedef struct { - sampl_t ao_readback[2]; + sampl_t ao_readback[2]; } fl512_private; #define devpriv ((fl512_private *) dev->private) -static const comedi_lrange range_fl512 = -{ 4, { - BIP_RANGE(0.5), - BIP_RANGE(1), - BIP_RANGE(5), - BIP_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(5), - UNI_RANGE(10), -}}; +static const comedi_lrange range_fl512 = { 4, { + BIP_RANGE(0.5), + BIP_RANGE(1), + BIP_RANGE(5), + BIP_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(5), + UNI_RANGE(10), + } +}; -static int fl512_attach(comedi_device *dev,comedi_devconfig *it); -static int fl512_detach(comedi_device *dev); +static int fl512_attach(comedi_device * dev, comedi_devconfig * it); +static int fl512_detach(comedi_device * dev); static comedi_driver driver_fl512 = { - driver_name: "fl512", - module: THIS_MODULE, - attach: fl512_attach, - detach: fl512_detach, + driver_name:"fl512", + module:THIS_MODULE, + attach:fl512_attach, + detach:fl512_detach, }; + COMEDI_INITCLEANUP(driver_fl512); -static int fl512_ai_insn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); -static int fl512_ao_insn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); -static int fl512_ao_insn_readback(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); +static int fl512_ai_insn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int fl512_ao_insn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int fl512_ao_insn_readback(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* * fl512_ai_insn : this is the analog input function */ -static int fl512_ai_insn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int fl512_ai_insn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int n; - unsigned int lo_byte, hi_byte; - char chan = CR_CHAN(insn->chanspec); - unsigned long iobase = dev->iobase; - - for(n=0; nn; n++) { /* sample n times on selected channel */ - /* XXX probably can move next step out of for() loop -- will make - * AI a little bit faster. */ - outb(chan,iobase+2); /* select chan */ - outb(0,iobase+3); /* start conversion */ - /* XXX should test "done" flag instead of delay */ - comedi_udelay(30); /* sleep 30 usec */ - lo_byte = inb(iobase+2); /* low 8 byte */ - hi_byte = inb(iobase+3) & 0xf; /* high 4 bit and mask */ - data[n] = lo_byte + (hi_byte << 8); - } - return n; + int n; + unsigned int lo_byte, hi_byte; + char chan = CR_CHAN(insn->chanspec); + unsigned long iobase = dev->iobase; + + for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */ + /* XXX probably can move next step out of for() loop -- will make + * AI a little bit faster. */ + outb(chan, iobase + 2); /* select chan */ + outb(0, iobase + 3); /* start conversion */ + /* XXX should test "done" flag instead of delay */ + comedi_udelay(30); /* sleep 30 usec */ + lo_byte = inb(iobase + 2); /* low 8 byte */ + hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */ + data[n] = lo_byte + (hi_byte << 8); + } + return n; } /* * fl512_ao_insn : used to write to a DA port n times */ -static int fl512_ao_insn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int fl512_ao_insn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int n; - int chan = CR_CHAN(insn->chanspec); /* get chan to write */ - unsigned long iobase = dev->iobase; /* get base address */ - - for (n=0; nn; n++) { /* write n data set */ - outb(data[n] & 0x0ff, iobase+4+2*chan); /* write low byte */ - outb((data[n] & 0xf00) >> 8, iobase+4+2*chan); /* write high byte */ - inb(iobase+4+2*chan); /* trig */ - - devpriv->ao_readback[chan]=data[n]; - } - return n; + int n; + int chan = CR_CHAN(insn->chanspec); /* get chan to write */ + unsigned long iobase = dev->iobase; /* get base address */ + + for (n = 0; n < insn->n; n++) { /* write n data set */ + outb(data[n] & 0x0ff, iobase + 4 + 2 * chan); /* write low byte */ + outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan); /* write high byte */ + inb(iobase + 4 + 2 * chan); /* trig */ + + devpriv->ao_readback[chan] = data[n]; + } + return n; } /* * fl512_ao_insn_readback : used to read previous values written to * DA port */ -static int fl512_ao_insn_readback(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int fl512_ao_insn_readback(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int n; - int chan = CR_CHAN(insn->chanspec); + int n; + int chan = CR_CHAN(insn->chanspec); - for (n=0; nn; n++) { - data[n] = devpriv->ao_readback[chan]; - } + for (n = 0; n < insn->n; n++) { + data[n] = devpriv->ao_readback[chan]; + } - return n; + return n; } /* * start attach */ -static int fl512_attach(comedi_device *dev,comedi_devconfig *it) +static int fl512_attach(comedi_device * dev, comedi_devconfig * it) { - unsigned long iobase; - comedi_subdevice *s; /* pointer to the subdevice: - Analog in, Analog out, ( not made ->and Digital IO) */ - - iobase = it->options[0]; - printk("comedi:%d fl512: 0x%04lx",dev->minor,iobase); - if (!request_region(iobase, FL512_SIZE, "fl512")) { - printk(" I/O port conflict\n"); - return -EIO; - } - dev->iobase = iobase; - dev->board_name = "fl512"; - if(alloc_private(dev,sizeof(fl512_private)) < 0) - return -ENOMEM; + unsigned long iobase; + comedi_subdevice *s; /* pointer to the subdevice: + Analog in, Analog out, ( not made ->and Digital IO) */ + + iobase = it->options[0]; + printk("comedi:%d fl512: 0x%04lx", dev->minor, iobase); + if (!request_region(iobase, FL512_SIZE, "fl512")) { + printk(" I/O port conflict\n"); + return -EIO; + } + dev->iobase = iobase; + dev->board_name = "fl512"; + if (alloc_private(dev, sizeof(fl512_private)) < 0) + return -ENOMEM; #if DEBUG - printk("malloc ok\n"); + printk("malloc ok\n"); #endif - if(alloc_subdevices(dev, 2)<0) - return -ENOMEM; - - /* - * this if the definitions of the supdevices, 2 have been defined - */ - /* Analog indput */ - s = dev->subdevices+0; - s->type = COMEDI_SUBD_AI; /* define subdevice as Analog In */ - s->subdev_flags = SDF_READABLE|SDF_GROUND;/* you can read it from userspace */ - s->n_chan = 16; /* Number of Analog input channels */ - s->maxdata = 0x0fff; /* accept only 12 bits of data */ - s->range_table = &range_fl512; /* device use one of the ranges */ - s->insn_read = fl512_ai_insn; /* function to call when read AD */ - printk("comedi: fl512: subdevice 0 initialized\n"); - - /* Analog output */ - s = dev->subdevices+1; - s->type = COMEDI_SUBD_AO; /* define subdevice as Analog OUT */ - s->subdev_flags = SDF_WRITABLE; /* you can write it from userspace */ - s->n_chan = 2; /* Number of Analog output channels */ - s->maxdata = 0x0fff; /* accept only 12 bits of data */ - s->range_table = &range_fl512; /* device use one of the ranges */ - s->insn_write = fl512_ao_insn; /* function to call when write DA */ - s->insn_read = fl512_ao_insn_readback; /* function to call when reading DA */ - printk("comedi: fl512: subdevice 1 initialized\n"); - - return 1; + if (alloc_subdevices(dev, 2) < 0) + return -ENOMEM; + + /* + * this if the definitions of the supdevices, 2 have been defined + */ + /* Analog indput */ + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_AI; /* define subdevice as Analog In */ + s->subdev_flags = SDF_READABLE | SDF_GROUND; /* you can read it from userspace */ + s->n_chan = 16; /* Number of Analog input channels */ + s->maxdata = 0x0fff; /* accept only 12 bits of data */ + s->range_table = &range_fl512; /* device use one of the ranges */ + s->insn_read = fl512_ai_insn; /* function to call when read AD */ + printk("comedi: fl512: subdevice 0 initialized\n"); + + /* Analog output */ + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_AO; /* define subdevice as Analog OUT */ + s->subdev_flags = SDF_WRITABLE; /* you can write it from userspace */ + s->n_chan = 2; /* Number of Analog output channels */ + s->maxdata = 0x0fff; /* accept only 12 bits of data */ + s->range_table = &range_fl512; /* device use one of the ranges */ + s->insn_write = fl512_ao_insn; /* function to call when write DA */ + s->insn_read = fl512_ao_insn_readback; /* function to call when reading DA */ + printk("comedi: fl512: subdevice 1 initialized\n"); + + return 1; } -static int fl512_detach(comedi_device *dev) +static int fl512_detach(comedi_device * dev) { - if (dev->iobase) release_region(dev->iobase,FL512_SIZE); - printk("comedi%d: fl512: dummy i detach\n",dev->minor); - return 0; + if (dev->iobase) + release_region(dev->iobase, FL512_SIZE); + printk("comedi%d: fl512: dummy i detach\n", dev->minor); + return 0; } - - diff --git a/comedi/drivers/gsc_hpdi.c b/comedi/drivers/gsc_hpdi.c index 4af15bb7..317429eb 100644 --- a/comedi/drivers/gsc_hpdi.c +++ b/comedi/drivers/gsc_hpdi.c @@ -52,17 +52,18 @@ support could be added to this driver. #include "plx9080.h" #include "comedi_fc.h" -static int hpdi_attach( comedi_device *dev, comedi_devconfig *it ); -static int hpdi_detach( comedi_device *dev ); -void abort_dma( comedi_device *dev, unsigned int channel ); -static int hpdi_cmd( comedi_device *dev, comedi_subdevice *s ); -static int hpdi_cmd_test( comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd ); -static int hpdi_cancel( comedi_device *dev, comedi_subdevice *s ); +static int hpdi_attach(comedi_device * dev, comedi_devconfig * it); +static int hpdi_detach(comedi_device * dev); +void abort_dma(comedi_device * dev, unsigned int channel); +static int hpdi_cmd(comedi_device * dev, comedi_subdevice * s); +static int hpdi_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int hpdi_cancel(comedi_device * dev, comedi_subdevice * s); static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG); -static int dio_config_block_size( comedi_device *dev, lsampl_t *data ); +static int dio_config_block_size(comedi_device * dev, lsampl_t * data); -#undef HPDI_DEBUG // disable debugging messages -//#define HPDI_DEBUG // enable debugging code +#undef HPDI_DEBUG // disable debugging messages +//#define HPDI_DEBUG // enable debugging code #ifdef HPDI_DEBUG #define DEBUG_PRINT(format, args...) rt_printk(format , ## args ) @@ -70,20 +71,18 @@ static int dio_config_block_size( comedi_device *dev, lsampl_t *data ); #define DEBUG_PRINT(format, args...) #endif -#define TIMER_BASE 50 // 20MHz master clock +#define TIMER_BASE 50 // 20MHz master clock #define DMA_BUFFER_SIZE 0x10000 #define NUM_DMA_BUFFERS 4 #define NUM_DMA_DESCRIPTORS 256 // indices of base address regions -enum base_address_regions -{ +enum base_address_regions { PLX9080_BADDRINDEX = 0, HPDI_BADDRINDEX = 2, }; -enum hpdi_registers -{ +enum hpdi_registers { FIRMWARE_REV_REG = 0x0, BOARD_CONTROL_REG = 0x4, BOARD_STATUS_REG = 0x8, @@ -107,11 +106,10 @@ enum hpdi_registers INTERRUPT_POLARITY_REG = 0x54, }; -int command_channel_valid( unsigned int channel ) +int command_channel_valid(unsigned int channel) { - if( channel == 0 || channel > 6 ) - { - rt_printk( "gsc_hpdi: bug! invalid cable command channel\n"); + if (channel == 0 || channel > 6) { + rt_printk("gsc_hpdi: bug! invalid cable command channel\n"); return 0; } return 1; @@ -119,55 +117,54 @@ int command_channel_valid( unsigned int channel ) // bit definitions -enum firmware_revision_bits -{ +enum firmware_revision_bits { FEATURES_REG_PRESENT_BIT = 0x8000, }; -int firmware_revision( uint32_t fwr_bits ) +int firmware_revision(uint32_t fwr_bits) { return fwr_bits & 0xff; } -int pcb_revision( uint32_t fwr_bits ) + +int pcb_revision(uint32_t fwr_bits) { - return ( fwr_bits >> 8 ) & 0xff; + return (fwr_bits >> 8) & 0xff; } -int hpdi_subid( uint32_t fwr_bits ) + +int hpdi_subid(uint32_t fwr_bits) { - return ( fwr_bits >> 16 ) & 0xff; + return (fwr_bits >> 16) & 0xff; } -enum board_control_bits -{ +enum board_control_bits { BOARD_RESET_BIT = 0x1, /* wait 10usec before accessing fifos */ TX_FIFO_RESET_BIT = 0x2, RX_FIFO_RESET_BIT = 0x4, TX_ENABLE_BIT = 0x10, RX_ENABLE_BIT = 0x20, - DEMAND_DMA_DIRECTION_TX_BIT = 0x40, /* for channel 0, channel 1 can only transmit (when present) */ + DEMAND_DMA_DIRECTION_TX_BIT = 0x40, /* for channel 0, channel 1 can only transmit (when present) */ LINE_VALID_ON_STATUS_VALID_BIT = 0x80, START_TX_BIT = 0x10, CABLE_THROTTLE_ENABLE_BIT = 0x20, TEST_MODE_ENABLE_BIT = 0x80000000, }; -uint32_t command_discrete_output_bits( unsigned int channel, int output, int output_value ) +uint32_t command_discrete_output_bits(unsigned int channel, int output, + int output_value) { uint32_t bits = 0; - if( command_channel_valid( channel ) == 0 ) + if (command_channel_valid(channel) == 0) return 0; - if( output ) - { - bits |= 0x1 << ( 16 + channel ); - if( output_value ) - bits |= 0x1 << ( 24 + channel ); - }else - bits |= 0x1 << ( 24 + channel ); + if (output) { + bits |= 0x1 << (16 + channel); + if (output_value) + bits |= 0x1 << (24 + channel); + } else + bits |= 0x1 << (24 + channel); return bits; } -enum board_status_bits -{ +enum board_status_bits { COMMAND_LINE_STATUS_MASK = 0x7f, TX_IN_PROGRESS_BIT = 0x80, TX_NOT_EMPTY_BIT = 0x100, @@ -185,27 +182,27 @@ enum board_status_bits RX_OVERRUN_BIT = 0x800000, }; -uint32_t almost_full_bits( unsigned int num_words ) +uint32_t almost_full_bits(unsigned int num_words) { // XXX need to add or subtract one? - return ( num_words << 16 ) & 0xff0000; + return (num_words << 16) & 0xff0000; } -uint32_t almost_empty_bits( unsigned int num_words ) + +uint32_t almost_empty_bits(unsigned int num_words) { return num_words & 0xffff; } -unsigned int almost_full_num_words( uint32_t bits ) +unsigned int almost_full_num_words(uint32_t bits) { // XXX need to add or subtract one? - return ( bits >> 16 ) & 0xffff; + return (bits >> 16) & 0xffff; } -unsigned int almost_empty_num_words( uint32_t bits ) +unsigned int almost_empty_num_words(uint32_t bits) { return bits & 0xffff; } -enum features_bits -{ +enum features_bits { FIFO_SIZE_PRESENT_BIT = 0x1, FIFO_WORDS_PRESENT_BIT = 0x2, LEVEL_EDGE_INTERRUPTS_PRESENT_BIT = 0x4, @@ -214,8 +211,7 @@ enum features_bits OVERRUN_UNDERRUN_SUPPORTED_BIT = 0x20, }; -enum interrupt_sources -{ +enum interrupt_sources { FRAME_VALID_START_INTR = 0, FRAME_VALID_END_INTR = 1, TX_FIFO_EMPTY_INTR = 8, @@ -227,83 +223,83 @@ enum interrupt_sources RX_ALMOST_FULL_INTR = 14, RX_FULL_INTR = 15, }; -int command_intr_source( unsigned int channel ) +int command_intr_source(unsigned int channel) { - if( command_channel_valid( channel ) == 0 ) + if (command_channel_valid(channel) == 0) channel = 1; return channel + 1; } -uint32_t intr_bit( int interrupt_source ) + +uint32_t intr_bit(int interrupt_source) { return 0x1 << interrupt_source; } -uint32_t tx_clock_divisor_bits( unsigned int divisor ) +uint32_t tx_clock_divisor_bits(unsigned int divisor) { return divisor & 0xff; } -unsigned int fifo_size( uint32_t fifo_size_bits ) +unsigned int fifo_size(uint32_t fifo_size_bits) { return fifo_size_bits & 0xfffff; } -unsigned int fifo_words( uint32_t fifo_words_bits ) +unsigned int fifo_words(uint32_t fifo_words_bits) { return fifo_words_bits & 0xfffff; } -uint32_t intr_edge_bit( int interrupt_source ) +uint32_t intr_edge_bit(int interrupt_source) { return 0x1 << interrupt_source; } -uint32_t intr_active_high_bit( int interrupt_source ) +uint32_t intr_active_high_bit(int interrupt_source) { return 0x1 << interrupt_source; } -typedef struct -{ +typedef struct { char *name; - int device_id; // pci device id + int device_id; // pci device id int subdevice_id; // pci subdevice id } hpdi_board; -static const hpdi_board hpdi_boards[] = -{ +static const hpdi_board hpdi_boards[] = { { - name: "pci-hpdi32", - device_id: PCI_DEVICE_ID_PLX_9080, - subdevice_id: 0x2400, - }, + name: "pci-hpdi32", + device_id:PCI_DEVICE_ID_PLX_9080, + subdevice_id:0x2400, + }, #if 0 { - name: "pxi-hpdi32", - device_id: 0x9656, - subdevice_id: 0x2705, - }, + name: "pxi-hpdi32", + device_id:0x9656, + subdevice_id:0x2705, + }, #endif }; -static inline unsigned int num_boards( void ) +static inline unsigned int num_boards(void) { - return sizeof( hpdi_boards ) / sizeof( hpdi_board ); + return sizeof(hpdi_boards) / sizeof(hpdi_board); } static struct pci_device_id hpdi_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX, 0x2400, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX, 0x2400, + 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, hpdi_pci_table); -static inline hpdi_board* board( const comedi_device *dev ) +static inline hpdi_board *board(const comedi_device * dev) { - return ( hpdi_board * ) dev->board_ptr; + return (hpdi_board *) dev->board_ptr; } -typedef struct -{ +typedef struct { struct pci_dev *hw_dev; // pointer to board's pci_dev struct // base addresses (physical) resource_size_t plx9080_phys_iobase; @@ -311,88 +307,99 @@ typedef struct // base addresses (ioremapped) void *plx9080_iobase; void *hpdi_iobase; - uint32_t *dio_buffer[ NUM_DMA_BUFFERS ]; // dma buffers - dma_addr_t dio_buffer_phys_addr[ NUM_DMA_BUFFERS ]; // physical addresses of dma buffers + uint32_t *dio_buffer[NUM_DMA_BUFFERS]; // dma buffers + dma_addr_t dio_buffer_phys_addr[NUM_DMA_BUFFERS]; // physical addresses of dma buffers struct plx_dma_desc *dma_desc; // array of dma descriptors read by plx9080, allocated to get proper alignment dma_addr_t dma_desc_phys_addr; // physical address of dma descriptor array unsigned int num_dma_descriptors; - uint32_t *desc_dio_buffer[ NUM_DMA_DESCRIPTORS ]; // pointer to start of buffers indexed by descriptor + uint32_t *desc_dio_buffer[NUM_DMA_DESCRIPTORS]; // pointer to start of buffers indexed by descriptor volatile unsigned int dma_desc_index; // index of the dma descriptor that is currently being used unsigned int tx_fifo_size; unsigned int rx_fifo_size; volatile unsigned long dio_count; - volatile uint32_t bits[ 24 ]; // software copies of values written to hpdi registers + volatile uint32_t bits[24]; // software copies of values written to hpdi registers volatile unsigned int block_size; // number of bytes at which to generate COMEDI_CB_BLOCK events - unsigned dio_config_output : 1; + unsigned dio_config_output:1; } hpdi_private; -static inline hpdi_private* priv( comedi_device *dev ) +static inline hpdi_private *priv(comedi_device * dev) { return dev->private; } -static comedi_driver driver_hpdi = -{ - driver_name: "gsc_hpdi", - module: THIS_MODULE, - attach: hpdi_attach, - detach: hpdi_detach, +static comedi_driver driver_hpdi = { + driver_name:"gsc_hpdi", + module:THIS_MODULE, + attach:hpdi_attach, + detach:hpdi_detach, }; -COMEDI_INITCLEANUP( driver_hpdi ); +COMEDI_INITCLEANUP(driver_hpdi); -static int dio_config_insn( comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int dio_config_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch( data[ 0 ] ) - { - case INSN_CONFIG_DIO_OUTPUT: - priv(dev)->dio_config_output = 1; - return insn->n; - break; - case INSN_CONFIG_DIO_INPUT: - priv(dev)->dio_config_output = 0; - return insn->n; - break; - case INSN_CONFIG_DIO_QUERY: - data[1] = priv(dev)->dio_config_output ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; - break; - case INSN_CONFIG_BLOCK_SIZE: - return dio_config_block_size( dev, data ); - break; - default: - break; + switch (data[0]) { + case INSN_CONFIG_DIO_OUTPUT: + priv(dev)->dio_config_output = 1; + return insn->n; + break; + case INSN_CONFIG_DIO_INPUT: + priv(dev)->dio_config_output = 0; + return insn->n; + break; + case INSN_CONFIG_DIO_QUERY: + data[1] = + priv(dev)-> + dio_config_output ? COMEDI_OUTPUT : COMEDI_INPUT; + return insn->n; + break; + case INSN_CONFIG_BLOCK_SIZE: + return dio_config_block_size(dev, data); + break; + default: + break; } return -EINVAL; } -static void disable_plx_interrupts( comedi_device *dev ) +static void disable_plx_interrupts(comedi_device * dev) { - writel( 0, priv(dev)->plx9080_iobase + PLX_INTRCS_REG ); + writel(0, priv(dev)->plx9080_iobase + PLX_INTRCS_REG); } // initialize plx9080 chip -static void init_plx9080(comedi_device *dev) +static void init_plx9080(comedi_device * dev) { uint32_t bits; void *plx_iobase = priv(dev)->plx9080_iobase; // plx9080 dump - DEBUG_PRINT(" plx interrupt status 0x%x\n", readl(plx_iobase + PLX_INTRCS_REG)); + DEBUG_PRINT(" plx interrupt status 0x%x\n", + readl(plx_iobase + PLX_INTRCS_REG)); DEBUG_PRINT(" plx id bits 0x%x\n", readl(plx_iobase + PLX_ID_REG)); - DEBUG_PRINT(" plx control reg 0x%x\n", readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG)); - - DEBUG_PRINT(" plx revision 0x%x\n", readl(plx_iobase + PLX_REVISION_REG)); - DEBUG_PRINT(" plx dma channel 0 mode 0x%x\n", readl(plx_iobase + PLX_DMA0_MODE_REG)); - DEBUG_PRINT(" plx dma channel 1 mode 0x%x\n", readl(plx_iobase + PLX_DMA1_MODE_REG)); - DEBUG_PRINT(" plx dma channel 0 pci address 0x%x\n", readl(plx_iobase + PLX_DMA0_PCI_ADDRESS_REG)); - DEBUG_PRINT(" plx dma channel 0 local address 0x%x\n", readl(plx_iobase + PLX_DMA0_LOCAL_ADDRESS_REG)); - DEBUG_PRINT(" plx dma channel 0 transfer size 0x%x\n", readl(plx_iobase + PLX_DMA0_TRANSFER_SIZE_REG)); - DEBUG_PRINT(" plx dma channel 0 descriptor 0x%x\n", readl(plx_iobase + PLX_DMA0_DESCRIPTOR_REG)); - DEBUG_PRINT(" plx dma channel 0 command status 0x%x\n", readb(plx_iobase + PLX_DMA0_CS_REG)); - DEBUG_PRINT(" plx dma channel 0 threshold 0x%x\n", readl(plx_iobase + PLX_DMA0_THRESHOLD_REG)); + DEBUG_PRINT(" plx control reg 0x%x\n", + readl(priv(dev)->plx9080_iobase + PLX_CONTROL_REG)); + + DEBUG_PRINT(" plx revision 0x%x\n", + readl(plx_iobase + PLX_REVISION_REG)); + DEBUG_PRINT(" plx dma channel 0 mode 0x%x\n", + readl(plx_iobase + PLX_DMA0_MODE_REG)); + DEBUG_PRINT(" plx dma channel 1 mode 0x%x\n", + readl(plx_iobase + PLX_DMA1_MODE_REG)); + DEBUG_PRINT(" plx dma channel 0 pci address 0x%x\n", + readl(plx_iobase + PLX_DMA0_PCI_ADDRESS_REG)); + DEBUG_PRINT(" plx dma channel 0 local address 0x%x\n", + readl(plx_iobase + PLX_DMA0_LOCAL_ADDRESS_REG)); + DEBUG_PRINT(" plx dma channel 0 transfer size 0x%x\n", + readl(plx_iobase + PLX_DMA0_TRANSFER_SIZE_REG)); + DEBUG_PRINT(" plx dma channel 0 descriptor 0x%x\n", + readl(plx_iobase + PLX_DMA0_DESCRIPTOR_REG)); + DEBUG_PRINT(" plx dma channel 0 command status 0x%x\n", + readb(plx_iobase + PLX_DMA0_CS_REG)); + DEBUG_PRINT(" plx dma channel 0 threshold 0x%x\n", + readl(plx_iobase + PLX_DMA0_THRESHOLD_REG)); DEBUG_PRINT(" plx bigend 0x%x\n", readl(plx_iobase + PLX_BIGEND_REG)); #ifdef __BIG_ENDIAN bits = BIGEND_DMA0 | BIGEND_DMA1; @@ -401,7 +408,7 @@ static void init_plx9080(comedi_device *dev) #endif writel(bits, priv(dev)->plx9080_iobase + PLX_BIGEND_REG); - disable_plx_interrupts( dev ); + disable_plx_interrupts(dev); abort_dma(dev, 0); abort_dma(dev, 1); @@ -428,11 +435,11 @@ static void init_plx9080(comedi_device *dev) /* Allocate and initialize the subdevice structures. */ -static int setup_subdevices(comedi_device *dev) +static int setup_subdevices(comedi_device * dev) { comedi_subdevice *s; - if( alloc_subdevices( dev, 1 ) < 0 ) + if (alloc_subdevices(dev, 1) < 0) return -ENOMEM; s = dev->subdevices + 0; @@ -440,7 +447,8 @@ static int setup_subdevices(comedi_device *dev) dev->read_subdev = s; /* dev->write_subdev = s; */ s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITEABLE | SDF_LSAMPL | SDF_CMD_READ; + s->subdev_flags = + SDF_READABLE | SDF_WRITEABLE | SDF_LSAMPL | SDF_CMD_READ; s->n_chan = 32; s->len_chanlist = 32; s->maxdata = 1; @@ -453,150 +461,158 @@ static int setup_subdevices(comedi_device *dev) return 0; } -static int init_hpdi( comedi_device *dev ) +static int init_hpdi(comedi_device * dev) { uint32_t plx_intcsr_bits; - writel( BOARD_RESET_BIT, priv(dev)->hpdi_iobase + BOARD_CONTROL_REG ); - comedi_udelay( 10 ); + writel(BOARD_RESET_BIT, priv(dev)->hpdi_iobase + BOARD_CONTROL_REG); + comedi_udelay(10); - writel( almost_empty_bits( 32 ) | almost_full_bits( 32 ), - priv(dev)->hpdi_iobase + RX_PROG_ALMOST_REG ); - writel( almost_empty_bits( 32 ) | almost_full_bits( 32 ), - priv(dev)->hpdi_iobase + TX_PROG_ALMOST_REG ); + writel(almost_empty_bits(32) | almost_full_bits(32), + priv(dev)->hpdi_iobase + RX_PROG_ALMOST_REG); + writel(almost_empty_bits(32) | almost_full_bits(32), + priv(dev)->hpdi_iobase + TX_PROG_ALMOST_REG); - priv(dev)->tx_fifo_size = fifo_size( readl( priv(dev)->hpdi_iobase + - TX_FIFO_SIZE_REG ) ); - priv(dev)->rx_fifo_size = fifo_size( readl( priv(dev)->hpdi_iobase + - RX_FIFO_SIZE_REG ) ); + priv(dev)->tx_fifo_size = fifo_size(readl(priv(dev)->hpdi_iobase + + TX_FIFO_SIZE_REG)); + priv(dev)->rx_fifo_size = fifo_size(readl(priv(dev)->hpdi_iobase + + RX_FIFO_SIZE_REG)); - writel( 0, priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG ); + writel(0, priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG); // enable interrupts - plx_intcsr_bits = ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | ICS_LIE | ICS_DMA0_E; - writel( plx_intcsr_bits, priv(dev)->plx9080_iobase + PLX_INTRCS_REG ); + plx_intcsr_bits = + ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | ICS_LIE | + ICS_DMA0_E; + writel(plx_intcsr_bits, priv(dev)->plx9080_iobase + PLX_INTRCS_REG); return 0; } // setup dma descriptors so a link completes every 'transfer_size' bytes -static int setup_dma_descriptors( comedi_device *dev, unsigned int transfer_size ) +static int setup_dma_descriptors(comedi_device * dev, + unsigned int transfer_size) { unsigned int buffer_index, buffer_offset; uint32_t next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI; unsigned int i; - if( transfer_size > DMA_BUFFER_SIZE ) + if (transfer_size > DMA_BUFFER_SIZE) transfer_size = DMA_BUFFER_SIZE; - transfer_size -= transfer_size % sizeof( uint32_t ); - if( transfer_size == 0 ) return -1; + transfer_size -= transfer_size % sizeof(uint32_t); + if (transfer_size == 0) + return -1; - DEBUG_PRINT(" transfer_size %i\n", transfer_size ); - DEBUG_PRINT(" descriptors at 0x%lx\n", (unsigned long) priv(dev)->dma_desc_phys_addr ); + DEBUG_PRINT(" transfer_size %i\n", transfer_size); + DEBUG_PRINT(" descriptors at 0x%lx\n", + (unsigned long)priv(dev)->dma_desc_phys_addr); buffer_offset = 0; buffer_index = 0; - for( i = 0; i < NUM_DMA_DESCRIPTORS && - buffer_index < NUM_DMA_BUFFERS; i++ ) - { - priv(dev)->dma_desc[ i ].pci_start_addr = cpu_to_le32(priv(dev)->dio_buffer_phys_addr[ buffer_index ] + - buffer_offset); - priv(dev)->dma_desc[ i ].local_start_addr = cpu_to_le32(FIFO_REG); - priv(dev)->dma_desc[ i ].transfer_size = cpu_to_le32(transfer_size); - priv(dev)->dma_desc[ i ].next = cpu_to_le32(( priv(dev)->dma_desc_phys_addr + - ( i + 1 ) * sizeof( priv(dev)->dma_desc[ 0 ] ) ) | next_bits); - - priv(dev)->desc_dio_buffer[ i ] = priv(dev)->dio_buffer[ buffer_index ] + - ( buffer_offset / sizeof( uint32_t ) ); + for (i = 0; i < NUM_DMA_DESCRIPTORS && + buffer_index < NUM_DMA_BUFFERS; i++) { + priv(dev)->dma_desc[i].pci_start_addr = + cpu_to_le32(priv(dev)-> + dio_buffer_phys_addr[buffer_index] + buffer_offset); + priv(dev)->dma_desc[i].local_start_addr = cpu_to_le32(FIFO_REG); + priv(dev)->dma_desc[i].transfer_size = + cpu_to_le32(transfer_size); + priv(dev)->dma_desc[i].next = + cpu_to_le32((priv(dev)->dma_desc_phys_addr + (i + + 1) * + sizeof(priv(dev)->dma_desc[0])) | next_bits); + + priv(dev)->desc_dio_buffer[i] = + priv(dev)->dio_buffer[buffer_index] + + (buffer_offset / sizeof(uint32_t)); buffer_offset += transfer_size; - if( transfer_size + buffer_offset > DMA_BUFFER_SIZE ) - { + if (transfer_size + buffer_offset > DMA_BUFFER_SIZE) { buffer_offset = 0; buffer_index++; } - DEBUG_PRINT(" desc %i\n", i ); - DEBUG_PRINT(" start addr virt 0x%p, phys 0x%lx\n", priv(dev)->desc_dio_buffer[ i ], - (unsigned long)priv(dev)->dma_desc[ i ].pci_start_addr ); - DEBUG_PRINT(" next 0x%lx\n", (unsigned long)priv(dev)->dma_desc[ i ].next ); + DEBUG_PRINT(" desc %i\n", i); + DEBUG_PRINT(" start addr virt 0x%p, phys 0x%lx\n", + priv(dev)->desc_dio_buffer[i], + (unsigned long)priv(dev)->dma_desc[i].pci_start_addr); + DEBUG_PRINT(" next 0x%lx\n", + (unsigned long)priv(dev)->dma_desc[i].next); } priv(dev)->num_dma_descriptors = i; // fix last descriptor to point back to first - priv(dev)->dma_desc[ i - 1 ].next = + priv(dev)->dma_desc[i - 1].next = cpu_to_le32(priv(dev)->dma_desc_phys_addr | next_bits); DEBUG_PRINT(" desc %i next fixup 0x%lx\n", i - 1, - (unsigned long) priv(dev)->dma_desc[ i - 1 ].next ); + (unsigned long)priv(dev)->dma_desc[i - 1].next); priv(dev)->block_size = transfer_size; return transfer_size; } -static int hpdi_attach(comedi_device *dev, comedi_devconfig *it) +static int hpdi_attach(comedi_device * dev, comedi_devconfig * it) { - struct pci_dev* pcidev; + struct pci_dev *pcidev; int i; int retval; - printk( "comedi%d: gsc_hpdi\n", dev->minor ); + printk("comedi%d: gsc_hpdi\n", dev->minor); - if( alloc_private( dev, sizeof( hpdi_private ) ) < 0 ) + if (alloc_private(dev, sizeof(hpdi_private)) < 0) return -ENOMEM; pcidev = NULL; - for( i = 0; i < num_boards() && dev->board_ptr == NULL; i++ ) - { - do - { - pcidev = pci_get_subsys( PCI_VENDOR_ID_PLX, hpdi_boards[ i ].device_id, - PCI_VENDOR_ID_PLX, hpdi_boards[ i ].subdevice_id, pcidev ); + for (i = 0; i < num_boards() && dev->board_ptr == NULL; i++) { + do { + pcidev = pci_get_subsys(PCI_VENDOR_ID_PLX, + hpdi_boards[i].device_id, PCI_VENDOR_ID_PLX, + hpdi_boards[i].subdevice_id, pcidev); // was a particular bus/slot requested? - if( it->options[0] || it->options[1] ) - { + if (it->options[0] || it->options[1]) { // are we on the wrong bus/slot? - if( pcidev->bus->number != it->options[0] || - PCI_SLOT( pcidev->devfn ) != it->options[1] ) + if (pcidev->bus->number != it->options[0] || + PCI_SLOT(pcidev->devfn) != + it->options[1]) continue; } - if( pcidev ) - { + if (pcidev) { priv(dev)->hw_dev = pcidev; dev->board_ptr = hpdi_boards + i; break; } - }while( pcidev != NULL ); + } while (pcidev != NULL); } - if( dev->board_ptr == NULL ) - { + if (dev->board_ptr == NULL) { printk("gsc_hpdi: no hpdi card found\n"); return -EIO; } - printk("gsc_hpdi: found %s on bus %i, slot %i\n", board( dev )->name, + printk("gsc_hpdi: found %s on bus %i, slot %i\n", board(dev)->name, pcidev->bus->number, PCI_SLOT(pcidev->devfn)); - if( comedi_pci_enable( pcidev, driver_hpdi.driver_name ) ) - { - printk(KERN_WARNING " failed enable PCI device and request regions\n"); + if (comedi_pci_enable(pcidev, driver_hpdi.driver_name)) { + printk(KERN_WARNING + " failed enable PCI device and request regions\n"); return -EIO; } - pci_set_master( pcidev ); + pci_set_master(pcidev); //Initialize dev->board_name dev->board_name = board(dev)->name; - priv(dev)->plx9080_phys_iobase = pci_resource_start(pcidev, PLX9080_BADDRINDEX); - priv(dev)->hpdi_phys_iobase = pci_resource_start(pcidev, HPDI_BADDRINDEX); + priv(dev)->plx9080_phys_iobase = + pci_resource_start(pcidev, PLX9080_BADDRINDEX); + priv(dev)->hpdi_phys_iobase = + pci_resource_start(pcidev, HPDI_BADDRINDEX); // remap, won't work with 2.0 kernels but who cares - priv(dev)->plx9080_iobase = ioremap( priv(dev)->plx9080_phys_iobase, - pci_resource_len( pcidev, PLX9080_BADDRINDEX ) ); - priv(dev)->hpdi_iobase = ioremap( priv(dev)->hpdi_phys_iobase, - pci_resource_len( pcidev, HPDI_BADDRINDEX ) ); - if (!priv(dev)->plx9080_iobase || !priv(dev)->hpdi_iobase) - { + priv(dev)->plx9080_iobase = ioremap(priv(dev)->plx9080_phys_iobase, + pci_resource_len(pcidev, PLX9080_BADDRINDEX)); + priv(dev)->hpdi_iobase = ioremap(priv(dev)->hpdi_phys_iobase, + pci_resource_len(pcidev, HPDI_BADDRINDEX)); + if (!priv(dev)->plx9080_iobase || !priv(dev)->hpdi_iobase) { printk(" failed to remap io memory\n"); return -ENOMEM; } @@ -607,10 +623,9 @@ static int hpdi_attach(comedi_device *dev, comedi_devconfig *it) init_plx9080(dev); // get irq - if( comedi_request_irq( pcidev->irq, handle_interrupt, IRQF_SHARED, driver_hpdi.driver_name, - dev ) ) - { - printk( " unable to allocate irq %u\n", pcidev->irq ); + if (comedi_request_irq(pcidev->irq, handle_interrupt, IRQF_SHARED, + driver_hpdi.driver_name, dev)) { + printk(" unable to allocate irq %u\n", pcidev->irq); return -EINVAL; } dev->irq = pcidev->irq; @@ -618,67 +633,68 @@ static int hpdi_attach(comedi_device *dev, comedi_devconfig *it) printk(" irq %u\n", dev->irq); // alocate pci dma buffers - for( i = 0; i < NUM_DMA_BUFFERS; i++ ) - { - priv(dev)->dio_buffer[ i ] = pci_alloc_consistent( priv(dev)->hw_dev, - DMA_BUFFER_SIZE, &priv(dev)->dio_buffer_phys_addr[ i ] ); - DEBUG_PRINT( "dio_buffer at virt 0x%p, phys 0x%lx\n", - priv(dev)->dio_buffer[ i ], (unsigned long) priv(dev)->dio_buffer_phys_addr[ i ]); + for (i = 0; i < NUM_DMA_BUFFERS; i++) { + priv(dev)->dio_buffer[i] = + pci_alloc_consistent(priv(dev)->hw_dev, DMA_BUFFER_SIZE, + &priv(dev)->dio_buffer_phys_addr[i]); + DEBUG_PRINT("dio_buffer at virt 0x%p, phys 0x%lx\n", + priv(dev)->dio_buffer[i], + (unsigned long)priv(dev)->dio_buffer_phys_addr[i]); } // allocate dma descriptors - priv(dev)->dma_desc = pci_alloc_consistent( priv(dev)->hw_dev, - sizeof( struct plx_dma_desc ) * NUM_DMA_DESCRIPTORS, + priv(dev)->dma_desc = pci_alloc_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * NUM_DMA_DESCRIPTORS, &priv(dev)->dma_desc_phys_addr); - if( priv(dev)->dma_desc_phys_addr & 0xf ) - { + if (priv(dev)->dma_desc_phys_addr & 0xf) { printk(" dma descriptors not quad-word aligned (bug)\n"); return -EIO; } - retval = setup_dma_descriptors( dev, 0x1000 ); - if( retval < 0 ) + retval = setup_dma_descriptors(dev, 0x1000); + if (retval < 0) return retval; - retval = setup_subdevices( dev ); - if( retval < 0 ) + retval = setup_subdevices(dev); + if (retval < 0) return retval; - return init_hpdi( dev ); + return init_hpdi(dev); } -static int hpdi_detach(comedi_device *dev) +static int hpdi_detach(comedi_device * dev) { unsigned int i; - printk( "comedi%d: gsc_hpdi: remove\n", dev->minor ); + printk("comedi%d: gsc_hpdi: remove\n", dev->minor); - if( dev->irq ) - comedi_free_irq( dev->irq, dev ); - if( priv(dev) ) - { - if( priv(dev)->hw_dev ) - { - if(priv(dev)->plx9080_iobase) - { - disable_plx_interrupts( dev ); - iounmap( (void*) priv(dev)->plx9080_iobase ); + if (dev->irq) + comedi_free_irq(dev->irq, dev); + if (priv(dev)) { + if (priv(dev)->hw_dev) { + if (priv(dev)->plx9080_iobase) { + disable_plx_interrupts(dev); + iounmap((void *)priv(dev)->plx9080_iobase); } - if( priv(dev)->hpdi_iobase ) - iounmap((void*)priv(dev)->hpdi_iobase); + if (priv(dev)->hpdi_iobase) + iounmap((void *)priv(dev)->hpdi_iobase); // free pci dma buffers - for( i = 0; i < NUM_DMA_BUFFERS; i++ ) - { - if( priv(dev)->dio_buffer[ i ] ) - pci_free_consistent( priv(dev)->hw_dev, DMA_BUFFER_SIZE, - priv(dev)->dio_buffer[ i ], priv(dev)->dio_buffer_phys_addr[ i ] ); + for (i = 0; i < NUM_DMA_BUFFERS; i++) { + if (priv(dev)->dio_buffer[i]) + pci_free_consistent(priv(dev)->hw_dev, + DMA_BUFFER_SIZE, + priv(dev)->dio_buffer[i], + priv(dev)-> + dio_buffer_phys_addr[i]); } // free dma descriptors - if( priv(dev)->dma_desc ) - pci_free_consistent( priv(dev)->hw_dev, sizeof( struct plx_dma_desc ) * - NUM_DMA_DESCRIPTORS, priv(dev)->dma_desc, priv(dev)->dma_desc_phys_addr ); - if(priv(dev)->hpdi_phys_iobase) - { - comedi_pci_disable( priv(dev)->hw_dev ); + if (priv(dev)->dma_desc) + pci_free_consistent(priv(dev)->hw_dev, + sizeof(struct plx_dma_desc) * + NUM_DMA_DESCRIPTORS, + priv(dev)->dma_desc, + priv(dev)->dma_desc_phys_addr); + if (priv(dev)->hpdi_phys_iobase) { + comedi_pci_disable(priv(dev)->hw_dev); } pci_dev_put(priv(dev)->hw_dev); } @@ -686,22 +702,24 @@ static int hpdi_detach(comedi_device *dev) return 0; } -static int dio_config_block_size( comedi_device *dev, lsampl_t *data ) +static int dio_config_block_size(comedi_device * dev, lsampl_t * data) { unsigned int requested_block_size; int retval; - requested_block_size = data[ 1 ]; + requested_block_size = data[1]; - retval = setup_dma_descriptors( dev, requested_block_size ); - if( retval < 0 ) return retval; + retval = setup_dma_descriptors(dev, requested_block_size); + if (retval < 0) + return retval; - data[ 1 ] = retval; + data[1] = retval; return 2; } -static int di_cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) +static int di_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -711,165 +729,173 @@ static int di_cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd) tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if( !cmd->start_src || tmp != cmd->start_src ) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if( !cmd->scan_begin_src || tmp != cmd->scan_begin_src ) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if( !cmd->convert_src || tmp != cmd->convert_src ) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if( !cmd->scan_end_src || tmp != cmd->scan_end_src ) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if( !cmd->stop_src || tmp != cmd->stop_src ) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ // uniqueness check - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE ) err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if( !cmd->chanlist_len ) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 32; err++; } - if( cmd->scan_end_arg != cmd->chanlist_len ) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - switch(cmd->stop_src) - { - case TRIG_COUNT: - if(!cmd->stop_arg) - { - cmd->stop_arg = 1; - err++; - } - break; - case TRIG_NONE: - if(cmd->stop_arg != 0) - { - cmd->stop_arg = 0; - err++; - } - break; - default: - break; + switch (cmd->stop_src) { + case TRIG_COUNT: + if (!cmd->stop_arg) { + cmd->stop_arg = 1; + err++; + } + break; + case TRIG_NONE: + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; + err++; + } + break; + default: + break; } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(err) return 4; + if (err) + return 4; - if( cmd->chanlist ) - { - for( i = 1; i < cmd->chanlist_len; i++ ) - { - if( CR_CHAN( cmd->chanlist[ i ] ) != i ) - { + if (cmd->chanlist) { + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != i) { // XXX could support 8 channels or 16 channels - comedi_error( dev, "chanlist must be channels 0 to 31 in order" ); + comedi_error(dev, + "chanlist must be channels 0 to 31 in order"); err++; break; } } } - if(err) return 5; + if (err) + return 5; return 0; } -static int hpdi_cmd_test( comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd ) +static int hpdi_cmd_test(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - if( priv(dev)->dio_config_output ) - { + if (priv(dev)->dio_config_output) { return -EINVAL; - }else - return di_cmd_test( dev, s, cmd ); + } else + return di_cmd_test(dev, s, cmd); } -static inline void hpdi_writel( comedi_device *dev, uint32_t bits, unsigned int offset ) +static inline void hpdi_writel(comedi_device * dev, uint32_t bits, + unsigned int offset) { - writel( bits | priv(dev)->bits[ offset / sizeof( uint32_t ) ], - priv(dev)->hpdi_iobase + offset ); + writel(bits | priv(dev)->bits[offset / sizeof(uint32_t)], + priv(dev)->hpdi_iobase + offset); } -static int di_cmd(comedi_device *dev,comedi_subdevice *s) +static int di_cmd(comedi_device * dev, comedi_subdevice * s) { uint32_t bits; unsigned long flags; comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; - hpdi_writel( dev, RX_FIFO_RESET_BIT, BOARD_CONTROL_REG ); + hpdi_writel(dev, RX_FIFO_RESET_BIT, BOARD_CONTROL_REG); - DEBUG_PRINT( "hpdi: in di_cmd\n"); + DEBUG_PRINT("hpdi: in di_cmd\n"); abort_dma(dev, 0); priv(dev)->dma_desc_index = 0; /* These register are supposedly unused during chained dma, - * but I have found that left over values from last operation - * occasionally cause problems with transfer of first dma - * block. Initializing them to zero seems to fix the problem. */ + * but I have found that left over values from last operation + * occasionally cause problems with transfer of first dma + * block. Initializing them to zero seems to fix the problem. */ writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_TRANSFER_SIZE_REG); writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); writel(0, priv(dev)->plx9080_iobase + PLX_DMA0_LOCAL_ADDRESS_REG); // give location of first dma descriptor - bits = priv(dev)->dma_desc_phys_addr | PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI; - writel( bits, priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG ); + bits = priv(dev)-> + dma_desc_phys_addr | PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | + PLX_XFER_LOCAL_TO_PCI; + writel(bits, priv(dev)->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); // spinlock for plx dma control/status reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); // enable dma transfer - writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - if( cmd->stop_src == TRIG_COUNT ) + if (cmd->stop_src == TRIG_COUNT) priv(dev)->dio_count = cmd->stop_arg; else priv(dev)->dio_count = 1; // clear over/under run status flags - writel( RX_UNDERRUN_BIT | RX_OVERRUN_BIT, priv(dev)->hpdi_iobase + BOARD_STATUS_REG ); + writel(RX_UNDERRUN_BIT | RX_OVERRUN_BIT, + priv(dev)->hpdi_iobase + BOARD_STATUS_REG); // enable interrupts - writel( intr_bit( RX_FULL_INTR ), priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG ); + writel(intr_bit(RX_FULL_INTR), + priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG); - DEBUG_PRINT( "hpdi: starting rx\n"); - hpdi_writel( dev, RX_ENABLE_BIT, BOARD_CONTROL_REG ); + DEBUG_PRINT("hpdi: starting rx\n"); + hpdi_writel(dev, RX_ENABLE_BIT, BOARD_CONTROL_REG); return 0; } -static int hpdi_cmd( comedi_device *dev, comedi_subdevice *s ) +static int hpdi_cmd(comedi_device * dev, comedi_subdevice * s) { - if( priv(dev)->dio_config_output ) - { + if (priv(dev)->dio_config_output) { return -EINVAL; - }else - return di_cmd( dev, s ); + } else + return di_cmd(dev, s); } -static void drain_dma_buffers(comedi_device *dev, unsigned int channel) +static void drain_dma_buffers(comedi_device * dev, unsigned int channel) { comedi_async *async = dev->read_subdev->async; uint32_t next_transfer_addr; @@ -877,35 +903,39 @@ static void drain_dma_buffers(comedi_device *dev, unsigned int channel) int num_samples = 0; void *pci_addr_reg; - if(channel) - pci_addr_reg = priv(dev)->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG; + if (channel) + pci_addr_reg = + priv(dev)->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG; else - pci_addr_reg = priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; + pci_addr_reg = + priv(dev)->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG; // loop until we have read all the full buffers j = 0; - for(next_transfer_addr = readl(pci_addr_reg); - (next_transfer_addr < le32_to_cpu(priv(dev)->dma_desc[ priv(dev)->dma_desc_index ].pci_start_addr) || - next_transfer_addr >= le32_to_cpu(priv(dev)->dma_desc[ priv(dev)->dma_desc_index ].pci_start_addr) + - priv(dev)->block_size ) && - j < priv(dev)->num_dma_descriptors; - j++ ) - { + for (next_transfer_addr = readl(pci_addr_reg); + (next_transfer_addr < + le32_to_cpu(priv(dev)->dma_desc[priv(dev)-> + dma_desc_index].pci_start_addr) + || next_transfer_addr >= + le32_to_cpu(priv(dev)->dma_desc[priv(dev)-> + dma_desc_index].pci_start_addr) + + priv(dev)->block_size) + && j < priv(dev)->num_dma_descriptors; j++) { // transfer data from dma buffer to comedi buffer - num_samples = priv(dev)->block_size / sizeof( uint32_t ); - if( async->cmd.stop_src == TRIG_COUNT ) - { - if(num_samples > priv(dev)->dio_count) + num_samples = priv(dev)->block_size / sizeof(uint32_t); + if (async->cmd.stop_src == TRIG_COUNT) { + if (num_samples > priv(dev)->dio_count) num_samples = priv(dev)->dio_count; priv(dev)->dio_count -= num_samples; } - cfc_write_array_to_buffer( dev->read_subdev, priv(dev)->desc_dio_buffer[ priv(dev)->dma_desc_index ], - num_samples * sizeof( uint32_t ) ); + cfc_write_array_to_buffer(dev->read_subdev, + priv(dev)->desc_dio_buffer[priv(dev)->dma_desc_index], + num_samples * sizeof(uint32_t)); priv(dev)->dma_desc_index++; priv(dev)->dma_desc_index %= priv(dev)->num_dma_descriptors; DEBUG_PRINT("next desc addr 0x%lx\n", (unsigned long) - priv(dev)->dma_desc[ priv(dev)->dma_desc_index ].next ); + priv(dev)->dma_desc[priv(dev)->dma_desc_index].next); DEBUG_PRINT("pci addr reg 0x%x\n", next_transfer_addr); } // XXX check for buffer overrun somehow @@ -922,110 +952,105 @@ static irqreturn_t handle_interrupt(int irq, void *d PT_REGS_ARG) uint8_t dma0_status, dma1_status; unsigned long flags; - if (!dev->attached) - { + if (!dev->attached) { return IRQ_NONE; } - plx_status = readl( priv(dev)->plx9080_iobase + PLX_INTRCS_REG ); - if( ( plx_status & ( ICS_DMA0_A | ICS_DMA1_A | ICS_LIA ) ) == 0 ) - { + plx_status = readl(priv(dev)->plx9080_iobase + PLX_INTRCS_REG); + if ((plx_status & (ICS_DMA0_A | ICS_DMA1_A | ICS_LIA)) == 0) { return IRQ_NONE; } - hpdi_intr_status = readl( priv(dev)->hpdi_iobase + INTERRUPT_STATUS_REG ); - hpdi_board_status = readl( priv(dev)->hpdi_iobase + BOARD_STATUS_REG ); + hpdi_intr_status = readl(priv(dev)->hpdi_iobase + INTERRUPT_STATUS_REG); + hpdi_board_status = readl(priv(dev)->hpdi_iobase + BOARD_STATUS_REG); async->events = 0; - if( hpdi_intr_status ) - { + if (hpdi_intr_status) { DEBUG_PRINT("hpdi: intr status 0x%x, ", hpdi_intr_status); - writel( hpdi_intr_status, priv(dev)->hpdi_iobase + INTERRUPT_STATUS_REG ); + writel(hpdi_intr_status, + priv(dev)->hpdi_iobase + INTERRUPT_STATUS_REG); } - // spin lock makes sure noone else changes plx dma control reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); dma0_status = readb(priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); - if(plx_status & ICS_DMA0_A) - { // dma chan 0 interrupt - writeb((dma0_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); + if (plx_status & ICS_DMA0_A) { // dma chan 0 interrupt + writeb((dma0_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG); DEBUG_PRINT("dma0 status 0x%x\n", dma0_status); - if(dma0_status & PLX_DMA_EN_BIT) - { + if (dma0_status & PLX_DMA_EN_BIT) { drain_dma_buffers(dev, 0); } DEBUG_PRINT(" cleared dma ch0 interrupt\n"); } - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // spin lock makes sure noone else changes plx dma control reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); dma1_status = readb(priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); - if(plx_status & ICS_DMA1_A) // XXX - { // dma chan 1 interrupt - writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); + if (plx_status & ICS_DMA1_A) // XXX + { // dma chan 1 interrupt + writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, + priv(dev)->plx9080_iobase + PLX_DMA1_CS_REG); DEBUG_PRINT("dma1 status 0x%x\n", dma1_status); DEBUG_PRINT(" cleared dma ch1 interrupt\n"); } - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // clear possible plx9080 interrupt sources - if(plx_status & ICS_LDIA) - { // clear local doorbell interrupt + if (plx_status & ICS_LDIA) { // clear local doorbell interrupt plx_bits = readl(priv(dev)->plx9080_iobase + PLX_DBR_OUT_REG); writel(plx_bits, priv(dev)->plx9080_iobase + PLX_DBR_OUT_REG); DEBUG_PRINT(" cleared local doorbell bits 0x%x\n", plx_bits); } - if( hpdi_board_status & RX_OVERRUN_BIT ) - { + if (hpdi_board_status & RX_OVERRUN_BIT) { comedi_error(dev, "rx fifo overrun"); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; - DEBUG_PRINT( "dma0_status 0x%x\n", (int)readb(priv(dev)->plx9080_iobase + PLX_DMA0_CS_REG)); + DEBUG_PRINT("dma0_status 0x%x\n", + (int)readb(priv(dev)->plx9080_iobase + + PLX_DMA0_CS_REG)); } - if( hpdi_board_status & RX_UNDERRUN_BIT ) - { + if (hpdi_board_status & RX_UNDERRUN_BIT) { comedi_error(dev, "rx fifo underrun"); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; } - if( priv(dev)->dio_count == 0 ) + if (priv(dev)->dio_count == 0) async->events |= COMEDI_CB_EOA; DEBUG_PRINT("board status 0x%x, ", hpdi_board_status); DEBUG_PRINT("plx status 0x%x\n", plx_status); - if( async->events ) - DEBUG_PRINT( " events 0x%x\n", async->events ); + if (async->events) + DEBUG_PRINT(" events 0x%x\n", async->events); - cfc_handle_events( dev, s ); + cfc_handle_events(dev, s); return IRQ_HANDLED; } -void abort_dma( comedi_device *dev, unsigned int channel ) +void abort_dma(comedi_device * dev, unsigned int channel) { unsigned long flags; // spinlock for plx dma control/status reg - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); - plx9080_abort_dma( priv( dev )->plx9080_iobase, channel ); + plx9080_abort_dma(priv(dev)->plx9080_iobase, channel); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } -static int hpdi_cancel( comedi_device *dev, comedi_subdevice *s ) +static int hpdi_cancel(comedi_device * dev, comedi_subdevice * s) { - hpdi_writel( dev, 0, BOARD_CONTROL_REG ); + hpdi_writel(dev, 0, BOARD_CONTROL_REG); - writel( 0, priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG ); + writel(0, priv(dev)->hpdi_iobase + INTERRUPT_CONTROL_REG); abort_dma(dev, 0); return 0; } - diff --git a/comedi/drivers/icp_multi.c b/comedi/drivers/icp_multi.c index a72fd614..b5f47a38 100644 --- a/comedi/drivers/icp_multi.c +++ b/comedi/drivers/icp_multi.c @@ -20,7 +20,6 @@ */ - /* Driver: icp_multi Description: Inova ICP_MULTI @@ -58,7 +57,6 @@ Options: #include "icp_multi.h" - #define DEVICE_ID 0x8000 /* Device ID */ #define ICP_MULTI_EXTDEBUG @@ -68,145 +66,142 @@ Options: #define IORANGE_ICP_MULTI 32 -#define ICP_MULTI_ADC_CSR 0 /* R/W: ADC command/status register */ -#define ICP_MULTI_AI 2 /* R: Analogue input data */ -#define ICP_MULTI_DAC_CSR 4 /* R/W: DAC command/status register */ -#define ICP_MULTI_AO 6 /* R/W: Analogue output data */ -#define ICP_MULTI_DI 8 /* R/W: Digital inouts */ -#define ICP_MULTI_DO 0x0A /* R/W: Digital outputs */ -#define ICP_MULTI_INT_EN 0x0C /* R/W: Interrupt enable register */ -#define ICP_MULTI_INT_STAT 0x0E /* R/W: Interrupt status register */ -#define ICP_MULTI_CNTR0 0x10 /* R/W: Counter 0 */ -#define ICP_MULTI_CNTR1 0x12 /* R/W: counter 1 */ -#define ICP_MULTI_CNTR2 0x14 /* R/W: Counter 2 */ -#define ICP_MULTI_CNTR3 0x16 /* R/W: Counter 3 */ +#define ICP_MULTI_ADC_CSR 0 /* R/W: ADC command/status register */ +#define ICP_MULTI_AI 2 /* R: Analogue input data */ +#define ICP_MULTI_DAC_CSR 4 /* R/W: DAC command/status register */ +#define ICP_MULTI_AO 6 /* R/W: Analogue output data */ +#define ICP_MULTI_DI 8 /* R/W: Digital inouts */ +#define ICP_MULTI_DO 0x0A /* R/W: Digital outputs */ +#define ICP_MULTI_INT_EN 0x0C /* R/W: Interrupt enable register */ +#define ICP_MULTI_INT_STAT 0x0E /* R/W: Interrupt status register */ +#define ICP_MULTI_CNTR0 0x10 /* R/W: Counter 0 */ +#define ICP_MULTI_CNTR1 0x12 /* R/W: counter 1 */ +#define ICP_MULTI_CNTR2 0x14 /* R/W: Counter 2 */ +#define ICP_MULTI_CNTR3 0x16 /* R/W: Counter 3 */ #define ICP_MULTI_SIZE 0x20 /* 32 bytes */ // Define bits from ADC command/status register -#define ADC_ST 0x0001 /* Start ADC */ -#define ADC_BSY 0x0001 /* ADC busy */ -#define ADC_BI 0x0010 /* Bipolar input range 1 = bipolar */ -#define ADC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ -#define ADC_DI 0x0040 /* Differential input mode 1 = differential */ +#define ADC_ST 0x0001 /* Start ADC */ +#define ADC_BSY 0x0001 /* ADC busy */ +#define ADC_BI 0x0010 /* Bipolar input range 1 = bipolar */ +#define ADC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ +#define ADC_DI 0x0040 /* Differential input mode 1 = differential */ // Define bits from DAC command/status register -#define DAC_ST 0x0001 /* Start DAC */ -#define DAC_BSY 0x0001 /* DAC busy */ -#define DAC_BI 0x0010 /* Bipolar input range 1 = bipolar */ -#define DAC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ +#define DAC_ST 0x0001 /* Start DAC */ +#define DAC_BSY 0x0001 /* DAC busy */ +#define DAC_BI 0x0010 /* Bipolar input range 1 = bipolar */ +#define DAC_RA 0x0020 /* Input range 0 = 5V, 1 = 10V */ // Define bits from interrupt enable/status registers -#define ADC_READY 0x0001 /* A/d conversion ready interrupt */ -#define DAC_READY 0x0002 /* D/a conversion ready interrupt */ -#define DOUT_ERROR 0x0004 /* Digital output error interrupt */ -#define DIN_STATUS 0x0008 /* Digital input status change interrupt */ -#define CIE0 0x0010 /* Counter 0 overrun interrupt */ -#define CIE1 0x0020 /* Counter 1 overrun interrupt */ -#define CIE2 0x0040 /* Counter 2 overrun interrupt */ -#define CIE3 0x0080 /* Counter 3 overrun interrupt */ +#define ADC_READY 0x0001 /* A/d conversion ready interrupt */ +#define DAC_READY 0x0002 /* D/a conversion ready interrupt */ +#define DOUT_ERROR 0x0004 /* Digital output error interrupt */ +#define DIN_STATUS 0x0008 /* Digital input status change interrupt */ +#define CIE0 0x0010 /* Counter 0 overrun interrupt */ +#define CIE1 0x0020 /* Counter 1 overrun interrupt */ +#define CIE2 0x0040 /* Counter 2 overrun interrupt */ +#define CIE3 0x0080 /* Counter 3 overrun interrupt */ // Useful definitions -#define Status_IRQ 0x00ff // All interrupts - +#define Status_IRQ 0x00ff // All interrupts // Define analogue range -static const comedi_lrange range_analog={ 4, { - UNI_RANGE(5), - UNI_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(10) +static const comedi_lrange range_analog = { 4, { + UNI_RANGE(5), + UNI_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(10) } }; -static const char range_codes_analog[]={0x00, 0x20, 0x10, 0x30}; - +static const char range_codes_analog[] = { 0x00, 0x20, 0x10, 0x30 }; /* ============================================================================== Forward declarations ============================================================================== */ -static int icp_multi_attach(comedi_device *dev, comedi_devconfig *it); -static int icp_multi_detach(comedi_device *dev); - +static int icp_multi_attach(comedi_device * dev, comedi_devconfig * it); +static int icp_multi_detach(comedi_device * dev); /* ============================================================================== Data & Structure declarations ============================================================================== */ -static unsigned short pci_list_builded=0; /*>0 list of card is known */ +static unsigned short pci_list_builded = 0; /*>0 list of card is known */ typedef struct { - const char *name; // driver name - int device_id; - int iorange; // I/O range len - char have_irq; // 1=card support IRQ - char cardtype; // 0=ICP Multi - int n_aichan; // num of A/D chans - int n_aichand; // num of A/D chans in diff mode - int n_aochan; // num of D/A chans - int n_dichan; // num of DI chans - int n_dochan; // num of DO chans - int n_ctrs; // num of counters - int ai_maxdata; // resolution of A/D - int ao_maxdata; // resolution of D/A - const comedi_lrange *rangelist_ai; // rangelist for A/D - const char *rangecode; // range codes for programming - const comedi_lrange *rangelist_ao; // rangelist for D/A + const char *name; // driver name + int device_id; + int iorange; // I/O range len + char have_irq; // 1=card support IRQ + char cardtype; // 0=ICP Multi + int n_aichan; // num of A/D chans + int n_aichand; // num of A/D chans in diff mode + int n_aochan; // num of D/A chans + int n_dichan; // num of DI chans + int n_dochan; // num of DO chans + int n_ctrs; // num of counters + int ai_maxdata; // resolution of A/D + int ao_maxdata; // resolution of D/A + const comedi_lrange *rangelist_ai; // rangelist for A/D + const char *rangecode; // range codes for programming + const comedi_lrange *rangelist_ao; // rangelist for D/A } boardtype; -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"icp_multi", // Driver name - DEVICE_ID, // PCI device ID - IORANGE_ICP_MULTI, // I/O range length - 1, // 1=Card supports interrupts - TYPE_ICP_MULTI, // Card type = ICP MULTI - 16, // Num of A/D channels - 8, // Num of A/D channels in diff mode - 4, // Num of D/A channels - 16, // Num of digital inputs - 8, // Num of digital outputs - 4, // Num of counters - 0x0fff, // Resolution of A/D - 0x0fff, // Resolution of D/A - &range_analog, // Rangelist for A/D - range_codes_analog, // Range codes for programming - &range_analog }, // Rangelist for D/A + DEVICE_ID, // PCI device ID + IORANGE_ICP_MULTI, // I/O range length + 1, // 1=Card supports interrupts + TYPE_ICP_MULTI, // Card type = ICP MULTI + 16, // Num of A/D channels + 8, // Num of A/D channels in diff mode + 4, // Num of D/A channels + 16, // Num of digital inputs + 8, // Num of digital outputs + 4, // Num of counters + 0x0fff, // Resolution of A/D + 0x0fff, // Resolution of D/A + &range_analog, // Rangelist for A/D + range_codes_analog, // Range codes for programming + &range_analog}, // Rangelist for D/A }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -static comedi_driver driver_icp_multi={ - driver_name: "icp_multi", - module: THIS_MODULE, - attach: icp_multi_attach, - detach: icp_multi_detach, - num_names: n_boardtypes, - board_name: &boardtypes[0].name, - offset: sizeof(boardtype), +static comedi_driver driver_icp_multi = { + driver_name:"icp_multi", + module:THIS_MODULE, + attach:icp_multi_attach, + detach:icp_multi_detach, + num_names:n_boardtypes, + board_name:&boardtypes[0].name, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_icp_multi); -typedef struct{ - struct pcilst_struct *card; // pointer to card - char valid; // card is usable - void *io_addr; // Pointer to mapped io address - resource_size_t phys_iobase; // Physical io address - unsigned int AdcCmdStatus; // ADC Command/Status register - unsigned int DacCmdStatus; // DAC Command/Status register - unsigned int IntEnable; // Interrupt Enable register - unsigned int IntStatus; // Interrupt Status register - unsigned int act_chanlist[32]; // list of scaned channel - unsigned char act_chanlist_len; // len of scanlist - unsigned char act_chanlist_pos; // actual position in MUX list - unsigned int *ai_chanlist; // actaul chanlist - sampl_t *ai_data; // data buffer - sampl_t ao_data[4]; // data output buffer - sampl_t di_data; // Digital input data - unsigned int do_data; // Remember digital output data +typedef struct { + struct pcilst_struct *card; // pointer to card + char valid; // card is usable + void *io_addr; // Pointer to mapped io address + resource_size_t phys_iobase; // Physical io address + unsigned int AdcCmdStatus; // ADC Command/Status register + unsigned int DacCmdStatus; // DAC Command/Status register + unsigned int IntEnable; // Interrupt Enable register + unsigned int IntStatus; // Interrupt Status register + unsigned int act_chanlist[32]; // list of scaned channel + unsigned char act_chanlist_len; // len of scanlist + unsigned char act_chanlist_pos; // actual position in MUX list + unsigned int *ai_chanlist; // actaul chanlist + sampl_t *ai_data; // data buffer + sampl_t ao_data[4]; // data output buffer + sampl_t di_data; // Digital input data + unsigned int do_data; // Remember digital output data } icp_multi_private; #define devpriv ((icp_multi_private *)dev->private) @@ -219,11 +214,12 @@ typedef struct{ */ #if 0 -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan); +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan); #endif -static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan); -static int icp_multi_reset(comedi_device *dev); - +static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan); +static int icp_multi_reset(comedi_device * dev); /* ============================================================================== @@ -231,7 +227,6 @@ static int icp_multi_reset(comedi_device *dev); ============================================================================== */ - /* ============================================================================== @@ -250,91 +245,103 @@ static int icp_multi_reset(comedi_device *dev); ============================================================================== */ -static int icp_multi_insn_read_ai(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_read_ai(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,timeout; + int n, timeout; #ifdef ICP_MULTI_EXTDEBUG printk("icp multi EDBG: BGN: icp_multi_insn_read_ai(...)\n"); #endif // Disable A/D conversion ready interrupt devpriv->IntEnable &= ~ADC_READY; - writew(devpriv->IntEnable,devpriv->io_addr + ICP_MULTI_INT_EN); + writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN); // Clear interrupt status devpriv->IntStatus |= ADC_READY; - writew(devpriv->IntStatus,devpriv->io_addr + ICP_MULTI_INT_STAT); + writew(devpriv->IntStatus, devpriv->io_addr + ICP_MULTI_INT_STAT); // Set up appropriate channel, mode and range data, for specified channel setup_channel_list(dev, s, &insn->chanspec, 1); #ifdef ICP_MULTI_EXTDEBUG - printk("icp_multi A ST=%4x IO=%p\n",readw(devpriv->io_addr+ICP_MULTI_ADC_CSR), devpriv->io_addr+ICP_MULTI_ADC_CSR); + printk("icp_multi A ST=%4x IO=%p\n", + readw(devpriv->io_addr + ICP_MULTI_ADC_CSR), + devpriv->io_addr + ICP_MULTI_ADC_CSR); #endif - for (n=0; nn; n++) { + for (n = 0; n < insn->n; n++) { // Set start ADC bit devpriv->AdcCmdStatus |= ADC_ST; - writew(devpriv->AdcCmdStatus, devpriv->io_addr+ICP_MULTI_ADC_CSR); + writew(devpriv->AdcCmdStatus, + devpriv->io_addr + ICP_MULTI_ADC_CSR); devpriv->AdcCmdStatus &= ~ADC_ST; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi B n=%d ST=%4x\n",n,readw(devpriv->io_addr+ICP_MULTI_ADC_CSR)); + printk("icp multi B n=%d ST=%4x\n", n, + readw(devpriv->io_addr + ICP_MULTI_ADC_CSR)); #endif comedi_udelay(1); #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi C n=%d ST=%4x\n",n,readw(devpriv->io_addr+ICP_MULTI_ADC_CSR)); + printk("icp multi C n=%d ST=%4x\n", n, + readw(devpriv->io_addr + ICP_MULTI_ADC_CSR)); #endif // Wait for conversion to complete, or get fed up waiting - timeout=100; - while (timeout--) { - if (!(readw(devpriv->io_addr+ICP_MULTI_ADC_CSR) & ADC_BSY)) + timeout = 100; + while (timeout--) { + if (!(readw(devpriv->io_addr + + ICP_MULTI_ADC_CSR) & ADC_BSY)) goto conv_finish; #ifdef ICP_MULTI_EXTDEBUG - if (!(timeout%10)) - printk("icp multi D n=%d tm=%d ST=%4x\n",n,timeout,readw(devpriv->io_addr+ICP_MULTI_ADC_CSR)); + if (!(timeout % 10)) + printk("icp multi D n=%d tm=%d ST=%4x\n", n, + timeout, + readw(devpriv->io_addr + + ICP_MULTI_ADC_CSR)); #endif comedi_udelay(1); - } + } // If we reach here, a timeout has occurred - comedi_error(dev,"A/D insn timeout"); + comedi_error(dev, "A/D insn timeout"); // Disable interrupt devpriv->IntEnable &= ~ADC_READY; - writew(devpriv->IntEnable,devpriv->io_addr + ICP_MULTI_INT_EN); + writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN); // Clear interrupt status devpriv->IntStatus |= ADC_READY; - writew(devpriv->IntStatus,devpriv->io_addr + ICP_MULTI_INT_STAT); + writew(devpriv->IntStatus, + devpriv->io_addr + ICP_MULTI_INT_STAT); // Clear data received - data[n]=0; + data[n] = 0; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: END: icp_multi_insn_read_ai(...) n=%d\n",n); + printk("icp multi EDBG: END: icp_multi_insn_read_ai(...) n=%d\n", n); #endif - return -ETIME; + return -ETIME; -conv_finish: - data[n] = (readw(devpriv->io_addr+ICP_MULTI_AI) >> 4 ) & 0x0fff; + conv_finish: + data[n] = + (readw(devpriv->io_addr + ICP_MULTI_AI) >> 4) & 0x0fff; } // Disable interrupt devpriv->IntEnable &= ~ADC_READY; - writew(devpriv->IntEnable,devpriv->io_addr + ICP_MULTI_INT_EN); + writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN); // Clear interrupt status devpriv->IntStatus |= ADC_READY; - writew(devpriv->IntStatus,devpriv->io_addr + ICP_MULTI_INT_STAT); + writew(devpriv->IntStatus, devpriv->io_addr + ICP_MULTI_INT_STAT); #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: END: icp_multi_insn_read_ai(...) n=%d\n",n); + printk("icp multi EDBG: END: icp_multi_insn_read_ai(...) n=%d\n", n); #endif return n; } @@ -357,7 +364,8 @@ conv_finish: ============================================================================== */ -static int icp_multi_insn_write_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_write_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n, chan, range, timeout; @@ -366,11 +374,11 @@ static int icp_multi_insn_write_ao(comedi_device * dev, comedi_subdevice * s, co #endif // Disable D/A conversion ready interrupt devpriv->IntEnable &= ~DAC_READY; - writew(devpriv->IntEnable,devpriv->io_addr + ICP_MULTI_INT_EN); + writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN); // Clear interrupt status devpriv->IntStatus |= DAC_READY; - writew(devpriv->IntStatus,devpriv->io_addr + ICP_MULTI_INT_STAT); + writew(devpriv->IntStatus, devpriv->io_addr + ICP_MULTI_INT_STAT); // Get channel number and range chan = CR_CHAN(insn->chanspec); @@ -385,59 +393,65 @@ static int icp_multi_insn_write_ao(comedi_device * dev, comedi_subdevice * s, co devpriv->DacCmdStatus |= this_board->rangecode[range]; devpriv->DacCmdStatus |= (chan << 8); - writew(devpriv->DacCmdStatus, devpriv->io_addr+ICP_MULTI_DAC_CSR); + writew(devpriv->DacCmdStatus, devpriv->io_addr + ICP_MULTI_DAC_CSR); - for (n=0; nn; n++) { + for (n = 0; n < insn->n; n++) { // Wait for analogue output data register to be ready for new data, or get fed up waiting - timeout=100; - while (timeout--) { - if (!(readw(devpriv->io_addr+ICP_MULTI_DAC_CSR) & DAC_BSY)) + timeout = 100; + while (timeout--) { + if (!(readw(devpriv->io_addr + + ICP_MULTI_DAC_CSR) & DAC_BSY)) goto dac_ready; #ifdef ICP_MULTI_EXTDEBUG - if (!(timeout%10)) - printk("icp multi A n=%d tm=%d ST=%4x\n",n,timeout,readw(devpriv->io_addr+ICP_MULTI_DAC_CSR)); + if (!(timeout % 10)) + printk("icp multi A n=%d tm=%d ST=%4x\n", n, + timeout, + readw(devpriv->io_addr + + ICP_MULTI_DAC_CSR)); #endif comedi_udelay(1); - } + } // If we reach here, a timeout has occurred - comedi_error(dev,"D/A insn timeout"); + comedi_error(dev, "D/A insn timeout"); // Disable interrupt devpriv->IntEnable &= ~DAC_READY; - writew(devpriv->IntEnable,devpriv->io_addr + ICP_MULTI_INT_EN); + writew(devpriv->IntEnable, devpriv->io_addr + ICP_MULTI_INT_EN); // Clear interrupt status devpriv->IntStatus |= DAC_READY; - writew(devpriv->IntStatus,devpriv->io_addr + ICP_MULTI_INT_STAT); + writew(devpriv->IntStatus, + devpriv->io_addr + ICP_MULTI_INT_STAT); // Clear data received - devpriv->ao_data[chan]=0; + devpriv->ao_data[chan] = 0; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: END: icp_multi_insn_write_ao(...) n=%d\n",n); + printk("icp multi EDBG: END: icp_multi_insn_write_ao(...) n=%d\n", n); #endif - return -ETIME; + return -ETIME; -dac_ready: + dac_ready: // Write data to analogue output data register writew(data[n], devpriv->io_addr + ICP_MULTI_AO); // Set DAC_ST bit to write the data to selected channel devpriv->DacCmdStatus |= DAC_ST; - writew(devpriv->DacCmdStatus, devpriv->io_addr+ICP_MULTI_DAC_CSR); + writew(devpriv->DacCmdStatus, + devpriv->io_addr + ICP_MULTI_DAC_CSR); devpriv->DacCmdStatus &= ~DAC_ST; // Save analogue output data - devpriv->ao_data[chan]=data[n]; + devpriv->ao_data[chan] = data[n]; } #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: END: icp_multi_insn_write_ao(...) n=%d\n",n); + printk("icp multi EDBG: END: icp_multi_insn_write_ao(...) n=%d\n", n); #endif - return n; + return n; } /* @@ -458,16 +472,17 @@ dac_ready: ============================================================================== */ -static int icp_multi_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_read_ao(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,chan; + int n, chan; // Get channel number chan = CR_CHAN(insn->chanspec); // Read analogue outputs - for (n=0; nn; n++) - data[n]=devpriv->ao_data[chan]; + for (n = 0; n < insn->n; n++) + data[n] = devpriv->ao_data[chan]; return n; } @@ -490,7 +505,8 @@ static int icp_multi_insn_read_ao(comedi_device * dev, comedi_subdevice * s, com ============================================================================== */ -static int icp_multi_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_bits_di(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[1] = readw(devpriv->io_addr + ICP_MULTI_DI); @@ -515,7 +531,8 @@ static int icp_multi_insn_bits_di(comedi_device *dev,comedi_subdevice *s, comedi ============================================================================== */ -static int icp_multi_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) +static int icp_multi_insn_bits_do(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { #ifdef ICP_MULTI_EXTDEBUG printk("icp multi EDBG: BGN: icp_multi_insn_bits_do(...)\n"); @@ -533,12 +550,11 @@ static int icp_multi_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi data[1] = readw(devpriv->io_addr + ICP_MULTI_DI); #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: END: icp_multi_insn_bits_do(...)\n"); + printk("icp multi EDBG: END: icp_multi_insn_bits_do(...)\n"); #endif return 2; } - /* ============================================================================== @@ -557,12 +573,12 @@ static int icp_multi_insn_bits_do(comedi_device *dev,comedi_subdevice *s, comedi ============================================================================== */ -static int icp_multi_insn_read_ctr(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_read_ctr(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - return 0; + return 0; } - /* ============================================================================== @@ -581,13 +597,12 @@ static int icp_multi_insn_read_ctr(comedi_device * dev, comedi_subdevice * s, co ============================================================================== */ -static int icp_multi_insn_write_ctr(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data) +static int icp_multi_insn_write_ctr(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - return 0; + return 0; } - - /* ============================================================================== @@ -605,11 +620,12 @@ static int icp_multi_insn_write_ctr(comedi_device * dev, comedi_subdevice * s, c */ static irqreturn_t interrupt_service_icp_multi(int irq, void *d PT_REGS_ARG) { - comedi_device *dev = d; - int int_no; + comedi_device *dev = d; + int int_no; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: BGN: interrupt_service_icp_multi(%d,...)\n",irq); + printk("icp multi EDBG: BGN: interrupt_service_icp_multi(%d,...)\n", + irq); #endif // Is this interrupt from our board? @@ -619,30 +635,30 @@ static irqreturn_t interrupt_service_icp_multi(int irq, void *d PT_REGS_ARG) return IRQ_NONE; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: interrupt_service_icp_multi() ST: %4x\n",readw(devpriv->io_addr + ICP_MULTI_INT_STAT)); + printk("icp multi EDBG: interrupt_service_icp_multi() ST: %4x\n", + readw(devpriv->io_addr + ICP_MULTI_INT_STAT)); #endif // Determine which interrupt is active & handle it - switch(int_no) - { - case ADC_READY: - break; - case DAC_READY: - break; - case DOUT_ERROR: - break; - case DIN_STATUS: - break; - case CIE0: - break; - case CIE1: - break; - case CIE2: - break; - case CIE3: - break; - default: - break; + switch (int_no) { + case ADC_READY: + break; + case DAC_READY: + break; + case DOUT_ERROR: + break; + case DIN_STATUS: + break; + case CIE0: + break; + case CIE1: + break; + case CIE2: + break; + case CIE3: + break; + default: + break; } @@ -652,7 +668,6 @@ static irqreturn_t interrupt_service_icp_multi(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } - #if 0 /* ============================================================================== @@ -674,41 +689,40 @@ static irqreturn_t interrupt_service_icp_multi(int irq, void *d PT_REGS_ARG) ============================================================================== */ -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan) +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan) { - unsigned int i; + unsigned int i; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: check_channel_list(...,%d)\n",n_chan); + printk("icp multi EDBG: check_channel_list(...,%d)\n", n_chan); #endif - // Check that we at least have one channel to check - if (n_chan<1) { - comedi_error(dev,"range/channel list is empty!"); + // Check that we at least have one channel to check + if (n_chan < 1) { + comedi_error(dev, "range/channel list is empty!"); return 0; - } - + } // Check all channels - for (i=0; i this_board->n_aichand) { - comedi_error(dev,"Incorrect differential ai channel number"); + comedi_error(dev, + "Incorrect differential ai channel number"); return 0; } - } - else { + } else { if (CR_CHAN(chanlist[i]) > this_board->n_aichan) { - comedi_error(dev,"Incorrect ai channel number"); + comedi_error(dev, + "Incorrect ai channel number"); return 0; } - } + } } return 1; } #endif - - /* ============================================================================== @@ -729,28 +743,27 @@ static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigne ============================================================================== */ -static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan) +static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan) { unsigned int i, range, chanprog; unsigned int diff; #ifdef ICP_MULTI_EXTDEBUG - printk("icp multi EDBG: setup_channel_list(...,%d)\n",n_chan); + printk("icp multi EDBG: setup_channel_list(...,%d)\n", n_chan); #endif - devpriv->act_chanlist_len=n_chan; - devpriv->act_chanlist_pos=0; + devpriv->act_chanlist_len = n_chan; + devpriv->act_chanlist_pos = 0; - for (i=0; iAdcCmdStatus |= (chanprog << 9); devpriv->AdcCmdStatus |= ADC_DI; - } - else + } else // Set channel number, bits 8-11 devpriv->AdcCmdStatus |= (chanprog << 8); // Get range for current channel - range=this_board->rangecode[CR_RANGE(chanlist[i])]; + range = this_board->rangecode[CR_RANGE(chanlist[i])]; // Set range. bits 4-5 devpriv->AdcCmdStatus |= range; - /* Output channel, range, mode to ICP Multi*/ - writew(devpriv->AdcCmdStatus, devpriv->io_addr+ICP_MULTI_ADC_CSR); + /* Output channel, range, mode to ICP Multi */ + writew(devpriv->AdcCmdStatus, + devpriv->io_addr + ICP_MULTI_ADC_CSR); #ifdef ICP_MULTI_EXTDEBUG - printk("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range, devpriv->act_chanlist[i]); + printk("GS: %2d. [%4x]=%4x %4x\n", i, chanprog, range, + devpriv->act_chanlist[i]); #endif } } - /* ============================================================================== @@ -799,9 +812,9 @@ static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsign ============================================================================== */ -static int icp_multi_reset(comedi_device *dev) +static int icp_multi_reset(comedi_device * dev) { - unsigned int i; + unsigned int i; #ifdef ICP_MULTI_EXTDEBUG printk("icp_multi EDBG: BGN: icp_multi_reset(...)\n"); @@ -812,25 +825,25 @@ static int icp_multi_reset(comedi_device *dev) if (this_board->n_aochan) // Set DACs to 0..5V range and 0V output - for (i =0; i < this_board->n_aochan; i++) { + for (i = 0; i < this_board->n_aochan; i++) { devpriv->DacCmdStatus &= 0xfcce; // Set channel number devpriv->DacCmdStatus |= (i << 8); // Output 0V - writew(0, devpriv->io_addr+ICP_MULTI_AO); + writew(0, devpriv->io_addr + ICP_MULTI_AO); // Set start conversion bit devpriv->DacCmdStatus |= DAC_ST; // Output to command / status register - writew(devpriv->DacCmdStatus, devpriv->io_addr+ICP_MULTI_DAC_CSR); + writew(devpriv->DacCmdStatus, + devpriv->io_addr + ICP_MULTI_DAC_CSR); // Delay to allow DAC time to recover comedi_udelay(1); } - // Digital outputs to 0 writew(0, devpriv->io_addr + ICP_MULTI_DO); @@ -857,49 +870,53 @@ static int icp_multi_reset(comedi_device *dev) ============================================================================== */ -static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) +static int icp_multi_attach(comedi_device * dev, comedi_devconfig * it) { - comedi_subdevice *s; + comedi_subdevice *s; int ret, subdev, n_subdevices; - unsigned int irq; - struct pcilst_struct *card=NULL; - resource_size_t io_addr[5], iobase; - unsigned char pci_bus, pci_slot, pci_func; + unsigned int irq; + struct pcilst_struct *card = NULL; + resource_size_t io_addr[5], iobase; + unsigned char pci_bus, pci_slot, pci_func; printk("icp_multi EDBG: BGN: icp_multi_attach(...)\n"); // Alocate private data storage space - if ((ret=alloc_private(dev, sizeof(icp_multi_private)))<0) + if ((ret = alloc_private(dev, sizeof(icp_multi_private))) < 0) return ret; // Initialise list of PCI cards in system, if not already done so if (pci_list_builded++ == 0) { pci_card_list_init(PCI_VENDOR_ID_ICP, #ifdef ICP_MULTI_EXTDEBUG - 1 + 1 #else - 0 + 0 #endif ); } - printk("Anne's comedi%d: icp_multi: board=%s", dev->minor, this_board->name); + printk("Anne's comedi%d: icp_multi: board=%s", dev->minor, + this_board->name); - if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ICP, this_board->device_id, it->options[0], it->options[1]))==NULL) + if ((card = select_and_alloc_pci_card(PCI_VENDOR_ID_ICP, + this_board->device_id, it->options[0], + it->options[1])) == NULL) return -EIO; devpriv->card = card; - if ((pci_card_data(card, &pci_bus, &pci_slot, &pci_func, &io_addr[0], &irq))<0) { + if ((pci_card_data(card, &pci_bus, &pci_slot, &pci_func, &io_addr[0], + &irq)) < 0) { printk(" - Can't get configuration data!\n"); return -EIO; } - iobase=io_addr[2]; + iobase = io_addr[2]; devpriv->phys_iobase = iobase; printk(", b:s:f=%d:%d:%d, io=0x%8llx \n", pci_bus, pci_slot, pci_func, - (unsigned long long)iobase); + (unsigned long long)iobase); devpriv->io_addr = ioremap(iobase, ICP_MULTI_SIZE); @@ -907,72 +924,75 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) printk("ioremap failed.\n"); return -ENOMEM; } - #ifdef ICP_MULTI_EXTDEBUG - printk("0x%08llx mapped to %p, ", (unsigned long long)iobase, devpriv->io_addr); + printk("0x%08llx mapped to %p, ", (unsigned long long)iobase, + devpriv->io_addr); #endif dev->board_name = this_board->name; - n_subdevices = 0; - if (this_board->n_aichan) n_subdevices++; - if (this_board->n_aochan) n_subdevices++; - if (this_board->n_dichan) n_subdevices++; - if (this_board->n_dochan) n_subdevices++; - if (this_board->n_ctrs) n_subdevices++; - - if((ret=alloc_subdevices(dev, n_subdevices))<0) { - return ret; + n_subdevices = 0; + if (this_board->n_aichan) + n_subdevices++; + if (this_board->n_aochan) + n_subdevices++; + if (this_board->n_dichan) + n_subdevices++; + if (this_board->n_dochan) + n_subdevices++; + if (this_board->n_ctrs) + n_subdevices++; + + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) { + return ret; } icp_multi_reset(dev); if (this_board->have_irq) { - if (irq) { - if (comedi_request_irq(irq, interrupt_service_icp_multi, IRQF_SHARED, "Inova Icp Multi", dev)) { + if (irq) { + if (comedi_request_irq(irq, interrupt_service_icp_multi, + IRQF_SHARED, "Inova Icp Multi", dev)) { printk(", unable to allocate IRQ %u, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ - } - else + irq = 0; /* Can't use IRQ */ + } else printk(", irq=%u", irq); - } - else + } else printk(", IRQ disabled"); - } - else - irq=0; + } else + irq = 0; - dev->irq = irq; + dev->irq = irq; printk(".\n"); - subdev=0; + subdev = 0; if (this_board->n_aichan) { s = dev->subdevices + subdev; dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_COMMON|SDF_GROUND; + s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND; if (this_board->n_aichand) s->subdev_flags |= SDF_DIFF; s->n_chan = this_board->n_aichan; s->maxdata = this_board->ai_maxdata; s->len_chanlist = this_board->n_aichan; s->range_table = this_board->rangelist_ai; - s->insn_read=icp_multi_insn_read_ai; + s->insn_read = icp_multi_insn_read_ai; subdev++; } if (this_board->n_aochan) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_aochan; s->maxdata = this_board->ao_maxdata; s->len_chanlist = this_board->n_aochan; s->range_table = this_board->rangelist_ao; - s->insn_write=icp_multi_insn_write_ao; - s->insn_read=icp_multi_insn_read_ao; + s->insn_write = icp_multi_insn_write_ao; + s->insn_read = icp_multi_insn_read_ao; subdev++; } @@ -984,8 +1004,8 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) s->maxdata = 1; s->len_chanlist = this_board->n_dichan; s->range_table = &range_digital; - s->io_bits=0; - s->insn_bits=icp_multi_insn_bits_di; + s->io_bits = 0; + s->insn_bits = icp_multi_insn_bits_di; subdev++; } @@ -997,22 +1017,22 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) s->maxdata = 1; s->len_chanlist = this_board->n_dochan; s->range_table = &range_digital; - s->io_bits=(1 << this_board->n_dochan)-1; - s->state=0; - s->insn_bits=icp_multi_insn_bits_do; + s->io_bits = (1 << this_board->n_dochan) - 1; + s->state = 0; + s->insn_bits = icp_multi_insn_bits_do; subdev++; } if (this_board->n_ctrs) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND|SDF_COMMON; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; s->n_chan = this_board->n_ctrs; s->maxdata = 0xffff; s->len_chanlist = this_board->n_ctrs; - s->state=0; - s->insn_read=icp_multi_insn_read_ctr; - s->insn_write=icp_multi_insn_write_ctr; + s->state = 0; + s->insn_read = icp_multi_insn_read_ctr; + s->insn_write = icp_multi_insn_write_ctr; subdev++; } @@ -1041,7 +1061,7 @@ static int icp_multi_attach(comedi_device *dev,comedi_devconfig *it) ============================================================================== */ -static int icp_multi_detach(comedi_device *dev) +static int icp_multi_detach(comedi_device * dev) { if (dev->private) @@ -1049,7 +1069,7 @@ static int icp_multi_detach(comedi_device *dev) icp_multi_reset(dev); if (dev->irq) - comedi_free_irq(dev->irq,dev); + comedi_free_irq(dev->irq, dev); if (dev->private && devpriv->io_addr) iounmap(devpriv->io_addr); @@ -1058,10 +1078,8 @@ static int icp_multi_detach(comedi_device *dev) pci_card_free(devpriv->card); if (--pci_list_builded == 0) { - pci_card_list_cleanup(PCI_VENDOR_ID_ICP); + pci_card_list_cleanup(PCI_VENDOR_ID_ICP); } - return 0; } - diff --git a/comedi/drivers/icp_multi.h b/comedi/drivers/icp_multi.h index 0b403ac6..adce960a 100644 --- a/comedi/drivers/icp_multi.h +++ b/comedi/drivers/icp_multi.h @@ -13,21 +13,19 @@ #include #include "comedi_pci.h" - - /****************************************************************************/ -struct pcilst_struct{ - struct pcilst_struct *next; - int used; - struct pci_dev *pcidev; - unsigned short vendor; - unsigned short device; - unsigned char pci_bus; - unsigned char pci_slot; - unsigned char pci_func; - resource_size_t io_addr[5]; - unsigned int irq; +struct pcilst_struct { + struct pcilst_struct *next; + int used; + struct pci_dev *pcidev; + unsigned short vendor; + unsigned short device; + unsigned char pci_bus; + unsigned char pci_slot; + unsigned char pci_func; + resource_size_t io_addr[5]; + unsigned int irq; }; struct pcilst_struct *inova_devices; // ptr to root list of all Inova devices @@ -36,16 +34,21 @@ struct pcilst_struct *inova_devices; // ptr to root list of all Inova devices static void pci_card_list_init(unsigned short pci_vendor, char display); static void pci_card_list_cleanup(unsigned short pci_vendor); -static struct pcilst_struct *find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id); -static int find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card); -static struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot); +static struct pcilst_struct *find_free_pci_card_by_device(unsigned short + vendor_id, unsigned short device_id); +static int find_free_pci_card_by_position(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, struct pcilst_struct **card); +static struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot); static int pci_card_alloc(struct pcilst_struct *amcc); static int pci_card_free(struct pcilst_struct *amcc); static void pci_card_list_display(void); static int pci_card_data(struct pcilst_struct *amcc, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - resource_size_t *io_addr, unsigned int *irq); + unsigned char *pci_bus, unsigned char *pci_slot, + unsigned char *pci_func, resource_size_t * io_addr, unsigned int *irq); /****************************************************************************/ @@ -53,70 +56,79 @@ static int pci_card_data(struct pcilst_struct *amcc, static void pci_card_list_init(unsigned short pci_vendor, char display) { struct pci_dev *pcidev; - struct pcilst_struct *inova,*last; + struct pcilst_struct *inova, *last; int i; - inova_devices=NULL; - last=NULL; - - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + inova_devices = NULL; + last = NULL; + + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if(pcidev->vendor==pci_vendor){ - inova=kmalloc(sizeof(*inova),GFP_KERNEL); - if(!inova){ + if (pcidev->vendor == pci_vendor) { + inova = kmalloc(sizeof(*inova), GFP_KERNEL); + if (!inova) { printk("icp_multi: pci_card_list_init: allocation failed\n"); pci_dev_put(pcidev); break; } - memset(inova,0,sizeof(*inova)); - - inova->pcidev=pci_dev_get(pcidev); - if (last) { last->next=inova; } - else { inova_devices=inova; } - last=inova; - - inova->vendor=pcidev->vendor; - inova->device=pcidev->device; - inova->pci_bus=pcidev->bus->number; - inova->pci_slot=PCI_SLOT(pcidev->devfn); - inova->pci_func=PCI_FUNC(pcidev->devfn); + memset(inova, 0, sizeof(*inova)); + + inova->pcidev = pci_dev_get(pcidev); + if (last) { + last->next = inova; + } else { + inova_devices = inova; + } + last = inova; + + inova->vendor = pcidev->vendor; + inova->device = pcidev->device; + inova->pci_bus = pcidev->bus->number; + inova->pci_slot = PCI_SLOT(pcidev->devfn); + inova->pci_func = PCI_FUNC(pcidev->devfn); /* Note: resources may be invalid if PCI device * not enabled, but they are corrected in * pci_card_alloc. */ - for (i=0;i<5;i++) - inova->io_addr[i]=pci_resource_start(pcidev, i); - inova->irq=pcidev->irq; + for (i = 0; i < 5; i++) + inova->io_addr[i] = + pci_resource_start(pcidev, i); + inova->irq = pcidev->irq; } } - if (display) pci_card_list_display(); + if (display) + pci_card_list_display(); } /****************************************************************************/ /* free up list of amcc cards in this system */ static void pci_card_list_cleanup(unsigned short pci_vendor) { - struct pcilst_struct *inova,*next; + struct pcilst_struct *inova, *next; - for(inova=inova_devices; inova; inova=next){ - next=inova->next; + for (inova = inova_devices; inova; inova = next) { + next = inova->next; pci_dev_put(inova->pcidev); kfree(inova); } - - inova_devices=NULL; + + inova_devices = NULL; } /****************************************************************************/ /* find first unused card with this device_id */ -static struct pcilst_struct *find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id) +static struct pcilst_struct *find_free_pci_card_by_device(unsigned short + vendor_id, unsigned short device_id) { - struct pcilst_struct *inova,*next; + struct pcilst_struct *inova, *next; + + for (inova = inova_devices; inova; inova = next) { + next = inova->next; + if ((!inova->used) && (inova->device == device_id) + && (inova->vendor == vendor_id)) + return inova; - for (inova=inova_devices; inova; inova=next) { - next=inova->next; - if ((!inova->used)&&(inova->device==device_id)&&(inova->vendor==vendor_id)) return inova; - } return NULL; @@ -124,16 +136,20 @@ static struct pcilst_struct *find_free_pci_card_by_device(unsigned short vendor_ /****************************************************************************/ /* find card on requested position */ -static int find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card) +static int find_free_pci_card_by_position(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot, struct pcilst_struct **card) { - struct pcilst_struct *inova,*next; + struct pcilst_struct *inova, *next; - *card=NULL; - for (inova=inova_devices; inova; inova=next) { - next=inova->next; - if ((inova->vendor==vendor_id)&&(inova->device==device_id)&&(inova->pci_bus==pci_bus)&&(inova->pci_slot==pci_slot)) { + *card = NULL; + for (inova = inova_devices; inova; inova = next) { + next = inova->next; + if ((inova->vendor == vendor_id) && (inova->device == device_id) + && (inova->pci_bus == pci_bus) + && (inova->pci_slot == pci_slot)) { if (!(inova->used)) { - *card=inova; + *card = inova; return 0; // ok, card is found } else { return 2; // card exist but is used @@ -141,7 +157,7 @@ static int find_free_pci_card_by_position(unsigned short vendor_id, unsigned sho } } - return 1; // no card found + return 1; // no card found } /****************************************************************************/ @@ -155,16 +171,17 @@ static int pci_card_alloc(struct pcilst_struct *inova) return -1; } - if (inova->used) return 1; + if (inova->used) + return 1; if (comedi_pci_enable(inova->pcidev, "icp_multi")) { rt_printk(" - Can't enable PCI device and request regions!\n"); return -1; } /* Resources will be accurate now. */ - for (i=0;i<5;i++) - inova->io_addr[i]=pci_resource_start(inova->pcidev, i); - inova->irq=inova->pcidev->irq; - inova->used=1; + for (i = 0; i < 5; i++) + inova->io_addr[i] = pci_resource_start(inova->pcidev, i); + inova->irq = inova->pcidev->irq; + inova->used = 1; return 0; } @@ -172,10 +189,12 @@ static int pci_card_alloc(struct pcilst_struct *inova) /* mark card as free */ static int pci_card_free(struct pcilst_struct *inova) { - if (!inova) return -1; + if (!inova) + return -1; - if (!inova->used) return 1; - inova->used=0; + if (!inova->used) + return 1; + inova->used = 0; comedi_pci_disable(inova->pcidev); return 0; } @@ -189,58 +208,64 @@ static void pci_card_list_display(void) printk("Anne's List of pci cards\n"); printk("bus:slot:func vendor device io_inova io_daq irq used\n"); - for (inova=inova_devices; inova; inova=next) { - next=inova->next; - printk("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n", - inova->pci_bus,inova->pci_slot,inova->pci_func,inova->vendor,inova->device, - (unsigned long long)inova->io_addr[0],(unsigned long long)inova->io_addr[2],inova->irq,inova->used); - + for (inova = inova_devices; inova; inova = next) { + next = inova->next; + printk("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n", inova->pci_bus, inova->pci_slot, inova->pci_func, inova->vendor, inova->device, (unsigned long long)inova->io_addr[0], (unsigned long long)inova->io_addr[2], inova->irq, inova->used); + } } /****************************************************************************/ /* return all card information for driver */ static int pci_card_data(struct pcilst_struct *inova, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - resource_size_t *io_addr, unsigned int *irq) + unsigned char *pci_bus, unsigned char *pci_slot, + unsigned char *pci_func, resource_size_t * io_addr, unsigned int *irq) { - int i; - - if (!inova) return -1; - *pci_bus=inova->pci_bus; - *pci_slot=inova->pci_slot; - *pci_func=inova->pci_func; - for (i=0;i<5;i++) - io_addr[i]=inova->io_addr[i]; - *irq=inova->irq; + int i; + + if (!inova) + return -1; + *pci_bus = inova->pci_bus; + *pci_slot = inova->pci_slot; + *pci_func = inova->pci_func; + for (i = 0; i < 5; i++) + io_addr[i] = inova->io_addr[i]; + *irq = inova->irq; return 0; } /****************************************************************************/ /* select and alloc card */ -static struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot) +static struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, + unsigned short device_id, unsigned short pci_bus, + unsigned short pci_slot) { struct pcilst_struct *card; int err; - - if ((pci_bus<1)&(pci_slot<1)) { // use autodetection - if ((card=find_free_pci_card_by_device(vendor_id,device_id))==NULL) { + + if ((pci_bus < 1) & (pci_slot < 1)) { // use autodetection + if ((card = find_free_pci_card_by_device(vendor_id, + device_id)) == NULL) { rt_printk(" - Unused card not found in system!\n"); return NULL; } } else { - switch (find_free_pci_card_by_position(vendor_id,device_id,pci_bus,pci_slot,&card)) { + switch (find_free_pci_card_by_position(vendor_id, device_id, + pci_bus, pci_slot, &card)) { case 1: - rt_printk(" - Card not found on requested position b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card not found on requested position b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; case 2: - rt_printk(" - Card on requested position is used b:s %d:%d!\n",pci_bus,pci_slot); + rt_printk + (" - Card on requested position is used b:s %d:%d!\n", + pci_bus, pci_slot); return NULL; } } - - if ((err=pci_card_alloc(card))!=0) { + if ((err = pci_card_alloc(card)) != 0) { if (err > 0) rt_printk(" - Can't allocate card!\n"); /* else: error already printed. */ diff --git a/comedi/drivers/ii_pci20kc.c b/comedi/drivers/ii_pci20kc.c index 374e3dce..379bd84f 100644 --- a/comedi/drivers/ii_pci20kc.c +++ b/comedi/drivers/ii_pci20kc.c @@ -81,7 +81,6 @@ options for PCI-20341M: #include - #define PCI20000_ID 0x1d #define PCI20341_ID 0x77 #define PCI20006_ID 0xe3 @@ -115,7 +114,7 @@ options for PCI-20341M: #define PCI20006_LCHAN1 0x15 #define PCI20006_STROBE1 0x13 -#define PCI20341_INIT 0x04 +#define PCI20341_INIT 0x04 #define PCI20341_REPMODE 0x00 /* single shot mode */ #define PCI20341_PACER 0x00 /* Hardware Pacer disabled */ #define PCI20341_CHAN_NR 0x04 /* number of input channels */ @@ -134,21 +133,19 @@ options for PCI-20341M: #define PCI20341_MUX 0x04 /* Enable on-board MUX */ #define PCI20341_SCANLIST 0x80 /* Channel/Gain Scan List */ - - typedef union { void *iobase; struct { void *iobase; const comedi_lrange *ao_range_list[2]; /* range of channels of ao module */ lsampl_t last_data[2]; - }pci20006; + } pci20006; struct { void *iobase; int timebase; int settling_time; int ai_gain; - }pci20341; + } pci20341; } pci20xxx_subdev_private; typedef struct { @@ -163,17 +160,17 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it); static int pci20xxx_detach(comedi_device * dev); static comedi_driver driver_pci20xxx = { - driver_name: "ii_pci20kc", - module: THIS_MODULE, - attach: pci20xxx_attach, - detach: pci20xxx_detach, + driver_name:"ii_pci20kc", + module:THIS_MODULE, + attach:pci20xxx_attach, + detach:pci20xxx_detach, }; -static int pci20006_init(comedi_device * dev,comedi_subdevice *s, - int opt0,int opt1); -static int pci20341_init(comedi_device * dev,comedi_subdevice *s, - int opt0,int opt1); -static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s); +static int pci20006_init(comedi_device * dev, comedi_subdevice * s, + int opt0, int opt1); +static int pci20341_init(comedi_device * dev, comedi_subdevice * s, + int opt0, int opt1); +static int pci20xxx_dio_init(comedi_device * dev, comedi_subdevice * s); /* options[0] Board base address @@ -215,7 +212,7 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it) if ((ret = alloc_private(dev, sizeof(pci20xxx_private))) < 0) return ret; - devpriv->ioaddr = (void*) (unsigned long) it->options[0]; + devpriv->ioaddr = (void *)(unsigned long)it->options[0]; dev->board_name = "pci20kc"; /* Check PCI-20001 C-2A Carrier Board ID */ @@ -229,25 +226,28 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it) for (i = 0; i < PCI20000_MODULES; i++) { s = dev->subdevices + i; - id = readb(devpriv->ioaddr + (i+1) * PCI20000_OFFSET); - s->private = devpriv->subdev_private +i; + id = readb(devpriv->ioaddr + (i + 1) * PCI20000_OFFSET); + s->private = devpriv->subdev_private + i; sdp = s->private; - switch(id){ + switch (id) { case PCI20006_ID: - sdp->pci20006.iobase = devpriv->ioaddr + (i+1) * PCI20000_OFFSET; - pci20006_init(dev,s,it->options[2*i+2],it->options[2*i+3]); + sdp->pci20006.iobase = + devpriv->ioaddr + (i + 1) * PCI20000_OFFSET; + pci20006_init(dev, s, it->options[2 * i + 2], + it->options[2 * i + 3]); printk("comedi%d: ii_pci20kc", dev->minor); - printk(" PCI-20006 module in slot %d \n", i+1); + printk(" PCI-20006 module in slot %d \n", i + 1); break; case PCI20341_ID: - sdp->pci20341.iobase = devpriv->ioaddr + (i+1) * PCI20000_OFFSET; - pci20341_init(dev,s,it->options[2*i+2],it->options[2*i+3]); + sdp->pci20341.iobase = + devpriv->ioaddr + (i + 1) * PCI20000_OFFSET; + pci20341_init(dev, s, it->options[2 * i + 2], + it->options[2 * i + 3]); printk("comedi%d: ii_pci20kc", dev->minor); - printk(" PCI-20341 module in slot %d \n", i+1); + printk(" PCI-20341 module in slot %d \n", i + 1); break; default: - printk("ii_pci20kc: unknown module code 0x%02x in slot %d: module disabled\n", - id,i); + printk("ii_pci20kc: unknown module code 0x%02x in slot %d: module disabled\n", id, i); /* fall through */ case PCI20xxx_EMPTY_ID: s->type = COMEDI_SUBD_UNUSED; @@ -256,7 +256,7 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it) } /* initialize pci20xxx_private */ - pci20xxx_dio_init(dev,dev->subdevices + PCI20000_MODULES); + pci20xxx_dio_init(dev, dev->subdevices + PCI20000_MODULES); return 1; } @@ -271,9 +271,9 @@ static int pci20xxx_detach(comedi_device * dev) /* pci20006m */ static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data); + comedi_insn * insn, lsampl_t * data); static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data); + comedi_insn * insn, lsampl_t * data); static const comedi_lrange *pci20006_range_list[] = { &range_bipolar10, @@ -281,13 +281,15 @@ static const comedi_lrange *pci20006_range_list[] = { &range_bipolar5, }; -static int pci20006_init(comedi_device * dev,comedi_subdevice *s, - int opt0,int opt1) +static int pci20006_init(comedi_device * dev, comedi_subdevice * s, + int opt0, int opt1) { pci20xxx_subdev_private *sdp = s->private; - if(opt0<0 || opt0>2) opt0=0; - if(opt1<0 || opt1>2) opt1=0; + if (opt0 < 0 || opt0 > 2) + opt0 = 0; + if (opt1 < 0 || opt1 > 2) + opt1 = 0; sdp->pci20006.ao_range_list[0] = pci20006_range_list[opt0]; sdp->pci20006.ao_range_list[1] = pci20006_range_list[opt1]; @@ -305,7 +307,7 @@ static int pci20006_init(comedi_device * dev,comedi_subdevice *s, } static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { pci20xxx_subdev_private *sdp = s->private; @@ -315,18 +317,18 @@ static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s, } static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { pci20xxx_subdev_private *sdp = s->private; int hi, lo; unsigned int boarddata; sdp->pci20006.last_data[CR_CHAN(insn->chanspec)] = data[0]; - boarddata = (((unsigned int)data[0]+0x8000) & 0xffff); /* comedi-data -> board-data */ + boarddata = (((unsigned int)data[0] + 0x8000) & 0xffff); /* comedi-data -> board-data */ lo = (boarddata & 0xff); hi = ((boarddata >> 8) & 0xff); - switch ( CR_CHAN(insn->chanspec)) { + switch (CR_CHAN(insn->chanspec)) { case 0: writeb(lo, sdp->iobase + PCI20006_LCHAN0); writeb(hi, sdp->iobase + PCI20006_LCHAN0 + 1); @@ -348,30 +350,31 @@ static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s, /* PCI20341M */ static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data); + comedi_insn * insn, lsampl_t * data); static const int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 }; static const int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 }; -static const comedi_lrange range_bipolar0_5 = { 1, { BIP_RANGE(0.5) }}; -static const comedi_lrange range_bipolar0_05 = { 1, { BIP_RANGE(0.05) }}; -static const comedi_lrange range_bipolar0_025 = { 1, { BIP_RANGE(0.025) }}; +static const comedi_lrange range_bipolar0_5 = { 1, {BIP_RANGE(0.5)} }; +static const comedi_lrange range_bipolar0_05 = { 1, {BIP_RANGE(0.05)} }; +static const comedi_lrange range_bipolar0_025 = { 1, {BIP_RANGE(0.025)} }; -static const comedi_lrange * const pci20341_ranges[] = { +static const comedi_lrange *const pci20341_ranges[] = { &range_bipolar5, &range_bipolar0_5, &range_bipolar0_05, &range_bipolar0_025, - }; +}; -static int pci20341_init(comedi_device * dev,comedi_subdevice *s, - int opt0,int opt1) +static int pci20341_init(comedi_device * dev, comedi_subdevice * s, + int opt0, int opt1) { pci20xxx_subdev_private *sdp = s->private; - int option; + int option; /* options handling */ - if(opt0<0 || opt0>3)opt0=0; + if (opt0 < 0 || opt0 > 3) + opt0 = 0; sdp->pci20341.timebase = pci20341_timebase[opt0]; sdp->pci20341.settling_time = pci20341_settling_time[opt0]; @@ -386,43 +389,41 @@ static int pci20341_init(comedi_device * dev,comedi_subdevice *s, option = sdp->pci20341.timebase | PCI20341_REPMODE; /* depends on gain, trigger, repetition mode */ - writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG); /* initialize Module */ - writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS); /* set Pacer */ - writeb(option, sdp->iobase + PCI20341_OPT_REG); /* option register */ + writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG); /* initialize Module */ + writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS); /* set Pacer */ + writeb(option, sdp->iobase + PCI20341_OPT_REG); /* option register */ writeb(sdp->pci20341.settling_time, sdp->iobase + PCI20341_SET_TIME_REG); /* settling time counter */ /* trigger not implemented */ return 0; } static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { pci20xxx_subdev_private *sdp = s->private; unsigned int i = 0, j = 0; int lo, hi; - unsigned char eoc; /* end of conversion */ - unsigned int clb; /* channel list byte */ + unsigned char eoc; /* end of conversion */ + unsigned int clb; /* channel list byte */ unsigned int boarddata; - writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG); /* write number of input channels */ - clb = PCI20341_DAISY_CHAIN - | PCI20341_MUX - | (sdp->pci20341.ai_gain << 3) - | CR_CHAN(insn->chanspec); + writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG); /* write number of input channels */ + clb = PCI20341_DAISY_CHAIN | PCI20341_MUX | (sdp->pci20341.ai_gain << 3) + | CR_CHAN(insn->chanspec); writeb(clb, sdp->iobase + PCI20341_CHAN_LIST); - writeb(0x00, sdp->iobase + PCI20341_CC_RESET); /* reset settling time counter and trigger delay counter */ + writeb(0x00, sdp->iobase + PCI20341_CC_RESET); /* reset settling time counter and trigger delay counter */ writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET); /* generate Pacer */ - for (i=0; i < insn->n; i++) { + for (i = 0; i < insn->n; i++) { /* data polling isn't the niciest way to get the data, I know, * but there are only 6 cycles (mean) and it is easier than * the whole interrupt stuff - */ - j=0; - readb(sdp->iobase + PCI20341_SOFT_PACER); /* generate Pacer */ - eoc = readb(sdp->iobase + PCI20341_STATUS_REG); + */ + j = 0; + readb(sdp->iobase + PCI20341_SOFT_PACER); /* generate Pacer */ + eoc = readb(sdp->iobase + PCI20341_STATUS_REG); while ((eoc < 0x80) && j < 100) { /* poll Interrupt Flag */ j++; eoc = readb(sdp->iobase + PCI20341_STATUS_REG); @@ -433,8 +434,8 @@ static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s, } lo = readb(sdp->iobase + PCI20341_LDATA); hi = readb(sdp->iobase + PCI20341_LDATA + 1); - boarddata = lo + 0x100 * hi; - data[i] = (sampl_t)((boarddata + 0x8000) & 0xffff); /* board-data -> comedi-data */ + boarddata = lo + 0x100 * hi; + data[i] = (sampl_t) ((boarddata + 0x8000) & 0xffff); /* board-data -> comedi-data */ } return i; @@ -442,14 +443,14 @@ static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s, /* native DIO */ -static void pci20xxx_dio_config(comedi_device * dev,comedi_subdevice *s); -static int pci20xxx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int pci20xxx_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static void pci20xxx_dio_config(comedi_device * dev, comedi_subdevice * s); +static int pci20xxx_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pci20xxx_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* initialize pci20xxx_private */ -static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s) +static int pci20xxx_dio_init(comedi_device * dev, comedi_subdevice * s) { s->type = COMEDI_SUBD_DIO; @@ -463,111 +464,119 @@ static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s) s->io_bits = 0; /* digital I/O lines default to input on board reset. */ - pci20xxx_dio_config(dev,s); + pci20xxx_dio_config(dev, s); return 0; } -static int pci20xxx_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci20xxx_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int mask,bits; + int mask, bits; - mask = 1<chanspec); - if(mask&0x000000ff){ + mask = 1 << CR_CHAN(insn->chanspec); + if (mask & 0x000000ff) { bits = 0x000000ff; - }else if(mask & 0x0000ff00){ + } else if (mask & 0x0000ff00) { bits = 0x0000ff00; - }else if(mask & 0x00ff0000){ + } else if (mask & 0x00ff0000) { bits = 0x00ff0000; - }else { + } else { bits = 0xff000000; } - if(data[0]){ + if (data[0]) { s->io_bits |= bits; - }else{ + } else { s->io_bits &= ~bits; } - pci20xxx_dio_config(dev,s); + pci20xxx_dio_config(dev, s); return 1; } -static int pci20xxx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pci20xxx_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int mask = data[0]; s->state &= ~mask; - s->state |= (mask&data[1]); + s->state |= (mask & data[1]); mask &= s->io_bits; - if(mask&0x000000ff) - writeb((s->state>>0)&0xff, devpriv->ioaddr + PCI20000_DIO_0 ); - if(mask&0x0000ff00) - writeb((s->state>>8)&0xff, devpriv->ioaddr + PCI20000_DIO_1 ); - if(mask&0x00ff0000) - writeb((s->state>>16)&0xff, devpriv->ioaddr + PCI20000_DIO_2 ); - if(mask&0xff000000) - writeb((s->state>>24)&0xff, devpriv->ioaddr + PCI20000_DIO_3 ); - - data[1] = readb(devpriv->ioaddr + PCI20000_DIO_0 ); - data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_1 )<<8; - data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_2 )<<16; - data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_3 )<<24; + if (mask & 0x000000ff) + writeb((s->state >> 0) & 0xff, + devpriv->ioaddr + PCI20000_DIO_0); + if (mask & 0x0000ff00) + writeb((s->state >> 8) & 0xff, + devpriv->ioaddr + PCI20000_DIO_1); + if (mask & 0x00ff0000) + writeb((s->state >> 16) & 0xff, + devpriv->ioaddr + PCI20000_DIO_2); + if (mask & 0xff000000) + writeb((s->state >> 24) & 0xff, + devpriv->ioaddr + PCI20000_DIO_3); + + data[1] = readb(devpriv->ioaddr + PCI20000_DIO_0); + data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8; + data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16; + data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24; return 2; } -static void pci20xxx_dio_config(comedi_device * dev,comedi_subdevice *s) +static void pci20xxx_dio_config(comedi_device * dev, comedi_subdevice * s) { unsigned char control_01; unsigned char control_23; unsigned char buffer; control_01 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_01); - control_23 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_23); - buffer = readb(devpriv->ioaddr + PCI20000_DIO_BUFFER); + control_23 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_23); + buffer = readb(devpriv->ioaddr + PCI20000_DIO_BUFFER); - if(s->io_bits & 0x000000ff ){ + if (s->io_bits & 0x000000ff) { /* output port 0 */ control_01 &= PCI20000_DIO_EOC; - buffer = (buffer &(~(DIO_BE<io_bits & 0x0000ff00 ){ + if (s->io_bits & 0x0000ff00) { /* output port 1 */ control_01 &= PCI20000_DIO_OOC; - buffer = (buffer &(~(DIO_BE<io_bits & 0x00ff0000 ){ + if (s->io_bits & 0x00ff0000) { /* output port 2 */ control_23 &= PCI20000_DIO_EOC; - buffer = (buffer &(~(DIO_BE<io_bits & 0xff000000 ){ + if (s->io_bits & 0xff000000) { /* output port 3 */ control_23 &= PCI20000_DIO_OOC; - buffer = (buffer &(~(DIO_BE<ioaddr + PCI20000_DIO_CONTROL_01); - writeb(control_23, devpriv->ioaddr + PCI20000_DIO_CONTROL_23); - writeb(buffer, devpriv->ioaddr + PCI20000_DIO_BUFFER); + writeb(control_23, devpriv->ioaddr + PCI20000_DIO_CONTROL_23); + writeb(buffer, devpriv->ioaddr + PCI20000_DIO_BUFFER); } #if 0 @@ -578,25 +587,24 @@ static void pci20xxx_do(comedi_device * dev, comedi_subdevice * s) /* XXX it would be a good idea to only update the registers that _need_ to be updated. This requires changes to comedi, however. */ - writeb((s->state>>0)&0xff, devpriv->ioaddr + PCI20000_DIO_0 ); - writeb((s->state>>8)&0xff, devpriv->ioaddr + PCI20000_DIO_1 ); - writeb((s->state>>16)&0xff, devpriv->ioaddr + PCI20000_DIO_2 ); - writeb((s->state>>24)&0xff, devpriv->ioaddr + PCI20000_DIO_3 ); + writeb((s->state >> 0) & 0xff, devpriv->ioaddr + PCI20000_DIO_0); + writeb((s->state >> 8) & 0xff, devpriv->ioaddr + PCI20000_DIO_1); + writeb((s->state >> 16) & 0xff, devpriv->ioaddr + PCI20000_DIO_2); + writeb((s->state >> 24) & 0xff, devpriv->ioaddr + PCI20000_DIO_3); } static unsigned int pci20xxx_di(comedi_device * dev, comedi_subdevice * s) { /* XXX same note as above */ unsigned int bits; - - bits = readb(devpriv->ioaddr + PCI20000_DIO_0 ); - bits |= readb(devpriv->ioaddr + PCI20000_DIO_1 )<<8; - bits |= readb(devpriv->ioaddr + PCI20000_DIO_2 )<<16; - bits |= readb(devpriv->ioaddr + PCI20000_DIO_3 )<<24; + + bits = readb(devpriv->ioaddr + PCI20000_DIO_0); + bits |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8; + bits |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16; + bits |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24; return bits; } #endif COMEDI_INITCLEANUP(driver_pci20xxx); - diff --git a/comedi/drivers/jr3_pci.c b/comedi/drivers/jr3_pci.c index 497b74dd..e6fe774a 100644 --- a/comedi/drivers/jr3_pci.c +++ b/comedi/drivers/jr3_pci.c @@ -53,830 +53,920 @@ Devices: [JR3] PCI force sensor board (jr3_pci) static void comedi_fw_release(struct device *dev) { - printk(KERN_DEBUG "firmware_sample_driver: ghost_release\n"); + printk(KERN_DEBUG "firmware_sample_driver: ghost_release\n"); } static struct device comedi_fw_device = { - .bus_id = "comedi", - .release = comedi_fw_release + .bus_id = "comedi", + .release = comedi_fw_release }; -typedef int comedi_firmware_callback(comedi_device *dev, - u8 *data, - size_t size); - -static int comedi_load_firmware(comedi_device *dev, - char *name, - comedi_firmware_callback cb) { - int result = 0; - const struct firmware *fw; - char *firmware_path; - static const char *prefix = "comedi/"; - - firmware_path = kmalloc(strlen(prefix) + strlen(name) + 1, GFP_KERNEL); - if (!firmware_path) { - result = -ENOMEM; - } else { - firmware_path[0] = '\0'; - strcat(firmware_path, prefix); - strcat(firmware_path, name); - result = device_register(&comedi_fw_device); - if (result == 0) { - result = request_firmware(&fw, firmware_path, &comedi_fw_device); - if (result == 0) { - if (!cb) { - result = -EINVAL; +typedef int comedi_firmware_callback(comedi_device * dev, + u8 * data, size_t size); + +static int comedi_load_firmware(comedi_device * dev, + char *name, comedi_firmware_callback cb) +{ + int result = 0; + const struct firmware *fw; + char *firmware_path; + static const char *prefix = "comedi/"; + + firmware_path = kmalloc(strlen(prefix) + strlen(name) + 1, GFP_KERNEL); + if (!firmware_path) { + result = -ENOMEM; } else { - result = cb(dev, fw->data, fw->size); + firmware_path[0] = '\0'; + strcat(firmware_path, prefix); + strcat(firmware_path, name); + result = device_register(&comedi_fw_device); + if (result == 0) { + result = request_firmware(&fw, firmware_path, + &comedi_fw_device); + if (result == 0) { + if (!cb) { + result = -EINVAL; + } else { + result = cb(dev, fw->data, fw->size); + } + release_firmware(fw); + } + device_unregister(&comedi_fw_device); + } + kfree(firmware_path); } - release_firmware(fw); - } - device_unregister(&comedi_fw_device); - } - kfree(firmware_path); - } - return result; + return result; } - - #define PCI_VENDOR_ID_JR3 0x1762 #define PCI_DEVICE_ID_JR3_1_CHANNEL 0x3111 #define PCI_DEVICE_ID_JR3_2_CHANNEL 0x3112 #define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113 #define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114 -static int jr3_pci_attach(comedi_device *dev,comedi_devconfig *it); -static int jr3_pci_detach(comedi_device *dev); +static int jr3_pci_attach(comedi_device * dev, comedi_devconfig * it); +static int jr3_pci_detach(comedi_device * dev); static comedi_driver driver_jr3_pci = { - driver_name: "jr3_pci", - module: THIS_MODULE, - attach: jr3_pci_attach, - detach: jr3_pci_detach, + driver_name:"jr3_pci", + module:THIS_MODULE, + attach:jr3_pci_attach, + detach:jr3_pci_detach, }; static struct pci_device_id jr3_pci_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_4_CHANNEL, - PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_4_CHANNEL, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, jr3_pci_pci_table); typedef struct { - struct pci_dev *pci_dev; - int pci_enabled; - volatile jr3_t *iobase; - int n_channels; - struct timer_list timer; + struct pci_dev *pci_dev; + int pci_enabled; + volatile jr3_t *iobase; + int n_channels; + struct timer_list timer; } jr3_pci_dev_private; typedef struct { - int min; - int max; + int min; + int max; } poll_delay_t; typedef struct { - volatile jr3_channel_t *channel; - unsigned long next_time_min; - unsigned long next_time_max; - enum { state_jr3_poll, - state_jr3_init_wait_for_offset, - state_jr3_init_transform_complete, - state_jr3_init_set_full_scale_complete, - state_jr3_init_use_offset_complete, - state_jr3_done } state; - int channel_no; - int serial_no; - int model_no; - struct { - int length; - comedi_krange range; - } range[9]; - const comedi_lrange * range_table_list[8 * 7 + 2]; - lsampl_t maxdata_list[8 * 7 + 2]; - u16 errors; - int retries; + volatile jr3_channel_t *channel; + unsigned long next_time_min; + unsigned long next_time_max; + enum { state_jr3_poll, + state_jr3_init_wait_for_offset, + state_jr3_init_transform_complete, + state_jr3_init_set_full_scale_complete, + state_jr3_init_use_offset_complete, + state_jr3_done + } state; + int channel_no; + int serial_no; + int model_no; + struct { + int length; + comedi_krange range; + } range[9]; + const comedi_lrange *range_table_list[8 * 7 + 2]; + lsampl_t maxdata_list[8 * 7 + 2]; + u16 errors; + int retries; } jr3_pci_subdev_private; static poll_delay_t poll_delay_min_max(int min, int max) { - poll_delay_t result; + poll_delay_t result; - result.min = min; - result.max = max; - return result; + result.min = min; + result.max = max; + return result; } -static int is_complete(volatile jr3_channel_t *channel) +static int is_complete(volatile jr3_channel_t * channel) { - return get_s16(&channel->command_word0) == 0; + return get_s16(&channel->command_word0) == 0; } - + typedef struct { - struct { - u16 link_type; - s16 link_amount; - } link[8]; + struct { + u16 link_type; + s16 link_amount; + } link[8]; } transform_t; -static void set_transforms(volatile jr3_channel_t *channel, - transform_t transf, - short num) +static void set_transforms(volatile jr3_channel_t * channel, + transform_t transf, short num) { - int i; - - num &= 0x000f; // Make sure that 0 <= num <= 15 - for (i = 0 ; i < 8 ; i++) { - - set_u16(&channel->transforms[num].link[i].link_type, - transf.link[i].link_type); - comedi_udelay(1); - set_s16(&channel->transforms[num].link[i].link_amount, - transf.link[i].link_amount); - comedi_udelay(1); - if (transf.link[i].link_type == end_x_form) { - break; - } - } + int i; + + num &= 0x000f; // Make sure that 0 <= num <= 15 + for (i = 0; i < 8; i++) { + + set_u16(&channel->transforms[num].link[i].link_type, + transf.link[i].link_type); + comedi_udelay(1); + set_s16(&channel->transforms[num].link[i].link_amount, + transf.link[i].link_amount); + comedi_udelay(1); + if (transf.link[i].link_type == end_x_form) { + break; + } + } } -static void use_transform(volatile jr3_channel_t *channel, - short transf_num) +static void use_transform(volatile jr3_channel_t * channel, short transf_num) { - set_s16(&channel->command_word0, 0x0500 + (transf_num & 0x000f)); + set_s16(&channel->command_word0, 0x0500 + (transf_num & 0x000f)); } -static void use_offset(volatile jr3_channel_t *channel, short offset_num) +static void use_offset(volatile jr3_channel_t * channel, short offset_num) { - set_s16(&channel->command_word0, 0x0600 + (offset_num & 0x000f)); + set_s16(&channel->command_word0, 0x0600 + (offset_num & 0x000f)); } -static void set_offset(volatile jr3_channel_t *channel) +static void set_offset(volatile jr3_channel_t * channel) { - set_s16(&channel->command_word0, 0x0700); + set_s16(&channel->command_word0, 0x0700); } typedef struct { - s16 fx; - s16 fy; - s16 fz; - s16 mx; - s16 my; - s16 mz; + s16 fx; + s16 fy; + s16 fz; + s16 mx; + s16 my; + s16 mz; } six_axis_t; -static void set_full_scales(volatile jr3_channel_t *channel, - six_axis_t full_scale) +static void set_full_scales(volatile jr3_channel_t * channel, + six_axis_t full_scale) { - printk("%d %d %d %d %d %d\n", - full_scale.fx, - full_scale.fy, - full_scale.fz, - full_scale.mx, - full_scale.my, - full_scale.mz); - set_s16(&channel->full_scale.fx, full_scale.fx); - set_s16(&channel->full_scale.fy, full_scale.fy); - set_s16(&channel->full_scale.fz, full_scale.fz); - set_s16(&channel->full_scale.mx, full_scale.mx); - set_s16(&channel->full_scale.my, full_scale.my); - set_s16(&channel->full_scale.mz, full_scale.mz); - set_s16(&channel->command_word0, 0x0a00); + printk("%d %d %d %d %d %d\n", + full_scale.fx, + full_scale.fy, + full_scale.fz, full_scale.mx, full_scale.my, full_scale.mz); + set_s16(&channel->full_scale.fx, full_scale.fx); + set_s16(&channel->full_scale.fy, full_scale.fy); + set_s16(&channel->full_scale.fz, full_scale.fz); + set_s16(&channel->full_scale.mx, full_scale.mx); + set_s16(&channel->full_scale.my, full_scale.my); + set_s16(&channel->full_scale.mz, full_scale.mz); + set_s16(&channel->command_word0, 0x0a00); } -static six_axis_t get_min_full_scales(volatile jr3_channel_t *channel) +static six_axis_t get_min_full_scales(volatile jr3_channel_t * channel) { - six_axis_t result; - result.fx = get_s16(&channel->min_full_scale.fx); - result.fy = get_s16(&channel->min_full_scale.fy); - result.fz = get_s16(&channel->min_full_scale.fz); - result.mx = get_s16(&channel->min_full_scale.mx); - result.my = get_s16(&channel->min_full_scale.my); - result.mz = get_s16(&channel->min_full_scale.mz); - return result; + six_axis_t result; + result.fx = get_s16(&channel->min_full_scale.fx); + result.fy = get_s16(&channel->min_full_scale.fy); + result.fz = get_s16(&channel->min_full_scale.fz); + result.mx = get_s16(&channel->min_full_scale.mx); + result.my = get_s16(&channel->min_full_scale.my); + result.mz = get_s16(&channel->min_full_scale.mz); + return result; } - -static six_axis_t get_max_full_scales(volatile jr3_channel_t *channel) + +static six_axis_t get_max_full_scales(volatile jr3_channel_t * channel) { - six_axis_t result; - result.fx = get_s16(&channel->max_full_scale.fx); - result.fy = get_s16(&channel->max_full_scale.fy); - result.fz = get_s16(&channel->max_full_scale.fz); - result.mx = get_s16(&channel->max_full_scale.mx); - result.my = get_s16(&channel->max_full_scale.my); - result.mz = get_s16(&channel->max_full_scale.mz); - return result; + six_axis_t result; + result.fx = get_s16(&channel->max_full_scale.fx); + result.fy = get_s16(&channel->max_full_scale.fy); + result.fz = get_s16(&channel->max_full_scale.fz); + result.mx = get_s16(&channel->max_full_scale.mx); + result.my = get_s16(&channel->max_full_scale.my); + result.mz = get_s16(&channel->max_full_scale.mz); + return result; } - -static int jr3_pci_ai_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) + +static int jr3_pci_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int result; - jr3_pci_subdev_private *p; - int channel; - - p = s->private; - channel = CR_CHAN(insn->chanspec); - if (p == NULL || channel > 57) { - result = -EINVAL; - } else { - int i; - - result = insn->n; - if (p->state != state_jr3_done || - (get_u16(&p->channel->errors) & (watch_dog | watch_dog2 | - sensor_change))) { - /* No sensor or sensor changed */ - if (p->state == state_jr3_done) { - /* Restart polling */ - p->state = state_jr3_poll; - } - result = -EAGAIN; - } - for(i = 0 ; i < insn->n ; i++){ - if (channel < 56) { - int axis, filter; - - axis = channel % 8; - filter = channel / 8; - if (p->state != state_jr3_done) { - data[i] = 0; + int result; + jr3_pci_subdev_private *p; + int channel; + + p = s->private; + channel = CR_CHAN(insn->chanspec); + if (p == NULL || channel > 57) { + result = -EINVAL; } else { - int F = 0; - switch (axis) { - case 0: { - F = get_s16(&p->channel->filter[filter].fx); - } break; - case 1: { - F = get_s16(&p->channel->filter[filter].fy); - } break; - case 2: { - F = get_s16(&p->channel->filter[filter].fz); - } break; - case 3: { - F = get_s16(&p->channel->filter[filter].mx); - } break; - case 4: { - F = get_s16(&p->channel->filter[filter].my); - } break; - case 5: { - F = get_s16(&p->channel->filter[filter].mz); - } break; - case 6: { - F = get_s16(&p->channel->filter[filter].v1); - } break; - case 7: { - F = get_s16(&p->channel->filter[filter].v2); - } break; - } - data[i] = F + 0x4000; + int i; + + result = insn->n; + if (p->state != state_jr3_done || + (get_u16(&p->channel-> + errors) & (watch_dog | watch_dog2 | + sensor_change))) { + /* No sensor or sensor changed */ + if (p->state == state_jr3_done) { + /* Restart polling */ + p->state = state_jr3_poll; + } + result = -EAGAIN; + } + for (i = 0; i < insn->n; i++) { + if (channel < 56) { + int axis, filter; + + axis = channel % 8; + filter = channel / 8; + if (p->state != state_jr3_done) { + data[i] = 0; + } else { + int F = 0; + switch (axis) { + case 0:{ + F = get_s16(&p-> + channel-> + filter[filter]. + fx); + } + break; + case 1:{ + F = get_s16(&p-> + channel-> + filter[filter]. + fy); + } + break; + case 2:{ + F = get_s16(&p-> + channel-> + filter[filter]. + fz); + } + break; + case 3:{ + F = get_s16(&p-> + channel-> + filter[filter]. + mx); + } + break; + case 4:{ + F = get_s16(&p-> + channel-> + filter[filter]. + my); + } + break; + case 5:{ + F = get_s16(&p-> + channel-> + filter[filter]. + mz); + } + break; + case 6:{ + F = get_s16(&p-> + channel-> + filter[filter]. + v1); + } + break; + case 7:{ + F = get_s16(&p-> + channel-> + filter[filter]. + v2); + } + break; + } + data[i] = F + 0x4000; + } + } else if (channel == 56) { + if (p->state != state_jr3_done) { + data[i] = 0; + } else { + data[i] = + get_u16(&p->channel->model_no); + } + } else if (channel == 57) { + if (p->state != state_jr3_done) { + data[i] = 0; + } else { + data[i] = + get_u16(&p->channel->serial_no); + } + } + } } - } else if (channel == 56) { - if (p->state != state_jr3_done) { - data[i] = 0; - } else { - data[i] = get_u16(&p->channel->model_no); - } - } else if (channel == 57) { - if (p->state != state_jr3_done) { - data[i] = 0; - } else { - data[i] = get_u16(&p->channel->serial_no); - } - } - } - } - return result; + return result; } -static void jr3_pci_open(comedi_device *dev) +static void jr3_pci_open(comedi_device * dev) { - int i; - jr3_pci_dev_private *devpriv = dev->private; - - printk("jr3_pci_open\n"); - for (i = 0 ; i < devpriv->n_channels ; i++) { - jr3_pci_subdev_private *p; - - p = dev->subdevices[i].private; - if (p) { - printk("serial: %p %d (%d)\n", p, p->serial_no, p->channel_no); - } - } + int i; + jr3_pci_dev_private *devpriv = dev->private; + + printk("jr3_pci_open\n"); + for (i = 0; i < devpriv->n_channels; i++) { + jr3_pci_subdev_private *p; + + p = dev->subdevices[i].private; + if (p) { + printk("serial: %p %d (%d)\n", p, p->serial_no, + p->channel_no); + } + } } -int read_idm_word(u8 *data, size_t size, int *pos, unsigned int *val) { - int result = 0; - if (pos != 0 && val != 0) { - // Skip over non hex - for ( ; *pos < size && !isxdigit(data[*pos]) ; (*pos)++) {} - // Collect value - *val = 0; - for ( ; *pos < size && isxdigit(data[*pos]) ; (*pos)++) { - char ch = tolower(data[*pos]); - result = 1; - if ('0' <= ch && ch <= '9') { - *val = (*val << 4) + (ch - '0'); - } else if ('a' <= ch && ch <= 'f') { - *val = (*val << 4) + (ch - 'a' + 10); - } - } - } - return result; +int read_idm_word(u8 * data, size_t size, int *pos, unsigned int *val) +{ + int result = 0; + if (pos != 0 && val != 0) { + // Skip over non hex + for (; *pos < size && !isxdigit(data[*pos]); (*pos)++) { + } + // Collect value + *val = 0; + for (; *pos < size && isxdigit(data[*pos]); (*pos)++) { + char ch = tolower(data[*pos]); + result = 1; + if ('0' <= ch && ch <= '9') { + *val = (*val << 4) + (ch - '0'); + } else if ('a' <= ch && ch <= 'f') { + *val = (*val << 4) + (ch - 'a' + 10); + } + } + } + return result; } -static int jr3_download_firmware(comedi_device *dev, - u8 *data, - size_t size) +static int jr3_download_firmware(comedi_device * dev, u8 * data, size_t size) { - /* - * IDM file format is: - * { count, address, data } * - * ffff - */ - int result, more, pos, OK; - - result = 0; - more = 1; - pos = 0; - OK = 0; - while (more) { - unsigned int count, addr; - - more = more && read_idm_word(data, size, &pos, &count); - if (more && count == 0xffff) { - OK = 1; - break; - } - more = more && read_idm_word(data, size, &pos, &addr); - while (more && count > 0) { - unsigned int dummy; - more = more && read_idm_word(data, size, &pos, &dummy); - count--; - } - } - - if (!OK) { - result = -ENODATA; - } else { - int i; - jr3_pci_dev_private *p = dev->private; - - for (i = 0 ; i < p->n_channels ; i++) { - jr3_pci_subdev_private *sp; - - sp = dev->subdevices[i].private; - more = 1; - pos = 0; - while (more) { - unsigned int count, addr; - more = more && read_idm_word(data, size, &pos, &count); - if (more && count == 0xffff) { - break; + /* + * IDM file format is: + * { count, address, data } * + * ffff + */ + int result, more, pos, OK; + + result = 0; + more = 1; + pos = 0; + OK = 0; + while (more) { + unsigned int count, addr; + + more = more && read_idm_word(data, size, &pos, &count); + if (more && count == 0xffff) { + OK = 1; + break; + } + more = more && read_idm_word(data, size, &pos, &addr); + while (more && count > 0) { + unsigned int dummy; + more = more && read_idm_word(data, size, &pos, &dummy); + count--; + } } - more = more && read_idm_word(data, size, &pos, &addr); - printk("Loading#%d %4.4x bytes at %4.4x\n", i, count, addr); - while (more && count > 0) { - if (addr & 0x4000) { - // 16 bit data, never seen in real life!! - unsigned int data1; - - more = more && read_idm_word(data, size, &pos, &data1); - count--; - // printk("jr3_data, not tested\n"); - // jr3[addr + 0x20000 * pnum] = data1; - } else { - // Download 24 bit program - unsigned int data1, data2; - - more = more && read_idm_word(data, size, &pos, &data1); - more = more && read_idm_word(data, size, &pos, &data2); - count -= 2; - if (more) { - set_u16(&p->iobase->channel[i].program_low[addr], data1); - comedi_udelay(1); - set_u16(&p->iobase->channel[i].program_high[addr], data2); - comedi_udelay(1); - - } - } - addr++; + + if (!OK) { + result = -ENODATA; + } else { + int i; + jr3_pci_dev_private *p = dev->private; + + for (i = 0; i < p->n_channels; i++) { + jr3_pci_subdev_private *sp; + + sp = dev->subdevices[i].private; + more = 1; + pos = 0; + while (more) { + unsigned int count, addr; + more = more + && read_idm_word(data, size, &pos, + &count); + if (more && count == 0xffff) { + break; + } + more = more + && read_idm_word(data, size, &pos, + &addr); + printk("Loading#%d %4.4x bytes at %4.4x\n", i, + count, addr); + while (more && count > 0) { + if (addr & 0x4000) { + // 16 bit data, never seen in real life!! + unsigned int data1; + + more = more + && read_idm_word(data, + size, &pos, &data1); + count--; + // printk("jr3_data, not tested\n"); + // jr3[addr + 0x20000 * pnum] = data1; + } else { + // Download 24 bit program + unsigned int data1, data2; + + more = more + && read_idm_word(data, + size, &pos, &data1); + more = more + && read_idm_word(data, + size, &pos, &data2); + count -= 2; + if (more) { + set_u16(&p->iobase-> + channel[i]. + program_low + [addr], data1); + comedi_udelay(1); + set_u16(&p->iobase-> + channel[i]. + program_high + [addr], data2); + comedi_udelay(1); + + } + } + addr++; + } + } + } } - } - } - } - return result; + return result; } -static poll_delay_t jr3_pci_poll_subdevice(comedi_subdevice *s) +static poll_delay_t jr3_pci_poll_subdevice(comedi_subdevice * s) { - poll_delay_t result = poll_delay_min_max(1000, 2000); - jr3_pci_subdev_private *p = s->private; - - if (p) { - volatile jr3_channel_t *channel = p->channel; - int errors = get_u16(&channel->errors); - - if (errors != p->errors) { - printk("Errors: %x -> %x\n", p->errors, errors); - p->errors = errors; - } - if (errors & (watch_dog | watch_dog2 | sensor_change)) { - // Sensor communication lost, force poll mode - p->state = state_jr3_poll; - - } - switch (p->state) { - case state_jr3_poll: { - u16 model_no = get_u16(&channel->model_no); - u16 serial_no = get_u16(&channel->serial_no); - if ((errors & (watch_dog | watch_dog2)) || - model_no == 0 || serial_no == 0) { - // Still no sensor, keep on polling. Since it takes up to - // 10 seconds for offsets to stabilize, polling each - // second should suffice. - result = poll_delay_min_max(1000, 2000); - } else { - p->retries = 0; - p->state = state_jr3_init_wait_for_offset; - result = poll_delay_min_max(1000, 2000); - } - } break; - case state_jr3_init_wait_for_offset: { - p->retries++; - if (p->retries < 10) { - // Wait for offeset to stabilize (< 10 s according to manual) - result = poll_delay_min_max(1000, 2000); - } else { - transform_t transf; - - p->model_no = get_u16(&channel->model_no); - p->serial_no = get_u16(&channel->serial_no); - - printk("Setting transform for channel %d\n", p->channel_no); - printk("Sensor Model = %i\n", p->model_no); - printk("Sensor Serial = %i\n", p->serial_no); - - // Transformation all zeros - transf.link[0].link_type=(enum link_types)0; - transf.link[0].link_amount=0; - transf.link[1].link_type=(enum link_types)0; - transf.link[1].link_amount=0; - transf.link[2].link_type=(enum link_types)0; - transf.link[2].link_amount=0; - transf.link[3].link_type=(enum link_types)0; - transf.link[3].link_amount=0; - - set_transforms(channel, transf, 0); - use_transform(channel, 0); - p->state = state_jr3_init_transform_complete; - result = poll_delay_min_max(20, 100); // Allow 20 ms for completion - } - } break; - case state_jr3_init_transform_complete: { - if (! is_complete(channel)) { - printk("state_jr3_init_transform_complete complete = %d\n", - is_complete(channel)); - result = poll_delay_min_max(20, 100); - } else { - // Set full scale - six_axis_t min_full_scale; - six_axis_t max_full_scale; - - min_full_scale = get_min_full_scales(channel); - printk("Obtained Min. Full Scales:\n"); - printk("%i ", (min_full_scale).fx); - printk("%i ", (min_full_scale).fy); - printk("%i ", (min_full_scale).fz); - printk("%i ", (min_full_scale).mx); - printk("%i ", (min_full_scale).my); - printk("%i ", (min_full_scale).mz); - printk("\n"); - - - max_full_scale = get_max_full_scales(channel); - printk("Obtained Max. Full Scales:\n"); - printk("%i ", (max_full_scale).fx); - printk("%i ", (max_full_scale).fy); - printk("%i ", (max_full_scale).fz); - printk("%i ", (max_full_scale).mx); - printk("%i ", (max_full_scale).my); - printk("%i ", (max_full_scale).mz); - printk("\n"); - - set_full_scales(channel, max_full_scale); - - p->state = state_jr3_init_set_full_scale_complete; - result = poll_delay_min_max(20, 100); // Allow 20 ms for completion - } - } break; - case state_jr3_init_set_full_scale_complete: { - if (! is_complete(channel)) { - printk("state_jr3_init_set_full_scale_complete complete = %d\n", - is_complete(channel)); - result = poll_delay_min_max(20, 100); - } else { - volatile force_array_t *full_scale; - - // Use ranges in kN or we will overflow arount 2000N! - full_scale = &channel->full_scale; - p->range[0].range.min = -get_s16(&full_scale->fx) * 1000; - p->range[0].range.max = get_s16(&full_scale->fx) * 1000; - p->range[1].range.min = -get_s16(&full_scale->fy) * 1000; - p->range[1].range.max = get_s16(&full_scale->fy) * 1000; - p->range[2].range.min = -get_s16(&full_scale->fz) * 1000; - p->range[2].range.max = get_s16(&full_scale->fz) * 1000; - p->range[3].range.min = -get_s16(&full_scale->mx) * 100; - p->range[3].range.max = get_s16(&full_scale->mx) * 100; - p->range[4].range.min = -get_s16(&full_scale->my) * 100; - p->range[4].range.max = get_s16(&full_scale->my) * 100; - p->range[5].range.min = -get_s16(&full_scale->mz) * 100; - p->range[5].range.max = get_s16(&full_scale->mz) * 100; - p->range[6].range.min = -get_s16(&full_scale->v1) * 100; // ?? - p->range[6].range.max = get_s16(&full_scale->v1) * 100; // ?? - p->range[7].range.min = -get_s16(&full_scale->v2) * 100; // ?? - p->range[7].range.max = get_s16(&full_scale->v2) * 100; // ?? - p->range[8].range.min = 0; - p->range[8].range.max = 65535; - - { - int i; - for (i = 0 ; i < 9 ; i++) { - printk("%d %d - %d\n", - i, p->range[i].range.min, p->range[i].range.max); - } - } - - use_offset(channel, 0); - p->state = state_jr3_init_use_offset_complete; - result = poll_delay_min_max(40, 100); // Allow 40 ms for completion + poll_delay_t result = poll_delay_min_max(1000, 2000); + jr3_pci_subdev_private *p = s->private; + + if (p) { + volatile jr3_channel_t *channel = p->channel; + int errors = get_u16(&channel->errors); + + if (errors != p->errors) { + printk("Errors: %x -> %x\n", p->errors, errors); + p->errors = errors; + } + if (errors & (watch_dog | watch_dog2 | sensor_change)) { + // Sensor communication lost, force poll mode + p->state = state_jr3_poll; + + } + switch (p->state) { + case state_jr3_poll:{ + u16 model_no = get_u16(&channel->model_no); + u16 serial_no = get_u16(&channel->serial_no); + if ((errors & (watch_dog | watch_dog2)) || + model_no == 0 || serial_no == 0) { + // Still no sensor, keep on polling. Since it takes up to + // 10 seconds for offsets to stabilize, polling each + // second should suffice. + result = poll_delay_min_max(1000, 2000); + } else { + p->retries = 0; + p->state = + state_jr3_init_wait_for_offset; + result = poll_delay_min_max(1000, 2000); + } + } + break; + case state_jr3_init_wait_for_offset:{ + p->retries++; + if (p->retries < 10) { + // Wait for offeset to stabilize (< 10 s according to manual) + result = poll_delay_min_max(1000, 2000); + } else { + transform_t transf; + + p->model_no = + get_u16(&channel->model_no); + p->serial_no = + get_u16(&channel->serial_no); + + printk("Setting transform for channel %d\n", p->channel_no); + printk("Sensor Model = %i\n", + p->model_no); + printk("Sensor Serial = %i\n", + p->serial_no); + + // Transformation all zeros + transf.link[0].link_type = + (enum link_types)0; + transf.link[0].link_amount = 0; + transf.link[1].link_type = + (enum link_types)0; + transf.link[1].link_amount = 0; + transf.link[2].link_type = + (enum link_types)0; + transf.link[2].link_amount = 0; + transf.link[3].link_type = + (enum link_types)0; + transf.link[3].link_amount = 0; + + set_transforms(channel, transf, 0); + use_transform(channel, 0); + p->state = + state_jr3_init_transform_complete; + result = poll_delay_min_max(20, 100); // Allow 20 ms for completion + } + } break; + case state_jr3_init_transform_complete:{ + if (!is_complete(channel)) { + printk("state_jr3_init_transform_complete complete = %d\n", is_complete(channel)); + result = poll_delay_min_max(20, 100); + } else { + // Set full scale + six_axis_t min_full_scale; + six_axis_t max_full_scale; + + min_full_scale = + get_min_full_scales(channel); + printk("Obtained Min. Full Scales:\n"); + printk("%i ", (min_full_scale).fx); + printk("%i ", (min_full_scale).fy); + printk("%i ", (min_full_scale).fz); + printk("%i ", (min_full_scale).mx); + printk("%i ", (min_full_scale).my); + printk("%i ", (min_full_scale).mz); + printk("\n"); + + max_full_scale = + get_max_full_scales(channel); + printk("Obtained Max. Full Scales:\n"); + printk("%i ", (max_full_scale).fx); + printk("%i ", (max_full_scale).fy); + printk("%i ", (max_full_scale).fz); + printk("%i ", (max_full_scale).mx); + printk("%i ", (max_full_scale).my); + printk("%i ", (max_full_scale).mz); + printk("\n"); + + set_full_scales(channel, + max_full_scale); + + p->state = + state_jr3_init_set_full_scale_complete; + result = poll_delay_min_max(20, 100); // Allow 20 ms for completion + } + } + break; + case state_jr3_init_set_full_scale_complete:{ + if (!is_complete(channel)) { + printk("state_jr3_init_set_full_scale_complete complete = %d\n", is_complete(channel)); + result = poll_delay_min_max(20, 100); + } else { + volatile force_array_t *full_scale; + + // Use ranges in kN or we will overflow arount 2000N! + full_scale = &channel->full_scale; + p->range[0].range.min = + -get_s16(&full_scale->fx) * + 1000; + p->range[0].range.max = + get_s16(&full_scale->fx) * 1000; + p->range[1].range.min = + -get_s16(&full_scale->fy) * + 1000; + p->range[1].range.max = + get_s16(&full_scale->fy) * 1000; + p->range[2].range.min = + -get_s16(&full_scale->fz) * + 1000; + p->range[2].range.max = + get_s16(&full_scale->fz) * 1000; + p->range[3].range.min = + -get_s16(&full_scale->mx) * 100; + p->range[3].range.max = + get_s16(&full_scale->mx) * 100; + p->range[4].range.min = + -get_s16(&full_scale->my) * 100; + p->range[4].range.max = + get_s16(&full_scale->my) * 100; + p->range[5].range.min = + -get_s16(&full_scale->mz) * 100; + p->range[5].range.max = + get_s16(&full_scale->mz) * 100; + p->range[6].range.min = -get_s16(&full_scale->v1) * 100; // ?? + p->range[6].range.max = get_s16(&full_scale->v1) * 100; // ?? + p->range[7].range.min = -get_s16(&full_scale->v2) * 100; // ?? + p->range[7].range.max = get_s16(&full_scale->v2) * 100; // ?? + p->range[8].range.min = 0; + p->range[8].range.max = 65535; + + { + int i; + for (i = 0; i < 9; i++) { + printk("%d %d - %d\n", + i, + p->range[i]. + range.min, + p->range[i]. + range.max); + } + } + + use_offset(channel, 0); + p->state = + state_jr3_init_use_offset_complete; + result = poll_delay_min_max(40, 100); // Allow 40 ms for completion + } + } + break; + case state_jr3_init_use_offset_complete:{ + if (!is_complete(channel)) { + printk("state_jr3_init_use_offset_complete complete = %d\n", is_complete(channel)); + result = poll_delay_min_max(20, 100); + } else { + printk("Default offsets %d %d %d %d %d %d\n", get_s16(&channel->offsets.fx), get_s16(&channel->offsets.fy), get_s16(&channel->offsets.fz), get_s16(&channel->offsets.mx), get_s16(&channel->offsets.my), get_s16(&channel->offsets.mz)); + + set_s16(&channel->offsets.fx, 0); + set_s16(&channel->offsets.fy, 0); + set_s16(&channel->offsets.fz, 0); + set_s16(&channel->offsets.mx, 0); + set_s16(&channel->offsets.my, 0); + set_s16(&channel->offsets.mz, 0); + + set_offset(channel); + + p->state = state_jr3_done; + } + } + break; + case state_jr3_done:{ + poll_delay_min_max(10000, 20000); + } + break; + default:{ + poll_delay_min_max(1000, 2000); + } + break; + } } - } break; - case state_jr3_init_use_offset_complete: { - if (! is_complete(channel)) { - printk("state_jr3_init_use_offset_complete complete = %d\n", - is_complete(channel)); - result = poll_delay_min_max(20, 100); - } else { - printk("Default offsets %d %d %d %d %d %d\n", - get_s16(&channel->offsets.fx), - get_s16(&channel->offsets.fy), - get_s16(&channel->offsets.fz), - get_s16(&channel->offsets.mx), - get_s16(&channel->offsets.my), - get_s16(&channel->offsets.mz)); - - set_s16(&channel->offsets.fx, 0); - set_s16(&channel->offsets.fy, 0); - set_s16(&channel->offsets.fz, 0); - set_s16(&channel->offsets.mx, 0); - set_s16(&channel->offsets.my, 0); - set_s16(&channel->offsets.mz, 0); - - set_offset(channel); - - p->state = state_jr3_done; - } - } break; - case state_jr3_done: { - poll_delay_min_max(10000, 20000); - } break; - default: { - poll_delay_min_max(1000, 2000); - } break; - } - } - return result; + return result; } static void jr3_pci_poll_dev(unsigned long data) { - unsigned long flags; - comedi_device *dev = (comedi_device*)data; - jr3_pci_dev_private *devpriv = dev->private; - unsigned long now; - int delay; - int i; - - comedi_spin_lock_irqsave(&dev->spinlock, flags); - delay = 1000; - now = jiffies; - // Poll all channels that are ready to be polled - for (i = 0 ; i < devpriv->n_channels ;i++) { - jr3_pci_subdev_private *subdevpriv = dev->subdevices[i].private; - if (now > subdevpriv->next_time_min) { - poll_delay_t sub_delay; - - sub_delay = jr3_pci_poll_subdevice(&dev->subdevices[i]); - subdevpriv->next_time_min = jiffies + msecs_to_jiffies(sub_delay.min); - subdevpriv->next_time_max = jiffies + msecs_to_jiffies(sub_delay.max); - if (sub_delay.max && sub_delay.max < delay) { - // Wake up as late as possible -> poll as many channels as - // possible at once - delay = sub_delay.max; - } - } - } - comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - - devpriv->timer.expires = jiffies + msecs_to_jiffies(delay); - add_timer (&devpriv->timer); + unsigned long flags; + comedi_device *dev = (comedi_device *) data; + jr3_pci_dev_private *devpriv = dev->private; + unsigned long now; + int delay; + int i; + + comedi_spin_lock_irqsave(&dev->spinlock, flags); + delay = 1000; + now = jiffies; + // Poll all channels that are ready to be polled + for (i = 0; i < devpriv->n_channels; i++) { + jr3_pci_subdev_private *subdevpriv = dev->subdevices[i].private; + if (now > subdevpriv->next_time_min) { + poll_delay_t sub_delay; + + sub_delay = jr3_pci_poll_subdevice(&dev->subdevices[i]); + subdevpriv->next_time_min = + jiffies + msecs_to_jiffies(sub_delay.min); + subdevpriv->next_time_max = + jiffies + msecs_to_jiffies(sub_delay.max); + if (sub_delay.max && sub_delay.max < delay) { + // Wake up as late as possible -> poll as many channels as + // possible at once + delay = sub_delay.max; + } + } + } + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + + devpriv->timer.expires = jiffies + msecs_to_jiffies(delay); + add_timer(&devpriv->timer); } -static int jr3_pci_attach(comedi_device *dev, comedi_devconfig *it) +static int jr3_pci_attach(comedi_device * dev, comedi_devconfig * it) { - int result = 0; - struct pci_dev *card = NULL; - int opt_bus, opt_slot, i; - jr3_pci_dev_private *devpriv; - - printk("comedi%d: jr3_pci\n", dev->minor); - - opt_bus = it->options[0]; - opt_slot = it->options[1]; - - if (sizeof(jr3_channel_t) != 0xc00) { - printk("sizeof(jr3_channel_t) = %x [expected %x]\n", - (unsigned)sizeof(jr3_channel_t), 0xc00); - return -EINVAL; - } - - result = alloc_private(dev, sizeof(jr3_pci_dev_private)); - if(result < 0){ - return -ENOMEM; - } - card = NULL; - devpriv = dev->private; - init_timer (&devpriv->timer); - while(1) { - card = pci_get_device(PCI_VENDOR_ID_JR3, PCI_ANY_ID, card); - if (card == NULL) { - /* No card found */ - break; - } else { - switch(card->device) { - case PCI_DEVICE_ID_JR3_1_CHANNEL: { - devpriv->n_channels = 1; - } break; - case PCI_DEVICE_ID_JR3_2_CHANNEL: { - devpriv->n_channels = 2; - } break; - case PCI_DEVICE_ID_JR3_3_CHANNEL: { - devpriv->n_channels = 3; - } break; - case PCI_DEVICE_ID_JR3_4_CHANNEL: { - devpriv->n_channels = 4; - } break; - default: { - devpriv->n_channels = 0; + int result = 0; + struct pci_dev *card = NULL; + int opt_bus, opt_slot, i; + jr3_pci_dev_private *devpriv; + + printk("comedi%d: jr3_pci\n", dev->minor); + + opt_bus = it->options[0]; + opt_slot = it->options[1]; + + if (sizeof(jr3_channel_t) != 0xc00) { + printk("sizeof(jr3_channel_t) = %x [expected %x]\n", + (unsigned)sizeof(jr3_channel_t), 0xc00); + return -EINVAL; } - } - if (devpriv->n_channels >= 1) { - if (opt_bus == 0 && opt_slot == 0) { - /* Take first available card */ - break; - } else if (opt_bus == card->bus->number && - opt_slot == PCI_SLOT(card->devfn)) { - /* Take requested card */ - break; + + result = alloc_private(dev, sizeof(jr3_pci_dev_private)); + if (result < 0) { + return -ENOMEM; + } + card = NULL; + devpriv = dev->private; + init_timer(&devpriv->timer); + while (1) { + card = pci_get_device(PCI_VENDOR_ID_JR3, PCI_ANY_ID, card); + if (card == NULL) { + /* No card found */ + break; + } else { + switch (card->device) { + case PCI_DEVICE_ID_JR3_1_CHANNEL:{ + devpriv->n_channels = 1; + } + break; + case PCI_DEVICE_ID_JR3_2_CHANNEL:{ + devpriv->n_channels = 2; + } + break; + case PCI_DEVICE_ID_JR3_3_CHANNEL:{ + devpriv->n_channels = 3; + } + break; + case PCI_DEVICE_ID_JR3_4_CHANNEL:{ + devpriv->n_channels = 4; + } + break; + default:{ + devpriv->n_channels = 0; + } + } + if (devpriv->n_channels >= 1) { + if (opt_bus == 0 && opt_slot == 0) { + /* Take first available card */ + break; + } else if (opt_bus == card->bus->number && + opt_slot == PCI_SLOT(card->devfn)) { + /* Take requested card */ + break; + } + } + } + } + if (!card) { + printk(" no jr3_pci found\n"); + return -EIO; + } else { + devpriv->pci_dev = card; + dev->board_name = "jr3_pci"; + } + if ((result = comedi_pci_enable(card, "jr3_pci")) < 0) { + return -EIO; } - } - } - } - if (!card) { - printk(" no jr3_pci found\n"); - return -EIO; - }else{ - devpriv->pci_dev = card; - dev->board_name = "jr3_pci"; - } - if((result = comedi_pci_enable(card, "jr3_pci")) < 0) { - return -EIO; - } - devpriv->pci_enabled = 1; - devpriv->iobase = ioremap(pci_resource_start(card,0), sizeof(jr3_t)); - result = alloc_subdevices(dev, devpriv->n_channels); - if(result < 0) goto out; - - dev->open = jr3_pci_open; - for (i = 0 ; i < devpriv->n_channels ; i++) { - dev->subdevices[i].type = COMEDI_SUBD_AI; - dev->subdevices[i].subdev_flags = SDF_READABLE|SDF_GROUND; - dev->subdevices[i].n_chan = 8 * 7 + 2; - dev->subdevices[i].insn_read = jr3_pci_ai_insn_read; - dev->subdevices[i].private = kzalloc(sizeof(jr3_pci_subdev_private), - GFP_KERNEL); - if (dev->subdevices[i].private) { - jr3_pci_subdev_private *p; - int j; - - p = dev->subdevices[i].private; - p->channel = &devpriv->iobase->channel[i].data; - printk("p->channel %p %p (%tx)\n", - p->channel, devpriv->iobase, - ((char *)(p->channel) - (char *)(devpriv->iobase))); - p->channel_no = i; - for (j = 0 ; j < 8 ; j++) { - int k; - - p->range[j].length = 1; - p->range[j].range.min = -1000000; - p->range[j].range.max = 1000000; - for (k = 0 ; k < 7 ; k++) { - p->range_table_list[j + k * 8] = (comedi_lrange*)&p->range[j]; - p->maxdata_list[j + k * 8] = 0x7fff; + devpriv->pci_enabled = 1; + devpriv->iobase = ioremap(pci_resource_start(card, 0), sizeof(jr3_t)); + result = alloc_subdevices(dev, devpriv->n_channels); + if (result < 0) + goto out; + + dev->open = jr3_pci_open; + for (i = 0; i < devpriv->n_channels; i++) { + dev->subdevices[i].type = COMEDI_SUBD_AI; + dev->subdevices[i].subdev_flags = SDF_READABLE | SDF_GROUND; + dev->subdevices[i].n_chan = 8 * 7 + 2; + dev->subdevices[i].insn_read = jr3_pci_ai_insn_read; + dev->subdevices[i].private = + kzalloc(sizeof(jr3_pci_subdev_private), GFP_KERNEL); + if (dev->subdevices[i].private) { + jr3_pci_subdev_private *p; + int j; + + p = dev->subdevices[i].private; + p->channel = &devpriv->iobase->channel[i].data; + printk("p->channel %p %p (%tx)\n", + p->channel, devpriv->iobase, + ((char *)(p->channel) - + (char *)(devpriv->iobase))); + p->channel_no = i; + for (j = 0; j < 8; j++) { + int k; + + p->range[j].length = 1; + p->range[j].range.min = -1000000; + p->range[j].range.max = 1000000; + for (k = 0; k < 7; k++) { + p->range_table_list[j + k * 8] = + (comedi_lrange *) & p->range[j]; + p->maxdata_list[j + k * 8] = 0x7fff; + } + } + p->range[8].length = 1; + p->range[8].range.min = 0; + p->range[8].range.max = 65536; + + p->range_table_list[56] = + (comedi_lrange *) & p->range[8]; + p->range_table_list[57] = + (comedi_lrange *) & p->range[8]; + p->maxdata_list[56] = 0xffff; + p->maxdata_list[57] = 0xffff; + // Channel specific range and maxdata + dev->subdevices[i].range_table = 0; + dev->subdevices[i].range_table_list = + p->range_table_list; + dev->subdevices[i].maxdata = 0; + dev->subdevices[i].maxdata_list = p->maxdata_list; + } } - } - p->range[8].length = 1; - p->range[8].range.min = 0; - p->range[8].range.max = 65536; - - p->range_table_list[56] = (comedi_lrange*)&p->range[8]; - p->range_table_list[57] = (comedi_lrange*)&p->range[8]; - p->maxdata_list[56] = 0xffff; - p->maxdata_list[57] = 0xffff; - // Channel specific range and maxdata - dev->subdevices[i].range_table = 0; - dev->subdevices[i].range_table_list = p->range_table_list; - dev->subdevices[i].maxdata = 0; - dev->subdevices[i].maxdata_list = p->maxdata_list; - } - } - - // Reset DSP card - devpriv->iobase->channel[0].reset = 0; - - result = comedi_load_firmware(dev, "jr3pci.idm", jr3_download_firmware); - printk("Firmare load %d\n", result); - - if (result < 0) { - goto out; - } - - // TODO: use firmware to load preferred offset tables. Suggested format: - // model serial Fx Fy Fz Mx My Mz\n - // - // comedi_load_firmware(dev, "jr3_offsets_table", jr3_download_firmware); - - // It takes a few milliseconds for software to settle - // as much as we can read firmware version - msleep_interruptible(25); - for (i=0 ; i < 0x18 ; i++){ - printk("%c", get_u16(&devpriv->iobase->channel[0].data.copyright[i])>>8); - } - - // Start card timer - for (i = 0 ; i < devpriv->n_channels ; i++) { - jr3_pci_subdev_private *p = dev->subdevices[i].private; - - p->next_time_min = jiffies + msecs_to_jiffies(500); - p->next_time_max = jiffies + msecs_to_jiffies(2000); - } - - devpriv->timer.data = (unsigned long)dev; - devpriv->timer.function = jr3_pci_poll_dev; - devpriv->timer.expires = jiffies + msecs_to_jiffies(1000); - add_timer(&devpriv->timer); - - out: - return result; + + // Reset DSP card + devpriv->iobase->channel[0].reset = 0; + + result = comedi_load_firmware(dev, "jr3pci.idm", jr3_download_firmware); + printk("Firmare load %d\n", result); + + if (result < 0) { + goto out; + } + // TODO: use firmware to load preferred offset tables. Suggested format: + // model serial Fx Fy Fz Mx My Mz\n + // + // comedi_load_firmware(dev, "jr3_offsets_table", jr3_download_firmware); + + // It takes a few milliseconds for software to settle + // as much as we can read firmware version + msleep_interruptible(25); + for (i = 0; i < 0x18; i++) { + printk("%c", + get_u16(&devpriv->iobase->channel[0].data. + copyright[i]) >> 8); + } + + // Start card timer + for (i = 0; i < devpriv->n_channels; i++) { + jr3_pci_subdev_private *p = dev->subdevices[i].private; + + p->next_time_min = jiffies + msecs_to_jiffies(500); + p->next_time_max = jiffies + msecs_to_jiffies(2000); + } + + devpriv->timer.data = (unsigned long)dev; + devpriv->timer.function = jr3_pci_poll_dev; + devpriv->timer.expires = jiffies + msecs_to_jiffies(1000); + add_timer(&devpriv->timer); + + out: + return result; } static int jr3_pci_detach(comedi_device * dev) { - int i; - jr3_pci_dev_private *devpriv = dev->private; - - printk("comedi%d: jr3_pci: remove\n", dev->minor); - if (devpriv) { - del_timer_sync(&devpriv->timer); - - if (dev->subdevices) { - for (i = 0 ; i < devpriv->n_channels ;i++) { - kfree(dev->subdevices[i].private); - } - } - - if(devpriv->iobase) { - iounmap((void*)devpriv->iobase); - } - if(devpriv->pci_enabled) { - comedi_pci_disable(devpriv->pci_dev); - } - - if (devpriv->pci_dev) { - pci_dev_put(devpriv->pci_dev); - } - } - return 0; + int i; + jr3_pci_dev_private *devpriv = dev->private; + + printk("comedi%d: jr3_pci: remove\n", dev->minor); + if (devpriv) { + del_timer_sync(&devpriv->timer); + + if (dev->subdevices) { + for (i = 0; i < devpriv->n_channels; i++) { + kfree(dev->subdevices[i].private); + } + } + + if (devpriv->iobase) { + iounmap((void *)devpriv->iobase); + } + if (devpriv->pci_enabled) { + comedi_pci_disable(devpriv->pci_dev); + } + + if (devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } + } + return 0; } COMEDI_INITCLEANUP(driver_jr3_pci); - diff --git a/comedi/drivers/jr3_pci.h b/comedi/drivers/jr3_pci.h index 03b37bc0..aa756135 100644 --- a/comedi/drivers/jr3_pci.h +++ b/comedi/drivers/jr3_pci.h @@ -4,25 +4,25 @@ typedef u32 u_val_t; typedef s32 s_val_t; -static inline u16 get_u16(volatile const u_val_t *p) +static inline u16 get_u16(volatile const u_val_t * p) { - return (u16)readl(p); -} + return (u16) readl(p); +} -static inline void set_u16(volatile u_val_t *p, u16 val) +static inline void set_u16(volatile u_val_t * p, u16 val) { - writel(val, p); -} + writel(val, p); +} -static inline s16 get_s16(volatile const s_val_t *p) +static inline s16 get_s16(volatile const s_val_t * p) { - return (s16)readl(p); -} + return (s16) readl(p); +} -static inline void set_s16(volatile s_val_t *p, s16 val) +static inline void set_s16(volatile s_val_t * p, s16 val) { - writel(val, p); -} + writel(val, p); +} // The raw data is stored in a format which facilitates rapid // processing by the JR3 DSP chip. The raw_channel structure shows the @@ -41,37 +41,34 @@ static inline void set_s16(volatile s_val_t *p, s16 val) // Channels 1-6 contain the coupled force data Fx through Mz. Channel // 7 contains the sensor's calibration data. The use of channels 8-15 // varies with different sensors. -typedef struct raw_channel -{ - u_val_t raw_time; - s_val_t raw_data; - s_val_t reserved[2]; +typedef struct raw_channel { + u_val_t raw_time; + s_val_t raw_data; + s_val_t reserved[2]; } raw_channel_t; // The force_array structure shows the layout for the decoupled and // filtered force data. -typedef struct force_array -{ - s_val_t fx; - s_val_t fy; - s_val_t fz; - s_val_t mx; - s_val_t my; - s_val_t mz; - s_val_t v1; - s_val_t v2; +typedef struct force_array { + s_val_t fx; + s_val_t fy; + s_val_t fz; + s_val_t mx; + s_val_t my; + s_val_t mz; + s_val_t v1; + s_val_t v2; } force_array_t; // The six_axis_array structure shows the layout for the offsets and // the full scales. -typedef struct six_axis_array -{ - s_val_t fx; - s_val_t fy; - s_val_t fz; - s_val_t mx; - s_val_t my; - s_val_t mz; +typedef struct six_axis_array { + s_val_t fx; + s_val_t fy; + s_val_t fz; + s_val_t mx; + s_val_t my; + s_val_t mz; } six_axis_array_t; // VECT_BITS @@ -88,14 +85,14 @@ typedef struct six_axis_array // have two force vectors, set changeV1 to 1. typedef enum { - fx = 0x0001, - fy = 0x0002, - fz = 0x0004, - mx = 0x0008, - my = 0x0010, - mz = 0x0020, - changeV2 = 0x0040, - changeV1 = 0x0080 + fx = 0x0001, + fy = 0x0002, + fz = 0x0004, + mx = 0x0008, + my = 0x0010, + mz = 0x0020, + changeV2 = 0x0040, + changeV1 = 0x0080 } vect_bits_t; // WARNING_BITS @@ -107,12 +104,12 @@ typedef enum { // exceeded the near saturation value. typedef enum { - fx_near_sat = 0x0001, - fy_near_sat = 0x0002, - fz_near_sat = 0x0004, - mx_near_sat = 0x0008, - my_near_sat = 0x0010, - mz_near_sat = 0x0020 + fx_near_sat = 0x0001, + fy_near_sat = 0x0002, + fz_near_sat = 0x0004, + mx_near_sat = 0x0008, + my_near_sat = 0x0010, + mz_near_sat = 0x0020 } warning_bits_t; // ERROR_BITS @@ -170,21 +167,20 @@ typedef enum { // the sensor data is not being received correctly. typedef enum { - fx_sat = 0x0001, - fy_sat = 0x0002, - fz_sat = 0x0004, - mx_sat = 0x0008, - my_sat = 0x0010, - mz_sat = 0x0020, - memory_error = 0x0400, - sensor_change = 0x0800, - system_busy = 0x1000, - cal_crc_bad = 0x2000, - watch_dog2 = 0x4000, - watch_dog = 0x8000 + fx_sat = 0x0001, + fy_sat = 0x0002, + fz_sat = 0x0004, + mx_sat = 0x0008, + my_sat = 0x0010, + mz_sat = 0x0020, + memory_error = 0x0400, + sensor_change = 0x0800, + system_busy = 0x1000, + cal_crc_bad = 0x2000, + watch_dog2 = 0x4000, + watch_dog = 0x8000 } error_bits_t; - // THRESH_STRUCT // This structure shows the layout for a single threshold packet inside of a // load envelope. Each load envelope can contain several threshold structures. @@ -194,11 +190,10 @@ typedef enum { // bits will be set ... (pag.24). // 3. bit_pattern contains the bits that will be set if the threshold value is // met or exceeded. -typedef struct thresh_struct -{ - s32 data_address; - s32 threshold; - s32 bit_pattern; +typedef struct thresh_struct { + s32 data_address; + s32 threshold; + s32 bit_pattern; } thresh_struct; // LE_STRUCT @@ -210,11 +205,11 @@ typedef struct thresh_struct // command. // 2. number_of_xx_thresholds specify how many GE/LE threshold there are. typedef struct { - s32 latch_bits; - s32 number_of_ge_thresholds; - s32 number_of_le_thresholds; - struct thresh_struct thresholds[4]; - s32 reserved; + s32 latch_bits; + s32 number_of_ge_thresholds; + s32 number_of_le_thresholds; + struct thresh_struct thresholds[4]; + s32 reserved; } le_struct_t; // LINK_TYPES @@ -228,417 +223,412 @@ typedef struct { // 5 - rotate about Y axis (RY) // 6 - rotate about Z axis (RZ) // 7 - negate all axes (NEG) -typedef enum link_types -{ - end_x_form, - tx, - ty, - tz, - rx, - ry, - rz, - neg +typedef enum link_types { + end_x_form, + tx, + ty, + tz, + rx, + ry, + rz, + neg } link_types; // TRANSFORM // Structure used to describe a transform. typedef struct { - struct { - u_val_t link_type; - s_val_t link_amount; - } link[8]; + struct { + u_val_t link_type; + s_val_t link_amount; + } link[8]; } intern_transform_t; // JR3 force/torque sensor data definition. For more information see sensor and // hardware manuals. -typedef struct force_sensor_data -{ - // Raw_channels is the area used to store the raw data coming from - // the sensor. - - raw_channel_t raw_channels[16]; /* offset 0x0000 */ - - // Copyright is a null terminated ASCII string containing the JR3 - // copyright notice. - - u_val_t copyright[0x0018]; /* offset 0x0040 */ - s_val_t reserved1[0x0008]; /* offset 0x0058 */ - - // Shunts contains the sensor shunt readings. Some JR3 sensors have - // the ability to have their gains adjusted. This allows the - // hardware full scales to be adjusted to potentially allow - // better resolution or dynamic range. For sensors that have - // this ability, the gain of each sensor channel is measured at - // the time of calibration using a shunt resistor. The shunt - // resistor is placed across one arm of the resistor bridge, and - // the resulting change in the output of that channel is - // measured. This measurement is called the shunt reading, and - // is recorded here. If the user has changed the gain of the // - // sensor, and made new shunt measurements, those shunt - // measurements can be placed here. The JR3 DSP will then scale - // the calibration matrix such so that the gains are again - // proper for the indicated shunt readings. If shunts is 0, then - // the sensor cannot have its gain changed. For details on - // changing the sensor gain, and making shunts readings, please - // see the sensor manual. To make these values take effect the - // user must call either command (5) use transform # (pg. 33) or - // command (10) set new full scales (pg. 38). - - six_axis_array_t shunts; /* offset 0x0060 */ - s32 reserved2[2]; /* offset 0x0066 */ - - // Default_FS contains the full scale that is used if the user does - // not set a full scale. - - six_axis_array_t default_FS; /* offset 0x0068 */ - s_val_t reserved3; /* offset 0x006e */ - - // Load_envelope_num is the load envelope number that is currently - // in use. This value is set by the user after one of the load - // envelopes has been initialized. - - s_val_t load_envelope_num; /* offset 0x006f */ - - // Min_full_scale is the recommend minimum full scale. - // - // These values in conjunction with max_full_scale (pg. 9) helps - // determine the appropriate value for setting the full scales. The - // software allows the user to set the sensor full scale to an - // arbitrary value. But setting the full scales has some hazards. If - // the full scale is set too low, the data will saturate - // prematurely, and dynamic range will be lost. If the full scale is - // set too high, then resolution is lost as the data is shifted to - // the right and the least significant bits are lost. Therefore the - // maximum full scale is the maximum value at which no resolution is - // lost, and the minimum full scale is the value at which the data - // will not saturate prematurely. These values are calculated - // whenever a new coordinate transformation is calculated. It is - // possible for the recommended maximum to be less than the - // recommended minimum. This comes about primarily when using - // coordinate translations. If this is the case, it means that any - // full scale selection will be a compromise between dynamic range - // and resolution. It is usually recommended to compromise in favor - // of resolution which means that the recommend maximum full scale - // should be chosen. - // - // WARNING: Be sure that the full scale is no less than 0.4% of the - // recommended minimum full scale. Full scales below this value will - // cause erroneous results. - - six_axis_array_t min_full_scale; /* offset 0x0070 */ - s_val_t reserved4; /* offset 0x0076 */ - - // Transform_num is the transform number that is currently in use. - // This value is set by the JR3 DSP after the user has used command - // (5) use transform # (pg. 33). - - s_val_t transform_num; /* offset 0x0077 */ - - // Max_full_scale is the recommended maximum full scale. See - // min_full_scale (pg. 9) for more details. - - six_axis_array_t max_full_scale; /* offset 0x0078 */ - s_val_t reserved5; /* offset 0x007e */ - - // Peak_address is the address of the data which will be monitored - // by the peak routine. This value is set by the user. The peak - // routine will monitor any 8 contiguous addresses for peak values. - // (ex. to watch filter3 data for peaks, set this value to 0x00a8). - - s_val_t peak_address; /* offset 0x007f */ - - // Full_scale is the sensor full scales which are currently in use. - // Decoupled and filtered data is scaled so that +/- 16384 is equal - // to the full scales. The engineering units used are indicated by - // the units value discussed on page 16. The full scales for Fx, Fy, - // Fz, Mx, My and Mz can be written by the user prior to calling - // command (10) set new full scales (pg. 38). The full scales for V1 - // and V2 are set whenever the full scales are changed or when the - // axes used to calculate the vectors are changed. The full scale of - // V1 and V2 will always be equal to the largest full scale of the - // axes used for each vector respectively. - - force_array_t full_scale; /* offset 0x0080 */ - - // Offsets contains the sensor offsets. These values are subtracted from - // the sensor data to obtain the decoupled data. The offsets are set a - // few seconds (< 10) after the calibration data has been received. - // They are set so that the output data will be zero. These values - // can be written as well as read. The JR3 DSP will use the values - // written here within 2 ms of being written. To set future - // decoupled data to zero, add these values to the current decoupled - // data values and place the sum here. The JR3 DSP will change these - // values when a new transform is applied. So if the offsets are - // such that FX is 5 and all other values are zero, after rotating - // about Z by 90 degrees, FY would be 5 and all others would be zero. - - six_axis_array_t offsets; /* offset 0x0088 */ - - // Offset_num is the number of the offset currently in use. This - // value is set by the JR3 DSP after the user has executed the use - // offset # command (pg. 34). It can vary between 0 and 15. - - s_val_t offset_num; /* offset 0x008e */ - - // Vect_axes is a bit map showing which of the axes are being used - // in the vector calculations. This value is set by the JR3 DSP - // after the user has executed the set vector axes command (pg. 37). - - u_val_t vect_axes; /* offset 0x008f */ - - // Filter0 is the decoupled, unfiltered data from the JR3 sensor. - // This data has had the offsets removed. - // - // These force_arrays hold the filtered data. The decoupled data is - // passed through cascaded low pass filters. Each succeeding filter - // has a cutoff frequency of 1/4 of the preceding filter. The cutoff - // frequency of filter1 is 1/16 of the sample rate from the sensor. - // For a typical sensor with a sample rate of 8 kHz, the cutoff - // frequency of filter1 would be 500 Hz. The following filters would - // cutoff at 125 Hz, 31.25 Hz, 7.813 Hz, 1.953 Hz and 0.4883 Hz. - - struct force_array filter[7]; /* offset 0x0090, - offset 0x0098, - offset 0x00a0, - offset 0x00a8, - offset 0x00b0, - offset 0x00b8 , - offset 0x00c0 */ - - // Rate_data is the calculated rate data. It is a first derivative - // calculation. It is calculated at a frequency specified by the - // variable rate_divisor (pg. 12). The data on which the rate is - // calculated is specified by the variable rate_address (pg. 12). - - force_array_t rate_data; /* offset 0x00c8 */ - - // Minimum_data & maximum_data are the minimum and maximum (peak) - // data values. The JR3 DSP can monitor any 8 contiguous data items - // for minimums and maximums at full sensor bandwidth. This area is - // only updated at user request. This is done so that the user does - // not miss any peaks. To read the data, use either the read peaks - // command (pg. 40), or the read and reset peaks command (pg. 39). - // The address of the data to watch for peaks is stored in the - // variable peak_address (pg. 10). Peak data is lost when executing - // a coordinate transformation or a full scale change. Peak data is - // also lost when plugging in a new sensor. - - force_array_t minimum_data; /* offset 0x00d0 */ - force_array_t maximum_data; /* offset 0x00d8 */ - - // Near_sat_value & sat_value contain the value used to determine if - // the raw sensor is saturated. Because of decoupling and offset - // removal, it is difficult to tell from the processed data if the - // sensor is saturated. These values, in conjunction with the error - // and warning words (pg. 14), provide this critical information. - // These two values may be set by the host processor. These values - // are positive signed values, since the saturation logic uses the - // absolute values of the raw data. The near_sat_value defaults to - // approximately 80% of the ADC's full scale, which is 26214, while - // sat_value defaults to the ADC's full scale: - // - // sat_value = 32768 - 2^(16 - ADC bits) - - - s_val_t near_sat_value; /* offset 0x00e0 */ - s_val_t sat_value; /* offset 0x00e1 */ - - // Rate_address, rate_divisor & rate_count contain the data used to - // control the calculations of the rates. Rate_address is the - // address of the data used for the rate calculation. The JR3 DSP - // will calculate rates for any 8 contiguous values (ex. to - // calculate rates for filter3 data set rate_address to 0x00a8). - // Rate_divisor is how often the rate is calculated. If rate_divisor - // is 1, the rates are calculated at full sensor bandwidth. If - // rate_divisor is 200, rates are calculated every 200 samples. - // Rate_divisor can be any value between 1 and 65536. Set - // rate_divisor to 0 to calculate rates every 65536 samples. - // Rate_count starts at zero and counts until it equals - // rate_divisor, at which point the rates are calculated, and - // rate_count is reset to 0. When setting a new rate divisor, it is - // a good idea to set rate_count to one less than rate divisor. This - // will minimize the time necessary to start the rate calculations. - - s_val_t rate_address; /* offset 0x00e2 */ - u_val_t rate_divisor; /* offset 0x00e3 */ - u_val_t rate_count; /* offset 0x00e4 */ - - // Command_word2 through command_word0 are the locations used to - // send commands to the JR3 DSP. Their usage varies with the command - // and is detailed later in the Command Definitions section (pg. - // 29). In general the user places values into various memory - // locations, and then places the command word into command_word0. - // The JR3 DSP will process the command and place a 0 into - // command_word0 to indicate successful completion. Alternatively - // the JR3 DSP will place a negative number into command_word0 to - // indicate an error condition. Please note the command locations - // are numbered backwards. (I.E. command_word2 comes before - // command_word1). - - s_val_t command_word2; /* offset 0x00e5 */ - s_val_t command_word1; /* offset 0x00e6 */ - s_val_t command_word0; /* offset 0x00e7 */ - - // Count1 through count6 are unsigned counters which are incremented - // every time the matching filters are calculated. Filter1 is - // calculated at the sensor data bandwidth. So this counter would - // increment at 8 kHz for a typical sensor. The rest of the counters - // are incremented at 1/4 the interval of the counter immediately - // preceding it, so they would count at 2 kHz, 500 Hz, 125 Hz etc. - // These counters can be used to wait for data. Each time the - // counter changes, the corresponding data set can be sampled, and - // this will insure that the user gets each sample, once, and only - // once. - - u_val_t count1; /* offset 0x00e8 */ - u_val_t count2; /* offset 0x00e9 */ - u_val_t count3; /* offset 0x00ea */ - u_val_t count4; /* offset 0x00eb */ - u_val_t count5; /* offset 0x00ec */ - u_val_t count6; /* offset 0x00ed */ - - // Error_count is a running count of data reception errors. If this - // counter is changing rapidly, it probably indicates a bad sensor - // cable connection or other hardware problem. In most installations - // error_count should not change at all. But it is possible in an - // extremely noisy environment to experience occasional errors even - // without a hardware problem. If the sensor is well grounded, this - // is probably unavoidable in these environments. On the occasions - // where this counter counts a bad sample, that sample is ignored. - - u_val_t error_count; /* offset 0x00ee */ - - - // Count_x is a counter which is incremented every time the JR3 DSP - // searches its job queues and finds nothing to do. It indicates the - // amount of idle time the JR3 DSP has available. It can also be - // used to determine if the JR3 DSP is alive. See the Performance - // Issues section on pg. 49 for more details. - - u_val_t count_x; /* offset 0x00ef */ - - // Warnings & errors contain the warning and error bits - // respectively. The format of these two words is discussed on page - // 21 under the headings warnings_bits and error_bits. - - u_val_t warnings; /* offset 0x00f0 */ - u_val_t errors; /* offset 0x00f1 */ - - // Threshold_bits is a word containing the bits that are set by the - // load envelopes. See load_envelopes (pg. 17) and thresh_struct - // (pg. 23) for more details. - - s_val_t threshold_bits; /* offset 0x00f2 */ - - // Last_crc is the value that shows the actual calculated CRC. CRC - // is short for cyclic redundancy code. It should be zero. See the - // description for cal_crc_bad (pg. 21) for more information. - - s_val_t last_CRC; /* offset 0x00f3 */ - - // EEProm_ver_no contains the version number of the sensor EEProm. - // EEProm version numbers can vary between 0 and 255. - // Software_ver_no contains the software version number. Version - // 3.02 would be stored as 302. - - s_val_t eeprom_ver_no; /* offset 0x00f4 */ - s_val_t software_ver_no; /* offset 0x00f5 */ - - // Software_day & software_year are the release date of the software - // the JR3 DSP is currently running. Day is the day of the year, - // with January 1 being 1, and December 31, being 365 for non leap - // years. - - s_val_t software_day; /* offset 0x00f6 */ - s_val_t software_year; /* offset 0x00f7 */ - - // Serial_no & model_no are the two values which uniquely identify a - // sensor. This model number does not directly correspond to the JR3 - // model number, but it will provide a unique identifier for - // different sensor configurations. - - u_val_t serial_no; /* offset 0x00f8 */ - u_val_t model_no; /* offset 0x00f9 */ - - // Cal_day & cal_year are the sensor calibration date. Day is the - // day of the year, with January 1 being 1, and December 31, being - // 366 for leap years. - - s_val_t cal_day; /* offset 0x00fa */ - s_val_t cal_year; /* offset 0x00fb */ - - // Units is an enumerated read only value defining the engineering - // units used in the sensor full scale. The meanings of particular - // values are discussed in the section detailing the force_units - // structure on page 22. The engineering units are setto customer - // specifications during sensor manufacture and cannot be changed by - // writing to Units. - // - // Bits contains the number of bits of resolution of the ADC - // currently in use. - // - // Channels is a bit field showing which channels the current sensor - // is capable of sending. If bit 0 is active, this sensor can send - // channel 0, if bit 13 is active, this sensor can send channel 13, - // etc. This bit can be active, even if the sensor is not currently - // sending this channel. Some sensors are configurable as to which - // channels to send, and this field only contains information on the - // channels available to send, not on the current configuration. To - // find which channels are currently being sent, monitor the - // Raw_time fields (pg. 19) in the raw_channels array (pg. 7). If - // the time is changing periodically, then that channel is being - // received. - - u_val_t units; /* offset 0x00fc */ - s_val_t bits; /* offset 0x00fd */ - s_val_t channels; /* offset 0x00fe */ - - // Thickness specifies the overall thickness of the sensor from - // flange to flange. The engineering units for this value are - // contained in units (pg. 16). The sensor calibration is relative - // to the center of the sensor. This value allows easy coordinate - // transformation from the center of the sensor to either flange. - - s_val_t thickness; /* offset 0x00ff */ - - // Load_envelopes is a table containing the load envelope - // descriptions. There are 16 possible load envelope slots in the - // table. The slots are on 16 word boundaries and are numbered 0-15. - // Each load envelope needs to start at the beginning of a slot but - // need not be fully contained in that slot. That is to say that a - // single load envelope can be larger than a single slot. The - // software has been tested and ran satisfactorily with 50 - // thresholds active. A single load envelope this large would take - // up 5 of the 16 slots. The load envelope data is laid out in an - // order that is most efficient for the JR3 DSP. The structure is - // detailed later in the section showing the definition of the - // le_struct structure (pg. 23). - - le_struct_t load_envelopes[0x10]; /* offset 0x0100 */ - - // Transforms is a table containing the transform descriptions. - // There are 16 possible transform slots in the table. The slots are - // on 16 word boundaries and are numbered 0-15. Each transform needs - // to start at the beginning of a slot but need not be fully - // contained in that slot. That is to say that a single transform - // can be larger than a single slot. A transform is 2 * no of links - // + 1 words in length. So a single slot can contain a transform - // with 7 links. Two slots can contain a transform that is 15 links. - // The layout is detailed later in the section showing the - // definition of the transform structure (pg. 26). - - intern_transform_t transforms[0x10]; /* offset 0x0200 */ +typedef struct force_sensor_data { + // Raw_channels is the area used to store the raw data coming from + // the sensor. + + raw_channel_t raw_channels[16]; /* offset 0x0000 */ + + // Copyright is a null terminated ASCII string containing the JR3 + // copyright notice. + + u_val_t copyright[0x0018]; /* offset 0x0040 */ + s_val_t reserved1[0x0008]; /* offset 0x0058 */ + + // Shunts contains the sensor shunt readings. Some JR3 sensors have + // the ability to have their gains adjusted. This allows the + // hardware full scales to be adjusted to potentially allow + // better resolution or dynamic range. For sensors that have + // this ability, the gain of each sensor channel is measured at + // the time of calibration using a shunt resistor. The shunt + // resistor is placed across one arm of the resistor bridge, and + // the resulting change in the output of that channel is + // measured. This measurement is called the shunt reading, and + // is recorded here. If the user has changed the gain of the // + // sensor, and made new shunt measurements, those shunt + // measurements can be placed here. The JR3 DSP will then scale + // the calibration matrix such so that the gains are again + // proper for the indicated shunt readings. If shunts is 0, then + // the sensor cannot have its gain changed. For details on + // changing the sensor gain, and making shunts readings, please + // see the sensor manual. To make these values take effect the + // user must call either command (5) use transform # (pg. 33) or + // command (10) set new full scales (pg. 38). + + six_axis_array_t shunts; /* offset 0x0060 */ + s32 reserved2[2]; /* offset 0x0066 */ + + // Default_FS contains the full scale that is used if the user does + // not set a full scale. + + six_axis_array_t default_FS; /* offset 0x0068 */ + s_val_t reserved3; /* offset 0x006e */ + + // Load_envelope_num is the load envelope number that is currently + // in use. This value is set by the user after one of the load + // envelopes has been initialized. + + s_val_t load_envelope_num; /* offset 0x006f */ + + // Min_full_scale is the recommend minimum full scale. + // + // These values in conjunction with max_full_scale (pg. 9) helps + // determine the appropriate value for setting the full scales. The + // software allows the user to set the sensor full scale to an + // arbitrary value. But setting the full scales has some hazards. If + // the full scale is set too low, the data will saturate + // prematurely, and dynamic range will be lost. If the full scale is + // set too high, then resolution is lost as the data is shifted to + // the right and the least significant bits are lost. Therefore the + // maximum full scale is the maximum value at which no resolution is + // lost, and the minimum full scale is the value at which the data + // will not saturate prematurely. These values are calculated + // whenever a new coordinate transformation is calculated. It is + // possible for the recommended maximum to be less than the + // recommended minimum. This comes about primarily when using + // coordinate translations. If this is the case, it means that any + // full scale selection will be a compromise between dynamic range + // and resolution. It is usually recommended to compromise in favor + // of resolution which means that the recommend maximum full scale + // should be chosen. + // + // WARNING: Be sure that the full scale is no less than 0.4% of the + // recommended minimum full scale. Full scales below this value will + // cause erroneous results. + + six_axis_array_t min_full_scale; /* offset 0x0070 */ + s_val_t reserved4; /* offset 0x0076 */ + + // Transform_num is the transform number that is currently in use. + // This value is set by the JR3 DSP after the user has used command + // (5) use transform # (pg. 33). + + s_val_t transform_num; /* offset 0x0077 */ + + // Max_full_scale is the recommended maximum full scale. See + // min_full_scale (pg. 9) for more details. + + six_axis_array_t max_full_scale; /* offset 0x0078 */ + s_val_t reserved5; /* offset 0x007e */ + + // Peak_address is the address of the data which will be monitored + // by the peak routine. This value is set by the user. The peak + // routine will monitor any 8 contiguous addresses for peak values. + // (ex. to watch filter3 data for peaks, set this value to 0x00a8). + + s_val_t peak_address; /* offset 0x007f */ + + // Full_scale is the sensor full scales which are currently in use. + // Decoupled and filtered data is scaled so that +/- 16384 is equal + // to the full scales. The engineering units used are indicated by + // the units value discussed on page 16. The full scales for Fx, Fy, + // Fz, Mx, My and Mz can be written by the user prior to calling + // command (10) set new full scales (pg. 38). The full scales for V1 + // and V2 are set whenever the full scales are changed or when the + // axes used to calculate the vectors are changed. The full scale of + // V1 and V2 will always be equal to the largest full scale of the + // axes used for each vector respectively. + + force_array_t full_scale; /* offset 0x0080 */ + + // Offsets contains the sensor offsets. These values are subtracted from + // the sensor data to obtain the decoupled data. The offsets are set a + // few seconds (< 10) after the calibration data has been received. + // They are set so that the output data will be zero. These values + // can be written as well as read. The JR3 DSP will use the values + // written here within 2 ms of being written. To set future + // decoupled data to zero, add these values to the current decoupled + // data values and place the sum here. The JR3 DSP will change these + // values when a new transform is applied. So if the offsets are + // such that FX is 5 and all other values are zero, after rotating + // about Z by 90 degrees, FY would be 5 and all others would be zero. + + six_axis_array_t offsets; /* offset 0x0088 */ + + // Offset_num is the number of the offset currently in use. This + // value is set by the JR3 DSP after the user has executed the use + // offset # command (pg. 34). It can vary between 0 and 15. + + s_val_t offset_num; /* offset 0x008e */ + + // Vect_axes is a bit map showing which of the axes are being used + // in the vector calculations. This value is set by the JR3 DSP + // after the user has executed the set vector axes command (pg. 37). + + u_val_t vect_axes; /* offset 0x008f */ + + // Filter0 is the decoupled, unfiltered data from the JR3 sensor. + // This data has had the offsets removed. + // + // These force_arrays hold the filtered data. The decoupled data is + // passed through cascaded low pass filters. Each succeeding filter + // has a cutoff frequency of 1/4 of the preceding filter. The cutoff + // frequency of filter1 is 1/16 of the sample rate from the sensor. + // For a typical sensor with a sample rate of 8 kHz, the cutoff + // frequency of filter1 would be 500 Hz. The following filters would + // cutoff at 125 Hz, 31.25 Hz, 7.813 Hz, 1.953 Hz and 0.4883 Hz. + + struct force_array filter[7]; /* offset 0x0090, + offset 0x0098, + offset 0x00a0, + offset 0x00a8, + offset 0x00b0, + offset 0x00b8 , + offset 0x00c0 */ + + // Rate_data is the calculated rate data. It is a first derivative + // calculation. It is calculated at a frequency specified by the + // variable rate_divisor (pg. 12). The data on which the rate is + // calculated is specified by the variable rate_address (pg. 12). + + force_array_t rate_data; /* offset 0x00c8 */ + + // Minimum_data & maximum_data are the minimum and maximum (peak) + // data values. The JR3 DSP can monitor any 8 contiguous data items + // for minimums and maximums at full sensor bandwidth. This area is + // only updated at user request. This is done so that the user does + // not miss any peaks. To read the data, use either the read peaks + // command (pg. 40), or the read and reset peaks command (pg. 39). + // The address of the data to watch for peaks is stored in the + // variable peak_address (pg. 10). Peak data is lost when executing + // a coordinate transformation or a full scale change. Peak data is + // also lost when plugging in a new sensor. + + force_array_t minimum_data; /* offset 0x00d0 */ + force_array_t maximum_data; /* offset 0x00d8 */ + + // Near_sat_value & sat_value contain the value used to determine if + // the raw sensor is saturated. Because of decoupling and offset + // removal, it is difficult to tell from the processed data if the + // sensor is saturated. These values, in conjunction with the error + // and warning words (pg. 14), provide this critical information. + // These two values may be set by the host processor. These values + // are positive signed values, since the saturation logic uses the + // absolute values of the raw data. The near_sat_value defaults to + // approximately 80% of the ADC's full scale, which is 26214, while + // sat_value defaults to the ADC's full scale: + // + // sat_value = 32768 - 2^(16 - ADC bits) + + s_val_t near_sat_value; /* offset 0x00e0 */ + s_val_t sat_value; /* offset 0x00e1 */ + + // Rate_address, rate_divisor & rate_count contain the data used to + // control the calculations of the rates. Rate_address is the + // address of the data used for the rate calculation. The JR3 DSP + // will calculate rates for any 8 contiguous values (ex. to + // calculate rates for filter3 data set rate_address to 0x00a8). + // Rate_divisor is how often the rate is calculated. If rate_divisor + // is 1, the rates are calculated at full sensor bandwidth. If + // rate_divisor is 200, rates are calculated every 200 samples. + // Rate_divisor can be any value between 1 and 65536. Set + // rate_divisor to 0 to calculate rates every 65536 samples. + // Rate_count starts at zero and counts until it equals + // rate_divisor, at which point the rates are calculated, and + // rate_count is reset to 0. When setting a new rate divisor, it is + // a good idea to set rate_count to one less than rate divisor. This + // will minimize the time necessary to start the rate calculations. + + s_val_t rate_address; /* offset 0x00e2 */ + u_val_t rate_divisor; /* offset 0x00e3 */ + u_val_t rate_count; /* offset 0x00e4 */ + + // Command_word2 through command_word0 are the locations used to + // send commands to the JR3 DSP. Their usage varies with the command + // and is detailed later in the Command Definitions section (pg. + // 29). In general the user places values into various memory + // locations, and then places the command word into command_word0. + // The JR3 DSP will process the command and place a 0 into + // command_word0 to indicate successful completion. Alternatively + // the JR3 DSP will place a negative number into command_word0 to + // indicate an error condition. Please note the command locations + // are numbered backwards. (I.E. command_word2 comes before + // command_word1). + + s_val_t command_word2; /* offset 0x00e5 */ + s_val_t command_word1; /* offset 0x00e6 */ + s_val_t command_word0; /* offset 0x00e7 */ + + // Count1 through count6 are unsigned counters which are incremented + // every time the matching filters are calculated. Filter1 is + // calculated at the sensor data bandwidth. So this counter would + // increment at 8 kHz for a typical sensor. The rest of the counters + // are incremented at 1/4 the interval of the counter immediately + // preceding it, so they would count at 2 kHz, 500 Hz, 125 Hz etc. + // These counters can be used to wait for data. Each time the + // counter changes, the corresponding data set can be sampled, and + // this will insure that the user gets each sample, once, and only + // once. + + u_val_t count1; /* offset 0x00e8 */ + u_val_t count2; /* offset 0x00e9 */ + u_val_t count3; /* offset 0x00ea */ + u_val_t count4; /* offset 0x00eb */ + u_val_t count5; /* offset 0x00ec */ + u_val_t count6; /* offset 0x00ed */ + + // Error_count is a running count of data reception errors. If this + // counter is changing rapidly, it probably indicates a bad sensor + // cable connection or other hardware problem. In most installations + // error_count should not change at all. But it is possible in an + // extremely noisy environment to experience occasional errors even + // without a hardware problem. If the sensor is well grounded, this + // is probably unavoidable in these environments. On the occasions + // where this counter counts a bad sample, that sample is ignored. + + u_val_t error_count; /* offset 0x00ee */ + + // Count_x is a counter which is incremented every time the JR3 DSP + // searches its job queues and finds nothing to do. It indicates the + // amount of idle time the JR3 DSP has available. It can also be + // used to determine if the JR3 DSP is alive. See the Performance + // Issues section on pg. 49 for more details. + + u_val_t count_x; /* offset 0x00ef */ + + // Warnings & errors contain the warning and error bits + // respectively. The format of these two words is discussed on page + // 21 under the headings warnings_bits and error_bits. + + u_val_t warnings; /* offset 0x00f0 */ + u_val_t errors; /* offset 0x00f1 */ + + // Threshold_bits is a word containing the bits that are set by the + // load envelopes. See load_envelopes (pg. 17) and thresh_struct + // (pg. 23) for more details. + + s_val_t threshold_bits; /* offset 0x00f2 */ + + // Last_crc is the value that shows the actual calculated CRC. CRC + // is short for cyclic redundancy code. It should be zero. See the + // description for cal_crc_bad (pg. 21) for more information. + + s_val_t last_CRC; /* offset 0x00f3 */ + + // EEProm_ver_no contains the version number of the sensor EEProm. + // EEProm version numbers can vary between 0 and 255. + // Software_ver_no contains the software version number. Version + // 3.02 would be stored as 302. + + s_val_t eeprom_ver_no; /* offset 0x00f4 */ + s_val_t software_ver_no; /* offset 0x00f5 */ + + // Software_day & software_year are the release date of the software + // the JR3 DSP is currently running. Day is the day of the year, + // with January 1 being 1, and December 31, being 365 for non leap + // years. + + s_val_t software_day; /* offset 0x00f6 */ + s_val_t software_year; /* offset 0x00f7 */ + + // Serial_no & model_no are the two values which uniquely identify a + // sensor. This model number does not directly correspond to the JR3 + // model number, but it will provide a unique identifier for + // different sensor configurations. + + u_val_t serial_no; /* offset 0x00f8 */ + u_val_t model_no; /* offset 0x00f9 */ + + // Cal_day & cal_year are the sensor calibration date. Day is the + // day of the year, with January 1 being 1, and December 31, being + // 366 for leap years. + + s_val_t cal_day; /* offset 0x00fa */ + s_val_t cal_year; /* offset 0x00fb */ + + // Units is an enumerated read only value defining the engineering + // units used in the sensor full scale. The meanings of particular + // values are discussed in the section detailing the force_units + // structure on page 22. The engineering units are setto customer + // specifications during sensor manufacture and cannot be changed by + // writing to Units. + // + // Bits contains the number of bits of resolution of the ADC + // currently in use. + // + // Channels is a bit field showing which channels the current sensor + // is capable of sending. If bit 0 is active, this sensor can send + // channel 0, if bit 13 is active, this sensor can send channel 13, + // etc. This bit can be active, even if the sensor is not currently + // sending this channel. Some sensors are configurable as to which + // channels to send, and this field only contains information on the + // channels available to send, not on the current configuration. To + // find which channels are currently being sent, monitor the + // Raw_time fields (pg. 19) in the raw_channels array (pg. 7). If + // the time is changing periodically, then that channel is being + // received. + + u_val_t units; /* offset 0x00fc */ + s_val_t bits; /* offset 0x00fd */ + s_val_t channels; /* offset 0x00fe */ + + // Thickness specifies the overall thickness of the sensor from + // flange to flange. The engineering units for this value are + // contained in units (pg. 16). The sensor calibration is relative + // to the center of the sensor. This value allows easy coordinate + // transformation from the center of the sensor to either flange. + + s_val_t thickness; /* offset 0x00ff */ + + // Load_envelopes is a table containing the load envelope + // descriptions. There are 16 possible load envelope slots in the + // table. The slots are on 16 word boundaries and are numbered 0-15. + // Each load envelope needs to start at the beginning of a slot but + // need not be fully contained in that slot. That is to say that a + // single load envelope can be larger than a single slot. The + // software has been tested and ran satisfactorily with 50 + // thresholds active. A single load envelope this large would take + // up 5 of the 16 slots. The load envelope data is laid out in an + // order that is most efficient for the JR3 DSP. The structure is + // detailed later in the section showing the definition of the + // le_struct structure (pg. 23). + + le_struct_t load_envelopes[0x10]; /* offset 0x0100 */ + + // Transforms is a table containing the transform descriptions. + // There are 16 possible transform slots in the table. The slots are + // on 16 word boundaries and are numbered 0-15. Each transform needs + // to start at the beginning of a slot but need not be fully + // contained in that slot. That is to say that a single transform + // can be larger than a single slot. A transform is 2 * no of links + // + 1 words in length. So a single slot can contain a transform + // with 7 links. Two slots can contain a transform that is 15 links. + // The layout is detailed later in the section showing the + // definition of the transform structure (pg. 26). + + intern_transform_t transforms[0x10]; /* offset 0x0200 */ } jr3_channel_t; typedef struct { - struct { - u_val_t program_low[0x4000]; // 0x00000 - 0x10000 - jr3_channel_t data; // 0x10000 - 0x10c00 - char pad2[0x30000 - 0x00c00]; // 0x10c00 - 0x40000 - u_val_t program_high[0x8000]; // 0x40000 - 0x60000 - u32 reset; // 0x60000 - 0x60004 - char pad3[0x20000 - 0x00004]; // 0x60004 - 0x80000 - } channel[4]; + struct { + u_val_t program_low[0x4000]; // 0x00000 - 0x10000 + jr3_channel_t data; // 0x10000 - 0x10c00 + char pad2[0x30000 - 0x00c00]; // 0x10c00 - 0x40000 + u_val_t program_high[0x8000]; // 0x40000 - 0x60000 + u32 reset; // 0x60000 - 0x60004 + char pad3[0x20000 - 0x00004]; // 0x60004 - 0x80000 + } channel[4]; } jr3_t; - diff --git a/comedi/drivers/ke_counter.c b/comedi/drivers/ke_counter.c index 3f2d2942..9c6b70d3 100644 --- a/comedi/drivers/ke_counter.c +++ b/comedi/drivers/ke_counter.c @@ -42,208 +42,203 @@ Kolter Electronic PCI Counter Card. /*-- function prototypes ----------------------------------------------------*/ -static int cnt_attach(comedi_device *dev,comedi_devconfig *it); -static int cnt_detach(comedi_device *dev); +static int cnt_attach(comedi_device * dev, comedi_devconfig * it); +static int cnt_detach(comedi_device * dev); -static struct pci_device_id cnt_pci_table[] __devinitdata = -{ - { PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } +static struct pci_device_id cnt_pci_table[] __devinitdata = { + {PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, cnt_pci_table); /*-- board specification structure ------------------------------------------*/ -typedef struct -{ - const char *name; - int device_id; - int cnt_channel_nbr; - int cnt_bits; +typedef struct { + const char *name; + int device_id; + int cnt_channel_nbr; + int cnt_bits; } cnt_board_struct; -static const cnt_board_struct cnt_boards[] = -{ - { - name: CNT_DRIVER_NAME, - device_id: CNT_CARD_DEVICE_ID, - cnt_channel_nbr: 3, - cnt_bits: 24 - } +static const cnt_board_struct cnt_boards[] = { + { + name: CNT_DRIVER_NAME, + device_id:CNT_CARD_DEVICE_ID, + cnt_channel_nbr:3, + cnt_bits:24} }; #define cnt_board_nbr (sizeof(cnt_boards)/sizeof(cnt_board_struct)) /*-- device private structure -----------------------------------------------*/ -typedef struct -{ - struct pci_dev *pcidev; +typedef struct { + struct pci_dev *pcidev; } cnt_device_private; #define devpriv ((cnt_device_private *)dev->private) -static comedi_driver cnt_driver = -{ - driver_name: CNT_DRIVER_NAME, - module: THIS_MODULE, - attach: cnt_attach, - detach: cnt_detach, +static comedi_driver cnt_driver = { + driver_name:CNT_DRIVER_NAME, + module:THIS_MODULE, + attach:cnt_attach, + detach:cnt_detach, }; + COMEDI_INITCLEANUP(cnt_driver); /*-- counter write ----------------------------------------------------------*/ /* This should be used only for resetting the counters; maybe it is better to make a special command 'reset'. */ -static int cnt_winsn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int cnt_winsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int chan = CR_CHAN(insn->chanspec); - - outb((unsigned char)((data[0] >> 24) & 0xff), dev->iobase + chan * 0x20 + 0x10); - outb((unsigned char)((data[0] >> 16) & 0xff), dev->iobase + chan * 0x20 + 0x0c); - outb((unsigned char)((data[0] >> 8) & 0xff), dev->iobase + chan * 0x20 + 0x08); - outb((unsigned char)((data[0] >> 0) & 0xff), dev->iobase + chan * 0x20 + 0x04); - - /* return the number of samples written */ - return 1; + int chan = CR_CHAN(insn->chanspec); + + outb((unsigned char)((data[0] >> 24) & 0xff), + dev->iobase + chan * 0x20 + 0x10); + outb((unsigned char)((data[0] >> 16) & 0xff), + dev->iobase + chan * 0x20 + 0x0c); + outb((unsigned char)((data[0] >> 8) & 0xff), + dev->iobase + chan * 0x20 + 0x08); + outb((unsigned char)((data[0] >> 0) & 0xff), + dev->iobase + chan * 0x20 + 0x04); + + /* return the number of samples written */ + return 1; } /*-- counter read -----------------------------------------------------------*/ -static int cnt_rinsn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int cnt_rinsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - unsigned char a0, a1, a2, a3, a4; - int chan = CR_CHAN(insn->chanspec); - int result; + unsigned char a0, a1, a2, a3, a4; + int chan = CR_CHAN(insn->chanspec); + int result; - a0 = inb(dev->iobase + chan * 0x20); - a1 = inb(dev->iobase + chan * 0x20 + 0x04); - a2 = inb(dev->iobase + chan * 0x20 + 0x08); - a3 = inb(dev->iobase + chan * 0x20 + 0x0c); - a4 = inb(dev->iobase + chan * 0x20 + 0x10); + a0 = inb(dev->iobase + chan * 0x20); + a1 = inb(dev->iobase + chan * 0x20 + 0x04); + a2 = inb(dev->iobase + chan * 0x20 + 0x08); + a3 = inb(dev->iobase + chan * 0x20 + 0x0c); + a4 = inb(dev->iobase + chan * 0x20 + 0x10); - result = (a1 + (a2 * 256) + (a3 * 65536)); - if (a4 > 0) result = result - s->maxdata; + result = (a1 + (a2 * 256) + (a3 * 65536)); + if (a4 > 0) + result = result - s->maxdata; - *data = (lsampl_t)result; + *data = (lsampl_t) result; - /* return the number of samples read */ - return 1; + /* return the number of samples read */ + return 1; } /*-- attach -----------------------------------------------------------------*/ -static int cnt_attach(comedi_device *dev, comedi_devconfig *it) +static int cnt_attach(comedi_device * dev, comedi_devconfig * it) { - comedi_subdevice *subdevice; - struct pci_dev *pci_device; - cnt_board_struct *board; - unsigned long io_base; - int error, i; + comedi_subdevice *subdevice; + struct pci_dev *pci_device; + cnt_board_struct *board; + unsigned long io_base; + int error, i; /* allocate device private structure */ - if((error = alloc_private(dev, sizeof(cnt_device_private))) < 0) - { + if ((error = alloc_private(dev, sizeof(cnt_device_private))) < 0) { + return error; + } + + /* Probe the device to determine what device in the series it is. */ + for (pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_device != NULL; + pci_device = + pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { + if (pci_device->vendor == PCI_VENDOR_ID_KOLTER) { + for (i = 0; i < cnt_board_nbr; i++) { + if (cnt_boards[i].device_id == + pci_device->device) { + /* was a particular bus/slot requested? */ + if ((it->options[0] != 0) + || (it->options[1] != 0)) { + /* are we on the wrong bus/slot? */ + if (pci_device->bus->number != + it->options[0] + || PCI_SLOT(pci_device-> + devfn) != + it->options[1]) { + continue; + } + } + + dev->board_ptr = cnt_boards + i; + board = (cnt_board_struct *) dev-> + board_ptr; + goto found; + } + } + } + } + printk("comedi%d: no supported board found! (req. bus/slot: %d/%d)\n", + dev->minor, it->options[0], it->options[1]); + return -EIO; + + found: + printk("comedi%d: found %s at PCI bus %d, slot %d\n", dev->minor, + board->name, pci_device->bus->number, + PCI_SLOT(pci_device->devfn)); + devpriv->pcidev = pci_device; + dev->board_name = board->name; + + /* enable PCI device and request regions */ + if ((error = comedi_pci_enable(pci_device, CNT_DRIVER_NAME)) < 0) { + printk("comedi%d: failed to enable PCI device and request regions!\n", dev->minor); + return error; + } + + /* read register base address [PCI_BASE_ADDRESS #0] */ + io_base = pci_resource_start(pci_device, 0); + dev->iobase = io_base; + + /* allocate the subdevice structures */ + if ((error = alloc_subdevices(dev, 1)) < 0) { return error; } - /* Probe the device to determine what device in the series it is. */ - for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) - { - if(pci_device->vendor == PCI_VENDOR_ID_KOLTER) - { - for(i=0; idevice) - { - /* was a particular bus/slot requested? */ - if((it->options[0] != 0) || (it->options[1] != 0)) - { - /* are we on the wrong bus/slot? */ - if(pci_device->bus->number != it->options[0] || - PCI_SLOT(pci_device->devfn) != it->options[1]) - { - continue; - } - } - - dev->board_ptr = cnt_boards + i; - board = (cnt_board_struct *)dev->board_ptr; - goto found; - } - } - } - } - printk("comedi%d: no supported board found! (req. bus/slot: %d/%d)\n", - dev->minor, it->options[0], it->options[1]); - return -EIO; - -found: - printk("comedi%d: found %s at PCI bus %d, slot %d\n",dev->minor, - board->name, pci_device->bus->number, PCI_SLOT(pci_device->devfn)); - devpriv->pcidev = pci_device; - dev->board_name = board->name; - - /* enable PCI device and request regions */ - if((error = comedi_pci_enable(pci_device, CNT_DRIVER_NAME)) < 0) - { - printk("comedi%d: failed to enable PCI device and request regions!\n", - dev->minor); - return error; - } - - /* read register base address [PCI_BASE_ADDRESS #0] */ - io_base = pci_resource_start(pci_device, 0); - dev->iobase = io_base; - - /* allocate the subdevice structures */ - if((error = alloc_subdevices(dev, 1)) < 0) - { - return error; - } - - subdevice = dev->subdevices + 0; - dev->read_subdev = subdevice; - - subdevice->type = COMEDI_SUBD_COUNTER; - subdevice->subdev_flags = SDF_READABLE /* | SDF_COMMON*/; - subdevice->n_chan = board->cnt_channel_nbr; - subdevice->maxdata = (1 << board->cnt_bits) - 1; - subdevice->insn_read = cnt_rinsn; - subdevice->insn_write = cnt_winsn; - - // select 20MHz clock - outb(3, dev->iobase + 248); - - // reset all counters - outb(0, dev->iobase); - outb(0, dev->iobase + 0x20); - outb(0, dev->iobase + 0x40); - - printk("comedi%d: " CNT_DRIVER_NAME " attached.\n",dev->minor); - return 0; + subdevice = dev->subdevices + 0; + dev->read_subdev = subdevice; + + subdevice->type = COMEDI_SUBD_COUNTER; + subdevice->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ; + subdevice->n_chan = board->cnt_channel_nbr; + subdevice->maxdata = (1 << board->cnt_bits) - 1; + subdevice->insn_read = cnt_rinsn; + subdevice->insn_write = cnt_winsn; + + // select 20MHz clock + outb(3, dev->iobase + 248); + + // reset all counters + outb(0, dev->iobase); + outb(0, dev->iobase + 0x20); + outb(0, dev->iobase + 0x40); + + printk("comedi%d: " CNT_DRIVER_NAME " attached.\n", dev->minor); + return 0; } /*-- detach -----------------------------------------------------------------*/ -static int cnt_detach(comedi_device *dev) +static int cnt_detach(comedi_device * dev) { - if (devpriv && devpriv->pcidev) - { - if(dev->iobase) - { + if (devpriv && devpriv->pcidev) { + if (dev->iobase) { comedi_pci_disable(devpriv->pcidev); } pci_dev_put(devpriv->pcidev); } - printk("comedi%d: " CNT_DRIVER_NAME " remove\n",dev->minor); + printk("comedi%d: " CNT_DRIVER_NAME " remove\n", dev->minor); return 0; } diff --git a/comedi/drivers/me4000.c b/comedi/drivers/me4000.c index 7553b2d8..ed7b34ae 100644 --- a/comedi/drivers/me4000.c +++ b/comedi/drivers/me4000.c @@ -65,640 +65,667 @@ broken. #endif static const me4000_board_t me4000_boards[] = { - { "ME-4650" , 0x4650, { 0, 0 }, { 16, 0, 0, 0 }, { 4 }, { 0 } }, + {"ME-4650", 0x4650, {0, 0}, {16, 0, 0, 0}, {4}, {0}}, - { "ME-4660" , 0x4660, { 0, 0 }, { 32, 0, 16, 0 }, { 4 }, { 3 } }, - { "ME-4660i" , 0x4661, { 0, 0 }, { 32, 0, 16, 0 }, { 4 }, { 3 } }, - { "ME-4660s" , 0x4662, { 0, 0 }, { 32, 8, 16, 0 }, { 4 }, { 3 } }, - { "ME-4660is", 0x4663, { 0, 0 }, { 32, 8, 16, 0 }, { 4 }, { 3 } }, + {"ME-4660", 0x4660, {0, 0}, {32, 0, 16, 0}, {4}, {3}}, + {"ME-4660i", 0x4661, {0, 0}, {32, 0, 16, 0}, {4}, {3}}, + {"ME-4660s", 0x4662, {0, 0}, {32, 8, 16, 0}, {4}, {3}}, + {"ME-4660is", 0x4663, {0, 0}, {32, 8, 16, 0}, {4}, {3}}, - { "ME-4670" , 0x4670, { 4, 0 }, { 32, 0, 16, 1 }, { 4 }, { 3 } }, - { "ME-4670i" , 0x4671, { 4, 0 }, { 32, 0, 16, 1 }, { 4 }, { 3 } }, - { "ME-4670s" , 0x4672, { 4, 0 }, { 32, 8, 16, 1 }, { 4 }, { 3 } }, - { "ME-4670is", 0x4673, { 4, 0 }, { 32, 8, 16, 1 }, { 4 }, { 3 } }, + {"ME-4670", 0x4670, {4, 0}, {32, 0, 16, 1}, {4}, {3}}, + {"ME-4670i", 0x4671, {4, 0}, {32, 0, 16, 1}, {4}, {3}}, + {"ME-4670s", 0x4672, {4, 0}, {32, 8, 16, 1}, {4}, {3}}, + {"ME-4670is", 0x4673, {4, 0}, {32, 8, 16, 1}, {4}, {3}}, - { "ME-4680" , 0x4680, { 4, 4 }, { 32, 0, 16, 1 }, { 4 }, { 3 } }, - { "ME-4680i" , 0x4681, { 4, 4 }, { 32, 0, 16, 1 }, { 4 }, { 3 } }, - { "ME-4680s" , 0x4682, { 4, 4 }, { 32, 8, 16, 1 }, { 4 }, { 3 } }, - { "ME-4680is", 0x4683, { 4, 4 }, { 32, 8, 16, 1 }, { 4 }, { 3 } }, + {"ME-4680", 0x4680, {4, 4}, {32, 0, 16, 1}, {4}, {3}}, + {"ME-4680i", 0x4681, {4, 4}, {32, 0, 16, 1}, {4}, {3}}, + {"ME-4680s", 0x4682, {4, 4}, {32, 8, 16, 1}, {4}, {3}}, + {"ME-4680is", 0x4683, {4, 4}, {32, 8, 16, 1}, {4}, {3}}, - { 0 }, + {0}, }; #define ME4000_BOARD_VERSIONS (sizeof(me4000_boards) / sizeof(me4000_board_t) - 1) - - /*----------------------------------------------------------------------------- Comedi function prototypes ---------------------------------------------------------------------------*/ -static int me4000_attach(comedi_device *dev, comedi_devconfig *it); -static int me4000_detach(comedi_device *dev); +static int me4000_attach(comedi_device * dev, comedi_devconfig * it); +static int me4000_detach(comedi_device * dev); static comedi_driver driver_me4000 = { - driver_name: "me4000", - module: THIS_MODULE, - attach: me4000_attach, - detach: me4000_detach, + driver_name:"me4000", + module:THIS_MODULE, + attach:me4000_attach, + detach:me4000_detach, }; - - /*----------------------------------------------------------------------------- Meilhaus function prototypes ---------------------------------------------------------------------------*/ -static int me4000_probe(comedi_device *dev, comedi_devconfig *it); -static int get_registers(comedi_device *dev, struct pci_dev *pci_dev_p); -static int init_board_info(comedi_device *dev, struct pci_dev *pci_dev_p); -static int init_ao_context(comedi_device *dev); -static int init_ai_context(comedi_device *dev); -static int init_dio_context(comedi_device *dev); -static int init_cnt_context(comedi_device *dev); -static int xilinx_download(comedi_device *dev); -static int reset_board(comedi_device *dev); - -static int me4000_dio_insn_bits( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_dio_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int cnt_reset(comedi_device *dev, unsigned int channel); - -static int cnt_config( - comedi_device *dev, - unsigned int channel, - unsigned int mode); - -static int me4000_cnt_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_cnt_insn_write( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_cnt_insn_read( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_ai_insn_read( - comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_ai_cancel(comedi_device *dev, comedi_subdevice *s); - -static int ai_check_chanlist( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd); - -static int ai_round_cmd_args( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd, +static int me4000_probe(comedi_device * dev, comedi_devconfig * it); +static int get_registers(comedi_device * dev, struct pci_dev *pci_dev_p); +static int init_board_info(comedi_device * dev, struct pci_dev *pci_dev_p); +static int init_ao_context(comedi_device * dev); +static int init_ai_context(comedi_device * dev); +static int init_dio_context(comedi_device * dev); +static int init_cnt_context(comedi_device * dev); +static int xilinx_download(comedi_device * dev); +static int reset_board(comedi_device * dev); + +static int me4000_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static int me4000_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static int cnt_reset(comedi_device * dev, unsigned int channel); + +static int cnt_config(comedi_device * dev, + unsigned int channel, unsigned int mode); + +static int me4000_cnt_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static int me4000_cnt_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static int me4000_cnt_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static int me4000_ai_insn_read(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data); + +static int me4000_ai_cancel(comedi_device * dev, comedi_subdevice * s); + +static int ai_check_chanlist(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd); + +static int ai_round_cmd_args(comedi_device * dev, + comedi_subdevice * s, + comedi_cmd * cmd, unsigned int *init_ticks, - unsigned int *scan_ticks, - unsigned int *chan_ticks); + unsigned int *scan_ticks, unsigned int *chan_ticks); -static int ai_prepare( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd, - unsigned int init_ticks, - unsigned int scan_ticks, - unsigned int chan_ticks); - -static int ai_write_chanlist( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd); - -static irqreturn_t me4000_ai_isr( - int irq, - void *dev_id - PT_REGS_ARG); - -static int me4000_ai_do_cmd_test( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd); - -static int me4000_ai_do_cmd(comedi_device *dev, comedi_subdevice *s); - -static int me4000_ao_insn_write( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static int me4000_ao_insn_read( - comedi_device * dev, +static int ai_prepare(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, - lsampl_t *data); + comedi_cmd * cmd, + unsigned int init_ticks, + unsigned int scan_ticks, unsigned int chan_ticks); + +static int ai_write_chanlist(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd); + +static irqreturn_t me4000_ai_isr(int irq, void *dev_id PT_REGS_ARG); + +static int me4000_ai_do_cmd_test(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd); + +static int me4000_ai_do_cmd(comedi_device * dev, comedi_subdevice * s); + +static int me4000_ao_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int me4000_ao_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /*----------------------------------------------------------------------------- Meilhaus inline functions ---------------------------------------------------------------------------*/ -static void inline me4000_outb(comedi_device *dev, unsigned char value, unsigned long port); -static void inline me4000_outl(comedi_device *dev, unsigned long value, unsigned long port); -static unsigned long inline me4000_inl(comedi_device *dev, unsigned long port); -static unsigned char inline me4000_inb(comedi_device *dev, unsigned long port); - - -static void me4000_outb(comedi_device *dev, unsigned char value, unsigned long port){ - PORT_PDEBUG("--> 0x%02X port 0x%04lX\n", value, port); - outb(value, port); +static void inline me4000_outb(comedi_device * dev, unsigned char value, + unsigned long port); +static void inline me4000_outl(comedi_device * dev, unsigned long value, + unsigned long port); +static unsigned long inline me4000_inl(comedi_device * dev, unsigned long port); +static unsigned char inline me4000_inb(comedi_device * dev, unsigned long port); + +static void me4000_outb(comedi_device * dev, unsigned char value, + unsigned long port) +{ + PORT_PDEBUG("--> 0x%02X port 0x%04lX\n", value, port); + outb(value, port); } -static void me4000_outl(comedi_device *dev, unsigned long value, unsigned long port){ - PORT_PDEBUG("--> 0x%08lX port 0x%04lX\n", value, port); - outl(value, port); +static void me4000_outl(comedi_device * dev, unsigned long value, + unsigned long port) +{ + PORT_PDEBUG("--> 0x%08lX port 0x%04lX\n", value, port); + outl(value, port); } -static unsigned long me4000_inl(comedi_device *dev, unsigned long port){ - unsigned long value; - value = inl(port); - PORT_PDEBUG("<-- 0x%08lX port 0x%04lX\n", value, port); - return value; +static unsigned long me4000_inl(comedi_device * dev, unsigned long port) +{ + unsigned long value; + value = inl(port); + PORT_PDEBUG("<-- 0x%08lX port 0x%04lX\n", value, port); + return value; } -static unsigned char me4000_inb(comedi_device *dev, unsigned long port){ - unsigned char value; - value = inb(port); - PORT_PDEBUG("<-- 0x%08X port 0x%04lX\n", value, port); - return value; +static unsigned char me4000_inb(comedi_device * dev, unsigned long port) +{ + unsigned char value; + value = inb(port); + PORT_PDEBUG("<-- 0x%08X port 0x%04lX\n", value, port); + return value; } - - -static const comedi_lrange me4000_ai_range= -{ - 4, - { - UNI_RANGE(2.5), - UNI_RANGE(10), - BIP_RANGE(2.5), - BIP_RANGE(10), - } +static const comedi_lrange me4000_ai_range = { + 4, + { + UNI_RANGE(2.5), + UNI_RANGE(10), + BIP_RANGE(2.5), + BIP_RANGE(10), + } }; - - -static const comedi_lrange me4000_ao_range= -{ - 1, - { - BIP_RANGE(10), - } +static const comedi_lrange me4000_ao_range = { + 1, + { + BIP_RANGE(10), + } }; +static int me4000_attach(comedi_device * dev, comedi_devconfig * it) +{ + comedi_subdevice *s; + int result; + CALL_PDEBUG("In me4000_attach()\n"); -static int me4000_attach(comedi_device *dev, comedi_devconfig *it){ - comedi_subdevice *s; - int result; - - CALL_PDEBUG("In me4000_attach()\n"); - - result = me4000_probe(dev, it); - if(result) return result; + result = me4000_probe(dev, it); + if (result) + return result; - /* - * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. It relies on - * n_subdevices being set correctly. - */ - if(alloc_subdevices(dev, 4) < 0) - return -ENOMEM; + /* + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. It relies on + * n_subdevices being set correctly. + */ + if (alloc_subdevices(dev, 4) < 0) + return -ENOMEM; /*========================================================================= Analog input subdevice ========================================================================*/ - s = dev->subdevices + 0; - - if(thisboard->ai.count){ - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; - s->n_chan = thisboard->ai.count; - s->maxdata = 0xFFFF; // 16 bit ADC - s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT; - s->range_table = &me4000_ai_range; - s->insn_read = me4000_ai_insn_read; - - if(info->irq > 0){ - if(comedi_request_irq(info->irq, me4000_ai_isr, IRQF_SHARED, "ME-4000", dev)) { - printk("comedi%d: me4000: me4000_attach(): Unable to allocate irq\n", dev->minor); - } - else{ - dev->read_subdev = s; - s->subdev_flags |= SDF_CMD_READ; - s->cancel = me4000_ai_cancel; - s->do_cmdtest = me4000_ai_do_cmd_test; - s->do_cmd = me4000_ai_do_cmd; - } - } - else{ - printk(KERN_WARNING"comedi%d: me4000: me4000_attach(): No interrupt available\n", dev->minor); - } - } - else{ - s->type = COMEDI_SUBD_UNUSED; - } + s = dev->subdevices + 0; + + if (thisboard->ai.count) { + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF; + s->n_chan = thisboard->ai.count; + s->maxdata = 0xFFFF; // 16 bit ADC + s->len_chanlist = ME4000_AI_CHANNEL_LIST_COUNT; + s->range_table = &me4000_ai_range; + s->insn_read = me4000_ai_insn_read; + + if (info->irq > 0) { + if (comedi_request_irq(info->irq, me4000_ai_isr, + IRQF_SHARED, "ME-4000", dev)) { + printk("comedi%d: me4000: me4000_attach(): Unable to allocate irq\n", dev->minor); + } else { + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->cancel = me4000_ai_cancel; + s->do_cmdtest = me4000_ai_do_cmd_test; + s->do_cmd = me4000_ai_do_cmd; + } + } else { + printk(KERN_WARNING + "comedi%d: me4000: me4000_attach(): No interrupt available\n", + dev->minor); + } + } else { + s->type = COMEDI_SUBD_UNUSED; + } /*========================================================================= Analog output subdevice ========================================================================*/ - s = dev->subdevices + 1; - - if(thisboard->ao.count){ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE | SDF_COMMON | SDF_GROUND; - s->n_chan = thisboard->ao.count; - s->maxdata = 0xFFFF; // 16 bit DAC - s->range_table = &me4000_ao_range; - s->insn_write = me4000_ao_insn_write; - s->insn_read = me4000_ao_insn_read; - } - else{ - s->type = COMEDI_SUBD_UNUSED; - } + s = dev->subdevices + 1; + + if (thisboard->ao.count) { + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE | SDF_COMMON | SDF_GROUND; + s->n_chan = thisboard->ao.count; + s->maxdata = 0xFFFF; // 16 bit DAC + s->range_table = &me4000_ao_range; + s->insn_write = me4000_ao_insn_write; + s->insn_read = me4000_ao_insn_read; + } else { + s->type = COMEDI_SUBD_UNUSED; + } /*========================================================================= Digital I/O subdevice ========================================================================*/ - s = dev->subdevices + 2; - - if(thisboard->dio.count){ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = thisboard->dio.count * 8; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = me4000_dio_insn_bits; - s->insn_config = me4000_dio_insn_config; - } - else{ - s->type = COMEDI_SUBD_UNUSED; - } - - /* - * Check for optoisolated ME-4000 version. If one the first - * port is a fixed output port and the second is a fixed input port. - */ - if(!me4000_inl(dev, info->dio_context.dir_reg)){ - s->io_bits |= 0xFF; - me4000_outl(dev, ME4000_DIO_CTRL_BIT_MODE_0, info->dio_context.dir_reg); - } + s = dev->subdevices + 2; + + if (thisboard->dio.count) { + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = thisboard->dio.count * 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = me4000_dio_insn_bits; + s->insn_config = me4000_dio_insn_config; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + + /* + * Check for optoisolated ME-4000 version. If one the first + * port is a fixed output port and the second is a fixed input port. + */ + if (!me4000_inl(dev, info->dio_context.dir_reg)) { + s->io_bits |= 0xFF; + me4000_outl(dev, ME4000_DIO_CTRL_BIT_MODE_0, + info->dio_context.dir_reg); + } /*========================================================================= Counter subdevice ========================================================================*/ - s = dev->subdevices + 3; - - if(thisboard->cnt.count){ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = thisboard->cnt.count; - s->maxdata = 0xFFFF; // 16 bit counters - s->insn_read = me4000_cnt_insn_read; - s->insn_write = me4000_cnt_insn_write; - s->insn_config = me4000_cnt_insn_config; - } - else{ - s->type = COMEDI_SUBD_UNUSED; - } - - return 0; -} - + s = dev->subdevices + 3; + + if (thisboard->cnt.count) { + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = thisboard->cnt.count; + s->maxdata = 0xFFFF; // 16 bit counters + s->insn_read = me4000_cnt_insn_read; + s->insn_write = me4000_cnt_insn_write; + s->insn_config = me4000_cnt_insn_config; + } else { + s->type = COMEDI_SUBD_UNUSED; + } + return 0; +} -static int me4000_probe(comedi_device *dev, comedi_devconfig *it){ - struct pci_dev* pci_device; - int result, i; - me4000_board_t *board; +static int me4000_probe(comedi_device * dev, comedi_devconfig * it) +{ + struct pci_dev *pci_device; + int result, i; + me4000_board_t *board; - CALL_PDEBUG("In me4000_probe()\n"); + CALL_PDEBUG("In me4000_probe()\n"); /* Allocate private memory */ - if(alloc_private(dev, sizeof(me4000_info_t)) < 0){ + if (alloc_private(dev, sizeof(me4000_info_t)) < 0) { return -ENOMEM; } - /* - * Probe the device to determine what device in the series it is. - */ - for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { - if(pci_device->vendor == PCI_VENDOR_ID_MEILHAUS){ - for(i = 0; i < ME4000_BOARD_VERSIONS; i++){ - if(me4000_boards[i].device_id == pci_device->device){ + /* + * Probe the device to determine what device in the series it is. + */ + for (pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_device != NULL; + pci_device = + pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { + if (pci_device->vendor == PCI_VENDOR_ID_MEILHAUS) { + for (i = 0; i < ME4000_BOARD_VERSIONS; i++) { + if (me4000_boards[i].device_id == + pci_device->device) { /* Was a particular bus/slot requested? */ - if((it->options[0] != 0) || (it->options[1] != 0)){ + if ((it->options[0] != 0) + || (it->options[1] != 0)) { /* Are we on the wrong bus/slot? */ - if(pci_device->bus->number != it->options[0] || - PCI_SLOT(pci_device->devfn) != it->options[1]){ + if (pci_device->bus->number != + it->options[0] + || PCI_SLOT(pci_device-> + devfn) != + it->options[1]) { continue; } } dev->board_ptr = me4000_boards + i; - board = (me4000_board_t *) dev->board_ptr; + board = (me4000_board_t *) dev-> + board_ptr; info->pci_dev_p = pci_device; goto found; } } } - } + } - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): No supported board found (req. bus/slot : %d/%d)\n", - dev->minor,it->options[0], it->options[1]); - return -ENODEV; + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): No supported board found (req. bus/slot : %d/%d)\n", + dev->minor, it->options[0], it->options[1]); + return -ENODEV; -found: + found: - printk(KERN_INFO"comedi%d: me4000: me4000_probe(): Found %s at PCI bus %d, slot %d\n", - dev->minor, me4000_boards[i].name, - pci_device->bus->number, PCI_SLOT(pci_device->devfn)); + printk(KERN_INFO + "comedi%d: me4000: me4000_probe(): Found %s at PCI bus %d, slot %d\n", + dev->minor, me4000_boards[i].name, pci_device->bus->number, + PCI_SLOT(pci_device->devfn)); - /* Set data in device structure */ - dev->board_name = board->name; + /* Set data in device structure */ + dev->board_name = board->name; - /* Enable PCI device and request regions */ - result = comedi_pci_enable(pci_device, dev->board_name); - if(result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot enable PCI device and request I/O regions\n", dev->minor); + /* Enable PCI device and request regions */ + result = comedi_pci_enable(pci_device, dev->board_name); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot enable PCI device and request I/O regions\n", + dev->minor); return result; - } + } - /* Get the PCI base registers */ - result = get_registers(dev, pci_device); - if(result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot get registers\n", dev->minor); + /* Get the PCI base registers */ + result = get_registers(dev, pci_device); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot get registers\n", + dev->minor); return result; - } - /* Initialize board info */ - result = init_board_info(dev, pci_device); - if (result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot init baord info\n", dev->minor); + } + /* Initialize board info */ + result = init_board_info(dev, pci_device); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot init baord info\n", + dev->minor); return result; - } + } - /* Init analog output context */ - result = init_ao_context(dev); - if (result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot init ao context\n", dev->minor); + /* Init analog output context */ + result = init_ao_context(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot init ao context\n", + dev->minor); return result; - } + } - /* Init analog input context */ - result = init_ai_context(dev); - if (result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot init ai context\n", dev->minor); + /* Init analog input context */ + result = init_ai_context(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot init ai context\n", + dev->minor); return result; - } + } - /* Init digital I/O context */ - result = init_dio_context(dev); - if (result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot init dio context\n", dev->minor); + /* Init digital I/O context */ + result = init_dio_context(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot init dio context\n", + dev->minor); return result; - } + } - /* Init counter context */ - result = init_cnt_context(dev); - if (result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Cannot init cnt context\n", dev->minor); + /* Init counter context */ + result = init_cnt_context(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Cannot init cnt context\n", + dev->minor); return result; - } + } - /* Download the xilinx firmware */ - result = xilinx_download(dev); - if(result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Can't download firmware\n", dev->minor); + /* Download the xilinx firmware */ + result = xilinx_download(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Can't download firmware\n", + dev->minor); return result; - } + } - /* Make a hardware reset */ - result = reset_board(dev); - if(result){ - printk(KERN_ERR"comedi%d: me4000: me4000_probe(): Can't reset board\n", dev->minor); + /* Make a hardware reset */ + result = reset_board(dev); + if (result) { + printk(KERN_ERR + "comedi%d: me4000: me4000_probe(): Can't reset board\n", + dev->minor); return result; - } + } - return 0; + return 0; } +static int get_registers(comedi_device * dev, struct pci_dev *pci_dev_p) +{ - -static int get_registers(comedi_device *dev, struct pci_dev *pci_dev_p){ - - CALL_PDEBUG("In get_registers()\n"); + CALL_PDEBUG("In get_registers()\n"); /*--------------------------- plx regbase ---------------------------------*/ - info->plx_regbase = pci_resource_start (pci_dev_p, 1); - if(info->plx_regbase == 0){ - printk(KERN_ERR"comedi%d: me4000: get_registers(): PCI base address 1 is not available\n", dev->minor); - return -ENODEV; - } - info->plx_regbase_size = pci_resource_len(pci_dev_p, 1); - + info->plx_regbase = pci_resource_start(pci_dev_p, 1); + if (info->plx_regbase == 0) { + printk(KERN_ERR + "comedi%d: me4000: get_registers(): PCI base address 1 is not available\n", + dev->minor); + return -ENODEV; + } + info->plx_regbase_size = pci_resource_len(pci_dev_p, 1); /*--------------------------- me4000 regbase ------------------------------*/ - info->me4000_regbase = pci_resource_start (pci_dev_p, 2); - if(info->me4000_regbase == 0){ - printk(KERN_ERR"comedi%d: me4000: get_registers(): PCI base address 2 is not available\n", dev->minor); - return -ENODEV; - } - info->me4000_regbase_size = pci_resource_len(pci_dev_p, 2); - + info->me4000_regbase = pci_resource_start(pci_dev_p, 2); + if (info->me4000_regbase == 0) { + printk(KERN_ERR + "comedi%d: me4000: get_registers(): PCI base address 2 is not available\n", + dev->minor); + return -ENODEV; + } + info->me4000_regbase_size = pci_resource_len(pci_dev_p, 2); /*--------------------------- timer regbase ------------------------------*/ - info->timer_regbase = pci_resource_start (pci_dev_p, 3); - if(info->timer_regbase == 0){ - printk(KERN_ERR"comedi%d: me4000: get_registers(): PCI base address 3 is not available\n", dev->minor); - return -ENODEV; - } - info->timer_regbase_size = pci_resource_len(pci_dev_p, 3); - + info->timer_regbase = pci_resource_start(pci_dev_p, 3); + if (info->timer_regbase == 0) { + printk(KERN_ERR + "comedi%d: me4000: get_registers(): PCI base address 3 is not available\n", + dev->minor); + return -ENODEV; + } + info->timer_regbase_size = pci_resource_len(pci_dev_p, 3); /*--------------------------- program regbase ------------------------------*/ - info->program_regbase = pci_resource_start (pci_dev_p, 5); - if(info->program_regbase == 0){ - printk(KERN_ERR"comedi%d: me4000: get_registers(): PCI base address 5 is not available\n", dev->minor); - return -ENODEV; - } - info->program_regbase_size = pci_resource_len(pci_dev_p, 5); + info->program_regbase = pci_resource_start(pci_dev_p, 5); + if (info->program_regbase == 0) { + printk(KERN_ERR + "comedi%d: me4000: get_registers(): PCI base address 5 is not available\n", + dev->minor); + return -ENODEV; + } + info->program_regbase_size = pci_resource_len(pci_dev_p, 5); - return 0; + return 0; } +static int init_board_info(comedi_device * dev, struct pci_dev *pci_dev_p) +{ + int result; + CALL_PDEBUG("In init_board_info()\n"); -static int init_board_info(comedi_device *dev, struct pci_dev *pci_dev_p){ - int result; - - CALL_PDEBUG("In init_board_info()\n"); - - /* Init spin locks */ - //spin_lock_init(&info->preload_lock); - //spin_lock_init(&info->ai_ctrl_lock); + /* Init spin locks */ + //spin_lock_init(&info->preload_lock); + //spin_lock_init(&info->ai_ctrl_lock); - /* Get the serial number */ - result = pci_read_config_dword(pci_dev_p, 0x2C, &info->serial_no); - if(result != PCIBIOS_SUCCESSFUL){ - return result; - } + /* Get the serial number */ + result = pci_read_config_dword(pci_dev_p, 0x2C, &info->serial_no); + if (result != PCIBIOS_SUCCESSFUL) { + return result; + } - /* Get the hardware revision */ - result = pci_read_config_byte(pci_dev_p, 0x08, &info->hw_revision); - if(result != PCIBIOS_SUCCESSFUL){ - return result; - } + /* Get the hardware revision */ + result = pci_read_config_byte(pci_dev_p, 0x08, &info->hw_revision); + if (result != PCIBIOS_SUCCESSFUL) { + return result; + } - /* Get the vendor id */ - info->vendor_id = pci_dev_p->vendor; + /* Get the vendor id */ + info->vendor_id = pci_dev_p->vendor; - /* Get the device id */ - info->device_id = pci_dev_p->device; + /* Get the device id */ + info->device_id = pci_dev_p->device; - /* Get the irq assigned to the board */ - info->irq = pci_dev_p->irq; + /* Get the irq assigned to the board */ + info->irq = pci_dev_p->irq; - return 0; + return 0; } - - -static int init_ao_context(comedi_device *dev){ - int i; - - CALL_PDEBUG("In init_ao_context()\n"); - - for(i = 0; i < thisboard->ao.count; i++){ - //spin_lock_init(&info->ao_context[i].use_lock); - info->ao_context[i].irq = info->irq; - - switch(i){ - case 0: - info->ao_context[i].ctrl_reg = info->me4000_regbase + ME4000_AO_00_CTRL_REG; - info->ao_context[i].status_reg = info->me4000_regbase + ME4000_AO_00_STATUS_REG; - info->ao_context[i].fifo_reg = info->me4000_regbase + ME4000_AO_00_FIFO_REG; - info->ao_context[i].single_reg = info->me4000_regbase + ME4000_AO_00_SINGLE_REG; - info->ao_context[i].timer_reg = info->me4000_regbase + ME4000_AO_00_TIMER_REG; - info->ao_context[i].irq_status_reg = info->me4000_regbase + ME4000_IRQ_STATUS_REG; - info->ao_context[i].preload_reg = info->me4000_regbase + ME4000_AO_LOADSETREG_XX; - break; - case 1: - info->ao_context[i].ctrl_reg = info->me4000_regbase + ME4000_AO_01_CTRL_REG; - info->ao_context[i].status_reg = info->me4000_regbase + ME4000_AO_01_STATUS_REG; - info->ao_context[i].fifo_reg = info->me4000_regbase + ME4000_AO_01_FIFO_REG; - info->ao_context[i].single_reg = info->me4000_regbase + ME4000_AO_01_SINGLE_REG; - info->ao_context[i].timer_reg = info->me4000_regbase + ME4000_AO_01_TIMER_REG; - info->ao_context[i].irq_status_reg = info->me4000_regbase + ME4000_IRQ_STATUS_REG; - info->ao_context[i].preload_reg = info->me4000_regbase + ME4000_AO_LOADSETREG_XX; - break; - case 2: - info->ao_context[i].ctrl_reg = info->me4000_regbase + ME4000_AO_02_CTRL_REG; - info->ao_context[i].status_reg = info->me4000_regbase + ME4000_AO_02_STATUS_REG; - info->ao_context[i].fifo_reg = info->me4000_regbase + ME4000_AO_02_FIFO_REG; - info->ao_context[i].single_reg = info->me4000_regbase + ME4000_AO_02_SINGLE_REG; - info->ao_context[i].timer_reg = info->me4000_regbase + ME4000_AO_02_TIMER_REG; - info->ao_context[i].irq_status_reg = info->me4000_regbase + ME4000_IRQ_STATUS_REG; - info->ao_context[i].preload_reg = info->me4000_regbase + ME4000_AO_LOADSETREG_XX; - break; - case 3: - info->ao_context[i].ctrl_reg = info->me4000_regbase + ME4000_AO_03_CTRL_REG; - info->ao_context[i].status_reg = info->me4000_regbase + ME4000_AO_03_STATUS_REG; - info->ao_context[i].fifo_reg = info->me4000_regbase + ME4000_AO_03_FIFO_REG; - info->ao_context[i].single_reg = info->me4000_regbase + ME4000_AO_03_SINGLE_REG; - info->ao_context[i].timer_reg = info->me4000_regbase + ME4000_AO_03_TIMER_REG; - info->ao_context[i].irq_status_reg = info->me4000_regbase + ME4000_IRQ_STATUS_REG; - info->ao_context[i].preload_reg = info->me4000_regbase + ME4000_AO_LOADSETREG_XX; - break; - default: - break; +static int init_ao_context(comedi_device * dev) +{ + int i; + + CALL_PDEBUG("In init_ao_context()\n"); + + for (i = 0; i < thisboard->ao.count; i++) { + //spin_lock_init(&info->ao_context[i].use_lock); + info->ao_context[i].irq = info->irq; + + switch (i) { + case 0: + info->ao_context[i].ctrl_reg = + info->me4000_regbase + ME4000_AO_00_CTRL_REG; + info->ao_context[i].status_reg = + info->me4000_regbase + ME4000_AO_00_STATUS_REG; + info->ao_context[i].fifo_reg = + info->me4000_regbase + ME4000_AO_00_FIFO_REG; + info->ao_context[i].single_reg = + info->me4000_regbase + ME4000_AO_00_SINGLE_REG; + info->ao_context[i].timer_reg = + info->me4000_regbase + ME4000_AO_00_TIMER_REG; + info->ao_context[i].irq_status_reg = + info->me4000_regbase + ME4000_IRQ_STATUS_REG; + info->ao_context[i].preload_reg = + info->me4000_regbase + ME4000_AO_LOADSETREG_XX; + break; + case 1: + info->ao_context[i].ctrl_reg = + info->me4000_regbase + ME4000_AO_01_CTRL_REG; + info->ao_context[i].status_reg = + info->me4000_regbase + ME4000_AO_01_STATUS_REG; + info->ao_context[i].fifo_reg = + info->me4000_regbase + ME4000_AO_01_FIFO_REG; + info->ao_context[i].single_reg = + info->me4000_regbase + ME4000_AO_01_SINGLE_REG; + info->ao_context[i].timer_reg = + info->me4000_regbase + ME4000_AO_01_TIMER_REG; + info->ao_context[i].irq_status_reg = + info->me4000_regbase + ME4000_IRQ_STATUS_REG; + info->ao_context[i].preload_reg = + info->me4000_regbase + ME4000_AO_LOADSETREG_XX; + break; + case 2: + info->ao_context[i].ctrl_reg = + info->me4000_regbase + ME4000_AO_02_CTRL_REG; + info->ao_context[i].status_reg = + info->me4000_regbase + ME4000_AO_02_STATUS_REG; + info->ao_context[i].fifo_reg = + info->me4000_regbase + ME4000_AO_02_FIFO_REG; + info->ao_context[i].single_reg = + info->me4000_regbase + ME4000_AO_02_SINGLE_REG; + info->ao_context[i].timer_reg = + info->me4000_regbase + ME4000_AO_02_TIMER_REG; + info->ao_context[i].irq_status_reg = + info->me4000_regbase + ME4000_IRQ_STATUS_REG; + info->ao_context[i].preload_reg = + info->me4000_regbase + ME4000_AO_LOADSETREG_XX; + break; + case 3: + info->ao_context[i].ctrl_reg = + info->me4000_regbase + ME4000_AO_03_CTRL_REG; + info->ao_context[i].status_reg = + info->me4000_regbase + ME4000_AO_03_STATUS_REG; + info->ao_context[i].fifo_reg = + info->me4000_regbase + ME4000_AO_03_FIFO_REG; + info->ao_context[i].single_reg = + info->me4000_regbase + ME4000_AO_03_SINGLE_REG; + info->ao_context[i].timer_reg = + info->me4000_regbase + ME4000_AO_03_TIMER_REG; + info->ao_context[i].irq_status_reg = + info->me4000_regbase + ME4000_IRQ_STATUS_REG; + info->ao_context[i].preload_reg = + info->me4000_regbase + ME4000_AO_LOADSETREG_XX; + break; + default: + break; + } } - } - return 0; + return 0; } +static int init_ai_context(comedi_device * dev) +{ + CALL_PDEBUG("In init_ai_context()\n"); + + info->ai_context.irq = info->irq; + + info->ai_context.ctrl_reg = info->me4000_regbase + ME4000_AI_CTRL_REG; + info->ai_context.status_reg = + info->me4000_regbase + ME4000_AI_STATUS_REG; + info->ai_context.channel_list_reg = + info->me4000_regbase + ME4000_AI_CHANNEL_LIST_REG; + info->ai_context.data_reg = info->me4000_regbase + ME4000_AI_DATA_REG; + info->ai_context.chan_timer_reg = + info->me4000_regbase + ME4000_AI_CHAN_TIMER_REG; + info->ai_context.chan_pre_timer_reg = + info->me4000_regbase + ME4000_AI_CHAN_PRE_TIMER_REG; + info->ai_context.scan_timer_low_reg = + info->me4000_regbase + ME4000_AI_SCAN_TIMER_LOW_REG; + info->ai_context.scan_timer_high_reg = + info->me4000_regbase + ME4000_AI_SCAN_TIMER_HIGH_REG; + info->ai_context.scan_pre_timer_low_reg = + info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_LOW_REG; + info->ai_context.scan_pre_timer_high_reg = + info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_HIGH_REG; + info->ai_context.start_reg = info->me4000_regbase + ME4000_AI_START_REG; + info->ai_context.irq_status_reg = + info->me4000_regbase + ME4000_IRQ_STATUS_REG; + info->ai_context.sample_counter_reg = + info->me4000_regbase + ME4000_AI_SAMPLE_COUNTER_REG; -static int init_ai_context(comedi_device *dev){ - - CALL_PDEBUG("In init_ai_context()\n"); - - info->ai_context.irq = info->irq; - - info->ai_context.ctrl_reg = info->me4000_regbase + ME4000_AI_CTRL_REG; - info->ai_context.status_reg = info->me4000_regbase + ME4000_AI_STATUS_REG; - info->ai_context.channel_list_reg = info->me4000_regbase + ME4000_AI_CHANNEL_LIST_REG; - info->ai_context.data_reg = info->me4000_regbase + ME4000_AI_DATA_REG; - info->ai_context.chan_timer_reg = info->me4000_regbase + ME4000_AI_CHAN_TIMER_REG; - info->ai_context.chan_pre_timer_reg = info->me4000_regbase + ME4000_AI_CHAN_PRE_TIMER_REG; - info->ai_context.scan_timer_low_reg = info->me4000_regbase + ME4000_AI_SCAN_TIMER_LOW_REG; - info->ai_context.scan_timer_high_reg = info->me4000_regbase + ME4000_AI_SCAN_TIMER_HIGH_REG; - info->ai_context.scan_pre_timer_low_reg = info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_LOW_REG; - info->ai_context.scan_pre_timer_high_reg = info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_HIGH_REG; - info->ai_context.start_reg = info->me4000_regbase + ME4000_AI_START_REG; - info->ai_context.irq_status_reg = info->me4000_regbase + ME4000_IRQ_STATUS_REG; - info->ai_context.sample_counter_reg = info->me4000_regbase + ME4000_AI_SAMPLE_COUNTER_REG; - - return 0; + return 0; } +static int init_dio_context(comedi_device * dev) +{ + CALL_PDEBUG("In init_dio_context()\n"); -static int init_dio_context(comedi_device *dev){ - - CALL_PDEBUG("In init_dio_context()\n"); - - info->dio_context.dir_reg = info->me4000_regbase + ME4000_DIO_DIR_REG; - info->dio_context.ctrl_reg = info->me4000_regbase + ME4000_DIO_CTRL_REG; - info->dio_context.port_0_reg = info->me4000_regbase + ME4000_DIO_PORT_0_REG; - info->dio_context.port_1_reg = info->me4000_regbase + ME4000_DIO_PORT_1_REG; - info->dio_context.port_2_reg = info->me4000_regbase + ME4000_DIO_PORT_2_REG; - info->dio_context.port_3_reg = info->me4000_regbase + ME4000_DIO_PORT_3_REG; + info->dio_context.dir_reg = info->me4000_regbase + ME4000_DIO_DIR_REG; + info->dio_context.ctrl_reg = info->me4000_regbase + ME4000_DIO_CTRL_REG; + info->dio_context.port_0_reg = + info->me4000_regbase + ME4000_DIO_PORT_0_REG; + info->dio_context.port_1_reg = + info->me4000_regbase + ME4000_DIO_PORT_1_REG; + info->dio_context.port_2_reg = + info->me4000_regbase + ME4000_DIO_PORT_2_REG; + info->dio_context.port_3_reg = + info->me4000_regbase + ME4000_DIO_PORT_3_REG; - return 0; + return 0; } +static int init_cnt_context(comedi_device * dev) +{ + CALL_PDEBUG("In init_cnt_context()\n"); -static int init_cnt_context(comedi_device *dev){ - - CALL_PDEBUG("In init_cnt_context()\n"); - - info->cnt_context.ctrl_reg = info->timer_regbase + ME4000_CNT_CTRL_REG; - info->cnt_context.counter_0_reg = info->timer_regbase + ME4000_CNT_COUNTER_0_REG; - info->cnt_context.counter_1_reg = info->timer_regbase + ME4000_CNT_COUNTER_1_REG; - info->cnt_context.counter_2_reg = info->timer_regbase + ME4000_CNT_COUNTER_2_REG; + info->cnt_context.ctrl_reg = info->timer_regbase + ME4000_CNT_CTRL_REG; + info->cnt_context.counter_0_reg = + info->timer_regbase + ME4000_CNT_COUNTER_0_REG; + info->cnt_context.counter_1_reg = + info->timer_regbase + ME4000_CNT_COUNTER_1_REG; + info->cnt_context.counter_2_reg = + info->timer_regbase + ME4000_CNT_COUNTER_2_REG; - return 0; + return 0; } #define FIRMWARE_NOT_AVAILABLE 1 @@ -706,147 +733,154 @@ static int init_cnt_context(comedi_device *dev){ extern unsigned char *xilinx_firm; #endif -static int xilinx_download(comedi_device *dev){ - u32 value = 0; - wait_queue_head_t queue; - int idx = 0; - int size = 0; - - CALL_PDEBUG("In xilinx_download()\n"); - - init_waitqueue_head(&queue); - - /* - * Set PLX local interrupt 2 polarity to high. - * Interrupt is thrown by init pin of xilinx. - */ - outl(0x10, info->plx_regbase + PLX_INTCSR); - - /* Set /CS and /WRITE of the Xilinx */ - value = inl(info->plx_regbase + PLX_ICR); - value |= 0x100; - outl(value, info->plx_regbase + PLX_ICR); - - /* Init Xilinx with CS1 */ - inb(info->program_regbase + 0xC8); - - /* Wait until /INIT pin is set */ - udelay(20); - if(! inl(info->plx_regbase + PLX_INTCSR) & 0x20){ - printk(KERN_ERR"comedi%d: me4000: xilinx_download(): Can't init Xilinx\n", dev->minor); - return -EIO; - } - - /* Reset /CS and /WRITE of the Xilinx */ - value = inl(info->plx_regbase + PLX_ICR); - value &= ~0x100; - outl(value, info->plx_regbase + PLX_ICR); - if(FIRMWARE_NOT_AVAILABLE){ - comedi_error(dev, "xilinx firmware unavailable due to licensing, aborting"); - return -EIO; - } - else{ - /* Download Xilinx firmware */ - size = (xilinx_firm[0] << 24) + (xilinx_firm[1] << 16) + (xilinx_firm[2] << 8) + xilinx_firm[3]; - udelay(10); - - for(idx = 0; idx < size; idx++){ - outb(xilinx_firm[16+idx], info->program_regbase); - udelay(10); +static int xilinx_download(comedi_device * dev) +{ + u32 value = 0; + wait_queue_head_t queue; + int idx = 0; + int size = 0; + + CALL_PDEBUG("In xilinx_download()\n"); + + init_waitqueue_head(&queue); + + /* + * Set PLX local interrupt 2 polarity to high. + * Interrupt is thrown by init pin of xilinx. + */ + outl(0x10, info->plx_regbase + PLX_INTCSR); + + /* Set /CS and /WRITE of the Xilinx */ + value = inl(info->plx_regbase + PLX_ICR); + value |= 0x100; + outl(value, info->plx_regbase + PLX_ICR); + + /* Init Xilinx with CS1 */ + inb(info->program_regbase + 0xC8); + + /* Wait until /INIT pin is set */ + udelay(20); + if (!inl(info->plx_regbase + PLX_INTCSR) & 0x20) { + printk(KERN_ERR + "comedi%d: me4000: xilinx_download(): Can't init Xilinx\n", + dev->minor); + return -EIO; + } - /* Check if BUSY flag is low */ - if(inl(info->plx_regbase + PLX_ICR) & 0x20){ - printk(KERN_ERR"comedi%d: me4000: xilinx_download(): Xilinx is still busy (idx = %d)\n", dev->minor, idx); + /* Reset /CS and /WRITE of the Xilinx */ + value = inl(info->plx_regbase + PLX_ICR); + value &= ~0x100; + outl(value, info->plx_regbase + PLX_ICR); + if (FIRMWARE_NOT_AVAILABLE) { + comedi_error(dev, + "xilinx firmware unavailable due to licensing, aborting"); return -EIO; - } + } else { + /* Download Xilinx firmware */ + size = (xilinx_firm[0] << 24) + (xilinx_firm[1] << 16) + + (xilinx_firm[2] << 8) + xilinx_firm[3]; + udelay(10); + + for (idx = 0; idx < size; idx++) { + outb(xilinx_firm[16 + idx], info->program_regbase); + udelay(10); + + /* Check if BUSY flag is low */ + if (inl(info->plx_regbase + PLX_ICR) & 0x20) { + printk(KERN_ERR + "comedi%d: me4000: xilinx_download(): Xilinx is still busy (idx = %d)\n", + dev->minor, idx); + return -EIO; + } + } } - } - /* If done flag is high download was successful */ - if (inl(info->plx_regbase + PLX_ICR) & 0x4){ - } - else{ - printk(KERN_ERR"comedi%d: me4000: xilinx_download(): DONE flag is not set\n", dev->minor); - printk(KERN_ERR"comedi%d: me4000: xilinx_download(): Download not succesful\n", dev->minor); - return -EIO; - } + /* If done flag is high download was successful */ + if (inl(info->plx_regbase + PLX_ICR) & 0x4) { + } else { + printk(KERN_ERR + "comedi%d: me4000: xilinx_download(): DONE flag is not set\n", + dev->minor); + printk(KERN_ERR + "comedi%d: me4000: xilinx_download(): Download not succesful\n", + dev->minor); + return -EIO; + } - /* Set /CS and /WRITE */ - value = inl(info->plx_regbase + PLX_ICR); - value |= 0x100; - outl(value, info->plx_regbase + PLX_ICR); + /* Set /CS and /WRITE */ + value = inl(info->plx_regbase + PLX_ICR); + value |= 0x100; + outl(value, info->plx_regbase + PLX_ICR); - return 0; + return 0; } +static int reset_board(comedi_device * dev) +{ + unsigned long icr; + + CALL_PDEBUG("In reset_board()\n"); + + /* Make a hardware reset */ + icr = me4000_inl(dev, info->plx_regbase + PLX_ICR); + icr |= 0x40000000; + me4000_outl(dev, icr, info->plx_regbase + PLX_ICR); + icr &= ~0x40000000; + me4000_outl(dev, icr, info->plx_regbase + PLX_ICR); + + /* 0x8000 to the DACs means an output voltage of 0V */ + me4000_outl(dev, 0x8000, + info->me4000_regbase + ME4000_AO_00_SINGLE_REG); + me4000_outl(dev, 0x8000, + info->me4000_regbase + ME4000_AO_01_SINGLE_REG); + me4000_outl(dev, 0x8000, + info->me4000_regbase + ME4000_AO_02_SINGLE_REG); + me4000_outl(dev, 0x8000, + info->me4000_regbase + ME4000_AO_03_SINGLE_REG); + + /* Set both stop bits in the analog input control register */ + me4000_outl(dev, + ME4000_AI_CTRL_BIT_IMMEDIATE_STOP | ME4000_AI_CTRL_BIT_STOP, + info->me4000_regbase + ME4000_AI_CTRL_REG); + + /* Set both stop bits in the analog output control register */ + me4000_outl(dev, + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, + info->me4000_regbase + ME4000_AO_00_CTRL_REG); + me4000_outl(dev, + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, + info->me4000_regbase + ME4000_AO_01_CTRL_REG); + me4000_outl(dev, + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, + info->me4000_regbase + ME4000_AO_02_CTRL_REG); + me4000_outl(dev, + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, + info->me4000_regbase + ME4000_AO_03_CTRL_REG); + + /* Enable interrupts on the PLX */ + me4000_outl(dev, 0x43, info->plx_regbase + PLX_INTCSR); + + /* Set the adustment register for AO demux */ + me4000_outl(dev, ME4000_AO_DEMUX_ADJUST_VALUE, + info->me4000_regbase + ME4000_AO_DEMUX_ADJUST_REG); + + /* Set digital I/O direction for port 0 to output on isolated versions */ + if (!(me4000_inl(dev, info->me4000_regbase + ME4000_DIO_DIR_REG) & 0x1)) { + me4000_outl(dev, 0x1, + info->me4000_regbase + ME4000_DIO_CTRL_REG); + } - -static int reset_board(comedi_device *dev){ - unsigned long icr; - - CALL_PDEBUG("In reset_board()\n"); - - /* Make a hardware reset */ - icr = me4000_inl(dev, info->plx_regbase + PLX_ICR); - icr |= 0x40000000; - me4000_outl(dev, icr, info->plx_regbase + PLX_ICR); - icr &= ~0x40000000; - me4000_outl(dev, icr, info->plx_regbase + PLX_ICR); - - /* 0x8000 to the DACs means an output voltage of 0V */ - me4000_outl(dev, 0x8000, info->me4000_regbase + ME4000_AO_00_SINGLE_REG); - me4000_outl(dev, 0x8000, info->me4000_regbase + ME4000_AO_01_SINGLE_REG); - me4000_outl(dev, 0x8000, info->me4000_regbase + ME4000_AO_02_SINGLE_REG); - me4000_outl(dev, 0x8000, info->me4000_regbase + ME4000_AO_03_SINGLE_REG); - - /* Set both stop bits in the analog input control register */ - me4000_outl( - dev, - ME4000_AI_CTRL_BIT_IMMEDIATE_STOP | ME4000_AI_CTRL_BIT_STOP, - info->me4000_regbase + ME4000_AI_CTRL_REG); - - /* Set both stop bits in the analog output control register */ - me4000_outl( - dev, - ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, - info->me4000_regbase + ME4000_AO_00_CTRL_REG); - me4000_outl( - dev, - ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, - info->me4000_regbase + ME4000_AO_01_CTRL_REG); - me4000_outl( - dev, - ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, - info->me4000_regbase + ME4000_AO_02_CTRL_REG); - me4000_outl( - dev, - ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP, - info->me4000_regbase + ME4000_AO_03_CTRL_REG); - - /* Enable interrupts on the PLX */ - me4000_outl(dev, 0x43, info->plx_regbase + PLX_INTCSR); - - /* Set the adustment register for AO demux */ - me4000_outl(dev, ME4000_AO_DEMUX_ADJUST_VALUE, info->me4000_regbase + ME4000_AO_DEMUX_ADJUST_REG); - - /* Set digital I/O direction for port 0 to output on isolated versions */ - if(!(me4000_inl(dev, info->me4000_regbase + ME4000_DIO_DIR_REG) & 0x1)){ - me4000_outl(dev, 0x1, info->me4000_regbase + ME4000_DIO_CTRL_REG); - } - - return 0; + return 0; } - - -static int me4000_detach(comedi_device *dev){ +static int me4000_detach(comedi_device * dev) +{ CALL_PDEBUG("In me4000_detach()\n"); - if(info){ - if(info->pci_dev_p) { + if (info) { + if (info->pci_dev_p) { reset_board(dev); - if(info->plx_regbase) - { + if (info->plx_regbase) { comedi_pci_disable(info->pci_dev_p); } pci_dev_put(info->pci_dev_p); @@ -856,475 +890,462 @@ static int me4000_detach(comedi_device *dev){ return 0; } - - /*============================================================================= Analog input section ===========================================================================*/ -static int me4000_ai_insn_read( - comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data){ +static int me4000_ai_insn_read(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data) +{ - int chan = CR_CHAN(insn->chanspec); - int rang = CR_RANGE(insn->chanspec); - int aref = CR_AREF(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); + int rang = CR_RANGE(insn->chanspec); + int aref = CR_AREF(insn->chanspec); - unsigned long entry = 0; - unsigned long tmp; - long lval; + unsigned long entry = 0; + unsigned long tmp; + long lval; - CALL_PDEBUG("In me4000_ai_insn_read()\n"); + CALL_PDEBUG("In me4000_ai_insn_read()\n"); - if(insn->n == 0){ - return 0; - } - else if(insn->n > 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Invalid instruction length %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - switch(rang){ + if (insn->n == 0) { + return 0; + } else if (insn->n > 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Invalid instruction length %d\n", + dev->minor, insn->n); + return -EINVAL; + } + + switch (rang) { case 0: - entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5; - break; + entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5; + break; case 1: - entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10; - break; + entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10; + break; case 2: - entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5; - break; + entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5; + break; case 3: - entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10; - break; + entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Invalid range specified\n", dev->minor); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Invalid range specified\n", + dev->minor); + return -EINVAL; + } - switch(aref){ + switch (aref) { case AREF_GROUND: case AREF_COMMON: - if(chan >= thisboard->ai.count){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Analog input is not available\n", dev->minor); - return -EINVAL; - } - entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED | chan; - break; + if (chan >= thisboard->ai.count) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Analog input is not available\n", + dev->minor); + return -EINVAL; + } + entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED | chan; + break; case AREF_DIFF: - if(rang == 0 || rang == 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Range must be bipolar when aref = diff\n", + if (rang == 0 || rang == 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Range must be bipolar when aref = diff\n", + dev->minor); + return -EINVAL; + } + + if (chan >= thisboard->ai.diff_count) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Analog input is not available\n", + dev->minor); + return -EINVAL; + } + entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL | chan; + break; + default: + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Invalid aref specified\n", dev->minor); return -EINVAL; - } + } - if(chan >= thisboard->ai.diff_count){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Analog input is not available\n", dev->minor); - return -EINVAL; - } - entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL | chan; - break; - default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Invalid aref specified\n", dev->minor); - return -EINVAL; - } - - entry |= ME4000_AI_LIST_LAST_ENTRY; - - /* Clear channel list, data fifo and both stop bits */ - tmp = me4000_inl(dev, info->ai_context.ctrl_reg); - tmp &= ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO | - ME4000_AI_CTRL_BIT_DATA_FIFO | - ME4000_AI_CTRL_BIT_STOP | - ME4000_AI_CTRL_BIT_IMMEDIATE_STOP); - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - - /* Set the acquisition mode to single */ - tmp &= ~(ME4000_AI_CTRL_BIT_MODE_0 | ME4000_AI_CTRL_BIT_MODE_1 | ME4000_AI_CTRL_BIT_MODE_2); - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - - /* Enable channel list and data fifo */ - tmp |= ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_DATA_FIFO; - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - - /* Generate channel list entry */ - me4000_outl(dev, entry, info->ai_context.channel_list_reg); - - /* Set the timer to maximum sample rate */ - me4000_outl(dev, ME4000_AI_MIN_TICKS, info->ai_context.chan_timer_reg); - me4000_outl(dev, ME4000_AI_MIN_TICKS, info->ai_context.chan_pre_timer_reg); - - /* Start conversion by dummy read */ - me4000_inl(dev, info->ai_context.start_reg); - - /* Wait until ready */ - udelay(10); - if(!(me4000_inl(dev, info->ai_context.status_reg) & ME4000_AI_STATUS_BIT_EF_DATA)){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_insn_read(): Value not available after wait\n", dev->minor); - return -EIO; - } - - /* Read value from data fifo */ - lval = me4000_inl(dev, info->ai_context.data_reg) & 0xFFFF; - data[0] = lval ^ 0x8000; - - return 1; -} + entry |= ME4000_AI_LIST_LAST_ENTRY; + + /* Clear channel list, data fifo and both stop bits */ + tmp = me4000_inl(dev, info->ai_context.ctrl_reg); + tmp &= ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO | + ME4000_AI_CTRL_BIT_DATA_FIFO | + ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP); + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); + + /* Set the acquisition mode to single */ + tmp &= ~(ME4000_AI_CTRL_BIT_MODE_0 | ME4000_AI_CTRL_BIT_MODE_1 | + ME4000_AI_CTRL_BIT_MODE_2); + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); + + /* Enable channel list and data fifo */ + tmp |= ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_DATA_FIFO; + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); + + /* Generate channel list entry */ + me4000_outl(dev, entry, info->ai_context.channel_list_reg); + + /* Set the timer to maximum sample rate */ + me4000_outl(dev, ME4000_AI_MIN_TICKS, info->ai_context.chan_timer_reg); + me4000_outl(dev, ME4000_AI_MIN_TICKS, + info->ai_context.chan_pre_timer_reg); + + /* Start conversion by dummy read */ + me4000_inl(dev, info->ai_context.start_reg); + + /* Wait until ready */ + udelay(10); + if (!(me4000_inl(dev, info->ai_context. + status_reg) & ME4000_AI_STATUS_BIT_EF_DATA)) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_insn_read(): Value not available after wait\n", + dev->minor); + return -EIO; + } + /* Read value from data fifo */ + lval = me4000_inl(dev, info->ai_context.data_reg) & 0xFFFF; + data[0] = lval ^ 0x8000; + return 1; +} -static int me4000_ai_cancel(comedi_device *dev, comedi_subdevice *s){ - unsigned long tmp; +static int me4000_ai_cancel(comedi_device * dev, comedi_subdevice * s) +{ + unsigned long tmp; - CALL_PDEBUG("In me4000_ai_cancel()\n"); + CALL_PDEBUG("In me4000_ai_cancel()\n"); - /* Stop any running conversion */ - tmp = me4000_inl(dev, info->ai_context.ctrl_reg); - tmp &= ~(ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP); - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); + /* Stop any running conversion */ + tmp = me4000_inl(dev, info->ai_context.ctrl_reg); + tmp &= ~(ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP); + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - /* Clear the control register */ - me4000_outl(dev, 0x0, info->ai_context.ctrl_reg); + /* Clear the control register */ + me4000_outl(dev, 0x0, info->ai_context.ctrl_reg); - return 0; + return 0; } +static int ai_check_chanlist(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) +{ + int aref; + int i; + CALL_PDEBUG("In ai_check_chanlist()\n"); -static int ai_check_chanlist( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd){ - int aref; - int i; - - CALL_PDEBUG("In ai_check_chanlist()\n"); - - /* Check whether a channel list is available */ - if(!cmd->chanlist_len){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): No channel list available\n", dev->minor); - return -EINVAL; - } - - /* Check the channel list size */ - if(cmd->chanlist_len > ME4000_AI_CHANNEL_LIST_COUNT){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): Channel list is to large\n", dev->minor); - return -EINVAL; - } - - /* Check the pointer */ - if(!cmd->chanlist){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): NULL pointer to channel list\n", dev->minor); - return -EFAULT; - } - - /* Check whether aref is equal for all entries */ - aref = CR_AREF(cmd->chanlist[0]); - for(i = 0; i < cmd->chanlist_len; i++){ - if(CR_AREF(cmd->chanlist[i]) != aref){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): Mode is not equal for all entries\n", dev->minor); - return -EINVAL; - } - } - - /* Check whether channels are available for this ending */ - if(aref == SDF_DIFF){ - for(i = 0; i < cmd->chanlist_len; i++){ - if(CR_CHAN(cmd->chanlist[i]) >= thisboard->ai.diff_count){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): Channel number to high\n", dev->minor); + /* Check whether a channel list is available */ + if (!cmd->chanlist_len) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): No channel list available\n", + dev->minor); return -EINVAL; - } } - } - else{ - for(i = 0; i < cmd->chanlist_len; i++){ - if(CR_CHAN(cmd->chanlist[i]) >= thisboard->ai.count){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): Channel number to high\n", dev->minor); + + /* Check the channel list size */ + if (cmd->chanlist_len > ME4000_AI_CHANNEL_LIST_COUNT) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): Channel list is to large\n", + dev->minor); return -EINVAL; - } } - } - /* Check if bipolar is set for all entries when in differential mode */ - if(aref == SDF_DIFF){ - for(i = 0; i < cmd->chanlist_len; i++){ - if(CR_RANGE(cmd->chanlist[i]) != 1 && - CR_RANGE(cmd->chanlist[i]) != 2){ - printk(KERN_ERR"comedi%d: me4000: ai_check_chanlist(): Bipolar is not selected in differential mode\n", + /* Check the pointer */ + if (!cmd->chanlist) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): NULL pointer to channel list\n", dev->minor); - return -EINVAL; - } + return -EFAULT; } - } - return 0; -} + /* Check whether aref is equal for all entries */ + aref = CR_AREF(cmd->chanlist[0]); + for (i = 0; i < cmd->chanlist_len; i++) { + if (CR_AREF(cmd->chanlist[i]) != aref) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): Mode is not equal for all entries\n", + dev->minor); + return -EINVAL; + } + } + /* Check whether channels are available for this ending */ + if (aref == SDF_DIFF) { + for (i = 0; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) >= + thisboard->ai.diff_count) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): Channel number to high\n", + dev->minor); + return -EINVAL; + } + } + } else { + for (i = 0; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) >= thisboard->ai.count) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): Channel number to high\n", + dev->minor); + return -EINVAL; + } + } + } + /* Check if bipolar is set for all entries when in differential mode */ + if (aref == SDF_DIFF) { + for (i = 0; i < cmd->chanlist_len; i++) { + if (CR_RANGE(cmd->chanlist[i]) != 1 && + CR_RANGE(cmd->chanlist[i]) != 2) { + printk(KERN_ERR + "comedi%d: me4000: ai_check_chanlist(): Bipolar is not selected in differential mode\n", + dev->minor); + return -EINVAL; + } + } + } + + return 0; +} -static int ai_round_cmd_args( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd, +static int ai_round_cmd_args(comedi_device * dev, + comedi_subdevice * s, + comedi_cmd * cmd, unsigned int *init_ticks, - unsigned int *scan_ticks, - unsigned int *chan_ticks){ + unsigned int *scan_ticks, unsigned int *chan_ticks) +{ - int rest; + int rest; - CALL_PDEBUG("In ai_round_cmd_args()\n"); + CALL_PDEBUG("In ai_round_cmd_args()\n"); - *init_ticks = 0; - *scan_ticks = 0; - *chan_ticks = 0; + *init_ticks = 0; + *scan_ticks = 0; + *chan_ticks = 0; - PDEBUG("ai_round_cmd_arg(): start_arg = %d\n", cmd->start_arg); - PDEBUG("ai_round_cmd_arg(): scan_begin_arg = %d\n", cmd->scan_begin_arg); - PDEBUG("ai_round_cmd_arg(): convert_arg = %d\n", cmd->convert_arg); + PDEBUG("ai_round_cmd_arg(): start_arg = %d\n", cmd->start_arg); + PDEBUG("ai_round_cmd_arg(): scan_begin_arg = %d\n", + cmd->scan_begin_arg); + PDEBUG("ai_round_cmd_arg(): convert_arg = %d\n", cmd->convert_arg); - if(cmd->start_arg){ - *init_ticks = (cmd->start_arg * 33) / 1000; - rest = (cmd->start_arg * 33) % 1000; + if (cmd->start_arg) { + *init_ticks = (cmd->start_arg * 33) / 1000; + rest = (cmd->start_arg * 33) % 1000; - if(cmd->flags & TRIG_ROUND_NEAREST){ - if(rest > 33){ - (*init_ticks) ++; - } - } - else if(cmd->flags & TRIG_ROUND_UP){ - if(rest) (*init_ticks) ++; + if (cmd->flags & TRIG_ROUND_NEAREST) { + if (rest > 33) { + (*init_ticks)++; + } + } else if (cmd->flags & TRIG_ROUND_UP) { + if (rest) + (*init_ticks)++; + } } - } - if(cmd->scan_begin_arg){ - *scan_ticks = (cmd->scan_begin_arg * 33) / 1000; - rest = (cmd->scan_begin_arg * 33) % 1000; + if (cmd->scan_begin_arg) { + *scan_ticks = (cmd->scan_begin_arg * 33) / 1000; + rest = (cmd->scan_begin_arg * 33) % 1000; - if(cmd->flags & TRIG_ROUND_NEAREST){ - if(rest > 33){ - (*scan_ticks) ++; - } - } - else if(cmd->flags & TRIG_ROUND_UP){ - if(rest) (*scan_ticks) ++; + if (cmd->flags & TRIG_ROUND_NEAREST) { + if (rest > 33) { + (*scan_ticks)++; + } + } else if (cmd->flags & TRIG_ROUND_UP) { + if (rest) + (*scan_ticks)++; + } } - } - if(cmd->convert_arg){ - *chan_ticks = (cmd->convert_arg * 33) / 1000; - rest = (cmd->convert_arg * 33) % 1000; + if (cmd->convert_arg) { + *chan_ticks = (cmd->convert_arg * 33) / 1000; + rest = (cmd->convert_arg * 33) % 1000; - if(cmd->flags & TRIG_ROUND_NEAREST){ - if(rest > 33){ - (*chan_ticks) ++; - } - } - else if(cmd->flags & TRIG_ROUND_UP){ - if(rest) (*chan_ticks) ++; + if (cmd->flags & TRIG_ROUND_NEAREST) { + if (rest > 33) { + (*chan_ticks)++; + } + } else if (cmd->flags & TRIG_ROUND_UP) { + if (rest) + (*chan_ticks)++; + } } - } - PDEBUG("ai_round_cmd_args(): init_ticks = %d\n", *init_ticks); - PDEBUG("ai_round_cmd_args(): scan_ticks = %d\n", *scan_ticks); - PDEBUG("ai_round_cmd_args(): chan_ticks = %d\n", *chan_ticks); + PDEBUG("ai_round_cmd_args(): init_ticks = %d\n", *init_ticks); + PDEBUG("ai_round_cmd_args(): scan_ticks = %d\n", *scan_ticks); + PDEBUG("ai_round_cmd_args(): chan_ticks = %d\n", *chan_ticks); - return 0; + return 0; } - - -static void ai_write_timer( - comedi_device *dev, +static void ai_write_timer(comedi_device * dev, unsigned int init_ticks, - unsigned int scan_ticks, - unsigned int chan_ticks){ + unsigned int scan_ticks, unsigned int chan_ticks) +{ - CALL_PDEBUG("In ai_write_timer()\n"); + CALL_PDEBUG("In ai_write_timer()\n"); - me4000_outl(dev, init_ticks - 1, info->ai_context.scan_pre_timer_low_reg); - me4000_outl(dev, 0x0, info->ai_context.scan_pre_timer_high_reg); + me4000_outl(dev, init_ticks - 1, + info->ai_context.scan_pre_timer_low_reg); + me4000_outl(dev, 0x0, info->ai_context.scan_pre_timer_high_reg); - if(scan_ticks){ - me4000_outl(dev, scan_ticks - 1, info->ai_context.scan_timer_low_reg); - me4000_outl(dev, 0x0, info->ai_context.scan_timer_high_reg); - } + if (scan_ticks) { + me4000_outl(dev, scan_ticks - 1, + info->ai_context.scan_timer_low_reg); + me4000_outl(dev, 0x0, info->ai_context.scan_timer_high_reg); + } - me4000_outl(dev, chan_ticks - 1, info->ai_context.chan_pre_timer_reg); - me4000_outl(dev, chan_ticks - 1, info->ai_context.chan_timer_reg); + me4000_outl(dev, chan_ticks - 1, info->ai_context.chan_pre_timer_reg); + me4000_outl(dev, chan_ticks - 1, info->ai_context.chan_timer_reg); } - - -static int ai_prepare( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd, +static int ai_prepare(comedi_device * dev, + comedi_subdevice * s, + comedi_cmd * cmd, unsigned int init_ticks, - unsigned int scan_ticks, - unsigned int chan_ticks){ - - unsigned long tmp = 0; - - CALL_PDEBUG("In ai_prepare()\n"); - - /* Write timer arguments */ - ai_write_timer(dev, init_ticks, scan_ticks, chan_ticks); - - /* Reset control register */ - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - - /* Start sources */ - if((cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER) || - (cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER)){ - tmp = - ME4000_AI_CTRL_BIT_MODE_1 | - ME4000_AI_CTRL_BIT_CHANNEL_FIFO | - ME4000_AI_CTRL_BIT_DATA_FIFO; - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_TIMER){ - tmp = - ME4000_AI_CTRL_BIT_MODE_2 | - ME4000_AI_CTRL_BIT_CHANNEL_FIFO | - ME4000_AI_CTRL_BIT_DATA_FIFO; - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_EXT){ - tmp = - ME4000_AI_CTRL_BIT_MODE_0 | - ME4000_AI_CTRL_BIT_MODE_1 | - ME4000_AI_CTRL_BIT_CHANNEL_FIFO | - ME4000_AI_CTRL_BIT_DATA_FIFO; - } - else{ - tmp = - ME4000_AI_CTRL_BIT_MODE_0 | - ME4000_AI_CTRL_BIT_CHANNEL_FIFO | - ME4000_AI_CTRL_BIT_DATA_FIFO; - } - - /* Stop triggers */ - if(cmd->stop_src == TRIG_COUNT){ - me4000_outl(dev, cmd->chanlist_len * cmd->stop_arg, info->ai_context.sample_counter_reg); - tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; - } - else if( cmd->stop_src == TRIG_NONE && - cmd->scan_end_src == TRIG_COUNT){ - me4000_outl(dev, cmd->scan_end_arg, info->ai_context.sample_counter_reg); - tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; - } - else{ - tmp |= ME4000_AI_CTRL_BIT_HF_IRQ; - } - - /* Write the setup to the control register */ - me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - - /* Write the channel list */ - ai_write_chanlist(dev, s, cmd); - - return 0; -} + unsigned int scan_ticks, unsigned int chan_ticks) +{ + unsigned long tmp = 0; + + CALL_PDEBUG("In ai_prepare()\n"); + + /* Write timer arguments */ + ai_write_timer(dev, init_ticks, scan_ticks, chan_ticks); + + /* Reset control register */ + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); + + /* Start sources */ + if ((cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_TIMER && + cmd->convert_src == TRIG_TIMER) || + (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER)) { + tmp = ME4000_AI_CTRL_BIT_MODE_1 | + ME4000_AI_CTRL_BIT_CHANNEL_FIFO | + ME4000_AI_CTRL_BIT_DATA_FIFO; + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_TIMER) { + tmp = ME4000_AI_CTRL_BIT_MODE_2 | + ME4000_AI_CTRL_BIT_CHANNEL_FIFO | + ME4000_AI_CTRL_BIT_DATA_FIFO; + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_EXT) { + tmp = ME4000_AI_CTRL_BIT_MODE_0 | + ME4000_AI_CTRL_BIT_MODE_1 | + ME4000_AI_CTRL_BIT_CHANNEL_FIFO | + ME4000_AI_CTRL_BIT_DATA_FIFO; + } else { + tmp = ME4000_AI_CTRL_BIT_MODE_0 | + ME4000_AI_CTRL_BIT_CHANNEL_FIFO | + ME4000_AI_CTRL_BIT_DATA_FIFO; + } + /* Stop triggers */ + if (cmd->stop_src == TRIG_COUNT) { + me4000_outl(dev, cmd->chanlist_len * cmd->stop_arg, + info->ai_context.sample_counter_reg); + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; + } else if (cmd->stop_src == TRIG_NONE && + cmd->scan_end_src == TRIG_COUNT) { + me4000_outl(dev, cmd->scan_end_arg, + info->ai_context.sample_counter_reg); + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ; + } else { + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ; + } -static int ai_write_chanlist( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd){ - unsigned int entry; - unsigned int chan; - unsigned int rang; - unsigned int aref; - int i; + /* Write the setup to the control register */ + me4000_outl(dev, tmp, info->ai_context.ctrl_reg); - CALL_PDEBUG("In ai_write_chanlist()\n"); + /* Write the channel list */ + ai_write_chanlist(dev, s, cmd); - for(i = 0; i < cmd->chanlist_len; i++){ - chan = CR_CHAN(cmd->chanlist[i]); - rang = CR_RANGE(cmd->chanlist[i]); - aref = CR_AREF(cmd->chanlist[i]); + return 0; +} - entry = chan; +static int ai_write_chanlist(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) +{ + unsigned int entry; + unsigned int chan; + unsigned int rang; + unsigned int aref; + int i; + + CALL_PDEBUG("In ai_write_chanlist()\n"); + + for (i = 0; i < cmd->chanlist_len; i++) { + chan = CR_CHAN(cmd->chanlist[i]); + rang = CR_RANGE(cmd->chanlist[i]); + aref = CR_AREF(cmd->chanlist[i]); + + entry = chan; + + if (rang == 0) { + entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5; + } else if (rang == 1) { + entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10; + } else if (rang == 2) { + entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5; + } else { + entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10; + } - if(rang == 0){ - entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5; - } - else if(rang == 1){ - entry |= ME4000_AI_LIST_RANGE_UNIPOLAR_10; - } - else if(rang == 2){ - entry |= ME4000_AI_LIST_RANGE_BIPOLAR_2_5; - } - else{ - entry |= ME4000_AI_LIST_RANGE_BIPOLAR_10; - } + if (aref == SDF_DIFF) { + entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL; + } else { + entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED; + } - if(aref == SDF_DIFF){ - entry |= ME4000_AI_LIST_INPUT_DIFFERENTIAL; + me4000_outl(dev, entry, info->ai_context.channel_list_reg); } - else{ - entry |= ME4000_AI_LIST_INPUT_SINGLE_ENDED; - } - - me4000_outl(dev, entry, info->ai_context.channel_list_reg); - } - return 0; + return 0; } +static int me4000_ai_do_cmd(comedi_device * dev, comedi_subdevice * s) +{ + int err; + unsigned int init_ticks = 0; + unsigned int scan_ticks = 0; + unsigned int chan_ticks = 0; + comedi_cmd *cmd = &s->async->cmd; + CALL_PDEBUG("In me4000_ai_do_cmd()\n"); -static int me4000_ai_do_cmd(comedi_device *dev, comedi_subdevice *s){ - int err; - unsigned int init_ticks = 0; - unsigned int scan_ticks = 0; - unsigned int chan_ticks = 0; - comedi_cmd *cmd= &s->async->cmd; - - CALL_PDEBUG("In me4000_ai_do_cmd()\n"); - - /* Reset the analog input */ - err = me4000_ai_cancel(dev, s); - if(err) return err; - - /* Round the timer arguments */ - err = ai_round_cmd_args( - dev, - s, - cmd, - &init_ticks, - &scan_ticks, - &chan_ticks); - if(err) return err; - - /* Prepare the AI for acquisition */ - err = ai_prepare( - dev, - s, - cmd, - init_ticks, - scan_ticks, - chan_ticks); - if(err) return err; - - /* Start acquistion by dummy read */ - me4000_inl(dev, info->ai_context.start_reg); - - return 0; -} + /* Reset the analog input */ + err = me4000_ai_cancel(dev, s); + if (err) + return err; + /* Round the timer arguments */ + err = ai_round_cmd_args(dev, + s, cmd, &init_ticks, &scan_ticks, &chan_ticks); + if (err) + return err; + /* Prepare the AI for acquisition */ + err = ai_prepare(dev, s, cmd, init_ticks, scan_ticks, chan_ticks); + if (err) + return err; + + /* Start acquistion by dummy read */ + me4000_inl(dev, info->ai_context.start_reg); + + return 0; +} /* * me4000_ai_do_cmd_test(): @@ -1338,934 +1359,982 @@ static int me4000_ai_do_cmd(comedi_device *dev, comedi_subdevice *s){ * - invalid chanlist * So I tried to adopt this scheme. */ -static int me4000_ai_do_cmd_test( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd){ - - unsigned int init_ticks; - unsigned int chan_ticks; - unsigned int scan_ticks; - int err = 0; - - CALL_PDEBUG("In me4000_ai_do_cmd_test()\n"); - - PDEBUG("me4000_ai_do_cmd_test(): subdev = %d\n", cmd->subdev); - PDEBUG("me4000_ai_do_cmd_test(): flags = %08X\n", cmd->flags); - PDEBUG("me4000_ai_do_cmd_test(): start_src = %08X\n", cmd->start_src); - PDEBUG("me4000_ai_do_cmd_test(): start_arg = %d\n", cmd->start_arg); - PDEBUG("me4000_ai_do_cmd_test(): scan_begin_src = %08X\n", cmd->scan_begin_src); - PDEBUG("me4000_ai_do_cmd_test(): scan_begin_arg = %d\n", cmd->scan_begin_arg); - PDEBUG("me4000_ai_do_cmd_test(): convert_src = %08X\n", cmd->convert_src); - PDEBUG("me4000_ai_do_cmd_test(): convert_arg = %d\n", cmd->convert_arg); - PDEBUG("me4000_ai_do_cmd_test(): scan_end_src = %08X\n", cmd->scan_end_src); - PDEBUG("me4000_ai_do_cmd_test(): scan_end_arg = %d\n", cmd->scan_end_arg); - PDEBUG("me4000_ai_do_cmd_test(): stop_src = %08X\n", cmd->stop_src); - PDEBUG("me4000_ai_do_cmd_test(): stop_arg = %d\n", cmd->stop_arg); - PDEBUG("me4000_ai_do_cmd_test(): chanlist = %d\n", (unsigned int) cmd->chanlist); - PDEBUG("me4000_ai_do_cmd_test(): chanlist_len = %d\n", cmd->chanlist_len); - - /* Only rounding flags are implemented */ - cmd->flags &= TRIG_ROUND_NEAREST | TRIG_ROUND_UP | TRIG_ROUND_DOWN; - - /* Round the timer arguments */ - ai_round_cmd_args( - dev, - s, - cmd, - &init_ticks, - &scan_ticks, - &chan_ticks); - - /* - * Stage 1. Check if the trigger sources are generally valid. - */ - switch(cmd->start_src){ +static int me4000_ai_do_cmd_test(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) +{ + + unsigned int init_ticks; + unsigned int chan_ticks; + unsigned int scan_ticks; + int err = 0; + + CALL_PDEBUG("In me4000_ai_do_cmd_test()\n"); + + PDEBUG("me4000_ai_do_cmd_test(): subdev = %d\n", cmd->subdev); + PDEBUG("me4000_ai_do_cmd_test(): flags = %08X\n", cmd->flags); + PDEBUG("me4000_ai_do_cmd_test(): start_src = %08X\n", + cmd->start_src); + PDEBUG("me4000_ai_do_cmd_test(): start_arg = %d\n", + cmd->start_arg); + PDEBUG("me4000_ai_do_cmd_test(): scan_begin_src = %08X\n", + cmd->scan_begin_src); + PDEBUG("me4000_ai_do_cmd_test(): scan_begin_arg = %d\n", + cmd->scan_begin_arg); + PDEBUG("me4000_ai_do_cmd_test(): convert_src = %08X\n", + cmd->convert_src); + PDEBUG("me4000_ai_do_cmd_test(): convert_arg = %d\n", + cmd->convert_arg); + PDEBUG("me4000_ai_do_cmd_test(): scan_end_src = %08X\n", + cmd->scan_end_src); + PDEBUG("me4000_ai_do_cmd_test(): scan_end_arg = %d\n", + cmd->scan_end_arg); + PDEBUG("me4000_ai_do_cmd_test(): stop_src = %08X\n", + cmd->stop_src); + PDEBUG("me4000_ai_do_cmd_test(): stop_arg = %d\n", cmd->stop_arg); + PDEBUG("me4000_ai_do_cmd_test(): chanlist = %d\n", + (unsigned int)cmd->chanlist); + PDEBUG("me4000_ai_do_cmd_test(): chanlist_len = %d\n", + cmd->chanlist_len); + + /* Only rounding flags are implemented */ + cmd->flags &= TRIG_ROUND_NEAREST | TRIG_ROUND_UP | TRIG_ROUND_DOWN; + + /* Round the timer arguments */ + ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks); + + /* + * Stage 1. Check if the trigger sources are generally valid. + */ + switch (cmd->start_src) { case TRIG_NOW: case TRIG_EXT: - break; + break; case TRIG_ANY: - cmd->start_src &= TRIG_NOW | TRIG_EXT; - err++; - break; + cmd->start_src &= TRIG_NOW | TRIG_EXT; + err++; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start source\n", dev->minor); - cmd->start_src = TRIG_NOW; - err++; - } - switch(cmd->scan_begin_src){ + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start source\n", + dev->minor); + cmd->start_src = TRIG_NOW; + err++; + } + switch (cmd->scan_begin_src) { case TRIG_FOLLOW: case TRIG_TIMER: case TRIG_EXT: - break; + break; case TRIG_ANY: - cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT; - err++; - break; + cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT; + err++; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan begin source\n", dev->minor); - cmd->scan_begin_src = TRIG_FOLLOW; - err++; - } - switch(cmd->convert_src){ + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan begin source\n", + dev->minor); + cmd->scan_begin_src = TRIG_FOLLOW; + err++; + } + switch (cmd->convert_src) { case TRIG_TIMER: case TRIG_EXT: - break; + break; case TRIG_ANY: - cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - err++; - break; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + err++; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert source\n", dev->minor); - cmd->convert_src = TRIG_TIMER; - err++; - } - switch(cmd->scan_end_src){ + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert source\n", + dev->minor); + cmd->convert_src = TRIG_TIMER; + err++; + } + switch (cmd->scan_end_src) { case TRIG_NONE: case TRIG_COUNT: - break; + break; case TRIG_ANY: - cmd->scan_end_src &= TRIG_NONE | TRIG_COUNT; - err++; - break; + cmd->scan_end_src &= TRIG_NONE | TRIG_COUNT; + err++; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end source\n", dev->minor); - cmd->scan_end_src = TRIG_NONE; - err++; - } - switch(cmd->stop_src){ + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end source\n", + dev->minor); + cmd->scan_end_src = TRIG_NONE; + err++; + } + switch (cmd->stop_src) { case TRIG_NONE: case TRIG_COUNT: - break; + break; case TRIG_ANY: - cmd->stop_src &= TRIG_NONE | TRIG_COUNT; - err++; - break; + cmd->stop_src &= TRIG_NONE | TRIG_COUNT; + err++; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop source\n", dev->minor); - cmd->stop_src = TRIG_NONE; - err++; - } - if(err){ - return 1; - } - - /* - * Stage 2. Check for trigger source conflicts. - */ - if( cmd->start_src == TRIG_NOW && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER){ - } - else if(cmd->start_src == TRIG_NOW && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER){ - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER){ - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER){ - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_TIMER){ - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_EXT){ - } - else{ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start trigger combination\n", dev->minor); - cmd->start_src = TRIG_NOW; - cmd->scan_begin_src = TRIG_FOLLOW; - cmd->convert_src = TRIG_TIMER; - err++; - } - - if( cmd->stop_src == TRIG_NONE && - cmd->scan_end_src == TRIG_NONE){ - } - else if( cmd->stop_src == TRIG_COUNT && - cmd->scan_end_src == TRIG_NONE){ - } - else if( cmd->stop_src == TRIG_NONE && - cmd->scan_end_src == TRIG_COUNT){ - } - else if( cmd->stop_src == TRIG_COUNT && - cmd->scan_end_src == TRIG_COUNT){ - } - else{ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop trigger combination\n", dev->minor); - cmd->stop_src = TRIG_NONE; - cmd->scan_end_src = TRIG_NONE; - err++; - } - if(err){ - return 2; - } - - /* - * Stage 3. Check if arguments are generally valid. - */ - if(cmd->chanlist_len < 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): No channel list\n", dev->minor); - cmd->chanlist_len = 1; - err++; - } - if(init_ticks < 66){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Start arg to low\n", dev->minor); - cmd->start_arg = 2000; - err++; - } - if(scan_ticks && scan_ticks < 67){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Scan begin arg to low\n", dev->minor); - cmd->scan_begin_arg = 2031; - err++; - } - if(chan_ticks < 66){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Convert arg to low\n", dev->minor); - cmd->convert_arg = 2000; - err++; - } - if(err){ - return 3; - } - - /* - * Stage 4. Check for argument conflicts. - */ - if( cmd->start_src == TRIG_NOW && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - if(chan_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", dev->minor); - cmd->convert_arg = 2000; // 66 ticks at least - err++; - } - if(scan_ticks <= cmd->chanlist_len * chan_ticks){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", dev->minor); - cmd->scan_end_arg = 2000 * cmd->chanlist_len + 31; // At least one tick more - err++; - } - } - else if(cmd->start_src == TRIG_NOW && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - if(chan_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", dev->minor); - cmd->convert_arg = 2000; // 66 ticks at least - err++; - } - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_TIMER && - cmd->convert_src == TRIG_TIMER){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - if(chan_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", dev->minor); - cmd->convert_arg = 2000; // 66 ticks at least - err++; - } - if(scan_ticks <= cmd->chanlist_len * chan_ticks){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", dev->minor); - cmd->scan_end_arg = 2000 * cmd->chanlist_len + 31; // At least one tick more - err++; - } - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_FOLLOW && - cmd->convert_src == TRIG_TIMER){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - if(chan_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", dev->minor); - cmd->convert_arg = 2000; // 66 ticks at least - err++; - } - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_TIMER){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - if(chan_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", dev->minor); - cmd->convert_arg = 2000; // 66 ticks at least - err++; - } - } - else if(cmd->start_src == TRIG_EXT && - cmd->scan_begin_src == TRIG_EXT && - cmd->convert_src == TRIG_EXT){ - - /* Check timer arguments */ - if(init_ticks < ME4000_AI_MIN_TICKS){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", dev->minor); - cmd->start_arg = 2000; // 66 ticks at least - err++; - } - } - if(cmd->stop_src == TRIG_COUNT){ - if(cmd->stop_arg == 0){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop arg\n", dev->minor); - cmd->stop_arg = 1; - err++; - } - } - if(cmd->scan_end_src == TRIG_COUNT){ - if(cmd->scan_end_arg == 0){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", dev->minor); - cmd->scan_end_arg = 1; - err++; - } - } - if(err){ - return 4; - } - - /* - * Stage 5. Check the channel list. - */ - if(ai_check_chanlist(dev, s, cmd)) - return 5; - - return 0; -} - + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop source\n", + dev->minor); + cmd->stop_src = TRIG_NONE; + err++; + } + if (err) { + return 1; + } + /* + * Stage 2. Check for trigger source conflicts. + */ + if (cmd->start_src == TRIG_NOW && + cmd->scan_begin_src == TRIG_TIMER && + cmd->convert_src == TRIG_TIMER) { + } else if (cmd->start_src == TRIG_NOW && + cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER) { + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_TIMER && + cmd->convert_src == TRIG_TIMER) { + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER) { + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_TIMER) { + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_EXT) { + } else { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start trigger combination\n", + dev->minor); + cmd->start_src = TRIG_NOW; + cmd->scan_begin_src = TRIG_FOLLOW; + cmd->convert_src = TRIG_TIMER; + err++; + } -static irqreturn_t me4000_ai_isr(int irq, void *dev_id PT_REGS_ARG){ - unsigned int tmp; - comedi_device *dev = dev_id; - comedi_subdevice *s = dev->subdevices; - me4000_ai_context_t *ai_context = &info->ai_context; - int i; - int c = 0; - long lval; + if (cmd->stop_src == TRIG_NONE && cmd->scan_end_src == TRIG_NONE) { + } else if (cmd->stop_src == TRIG_COUNT && + cmd->scan_end_src == TRIG_NONE) { + } else if (cmd->stop_src == TRIG_NONE && + cmd->scan_end_src == TRIG_COUNT) { + } else if (cmd->stop_src == TRIG_COUNT && + cmd->scan_end_src == TRIG_COUNT) { + } else { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop trigger combination\n", + dev->minor); + cmd->stop_src = TRIG_NONE; + cmd->scan_end_src = TRIG_NONE; + err++; + } + if (err) { + return 2; + } - ISR_PDEBUG("me4000_ai_isr() is executed\n"); + /* + * Stage 3. Check if arguments are generally valid. + */ + if (cmd->chanlist_len < 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): No channel list\n", + dev->minor); + cmd->chanlist_len = 1; + err++; + } + if (init_ticks < 66) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Start arg to low\n", + dev->minor); + cmd->start_arg = 2000; + err++; + } + if (scan_ticks && scan_ticks < 67) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Scan begin arg to low\n", + dev->minor); + cmd->scan_begin_arg = 2031; + err++; + } + if (chan_ticks < 66) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Convert arg to low\n", + dev->minor); + cmd->convert_arg = 2000; + err++; + } + if (err) { + return 3; + } - if(!dev->attached){ - ISR_PDEBUG("me4000_ai_isr() premature interrupt\n"); - return IRQ_NONE; - } + /* + * Stage 4. Check for argument conflicts. + */ + if (cmd->start_src == TRIG_NOW && + cmd->scan_begin_src == TRIG_TIMER && + cmd->convert_src == TRIG_TIMER) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + if (chan_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", + dev->minor); + cmd->convert_arg = 2000; // 66 ticks at least + err++; + } + if (scan_ticks <= cmd->chanlist_len * chan_ticks) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", + dev->minor); + cmd->scan_end_arg = 2000 * cmd->chanlist_len + 31; // At least one tick more + err++; + } + } else if (cmd->start_src == TRIG_NOW && + cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + if (chan_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", + dev->minor); + cmd->convert_arg = 2000; // 66 ticks at least + err++; + } + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_TIMER && + cmd->convert_src == TRIG_TIMER) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + if (chan_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", + dev->minor); + cmd->convert_arg = 2000; // 66 ticks at least + err++; + } + if (scan_ticks <= cmd->chanlist_len * chan_ticks) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", + dev->minor); + cmd->scan_end_arg = 2000 * cmd->chanlist_len + 31; // At least one tick more + err++; + } + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_FOLLOW && + cmd->convert_src == TRIG_TIMER) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + if (chan_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", + dev->minor); + cmd->convert_arg = 2000; // 66 ticks at least + err++; + } + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_TIMER) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + if (chan_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid convert arg\n", + dev->minor); + cmd->convert_arg = 2000; // 66 ticks at least + err++; + } + } else if (cmd->start_src == TRIG_EXT && + cmd->scan_begin_src == TRIG_EXT && + cmd->convert_src == TRIG_EXT) { + + /* Check timer arguments */ + if (init_ticks < ME4000_AI_MIN_TICKS) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid start arg\n", + dev->minor); + cmd->start_arg = 2000; // 66 ticks at least + err++; + } + } + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg == 0) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid stop arg\n", + dev->minor); + cmd->stop_arg = 1; + err++; + } + } + if (cmd->scan_end_src == TRIG_COUNT) { + if (cmd->scan_end_arg == 0) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_do_cmd_test(): Invalid scan end arg\n", + dev->minor); + cmd->scan_end_arg = 1; + err++; + } + } + if (err) { + return 4; + } - /* Reset all events */ - s->async->events = 0; + /* + * Stage 5. Check the channel list. + */ + if (ai_check_chanlist(dev, s, cmd)) + return 5; - /* Check if irq number is right */ - if(irq != ai_context->irq){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): Incorrect interrupt num: %d\n", dev->minor, irq); - return IRQ_HANDLED; - } + return 0; +} - if(me4000_inl(dev, ai_context->irq_status_reg) & ME4000_IRQ_STATUS_BIT_AI_HF){ - ISR_PDEBUG("me4000_ai_isr(): Fifo half full interrupt occured\n"); +static irqreturn_t me4000_ai_isr(int irq, void *dev_id PT_REGS_ARG) +{ + unsigned int tmp; + comedi_device *dev = dev_id; + comedi_subdevice *s = dev->subdevices; + me4000_ai_context_t *ai_context = &info->ai_context; + int i; + int c = 0; + long lval; + + ISR_PDEBUG("me4000_ai_isr() is executed\n"); + + if (!dev->attached) { + ISR_PDEBUG("me4000_ai_isr() premature interrupt\n"); + return IRQ_NONE; + } - /* Read status register to find out what happened */ - tmp = me4000_inl(dev, ai_context->ctrl_reg); + /* Reset all events */ + s->async->events = 0; - if(!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) && - !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) && - (tmp & ME4000_AI_STATUS_BIT_EF_DATA)){ - ISR_PDEBUG("me4000_ai_isr(): Fifo full\n"); - c = ME4000_AI_FIFO_COUNT; + /* Check if irq number is right */ + if (irq != ai_context->irq) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): Incorrect interrupt num: %d\n", + dev->minor, irq); + return IRQ_HANDLED; + } - /* FIFO overflow, so stop conversion and disable all interrupts */ - tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; - tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ); - me4000_outl(dev, tmp, ai_context->ctrl_reg); + if (me4000_inl(dev, + ai_context-> + irq_status_reg) & ME4000_IRQ_STATUS_BIT_AI_HF) { + ISR_PDEBUG + ("me4000_ai_isr(): Fifo half full interrupt occured\n"); + + /* Read status register to find out what happened */ + tmp = me4000_inl(dev, ai_context->ctrl_reg); + + if (!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) && + !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) && + (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) { + ISR_PDEBUG("me4000_ai_isr(): Fifo full\n"); + c = ME4000_AI_FIFO_COUNT; + + /* FIFO overflow, so stop conversion and disable all interrupts */ + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; + tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | + ME4000_AI_CTRL_BIT_SC_IRQ); + me4000_outl(dev, tmp, ai_context->ctrl_reg); + + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): FIFO overflow\n", + dev->minor); + } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA) + && !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) + && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) { + ISR_PDEBUG("me4000_ai_isr(): Fifo half full\n"); + + s->async->events |= COMEDI_CB_BLOCK; + + c = ME4000_AI_FIFO_COUNT / 2; + } else { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): Can't determine state of fifo\n", + dev->minor); + c = 0; + + /* Undefined state, so stop conversion and disable all interrupts */ + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; + tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | + ME4000_AI_CTRL_BIT_SC_IRQ); + me4000_outl(dev, tmp, ai_context->ctrl_reg); + + s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): Undefined FIFO state\n", + dev->minor); + } - s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + ISR_PDEBUG("me4000_ai_isr(): Try to read %d values\n", c); - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): FIFO overflow\n", dev->minor); - } - else if((tmp & ME4000_AI_STATUS_BIT_FF_DATA) && - !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) && - (tmp & ME4000_AI_STATUS_BIT_EF_DATA)){ - ISR_PDEBUG("me4000_ai_isr(): Fifo half full\n"); + for (i = 0; i < c; i++) { + /* Read value from data fifo */ + lval = inl(ai_context->data_reg) & 0xFFFF; + lval ^= 0x8000; - s->async->events |= COMEDI_CB_BLOCK; + if (!comedi_buf_put(s->async, lval)) { + /* Buffer overflow, so stop conversion and disable all interrupts */ + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; + tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | + ME4000_AI_CTRL_BIT_SC_IRQ); + me4000_outl(dev, tmp, ai_context->ctrl_reg); - c = ME4000_AI_FIFO_COUNT/2; - } - else{ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): Can't determine state of fifo\n", dev->minor); - c = 0; + s->async->events |= COMEDI_CB_OVERFLOW; - /* Undefined state, so stop conversion and disable all interrupts */ - tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; - tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ); - me4000_outl(dev, tmp, ai_context->ctrl_reg); + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): Buffer overflow\n", + dev->minor); - s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + break; + } + } - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): Undefined FIFO state\n", dev->minor); + /* Work is done, so reset the interrupt */ + ISR_PDEBUG("me4000_ai_isr(): Reset fifo half full interrupt\n"); + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ_RESET; + me4000_outl(dev, tmp, ai_context->ctrl_reg); + tmp &= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET; + me4000_outl(dev, tmp, ai_context->ctrl_reg); } - ISR_PDEBUG("me4000_ai_isr(): Try to read %d values\n", c); + if (me4000_inl(dev, + ai_context-> + irq_status_reg) & ME4000_IRQ_STATUS_BIT_SC) { + ISR_PDEBUG + ("me4000_ai_isr(): Sample counter interrupt occured\n"); - for(i = 0; i < c; i++){ - /* Read value from data fifo */ - lval = inl(ai_context->data_reg) & 0xFFFF; - lval ^= 0x8000; + s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOA; - if(!comedi_buf_put(s->async, lval)){ - /* Buffer overflow, so stop conversion and disable all interrupts */ + /* Acquisition is complete, so stop conversion and disable all interrupts */ + tmp = me4000_inl(dev, ai_context->ctrl_reg); tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ); me4000_outl(dev, tmp, ai_context->ctrl_reg); - s->async->events |= COMEDI_CB_OVERFLOW; - - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): Buffer overflow\n", dev->minor); + /* Poll data until fifo empty */ + while (inl(ai_context->ctrl_reg) & ME4000_AI_STATUS_BIT_EF_DATA) { + /* Read value from data fifo */ + lval = inl(ai_context->data_reg) & 0xFFFF; + lval ^= 0x8000; + + if (!comedi_buf_put(s->async, lval)) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ai_isr(): Buffer overflow\n", + dev->minor); + s->async->events |= COMEDI_CB_OVERFLOW; + break; + } + } - break; - } + /* Work is done, so reset the interrupt */ + ISR_PDEBUG + ("me4000_ai_isr(): Reset interrupt from sample counter\n"); + tmp |= ME4000_AI_CTRL_BIT_SC_IRQ_RESET; + me4000_outl(dev, tmp, ai_context->ctrl_reg); + tmp &= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET; + me4000_outl(dev, tmp, ai_context->ctrl_reg); } - /* Work is done, so reset the interrupt */ - ISR_PDEBUG("me4000_ai_isr(): Reset fifo half full interrupt\n"); - tmp |= ME4000_AI_CTRL_BIT_HF_IRQ_RESET; - me4000_outl(dev, tmp, ai_context->ctrl_reg); - tmp &= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET; - me4000_outl(dev, tmp, ai_context->ctrl_reg); - } - - if(me4000_inl(dev, ai_context->irq_status_reg) & ME4000_IRQ_STATUS_BIT_SC){ - ISR_PDEBUG("me4000_ai_isr(): Sample counter interrupt occured\n"); + ISR_PDEBUG("me4000_ai_isr(): Events = 0x%X\n", s->async->events); - s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOA; + if (s->async->events) + comedi_event(dev, s); - /* Acquisition is complete, so stop conversion and disable all interrupts */ - tmp = me4000_inl(dev, ai_context->ctrl_reg); - tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP; - tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ); - me4000_outl(dev, tmp, ai_context->ctrl_reg); + return IRQ_HANDLED; +} - /* Poll data until fifo empty */ - while(inl(ai_context->ctrl_reg) & ME4000_AI_STATUS_BIT_EF_DATA){ - /* Read value from data fifo */ - lval = inl(ai_context->data_reg) & 0xFFFF; - lval ^= 0x8000; +/*============================================================================= + Analog output section + ===========================================================================*/ - if(!comedi_buf_put(s->async, lval)){ - printk(KERN_ERR"comedi%d: me4000: me4000_ai_isr(): Buffer overflow\n", dev->minor); - s->async->events |= COMEDI_CB_OVERFLOW; - break; - } - } +static int me4000_ao_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ - /* Work is done, so reset the interrupt */ - ISR_PDEBUG("me4000_ai_isr(): Reset interrupt from sample counter\n"); - tmp |= ME4000_AI_CTRL_BIT_SC_IRQ_RESET; - me4000_outl(dev, tmp, ai_context->ctrl_reg); - tmp &= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET; - me4000_outl(dev, tmp, ai_context->ctrl_reg); - } + int chan = CR_CHAN(insn->chanspec); + int rang = CR_RANGE(insn->chanspec); + int aref = CR_AREF(insn->chanspec); + unsigned long tmp; - ISR_PDEBUG("me4000_ai_isr(): Events = 0x%X\n", s->async->events); + CALL_PDEBUG("In me4000_ao_insn_write()\n"); - if(s->async->events) - comedi_event(dev, s); + if (insn->n == 0) { + return 0; + } else if (insn->n > 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ao_insn_write(): Invalid instruction length %d\n", + dev->minor, insn->n); + return -EINVAL; + } - return IRQ_HANDLED; -} + if (chan >= thisboard->ao.count) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ao_insn_write(): Invalid channel %d\n", + dev->minor, insn->n); + return -EINVAL; + } + if (rang != 0) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ao_insn_write(): Invalid range %d\n", + dev->minor, insn->n); + return -EINVAL; + } + if (aref != AREF_GROUND && aref != AREF_COMMON) { + printk(KERN_ERR + "comedi%d: me4000: me4000_ao_insn_write(): Invalid aref %d\n", + dev->minor, insn->n); + return -EINVAL; + } -/*============================================================================= - Analog output section - ===========================================================================*/ + /* Stop any running conversion */ + tmp = me4000_inl(dev, info->ao_context[chan].ctrl_reg); + tmp |= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP; + me4000_outl(dev, tmp, info->ao_context[chan].ctrl_reg); -static int me4000_ao_insn_write( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ + /* Clear control register and set to single mode */ + me4000_outl(dev, 0x0, info->ao_context[chan].ctrl_reg); - int chan = CR_CHAN(insn->chanspec); - int rang = CR_RANGE(insn->chanspec); - int aref = CR_AREF(insn->chanspec); - unsigned long tmp; + /* Write data value */ + me4000_outl(dev, data[0], info->ao_context[chan].single_reg); - CALL_PDEBUG("In me4000_ao_insn_write()\n"); + /* Store in the mirror */ + info->ao_context[chan].mirror = data[0]; - if(insn->n == 0){ - return 0; - } - else if(insn->n > 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_ao_insn_write(): Invalid instruction length %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - if(chan >= thisboard->ao.count){ - printk(KERN_ERR"comedi%d: me4000: me4000_ao_insn_write(): Invalid channel %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - if(rang != 0){ - printk(KERN_ERR"comedi%d: me4000: me4000_ao_insn_write(): Invalid range %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - if(aref != AREF_GROUND && aref != AREF_COMMON){ - printk(KERN_ERR"comedi%d: me4000: me4000_ao_insn_write(): Invalid aref %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - /* Stop any running conversion */ - tmp = me4000_inl(dev, info->ao_context[chan].ctrl_reg); - tmp |= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP; - me4000_outl(dev, tmp, info->ao_context[chan].ctrl_reg); - - /* Clear control register and set to single mode */ - me4000_outl(dev, 0x0, info->ao_context[chan].ctrl_reg); - - /* Write data value */ - me4000_outl(dev, data[0], info->ao_context[chan].single_reg); - - /* Store in the mirror */ - info->ao_context[chan].mirror = data[0]; - - return 1; + return 1; } +static int me4000_ao_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + int chan = CR_CHAN(insn->chanspec); + if (insn->n == 0) { + return 0; + } else if (insn->n > 1) { + printk("comedi%d: me4000: me4000_ao_insn_read(): Invalid instruction length\n", dev->minor); + return -EINVAL; + } -static int me4000_ao_insn_read( - comedi_device * dev, - comedi_subdevice * s, - comedi_insn *insn, - lsampl_t *data){ - int chan = CR_CHAN(insn->chanspec); - - if(insn->n == 0){ - return 0; - } - else if(insn->n > 1){ - printk("comedi%d: me4000: me4000_ao_insn_read(): Invalid instruction length\n", dev->minor); - return -EINVAL; - } - - data[0] = info->ao_context[chan].mirror; + data[0] = info->ao_context[chan].mirror; - return 1; + return 1; } - - /*============================================================================= Digital I/O section ===========================================================================*/ -static int me4000_dio_insn_bits( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ +static int me4000_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ - CALL_PDEBUG("In me4000_dio_insn_bits()\n"); + CALL_PDEBUG("In me4000_dio_insn_bits()\n"); - /* Length of data must be 2 (mask and new data, see below) */ - if(insn->n == 0){ - return 0; - } - if(insn->n != 2){ - printk("comedi%d: me4000: me4000_dio_insn_bits(): Invalid instruction length\n", dev->minor); - return -EINVAL; - } - - /* - * The insn data consists of a mask in data[0] and the new data - * in data[1]. The mask defines which bits we are concerning about. - * The new data must be anded with the mask. - * Each channel corresponds to a bit. - */ - if(data[0]){ - /* Check if requested ports are configured for output */ - if((s->io_bits & data[0]) != data[0]) - return -EIO; - - s->state &= ~data[0]; - s->state |= data[0] & data[1]; - - /* Write out the new digital output lines */ - me4000_outl(dev, (s->state >> 0) & 0xFF, info->dio_context.port_0_reg); - me4000_outl(dev, (s->state >> 8) & 0xFF, info->dio_context.port_1_reg); - me4000_outl(dev, (s->state >> 16) & 0xFF, info->dio_context.port_2_reg); - me4000_outl(dev, (s->state >> 24) & 0xFF, info->dio_context.port_3_reg); - } - - /* On return, data[1] contains the value of - the digital input and output lines. */ - data[1] = - ((me4000_inl(dev, info->dio_context.port_0_reg) & 0xFF) << 0) | - ((me4000_inl(dev, info->dio_context.port_1_reg) & 0xFF) << 8) | - ((me4000_inl(dev, info->dio_context.port_2_reg) & 0xFF) << 16) | - ((me4000_inl(dev, info->dio_context.port_3_reg) & 0xFF) << 24); - - return 2; -} + /* Length of data must be 2 (mask and new data, see below) */ + if (insn->n == 0) { + return 0; + } + if (insn->n != 2) { + printk("comedi%d: me4000: me4000_dio_insn_bits(): Invalid instruction length\n", dev->minor); + return -EINVAL; + } + + /* + * The insn data consists of a mask in data[0] and the new data + * in data[1]. The mask defines which bits we are concerning about. + * The new data must be anded with the mask. + * Each channel corresponds to a bit. + */ + if (data[0]) { + /* Check if requested ports are configured for output */ + if ((s->io_bits & data[0]) != data[0]) + return -EIO; + + s->state &= ~data[0]; + s->state |= data[0] & data[1]; + + /* Write out the new digital output lines */ + me4000_outl(dev, (s->state >> 0) & 0xFF, + info->dio_context.port_0_reg); + me4000_outl(dev, (s->state >> 8) & 0xFF, + info->dio_context.port_1_reg); + me4000_outl(dev, (s->state >> 16) & 0xFF, + info->dio_context.port_2_reg); + me4000_outl(dev, (s->state >> 24) & 0xFF, + info->dio_context.port_3_reg); + } + /* On return, data[1] contains the value of + the digital input and output lines. */ + data[1] = + ((me4000_inl(dev, info->dio_context.port_0_reg) & 0xFF) << 0) | + ((me4000_inl(dev, info->dio_context.port_1_reg) & 0xFF) << 8) | + ((me4000_inl(dev, info->dio_context.port_2_reg) & 0xFF) << 16) | + ((me4000_inl(dev, info->dio_context.port_3_reg) & 0xFF) << 24); + return 2; +} -static int me4000_dio_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ +static int me4000_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ unsigned long tmp; int chan = CR_CHAN(insn->chanspec); CALL_PDEBUG("In me4000_dio_insn_config()\n"); - if(data[0] == INSN_CONFIG_DIO_QUERY) - { - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + if (data[0] == INSN_CONFIG_DIO_QUERY) { + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; } - /* - * The input or output configuration of each digital line is - * configured by a special insn_config instruction. chanspec - * contains the channel to be changed, and data[0] contains the - * value COMEDI_INPUT or COMEDI_OUTPUT. - * On the ME-4000 it is only possible to switch port wise (8 bit) - */ - - tmp = me4000_inl(dev, info->dio_context.ctrl_reg); - - if(data[0] == COMEDI_OUTPUT){ - if(chan < 8){ - s->io_bits |= 0xFF; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_0 | ME4000_DIO_CTRL_BIT_MODE_1); - tmp |= ME4000_DIO_CTRL_BIT_MODE_0; - } - else if(chan < 16){ - /* - * Chech for optoisolated ME-4000 version. If one the first - * port is a fixed output port and the second is a fixed input port. - */ - if(!me4000_inl(dev, info->dio_context.dir_reg)) - return -ENODEV; - - s->io_bits |= 0xFF00; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_2 | ME4000_DIO_CTRL_BIT_MODE_3); - tmp |= ME4000_DIO_CTRL_BIT_MODE_2; - } - else if(chan < 24){ - s->io_bits |= 0xFF0000; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_4 | ME4000_DIO_CTRL_BIT_MODE_5); - tmp |= ME4000_DIO_CTRL_BIT_MODE_4; - } - else if(chan < 32){ - s->io_bits |= 0xFF000000; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_6 | ME4000_DIO_CTRL_BIT_MODE_7); - tmp |= ME4000_DIO_CTRL_BIT_MODE_6; - } - else{ - return -EINVAL; - } - } - else{ - if(chan < 8){ - /* - * Chech for optoisolated ME-4000 version. If one the first - * port is a fixed output port and the second is a fixed input port. - */ - if(!me4000_inl(dev, info->dio_context.dir_reg)) - return -ENODEV; - - s->io_bits &= ~0xFF; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_0 | ME4000_DIO_CTRL_BIT_MODE_1); - } - else if(chan < 16){ - s->io_bits &= ~0xFF00; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_2 | ME4000_DIO_CTRL_BIT_MODE_3); - } - else if(chan < 24){ - s->io_bits &= ~0xFF0000; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_4 | ME4000_DIO_CTRL_BIT_MODE_5); - } - else if(chan < 32){ - s->io_bits &= ~0xFF000000; - tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_6 | ME4000_DIO_CTRL_BIT_MODE_7); - } - else{ - return -EINVAL; + /* + * The input or output configuration of each digital line is + * configured by a special insn_config instruction. chanspec + * contains the channel to be changed, and data[0] contains the + * value COMEDI_INPUT or COMEDI_OUTPUT. + * On the ME-4000 it is only possible to switch port wise (8 bit) + */ + + tmp = me4000_inl(dev, info->dio_context.ctrl_reg); + + if (data[0] == COMEDI_OUTPUT) { + if (chan < 8) { + s->io_bits |= 0xFF; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_0 | + ME4000_DIO_CTRL_BIT_MODE_1); + tmp |= ME4000_DIO_CTRL_BIT_MODE_0; + } else if (chan < 16) { + /* + * Chech for optoisolated ME-4000 version. If one the first + * port is a fixed output port and the second is a fixed input port. + */ + if (!me4000_inl(dev, info->dio_context.dir_reg)) + return -ENODEV; + + s->io_bits |= 0xFF00; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_2 | + ME4000_DIO_CTRL_BIT_MODE_3); + tmp |= ME4000_DIO_CTRL_BIT_MODE_2; + } else if (chan < 24) { + s->io_bits |= 0xFF0000; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_4 | + ME4000_DIO_CTRL_BIT_MODE_5); + tmp |= ME4000_DIO_CTRL_BIT_MODE_4; + } else if (chan < 32) { + s->io_bits |= 0xFF000000; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_6 | + ME4000_DIO_CTRL_BIT_MODE_7); + tmp |= ME4000_DIO_CTRL_BIT_MODE_6; + } else { + return -EINVAL; + } + } else { + if (chan < 8) { + /* + * Chech for optoisolated ME-4000 version. If one the first + * port is a fixed output port and the second is a fixed input port. + */ + if (!me4000_inl(dev, info->dio_context.dir_reg)) + return -ENODEV; + + s->io_bits &= ~0xFF; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_0 | + ME4000_DIO_CTRL_BIT_MODE_1); + } else if (chan < 16) { + s->io_bits &= ~0xFF00; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_2 | + ME4000_DIO_CTRL_BIT_MODE_3); + } else if (chan < 24) { + s->io_bits &= ~0xFF0000; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_4 | + ME4000_DIO_CTRL_BIT_MODE_5); + } else if (chan < 32) { + s->io_bits &= ~0xFF000000; + tmp &= ~(ME4000_DIO_CTRL_BIT_MODE_6 | + ME4000_DIO_CTRL_BIT_MODE_7); + } else { + return -EINVAL; + } } - } - me4000_outl(dev, tmp, info->dio_context.ctrl_reg); + me4000_outl(dev, tmp, info->dio_context.ctrl_reg); - return 1; + return 1; } - - /*============================================================================= Counter section ===========================================================================*/ -static int cnt_reset(comedi_device *dev, unsigned int channel){ +static int cnt_reset(comedi_device * dev, unsigned int channel) +{ - CALL_PDEBUG("In cnt_reset()\n"); + CALL_PDEBUG("In cnt_reset()\n"); - switch(channel){ + switch (channel) { case 0: - me4000_outb(dev, 0x30, info->cnt_context.ctrl_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_0_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_0_reg); - break; + me4000_outb(dev, 0x30, info->cnt_context.ctrl_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_0_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_0_reg); + break; case 1: - me4000_outb(dev, 0x70, info->cnt_context.ctrl_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_1_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_1_reg); - break; + me4000_outb(dev, 0x70, info->cnt_context.ctrl_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_1_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_1_reg); + break; case 2: - me4000_outb(dev, 0xB0, info->cnt_context.ctrl_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_2_reg); - me4000_outb(dev, 0x00, info->cnt_context.counter_2_reg); - break; + me4000_outb(dev, 0xB0, info->cnt_context.ctrl_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_2_reg); + me4000_outb(dev, 0x00, info->cnt_context.counter_2_reg); + break; default: - printk(KERN_ERR"comedi%d: me4000: cnt_reset(): Invalid channel\n", dev->minor); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: cnt_reset(): Invalid channel\n", + dev->minor); + return -EINVAL; + } - return 0; + return 0; } +static int cnt_config(comedi_device * dev, unsigned int channel, + unsigned int mode) +{ + int tmp = 0; + CALL_PDEBUG("In cnt_config()\n"); -static int cnt_config(comedi_device *dev, unsigned int channel, unsigned int mode){ - int tmp = 0; - - CALL_PDEBUG("In cnt_config()\n"); - - switch(channel){ + switch (channel) { case 0: - tmp |= ME4000_CNT_COUNTER_0; - break; + tmp |= ME4000_CNT_COUNTER_0; + break; case 1: - tmp |= ME4000_CNT_COUNTER_1; - break; + tmp |= ME4000_CNT_COUNTER_1; + break; case 2: - tmp |= ME4000_CNT_COUNTER_2; - break; + tmp |= ME4000_CNT_COUNTER_2; + break; default: - printk(KERN_ERR"comedi%d: me4000: cnt_config(): Invalid channel\n", dev->minor); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: cnt_config(): Invalid channel\n", + dev->minor); + return -EINVAL; + } - switch(mode){ + switch (mode) { case 0: - tmp |= ME4000_CNT_MODE_0; - break; + tmp |= ME4000_CNT_MODE_0; + break; case 1: - tmp |= ME4000_CNT_MODE_1; - break; + tmp |= ME4000_CNT_MODE_1; + break; case 2: - tmp |= ME4000_CNT_MODE_2; - break; + tmp |= ME4000_CNT_MODE_2; + break; case 3: - tmp |= ME4000_CNT_MODE_3; - break; + tmp |= ME4000_CNT_MODE_3; + break; case 4: - tmp |= ME4000_CNT_MODE_4; - break; + tmp |= ME4000_CNT_MODE_4; + break; case 5: - tmp |= ME4000_CNT_MODE_5; - break; + tmp |= ME4000_CNT_MODE_5; + break; default: - printk(KERN_ERR"comedi%d: me4000: cnt_config(): Invalid counter mode\n", dev->minor); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: cnt_config(): Invalid counter mode\n", + dev->minor); + return -EINVAL; + } - /* Write the control word */ - tmp |= 0x30; - me4000_outb(dev, tmp, info->cnt_context.ctrl_reg); + /* Write the control word */ + tmp |= 0x30; + me4000_outb(dev, tmp, info->cnt_context.ctrl_reg); - return 0; + return 0; } +static int me4000_cnt_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + int err; -static int me4000_cnt_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ - - int err; - - CALL_PDEBUG("In me4000_cnt_insn_config()\n"); + CALL_PDEBUG("In me4000_cnt_insn_config()\n"); - switch(data[0]){ + switch (data[0]) { case GPCT_RESET: - if(insn->n != 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction length%d\n", - dev->minor, insn->n); - return -EINVAL; - } + if (insn->n != 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction length%d\n", + dev->minor, insn->n); + return -EINVAL; + } - err = cnt_reset(dev, insn->chanspec); - if(err) return err; - break; + err = cnt_reset(dev, insn->chanspec); + if (err) + return err; + break; case GPCT_SET_OPERATION: - if(insn->n != 2){ - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction length%d\n", - dev->minor, insn->n); - return -EINVAL; - } + if (insn->n != 2) { + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction length%d\n", + dev->minor, insn->n); + return -EINVAL; + } - err = cnt_config(dev, insn->chanspec, data[1]); - if(err) return err; - break; + err = cnt_config(dev, insn->chanspec, data[1]); + if (err) + return err; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction\n", - dev->minor); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_config(): Invalid instruction\n", + dev->minor); + return -EINVAL; + } - return 2; + return 2; } +static int me4000_cnt_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + unsigned short tmp; -static int me4000_cnt_insn_read( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ - - unsigned short tmp; + CALL_PDEBUG("In me4000_cnt_insn_read()\n"); - CALL_PDEBUG("In me4000_cnt_insn_read()\n"); + if (insn->n == 0) { + return 0; + } + if (insn->n > 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_read(): Invalid instruction length %d\n", + dev->minor, insn->n); + return -EINVAL; + } - if(insn->n == 0){ - return 0; - } - if(insn->n > 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_read(): Invalid instruction length %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - switch(insn->chanspec){ + switch (insn->chanspec) { case 0: - tmp = me4000_inb(dev, info->cnt_context.counter_0_reg); - data[0] = tmp; - tmp = me4000_inb(dev, info->cnt_context.counter_0_reg); - data[0] |= tmp << 8; - break; + tmp = me4000_inb(dev, info->cnt_context.counter_0_reg); + data[0] = tmp; + tmp = me4000_inb(dev, info->cnt_context.counter_0_reg); + data[0] |= tmp << 8; + break; case 1: - tmp = me4000_inb(dev, info->cnt_context.counter_1_reg); - data[0] = tmp; - tmp = me4000_inb(dev, info->cnt_context.counter_1_reg); - data[0] |= tmp << 8; - break; + tmp = me4000_inb(dev, info->cnt_context.counter_1_reg); + data[0] = tmp; + tmp = me4000_inb(dev, info->cnt_context.counter_1_reg); + data[0] |= tmp << 8; + break; case 2: - tmp = me4000_inb(dev, info->cnt_context.counter_2_reg); - data[0] = tmp; - tmp = me4000_inb(dev, info->cnt_context.counter_2_reg); - data[0] |= tmp << 8; - break; + tmp = me4000_inb(dev, info->cnt_context.counter_2_reg); + data[0] = tmp; + tmp = me4000_inb(dev, info->cnt_context.counter_2_reg); + data[0] |= tmp << 8; + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_read(): Invalid channel %d\n", - dev->minor, insn->chanspec); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_read(): Invalid channel %d\n", + dev->minor, insn->chanspec); + return -EINVAL; + } - return 1; + return 1; } +static int me4000_cnt_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + unsigned short tmp; -static int me4000_cnt_insn_write( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data){ - - unsigned short tmp; + CALL_PDEBUG("In me4000_cnt_insn_write()\n"); - CALL_PDEBUG("In me4000_cnt_insn_write()\n"); + if (insn->n == 0) { + return 0; + } else if (insn->n > 1) { + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_write(): Invalid instruction length %d\n", + dev->minor, insn->n); + return -EINVAL; + } - if(insn->n == 0){ - return 0; - } - else if(insn->n > 1){ - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_write(): Invalid instruction length %d\n", - dev->minor, insn->n); - return -EINVAL; - } - - switch(insn->chanspec){ + switch (insn->chanspec) { case 0: - tmp = data[0] & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_0_reg); - tmp = (data[0] >> 8) & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_0_reg); - break; + tmp = data[0] & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_0_reg); + tmp = (data[0] >> 8) & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_0_reg); + break; case 1: - tmp = data[0] & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_1_reg); - tmp = (data[0] >> 8) & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_1_reg); - break; + tmp = data[0] & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_1_reg); + tmp = (data[0] >> 8) & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_1_reg); + break; case 2: - tmp = data[0] & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_2_reg); - tmp = (data[0] >> 8) & 0xFF; - me4000_outb(dev, tmp, info->cnt_context.counter_2_reg); - break; + tmp = data[0] & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_2_reg); + tmp = (data[0] >> 8) & 0xFF; + me4000_outb(dev, tmp, info->cnt_context.counter_2_reg); + break; default: - printk(KERN_ERR"comedi%d: me4000: me4000_cnt_insn_write(): Invalid channel %d\n", - dev->minor, insn->chanspec); - return -EINVAL; - } + printk(KERN_ERR + "comedi%d: me4000: me4000_cnt_insn_write(): Invalid channel %d\n", + dev->minor, insn->chanspec); + return -EINVAL; + } - return 1; + return 1; } - - COMEDI_INITCLEANUP(driver_me4000); diff --git a/comedi/drivers/me4000.h b/comedi/drivers/me4000.h index feeed106..cfb0fc83 100644 --- a/comedi/drivers/me4000.h +++ b/comedi/drivers/me4000.h @@ -24,7 +24,6 @@ #ifndef _ME4000_H_ #define _ME4000_H_ - /*============================================================================= Debug section ===========================================================================*/ @@ -38,112 +37,108 @@ #undef CALL_PDEBUG #define CALL_PDEBUG(fmt, args...) printk(KERN_DEBUG"comedi%d: me4000: " fmt, dev->minor, ##args) #else -# define CALL_PDEBUG(fmt, args...) // no debugging, do nothing +# define CALL_PDEBUG(fmt, args...) // no debugging, do nothing #endif #ifdef ME4000_PORT_DEBUG #undef PORT_PDEBUG #define PORT_PDEBUG(fmt, args...) printk(KERN_DEBUG"comedi%d: me4000: " fmt, dev->minor, ##args) #else -#define PORT_PDEBUG(fmt, args...) // no debugging, do nothing +#define PORT_PDEBUG(fmt, args...) // no debugging, do nothing #endif #ifdef ME4000_ISR_DEBUG #undef ISR_PDEBUG #define ISR_PDEBUG(fmt, args...) printk(KERN_DEBUG"comedi%d: me4000: " fmt, dev->minor, ##args) #else -#define ISR_PDEBUG(fmt, args...) // no debugging, do nothing +#define ISR_PDEBUG(fmt, args...) // no debugging, do nothing #endif #ifdef ME4000_DEBUG #undef PDEBUG #define PDEBUG(fmt, args...) printk(KERN_DEBUG"comedi%d: me4000: " fmt, dev->minor, ##args) #else -#define PDEBUG(fmt, args...) // no debugging, do nothing +#define PDEBUG(fmt, args...) // no debugging, do nothing #endif - /*============================================================================= PCI vendor and device IDs ===========================================================================*/ #define PCI_VENDOR_ID_MEILHAUS 0x1402 +#define PCI_DEVICE_ID_MEILHAUS_ME4650 0x4650 // Low Cost version -#define PCI_DEVICE_ID_MEILHAUS_ME4650 0x4650 // Low Cost version - -#define PCI_DEVICE_ID_MEILHAUS_ME4660 0x4660 // Standard version -#define PCI_DEVICE_ID_MEILHAUS_ME4660I 0x4661 // Isolated version -#define PCI_DEVICE_ID_MEILHAUS_ME4660S 0x4662 // Standard version with Sample and Hold -#define PCI_DEVICE_ID_MEILHAUS_ME4660IS 0x4663 // Isolated version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4660 0x4660 // Standard version +#define PCI_DEVICE_ID_MEILHAUS_ME4660I 0x4661 // Isolated version +#define PCI_DEVICE_ID_MEILHAUS_ME4660S 0x4662 // Standard version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4660IS 0x4663 // Isolated version with Sample and Hold -#define PCI_DEVICE_ID_MEILHAUS_ME4670 0x4670 // Standard version -#define PCI_DEVICE_ID_MEILHAUS_ME4670I 0x4671 // Isolated version -#define PCI_DEVICE_ID_MEILHAUS_ME4670S 0x4672 // Standard version with Sample and Hold -#define PCI_DEVICE_ID_MEILHAUS_ME4670IS 0x4673 // Isolated version with Sample and Hold - -#define PCI_DEVICE_ID_MEILHAUS_ME4680 0x4680 // Standard version -#define PCI_DEVICE_ID_MEILHAUS_ME4680I 0x4681 // Isolated version -#define PCI_DEVICE_ID_MEILHAUS_ME4680S 0x4682 // Standard version with Sample and Hold -#define PCI_DEVICE_ID_MEILHAUS_ME4680IS 0x4683 // Isolated version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4670 0x4670 // Standard version +#define PCI_DEVICE_ID_MEILHAUS_ME4670I 0x4671 // Isolated version +#define PCI_DEVICE_ID_MEILHAUS_ME4670S 0x4672 // Standard version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4670IS 0x4673 // Isolated version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4680 0x4680 // Standard version +#define PCI_DEVICE_ID_MEILHAUS_ME4680I 0x4681 // Isolated version +#define PCI_DEVICE_ID_MEILHAUS_ME4680S 0x4682 // Standard version with Sample and Hold +#define PCI_DEVICE_ID_MEILHAUS_ME4680IS 0x4683 // Isolated version with Sample and Hold /*============================================================================= ME-4000 base register offsets ===========================================================================*/ -#define ME4000_AO_00_CTRL_REG 0x00 // R/W -#define ME4000_AO_00_STATUS_REG 0x04 // R/_ -#define ME4000_AO_00_FIFO_REG 0x08 // _/W -#define ME4000_AO_00_SINGLE_REG 0x0C // R/W -#define ME4000_AO_00_TIMER_REG 0x10 // _/W - -#define ME4000_AO_01_CTRL_REG 0x18 // R/W -#define ME4000_AO_01_STATUS_REG 0x1C // R/_ -#define ME4000_AO_01_FIFO_REG 0x20 // _/W -#define ME4000_AO_01_SINGLE_REG 0x24 // R/W -#define ME4000_AO_01_TIMER_REG 0x28 // _/W - -#define ME4000_AO_02_CTRL_REG 0x30 // R/W -#define ME4000_AO_02_STATUS_REG 0x34 // R/_ -#define ME4000_AO_02_FIFO_REG 0x38 // _/W -#define ME4000_AO_02_SINGLE_REG 0x3C // R/W -#define ME4000_AO_02_TIMER_REG 0x40 // _/W - -#define ME4000_AO_03_CTRL_REG 0x48 // R/W -#define ME4000_AO_03_STATUS_REG 0x4C // R/_ -#define ME4000_AO_03_FIFO_REG 0x50 // _/W -#define ME4000_AO_03_SINGLE_REG 0x54 // R/W -#define ME4000_AO_03_TIMER_REG 0x58 // _/W - -#define ME4000_AI_CTRL_REG 0x74 // _/W -#define ME4000_AI_STATUS_REG 0x74 // R/_ -#define ME4000_AI_CHANNEL_LIST_REG 0x78 // _/W -#define ME4000_AI_DATA_REG 0x7C // R/_ -#define ME4000_AI_CHAN_TIMER_REG 0x80 // _/W -#define ME4000_AI_CHAN_PRE_TIMER_REG 0x84 // _/W -#define ME4000_AI_SCAN_TIMER_LOW_REG 0x88 // _/W -#define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8C // _/W -#define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90 // _/W -#define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94 // _/W -#define ME4000_AI_START_REG 0x98 // R/_ - -#define ME4000_IRQ_STATUS_REG 0x9C // R/_ - -#define ME4000_DIO_PORT_0_REG 0xA0 // R/W -#define ME4000_DIO_PORT_1_REG 0xA4 // R/W -#define ME4000_DIO_PORT_2_REG 0xA8 // R/W -#define ME4000_DIO_PORT_3_REG 0xAC // R/W -#define ME4000_DIO_DIR_REG 0xB0 // R/W - -#define ME4000_AO_LOADSETREG_XX 0xB4 // R/W - -#define ME4000_DIO_CTRL_REG 0xB8 // R/W - -#define ME4000_AO_DEMUX_ADJUST_REG 0xBC // -/W - -#define ME4000_AI_SAMPLE_COUNTER_REG 0xC0 // _/W - +#define ME4000_AO_00_CTRL_REG 0x00 // R/W +#define ME4000_AO_00_STATUS_REG 0x04 // R/_ +#define ME4000_AO_00_FIFO_REG 0x08 // _/W +#define ME4000_AO_00_SINGLE_REG 0x0C // R/W +#define ME4000_AO_00_TIMER_REG 0x10 // _/W + +#define ME4000_AO_01_CTRL_REG 0x18 // R/W +#define ME4000_AO_01_STATUS_REG 0x1C // R/_ +#define ME4000_AO_01_FIFO_REG 0x20 // _/W +#define ME4000_AO_01_SINGLE_REG 0x24 // R/W +#define ME4000_AO_01_TIMER_REG 0x28 // _/W + +#define ME4000_AO_02_CTRL_REG 0x30 // R/W +#define ME4000_AO_02_STATUS_REG 0x34 // R/_ +#define ME4000_AO_02_FIFO_REG 0x38 // _/W +#define ME4000_AO_02_SINGLE_REG 0x3C // R/W +#define ME4000_AO_02_TIMER_REG 0x40 // _/W + +#define ME4000_AO_03_CTRL_REG 0x48 // R/W +#define ME4000_AO_03_STATUS_REG 0x4C // R/_ +#define ME4000_AO_03_FIFO_REG 0x50 // _/W +#define ME4000_AO_03_SINGLE_REG 0x54 // R/W +#define ME4000_AO_03_TIMER_REG 0x58 // _/W + +#define ME4000_AI_CTRL_REG 0x74 // _/W +#define ME4000_AI_STATUS_REG 0x74 // R/_ +#define ME4000_AI_CHANNEL_LIST_REG 0x78 // _/W +#define ME4000_AI_DATA_REG 0x7C // R/_ +#define ME4000_AI_CHAN_TIMER_REG 0x80 // _/W +#define ME4000_AI_CHAN_PRE_TIMER_REG 0x84 // _/W +#define ME4000_AI_SCAN_TIMER_LOW_REG 0x88 // _/W +#define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8C // _/W +#define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90 // _/W +#define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94 // _/W +#define ME4000_AI_START_REG 0x98 // R/_ + +#define ME4000_IRQ_STATUS_REG 0x9C // R/_ + +#define ME4000_DIO_PORT_0_REG 0xA0 // R/W +#define ME4000_DIO_PORT_1_REG 0xA4 // R/W +#define ME4000_DIO_PORT_2_REG 0xA8 // R/W +#define ME4000_DIO_PORT_3_REG 0xAC // R/W +#define ME4000_DIO_DIR_REG 0xB0 // R/W + +#define ME4000_AO_LOADSETREG_XX 0xB4 // R/W + +#define ME4000_DIO_CTRL_REG 0xB8 // R/W + +#define ME4000_AO_DEMUX_ADJUST_REG 0xBC // -/W + +#define ME4000_AI_SAMPLE_COUNTER_REG 0xC0 // _/W /*============================================================================= Value to adjust Demux @@ -151,7 +146,6 @@ #define ME4000_AO_DEMUX_ADJUST_VALUE 0x4C - /*============================================================================= Counter base register offsets ===========================================================================*/ @@ -161,7 +155,6 @@ #define ME4000_CNT_COUNTER_2_REG 0x02 #define ME4000_CNT_CTRL_REG 0x03 - /*============================================================================= PLX base register offsets ===========================================================================*/ @@ -169,20 +162,18 @@ #define PLX_INTCSR 0x4C // Interrupt control and status register #define PLX_ICR 0x50 // Initialization control register - /*============================================================================= Bits for the PLX_ICSR register ===========================================================================*/ -#define PLX_INTCSR_LOCAL_INT1_EN 0x01 // If set, local interrupt 1 is enabled (r/w) -#define PLX_INTCSR_LOCAL_INT1_POL 0x02 // If set, local interrupt 1 polarity is active high (r/w) -#define PLX_INTCSR_LOCAL_INT1_STATE 0x04 // If set, local interrupt 1 is active (r/_) -#define PLX_INTCSR_LOCAL_INT2_EN 0x08 // If set, local interrupt 2 is enabled (r/w) -#define PLX_INTCSR_LOCAL_INT2_POL 0x10 // If set, local interrupt 2 polarity is active high (r/w) -#define PLX_INTCSR_LOCAL_INT2_STATE 0x20 // If set, local interrupt 2 is active (r/_) -#define PLX_INTCSR_PCI_INT_EN 0x40 // If set, PCI interrupt is enabled (r/w) -#define PLX_INTCSR_SOFT_INT 0x80 // If set, a software interrupt is generated (r/w) - +#define PLX_INTCSR_LOCAL_INT1_EN 0x01 // If set, local interrupt 1 is enabled (r/w) +#define PLX_INTCSR_LOCAL_INT1_POL 0x02 // If set, local interrupt 1 polarity is active high (r/w) +#define PLX_INTCSR_LOCAL_INT1_STATE 0x04 // If set, local interrupt 1 is active (r/_) +#define PLX_INTCSR_LOCAL_INT2_EN 0x08 // If set, local interrupt 2 is enabled (r/w) +#define PLX_INTCSR_LOCAL_INT2_POL 0x10 // If set, local interrupt 2 polarity is active high (r/w) +#define PLX_INTCSR_LOCAL_INT2_STATE 0x20 // If set, local interrupt 2 is active (r/_) +#define PLX_INTCSR_PCI_INT_EN 0x40 // If set, PCI interrupt is enabled (r/w) +#define PLX_INTCSR_SOFT_INT 0x80 // If set, a software interrupt is generated (r/w) /*============================================================================= Bits for the PLX_ICR register @@ -198,7 +189,6 @@ #define EEPROM_DELAY 1 - /*============================================================================= Bits for the ME4000_AO_CTRL_REG register ===========================================================================*/ @@ -215,7 +205,6 @@ #define ME4000_AO_CTRL_BIT_ENABLE_IRQ 0x200 #define ME4000_AO_CTRL_BIT_RESET_IRQ 0x400 - /*============================================================================= Bits for the ME4000_AO_STATUS_REG register ===========================================================================*/ @@ -225,7 +214,6 @@ #define ME4000_AO_STATUS_BIT_HF 0x04 #define ME4000_AO_STATUS_BIT_EF 0x08 - /*============================================================================= Bits for the ME4000_AI_CTRL_REG register ===========================================================================*/ @@ -254,7 +242,6 @@ #define ME4000_AI_CTRL_BIT_SC_RELOAD 0x00200000 #define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH 0x80000000 - /*============================================================================= Bits for the ME4000_AI_STATUS_REG register ===========================================================================*/ @@ -268,7 +255,6 @@ #define ME4000_AI_STATUS_BIT_LE 0x10000000 #define ME4000_AI_STATUS_BIT_FSM 0x20000000 - /*============================================================================= Bits for the ME4000_IRQ_STATUS_REG register ===========================================================================*/ @@ -282,7 +268,6 @@ #define ME4000_IRQ_STATUS_BIT_AO_3_HF 0x40 #define ME4000_IRQ_STATUS_BIT_SC 0x80 - /*============================================================================= Bits for the ME4000_DIO_CTRL_REG register ===========================================================================*/ @@ -304,163 +289,149 @@ #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 0x1000 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 0x2000 - /*============================================================================= Information about the hardware capabilities ===========================================================================*/ typedef struct me4000_ao_info { - int count; - int fifo_count; + int count; + int fifo_count; } me4000_ao_info_t; - typedef struct me4000_ai_info { - int count; - int sh_count; - int diff_count; - int ex_trig_analog; + int count; + int sh_count; + int diff_count; + int ex_trig_analog; } me4000_ai_info_t; - typedef struct me4000_dio_info { - int count; + int count; } me4000_dio_info_t; - typedef struct me4000_cnt_info { - int count; + int count; } me4000_cnt_info_t; - typedef struct me4000_board { - const char *name; - unsigned short device_id; - me4000_ao_info_t ao; - me4000_ai_info_t ai; - me4000_dio_info_t dio; - me4000_cnt_info_t cnt; + const char *name; + unsigned short device_id; + me4000_ao_info_t ao; + me4000_ai_info_t ai; + me4000_dio_info_t dio; + me4000_cnt_info_t cnt; } me4000_board_t; - #define thisboard ((const me4000_board_t *)dev->board_ptr) - /*============================================================================= PCI device table. This is used by modprobe to translate PCI IDs to drivers. ===========================================================================*/ static struct pci_device_id me4000_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_MEILHAUS, 0x4650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_MEILHAUS, 0x4650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - { PCI_VENDOR_ID_MEILHAUS, 0x4660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4661, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4662, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_MEILHAUS, 0x4660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4661, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4662, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - { PCI_VENDOR_ID_MEILHAUS, 0x4670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_MEILHAUS, 0x4670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - { PCI_VENDOR_ID_MEILHAUS, 0x4680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4681, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4682, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, 0x4683, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_MEILHAUS, 0x4680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4681, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4682, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_MEILHAUS, 0x4683, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - { 0 } + {0} }; MODULE_DEVICE_TABLE(pci, me4000_pci_table); - /*============================================================================= Global board and subdevice information structures ===========================================================================*/ typedef struct me4000_ao_context { - int irq; + int irq; - unsigned long mirror; // Store the last written value + unsigned long mirror; // Store the last written value - unsigned long ctrl_reg; - unsigned long status_reg; - unsigned long fifo_reg; - unsigned long single_reg; - unsigned long timer_reg; - unsigned long irq_status_reg; - unsigned long preload_reg; + unsigned long ctrl_reg; + unsigned long status_reg; + unsigned long fifo_reg; + unsigned long single_reg; + unsigned long timer_reg; + unsigned long irq_status_reg; + unsigned long preload_reg; } me4000_ao_context_t; - typedef struct me4000_ai_context { - int irq; - - unsigned long ctrl_reg; - unsigned long status_reg; - unsigned long channel_list_reg; - unsigned long data_reg; - unsigned long chan_timer_reg; - unsigned long chan_pre_timer_reg; - unsigned long scan_timer_low_reg; - unsigned long scan_timer_high_reg; - unsigned long scan_pre_timer_low_reg; - unsigned long scan_pre_timer_high_reg; - unsigned long start_reg; - unsigned long irq_status_reg; - unsigned long sample_counter_reg; + int irq; + + unsigned long ctrl_reg; + unsigned long status_reg; + unsigned long channel_list_reg; + unsigned long data_reg; + unsigned long chan_timer_reg; + unsigned long chan_pre_timer_reg; + unsigned long scan_timer_low_reg; + unsigned long scan_timer_high_reg; + unsigned long scan_pre_timer_low_reg; + unsigned long scan_pre_timer_high_reg; + unsigned long start_reg; + unsigned long irq_status_reg; + unsigned long sample_counter_reg; } me4000_ai_context_t; - typedef struct me4000_dio_context { - unsigned long dir_reg; - unsigned long ctrl_reg; - unsigned long port_0_reg; - unsigned long port_1_reg; - unsigned long port_2_reg; - unsigned long port_3_reg; + unsigned long dir_reg; + unsigned long ctrl_reg; + unsigned long port_0_reg; + unsigned long port_1_reg; + unsigned long port_2_reg; + unsigned long port_3_reg; } me4000_dio_context_t; - typedef struct me4000_cnt_context { - unsigned long ctrl_reg; - unsigned long counter_0_reg; - unsigned long counter_1_reg; - unsigned long counter_2_reg; + unsigned long ctrl_reg; + unsigned long counter_0_reg; + unsigned long counter_1_reg; + unsigned long counter_2_reg; } me4000_cnt_context_t; - typedef struct me4000_info { - unsigned long plx_regbase; // PLX configuration space base address - unsigned long me4000_regbase; // Base address of the ME4000 - unsigned long timer_regbase; // Base address of the timer circuit - unsigned long program_regbase; // Base address to set the program pin for the xilinx + unsigned long plx_regbase; // PLX configuration space base address + unsigned long me4000_regbase; // Base address of the ME4000 + unsigned long timer_regbase; // Base address of the timer circuit + unsigned long program_regbase; // Base address to set the program pin for the xilinx - unsigned long plx_regbase_size; // PLX register set space - unsigned long me4000_regbase_size; // ME4000 register set space - unsigned long timer_regbase_size; // Timer circuit register set space - unsigned long program_regbase_size; // Size of program base address of the ME4000 + unsigned long plx_regbase_size; // PLX register set space + unsigned long me4000_regbase_size; // ME4000 register set space + unsigned long timer_regbase_size; // Timer circuit register set space + unsigned long program_regbase_size; // Size of program base address of the ME4000 - unsigned int serial_no; // Serial number of the board - unsigned char hw_revision; // Hardware revision of the board - unsigned short vendor_id; // Meilhaus vendor id - unsigned short device_id; // Device id + unsigned int serial_no; // Serial number of the board + unsigned char hw_revision; // Hardware revision of the board + unsigned short vendor_id; // Meilhaus vendor id + unsigned short device_id; // Device id - struct pci_dev *pci_dev_p; // General PCI information + struct pci_dev *pci_dev_p; // General PCI information - unsigned int irq; // IRQ assigned from the PCI BIOS + unsigned int irq; // IRQ assigned from the PCI BIOS - struct me4000_ai_context ai_context; // Analog input specific context - struct me4000_ao_context ao_context[4]; // Vector with analog output specific context - struct me4000_dio_context dio_context; // Digital I/O specific context - struct me4000_cnt_context cnt_context; // Counter specific context + struct me4000_ai_context ai_context; // Analog input specific context + struct me4000_ao_context ao_context[4]; // Vector with analog output specific context + struct me4000_dio_context dio_context; // Digital I/O specific context + struct me4000_cnt_context cnt_context; // Counter specific context } me4000_info_t; - #define info ((me4000_info_t *)dev->private) - /*----------------------------------------------------------------------------- Defines for analog input ----------------------------------------------------------------------------*/ @@ -469,10 +440,9 @@ typedef struct me4000_info { #define ME4000_AI_FIFO_COUNT 2048 #define ME4000_AI_MIN_TICKS 66 -#define ME4000_AI_MIN_SAMPLE_TIME 2000 // Minimum sample time [ns] +#define ME4000_AI_MIN_SAMPLE_TIME 2000 // Minimum sample time [ns] #define ME4000_AI_BASE_FREQUENCY (unsigned int) 33E6 - /* Channel list defines and masks */ #define ME4000_AI_CHANNEL_LIST_COUNT 1024 @@ -486,7 +456,6 @@ typedef struct me4000_info { #define ME4000_AI_LIST_LAST_ENTRY 0x100 - /*----------------------------------------------------------------------------- Defines for counters ----------------------------------------------------------------------------*/ @@ -495,12 +464,11 @@ typedef struct me4000_info { #define ME4000_CNT_COUNTER_1 0x40 #define ME4000_CNT_COUNTER_2 0x80 -#define ME4000_CNT_MODE_0 0x00 // Change state if zero crossing -#define ME4000_CNT_MODE_1 0x02 // Retriggerable One-Shot -#define ME4000_CNT_MODE_2 0x04 // Asymmetrical divider -#define ME4000_CNT_MODE_3 0x06 // Symmetrical divider -#define ME4000_CNT_MODE_4 0x08 // Counter start by software trigger -#define ME4000_CNT_MODE_5 0x0A // Counter start by hardware trigger - +#define ME4000_CNT_MODE_0 0x00 // Change state if zero crossing +#define ME4000_CNT_MODE_1 0x02 // Retriggerable One-Shot +#define ME4000_CNT_MODE_2 0x04 // Asymmetrical divider +#define ME4000_CNT_MODE_3 0x06 // Symmetrical divider +#define ME4000_CNT_MODE_4 0x08 // Counter start by software trigger +#define ME4000_CNT_MODE_5 0x0A // Counter start by hardware trigger #endif diff --git a/comedi/drivers/me_daq.c b/comedi/drivers/me_daq.c index 82fdd9c8..803c05bf 100644 --- a/comedi/drivers/me_daq.c +++ b/comedi/drivers/me_daq.c @@ -61,10 +61,10 @@ from http://www.comedi.org #define ME2000_DEVICE_ID 0x2000 #define ME2600_DEVICE_ID 0x2600 -#define PLX_INTCSR 0x4C // PLX interrupt status register -#define XILINX_DOWNLOAD_RESET 0x42 // Xilinx registers +#define PLX_INTCSR 0x4C // PLX interrupt status register +#define XILINX_DOWNLOAD_RESET 0x42 // Xilinx registers -#define ME_CONTROL_1 0x0000 // - | W +#define ME_CONTROL_1 0x0000 // - | W #define INTERRUPT_ENABLE (1<<15) #define COUNTER_B_IRQ (1<<12) #define COUNTER_A_IRQ (1<<11) @@ -79,8 +79,8 @@ from http://www.comedi.org #define SOFTWARE_TRIGGERED_ADC (1<<0) #define SCAN_TRIGGERED_ADC (2<<0) #define EXT_TRIGGERED_ADC (3<<0) -#define ME_ADC_START 0x0000 // R | - -#define ME_CONTROL_2 0x0002 // - | W +#define ME_ADC_START 0x0000 // R | - +#define ME_CONTROL_2 0x0002 // - | W #define ENABLE_ADFIFO (1<<10) #define ENABLE_CHANLIST (1<<9) #define ENABLE_PORT_B (1<<7) @@ -89,8 +89,8 @@ from http://www.comedi.org #define ENABLE_COUNTER_A (1<<3) #define ENABLE_DAC (1<<1) #define BUFFERED_DAC (1<<0) -#define ME_DAC_UPDATE 0x0002 // R | - -#define ME_STATUS 0x0004 // R | - +#define ME_DAC_UPDATE 0x0002 // R | - +#define ME_STATUS 0x0004 // R | - #define COUNTER_B_IRQ_PENDING (1<<12) #define COUNTER_A_IRQ_PENDING (1<<11) #define CHANLIST_READY_IRQ_PENDING (1<<10) @@ -101,20 +101,20 @@ from http://www.comedi.org #define ADFIFO_EMPTY (1<<2) #define CHANLIST_FULL (1<<1) #define FST_ACTIVE (1<<0) -#define ME_RESET_INTERRUPT 0x0004 // - | W -#define ME_DIO_PORT_A 0x0006 // R | W -#define ME_DIO_PORT_B 0x0008 // R | W -#define ME_TIMER_DATA_0 0x000A // - | W -#define ME_TIMER_DATA_1 0x000C // - | W -#define ME_TIMER_DATA_2 0x000E // - | W -#define ME_CHANNEL_LIST 0x0010 // - | W +#define ME_RESET_INTERRUPT 0x0004 // - | W +#define ME_DIO_PORT_A 0x0006 // R | W +#define ME_DIO_PORT_B 0x0008 // R | W +#define ME_TIMER_DATA_0 0x000A // - | W +#define ME_TIMER_DATA_1 0x000C // - | W +#define ME_TIMER_DATA_2 0x000E // - | W +#define ME_CHANNEL_LIST 0x0010 // - | W #define ADC_UNIPOLAR (1<<6) #define ADC_GAIN_0 (0<<4) #define ADC_GAIN_1 (1<<4) #define ADC_GAIN_2 (2<<4) #define ADC_GAIN_3 (3<<4) -#define ME_READ_AD_FIFO 0x0010 // R | - -#define ME_DAC_CONTROL 0x0012 // - | W +#define ME_READ_AD_FIFO 0x0010 // R | - +#define ME_DAC_CONTROL 0x0012 // - | W #define DAC_UNIPOLAR_D (0<<4) #define DAC_BIPOLAR_D (1<<4) #define DAC_UNIPOLAR_C (0<<5) @@ -131,152 +131,150 @@ from http://www.comedi.org #define DAC_GAIN_1_B (1<<10) #define DAC_GAIN_0_A (0<<11) #define DAC_GAIN_1_A (1<<11) -#define ME_DAC_CONTROL_UPDATE 0x0012 // R | - -#define ME_DAC_DATA_A 0x0014 // - | W -#define ME_DAC_DATA_B 0x0016 // - | W -#define ME_DAC_DATA_C 0x0018 // - | W -#define ME_DAC_DATA_D 0x001A // - | W -#define ME_COUNTER_ENDDATA_A 0x001C // - | W -#define ME_COUNTER_ENDDATA_B 0x001E // - | W -#define ME_COUNTER_STARTDATA_A 0x0020 // - | W -#define ME_COUNTER_VALUE_A 0x0020 // R | - -#define ME_COUNTER_STARTDATA_B 0x0022 // - | W -#define ME_COUNTER_VALUE_B 0x0022 // R | - +#define ME_DAC_CONTROL_UPDATE 0x0012 // R | - +#define ME_DAC_DATA_A 0x0014 // - | W +#define ME_DAC_DATA_B 0x0016 // - | W +#define ME_DAC_DATA_C 0x0018 // - | W +#define ME_DAC_DATA_D 0x001A // - | W +#define ME_COUNTER_ENDDATA_A 0x001C // - | W +#define ME_COUNTER_ENDDATA_B 0x001E // - | W +#define ME_COUNTER_STARTDATA_A 0x0020 // - | W +#define ME_COUNTER_VALUE_A 0x0020 // R | - +#define ME_COUNTER_STARTDATA_B 0x0022 // - | W +#define ME_COUNTER_VALUE_B 0x0022 // R | - // // Function prototypes // -static int me_attach(comedi_device *dev, comedi_devconfig *it); -static int me_detach(comedi_device *dev); +static int me_attach(comedi_device * dev, comedi_devconfig * it); +static int me_detach(comedi_device * dev); -static const comedi_lrange me2000_ai_range= -{ - 8, - { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) - } +static const comedi_lrange me2000_ai_range = { + 8, + { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25) + } }; -static const comedi_lrange me2600_ai_range= -{ - 8, - { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25) - } +static const comedi_lrange me2600_ai_range = { + 8, + { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25) + } }; -static const comedi_lrange me2600_ao_range= -{ - 3, - { - BIP_RANGE(10), - BIP_RANGE(5), - UNI_RANGE(10) - } +static const comedi_lrange me2600_ao_range = { + 3, + { + BIP_RANGE(10), + BIP_RANGE(5), + UNI_RANGE(10) + } }; -static struct pci_device_id me_pci_table[] __devinitdata = -{ - { PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } +static struct pci_device_id me_pci_table[] __devinitdata = { + {PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + 0}, + {PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, me_pci_table); // // Board specification structure // -typedef struct -{ - const char *name; // driver name - int device_id; - int ao_channel_nbr; // DA config - int ao_resolution; - int ao_resolution_mask; - const comedi_lrange *ao_range_list; - int ai_channel_nbr; // AD config - int ai_resolution; - int ai_resolution_mask; - const comedi_lrange *ai_range_list; - int dio_channel_nbr; // DIO config +typedef struct { + const char *name; // driver name + int device_id; + int ao_channel_nbr; // DA config + int ao_resolution; + int ao_resolution_mask; + const comedi_lrange *ao_range_list; + int ai_channel_nbr; // AD config + int ai_resolution; + int ai_resolution_mask; + const comedi_lrange *ai_range_list; + int dio_channel_nbr; // DIO config } me_board_struct; -static const me_board_struct me_boards[] = -{ - { // -- ME-2600i -- - name: ME_DRIVER_NAME, - device_id: ME2600_DEVICE_ID, - ao_channel_nbr: 4, // Analog Output - ao_resolution: 12, - ao_resolution_mask: 0x0fff, - ao_range_list: &me2600_ao_range, - ai_channel_nbr: 16, // Analog Input - ai_resolution: 12, - ai_resolution_mask: 0x0fff, - ai_range_list: &me2600_ai_range, - dio_channel_nbr: 32, - }, - { // -- ME-2000i -- - name: ME_DRIVER_NAME, - device_id: ME2000_DEVICE_ID, - ao_channel_nbr: 0, // Analog Output - ao_resolution: 0, - ao_resolution_mask: 0, - ao_range_list: 0, - ai_channel_nbr: 16, // Analog Input - ai_resolution: 12, - ai_resolution_mask: 0x0fff, - ai_range_list: &me2000_ai_range, - dio_channel_nbr: 32, - } +static const me_board_struct me_boards[] = { + { // -- ME-2600i -- + name: ME_DRIVER_NAME, + device_id:ME2600_DEVICE_ID, + ao_channel_nbr:4,// Analog Output + ao_resolution:12, + ao_resolution_mask:0x0fff, + ao_range_list:&me2600_ao_range, + ai_channel_nbr:16, + // Analog Input + ai_resolution:12, + ai_resolution_mask:0x0fff, + ai_range_list:&me2600_ai_range, + dio_channel_nbr:32, + }, + { // -- ME-2000i -- + name: ME_DRIVER_NAME, + device_id:ME2000_DEVICE_ID, + ao_channel_nbr:0,// Analog Output + ao_resolution:0, + ao_resolution_mask:0, + ao_range_list:0, + ai_channel_nbr:16, + // Analog Input + ai_resolution:12, + ai_resolution_mask:0x0fff, + ai_range_list:&me2000_ai_range, + dio_channel_nbr:32, + } }; #define me_board_nbr (sizeof(me_boards)/sizeof(me_board_struct)) -static comedi_driver me_driver= -{ - driver_name: ME_DRIVER_NAME, - module: THIS_MODULE, - attach: me_attach, - detach: me_detach, - num_names: me_board_nbr, - board_name: &me_boards[0].name, - offset: sizeof(me_board_struct), +static comedi_driver me_driver = { + driver_name:ME_DRIVER_NAME, + module:THIS_MODULE, + attach:me_attach, + detach:me_detach, + num_names:me_board_nbr, + board_name:&me_boards[0].name, + offset:sizeof(me_board_struct), }; + COMEDI_INITCLEANUP(me_driver); // // Private data structure // -typedef struct -{ - struct pci_dev* pci_device; - void *plx_regbase; // PLX configuration base address - void *me_regbase; // Base address of the Meilhaus card - unsigned long plx_regbase_size; // Size of PLX configuration space - unsigned long me_regbase_size; // Size of Meilhaus space +typedef struct { + struct pci_dev *pci_device; + void *plx_regbase; // PLX configuration base address + void *me_regbase; // Base address of the Meilhaus card + unsigned long plx_regbase_size; // Size of PLX configuration space + unsigned long me_regbase_size; // Size of Meilhaus space - unsigned short control_1; // Mirror of CONTROL_1 register - unsigned short control_2; // Mirror of CONTROL_2 register - unsigned short dac_control; // Mirror of the DAC_CONTROL register - int ao_readback[4]; // Mirror of analog output data + unsigned short control_1; // Mirror of CONTROL_1 register + unsigned short control_2; // Mirror of CONTROL_2 register + unsigned short dac_control; // Mirror of the DAC_CONTROL register + int ao_readback[4]; // Mirror of analog output data } me_private_data_struct; @@ -290,8 +288,8 @@ typedef struct static __inline__ void sleep(unsigned sec) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(sec*HZ); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(sec * HZ); } // ------------------------------------------------------------------ @@ -300,80 +298,69 @@ static __inline__ void sleep(unsigned sec) // // ------------------------------------------------------------------ -static int me_dio_insn_config(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int me_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int bits; - int mask = 1 << CR_CHAN(insn->chanspec); - - /* calculate port */ - if(mask & 0x0000ffff) /* Port A in use */ - { - bits = 0x0000ffff; - - /* Enable Port A */ - dev_private->control_2 |= ENABLE_PORT_A; - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - } - else /* Port B in use */ - { - bits = 0xffff0000; - - /* Enable Port B */ - dev_private->control_2 |= ENABLE_PORT_B; - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - } - - - if(data[0]) /* Config port as output */ - { - s->io_bits |= bits; - } - else /* Config port as input */ - { - s->io_bits &= ~bits; - } - - return 1; + int bits; + int mask = 1 << CR_CHAN(insn->chanspec); + + /* calculate port */ + if (mask & 0x0000ffff) { /* Port A in use */ + bits = 0x0000ffff; + + /* Enable Port A */ + dev_private->control_2 |= ENABLE_PORT_A; + writew(dev_private->control_2, + dev_private->me_regbase + ME_CONTROL_2); + } else { /* Port B in use */ + + bits = 0xffff0000; + + /* Enable Port B */ + dev_private->control_2 |= ENABLE_PORT_B; + writew(dev_private->control_2, + dev_private->me_regbase + ME_CONTROL_2); + } + + if (data[0]) { /* Config port as output */ + s->io_bits |= bits; + } else { /* Config port as input */ + + s->io_bits &= ~bits; + } + + return 1; } // // Digital instant input/outputs // -static int me_dio_insn_bits(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int me_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - unsigned int mask = data[0]; - s->state &= ~mask; - s->state |= (mask & data[1]); - - mask &= s->io_bits; - if(mask & 0x0000ffff) /* Port A */ - { - writew((s->state & 0xffff), dev_private->me_regbase + ME_DIO_PORT_A); - } - else - { - data[1] &= ~0x0000ffff; - data[1] |= readw(dev_private->me_regbase + ME_DIO_PORT_A); - } - - if(mask & 0xffff0000) /* Port B */ - { - writew(((s->state >> 16) & 0xffff), dev_private->me_regbase + ME_DIO_PORT_B); - } - else - { - data[1] &= ~0xffff0000; - data[1] |= readw(dev_private->me_regbase + ME_DIO_PORT_B) << 16; - } - - return 2; + unsigned int mask = data[0]; + s->state &= ~mask; + s->state |= (mask & data[1]); + + mask &= s->io_bits; + if (mask & 0x0000ffff) { /* Port A */ + writew((s->state & 0xffff), + dev_private->me_regbase + ME_DIO_PORT_A); + } else { + data[1] &= ~0x0000ffff; + data[1] |= readw(dev_private->me_regbase + ME_DIO_PORT_A); + } + + if (mask & 0xffff0000) { /* Port B */ + writew(((s->state >> 16) & 0xffff), + dev_private->me_regbase + ME_DIO_PORT_B); + } else { + data[1] &= ~0xffff0000; + data[1] |= readw(dev_private->me_regbase + ME_DIO_PORT_B) << 16; + } + + return 2; } // ------------------------------------------------------------------ @@ -385,73 +372,67 @@ static int me_dio_insn_bits(comedi_device *dev, // // Analog instant input // -static int me_ai_insn_read(comedi_device *dev, - comedi_subdevice *subdevice, - comedi_insn *insn, - lsampl_t *data) +static int me_ai_insn_read(comedi_device * dev, + comedi_subdevice * subdevice, comedi_insn * insn, lsampl_t * data) { - unsigned short value; - int chan = CR_CHAN((&insn->chanspec)[0]); - int rang = CR_RANGE((&insn->chanspec)[0]); - int aref = CR_AREF((&insn->chanspec)[0]); - int i; - - /* stop any running conversion */ - dev_private->control_1 &= 0xFFFC; - writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); - - /* clear chanlist and ad fifo */ - dev_private->control_2 &= ~(ENABLE_ADFIFO | ENABLE_CHANLIST); - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - - /* reset any pending interrupt */ - writew(0x00, dev_private->me_regbase + ME_RESET_INTERRUPT); - - /* enable the chanlist and ADC fifo */ - dev_private->control_2 |= (ENABLE_ADFIFO | ENABLE_CHANLIST); - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - - /* write to channel list fifo */ - value = chan & 0x0f; // b3:b0 are the channel number - value |= (rang & 0x03) << 4; // b5:b4 are the channel gain - value |= (rang & 0x04) << 4; // b6 channel polarity - value |= ((aref & AREF_DIFF) ? 0x80 : 0); // b7 single or differential - writew(value & 0xff, dev_private->me_regbase + ME_CHANNEL_LIST); - - /* set ADC mode to software trigger */ - dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC; - writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); - - /* start conversion by reading from ADC_START */ - readw(dev_private->me_regbase + ME_ADC_START); - - /* wait for ADC fifo not empty flag */ - for(i = 100000; i > 0; i--) - { - if(!(readw(dev_private->me_regbase + ME_STATUS) & 0x0004)) - { - break; - } - } - - /* get value from ADC fifo*/ - if(i) - { - data[0] = (readw(dev_private->me_regbase + ME_READ_AD_FIFO) ^ 0x800) & 0x0FFF; - } - else - { - printk("comedi%d: Cannot get single value\n", dev->minor); - return -EIO; - } - - /* stop any running conversion */ - dev_private->control_1 &= 0xFFFC; - writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); - - return 1; -} + unsigned short value; + int chan = CR_CHAN((&insn->chanspec)[0]); + int rang = CR_RANGE((&insn->chanspec)[0]); + int aref = CR_AREF((&insn->chanspec)[0]); + int i; + + /* stop any running conversion */ + dev_private->control_1 &= 0xFFFC; + writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); + + /* clear chanlist and ad fifo */ + dev_private->control_2 &= ~(ENABLE_ADFIFO | ENABLE_CHANLIST); + writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); + + /* reset any pending interrupt */ + writew(0x00, dev_private->me_regbase + ME_RESET_INTERRUPT); + + /* enable the chanlist and ADC fifo */ + dev_private->control_2 |= (ENABLE_ADFIFO | ENABLE_CHANLIST); + writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); + + /* write to channel list fifo */ + value = chan & 0x0f; // b3:b0 are the channel number + value |= (rang & 0x03) << 4; // b5:b4 are the channel gain + value |= (rang & 0x04) << 4; // b6 channel polarity + value |= ((aref & AREF_DIFF) ? 0x80 : 0); // b7 single or differential + writew(value & 0xff, dev_private->me_regbase + ME_CHANNEL_LIST); + + /* set ADC mode to software trigger */ + dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC; + writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); + + /* start conversion by reading from ADC_START */ + readw(dev_private->me_regbase + ME_ADC_START); + + /* wait for ADC fifo not empty flag */ + for (i = 100000; i > 0; i--) { + if (!(readw(dev_private->me_regbase + ME_STATUS) & 0x0004)) { + break; + } + } + + /* get value from ADC fifo */ + if (i) { + data[0] = + (readw(dev_private->me_regbase + + ME_READ_AD_FIFO) ^ 0x800) & 0x0FFF; + } else { + printk("comedi%d: Cannot get single value\n", dev->minor); + return -EIO; + } + /* stop any running conversion */ + dev_private->control_1 &= 0xFFFC; + writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); + + return 1; +} // ------------------------------------------------------------------ // @@ -462,35 +443,32 @@ static int me_ai_insn_read(comedi_device *dev, // // Cancel analog input autoscan // -static int me_ai_cancel(comedi_device *dev, - comedi_subdevice *s) +static int me_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - /* disable interrupts */ + /* disable interrupts */ - /* stop any running conversion */ - dev_private->control_1 &= 0xFFFC; - writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); + /* stop any running conversion */ + dev_private->control_1 &= 0xFFFC; + writew(dev_private->control_1, dev_private->me_regbase + ME_CONTROL_1); - return 0; + return 0; } // // Test analog input command // -static int me_ai_do_cmd_test(comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +static int me_ai_do_cmd_test(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - return 0; + return 0; } // // Analog input command // -static int me_ai_do_cmd(comedi_device *dev, - comedi_subdevice *subdevice) +static int me_ai_do_cmd(comedi_device * dev, comedi_subdevice * subdevice) { - return 0; + return 0; } // ------------------------------------------------------------------ @@ -502,70 +480,68 @@ static int me_ai_do_cmd(comedi_device *dev, // // Analog instant output // -static int me_ao_insn_write(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int me_ao_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int chan; - int rang; - int i; - - /* Enable all DAC */ - dev_private->control_2 |= ENABLE_DAC; - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - - /* and set DAC to "buffered" mode */ - dev_private->control_2 |= BUFFERED_DAC; - writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); - - /* Set dac-control register */ - for (i=0; i < insn->n; i++) - { - chan = CR_CHAN((&insn->chanspec)[i]); - rang = CR_RANGE((&insn->chanspec)[i]); - - dev_private->dac_control &= ~(0x0880 >> chan); /* clear bits for this channel */ - if (rang == 0) - dev_private->dac_control |= ((DAC_BIPOLAR_A | DAC_GAIN_1_A) >> chan); - else if (rang == 1) - dev_private->dac_control |= ((DAC_BIPOLAR_A | DAC_GAIN_0_A) >> chan); - } - writew(dev_private->dac_control, dev_private->me_regbase + ME_DAC_CONTROL); - - /* Update dac-control register */ - readw(dev_private->me_regbase + ME_DAC_CONTROL_UPDATE); - - /* Set data register */ - for (i=0; i < insn->n; i++) - { - chan = CR_CHAN((&insn->chanspec)[i]); - writew((data[0] & s->maxdata), dev_private->me_regbase + ME_DAC_DATA_A + (chan<<1)); - dev_private->ao_readback[chan] = (data[0] & s->maxdata); - } - - /* Update dac with data registers */ - readw(dev_private->me_regbase + ME_DAC_UPDATE); - - return i; + int chan; + int rang; + int i; + + /* Enable all DAC */ + dev_private->control_2 |= ENABLE_DAC; + writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); + + /* and set DAC to "buffered" mode */ + dev_private->control_2 |= BUFFERED_DAC; + writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); + + /* Set dac-control register */ + for (i = 0; i < insn->n; i++) { + chan = CR_CHAN((&insn->chanspec)[i]); + rang = CR_RANGE((&insn->chanspec)[i]); + + dev_private->dac_control &= ~(0x0880 >> chan); /* clear bits for this channel */ + if (rang == 0) + dev_private->dac_control |= + ((DAC_BIPOLAR_A | DAC_GAIN_1_A) >> chan); + else if (rang == 1) + dev_private->dac_control |= + ((DAC_BIPOLAR_A | DAC_GAIN_0_A) >> chan); + } + writew(dev_private->dac_control, + dev_private->me_regbase + ME_DAC_CONTROL); + + /* Update dac-control register */ + readw(dev_private->me_regbase + ME_DAC_CONTROL_UPDATE); + + /* Set data register */ + for (i = 0; i < insn->n; i++) { + chan = CR_CHAN((&insn->chanspec)[i]); + writew((data[0] & s->maxdata), + dev_private->me_regbase + ME_DAC_DATA_A + (chan << 1)); + dev_private->ao_readback[chan] = (data[0] & s->maxdata); + } + + /* Update dac with data registers */ + readw(dev_private->me_regbase + ME_DAC_UPDATE); + + return i; } // // Analog output readback // static int me_ao_insn_read(comedi_device * dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i; + int i; - for (i=0; i < insn->n; i++) - { - data[i] = dev_private->ao_readback[CR_CHAN((&insn->chanspec)[i])]; - } + for (i = 0; i < insn->n; i++) { + data[i] = + dev_private->ao_readback[CR_CHAN((&insn->chanspec)[i])]; + } - return 1; + return 1; } // ------------------------------------------------------------------ @@ -578,93 +554,92 @@ static int me_ao_insn_read(comedi_device * dev, // Xilinx firmware download for card: ME-2600i // -static int me2600_xilinx_download(comedi_device *dev, unsigned char +static int me2600_xilinx_download(comedi_device * dev, unsigned char *me2600_firmware, unsigned int length) { - unsigned int value; - unsigned int file_length; - unsigned int i; - - /* disable irq's on PLX */ - writel(0x00, dev_private->plx_regbase + PLX_INTCSR); - - /* First, make a dummy read to reset xilinx */ - value = readw(dev_private->me_regbase + XILINX_DOWNLOAD_RESET); - - /* Wait until reset is over */ - sleep(1); - - /* Write a dummy value to Xilinx */ - writeb(0x00, dev_private->me_regbase + 0x0); - sleep(1); - - /* - * Format of the firmware - * Build longs from the byte-wise coded header - * Byte 1-3: length of the array - * Byte 4-7: version - * Byte 8-11: date - * Byte 12-15: reserved - */ - if(length<16)return -EINVAL; - file_length = - (((unsigned int)me2600_firmware[0] & 0xff)<<24) + - (((unsigned int)me2600_firmware[1] & 0xff)<<16) + - (((unsigned int)me2600_firmware[2] & 0xff)<< 8) + - ((unsigned int)me2600_firmware[3] & 0xff); - - /* - * Loop for writing firmware byte by byte to xilinx - * Firmware data start at offfset 16 - */ - for(i = 0; i < file_length; i++) - { - writeb((me2600_firmware[16+i] & 0xff), dev_private->me_regbase + 0x0); - } - - /* Write 5 dummy values to xilinx */ - for(i = 0; i < 5; i++) - { - writeb(0x00, dev_private->me_regbase + 0x0); - } - - /* Test if there was an error during download -> INTB was thrown */ - value = readl(dev_private->plx_regbase + PLX_INTCSR); - if(value & 0x20) - { - /* Disable interrupt */ - writel(0x00, dev_private->plx_regbase + PLX_INTCSR); - printk("comedi%d: Xilinx download failed\n", dev->minor); - return -EIO; - } - - /* Wait until the Xilinx is ready for real work */ - sleep(1); - - /* Enable PLX-Interrupts */ - writel(0x43, dev_private->plx_regbase + PLX_INTCSR); - - return 0; + unsigned int value; + unsigned int file_length; + unsigned int i; + + /* disable irq's on PLX */ + writel(0x00, dev_private->plx_regbase + PLX_INTCSR); + + /* First, make a dummy read to reset xilinx */ + value = readw(dev_private->me_regbase + XILINX_DOWNLOAD_RESET); + + /* Wait until reset is over */ + sleep(1); + + /* Write a dummy value to Xilinx */ + writeb(0x00, dev_private->me_regbase + 0x0); + sleep(1); + + /* + * Format of the firmware + * Build longs from the byte-wise coded header + * Byte 1-3: length of the array + * Byte 4-7: version + * Byte 8-11: date + * Byte 12-15: reserved + */ + if (length < 16) + return -EINVAL; + file_length = + (((unsigned int)me2600_firmware[0] & 0xff) << 24) + + (((unsigned int)me2600_firmware[1] & 0xff) << 16) + + (((unsigned int)me2600_firmware[2] & 0xff) << 8) + + ((unsigned int)me2600_firmware[3] & 0xff); + + /* + * Loop for writing firmware byte by byte to xilinx + * Firmware data start at offfset 16 + */ + for (i = 0; i < file_length; i++) { + writeb((me2600_firmware[16 + i] & 0xff), + dev_private->me_regbase + 0x0); + } + + /* Write 5 dummy values to xilinx */ + for (i = 0; i < 5; i++) { + writeb(0x00, dev_private->me_regbase + 0x0); + } + + /* Test if there was an error during download -> INTB was thrown */ + value = readl(dev_private->plx_regbase + PLX_INTCSR); + if (value & 0x20) { + /* Disable interrupt */ + writel(0x00, dev_private->plx_regbase + PLX_INTCSR); + printk("comedi%d: Xilinx download failed\n", dev->minor); + return -EIO; + } + + /* Wait until the Xilinx is ready for real work */ + sleep(1); + + /* Enable PLX-Interrupts */ + writel(0x43, dev_private->plx_regbase + PLX_INTCSR); + + return 0; } // // Reset device // -static int me_reset(comedi_device *dev) +static int me_reset(comedi_device * dev) { - /* Reset board */ - writew(0x00, dev_private->me_regbase + ME_CONTROL_1); - writew(0x00, dev_private->me_regbase + ME_CONTROL_2); - writew(0x00, dev_private->me_regbase + ME_RESET_INTERRUPT); - writew(0x00, dev_private->me_regbase + ME_DAC_CONTROL); - - /* Save values in the board context */ - dev_private->dac_control = 0; - dev_private->control_1 = 0; - dev_private->control_2 = 0; - - return 0; + /* Reset board */ + writew(0x00, dev_private->me_regbase + ME_CONTROL_1); + writew(0x00, dev_private->me_regbase + ME_CONTROL_2); + writew(0x00, dev_private->me_regbase + ME_RESET_INTERRUPT); + writew(0x00, dev_private->me_regbase + ME_DAC_CONTROL); + + /* Save values in the board context */ + dev_private->dac_control = 0; + dev_private->control_1 = 0; + dev_private->control_2 = 0; + + return 0; } // @@ -674,224 +649,210 @@ static int me_reset(comedi_device *dev) // - Declare device driver capability // -static int me_attach(comedi_device *dev,comedi_devconfig *it) +static int me_attach(comedi_device * dev, comedi_devconfig * it) { - struct pci_dev* pci_device; - comedi_subdevice *subdevice; - me_board_struct* board; - resource_size_t plx_regbase_tmp; - unsigned long plx_regbase_size_tmp; - resource_size_t me_regbase_tmp; - unsigned long me_regbase_size_tmp; - resource_size_t swap_regbase_tmp; - unsigned long swap_regbase_size_tmp; - resource_size_t regbase_tmp; - int result, error, i; - - // Allocate private memory - if(alloc_private(dev,sizeof(me_private_data_struct)) < 0) - { - return -ENOMEM; - } - + struct pci_dev *pci_device; + comedi_subdevice *subdevice; + me_board_struct *board; + resource_size_t plx_regbase_tmp; + unsigned long plx_regbase_size_tmp; + resource_size_t me_regbase_tmp; + unsigned long me_regbase_size_tmp; + resource_size_t swap_regbase_tmp; + unsigned long swap_regbase_size_tmp; + resource_size_t regbase_tmp; + int result, error, i; + + // Allocate private memory + if (alloc_private(dev, sizeof(me_private_data_struct)) < 0) { + return -ENOMEM; + } // // Probe the device to determine what device in the series it is. // - for(pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pci_device != NULL ; - pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) - { - if(pci_device->vendor == PCI_VENDOR_ID_MEILHAUS) - { - for(i = 0; i < me_board_nbr; i++) - { - if(me_boards[i].device_id == pci_device->device) - { - // was a particular bus/slot requested? - if((it->options[0] != 0) || (it->options[1] != 0)) - { - // are we on the wrong bus/slot? - if(pci_device->bus->number != it->options[0] || - PCI_SLOT(pci_device->devfn) != it->options[1]) - { - continue; - } - } - - dev->board_ptr = me_boards + i; - board = (me_board_struct *) dev->board_ptr; - dev_private->pci_device = pci_device; - goto found; - } - } - } - } - - printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", - dev->minor,it->options[0], it->options[1]); - return -EIO; - -found: - - printk("comedi%d: found %s at PCI bus %d, slot %d\n", - dev->minor, me_boards[i].name, - pci_device->bus->number, PCI_SLOT(pci_device->devfn)); - - // Enable PCI device and request PCI regions - if(comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0) - { - printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); - return -EIO; - } - - // Set data in device structure - - dev->board_name = board->name; - - // Read PLX register base address [PCI_BASE_ADDRESS #0]. - - plx_regbase_tmp = pci_resource_start(pci_device, 0); - plx_regbase_size_tmp = pci_resource_len(pci_device, 0); - dev_private->plx_regbase = ioremap(plx_regbase_tmp, plx_regbase_size_tmp); - dev_private->plx_regbase_size = plx_regbase_size_tmp; - if(!dev_private->plx_regbase) - { - printk("comedi%d: Failed to remap I/O memory\n", dev->minor); - return -ENOMEM; - } - - // Read Swap base address [PCI_BASE_ADDRESS #5]. - - swap_regbase_tmp = pci_resource_start(pci_device, 5); - swap_regbase_size_tmp = pci_resource_len(pci_device, 5); - - if(!swap_regbase_tmp) - { - printk("comedi%d: Swap not present\n", dev->minor); - } + for (pci_device = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pci_device != NULL; + pci_device = + pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_device)) { + if (pci_device->vendor == PCI_VENDOR_ID_MEILHAUS) { + for (i = 0; i < me_board_nbr; i++) { + if (me_boards[i].device_id == + pci_device->device) { + // was a particular bus/slot requested? + if ((it->options[0] != 0) + || (it->options[1] != 0)) { + // are we on the wrong bus/slot? + if (pci_device->bus->number != + it->options[0] + || PCI_SLOT(pci_device-> + devfn) != + it->options[1]) { + continue; + } + } + + dev->board_ptr = me_boards + i; + board = (me_board_struct *) dev-> + board_ptr; + dev_private->pci_device = pci_device; + goto found; + } + } + } + } - /*----------------------------------------------------- Workaround start ---*/ - if(plx_regbase_tmp & 0x0080) - { - printk("comedi%d: PLX-Bug detected\n", dev->minor); - - if(swap_regbase_tmp) - { - regbase_tmp = plx_regbase_tmp; - plx_regbase_tmp = swap_regbase_tmp; - swap_regbase_tmp = regbase_tmp; - - result = pci_write_config_dword(pci_device, PCI_BASE_ADDRESS_0, plx_regbase_tmp); - if(result != PCIBIOS_SUCCESSFUL) - return -EIO; - - result = pci_write_config_dword(pci_device, PCI_BASE_ADDRESS_5, swap_regbase_tmp); - if(result != PCIBIOS_SUCCESSFUL) - return -EIO; - } - else - { - plx_regbase_tmp -= 0x80; - result = pci_write_config_dword(pci_device, PCI_BASE_ADDRESS_0, plx_regbase_tmp); - if(result != PCIBIOS_SUCCESSFUL) - return -EIO; - } - } - /*----------------------------------------------------- Workaround end -----*/ + printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", + dev->minor, it->options[0], it->options[1]); + return -EIO; + + found: + + printk("comedi%d: found %s at PCI bus %d, slot %d\n", + dev->minor, me_boards[i].name, + pci_device->bus->number, PCI_SLOT(pci_device->devfn)); + // Enable PCI device and request PCI regions + if (comedi_pci_enable(pci_device, ME_DRIVER_NAME) < 0) { + printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor); + return -EIO; + } + // Set data in device structure - // Read Meilhaus register base address [PCI_BASE_ADDRESS #2]. + dev->board_name = board->name; - me_regbase_tmp = pci_resource_start(pci_device, 2); - me_regbase_size_tmp = pci_resource_len(pci_device, 2); - dev_private->me_regbase_size = me_regbase_size_tmp; - dev_private->me_regbase = ioremap(me_regbase_tmp, me_regbase_size_tmp); - if(!dev_private->me_regbase) - { - printk("comedi%d: Failed to remap I/O memory\n", dev->minor); - return -ENOMEM; - } + // Read PLX register base address [PCI_BASE_ADDRESS #0]. - // Download firmware and reset card - if(board->device_id == ME2600_DEVICE_ID) - { - unsigned char *aux_data; - int aux_len; + plx_regbase_tmp = pci_resource_start(pci_device, 0); + plx_regbase_size_tmp = pci_resource_len(pci_device, 0); + dev_private->plx_regbase = + ioremap(plx_regbase_tmp, plx_regbase_size_tmp); + dev_private->plx_regbase_size = plx_regbase_size_tmp; + if (!dev_private->plx_regbase) { + printk("comedi%d: Failed to remap I/O memory\n", dev->minor); + return -ENOMEM; + } + // Read Swap base address [PCI_BASE_ADDRESS #5]. - aux_data = comedi_aux_data(it->options, 0); - aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + swap_regbase_tmp = pci_resource_start(pci_device, 5); + swap_regbase_size_tmp = pci_resource_len(pci_device, 5); - if(!aux_data || aux_len < 1) - { - comedi_error(dev, "You must provide me2600 firmware using the --init-data option of comedi_config"); + if (!swap_regbase_tmp) { + printk("comedi%d: Swap not present\n", dev->minor); + } + + /*----------------------------------------------------- Workaround start ---*/ + if (plx_regbase_tmp & 0x0080) { + printk("comedi%d: PLX-Bug detected\n", dev->minor); + + if (swap_regbase_tmp) { + regbase_tmp = plx_regbase_tmp; + plx_regbase_tmp = swap_regbase_tmp; + swap_regbase_tmp = regbase_tmp; + + result = pci_write_config_dword(pci_device, + PCI_BASE_ADDRESS_0, plx_regbase_tmp); + if (result != PCIBIOS_SUCCESSFUL) + return -EIO; + + result = pci_write_config_dword(pci_device, + PCI_BASE_ADDRESS_5, swap_regbase_tmp); + if (result != PCIBIOS_SUCCESSFUL) + return -EIO; + } else { + plx_regbase_tmp -= 0x80; + result = pci_write_config_dword(pci_device, + PCI_BASE_ADDRESS_0, plx_regbase_tmp); + if (result != PCIBIOS_SUCCESSFUL) + return -EIO; + } + } + /*----------------------------------------------------- Workaround end -----*/ + + // Read Meilhaus register base address [PCI_BASE_ADDRESS #2]. + + me_regbase_tmp = pci_resource_start(pci_device, 2); + me_regbase_size_tmp = pci_resource_len(pci_device, 2); + dev_private->me_regbase_size = me_regbase_size_tmp; + dev_private->me_regbase = ioremap(me_regbase_tmp, me_regbase_size_tmp); + if (!dev_private->me_regbase) { + printk("comedi%d: Failed to remap I/O memory\n", dev->minor); + return -ENOMEM; + } + // Download firmware and reset card + if (board->device_id == ME2600_DEVICE_ID) { + unsigned char *aux_data; + int aux_len; + + aux_data = comedi_aux_data(it->options, 0); + aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + + if (!aux_data || aux_len < 1) { + comedi_error(dev, + "You must provide me2600 firmware using the --init-data option of comedi_config"); return -EINVAL; } - me2600_xilinx_download(dev, aux_data, aux_len); - } - - me_reset(dev); - - // device driver capabilities - - if((error = alloc_subdevices(dev, 3)) < 0) - return error; - - subdevice = dev->subdevices + 0; - subdevice->type = COMEDI_SUBD_AI; - subdevice->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_CMD_READ; - subdevice->n_chan = board->ai_channel_nbr; - subdevice->maxdata = board->ai_resolution_mask; - subdevice->len_chanlist = board->ai_channel_nbr; - subdevice->range_table = board->ai_range_list; - subdevice->cancel = me_ai_cancel; - subdevice->insn_read = me_ai_insn_read; - subdevice->do_cmdtest = me_ai_do_cmd_test; - subdevice->do_cmd = me_ai_do_cmd; - - subdevice = dev->subdevices + 1; - subdevice->type = COMEDI_SUBD_AO; - subdevice->subdev_flags = SDF_WRITEABLE | SDF_COMMON; - subdevice->n_chan = board->ao_channel_nbr; - subdevice->maxdata = board->ao_resolution_mask; - subdevice->len_chanlist = board->ao_channel_nbr; - subdevice->range_table = board->ao_range_list; - subdevice->insn_read = me_ao_insn_read; - subdevice->insn_write = me_ao_insn_write; - - subdevice = dev->subdevices + 2; - subdevice->type = COMEDI_SUBD_DIO; - subdevice->subdev_flags = SDF_READABLE | SDF_WRITEABLE; - subdevice->n_chan = board->dio_channel_nbr; - subdevice->maxdata = 1; - subdevice->len_chanlist = board->dio_channel_nbr; - subdevice->range_table = &range_digital; - subdevice->insn_bits = me_dio_insn_bits; - subdevice->insn_config = me_dio_insn_config; - subdevice->io_bits = 0; - - printk("comedi%d: " ME_DRIVER_NAME " attached.\n", dev->minor); - return 0; -} + me2600_xilinx_download(dev, aux_data, aux_len); + } + me_reset(dev); + + // device driver capabilities + + if ((error = alloc_subdevices(dev, 3)) < 0) + return error; + + subdevice = dev->subdevices + 0; + subdevice->type = COMEDI_SUBD_AI; + subdevice->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_CMD_READ; + subdevice->n_chan = board->ai_channel_nbr; + subdevice->maxdata = board->ai_resolution_mask; + subdevice->len_chanlist = board->ai_channel_nbr; + subdevice->range_table = board->ai_range_list; + subdevice->cancel = me_ai_cancel; + subdevice->insn_read = me_ai_insn_read; + subdevice->do_cmdtest = me_ai_do_cmd_test; + subdevice->do_cmd = me_ai_do_cmd; + + subdevice = dev->subdevices + 1; + subdevice->type = COMEDI_SUBD_AO; + subdevice->subdev_flags = SDF_WRITEABLE | SDF_COMMON; + subdevice->n_chan = board->ao_channel_nbr; + subdevice->maxdata = board->ao_resolution_mask; + subdevice->len_chanlist = board->ao_channel_nbr; + subdevice->range_table = board->ao_range_list; + subdevice->insn_read = me_ao_insn_read; + subdevice->insn_write = me_ao_insn_write; + + subdevice = dev->subdevices + 2; + subdevice->type = COMEDI_SUBD_DIO; + subdevice->subdev_flags = SDF_READABLE | SDF_WRITEABLE; + subdevice->n_chan = board->dio_channel_nbr; + subdevice->maxdata = 1; + subdevice->len_chanlist = board->dio_channel_nbr; + subdevice->range_table = &range_digital; + subdevice->insn_bits = me_dio_insn_bits; + subdevice->insn_config = me_dio_insn_config; + subdevice->io_bits = 0; + + printk("comedi%d: " ME_DRIVER_NAME " attached.\n", dev->minor); + return 0; +} // // Detach // -static int me_detach(comedi_device *dev) +static int me_detach(comedi_device * dev) { - if(dev_private) - { - if (dev_private->me_regbase) - { + if (dev_private) { + if (dev_private->me_regbase) { me_reset(dev); iounmap(dev_private->me_regbase); } if (dev_private->plx_regbase) iounmap(dev_private->plx_regbase); - if(dev_private->pci_device) - { - if(dev_private->plx_regbase_size) - { + if (dev_private->pci_device) { + if (dev_private->plx_regbase_size) { comedi_pci_disable(dev_private->pci_device); } pci_dev_put(dev_private->pci_device); diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 0cee3743..2094b9c9 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -25,7 +25,6 @@ The PCI-MIO E series driver was originally written by Tomasz Motylewski <...>, and ported to comedi by ds. - References for specifications: 321747b.pdf Register Level Programmer Manual (obsolete) @@ -58,7 +57,6 @@ #include - #define PCI_MITE_SIZE 4096 #define PCI_DAQ_SIZE 4096 #define PCI_DAQ_SIZE_660X 8192 @@ -69,45 +67,40 @@ struct mite_struct *mite_devices = NULL; #define TOP_OF_PAGE(x) ((x)|(~(PAGE_MASK))) - void mite_init(void) { struct pci_dev *pcidev; struct mite_struct *mite; - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { - if(pcidev->vendor==PCI_VENDOR_ID_NATINST){ + if (pcidev->vendor == PCI_VENDOR_ID_NATINST) { unsigned i; - mite=kzalloc(sizeof(*mite),GFP_KERNEL); - if(!mite){ + mite = kzalloc(sizeof(*mite), GFP_KERNEL); + if (!mite) { printk("mite: allocation failed\n"); pci_dev_put(pcidev); return; } spin_lock_init(&mite->lock); - mite->pcidev=pci_dev_get(pcidev); - for(i = 0; i < MAX_MITE_DMA_CHANNELS; ++i) - { + mite->pcidev = pci_dev_get(pcidev); + for (i = 0; i < MAX_MITE_DMA_CHANNELS; ++i) { mite->channels[i].mite = mite; mite->channels[i].channel = i; mite->channels[i].done = 1; } - mite->next=mite_devices; - mite_devices=mite; + mite->next = mite_devices; + mite_devices = mite; } } } static void dump_chip_signature(u32 csigr_bits) { - printk("mite: version = %i, type = %i, mite mode = %i, interface mode = %i\n", - mite_csigr_version(csigr_bits), mite_csigr_type(csigr_bits), - mite_csigr_mmode(csigr_bits), mite_csigr_imode(csigr_bits)); - printk("mite: num channels = %i, write post fifo depth = %i, wins = %i, iowins = %i\n", - mite_csigr_dmac(csigr_bits), mite_csigr_wpdep(csigr_bits), - mite_csigr_wins(csigr_bits), mite_csigr_iowins(csigr_bits)); + printk("mite: version = %i, type = %i, mite mode = %i, interface mode = %i\n", mite_csigr_version(csigr_bits), mite_csigr_type(csigr_bits), mite_csigr_mmode(csigr_bits), mite_csigr_imode(csigr_bits)); + printk("mite: num channels = %i, write post fifo depth = %i, wins = %i, iowins = %i\n", mite_csigr_dmac(csigr_bits), mite_csigr_wpdep(csigr_bits), mite_csigr_wins(csigr_bits), mite_csigr_iowins(csigr_bits)); } int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1) @@ -118,7 +111,7 @@ int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1) u32 csigr_bits; unsigned unknown_dma_burst_bits; - if(comedi_pci_enable( mite->pcidev, "mite" ) ) { + if (comedi_pci_enable(mite->pcidev, "mite")) { printk("error enabling mite and requesting io regions\n"); return -EIO; } @@ -127,57 +120,62 @@ int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1) addr = pci_resource_start(mite->pcidev, 0); mite->mite_phys_addr = addr; mite->mite_io_addr = ioremap(addr, PCI_MITE_SIZE); - if( !mite->mite_io_addr ) { + if (!mite->mite_io_addr) { printk("failed to remap mite io memory address\n"); return -ENOMEM; } - printk("MITE:0x%08llx mapped to %p ",(unsigned long long)mite->mite_phys_addr,mite->mite_io_addr); + printk("MITE:0x%08llx mapped to %p ", + (unsigned long long)mite->mite_phys_addr, mite->mite_io_addr); - addr=pci_resource_start(mite->pcidev, 1); - mite->daq_phys_addr=addr; + addr = pci_resource_start(mite->pcidev, 1); + mite->daq_phys_addr = addr; length = pci_resource_len(mite->pcidev, 1); // In case of a 660x board, DAQ size is 8k instead of 4k (see as shown by lspci output) mite->daq_io_addr = ioremap(mite->daq_phys_addr, length); - if( !mite->daq_io_addr ) { + if (!mite->daq_io_addr) { printk("failed to remap daq io memory address\n"); return -ENOMEM; } - printk("DAQ:0x%08llx mapped to %p\n",(unsigned long long)mite->daq_phys_addr,mite->daq_io_addr); + printk("DAQ:0x%08llx mapped to %p\n", + (unsigned long long)mite->daq_phys_addr, mite->daq_io_addr); - if(use_iodwbsr_1) - { + if (use_iodwbsr_1) { writel(0, mite->mite_io_addr + MITE_IODWBSR); printk("mite: using I/O Window Base Size register 1\n"); - writel(mite->daq_phys_addr | WENAB | MITE_IODWBSR_1_WSIZE_bits(length), mite->mite_io_addr + MITE_IODWBSR_1); + writel(mite-> + daq_phys_addr | WENAB | + MITE_IODWBSR_1_WSIZE_bits(length), + mite->mite_io_addr + MITE_IODWBSR_1); writel(0, mite->mite_io_addr + MITE_IODWCR_1); - }else - { - writel(mite->daq_phys_addr | WENAB, mite->mite_io_addr + MITE_IODWBSR); + } else { + writel(mite->daq_phys_addr | WENAB, + mite->mite_io_addr + MITE_IODWBSR); } /* make sure dma bursts work. I got this from running a bus analyzer - on a pxi-6281 and a pxi-6713. 6713 powered up with register value - of 0x61f and bursts worked. 6281 powered up with register value of - 0x1f and bursts didn't work. The NI windows driver reads the register, - then does a bitwise-or of 0x600 with it and writes it back. - */ - unknown_dma_burst_bits = readl(mite->mite_io_addr + MITE_UNKNOWN_DMA_BURST_REG); + on a pxi-6281 and a pxi-6713. 6713 powered up with register value + of 0x61f and bursts worked. 6281 powered up with register value of + 0x1f and bursts didn't work. The NI windows driver reads the register, + then does a bitwise-or of 0x600 with it and writes it back. + */ + unknown_dma_burst_bits = + readl(mite->mite_io_addr + MITE_UNKNOWN_DMA_BURST_REG); unknown_dma_burst_bits |= UNKNOWN_DMA_BURST_ENABLE_BITS; - writel(unknown_dma_burst_bits, mite->mite_io_addr + MITE_UNKNOWN_DMA_BURST_REG); + writel(unknown_dma_burst_bits, + mite->mite_io_addr + MITE_UNKNOWN_DMA_BURST_REG); csigr_bits = readl(mite->mite_io_addr + MITE_CSIGR); mite->num_channels = mite_csigr_dmac(csigr_bits); - if(mite->num_channels > MAX_MITE_DMA_CHANNELS) - { - printk("mite: bug? chip claims to have %i dma channels. Setting to %i.\n", - mite->num_channels, MAX_MITE_DMA_CHANNELS); + if (mite->num_channels > MAX_MITE_DMA_CHANNELS) { + printk("mite: bug? chip claims to have %i dma channels. Setting to %i.\n", mite->num_channels, MAX_MITE_DMA_CHANNELS); mite->num_channels = MAX_MITE_DMA_CHANNELS; } dump_chip_signature(csigr_bits); - for( i = 0; i < mite->num_channels; i++ ) { + for (i = 0; i < mite->num_channels; i++) { writel(CHOR_DMARESET, mite->mite_io_addr + MITE_CHOR(i)); /* disable interrupts */ - writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE | - CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE | CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE, + writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE | + CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE | + CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE, mite->mite_io_addr + MITE_CHCR(i)); } mite->used = 1; @@ -192,11 +190,11 @@ int mite_setup(struct mite_struct *mite) void mite_cleanup(void) { - struct mite_struct *mite,*next; + struct mite_struct *mite, *next; - for(mite=mite_devices;mite;mite=next){ + for (mite = mite_devices; mite; mite = next) { pci_dev_put(mite->pcidev); - next=mite->next; + next = mite->next; kfree(mite); } } @@ -205,41 +203,44 @@ void mite_unsetup(struct mite_struct *mite) { //unsigned long offset, start, length; - if(!mite)return; + if (!mite) + return; - if(mite->mite_io_addr){ + if (mite->mite_io_addr) { iounmap(mite->mite_io_addr); - mite->mite_io_addr=NULL; + mite->mite_io_addr = NULL; } - if(mite->daq_io_addr){ + if (mite->daq_io_addr) { iounmap(mite->daq_io_addr); - mite->daq_io_addr=NULL; + mite->daq_io_addr = NULL; } - if( mite->mite_phys_addr ){ - comedi_pci_disable( mite->pcidev ); + if (mite->mite_phys_addr) { + comedi_pci_disable(mite->pcidev); mite->mite_phys_addr = 0; } mite->used = 0; } - void mite_list_devices(void) { - struct mite_struct *mite,*next; + struct mite_struct *mite, *next; printk("Available NI device IDs:"); - if(mite_devices)for(mite=mite_devices;mite;mite=next){ - next=mite->next; - printk(" 0x%04x",mite_device_id(mite)); - if(mite->used)printk("(used)"); - } + if (mite_devices) + for (mite = mite_devices; mite; mite = next) { + next = mite->next; + printk(" 0x%04x", mite_device_id(mite)); + if (mite->used) + printk("(used)"); + } printk("\n"); } -struct mite_channel* mite_request_channel_in_range(struct mite_struct *mite, struct mite_dma_descriptor_ring *ring, - unsigned min_channel, unsigned max_channel) +struct mite_channel *mite_request_channel_in_range(struct mite_struct *mite, + struct mite_dma_descriptor_ring *ring, unsigned min_channel, + unsigned max_channel) { int i; unsigned long flags; @@ -247,10 +248,8 @@ struct mite_channel* mite_request_channel_in_range(struct mite_struct *mite, str // spin lock so mite_release_channel can be called safely from interrupts comedi_spin_lock_irqsave(&mite->lock, flags); - for(i = min_channel; i <= max_channel; ++i) - { - if(mite->channel_allocated[i] == 0) - { + for (i = min_channel; i <= max_channel; ++i) { + if (mite->channel_allocated[i] == 0) { mite->channel_allocated[i] = 1; channel = &mite->channels[i]; channel->ring = ring; @@ -268,8 +267,7 @@ void mite_release_channel(struct mite_channel *mite_chan) // spin lock to prevent races with mite_request_channel comedi_spin_lock_irqsave(&mite->lock, flags); - if(mite->channel_allocated[mite_chan->channel]) - { + if (mite->channel_allocated[mite_chan->channel]) { // disable all channel's interrupts writel(CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE | @@ -293,7 +291,7 @@ void mite_dma_arm(struct mite_channel *mite_chan) MDPRINTK("mite_dma_arm ch%i\n", channel); /* memory barrier is intended to insure any twiddling with the buffer - is done before writing to the mite to arm dma transfer */ + is done before writing to the mite to arm dma transfer */ smp_mb(); /* arm */ chor = CHOR_START; @@ -302,56 +300,62 @@ void mite_dma_arm(struct mite_channel *mite_chan) writel(chor, mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); mmiowb(); comedi_spin_unlock_irqrestore(&mite->lock, flags); -// mite_dma_tcr(mite, channel); +// mite_dma_tcr(mite, channel); } - /**************************************/ -int mite_buf_change(struct mite_dma_descriptor_ring *ring, comedi_async *async) +int mite_buf_change(struct mite_dma_descriptor_ring *ring, comedi_async * async) { unsigned int n_links; int i; - if(ring->descriptors){ - dma_free_coherent(ring->hw_dev, ring->n_links * sizeof(struct mite_dma_descriptor), + if (ring->descriptors) { + dma_free_coherent(ring->hw_dev, + ring->n_links * sizeof(struct mite_dma_descriptor), ring->descriptors, ring->descriptors_dma_addr); } ring->descriptors = NULL; ring->descriptors_dma_addr = 0; ring->n_links = 0; - if(async->prealloc_bufsz==0){ + if (async->prealloc_bufsz == 0) { return 0; } n_links = async->prealloc_bufsz >> PAGE_SHIFT; MDPRINTK("ring->hw_dev=%p, n_links=0x%04x\n", ring->hw_dev, n_links); - ring->descriptors = dma_alloc_coherent(ring->hw_dev, n_links * sizeof(struct mite_dma_descriptor), + ring->descriptors = + dma_alloc_coherent(ring->hw_dev, + n_links * sizeof(struct mite_dma_descriptor), &ring->descriptors_dma_addr, GFP_KERNEL); - if(!ring->descriptors){ + if (!ring->descriptors) { printk("mite: ring buffer allocation failed\n"); return -ENOMEM; } ring->n_links = n_links; - for(i = 0; i < n_links; i++){ + for (i = 0; i < n_links; i++) { ring->descriptors[i].count = cpu_to_le32(PAGE_SIZE); - ring->descriptors[i].addr = cpu_to_le32(async->buf_page_list[i].dma_addr); - ring->descriptors[i].next = cpu_to_le32(ring->descriptors_dma_addr + (i + 1) * sizeof(struct mite_dma_descriptor)); + ring->descriptors[i].addr = + cpu_to_le32(async->buf_page_list[i].dma_addr); + ring->descriptors[i].next = + cpu_to_le32(ring->descriptors_dma_addr + (i + + 1) * sizeof(struct mite_dma_descriptor)); } - ring->descriptors[n_links - 1].next = cpu_to_le32(ring->descriptors_dma_addr); + ring->descriptors[n_links - 1].next = + cpu_to_le32(ring->descriptors_dma_addr); /* barrier is meant to insure that all the writes to the dma descriptors - have completed before the dma controller is commanded to read them */ + have completed before the dma controller is commanded to read them */ smp_wmb(); return 0; } void mite_prep_dma(struct mite_channel *mite_chan, - unsigned int num_device_bits, unsigned int num_memory_bits ) + unsigned int num_device_bits, unsigned int num_memory_bits) { - unsigned int chor,chcr,mcr,dcr,lkcr; + unsigned int chor, chcr, mcr, dcr, lkcr; struct mite_struct *mite = mite_chan->mite; MDPRINTK("mite_prep_dma ch%i\n", mite_chan->channel); @@ -361,7 +365,8 @@ void mite_prep_dma(struct mite_channel *mite_chan, writel(chor, mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); /* short link chaining mode */ - chcr = CHCR_SET_DMA_IE | CHCR_LINKSHORT | CHCR_SET_DONE_IE | CHCR_BURSTEN; + chcr = CHCR_SET_DMA_IE | CHCR_LINKSHORT | CHCR_SET_DONE_IE | + CHCR_BURSTEN; /* * Link Complete Interrupt: interrupt every time a link * in MITE_RING is completed. This can generate a lot of @@ -371,53 +376,54 @@ void mite_prep_dma(struct mite_channel *mite_chan, * "read()" to calculate the number of bytes available. */ chcr |= CHCR_SET_LC_IE; - if(num_memory_bits == 32 && num_device_bits == 16) - { + if (num_memory_bits == 32 && num_device_bits == 16) { /* Doing a combined 32 and 16 bit byteswap gets the 16 bit samples into the fifo in the right order. - Tested doing 32 bit memory to 16 bit device transfers to the analog out of a pxi-6281, - which has mite version = 1, type = 4. This also works for dma reads from the counters - on e-series boards. */ + Tested doing 32 bit memory to 16 bit device transfers to the analog out of a pxi-6281, + which has mite version = 1, type = 4. This also works for dma reads from the counters + on e-series boards. */ chcr |= CHCR_BYTE_SWAP_DEVICE | CHCR_BYTE_SWAP_MEMORY; } - if(mite_chan->dir == COMEDI_INPUT){ + if (mite_chan->dir == COMEDI_INPUT) { chcr |= CHCR_DEV_TO_MEM; } writel(chcr, mite->mite_io_addr + MITE_CHCR(mite_chan->channel)); /* to/from memory */ mcr = CR_RL(64) | CR_ASEQUP; - switch( num_memory_bits ){ - case 8: - mcr |= CR_PSIZE8; - break; - case 16: - mcr |= CR_PSIZE16; - break; - case 32: - mcr |= CR_PSIZE32; - break; - default: - rt_printk( "mite: bug! invalid mem bit width for dma transfer\n" ); - break; + switch (num_memory_bits) { + case 8: + mcr |= CR_PSIZE8; + break; + case 16: + mcr |= CR_PSIZE16; + break; + case 32: + mcr |= CR_PSIZE32; + break; + default: + rt_printk + ("mite: bug! invalid mem bit width for dma transfer\n"); + break; } writel(mcr, mite->mite_io_addr + MITE_MCR(mite_chan->channel)); /* from/to device */ dcr = CR_RL(64) | CR_ASEQUP; dcr |= CR_PORTIO | CR_AMDEVICE | CR_REQSDRQ(mite_chan->channel); - switch( num_device_bits ){ - case 8: - dcr |= CR_PSIZE8; - break; - case 16: - dcr |= CR_PSIZE16; - break; - case 32: - dcr |= CR_PSIZE32; - break; - default: - rt_printk( "mite: bug! invalid dev bit width for dma transfer\n" ); - break; + switch (num_device_bits) { + case 8: + dcr |= CR_PSIZE8; + break; + case 16: + dcr |= CR_PSIZE16; + break; + case 32: + dcr |= CR_PSIZE32; + break; + default: + rt_printk + ("mite: bug! invalid dev bit width for dma transfer\n"); + break; } writel(dcr, mite->mite_io_addr + MITE_DCR(mite_chan->channel)); @@ -441,14 +447,15 @@ u32 mite_device_bytes_transferred(struct mite_channel *mite_chan) return readl(mite->mite_io_addr + MITE_DAR(mite_chan->channel)); } -u32 mite_bytes_in_transit(struct mite_channel *mite_chan) +u32 mite_bytes_in_transit(struct mite_channel * mite_chan) { struct mite_struct *mite = mite_chan->mite; - return readl(mite->mite_io_addr + MITE_FCR(mite_chan->channel)) & 0x000000FF; + return readl(mite->mite_io_addr + + MITE_FCR(mite_chan->channel)) & 0x000000FF; } // returns lower bound for number of bytes transferred from device to memory -u32 mite_bytes_written_to_memory_lb(struct mite_channel *mite_chan) +u32 mite_bytes_written_to_memory_lb(struct mite_channel * mite_chan) { u32 device_byte_count; @@ -457,7 +464,7 @@ u32 mite_bytes_written_to_memory_lb(struct mite_channel *mite_chan) } // returns upper bound for number of bytes transferred from device to memory -u32 mite_bytes_written_to_memory_ub(struct mite_channel *mite_chan) +u32 mite_bytes_written_to_memory_ub(struct mite_channel * mite_chan) { u32 in_transit_count; @@ -466,7 +473,7 @@ u32 mite_bytes_written_to_memory_ub(struct mite_channel *mite_chan) } // returns lower bound for number of bytes read from memory for transfer to device -u32 mite_bytes_read_from_memory_lb(struct mite_channel *mite_chan) +u32 mite_bytes_read_from_memory_lb(struct mite_channel * mite_chan) { u32 device_byte_count; @@ -475,7 +482,7 @@ u32 mite_bytes_read_from_memory_lb(struct mite_channel *mite_chan) } // returns upper bound for number of bytes read from memory for transfer to device -u32 mite_bytes_read_from_memory_ub(struct mite_channel *mite_chan) +u32 mite_bytes_read_from_memory_ub(struct mite_channel * mite_chan) { u32 in_transit_count; @@ -491,7 +498,8 @@ unsigned mite_dma_tcr(struct mite_channel *mite_chan) lkar = readl(mite->mite_io_addr + MITE_LKAR(mite_chan->channel)); tcr = readl(mite->mite_io_addr + MITE_TCR(mite_chan->channel)); - MDPRINTK("mite_dma_tcr ch%i, lkar=0x%08x tcr=%d\n", mite_chan->channel, lkar, tcr); + MDPRINTK("mite_dma_tcr ch%i, lkar=0x%08x tcr=%d\n", mite_chan->channel, + lkar, tcr); return tcr; } @@ -506,7 +514,7 @@ void mite_dma_disarm(struct mite_channel *mite_chan) writel(chor, mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); } -int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async) +int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async * async) { int count; unsigned int nbytes, old_alloc_count; @@ -517,8 +525,8 @@ int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async) comedi_buf_write_alloc(async, async->prealloc_bufsz); nbytes = mite_bytes_written_to_memory_lb(mite_chan); - if((int)(mite_bytes_written_to_memory_ub(mite_chan) - old_alloc_count) > 0) - { + if ((int)(mite_bytes_written_to_memory_ub(mite_chan) - + old_alloc_count) > 0) { rt_printk("mite: DMA overwrite of free area\n"); async->events |= COMEDI_CB_OVERFLOW; return -1; @@ -527,15 +535,13 @@ int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async) count = nbytes - async->buf_write_count; /* it's possible count will be negative due to * conservative value returned by mite_bytes_written_to_memory_lb */ - if( count <= 0 ) - { + if (count <= 0) { return 0; } comedi_buf_write_free(async, count); async->scan_progress += count; - if(async->scan_progress >= bytes_per_scan) - { + if (async->scan_progress >= bytes_per_scan) { async->scan_progress %= bytes_per_scan; async->events |= COMEDI_CB_EOS; } @@ -543,37 +549,35 @@ int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async) return 0; } -int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async *async) +int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async * async) { int count; u32 nbytes_ub, nbytes_lb; unsigned int old_alloc_count; - u32 stop_count = async->cmd.stop_arg * cfc_bytes_per_scan(async->subdevice); + u32 stop_count = + async->cmd.stop_arg * cfc_bytes_per_scan(async->subdevice); old_alloc_count = async->buf_read_alloc_count; // read alloc as much as we can comedi_buf_read_alloc(async, async->prealloc_bufsz); nbytes_lb = mite_bytes_read_from_memory_lb(mite_chan); - if(async->cmd.stop_src == TRIG_COUNT && - (int) (nbytes_lb - stop_count) > 0) + if (async->cmd.stop_src == TRIG_COUNT && + (int)(nbytes_lb - stop_count) > 0) nbytes_lb = stop_count; nbytes_ub = mite_bytes_read_from_memory_ub(mite_chan); - if(async->cmd.stop_src == TRIG_COUNT && - (int) (nbytes_ub - stop_count) > 0) + if (async->cmd.stop_src == TRIG_COUNT && + (int)(nbytes_ub - stop_count) > 0) nbytes_ub = stop_count; - if((int)(nbytes_ub - old_alloc_count) > 0) - { + if ((int)(nbytes_ub - old_alloc_count) > 0) { rt_printk("mite: DMA underrun\n"); async->events |= COMEDI_CB_OVERFLOW; return -1; } count = nbytes_lb - async->buf_read_count; - if(count <= 0) - { + if (count <= 0) { return 0; } - if(count) - { + if (count) { comedi_buf_read_free(async, count); async->events |= COMEDI_CB_BLOCK; } @@ -588,10 +592,10 @@ unsigned mite_get_status(struct mite_channel *mite_chan) comedi_spin_lock_irqsave(&mite->lock, flags); status = readl(mite->mite_io_addr + MITE_CHSR(mite_chan->channel)); - if(status & CHSR_DONE) - { + if (status & CHSR_DONE) { mite_chan->done = 1; - writel(CHOR_CLRDONE, mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); + writel(CHOR_CLRDONE, + mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); } mmiowb(); comedi_spin_unlock_irqrestore(&mite->lock, flags); @@ -617,7 +621,7 @@ static void mite_decode(char **bit_str, unsigned int bits); /* names of bits in mite registers */ -static const char * const mite_CHOR_strings[] = { +static const char *const mite_CHOR_strings[] = { "start", "cont", "stop", "abort", "freset", "clrlc", "clrrb", "clrdone", "clr_lpause", "set_lpause", "clr_send_tc", @@ -629,7 +633,7 @@ static const char * const mite_CHOR_strings[] = { "dmareset", }; -static const char * const mite_CHCR_strings[] = { +static const char *const mite_CHCR_strings[] = { "continue", "ringbuff", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", @@ -640,7 +644,7 @@ static const char * const mite_CHCR_strings[] = { "clr_linkp_ie", "set_linkp_ie", "clr_dma_ie", "set_dma_ie", }; -static const char * const mite_MCR_strings[] = { +static const char *const mite_MCR_strings[] = { "amdevice", "1", "2", "3", "4", "5", "portio", "portvxi", "psizebyte", "psizehalf (byte & half = word)", "aseqxp1", "11", @@ -651,7 +655,7 @@ static const char * const mite_MCR_strings[] = { "28", "29", "30", "stopen", }; -static const char * const mite_DCR_strings[] = { +static const char *const mite_DCR_strings[] = { "amdevice", "1", "2", "3", "4", "5", "portio", "portvxi", "psizebyte", "psizehalf (byte & half = word)", "aseqxp1", "aseqxp2", @@ -662,7 +666,7 @@ static const char * const mite_DCR_strings[] = { "28", "wsdevc", "wsdevs", "rwdevpack", }; -static const char * const mite_LKCR_strings[] = { +static const char *const mite_LKCR_strings[] = { "amdevice", "1", "2", "3", "4", "5", "portio", "portvxi", "psizebyte", "psizehalf (byte & half = word)", "asequp", "aseqdown", @@ -673,8 +677,7 @@ static const char * const mite_LKCR_strings[] = { "28", "29", "30", "chngend", }; - -static const char * const mite_CHSR_strings[] = { +static const char *const mite_CHSR_strings[] = { "d.err0", "d.err1", "m.err0", "m.err1", "l.err0", "l.err1", "drq0", "drq1", "end", "xferr", "operr0", "operr1", @@ -687,51 +690,58 @@ static const char * const mite_CHSR_strings[] = { void mite_dump_regs(struct mite_channel *mite_chan) { - unsigned long mite_io_addr = (unsigned long) mite_chan->mite->mite_io_addr; - unsigned long addr=0; - unsigned long temp=0; + unsigned long mite_io_addr = + (unsigned long)mite_chan->mite->mite_io_addr; + unsigned long addr = 0; + unsigned long temp = 0; printk("mite_dump_regs ch%i\n", mite_chan->channel); printk("mite address is =0x%08lx\n", mite_io_addr); - addr = mite_io_addr+MITE_CHOR(channel); - printk("mite status[CHOR]at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_CHOR_strings,temp); - addr = mite_io_addr+MITE_CHCR(channel); - printk("mite status[CHCR]at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_CHCR_strings,temp); - addr = mite_io_addr+MITE_TCR(channel); - printk("mite status[TCR] at 0x%08lx =0x%08x\n",addr, readl(addr)); - addr = mite_io_addr+MITE_MCR(channel); - printk("mite status[MCR] at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_MCR_strings,temp); - - addr = mite_io_addr+MITE_MAR(channel); - printk("mite status[MAR] at 0x%08lx =0x%08x\n",addr, readl(addr)); - addr = mite_io_addr+MITE_DCR(channel); - printk("mite status[DCR] at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_DCR_strings,temp); - addr = mite_io_addr+MITE_DAR(channel); - printk("mite status[DAR] at 0x%08lx =0x%08x\n",addr, readl(addr)); - addr = mite_io_addr+MITE_LKCR(channel); - printk("mite status[LKCR]at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_LKCR_strings,temp); + addr = mite_io_addr + MITE_CHOR(channel); + printk("mite status[CHOR]at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_CHOR_strings, temp); + addr = mite_io_addr + MITE_CHCR(channel); + printk("mite status[CHCR]at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_CHCR_strings, temp); + addr = mite_io_addr + MITE_TCR(channel); + printk("mite status[TCR] at 0x%08lx =0x%08x\n", addr, readl(addr)); + addr = mite_io_addr + MITE_MCR(channel); + printk("mite status[MCR] at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_MCR_strings, temp); + + addr = mite_io_addr + MITE_MAR(channel); + printk("mite status[MAR] at 0x%08lx =0x%08x\n", addr, readl(addr)); + addr = mite_io_addr + MITE_DCR(channel); + printk("mite status[DCR] at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_DCR_strings, temp); + addr = mite_io_addr + MITE_DAR(channel); + printk("mite status[DAR] at 0x%08lx =0x%08x\n", addr, readl(addr)); + addr = mite_io_addr + MITE_LKCR(channel); + printk("mite status[LKCR]at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_LKCR_strings, temp); addr = mite_io_addr + MITE_LKAR(channel); - printk("mite status[LKAR]at 0x%08lx =0x%08x\n",addr, readl(addr)); - - addr = mite_io_addr+MITE_CHSR(channel); - printk("mite status[CHSR]at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_CHSR_strings,temp); - addr = mite_io_addr+MITE_FCR(channel); - printk("mite status[FCR] at 0x%08lx =0x%08x\n\n",addr, readl(addr)); + printk("mite status[LKAR]at 0x%08lx =0x%08x\n", addr, readl(addr)); + + addr = mite_io_addr + MITE_CHSR(channel); + printk("mite status[CHSR]at 0x%08lx =0x%08lx\n", addr, temp = + readl(addr)); + mite_decode(mite_CHSR_strings, temp); + addr = mite_io_addr + MITE_FCR(channel); + printk("mite status[FCR] at 0x%08lx =0x%08x\n\n", addr, readl(addr)); } static void mite_decode(char **bit_str, unsigned int bits) { int i; - for(i=31;i>=0;i--){ - if(bits&(1<= 0; i--) { + if (bits & (1 << i)) { printk(" %s", bit_str[i]); } } @@ -739,7 +749,6 @@ static void mite_decode(char **bit_str, unsigned int bits) } #endif - #ifdef MODULE int __init init_module(void) { @@ -786,4 +795,3 @@ EXPORT_SYMBOL(mite_dump_regs); #endif #endif - diff --git a/comedi/drivers/mite.h b/comedi/drivers/mite.h index b810fc86..f47db61a 100644 --- a/comedi/drivers/mite.h +++ b/comedi/drivers/mite.h @@ -27,7 +27,6 @@ #include #include - #define PCI_VENDOR_ID_NATINST 0x1093 // #define DEBUG_MITE @@ -41,22 +40,21 @@ #define MAX_MITE_DMA_CHANNELS 8 -struct mite_dma_descriptor{ +struct mite_dma_descriptor { u32 count; u32 addr; u32 next; u32 dar; }; -struct mite_dma_descriptor_ring -{ +struct mite_dma_descriptor_ring { struct device *hw_dev; unsigned int n_links; struct mite_dma_descriptor *descriptors; dma_addr_t descriptors_dma_addr; }; -struct mite_channel{ +struct mite_channel { struct mite_struct *mite; unsigned channel; int dir; @@ -64,7 +62,7 @@ struct mite_channel{ struct mite_dma_descriptor_ring *ring; }; -struct mite_struct{ +struct mite_struct { struct mite_struct *next; int used; @@ -80,13 +78,15 @@ struct mite_struct{ spinlock_t lock; }; -static inline struct mite_dma_descriptor_ring* mite_alloc_ring(struct mite_struct *mite) +static inline struct mite_dma_descriptor_ring *mite_alloc_ring(struct + mite_struct *mite) { - struct mite_dma_descriptor_ring *ring = kmalloc(sizeof(struct mite_dma_descriptor_ring), GFP_KERNEL); - if(ring == NULL) return ring; + struct mite_dma_descriptor_ring *ring = + kmalloc(sizeof(struct mite_dma_descriptor_ring), GFP_KERNEL); + if (ring == NULL) + return ring; ring->hw_dev = get_device(&mite->pcidev->dev); - if(ring->hw_dev == NULL) - { + if (ring->hw_dev == NULL) { kfree(ring); return NULL; } @@ -98,11 +98,11 @@ static inline struct mite_dma_descriptor_ring* mite_alloc_ring(struct mite_struc static inline void mite_free_ring(struct mite_dma_descriptor_ring *ring) { - if(ring) - { - if(ring->descriptors) - { - dma_free_coherent(ring->hw_dev, ring->n_links * sizeof(struct mite_dma_descriptor), + if (ring) { + if (ring->descriptors) { + dma_free_coherent(ring->hw_dev, + ring->n_links * + sizeof(struct mite_dma_descriptor), ring->descriptors, ring->descriptors_dma_addr); } put_device(ring->hw_dev); @@ -127,21 +127,22 @@ int mite_setup(struct mite_struct *mite); int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1); void mite_unsetup(struct mite_struct *mite); void mite_list_devices(void); -struct mite_channel* mite_request_channel_in_range( - struct mite_struct *mite, struct mite_dma_descriptor_ring *ring, - unsigned min_channel, unsigned max_channel); -static inline struct mite_channel* mite_request_channel( - struct mite_struct *mite, struct mite_dma_descriptor_ring *ring) -{ - return mite_request_channel_in_range(mite, ring, 0, mite->num_channels - 1); +struct mite_channel *mite_request_channel_in_range(struct mite_struct *mite, + struct mite_dma_descriptor_ring *ring, unsigned min_channel, + unsigned max_channel); +static inline struct mite_channel *mite_request_channel(struct mite_struct + *mite, struct mite_dma_descriptor_ring *ring) +{ + return mite_request_channel_in_range(mite, ring, 0, + mite->num_channels - 1); } void mite_release_channel(struct mite_channel *mite_chan); -unsigned mite_dma_tcr(struct mite_channel *mite_chan ); -void mite_dma_arm(struct mite_channel *mite_chan ); -void mite_dma_disarm(struct mite_channel *mite_chan ); -int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async); -int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async *async); +unsigned mite_dma_tcr(struct mite_channel *mite_chan); +void mite_dma_arm(struct mite_channel *mite_chan); +void mite_dma_disarm(struct mite_channel *mite_chan); +int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async * async); +int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async * async); u32 mite_bytes_written_to_memory_lb(struct mite_channel *mite_chan); u32 mite_bytes_written_to_memory_ub(struct mite_channel *mite_chan); u32 mite_bytes_read_from_memory_lb(struct mite_channel *mite_chan); @@ -151,13 +152,16 @@ unsigned mite_get_status(struct mite_channel *mite_chan); int mite_done(struct mite_channel *mite_chan); #if 0 -unsigned long mite_ll_from_kvmem(struct mite_struct *mite,comedi_async *async,int len); -void mite_setregs(struct mite_struct *mite,unsigned long ll_start,int chan, int dir); +unsigned long mite_ll_from_kvmem(struct mite_struct *mite, comedi_async * async, + int len); +void mite_setregs(struct mite_struct *mite, unsigned long ll_start, int chan, + int dir); #endif void mite_prep_dma(struct mite_channel *mite_chan, - unsigned int num_device_bits, unsigned int num_memory_bits ); -int mite_buf_change(struct mite_dma_descriptor_ring *ring, comedi_async *async); + unsigned int num_device_bits, unsigned int num_memory_bits); +int mite_buf_change(struct mite_dma_descriptor_ring *ring, + comedi_async * async); #ifdef DEBUG_MITE void mite_print_chsr(unsigned int chsr); @@ -169,14 +173,13 @@ static inline int CHAN_OFFSET(int channel) return 0x500 + 0x100 * channel; }; -enum mite_registers -{ +enum mite_registers { /* The bits 0x90180700 in MITE_UNKNOWN_DMA_BURST_REG can be - written and read back. The bits 0x1f always read as 1. - The rest always read as zero. */ + written and read back. The bits 0x1f always read as 1. + The rest always read as zero. */ MITE_UNKNOWN_DMA_BURST_REG = 0x28, - MITE_IODWBSR = 0xc0, //IO Device Window Base Size Register - MITE_IODWBSR_1 = 0xc4, // IO Device Window Base Size Register 1 + MITE_IODWBSR = 0xc0, //IO Device Window Base Size Register + MITE_IODWBSR_1 = 0xc4, // IO Device Window Base Size Register 1 MITE_IODWCR_1 = 0xf4, MITE_PCI_CONFIG_OFFSET = 0x300, MITE_CSIGR = 0x460 //chip signature @@ -250,21 +253,20 @@ static inline int MITE_FCR(int channel) // fifo count return CHAN_OFFSET(channel) + 0x40; }; -enum MITE_IODWBSR_bits -{ - WENAB = 0x80, // window enable +enum MITE_IODWBSR_bits { + WENAB = 0x80, // window enable }; static inline unsigned MITE_IODWBSR_1_WSIZE_bits(unsigned size) { unsigned order = 0; - while(size >>= 1) ++order; + while (size >>= 1) + ++order; BUG_ON(order < 1); return (order - 1) & 0x1f; } -enum MITE_UNKNOWN_DMA_BURST_bits -{ +enum MITE_UNKNOWN_DMA_BURST_bits { UNKNOWN_DMA_BURST_ENABLE_BITS = 0x600 }; @@ -273,115 +275,115 @@ static inline int mite_csigr_version(u32 csigr_bits) return csigr_bits & 0xf; }; static inline int mite_csigr_type(u32 csigr_bits) -{ // original mite = 0, minimite = 1 +{ // original mite = 0, minimite = 1 return (csigr_bits >> 4) & 0xf; }; static inline int mite_csigr_mmode(u32 csigr_bits) -{ // mite mode, minimite = 1 +{ // mite mode, minimite = 1 return (csigr_bits >> 8) & 0x3; }; static inline int mite_csigr_imode(u32 csigr_bits) -{ // cpu port interface mode, pci = 0x3 +{ // cpu port interface mode, pci = 0x3 return (csigr_bits >> 12) & 0x3; }; static inline int mite_csigr_dmac(u32 csigr_bits) -{ // number of dma channels +{ // number of dma channels return (csigr_bits >> 16) & 0xf; }; static inline int mite_csigr_wpdep(u32 csigr_bits) -{ // write post fifo depth +{ // write post fifo depth unsigned int wpdep_bits = (csigr_bits >> 20) & 0x7; - if(wpdep_bits == 0) return 0; - else return 1 << (wpdep_bits - 1); + if (wpdep_bits == 0) + return 0; + else + return 1 << (wpdep_bits - 1); }; static inline int mite_csigr_wins(u32 csigr_bits) { return (csigr_bits >> 24) & 0x1f; }; static inline int mite_csigr_iowins(u32 csigr_bits) -{ // number of io windows +{ // number of io windows return (csigr_bits >> 29) & 0x7; }; -enum MITE_MCR_bits -{ +enum MITE_MCR_bits { MCRPON = 0, }; -enum MITE_DCR_bits -{ - DCR_NORMAL = (1<<29), +enum MITE_DCR_bits { + DCR_NORMAL = (1 << 29), DCRPON = 0, }; -enum MITE_CHOR_bits -{ - CHOR_DMARESET = (1<<31), - CHOR_SET_SEND_TC = (1<<11), - CHOR_CLR_SEND_TC = (1<<10), - CHOR_SET_LPAUSE = (1<<9), - CHOR_CLR_LPAUSE = (1<<8), - CHOR_CLRDONE = (1<<7), - CHOR_CLRRB = (1<<6), - CHOR_CLRLC = (1<<5), - CHOR_FRESET = (1<<4), - CHOR_ABORT = (1<<3), /* stop without emptying fifo */ - CHOR_STOP = (1<<2), /* stop after emptying fifo */ - CHOR_CONT = (1<<1), - CHOR_START = (1<<0), - CHOR_PON = (CHOR_CLR_SEND_TC|CHOR_CLR_LPAUSE), -}; - -enum MITE_CHCR_bits -{ - CHCR_SET_DMA_IE = (1<<31), - CHCR_CLR_DMA_IE = (1<<30), - CHCR_SET_LINKP_IE = (1<<29), - CHCR_CLR_LINKP_IE = (1<<28), - CHCR_SET_SAR_IE = (1<<27), - CHCR_CLR_SAR_IE = (1<<26), - CHCR_SET_DONE_IE = (1<<25), - CHCR_CLR_DONE_IE = (1<<24), - CHCR_SET_MRDY_IE = (1<<23), - CHCR_CLR_MRDY_IE = (1<<22), - CHCR_SET_DRDY_IE = (1<<21), - CHCR_CLR_DRDY_IE = (1<<20), - CHCR_SET_LC_IE = (1<<19), - CHCR_CLR_LC_IE = (1<<18), - CHCR_SET_CONT_RB_IE = (1<<17), - CHCR_CLR_CONT_RB_IE = (1<<16), - CHCR_FIFODIS = (1<<15), - CHCR_FIFO_ON = 0, - CHCR_BURSTEN = (1<<14), - CHCR_NO_BURSTEN = 0, - CHCR_BYTE_SWAP_DEVICE = (1 << 6), - CHCR_BYTE_SWAP_MEMORY = (1 << 4), - CHCR_DIR = (1<<3), - CHCR_DEV_TO_MEM = CHCR_DIR, - CHCR_MEM_TO_DEV = 0, - CHCR_NORMAL = (0<<0), - CHCR_CONTINUE = (1<<0), - CHCR_RINGBUFF = (2<<0), - CHCR_LINKSHORT = (4<<0), - CHCR_LINKLONG = (5<<0), - CHCRPON = (CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE | CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE | CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE), -}; - -enum ConfigRegister_bits -{ +enum MITE_CHOR_bits { + CHOR_DMARESET = (1 << 31), + CHOR_SET_SEND_TC = (1 << 11), + CHOR_CLR_SEND_TC = (1 << 10), + CHOR_SET_LPAUSE = (1 << 9), + CHOR_CLR_LPAUSE = (1 << 8), + CHOR_CLRDONE = (1 << 7), + CHOR_CLRRB = (1 << 6), + CHOR_CLRLC = (1 << 5), + CHOR_FRESET = (1 << 4), + CHOR_ABORT = (1 << 3), /* stop without emptying fifo */ + CHOR_STOP = (1 << 2), /* stop after emptying fifo */ + CHOR_CONT = (1 << 1), + CHOR_START = (1 << 0), + CHOR_PON = (CHOR_CLR_SEND_TC | CHOR_CLR_LPAUSE), +}; + +enum MITE_CHCR_bits { + CHCR_SET_DMA_IE = (1 << 31), + CHCR_CLR_DMA_IE = (1 << 30), + CHCR_SET_LINKP_IE = (1 << 29), + CHCR_CLR_LINKP_IE = (1 << 28), + CHCR_SET_SAR_IE = (1 << 27), + CHCR_CLR_SAR_IE = (1 << 26), + CHCR_SET_DONE_IE = (1 << 25), + CHCR_CLR_DONE_IE = (1 << 24), + CHCR_SET_MRDY_IE = (1 << 23), + CHCR_CLR_MRDY_IE = (1 << 22), + CHCR_SET_DRDY_IE = (1 << 21), + CHCR_CLR_DRDY_IE = (1 << 20), + CHCR_SET_LC_IE = (1 << 19), + CHCR_CLR_LC_IE = (1 << 18), + CHCR_SET_CONT_RB_IE = (1 << 17), + CHCR_CLR_CONT_RB_IE = (1 << 16), + CHCR_FIFODIS = (1 << 15), + CHCR_FIFO_ON = 0, + CHCR_BURSTEN = (1 << 14), + CHCR_NO_BURSTEN = 0, + CHCR_BYTE_SWAP_DEVICE = (1 << 6), + CHCR_BYTE_SWAP_MEMORY = (1 << 4), + CHCR_DIR = (1 << 3), + CHCR_DEV_TO_MEM = CHCR_DIR, + CHCR_MEM_TO_DEV = 0, + CHCR_NORMAL = (0 << 0), + CHCR_CONTINUE = (1 << 0), + CHCR_RINGBUFF = (2 << 0), + CHCR_LINKSHORT = (4 << 0), + CHCR_LINKLONG = (5 << 0), + CHCRPON = + (CHCR_CLR_DMA_IE | CHCR_CLR_LINKP_IE | CHCR_CLR_SAR_IE | + CHCR_CLR_DONE_IE | CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE | + CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE), +}; + +enum ConfigRegister_bits { CR_REQS_MASK = 0x7 << 16, CR_ASEQDONT = 0x0 << 10, CR_ASEQUP = 0x1 << 10, CR_ASEQDOWN = 0x2 << 10, CR_ASEQ_MASK = 0x3 << 10, - CR_PSIZE8 = (1<<8), - CR_PSIZE16 = (2<<8), - CR_PSIZE32 = (3<<8), - CR_PORTCPU = (0<<6), - CR_PORTIO = (1<<6), - CR_PORTVXI = (2<<6), - CR_PORTMXI = (3<<6), - CR_AMDEVICE = (1<<0), + CR_PSIZE8 = (1 << 8), + CR_PSIZE16 = (2 << 8), + CR_PSIZE32 = (3 << 8), + CR_PORTCPU = (0 << 6), + CR_PORTIO = (1 << 6), + CR_PORTVXI = (2 << 6), + CR_PORTMXI = (3 << 6), + CR_AMDEVICE = (1 << 0), }; static inline int CR_REQS(int source) { @@ -390,62 +392,61 @@ static inline int CR_REQS(int source) static inline int CR_REQSDRQ(unsigned drq_line) { /* This also works on m-series when - using channels (drq_line) 4 or 5. */ + using channels (drq_line) 4 or 5. */ return CR_REQS((drq_line & 0x3) | 0x4); } static inline int CR_RL(unsigned int retry_limit) { int value = 0; - while(retry_limit) - { + while (retry_limit) { retry_limit >>= 1; value++; } - if(value > 0x7) rt_printk("comedi: bug! retry_limit too large\n"); + if (value > 0x7) + rt_printk("comedi: bug! retry_limit too large\n"); return (value & 0x7) << 21; } -enum CHSR_bits -{ - CHSR_INT = (1<<31), - CHSR_LPAUSES = (1<<29), - CHSR_SARS = (1<<27), - CHSR_DONE = (1<<25), - CHSR_MRDY = (1<<23), - CHSR_DRDY = (1<<21), - CHSR_LINKC = (1<<19), - CHSR_CONTS_RB = (1<<17), - CHSR_ERROR = (1<<15), - CHSR_SABORT = (1<<14), - CHSR_HABORT = (1<<13), - CHSR_STOPS = (1<<12), - CHSR_OPERR_mask = (3<<10), - CHSR_OPERR_NOERROR = (0<<10), - CHSR_OPERR_FIFOERROR = (1<<10), - CHSR_OPERR_LINKERROR = (1<<10), /* ??? */ - CHSR_XFERR = (1<<9), - CHSR_END = (1<<8), - CHSR_DRQ1 = (1<<7), - CHSR_DRQ0 = (1<<6), - CHSR_LxERR_mask = (3<<4), - CHSR_LBERR = (1<<4), - CHSR_LRERR = (2<<4), - CHSR_LOERR = (3<<4), - CHSR_MxERR_mask = (3<<2), - CHSR_MBERR = (1<<2), - CHSR_MRERR = (2<<2), - CHSR_MOERR = (3<<2), - CHSR_DxERR_mask = (3<<0), - CHSR_DBERR = (1<<0), - CHSR_DRERR = (2<<0), - CHSR_DOERR = (3<<0), +enum CHSR_bits { + CHSR_INT = (1 << 31), + CHSR_LPAUSES = (1 << 29), + CHSR_SARS = (1 << 27), + CHSR_DONE = (1 << 25), + CHSR_MRDY = (1 << 23), + CHSR_DRDY = (1 << 21), + CHSR_LINKC = (1 << 19), + CHSR_CONTS_RB = (1 << 17), + CHSR_ERROR = (1 << 15), + CHSR_SABORT = (1 << 14), + CHSR_HABORT = (1 << 13), + CHSR_STOPS = (1 << 12), + CHSR_OPERR_mask = (3 << 10), + CHSR_OPERR_NOERROR = (0 << 10), + CHSR_OPERR_FIFOERROR = (1 << 10), + CHSR_OPERR_LINKERROR = (1 << 10), /* ??? */ + CHSR_XFERR = (1 << 9), + CHSR_END = (1 << 8), + CHSR_DRQ1 = (1 << 7), + CHSR_DRQ0 = (1 << 6), + CHSR_LxERR_mask = (3 << 4), + CHSR_LBERR = (1 << 4), + CHSR_LRERR = (2 << 4), + CHSR_LOERR = (3 << 4), + CHSR_MxERR_mask = (3 << 2), + CHSR_MBERR = (1 << 2), + CHSR_MRERR = (2 << 2), + CHSR_MOERR = (3 << 2), + CHSR_DxERR_mask = (3 << 0), + CHSR_DBERR = (1 << 0), + CHSR_DRERR = (2 << 0), + CHSR_DOERR = (3 << 0), }; static inline void mite_dma_reset(struct mite_channel *mite_chan) { - writel(CHOR_DMARESET | CHOR_FRESET, mite_chan->mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); + writel(CHOR_DMARESET | CHOR_FRESET, + mite_chan->mite->mite_io_addr + MITE_CHOR(mite_chan->channel)); }; #endif - diff --git a/comedi/drivers/mpc624.c b/comedi/drivers/mpc624.c index 2b7d8da3..cb73fc8d 100644 --- a/comedi/drivers/mpc624.c +++ b/comedi/drivers/mpc624.c @@ -62,16 +62,16 @@ Configuration Options: #include // Consecutive I/O port addresses -#define MPC624_SIZE 16 +#define MPC624_SIZE 16 // Offsets of different ports -#define MPC624_MASTER_CONTROL 0 // not used -#define MPC624_GNMUXCH 1 // Gain, Mux, Channel of ADC -#define MPC624_ADC 2 // read/write to/from ADC -#define MPC624_EE 3 // read/write to/from serial EEPROM via I2C -#define MPC624_LEDS 4 // write to LEDs -#define MPC624_DIO 5 // read/write to/from digital I/O ports -#define MPC624_IRQ_MASK 6 // IRQ masking enable/disable +#define MPC624_MASTER_CONTROL 0 // not used +#define MPC624_GNMUXCH 1 // Gain, Mux, Channel of ADC +#define MPC624_ADC 2 // read/write to/from ADC +#define MPC624_EE 3 // read/write to/from serial EEPROM via I2C +#define MPC624_LEDS 4 // write to LEDs +#define MPC624_DIO 5 // read/write to/from digital I/O ports +#define MPC624_IRQ_MASK 6 // IRQ masking enable/disable // Register bits' names #define MPC624_ADBUSY (1<<5) @@ -120,139 +120,134 @@ Configuration Options: #define MPC624_SPEED_13_75_Hz (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR0) #define MPC624_SPEED_6_875_Hz (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR2 | MPC624_OSR1 | MPC624_OSR0) //---------------------------------------------------------------------------- -typedef struct -{ - unsigned long int ulConvertionRate; // set by mpc624_attach() from driver's parameters +typedef struct { + unsigned long int ulConvertionRate; // set by mpc624_attach() from driver's parameters } skel_private; #define devpriv ((skel_private *)dev->private) //---------------------------------------------------------------------------- -static const comedi_lrange range_mpc624_bipolar1 = -{ - 1, - { +static const comedi_lrange range_mpc624_bipolar1 = { + 1, + { // BIP_RANGE(1.01) // this is correct, - // but my MPC-624 actually seems to have a range of 2.02 - BIP_RANGE(2.02) - } + // but my MPC-624 actually seems to have a range of 2.02 + BIP_RANGE(2.02) + } }; -static const comedi_lrange range_mpc624_bipolar10 = -{ - 1, - { +static const comedi_lrange range_mpc624_bipolar10 = { + 1, + { // BIP_RANGE(10.1) // this is correct, - // but my MPC-624 actually seems to have a range of 20.2 - BIP_RANGE(20.2) - } + // but my MPC-624 actually seems to have a range of 20.2 + BIP_RANGE(20.2) + } }; + //---------------------------------------------------------------------------- -static int mpc624_attach(comedi_device *dev,comedi_devconfig *it); -static int mpc624_detach(comedi_device *dev); +static int mpc624_attach(comedi_device * dev, comedi_devconfig * it); +static int mpc624_detach(comedi_device * dev); //---------------------------------------------------------------------------- -static comedi_driver driver_mpc624 = -{ - driver_name: "mpc624", - module: THIS_MODULE, - attach: mpc624_attach, - detach: mpc624_detach +static comedi_driver driver_mpc624 = { + driver_name:"mpc624", + module:THIS_MODULE, + attach:mpc624_attach, + detach:mpc624_detach }; + //---------------------------------------------------------------------------- -static int mpc624_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, - lsampl_t *data); +static int mpc624_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); //---------------------------------------------------------------------------- -static int mpc624_attach(comedi_device *dev, comedi_devconfig *it) +static int mpc624_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - unsigned long iobase; + unsigned long iobase; - iobase = it->options[0]; + iobase = it->options[0]; rt_printk("comedi%d: mpc624 [0x%04lx, ", dev->minor, iobase); - if(request_region(iobase, MPC624_SIZE, "mpc624") == NULL) - { - rt_printk("I/O port(s) in use\n"); - return -EIO; - } + if (request_region(iobase, MPC624_SIZE, "mpc624") == NULL) { + rt_printk("I/O port(s) in use\n"); + return -EIO; + } dev->iobase = iobase; dev->board_name = "mpc624"; - - // Private structure initialization - if(alloc_private(dev, sizeof(skel_private)) < 0) - return -ENOMEM; - - switch(it->options[1]) - { - case 0: - devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; - rt_printk("3.52 kHz, "); - break; - case 1: - devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz; - rt_printk("1.76 kHz, "); - break; - case 2: - devpriv->ulConvertionRate = MPC624_SPEED_880_Hz; - rt_printk("880 Hz, "); - break; - case 3: - devpriv->ulConvertionRate = MPC624_SPEED_440_Hz; - rt_printk("440 Hz, "); - break; - case 4: - devpriv->ulConvertionRate = MPC624_SPEED_220_Hz; - rt_printk("220 Hz, "); - break; - case 5: - devpriv->ulConvertionRate = MPC624_SPEED_110_Hz; - rt_printk("110 Hz, "); - break; - case 6: - devpriv->ulConvertionRate = MPC624_SPEED_55_Hz; - rt_printk("55 Hz, "); - break; - case 7: - devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz; - rt_printk("27.5 Hz, "); - break; - case 8: - devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz; - rt_printk("13.75 Hz, "); - break; - case 9: - devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz; - rt_printk("6.875 Hz, "); - break; - default: - rt_printk("illegal convertion rate setting! Valid numbers are 0..9. Using 9 => 6.875 Hz, "); - devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; - } - - // Subdevices structures - if(alloc_subdevices(dev, 1) < 0) + + // Private structure initialization + if (alloc_private(dev, sizeof(skel_private)) < 0) + return -ENOMEM; + + switch (it->options[1]) { + case 0: + devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; + rt_printk("3.52 kHz, "); + break; + case 1: + devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz; + rt_printk("1.76 kHz, "); + break; + case 2: + devpriv->ulConvertionRate = MPC624_SPEED_880_Hz; + rt_printk("880 Hz, "); + break; + case 3: + devpriv->ulConvertionRate = MPC624_SPEED_440_Hz; + rt_printk("440 Hz, "); + break; + case 4: + devpriv->ulConvertionRate = MPC624_SPEED_220_Hz; + rt_printk("220 Hz, "); + break; + case 5: + devpriv->ulConvertionRate = MPC624_SPEED_110_Hz; + rt_printk("110 Hz, "); + break; + case 6: + devpriv->ulConvertionRate = MPC624_SPEED_55_Hz; + rt_printk("55 Hz, "); + break; + case 7: + devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz; + rt_printk("27.5 Hz, "); + break; + case 8: + devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz; + rt_printk("13.75 Hz, "); + break; + case 9: + devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz; + rt_printk("6.875 Hz, "); + break; + default: + rt_printk + ("illegal convertion rate setting! Valid numbers are 0..9. Using 9 => 6.875 Hz, "); + devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz; + } + + // Subdevices structures + if (alloc_subdevices(dev, 1) < 0) return -ENOMEM; - s=dev->subdevices+0; - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_DIFF; - s->n_chan=8; - switch(it->options[1]) - { - default: - s->maxdata=0x3FFFFFFF; - rt_printk("30 bit, "); - } - - switch(it->options[1]) - { - case 0: - s->range_table=&range_mpc624_bipolar1; - rt_printk("1.01V]: "); - break; - default: - s->range_table=&range_mpc624_bipolar10; - rt_printk("10.1V]: "); - } - s->len_chanlist=1; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_DIFF; + s->n_chan = 8; + switch (it->options[1]) { + default: + s->maxdata = 0x3FFFFFFF; + rt_printk("30 bit, "); + } + + switch (it->options[1]) { + case 0: + s->range_table = &range_mpc624_bipolar1; + rt_printk("1.01V]: "); + break; + default: + s->range_table = &range_mpc624_bipolar10; + rt_printk("10.1V]: "); + } + s->len_chanlist = 1; s->insn_read = mpc624_ai_rinsn; rt_printk("attached\n"); @@ -260,129 +255,126 @@ static int mpc624_attach(comedi_device *dev, comedi_devconfig *it) return 1; } -static int mpc624_detach(comedi_device *dev) +static int mpc624_detach(comedi_device * dev) { - rt_printk("comedi%d: mpc624: remove\n",dev->minor); - - if(dev->iobase) - release_region(dev->iobase, MPC624_SIZE); - + rt_printk("comedi%d: mpc624: remove\n", dev->minor); + + if (dev->iobase) + release_region(dev->iobase, MPC624_SIZE); + return 0; } // Timeout 200ms #define TIMEOUT 200 -static int mpc624_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int mpc624_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n, i; - unsigned long int data_in, data_out; - unsigned char ucPort; + unsigned long int data_in, data_out; + unsigned char ucPort; - // WARNING: We always write 0 to GNSWA bit, so the channel range is +-/10.1Vdc + // WARNING: We always write 0 to GNSWA bit, so the channel range is +-/10.1Vdc outb(insn->chanspec, dev->iobase + MPC624_GNMUXCH); // rt_printk("Channel %d: \n", insn->chanspec); - if(!insn->n) - { - rt_printk("MPC624: Warning, no data to aquire\n"); - return 0; - } - - for(n=0; n < insn->n; n++) - { - // Trigger the convertion - outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); - comedi_udelay(1); - outb(MPC624_ADCS | MPC624_ADSCK, dev->iobase + MPC624_ADC); - comedi_udelay(1); - outb(0, dev->iobase + MPC624_ADC); - comedi_udelay(1); - + if (!insn->n) { + rt_printk("MPC624: Warning, no data to aquire\n"); + return 0; + } + + for (n = 0; n < insn->n; n++) { + // Trigger the convertion + outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); + comedi_udelay(1); + outb(MPC624_ADCS | MPC624_ADSCK, dev->iobase + MPC624_ADC); + comedi_udelay(1); + outb(0, dev->iobase + MPC624_ADC); + comedi_udelay(1); + // Wait for the convertion to end - for(i=0; iiobase + MPC624_ADC); - if(ucPort & MPC624_ADBUSY) - comedi_udelay(1000); - else - break; + for (i = 0; i < TIMEOUT; i++) { + ucPort = inb(dev->iobase + MPC624_ADC); + if (ucPort & MPC624_ADBUSY) + comedi_udelay(1000); + else + break; } - if(i == TIMEOUT) - { + if (i == TIMEOUT) { rt_printk("MPC624: timeout (%dms)\n", TIMEOUT); data[n] = 0; return -ETIMEDOUT; } - // Start reading data - data_in = 0; - data_out = devpriv->ulConvertionRate; - comedi_udelay(1); - for(i = 0; i < 32; i++) - { - // Set the clock low - outb(0, dev->iobase + MPC624_ADC); - comedi_udelay(1); - - if(data_out & (1<<31)) // the next bit is a 1 - { - // Set the ADSDI line (send to MPC624) - outb(MPC624_ADSDI, dev->iobase + MPC624_ADC); - comedi_udelay(1); - // Set the clock high - outb(MPC624_ADSCK | MPC624_ADSDI, dev->iobase + MPC624_ADC); - } - else // the next bit is a 0 - { - // Set the ADSDI line (send to MPC624) - outb(0, dev->iobase + MPC624_ADC); - comedi_udelay(1); - // Set the clock high - outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); - } - // Read ADSDO on high clock (receive from MPC624) - comedi_udelay(1); - data_in <<= 1; - data_in |= (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4; - comedi_udelay(1); - - data_out <<= 1; - } - - // Received 32-bit long value consist of: - // 31: EOC (End Of Transmission) bit - should be 0 - // 30: DMY (Dummy) bit - should be 0 - // 29: SIG (Sign) bit - 1 if the voltage is positive, 0 if negative - // 28: MSB (Most Significant Bit) - the first bit of convertion result - // .... - // 05: LSB (Least Significant Bit) - the last bit of convertion result - // 04: sub-LSB - sub-LSBs are basically noise, but when - // 03: sub-LSB averaged properly, they can increase convertion - // 02: sub-LSB precision up to 29 bits; they can be discarded - // 01: sub-LSB without loss of resolution. - // 00: sub-LSB - - if(data_in & MPC624_EOC_BIT) - rt_printk("MPC624: EOC bit is set (data_in=%lu)!", data_in); - if(data_in & MPC624_DMY_BIT) - rt_printk("MPC624: DMY bit is set (data_in=%lu)!", data_in); - if(data_in & MPC624_SGN_BIT) // check the sign bit - { // The voltage is positive - data_in &= 0x3FFFFFFF; // EOC and DMY should be 0, but we will mask them out just to be sure - data[n] = data_in; // comedi operates on unsigned numbers, so we don't clear the SGN bit - // SGN bit is still set! It's correct, since we're converting to unsigned. - } - else - { // The voltage is negative - // data_in contains a number in 30-bit two's complement code and we must deal with it - data_in |= MPC624_SGN_BIT; - data_in = ~data_in; - data_in += 1; - data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT); - // clear EOC and DMY bits - data_in = 0x20000000 - data_in; - data[n] = data_in; - } + data_in = 0; + data_out = devpriv->ulConvertionRate; + comedi_udelay(1); + for (i = 0; i < 32; i++) { + // Set the clock low + outb(0, dev->iobase + MPC624_ADC); + comedi_udelay(1); + + if (data_out & (1 << 31)) // the next bit is a 1 + { + // Set the ADSDI line (send to MPC624) + outb(MPC624_ADSDI, dev->iobase + MPC624_ADC); + comedi_udelay(1); + // Set the clock high + outb(MPC624_ADSCK | MPC624_ADSDI, + dev->iobase + MPC624_ADC); + } else // the next bit is a 0 + { + // Set the ADSDI line (send to MPC624) + outb(0, dev->iobase + MPC624_ADC); + comedi_udelay(1); + // Set the clock high + outb(MPC624_ADSCK, dev->iobase + MPC624_ADC); + } + // Read ADSDO on high clock (receive from MPC624) + comedi_udelay(1); + data_in <<= 1; + data_in |= + (inb(dev->iobase + + MPC624_ADC) & MPC624_ADSDO) >> 4; + comedi_udelay(1); + + data_out <<= 1; + } + + // Received 32-bit long value consist of: + // 31: EOC (End Of Transmission) bit - should be 0 + // 30: DMY (Dummy) bit - should be 0 + // 29: SIG (Sign) bit - 1 if the voltage is positive, 0 if negative + // 28: MSB (Most Significant Bit) - the first bit of convertion result + // .... + // 05: LSB (Least Significant Bit) - the last bit of convertion result + // 04: sub-LSB - sub-LSBs are basically noise, but when + // 03: sub-LSB averaged properly, they can increase convertion + // 02: sub-LSB precision up to 29 bits; they can be discarded + // 01: sub-LSB without loss of resolution. + // 00: sub-LSB + + if (data_in & MPC624_EOC_BIT) + rt_printk("MPC624: EOC bit is set (data_in=%lu)!", + data_in); + if (data_in & MPC624_DMY_BIT) + rt_printk("MPC624: DMY bit is set (data_in=%lu)!", + data_in); + if (data_in & MPC624_SGN_BIT) // check the sign bit + { // The voltage is positive + data_in &= 0x3FFFFFFF; // EOC and DMY should be 0, but we will mask them out just to be sure + data[n] = data_in; // comedi operates on unsigned numbers, so we don't clear the SGN bit + // SGN bit is still set! It's correct, since we're converting to unsigned. + } else { // The voltage is negative + // data_in contains a number in 30-bit two's complement code and we must deal with it + data_in |= MPC624_SGN_BIT; + data_in = ~data_in; + data_in += 1; + data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT); + // clear EOC and DMY bits + data_in = 0x20000000 - data_in; + data[n] = data_in; + } } // Return the number of samples read/written diff --git a/comedi/drivers/mpc8260cpm.c b/comedi/drivers/mpc8260cpm.c index ca421a7a..b931ca1e 100644 --- a/comedi/drivers/mpc8260cpm.c +++ b/comedi/drivers/mpc8260cpm.c @@ -36,69 +36,71 @@ It is apparently missing some code. #include - extern unsigned long mpc8260_dio_reserved[4]; -typedef struct{ +typedef struct { int data; -}mpc8260cpm_private; +} mpc8260cpm_private; #define devpriv ((mpc8260cpm_private *)dev->private) -static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it); -static int mpc8260cpm_detach(comedi_device *dev); -static comedi_driver driver_mpc8260cpm={ - driver_name: "mpc8260cpm", - module: THIS_MODULE, - attach: mpc8260cpm_attach, - detach: mpc8260cpm_detach, +static int mpc8260cpm_attach(comedi_device * dev, comedi_devconfig * it); +static int mpc8260cpm_detach(comedi_device * dev); +static comedi_driver driver_mpc8260cpm = { + driver_name:"mpc8260cpm", + module:THIS_MODULE, + attach:mpc8260cpm_attach, + detach:mpc8260cpm_detach, }; + COMEDI_INITCLEANUP(driver_mpc8260cpm); -static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int mpc8260cpm_dio_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int mpc8260cpm_dio_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it) +static int mpc8260cpm_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int i; - printk("comedi%d: mpc8260cpm: ",dev->minor); - + printk("comedi%d: mpc8260cpm: ", dev->minor); + dev->board_ptr = mpc8260cpm_boards + dev->board; dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(mpc8260cpm_private))<0) + if (alloc_private(dev, sizeof(mpc8260cpm_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev,4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - for(i=0;i<4;i++){ - s=dev->subdevices+i; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=32; - s->maxdata=1; - s->range_table=&range_digital; + for (i = 0; i < 4; i++) { + s = dev->subdevices + i; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 32; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_config = mpc8260cpm_dio_config; s->insn_bits = mpc8260cpm_dio_bits; } - + return 1; } -static int mpc8260cpm_detach(comedi_device *dev) +static int mpc8260cpm_detach(comedi_device * dev) { - printk("comedi%d: mpc8260cpm: remove\n",dev->minor); - + printk("comedi%d: mpc8260cpm: remove\n", dev->minor); + return 0; } static unsigned long *cpm_pdat(int port) { - switch(port){ + switch (port) { case 0: return &io->iop_pdata; case 1: @@ -110,7 +112,8 @@ static unsigned long *cpm_pdat(int port) } } -static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int mpc8260cpm_dio_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; unsigned int d; @@ -118,12 +121,12 @@ static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_i int port; port = (int)s->private; - mask = 1<chanspec); - if(mask&cpm_reserved_bits[port]){ + mask = 1 << CR_CHAN(insn->chanspec); + if (mask & cpm_reserved_bits[port]) { return -EINVAL; } - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: s->io_bits |= mask; break; @@ -131,34 +134,34 @@ static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_i s->io_bits &= ~mask; break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: return -EINVAL; } - switch(port){ - case 0: return &io->iop_pdira; - case 1: return &io->iop_pdirb; - case 2: return &io->iop_pdirc; - case 3: return &io->iop_pdird; + switch (port) { + case 0: + return &io->iop_pdira; + case 1: + return &io->iop_pdirb; + case 2: + return &io->iop_pdirc; + case 3: + return &io->iop_pdird; } - return 1; } -static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int mpc8260cpm_dio_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int port; unsigned long *p; - - p = cpm_pdat((int)s->private); - - + p = cpm_pdat((int)s->private); return 2; } - diff --git a/comedi/drivers/multiq3.c b/comedi/drivers/multiq3.c index 9d457628..63644b18 100644 --- a/comedi/drivers/multiq3.c +++ b/comedi/drivers/multiq3.c @@ -33,7 +33,6 @@ Devices: [Quanser Consulting] MultiQ-3 (multiq3) #include - #define MULTIQ3_SIZE 16 /* @@ -83,45 +82,49 @@ Devices: [Quanser Consulting] MultiQ-3 (multiq3) #define MULTIQ3_TIMEOUT 30 -static int multiq3_attach(comedi_device *dev,comedi_devconfig *it); -static int multiq3_detach(comedi_device *dev); -static comedi_driver driver_multiq3={ - driver_name: "multiq3", - module: THIS_MODULE, - attach: multiq3_attach, - detach: multiq3_detach, +static int multiq3_attach(comedi_device * dev, comedi_devconfig * it); +static int multiq3_detach(comedi_device * dev); +static comedi_driver driver_multiq3 = { + driver_name:"multiq3", + module:THIS_MODULE, + attach:multiq3_attach, + detach:multiq3_detach, }; + COMEDI_INITCLEANUP(driver_multiq3); -struct multiq3_private{ +struct multiq3_private { lsampl_t ao_readback[2]; }; #define devpriv ((struct multiq3_private *)dev->private) -static int multiq3_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,n; + int i, n; int chan; unsigned int hi, lo; chan = CR_CHAN(insn->chanspec); - outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan<<3), - dev->iobase+MULTIQ3_CONTROL); + outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3), + dev->iobase + MULTIQ3_CONTROL); - for(i = 0; i < MULTIQ3_TIMEOUT; i++) { - if(inw(dev->iobase+MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC) + for (i = 0; i < MULTIQ3_TIMEOUT; i++) { + if (inw(dev->iobase + MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC) break; } - if(i==MULTIQ3_TIMEOUT)return -ETIMEDOUT; - - for(n=0;nn;n++){ - outw(0, dev->iobase+MULTIQ3_AD_CS); - for(i = 0; i < MULTIQ3_TIMEOUT; i++) { - if(inw(dev->iobase+MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC_I) + if (i == MULTIQ3_TIMEOUT) + return -ETIMEDOUT; + + for (n = 0; n < insn->n; n++) { + outw(0, dev->iobase + MULTIQ3_AD_CS); + for (i = 0; i < MULTIQ3_TIMEOUT; i++) { + if (inw(dev->iobase + + MULTIQ3_STATUS) & MULTIQ3_STATUS_EOC_I) break; } - if(i==MULTIQ3_TIMEOUT)return -ETIMEDOUT; + if (i == MULTIQ3_TIMEOUT) + return -ETIMEDOUT; hi = inb(dev->iobase + MULTIQ3_AD_CS); lo = inb(dev->iobase + MULTIQ3_AD_CS); @@ -131,30 +134,30 @@ static int multiq3_ai_insn_read(comedi_device *dev,comedi_subdevice *s, return n; } -static int multiq3_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[chan]; + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[chan]; } return i; } -static int multiq3_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { outw(MULTIQ3_CONTROL_MUST | MULTIQ3_DA_LOAD | chan, - dev->iobase+MULTIQ3_CONTROL); - outw(data[i], dev->iobase+MULTIQ3_DAC_DATA); - outw(MULTIQ3_CONTROL_MUST, dev->iobase+MULTIQ3_CONTROL); + dev->iobase + MULTIQ3_CONTROL); + outw(data[i], dev->iobase + MULTIQ3_DAC_DATA); + outw(MULTIQ3_CONTROL_MUST, dev->iobase + MULTIQ3_CONTROL); devpriv->ao_readback[chan] = data[i]; } @@ -162,64 +165,68 @@ static int multiq3_ao_insn_write(comedi_device *dev, comedi_subdevice *s, return i; } -static int multiq3_di_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1] = inw(dev->iobase + MULTIQ3_DIGIN_PORT); + data[1] = inw(dev->iobase + MULTIQ3_DIGIN_PORT); - return 2; + return 2; } -static int multiq3_do_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - outw(s->state, dev->iobase + MULTIQ3_DIGOUT_PORT); + s->state &= ~data[0]; + s->state |= (data[0] & data[1]); + outw(s->state, dev->iobase + MULTIQ3_DIGOUT_PORT); - data[1] = s->state; + data[1] = s->state; - return 2; + return 2; } -static int multiq3_encoder_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int multiq3_encoder_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int chan = CR_CHAN(insn->chanspec); - int control = MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan<<3); - - for(n=0;nn;n++){ - int value; - outw(control, dev->iobase+MULTIQ3_CONTROL); - outb(MULTIQ3_BP_RESET, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase+MULTIQ3_ENC_CONTROL); - value = inb(dev->iobase+MULTIQ3_ENC_DATA); - value |= (inb(dev->iobase+MULTIQ3_ENC_DATA)<<8); - value |= (inb(dev->iobase+MULTIQ3_ENC_DATA)<<16); - data[n] = (value + 0x800000) & 0xffffff; + int control = MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3); + + for (n = 0; n < insn->n; n++) { + int value; + outw(control, dev->iobase + MULTIQ3_CONTROL); + outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase + MULTIQ3_ENC_CONTROL); + value = inb(dev->iobase + MULTIQ3_ENC_DATA); + value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 8); + value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 16); + data[n] = (value + 0x800000) & 0xffffff; } return n; } -static void encoder_reset(comedi_device *dev) { - int chan; - for (chan = 0 ; chan < dev->subdevices[4].n_chan ; chan++) { - int control = MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan<<3); - outw(control, dev->iobase+MULTIQ3_CONTROL); - outb(MULTIQ3_EFLAG_RESET, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_BP_RESET, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_CLOCK_DATA, dev->iobase+MULTIQ3_ENC_DATA); - outb(MULTIQ3_CLOCK_SETUP, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_INPUT_SETUP, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_QUAD_X4, dev->iobase+MULTIQ3_ENC_CONTROL); - outb(MULTIQ3_CNTR_RESET, dev->iobase+MULTIQ3_ENC_CONTROL); - } +static void encoder_reset(comedi_device * dev) +{ + int chan; + for (chan = 0; chan < dev->subdevices[4].n_chan; chan++) { + int control = + MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3); + outw(control, dev->iobase + MULTIQ3_CONTROL); + outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA); + outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CONTROL); + outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CONTROL); + } } /* @@ -230,93 +237,97 @@ static void encoder_reset(comedi_device *dev) { static int multiq3_attach(comedi_device * dev, comedi_devconfig * it) { - int result = 0; - unsigned long iobase; - unsigned int irq; - comedi_subdevice *s; - - iobase = it->options[0]; - printk("comedi%d: multiq3: 0x%04lx ", dev->minor, iobase); - if (!request_region(iobase, MULTIQ3_SIZE, "multiq3")) { - printk("comedi%d: I/O port conflict\n", dev->minor); - return -EIO; - } - - dev->iobase = iobase; - - irq = it->options[1]; - if (irq) { - printk("comedi%d: irq = %u ignored\n", dev->minor, irq); - } else { - printk("comedi%d: no irq\n", dev->minor); - } - dev->board_name = "multiq3"; - result = alloc_subdevices(dev, 5); - if(result<0)return result; - - result = alloc_private(dev,sizeof(struct multiq3_private)); - if(result<0)return result; - - s = dev->subdevices + 0; - /* ai subdevice */ - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_GROUND; - s->n_chan = 8; - s->insn_read = multiq3_ai_insn_read; - s->maxdata = 0x1fff; - s->range_table = &range_bipolar5; - - s = dev->subdevices + 1; - /* ao subdevice */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 8; - s->insn_read = multiq3_ao_insn_read; - s->insn_write = multiq3_ao_insn_write; - s->maxdata = 0xfff; - s->range_table = &range_bipolar5; - - s = dev->subdevices + 2; - /* di subdevice */ - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 16; - s->insn_bits = multiq3_di_insn_bits; - s->maxdata = 1; - s->range_table = &range_digital; - - s = dev->subdevices + 3; - /* do subdevice */ - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = 16; - s->insn_bits = multiq3_do_insn_bits; - s->maxdata = 1; - s->range_table = &range_digital; - s->state = 0; - - s = dev->subdevices + 4; - /* encoder (counter) subdevice */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_LSAMPL; - s->n_chan = it->options[2] * 2; - s->insn_read = multiq3_encoder_insn_read; - s->maxdata = 0xffffff; - s->range_table = &range_unknown; - - encoder_reset(dev); - - return 0; -} + int result = 0; + unsigned long iobase; + unsigned int irq; + comedi_subdevice *s; + + iobase = it->options[0]; + printk("comedi%d: multiq3: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, MULTIQ3_SIZE, "multiq3")) { + printk("comedi%d: I/O port conflict\n", dev->minor); + return -EIO; + } + + dev->iobase = iobase; + irq = it->options[1]; + if (irq) { + printk("comedi%d: irq = %u ignored\n", dev->minor, irq); + } else { + printk("comedi%d: no irq\n", dev->minor); + } + dev->board_name = "multiq3"; + result = alloc_subdevices(dev, 5); + if (result < 0) + return result; + + result = alloc_private(dev, sizeof(struct multiq3_private)); + if (result < 0) + return result; + + s = dev->subdevices + 0; + /* ai subdevice */ + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 8; + s->insn_read = multiq3_ai_insn_read; + s->maxdata = 0x1fff; + s->range_table = &range_bipolar5; + + s = dev->subdevices + 1; + /* ao subdevice */ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->insn_read = multiq3_ao_insn_read; + s->insn_write = multiq3_ao_insn_write; + s->maxdata = 0xfff; + s->range_table = &range_bipolar5; + + s = dev->subdevices + 2; + /* di subdevice */ + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 16; + s->insn_bits = multiq3_di_insn_bits; + s->maxdata = 1; + s->range_table = &range_digital; + + s = dev->subdevices + 3; + /* do subdevice */ + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 16; + s->insn_bits = multiq3_do_insn_bits; + s->maxdata = 1; + s->range_table = &range_digital; + s->state = 0; + + s = dev->subdevices + 4; + /* encoder (counter) subdevice */ + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_LSAMPL; + s->n_chan = it->options[2] * 2; + s->insn_read = multiq3_encoder_insn_read; + s->maxdata = 0xffffff; + s->range_table = &range_unknown; + + encoder_reset(dev); + + return 0; +} static int multiq3_detach(comedi_device * dev) { - printk("comedi%d: multiq3: remove\n", dev->minor); + printk("comedi%d: multiq3: remove\n", dev->minor); - if (dev->iobase) { release_region(dev->iobase, MULTIQ3_SIZE); } - if (dev->irq) { free_irq(dev->irq,dev); } + if (dev->iobase) { + release_region(dev->iobase, MULTIQ3_SIZE); + } + if (dev->irq) { + free_irq(dev->irq, dev); + } - return 0; + return 0; } - diff --git a/comedi/drivers/ni_6527.c b/comedi/drivers/ni_6527.c index 2b5c5677..01dff1c5 100644 --- a/comedi/drivers/ni_6527.c +++ b/comedi/drivers/ni_6527.c @@ -45,11 +45,9 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800 #include "mite.h" - #define NI6527_DIO_SIZE 4096 #define NI6527_MITE_SIZE 4096 - #define Port_Register(x) (0x00+(x)) #define ID_Register 0x06 @@ -77,119 +75,135 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800 #define Rising_Edge_Detection_Enable(x) (0x018+(x)) #define Falling_Edge_Detection_Enable(x) (0x020+(x)) - - -static int ni6527_attach(comedi_device *dev,comedi_devconfig *it); -static int ni6527_detach(comedi_device *dev); -static comedi_driver driver_ni6527={ - driver_name: "ni6527", - module: THIS_MODULE, - attach: ni6527_attach, - detach: ni6527_detach, +static int ni6527_attach(comedi_device * dev, comedi_devconfig * it); +static int ni6527_detach(comedi_device * dev); +static comedi_driver driver_ni6527 = { + driver_name:"ni6527", + module:THIS_MODULE, + attach:ni6527_attach, + detach:ni6527_detach, }; + COMEDI_INITCLEANUP(driver_ni6527); -typedef struct{ +typedef struct { int dev_id; const char *name; -}ni6527_board; +} ni6527_board; static const ni6527_board ni6527_boards[] = { { - dev_id: 0x2b20, - name: "pci-6527", - }, + dev_id: 0x2b20, + name: "pci-6527", + }, { - dev_id: 0x2b10, - name: "pxi-6527", - }, + dev_id: 0x2b10, + name: "pxi-6527", + }, }; #define n_ni6527_boards (sizeof(ni6527_boards)/sizeof(ni6527_boards[0])) #define this_board ((const ni6527_board *)dev->board_ptr) static struct pci_device_id ni6527_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x2b10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2b20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x2b10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2b20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, ni6527_pci_table); -typedef struct{ +typedef struct { struct mite_struct *mite; unsigned int filter_interval; unsigned int filter_enable; -}ni6527_private; +} ni6527_private; #define devpriv ((ni6527_private *)dev->private) -static int ni6527_find_device(comedi_device *dev,int bus,int slot); - +static int ni6527_find_device(comedi_device * dev, int bus, int slot); -static int ni6527_di_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni6527_di_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); unsigned int interval; - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0] != INSN_CONFIG_FILTER)return -EINVAL; + if (data[0] != INSN_CONFIG_FILTER) + return -EINVAL; - if(data[1]){ - interval = (data[1]+100)/200; - data[1] = interval*200; + if (data[1]) { + interval = (data[1] + 100) / 200; + data[1] = interval * 200; - if(interval!=devpriv->filter_interval){ - writeb(interval&0xff, devpriv->mite->daq_io_addr + Filter_Interval(0)); - writeb((interval>>8)&0xff, devpriv->mite->daq_io_addr + Filter_Interval(1)); - writeb((interval>>16)&0x0f, devpriv->mite->daq_io_addr + Filter_Interval(2)); + if (interval != devpriv->filter_interval) { + writeb(interval & 0xff, + devpriv->mite->daq_io_addr + + Filter_Interval(0)); + writeb((interval >> 8) & 0xff, + devpriv->mite->daq_io_addr + + Filter_Interval(1)); + writeb((interval >> 16) & 0x0f, + devpriv->mite->daq_io_addr + + Filter_Interval(2)); - writeb(ClrInterval, devpriv->mite->daq_io_addr + Clear_Register); + writeb(ClrInterval, + devpriv->mite->daq_io_addr + Clear_Register); devpriv->filter_interval = interval; } - devpriv->filter_enable |= 1<filter_enable &= ~(1<filter_enable |= 1 << chan; + } else { + devpriv->filter_enable &= ~(1 << chan); } - writeb(devpriv->filter_enable, devpriv->mite->daq_io_addr + Filter_Enable(0)); - writeb(devpriv->filter_enable>>8, devpriv->mite->daq_io_addr + Filter_Enable(1)); - writeb(devpriv->filter_enable>>16, devpriv->mite->daq_io_addr + Filter_Enable(2)); + writeb(devpriv->filter_enable, + devpriv->mite->daq_io_addr + Filter_Enable(0)); + writeb(devpriv->filter_enable >> 8, + devpriv->mite->daq_io_addr + Filter_Enable(1)); + writeb(devpriv->filter_enable >> 16, + devpriv->mite->daq_io_addr + Filter_Enable(2)); return 2; } -static int ni6527_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni6527_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1] = readb(devpriv->mite->daq_io_addr+Port_Register(0)); - data[1] |= readb(devpriv->mite->daq_io_addr+Port_Register(1))<<8; - data[1] |= readb(devpriv->mite->daq_io_addr+Port_Register(2))<<16; + data[1] = readb(devpriv->mite->daq_io_addr + Port_Register(0)); + data[1] |= readb(devpriv->mite->daq_io_addr + Port_Register(1)) << 8; + data[1] |= readb(devpriv->mite->daq_io_addr + Port_Register(2)) << 16; return 2; } -static int ni6527_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni6527_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); /* The open relay state on the board cooresponds to 1, * but in Comedi, it is represented by 0. */ - if(data[0]&0x0000ff){ - writeb((s->state^0xff),devpriv->mite->daq_io_addr+Port_Register(3)); + if (data[0] & 0x0000ff) { + writeb((s->state ^ 0xff), + devpriv->mite->daq_io_addr + Port_Register(3)); } - if(data[0]&0x00ff00){ - writeb((s->state>>8)^0xff,devpriv->mite->daq_io_addr+Port_Register(4)); + if (data[0] & 0x00ff00) { + writeb((s->state >> 8) ^ 0xff, + devpriv->mite->daq_io_addr + Port_Register(4)); } - if(data[0]&0xff0000){ - writeb((s->state>>16)^0xff,devpriv->mite->daq_io_addr+Port_Register(5)); + if (data[0] & 0xff0000) { + writeb((s->state >> 16) ^ 0xff, + devpriv->mite->daq_io_addr + Port_Register(5)); } } data[1] = s->state; @@ -204,10 +218,13 @@ static irqreturn_t ni6527_interrupt(int irq, void *d PT_REGS_ARG) unsigned int status; status = readb(devpriv->mite->daq_io_addr + Change_Status); - if((status & MasterInterruptStatus) == 0) return IRQ_NONE; - if((status & EdgeStatus) == 0) return IRQ_NONE; + if ((status & MasterInterruptStatus) == 0) + return IRQ_NONE; + if ((status & EdgeStatus) == 0) + return IRQ_NONE; - writeb(ClrEdge | ClrOverflow, devpriv->mite->daq_io_addr + Clear_Register); + writeb(ClrEdge | ClrOverflow, + devpriv->mite->daq_io_addr + Clear_Register); comedi_buf_put(s->async, 0); s->async->events |= COMEDI_CB_EOS; @@ -215,171 +232,189 @@ static irqreturn_t ni6527_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static int ni6527_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int ni6527_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_OTHER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_FOLLOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=1){ - cmd->scan_end_arg=1; + if (cmd->scan_end_arg != 1) { + cmd->scan_end_arg = 1; err++; } - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(err)return 4; + if (err) + return 4; return 0; } -static int ni6527_intr_cmd(comedi_device *dev,comedi_subdevice *s) +static int ni6527_intr_cmd(comedi_device * dev, comedi_subdevice * s) { //comedi_cmd *cmd = &s->async->cmd; - writeb(ClrEdge|ClrOverflow, devpriv->mite->daq_io_addr + Clear_Register); - writeb(FallingEdgeIntEnable|RisingEdgeIntEnable| - MasterInterruptEnable|EdgeIntEnable, + writeb(ClrEdge | ClrOverflow, + devpriv->mite->daq_io_addr + Clear_Register); + writeb(FallingEdgeIntEnable | RisingEdgeIntEnable | + MasterInterruptEnable | EdgeIntEnable, devpriv->mite->daq_io_addr + Master_Interrupt_Control); return 0; } -static int ni6527_intr_cancel(comedi_device *dev,comedi_subdevice *s) +static int ni6527_intr_cancel(comedi_device * dev, comedi_subdevice * s) { writeb(0x00, devpriv->mite->daq_io_addr + Master_Interrupt_Control); return 0; } -static int ni6527_intr_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni6527_intr_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n < 1)return -EINVAL; + if (insn->n < 1) + return -EINVAL; data[1] = 0; return 2; } -static int ni6527_intr_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni6527_intr_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n < 1)return -EINVAL; - if(data[0] != INSN_CONFIG_CHANGE_NOTIFY)return -EINVAL; - - writeb(data[1], devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(0)); - writeb(data[1]>>8, devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(1)); - writeb(data[1]>>16, devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(2)); - - writeb(data[2], devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(0)); - writeb(data[2]>>8, devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(1)); - writeb(data[2]>>16, devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(2)); + if (insn->n < 1) + return -EINVAL; + if (data[0] != INSN_CONFIG_CHANGE_NOTIFY) + return -EINVAL; + + writeb(data[1], + devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(0)); + writeb(data[1] >> 8, + devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(1)); + writeb(data[1] >> 16, + devpriv->mite->daq_io_addr + Rising_Edge_Detection_Enable(2)); + + writeb(data[2], + devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(0)); + writeb(data[2] >> 8, + devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(1)); + writeb(data[2] >> 16, + devpriv->mite->daq_io_addr + Falling_Edge_Detection_Enable(2)); return 2; } - -static int ni6527_attach(comedi_device *dev,comedi_devconfig *it) +static int ni6527_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int ret; - printk("comedi%d: ni6527:",dev->minor); + printk("comedi%d: ni6527:", dev->minor); - if((ret=alloc_private(dev,sizeof(ni6527_private)))<0) + if ((ret = alloc_private(dev, sizeof(ni6527_private))) < 0) return ret; - ret=ni6527_find_device(dev,it->options[0],it->options[1]); - if(ret<0)return ret; + ret = ni6527_find_device(dev, it->options[0], it->options[1]); + if (ret < 0) + return ret; ret = mite_setup(devpriv->mite); - if(ret < 0) - { + if (ret < 0) { printk("error setting up mite\n"); return ret; } - dev->board_name=this_board->name; - printk(" %s",dev->board_name); + dev->board_name = this_board->name; + printk(" %s", dev->board_name); printk(" ID=0x%02x", readb(devpriv->mite->daq_io_addr + ID_Register)); - if((ret=alloc_subdevices(dev,3))<0) + if ((ret = alloc_subdevices(dev, 3)) < 0) return ret; - s=dev->subdevices+0; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->n_chan=24; - s->range_table=&range_digital; - s->maxdata=1; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 24; + s->range_table = &range_digital; + s->maxdata = 1; s->insn_config = ni6527_di_insn_config; s->insn_bits = ni6527_di_insn_bits; - s=dev->subdevices+1; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=24; - s->range_table=&range_unknown; /* FIXME: actually conductance */ - s->maxdata=1; + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 24; + s->range_table = &range_unknown; /* FIXME: actually conductance */ + s->maxdata = 1; s->insn_bits = ni6527_do_insn_bits; - s=dev->subdevices + 2; + s = dev->subdevices + 2; dev->read_subdev = s; - s->type=COMEDI_SUBD_DI; + s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; - s->n_chan=1; - s->range_table=&range_unknown; - s->maxdata=1; + s->n_chan = 1; + s->range_table = &range_unknown; + s->maxdata = 1; s->do_cmdtest = ni6527_intr_cmdtest; s->do_cmd = ni6527_intr_cmd; s->cancel = ni6527_intr_cancel; @@ -390,14 +425,15 @@ static int ni6527_attach(comedi_device *dev,comedi_devconfig *it) writeb(0x00, devpriv->mite->daq_io_addr + Filter_Enable(1)); writeb(0x00, devpriv->mite->daq_io_addr + Filter_Enable(2)); - writeb(ClrEdge|ClrOverflow|ClrFilter|ClrInterval, + writeb(ClrEdge | ClrOverflow | ClrFilter | ClrInterval, devpriv->mite->daq_io_addr + Clear_Register); writeb(0x00, devpriv->mite->daq_io_addr + Master_Interrupt_Control); - ret = comedi_request_irq(mite_irq(devpriv->mite), ni6527_interrupt, IRQF_SHARED, "ni6527", dev); - if(ret<0){ + ret = comedi_request_irq(mite_irq(devpriv->mite), ni6527_interrupt, + IRQF_SHARED, "ni6527", dev); + if (ret < 0) { printk(" irq not available"); - }else + } else dev->irq = mite_irq(devpriv->mite); printk("\n"); @@ -405,39 +441,41 @@ static int ni6527_attach(comedi_device *dev,comedi_devconfig *it) return 0; } -static int ni6527_detach(comedi_device *dev) +static int ni6527_detach(comedi_device * dev) { - if(devpriv && devpriv->mite && devpriv->mite->daq_io_addr){ - writeb(0x00, devpriv->mite->daq_io_addr + Master_Interrupt_Control); + if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr) { + writeb(0x00, + devpriv->mite->daq_io_addr + Master_Interrupt_Control); } - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } - if(devpriv && devpriv->mite){ + if (devpriv && devpriv->mite) { mite_unsetup(devpriv->mite); } return 0; } -static int ni6527_find_device(comedi_device *dev,int bus,int slot) +static int ni6527_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for(mite=mite_devices;mite;mite=mite->next){ - if(mite->used)continue; - if(bus || slot){ - if(bus!=mite->pcidev->bus->number || - slot!=PCI_SLOT(mite->pcidev->devfn)) + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number || + slot != PCI_SLOT(mite->pcidev->devfn)) continue; } - for(i=0;iboard_ptr = ni6527_boards + i; - devpriv->mite=mite; + devpriv->mite = mite; return 0; } } @@ -446,4 +484,3 @@ static int ni6527_find_device(comedi_device *dev,int bus,int slot) mite_list_devices(); return -EIO; } - diff --git a/comedi/drivers/ni_65xx.c b/comedi/drivers/ni_65xx.c index 63bfd2ec..227c323b 100644 --- a/comedi/drivers/ni_65xx.c +++ b/comedi/drivers/ni_65xx.c @@ -54,7 +54,6 @@ except maybe the 6514. #include "mite.h" - #define NI6514_DIO_SIZE 4096 #define NI6514_MITE_SIZE 4096 @@ -82,6 +81,7 @@ static inline unsigned Filter_Enable(unsigned port) { return 0x44 + port * ni_65xx_port_offset; } + #define ID_Register 0x00 #define Clear_Register 0x01 @@ -102,162 +102,146 @@ static inline unsigned Filter_Enable(unsigned port) #define OverflowIntEnable 0x02 #define EdgeIntEnable 0x01 -static int ni_65xx_attach(comedi_device *dev,comedi_devconfig *it); -static int ni_65xx_detach(comedi_device *dev); -static comedi_driver driver_ni_65xx={ - driver_name: "ni_65xx", - module: THIS_MODULE, - attach: ni_65xx_attach, - detach: ni_65xx_detach, +static int ni_65xx_attach(comedi_device * dev, comedi_devconfig * it); +static int ni_65xx_detach(comedi_device * dev); +static comedi_driver driver_ni_65xx = { + driver_name:"ni_65xx", + module:THIS_MODULE, + attach:ni_65xx_attach, + detach:ni_65xx_detach, }; + COMEDI_INITCLEANUP(driver_ni_65xx); -typedef struct{ +typedef struct { int dev_id; const char *name; unsigned num_dio_ports; unsigned num_di_ports; unsigned num_do_ports; - unsigned invert_outputs : 1; -}ni_65xx_board; + unsigned invert_outputs:1; +} ni_65xx_board; static const ni_65xx_board ni_65xx_boards[] = { { - dev_id: 0x7085, - name: "pci-6509", - num_dio_ports: 12, - invert_outputs: 0 - }, - { - dev_id: 0x1710, - name: "pxi-6509", - num_dio_ports: 12, - invert_outputs: 0 - }, - { - dev_id: 0x7124, - name: "pci-6510", - num_di_ports: 4 - }, - { - dev_id: 0x70c3, - name: "pci-6511", - num_di_ports: 8 - }, - { - dev_id: 0x70d3, - name: "pxi-6511", - num_di_ports: 8 - }, - { - dev_id: 0x70cc, - name: "pci-6512", - num_do_ports: 8 - }, - { - dev_id: 0x70d2, - name: "pxi-6512", - num_do_ports: 8 - }, - { - dev_id: 0x70c8, - name: "pci-6513", - num_do_ports: 8, - invert_outputs: 1 - }, - { - dev_id: 0x70d1, - name: "pxi-6513", - num_do_ports: 8, - invert_outputs: 1 - }, - { - dev_id: 0x7088, - name: "pci-6514", - num_di_ports: 4, - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x70CD, - name: "pxi-6514", - num_di_ports: 4, - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x7087, - name: "pci-6515", - num_di_ports: 4, - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x70c9, - name: "pxi-6515", - num_di_ports: 4, - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x7125, - name: "pci-6516", - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x7126, - name: "pci-6517", - num_do_ports: 4, - invert_outputs: 1 - }, - { - dev_id: 0x7127, - name: "pci-6518", - num_di_ports: 2, - num_do_ports: 2, - invert_outputs: 1 - }, - { - dev_id: 0x7128, - name: "pci-6519", - num_di_ports: 2, - num_do_ports: 2, - invert_outputs: 1 - }, - { - dev_id: 0x71c5, - name: "pci-6520", - num_di_ports: 1, - num_do_ports: 1, - }, - { - dev_id: 0x718b, - name: "pci-6521", - num_di_ports: 1, - num_do_ports: 1, - }, - { - dev_id: 0x718c, - name: "pxi-6521", - num_di_ports: 1, - num_do_ports: 1, - }, - { - dev_id: 0x70a9, - name: "pci-6528", - num_di_ports: 3, - num_do_ports: 3, - }, - { - dev_id: 0x7086, - name: "pxi-6528", - num_di_ports: 3, - num_do_ports: 3, - }, + dev_id: 0x7085, + name: "pci-6509", + num_dio_ports:12, + invert_outputs:0}, + { + dev_id: 0x1710, + name: "pxi-6509", + num_dio_ports:12, + invert_outputs:0}, + { + dev_id: 0x7124, + name: "pci-6510", + num_di_ports:4}, + { + dev_id: 0x70c3, + name: "pci-6511", + num_di_ports:8}, + { + dev_id: 0x70d3, + name: "pxi-6511", + num_di_ports:8}, + { + dev_id: 0x70cc, + name: "pci-6512", + num_do_ports:8}, + { + dev_id: 0x70d2, + name: "pxi-6512", + num_do_ports:8}, + { + dev_id: 0x70c8, + name: "pci-6513", + num_do_ports:8, + invert_outputs:1}, + { + dev_id: 0x70d1, + name: "pxi-6513", + num_do_ports:8, + invert_outputs:1}, + { + dev_id: 0x7088, + name: "pci-6514", + num_di_ports:4, + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x70CD, + name: "pxi-6514", + num_di_ports:4, + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x7087, + name: "pci-6515", + num_di_ports:4, + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x70c9, + name: "pxi-6515", + num_di_ports:4, + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x7125, + name: "pci-6516", + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x7126, + name: "pci-6517", + num_do_ports:4, + invert_outputs:1}, + { + dev_id: 0x7127, + name: "pci-6518", + num_di_ports:2, + num_do_ports:2, + invert_outputs:1}, + { + dev_id: 0x7128, + name: "pci-6519", + num_di_ports:2, + num_do_ports:2, + invert_outputs:1}, + { + dev_id: 0x71c5, + name: "pci-6520", + num_di_ports:1, + num_do_ports:1, + }, + { + dev_id: 0x718b, + name: "pci-6521", + num_di_ports:1, + num_do_ports:1, + }, + { + dev_id: 0x718c, + name: "pxi-6521", + num_di_ports:1, + num_do_ports:1, + }, + { + dev_id: 0x70a9, + name: "pci-6528", + num_di_ports:3, + num_do_ports:3, + }, + { + dev_id: 0x7086, + name: "pxi-6528", + num_di_ports:3, + num_do_ports:3, + }, }; #define n_ni_65xx_boards (sizeof(ni_65xx_boards)/sizeof(ni_65xx_boards[0])) -static inline const ni_65xx_board* board(comedi_device *dev) +static inline const ni_65xx_board *board(comedi_device * dev) { return dev->board_ptr; } @@ -265,124 +249,138 @@ static inline unsigned ni_65xx_port_by_channel(unsigned channel) { return channel / ni_65xx_channels_per_port; } -static inline unsigned ni_65xx_total_num_ports(const ni_65xx_board *board) +static inline unsigned ni_65xx_total_num_ports(const ni_65xx_board * board) { return board->num_dio_ports + board->num_di_ports + board->num_do_ports; } static struct pci_device_id ni_65xx_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x1710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7085, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7086, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7087, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7088, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70a9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70c3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70c8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70c9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70CD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70d2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70d3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7126, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7127, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x7128, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x718b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x718c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x71c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x1710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7085, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7086, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7087, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7088, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70a9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70c3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70c8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70c9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70CD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70d2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70d3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7126, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7127, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x7128, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x718b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x718c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x71c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, ni_65xx_pci_table); -typedef struct{ +typedef struct { struct mite_struct *mite; unsigned int filter_interval; unsigned short filter_enable[NI_65XX_MAX_NUM_PORTS]; unsigned short output_bits[NI_65XX_MAX_NUM_PORTS]; unsigned short dio_direction[NI_65XX_MAX_NUM_PORTS]; -}ni_65xx_private; -static inline ni_65xx_private* private(comedi_device *dev) +} ni_65xx_private; +static inline ni_65xx_private *private(comedi_device * dev) { return dev->private; } -typedef struct -{ +typedef struct { unsigned base_port; -}ni_65xx_subdevice_private; -static inline ni_65xx_subdevice_private* sprivate(comedi_subdevice *subdev) +} ni_65xx_subdevice_private; +static inline ni_65xx_subdevice_private *sprivate(comedi_subdevice * subdev) { return subdev->private; } -static ni_65xx_subdevice_private* ni_65xx_alloc_subdevice_private(void) +static ni_65xx_subdevice_private *ni_65xx_alloc_subdevice_private(void) { - ni_65xx_subdevice_private *subdev_private = kzalloc(sizeof(ni_65xx_subdevice_private), GFP_KERNEL); - if(subdev_private == NULL) return NULL; + ni_65xx_subdevice_private *subdev_private = + kzalloc(sizeof(ni_65xx_subdevice_private), GFP_KERNEL); + if (subdev_private == NULL) + return NULL; return subdev_private; } -static int ni_65xx_find_device(comedi_device *dev,int bus,int slot); +static int ni_65xx_find_device(comedi_device * dev, int bus, int slot); -static int ni_65xx_config_filter(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_65xx_config_filter(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { const unsigned chan = CR_CHAN(insn->chanspec); - const unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan); + const unsigned port = + sprivate(s)->base_port + ni_65xx_port_by_channel(chan); - if(data[0] != INSN_CONFIG_FILTER) return -EINVAL; - if(data[1]) - { + if (data[0] != INSN_CONFIG_FILTER) + return -EINVAL; + if (data[1]) { static const unsigned filter_resolution_ns = 200; static const unsigned max_filter_interval = 0xfffff; - unsigned interval = (data[1] + (filter_resolution_ns / 2)) / filter_resolution_ns; - if(interval > max_filter_interval) interval = max_filter_interval; + unsigned interval = + (data[1] + + (filter_resolution_ns / 2)) / filter_resolution_ns; + if (interval > max_filter_interval) + interval = max_filter_interval; data[1] = interval * filter_resolution_ns; - if(interval != private(dev)->filter_interval) - { - writeb(interval, private(dev)->mite->daq_io_addr + Filter_Interval); + if (interval != private(dev)->filter_interval) { + writeb(interval, + private(dev)->mite->daq_io_addr + + Filter_Interval); private(dev)->filter_interval = interval; } - private(dev)->filter_enable[port] |= 1 << (chan % ni_65xx_channels_per_port); - }else{ - private(dev)->filter_enable[port] &= ~(1 << (chan % ni_65xx_channels_per_port)); + private(dev)->filter_enable[port] |= + 1 << (chan % ni_65xx_channels_per_port); + } else { + private(dev)->filter_enable[port] &= + ~(1 << (chan % ni_65xx_channels_per_port)); } - writeb(private(dev)->filter_enable[port], private(dev)->mite->daq_io_addr + Filter_Enable(port)); + writeb(private(dev)->filter_enable[port], + private(dev)->mite->daq_io_addr + Filter_Enable(port)); return 2; } -static int ni_65xx_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_65xx_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned port; - if(insn->n < 1) return -EINVAL; - port = sprivate(s)->base_port + ni_65xx_port_by_channel(CR_CHAN(insn->chanspec)); - switch(data[0]) - { + if (insn->n < 1) + return -EINVAL; + port = sprivate(s)->base_port + + ni_65xx_port_by_channel(CR_CHAN(insn->chanspec)); + switch (data[0]) { case INSN_CONFIG_FILTER: return ni_65xx_config_filter(dev, s, insn, data); break; case INSN_CONFIG_DIO_OUTPUT: - if(s->type != COMEDI_SUBD_DIO) return -EINVAL; + if (s->type != COMEDI_SUBD_DIO) + return -EINVAL; private(dev)->dio_direction[port] = COMEDI_OUTPUT; writeb(0, private(dev)->mite->daq_io_addr + Port_Select(port)); return 1; break; case INSN_CONFIG_DIO_INPUT: - if(s->type != COMEDI_SUBD_DIO) return -EINVAL; + if (s->type != COMEDI_SUBD_DIO) + return -EINVAL; private(dev)->dio_direction[port] = COMEDI_INPUT; writeb(1, private(dev)->mite->daq_io_addr + Port_Select(port)); return 1; break; case INSN_CONFIG_DIO_QUERY: - if(s->type != COMEDI_SUBD_DIO) return -EINVAL; + if (s->type != COMEDI_SUBD_DIO) + return -EINVAL; data[1] = private(dev)->dio_direction[port]; return insn->n; break; @@ -392,55 +390,60 @@ static int ni_65xx_dio_insn_config(comedi_device *dev,comedi_subdevice *s, return -EINVAL; } -static int ni_65xx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_65xx_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned base_bitfield_channel; const unsigned max_ports_per_bitfield = 5; unsigned read_bits = 0; unsigned j; - if(insn->n != 2) return -EINVAL; + if (insn->n != 2) + return -EINVAL; base_bitfield_channel = CR_CHAN(insn->chanspec); - for(j = 0; j < max_ports_per_bitfield; ++j) - { - const unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(base_bitfield_channel) + j; + for (j = 0; j < max_ports_per_bitfield; ++j) { + const unsigned port = + sprivate(s)->base_port + + ni_65xx_port_by_channel(base_bitfield_channel) + j; unsigned base_port_channel; unsigned port_mask, port_data, port_read_bits; int bitshift; - if(port >= ni_65xx_total_num_ports(board(dev))) break; + if (port >= ni_65xx_total_num_ports(board(dev))) + break; base_port_channel = port * ni_65xx_channels_per_port; port_mask = data[0]; port_data = data[1]; bitshift = base_port_channel - base_bitfield_channel; - if(bitshift >= 32 || bitshift <= -32) break; - if(bitshift > 0) - { + if (bitshift >= 32 || bitshift <= -32) + break; + if (bitshift > 0) { port_mask >>= bitshift; port_data >>= bitshift; - }else - { + } else { port_mask <<= -bitshift; port_data <<= -bitshift; } port_mask &= 0xff; port_data &= 0xff; - if(port_mask) - { + if (port_mask) { unsigned bits; private(dev)->output_bits[port] &= ~port_mask; - private(dev)->output_bits[port] |= port_data & port_mask; + private(dev)->output_bits[port] |= + port_data & port_mask; bits = private(dev)->output_bits[port]; - if(board(dev)->invert_outputs) bits = ~bits; - writeb(bits, private(dev)->mite->daq_io_addr + Port_Data(port)); -// rt_printk("wrote 0x%x to port %i\n", bits, port); + if (board(dev)->invert_outputs) + bits = ~bits; + writeb(bits, + private(dev)->mite->daq_io_addr + + Port_Data(port)); +// rt_printk("wrote 0x%x to port %i\n", bits, port); } - port_read_bits = readb(private(dev)->mite->daq_io_addr + Port_Data(port)); -// rt_printk("read 0x%x from port %i\n", port_read_bits, port); - if(bitshift > 0) - { + port_read_bits = + readb(private(dev)->mite->daq_io_addr + + Port_Data(port)); +// rt_printk("read 0x%x from port %i\n", port_read_bits, port); + if (bitshift > 0) { port_read_bits <<= bitshift; - }else - { + } else { port_read_bits >>= -bitshift; } read_bits |= port_read_bits; @@ -456,10 +459,13 @@ static irqreturn_t ni_65xx_interrupt(int irq, void *d PT_REGS_ARG) unsigned int status; status = readb(private(dev)->mite->daq_io_addr + Change_Status); - if((status & MasterInterruptStatus) == 0) return IRQ_NONE; - if((status & EdgeStatus) == 0) return IRQ_NONE; + if ((status & MasterInterruptStatus) == 0) + return IRQ_NONE; + if ((status & EdgeStatus) == 0) + return IRQ_NONE; - writeb(ClrEdge | ClrOverflow, private(dev)->mite->daq_io_addr + Clear_Register); + writeb(ClrEdge | ClrOverflow, + private(dev)->mite->daq_io_addr + Clear_Register); comedi_buf_put(s->async, 0); s->async->events |= COMEDI_CB_EOS; @@ -467,240 +473,275 @@ static irqreturn_t ni_65xx_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } -static int ni_65xx_intr_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int ni_65xx_intr_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_OTHER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_FOLLOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ + if (cmd->scan_begin_arg != 0) { cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=1){ - cmd->scan_end_arg=1; + if (cmd->scan_end_arg != 1) { + cmd->scan_end_arg = 1; err++; } - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(err)return 4; + if (err) + return 4; return 0; } -static int ni_65xx_intr_cmd(comedi_device *dev,comedi_subdevice *s) +static int ni_65xx_intr_cmd(comedi_device * dev, comedi_subdevice * s) { //comedi_cmd *cmd = &s->async->cmd; - writeb(ClrEdge|ClrOverflow, private(dev)->mite->daq_io_addr + Clear_Register); - writeb(FallingEdgeIntEnable|RisingEdgeIntEnable| - MasterInterruptEnable|EdgeIntEnable, + writeb(ClrEdge | ClrOverflow, + private(dev)->mite->daq_io_addr + Clear_Register); + writeb(FallingEdgeIntEnable | RisingEdgeIntEnable | + MasterInterruptEnable | EdgeIntEnable, private(dev)->mite->daq_io_addr + Master_Interrupt_Control); return 0; } -static int ni_65xx_intr_cancel(comedi_device *dev,comedi_subdevice *s) +static int ni_65xx_intr_cancel(comedi_device * dev, comedi_subdevice * s) { - writeb(0x00, private(dev)->mite->daq_io_addr + Master_Interrupt_Control); + writeb(0x00, + private(dev)->mite->daq_io_addr + Master_Interrupt_Control); return 0; } -static int ni_65xx_intr_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_65xx_intr_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n < 1)return -EINVAL; + if (insn->n < 1) + return -EINVAL; data[1] = 0; return 2; } -static int ni_65xx_intr_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_65xx_intr_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n < 1)return -EINVAL; - if(data[0] != INSN_CONFIG_CHANGE_NOTIFY)return -EINVAL; - - writeb(data[1], private(dev)->mite->daq_io_addr + Rising_Edge_Detection_Enable(0)); - writeb(data[1]>>8, private(dev)->mite->daq_io_addr + Rising_Edge_Detection_Enable(0x10)); - writeb(data[1]>>16, private(dev)->mite->daq_io_addr + Rising_Edge_Detection_Enable(0x20)); - writeb(data[1]>>24, private(dev)->mite->daq_io_addr + Rising_Edge_Detection_Enable(0x30)); - - writeb(data[2], private(dev)->mite->daq_io_addr + Falling_Edge_Detection_Enable(0)); - writeb(data[2]>>8, private(dev)->mite->daq_io_addr + Falling_Edge_Detection_Enable(0x10)); - writeb(data[2]>>16, private(dev)->mite->daq_io_addr + Falling_Edge_Detection_Enable(0x20)); - writeb(data[2]>>24, private(dev)->mite->daq_io_addr + Falling_Edge_Detection_Enable(0x30)); + if (insn->n < 1) + return -EINVAL; + if (data[0] != INSN_CONFIG_CHANGE_NOTIFY) + return -EINVAL; + + writeb(data[1], + private(dev)->mite->daq_io_addr + + Rising_Edge_Detection_Enable(0)); + writeb(data[1] >> 8, + private(dev)->mite->daq_io_addr + + Rising_Edge_Detection_Enable(0x10)); + writeb(data[1] >> 16, + private(dev)->mite->daq_io_addr + + Rising_Edge_Detection_Enable(0x20)); + writeb(data[1] >> 24, + private(dev)->mite->daq_io_addr + + Rising_Edge_Detection_Enable(0x30)); + + writeb(data[2], + private(dev)->mite->daq_io_addr + + Falling_Edge_Detection_Enable(0)); + writeb(data[2] >> 8, + private(dev)->mite->daq_io_addr + + Falling_Edge_Detection_Enable(0x10)); + writeb(data[2] >> 16, + private(dev)->mite->daq_io_addr + + Falling_Edge_Detection_Enable(0x20)); + writeb(data[2] >> 24, + private(dev)->mite->daq_io_addr + + Falling_Edge_Detection_Enable(0x30)); return 2; } - -static int ni_65xx_attach(comedi_device *dev,comedi_devconfig *it) +static int ni_65xx_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned i; int ret; - printk("comedi%d: ni_65xx:",dev->minor); + printk("comedi%d: ni_65xx:", dev->minor); - if((ret=alloc_private(dev,sizeof(ni_65xx_private)))<0) + if ((ret = alloc_private(dev, sizeof(ni_65xx_private))) < 0) return ret; - ret=ni_65xx_find_device(dev,it->options[0],it->options[1]); - if(ret<0)return ret; + ret = ni_65xx_find_device(dev, it->options[0], it->options[1]); + if (ret < 0) + return ret; ret = mite_setup(private(dev)->mite); - if(ret < 0) - { + if (ret < 0) { printk("error setting up mite\n"); return ret; } dev->board_name = board(dev)->name; dev->irq = mite_irq(private(dev)->mite); - printk(" %s",dev->board_name); + printk(" %s", dev->board_name); - printk(" ID=0x%02x", readb(private(dev)->mite->daq_io_addr + ID_Register)); + printk(" ID=0x%02x", + readb(private(dev)->mite->daq_io_addr + ID_Register)); - if((ret=alloc_subdevices(dev, 4)) < 0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; s = dev->subdevices + 0; - if(board(dev)->num_di_ports) - { + if (board(dev)->num_di_ports) { s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; - s->n_chan = board(dev)->num_di_ports * ni_65xx_channels_per_port; + s->n_chan = + board(dev)->num_di_ports * ni_65xx_channels_per_port; s->range_table = &range_digital; s->maxdata = 1; s->insn_config = ni_65xx_dio_insn_config; s->insn_bits = ni_65xx_dio_insn_bits; s->private = ni_65xx_alloc_subdevice_private(); - if(s->private == NULL) return -ENOMEM; + if (s->private == NULL) + return -ENOMEM; sprivate(s)->base_port = 0; - }else - { + } else { s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices + 1; - if(board(dev)->num_do_ports) - { + s = dev->subdevices + 1; + if (board(dev)->num_do_ports) { s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = board(dev)->num_di_ports * ni_65xx_channels_per_port; + s->n_chan = + board(dev)->num_di_ports * ni_65xx_channels_per_port; s->range_table = &range_digital; s->maxdata = 1; s->insn_bits = ni_65xx_dio_insn_bits; s->private = ni_65xx_alloc_subdevice_private(); - if(s->private == NULL) return -ENOMEM; + if (s->private == NULL) + return -ENOMEM; sprivate(s)->base_port = board(dev)->num_di_ports; - }else - { + } else { s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices + 2; - if(board(dev)->num_dio_ports) - { + s = dev->subdevices + 2; + if (board(dev)->num_dio_ports) { s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; - s->n_chan = board(dev)->num_dio_ports * ni_65xx_channels_per_port; - s->range_table=&range_digital; - s->maxdata=1; + s->n_chan = + board(dev)->num_dio_ports * ni_65xx_channels_per_port; + s->range_table = &range_digital; + s->maxdata = 1; s->insn_config = ni_65xx_dio_insn_config; s->insn_bits = ni_65xx_dio_insn_bits; s->private = ni_65xx_alloc_subdevice_private(); - if(s->private == NULL) return -ENOMEM; + if (s->private == NULL) + return -ENOMEM; sprivate(s)->base_port = 0; - for(i = 0; i < board(dev)->num_dio_ports; ++i) - { + for (i = 0; i < board(dev)->num_dio_ports; ++i) { // configure all ports for input - writeb(0x1, private(dev)->mite->daq_io_addr + Port_Select(i)); + writeb(0x1, + private(dev)->mite->daq_io_addr + + Port_Select(i)); } - }else - { + } else { s->type = COMEDI_SUBD_UNUSED; } - s=dev->subdevices + 3; + s = dev->subdevices + 3; dev->read_subdev = s; - s->type=COMEDI_SUBD_DI; + s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE | SDF_CMD_READ; - s->n_chan=1; - s->range_table=&range_unknown; - s->maxdata=1; + s->n_chan = 1; + s->range_table = &range_unknown; + s->maxdata = 1; s->do_cmdtest = ni_65xx_intr_cmdtest; s->do_cmd = ni_65xx_intr_cmd; s->cancel = ni_65xx_intr_cancel; s->insn_bits = ni_65xx_intr_insn_bits; s->insn_config = ni_65xx_intr_insn_config; - for(i = 0; i < ni_65xx_total_num_ports(board(dev)); ++i) - { - writeb(0x00, private(dev)->mite->daq_io_addr + Filter_Enable(i)); - if(board(dev)->invert_outputs) - writeb(0x01, private(dev)->mite->daq_io_addr + Port_Data(i)); + for (i = 0; i < ni_65xx_total_num_ports(board(dev)); ++i) { + writeb(0x00, + private(dev)->mite->daq_io_addr + Filter_Enable(i)); + if (board(dev)->invert_outputs) + writeb(0x01, + private(dev)->mite->daq_io_addr + Port_Data(i)); else - writeb(0x00, private(dev)->mite->daq_io_addr + Port_Data(i)); + writeb(0x00, + private(dev)->mite->daq_io_addr + Port_Data(i)); } - writeb(ClrEdge|ClrOverflow, + writeb(ClrEdge | ClrOverflow, private(dev)->mite->daq_io_addr + Clear_Register); - writeb(0x00, private(dev)->mite->daq_io_addr + Master_Interrupt_Control); + writeb(0x00, + private(dev)->mite->daq_io_addr + Master_Interrupt_Control); /* Set filter interval to 0 (32bit reg) */ writeb(0x00000000, private(dev)->mite->daq_io_addr + Filter_Interval); - ret=comedi_request_irq(dev->irq,ni_65xx_interrupt,IRQF_SHARED,"ni_65xx",dev); - if(ret<0){ - dev->irq=0; + ret = comedi_request_irq(dev->irq, ni_65xx_interrupt, IRQF_SHARED, + "ni_65xx", dev); + if (ret < 0) { + dev->irq = 0; printk(" irq not available"); } @@ -709,50 +750,51 @@ static int ni_65xx_attach(comedi_device *dev,comedi_devconfig *it) return 0; } -static int ni_65xx_detach(comedi_device *dev) +static int ni_65xx_detach(comedi_device * dev) { - if(private(dev) && private(dev)->mite && private(dev)->mite->daq_io_addr){ - writeb(0x00, private(dev)->mite->daq_io_addr + Master_Interrupt_Control); + if (private(dev) && private(dev)->mite + && private(dev)->mite->daq_io_addr) { + writeb(0x00, + private(dev)->mite->daq_io_addr + + Master_Interrupt_Control); } - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } - if(private(dev)) - { + if (private(dev)) { unsigned i; - for(i = 0; i < dev->n_subdevices; ++i) - { - if(dev->subdevices[i].private) - { + for (i = 0; i < dev->n_subdevices; ++i) { + if (dev->subdevices[i].private) { kfree(dev->subdevices[i].private); dev->subdevices[i].private = NULL; } } - if(private(dev)->mite){ + if (private(dev)->mite) { mite_unsetup(private(dev)->mite); } } return 0; } -static int ni_65xx_find_device(comedi_device *dev,int bus,int slot) +static int ni_65xx_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for(mite=mite_devices;mite;mite=mite->next){ - if(mite->used)continue; - if(bus || slot){ - if(bus!=mite->pcidev->bus->number || - slot!=PCI_SLOT(mite->pcidev->devfn)) + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number || + slot != PCI_SLOT(mite->pcidev->devfn)) continue; } - for(i=0;iboard_ptr = ni_65xx_boards + i; - private(dev)->mite=mite; + private(dev)->mite = mite; return 0; } } @@ -761,4 +803,3 @@ static int ni_65xx_find_device(comedi_device *dev,int bus,int slot) mite_list_devices(); return -EIO; } - diff --git a/comedi/drivers/ni_660x.c b/comedi/drivers/ni_660x.c index 50f94e97..4c88698c 100644 --- a/comedi/drivers/ni_660x.c +++ b/comedi/drivers/ni_660x.c @@ -44,8 +44,7 @@ DAQ 6601/6602 User Manual (NI 322137B-01) #include "mite.h" #include "ni_tio.h" -enum ni_660x_constants -{ +enum ni_660x_constants { min_counter_pfi_chan = 8, max_dio_pfi_chan = 31, counters_per_chip = 4 @@ -56,8 +55,7 @@ enum ni_660x_constants #define MAX_DMA_CHANNEL 4 /* See Register-Level Programmer Manual page 3.1 */ -typedef enum -{ +typedef enum { G0InterruptAcknowledge, G0StatusRegister, G1InterruptAcknowledge, @@ -166,30 +164,26 @@ static inline unsigned IOConfigReg(unsigned pfi_channel) return reg; } -enum ni_660x_register_width -{ +enum ni_660x_register_width { DATA_1B, DATA_2B, DATA_4B }; -enum ni_660x_register_direction -{ +enum ni_660x_register_direction { NI_660x_READ, NI_660x_WRITE, NI_660x_READ_WRITE }; -enum ni_660x_pfi_output_select -{ +enum ni_660x_pfi_output_select { pfi_output_select_high_Z = 0, pfi_output_select_counter = 1, pfi_output_select_do = 2, num_pfi_output_selects }; -enum ni_660x_subdevices -{ +enum ni_660x_subdevices { NI_660X_DIO_SUBDEV = 1, NI_660X_GPCT_SUBDEV_0 = 2 }; @@ -198,17 +192,14 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned index) return NI_660X_GPCT_SUBDEV_0 + index; } -typedef struct -{ - const char *name; // Register Name - int offset; // Offset from base address from GPCT chip +typedef struct { + const char *name; // Register Name + int offset; // Offset from base address from GPCT chip enum ni_660x_register_direction direction; - enum ni_660x_register_width size; // 1 byte, 2 bytes, or 4 bytes + enum ni_660x_register_width size; // 1 byte, 2 bytes, or 4 bytes } NI_660xRegisterData; - -static const NI_660xRegisterData registerData[NumRegisters] = -{ +static const NI_660xRegisterData registerData[NumRegisters] = { {"G0 Interrupt Acknowledge", 0x004, NI_660x_WRITE, DATA_2B}, {"G0 Status Register", 0x004, NI_660x_READ, DATA_2B}, {"G1 Interrupt Acknowledge", 0x006, NI_660x_WRITE, DATA_2B}, @@ -310,22 +301,24 @@ static const NI_660xRegisterData registerData[NumRegisters] = }; // kind of ENABLE for the second counter -enum clock_config_register_bits -{ +enum clock_config_register_bits { CounterSwap = 0x1 << 21 }; // ioconfigreg static inline unsigned ioconfig_bitshift(unsigned pfi_channel) { - if(pfi_channel % 2) return 0; - else return 8; + if (pfi_channel % 2) + return 0; + else + return 8; } static inline unsigned pfi_output_select_mask(unsigned pfi_channel) { return 0x3 << ioconfig_bitshift(pfi_channel); } -static inline unsigned pfi_output_select_bits(unsigned pfi_channel, unsigned output_select) +static inline unsigned pfi_output_select_bits(unsigned pfi_channel, + unsigned output_select) { return (output_select & 0x3) << ioconfig_bitshift(pfi_channel); } @@ -333,7 +326,8 @@ static inline unsigned pfi_input_select_mask(unsigned pfi_channel) { return 0x7 << (4 + ioconfig_bitshift(pfi_channel)); } -static inline unsigned pfi_input_select_bits(unsigned pfi_channel, unsigned input_select) +static inline unsigned pfi_input_select_bits(unsigned pfi_channel, + unsigned input_select) { return (input_select & 0x7) << (4 + ioconfig_bitshift(pfi_channel)); } @@ -344,8 +338,7 @@ static inline unsigned dma_select_mask(unsigned dma_channel) BUG_ON(dma_channel >= MAX_DMA_CHANNEL); return 0x1f << (8 * dma_channel); } -enum dma_selection -{ +enum dma_selection { dma_selection_none = 0x1f, }; static inline unsigned dma_selection_counter(unsigned counter_index) @@ -364,8 +357,7 @@ static inline unsigned dma_reset_bit(unsigned dma_channel) return 0x80 << (8 * dma_channel); } -enum global_interrupt_status_register_bits -{ +enum global_interrupt_status_register_bits { Counter_0_Int_Bit = 0x100, Counter_1_Int_Bit = 0x200, Counter_2_Int_Bit = 0x400, @@ -374,127 +366,118 @@ enum global_interrupt_status_register_bits Global_Int_Bit = 0x80000000 }; -enum global_interrupt_config_register_bits -{ +enum global_interrupt_config_register_bits { Cascade_Int_Enable_Bit = 0x20000000, Global_Int_Polarity_Bit = 0x40000000, Global_Int_Enable_Bit = 0x80000000 }; // Offset of the GPCT chips from the base-adress of the card -static const unsigned GPCT_OFFSET[2] = {0x0, 0x800}; /* First chip is at base-address + - 0x00, etc. */ +static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 }; /* First chip is at base-address + + 0x00, etc. */ /* Board description*/ -typedef struct -{ - unsigned short dev_id; /* `lspci` will show you this */ +typedef struct { + unsigned short dev_id; /* `lspci` will show you this */ const char *name; - unsigned n_chips; /* total number of TIO chips */ + unsigned n_chips; /* total number of TIO chips */ } ni_660x_board; -static const ni_660x_board ni_660x_boards[] = -{ +static const ni_660x_board ni_660x_boards[] = { { - dev_id : 0x2c60, - name : "PCI-6601", - n_chips : 1, - }, + dev_id: 0x2c60, + name: "PCI-6601", + n_chips: 1, + }, { - dev_id : 0x1310, - name : "PCI-6602", - n_chips : 2, - }, + dev_id: 0x1310, + name: "PCI-6602", + n_chips: 2, + }, { - dev_id : 0x1360, - name : "PXI-6602", - n_chips : 2, - }, + dev_id: 0x1360, + name: "PXI-6602", + n_chips: 2, + }, { - dev_id : 0x2cc0, - name : "PXI-6608", - n_chips : 2, - }, + dev_id: 0x2cc0, + name: "PXI-6608", + n_chips: 2, + }, }; + #define NI_660X_MAX_NUM_CHIPS 2 #define NI_660X_MAX_NUM_COUNTERS (NI_660X_MAX_NUM_CHIPS * counters_per_chip) static struct pci_device_id ni_660x_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x2c60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2cc0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x2c60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2cc0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, ni_660x_pci_table); -typedef struct -{ +typedef struct { struct mite_struct *mite; struct ni_gpct_device *counter_dev; uint64_t pfi_direction_bits; - struct mite_dma_descriptor_ring *mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip]; + struct mite_dma_descriptor_ring + *mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip]; spinlock_t mite_channel_lock; unsigned dma_configuration_soft_copies[NI_660X_MAX_NUM_CHIPS]; spinlock_t soft_reg_copy_lock; unsigned short pfi_output_selects[NUM_PFI_CHANNELS]; -}ni_660x_private; +} ni_660x_private; -static inline ni_660x_private* private(comedi_device *dev) +static inline ni_660x_private *private(comedi_device * dev) { return dev->private; } + /* initialized in ni_660x_find_device() */ -static inline const ni_660x_board* board(comedi_device *dev) +static inline const ni_660x_board *board(comedi_device * dev) { return dev->board_ptr; } #define n_ni_660x_boards (sizeof(ni_660x_boards)/sizeof(ni_660x_boards[0])) -static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it); -static int ni_660x_detach(comedi_device *dev); -static void init_tio_chip(comedi_device *dev, int chipset); -static void ni_660x_select_pfi_output(comedi_device *dev, unsigned pfi_channel, unsigned output_select); - -static comedi_driver driver_ni_660x= -{ - driver_name: "ni_660x", - module: THIS_MODULE, - attach: ni_660x_attach, - detach: ni_660x_detach, +static int ni_660x_attach(comedi_device * dev, comedi_devconfig * it); +static int ni_660x_detach(comedi_device * dev); +static void init_tio_chip(comedi_device * dev, int chipset); +static void ni_660x_select_pfi_output(comedi_device * dev, unsigned pfi_channel, + unsigned output_select); + +static comedi_driver driver_ni_660x = { + driver_name:"ni_660x", + module:THIS_MODULE, + attach:ni_660x_attach, + detach:ni_660x_detach, }; COMEDI_INITCLEANUP(driver_ni_660x); -static int ni_660x_find_device(comedi_device *dev, int bus, int slot); -static int ni_660x_set_pfi_routing(comedi_device *dev, unsigned chan, unsigned source); +static int ni_660x_find_device(comedi_device * dev, int bus, int slot); +static int ni_660x_set_pfi_routing(comedi_device * dev, unsigned chan, + unsigned source); /* Possible instructions for a GPCT */ -static int ni_660x_GPCT_rinsn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); -static int ni_660x_GPCT_insn_config(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); -static int ni_660x_GPCT_winsn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t * data); +static int ni_660x_GPCT_rinsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int ni_660x_GPCT_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int ni_660x_GPCT_winsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* Possible instructions for Digital IO */ -static int ni_660x_dio_insn_config(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); -static int ni_660x_dio_insn_bits(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data); - -static inline unsigned ni_660x_num_counters(comedi_device *dev) +static int ni_660x_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int ni_660x_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); + +static inline unsigned ni_660x_num_counters(comedi_device * dev) { return board(dev)->n_chips * counters_per_chip; } @@ -502,8 +485,7 @@ static inline unsigned ni_660x_num_counters(comedi_device *dev) static NI_660x_Register ni_gpct_to_660x_register(enum ni_gpct_register reg) { NI_660x_Register ni_660x_register; - switch(reg) - { + switch (reg) { case NITIO_G0_Autoincrement_Reg: ni_660x_register = G0AutoincrementRegister; break; @@ -709,7 +691,8 @@ static NI_660x_Register ni_gpct_to_660x_register(enum ni_gpct_register reg) ni_660x_register = G3InterruptEnable; break; default: - rt_printk("%s: unhandled register 0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: unhandled register 0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return 0; break; @@ -717,13 +700,14 @@ static NI_660x_Register ni_gpct_to_660x_register(enum ni_gpct_register reg) return ni_660x_register; } -static inline void ni_660x_write_register(comedi_device *dev, unsigned chip_index, unsigned bits, NI_660x_Register reg) +static inline void ni_660x_write_register(comedi_device * dev, + unsigned chip_index, unsigned bits, NI_660x_Register reg) { - void * const write_address = private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + + void *const write_address = + private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + registerData[reg].offset; - switch(registerData[reg].size) - { + switch (registerData[reg].size) { case DATA_2B: writew(bits, write_address); break; @@ -731,18 +715,21 @@ static inline void ni_660x_write_register(comedi_device *dev, unsigned chip_inde writel(bits, write_address); break; default: - rt_printk("%s: %s: bug! unhandled case (reg=0x%x) in switch.\n", __FILE__, __FUNCTION__, reg); + rt_printk("%s: %s: bug! unhandled case (reg=0x%x) in switch.\n", + __FILE__, __FUNCTION__, reg); BUG(); break; } } -static inline unsigned ni_660x_read_register(comedi_device *dev, unsigned chip_index, NI_660x_Register reg) +static inline unsigned ni_660x_read_register(comedi_device * dev, + unsigned chip_index, NI_660x_Register reg) { - void * const read_address = private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + registerData[reg].offset; + void *const read_address = + private(dev)->mite->daq_io_addr + GPCT_OFFSET[chip_index] + + registerData[reg].offset; - switch(registerData[reg].size) - { + switch (registerData[reg].size) { case DATA_2B: return readw(read_address); break; @@ -750,47 +737,58 @@ static inline unsigned ni_660x_read_register(comedi_device *dev, unsigned chip_i return readl(read_address); break; default: - rt_printk("%s: %s: bug! unhandled case (reg=0x%x) in switch.\n", __FILE__, __FUNCTION__, reg); + rt_printk("%s: %s: bug! unhandled case (reg=0x%x) in switch.\n", + __FILE__, __FUNCTION__, reg); BUG(); break; } return 0; } -static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg) +static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, + enum ni_gpct_register reg) { comedi_device *dev = counter->counter_dev->dev; NI_660x_Register ni_660x_register = ni_gpct_to_660x_register(reg); - ni_660x_write_register(dev, counter->chip_index, bits, ni_660x_register); + ni_660x_write_register(dev, counter->chip_index, bits, + ni_660x_register); } -static unsigned ni_gpct_read_register(struct ni_gpct *counter, enum ni_gpct_register reg) +static unsigned ni_gpct_read_register(struct ni_gpct *counter, + enum ni_gpct_register reg) { comedi_device *dev = counter->counter_dev->dev; NI_660x_Register ni_660x_register = ni_gpct_to_660x_register(reg); - return ni_660x_read_register(dev, counter->chip_index, ni_660x_register); + return ni_660x_read_register(dev, counter->chip_index, + ni_660x_register); } -static inline struct mite_dma_descriptor_ring* mite_ring(ni_660x_private *priv, struct ni_gpct *counter) +static inline struct mite_dma_descriptor_ring *mite_ring(ni_660x_private * priv, + struct ni_gpct *counter) { return priv->mite_rings[counter->chip_index][counter->counter_index]; } -static inline void ni_660x_set_dma_channel(comedi_device *dev, unsigned mite_channel, struct ni_gpct *counter) +static inline void ni_660x_set_dma_channel(comedi_device * dev, + unsigned mite_channel, struct ni_gpct *counter) { unsigned long flags; comedi_spin_lock_irqsave(&private(dev)->soft_reg_copy_lock, flags); private(dev)->dma_configuration_soft_copies[counter->chip_index] &= ~dma_select_mask(mite_channel); private(dev)->dma_configuration_soft_copies[counter->chip_index] |= - dma_select_bits(mite_channel, dma_selection_counter(counter->counter_index)); - ni_660x_write_register(dev, counter->chip_index, private(dev)->dma_configuration_soft_copies[counter->chip_index] | - dma_reset_bit(mite_channel), DMAConfigRegister); + dma_select_bits(mite_channel, + dma_selection_counter(counter->counter_index)); + ni_660x_write_register(dev, counter->chip_index, + private(dev)->dma_configuration_soft_copies[counter-> + chip_index] | dma_reset_bit(mite_channel), + DMAConfigRegister); mmiowb(); comedi_spin_unlock_irqrestore(&private(dev)->soft_reg_copy_lock, flags); } -static inline void ni_660x_unset_dma_channel(comedi_device *dev, unsigned mite_channel, struct ni_gpct *counter) +static inline void ni_660x_unset_dma_channel(comedi_device * dev, + unsigned mite_channel, struct ni_gpct *counter) { unsigned long flags; comedi_spin_lock_irqsave(&private(dev)->soft_reg_copy_lock, flags); @@ -798,24 +796,29 @@ static inline void ni_660x_unset_dma_channel(comedi_device *dev, unsigned mite_c ~dma_select_mask(mite_channel); private(dev)->dma_configuration_soft_copies[counter->chip_index] |= dma_select_bits(mite_channel, dma_selection_none); - ni_660x_write_register(dev, counter->chip_index, private(dev)->dma_configuration_soft_copies[counter->chip_index], - DMAConfigRegister); + ni_660x_write_register(dev, counter->chip_index, + private(dev)->dma_configuration_soft_copies[counter-> + chip_index], DMAConfigRegister); mmiowb(); comedi_spin_unlock_irqrestore(&private(dev)->soft_reg_copy_lock, flags); } -static int ni_660x_request_mite_channel(comedi_device *dev, struct ni_gpct *counter, enum comedi_io_direction direction) +static int ni_660x_request_mite_channel(comedi_device * dev, + struct ni_gpct *counter, enum comedi_io_direction direction) { unsigned long flags; struct mite_channel *mite_chan; comedi_spin_lock_irqsave(&private(dev)->mite_channel_lock, flags); BUG_ON(counter->mite_chan); - mite_chan = mite_request_channel(private(dev)->mite, mite_ring(private(dev), counter)); - if(mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&private(dev)->mite_channel_lock, flags); - comedi_error(dev, "failed to reserve mite dma channel for counter."); + mite_chan = + mite_request_channel(private(dev)->mite, mite_ring(private(dev), + counter)); + if (mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&private(dev)->mite_channel_lock, + flags); + comedi_error(dev, + "failed to reserve mite dma channel for counter."); return -EBUSY; } mite_chan->dir = direction; @@ -825,13 +828,12 @@ static int ni_660x_request_mite_channel(comedi_device *dev, struct ni_gpct *coun return 0; } -void ni_660x_release_mite_channel(comedi_device *dev, struct ni_gpct *counter) +void ni_660x_release_mite_channel(comedi_device * dev, struct ni_gpct *counter) { unsigned long flags; comedi_spin_lock_irqsave(&private(dev)->mite_channel_lock, flags); - if(counter->mite_chan) - { + if (counter->mite_chan) { struct mite_channel *mite_chan = counter->mite_chan; ni_660x_unset_dma_channel(dev, mite_chan->channel, counter); @@ -841,17 +843,17 @@ void ni_660x_release_mite_channel(comedi_device *dev, struct ni_gpct *counter) comedi_spin_unlock_irqrestore(&private(dev)->mite_channel_lock, flags); } -static int ni_660x_cmd(comedi_device *dev, comedi_subdevice *s) +static int ni_660x_cmd(comedi_device * dev, comedi_subdevice * s) { int retval; struct ni_gpct *counter = subdev_to_counter(s); -// const comedi_cmd *cmd = &s->async->cmd; +// const comedi_cmd *cmd = &s->async->cmd; retval = ni_660x_request_mite_channel(dev, counter, COMEDI_INPUT); - if(retval) - { - comedi_error(dev, "no dma channel available for use by counter"); + if (retval) { + comedi_error(dev, + "no dma channel available for use by counter"); return retval; } ni_tio_acknowledge_and_confirm(counter, NULL, NULL, NULL, NULL); @@ -860,14 +862,15 @@ static int ni_660x_cmd(comedi_device *dev, comedi_subdevice *s) return retval; } -static int ni_660x_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) +static int ni_660x_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { struct ni_gpct *counter = subdev_to_counter(s); return ni_tio_cmdtest(counter, cmd); } -static int ni_660x_cancel(comedi_device *dev, comedi_subdevice *s) +static int ni_660x_cancel(comedi_device * dev, comedi_subdevice * s) { struct ni_gpct *counter = subdev_to_counter(s); int retval; @@ -877,25 +880,27 @@ static int ni_660x_cancel(comedi_device *dev, comedi_subdevice *s) return retval; } -static void set_tio_counterswap(comedi_device *dev, int chipset) +static void set_tio_counterswap(comedi_device * dev, int chipset) { /* See P. 3.5 of the Register-Level Programming manual. The - CounterSwap bit has to be set on the second chip, otherwise - it will try to use the same pins as the first chip. - */ - if(chipset) - ni_660x_write_register(dev, chipset, CounterSwap, ClockConfigRegister); + CounterSwap bit has to be set on the second chip, otherwise + it will try to use the same pins as the first chip. + */ + if (chipset) + ni_660x_write_register(dev, chipset, CounterSwap, + ClockConfigRegister); else ni_660x_write_register(dev, chipset, 0, ClockConfigRegister); } -static void ni_660x_handle_gpct_interrupt(comedi_device *dev, comedi_subdevice *s) +static void ni_660x_handle_gpct_interrupt(comedi_device * dev, + comedi_subdevice * s) { ni_tio_handle_interrupt(subdev_to_counter(s), s); - if(s->async->events) - { - if(s->async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) - { + if (s->async->events) { + if (s->async-> + events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | + COMEDI_CB_OVERFLOW)) { ni_660x_cancel(dev, s); } comedi_event(dev, s); @@ -908,54 +913,54 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d PT_REGS_ARG) comedi_subdevice *s; unsigned i; - if(dev->attached == 0) return IRQ_NONE; + if (dev->attached == 0) + return IRQ_NONE; smp_mb(); - for(i = 0; i < ni_660x_num_counters(dev); ++i) - { + for (i = 0; i < ni_660x_num_counters(dev); ++i) { s = dev->subdevices + NI_660X_GPCT_SUBDEV(i); ni_660x_handle_gpct_interrupt(dev, s); } return IRQ_HANDLED; } -static int ni_660x_buf_change(comedi_device *dev, comedi_subdevice *s, +static int ni_660x_buf_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; - ret = mite_buf_change(mite_ring(private(dev), subdev_to_counter(s)), s->async); - if(ret < 0) return ret; + ret = mite_buf_change(mite_ring(private(dev), subdev_to_counter(s)), + s->async); + if (ret < 0) + return ret; return 0; } -static int ni_660x_allocate_private(comedi_device *dev) +static int ni_660x_allocate_private(comedi_device * dev) { int retval; unsigned i; - if((retval = alloc_private(dev, sizeof(ni_660x_private))) < 0) return retval; + if ((retval = alloc_private(dev, sizeof(ni_660x_private))) < 0) + return retval; spin_lock_init(&private(dev)->mite_channel_lock); spin_lock_init(&private(dev)->soft_reg_copy_lock); - for(i = 0; i < NUM_PFI_CHANNELS; ++i) - { + for (i = 0; i < NUM_PFI_CHANNELS; ++i) { private(dev)->pfi_output_selects[i] = pfi_output_select_counter; } return 0; } -static int ni_660x_alloc_mite_rings(comedi_device *dev) +static int ni_660x_alloc_mite_rings(comedi_device * dev) { unsigned i; unsigned j; - for(i = 0; i < board(dev)->n_chips; ++i) - { - for(j = 0; j < counters_per_chip; ++j) - { - private(dev)->mite_rings[i][j] = mite_alloc_ring(private(dev)->mite); - if(private(dev)->mite_rings[i][j] == NULL) - { + for (i = 0; i < board(dev)->n_chips; ++i) { + for (j = 0; j < counters_per_chip; ++j) { + private(dev)->mite_rings[i][j] = + mite_alloc_ring(private(dev)->mite); + if (private(dev)->mite_rings[i][j] == NULL) { return -ENOMEM; } } @@ -963,33 +968,33 @@ static int ni_660x_alloc_mite_rings(comedi_device *dev) return 0; } -static void ni_660x_free_mite_rings(comedi_device *dev) +static void ni_660x_free_mite_rings(comedi_device * dev) { unsigned i; unsigned j; - for(i = 0; i < board(dev)->n_chips; ++i) - { - for(j = 0; j < counters_per_chip; ++j) - { + for (i = 0; i < board(dev)->n_chips; ++i) { + for (j = 0; j < counters_per_chip; ++j) { mite_free_ring(private(dev)->mite_rings[i][j]); } } } -static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it) +static int ni_660x_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int ret; unsigned i; unsigned global_interrupt_config_bits; - printk("comedi%d: ni_660x: ",dev->minor); + printk("comedi%d: ni_660x: ", dev->minor); ret = ni_660x_allocate_private(dev); - if(ret < 0) return ret; + if (ret < 0) + return ret; ret = ni_660x_find_device(dev, it->options[0], it->options[1]); - if (ret<0) return ret; + if (ret < 0) + return ret; dev->board_name = board(dev)->name; @@ -1000,13 +1005,15 @@ static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it) } comedi_set_hw_dev(dev, &private(dev)->mite->pcidev->dev); ret = ni_660x_alloc_mite_rings(dev); - if(ret < 0) return ret; + if (ret < 0) + return ret; printk(" %s ", dev->board_name); dev->n_subdevices = 2 + NI_660X_MAX_NUM_COUNTERS; - if(alloc_subdevices(dev, dev->n_subdevices) < 0) return -ENOMEM; + if (alloc_subdevices(dev, dev->n_subdevices) < 0) + return -ENOMEM; s = dev->subdevices + 0; /* Old GENERAL-PURPOSE COUNTER/TIME (GPCT) subdevice, no longer used */ @@ -1014,28 +1021,29 @@ static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it) s = dev->subdevices + NI_660X_DIO_SUBDEV; /* DIGITAL I/O SUBDEVICE */ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->n_chan = NUM_PFI_CHANNELS; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = ni_660x_dio_insn_bits; - s->insn_config = ni_660x_dio_insn_config; - s->io_bits = 0; /* all bits default to input */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = NUM_PFI_CHANNELS; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = ni_660x_dio_insn_bits; + s->insn_config = ni_660x_dio_insn_config; + s->io_bits = 0; /* all bits default to input */ // we use the ioconfig registers to control dio direction, so zero output enables in stc dio control reg ni_660x_write_register(dev, 0, 0, STCDIOControl); private(dev)->counter_dev = ni_gpct_device_construct(dev, &ni_gpct_write_register, &ni_gpct_read_register, ni_gpct_variant_660x, ni_660x_num_counters(dev)); - if(private(dev)->counter_dev == NULL) return -ENOMEM; - for(i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) - { + if (private(dev)->counter_dev == NULL) + return -ENOMEM; + for (i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) { s = dev->subdevices + NI_660X_GPCT_SUBDEV(i); - if(i < ni_660x_num_counters(dev)) - { + if (i < ni_660x_num_counters(dev)) { s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_CMD_READ /* | SDF_CMD_WRITE */; + s->subdev_flags = + SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | + SDF_CMD_READ /* | SDF_CMD_WRITE */ ; s->n_chan = 3; s->maxdata = 0xffffffff; s->insn_read = ni_660x_GPCT_rinsn; @@ -1049,43 +1057,42 @@ static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it) s->buf_change = &ni_660x_buf_change; s->private = &private(dev)->counter_dev->counters[i]; - private(dev)->counter_dev->counters[i].chip_index = i / counters_per_chip; - private(dev)->counter_dev->counters[i].counter_index = i % counters_per_chip; - }else - { + private(dev)->counter_dev->counters[i].chip_index = + i / counters_per_chip; + private(dev)->counter_dev->counters[i].counter_index = + i % counters_per_chip; + } else { s->type = COMEDI_SUBD_UNUSED; } } - for(i = 0; i < board(dev)->n_chips; ++i) - { + for (i = 0; i < board(dev)->n_chips; ++i) { init_tio_chip(dev, i); } - for(i = 0; i < ni_660x_num_counters(dev); ++i) - { + for (i = 0; i < ni_660x_num_counters(dev); ++i) { ni_tio_init_counter(&private(dev)->counter_dev->counters[i]); } - for(i = 0; i < NUM_PFI_CHANNELS; ++i) - { - if(i < min_counter_pfi_chan) + for (i = 0; i < NUM_PFI_CHANNELS; ++i) { + if (i < min_counter_pfi_chan) ni_660x_set_pfi_routing(dev, i, pfi_output_select_do); else - ni_660x_set_pfi_routing(dev, i, pfi_output_select_counter); + ni_660x_set_pfi_routing(dev, i, + pfi_output_select_counter); ni_660x_select_pfi_output(dev, i, pfi_output_select_high_Z); } /* to be safe, set counterswap bits on tio chips after all the counter - outputs have been set to high impedance mode */ - for(i = 0; i < board(dev)->n_chips; ++i) - { + outputs have been set to high impedance mode */ + for (i = 0; i < board(dev)->n_chips; ++i) { set_tio_counterswap(dev, i); } - if((ret = comedi_request_irq(mite_irq(private(dev)->mite), &ni_660x_interrupt, IRQF_SHARED, "ni_660x", dev)) < 0) - { + if ((ret = comedi_request_irq(mite_irq(private(dev)->mite), + &ni_660x_interrupt, IRQF_SHARED, "ni_660x", + dev)) < 0) { printk(" irq not available\n"); return ret; } dev->irq = mite_irq(private(dev)->mite); global_interrupt_config_bits = Global_Int_Enable_Bit; - if(board(dev)->n_chips > 1) + if (board(dev)->n_chips > 1) global_interrupt_config_bits |= Cascade_Int_Enable_Bit; ni_660x_write_register(dev, 0, global_interrupt_config_bits, GlobalInterruptConfigRegister); @@ -1093,21 +1100,18 @@ static int ni_660x_attach(comedi_device *dev,comedi_devconfig *it) return 0; } - -static int -ni_660x_detach(comedi_device *dev) +static int ni_660x_detach(comedi_device * dev) { - printk("comedi%d: ni_660x: remove\n",dev->minor); + printk("comedi%d: ni_660x: remove\n", dev->minor); /* Free irq */ - if(dev->irq) comedi_free_irq(dev->irq, dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); - if(dev->private) - { - if(private(dev)->counter_dev) + if (dev->private) { + if (private(dev)->counter_dev) ni_gpct_device_destroy(private(dev)->counter_dev); - if(private(dev)->mite) - { + if (private(dev)->mite) { ni_660x_free_mite_rings(dev); mite_unsetup(private(dev)->mite); } @@ -1116,59 +1120,59 @@ ni_660x_detach(comedi_device *dev) } static int -ni_660x_GPCT_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +ni_660x_GPCT_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { return ni_tio_rinsn(subdev_to_counter(s), insn, data); } -static void init_tio_chip(comedi_device *dev, int chipset) +static void init_tio_chip(comedi_device * dev, int chipset) { unsigned i; // init dma configuration register private(dev)->dma_configuration_soft_copies[chipset] = 0; - for(i = 0; i < MAX_DMA_CHANNEL; ++i) - { + for (i = 0; i < MAX_DMA_CHANNEL; ++i) { private(dev)->dma_configuration_soft_copies[chipset] |= - dma_select_bits(i, dma_selection_none) & dma_select_mask(i); + dma_select_bits(i, + dma_selection_none) & dma_select_mask(i); } - ni_660x_write_register(dev, chipset, private(dev)->dma_configuration_soft_copies[chipset], + ni_660x_write_register(dev, chipset, + private(dev)->dma_configuration_soft_copies[chipset], DMAConfigRegister); } static int -ni_660x_GPCT_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +ni_660x_GPCT_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { return ni_tio_insn_config(subdev_to_counter(s), insn, data); } -static int ni_660x_GPCT_winsn(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t * data) +static int ni_660x_GPCT_winsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { return ni_tio_winsn(subdev_to_counter(s), insn, data); } -static int -ni_660x_find_device(comedi_device *dev, int bus, int slot) +static int ni_660x_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for (mite=mite_devices; mite; mite=mite->next) { - if (mite->used) continue; + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; if (bus || slot) { - if (bus!=mite->pcidev->bus->number || - slot!=PCI_SLOT(mite->pcidev->devfn)) continue; + if (bus != mite->pcidev->bus->number || + slot != PCI_SLOT(mite->pcidev->devfn)) + continue; } - for (i=0; iboard_ptr=ni_660x_boards+i; - private(dev)->mite=mite; + for (i = 0; i < n_ni_660x_boards; i++) { + if (mite_device_id(mite) == ni_660x_boards[i].dev_id) { + dev->board_ptr = ni_660x_boards + i; + private(dev)->mite = mite; return 0; } } @@ -1178,29 +1182,28 @@ ni_660x_find_device(comedi_device *dev, int bus, int slot) return -EIO; } - -static int ni_660x_dio_insn_bits(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int ni_660x_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { unsigned base_bitfield_channel = CR_CHAN(insn->chanspec); // Check if we have to write some bits - if(data[0]) - { + if (data[0]) { s->state &= ~(data[0] << base_bitfield_channel); s->state |= (data[0] & data[1]) << base_bitfield_channel; /* Write out the new digital output lines */ ni_660x_write_register(dev, 0, s->state, DIO32Output); } /* on return, data[1] contains the value of the digital - * input and output lines. */ - data[1] = (ni_660x_read_register(dev, 0, DIO32Input) >> base_bitfield_channel); + * input and output lines. */ + data[1] = + (ni_660x_read_register(dev, 0, + DIO32Input) >> base_bitfield_channel); return 2; } -static void ni_660x_select_pfi_output(comedi_device *dev, unsigned pfi_channel, unsigned output_select) +static void ni_660x_select_pfi_output(comedi_device * dev, unsigned pfi_channel, + unsigned output_select) { unsigned bits = ni_660x_read_register(dev, 0, IOConfigReg(pfi_channel)); @@ -1209,32 +1212,37 @@ static void ni_660x_select_pfi_output(comedi_device *dev, unsigned pfi_channel, ni_660x_write_register(dev, 0, bits, IOConfigReg(pfi_channel)); } -static int ni_660x_set_pfi_routing(comedi_device *dev, unsigned chan, unsigned source) +static int ni_660x_set_pfi_routing(comedi_device * dev, unsigned chan, + unsigned source) { - if(source > num_pfi_output_selects) return -EINVAL; - if(source == pfi_output_select_high_Z) return -EINVAL; - if(chan < min_counter_pfi_chan) - { - if(source == pfi_output_select_counter) return -EINVAL; - }else if(chan > max_dio_pfi_chan) - { - if(source == pfi_output_select_do) return -EINVAL; + if (source > num_pfi_output_selects) + return -EINVAL; + if (source == pfi_output_select_high_Z) + return -EINVAL; + if (chan < min_counter_pfi_chan) { + if (source == pfi_output_select_counter) + return -EINVAL; + } else if (chan > max_dio_pfi_chan) { + if (source == pfi_output_select_do) + return -EINVAL; } BUG_ON(chan >= NUM_PFI_CHANNELS); private(dev)->pfi_output_selects[chan] = source; - if(private(dev)->pfi_direction_bits & (((uint64_t)1) << chan)) - ni_660x_select_pfi_output(dev, chan, private(dev)->pfi_output_selects[chan]); + if (private(dev)->pfi_direction_bits & (((uint64_t) 1) << chan)) + ni_660x_select_pfi_output(dev, chan, + private(dev)->pfi_output_selects[chan]); return 0; } -static unsigned ni_660x_get_pfi_routing(comedi_device *dev, unsigned chan) +static unsigned ni_660x_get_pfi_routing(comedi_device * dev, unsigned chan) { BUG_ON(chan >= NUM_PFI_CHANNELS); return private(dev)->pfi_output_selects[chan]; } -static void ni660x_config_filter(comedi_device *dev, unsigned pfi_channel, enum ni_gpct_filter_select filter) +static void ni660x_config_filter(comedi_device * dev, unsigned pfi_channel, + enum ni_gpct_filter_select filter) { unsigned bits = ni_660x_read_register(dev, 0, IOConfigReg(pfi_channel)); bits &= ~pfi_input_select_mask(pfi_channel); @@ -1242,30 +1250,31 @@ static void ni660x_config_filter(comedi_device *dev, unsigned pfi_channel, enum ni_660x_write_register(dev, 0, bits, IOConfigReg(pfi_channel)); } -static int ni_660x_dio_insn_config(comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int ni_660x_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); /* The input or output configuration of each digital line is - * configured by a special insn_config instruction. chanspec - * contains the channel to be changed, and data[0] contains the - * value COMEDI_INPUT or COMEDI_OUTPUT. */ + * configured by a special insn_config instruction. chanspec + * contains the channel to be changed, and data[0] contains the + * value COMEDI_INPUT or COMEDI_OUTPUT. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - private(dev)->pfi_direction_bits |= ((uint64_t)1) << chan; - ni_660x_select_pfi_output(dev, chan, private(dev)->pfi_output_selects[chan]); + private(dev)->pfi_direction_bits |= ((uint64_t) 1) << chan; + ni_660x_select_pfi_output(dev, chan, + private(dev)->pfi_output_selects[chan]); break; case INSN_CONFIG_DIO_INPUT: - private(dev)->pfi_direction_bits &= ~(((uint64_t)1) << chan); + private(dev)->pfi_direction_bits &= ~(((uint64_t) 1) << chan); ni_660x_select_pfi_output(dev, chan, pfi_output_select_high_Z); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (private(dev)->pfi_direction_bits & (((uint64_t)1) << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (private(dev)-> + pfi_direction_bits & (((uint64_t) 1) << chan)) ? + COMEDI_OUTPUT : COMEDI_INPUT; return 0; case INSN_CONFIG_SET_ROUTING: return ni_660x_set_pfi_routing(dev, chan, data[1]); @@ -1282,5 +1291,3 @@ static int ni_660x_dio_insn_config(comedi_device *dev, }; return 0; } - - diff --git a/comedi/drivers/ni_670x.c b/comedi/drivers/ni_670x.c index eb89b3c2..3bb2b49c 100644 --- a/comedi/drivers/ni_670x.c +++ b/comedi/drivers/ni_670x.c @@ -51,7 +51,7 @@ Commands are not supported. #define AO_CHAN_OFFSET 0x0c #define AO_STATUS_OFFSET 0x10 #define AO_CONTROL_OFFSET 0x10 -#define DIO_PORT0_DIR_OFFSET 0x20 +#define DIO_PORT0_DIR_OFFSET 0x20 #define DIO_PORT0_DATA_OFFSET 0x24 #define DIO_PORT1_DIR_OFFSET 0x28 #define DIO_PORT1_DATA_OFFSET 0x2c @@ -60,269 +60,269 @@ Commands are not supported. /* Board description*/ -typedef struct ni_670x_board_struct -{ +typedef struct ni_670x_board_struct { unsigned short dev_id; const char *name; unsigned short ao_chans; unsigned short ao_bits; -}ni_670x_board; -static const ni_670x_board ni_670x_boards[] = -{ +} ni_670x_board; +static const ni_670x_board ni_670x_boards[] = { { - dev_id : 0x2c90, - name : "PCI-6703", - ao_chans : 16, - ao_bits : 16, - }, + dev_id: 0x2c90, + name: "PCI-6703", + ao_chans:16, + ao_bits: 16, + }, { - dev_id : 0x1920, - name : "PXI-6704", - ao_chans : 32, - ao_bits : 16, - }, + dev_id: 0x1920, + name: "PXI-6704", + ao_chans:32, + ao_bits: 16, + }, { - dev_id : 0x1290, - name : "PCI-6704", - ao_chans : 32, - ao_bits : 16, - }, + dev_id: 0x1290, + name: "PCI-6704", + ao_chans:32, + ao_bits: 16, + }, }; static struct pci_device_id ni_670x_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x2c90, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, + {PCI_VENDOR_ID_NATINST, 0x2c90, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, //{ PCI_VENDOR_ID_NATINST, 0x0000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {0} }; + MODULE_DEVICE_TABLE(pci, ni_670x_pci_table); #define thisboard ((ni_670x_board *)dev->board_ptr) -typedef struct -{ +typedef struct { struct mite_struct *mite; int boardtype; int dio; lsampl_t ao_readback[32]; -}ni_670x_private; +} ni_670x_private; #define devpriv ((ni_670x_private *)dev->private) #define n_ni_670x_boards (sizeof(ni_670x_boards)/sizeof(ni_670x_boards[0])) -static int ni_670x_attach(comedi_device *dev,comedi_devconfig *it); -static int ni_670x_detach(comedi_device *dev); +static int ni_670x_attach(comedi_device * dev, comedi_devconfig * it); +static int ni_670x_detach(comedi_device * dev); -static comedi_driver driver_ni_670x= -{ - driver_name: "ni_670x", - module: THIS_MODULE, - attach: ni_670x_attach, - detach: ni_670x_detach, +static comedi_driver driver_ni_670x = { + driver_name:"ni_670x", + module:THIS_MODULE, + attach:ni_670x_attach, + detach:ni_670x_detach, }; -COMEDI_INITCLEANUP(driver_ni_670x); -static comedi_lrange range_0_20mA = { 1, { RANGE_mA(0,20)}}; +COMEDI_INITCLEANUP(driver_ni_670x); -static int ni_670x_find_device(comedi_device *dev,int bus,int slot); +static comedi_lrange range_0_20mA = { 1, {RANGE_mA(0, 20)} }; -static int ni_670x_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ni_670x_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ni_670x_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int ni_670x_dio_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int ni_670x_find_device(comedi_device * dev, int bus, int slot); +static int ni_670x_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_670x_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_670x_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_670x_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int ni_670x_attach(comedi_device *dev,comedi_devconfig *it) +static int ni_670x_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int ret; int i; - - printk("comedi%d: ni_670x: ",dev->minor); - if((ret=alloc_private(dev,sizeof(ni_670x_private)))<0) + printk("comedi%d: ni_670x: ", dev->minor); + + if ((ret = alloc_private(dev, sizeof(ni_670x_private))) < 0) return ret; - - ret=ni_670x_find_device(dev,it->options[0],it->options[1]); - if(ret<0) return ret; - + + ret = ni_670x_find_device(dev, it->options[0], it->options[1]); + if (ret < 0) + return ret; + ret = mite_setup(devpriv->mite); - if(ret < 0) - { + if (ret < 0) { printk("error setting up mite\n"); return ret; } - dev->board_name=thisboard->name; - dev->irq=mite_irq(devpriv->mite); - printk(" %s",dev->board_name); + dev->board_name = thisboard->name; + dev->irq = mite_irq(devpriv->mite); + printk(" %s", dev->board_name); - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* analog output subdevice */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE; - s->n_chan = thisboard->ao_chans; - s->maxdata = 0xffff; - if(s->n_chan == 32){ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->ao_chans; + s->maxdata = 0xffff; + if (s->n_chan == 32) { const comedi_lrange **range_table_list; - range_table_list = kmalloc(sizeof(comedi_lrange *)*32, + range_table_list = kmalloc(sizeof(comedi_lrange *) * 32, GFP_KERNEL); - if(!range_table_list) + if (!range_table_list) return -ENOMEM; s->range_table_list = range_table_list; - for(i=0;i<16;i++){ - range_table_list[i] = &range_bipolar10; - range_table_list[16+i] = &range_0_20mA; + for (i = 0; i < 16; i++) { + range_table_list[i] = &range_bipolar10; + range_table_list[16 + i] = &range_0_20mA; } - }else{ - s->range_table = &range_bipolar10; + } else { + s->range_table = &range_bipolar10; } - s->insn_write = &ni_670x_ao_winsn; - s->insn_read = &ni_670x_ao_rinsn; + s->insn_write = &ni_670x_ao_winsn; + s->insn_read = &ni_670x_ao_rinsn; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* digital i/o subdevice */ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->n_chan = 8; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_bits = ni_670x_dio_insn_bits; - s->insn_config = ni_670x_dio_insn_config; - - writel(0x10 ,devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET); /* Config of misc registers */ - writel(0x00 ,devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET); /* Config of ao registers */ - + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = ni_670x_dio_insn_bits; + s->insn_config = ni_670x_dio_insn_config; + + writel(0x10, devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET); /* Config of misc registers */ + writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET); /* Config of ao registers */ + printk("attached\n"); return 1; } - -static int ni_670x_detach(comedi_device *dev) +static int ni_670x_detach(comedi_device * dev) { - printk("comedi%d: ni_670x: remove\n",dev->minor); - - if(dev->subdevices[0].range_table_list){ + printk("comedi%d: ni_670x: remove\n", dev->minor); + + if (dev->subdevices[0].range_table_list) { kfree(dev->subdevices[0].range_table_list); } - if(dev->private && devpriv->mite) + if (dev->private && devpriv->mite) mite_unsetup(devpriv->mite); - - if(dev->irq) - comedi_free_irq(dev->irq,dev); - - return 0; -} - + if (dev->irq) + comedi_free_irq(dev->irq, dev); + return 0; +} -static int ni_670x_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ni_670x_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); /* Channel number mapping : - - NI 6703/ NI 6704 | NI 6704 Only - ---------------------------------------------------- - vch(0) : 0 | ich(16) : 1 - vch(1) : 2 | ich(17) : 3 - . : . | . . - . : . | . . - . : . | . . - vch(15) : 30 | ich(31) : 31 */ - - for(i=0;in;i++){ - writel(((chan&15)<<1) | ((chan&16)>>4), - devpriv->mite->daq_io_addr + AO_CHAN_OFFSET); /* First write in channel register which channel to use */ - writel(data[i],devpriv->mite->daq_io_addr + AO_VALUE_OFFSET); /* write channel value */ + + NI 6703/ NI 6704 | NI 6704 Only + ---------------------------------------------------- + vch(0) : 0 | ich(16) : 1 + vch(1) : 2 | ich(17) : 3 + . : . | . . + . : . | . . + . : . | . . + vch(15) : 30 | ich(31) : 31 */ + + for (i = 0; i < insn->n; i++) { + writel(((chan & 15) << 1) | ((chan & 16) >> 4), devpriv->mite->daq_io_addr + AO_CHAN_OFFSET); /* First write in channel register which channel to use */ + writel(data[i], devpriv->mite->daq_io_addr + AO_VALUE_OFFSET); /* write channel value */ devpriv->ao_readback[chan] = data[i]; } return i; } -static int ni_670x_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ni_670x_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; } -static int ni_670x_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ni_670x_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ - if(data[0]) - { + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; - writel(s->state,devpriv->mite->daq_io_addr + DIO_PORT0_DATA_OFFSET); + s->state |= data[0] & data[1]; + writel(s->state, + devpriv->mite->daq_io_addr + DIO_PORT0_DATA_OFFSET); } - + /* on return, data[1] contains the value of the digital * input lines. */ - data[1]=readl(devpriv->mite->daq_io_addr + DIO_PORT0_DATA_OFFSET); + data[1] = readl(devpriv->mite->daq_io_addr + DIO_PORT0_DATA_OFFSET); return 2; } -static int ni_670x_dio_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ni_670x_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<io_bits |= 1 << chan; break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<io_bits &= ~(1 << chan); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1< + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: return -EINVAL; break; } - writel(s->io_bits,devpriv->mite->daq_io_addr + DIO_PORT0_DIR_OFFSET); + writel(s->io_bits, devpriv->mite->daq_io_addr + DIO_PORT0_DIR_OFFSET); return insn->n; } -static int ni_670x_find_device(comedi_device *dev,int bus,int slot) +static int ni_670x_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for(mite=mite_devices;mite;mite=mite->next) - { - if(mite->used)continue; - if(bus || slot) - { - if(bus!=mite->pcidev->bus->number || slot!=PCI_SLOT(mite->pcidev->devfn)) + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number + || slot != PCI_SLOT(mite->pcidev->devfn)) continue; } - for(i=0;iboard_ptr=ni_670x_boards+i; - devpriv->mite=mite; + for (i = 0; i < n_ni_670x_boards; i++) { + if (mite_device_id(mite) == ni_670x_boards[i].dev_id) { + dev->board_ptr = ni_670x_boards + i; + devpriv->mite = mite; return 0; } @@ -332,4 +332,3 @@ static int ni_670x_find_device(comedi_device *dev,int bus,int slot) mite_list_devices(); return -EIO; } - diff --git a/comedi/drivers/ni_at_a2150.c b/comedi/drivers/ni_at_a2150.c index f99aec58..48d46095 100644 --- a/comedi/drivers/ni_at_a2150.c +++ b/comedi/drivers/ni_at_a2150.c @@ -75,8 +75,8 @@ TRIG_WAKE_EOS #define A2150_SIZE 28 #define A2150_DMA_BUFFER_SIZE 0xff00 // size in bytes of dma buffer -//#define A2150_DEBUG // enable debugging code -#undef A2150_DEBUG // disable debugging code +//#define A2150_DEBUG // enable debugging code +#undef A2150_DEBUG // disable debugging code /* Registers and bits */ #define CONFIG_REG 0x0 @@ -119,72 +119,76 @@ TRIG_WAKE_EOS #define I8253_MODE_REG 0x17 #define HW_COUNT_DISABLE 0x30 // disable hardware counting of conversions -typedef struct a2150_board_struct{ +typedef struct a2150_board_struct { const char *name; - int clock[4]; // master clock periods, in nanoseconds - int num_clocks; // number of available master clock speeds - int ai_speed; // maximum conversion rate in nanoseconds -}a2150_board; + int clock[4]; // master clock periods, in nanoseconds + int num_clocks; // number of available master clock speeds + int ai_speed; // maximum conversion rate in nanoseconds +} a2150_board; //analog input range static const comedi_lrange range_a2150 = { 1, { - RANGE( -2.828, 2.828 ), - } + RANGE(-2.828, 2.828), + } }; // enum must match board indices -enum{a2150_c, a2150_s}; -static const a2150_board a2150_boards[] = -{ - { - name: "at-a2150c", - clock: {31250, 22676, 20833, 19531}, - num_clocks: 4, - ai_speed: 19531, - }, - { - name: "at-a2150s", - clock: {62500, 50000, 41667, 0}, - num_clocks: 3, - ai_speed: 41667, - }, +enum { a2150_c, a2150_s }; +static const a2150_board a2150_boards[] = { + { + name: "at-a2150c", + clock: {31250, 22676, 20833, 19531}, + num_clocks:4, + ai_speed:19531, + }, + { + name: "at-a2150s", + clock: {62500, 50000, 41667, 0}, + num_clocks:3, + ai_speed:41667, + }, }; + /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const a2150_board *)dev->board_ptr) -typedef struct{ - volatile unsigned int count; /* number of data points left to be taken */ +typedef struct { + volatile unsigned int count; /* number of data points left to be taken */ unsigned int dma; // dma channel s16 *dma_buffer; // dma buffer unsigned int dma_transfer_size; // size in bytes of dma transfers int irq_dma_bits; // irq/dma register bits int config_bits; // config register bits -}a2150_private; +} a2150_private; #define devpriv ((a2150_private *)dev->private) -static int a2150_attach(comedi_device *dev,comedi_devconfig *it); -static int a2150_detach(comedi_device *dev); -static int a2150_cancel(comedi_device *dev, comedi_subdevice *s); +static int a2150_attach(comedi_device * dev, comedi_devconfig * it); +static int a2150_detach(comedi_device * dev); +static int a2150_cancel(comedi_device * dev, comedi_subdevice * s); -static comedi_driver driver_a2150={ - driver_name: "ni_at_a2150", - module: THIS_MODULE, - attach: a2150_attach, - detach: a2150_detach, +static comedi_driver driver_a2150 = { + driver_name:"ni_at_a2150", + module:THIS_MODULE, + attach:a2150_attach, + detach:a2150_detach, }; static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG); -static int a2150_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int a2150_get_timing(comedi_device *dev, unsigned int *period, int flags); -static int a2150_probe(comedi_device *dev); -static int a2150_set_chanlist(comedi_device *dev, unsigned int start_channel, unsigned int num_channels); +static int a2150_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int a2150_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int a2150_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int a2150_get_timing(comedi_device * dev, unsigned int *period, + int flags); +static int a2150_probe(comedi_device * dev); +static int a2150_set_chanlist(comedi_device * dev, unsigned int start_channel, + unsigned int num_channels); /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. @@ -193,7 +197,7 @@ COMEDI_INITCLEANUP(driver_a2150); #ifdef A2150_DEBUG -static void ni_dump_regs(comedi_device *dev) +static void ni_dump_regs(comedi_device * dev) { rt_printk("config bits 0x%x\n", devpriv->config_bits); rt_printk("irq dma bits 0x%x\n", devpriv->irq_dma_bits); @@ -216,8 +220,7 @@ static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG) sampl_t dpnt; static const int sample_size = sizeof(devpriv->dma_buffer[0]); - if(dev->attached == 0) - { + if (dev->attached == 0) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } @@ -228,21 +231,18 @@ static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG) status = inw(dev->iobase + STATUS_REG); - if((status & INTR_BIT ) == 0) - { + if ((status & INTR_BIT) == 0) { comedi_error(dev, "spurious interrupt"); return IRQ_NONE; } - if(status & OVFL_BIT) - { + if (status & OVFL_BIT) { comedi_error(dev, "fifo overflow"); a2150_cancel(dev, s); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; } - if((status & DMA_TC_BIT) == 0) - { + if ((status & DMA_TC_BIT) == 0) { comedi_error(dev, "caught non-dma interrupt? Aborting."); a2150_cancel(dev, s); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; @@ -257,46 +257,40 @@ static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG) clear_dma_ff(devpriv->dma); // figure out how many points to read - max_points = devpriv->dma_transfer_size / sample_size; + max_points = devpriv->dma_transfer_size / sample_size; /* residue is the number of points left to be done on the dma * transfer. It should always be zero at this point unless * the stop_src is set to external triggering. */ residue = get_dma_residue(devpriv->dma) / sample_size; num_points = max_points - residue; - if(devpriv->count < num_points && - cmd->stop_src == TRIG_COUNT) + if (devpriv->count < num_points && cmd->stop_src == TRIG_COUNT) num_points = devpriv->count; // figure out how many points will be stored next time leftover = 0; - if(cmd->stop_src == TRIG_NONE) - { + if (cmd->stop_src == TRIG_NONE) { leftover = devpriv->dma_transfer_size / sample_size; - }else if(devpriv->count > max_points) - { + } else if (devpriv->count > max_points) { leftover = devpriv->count - max_points; - if(leftover > max_points) + if (leftover > max_points) leftover = max_points; } /* there should only be a residue if collection was stopped by having * the stop_src set to an external trigger, in which case there * will be no more data */ - if(residue) + if (residue) leftover = 0; - for(i = 0; i < num_points; i++) - { + for (i = 0; i < num_points; i++) { /* write data point to comedi buffer */ dpnt = devpriv->dma_buffer[i]; // convert from 2's complement to unsigned coding dpnt ^= 0x8000; - cfc_write_to_buffer( s, dpnt ); - if(cmd->stop_src == TRIG_COUNT) - { - if(--devpriv->count == 0) - { /* end of acquisition */ + cfc_write_to_buffer(s, dpnt); + if (cmd->stop_src == TRIG_COUNT) { + if (--devpriv->count == 0) { /* end of acquisition */ a2150_cancel(dev, s); async->events |= COMEDI_CB_EOA; break; @@ -304,8 +298,7 @@ static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG) } } // re-enable dma - if(leftover) - { + if (leftover) { set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer)); set_dma_count(devpriv->dma, leftover * sample_size); enable_dma(devpriv->dma); @@ -323,13 +316,13 @@ static irqreturn_t a2150_interrupt(int irq, void *d PT_REGS_ARG) } // probes board type, returns offset -static int a2150_probe(comedi_device *dev) +static int a2150_probe(comedi_device * dev) { int status = inw(dev->iobase + STATUS_REG); return ID_BITS(status); } -static int a2150_attach(comedi_device *dev, comedi_devconfig *it) +static int a2150_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase = it->options[0]; @@ -338,75 +331,65 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) static const int timeout = 2000; int i; - printk("comedi%d: %s: io 0x%lx", dev->minor, driver_a2150.driver_name, iobase); - if(irq) - { + printk("comedi%d: %s: io 0x%lx", dev->minor, driver_a2150.driver_name, + iobase); + if (irq) { printk(", irq %u", irq); - }else - { + } else { printk(", no irq"); } - if(dma) - { + if (dma) { printk(", dma %u", dma); - }else - { + } else { printk(", no dma"); } printk("\n"); /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(a2150_private)) < 0) + if (alloc_private(dev, sizeof(a2150_private)) < 0) return -ENOMEM; - if(iobase == 0) - { + if (iobase == 0) { printk(" io base address required\n"); return -EINVAL; } /* check if io addresses are available */ - if(!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) - { + if (!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) { printk(" I/O port conflict\n"); return -EIO; } dev->iobase = iobase; /* grab our IRQ */ - if(irq) - { + if (irq) { // check that irq is supported - if(irq < 3 || irq == 8 || irq == 13 || irq > 15) - { + if (irq < 3 || irq == 8 || irq == 13 || irq > 15) { printk(" invalid irq line %u\n", irq); return -EINVAL; } - if(comedi_request_irq( irq, a2150_interrupt, 0, driver_a2150.driver_name, dev )) - { - printk( "unable to allocate irq %u\n", irq); + if (comedi_request_irq(irq, a2150_interrupt, 0, + driver_a2150.driver_name, dev)) { + printk("unable to allocate irq %u\n", irq); return -EINVAL; } devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq); dev->irq = irq; } - // initialize dma - if(dma) - { - if(dma == 4 || dma > 7) - { + if (dma) { + if (dma == 4 || dma > 7) { printk(" invalid dma channel %u\n", dma); return -EINVAL; } - if(request_dma(dma, driver_a2150.driver_name)) - { + if (request_dma(dma, driver_a2150.driver_name)) { printk(" failed to allocate dma channel %u\n", dma); return -EINVAL; } devpriv->dma = dma; - devpriv->dma_buffer = kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); - if(devpriv->dma_buffer == NULL) + devpriv->dma_buffer = + kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); + if (devpriv->dma_buffer == NULL) return -ENOMEM; disable_dma(dma); @@ -418,7 +401,7 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) dev->board_ptr = a2150_boards + a2150_probe(dev); dev->board_name = thisboard->name; - if(alloc_subdevices(dev, 1) < 0) + if (alloc_subdevices(dev, 1) < 0) return -ENOMEM; /* analog input subdevice */ @@ -449,14 +432,12 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) devpriv->config_bits = 0; outw(devpriv->config_bits, dev->iobase + CONFIG_REG); // wait until offset calibration is done, then enable analog inputs - for(i = 0; i < timeout; i++) - { - if((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0) + for (i = 0; i < timeout; i++) { + if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0) break; comedi_udelay(1000); } - if(i == timeout) - { + if (i == timeout) { printk(" timed out waiting for offset calibration to complete\n"); return -ETIME; } @@ -466,32 +447,30 @@ static int a2150_attach(comedi_device *dev, comedi_devconfig *it) return 0; }; -static int a2150_detach(comedi_device *dev) +static int a2150_detach(comedi_device * dev) { printk("comedi%d: %s: remove\n", dev->minor, driver_a2150.driver_name); /* only free stuff if it has been allocated by _attach */ - if(dev->iobase) - { + if (dev->iobase) { // put board in power-down mode outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG); release_region(dev->iobase, A2150_SIZE); } - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(devpriv) - { - if(devpriv->dma) + if (devpriv) { + if (devpriv->dma) free_dma(devpriv->dma); - if(devpriv->dma_buffer) + if (devpriv->dma_buffer) kfree(devpriv->dma_buffer); } return 0; }; -static int a2150_cancel(comedi_device *dev, comedi_subdevice *s) +static int a2150_cancel(comedi_device * dev, comedi_subdevice * s) { // disable dma on card devpriv->irq_dma_bits &= ~DMA_INTR_EN_BIT & ~DMA_EN_BIT; @@ -506,7 +485,8 @@ static int a2150_cancel(comedi_device *dev, comedi_subdevice *s) return 0; } -static int a2150_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int a2150_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp; @@ -517,125 +497,125 @@ static int a2150_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *c tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_COUNT | TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) err++; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg != 0) - { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { cmd->chanlist_len = 1; err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + 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) - { + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { cmd->stop_arg = 1; err++; } - } else - { /* TRIG_NONE */ - if(cmd->stop_arg != 0) - { + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; a2150_get_timing(dev, &cmd->scan_begin_arg, cmd->flags); - if(tmp != cmd->scan_begin_arg) err++; + if (tmp != cmd->scan_begin_arg) + err++; } - if(err)return 4; + if (err) + return 4; // check channel/gain list against card's limitations - if(cmd->chanlist) - { + if (cmd->chanlist) { startChan = CR_CHAN(cmd->chanlist[0]); - for(i = 1; i < cmd->chanlist_len; i++) - { - if(CR_CHAN(cmd->chanlist[i]) != (startChan + i)) - { - comedi_error(dev, "entries in chanlist must be consecutive channels, counting upwards\n"); + for (i = 1; i < cmd->chanlist_len; i++) { + if (CR_CHAN(cmd->chanlist[i]) != (startChan + i)) { + comedi_error(dev, + "entries in chanlist must be consecutive channels, counting upwards\n"); err++; } } - if(cmd->chanlist_len == 2 && CR_CHAN(cmd->chanlist[0]) == 1) - { - comedi_error(dev, "length 2 chanlist must be channels 0,1 or channels 2,3"); + if (cmd->chanlist_len == 2 && CR_CHAN(cmd->chanlist[0]) == 1) { + comedi_error(dev, + "length 2 chanlist must be channels 0,1 or channels 2,3"); err++; } - if(cmd->chanlist_len == 3) - { - comedi_error(dev, "chanlist must have 1,2 or 4 channels"); + if (cmd->chanlist_len == 3) { + comedi_error(dev, + "chanlist must have 1,2 or 4 channels"); err++; } - if(CR_AREF(cmd->chanlist[0]) != CR_AREF(cmd->chanlist[1]) || + if (CR_AREF(cmd->chanlist[0]) != CR_AREF(cmd->chanlist[1]) || CR_AREF(cmd->chanlist[2]) != CR_AREF(cmd->chanlist[3])) { - comedi_error(dev, "channels 0/1 and 2/3 must have the same analog reference"); + comedi_error(dev, + "channels 0/1 and 2/3 must have the same analog reference"); err++; } } - if(err)return 5; + if (err) + return 5; return 0; } -static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int a2150_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -643,30 +623,30 @@ static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) unsigned int old_config_bits = devpriv->config_bits; unsigned int trigger_bits; - if(!dev->irq || !devpriv->dma) - { - comedi_error(dev, " irq and dma required, cannot do hardware conversions"); + if (!dev->irq || !devpriv->dma) { + comedi_error(dev, + " irq and dma required, cannot do hardware conversions"); return -1; } - if(cmd->flags & TRIG_RT) - { - comedi_error(dev, " dma incompatible with hard real-time interrupt (TRIG_RT), aborting"); + if (cmd->flags & TRIG_RT) { + comedi_error(dev, + " dma incompatible with hard real-time interrupt (TRIG_RT), aborting"); return -1; } - // clear fifo and reset triggering circuitry outw(0, dev->iobase + FIFO_RESET_REG); /* setup chanlist */ - if(a2150_set_chanlist(dev, CR_CHAN(cmd->chanlist[0]), cmd->chanlist_len) < 0) + if (a2150_set_chanlist(dev, CR_CHAN(cmd->chanlist[0]), + cmd->chanlist_len) < 0) return -1; // setup ac/dc coupling - if(CR_AREF(cmd->chanlist[0]) == AREF_OTHER) + if (CR_AREF(cmd->chanlist[0]) == AREF_OTHER) devpriv->config_bits |= AC0_BIT; else devpriv->config_bits &= ~AC0_BIT; - if(CR_AREF(cmd->chanlist[2]) == AREF_OTHER) + if (CR_AREF(cmd->chanlist[2]) == AREF_OTHER) devpriv->config_bits |= AC1_BIT; else devpriv->config_bits &= ~AC1_BIT; @@ -689,18 +669,20 @@ static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer)); // set size of transfer to fill in 1/3 second #define ONE_THIRD_SECOND 333333333 - devpriv->dma_transfer_size = sizeof(devpriv->dma_buffer[0]) * cmd->chanlist_len * + devpriv->dma_transfer_size = + sizeof(devpriv->dma_buffer[0]) * cmd->chanlist_len * ONE_THIRD_SECOND / cmd->scan_begin_arg; - if(devpriv->dma_transfer_size > A2150_DMA_BUFFER_SIZE) + if (devpriv->dma_transfer_size > A2150_DMA_BUFFER_SIZE) devpriv->dma_transfer_size = A2150_DMA_BUFFER_SIZE; - if(devpriv->dma_transfer_size < sizeof(devpriv->dma_buffer[0])) + if (devpriv->dma_transfer_size < sizeof(devpriv->dma_buffer[0])) devpriv->dma_transfer_size = sizeof(devpriv->dma_buffer[0]); - devpriv->dma_transfer_size -= devpriv->dma_transfer_size % sizeof(devpriv->dma_buffer[0]); + devpriv->dma_transfer_size -= + devpriv->dma_transfer_size % sizeof(devpriv->dma_buffer[0]); set_dma_count(devpriv->dma, devpriv->dma_transfer_size); enable_dma(devpriv->dma); release_dma_lock(lock_flags); - /* clear dma interrupt before enabling it, to try and get rid of that + /* clear dma interrupt before enabling it, to try and get rid of that * one spurious interrupt that has been happening */ outw(0x00, dev->iobase + DMA_TC_CLEAR_REG); @@ -714,22 +696,19 @@ static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) // setup start triggering trigger_bits = 0; // decide if we need to wait 72 periods for valid data - if(cmd->start_src == TRIG_NOW && - (old_config_bits & CLOCK_MASK) != (devpriv->config_bits & CLOCK_MASK)) - { + if (cmd->start_src == TRIG_NOW && + (old_config_bits & CLOCK_MASK) != + (devpriv->config_bits & CLOCK_MASK)) { // set trigger source to delay trigger trigger_bits |= DELAY_TRIGGER_BITS; - }else - { + } else { // otherwise no delay trigger_bits |= POST_TRIGGER_BITS; } // enable external hardware trigger - if(cmd->start_src == TRIG_EXT) - { + if (cmd->start_src == TRIG_EXT) { trigger_bits |= HW_TRIG_EN; - }else if(cmd->start_src == TRIG_OTHER) - { + } else if (cmd->start_src == TRIG_OTHER) { // XXX add support for level/slope start trigger using TRIG_OTHER comedi_error(dev, "you shouldn't see this?"); } @@ -737,11 +716,9 @@ static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) outw(trigger_bits, dev->iobase + TRIGGER_REG); // start aquisition for soft trigger - if(cmd->start_src == TRIG_NOW) - { + if (cmd->start_src == TRIG_NOW) { outw(0, dev->iobase + FIFO_START_REG); } - #ifdef A2150_DEBUG ni_dump_regs(dev); #endif @@ -749,7 +726,8 @@ static int a2150_ai_cmd(comedi_device *dev, comedi_subdevice *s) return 0; } -static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int a2150_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int i, n; static const int timeout = 100000; @@ -759,7 +737,7 @@ static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * outw(0, dev->iobase + FIFO_RESET_REG); /* setup chanlist */ - if(a2150_set_chanlist(dev, CR_CHAN(insn->chanspec), 1) < 0) + if (a2150_set_chanlist(dev, CR_CHAN(insn->chanspec), 1) < 0) return -1; // set dc coupling @@ -780,16 +758,13 @@ static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * outw(0, dev->iobase + FIFO_START_REG); /* there is a 35.6 sample delay for data to get through the antialias filter */ - for(n = 0; n < filter_delay; n++) - { - for(i = 0; i < timeout; i++) - { - if(inw(dev->iobase + STATUS_REG) & FNE_BIT) + for (n = 0; n < filter_delay; n++) { + for (i = 0; i < timeout; i++) { + if (inw(dev->iobase + STATUS_REG) & FNE_BIT) break; comedi_udelay(1); } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } @@ -797,26 +772,22 @@ static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * } // read data - for(n = 0; n < insn->n; n++) - { - for(i = 0; i < timeout; i++) - { - if(inw(dev->iobase + STATUS_REG) & FNE_BIT) + for (n = 0; n < insn->n; n++) { + for (i = 0; i < timeout; i++) { + if (inw(dev->iobase + STATUS_REG) & FNE_BIT) break; comedi_udelay(1); } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } - #ifdef A2150_DEBUG - ni_dump_regs(dev); + ni_dump_regs(dev); #endif data[n] = inw(dev->iobase + FIFO_DATA_REG); #ifdef A2150_DEBUG - rt_printk(" data is %i\n", data[n]); + rt_printk(" data is %i\n", data[n]); #endif data[n] ^= 0x8000; } @@ -829,7 +800,8 @@ static int a2150_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * /* sets bits in devpriv->clock_bits to nearest approximation of requested period, * adjusts requested period to actual timing. */ -static int a2150_get_timing(comedi_device *dev, unsigned int *period, int flags) +static int a2150_get_timing(comedi_device * dev, unsigned int *period, + int flags) { int lub, glb, temp; int lub_divisor_shift, lub_index, glb_divisor_shift, glb_index; @@ -844,28 +816,24 @@ static int a2150_get_timing(comedi_device *dev, unsigned int *period, int flags) glb = thisboard->clock[glb_index] * (1 << glb_divisor_shift); // make sure period is in available range - if(*period < glb) + if (*period < glb) *period = glb; - if(*period > lub) + if (*period > lub) *period = lub; // we can multiply period by 1, 2, 4, or 8, using (1 << i) - for(i = 0; i < 4; i++) - { + for (i = 0; i < 4; i++) { // there are a maximum of 4 master clocks - for(j = 0; j < thisboard->num_clocks; j++) - { + for (j = 0; j < thisboard->num_clocks; j++) { // temp is the period in nanosec we are evaluating temp = thisboard->clock[j] * (1 << i); // if it is the best match yet - if(temp < lub && temp >= *period) - { + if (temp < lub && temp >= *period) { lub_divisor_shift = i; lub_index = j; lub = temp; } - if(temp > glb && temp <= *period) - { + if (temp > glb && temp <= *period) { glb_divisor_shift = i; glb_index = j; glb = temp; @@ -873,72 +841,67 @@ static int a2150_get_timing(comedi_device *dev, unsigned int *period, int flags) } } flags &= TRIG_ROUND_MASK; - switch (flags) - { - case TRIG_ROUND_NEAREST: - default: - // if least upper bound is better approximation - if(lub - *period < *period - glb) - { - *period = lub; - }else - { - *period = glb; - } - break; - case TRIG_ROUND_UP: - *period = lub; - break; - case TRIG_ROUND_DOWN: - *period = glb; - break; + switch (flags) { + case TRIG_ROUND_NEAREST: + default: + // if least upper bound is better approximation + if (lub - *period < *period - glb) { + *period = lub; + } else { + *period = glb; + } + break; + case TRIG_ROUND_UP: + *period = lub; + break; + case TRIG_ROUND_DOWN: + *period = glb; + break; } // set clock bits for config register appropriately devpriv->config_bits &= ~CLOCK_MASK; - if(*period == lub) - { - devpriv->config_bits |= CLOCK_SELECT_BITS(lub_index) | CLOCK_DIVISOR_BITS(lub_divisor_shift); - }else - { - devpriv->config_bits |= CLOCK_SELECT_BITS(glb_index) | CLOCK_DIVISOR_BITS(glb_divisor_shift); + if (*period == lub) { + devpriv->config_bits |= + CLOCK_SELECT_BITS(lub_index) | + CLOCK_DIVISOR_BITS(lub_divisor_shift); + } else { + devpriv->config_bits |= + CLOCK_SELECT_BITS(glb_index) | + CLOCK_DIVISOR_BITS(glb_divisor_shift); } return 0; } -static int a2150_set_chanlist(comedi_device *dev, unsigned int start_channel, unsigned int num_channels) +static int a2150_set_chanlist(comedi_device * dev, unsigned int start_channel, + unsigned int num_channels) { - if(start_channel + num_channels > 4) + if (start_channel + num_channels > 4) return -1; devpriv->config_bits &= ~CHANNEL_MASK; - switch(num_channels) - { - case 1: - devpriv->config_bits |= CHANNEL_BITS(0x4 | start_channel); - break; - case 2: - if(start_channel == 0) - { - devpriv->config_bits |= CHANNEL_BITS(0x2); - }else if(start_channel == 2) - { - devpriv->config_bits |= CHANNEL_BITS(0x3); - }else - { - return -1; - } - break; - case 4: - devpriv->config_bits |= CHANNEL_BITS(0x1); - break; - default: + switch (num_channels) { + case 1: + devpriv->config_bits |= CHANNEL_BITS(0x4 | start_channel); + break; + case 2: + if (start_channel == 0) { + devpriv->config_bits |= CHANNEL_BITS(0x2); + } else if (start_channel == 2) { + devpriv->config_bits |= CHANNEL_BITS(0x3); + } else { return -1; - break; + } + break; + case 4: + devpriv->config_bits |= CHANNEL_BITS(0x1); + break; + default: + return -1; + break; } return 0; } - diff --git a/comedi/drivers/ni_at_ao.c b/comedi/drivers/ni_at_ao.c index 2147c6dd..17d055e6 100644 --- a/comedi/drivers/ni_at_ao.c +++ b/comedi/drivers/ni_at_ao.c @@ -44,7 +44,6 @@ Configuration options: #include - /* board egisters */ /* registers with _2_ are accessed when GRP2WR is set in CFG1 */ @@ -55,33 +54,33 @@ Configuration options: #define ATAO_DOUT 0x00 /* W 16 */ #define ATAO_CFG2 0x02 /* W 16 */ - #define CALLD1 0x8000 - #define CALLD0 0x4000 - #define FFRTEN 0x2000 - #define DAC2S8 0x1000 - #define DAC2S6 0x0800 - #define DAC2S4 0x0400 - #define DAC2S2 0x0200 - #define DAC2S0 0x0100 - #define LDAC8 0x0080 - #define LDAC6 0x0040 - #define LDAC4 0x0020 - #define LDAC2 0x0010 - #define LDAC0 0x0008 - #define PROMEN 0x0004 - #define SCLK 0x0002 - #define SDATA 0x0001 +#define CALLD1 0x8000 +#define CALLD0 0x4000 +#define FFRTEN 0x2000 +#define DAC2S8 0x1000 +#define DAC2S6 0x0800 +#define DAC2S4 0x0400 +#define DAC2S2 0x0200 +#define DAC2S0 0x0100 +#define LDAC8 0x0080 +#define LDAC6 0x0040 +#define LDAC4 0x0020 +#define LDAC2 0x0010 +#define LDAC0 0x0008 +#define PROMEN 0x0004 +#define SCLK 0x0002 +#define SDATA 0x0001 #define ATAO_2_INT1CLR 0x02 /* W 16 */ #define ATAO_CFG3 0x04 /* W 16 */ - #define DMAMODE 0x0040 - #define CLKOUT 0x0020 - #define RCLKEN 0x0010 - #define DOUTEN2 0x0008 - #define DOUTEN1 0x0004 - #define EN2_5V 0x0002 - #define SCANEN 0x0001 +#define DMAMODE 0x0040 +#define CLKOUT 0x0020 +#define RCLKEN 0x0010 +#define DOUTEN2 0x0008 +#define DOUTEN1 0x0004 +#define EN2_5V 0x0002 +#define SCANEN 0x0001 #define ATAO_2_INT2CLR 0x04 /* W 16 */ @@ -91,57 +90,57 @@ Configuration options: #define ATAO_82C53_CNTR2 0x07 /* RW 8 */ #define ATAO_82C53_CNTR3 0x08 /* RW 8 */ #define ATAO_82C53_CNTRCMD 0x09 /* W 8 */ - #define CNTRSEL1 0x80 - #define CNTRSEL0 0x40 - #define RWSEL1 0x20 - #define RWSEL0 0x10 - #define MODESEL2 0x08 - #define MODESEL1 0x04 - #define MODESEL0 0x02 - #define BCDSEL 0x01 +#define CNTRSEL1 0x80 +#define CNTRSEL0 0x40 +#define RWSEL1 0x20 +#define RWSEL0 0x10 +#define MODESEL2 0x08 +#define MODESEL1 0x04 +#define MODESEL0 0x02 +#define BCDSEL 0x01 /* read-back command */ - #define COUNT 0x20 - #define STATUS 0x10 - #define CNTR3 0x08 - #define CNTR2 0x04 - #define CNTR1 0x02 +#define COUNT 0x20 +#define STATUS 0x10 +#define CNTR3 0x08 +#define CNTR2 0x04 +#define CNTR1 0x02 /* status */ - #define OUT 0x80 - #define _NULL 0x40 - #define RW1 0x20 - #define RW0 0x10 - #define MODE2 0x08 - #define MODE1 0x04 - #define MODE0 0x02 - #define BCD 0x01 +#define OUT 0x80 +#define _NULL 0x40 +#define RW1 0x20 +#define RW0 0x10 +#define MODE2 0x08 +#define MODE1 0x04 +#define MODE0 0x02 +#define BCD 0x01 #define ATAO_2_RTSISHFT 0x06 /* W 8 */ - #define RSI 0x01 +#define RSI 0x01 #define ATAO_2_RTSISTRB 0x07 /* W 8 */ #define ATAO_CFG1 0x0a /* W 16 */ - #define EXTINT2EN 0x8000 - #define EXTINT1EN 0x4000 - #define CNTINT2EN 0x2000 - #define CNTINT1EN 0x1000 - #define TCINTEN 0x0800 - #define CNT1SRC 0x0400 - #define CNT2SRC 0x0200 - #define FIFOEN 0x0100 - #define GRP2WR 0x0080 - #define EXTUPDEN 0x0040 - #define DMARQ 0x0020 - #define DMAEN 0x0010 - #define CH_mask 0x000f +#define EXTINT2EN 0x8000 +#define EXTINT1EN 0x4000 +#define CNTINT2EN 0x2000 +#define CNTINT1EN 0x1000 +#define TCINTEN 0x0800 +#define CNT1SRC 0x0400 +#define CNT2SRC 0x0200 +#define FIFOEN 0x0100 +#define GRP2WR 0x0080 +#define EXTUPDEN 0x0040 +#define DMARQ 0x0020 +#define DMAEN 0x0010 +#define CH_mask 0x000f #define ATAO_STATUS 0x0a /* R 16 */ - #define FH 0x0040 - #define FE 0x0020 - #define FF 0x0010 - #define INT2 0x0008 - #define INT1 0x0004 - #define TCINT 0x0002 - #define PROMOUT 0x0001 +#define FH 0x0040 +#define FE 0x0020 +#define FF 0x0010 +#define INT2 0x0008 +#define INT1 0x0004 +#define TCINT 0x0002 +#define PROMOUT 0x0001 #define ATAO_FIFO_WRITE 0x0c /* W 16 */ #define ATAO_FIFO_CLEAR 0x0c /* R 16 */ @@ -152,71 +151,76 @@ Configuration options: * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct atao_board_struct{ +typedef struct atao_board_struct { const char *name; int n_ao_chans; -}atao_board; +} atao_board; static const atao_board atao_boards[] = { { - name: "ai-ao-6", - n_ao_chans: 6, - }, + name: "ai-ao-6", + n_ao_chans:6, + }, { - name: "ai-ao-10", - n_ao_chans: 10, - }, + name: "ai-ao-10", + n_ao_chans:10, + }, }; + #define thisboard ((atao_board *)dev->board_ptr) -typedef struct{ +typedef struct { unsigned short cfg1; unsigned short cfg2; unsigned short cfg3; /* Used for AO readback */ lsampl_t ao_readback[10]; -}atao_private; +} atao_private; #define devpriv ((atao_private *)dev->private) -static int atao_attach(comedi_device *dev,comedi_devconfig *it); -static int atao_detach(comedi_device *dev); -static comedi_driver driver_atao={ - driver_name: "ni_at_ao", - module: THIS_MODULE, - attach: atao_attach, - detach: atao_detach, - board_name: &atao_boards[0].name, - offset: sizeof(atao_board), - num_names: sizeof(atao_boards) / sizeof(atao_board), +static int atao_attach(comedi_device * dev, comedi_devconfig * it); +static int atao_detach(comedi_device * dev); +static comedi_driver driver_atao = { + driver_name:"ni_at_ao", + module:THIS_MODULE, + attach:atao_attach, + detach:atao_detach, + board_name:&atao_boards[0].name, + offset:sizeof(atao_board), + num_names:sizeof(atao_boards) / sizeof(atao_board), }; -COMEDI_INITCLEANUP(driver_atao); - -static void atao_reset(comedi_device *dev); -static int atao_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int atao_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int atao_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int atao_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int atao_calib_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int atao_calib_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +COMEDI_INITCLEANUP(driver_atao); -static int atao_attach(comedi_device *dev,comedi_devconfig *it) +static void atao_reset(comedi_device * dev); + +static int atao_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int atao_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int atao_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int atao_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int atao_calib_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int atao_calib_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int atao_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; int ao_unipolar; iobase = it->options[0]; - if(iobase==0)iobase = 0x1c0; + if (iobase == 0) + iobase = 0x1c0; ao_unipolar = it->options[3]; - printk("comedi%d: ni_at_ao: 0x%04lx",dev->minor,iobase); + printk("comedi%d: ni_at_ao: 0x%04lx", dev->minor, iobase); - if(!request_region(iobase, ATAO_SIZE, "ni_at_ao")){ + if (!request_region(iobase, ATAO_SIZE, "ni_at_ao")) { printk(" I/O port conflict\n"); return -EIO; } @@ -226,48 +230,48 @@ static int atao_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(atao_private))<0) + if (alloc_private(dev, sizeof(atao_private)) < 0) return -ENOMEM; - if(alloc_subdevices(dev, 4)<0) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=thisboard->n_ao_chans; - s->maxdata=(1<<12)-1; - if(ao_unipolar) - s->range_table=&range_unipolar10; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = thisboard->n_ao_chans; + s->maxdata = (1 << 12) - 1; + if (ao_unipolar) + s->range_table = &range_unipolar10; else - s->range_table=&range_bipolar10; + s->range_table = &range_bipolar10; s->insn_write = &atao_ao_winsn; s->insn_read = &atao_ao_rinsn; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* digital i/o subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = atao_dio_insn_bits; s->insn_config = atao_dio_insn_config; - s=dev->subdevices+2; + s = dev->subdevices + 2; /* caldac subdevice */ - s->type=COMEDI_SUBD_CALIB; - s->subdev_flags = SDF_WRITABLE|SDF_INTERNAL; + s->type = COMEDI_SUBD_CALIB; + s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 21; s->maxdata = 0xff; s->insn_read = atao_calib_insn_read; s->insn_write = atao_calib_insn_write; - s=dev->subdevices+3; + s = dev->subdevices + 3; /* eeprom subdevice */ //s->type=COMEDI_SUBD_EEPROM; - s->type=COMEDI_SUBD_UNUSED; + s->type = COMEDI_SUBD_UNUSED; atao_reset(dev); @@ -276,19 +280,17 @@ static int atao_attach(comedi_device *dev,comedi_devconfig *it) return 0; } - -static int atao_detach(comedi_device *dev) +static int atao_detach(comedi_device * dev) { - printk("comedi%d: atao: remove\n",dev->minor); + printk("comedi%d: atao: remove\n", dev->minor); - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, ATAO_SIZE); return 0; } - -static void atao_reset(comedi_device *dev) +static void atao_reset(comedi_device * dev) { /* This is the reset sequence described in the manual */ @@ -318,23 +320,21 @@ static void atao_reset(comedi_device *dev) outw(devpriv->cfg1, dev->iobase + ATAO_CFG1); } - -static int atao_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int atao_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); short bits; - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { bits = data[i] - 0x800; - if(chan == 0) - { + if (chan == 0) { devpriv->cfg1 |= GRP2WR; outw(devpriv->cfg1, dev->iobase + ATAO_CFG1); } outw(bits, dev->iobase + ATAO_DACn(chan)); - if(chan == 0) - { + if (chan == 0) { devpriv->cfg1 &= ~GRP2WR; outw(devpriv->cfg1, dev->iobase + ATAO_CFG1); } @@ -344,37 +344,39 @@ static int atao_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins return i; } -static int atao_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int atao_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; } -static int atao_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int atao_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; - outw(s->state,dev->iobase + ATAO_DOUT); + s->state |= data[0] & data[1]; + outw(s->state, dev->iobase + ATAO_DOUT); } - data[1]=inw(dev->iobase + ATAO_DIN); + data[1] = inw(dev->iobase + ATAO_DIN); return 2; } -static int atao_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int atao_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); unsigned int mask, bit; /* The input or output configuration of each digital line is @@ -385,8 +387,7 @@ static int atao_dio_insn_config(comedi_device *dev,comedi_subdevice *s, mask = (chan < 4) ? 0x0f : 0xf0; bit = (chan < 4) ? DOUTEN1 : DOUTEN2; - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: s->io_bits |= mask; devpriv->cfg3 |= bit; @@ -396,7 +397,9 @@ static int atao_dio_insn_config(comedi_device *dev,comedi_subdevice *s, devpriv->cfg3 &= ~bit; break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: @@ -409,40 +412,40 @@ static int atao_dio_insn_config(comedi_device *dev,comedi_subdevice *s, return 1; } - /* * Figure 2-1 in the manual shows 3 chips labeled DAC8800, which * are 8-channel 8-bit DACs. These are most likely the calibration * DACs. It is not explicitly stated in the manual how to access * the caldacs, but we can guess. */ -static int atao_calib_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int atao_calib_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; - for(i=0;in;i++){ - data[i]=0; /* XXX */ + for (i = 0; i < insn->n; i++) { + data[i] = 0; /* XXX */ } return insn->n; } -static int atao_calib_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int atao_calib_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int bitstring, bit; unsigned int chan = CR_CHAN(insn->chanspec); - bitstring = ((chan&0x7)<<8)|(data[insn->n-1]&0xff); + bitstring = ((chan & 0x7) << 8) | (data[insn->n - 1] & 0xff); - for(bit=1<<(11-1);bit;bit>>=1){ - outw(devpriv->cfg2 | ((bit&bitstring)?SDATA:0), dev->iobase + ATAO_CFG2); - outw(devpriv->cfg2 | SCLK | ((bit&bitstring)?SDATA:0), dev->iobase + ATAO_CFG2); + for (bit = 1 << (11 - 1); bit; bit >>= 1) { + outw(devpriv->cfg2 | ((bit & bitstring) ? SDATA : 0), + dev->iobase + ATAO_CFG2); + outw(devpriv->cfg2 | SCLK | ((bit & bitstring) ? SDATA : 0), + dev->iobase + ATAO_CFG2); } /* strobe the appropriate caldac */ - outw(devpriv->cfg2 | (((chan>>3) + 1)<<14), dev->iobase + ATAO_CFG2); + outw(devpriv->cfg2 | (((chan >> 3) + 1) << 14), + dev->iobase + ATAO_CFG2); outw(devpriv->cfg2, dev->iobase + ATAO_CFG2); return insn->n; } - - diff --git a/comedi/drivers/ni_atmio.c b/comedi/drivers/ni_atmio.c index 2e09c8dd..92a82a08 100644 --- a/comedi/drivers/ni_atmio.c +++ b/comedi/drivers/ni_atmio.c @@ -64,7 +64,6 @@ are not supported. The real guts of the driver is in ni_mio_common.c, which is included both here and in ni_pcimio.c - Interrupt support added by Truxton Fulton References for specifications: @@ -115,160 +114,161 @@ are not supported. #define MAX_N_CALDACS 32 -static const ni_board ni_boards[]={ - { device_id: 44, - isapnp_id: 0x0000, /* XXX unknown */ - name: "at-mio-16e-1", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 800, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - has_8255: 0, - .num_p0_dio_channels = 8, - caldac: {mb88341}, - }, - { device_id: 25, - isapnp_id: 0x1900, - name: "at-mio-16e-2", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 2048, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 2000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - has_8255: 0, - .num_p0_dio_channels = 8, - caldac: {mb88341}, - }, - { device_id: 36, - isapnp_id: 0x2400, - name: "at-mio-16e-10", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 10000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 37, - isapnp_id: 0x2500, - name: "at-mio-16de-10", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 10000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 1, - }, - { device_id: 38, - isapnp_id: 0x2600, - name: "at-mio-64e-3", - n_adchan: 64, - adbits: 12, - ai_fifo_depth: 2048, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 2000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - has_8255: 0, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - }, - { device_id: 39, - isapnp_id: 0x2700, - name: "at-mio-16xe-50", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_8, - ai_speed: 50000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 50000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043}, - has_8255: 0, - }, - { device_id: 50, - isapnp_id: 0x0000, /* XXX unknown */ - name: "at-mio-16xe-10", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - { device_id: 51, - isapnp_id: 0x0000, /* XXX unknown */ - name: "at-ai-16xe-10", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, /* unknown */ - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - } +static const ni_board ni_boards[] = { + {device_id:44, + isapnp_id:0x0000,/* XXX unknown */ + name: "at-mio-16e-1", + n_adchan:16, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:800, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + has_8255:0, + .num_p0_dio_channels = 8, + caldac: {mb88341}, + }, + {device_id:25, + isapnp_id:0x1900, + name: "at-mio-16e-2", + n_adchan:16, + adbits: 12, + ai_fifo_depth:2048, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:2000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + has_8255:0, + .num_p0_dio_channels = 8, + caldac: {mb88341}, + }, + {device_id:36, + isapnp_id:0x2400, + name: "at-mio-16e-10", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:10000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:37, + isapnp_id:0x2500, + name: "at-mio-16de-10", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:10000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:1, + }, + {device_id:38, + isapnp_id:0x2600, + name: "at-mio-64e-3", + n_adchan:64, + adbits: 12, + ai_fifo_depth:2048, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:2000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + has_8255:0, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + }, + {device_id:39, + isapnp_id:0x2700, + name: "at-mio-16xe-50", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_8, + ai_speed:50000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:50000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043}, + has_8255:0, + }, + {device_id:50, + isapnp_id:0x0000,/* XXX unknown */ + name: "at-mio-16xe-10", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + {device_id:51, + isapnp_id:0x0000,/* XXX unknown */ + name: "at-ai-16xe-10", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, /* unknown */ + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + } }; -static const int ni_irqpin[]={-1,-1,-1,0,1,2,-1,3,-1,-1,4,5,6,-1,-1,7}; +static const int ni_irqpin[] = + { -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7 }; #define interrupt_pin(a) (ni_irqpin[(a)]) @@ -276,10 +276,9 @@ static const int ni_irqpin[]={-1,-1,-1,0,1,2,-1,3,-1,-1,4,5,6,-1,-1,7}; #define NI_E_IRQ_FLAGS 0 -typedef struct{ +typedef struct { struct pnp_dev *isapnp_dev; - NI_PRIVATE_COMMON -}ni_private; + NI_PRIVATE_COMMON} ni_private; #define devpriv ((ni_private *)dev->private) /* How we access registers */ @@ -297,138 +296,137 @@ typedef struct{ * read/written directly in the I/O space of the board. The * AT-MIO devices map the low 8 STC registers to iobase+addr*2. */ -static void ni_atmio_win_out(comedi_device *dev, uint16_t data, int addr) +static void ni_atmio_win_out(comedi_device * dev, uint16_t data, int addr) { unsigned long flags; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - if((addr)<8){ - ni_writew(data,addr*2); - }else{ - ni_writew(addr,Window_Address); - ni_writew(data,Window_Data); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + if ((addr) < 8) { + ni_writew(data, addr * 2); + } else { + ni_writew(addr, Window_Address); + ni_writew(data, Window_Data); } - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); } -static uint16_t ni_atmio_win_in(comedi_device *dev, int addr) +static uint16_t ni_atmio_win_in(comedi_device * dev, int addr) { unsigned long flags; uint16_t ret; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - if(addr<8){ - ret = ni_readw(addr*2); - }else{ - ni_writew(addr,Window_Address); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + if (addr < 8) { + ret = ni_readw(addr * 2); + } else { + ni_writew(addr, Window_Address); ret = ni_readw(Window_Data); } - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); return ret; } static struct pnp_device_id device_ids[] = { - {.id = "NIC1900", .driver_data = 0}, - {.id = "NIC2400", .driver_data = 0}, - {.id = "NIC2500", .driver_data = 0}, - {.id = "NIC2600", .driver_data = 0}, - {.id = "NIC2700", .driver_data = 0}, + {.id = "NIC1900",.driver_data = 0}, + {.id = "NIC2400",.driver_data = 0}, + {.id = "NIC2500",.driver_data = 0}, + {.id = "NIC2600",.driver_data = 0}, + {.id = "NIC2700",.driver_data = 0}, {.id = ""} }; + MODULE_DEVICE_TABLE(pnp, device_ids); -static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it); -static int ni_atmio_detach(comedi_device *dev); -static comedi_driver driver_atmio={ - driver_name: "ni_atmio", - module: THIS_MODULE, - attach: ni_atmio_attach, - detach: ni_atmio_detach, +static int ni_atmio_attach(comedi_device * dev, comedi_devconfig * it); +static int ni_atmio_detach(comedi_device * dev); +static comedi_driver driver_atmio = { + driver_name:"ni_atmio", + module:THIS_MODULE, + attach:ni_atmio_attach, + detach:ni_atmio_detach, }; COMEDI_INITCLEANUP(driver_atmio); #include "ni_mio_common.c" -static int ni_getboardtype(comedi_device *dev); +static int ni_getboardtype(comedi_device * dev); /* clean up allocated resources */ -static int ni_atmio_detach(comedi_device *dev) +static int ni_atmio_detach(comedi_device * dev) { mio_common_detach(dev); - if(dev->iobase) - release_region(dev->iobase,NI_SIZE); - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->iobase) + release_region(dev->iobase, NI_SIZE); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } - if(devpriv->isapnp_dev) + if (devpriv->isapnp_dev) pnp_device_detach(devpriv->isapnp_dev); return 0; } -static int ni_isapnp_find_board( struct pnp_dev **dev ) +static int ni_isapnp_find_board(struct pnp_dev **dev) { struct pnp_dev *isapnp_dev = NULL; int i; - for( i = 0; i < n_ni_boards; i++ ) - { + for (i = 0; i < n_ni_boards; i++) { isapnp_dev = pnp_find_dev(NULL, - ISAPNP_VENDOR('N','I','C'), - ISAPNP_FUNCTION( ni_boards[ i ].isapnp_id ), - NULL); + ISAPNP_VENDOR('N', 'I', 'C'), + ISAPNP_FUNCTION(ni_boards[i].isapnp_id), NULL); - if(isapnp_dev == NULL || isapnp_dev->card == NULL) continue; + if (isapnp_dev == NULL || isapnp_dev->card == NULL) + continue; - if(pnp_device_attach(isapnp_dev) < 0) - { - printk( "ni_atmio: %s found but already active, skipping.\n", ni_boards[ i ].name ); + if (pnp_device_attach(isapnp_dev) < 0) { + printk("ni_atmio: %s found but already active, skipping.\n", ni_boards[i].name); continue; } - if(pnp_activate_dev(isapnp_dev) < 0) - { + if (pnp_activate_dev(isapnp_dev) < 0) { pnp_device_detach(isapnp_dev); return -EAGAIN; } - if(!pnp_port_valid(isapnp_dev, 0) || !pnp_irq_valid(isapnp_dev, 0)) - { + if (!pnp_port_valid(isapnp_dev, 0) + || !pnp_irq_valid(isapnp_dev, 0)) { pnp_device_detach(isapnp_dev); printk("ni_atmio: pnp invalid port or irq, aborting\n"); return -ENOMEM; } break; } - if( i == n_ni_boards ) return -ENODEV; + if (i == n_ni_boards) + return -ENODEV; *dev = isapnp_dev; return 0; } -static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it) +static int ni_atmio_attach(comedi_device * dev, comedi_devconfig * it) { struct pnp_dev *isapnp_dev; - int ret; - unsigned long iobase; - int board; - unsigned int irq; + int ret; + unsigned long iobase; + int board; + unsigned int irq; /* allocate private area */ - if((ret = ni_alloc_private(dev)) < 0) + if ((ret = ni_alloc_private(dev)) < 0) return ret; devpriv->stc_writew = &ni_atmio_win_out; devpriv->stc_readw = &ni_atmio_win_in; devpriv->stc_writel = &win_out2; devpriv->stc_readl = &win_in2; - iobase=it->options[0]; - irq=it->options[1]; + iobase = it->options[0]; + irq = it->options[1]; isapnp_dev = NULL; - if( iobase == 0 ) - { - ret = ni_isapnp_find_board( &isapnp_dev ); - if( ret < 0 ) return ret; + if (iobase == 0) { + ret = ni_isapnp_find_board(&isapnp_dev); + if (ret < 0) + return ret; iobase = pnp_port_start(isapnp_dev, 0); irq = pnp_irq(isapnp_dev, 0); @@ -437,78 +435,79 @@ static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it) /* reserve our I/O region */ - printk("comedi%d: ni_atmio: 0x%04lx",dev->minor,iobase); - if(!request_region(iobase,NI_SIZE,"ni_atmio")){ + printk("comedi%d: ni_atmio: 0x%04lx", dev->minor, iobase); + if (!request_region(iobase, NI_SIZE, "ni_atmio")) { printk(" I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; #ifdef DEBUG /* board existence sanity check */ - { - int i; - - printk(" board fingerprint:"); - for(i=0;i<16;i+=2){ - printk(" %04x %02x",inw(dev->iobase+i),inb(dev->iobase+i+1)); - } - } + { + int i; + + printk(" board fingerprint:"); + for (i = 0; i < 16; i += 2) { + printk(" %04x %02x", inw(dev->iobase + i), + inb(dev->iobase + i + 1)); + } + } #endif /* get board type */ - board=ni_getboardtype(dev); - if(board<0)return -EIO; + board = ni_getboardtype(dev); + if (board < 0) + return -EIO; - dev->board_ptr=ni_boards + board; + dev->board_ptr = ni_boards + board; - printk(" %s",boardtype.name); - dev->board_name=boardtype.name; + printk(" %s", boardtype.name); + dev->board_name = boardtype.name; /* irq stuff */ - if(irq!=0){ - if(irq>15 || ni_irqpin[irq]==-1){ - printk(" invalid irq %u\n",irq); + if (irq != 0) { + if (irq > 15 || ni_irqpin[irq] == -1) { + printk(" invalid irq %u\n", irq); return -EINVAL; } - printk(" ( irq = %u )",irq); - if( (ret=comedi_request_irq(irq,ni_E_interrupt,NI_E_IRQ_FLAGS,"ni_atmio",dev))<0 ){ + printk(" ( irq = %u )", irq); + if ((ret = comedi_request_irq(irq, ni_E_interrupt, + NI_E_IRQ_FLAGS, "ni_atmio", dev)) < 0) { printk(" irq not available\n"); return -EINVAL; } - dev->irq=irq; + dev->irq = irq; } /* generic E series stuff in ni_mio_common.c */ - if( (ret=ni_E_init(dev,it))<0 ){ + if ((ret = ni_E_init(dev, it)) < 0) { return ret; } return 0; } - -static int ni_getboardtype(comedi_device *dev) +static int ni_getboardtype(comedi_device * dev) { - int device_id=ni_read_eeprom(dev,511); + int device_id = ni_read_eeprom(dev, 511); int i; - for(i=0;iprivate) #define ATMIO16D_TIMEOUT 10 - -typedef struct{ +typedef struct { const char *name; int has_8255; -}atmio16_board_t; -static const atmio16_board_t atmio16_boards[]={ +} atmio16_board_t; +static const atmio16_board_t atmio16_boards[] = { { - name: "atmio16", - has_8255: 0, - }, + name: "atmio16", + has_8255:0, + }, { - name: "atmio16d", - has_8255: 1, - }, + name: "atmio16d", + has_8255:1, + }, }; + #define n_atmio16_boards sizeof(atmio16_boards)/sizeof(atmio16_boards[0]) #define boardtype ((const atmio16_board_t *)dev->board_ptr) - /* function prototypes */ -static int atmio16d_attach(comedi_device *dev,comedi_devconfig *it); -static int atmio16d_detach(comedi_device *dev); +static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it); +static int atmio16d_detach(comedi_device * dev); static irqreturn_t atmio16d_interrupt(int irq, void *d PT_REGS_ARG); -static int atmio16d_ai_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); -static int atmio16d_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int atmio16d_ai_cancel(comedi_device *dev, comedi_subdevice *s); -static void reset_counters(comedi_device *dev); -static void reset_atmio16d(comedi_device *dev); +static int atmio16d_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int atmio16d_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int atmio16d_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static void reset_counters(comedi_device * dev); +static void reset_atmio16d(comedi_device * dev); /* main driver struct */ -static comedi_driver driver_atmio16d={ - driver_name: "atmio16", - module: THIS_MODULE, - attach: atmio16d_attach, - detach: atmio16d_detach, - board_name: &atmio16_boards[0].name, - num_names: n_atmio16_boards, - offset: sizeof(atmio16_board_t), +static comedi_driver driver_atmio16d = { + driver_name:"atmio16", + module:THIS_MODULE, + attach:atmio16d_attach, + detach:atmio16d_detach, + board_name:&atmio16_boards[0].name, + num_names:n_atmio16_boards, + offset:sizeof(atmio16_board_t), }; + COMEDI_INITCLEANUP(driver_atmio16d); /* range structs */ static const comedi_lrange range_atmio16d_ai_10_bipolar = { 4, { - BIP_RANGE( 10 ), - BIP_RANGE( 1 ), - BIP_RANGE( 0.1 ), - BIP_RANGE( 0.02 ) -} }; + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.02) + } +}; static const comedi_lrange range_atmio16d_ai_5_bipolar = { 4, { - BIP_RANGE( 5 ), - BIP_RANGE( 0.5 ), - BIP_RANGE( 0.05 ), - BIP_RANGE( 0.01 ) -} }; + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.01) + } +}; static const comedi_lrange range_atmio16d_ai_unipolar = { 4, { - UNI_RANGE( 10 ), - UNI_RANGE( 1 ), - UNI_RANGE( 0.1 ), - UNI_RANGE( 0.02 ) -} }; - + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.02) + } +}; /* private data struct */ typedef struct { @@ -183,75 +185,74 @@ typedef struct { unsigned int com_reg_2_state; /* current state of command register 2 */ } atmio16d_private; - -static void reset_counters(comedi_device *dev) +static void reset_counters(comedi_device * dev) { /* Counter 2 */ - outw(0xFFC2, dev->iobase+AM9513A_COM_REG); - outw(0xFF02, dev->iobase+AM9513A_COM_REG); - outw(0x4, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0A, dev->iobase+AM9513A_COM_REG); - outw(0x3, dev->iobase+AM9513A_DATA_REG); - outw(0xFF42, dev->iobase+AM9513A_COM_REG); - outw(0xFF42, dev->iobase+AM9513A_COM_REG); + outw(0xFFC2, dev->iobase + AM9513A_COM_REG); + outw(0xFF02, dev->iobase + AM9513A_COM_REG); + outw(0x4, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0A, dev->iobase + AM9513A_COM_REG); + outw(0x3, dev->iobase + AM9513A_DATA_REG); + outw(0xFF42, dev->iobase + AM9513A_COM_REG); + outw(0xFF42, dev->iobase + AM9513A_COM_REG); /* Counter 3 */ - outw(0xFFC4, dev->iobase+AM9513A_COM_REG); - outw(0xFF03, dev->iobase+AM9513A_COM_REG); - outw(0x4, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0B, dev->iobase+AM9513A_COM_REG); - outw(0x3, dev->iobase+AM9513A_DATA_REG); - outw(0xFF44, dev->iobase+AM9513A_COM_REG); - outw(0xFF44, dev->iobase+AM9513A_COM_REG); + outw(0xFFC4, dev->iobase + AM9513A_COM_REG); + outw(0xFF03, dev->iobase + AM9513A_COM_REG); + outw(0x4, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0B, dev->iobase + AM9513A_COM_REG); + outw(0x3, dev->iobase + AM9513A_DATA_REG); + outw(0xFF44, dev->iobase + AM9513A_COM_REG); + outw(0xFF44, dev->iobase + AM9513A_COM_REG); /* Counter 4 */ - outw(0xFFC8, dev->iobase+AM9513A_COM_REG); - outw(0xFF04, dev->iobase+AM9513A_COM_REG); - outw(0x4, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0C, dev->iobase+AM9513A_COM_REG); - outw(0x3, dev->iobase+AM9513A_DATA_REG); - outw(0xFF48, dev->iobase+AM9513A_COM_REG); - outw(0xFF48, dev->iobase+AM9513A_COM_REG); + outw(0xFFC8, dev->iobase + AM9513A_COM_REG); + outw(0xFF04, dev->iobase + AM9513A_COM_REG); + outw(0x4, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0C, dev->iobase + AM9513A_COM_REG); + outw(0x3, dev->iobase + AM9513A_DATA_REG); + outw(0xFF48, dev->iobase + AM9513A_COM_REG); + outw(0xFF48, dev->iobase + AM9513A_COM_REG); /* Counter 5 */ - outw(0xFFD0, dev->iobase+AM9513A_COM_REG); - outw(0xFF05, dev->iobase+AM9513A_COM_REG); - outw(0x4, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0D, dev->iobase+AM9513A_COM_REG); - outw(0x3, dev->iobase+AM9513A_DATA_REG); - outw(0xFF50, dev->iobase+AM9513A_COM_REG); - outw(0xFF50, dev->iobase+AM9513A_COM_REG); - - outw(0, dev->iobase+AD_CLEAR_REG); + outw(0xFFD0, dev->iobase + AM9513A_COM_REG); + outw(0xFF05, dev->iobase + AM9513A_COM_REG); + outw(0x4, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0D, dev->iobase + AM9513A_COM_REG); + outw(0x3, dev->iobase + AM9513A_DATA_REG); + outw(0xFF50, dev->iobase + AM9513A_COM_REG); + outw(0xFF50, dev->iobase + AM9513A_COM_REG); + + outw(0, dev->iobase + AD_CLEAR_REG); } -static void reset_atmio16d(comedi_device *dev) +static void reset_atmio16d(comedi_device * dev) { int i; /* now we need to initialize the board */ - outw(0, dev->iobase+COM_REG_1); - outw(0, dev->iobase+COM_REG_2); - outw(0, dev->iobase+MUX_GAIN_REG); + outw(0, dev->iobase + COM_REG_1); + outw(0, dev->iobase + COM_REG_2); + outw(0, dev->iobase + MUX_GAIN_REG); /* init AM9513A timer */ - outw(0xFFFF, dev->iobase+AM9513A_COM_REG); - outw(0xFFEF, dev->iobase+AM9513A_COM_REG); - outw(0xFF17, dev->iobase+AM9513A_COM_REG); - outw(0xF000, dev->iobase+AM9513A_DATA_REG); - for(i=1; i<=5; ++i) { - outw(0xFF00+i, dev->iobase+AM9513A_COM_REG); - outw(0x0004, dev->iobase+AM9513A_DATA_REG); - outw(0xFF08+i, dev->iobase+AM9513A_COM_REG); - outw(0x3, dev->iobase+AM9513A_DATA_REG); + outw(0xFFFF, dev->iobase + AM9513A_COM_REG); + outw(0xFFEF, dev->iobase + AM9513A_COM_REG); + outw(0xFF17, dev->iobase + AM9513A_COM_REG); + outw(0xF000, dev->iobase + AM9513A_DATA_REG); + for (i = 1; i <= 5; ++i) { + outw(0xFF00 + i, dev->iobase + AM9513A_COM_REG); + outw(0x0004, dev->iobase + AM9513A_DATA_REG); + outw(0xFF08 + i, dev->iobase + AM9513A_COM_REG); + outw(0x3, dev->iobase + AM9513A_DATA_REG); } - outw(0xFF5F, dev->iobase+AM9513A_COM_REG); + outw(0xFF5F, dev->iobase + AM9513A_COM_REG); /* timer init done */ - outw(0, dev->iobase+AD_CLEAR_REG); - outw(0, dev->iobase+INT2CLR_REG); + outw(0, dev->iobase + AD_CLEAR_REG); + outw(0, dev->iobase + INT2CLR_REG); /* select straight binary mode for Analog Input */ devpriv->com_reg_1_state |= 1; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); devpriv->adc_coding = adc_straight; /* zero the analog outputs */ - outw(2048, dev->iobase+DAC0_REG); - outw(2048, dev->iobase+DAC1_REG); + outw(2048, dev->iobase + DAC0_REG); + outw(2048, dev->iobase + DAC1_REG); } static irqreturn_t atmio16d_interrupt(int irq, void *d PT_REGS_ARG) @@ -259,109 +260,116 @@ static irqreturn_t atmio16d_interrupt(int irq, void *d PT_REGS_ARG) comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; -// printk("atmio16d_interrupt!\n"); +// printk("atmio16d_interrupt!\n"); - comedi_buf_put( s->async, inw(dev->iobase+AD_FIFO_REG) ); + comedi_buf_put(s->async, inw(dev->iobase + AD_FIFO_REG)); comedi_event(dev, s); return IRQ_HANDLED; } -static int atmio16d_ai_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) +static int atmio16d_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0, tmp; + int err = 0, tmp; #ifdef DEBUG1 printk("atmio16d_ai_cmdtest\n"); #endif /* make sure triggers are valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_FOLLOW|TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_FOLLOW && - cmd->scan_begin_src!=TRIG_EXT && - cmd->scan_begin_src!=TRIG_TIMER)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - }else{ + } else { #if 0 /* external trigger */ /* should be level/edge, hi/lo specification here */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } #endif } - if(cmd->convert_arg<10000){ - cmd->convert_arg=10000; + if (cmd->convert_arg < 10000) { + cmd->convert_arg = 10000; err++; } - - #if 0 - if(cmd->convert_arg>SLOWEST_TIMER){ - cmd->convert_arg=SLOWEST_TIMER; + if (cmd->convert_arg > SLOWEST_TIMER) { + cmd->convert_arg = SLOWEST_TIMER; err++; } #endif - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; return 0; } -static int atmio16d_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int atmio16d_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned int timer, base_clock; @@ -374,141 +382,142 @@ static int atmio16d_ai_cmd(comedi_device *dev, comedi_subdevice *s) * It is still uber-experimental */ reset_counters(dev); - s->async->cur_chan = 0; + s->async->cur_chan = 0; /* check if scanning multiple channels */ - if(cmd->chanlist_len < 2) { + if (cmd->chanlist_len < 2) { devpriv->com_reg_1_state &= ~COMREG1_SCANEN; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); } else { devpriv->com_reg_1_state |= COMREG1_SCANEN; devpriv->com_reg_2_state |= COMREG2_SCN2; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); - outw(devpriv->com_reg_2_state, dev->iobase+COM_REG_2); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); + outw(devpriv->com_reg_2_state, dev->iobase + COM_REG_2); } /* Setup the Mux-Gain Counter */ - for(i=0; i < cmd->chanlist_len; ++i ) { + for (i = 0; i < cmd->chanlist_len; ++i) { chan = CR_CHAN(cmd->chanlist[i]); gain = CR_RANGE(cmd->chanlist[i]); - outw(i, dev->iobase+MUX_CNTR_REG); - tmp = chan|(gain<<6); - if( i == cmd->scan_end_arg-1 ) tmp |= 0x0010; /* set LASTONE bit */ - outw(tmp, dev->iobase+MUX_GAIN_REG); + outw(i, dev->iobase + MUX_CNTR_REG); + tmp = chan | (gain << 6); + if (i == cmd->scan_end_arg - 1) + tmp |= 0x0010; /* set LASTONE bit */ + outw(tmp, dev->iobase + MUX_GAIN_REG); } /* Now program the sample interval timer */ /* Figure out which clock to use then get an * appropriate timer value */ - if(cmd->convert_arg<65536000) { + if (cmd->convert_arg < 65536000) { base_clock = CLOCK_1_MHZ; - timer = cmd->convert_arg/1000; - } else if(cmd->convert_arg<655360000) { + timer = cmd->convert_arg / 1000; + } else if (cmd->convert_arg < 655360000) { base_clock = CLOCK_100_KHZ; - timer = cmd->convert_arg/10000; - } else if(cmd->convert_arg<=0xffffffff /* 6553600000 */ ) { + timer = cmd->convert_arg / 10000; + } else if (cmd->convert_arg <= 0xffffffff /* 6553600000 */ ) { base_clock = CLOCK_10_KHZ; - timer = cmd->convert_arg/100000; - } else if(cmd->convert_arg<=0xffffffff /* 65536000000 */ ) { + timer = cmd->convert_arg / 100000; + } else if (cmd->convert_arg <= 0xffffffff /* 65536000000 */ ) { base_clock = CLOCK_1_KHZ; - timer = cmd->convert_arg/1000000; + timer = cmd->convert_arg / 1000000; } - outw(0xFF03, dev->iobase+AM9513A_COM_REG); - outw(base_clock, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0B, dev->iobase+AM9513A_COM_REG); - outw(0x2, dev->iobase+AM9513A_DATA_REG); - outw(0xFF44, dev->iobase+AM9513A_COM_REG); - outw(0xFFF3, dev->iobase+AM9513A_COM_REG); - outw(timer, dev->iobase+AM9513A_DATA_REG); - outw(0xFF24, dev->iobase+AM9513A_COM_REG); - - + outw(0xFF03, dev->iobase + AM9513A_COM_REG); + outw(base_clock, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0B, dev->iobase + AM9513A_COM_REG); + outw(0x2, dev->iobase + AM9513A_DATA_REG); + outw(0xFF44, dev->iobase + AM9513A_COM_REG); + outw(0xFFF3, dev->iobase + AM9513A_COM_REG); + outw(timer, dev->iobase + AM9513A_DATA_REG); + outw(0xFF24, dev->iobase + AM9513A_COM_REG); /* Now figure out how many samples to get */ /* and program the sample counter */ - sample_count = cmd->stop_arg*cmd->scan_end_arg; - outw(0xFF04, dev->iobase+AM9513A_COM_REG); - outw(0x1025, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0C, dev->iobase+AM9513A_COM_REG); - if(sample_count < 65536) { + sample_count = cmd->stop_arg * cmd->scan_end_arg; + outw(0xFF04, dev->iobase + AM9513A_COM_REG); + outw(0x1025, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0C, dev->iobase + AM9513A_COM_REG); + if (sample_count < 65536) { /* use only Counter 4 */ - outw(sample_count, dev->iobase+AM9513A_DATA_REG); - outw(0xFF48, dev->iobase+AM9513A_COM_REG); - outw(0xFFF4, dev->iobase+AM9513A_COM_REG); - outw(0xFF28, dev->iobase+AM9513A_COM_REG); + outw(sample_count, dev->iobase + AM9513A_DATA_REG); + outw(0xFF48, dev->iobase + AM9513A_COM_REG); + outw(0xFFF4, dev->iobase + AM9513A_COM_REG); + outw(0xFF28, dev->iobase + AM9513A_COM_REG); devpriv->com_reg_1_state &= ~COMREG1_1632CNT; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); } else { /* Counter 4 and 5 are needed */ - if( (tmp=sample_count&0xFFFF) ) { - outw(tmp-1, dev->iobase+AM9513A_DATA_REG); + if ((tmp = sample_count & 0xFFFF)) { + outw(tmp - 1, dev->iobase + AM9513A_DATA_REG); } else { - outw(0xFFFF, dev->iobase+AM9513A_DATA_REG); + outw(0xFFFF, dev->iobase + AM9513A_DATA_REG); } - outw(0xFF48, dev->iobase+AM9513A_COM_REG); - outw(0, dev->iobase+AM9513A_DATA_REG); - outw(0xFF28, dev->iobase+AM9513A_COM_REG); - outw(0xFF05, dev->iobase+AM9513A_COM_REG); - outw(0x25, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0D, dev->iobase+AM9513A_COM_REG); - tmp=sample_count&0xFFFF; - if( (tmp == 0) || (tmp == 1) ) { - outw( (sample_count>>16)&0xFFFF, dev->iobase+AM9513A_DATA_REG); + outw(0xFF48, dev->iobase + AM9513A_COM_REG); + outw(0, dev->iobase + AM9513A_DATA_REG); + outw(0xFF28, dev->iobase + AM9513A_COM_REG); + outw(0xFF05, dev->iobase + AM9513A_COM_REG); + outw(0x25, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0D, dev->iobase + AM9513A_COM_REG); + tmp = sample_count & 0xFFFF; + if ((tmp == 0) || (tmp == 1)) { + outw((sample_count >> 16) & 0xFFFF, + dev->iobase + AM9513A_DATA_REG); } else { - outw( ((sample_count>>16)&0xFFFF)+1, dev->iobase+AM9513A_DATA_REG); + outw(((sample_count >> 16) & 0xFFFF) + 1, + dev->iobase + AM9513A_DATA_REG); } - outw(0xFF70, dev->iobase+AM9513A_COM_REG); + outw(0xFF70, dev->iobase + AM9513A_COM_REG); devpriv->com_reg_1_state |= COMREG1_1632CNT; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); } /* Program the scan interval timer ONLY IF SCANNING IS ENABLED */ /* Figure out which clock to use then get an * appropriate timer value */ - if(cmd->chanlist_len > 1) { - if(cmd->scan_begin_arg<65536000) { + if (cmd->chanlist_len > 1) { + if (cmd->scan_begin_arg < 65536000) { base_clock = CLOCK_1_MHZ; - timer = cmd->scan_begin_arg/1000; - } else if(cmd->scan_begin_arg<655360000) { + timer = cmd->scan_begin_arg / 1000; + } else if (cmd->scan_begin_arg < 655360000) { base_clock = CLOCK_100_KHZ; - timer = cmd->scan_begin_arg/10000; - } else if(cmd->scan_begin_arg<0xffffffff /* 6553600000 */ ) { + timer = cmd->scan_begin_arg / 10000; + } else if (cmd->scan_begin_arg < 0xffffffff /* 6553600000 */ ) { base_clock = CLOCK_10_KHZ; - timer = cmd->scan_begin_arg/100000; - } else if(cmd->scan_begin_arg<0xffffffff /* 65536000000 */ ) { + timer = cmd->scan_begin_arg / 100000; + } else if (cmd->scan_begin_arg < 0xffffffff /* 65536000000 */ ) { base_clock = CLOCK_1_KHZ; - timer = cmd->scan_begin_arg/1000000; + timer = cmd->scan_begin_arg / 1000000; } - outw(0xFF02, dev->iobase+AM9513A_COM_REG); - outw(base_clock, dev->iobase+AM9513A_DATA_REG); - outw(0xFF0A, dev->iobase+AM9513A_COM_REG); - outw(0x2, dev->iobase+AM9513A_DATA_REG); - outw(0xFF42, dev->iobase+AM9513A_COM_REG); - outw(0xFFF2, dev->iobase+AM9513A_COM_REG); - outw(timer, dev->iobase+AM9513A_DATA_REG); - outw(0xFF22, dev->iobase+AM9513A_COM_REG); + outw(0xFF02, dev->iobase + AM9513A_COM_REG); + outw(base_clock, dev->iobase + AM9513A_DATA_REG); + outw(0xFF0A, dev->iobase + AM9513A_COM_REG); + outw(0x2, dev->iobase + AM9513A_DATA_REG); + outw(0xFF42, dev->iobase + AM9513A_COM_REG); + outw(0xFFF2, dev->iobase + AM9513A_COM_REG); + outw(timer, dev->iobase + AM9513A_DATA_REG); + outw(0xFF22, dev->iobase + AM9513A_COM_REG); } /* Clear the A/D FIFO and reset the MUX counter */ - outw(0, dev->iobase+AD_CLEAR_REG); - outw(0, dev->iobase+MUX_CNTR_REG); - outw(0, dev->iobase+INT2CLR_REG); + outw(0, dev->iobase + AD_CLEAR_REG); + outw(0, dev->iobase + MUX_CNTR_REG); + outw(0, dev->iobase + INT2CLR_REG); /* enable this acquisition operation */ devpriv->com_reg_1_state |= COMREG1_DAQEN; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); /* enable interrupts for conversion completion */ devpriv->com_reg_1_state |= COMREG1_CONVINTEN; devpriv->com_reg_2_state |= COMREG2_INTEN; - outw(devpriv->com_reg_1_state, dev->iobase+COM_REG_1); - outw(devpriv->com_reg_2_state, dev->iobase+COM_REG_2); + outw(devpriv->com_reg_1_state, dev->iobase + COM_REG_1); + outw(devpriv->com_reg_2_state, dev->iobase + COM_REG_2); /* apply a trigger. this starts the counters! */ - outw(0, dev->iobase+START_DAQ_REG); + outw(0, dev->iobase + START_DAQ_REG); return 0; } /* This will cancel a running acquisition operation */ -static int atmio16d_ai_cancel(comedi_device *dev, comedi_subdevice *s) +static int atmio16d_ai_cancel(comedi_device * dev, comedi_subdevice * s) { reset_atmio16d(dev); @@ -516,8 +525,8 @@ static int atmio16d_ai_cancel(comedi_device *dev, comedi_subdevice *s) } /* Mode 0 is used to get a single conversion on demand */ -static int atmio16d_ai_insn_read(comedi_device * dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int atmio16d_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i, t; int chan; @@ -536,36 +545,36 @@ static int atmio16d_ai_insn_read(comedi_device * dev, comedi_subdevice *s, //outw( 0, dev->iobase+MUX_CNTR_REG ); /* set the Input MUX gain */ - outw( chan|(gain<<6), dev->iobase+MUX_GAIN_REG); + outw(chan | (gain << 6), dev->iobase + MUX_GAIN_REG); - for(i=0 ; i < insn->n ; i++) { + for (i = 0; i < insn->n; i++) { /* start the conversion */ - outw(0, dev->iobase+START_CONVERT_REG); + outw(0, dev->iobase + START_CONVERT_REG); /* wait for it to finish */ - for(t = 0; t < ATMIO16D_TIMEOUT; t++) { + for (t = 0; t < ATMIO16D_TIMEOUT; t++) { /* check conversion status */ - status=inw(dev->iobase+STAT_REG); + status = inw(dev->iobase + STAT_REG); #ifdef DEBUG1 - printk("status=%x\n",status); + printk("status=%x\n", status); #endif - if( status&STAT_AD_CONVAVAIL ) { + if (status & STAT_AD_CONVAVAIL) { /* read the data now */ - data[i] = inw( dev->iobase+AD_FIFO_REG ); + data[i] = inw(dev->iobase + AD_FIFO_REG); /* change to two's complement if need be */ - if( devpriv->adc_coding == adc_2comp ) { + if (devpriv->adc_coding == adc_2comp) { data[i] ^= 0x800; } break; } - if( status&STAT_AD_OVERFLOW ){ + if (status & STAT_AD_OVERFLOW) { printk("atmio16d: a/d FIFO overflow\n"); - outw(0,dev->iobase+AD_CLEAR_REG); + outw(0, dev->iobase + AD_CLEAR_REG); return -ETIME; } } /* end waiting, now check if it timed out */ - if( t == ATMIO16D_TIMEOUT ){ + if (t == ATMIO16D_TIMEOUT) { rt_printk("atmio16d: timeout\n"); return -ETIME; @@ -575,23 +584,23 @@ static int atmio16d_ai_insn_read(comedi_device * dev, comedi_subdevice *s, return i; } -static int atmio16d_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int atmio16d_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; #ifdef DEBUG1 printk("atmio16d_ao_insn_read\n"); #endif - for(i=0;in;i++){ - data[i]=devpriv->ao_readback[CR_CHAN(insn->chanspec)]; + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; } return i; } -static int atmio16d_ao_insn_write(comedi_device * dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int atmio16d_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan; @@ -600,11 +609,11 @@ static int atmio16d_ao_insn_write(comedi_device * dev, comedi_subdevice *s, printk("atmio16d_ao_insn_write\n"); #endif - chan=CR_CHAN(insn->chanspec); + chan = CR_CHAN(insn->chanspec); - for(i=0; i < insn->n; i++) { + for (i = 0; i < insn->n; i++) { d = data[i]; - switch(chan){ + switch (chan) { case 0: if (devpriv->dac0_coding == dac_2comp) { d ^= 0x800; @@ -625,44 +634,44 @@ static int atmio16d_ao_insn_write(comedi_device * dev, comedi_subdevice *s, return i; } - -static int atmio16d_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int atmio16d_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]|data[1]); - outw(s->state, dev->iobase+MIO_16_DIG_OUT_REG ); + s->state |= (data[0] | data[1]); + outw(s->state, dev->iobase + MIO_16_DIG_OUT_REG); } - data[1] = inw(dev->iobase+MIO_16_DIG_IN_REG); + data[1] = inw(dev->iobase + MIO_16_DIG_IN_REG); return 2; } -static int atmio16d_dio_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int atmio16d_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int mask; - for(i=0;in;i++){ - mask=(CR_CHAN(insn->chanspec)<4)?0x0f:0xf0; + for (i = 0; i < insn->n; i++) { + mask = (CR_CHAN(insn->chanspec) < 4) ? 0x0f : 0xf0; s->io_bits &= ~mask; - if(data[i])s->io_bits |= mask; + if (data[i]) + s->io_bits |= mask; } - devpriv->com_reg_2_state &= ~(COMREG2_DOUTEN0|COMREG2_DOUTEN1); - if(s->io_bits&0x0f) + devpriv->com_reg_2_state &= ~(COMREG2_DOUTEN0 | COMREG2_DOUTEN1); + if (s->io_bits & 0x0f) devpriv->com_reg_2_state |= COMREG2_DOUTEN0; - if(s->io_bits&0xf0) + if (s->io_bits & 0xf0) devpriv->com_reg_2_state |= COMREG2_DOUTEN1; - outw(devpriv->com_reg_2_state, dev->iobase+COM_REG_2); + outw(devpriv->com_reg_2_state, dev->iobase + COM_REG_2); return i; } - /* options[0] - I/O port options[1] - MIO irq @@ -712,35 +721,31 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) } dev->iobase = iobase; - /* board name */ dev->board_name = boardtype->name; - if((ret=alloc_subdevices(dev, 4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(atmio16d_private)))<0) + if ((ret = alloc_private(dev, sizeof(atmio16d_private))) < 0) return ret; - /* reset the atmio16d hardware */ reset_atmio16d(dev); /* check if our interrupt is available and get it */ - irq=it->options[1]; - if(irq){ - if((ret=comedi_request_irq(irq,atmio16d_interrupt, - 0, "atmio16d", dev))<0) - { + irq = it->options[1]; + if (irq) { + if ((ret = comedi_request_irq(irq, atmio16d_interrupt, + 0, "atmio16d", dev)) < 0) { printk("failed to allocate irq %u\n", irq); return ret; } - dev->irq=irq; - printk("( irq = %u )\n",irq); + dev->irq = irq; + printk("( irq = %u )\n", irq); } else { printk("( no irq )"); } - /* set device options */ devpriv->adc_mux = it->options[5]; devpriv->adc_range = it->options[6]; @@ -752,20 +757,19 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) devpriv->dac1_reference = it->options[11]; devpriv->dac1_coding = it->options[12]; - /* setup sub-devices */ - s=dev->subdevices+0; + s = dev->subdevices + 0; dev->read_subdev = s; /* ai subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; - s->n_chan=(devpriv->adc_mux? 16 : 8); - s->len_chanlist=16; + s->n_chan = (devpriv->adc_mux ? 16 : 8); + s->len_chanlist = 16; s->insn_read = atmio16d_ai_insn_read; - s->do_cmdtest=atmio16d_ai_cmdtest; - s->do_cmd=atmio16d_ai_cmd; - s->cancel=atmio16d_ai_cancel; - s->maxdata=0xfff; /* 4095 decimal */ + s->do_cmdtest = atmio16d_ai_cmdtest; + s->do_cmd = atmio16d_ai_cmd; + s->cancel = atmio16d_ai_cancel; + s->maxdata = 0xfff; /* 4095 decimal */ switch (devpriv->adc_range) { case adc_bipolar10: s->range_table = &range_atmio16d_ai_10_bipolar; @@ -780,13 +784,13 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) /* ao subdevice */ s++; - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=2; - s->insn_read=atmio16d_ao_insn_read; - s->insn_write=atmio16d_ao_insn_write; - s->maxdata=0xfff; /* 4095 decimal */ - s->range_table_list=devpriv->ao_range_type_list; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->insn_read = atmio16d_ao_insn_read; + s->insn_write = atmio16d_ao_insn_write; + s->maxdata = 0xfff; /* 4095 decimal */ + s->range_table_list = devpriv->ao_range_type_list; switch (devpriv->dac0_range) { case dac_bipolar: devpriv->ao_range_type_list[0] = &range_bipolar10; @@ -804,56 +808,51 @@ static int atmio16d_attach(comedi_device * dev, comedi_devconfig * it) break; } - /* Digital I/O */ s++; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_WRITABLE|SDF_READABLE; - s->n_chan=8; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE; + s->n_chan = 8; s->insn_bits = atmio16d_dio_insn_bits; s->insn_config = atmio16d_dio_insn_config; - s->maxdata=1; - s->range_table=&range_digital; - + s->maxdata = 1; + s->range_table = &range_digital; /* 8255 subdevice */ s++; - if(boardtype->has_8255){ - subdev_8255_init(dev,s,NULL,dev->iobase); - }else{ - s->type=COMEDI_SUBD_UNUSED; + if (boardtype->has_8255) { + subdev_8255_init(dev, s, NULL, dev->iobase); + } else { + s->type = COMEDI_SUBD_UNUSED; } /* don't yet know how to deal with counter/timers */ #if 0 s++; /* do */ - s->type=COMEDI_SUBD_TIMER; - s->n_chan=0; - s->maxdata=0 + s->type = COMEDI_SUBD_TIMER; + s->n_chan = 0; + s->maxdata = 0 #endif - - printk("\n"); + printk("\n"); return 0; } - static int atmio16d_detach(comedi_device * dev) { printk("comedi%d: atmio16d: remove\n", dev->minor); - if(dev->subdevices && boardtype->has_8255) - subdev_8255_cleanup(dev,dev->subdevices + 3); + if (dev->subdevices && boardtype->has_8255) + subdev_8255_cleanup(dev, dev->subdevices + 3); - if(dev->irq) - comedi_free_irq(dev->irq,dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); reset_atmio16d(dev); - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, ATMIO16D_SIZE); return 0; } - diff --git a/comedi/drivers/ni_daq_dio24.c b/comedi/drivers/ni_daq_dio24.c index bb52285b..790ecfe0 100644 --- a/comedi/drivers/ni_daq_dio24.c +++ b/comedi/drivers/ni_daq_dio24.c @@ -37,8 +37,7 @@ This is just a wrapper around the 8255.o driver to properly handle the PCMCIA interface. */ - -//#define LABPC_DEBUG // enable debugging messages +//#define LABPC_DEBUG // enable debugging messages #undef LABPC_DEBUG #include @@ -56,38 +55,36 @@ the PCMCIA interface. static struct pcmcia_device *pcmcia_cur_dev = NULL; -#define DIO24_SIZE 4 // size of io region used by board +#define DIO24_SIZE 4 // size of io region used by board -static int dio24_attach(comedi_device *dev,comedi_devconfig *it); -static int dio24_detach(comedi_device *dev); +static int dio24_attach(comedi_device * dev, comedi_devconfig * it); +static int dio24_detach(comedi_device * dev); -enum dio24_bustype {pcmcia_bustype}; +enum dio24_bustype { pcmcia_bustype }; -typedef struct dio24_board_struct{ +typedef struct dio24_board_struct { const char *name; - int device_id; // device id for pcmcia board + int device_id; // device id for pcmcia board enum dio24_bustype bustype; // PCMCIA - int have_dio; // have 8255 chip + int have_dio; // have 8255 chip // function pointers so we can use inb/outb or readb/writeb as appropriate - unsigned int (*read_byte)(unsigned int address); - void (*write_byte)(unsigned int byte, unsigned int address); -}dio24_board; - + unsigned int (*read_byte) (unsigned int address); + void (*write_byte) (unsigned int byte, unsigned int address); +} dio24_board; -static const dio24_board dio24_boards[] = -{ +static const dio24_board dio24_boards[] = { { - name: "daqcard-dio24", - device_id: 0x475c, // 0x10b is manufacturer id, 0x475c is device id - bustype: pcmcia_bustype, - have_dio: 1, - }, + name: "daqcard-dio24", + device_id:0x475c,// 0x10b is manufacturer id, 0x475c is device id + bustype: pcmcia_bustype, + have_dio:1, + }, { - name: "ni_daq_dio24", - device_id: 0x475c, // 0x10b is manufacturer id, 0x475c is device id - bustype: pcmcia_bustype, - have_dio: 1, - }, + name: "ni_daq_dio24", + device_id:0x475c,// 0x10b is manufacturer id, 0x475c is device id + bustype: pcmcia_bustype, + have_dio:1, + }, }; /* @@ -95,23 +92,23 @@ static const dio24_board dio24_boards[] = */ #define thisboard ((const dio24_board *)dev->board_ptr) -typedef struct{ - int data; /* number of data points left to be taken */ -}dio24_private; +typedef struct { + int data; /* number of data points left to be taken */ +} dio24_private; #define devpriv ((dio24_private *)dev->private) -static comedi_driver driver_dio24={ - driver_name: "ni_daq_dio24", - module: THIS_MODULE, - attach: dio24_attach, - detach: dio24_detach, - num_names: sizeof(dio24_boards) / sizeof(dio24_board), - board_name: &dio24_boards[0].name, - offset: sizeof(dio24_board), +static comedi_driver driver_dio24 = { + driver_name:"ni_daq_dio24", + module:THIS_MODULE, + attach:dio24_attach, + detach:dio24_detach, + num_names:sizeof(dio24_boards) / sizeof(dio24_board), + board_name:&dio24_boards[0].name, + offset:sizeof(dio24_board), }; -static int dio24_attach(comedi_device *dev, comedi_devconfig *it) +static int dio24_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase = 0; @@ -121,37 +118,36 @@ static int dio24_attach(comedi_device *dev, comedi_devconfig *it) struct pcmcia_device *link; /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(dio24_private)) < 0) + if (alloc_private(dev, sizeof(dio24_private)) < 0) return -ENOMEM; // get base address, irq etc. based on bustype - switch(thisboard->bustype) - { - case pcmcia_bustype: - link = pcmcia_cur_dev; /* XXX hack */ - if(!link) return -EIO; - iobase = link->io.BasePort1; + switch (thisboard->bustype) { + case pcmcia_bustype: + link = pcmcia_cur_dev; /* XXX hack */ + if (!link) + return -EIO; + iobase = link->io.BasePort1; #ifdef incomplete - irq = link->irq.AssignedIRQ; + irq = link->irq.AssignedIRQ; #endif - break; - default: - printk("bug! couldn't determine board type\n"); - return -EINVAL; - break; + break; + default: + printk("bug! couldn't determine board type\n"); + return -EINVAL; + break; } - printk("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor, thisboard->name, iobase); + printk("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor, + thisboard->name, iobase); #ifdef incomplete - if(irq) - { + if (irq) { printk(", irq %u", irq); } #endif printk("\n"); - if(iobase == 0) - { + if (iobase == 0) { printk("io base address is zero!\n"); return -EINVAL; } @@ -165,7 +161,7 @@ static int dio24_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = thisboard->name; - if(alloc_subdevices(dev, 1) < 0) + if (alloc_subdevices(dev, 1) < 0) return -ENOMEM; /* 8255 dio */ @@ -175,24 +171,21 @@ static int dio24_attach(comedi_device *dev, comedi_devconfig *it) return 0; }; -static int dio24_detach(comedi_device *dev) +static int dio24_detach(comedi_device * dev) { printk("comedi%d: ni_daq_dio24: remove\n", dev->minor); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 0); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 0); - if(thisboard->bustype != pcmcia_bustype && - dev->iobase) + if (thisboard->bustype != pcmcia_bustype && dev->iobase) release_region(dev->iobase, DIO24_SIZE); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); return 0; }; - - // PCMCIA crap /* @@ -206,8 +199,7 @@ static int dio24_detach(comedi_device *dev) static int pc_debug = PCMCIA_DEBUG; module_param(pc_debug, int, 0644); #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) -static char *version = -"ni_daq_dio24.c, based on dummy_cs.c"; +static char *version = "ni_daq_dio24.c, based on dummy_cs.c"; #else #define DEBUG(n, args...) #endif @@ -244,10 +236,10 @@ static void dio24_cs_detach(struct pcmcia_device *); static const dev_info_t dev_info = "ni_daq_dio24"; typedef struct local_info_t { - struct pcmcia_device *link; - dev_node_t node; - int stop; - struct bus_operations *bus; + struct pcmcia_device *link; + dev_node_t node; + int stop; + struct bus_operations *bus; } local_info_t; /*====================================================================== @@ -264,38 +256,40 @@ typedef struct local_info_t { static int dio24_cs_attach(struct pcmcia_device *link) { - local_info_t *local; + local_info_t *local; - printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - CS-attach!\n"); + printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - CS-attach!\n"); - DEBUG(0, "dio24_cs_attach()\n"); + DEBUG(0, "dio24_cs_attach()\n"); - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return -ENOMEM; - local->link = link; link->priv = local; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; - /* Interrupt setup */ - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; - link->irq.IRQInfo1 = IRQ_LEVEL_ID; - link->irq.Handler = NULL; + /* Interrupt setup */ + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; + link->irq.IRQInfo1 = IRQ_LEVEL_ID; + 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.IntType = INT_MEMORY_AND_IO; + /* + 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.IntType = INT_MEMORY_AND_IO; - pcmcia_cur_dev = link; + pcmcia_cur_dev = link; - dio24_config(link); + dio24_config(link); - return 0; -} /* dio24_cs_attach */ + return 0; +} /* dio24_cs_attach */ /*====================================================================== @@ -309,20 +303,20 @@ static int dio24_cs_attach(struct pcmcia_device *link) static void dio24_cs_detach(struct pcmcia_device *link) { - printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - cs-detach!\n"); + printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - cs-detach!\n"); - DEBUG(0, "dio24_cs_detach(0x%p)\n", link); + DEBUG(0, "dio24_cs_detach(0x%p)\n", link); - if(link->dev_node) { - ((local_info_t *)link->priv)->stop = 1; + if (link->dev_node) { + ((local_info_t *) link->priv)->stop = 1; dio24_release(link); - } + } - /* This points to the parent local_info_t struct */ - if(link->priv) + /* This points to the parent local_info_t struct */ + if (link->priv) kfree(link->priv); -} /* dio24_cs_detach */ +} /* dio24_cs_detach */ /*====================================================================== @@ -332,193 +326,193 @@ static void dio24_cs_detach(struct pcmcia_device *link) ======================================================================*/ - static void dio24_config(struct pcmcia_device *link) { - local_info_t *dev = link->priv; - tuple_t tuple; - cisparse_t parse; - int last_ret; - u_char buf[64]; - win_req_t req; - memreq_t map; - cistpl_cftable_entry_t dflt = { 0 }; - - printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO! - config\n"); - - DEBUG(0, "dio24_config(0x%p)\n", link); - - /* - This reads the card's CONFIG tuple to find its configuration - registers. - */ - tuple.DesiredTuple = CISTPL_CONFIG; - tuple.Attributes = 0; - tuple.TupleData = buf; - tuple.TupleDataMax = sizeof(buf); - tuple.TupleOffset = 0; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) - { - cs_error(link, GetFirstTuple, last_ret); + local_info_t *dev = link->priv; + tuple_t tuple; + cisparse_t parse; + int last_ret; + u_char buf[64]; + win_req_t req; + memreq_t map; + cistpl_cftable_entry_t dflt = { 0 }; + + printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO! - config\n"); + + DEBUG(0, "dio24_config(0x%p)\n", link); + + /* + This reads the card's CONFIG tuple to find its configuration + registers. + */ + tuple.DesiredTuple = CISTPL_CONFIG; + tuple.Attributes = 0; + tuple.TupleData = buf; + tuple.TupleDataMax = sizeof(buf); + tuple.TupleOffset = 0; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) { + cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) - { - cs_error(link, GetTupleData, last_ret); + if ((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) { + cs_error(link, GetTupleData, last_ret); goto cs_failed; } - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) - { - cs_error(link, ParseTuple, last_ret); + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) { + cs_error(link, ParseTuple, last_ret); goto cs_failed; } - link->conf.ConfigBase = parse.config.base; - link->conf.Present = parse.config.rmask[0]; - - /* - In this loop, we scan the CIS for configuration table entries, - each of which describes a valid card configuration, including - voltage, IO window, memory window, and interrupt settings. - - We make no assumptions about the card to be configured: we use - just the information available in the CIS. In an ideal world, - this would work for any PCMCIA card, but it requires a complete - and accurate CIS. In practice, a driver usually "knows" most of - these things without consulting the CIS, and most client drivers - will only use the CIS to fill in implementation-defined details. - */ - tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; - if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) - { - cs_error(link, GetFirstTuple, last_ret); + link->conf.ConfigBase = parse.config.base; + link->conf.Present = parse.config.rmask[0]; + + /* + In this loop, we scan the CIS for configuration table entries, + each of which describes a valid card configuration, including + voltage, IO window, memory window, and interrupt settings. + + We make no assumptions about the card to be configured: we use + just the information available in the CIS. In an ideal world, + this would work for any PCMCIA card, but it requires a complete + and accurate CIS. In practice, a driver usually "knows" most of + these things without consulting the CIS, and most client drivers + will only use the CIS to fill in implementation-defined details. + */ + tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) { + cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - while (1) { - cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); - if(pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry; - if(pcmcia_parse_tuple(link, &tuple, &parse) != 0) goto next_entry; - - if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; - if (cfg->index == 0) goto next_entry; - link->conf.ConfigIndex = cfg->index; - - /* Does this card need audio output? */ - if (cfg->flags & CISTPL_CFTABLE_AUDIO) { - link->conf.Attributes |= CONF_ENABLE_SPKR; - link->conf.Status = CCSR_AUDIO_ENA; - } + while (1) { + cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); + if (pcmcia_get_tuple_data(link, &tuple) != 0) + goto next_entry; + if (pcmcia_parse_tuple(link, &tuple, &parse) != 0) + goto next_entry; + + if (cfg->flags & CISTPL_CFTABLE_DEFAULT) + dflt = *cfg; + if (cfg->index == 0) + goto next_entry; + link->conf.ConfigIndex = cfg->index; + + /* Does this card need audio output? */ + if (cfg->flags & CISTPL_CFTABLE_AUDIO) { + link->conf.Attributes |= CONF_ENABLE_SPKR; + link->conf.Status = CCSR_AUDIO_ENA; + } - /* Do we need to allocate an interrupt? */ - if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) - link->conf.Attributes |= CONF_ENABLE_IRQ; - - /* IO window settings */ - link->io.NumPorts1 = link->io.NumPorts2 = 0; - if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { - cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; - link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; - if (!(io->flags & CISTPL_IO_8BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; - if (!(io->flags & CISTPL_IO_16BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; - link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; - link->io.BasePort1 = io->win[0].base; - link->io.NumPorts1 = io->win[0].len; - if (io->nwin > 1) { - link->io.Attributes2 = link->io.Attributes1; - link->io.BasePort2 = io->win[1].base; - link->io.NumPorts2 = io->win[1].len; - } - /* This reserves IO space but doesn't actually enable it */ - if(pcmcia_request_io(link, &link->io) != 0) goto next_entry; - } + /* Do we need to allocate an interrupt? */ + if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) + link->conf.Attributes |= CONF_ENABLE_IRQ; + + /* IO window settings */ + link->io.NumPorts1 = link->io.NumPorts2 = 0; + if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { + cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; + if (!(io->flags & CISTPL_IO_8BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; + if (!(io->flags & CISTPL_IO_16BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; + link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; + link->io.BasePort1 = io->win[0].base; + link->io.NumPorts1 = io->win[0].len; + if (io->nwin > 1) { + link->io.Attributes2 = link->io.Attributes1; + link->io.BasePort2 = io->win[1].base; + link->io.NumPorts2 = io->win[1].len; + } + /* This reserves IO space but doesn't actually enable it */ + if (pcmcia_request_io(link, &link->io) != 0) + goto next_entry; + } - if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { - cistpl_mem_t *mem = - (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; - req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM; - req.Attributes |= WIN_ENABLE; - req.Base = mem->win[0].host_addr; - req.Size = mem->win[0].len; - if (req.Size < 0x1000) - req.Size = 0x1000; - req.AccessSpeed = 0; - if(pcmcia_request_window(&link, &req, &link->win)) goto next_entry; - map.Page = 0; map.CardOffset = mem->win[0].card_addr; - if(pcmcia_map_mem_page(link->win, &map)) goto next_entry; - } - /* If we got this far, we're cool! */ - break; + if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { + cistpl_mem_t *mem = + (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; + req.Attributes = WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM; + req.Attributes |= WIN_ENABLE; + req.Base = mem->win[0].host_addr; + req.Size = mem->win[0].len; + if (req.Size < 0x1000) + req.Size = 0x1000; + req.AccessSpeed = 0; + if (pcmcia_request_window(&link, &req, &link->win)) + goto next_entry; + map.Page = 0; + map.CardOffset = mem->win[0].card_addr; + if (pcmcia_map_mem_page(link->win, &map)) + goto next_entry; + } + /* If we got this far, we're cool! */ + break; - next_entry: - if((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) - { - cs_error(link, GetNextTuple, last_ret); - goto cs_failed; + next_entry: + if ((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) { + cs_error(link, GetNextTuple, last_ret); + goto cs_failed; + } } - } - - /* - Allocate an interrupt line. Note that this does not assign a - handler to the interrupt, unless the 'Handler' member of the - irq structure is initialized. - */ - if (link->conf.Attributes & CONF_ENABLE_IRQ) - if((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) - { - cs_error(link, RequestIRQ, last_ret); + + /* + Allocate an interrupt line. Note that this does not assign a + handler to the interrupt, unless the 'Handler' member of the + irq structure is initialized. + */ + if (link->conf.Attributes & CONF_ENABLE_IRQ) + if ((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) { + cs_error(link, RequestIRQ, last_ret); goto cs_failed; } - /* - This actually configures the PCMCIA socket -- setting up - the I/O windows and the interrupt mapping, and putting the - card and host interface into "Memory and IO" mode. - */ - if((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) - { + /* + This actually configures the PCMCIA socket -- setting up + the I/O windows and the interrupt mapping, and putting the + card and host interface into "Memory and IO" mode. + */ + if ((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) { cs_error(link, RequestConfiguration, last_ret); goto cs_failed; } - /* - At this point, the dev_node_t structure(s) need to be - initialized and arranged in a linked list at link->dev. - */ - sprintf(dev->node.dev_name, "ni_daq_dio24"); - dev->node.major = dev->node.minor = 0; - link->dev_node = &dev->node; - - /* Finally, report what we've done */ - printk(KERN_INFO "%s: index 0x%02x", - dev->node.dev_name, link->conf.ConfigIndex); - if (link->conf.Attributes & CONF_ENABLE_IRQ) + /* + At this point, the dev_node_t structure(s) need to be + initialized and arranged in a linked list at link->dev. + */ + sprintf(dev->node.dev_name, "ni_daq_dio24"); + dev->node.major = dev->node.minor = 0; + link->dev_node = &dev->node; + + /* Finally, report what we've done */ + printk(KERN_INFO "%s: index 0x%02x", + dev->node.dev_name, link->conf.ConfigIndex); + if (link->conf.Attributes & CONF_ENABLE_IRQ) printk(", irq %d", link->irq.AssignedIRQ); - if (link->io.NumPorts1) + if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, - link->io.BasePort1+link->io.NumPorts1-1); - if (link->io.NumPorts2) + link->io.BasePort1 + link->io.NumPorts1 - 1); + if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, - link->io.BasePort2+link->io.NumPorts2-1); - if (link->win) - printk(", mem 0x%06lx-0x%06lx", req.Base, - req.Base+req.Size-1); - printk("\n"); + link->io.BasePort2 + link->io.NumPorts2 - 1); + if (link->win) + printk(", mem 0x%06lx-0x%06lx", req.Base, + req.Base + req.Size - 1); + printk("\n"); - return; + return; -cs_failed: - printk(KERN_INFO "Fallo"); - dio24_release(link); + cs_failed: + printk(KERN_INFO "Fallo"); + dio24_release(link); -} /* dio24_config */ +} /* dio24_config */ static void dio24_release(struct pcmcia_device *link) { - DEBUG(0, "dio24_release(0x%p)\n", link); + DEBUG(0, "dio24_release(0x%p)\n", link); pcmcia_disable_device(link); -} /* dio24_release */ +} /* dio24_release */ /*====================================================================== @@ -532,7 +526,6 @@ static void dio24_release(struct pcmcia_device *link) ======================================================================*/ - static int dio24_cs_suspend(struct pcmcia_device *link) { local_info_t *local = link->priv; @@ -540,7 +533,7 @@ static int dio24_cs_suspend(struct pcmcia_device *link) /* Mark the device as stopped, to block IO until later */ local->stop = 1; return 0; -} /* dio24_cs_suspend */ +} /* dio24_cs_suspend */ static int dio24_cs_resume(struct pcmcia_device *link) { @@ -548,12 +541,11 @@ static int dio24_cs_resume(struct pcmcia_device *link) local->stop = 0; return 0; -} /* dio24_cs_resume */ +} /* dio24_cs_resume */ /*====================================================================*/ -static struct pcmcia_device_id dio24_cs_ids[] = -{ +static struct pcmcia_device_id dio24_cs_ids[] = { /* N.B. These IDs should match those in dio24_boards */ PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ PCMCIA_DEVICE_NULL @@ -561,8 +553,7 @@ static struct pcmcia_device_id dio24_cs_ids[] = MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); -struct pcmcia_driver dio24_cs_driver = -{ +struct pcmcia_driver dio24_cs_driver = { .probe = dio24_cs_attach, .remove = dio24_cs_detach, .suspend = dio24_cs_suspend, @@ -570,21 +561,21 @@ struct pcmcia_driver dio24_cs_driver = .id_table = dio24_cs_ids, .owner = THIS_MODULE, .drv = { - .name = dev_info, - }, + .name = dev_info, + }, }; static int __init init_dio24_cs(void) { - printk("ni_daq_dio24: HOLA SOY YO!\n"); - DEBUG(0, "%s\n", version); + printk("ni_daq_dio24: HOLA SOY YO!\n"); + DEBUG(0, "%s\n", version); pcmcia_register_driver(&dio24_cs_driver); - return 0; + return 0; } static void __exit exit_dio24_cs(void) { - DEBUG(0, "ni_dio24: unloading\n"); + DEBUG(0, "ni_dio24: unloading\n"); pcmcia_unregister_driver(&dio24_cs_driver); } @@ -592,8 +583,8 @@ int __init init_module(void) { int ret; - ret = init_dio24_cs(); - if(ret < 0) + ret = init_dio24_cs(); + if (ret < 0) return ret; return comedi_driver_register(&driver_dio24); @@ -604,4 +595,3 @@ void __exit cleanup_module(void) exit_dio24_cs(); comedi_driver_unregister(&driver_dio24); } - diff --git a/comedi/drivers/ni_labpc.c b/comedi/drivers/ni_labpc.c index ea281968..f9afdc8a 100644 --- a/comedi/drivers/ni_labpc.c +++ b/comedi/drivers/ni_labpc.c @@ -74,7 +74,7 @@ NI manuals: */ #undef LABPC_DEBUG -//#define LABPC_DEBUG // enable debugging messages +//#define LABPC_DEBUG // enable debugging messages #include @@ -130,7 +130,7 @@ NI manuals: #define ADC_DIFF_BIT 0x8 // chooses differential inputs for adc (in conjunction with board jumper) #define EXT_CONVERT_DISABLE_BIT 0x10 #define COMMAND5_REG 0x1c // 1200 boards only, calibration stuff -#define EEPROM_WRITE_UNPROTECT_BIT 0x4// enable eeprom for write +#define EEPROM_WRITE_UNPROTECT_BIT 0x4 // enable eeprom for write #define DITHER_EN_BIT 0x8 // enable dithering #define CALDAC_LOAD_BIT 0x10 // load calibration dac #define SCLOCK_BIT 0x20 // serial clock - rising edge writes, falling edge reads @@ -161,36 +161,47 @@ NI manuals: #define INIT_A1_BITS 0x70 // put hardware conversion counter output in harmless state (a1 mode 0) #define COUNTER_B_BASE_REG 0x18 - -static int labpc_attach(comedi_device *dev,comedi_devconfig *it); -static int labpc_cancel(comedi_device *dev, comedi_subdevice *s); +static int labpc_attach(comedi_device * dev, comedi_devconfig * it); +static int labpc_cancel(comedi_device * dev, comedi_subdevice * s); static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG); -static int labpc_drain_fifo(comedi_device *dev); -static void labpc_drain_dma(comedi_device *dev); -static void handle_isa_dma(comedi_device *dev); -static void labpc_drain_dregs(comedi_device *dev); -static int labpc_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int labpc_ai_cmd(comedi_device *dev, comedi_subdevice *s); -static int labpc_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_ao_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_calib_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_calib_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_eeprom_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int labpc_eeprom_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); +static int labpc_drain_fifo(comedi_device * dev); +static void labpc_drain_dma(comedi_device * dev); +static void handle_isa_dma(comedi_device * dev); +static void labpc_drain_dregs(comedi_device * dev); +static int labpc_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int labpc_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int labpc_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_calib_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_calib_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int labpc_eeprom_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); static unsigned int labpc_suggest_transfer_size(comedi_cmd cmd); -static void labpc_adc_timing(comedi_device *dev, comedi_cmd *cmd); -static struct mite_struct* labpc_find_device(int bus, int slot); -static int labpc_dio_mem_callback(int dir, int port, int data, unsigned long arg); -static void labpc_serial_out(comedi_device *dev, unsigned int value, unsigned int num_bits); -static unsigned int labpc_serial_in(comedi_device *dev); -static unsigned int labpc_eeprom_read(comedi_device *dev, unsigned int address); -static unsigned int labpc_eeprom_read_status(comedi_device *dev); -static unsigned int labpc_eeprom_write(comedi_device *dev, unsigned int address, unsigned int value); -static void write_caldac(comedi_device *dev, unsigned int channel, unsigned int value); - -enum scan_mode -{ +static void labpc_adc_timing(comedi_device * dev, comedi_cmd * cmd); +static struct mite_struct *labpc_find_device(int bus, int slot); +static int labpc_dio_mem_callback(int dir, int port, int data, + unsigned long arg); +static void labpc_serial_out(comedi_device * dev, unsigned int value, + unsigned int num_bits); +static unsigned int labpc_serial_in(comedi_device * dev); +static unsigned int labpc_eeprom_read(comedi_device * dev, + unsigned int address); +static unsigned int labpc_eeprom_read_status(comedi_device * dev); +static unsigned int labpc_eeprom_write(comedi_device * dev, + unsigned int address, unsigned int value); +static void write_caldac(comedi_device * dev, unsigned int channel, + unsigned int value); + +enum scan_mode { MODE_SINGLE_CHAN, MODE_SINGLE_CHAN_INTERVAL, MODE_MULT_CHAN_UP, @@ -200,8 +211,7 @@ enum scan_mode //analog input ranges #define NUM_LABPC_PLUS_AI_RANGES 16 // indicates unipolar ranges -static const int labpc_plus_is_unipolar[NUM_LABPC_PLUS_AI_RANGES] = -{ +static const int labpc_plus_is_unipolar[NUM_LABPC_PLUS_AI_RANGES] = { 0, 0, 0, @@ -219,9 +229,9 @@ static const int labpc_plus_is_unipolar[NUM_LABPC_PLUS_AI_RANGES] = 1, 1, }; + // map range index to gain bits -static const int labpc_plus_ai_gain_bits[NUM_LABPC_PLUS_AI_RANGES] = -{ +static const int labpc_plus_ai_gain_bits[NUM_LABPC_PLUS_AI_RANGES] = { 0x00, 0x10, 0x20, @@ -242,29 +252,28 @@ static const int labpc_plus_ai_gain_bits[NUM_LABPC_PLUS_AI_RANGES] = static const comedi_lrange range_labpc_plus_ai = { NUM_LABPC_PLUS_AI_RANGES, { - BIP_RANGE(5), - BIP_RANGE(4), - BIP_RANGE(2.5), - BIP_RANGE(1), - BIP_RANGE(0.5), - BIP_RANGE(0.25), - BIP_RANGE(0.1), - BIP_RANGE(0.05), - UNI_RANGE(10), - UNI_RANGE(8), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1), - UNI_RANGE(0.5), - UNI_RANGE(0.2), - UNI_RANGE(0.1), - } + BIP_RANGE(5), + BIP_RANGE(4), + BIP_RANGE(2.5), + BIP_RANGE(1), + BIP_RANGE(0.5), + BIP_RANGE(0.25), + BIP_RANGE(0.1), + BIP_RANGE(0.05), + UNI_RANGE(10), + UNI_RANGE(8), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1), + UNI_RANGE(0.5), + UNI_RANGE(0.2), + UNI_RANGE(0.1), + } }; #define NUM_LABPC_1200_AI_RANGES 14 // indicates unipolar ranges -static const int labpc_1200_is_unipolar[NUM_LABPC_1200_AI_RANGES] = -{ +static const int labpc_1200_is_unipolar[NUM_LABPC_1200_AI_RANGES] = { 0, 0, 0, @@ -280,9 +289,9 @@ static const int labpc_1200_is_unipolar[NUM_LABPC_1200_AI_RANGES] = 1, 1, }; + // map range index to gain bits -static const int labpc_1200_ai_gain_bits[NUM_LABPC_1200_AI_RANGES] = -{ +static const int labpc_1200_ai_gain_bits[NUM_LABPC_1200_AI_RANGES] = { 0x00, 0x20, 0x30, @@ -301,21 +310,21 @@ static const int labpc_1200_ai_gain_bits[NUM_LABPC_1200_AI_RANGES] = static const comedi_lrange range_labpc_1200_ai = { NUM_LABPC_1200_AI_RANGES, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1), - BIP_RANGE(0.5), - BIP_RANGE(0.25), - BIP_RANGE(0.1), - BIP_RANGE(0.05), - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2), - UNI_RANGE(1), - UNI_RANGE(0.5), - UNI_RANGE(0.2), - UNI_RANGE(0.1), - } + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1), + BIP_RANGE(0.5), + BIP_RANGE(0.25), + BIP_RANGE(0.1), + BIP_RANGE(0.05), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2), + UNI_RANGE(1), + UNI_RANGE(0.5), + UNI_RANGE(0.2), + UNI_RANGE(0.1), + } }; //analog output ranges @@ -323,9 +332,9 @@ static const comedi_lrange range_labpc_1200_ai = { static const comedi_lrange range_labpc_ao = { 2, { - BIP_RANGE(5), - UNI_RANGE(10), - } + BIP_RANGE(5), + UNI_RANGE(10), + } }; /* functions that do inb/outb and readb/writeb so we can use @@ -340,95 +349,93 @@ static inline void labpc_outb(unsigned int byte, unsigned long address) } static inline unsigned int labpc_readb(unsigned long address) { - return readb((void*) address); + return readb((void *)address); } static inline void labpc_writeb(unsigned int byte, unsigned long address) { - writeb(byte, (void*) address); + writeb(byte, (void *)address); } -static const labpc_board labpc_boards[] = -{ - { - name: "lab-pc-1200", - ai_speed: 10000, - bustype: isa_bustype, - register_layout: labpc_1200_layout, - has_ao: 1, - ai_range_table: &range_labpc_1200_ai, - ai_range_code: labpc_1200_ai_gain_bits, - ai_range_is_unipolar: labpc_1200_is_unipolar, - ai_scan_up: 1, - memory_mapped_io: 0, - }, - { - name: "lab-pc-1200ai", - ai_speed: 10000, - bustype: isa_bustype, - register_layout: labpc_1200_layout, - has_ao: 0, - ai_range_table: &range_labpc_1200_ai, - ai_range_code: labpc_1200_ai_gain_bits, - ai_range_is_unipolar: labpc_1200_is_unipolar, - ai_scan_up: 1, - memory_mapped_io: 0, - }, - { - name: "lab-pc+", - ai_speed: 12000, - bustype: isa_bustype, - register_layout: labpc_plus_layout, - has_ao: 1, - ai_range_table: &range_labpc_plus_ai, - ai_range_code: labpc_plus_ai_gain_bits, - ai_range_is_unipolar: labpc_plus_is_unipolar, - ai_scan_up: 0, - memory_mapped_io: 0, - }, - { - name: "pci-1200", - device_id: 0x161, - ai_speed: 10000, - bustype: pci_bustype, - register_layout: labpc_1200_layout, - has_ao: 1, - ai_range_table: &range_labpc_1200_ai, - ai_range_code: labpc_1200_ai_gain_bits, - ai_range_is_unipolar: labpc_1200_is_unipolar, - ai_scan_up: 1, - memory_mapped_io: 1, - }, +static const labpc_board labpc_boards[] = { + { + name: "lab-pc-1200", + ai_speed:10000, + bustype: isa_bustype, + register_layout:labpc_1200_layout, + has_ao: 1, + ai_range_table:&range_labpc_1200_ai, + ai_range_code:labpc_1200_ai_gain_bits, + ai_range_is_unipolar:labpc_1200_is_unipolar, + ai_scan_up:1, + memory_mapped_io:0, + }, + { + name: "lab-pc-1200ai", + ai_speed:10000, + bustype: isa_bustype, + register_layout:labpc_1200_layout, + has_ao: 0, + ai_range_table:&range_labpc_1200_ai, + ai_range_code:labpc_1200_ai_gain_bits, + ai_range_is_unipolar:labpc_1200_is_unipolar, + ai_scan_up:1, + memory_mapped_io:0, + }, + { + name: "lab-pc+", + ai_speed:12000, + bustype: isa_bustype, + register_layout:labpc_plus_layout, + has_ao: 1, + ai_range_table:&range_labpc_plus_ai, + ai_range_code:labpc_plus_ai_gain_bits, + ai_range_is_unipolar:labpc_plus_is_unipolar, + ai_scan_up:0, + memory_mapped_io:0, + }, + { + name: "pci-1200", + device_id:0x161, + ai_speed:10000, + bustype: pci_bustype, + register_layout:labpc_1200_layout, + has_ao: 1, + ai_range_table:&range_labpc_1200_ai, + ai_range_code:labpc_1200_ai_gain_bits, + ai_range_is_unipolar:labpc_1200_is_unipolar, + ai_scan_up:1, + memory_mapped_io:1, + }, }; -const labpc_board labpc_cs_boards[NUM_LABPC_CS_BOARDS] = -{ - { - name: "daqcard-1200", - device_id: 0x103, // 0x10b is manufacturer id, 0x103 is device id - ai_speed: 10000, - bustype: pcmcia_bustype, - register_layout: labpc_1200_layout, - has_ao: 1, - ai_range_table: &range_labpc_1200_ai, - ai_range_code: labpc_1200_ai_gain_bits, - ai_range_is_unipolar: labpc_1200_is_unipolar, - ai_scan_up: 0, - memory_mapped_io: 0, - }, +const labpc_board labpc_cs_boards[NUM_LABPC_CS_BOARDS] = { + { + name: "daqcard-1200", + device_id:0x103, // 0x10b is manufacturer id, 0x103 is device id + ai_speed:10000, + bustype: pcmcia_bustype, + register_layout:labpc_1200_layout, + has_ao: 1, + ai_range_table:&range_labpc_1200_ai, + ai_range_code:labpc_1200_ai_gain_bits, + ai_range_is_unipolar:labpc_1200_is_unipolar, + ai_scan_up:0, + memory_mapped_io:0, + }, /* duplicate entry, to support using alternate name */ { - name: "ni_labpc_cs", - device_id: 0x103, - ai_speed: 10000, - bustype: pcmcia_bustype, - register_layout: labpc_1200_layout, - has_ao: 1, - ai_range_table: &range_labpc_1200_ai, - ai_range_code: labpc_1200_ai_gain_bits, - ai_range_is_unipolar: labpc_1200_is_unipolar, - ai_scan_up: 0, - memory_mapped_io: 0, - }, + name: "ni_labpc_cs", + device_id:0x103, + ai_speed:10000, + bustype: pcmcia_bustype, + register_layout:labpc_1200_layout, + has_ao: 1, + ai_range_table:&range_labpc_1200_ai, + ai_range_code:labpc_1200_ai_gain_bits, + ai_range_is_unipolar:labpc_1200_is_unipolar, + ai_scan_up:0, + memory_mapped_io:0, + }, }; /* @@ -441,74 +448,71 @@ static const int sample_size = 2; // 2 bytes per sample #define devpriv ((labpc_private *)dev->private) -static comedi_driver driver_labpc={ - driver_name: "ni_labpc", - module: THIS_MODULE, - attach: labpc_attach, - detach: labpc_common_detach, - num_names: sizeof(labpc_boards) / sizeof(labpc_board), - board_name: &labpc_boards[0].name, - offset: sizeof(labpc_board), +static comedi_driver driver_labpc = { + driver_name:"ni_labpc", + module:THIS_MODULE, + attach:labpc_attach, + detach:labpc_common_detach, + num_names:sizeof(labpc_boards) / sizeof(labpc_board), + board_name:&labpc_boards[0].name, + offset:sizeof(labpc_board), }; static struct pci_device_id labpc_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, labpc_pci_table); -static inline int labpc_counter_load(comedi_device *dev, unsigned long base_address, - unsigned int counter_number, unsigned int count, unsigned int mode) +static inline int labpc_counter_load(comedi_device * dev, + unsigned long base_address, unsigned int counter_number, + unsigned int count, unsigned int mode) { - if(thisboard->memory_mapped_io) - return i8254_mm_load((void*)base_address, 0, counter_number, count, mode); + if (thisboard->memory_mapped_io) + return i8254_mm_load((void *)base_address, 0, counter_number, + count, mode); else return i8254_load(base_address, 0, counter_number, count, mode); } -int labpc_common_attach( comedi_device *dev, unsigned long iobase, - unsigned int irq, unsigned int dma_chan ) +int labpc_common_attach(comedi_device * dev, unsigned long iobase, + unsigned int irq, unsigned int dma_chan) { comedi_subdevice *s; int i; unsigned long dma_flags, isr_flags; short lsb, msb; - printk("comedi%d: ni_labpc: %s, io 0x%lx", dev->minor, thisboard->name, iobase); - if(irq) - { + printk("comedi%d: ni_labpc: %s, io 0x%lx", dev->minor, thisboard->name, + iobase); + if (irq) { printk(", irq %u", irq); } - if(dma_chan) - { + if (dma_chan) { printk(", dma %u", dma_chan); } printk("\n"); - if(iobase == 0) - { + if (iobase == 0) { printk("io base address is zero!\n"); return -EINVAL; } - // request io regions for isa boards - if(thisboard->bustype == isa_bustype) - { + if (thisboard->bustype == isa_bustype) { /* check if io addresses are available */ - if(!request_region(iobase, LABPC_SIZE, driver_labpc.driver_name)) - { + if (!request_region(iobase, LABPC_SIZE, + driver_labpc.driver_name)) { printk("I/O port conflict\n"); return -EIO; } } dev->iobase = iobase; - if(thisboard->memory_mapped_io) - { + if (thisboard->memory_mapped_io) { devpriv->read_byte = labpc_readb; devpriv->write_byte = labpc_writeb; - }else - { + } else { devpriv->read_byte = labpc_inb; devpriv->write_byte = labpc_outb; } @@ -517,43 +521,41 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG); - if(thisboard->register_layout == labpc_1200_layout) - { - devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); - devpriv->write_byte(devpriv->command6_bits, dev->iobase + COMMAND6_REG); + if (thisboard->register_layout == labpc_1200_layout) { + devpriv->write_byte(devpriv->command5_bits, + dev->iobase + COMMAND5_REG); + devpriv->write_byte(devpriv->command6_bits, + dev->iobase + COMMAND6_REG); } /* grab our IRQ */ - if(irq) - { + if (irq) { isr_flags = 0; - if(thisboard->bustype == pci_bustype) + if (thisboard->bustype == pci_bustype) isr_flags |= IRQF_SHARED; - if(comedi_request_irq( irq, labpc_interrupt, isr_flags, driver_labpc.driver_name, dev)) - { - printk( "unable to allocate irq %u\n", irq); + if (comedi_request_irq(irq, labpc_interrupt, isr_flags, + driver_labpc.driver_name, dev)) { + printk("unable to allocate irq %u\n", irq); return -EINVAL; } } dev->irq = irq; // grab dma channel - if(dma_chan > 3) - { + if (dma_chan > 3) { printk(" invalid dma channel %u\n", dma_chan); return -EINVAL; - }else if(dma_chan) - { + } else if (dma_chan) { // allocate dma buffer - devpriv->dma_buffer = kmalloc(dma_buffer_size, GFP_KERNEL | GFP_DMA); - if(devpriv->dma_buffer == NULL) - { + devpriv->dma_buffer = + kmalloc(dma_buffer_size, GFP_KERNEL | GFP_DMA); + if (devpriv->dma_buffer == NULL) { printk(" failed to allocate dma buffer\n"); return -ENOMEM; } - if(request_dma(dma_chan, driver_labpc.driver_name)) - { - printk(" failed to allocate dma channel %u\n", dma_chan); + if (request_dma(dma_chan, driver_labpc.driver_name)) { + printk(" failed to allocate dma channel %u\n", + dma_chan); return -EINVAL; } devpriv->dma_chan = dma_chan; @@ -565,14 +567,16 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, dev->board_name = thisboard->name; - if(alloc_subdevices(dev, 5) < 0) + if (alloc_subdevices(dev, 5) < 0) return -ENOMEM; /* analog input subdevice */ s = dev->subdevices + 0; dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF | SDF_CMD_READ; + s->subdev_flags = + SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF | + SDF_CMD_READ; s->n_chan = 8; s->len_chanlist = 8; s->maxdata = (1 << 12) - 1; // 12 bit resolution @@ -584,11 +588,10 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, /* analog output */ s = dev->subdevices + 1; - if(thisboard->has_ao) - { + if (thisboard->has_ao) { /* Could provide command support, except it only has a one sample * hardware buffer for analog output and no underrun flag. */ - s->type=COMEDI_SUBD_AO; + s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; s->n_chan = NUM_AO_CHAN; s->maxdata = (1 << 12) - 1; // 12 bit resolution @@ -596,47 +599,44 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, s->insn_read = labpc_ao_rinsn; s->insn_write = labpc_ao_winsn; /* initialize analog outputs to a known value */ - for(i = 0; i < s->n_chan; i++) - { + for (i = 0; i < s->n_chan; i++) { devpriv->ao_value[i] = s->maxdata / 2; lsb = devpriv->ao_value[i] & 0xff; msb = (devpriv->ao_value[i] >> 8) & 0xff; devpriv->write_byte(lsb, dev->iobase + DAC_LSB_REG(i)); devpriv->write_byte(msb, dev->iobase + DAC_MSB_REG(i)); } - }else - { + } else { s->type = COMEDI_SUBD_UNUSED; } /* 8255 dio */ s = dev->subdevices + 2; // if board uses io memory we have to give a custom callback function to the 8255 driver - if(thisboard->memory_mapped_io) - subdev_8255_init(dev, s, labpc_dio_mem_callback, (unsigned long)(dev->iobase + DIO_BASE_REG)); + if (thisboard->memory_mapped_io) + subdev_8255_init(dev, s, labpc_dio_mem_callback, + (unsigned long)(dev->iobase + DIO_BASE_REG)); else subdev_8255_init(dev, s, NULL, dev->iobase + DIO_BASE_REG); // calibration subdevices for boards that have one s = dev->subdevices + 3; - if(thisboard->register_layout == labpc_1200_layout) - { - s->type=COMEDI_SUBD_CALIB; + if (thisboard->register_layout == labpc_1200_layout) { + s->type = COMEDI_SUBD_CALIB; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = 16; s->maxdata = 0xff; s->insn_read = labpc_calib_read_insn; s->insn_write = labpc_calib_write_insn; - for( i = 0; i < s->n_chan; i++ ) - write_caldac( dev, i, s->maxdata / 2 ); - }else + for (i = 0; i < s->n_chan; i++) + write_caldac(dev, i, s->maxdata / 2); + } else s->type = COMEDI_SUBD_UNUSED; /* EEPROM */ s = dev->subdevices + 4; - if(thisboard->register_layout == labpc_1200_layout) - { + if (thisboard->register_layout == labpc_1200_layout) { s->type = COMEDI_SUBD_MEMORY; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = EEPROM_SIZE; @@ -644,25 +644,23 @@ int labpc_common_attach( comedi_device *dev, unsigned long iobase, s->insn_read = labpc_eeprom_read_insn; s->insn_write = labpc_eeprom_write_insn; - for(i = 0; i < EEPROM_SIZE; i++) - { + for (i = 0; i < EEPROM_SIZE; i++) { devpriv->eeprom_data[i] = labpc_eeprom_read(dev, i); } #ifdef LABPC_DEBUG printk(" eeprom:"); - for(i = 0; i < EEPROM_SIZE; i++) - { + for (i = 0; i < EEPROM_SIZE; i++) { printk(" %i:0x%x ", i, devpriv->eeprom_data[i]); } printk("\n"); #endif - }else + } else s->type = COMEDI_SUBD_UNUSED; return 0; } -static int labpc_attach(comedi_device *dev, comedi_devconfig *it) +static int labpc_attach(comedi_device * dev, comedi_devconfig * it) { unsigned long iobase = 0; unsigned int irq = 0; @@ -670,66 +668,65 @@ static int labpc_attach(comedi_device *dev, comedi_devconfig *it) int ret; /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(labpc_private)) < 0) + if (alloc_private(dev, sizeof(labpc_private)) < 0) return -ENOMEM; // get base address, irq etc. based on bustype - switch(thisboard->bustype) - { - case isa_bustype: - iobase = it->options[0]; - irq = it->options[1]; - dma_chan = it->options[2]; - break; - case pci_bustype: - devpriv->mite = labpc_find_device(it->options[0], it->options[1]); - if(devpriv->mite == NULL) - { - return -EIO; - } - if(thisboard->device_id != mite_device_id(devpriv->mite)) - { // this should never happen since this driver only supports one type of pci board - printk("bug! mite device id does not match boardtype definition\n"); - return -EINVAL; - } - ret = mite_setup(devpriv->mite); - if(ret < 0) return ret; - iobase = (unsigned long) devpriv->mite->daq_io_addr; - irq = mite_irq(devpriv->mite); - break; - case pcmcia_bustype: - printk(" this driver does not support pcmcia cards, use ni_labpc_cs.o\n"); - return -EINVAL; - break; - default: - printk("bug! couldn't determine board type\n");\ + switch (thisboard->bustype) { + case isa_bustype: + iobase = it->options[0]; + irq = it->options[1]; + dma_chan = it->options[2]; + break; + case pci_bustype: + devpriv->mite = + labpc_find_device(it->options[0], it->options[1]); + if (devpriv->mite == NULL) { + return -EIO; + } + if (thisboard->device_id != mite_device_id(devpriv->mite)) { // this should never happen since this driver only supports one type of pci board + printk("bug! mite device id does not match boardtype definition\n"); return -EINVAL; - break; + } + ret = mite_setup(devpriv->mite); + if (ret < 0) + return ret; + iobase = (unsigned long)devpriv->mite->daq_io_addr; + irq = mite_irq(devpriv->mite); + break; + case pcmcia_bustype: + printk(" this driver does not support pcmcia cards, use ni_labpc_cs.o\n"); + return -EINVAL; + break; + default: + printk("bug! couldn't determine board type\n"); + return -EINVAL; + break; } - return labpc_common_attach( dev, iobase, irq, dma_chan ); + return labpc_common_attach(dev, iobase, irq, dma_chan); } // adapted from ni_pcimio for finding mite based boards (pc-1200) -static struct mite_struct* labpc_find_device(int bus, int slot) +static struct mite_struct *labpc_find_device(int bus, int slot) { struct mite_struct *mite; int i; - for(mite = mite_devices; mite; mite = mite->next) - { - if(mite->used) continue; + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; // if bus/slot are specified then make sure we have the right bus/slot - if(bus || slot) - { - if(bus != mite->pcidev->bus->number || slot != PCI_SLOT(mite->pcidev->devfn)) continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number + || slot != PCI_SLOT(mite->pcidev->devfn)) + continue; } - for(i = 0; i < driver_labpc.num_names; i++) - { - if(labpc_boards[i].bustype != pci_bustype) continue; - if(mite_device_id(mite) == labpc_boards[i].device_id) - { - return mite; - } + for (i = 0; i < driver_labpc.num_names; i++) { + if (labpc_boards[i].bustype != pci_bustype) + continue; + if (mite_device_id(mite) == labpc_boards[i].device_id) { + return mite; + } } } printk("no device found\n"); @@ -737,44 +734,43 @@ static struct mite_struct* labpc_find_device(int bus, int slot) return NULL; } -int labpc_common_detach(comedi_device *dev) +int labpc_common_detach(comedi_device * dev) { printk("comedi%d: ni_labpc: detach\n", dev->minor); - if(dev->subdevices) - subdev_8255_cleanup(dev,dev->subdevices + 2); + if (dev->subdevices) + subdev_8255_cleanup(dev, dev->subdevices + 2); /* only free stuff if it has been allocated by _attach */ - if(devpriv->dma_buffer) + if (devpriv->dma_buffer) kfree(devpriv->dma_buffer); - if(devpriv->dma_chan) + if (devpriv->dma_chan) free_dma(devpriv->dma_chan); - if(dev->irq) + if (dev->irq) comedi_free_irq(dev->irq, dev); - if(thisboard->bustype == isa_bustype && - dev->iobase) + if (thisboard->bustype == isa_bustype && dev->iobase) release_region(dev->iobase, LABPC_SIZE); - if( devpriv->mite ) - mite_unsetup( devpriv->mite ); + if (devpriv->mite) + mite_unsetup(devpriv->mite); return 0; }; -static void labpc_clear_adc_fifo( const comedi_device *dev ) +static void labpc_clear_adc_fifo(const comedi_device * dev) { devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG); devpriv->read_byte(dev->iobase + ADC_FIFO_REG); devpriv->read_byte(dev->iobase + ADC_FIFO_REG); } -static int labpc_cancel(comedi_device *dev, comedi_subdevice *s) +static int labpc_cancel(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT; devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); devpriv->command3_bits = 0; devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); @@ -782,91 +778,90 @@ static int labpc_cancel(comedi_device *dev, comedi_subdevice *s) return 0; } -static enum scan_mode labpc_ai_scan_mode( const comedi_cmd *cmd ) +static enum scan_mode labpc_ai_scan_mode(const comedi_cmd * cmd) { - if( cmd->chanlist_len == 1 ) + if (cmd->chanlist_len == 1) return MODE_SINGLE_CHAN; - if( CR_CHAN( cmd->chanlist[0] ) == CR_CHAN( cmd->chanlist[1] ) ) + if (CR_CHAN(cmd->chanlist[0]) == CR_CHAN(cmd->chanlist[1])) return MODE_SINGLE_CHAN_INTERVAL; - if( CR_CHAN( cmd->chanlist[0] ) < CR_CHAN( cmd->chanlist[1] ) ) + if (CR_CHAN(cmd->chanlist[0]) < CR_CHAN(cmd->chanlist[1])) return MODE_MULT_CHAN_UP; - if( CR_CHAN( cmd->chanlist[0] ) > CR_CHAN( cmd->chanlist[1] ) ) + if (CR_CHAN(cmd->chanlist[0]) > CR_CHAN(cmd->chanlist[1])) return MODE_MULT_CHAN_DOWN; - rt_printk( "ni_labpc: bug! this should never happen\n"); + rt_printk("ni_labpc: bug! this should never happen\n"); return 0; } -static int labpc_ai_chanlist_invalid( const comedi_device *dev, - const comedi_cmd *cmd ) +static int labpc_ai_chanlist_invalid(const comedi_device * dev, + const comedi_cmd * cmd) { int mode, channel, range, aref, i; - if( cmd->chanlist == NULL ) return 0; + if (cmd->chanlist == NULL) + return 0; - mode = labpc_ai_scan_mode( cmd ); + mode = labpc_ai_scan_mode(cmd); - if( mode == MODE_SINGLE_CHAN ) return 0; + if (mode == MODE_SINGLE_CHAN) + return 0; - if( mode == MODE_SINGLE_CHAN_INTERVAL ) - { - if( cmd->chanlist_len > 0xff ) - { - comedi_error(dev, "ni_labpc: chanlist too long for single channel interval mode\n"); + if (mode == MODE_SINGLE_CHAN_INTERVAL) { + if (cmd->chanlist_len > 0xff) { + comedi_error(dev, + "ni_labpc: chanlist too long for single channel interval mode\n"); return 1; } } - channel = CR_CHAN( cmd->chanlist[ 0 ] ); - range = CR_RANGE( cmd->chanlist[ 0 ] ); - aref = CR_AREF( cmd->chanlist[ 0 ] ); + channel = CR_CHAN(cmd->chanlist[0]); + range = CR_RANGE(cmd->chanlist[0]); + aref = CR_AREF(cmd->chanlist[0]); - for( i = 0; i < cmd->chanlist_len; i++ ) - { + for (i = 0; i < cmd->chanlist_len; i++) { - switch( mode ) - { - case MODE_SINGLE_CHAN_INTERVAL: - if( CR_CHAN( cmd->chanlist[ i ] ) != channel ) - { - comedi_error(dev, "channel scanning order specified in chanlist is not supported by hardware.\n"); - return 1; - } - break; - case MODE_MULT_CHAN_UP: - if( CR_CHAN( cmd->chanlist[ i ] ) != i ) - { - comedi_error(dev, "channel scanning order specified in chanlist is not supported by hardware.\n"); - return 1; - } - break; - case MODE_MULT_CHAN_DOWN: - if( CR_CHAN( cmd->chanlist[i] ) != - cmd->chanlist_len - i - 1 ) - { - comedi_error(dev, "channel scanning order specified in chanlist is not supported by hardware.\n"); - return 1; - } - break; - default: - rt_printk( "ni_labpc: bug! in chanlist check\n"); + switch (mode) { + case MODE_SINGLE_CHAN_INTERVAL: + if (CR_CHAN(cmd->chanlist[i]) != channel) { + comedi_error(dev, + "channel scanning order specified in chanlist is not supported by hardware.\n"); return 1; - break; + } + break; + case MODE_MULT_CHAN_UP: + if (CR_CHAN(cmd->chanlist[i]) != i) { + comedi_error(dev, + "channel scanning order specified in chanlist is not supported by hardware.\n"); + return 1; + } + break; + case MODE_MULT_CHAN_DOWN: + if (CR_CHAN(cmd->chanlist[i]) != + cmd->chanlist_len - i - 1) { + comedi_error(dev, + "channel scanning order specified in chanlist is not supported by hardware.\n"); + return 1; + } + break; + default: + rt_printk("ni_labpc: bug! in chanlist check\n"); + return 1; + break; } - if( CR_RANGE( cmd->chanlist[i] ) != range ) - { - comedi_error(dev, "entries in chanlist must all have the same range\n"); + if (CR_RANGE(cmd->chanlist[i]) != range) { + comedi_error(dev, + "entries in chanlist must all have the same range\n"); return 1; } - if( CR_AREF( cmd->chanlist[i] ) != aref ) - { - comedi_error(dev, "entries in chanlist must all have the same reference\n"); + if (CR_AREF(cmd->chanlist[i]) != aref) { + comedi_error(dev, + "entries in chanlist must all have the same reference\n"); return 1; } } @@ -874,63 +869,69 @@ static int labpc_ai_chanlist_invalid( const comedi_device *dev, return 0; } -static int labpc_use_continuous_mode( const comedi_cmd *cmd ) +static int labpc_use_continuous_mode(const comedi_cmd * cmd) { - if( labpc_ai_scan_mode( cmd ) == MODE_SINGLE_CHAN ) return 1; + if (labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN) + return 1; - if( cmd->scan_begin_src == TRIG_FOLLOW ) return 1; + if (cmd->scan_begin_src == TRIG_FOLLOW) + return 1; return 0; } -static unsigned int labpc_ai_convert_period( const comedi_cmd *cmd ) +static unsigned int labpc_ai_convert_period(const comedi_cmd * cmd) { - if( cmd->convert_src != TRIG_TIMER ) return 0; + if (cmd->convert_src != TRIG_TIMER) + return 0; - if( labpc_ai_scan_mode( cmd ) == MODE_SINGLE_CHAN && - cmd->scan_begin_src == TRIG_TIMER ) + if (labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN && + cmd->scan_begin_src == TRIG_TIMER) return cmd->scan_begin_arg; return cmd->convert_arg; } -static void labpc_set_ai_convert_period( comedi_cmd *cmd, unsigned int ns ) +static void labpc_set_ai_convert_period(comedi_cmd * cmd, unsigned int ns) { - if( cmd->convert_src != TRIG_TIMER ) return; + if (cmd->convert_src != TRIG_TIMER) + return; - if( labpc_ai_scan_mode( cmd ) == MODE_SINGLE_CHAN && - cmd->scan_begin_src == TRIG_TIMER ) - { + if (labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN && + cmd->scan_begin_src == TRIG_TIMER) { cmd->scan_begin_arg = ns; - if( cmd->convert_arg > cmd->scan_begin_arg ) + if (cmd->convert_arg > cmd->scan_begin_arg) cmd->convert_arg = cmd->scan_begin_arg; - }else + } else cmd->convert_arg = ns; } -static unsigned int labpc_ai_scan_period( const comedi_cmd *cmd ) +static unsigned int labpc_ai_scan_period(const comedi_cmd * cmd) { - if( cmd->scan_begin_src != TRIG_TIMER ) return 0; + if (cmd->scan_begin_src != TRIG_TIMER) + return 0; - if( labpc_ai_scan_mode( cmd ) == MODE_SINGLE_CHAN && - cmd->convert_src == TRIG_TIMER ) + if (labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN && + cmd->convert_src == TRIG_TIMER) return 0; return cmd->scan_begin_arg; } -static void labpc_set_ai_scan_period( comedi_cmd *cmd, unsigned int ns ) +static void labpc_set_ai_scan_period(comedi_cmd * cmd, unsigned int ns) { - if( cmd->scan_begin_src != TRIG_TIMER ) return; + if (cmd->scan_begin_src != TRIG_TIMER) + return; - if( labpc_ai_scan_mode( cmd ) == MODE_SINGLE_CHAN && - cmd->convert_src == TRIG_TIMER ) + if (labpc_ai_scan_mode(cmd) == MODE_SINGLE_CHAN && + cmd->convert_src == TRIG_TIMER) return; cmd->scan_begin_arg = ns; } -static int labpc_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int labpc_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int err = 0; int tmp, tmp2; @@ -940,132 +941,133 @@ static int labpc_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *c tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; stop_mask = TRIG_COUNT | TRIG_NONE; - if(thisboard->register_layout == labpc_1200_layout) + if (thisboard->register_layout == labpc_1200_layout) stop_mask |= TRIG_EXT; cmd->stop_src &= stop_mask; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT) err++; - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_FOLLOW && - cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_EXT && - cmd->stop_src != TRIG_NONE) err++; + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE) + err++; // can't have external stop and start triggers at once - if(cmd->start_src == TRIG_EXT && - cmd->stop_src == TRIG_EXT) err++; + if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg == TRIG_NOW && cmd->start_arg != 0) - { + if (cmd->start_arg == TRIG_NOW && cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->convert_src == TRIG_TIMER) - { - if(cmd->convert_arg < thisboard->ai_speed) - { + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < thisboard->ai_speed) { cmd->convert_arg = thisboard->ai_speed; err++; } } - // make sure scan timing is not too fast - if(cmd->scan_begin_src == TRIG_TIMER) - { - if(cmd->convert_src == TRIG_TIMER && - cmd->scan_begin_arg < cmd->convert_arg * cmd->chanlist_len) - { - cmd->scan_begin_arg = cmd->convert_arg * cmd->chanlist_len; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->convert_src == TRIG_TIMER && + cmd->scan_begin_arg < + cmd->convert_arg * cmd->chanlist_len) { + cmd->scan_begin_arg = + cmd->convert_arg * cmd->chanlist_len; err++; } - if(cmd->scan_begin_arg < thisboard->ai_speed * cmd->chanlist_len) - { - cmd->scan_begin_arg = thisboard->ai_speed * cmd->chanlist_len; + if (cmd->scan_begin_arg < + thisboard->ai_speed * cmd->chanlist_len) { + cmd->scan_begin_arg = + thisboard->ai_speed * cmd->chanlist_len; err++; } } - // stop source - switch(cmd->stop_src) - { - case TRIG_COUNT: - if(!cmd->stop_arg) - { - cmd->stop_arg = 1; - err++; - } - break; - case TRIG_NONE: - if(cmd->stop_arg != 0) - { - cmd->stop_arg = 0; - err++; - } - break; + switch (cmd->stop_src) { + case TRIG_COUNT: + if (!cmd->stop_arg) { + cmd->stop_arg = 1; + err++; + } + break; + case TRIG_NONE: + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; + err++; + } + break; // TRIG_EXT doesn't care since it doesn't trigger off a numbered channel - default: - break; + default: + break; } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ tmp = cmd->convert_arg; tmp2 = cmd->scan_begin_arg; labpc_adc_timing(dev, cmd); - if(tmp != cmd->convert_arg || - tmp2 != cmd->scan_begin_arg) err++; + if (tmp != cmd->convert_arg || tmp2 != cmd->scan_begin_arg) + err++; - if(err)return 4; + if (err) + return 4; - if( labpc_ai_chanlist_invalid( dev, cmd ) ) + if (labpc_ai_chanlist_invalid(dev, cmd)) return 5; return 0; } -static int labpc_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int labpc_ai_cmd(comedi_device * dev, comedi_subdevice * s) { int channel, range, aref; unsigned long irq_flags; @@ -1075,8 +1077,7 @@ static int labpc_ai_cmd(comedi_device *dev, comedi_subdevice *s) enum transfer_type xfer; unsigned long flags; - if(!dev->irq) - { + if (!dev->irq) { comedi_error(dev, "no irq assigned, cannot perform command"); return -1; } @@ -1085,194 +1086,190 @@ static int labpc_ai_cmd(comedi_device *dev, comedi_subdevice *s) aref = CR_AREF(cmd->chanlist[0]); // make sure board is disabled before setting up aquisition - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT; devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); devpriv->command3_bits = 0; devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); // initialize software conversion count - if(cmd->stop_src == TRIG_COUNT) - { + if (cmd->stop_src == TRIG_COUNT) { devpriv->count = cmd->stop_arg * cmd->chanlist_len; } // setup hardware conversion counter - if(cmd->stop_src == TRIG_EXT) - { + if (cmd->stop_src == TRIG_EXT) { // load counter a1 with count of 3 (pc+ manual says this is minimum allowed) using mode 0 - ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG, 1, 3, 0); - if(ret < 0) - { + ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG, + 1, 3, 0); + if (ret < 0) { comedi_error(dev, "error loading counter a1"); return -1; } - }else // otherwise, just put a1 in mode 0 with no count to set its output low - devpriv->write_byte(INIT_A1_BITS, dev->iobase + COUNTER_A_CONTROL_REG); + } else // otherwise, just put a1 in mode 0 with no count to set its output low + devpriv->write_byte(INIT_A1_BITS, + dev->iobase + COUNTER_A_CONTROL_REG); // figure out what method we will use to transfer data - if(devpriv->dma_chan && // need a dma channel allocated + if (devpriv->dma_chan && // need a dma channel allocated // dma unsafe at RT priority, and too much setup time for TRIG_WAKE_EOS for (cmd->flags & (TRIG_WAKE_EOS | TRIG_RT)) == 0 && // only available on the isa boards - thisboard->bustype == isa_bustype) - { + thisboard->bustype == isa_bustype) { xfer = isa_dma_transfer; - }else if(thisboard->register_layout == labpc_1200_layout && // pc-plus has no fifo-half full interrupt + } else if (thisboard->register_layout == labpc_1200_layout && // pc-plus has no fifo-half full interrupt // wake-end-of-scan should interrupt on fifo not empty (cmd->flags & TRIG_WAKE_EOS) == 0 && // make sure we are taking more than just a few points - (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) - { + (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) { xfer = fifo_half_full_transfer; - }else + } else xfer = fifo_not_empty_transfer; devpriv->current_transfer = xfer; // setup command6 register for 1200 boards - if(thisboard->register_layout == labpc_1200_layout) - { + if (thisboard->register_layout == labpc_1200_layout) { // reference inputs to ground or common? - if(aref != AREF_GROUND) + if (aref != AREF_GROUND) devpriv->command6_bits |= ADC_COMMON_BIT; else devpriv->command6_bits &= ~ADC_COMMON_BIT; // bipolar or unipolar range? - if(thisboard->ai_range_is_unipolar[range]) + if (thisboard->ai_range_is_unipolar[range]) devpriv->command6_bits |= ADC_UNIP_BIT; else devpriv->command6_bits &= ~ADC_UNIP_BIT; // interrupt on fifo half full? - if(xfer == fifo_half_full_transfer) + if (xfer == fifo_half_full_transfer) devpriv->command6_bits |= ADC_FHF_INTR_EN_BIT; else devpriv->command6_bits &= ~ADC_FHF_INTR_EN_BIT; // enable interrupt on counter a1 terminal count? - if(cmd->stop_src == TRIG_EXT) + if (cmd->stop_src == TRIG_EXT) devpriv->command6_bits |= A1_INTR_EN_BIT; else devpriv->command6_bits &= ~A1_INTR_EN_BIT; // are we scanning up or down through channels? - if( labpc_ai_scan_mode( cmd ) == MODE_MULT_CHAN_UP ) + if (labpc_ai_scan_mode(cmd) == MODE_MULT_CHAN_UP) devpriv->command6_bits |= ADC_SCAN_UP_BIT; else devpriv->command6_bits &= ~ADC_SCAN_UP_BIT; // write to register - devpriv->write_byte(devpriv->command6_bits, dev->iobase + COMMAND6_REG); + devpriv->write_byte(devpriv->command6_bits, + dev->iobase + COMMAND6_REG); } /* setup channel list, etc (command1 register) */ devpriv->command1_bits = 0; - if( labpc_ai_scan_mode( cmd ) == MODE_MULT_CHAN_UP ) + if (labpc_ai_scan_mode(cmd) == MODE_MULT_CHAN_UP) channel = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]); else channel = CR_CHAN(cmd->chanlist[0]); // munge channel bits for differential / scan disabled mode - if( labpc_ai_scan_mode( cmd ) != MODE_SINGLE_CHAN && aref == AREF_DIFF ) + if (labpc_ai_scan_mode(cmd) != MODE_SINGLE_CHAN && aref == AREF_DIFF) channel *= 2; devpriv->command1_bits |= ADC_CHAN_BITS(channel); devpriv->command1_bits |= thisboard->ai_range_code[range]; devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG); // manual says to set scan enable bit on second pass - if( labpc_ai_scan_mode( cmd ) == MODE_MULT_CHAN_UP || - labpc_ai_scan_mode( cmd ) == MODE_MULT_CHAN_DOWN ) - { + if (labpc_ai_scan_mode(cmd) == MODE_MULT_CHAN_UP || + labpc_ai_scan_mode(cmd) == MODE_MULT_CHAN_DOWN) { devpriv->command1_bits |= ADC_SCAN_EN_BIT; /* need a brief delay before enabling scan, or scan list will get screwed when you switch * between scan up to scan down mode - dunno why */ comedi_udelay(1); - devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG); + devpriv->write_byte(devpriv->command1_bits, + dev->iobase + COMMAND1_REG); } - // setup any external triggering/pacing (command4 register) devpriv->command4_bits = 0; - if(cmd->convert_src != TRIG_EXT) + if (cmd->convert_src != TRIG_EXT) devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT; /* XXX should discard first scan when using interval scanning * since manual says it is not synced with scan clock */ - if( labpc_use_continuous_mode( cmd ) == 0 ) - { + if (labpc_use_continuous_mode(cmd) == 0) { devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT; - if( cmd->scan_begin_src == TRIG_EXT ) + if (cmd->scan_begin_src == TRIG_EXT) devpriv->command4_bits |= EXT_SCAN_EN_BIT; } // single-ended/differential - if(aref == AREF_DIFF) + if (aref == AREF_DIFF) devpriv->command4_bits |= ADC_DIFF_BIT; devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG); - devpriv->write_byte( cmd->chanlist_len, dev->iobase + INTERVAL_COUNT_REG); + devpriv->write_byte(cmd->chanlist_len, + dev->iobase + INTERVAL_COUNT_REG); // load count - devpriv->write_byte(INTERVAL_LOAD_BITS, dev->iobase + INTERVAL_LOAD_REG); + devpriv->write_byte(INTERVAL_LOAD_BITS, + dev->iobase + INTERVAL_LOAD_REG); - if(cmd->convert_src == TRIG_TIMER || cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->convert_src == TRIG_TIMER || cmd->scan_begin_src == TRIG_TIMER) { // set up pacing labpc_adc_timing(dev, cmd); // load counter b0 in mode 3 - ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG, 0, devpriv->divisor_b0, 3); - if(ret < 0) - { + ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG, + 0, devpriv->divisor_b0, 3); + if (ret < 0) { comedi_error(dev, "error loading counter b0"); return -1; } } // set up conversion pacing - if( labpc_ai_convert_period( cmd ) ) - { + if (labpc_ai_convert_period(cmd)) { // load counter a0 in mode 2 - ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG, 0, devpriv->divisor_a0, 2); - if(ret < 0) - { + ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG, + 0, devpriv->divisor_a0, 2); + if (ret < 0) { comedi_error(dev, "error loading counter a0"); return -1; } - }else - devpriv->write_byte(INIT_A0_BITS, dev->iobase + COUNTER_A_CONTROL_REG); + } else + devpriv->write_byte(INIT_A0_BITS, + dev->iobase + COUNTER_A_CONTROL_REG); // set up scan pacing - if( labpc_ai_scan_period( cmd ) ) - { + if (labpc_ai_scan_period(cmd)) { // load counter b1 in mode 2 - ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG, 1, devpriv->divisor_b1, 2); - if(ret < 0) - { + ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG, + 1, devpriv->divisor_b1, 2); + if (ret < 0) { comedi_error(dev, "error loading counter b1"); return -1; } } - labpc_clear_adc_fifo( dev ); + labpc_clear_adc_fifo(dev); // set up dma transfer - if(xfer == isa_dma_transfer) - { + if (xfer == isa_dma_transfer) { irq_flags = claim_dma_lock(); disable_dma(devpriv->dma_chan); /* clear flip-flop to make sure 2-byte registers for - * count and address get set correctly */ + * count and address get set correctly */ clear_dma_ff(devpriv->dma_chan); - set_dma_addr(devpriv->dma_chan, virt_to_bus(devpriv->dma_buffer)); + set_dma_addr(devpriv->dma_chan, + virt_to_bus(devpriv->dma_buffer)); // set appropriate size of transfer devpriv->dma_transfer_size = labpc_suggest_transfer_size(*cmd); - if(cmd->stop_src == TRIG_COUNT && - devpriv->count * sample_size < devpriv->dma_transfer_size) - { - devpriv->dma_transfer_size = devpriv->count * sample_size; + if (cmd->stop_src == TRIG_COUNT && + devpriv->count * sample_size < + devpriv->dma_transfer_size) { + devpriv->dma_transfer_size = + devpriv->count * sample_size; } set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size); enable_dma(devpriv->dma_chan); release_dma_lock(irq_flags); // enable board's dma devpriv->command3_bits |= DMA_EN_BIT | DMATC_INTR_EN_BIT; - }else + } else devpriv->command3_bits &= ~DMA_EN_BIT & ~DMATC_INTR_EN_BIT; // enable error interrupts devpriv->command3_bits |= ERR_INTR_EN_BIT; // enable fifo not empty interrupt? - if(xfer == fifo_not_empty_transfer) + if (xfer == fifo_not_empty_transfer) devpriv->command3_bits |= ADC_FNE_INTR_EN_BIT; else devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT; @@ -1282,37 +1279,35 @@ static int labpc_ai_cmd(comedi_device *dev, comedi_subdevice *s) // command2 reg // use 2 cascaded counters for pacing - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->command2_bits |= CASCADE_BIT; - switch(cmd->start_src) - { - case TRIG_EXT: - devpriv->command2_bits |= HWTRIG_BIT; - devpriv->command2_bits &= ~PRETRIG_BIT & ~SWTRIG_BIT; - break; - case TRIG_NOW: - devpriv->command2_bits |= SWTRIG_BIT; - devpriv->command2_bits &= ~PRETRIG_BIT & ~HWTRIG_BIT; - break; - default: - comedi_error(dev, "bug with start_src"); - return -1; - break; + switch (cmd->start_src) { + case TRIG_EXT: + devpriv->command2_bits |= HWTRIG_BIT; + devpriv->command2_bits &= ~PRETRIG_BIT & ~SWTRIG_BIT; + break; + case TRIG_NOW: + devpriv->command2_bits |= SWTRIG_BIT; + devpriv->command2_bits &= ~PRETRIG_BIT & ~HWTRIG_BIT; + break; + default: + comedi_error(dev, "bug with start_src"); + return -1; + break; } - switch(cmd->stop_src) - { - case TRIG_EXT: - devpriv->command2_bits |= HWTRIG_BIT | PRETRIG_BIT; - break; - case TRIG_COUNT: - case TRIG_NONE: - break; - default: - comedi_error(dev, "bug with stop_src"); - return -1; + switch (cmd->stop_src) { + case TRIG_EXT: + devpriv->command2_bits |= HWTRIG_BIT | PRETRIG_BIT; + break; + case TRIG_COUNT: + case TRIG_NONE: + break; + default: + comedi_error(dev, "bug with stop_src"); + return -1; } devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } @@ -1325,8 +1320,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) comedi_async *async; comedi_cmd *cmd; - if(dev->attached == 0) - { + if (dev->attached == 0) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } @@ -1337,18 +1331,18 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) // read board status devpriv->status1_bits = devpriv->read_byte(dev->iobase + STATUS1_REG); - if(thisboard->register_layout == labpc_1200_layout) - devpriv->status2_bits = devpriv->read_byte(dev->iobase + STATUS2_REG); - - if((devpriv->status1_bits & (DMATC_BIT | TIMER_BIT | OVERFLOW_BIT | OVERRUN_BIT | DATA_AVAIL_BIT)) == 0 && - (devpriv->status2_bits & A1_TC_BIT) == 0 && - (devpriv->status2_bits & FNHF_BIT)) - { + if (thisboard->register_layout == labpc_1200_layout) + devpriv->status2_bits = + devpriv->read_byte(dev->iobase + STATUS2_REG); + + if ((devpriv->status1_bits & (DMATC_BIT | TIMER_BIT | OVERFLOW_BIT | + OVERRUN_BIT | DATA_AVAIL_BIT)) == 0 + && (devpriv->status2_bits & A1_TC_BIT) == 0 + && (devpriv->status2_bits & FNHF_BIT)) { return IRQ_NONE; } - if(devpriv->status1_bits & OVERRUN_BIT) - { + if (devpriv->status1_bits & OVERRUN_BIT) { // clear error interrupt devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; @@ -1357,25 +1351,23 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) return IRQ_HANDLED; } - if(devpriv->current_transfer == isa_dma_transfer) - { + if (devpriv->current_transfer == isa_dma_transfer) { // if a dma terminal count of external stop trigger has occurred - if(devpriv->status1_bits & DMATC_BIT || - (thisboard->register_layout == labpc_1200_layout && devpriv->status2_bits & A1_TC_BIT)) - { + if (devpriv->status1_bits & DMATC_BIT || + (thisboard->register_layout == labpc_1200_layout + && devpriv->status2_bits & A1_TC_BIT)) { handle_isa_dma(dev); } - }else labpc_drain_fifo(dev); + } else + labpc_drain_fifo(dev); - if(devpriv->status1_bits & TIMER_BIT) - { + if (devpriv->status1_bits & TIMER_BIT) { comedi_error(dev, "handled timer interrupt?"); // clear it devpriv->write_byte(0x1, dev->iobase + TIMER_CLEAR_REG); } - if(devpriv->status1_bits & OVERFLOW_BIT) - { + if (devpriv->status1_bits & OVERFLOW_BIT) { // clear error interrupt devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; @@ -1383,12 +1375,9 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) comedi_error(dev, "overflow"); return IRQ_HANDLED; } - // handle external stop trigger - if(cmd->stop_src == TRIG_EXT) - { - if(devpriv->status2_bits & A1_TC_BIT) - { + if (cmd->stop_src == TRIG_EXT) { + if (devpriv->status2_bits & A1_TC_BIT) { labpc_drain_dregs(dev); labpc_cancel(dev, s); async->events |= COMEDI_CB_EOA; @@ -1396,10 +1385,8 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) } /* TRIG_COUNT end of acquisition */ - if(cmd->stop_src == TRIG_COUNT) - { - if(devpriv->count == 0) - { + if (cmd->stop_src == TRIG_COUNT) { + if (devpriv->count == 0) { labpc_cancel(dev, s); async->events |= COMEDI_CB_EOA; } @@ -1410,7 +1397,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d PT_REGS_ARG) } // read all available samples from ai fifo -static int labpc_drain_fifo(comedi_device *dev) +static int labpc_drain_fifo(comedi_device * dev) { unsigned int lsb, msb; sampl_t data; @@ -1420,22 +1407,22 @@ static int labpc_drain_fifo(comedi_device *dev) devpriv->status1_bits = devpriv->read_byte(dev->iobase + STATUS1_REG); - for(i = 0; (devpriv->status1_bits & DATA_AVAIL_BIT) && i < timeout; i++) - { + for (i = 0; (devpriv->status1_bits & DATA_AVAIL_BIT) && i < timeout; + i++) { // quit if we have all the data we want - if(async->cmd.stop_src == TRIG_COUNT) - { - if(devpriv->count == 0) break; + if (async->cmd.stop_src == TRIG_COUNT) { + if (devpriv->count == 0) + break; devpriv->count--; } lsb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG); msb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG); data = (msb << 8) | lsb; - cfc_write_to_buffer( dev->read_subdev, data ); - devpriv->status1_bits = devpriv->read_byte(dev->iobase + STATUS1_REG); + cfc_write_to_buffer(dev->read_subdev, data); + devpriv->status1_bits = + devpriv->read_byte(dev->iobase + STATUS1_REG); } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "ai timeout, fifo never empties"); async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; return -1; @@ -1444,7 +1431,7 @@ static int labpc_drain_fifo(comedi_device *dev) return 0; } -static void labpc_drain_dma(comedi_device *dev) +static void labpc_drain_dma(comedi_device * dev) { comedi_subdevice *s = dev->read_subdev; comedi_async *async = s->async; @@ -1458,39 +1445,36 @@ static void labpc_drain_dma(comedi_device *dev) flags = claim_dma_lock(); disable_dma(devpriv->dma_chan); /* clear flip-flop to make sure 2-byte registers for - * count and address get set correctly */ + * count and address get set correctly */ clear_dma_ff(devpriv->dma_chan); // figure out how many points to read - max_points = devpriv->dma_transfer_size / sample_size; + max_points = devpriv->dma_transfer_size / sample_size; /* residue is the number of points left to be done on the dma - * transfer. It should always be zero at this point unless - * the stop_src is set to external triggering. - */ + * transfer. It should always be zero at this point unless + * the stop_src is set to external triggering. + */ residue = get_dma_residue(devpriv->dma_chan) / sample_size; num_points = max_points - residue; - if(devpriv->count < num_points && - async->cmd.stop_src == TRIG_COUNT) + if (devpriv->count < num_points && async->cmd.stop_src == TRIG_COUNT) num_points = devpriv->count; // figure out how many points will be stored next time leftover = 0; - if(async->cmd.stop_src != TRIG_COUNT) - { + if (async->cmd.stop_src != TRIG_COUNT) { leftover = devpriv->dma_transfer_size / sample_size; - }else if(devpriv->count > num_points) - { + } else if (devpriv->count > num_points) { leftover = devpriv->count - num_points; - if(leftover > max_points) + if (leftover > max_points) leftover = max_points; } /* write data to comedi buffer */ - for( i = 0; i < num_points; i++) - { - cfc_write_to_buffer( s, devpriv->dma_buffer[i] ); + for (i = 0; i < num_points; i++) { + cfc_write_to_buffer(s, devpriv->dma_buffer[i]); } - if(async->cmd.stop_src == TRIG_COUNT) devpriv->count -= num_points; + if (async->cmd.stop_src == TRIG_COUNT) + devpriv->count -= num_points; // set address and count for next transfer set_dma_addr(devpriv->dma_chan, virt_to_bus(devpriv->dma_buffer)); @@ -1500,7 +1484,7 @@ static void labpc_drain_dma(comedi_device *dev) async->events |= COMEDI_CB_BLOCK; } -static void handle_isa_dma(comedi_device *dev) +static void handle_isa_dma(comedi_device * dev) { labpc_drain_dma(dev); @@ -1512,53 +1496,53 @@ static void handle_isa_dma(comedi_device *dev) /* makes sure all data aquired by board is transfered to comedi (used * when aquisition is terminated by stop_src == TRIG_EXT). */ -static void labpc_drain_dregs(comedi_device *dev) +static void labpc_drain_dregs(comedi_device * dev) { - if(devpriv->current_transfer == isa_dma_transfer) + if (devpriv->current_transfer == isa_dma_transfer) labpc_drain_dma(dev); labpc_drain_fifo(dev); } -static int labpc_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int labpc_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i, n; + int i, n; int chan, range; int lsb, msb; int timeout = 1000; unsigned long flags; // disable timed conversions - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT; devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // disable interrupt generation and dma devpriv->command3_bits = 0; devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); - /* set gain and channel */ + /* set gain and channel */ devpriv->command1_bits = 0; chan = CR_CHAN(insn->chanspec); range = CR_RANGE(insn->chanspec); devpriv->command1_bits |= thisboard->ai_range_code[range]; // munge channel bits for differential/scan disabled mode - if(CR_AREF(insn->chanspec) == AREF_DIFF) + if (CR_AREF(insn->chanspec) == AREF_DIFF) chan *= 2; devpriv->command1_bits |= ADC_CHAN_BITS(chan); devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG); // setup command6 register for 1200 boards - if(thisboard->register_layout == labpc_1200_layout) - { + if (thisboard->register_layout == labpc_1200_layout) { // reference inputs to ground or common? - if(CR_AREF(insn->chanspec) != AREF_GROUND) + if (CR_AREF(insn->chanspec) != AREF_GROUND) devpriv->command6_bits |= ADC_COMMON_BIT; else devpriv->command6_bits &= ~ADC_COMMON_BIT; // bipolar or unipolar range? - if(thisboard->ai_range_is_unipolar[range]) + if (thisboard->ai_range_is_unipolar[range]) devpriv->command6_bits |= ADC_UNIP_BIT; else devpriv->command6_bits &= ~ADC_UNIP_BIT; @@ -1567,35 +1551,33 @@ static int labpc_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * // don't enable interrupt on counter a1 terminal count? devpriv->command6_bits &= ~A1_INTR_EN_BIT; // write to register - devpriv->write_byte(devpriv->command6_bits, dev->iobase + COMMAND6_REG); + devpriv->write_byte(devpriv->command6_bits, + dev->iobase + COMMAND6_REG); } - // setup command4 register devpriv->command4_bits = 0; devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT; // single-ended/differential - if(CR_AREF(insn->chanspec) == AREF_DIFF) + if (CR_AREF(insn->chanspec) == AREF_DIFF) devpriv->command4_bits |= ADC_DIFF_BIT; devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG); // initialize pacer counter output to make sure it doesn't cause any problems devpriv->write_byte(INIT_A0_BITS, dev->iobase + COUNTER_A_CONTROL_REG); - labpc_clear_adc_fifo( dev ); + labpc_clear_adc_fifo(dev); - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { /* trigger conversion */ devpriv->write_byte(0x1, dev->iobase + ADC_CONVERT_REG); - for(i = 0; i < timeout; i++) - { - if(devpriv->read_byte(dev->iobase + STATUS1_REG) & DATA_AVAIL_BIT) + for (i = 0; i < timeout; i++) { + if (devpriv->read_byte(dev->iobase + + STATUS1_REG) & DATA_AVAIL_BIT) break; - comedi_udelay( 1 ); + comedi_udelay(1); } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "timeout"); return -ETIME; } @@ -1608,8 +1590,8 @@ static int labpc_ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn * } // analog output insn -static int labpc_ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int labpc_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel, range; unsigned long flags; @@ -1620,26 +1602,25 @@ static int labpc_ao_winsn(comedi_device *dev, comedi_subdevice *s, // turn off pacing of analog output channel /* note: hardware bug in daqcard-1200 means pacing cannot * be independently enabled/disabled for its the two channels */ - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); devpriv->command2_bits &= ~DAC_PACED_BIT(channel); devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG); - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); // set range - if(thisboard->register_layout == labpc_1200_layout) - { + if (thisboard->register_layout == labpc_1200_layout) { range = CR_RANGE(insn->chanspec); - if(range & AO_RANGE_IS_UNIPOLAR) + if (range & AO_RANGE_IS_UNIPOLAR) devpriv->command6_bits |= DAC_UNIP_BIT(channel); else devpriv->command6_bits &= ~DAC_UNIP_BIT(channel); // write to register - devpriv->write_byte(devpriv->command6_bits, dev->iobase + COMMAND6_REG); + devpriv->write_byte(devpriv->command6_bits, + dev->iobase + COMMAND6_REG); } - // send data lsb = data[0] & 0xff; - msb = (data[0] >> 8 ) & 0xff; + msb = (data[0] >> 8) & 0xff; devpriv->write_byte(lsb, dev->iobase + DAC_LSB_REG(channel)); devpriv->write_byte(msb, dev->iobase + DAC_MSB_REG(channel)); @@ -1650,50 +1631,54 @@ static int labpc_ao_winsn(comedi_device *dev, comedi_subdevice *s, } // analog output readback insn -static int labpc_ao_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int labpc_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->ao_value[CR_CHAN(insn->chanspec)]; return 1; } -static int labpc_calib_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int labpc_calib_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->caldac[CR_CHAN(insn->chanspec)]; return 1; } -static int labpc_calib_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int labpc_calib_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel = CR_CHAN(insn->chanspec); - write_caldac( dev, channel, data[ 0 ] ); + write_caldac(dev, channel, data[0]); return 1; } -static int labpc_eeprom_read_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int labpc_eeprom_read_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->eeprom_data[CR_CHAN(insn->chanspec)]; return 1; } -static int labpc_eeprom_write_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int labpc_eeprom_write_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int channel = CR_CHAN(insn->chanspec); int ret; // only allow writes to user area of eeprom - if(channel < 16 || channel > 127) - { + if (channel < 16 || channel > 127) { printk("eeprom writes are only allowed to channels 16 through 127 (the pointer and user areas)"); return -EINVAL; } ret = labpc_eeprom_write(dev, channel, data[0]); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 1; } @@ -1704,7 +1689,7 @@ static unsigned int labpc_suggest_transfer_size(comedi_cmd cmd) unsigned int size; unsigned int freq; - if(cmd.convert_src == TRIG_TIMER) + if (cmd.convert_src == TRIG_TIMER) freq = 1000000000 / cmd.convert_arg; // return some default value else @@ -1714,143 +1699,154 @@ static unsigned int labpc_suggest_transfer_size(comedi_cmd cmd) size = (freq / 3) * sample_size; // set a minimum and maximum size allowed - if(size > dma_buffer_size) + if (size > dma_buffer_size) size = dma_buffer_size - dma_buffer_size % sample_size; - else if(size < sample_size) + else if (size < sample_size) size = sample_size; return size; } // figures out what counter values to use based on command -static void labpc_adc_timing(comedi_device *dev, comedi_cmd *cmd) +static void labpc_adc_timing(comedi_device * dev, comedi_cmd * cmd) { - const int max_counter_value = 0x10000; // max value for 16 bit counter in mode 2 - const int min_counter_value = 2; // min value for 16 bit counter in mode 2 + const int max_counter_value = 0x10000; // max value for 16 bit counter in mode 2 + const int min_counter_value = 2; // min value for 16 bit counter in mode 2 unsigned int base_period; // if both convert and scan triggers are TRIG_TIMER, then they both rely on counter b0 - if( labpc_ai_convert_period( cmd ) && labpc_ai_scan_period( cmd ) ) - { + if (labpc_ai_convert_period(cmd) && labpc_ai_scan_period(cmd)) { // pick the lowest b0 divisor value we can (for maximum input clock speed on convert and scan counters) - devpriv->divisor_b0 = (labpc_ai_scan_period( cmd ) - 1) / + devpriv->divisor_b0 = (labpc_ai_scan_period(cmd) - 1) / (LABPC_TIMER_BASE * max_counter_value) + 1; - if(devpriv->divisor_b0 < min_counter_value) + if (devpriv->divisor_b0 < min_counter_value) devpriv->divisor_b0 = min_counter_value; - if(devpriv->divisor_b0 > max_counter_value) + if (devpriv->divisor_b0 > max_counter_value) devpriv->divisor_b0 = max_counter_value; base_period = LABPC_TIMER_BASE * devpriv->divisor_b0; // set a0 for conversion frequency and b1 for scan frequency - switch(cmd->flags & TRIG_ROUND_MASK) - { - default: - case TRIG_ROUND_NEAREST: - devpriv->divisor_a0 = (labpc_ai_convert_period( cmd ) + (base_period / 2)) / base_period; - devpriv->divisor_b1 = (labpc_ai_scan_period( cmd ) + (base_period / 2)) / base_period; - break; - case TRIG_ROUND_UP: - devpriv->divisor_a0 = (labpc_ai_convert_period( cmd ) + (base_period - 1)) / base_period; - devpriv->divisor_b1 = (labpc_ai_scan_period( cmd ) + (base_period - 1)) / base_period; - break; - case TRIG_ROUND_DOWN: - devpriv->divisor_a0 = labpc_ai_convert_period( cmd ) / base_period; - devpriv->divisor_b1 = labpc_ai_scan_period( cmd ) / base_period; - break; + switch (cmd->flags & TRIG_ROUND_MASK) { + default: + case TRIG_ROUND_NEAREST: + devpriv->divisor_a0 = + (labpc_ai_convert_period(cmd) + + (base_period / 2)) / base_period; + devpriv->divisor_b1 = + (labpc_ai_scan_period(cmd) + + (base_period / 2)) / base_period; + break; + case TRIG_ROUND_UP: + devpriv->divisor_a0 = + (labpc_ai_convert_period(cmd) + (base_period - + 1)) / base_period; + devpriv->divisor_b1 = + (labpc_ai_scan_period(cmd) + (base_period - + 1)) / base_period; + break; + case TRIG_ROUND_DOWN: + devpriv->divisor_a0 = + labpc_ai_convert_period(cmd) / base_period; + devpriv->divisor_b1 = + labpc_ai_scan_period(cmd) / base_period; + break; } // make sure a0 and b1 values are acceptable - if(devpriv->divisor_a0 < min_counter_value) + if (devpriv->divisor_a0 < min_counter_value) devpriv->divisor_a0 = min_counter_value; - if(devpriv->divisor_a0 > max_counter_value) + if (devpriv->divisor_a0 > max_counter_value) devpriv->divisor_a0 = max_counter_value; - if(devpriv->divisor_b1 < min_counter_value) + if (devpriv->divisor_b1 < min_counter_value) devpriv->divisor_b1 = min_counter_value; - if(devpriv->divisor_b1 > max_counter_value) + if (devpriv->divisor_b1 > max_counter_value) devpriv->divisor_b1 = max_counter_value; // write corrected timings to command - labpc_set_ai_convert_period( cmd, base_period * devpriv->divisor_a0 ); - labpc_set_ai_scan_period( cmd, base_period * devpriv->divisor_b1 ); - // if only one TRIG_TIMER is used, we can employ the generic cascaded timing functions - }else if( labpc_ai_scan_period( cmd ) ) - { + labpc_set_ai_convert_period(cmd, + base_period * devpriv->divisor_a0); + labpc_set_ai_scan_period(cmd, + base_period * devpriv->divisor_b1); + // if only one TRIG_TIMER is used, we can employ the generic cascaded timing functions + } else if (labpc_ai_scan_period(cmd)) { unsigned int scan_period; - scan_period = labpc_ai_scan_period( cmd ); + scan_period = labpc_ai_scan_period(cmd); /* calculate cascaded counter values that give desired scan timing */ - i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE, &(devpriv->divisor_b1), &(devpriv->divisor_b0), + i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE, + &(devpriv->divisor_b1), &(devpriv->divisor_b0), &scan_period, cmd->flags & TRIG_ROUND_MASK); - labpc_set_ai_scan_period( cmd, scan_period ); - }else if( labpc_ai_convert_period( cmd ) ) - { + labpc_set_ai_scan_period(cmd, scan_period); + } else if (labpc_ai_convert_period(cmd)) { unsigned int convert_period; - convert_period = labpc_ai_convert_period( cmd ); + convert_period = labpc_ai_convert_period(cmd); /* calculate cascaded counter values that give desired conversion timing */ - i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE, &(devpriv->divisor_a0), &(devpriv->divisor_b0), + i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE, + &(devpriv->divisor_a0), &(devpriv->divisor_b0), &convert_period, cmd->flags & TRIG_ROUND_MASK); - labpc_set_ai_convert_period( cmd, convert_period ); + labpc_set_ai_convert_period(cmd, convert_period); } } - -static int labpc_dio_mem_callback(int dir, int port, int data, unsigned long iobase) +static int labpc_dio_mem_callback(int dir, int port, int data, + unsigned long iobase) { - if(dir) - { - writeb(data, (void*) (iobase + port)); + if (dir) { + writeb(data, (void *)(iobase + port)); return 0; - }else - { - return readb((void*)(iobase + port)); + } else { + return readb((void *)(iobase + port)); } } // lowlevel write to eeprom/dac -static void labpc_serial_out(comedi_device *dev, unsigned int value, unsigned int value_width) +static void labpc_serial_out(comedi_device * dev, unsigned int value, + unsigned int value_width) { int i; - for(i = 1; i <= value_width; i++) - { + for (i = 1; i <= value_width; i++) { // clear serial clock devpriv->command5_bits &= ~SCLOCK_BIT; // send bits most significant bit first - if(value & (1 << (value_width - i))) + if (value & (1 << (value_width - i))) devpriv->command5_bits |= SDATA_BIT; else devpriv->command5_bits &= ~SDATA_BIT; comedi_udelay(1); - devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); + devpriv->write_byte(devpriv->command5_bits, + dev->iobase + COMMAND5_REG); // set clock to load bit devpriv->command5_bits |= SCLOCK_BIT; comedi_udelay(1); - devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); + devpriv->write_byte(devpriv->command5_bits, + dev->iobase + COMMAND5_REG); } } // lowlevel read from eeprom -static unsigned int labpc_serial_in(comedi_device *dev) +static unsigned int labpc_serial_in(comedi_device * dev) { unsigned int value = 0; int i; const int value_width = 8; // number of bits wide values are - for(i = 1; i <= value_width; i++) - { + for (i = 1; i <= value_width; i++) { // set serial clock devpriv->command5_bits |= SCLOCK_BIT; comedi_udelay(1); - devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); + devpriv->write_byte(devpriv->command5_bits, + dev->iobase + COMMAND5_REG); // clear clock bit devpriv->command5_bits &= ~SCLOCK_BIT; comedi_udelay(1); - devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); + devpriv->write_byte(devpriv->command5_bits, + dev->iobase + COMMAND5_REG); // read bits most significant bit first comedi_udelay(1); - devpriv->status2_bits = devpriv->read_byte(dev->iobase + STATUS2_REG); - if(devpriv->status2_bits & EEPROM_OUT_BIT) - { + devpriv->status2_bits = + devpriv->read_byte(dev->iobase + STATUS2_REG); + if (devpriv->status2_bits & EEPROM_OUT_BIT) { value |= 1 << (value_width - i); } } @@ -1858,7 +1854,7 @@ static unsigned int labpc_serial_in(comedi_device *dev) return value; } -static unsigned int labpc_eeprom_read(comedi_device *dev, unsigned int address) +static unsigned int labpc_eeprom_read(comedi_device * dev, unsigned int address) { unsigned int value; const int read_instruction = 0x3; // bits to tell eeprom to expect a read @@ -1887,7 +1883,8 @@ static unsigned int labpc_eeprom_read(comedi_device *dev, unsigned int address) return value; } -static unsigned int labpc_eeprom_write(comedi_device *dev, unsigned int address, unsigned int value) +static unsigned int labpc_eeprom_write(comedi_device * dev, + unsigned int address, unsigned int value) { const int write_enable_instruction = 0x6; const int write_instruction = 0x2; @@ -1897,17 +1894,15 @@ static unsigned int labpc_eeprom_write(comedi_device *dev, unsigned int address, int i; // make sure there isn't already a write in progress - for(i = 0; i < timeout; i++) - { - if((labpc_eeprom_read_status(dev) & write_in_progress_bit) == 0) + for (i = 0; i < timeout; i++) { + if ((labpc_eeprom_read_status(dev) & write_in_progress_bit) == + 0) break; } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "eeprom write timed out"); return -ETIME; } - // update software copy of eeprom devpriv->eeprom_data[address] = value; @@ -1925,7 +1920,6 @@ static unsigned int labpc_eeprom_write(comedi_device *dev, unsigned int address, comedi_udelay(1); devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); - // send write instruction devpriv->command5_bits |= EEPROM_EN_BIT; comedi_udelay(1); @@ -1947,7 +1941,7 @@ static unsigned int labpc_eeprom_write(comedi_device *dev, unsigned int address, return 0; } -static unsigned int labpc_eeprom_read_status(comedi_device *dev) +static unsigned int labpc_eeprom_read_status(comedi_device * dev) { unsigned int value; const int read_status_instruction = 0x5; @@ -1975,13 +1969,16 @@ static unsigned int labpc_eeprom_read_status(comedi_device *dev) } // writes to 8 bit calibration dacs -static void write_caldac(comedi_device *dev, unsigned int channel, unsigned int value) +static void write_caldac(comedi_device * dev, unsigned int channel, + unsigned int value) { - if( value == devpriv->caldac[ channel ] ) return; - devpriv->caldac[ channel ] = value; + if (value == devpriv->caldac[channel]) + return; + devpriv->caldac[channel] = value; // clear caldac load bit and make sure we don't write to eeprom - devpriv->command5_bits &= ~CALDAC_LOAD_BIT & ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT; + devpriv->command5_bits &= + ~CALDAC_LOAD_BIT & ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT; comedi_udelay(1); devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG); @@ -2001,7 +1998,6 @@ static void write_caldac(comedi_device *dev, unsigned int channel, unsigned int COMEDI_INITCLEANUP(driver_labpc); -EXPORT_SYMBOL_GPL( labpc_common_attach ); -EXPORT_SYMBOL_GPL( labpc_common_detach ); -EXPORT_SYMBOL_GPL( labpc_cs_boards ); - +EXPORT_SYMBOL_GPL(labpc_common_attach); +EXPORT_SYMBOL_GPL(labpc_common_detach); +EXPORT_SYMBOL_GPL(labpc_cs_boards); diff --git a/comedi/drivers/ni_labpc.h b/comedi/drivers/ni_labpc.h index 7c7aa9cf..6eabe5cb 100644 --- a/comedi/drivers/ni_labpc.h +++ b/comedi/drivers/ni_labpc.h @@ -27,27 +27,28 @@ #define EEPROM_SIZE 256 // 256 byte eeprom #define NUM_AO_CHAN 2 // boards have two analog output channels -enum labpc_bustype {isa_bustype, pci_bustype, pcmcia_bustype}; -enum labpc_register_layout {labpc_plus_layout, labpc_1200_layout}; -enum transfer_type {fifo_not_empty_transfer, fifo_half_full_transfer, isa_dma_transfer}; +enum labpc_bustype { isa_bustype, pci_bustype, pcmcia_bustype }; +enum labpc_register_layout { labpc_plus_layout, labpc_1200_layout }; +enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer, + isa_dma_transfer }; -typedef struct labpc_board_struct{ +typedef struct labpc_board_struct { const char *name; - int device_id; // device id for pci and pcmcia boards - int ai_speed; // maximum input speed in nanoseconds + int device_id; // device id for pci and pcmcia boards + int ai_speed; // maximum input speed in nanoseconds enum labpc_bustype bustype; // ISA/PCI/etc. enum labpc_register_layout register_layout; // 1200 has extra registers compared to pc+ - int has_ao; // has analog output true/false + int has_ao; // has analog output true/false const comedi_lrange *ai_range_table; const int *ai_range_code; const int *ai_range_is_unipolar; - unsigned ai_scan_up : 1; // board can auto scan up in ai channels, not just down - unsigned memory_mapped_io : 1; /* uses memory mapped io instead of ioports */ -}labpc_board; + unsigned ai_scan_up:1; // board can auto scan up in ai channels, not just down + unsigned memory_mapped_io:1; /* uses memory mapped io instead of ioports */ +} labpc_board; -typedef struct{ +typedef struct { struct mite_struct *mite; // for mite chip on pci-1200 - volatile unsigned long long count; /* number of data points left to be taken */ + volatile unsigned long long count; /* number of data points left to be taken */ unsigned int ao_value[NUM_AO_CHAN]; // software copy of analog output values // software copys of bits written to command registers volatile unsigned int command1_bits; @@ -60,8 +61,8 @@ typedef struct{ volatile unsigned int status1_bits; volatile unsigned int status2_bits; unsigned int divisor_a0; /* value to load into board's counter a0 (conversion pacing) for timed conversions */ - unsigned int divisor_b0; /* value to load into board's counter b0 (master) for timed conversions */ - unsigned int divisor_b1; /* value to load into board's counter b1 (scan pacing) for timed conversions */ + unsigned int divisor_b0; /* value to load into board's counter b0 (master) for timed conversions */ + unsigned int divisor_b1; /* value to load into board's counter b1 (scan pacing) for timed conversions */ unsigned int dma_chan; // dma channel to use u16 *dma_buffer; // buffer ai will dma into unsigned int dma_transfer_size; // transfer size in bytes for current transfer @@ -69,16 +70,15 @@ typedef struct{ unsigned int eeprom_data[EEPROM_SIZE]; // stores contents of board's eeprom unsigned int caldac[16]; // stores settings of calibration dacs // function pointers so we can use inb/outb or readb/writeb as appropriate - unsigned int (*read_byte)(unsigned long address); - void (*write_byte)(unsigned int byte, unsigned long address); -}labpc_private; + unsigned int (*read_byte) (unsigned long address); + void (*write_byte) (unsigned int byte, unsigned long address); +} labpc_private; #define NUM_LABPC_CS_BOARDS 2 extern const labpc_board labpc_cs_boards[NUM_LABPC_CS_BOARDS]; -int labpc_common_attach( comedi_device *dev, unsigned long iobase, - unsigned int irq, unsigned int dma ); -int labpc_common_detach( comedi_device *dev ); +int labpc_common_attach(comedi_device * dev, unsigned long iobase, + unsigned int irq, unsigned int dma); +int labpc_common_detach(comedi_device * dev); - -#endif /* _NI_LABPC_H */ +#endif /* _NI_LABPC_H */ diff --git a/comedi/drivers/ni_labpc_cs.c b/comedi/drivers/ni_labpc_cs.c index 7f24ed75..e75e916f 100644 --- a/comedi/drivers/ni_labpc_cs.c +++ b/comedi/drivers/ni_labpc_cs.c @@ -60,7 +60,7 @@ NI manuals: */ #undef LABPC_DEBUG -//#define LABPC_DEBUG // enable debugging messages +//#define LABPC_DEBUG // enable debugging messages #include @@ -80,15 +80,14 @@ NI manuals: static struct pcmcia_device *pcmcia_cur_dev = NULL; -static int labpc_attach(comedi_device *dev,comedi_devconfig *it); +static int labpc_attach(comedi_device * dev, comedi_devconfig * it); /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const labpc_board *)dev->board_ptr) -static comedi_driver driver_labpc_cs = -{ +static comedi_driver driver_labpc_cs = { .driver_name = "ni_labpc_cs", .module = THIS_MODULE, .attach = &labpc_attach, @@ -98,31 +97,31 @@ static comedi_driver driver_labpc_cs = .offset = sizeof(labpc_board), }; -static int labpc_attach(comedi_device *dev, comedi_devconfig *it) +static int labpc_attach(comedi_device * dev, comedi_devconfig * it) { unsigned long iobase = 0; unsigned int irq = 0; struct pcmcia_device *link; /* allocate and initialize dev->private */ - if(alloc_private(dev, sizeof(labpc_private)) < 0) + if (alloc_private(dev, sizeof(labpc_private)) < 0) return -ENOMEM; // get base address, irq etc. based on bustype - switch(thisboard->bustype) - { - case pcmcia_bustype: - link = pcmcia_cur_dev; /* XXX hack */ - if(!link) return -EIO; - iobase = link->io.BasePort1; - irq = link->irq.AssignedIRQ; - break; - default: - printk("bug! couldn't determine board type\n");\ - return -EINVAL; - break; + switch (thisboard->bustype) { + case pcmcia_bustype: + link = pcmcia_cur_dev; /* XXX hack */ + if (!link) + return -EIO; + iobase = link->io.BasePort1; + irq = link->irq.AssignedIRQ; + break; + default: + printk("bug! couldn't determine board type\n"); + return -EINVAL; + break; } - return labpc_common_attach( dev, iobase, irq, 0 ); + return labpc_common_attach(dev, iobase, irq, 0); } /* @@ -137,7 +136,7 @@ static int pc_debug = PCMCIA_DEBUG; module_param(pc_debug, int, 0644); #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) static const char *version = -"ni_labpc.c, based on dummy_cs.c 1.31 2001/08/24 12:13:13"; + "ni_labpc.c, based on dummy_cs.c 1.31 2001/08/24 12:13:13"; #else #define DEBUG(n, args...) #endif @@ -192,7 +191,6 @@ typedef struct local_info_t { struct bus_operations *bus; } local_info_t; - /*====================================================================== labpc_cs_attach() creates an "instance" of the driver, allocating @@ -207,36 +205,38 @@ typedef struct local_info_t { static int labpc_cs_attach(struct pcmcia_device *link) { - local_info_t *local; + local_info_t *local; - DEBUG(0, "labpc_cs_attach()\n"); + DEBUG(0, "labpc_cs_attach()\n"); - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return -ENOMEM; - local->link = link; link->priv = local; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; + local->link = link; + link->priv = local; - /* Interrupt setup */ - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_FORCED_PULSE; - link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_PULSE_ID; - link->irq.Handler = NULL; + /* Interrupt setup */ + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_FORCED_PULSE; + link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_PULSE_ID; + 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.IntType = INT_MEMORY_AND_IO; + /* + 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.IntType = INT_MEMORY_AND_IO; - pcmcia_cur_dev = link; + pcmcia_cur_dev = link; - labpc_config(link); + labpc_config(link); - return 0; -} /* labpc_cs_attach */ + return 0; +} /* labpc_cs_attach */ /*====================================================================== @@ -249,24 +249,24 @@ static int labpc_cs_attach(struct pcmcia_device *link) static void labpc_cs_detach(struct pcmcia_device *link) { - DEBUG(0, "labpc_cs_detach(0x%p)\n", link); - - /* - If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ - if(link->dev_node) { - ((local_info_t *)link->priv)->stop = 1; + DEBUG(0, "labpc_cs_detach(0x%p)\n", link); + + /* + If the device is currently configured and active, we won't + actually delete it yet. Instead, it is marked so that when + the release() function is called, that will trigger a proper + detach(). + */ + if (link->dev_node) { + ((local_info_t *) link->priv)->stop = 1; labpc_release(link); - } + } - /* This points to the parent local_info_t struct */ - if(link->priv) + /* This points to the parent local_info_t struct */ + if (link->priv) kfree(link->priv); -} /* labpc_cs_detach */ +} /* labpc_cs_detach */ /*====================================================================== @@ -276,187 +276,187 @@ static void labpc_cs_detach(struct pcmcia_device *link) ======================================================================*/ - static void labpc_config(struct pcmcia_device *link) { - local_info_t *dev = link->priv; - tuple_t tuple; - cisparse_t parse; - int last_ret; - u_char buf[64]; - win_req_t req; - memreq_t map; - cistpl_cftable_entry_t dflt = { 0 }; - - DEBUG(0, "labpc_config(0x%p)\n", link); - - /* - This reads the card's CONFIG tuple to find its configuration - registers. - */ - tuple.DesiredTuple = CISTPL_CONFIG; - tuple.Attributes = 0; - tuple.TupleData = buf; - tuple.TupleDataMax = sizeof(buf); - tuple.TupleOffset = 0; - if((last_ret = pcmcia_get_first_tuple(link, &tuple))) - { + local_info_t *dev = link->priv; + tuple_t tuple; + cisparse_t parse; + int last_ret; + u_char buf[64]; + win_req_t req; + memreq_t map; + cistpl_cftable_entry_t dflt = { 0 }; + + DEBUG(0, "labpc_config(0x%p)\n", link); + + /* + This reads the card's CONFIG tuple to find its configuration + registers. + */ + tuple.DesiredTuple = CISTPL_CONFIG; + tuple.Attributes = 0; + tuple.TupleData = buf; + tuple.TupleDataMax = sizeof(buf); + tuple.TupleOffset = 0; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple))) { cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - if((last_ret = pcmcia_get_tuple_data(link, &tuple))) - { + if ((last_ret = pcmcia_get_tuple_data(link, &tuple))) { cs_error(link, GetTupleData, last_ret); goto cs_failed; } - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse))) - { + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse))) { cs_error(link, ParseTuple, last_ret); goto cs_failed; } - link->conf.ConfigBase = parse.config.base; - link->conf.Present = parse.config.rmask[0]; - - /* - In this loop, we scan the CIS for configuration table entries, - each of which describes a valid card configuration, including - voltage, IO window, memory window, and interrupt settings. - - We make no assumptions about the card to be configured: we use - just the information available in the CIS. In an ideal world, - this would work for any PCMCIA card, but it requires a complete - and accurate CIS. In practice, a driver usually "knows" most of - these things without consulting the CIS, and most client drivers - will only use the CIS to fill in implementation-defined details. - */ - tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; - if((last_ret = pcmcia_get_first_tuple(link, &tuple))) - { + link->conf.ConfigBase = parse.config.base; + link->conf.Present = parse.config.rmask[0]; + + /* + In this loop, we scan the CIS for configuration table entries, + each of which describes a valid card configuration, including + voltage, IO window, memory window, and interrupt settings. + + We make no assumptions about the card to be configured: we use + just the information available in the CIS. In an ideal world, + this would work for any PCMCIA card, but it requires a complete + and accurate CIS. In practice, a driver usually "knows" most of + these things without consulting the CIS, and most client drivers + will only use the CIS to fill in implementation-defined details. + */ + tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple))) { cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - while (1) { - cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); - if(pcmcia_get_tuple_data(link, &tuple)) goto next_entry; - if(pcmcia_parse_tuple(link, &tuple, &parse)) goto next_entry; - - if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; - if (cfg->index == 0) goto next_entry; - link->conf.ConfigIndex = cfg->index; - - /* Does this card need audio output? */ - if (cfg->flags & CISTPL_CFTABLE_AUDIO) { - link->conf.Attributes |= CONF_ENABLE_SPKR; - link->conf.Status = CCSR_AUDIO_ENA; - } + while (1) { + cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); + if (pcmcia_get_tuple_data(link, &tuple)) + goto next_entry; + if (pcmcia_parse_tuple(link, &tuple, &parse)) + goto next_entry; + + if (cfg->flags & CISTPL_CFTABLE_DEFAULT) + dflt = *cfg; + if (cfg->index == 0) + goto next_entry; + link->conf.ConfigIndex = cfg->index; + + /* Does this card need audio output? */ + if (cfg->flags & CISTPL_CFTABLE_AUDIO) { + link->conf.Attributes |= CONF_ENABLE_SPKR; + link->conf.Status = CCSR_AUDIO_ENA; + } - /* Do we need to allocate an interrupt? */ - if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) - link->conf.Attributes |= CONF_ENABLE_IRQ; - - /* IO window settings */ - link->io.NumPorts1 = link->io.NumPorts2 = 0; - if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { - cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; - link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; - link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; - link->io.BasePort1 = io->win[0].base; - link->io.NumPorts1 = io->win[0].len; - if (io->nwin > 1) { - link->io.Attributes2 = link->io.Attributes1; - link->io.BasePort2 = io->win[1].base; - link->io.NumPorts2 = io->win[1].len; - } - /* This reserves IO space but doesn't actually enable it */ - if(pcmcia_request_io(link, &link->io)) goto next_entry; - } + /* Do we need to allocate an interrupt? */ + if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) + link->conf.Attributes |= CONF_ENABLE_IRQ; + + /* IO window settings */ + link->io.NumPorts1 = link->io.NumPorts2 = 0; + if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { + cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; + link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; + link->io.BasePort1 = io->win[0].base; + link->io.NumPorts1 = io->win[0].len; + if (io->nwin > 1) { + link->io.Attributes2 = link->io.Attributes1; + link->io.BasePort2 = io->win[1].base; + link->io.NumPorts2 = io->win[1].len; + } + /* This reserves IO space but doesn't actually enable it */ + if (pcmcia_request_io(link, &link->io)) + goto next_entry; + } - if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { - cistpl_mem_t *mem = - (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; - req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM; - req.Attributes |= WIN_ENABLE; - req.Base = mem->win[0].host_addr; - req.Size = mem->win[0].len; - if (req.Size < 0x1000) - req.Size = 0x1000; - req.AccessSpeed = 0; - link->win = (window_handle_t)link; - if(pcmcia_request_window(&link, &req, &link->win)) goto next_entry; - map.Page = 0; map.CardOffset = mem->win[0].card_addr; - if(pcmcia_map_mem_page(link->win, &map)) goto next_entry; - } - /* If we got this far, we're cool! */ - break; + if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { + cistpl_mem_t *mem = + (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; + req.Attributes = WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM; + req.Attributes |= WIN_ENABLE; + req.Base = mem->win[0].host_addr; + req.Size = mem->win[0].len; + if (req.Size < 0x1000) + req.Size = 0x1000; + req.AccessSpeed = 0; + link->win = (window_handle_t) link; + if (pcmcia_request_window(&link, &req, &link->win)) + goto next_entry; + map.Page = 0; + map.CardOffset = mem->win[0].card_addr; + if (pcmcia_map_mem_page(link->win, &map)) + goto next_entry; + } + /* If we got this far, we're cool! */ + break; - next_entry: - if((last_ret = pcmcia_get_next_tuple(link, &tuple))) - { - cs_error(link, GetNextTuple, last_ret); - goto cs_failed; + next_entry: + if ((last_ret = pcmcia_get_next_tuple(link, &tuple))) { + cs_error(link, GetNextTuple, last_ret); + goto cs_failed; + } } - } - - /* - Allocate an interrupt line. Note that this does not assign a - handler to the interrupt, unless the 'Handler' member of the - irq structure is initialized. - */ - if (link->conf.Attributes & CONF_ENABLE_IRQ) - if((last_ret = pcmcia_request_irq(link, &link->irq))) - { + + /* + Allocate an interrupt line. Note that this does not assign a + handler to the interrupt, unless the 'Handler' member of the + irq structure is initialized. + */ + if (link->conf.Attributes & CONF_ENABLE_IRQ) + if ((last_ret = pcmcia_request_irq(link, &link->irq))) { cs_error(link, RequestIRQ, last_ret); goto cs_failed; } - /* - This actually configures the PCMCIA socket -- setting up - the I/O windows and the interrupt mapping, and putting the - card and host interface into "Memory and IO" mode. - */ - if((last_ret = pcmcia_request_configuration(link, &link->conf))) - { + /* + This actually configures the PCMCIA socket -- setting up + the I/O windows and the interrupt mapping, and putting the + card and host interface into "Memory and IO" mode. + */ + if ((last_ret = pcmcia_request_configuration(link, &link->conf))) { cs_error(link, RequestConfiguration, last_ret); goto cs_failed; } - /* - At this point, the dev_node_t structure(s) need to be - initialized and arranged in a linked list at link->dev. - */ - sprintf(dev->node.dev_name, "daqcard-1200"); - dev->node.major = dev->node.minor = 0; - link->dev_node = &dev->node; - - /* Finally, report what we've done */ - printk(KERN_INFO "%s: index 0x%02x", - dev->node.dev_name, link->conf.ConfigIndex); - if (link->conf.Attributes & CONF_ENABLE_IRQ) + /* + At this point, the dev_node_t structure(s) need to be + initialized and arranged in a linked list at link->dev. + */ + sprintf(dev->node.dev_name, "daqcard-1200"); + dev->node.major = dev->node.minor = 0; + link->dev_node = &dev->node; + + /* Finally, report what we've done */ + printk(KERN_INFO "%s: index 0x%02x", + dev->node.dev_name, link->conf.ConfigIndex); + if (link->conf.Attributes & CONF_ENABLE_IRQ) printk(", irq %d", link->irq.AssignedIRQ); - if (link->io.NumPorts1) + if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, - link->io.BasePort1+link->io.NumPorts1-1); - if (link->io.NumPorts2) - printk(" & 0x%04x-0x%04x", link->io.BasePort2, - link->io.BasePort2+link->io.NumPorts2-1); - if (link->win) - printk(", mem 0x%06lx-0x%06lx", req.Base, - req.Base+req.Size-1); - printk("\n"); + link->io.BasePort1 + link->io.NumPorts1 - 1); + if (link->io.NumPorts2) + printk(" & 0x%04x-0x%04x", link->io.BasePort2, + link->io.BasePort2 + link->io.NumPorts2 - 1); + if (link->win) + printk(", mem 0x%06lx-0x%06lx", req.Base, + req.Base + req.Size - 1); + printk("\n"); - return; + return; -cs_failed: - labpc_release(link); + cs_failed: + labpc_release(link); -} /* labpc_config */ +} /* labpc_config */ static void labpc_release(struct pcmcia_device *link) { DEBUG(0, "labpc_release(0x%p)\n", link); pcmcia_disable_device(link); -} /* labpc_release */ +} /* labpc_release */ /*====================================================================== @@ -477,7 +477,7 @@ static int labpc_cs_suspend(struct pcmcia_device *link) /* Mark the device as stopped, to block IO until later */ local->stop = 1; return 0; -} /* labpc_cs_suspend */ +} /* labpc_cs_suspend */ static int labpc_cs_resume(struct pcmcia_device *link) { @@ -485,21 +485,19 @@ static int labpc_cs_resume(struct pcmcia_device *link) local->stop = 0; return 0; -} /* labpc_cs_resume */ +} /* labpc_cs_resume */ /*====================================================================*/ -static struct pcmcia_device_id labpc_cs_ids[] = -{ +static struct pcmcia_device_id labpc_cs_ids[] = { /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */ - PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ + PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ PCMCIA_DEVICE_NULL }; MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids); -struct pcmcia_driver labpc_cs_driver = -{ +struct pcmcia_driver labpc_cs_driver = { .probe = labpc_cs_attach, .remove = labpc_cs_detach, .suspend = labpc_cs_suspend, @@ -507,20 +505,20 @@ struct pcmcia_driver labpc_cs_driver = .id_table = labpc_cs_ids, .owner = THIS_MODULE, .drv = { - .name = dev_info, - }, + .name = dev_info, + }, }; static int __init init_labpc_cs(void) { - DEBUG(0, "%s\n", version); + DEBUG(0, "%s\n", version); pcmcia_register_driver(&labpc_cs_driver); - return 0; + return 0; } static void __exit exit_labpc_cs(void) { - DEBUG(0, "ni_labpc: unloading\n"); + DEBUG(0, "ni_labpc: unloading\n"); pcmcia_unregister_driver(&labpc_cs_driver); } @@ -529,7 +527,7 @@ int __init labpc_init_module(void) int ret; ret = init_labpc_cs(); - if(ret < 0) + if (ret < 0) return ret; return comedi_driver_register(&driver_labpc_cs); @@ -542,6 +540,5 @@ void __exit labpc_exit_module(void) } MODULE_LICENSE("GPL"); -module_init( labpc_init_module ); -module_exit( labpc_exit_module ); - +module_init(labpc_init_module); +module_exit(labpc_exit_module); diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index 6657cc79..2276ffe6 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -74,113 +74,122 @@ static const unsigned old_RTSI_clock_channel = 7; /* Note: this table must match the ai_gain_* definitions */ -static const short ni_gainlkup[][16]={ +static const short ni_gainlkup[][16] = { /* ai_gain_16 */ - { 0, 1, 2, 3, 4, 5, 6, 7, 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, - 0x106, 0x107 }, + {0, 1, 2, 3, 4, 5, 6, 7, 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, + 0x106, 0x107}, /* ai_gain_8 */ - { 1, 2, 4, 7, 0x101, 0x102, 0x104, 0x107 }, + {1, 2, 4, 7, 0x101, 0x102, 0x104, 0x107}, /* ai_gain_14 */ - { 1, 2, 3, 4, 5, 6, 7, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, - 0x107 }, + {1, 2, 3, 4, 5, 6, 7, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, + 0x107}, /* ai_gain_4 */ - { 0, 1, 4, 7 }, + {0, 1, 4, 7}, /* ai_gain_611x */ - { 0x00a, 0x00b, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006 }, + {0x00a, 0x00b, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006}, /* ai_gain_622x */ - { 0, 1, 4, 5}, + {0, 1, 4, 5}, /* ai_gain_628x */ - { 1, 2, 3, 4, 5, 6, 7}, + {1, 2, 3, 4, 5, 6, 7}, /* ai_gain_6143 */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }; -static const comedi_lrange range_ni_E_ai={ 16, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2.5, 2.5 ), - RANGE( -1, 1 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.25, 0.25 ), - RANGE( -0.1, 0.1 ), - RANGE( -0.05, 0.05 ), - RANGE( 0, 20 ), - RANGE( 0, 10 ), - RANGE( 0, 5 ), - RANGE( 0, 2 ), - RANGE( 0, 1 ), - RANGE( 0, 0.5 ), - RANGE( 0, 0.2 ), - RANGE( 0, 0.1 ), -}}; -static const comedi_lrange range_ni_E_ai_limited={ 8, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -1, 1 ), - RANGE( -0.1, 0.1 ), - RANGE( 0, 10 ), - RANGE( 0, 5 ), - RANGE( 0, 1 ), - RANGE( 0, 0.1 ), -}}; -static const comedi_lrange range_ni_E_ai_limited14={ 14, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2, 2 ), - RANGE( -1, 1 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.2, 0.2 ), - RANGE( -0.1, 0.1 ), - RANGE( 0, 10 ), - RANGE( 0, 5 ), - RANGE( 0, 2 ), - RANGE( 0, 1 ), - RANGE( 0, 0.5 ), - RANGE( 0, 0.2 ), - RANGE( 0, 0.1 ), -}}; -static const comedi_lrange range_ni_E_ai_bipolar4={ 4, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.05, 0.05 ), -}}; -static const comedi_lrange range_ni_E_ai_611x={ 8, { - RANGE( -50, 50 ), - RANGE( -20, 20 ), - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2, 2 ), - RANGE( -1, 1 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.2, 0.2 ), -}}; -static const comedi_lrange range_ni_M_ai_622x={ 4, { - RANGE(-10, 10), - RANGE(-5, 5), - RANGE(-1, 1), - RANGE(-0.2, 0.2), -}}; -static const comedi_lrange range_ni_M_ai_628x={ 7, { - RANGE( -10, 10 ), - RANGE( -5, 5 ), - RANGE( -2, 2 ), - RANGE( -1, 1 ), - RANGE( -0.5, 0.5 ), - RANGE( -0.2, 0.2 ), - RANGE( -0.1, 0.1 ), -}}; +static const comedi_lrange range_ni_E_ai = { 16, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2.5, 2.5), + RANGE(-1, 1), + RANGE(-0.5, 0.5), + RANGE(-0.25, 0.25), + RANGE(-0.1, 0.1), + RANGE(-0.05, 0.05), + RANGE(0, 20), + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2), + RANGE(0, 1), + RANGE(0, 0.5), + RANGE(0, 0.2), + RANGE(0, 0.1), + } +}; +static const comedi_lrange range_ni_E_ai_limited = { 8, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-1, 1), + RANGE(-0.1, 0.1), + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 1), + RANGE(0, 0.1), + } +}; +static const comedi_lrange range_ni_E_ai_limited14 = { 14, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2, 2), + RANGE(-1, 1), + RANGE(-0.5, 0.5), + RANGE(-0.2, 0.2), + RANGE(-0.1, 0.1), + RANGE(0, 10), + RANGE(0, 5), + RANGE(0, 2), + RANGE(0, 1), + RANGE(0, 0.5), + RANGE(0, 0.2), + RANGE(0, 0.1), + } +}; +static const comedi_lrange range_ni_E_ai_bipolar4 = { 4, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-0.5, 0.5), + RANGE(-0.05, 0.05), + } +}; +static const comedi_lrange range_ni_E_ai_611x = { 8, { + RANGE(-50, 50), + RANGE(-20, 20), + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2, 2), + RANGE(-1, 1), + RANGE(-0.5, 0.5), + RANGE(-0.2, 0.2), + } +}; +static const comedi_lrange range_ni_M_ai_622x = { 4, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-1, 1), + RANGE(-0.2, 0.2), + } +}; +static const comedi_lrange range_ni_M_ai_628x = { 7, { + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2, 2), + RANGE(-1, 1), + RANGE(-0.5, 0.5), + RANGE(-0.2, 0.2), + RANGE(-0.1, 0.1), + } +}; static const comedi_lrange range_ni_S_ai_6143 = { 1, { - RANGE( -5, +5 ), -}}; + RANGE(-5, +5), + } +}; static const comedi_lrange range_ni_E_ao_ext = { 4, { - RANGE( -10, 10 ), - RANGE( 0, 10 ), - RANGE_ext( -1, 1 ), - RANGE_ext( 0, 1 ), -}}; + RANGE(-10, 10), + RANGE(0, 10), + RANGE_ext(-1, 1), + RANGE_ext(0, 1), + } +}; -static const comedi_lrange * const ni_range_lkup[]={ +static const comedi_lrange *const ni_range_lkup[] = { &range_ni_E_ai, &range_ni_E_ai_limited, &range_ni_E_ai_limited14, @@ -191,50 +200,49 @@ static const comedi_lrange * const ni_range_lkup[]={ &range_ni_S_ai_6143 }; - - -static int ni_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_cdio_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); -static int ni_cdio_cmd(comedi_device *dev,comedi_subdevice *s); -static int ni_cdio_cancel(comedi_device *dev,comedi_subdevice *s); -static void handle_cdio_interrupt(comedi_device *dev); -static int ni_cdo_inttrig(comedi_device *dev,comedi_subdevice *s, +static int ni_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_cdio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int ni_cdio_cmd(comedi_device * dev, comedi_subdevice * s); +static int ni_cdio_cancel(comedi_device * dev, comedi_subdevice * s); +static void handle_cdio_interrupt(comedi_device * dev); +static int ni_cdo_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum); -static int ni_serial_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_serial_hw_readwrite8(comedi_device *dev,comedi_subdevice *s, +static int ni_serial_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_serial_hw_readwrite8(comedi_device * dev, comedi_subdevice * s, unsigned char data_out, unsigned char *data_in); -static int ni_serial_sw_readwrite8(comedi_device *dev,comedi_subdevice *s, +static int ni_serial_sw_readwrite8(comedi_device * dev, comedi_subdevice * s, unsigned char data_out, unsigned char *data_in); -static int ni_calib_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_calib_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int ni_calib_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_calib_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int ni_eeprom_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_m_series_eeprom_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int ni_eeprom_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_m_series_eeprom_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); -static int ni_pfi_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_pfi_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static unsigned ni_old_get_pfi_routing(comedi_device *dev, unsigned chan); +static int ni_pfi_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_pfi_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static unsigned ni_old_get_pfi_routing(comedi_device * dev, unsigned chan); -static void ni_rtsi_init(comedi_device *dev); -static int ni_rtsi_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_rtsi_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static void ni_rtsi_init(comedi_device * dev); +static int ni_rtsi_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_rtsi_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static void caldac_setup(comedi_device *dev,comedi_subdevice *s); -static int ni_read_eeprom(comedi_device *dev,int addr); +static void caldac_setup(comedi_device * dev, comedi_subdevice * s); +static int ni_read_eeprom(comedi_device * dev, int addr); #ifdef DEBUG_STATUS_A static void ni_mio_print_status_a(int status); @@ -247,61 +255,65 @@ static void ni_mio_print_status_b(int status); #define ni_mio_print_status_b(a) #endif -static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s); +static int ni_ai_reset(comedi_device * dev, comedi_subdevice * s); #ifndef PCIDMA -static void ni_handle_fifo_half_full(comedi_device *dev); -static int ni_ao_fifo_half_empty(comedi_device *dev,comedi_subdevice *s); +static void ni_handle_fifo_half_full(comedi_device * dev); +static int ni_ao_fifo_half_empty(comedi_device * dev, comedi_subdevice * s); #endif -static void ni_handle_fifo_dregs(comedi_device *dev); -static int ni_ai_inttrig(comedi_device *dev,comedi_subdevice *s, +static void ni_handle_fifo_dregs(comedi_device * dev); +static int ni_ai_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum); -static void ni_load_channelgain_list(comedi_device *dev,unsigned int n_chan, +static void ni_load_channelgain_list(comedi_device * dev, unsigned int n_chan, unsigned int *list); -static void shutdown_ai_command( comedi_device *dev ); +static void shutdown_ai_command(comedi_device * dev); -static int ni_ao_inttrig(comedi_device *dev,comedi_subdevice *s, +static int ni_ao_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum); -static int ni_ao_reset(comedi_device *dev,comedi_subdevice *s); - -static int ni_8255_callback(int dir,int port,int data,unsigned long arg); - -static int ni_gpct_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_gpct_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_gpct_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_gpct_cmd(comedi_device *dev,comedi_subdevice *s); -static int ni_gpct_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); -static int ni_gpct_cancel(comedi_device *dev,comedi_subdevice *s); -static void handle_gpct_interrupt(comedi_device *dev, unsigned short counter_index); - -static int init_cs5529(comedi_device *dev); -static int cs5529_do_conversion(comedi_device *dev, unsigned short *data); -static int cs5529_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static unsigned int cs5529_config_read(comedi_device *dev, unsigned int reg_select_bits); -static void cs5529_config_write(comedi_device *dev, unsigned int value, unsigned int reg_select_bits); - -static int ni_m_series_pwm_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ni_6143_pwm_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); - -static int ni_set_master_clock(comedi_device *dev, unsigned source, unsigned period_ns); -static void ack_a_interrupt(comedi_device *dev, unsigned short a_status); -static void ack_b_interrupt(comedi_device *dev, unsigned short b_status); - -enum aimodes -{ +static int ni_ao_reset(comedi_device * dev, comedi_subdevice * s); + +static int ni_8255_callback(int dir, int port, int data, unsigned long arg); + +static int ni_gpct_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_gpct_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_gpct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_gpct_cmd(comedi_device * dev, comedi_subdevice * s); +static int ni_gpct_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int ni_gpct_cancel(comedi_device * dev, comedi_subdevice * s); +static void handle_gpct_interrupt(comedi_device * dev, + unsigned short counter_index); + +static int init_cs5529(comedi_device * dev); +static int cs5529_do_conversion(comedi_device * dev, unsigned short *data); +static int cs5529_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static unsigned int cs5529_config_read(comedi_device * dev, + unsigned int reg_select_bits); +static void cs5529_config_write(comedi_device * dev, unsigned int value, + unsigned int reg_select_bits); + +static int ni_m_series_pwm_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ni_6143_pwm_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int ni_set_master_clock(comedi_device * dev, unsigned source, + unsigned period_ns); +static void ack_a_interrupt(comedi_device * dev, unsigned short a_status); +static void ack_b_interrupt(comedi_device * dev, unsigned short b_status); + +enum aimodes { AIMODE_NONE = 0, AIMODE_HALF_FULL = 1, AIMODE_SCAN = 2, AIMODE_SAMPLE = 3, }; -enum ni_common_subdevices -{ +enum ni_common_subdevices { NI_AI_SUBDEV, NI_AO_SUBDEV, NI_DIO_SUBDEV, @@ -320,11 +332,12 @@ enum ni_common_subdevices }; static inline unsigned NI_GPCT_SUBDEV(unsigned counter_index) { - switch(counter_index) - { - case 0: return NI_GPCT0_SUBDEV; + switch (counter_index) { + case 0: + return NI_GPCT0_SUBDEV; break; - case 1: return NI_GPCT1_SUBDEV; + case 1: + return NI_GPCT1_SUBDEV; break; default: break; @@ -333,8 +346,7 @@ static inline unsigned NI_GPCT_SUBDEV(unsigned counter_index) return NI_GPCT0_SUBDEV; } -enum timebase_nanoseconds -{ +enum timebase_nanoseconds { TIMEBASE_1_NS = 50, TIMEBASE_2_NS = 10000 }; @@ -346,93 +358,97 @@ enum timebase_nanoseconds static const int num_adc_stages_611x = 3; -static void handle_a_interrupt(comedi_device *dev, unsigned short status, +static void handle_a_interrupt(comedi_device * dev, unsigned short status, unsigned ai_mite_status); -static void handle_b_interrupt(comedi_device *dev, unsigned short status, +static void handle_b_interrupt(comedi_device * dev, unsigned short status, unsigned ao_mite_status); -static void get_last_sample_611x( comedi_device *dev ); -static void get_last_sample_6143( comedi_device *dev ); +static void get_last_sample_611x(comedi_device * dev); +static void get_last_sample_6143(comedi_device * dev); #ifdef PCIDMA -static int ni_ai_drain_dma(comedi_device *dev ); -static inline void ni_set_bitfield(comedi_device *dev, int reg, unsigned bit_mask, unsigned bit_values); +static int ni_ai_drain_dma(comedi_device * dev); +static inline void ni_set_bitfield(comedi_device * dev, int reg, + unsigned bit_mask, unsigned bit_values); /* DMA channel setup */ // negative channel means no channel -static inline void ni_set_ai_dma_channel(comedi_device *dev, int channel) +static inline void ni_set_ai_dma_channel(comedi_device * dev, int channel) { unsigned bitfield; - if(channel >= 0) - { - bitfield = (ni_stc_dma_channel_select_bitfield(channel) << AI_DMA_Select_Shift) & AI_DMA_Select_Mask; - }else - { + if (channel >= 0) { + bitfield = + (ni_stc_dma_channel_select_bitfield(channel) << + AI_DMA_Select_Shift) & AI_DMA_Select_Mask; + } else { bitfield = 0; } ni_set_bitfield(dev, AI_AO_Select, AI_DMA_Select_Mask, bitfield); } // negative channel means no channel -static inline void ni_set_ao_dma_channel(comedi_device *dev, int channel) +static inline void ni_set_ao_dma_channel(comedi_device * dev, int channel) { unsigned bitfield; - if(channel >= 0) - { - bitfield = (ni_stc_dma_channel_select_bitfield(channel) << AO_DMA_Select_Shift) & AO_DMA_Select_Mask; - }else - { + if (channel >= 0) { + bitfield = + (ni_stc_dma_channel_select_bitfield(channel) << + AO_DMA_Select_Shift) & AO_DMA_Select_Mask; + } else { bitfield = 0; } ni_set_bitfield(dev, AI_AO_Select, AO_DMA_Select_Mask, bitfield); } // negative mite_channel means no channel -static inline void ni_set_gpct_dma_channel(comedi_device *dev, unsigned gpct_index, int mite_channel) +static inline void ni_set_gpct_dma_channel(comedi_device * dev, + unsigned gpct_index, int mite_channel) { unsigned bitfield; - if(mite_channel >= 0) - { + if (mite_channel >= 0) { bitfield = GPCT_DMA_Select_Bits(gpct_index, mite_channel); - }else - { + } else { bitfield = 0; } - ni_set_bitfield(dev, G0_G1_Select, GPCT_DMA_Select_Mask(gpct_index), bitfield); + ni_set_bitfield(dev, G0_G1_Select, GPCT_DMA_Select_Mask(gpct_index), + bitfield); } // negative mite_channel means no channel -static inline void ni_set_cdo_dma_channel(comedi_device *dev, int mite_channel) +static inline void ni_set_cdo_dma_channel(comedi_device * dev, int mite_channel) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags); devpriv->cdio_dma_select_reg &= ~CDO_DMA_Select_Mask; - if(mite_channel >= 0) - { + if (mite_channel >= 0) { /*XXX just guessing ni_stc_dma_channel_select_bitfield() returns the right bits, - under the assumption the cdio dma selection works just like ai/ao/gpct. - Definitely works for dma channels 0 and 1.*/ - devpriv->cdio_dma_select_reg |= (ni_stc_dma_channel_select_bitfield(mite_channel) << CDO_DMA_Select_Shift) & CDO_DMA_Select_Mask; + under the assumption the cdio dma selection works just like ai/ao/gpct. + Definitely works for dma channels 0 and 1. */ + devpriv->cdio_dma_select_reg |= + (ni_stc_dma_channel_select_bitfield(mite_channel) << + CDO_DMA_Select_Shift) & CDO_DMA_Select_Mask; } ni_writeb(devpriv->cdio_dma_select_reg, M_Offset_CDIO_DMA_Select); mmiowb(); comedi_spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags); } -static int ni_request_ai_mite_channel(comedi_device *dev) +static int ni_request_ai_mite_channel(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); BUG_ON(devpriv->ai_mite_chan); - devpriv->ai_mite_chan = mite_request_channel(devpriv->mite, devpriv->ai_mite_ring); - if(devpriv->ai_mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); - comedi_error(dev, "failed to reserve mite dma channel for analog input."); + devpriv->ai_mite_chan = + mite_request_channel(devpriv->mite, devpriv->ai_mite_ring); + if (devpriv->ai_mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags); + comedi_error(dev, + "failed to reserve mite dma channel for analog input."); return -EBUSY; } devpriv->ai_mite_chan->dir = COMEDI_INPUT; @@ -441,17 +457,19 @@ static int ni_request_ai_mite_channel(comedi_device *dev) return 0; } -static int ni_request_ao_mite_channel(comedi_device *dev) +static int ni_request_ao_mite_channel(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); BUG_ON(devpriv->ao_mite_chan); - devpriv->ao_mite_chan = mite_request_channel(devpriv->mite, devpriv->ao_mite_ring); - if(devpriv->ao_mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); - comedi_error(dev, "failed to reserve mite dma channel for analog outut."); + devpriv->ao_mite_chan = + mite_request_channel(devpriv->mite, devpriv->ao_mite_ring); + if (devpriv->ao_mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags); + comedi_error(dev, + "failed to reserve mite dma channel for analog outut."); return -EBUSY; } devpriv->ao_mite_chan->dir = COMEDI_OUTPUT; @@ -460,7 +478,8 @@ static int ni_request_ao_mite_channel(comedi_device *dev) return 0; } -static int ni_request_gpct_mite_channel(comedi_device *dev, unsigned gpct_index, enum comedi_io_direction direction) +static int ni_request_gpct_mite_channel(comedi_device * dev, + unsigned gpct_index, enum comedi_io_direction direction) { unsigned long flags; struct mite_channel *mite_chan; @@ -468,133 +487,137 @@ static int ni_request_gpct_mite_channel(comedi_device *dev, unsigned gpct_index, BUG_ON(gpct_index >= NUM_GPCT); comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); BUG_ON(devpriv->counter_dev->counters[gpct_index].mite_chan); - mite_chan = mite_request_channel(devpriv->mite, devpriv->gpct_mite_ring[gpct_index]); - if(mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); - comedi_error(dev, "failed to reserve mite dma channel for counter."); + mite_chan = + mite_request_channel(devpriv->mite, + devpriv->gpct_mite_ring[gpct_index]); + if (mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags); + comedi_error(dev, + "failed to reserve mite dma channel for counter."); return -EBUSY; } mite_chan->dir = direction; - ni_tio_set_mite_channel(&devpriv->counter_dev->counters[gpct_index], mite_chan); + ni_tio_set_mite_channel(&devpriv->counter_dev->counters[gpct_index], + mite_chan); ni_set_gpct_dma_channel(dev, gpct_index, mite_chan->channel); comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); return 0; } -#endif // PCIDMA +#endif // PCIDMA -static int ni_request_cdo_mite_channel(comedi_device *dev) +static int ni_request_cdo_mite_channel(comedi_device * dev) { #ifdef PCIDMA unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); BUG_ON(devpriv->cdo_mite_chan); - devpriv->cdo_mite_chan = mite_request_channel(devpriv->mite, devpriv->cdo_mite_ring); - if(devpriv->cdo_mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); - comedi_error(dev, "failed to reserve mite dma channel for correlated digital outut."); + devpriv->cdo_mite_chan = + mite_request_channel(devpriv->mite, devpriv->cdo_mite_ring); + if (devpriv->cdo_mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags); + comedi_error(dev, + "failed to reserve mite dma channel for correlated digital outut."); return -EBUSY; } devpriv->cdo_mite_chan->dir = COMEDI_OUTPUT; ni_set_cdo_dma_channel(dev, devpriv->cdo_mite_chan->channel); comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); -#endif // PCIDMA +#endif // PCIDMA return 0; } - -static void ni_release_ai_mite_channel(comedi_device *dev) +static void ni_release_ai_mite_channel(comedi_device * dev) { #ifdef PCIDMA unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ai_mite_chan) - { + if (devpriv->ai_mite_chan) { ni_set_ai_dma_channel(dev, -1); mite_release_channel(devpriv->ai_mite_chan); devpriv->ai_mite_chan = NULL; } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); -#endif // PCIDMA +#endif // PCIDMA } -static void ni_release_ao_mite_channel(comedi_device *dev) +static void ni_release_ao_mite_channel(comedi_device * dev) { #ifdef PCIDMA unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ao_mite_chan) - { + if (devpriv->ao_mite_chan) { ni_set_ao_dma_channel(dev, -1); mite_release_channel(devpriv->ao_mite_chan); devpriv->ao_mite_chan = NULL; } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); -#endif // PCIDMA +#endif // PCIDMA } -void ni_release_gpct_mite_channel(comedi_device *dev, unsigned gpct_index) +void ni_release_gpct_mite_channel(comedi_device * dev, unsigned gpct_index) { #ifdef PCIDMA unsigned long flags; BUG_ON(gpct_index >= NUM_GPCT); comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->counter_dev->counters[gpct_index].mite_chan) - { - struct mite_channel *mite_chan = devpriv->counter_dev->counters[gpct_index].mite_chan; + if (devpriv->counter_dev->counters[gpct_index].mite_chan) { + struct mite_channel *mite_chan = + devpriv->counter_dev->counters[gpct_index].mite_chan; ni_set_gpct_dma_channel(dev, gpct_index, -1); - ni_tio_set_mite_channel(&devpriv->counter_dev->counters[gpct_index], NULL); + ni_tio_set_mite_channel(&devpriv->counter_dev-> + counters[gpct_index], NULL); mite_release_channel(mite_chan); } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); -#endif // PCIDMA +#endif // PCIDMA } -static void ni_release_cdo_mite_channel(comedi_device *dev) +static void ni_release_cdo_mite_channel(comedi_device * dev) { #ifdef PCIDMA unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->cdo_mite_chan) - { + if (devpriv->cdo_mite_chan) { ni_set_cdo_dma_channel(dev, -1); mite_release_channel(devpriv->cdo_mite_chan); devpriv->cdo_mite_chan = NULL; } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); -#endif // PCIDMA +#endif // PCIDMA } // e-series boards use the second irq signals to generate dma requests for their counters -static void ni_e_series_enable_second_irq(comedi_device *dev, unsigned gpct_index, short enable) +static void ni_e_series_enable_second_irq(comedi_device * dev, + unsigned gpct_index, short enable) { - if(boardtype.reg_type & ni_reg_m_series_mask) return; - switch(gpct_index) - { + if (boardtype.reg_type & ni_reg_m_series_mask) + return; + switch (gpct_index) { case 0: - if(enable) - { - devpriv->stc_writew(dev, G0_Gate_Second_Irq_Enable, Second_IRQ_A_Enable_Register); - }else - { - devpriv->stc_writew(dev, 0, Second_IRQ_A_Enable_Register); + if (enable) { + devpriv->stc_writew(dev, G0_Gate_Second_Irq_Enable, + Second_IRQ_A_Enable_Register); + } else { + devpriv->stc_writew(dev, 0, + Second_IRQ_A_Enable_Register); } break; case 1: - if(enable) - { - devpriv->stc_writew(dev, G1_Gate_Second_Irq_Enable, Second_IRQ_B_Enable_Register); - }else - { - devpriv->stc_writew(dev, 0, Second_IRQ_B_Enable_Register); + if (enable) { + devpriv->stc_writew(dev, G1_Gate_Second_Irq_Enable, + Second_IRQ_B_Enable_Register); + } else { + devpriv->stc_writew(dev, 0, + Second_IRQ_B_Enable_Register); } break; default: @@ -603,36 +626,39 @@ static void ni_e_series_enable_second_irq(comedi_device *dev, unsigned gpct_inde } } -static void ni_clear_ai_fifo(comedi_device *dev){ - if(boardtype.reg_type == ni_reg_6143){ +static void ni_clear_ai_fifo(comedi_device * dev) +{ + if (boardtype.reg_type == ni_reg_6143) { // Flush the 6143 data FIFO - ni_writel(0x10, AIFIFO_Control_6143); // Flush fifo - ni_writel(0x00, AIFIFO_Control_6143); // Flush fifo - while(ni_readl(AIFIFO_Status_6143) & 0x10); // Wait for complete - }else { - devpriv->stc_writew(dev, 1,ADC_FIFO_Clear); - if(boardtype.reg_type == ni_reg_625x) - { + ni_writel(0x10, AIFIFO_Control_6143); // Flush fifo + ni_writel(0x00, AIFIFO_Control_6143); // Flush fifo + while (ni_readl(AIFIFO_Status_6143) & 0x10) ; // Wait for complete + } else { + devpriv->stc_writew(dev, 1, ADC_FIFO_Clear); + if (boardtype.reg_type == ni_reg_625x) { ni_writeb(0, M_Offset_Static_AI_Control(0)); ni_writeb(1, M_Offset_Static_AI_Control(0)); #if 0 - /* the NI example code does 3 convert pulses for 625x boards, - but that appears to be wrong in practice. */ - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); + /* the NI example code does 3 convert pulses for 625x boards, + but that appears to be wrong in practice. */ + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); #endif } } } -static void win_out2(comedi_device *dev, uint32_t data, int reg) +static void win_out2(comedi_device * dev, uint32_t data, int reg) { devpriv->stc_writew(dev, data >> 16, reg); devpriv->stc_writew(dev, data & 0xffff, reg + 1); } -static uint32_t win_in2(comedi_device *dev, int reg) +static uint32_t win_in2(comedi_device * dev, int reg) { uint32_t bits; bits = devpriv->stc_readw(dev, reg) << 16; @@ -641,76 +667,81 @@ static uint32_t win_in2(comedi_device *dev, int reg) } #define ao_win_out(data,addr) ni_ao_win_outw(dev,data,addr) -static inline void ni_ao_win_outw( comedi_device *dev, uint16_t data, int addr ) +static inline void ni_ao_win_outw(comedi_device * dev, uint16_t data, int addr) { unsigned long flags; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - ni_writew(addr,AO_Window_Address_611x); - ni_writew(data,AO_Window_Data_611x); - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + ni_writew(addr, AO_Window_Address_611x); + ni_writew(data, AO_Window_Data_611x); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); } -static inline void ni_ao_win_outl(comedi_device *dev, uint32_t data, int addr) +static inline void ni_ao_win_outl(comedi_device * dev, uint32_t data, int addr) { unsigned long flags; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - ni_writew(addr,AO_Window_Address_611x); - ni_writel(data,AO_Window_Data_611x); - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + ni_writew(addr, AO_Window_Address_611x); + ni_writel(data, AO_Window_Data_611x); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); } -static inline unsigned short ni_ao_win_inw( comedi_device *dev, int addr ) +static inline unsigned short ni_ao_win_inw(comedi_device * dev, int addr) { unsigned long flags; unsigned short data; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); ni_writew(addr, AO_Window_Address_611x); data = ni_readw(AO_Window_Data_611x); - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); return data; } -static inline void ni_set_bitfield(comedi_device *dev, int reg, unsigned bit_mask, unsigned bit_values) +static inline void ni_set_bitfield(comedi_device * dev, int reg, + unsigned bit_mask, unsigned bit_values) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags); - switch (reg){ - case Interrupt_A_Enable_Register: - devpriv->int_a_enable_reg &= ~bit_mask; - devpriv->int_a_enable_reg |= bit_values & bit_mask; - devpriv->stc_writew(dev, devpriv->int_a_enable_reg, Interrupt_A_Enable_Register); - break; - case Interrupt_B_Enable_Register: - devpriv->int_b_enable_reg &= ~bit_mask; - devpriv->int_b_enable_reg |= bit_values & bit_mask; - devpriv->stc_writew(dev, devpriv->int_b_enable_reg, Interrupt_B_Enable_Register); - break; - case IO_Bidirection_Pin_Register: - devpriv->io_bidirection_pin_reg &= ~bit_mask; - devpriv->io_bidirection_pin_reg |= bit_values & bit_mask; - devpriv->stc_writew(dev, devpriv->io_bidirection_pin_reg, IO_Bidirection_Pin_Register); - break; - case AI_AO_Select: - devpriv->ai_ao_select_reg &= ~bit_mask; - devpriv->ai_ao_select_reg |= bit_values & bit_mask; - ni_writeb(devpriv->ai_ao_select_reg, AI_AO_Select); - break; - case G0_G1_Select: - devpriv->g0_g1_select_reg &= ~bit_mask; - devpriv->g0_g1_select_reg |= bit_values & bit_mask; - ni_writeb(devpriv->g0_g1_select_reg, G0_G1_Select); - break; - default: - rt_printk("Warning %s() called with invalid register\n", __FUNCTION__); - rt_printk("reg is %d\n", reg); - break; + switch (reg) { + case Interrupt_A_Enable_Register: + devpriv->int_a_enable_reg &= ~bit_mask; + devpriv->int_a_enable_reg |= bit_values & bit_mask; + devpriv->stc_writew(dev, devpriv->int_a_enable_reg, + Interrupt_A_Enable_Register); + break; + case Interrupt_B_Enable_Register: + devpriv->int_b_enable_reg &= ~bit_mask; + devpriv->int_b_enable_reg |= bit_values & bit_mask; + devpriv->stc_writew(dev, devpriv->int_b_enable_reg, + Interrupt_B_Enable_Register); + break; + case IO_Bidirection_Pin_Register: + devpriv->io_bidirection_pin_reg &= ~bit_mask; + devpriv->io_bidirection_pin_reg |= bit_values & bit_mask; + devpriv->stc_writew(dev, devpriv->io_bidirection_pin_reg, + IO_Bidirection_Pin_Register); + break; + case AI_AO_Select: + devpriv->ai_ao_select_reg &= ~bit_mask; + devpriv->ai_ao_select_reg |= bit_values & bit_mask; + ni_writeb(devpriv->ai_ao_select_reg, AI_AO_Select); + break; + case G0_G1_Select: + devpriv->g0_g1_select_reg &= ~bit_mask; + devpriv->g0_g1_select_reg |= bit_values & bit_mask; + ni_writeb(devpriv->g0_g1_select_reg, G0_G1_Select); + break; + default: + rt_printk("Warning %s() called with invalid register\n", + __FUNCTION__); + rt_printk("reg is %d\n", reg); + break; } mmiowb(); - comedi_spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags ); + comedi_spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags); } /* ni_set_bits( ) allows different parts of the ni_mio_common driver to @@ -723,11 +754,12 @@ static inline void ni_set_bitfield(comedi_device *dev, int reg, unsigned bit_mas * * value should only be 1 or 0. */ -static inline void ni_set_bits(comedi_device *dev, int reg, unsigned bits, unsigned value) +static inline void ni_set_bits(comedi_device * dev, int reg, unsigned bits, + unsigned value) { unsigned bit_values; - if(value) + if (value) bit_values = bits; else bit_values = 0; @@ -736,7 +768,7 @@ static inline void ni_set_bits(comedi_device *dev, int reg, unsigned bits, unsig static irqreturn_t ni_E_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; + comedi_device *dev = d; unsigned short a_status; unsigned short b_status; unsigned int ai_mite_status = 0; @@ -744,37 +776,43 @@ static irqreturn_t ni_E_interrupt(int irq, void *d PT_REGS_ARG) unsigned long flags; struct mite_struct *mite = devpriv->mite; - if(dev->attached == 0) return IRQ_NONE; - smp_mb(); // make sure dev->attached is checked before handler does anything else. + if (dev->attached == 0) + return IRQ_NONE; + smp_mb(); // make sure dev->attached is checked before handler does anything else. // lock to avoid race with comedi_poll comedi_spin_lock_irqsave(&dev->spinlock, flags); a_status = devpriv->stc_readw(dev, AI_Status_1_Register); b_status = devpriv->stc_readw(dev, AO_Status_1_Register); - if(mite) - { + if (mite) { unsigned long flags_too; - comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags_too); - if(devpriv->ai_mite_chan) - { + comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, + flags_too); + if (devpriv->ai_mite_chan) { ai_mite_status = mite_get_status(devpriv->ai_mite_chan); - if(ai_mite_status & CHSR_LINKC) - writel(CHOR_CLRLC, devpriv->mite->mite_io_addr + MITE_CHOR(devpriv->ai_mite_chan->channel)); + if (ai_mite_status & CHSR_LINKC) + writel(CHOR_CLRLC, + devpriv->mite->mite_io_addr + + MITE_CHOR(devpriv->ai_mite_chan-> + channel)); } - if(devpriv->ao_mite_chan) - { + if (devpriv->ao_mite_chan) { ao_mite_status = mite_get_status(devpriv->ao_mite_chan); - if(ao_mite_status & CHSR_LINKC) - writel(CHOR_CLRLC, mite->mite_io_addr + MITE_CHOR(devpriv->ao_mite_chan->channel)); + if (ao_mite_status & CHSR_LINKC) + writel(CHOR_CLRLC, + mite->mite_io_addr + + MITE_CHOR(devpriv->ao_mite_chan-> + channel)); } - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags_too); + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags_too); } ack_a_interrupt(dev, a_status); ack_b_interrupt(dev, b_status); - if((a_status & Interrupt_A_St) || (ai_mite_status & CHSR_INT)) + if ((a_status & Interrupt_A_St) || (ai_mite_status & CHSR_INT)) handle_a_interrupt(dev, a_status, ai_mite_status); - if((b_status & Interrupt_B_St) || (ao_mite_status & CHSR_INT)) + if ((b_status & Interrupt_B_St) || (ao_mite_status & CHSR_INT)) handle_b_interrupt(dev, b_status, ao_mite_status); handle_gpct_interrupt(dev, 0); handle_gpct_interrupt(dev, 1); @@ -785,47 +823,44 @@ static irqreturn_t ni_E_interrupt(int irq, void *d PT_REGS_ARG) } #ifdef PCIDMA -static void ni_sync_ai_dma(comedi_device *dev) +static void ni_sync_ai_dma(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ai_mite_chan) + if (devpriv->ai_mite_chan) mite_sync_input_dma(devpriv->ai_mite_chan, s->async); comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); } -static void mite_handle_b_linkc(struct mite_struct *mite, comedi_device *dev) +static void mite_handle_b_linkc(struct mite_struct *mite, comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AO_SUBDEV; unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ao_mite_chan) - { + if (devpriv->ao_mite_chan) { mite_sync_output_dma(devpriv->ao_mite_chan, s->async); } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); } -static int ni_ao_wait_for_dma_load( comedi_device *dev ) +static int ni_ao_wait_for_dma_load(comedi_device * dev) { static const int timeout = 10000; int i; - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { unsigned short b_status; b_status = devpriv->stc_readw(dev, AO_Status_1_Register); - if( b_status & AO_FIFO_Half_Full_St ) + if (b_status & AO_FIFO_Half_Full_St) break; /* if we poll too often, the pci bus activity seems - to slow the dma transfer down */ + to slow the dma transfer down */ comedi_udelay(10); } - if( i == timeout ) - { + if (i == timeout) { comedi_error(dev, "timed out waiting for dma load"); return -EPIPE; } @@ -833,18 +868,17 @@ static int ni_ao_wait_for_dma_load( comedi_device *dev ) } #endif //PCIDMA -static void ni_handle_eos(comedi_device *dev, comedi_subdevice *s) +static void ni_handle_eos(comedi_device * dev, comedi_subdevice * s) { - if(devpriv->aimode == AIMODE_SCAN) - { + if (devpriv->aimode == AIMODE_SCAN) { #ifdef PCIDMA static const int timeout = 10; int i; - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { ni_sync_ai_dma(dev); - if((s->async->events & COMEDI_CB_EOS)) break; + if ((s->async->events & COMEDI_CB_EOS)) + break; comedi_udelay(1); } #else @@ -853,17 +887,17 @@ static void ni_handle_eos(comedi_device *dev, comedi_subdevice *s) #endif } /* handle special case of single scan using AI_End_On_End_Of_Scan */ - if((devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)){ - shutdown_ai_command( dev ); + if ((devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)) { + shutdown_ai_command(dev); } } -static void shutdown_ai_command( comedi_device *dev ) +static void shutdown_ai_command(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; #ifdef PCIDMA - ni_ai_drain_dma( dev ); + ni_ai_drain_dma(dev); #endif ni_handle_fifo_dregs(dev); get_last_sample_611x(dev); @@ -872,13 +906,13 @@ static void shutdown_ai_command( comedi_device *dev ) s->async->events |= COMEDI_CB_EOA; } -static void ni_event(comedi_device *dev, comedi_subdevice *s) +static void ni_event(comedi_device * dev, comedi_subdevice * s) { - if(s->async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW | COMEDI_CB_EOA)) + if (s->async-> + events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW | COMEDI_CB_EOA)) { - switch(dev->subdevices - s) - { - case NI_AI_SUBDEV: + switch (dev->subdevices - s) { + case NI_AI_SUBDEV: ni_ai_reset(dev, s); break; case NI_AO_SUBDEV: @@ -898,59 +932,64 @@ static void ni_event(comedi_device *dev, comedi_subdevice *s) comedi_event(dev, s); } -static void handle_gpct_interrupt(comedi_device *dev, unsigned short counter_index) +static void handle_gpct_interrupt(comedi_device * dev, + unsigned short counter_index) { comedi_subdevice *s = dev->subdevices + NI_GPCT_SUBDEV(counter_index); - ni_tio_handle_interrupt(&devpriv->counter_dev->counters[counter_index], s); - if(s->async->events) + ni_tio_handle_interrupt(&devpriv->counter_dev->counters[counter_index], + s); + if (s->async->events) ni_event(dev, s); } -static void ack_a_interrupt(comedi_device *dev, unsigned short a_status) +static void ack_a_interrupt(comedi_device * dev, unsigned short a_status) { unsigned short ack = 0; - if(a_status & AI_SC_TC_St) - { + if (a_status & AI_SC_TC_St) { ack |= AI_SC_TC_Interrupt_Ack; } - if(a_status & AI_START1_St) - { - ack |= AI_START1_Interrupt_Ack; + if (a_status & AI_START1_St) { + ack |= AI_START1_Interrupt_Ack; } - if(a_status & AI_START_St) - { + if (a_status & AI_START_St) { ack |= AI_START_Interrupt_Ack; } - if(a_status & AI_STOP_St) - { + if (a_status & AI_STOP_St) { /* not sure why we used to ack the START here also, instead of doing it independently. Frank Hess 2007-07-06 */ - ack |= AI_STOP_Interrupt_Ack /*| AI_START_Interrupt_Ack*/; + ack |= AI_STOP_Interrupt_Ack /*| AI_START_Interrupt_Ack */ ; } - if(ack) devpriv->stc_writew(dev, ack, Interrupt_A_Ack_Register); + if (ack) + devpriv->stc_writew(dev, ack, Interrupt_A_Ack_Register); } -static void handle_a_interrupt(comedi_device *dev, unsigned short status, +static void handle_a_interrupt(comedi_device * dev, unsigned short status, unsigned ai_mite_status) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; //67xx boards don't have ai subdevice, but their gpct0 might generate an a interrupt - if(s->type == COMEDI_SUBD_UNUSED) return; + if (s->type == COMEDI_SUBD_UNUSED) + return; #ifdef DEBUG_INTERRUPT - rt_printk("ni_mio_common: interrupt: a_status=%04x ai_mite_status=%08x\n", + rt_printk + ("ni_mio_common: interrupt: a_status=%04x ai_mite_status=%08x\n", status, ai_mite_status); ni_mio_print_status_a(status); #endif #ifdef PCIDMA - if(ai_mite_status & CHSR_LINKC){ + if (ai_mite_status & CHSR_LINKC) { ni_sync_ai_dma(dev); } - if(ai_mite_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_MRDY | CHSR_DRDY | CHSR_DRQ1 | CHSR_DRQ0 | CHSR_ERROR | CHSR_SABORT | CHSR_XFERR | CHSR_LxERR_mask)){ - rt_printk("unknown mite interrupt, ack! (ai_mite_status=%08x)\n", ai_mite_status); + if (ai_mite_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_MRDY | + CHSR_DRDY | CHSR_DRQ1 | CHSR_DRQ0 | CHSR_ERROR | + CHSR_SABORT | CHSR_XFERR | CHSR_LxERR_mask)) { + rt_printk + ("unknown mite interrupt, ack! (ai_mite_status=%08x)\n", + ai_mite_status); //mite_print_chsr(ai_mite_status); s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; //disable_irq(dev->irq); @@ -958,148 +997,157 @@ static void handle_a_interrupt(comedi_device *dev, unsigned short status, #endif /* test for all uncommon interrupt events at the same time */ - if(status&(AI_Overrun_St|AI_Overflow_St|AI_SC_TC_Error_St|AI_SC_TC_St|AI_START1_St)){ - if(status==0xffff){ - rt_printk("ni_mio_common: a_status=0xffff. Card removed?\n"); + if (status & (AI_Overrun_St | AI_Overflow_St | AI_SC_TC_Error_St | + AI_SC_TC_St | AI_START1_St)) { + if (status == 0xffff) { + rt_printk + ("ni_mio_common: a_status=0xffff. Card removed?\n"); /* we probably aren't even running a command now, * so it's a good idea to be careful. */ - if(comedi_get_subdevice_runflags(s) & SRF_RUNNING){ - s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) { + s->async->events |= + COMEDI_CB_ERROR | COMEDI_CB_EOA; ni_event(dev, s); } return; } - if(status&(AI_Overrun_St|AI_Overflow_St|AI_SC_TC_Error_St)){ + if (status & (AI_Overrun_St | AI_Overflow_St | + AI_SC_TC_Error_St)) { rt_printk("ni_mio_common: ai error a_status=%04x\n", status); ni_mio_print_status_a(status); - shutdown_ai_command( dev ); + shutdown_ai_command(dev); s->async->events |= COMEDI_CB_ERROR; - if(status & (AI_Overrun_St | AI_Overflow_St)) + if (status & (AI_Overrun_St | AI_Overflow_St)) s->async->events |= COMEDI_CB_OVERFLOW; ni_event(dev, s); return; } - if(status&AI_SC_TC_St){ + if (status & AI_SC_TC_St) { #ifdef DEBUG_INTERRUPT rt_printk("ni_mio_common: SC_TC interrupt\n"); #endif - if(!devpriv->ai_continuous){ + if (!devpriv->ai_continuous) { shutdown_ai_command(dev); } } } #ifndef PCIDMA - if(status&AI_FIFO_Half_Full_St){ + if (status & AI_FIFO_Half_Full_St) { int i; static const int timeout = 10; /* pcmcia cards (at least 6036) seem to stop producing interrupts if we *fail to get the fifo less than half full, so loop to be sure.*/ - for(i = 0; i < timeout; ++i) - { + for (i = 0; i < timeout; ++i) { ni_handle_fifo_half_full(dev); - if((devpriv->stc_readw(dev, AI_Status_1_Register) & AI_FIFO_Half_Full_St) == 0) + if ((devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Half_Full_St) == 0) break; } } #endif // !PCIDMA - if( (status & AI_STOP_St) ){ + if ((status & AI_STOP_St)) { ni_handle_eos(dev, s); } ni_event(dev, s); #ifdef DEBUG_INTERRUPT - status=devpriv->stc_readw(dev, AI_Status_1_Register); - if(status&Interrupt_A_St){ - rt_printk("handle_a_interrupt: didn't clear interrupt? status=0x%x\n", status); + status = devpriv->stc_readw(dev, AI_Status_1_Register); + if (status & Interrupt_A_St) { + rt_printk + ("handle_a_interrupt: didn't clear interrupt? status=0x%x\n", + status); } #endif } -static void ack_b_interrupt(comedi_device *dev, unsigned short b_status) +static void ack_b_interrupt(comedi_device * dev, unsigned short b_status) { unsigned short ack = 0; - if(b_status & AO_BC_TC_St) - { + if (b_status & AO_BC_TC_St) { ack |= AO_BC_TC_Interrupt_Ack; } - if(b_status & AO_Overrun_St) - { + if (b_status & AO_Overrun_St) { ack |= AO_Error_Interrupt_Ack; } - if(b_status & AO_START_St) - { + if (b_status & AO_START_St) { ack |= AO_START_Interrupt_Ack; } - if(b_status & AO_START1_St) - { + if (b_status & AO_START1_St) { ack |= AO_START1_Interrupt_Ack; } - if(b_status & AO_UC_TC_St) - { + if (b_status & AO_UC_TC_St) { ack |= AO_UC_TC_Interrupt_Ack; } - if(b_status & AO_UI2_TC_St) - { + if (b_status & AO_UI2_TC_St) { ack |= AO_UI2_TC_Interrupt_Ack; } - if(b_status & AO_UPDATE_St) - { + if (b_status & AO_UPDATE_St) { ack |= AO_UPDATE_Interrupt_Ack; } - if(ack) devpriv->stc_writew(dev, ack, Interrupt_B_Ack_Register); + if (ack) + devpriv->stc_writew(dev, ack, Interrupt_B_Ack_Register); } -static void handle_b_interrupt(comedi_device *dev, unsigned short b_status, +static void handle_b_interrupt(comedi_device * dev, unsigned short b_status, unsigned ao_mite_status) { comedi_subdevice *s = dev->subdevices + NI_AO_SUBDEV; //unsigned short ack=0; #ifdef DEBUG_INTERRUPT rt_printk("ni_mio_common: interrupt: b_status=%04x m1_status=%08x\n", - b_status,ao_mite_status); + b_status, ao_mite_status); ni_mio_print_status_b(b_status); #endif #ifdef PCIDMA /* Currently, mite.c requires us to handle LINKC */ - if(ao_mite_status & CHSR_LINKC){ + if (ao_mite_status & CHSR_LINKC) { mite_handle_b_linkc(devpriv->mite, dev); } - if(ao_mite_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_MRDY | CHSR_DRDY | CHSR_DRQ1 | CHSR_DRQ0 | CHSR_ERROR | CHSR_SABORT | CHSR_XFERR | CHSR_LxERR_mask)){ - rt_printk("unknown mite interrupt, ack! (ao_mite_status=%08x)\n", ao_mite_status); + if (ao_mite_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_MRDY | + CHSR_DRDY | CHSR_DRQ1 | CHSR_DRQ0 | CHSR_ERROR | + CHSR_SABORT | CHSR_XFERR | CHSR_LxERR_mask)) { + rt_printk + ("unknown mite interrupt, ack! (ao_mite_status=%08x)\n", + ao_mite_status); //mite_print_chsr(ao_mite_status); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; } #endif - if(b_status == 0xffff)return; - if(b_status & AO_Overrun_St){ - rt_printk("ni_mio_common: AO FIFO underrun status=0x%04x status2=0x%04x\n",b_status,devpriv->stc_readw(dev, AO_Status_2_Register)); + if (b_status == 0xffff) + return; + if (b_status & AO_Overrun_St) { + rt_printk + ("ni_mio_common: AO FIFO underrun status=0x%04x status2=0x%04x\n", + b_status, devpriv->stc_readw(dev, + AO_Status_2_Register)); s->async->events |= COMEDI_CB_OVERFLOW; } - if(b_status & AO_BC_TC_St){ - MDPRINTK("ni_mio_common: AO BC_TC status=0x%04x status2=0x%04x\n",b_status,devpriv->stc_readw(dev, AO_Status_2_Register)); + if (b_status & AO_BC_TC_St) { + MDPRINTK("ni_mio_common: AO BC_TC status=0x%04x status2=0x%04x\n", b_status, devpriv->stc_readw(dev, AO_Status_2_Register)); s->async->events |= COMEDI_CB_EOA; } - #ifndef PCIDMA - if(b_status & AO_FIFO_Request_St){ + if (b_status & AO_FIFO_Request_St) { int ret; ret = ni_ao_fifo_half_empty(dev, s); - if(!ret){ + if (!ret) { rt_printk("ni_mio_common: AO buffer underrun\n"); ni_set_bits(dev, Interrupt_B_Enable_Register, - AO_FIFO_Interrupt_Enable | AO_Error_Interrupt_Enable, 0); + AO_FIFO_Interrupt_Enable | + AO_Error_Interrupt_Enable, 0); s->async->events |= COMEDI_CB_OVERFLOW; } } @@ -1109,11 +1157,11 @@ static void handle_b_interrupt(comedi_device *dev, unsigned short b_status, } #ifdef DEBUG_STATUS_A -static const char * const status_a_strings[]={ - "passthru0","fifo","G0_gate","G0_TC", - "stop","start","sc_tc","start1", - "start2","sc_tc_error","overflow","overrun", - "fifo_empty","fifo_half_full","fifo_full","interrupt_a" +static const char *const status_a_strings[] = { + "passthru0", "fifo", "G0_gate", "G0_TC", + "stop", "start", "sc_tc", "start1", + "start2", "sc_tc_error", "overflow", "overrun", + "fifo_empty", "fifo_half_full", "fifo_full", "interrupt_a" }; static void ni_mio_print_status_a(int status) @@ -1121,9 +1169,9 @@ static void ni_mio_print_status_a(int status) int i; rt_printk("A status:"); - for(i=15;i>=0;i--){ - if(status&(1<= 0; i--) { + if (status & (1 << i)) { + rt_printk(" %s", status_a_strings[i]); } } rt_printk("\n"); @@ -1131,11 +1179,11 @@ static void ni_mio_print_status_a(int status) #endif #ifdef DEBUG_STATUS_B -static const char * const status_b_strings[]={ - "passthru1","fifo","G1_gate","G1_TC", - "UI2_TC","UPDATE","UC_TC","BC_TC", - "start1","overrun","start","bc_tc_error", - "fifo_empty","fifo_half_full","fifo_full","interrupt_b" +static const char *const status_b_strings[] = { + "passthru1", "fifo", "G1_gate", "G1_TC", + "UI2_TC", "UPDATE", "UC_TC", "BC_TC", + "start1", "overrun", "start", "bc_tc_error", + "fifo_empty", "fifo_half_full", "fifo_full", "interrupt_b" }; static void ni_mio_print_status_b(int status) @@ -1143,9 +1191,9 @@ static void ni_mio_print_status_b(int status) int i; rt_printk("B status:"); - for(i=15;i>=0;i--){ - if(status&(1<= 0; i--) { + if (status & (1 << i)) { + rt_printk(" %s", status_b_strings[i]); } } rt_printk("\n"); @@ -1154,7 +1202,7 @@ static void ni_mio_print_status_b(int status) #ifndef PCIDMA -static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, int n) +static void ni_ao_fifo_load(comedi_device * dev, comedi_subdevice * s, int n) { comedi_async *async = s->async; comedi_cmd *cmd = &async->cmd; @@ -1166,33 +1214,33 @@ static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, int n) int err = 1; chan = async->cur_chan; - for(i=0;ichanlist[chan]); - if(boardtype.reg_type & ni_reg_6xxx_mask) - { + if (boardtype.reg_type & ni_reg_6xxx_mask) { packed_data = d & 0xffff; /* 6711 only has 16 bit wide ao fifo */ - if(boardtype.reg_type != ni_reg_6711) - { + if (boardtype.reg_type != ni_reg_6711) { err &= comedi_buf_get(async, &d); - if(err == 0) break; + if (err == 0) + break; chan++; i++; - packed_data |= ( d << 16 ) & 0xffff0000; + packed_data |= (d << 16) & 0xffff0000; } - ni_writel( packed_data, DAC_FIFO_Data_611x ); - }else{ + ni_writel(packed_data, DAC_FIFO_Data_611x); + } else { ni_writew(d, DAC_FIFO_Data); } chan++; chan %= cmd->chanlist_len; } async->cur_chan = chan; - if(err==0){ + if (err == 0) { async->events |= COMEDI_CB_OVERFLOW; } } @@ -1213,119 +1261,120 @@ static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, int n) * RT code, as RT code might purposely be running close to the * metal. Needs to be fixed eventually. */ -static int ni_ao_fifo_half_empty(comedi_device *dev,comedi_subdevice *s) +static int ni_ao_fifo_half_empty(comedi_device * dev, comedi_subdevice * s) { int n; n = comedi_buf_read_n_available(s->async); - if(n==0){ + if (n == 0) { s->async->events |= COMEDI_CB_OVERFLOW; return 0; } n /= sizeof(sampl_t); - if(n > boardtype.ao_fifo_depth / 2) + if (n > boardtype.ao_fifo_depth / 2) n = boardtype.ao_fifo_depth / 2; - ni_ao_fifo_load(dev,s,n); + ni_ao_fifo_load(dev, s, n); s->async->events |= COMEDI_CB_BLOCK; return 1; } -static int ni_ao_prep_fifo(comedi_device *dev,comedi_subdevice *s) +static int ni_ao_prep_fifo(comedi_device * dev, comedi_subdevice * s) { int n; /* reset fifo */ - devpriv->stc_writew(dev, 1,DAC_FIFO_Clear); - if(boardtype.reg_type & ni_reg_6xxx_mask) + devpriv->stc_writew(dev, 1, DAC_FIFO_Clear); + if (boardtype.reg_type & ni_reg_6xxx_mask) ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x); /* load some data */ n = comedi_buf_read_n_available(s->async); - if(n==0)return 0; + if (n == 0) + return 0; n /= sizeof(sampl_t); - if(n > boardtype.ao_fifo_depth) + if (n > boardtype.ao_fifo_depth) n = boardtype.ao_fifo_depth; - ni_ao_fifo_load(dev,s,n); + ni_ao_fifo_load(dev, s, n); return n; } -static void ni_ai_fifo_read(comedi_device *dev,comedi_subdevice *s, - int n) +static void ni_ai_fifo_read(comedi_device * dev, comedi_subdevice * s, int n) { comedi_async *async = s->async; int i; - if(boardtype.reg_type == ni_reg_611x){ + if (boardtype.reg_type == ni_reg_611x) { sampl_t data[2]; u32 dl; - for( i = 0; i < n / 2; i++ ){ - dl=ni_readl(ADC_FIFO_Data_611x); + for (i = 0; i < n / 2; i++) { + dl = ni_readl(ADC_FIFO_Data_611x); /* This may get the hi/lo data in the wrong order */ - data[0] = (dl>>16) & 0xffff; + data[0] = (dl >> 16) & 0xffff; data[1] = dl & 0xffff; cfc_write_array_to_buffer(s, data, sizeof(data)); } /* Check if there's a single sample stuck in the FIFO */ - if( n % 2){ - dl=ni_readl(ADC_FIFO_Data_611x); + if (n % 2) { + dl = ni_readl(ADC_FIFO_Data_611x); data[0] = dl & 0xffff; cfc_write_to_buffer(s, data[0]); } - } else if(boardtype.reg_type == ni_reg_6143){ - sampl_t data[2]; - u32 dl; + } else if (boardtype.reg_type == ni_reg_6143) { + sampl_t data[2]; + u32 dl; // This just reads the FIFO assuming the data is present, no checks on the FIFO status are performed - for(i = 0; i < n / 2; i++){ + for (i = 0; i < n / 2; i++) { dl = ni_readl(AIFIFO_Data_6143); data[0] = (dl >> 16) & 0xffff; data[1] = dl & 0xffff; cfc_write_array_to_buffer(s, data, sizeof(data)); } - if(n % 2){ + if (n % 2) { /* Assume there is a single sample stuck in the FIFO */ ni_writel(0x01, AIFIFO_Control_6143); // Get stranded sample into FIFO dl = ni_readl(AIFIFO_Data_6143); data[0] = (dl >> 16) & 0xffff; cfc_write_to_buffer(s, data[0]); } - } else{ - if( n > sizeof(devpriv->ai_fifo_buffer) / sizeof(devpriv->ai_fifo_buffer[0])) - { - comedi_error( dev, "bug! ai_fifo_buffer too small" ); + } else { + if (n > sizeof(devpriv->ai_fifo_buffer) / + sizeof(devpriv->ai_fifo_buffer[0])) { + comedi_error(dev, "bug! ai_fifo_buffer too small"); async->events |= COMEDI_CB_ERROR; return; } - for(i = 0; i < n; i++){ - devpriv->ai_fifo_buffer[i] = ni_readw(ADC_FIFO_Data_Register); + for (i = 0; i < n; i++) { + devpriv->ai_fifo_buffer[i] = + ni_readw(ADC_FIFO_Data_Register); } - cfc_write_array_to_buffer( s, devpriv->ai_fifo_buffer, - n * sizeof(devpriv->ai_fifo_buffer[0]) ); + cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, + n * sizeof(devpriv->ai_fifo_buffer[0])); } } -static void ni_handle_fifo_half_full(comedi_device *dev) +static void ni_handle_fifo_half_full(comedi_device * dev) { int n; - comedi_subdevice *s=dev->subdevices + NI_AI_SUBDEV; + comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; - n=boardtype.ai_fifo_depth/2; + n = boardtype.ai_fifo_depth / 2; - ni_ai_fifo_read(dev,s,n); + ni_ai_fifo_read(dev, s, n); } #endif #ifdef PCIDMA -static int ni_ai_drain_dma(comedi_device *dev ) +static int ni_ai_drain_dma(comedi_device * dev) { int i; static const int timeout = 10000; @@ -1333,20 +1382,23 @@ static int ni_ai_drain_dma(comedi_device *dev ) int retval = 0; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ai_mite_chan) - { - for(i = 0; i < timeout; i++) - { - if((devpriv->stc_readw(dev, AI_Status_1_Register) & AI_FIFO_Empty_St) && - mite_bytes_in_transit(devpriv->ai_mite_chan) == 0) + if (devpriv->ai_mite_chan) { + for (i = 0; i < timeout; i++) { + if ((devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St) + && mite_bytes_in_transit(devpriv-> + ai_mite_chan) == 0) break; comedi_udelay(5); } - if(i == timeout) - { - rt_printk("ni_mio_common: wait for dma drain timed out\n"); - rt_printk("mite_bytes_in_transit=%i, AI_Status1_Register=0x%x\n", - mite_bytes_in_transit(devpriv->ai_mite_chan), devpriv->stc_readw(dev, AI_Status_1_Register)); + if (i == timeout) { + rt_printk + ("ni_mio_common: wait for dma drain timed out\n"); + rt_printk + ("mite_bytes_in_transit=%i, AI_Status1_Register=0x%x\n", + mite_bytes_in_transit(devpriv->ai_mite_chan), + devpriv->stc_readw(dev, AI_Status_1_Register)); retval = -1; } } @@ -1360,7 +1412,7 @@ static int ni_ai_drain_dma(comedi_device *dev ) /* Empties the AI fifo */ -static void ni_handle_fifo_dregs(comedi_device *dev) +static void ni_handle_fifo_dregs(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; sampl_t data[2]; @@ -1368,18 +1420,20 @@ static void ni_handle_fifo_dregs(comedi_device *dev) short fifo_empty; int i; - if(boardtype.reg_type == ni_reg_611x){ - while((devpriv->stc_readw(dev, AI_Status_1_Register)&AI_FIFO_Empty_St) == 0){ - dl=ni_readl(ADC_FIFO_Data_611x); + if (boardtype.reg_type == ni_reg_611x) { + while ((devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St) == 0) { + dl = ni_readl(ADC_FIFO_Data_611x); /* This may get the hi/lo data in the wrong order */ - data[0] = (dl>>16); - data[1] = (dl&0xffff); + data[0] = (dl >> 16); + data[1] = (dl & 0xffff); cfc_write_array_to_buffer(s, data, sizeof(data)); } - }else if(boardtype.reg_type == ni_reg_6143){ + } else if (boardtype.reg_type == ni_reg_6143) { i = 0; - while(ni_readl(AIFIFO_Status_6143) & 0x04){ + while (ni_readl(AIFIFO_Status_6143) & 0x04) { dl = ni_readl(AIFIFO_Data_6143); /* This may get the hi/lo data in the wrong order */ @@ -1389,55 +1443,65 @@ static void ni_handle_fifo_dregs(comedi_device *dev) i += 2; } // Check if stranded sample is present - if(ni_readl(AIFIFO_Status_6143) & 0x01){ + if (ni_readl(AIFIFO_Status_6143) & 0x01) { ni_writel(0x01, AIFIFO_Control_6143); // Get stranded sample into FIFO dl = ni_readl(AIFIFO_Data_6143); data[0] = (dl >> 16) & 0xffff; cfc_write_to_buffer(s, data[0]); } - }else{ - fifo_empty = devpriv->stc_readw(dev, AI_Status_1_Register) & AI_FIFO_Empty_St; - while(fifo_empty == 0) - { - for(i = 0; i < sizeof(devpriv->ai_fifo_buffer) / sizeof(devpriv->ai_fifo_buffer[0]); i++) - { - fifo_empty = devpriv->stc_readw(dev, AI_Status_1_Register) & AI_FIFO_Empty_St; - if(fifo_empty) break; - devpriv->ai_fifo_buffer[i] = ni_readw(ADC_FIFO_Data_Register); + } else { + fifo_empty = + devpriv->stc_readw(dev, + AI_Status_1_Register) & AI_FIFO_Empty_St; + while (fifo_empty == 0) { + for (i = 0; + i < + sizeof(devpriv->ai_fifo_buffer) / + sizeof(devpriv->ai_fifo_buffer[0]); i++) { + fifo_empty = + devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St; + if (fifo_empty) + break; + devpriv->ai_fifo_buffer[i] = + ni_readw(ADC_FIFO_Data_Register); } - cfc_write_array_to_buffer( s, devpriv->ai_fifo_buffer, - i * sizeof(devpriv->ai_fifo_buffer[0]) ); + cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, + i * sizeof(devpriv->ai_fifo_buffer[0])); } } } -static void get_last_sample_611x( comedi_device *dev ) +static void get_last_sample_611x(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; sampl_t data; u32 dl; - if(boardtype.reg_type != ni_reg_611x) return; + if (boardtype.reg_type != ni_reg_611x) + return; /* Check if there's a single sample stuck in the FIFO */ - if(ni_readb(XXX_Status)&0x80){ - dl=ni_readl(ADC_FIFO_Data_611x); - data = (dl&0xffff); + if (ni_readb(XXX_Status) & 0x80) { + dl = ni_readl(ADC_FIFO_Data_611x); + data = (dl & 0xffff); cfc_write_to_buffer(s, data); } } -static void get_last_sample_6143(comedi_device* dev) +static void get_last_sample_6143(comedi_device * dev) { - comedi_subdevice* s = dev->subdevices + NI_AI_SUBDEV; - sampl_t data; - u32 dl; + comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; + sampl_t data; + u32 dl; - if(boardtype.reg_type != ni_reg_6143) return; + if (boardtype.reg_type != ni_reg_6143) + return; /* Check if there's a single sample stuck in the FIFO */ - if(ni_readl(AIFIFO_Status_6143) & 0x01){ + if (ni_readl(AIFIFO_Status_6143) & 0x01) { ni_writel(0x01, AIFIFO_Control_6143); // Get stranded sample into FIFO dl = ni_readl(AIFIFO_Data_6143); @@ -1447,23 +1511,22 @@ static void get_last_sample_6143(comedi_device* dev) } } -static void ni_ai_munge(comedi_device *dev, comedi_subdevice *s, - void *data, unsigned int num_bytes, unsigned int chan_index ) +static void ni_ai_munge(comedi_device * dev, comedi_subdevice * s, + void *data, unsigned int num_bytes, unsigned int chan_index) { comedi_async *async = s->async; unsigned int i; unsigned int length = num_bytes / bytes_per_sample(s); sampl_t *array = data; lsampl_t *larray = data; - for(i = 0; i < length; i++) - { + for (i = 0; i < length; i++) { #ifdef PCIDMA - if(s->subdev_flags & SDF_LSAMPL) + if (s->subdev_flags & SDF_LSAMPL) larray[i] = le32_to_cpu(larray[i]); else array[i] = le16_to_cpu(array[i]); #endif - if(s->subdev_flags & SDF_LSAMPL) + if (s->subdev_flags & SDF_LSAMPL) larray[i] += devpriv->ai_offset[chan_index]; else array[i] += devpriv->ai_offset[chan_index]; @@ -1474,20 +1537,20 @@ static void ni_ai_munge(comedi_device *dev, comedi_subdevice *s, #ifdef PCIDMA -static int ni_ai_setup_MITE_dma(comedi_device *dev) +static int ni_ai_setup_MITE_dma(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AI_SUBDEV; int retval; retval = ni_request_ai_mite_channel(dev); - if(retval) return retval; -// rt_printk("comedi_debug: using mite channel %i for ai.\n", devpriv->ai_mite_chan->channel); + if (retval) + return retval; +// rt_printk("comedi_debug: using mite channel %i for ai.\n", devpriv->ai_mite_chan->channel); /* write alloc the entire buffer */ comedi_buf_write_alloc(s->async, s->async->prealloc_bufsz); - switch(boardtype.reg_type) - { + switch (boardtype.reg_type) { case ni_reg_611x: case ni_reg_6143: mite_prep_dma(devpriv->ai_mite_chan, 32, 16); @@ -1499,37 +1562,35 @@ static int ni_ai_setup_MITE_dma(comedi_device *dev) mite_prep_dma(devpriv->ai_mite_chan, 16, 16); break; }; - /*start the MITE*/ + /*start the MITE */ mite_dma_arm(devpriv->ai_mite_chan); return 0; } -static int ni_ao_setup_MITE_dma(comedi_device *dev) +static int ni_ao_setup_MITE_dma(comedi_device * dev) { comedi_subdevice *s = dev->subdevices + NI_AO_SUBDEV; int retval; unsigned long flags; retval = ni_request_ao_mite_channel(dev); - if(retval) return retval; + if (retval) + return retval; /* read alloc the entire buffer */ comedi_buf_read_alloc(s->async, s->async->prealloc_bufsz); comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->ao_mite_chan) - { - if(boardtype.reg_type & (ni_reg_611x | ni_reg_6713)) - { + if (devpriv->ao_mite_chan) { + if (boardtype.reg_type & (ni_reg_611x | ni_reg_6713)) { mite_prep_dma(devpriv->ao_mite_chan, 32, 32); - }else - { + } else { /* doing 32 instead of 16 bit wide transfers from memory - makes the mite do 32 bit pci transfers, doubling pci bandwidth. */ + makes the mite do 32 bit pci transfers, doubling pci bandwidth. */ mite_prep_dma(devpriv->ao_mite_chan, 16, 32); } mite_dma_arm(devpriv->ao_mite_chan); - }else + } else retval = -EIO; comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); @@ -1544,30 +1605,32 @@ static int ni_ao_setup_MITE_dma(comedi_device *dev) this is pretty harsh for a cancel, but it works... */ -static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s) +static int ni_ai_reset(comedi_device * dev, comedi_subdevice * s) { ni_release_ai_mite_channel(dev); /* ai configuration */ - devpriv->stc_writew(dev, AI_Configuration_Start | AI_Reset, Joint_Reset_Register); + devpriv->stc_writew(dev, AI_Configuration_Start | AI_Reset, + Joint_Reset_Register); ni_set_bits(dev, Interrupt_A_Enable_Register, - AI_SC_TC_Interrupt_Enable | AI_START1_Interrupt_Enable| - AI_START2_Interrupt_Enable| AI_START_Interrupt_Enable| - AI_STOP_Interrupt_Enable| AI_Error_Interrupt_Enable| - AI_FIFO_Interrupt_Enable,0); + AI_SC_TC_Interrupt_Enable | AI_START1_Interrupt_Enable | + AI_START2_Interrupt_Enable | AI_START_Interrupt_Enable | + AI_STOP_Interrupt_Enable | AI_Error_Interrupt_Enable | + AI_FIFO_Interrupt_Enable, 0); ni_clear_ai_fifo(dev); - if(boardtype.reg_type != ni_reg_6143) + if (boardtype.reg_type != ni_reg_6143) ni_writeb(0, Misc_Command); - devpriv->stc_writew(dev, AI_Disarm, AI_Command_1_Register); /* reset pulses */ - devpriv->stc_writew(dev, AI_Start_Stop | AI_Mode_1_Reserved /*| AI_Trigger_Once */, + devpriv->stc_writew(dev, AI_Disarm, AI_Command_1_Register); /* reset pulses */ + devpriv->stc_writew(dev, + AI_Start_Stop | AI_Mode_1_Reserved /*| AI_Trigger_Once */ , AI_Mode_1_Register); - devpriv->stc_writew(dev, 0x0000,AI_Mode_2_Register); + devpriv->stc_writew(dev, 0x0000, AI_Mode_2_Register); /* generate FIFO interrupts on non-empty */ - devpriv->stc_writew(dev, (0<<6)|0x0000,AI_Mode_3_Register); - if(boardtype.reg_type == ni_reg_611x){ + devpriv->stc_writew(dev, (0 << 6) | 0x0000, AI_Mode_3_Register); + if (boardtype.reg_type == ni_reg_611x) { devpriv->stc_writew(dev, AI_SHIFTIN_Pulse_Width | AI_SOC_Polarity | AI_LOCALMUX_CLK_Pulse_Width, AI_Personal_Register); @@ -1575,8 +1638,9 @@ static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s) AI_EXTMUX_CLK_Output_Select(0) | AI_LOCALMUX_CLK_Output_Select(2) | AI_SC_TC_Output_Select(3) | - AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_High), AI_Output_Control_Register); - }else if(boardtype.reg_type == ni_reg_6143){ + AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_High), + AI_Output_Control_Register); + } else if (boardtype.reg_type == ni_reg_6143) { devpriv->stc_writew(dev, AI_SHIFTIN_Pulse_Width | AI_SOC_Polarity | AI_LOCALMUX_CLK_Pulse_Width, AI_Personal_Register); @@ -1584,8 +1648,9 @@ static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s) AI_EXTMUX_CLK_Output_Select(0) | AI_LOCALMUX_CLK_Output_Select(2) | AI_SC_TC_Output_Select(3) | - AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_Low),AI_Output_Control_Register); - }else{ + AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_Low), + AI_Output_Control_Register); + } else { unsigned ai_output_control_bits; devpriv->stc_writew(dev, AI_SHIFTIN_Pulse_Width | AI_SOC_Polarity | @@ -1595,37 +1660,39 @@ static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s) AI_EXTMUX_CLK_Output_Select(0) | AI_LOCALMUX_CLK_Output_Select(2) | AI_SC_TC_Output_Select(3); - if(boardtype.reg_type == ni_reg_622x) - ai_output_control_bits |= AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_High); + if (boardtype.reg_type == ni_reg_622x) + ai_output_control_bits |= + AI_CONVERT_Output_Select + (AI_CONVERT_Output_Enable_High); else - ai_output_control_bits |= AI_CONVERT_Output_Select(AI_CONVERT_Output_Enable_Low); - devpriv->stc_writew(dev, ai_output_control_bits, AI_Output_Control_Register); + ai_output_control_bits |= + AI_CONVERT_Output_Select + (AI_CONVERT_Output_Enable_Low); + devpriv->stc_writew(dev, ai_output_control_bits, + AI_Output_Control_Register); } /* the following registers should not be changed, because there * are no backup registers in devpriv. If you want to change * any of these, add a backup register and other appropriate code: - * AI_Mode_1_Register - * AI_Mode_3_Register - * AI_Personal_Register - * AI_Output_Control_Register - */ - devpriv->stc_writew(dev, AI_SC_TC_Error_Confirm | AI_START_Interrupt_Ack | - AI_START2_Interrupt_Ack | AI_START1_Interrupt_Ack | - AI_SC_TC_Interrupt_Ack | AI_Error_Interrupt_Ack | - AI_STOP_Interrupt_Ack, Interrupt_A_Ack_Register); /* clear interrupts */ - - devpriv->stc_writew(dev, AI_Configuration_End,Joint_Reset_Register); + * AI_Mode_1_Register + * AI_Mode_3_Register + * AI_Personal_Register + * AI_Output_Control_Register + */ + devpriv->stc_writew(dev, AI_SC_TC_Error_Confirm | AI_START_Interrupt_Ack | AI_START2_Interrupt_Ack | AI_START1_Interrupt_Ack | AI_SC_TC_Interrupt_Ack | AI_Error_Interrupt_Ack | AI_STOP_Interrupt_Ack, Interrupt_A_Ack_Register); /* clear interrupts */ + + devpriv->stc_writew(dev, AI_Configuration_End, Joint_Reset_Register); return 0; } -static int ni_ai_poll(comedi_device *dev,comedi_subdevice *s) +static int ni_ai_poll(comedi_device * dev, comedi_subdevice * s) { unsigned long flags = 0; int count; // lock to avoid race with interrupt handler - if(in_interrupt() == 0) + if (in_interrupt() == 0) comedi_spin_lock_irqsave(&dev->spinlock, flags); #ifndef PCIDMA ni_handle_fifo_dregs(dev); @@ -1633,92 +1700,101 @@ static int ni_ai_poll(comedi_device *dev,comedi_subdevice *s) ni_sync_ai_dma(dev); #endif count = s->async->buf_write_count - s->async->buf_read_count; - if(in_interrupt() == 0) + if (in_interrupt() == 0) comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return count; } - -static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int ni_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,n; + int i, n; const unsigned int mask = (1 << boardtype.adbits) - 1; unsigned signbits; unsigned short d; unsigned long dl; - ni_load_channelgain_list(dev,1,&insn->chanspec); + ni_load_channelgain_list(dev, 1, &insn->chanspec); ni_clear_ai_fifo(dev); - signbits=devpriv->ai_offset[0]; - if(boardtype.reg_type == ni_reg_611x){ - for(n=0; n < num_adc_stages_611x; n++){ - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); + signbits = devpriv->ai_offset[0]; + if (boardtype.reg_type == ni_reg_611x) { + for (n = 0; n < num_adc_stages_611x; n++) { + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); comedi_udelay(1); } - for(n=0; nn; n++){ - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); + for (n = 0; n < insn->n; n++) { + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); /* The 611x has screwy 32-bit FIFOs. */ d = 0; - for(i=0; i> 16 ) & 0xffff; + for (i = 0; i < NI_TIMEOUT; i++) { + if (ni_readb(XXX_Status) & 0x80) { + d = (ni_readl(ADC_FIFO_Data_611x) >> 16) + & 0xffff; break; } - if(!(devpriv->stc_readw(dev, AI_Status_1_Register)&AI_FIFO_Empty_St)) - { - d = ni_readl(ADC_FIFO_Data_611x) & 0xffff; + if (!(devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St)) { + d = ni_readl(ADC_FIFO_Data_611x) & + 0xffff; break; } } - if(i==NI_TIMEOUT){ - rt_printk("ni_mio_common: timeout in 611x ni_ai_insn_read\n"); + if (i == NI_TIMEOUT) { + rt_printk + ("ni_mio_common: timeout in 611x ni_ai_insn_read\n"); return -ETIME; } d += signbits; - data[ n ] = d; + data[n] = d; } - }else if(boardtype.reg_type == ni_reg_6143){ - for(n = 0; n < insn->n; n++){ - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); + } else if (boardtype.reg_type == ni_reg_6143) { + for (n = 0; n < insn->n; n++) { + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); /* The 6143 has 32-bit FIFOs. You need to strobe a bit to move a single 16bit stranded sample into the FIFO */ dl = 0; - for(i = 0; i < NI_TIMEOUT; i++){ - if(ni_readl(AIFIFO_Status_6143) & 0x01) - { + for (i = 0; i < NI_TIMEOUT; i++) { + if (ni_readl(AIFIFO_Status_6143) & 0x01) { ni_writel(0x01, AIFIFO_Control_6143); // Get stranded sample into FIFO dl = ni_readl(AIFIFO_Data_6143); break; } } - if(i == NI_TIMEOUT){ - rt_printk("ni_mio_common: timeout in 6143 ni_ai_insn_read\n"); + if (i == NI_TIMEOUT) { + rt_printk + ("ni_mio_common: timeout in 6143 ni_ai_insn_read\n"); return -ETIME; } data[n] = (((dl >> 16) & 0xFFFF) + signbits) & 0xFFFF; } - }else{ - for(n = 0; n < insn->n; n++){ - devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); - for(i = 0; i < NI_TIMEOUT; i++){ - if(!(devpriv->stc_readw(dev, AI_Status_1_Register)&AI_FIFO_Empty_St)) - break; + } else { + for (n = 0; n < insn->n; n++) { + devpriv->stc_writew(dev, AI_CONVERT_Pulse, + AI_Command_1_Register); + for (i = 0; i < NI_TIMEOUT; i++) { + if (!(devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St)) + break; } - if(i == NI_TIMEOUT){ - rt_printk("ni_mio_common: timeout in ni_ai_insn_read\n"); + if (i == NI_TIMEOUT) { + rt_printk + ("ni_mio_common: timeout in ni_ai_insn_read\n"); return -ETIME; } - if(boardtype.reg_type & ni_reg_m_series_mask) - { - data[n] = ni_readl(M_Offset_AI_FIFO_Data) & mask; - }else - { + if (boardtype.reg_type & ni_reg_m_series_mask) { + data[n] = + ni_readl(M_Offset_AI_FIFO_Data) & mask; + } else { d = ni_readw(ADC_FIFO_Data_Register); - d += signbits; /* subtle: needs to be short addition */ + d += signbits; /* subtle: needs to be short addition */ data[n] = d; } } @@ -1726,14 +1802,14 @@ static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *i return insn->n; } -void ni_prime_channelgain_list(comedi_device *dev) +void ni_prime_channelgain_list(comedi_device * dev) { int i; devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register); - for(i = 0; i < NI_TIMEOUT; ++i) - { - if(!(devpriv->stc_readw(dev, AI_Status_1_Register) & AI_FIFO_Empty_St)) - { + for (i = 0; i < NI_TIMEOUT; ++i) { + if (!(devpriv->stc_readw(dev, + AI_Status_1_Register) & + AI_FIFO_Empty_St)) { devpriv->stc_writew(dev, 1, ADC_FIFO_Clear); return; } @@ -1742,8 +1818,8 @@ void ni_prime_channelgain_list(comedi_device *dev) rt_printk("ni_mio_common: timeout loading channel/gain list\n"); } -static void ni_m_series_load_channelgain_list(comedi_device *dev,unsigned int n_chan, - unsigned int *list) +static void ni_m_series_load_channelgain_list(comedi_device * dev, + unsigned int n_chan, unsigned int *list) { unsigned int chan, range, aref; unsigned int i; @@ -1753,9 +1829,8 @@ static void ni_m_series_load_channelgain_list(comedi_device *dev,unsigned int n_ devpriv->stc_writew(dev, 1, Configuration_Memory_Clear); -// offset = 1 << (boardtype.adbits - 1); - if((list[0] & CR_ALT_SOURCE)) - { +// offset = 1 << (boardtype.adbits - 1); + if ((list[0] & CR_ALT_SOURCE)) { unsigned bypass_bits; chan = CR_CHAN(list[0]); range = CR_RANGE(list[0]); @@ -1763,22 +1838,23 @@ static void ni_m_series_load_channelgain_list(comedi_device *dev,unsigned int n_ dither = ((list[0] & CR_ALT_FILTER) != 0); bypass_bits = MSeries_AI_Bypass_Config_FIFO_Bit; bypass_bits |= chan; - bypass_bits |= (devpriv->ai_calib_source) & (MSeries_AI_Bypass_Cal_Sel_Pos_Mask | - MSeries_AI_Bypass_Cal_Sel_Neg_Mask | MSeries_AI_Bypass_Mode_Mux_Mask | + bypass_bits |= + (devpriv-> + ai_calib_source) & (MSeries_AI_Bypass_Cal_Sel_Pos_Mask | + MSeries_AI_Bypass_Cal_Sel_Neg_Mask | + MSeries_AI_Bypass_Mode_Mux_Mask | MSeries_AO_Bypass_AO_Cal_Sel_Mask); bypass_bits |= MSeries_AI_Bypass_Gain_Bits(range_code); - if(dither) + if (dither) bypass_bits |= MSeries_AI_Bypass_Dither_Bit; // don't use 2's complement encoding bypass_bits |= MSeries_AI_Bypass_Polarity_Bit; ni_writel(bypass_bits, M_Offset_AI_Config_FIFO_Bypass); - }else - { + } else { ni_writel(0, M_Offset_AI_Config_FIFO_Bypass); } offset = 0; - for(i = 0; i < n_chan; i++) - { + for (i = 0; i < n_chan; i++) { unsigned config_bits = 0; chan = CR_CHAN(list[i]); aref = CR_AREF(list[i]); @@ -1787,25 +1863,30 @@ static void ni_m_series_load_channelgain_list(comedi_device *dev,unsigned int n_ range_code = ni_gainlkup[boardtype.gainlkup][range]; devpriv->ai_offset[i] = offset; - switch( aref ) - { - case AREF_DIFF: - config_bits |= MSeries_AI_Config_Channel_Type_Differential_Bits; - break; - case AREF_COMMON: - config_bits |= MSeries_AI_Config_Channel_Type_Common_Ref_Bits; - break; - case AREF_GROUND: - config_bits |= MSeries_AI_Config_Channel_Type_Ground_Ref_Bits; - break; - case AREF_OTHER: - break; + switch (aref) { + case AREF_DIFF: + config_bits |= + MSeries_AI_Config_Channel_Type_Differential_Bits; + break; + case AREF_COMMON: + config_bits |= + MSeries_AI_Config_Channel_Type_Common_Ref_Bits; + break; + case AREF_GROUND: + config_bits |= + MSeries_AI_Config_Channel_Type_Ground_Ref_Bits; + break; + case AREF_OTHER: + break; } config_bits |= MSeries_AI_Config_Channel_Bits(chan); - config_bits |= MSeries_AI_Config_Bank_Bits(boardtype.reg_type, chan); + config_bits |= + MSeries_AI_Config_Bank_Bits(boardtype.reg_type, chan); config_bits |= MSeries_AI_Config_Gain_Bits(range_code); - if(i == n_chan - 1) config_bits |= MSeries_AI_Config_Last_Channel_Bit; - if(dither) config_bits |= MSeries_AI_Config_Dither_Bit; + if (i == n_chan - 1) + config_bits |= MSeries_AI_Config_Last_Channel_Bit; + if (dither) + config_bits |= MSeries_AI_Config_Dither_Bit; // don't use 2's complement encoding config_bits |= MSeries_AI_Config_Polarity_Bit; ni_writew(config_bits, M_Offset_AI_Config_FIFO_Data); @@ -1842,119 +1923,131 @@ static void ni_m_series_load_channelgain_list(comedi_device *dev,unsigned int n_ * bits 0-2: channel * valid channels are 0-3 */ -static void ni_load_channelgain_list(comedi_device *dev,unsigned int n_chan, +static void ni_load_channelgain_list(comedi_device * dev, unsigned int n_chan, unsigned int *list) { - unsigned int chan,range,aref; + unsigned int chan, range, aref; unsigned int i; - unsigned int hi,lo; + unsigned int hi, lo; unsigned offset; unsigned int dither; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { ni_m_series_load_channelgain_list(dev, n_chan, list); return; } - if(n_chan == 1 && (boardtype.reg_type != ni_reg_611x) && (boardtype.reg_type != ni_reg_6143)){ - if(devpriv->changain_state && devpriv->changain_spec==list[0]){ + if (n_chan == 1 && (boardtype.reg_type != ni_reg_611x) + && (boardtype.reg_type != ni_reg_6143)) { + if (devpriv->changain_state + && devpriv->changain_spec == list[0]) { // ready to go. return; } - devpriv->changain_state=1; - devpriv->changain_spec=list[0]; - }else{ - devpriv->changain_state=0; + devpriv->changain_state = 1; + devpriv->changain_spec = list[0]; + } else { + devpriv->changain_state = 0; } - devpriv->stc_writew(dev, 1,Configuration_Memory_Clear); + devpriv->stc_writew(dev, 1, Configuration_Memory_Clear); // Set up Calibration mode if required - if(boardtype.reg_type == ni_reg_6143){ - if((list[0] & CR_ALT_SOURCE) && !devpriv->ai_calib_source_enabled){ + if (boardtype.reg_type == ni_reg_6143) { + if ((list[0] & CR_ALT_SOURCE) + && !devpriv->ai_calib_source_enabled) { // Strobe Relay enable bit - ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOn, Calibration_Channel_6143); - ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143); + ni_writew(devpriv-> + ai_calib_source | + Calibration_Channel_6143_RelayOn, + Calibration_Channel_6143); + ni_writew(devpriv->ai_calib_source, + Calibration_Channel_6143); devpriv->ai_calib_source_enabled = 1; msleep_interruptible(100); // Allow relays to change - } - else if(!(list[0] & CR_ALT_SOURCE) && devpriv->ai_calib_source_enabled){ + } else if (!(list[0] & CR_ALT_SOURCE) + && devpriv->ai_calib_source_enabled) { // Strobe Relay disable bit - ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOff, Calibration_Channel_6143); - ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143); + ni_writew(devpriv-> + ai_calib_source | + Calibration_Channel_6143_RelayOff, + Calibration_Channel_6143); + ni_writew(devpriv->ai_calib_source, + Calibration_Channel_6143); devpriv->ai_calib_source_enabled = 0; msleep_interruptible(100); // Allow relays to change } } - offset=1<<(boardtype.adbits-1); - for(i=0;iai_calib_source; - }else{ - chan=CR_CHAN(list[i]); + offset = 1 << (boardtype.adbits - 1); + for (i = 0; i < n_chan; i++) { + if ((boardtype.reg_type != ni_reg_6143) + && (list[i] & CR_ALT_SOURCE)) { + chan = devpriv->ai_calib_source; + } else { + chan = CR_CHAN(list[i]); } - aref=CR_AREF(list[i]); - range=CR_RANGE(list[i]); - dither=((list[i]&CR_ALT_FILTER)!=0); + aref = CR_AREF(list[i]); + range = CR_RANGE(list[i]); + dither = ((list[i] & CR_ALT_FILTER) != 0); /* fix the external/internal range differences */ range = ni_gainlkup[boardtype.gainlkup][range]; - if(boardtype.reg_type == ni_reg_611x) + if (boardtype.reg_type == ni_reg_611x) devpriv->ai_offset[i] = offset; else - devpriv->ai_offset[i] = (range&0x100)?0:offset; + devpriv->ai_offset[i] = (range & 0x100) ? 0 : offset; hi = 0; - if( ( list[i] & CR_ALT_SOURCE ) ) - { - if(boardtype.reg_type == ni_reg_611x) - ni_writew(CR_CHAN(list[i])&0x0003, Calibration_Channel_Select_611x); - }else - { - if(boardtype.reg_type == ni_reg_611x) + if ((list[i] & CR_ALT_SOURCE)) { + if (boardtype.reg_type == ni_reg_611x) + ni_writew(CR_CHAN(list[i]) & 0x0003, + Calibration_Channel_Select_611x); + } else { + if (boardtype.reg_type == ni_reg_611x) aref = AREF_DIFF; - else if(boardtype.reg_type == ni_reg_6143) + else if (boardtype.reg_type == ni_reg_6143) aref = AREF_OTHER; - switch( aref ) - { - case AREF_DIFF: - hi |= AI_DIFFERENTIAL; - break; - case AREF_COMMON: - hi |= AI_COMMON; - break; - case AREF_GROUND: - hi |= AI_GROUND; - break; - case AREF_OTHER: - break; + switch (aref) { + case AREF_DIFF: + hi |= AI_DIFFERENTIAL; + break; + case AREF_COMMON: + hi |= AI_COMMON; + break; + case AREF_GROUND: + hi |= AI_GROUND; + break; + case AREF_OTHER: + break; } } - hi |= AI_CONFIG_CHANNEL( chan ); + hi |= AI_CONFIG_CHANNEL(chan); - ni_writew(hi,Configuration_Memory_High); + ni_writew(hi, Configuration_Memory_High); - if(boardtype.reg_type != ni_reg_6143){ + if (boardtype.reg_type != ni_reg_6143) { lo = range; - if(i == n_chan - 1) lo |= AI_LAST_CHANNEL; - if( dither ) lo |= AI_DITHER; + if (i == n_chan - 1) + lo |= AI_LAST_CHANNEL; + if (dither) + lo |= AI_DITHER; - ni_writew(lo,Configuration_Memory_Low); + ni_writew(lo, Configuration_Memory_Low); } } /* prime the channel/gain list */ - if((boardtype.reg_type != ni_reg_611x) && (boardtype.reg_type != ni_reg_6143)){ + if ((boardtype.reg_type != ni_reg_611x) + && (boardtype.reg_type != ni_reg_6143)) { ni_prime_channelgain_list(dev); } } -static int ni_ns_to_timer(const comedi_device *dev, unsigned nanosec, int round_mode) +static int ni_ns_to_timer(const comedi_device * dev, unsigned nanosec, + int round_mode) { int divider; - switch(round_mode) - { + switch (round_mode) { case TRIG_ROUND_NEAREST: default: divider = (nanosec + devpriv->clock_ns / 2) / devpriv->clock_ns; @@ -1963,265 +2056,293 @@ static int ni_ns_to_timer(const comedi_device *dev, unsigned nanosec, int round_ divider = (nanosec) / devpriv->clock_ns; break; case TRIG_ROUND_UP: - divider=(nanosec + devpriv->clock_ns - 1) / devpriv->clock_ns; + divider = (nanosec + devpriv->clock_ns - 1) / devpriv->clock_ns; break; } return divider - 1; } -static unsigned ni_timer_to_ns(const comedi_device *dev, int timer) +static unsigned ni_timer_to_ns(const comedi_device * dev, int timer) { return devpriv->clock_ns * (timer + 1); } -static unsigned ni_min_ai_scan_period_ns(comedi_device *dev, unsigned num_channels) +static unsigned ni_min_ai_scan_period_ns(comedi_device * dev, + unsigned num_channels) { - switch(boardtype.reg_type) - { + switch (boardtype.reg_type) { case ni_reg_611x: case ni_reg_6143: - // simultaneously-sampled inputs + // simultaneously-sampled inputs return boardtype.ai_speed; break; default: - // multiplexed inputs + // multiplexed inputs break; }; return boardtype.ai_speed * num_channels; } -static int ni_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int ni_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; int sources; /* step 1: make sure trigger sources are trivially valid */ - if((cmd->flags & CMDF_WRITE)) - { + if ((cmd->flags & CMDF_WRITE)) { cmd->flags &= ~CMDF_WRITE; } - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_INT|TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_INT | TRIG_EXT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; sources = TRIG_TIMER | TRIG_EXT; - if((boardtype.reg_type == ni_reg_611x) || (boardtype.reg_type == ni_reg_6143)) sources |= TRIG_NOW; + if ((boardtype.reg_type == ni_reg_611x) + || (boardtype.reg_type == ni_reg_6143)) + sources |= TRIG_NOW; cmd->convert_src &= sources; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->start_src!=TRIG_NOW && - cmd->start_src!=TRIG_INT && - cmd->start_src!=TRIG_EXT)err++; - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT && - cmd->scan_begin_src!=TRIG_OTHER)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT && - cmd->convert_src!=TRIG_NOW)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; + if (cmd->start_src != TRIG_NOW && + cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_OTHER) + err++; + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_src==TRIG_EXT){ + if (cmd->start_src == TRIG_EXT) { /* external trigger */ unsigned int tmp = CR_CHAN(cmd->start_arg); - if(tmp > 16) tmp = 16; + if (tmp > 16) + tmp = 16; tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE)); - if(cmd->start_arg != tmp){ + if (cmd->start_arg != tmp) { cmd->start_arg = tmp; err++; } - }else{ - if(cmd->start_arg!=0){ + } else { + if (cmd->start_arg != 0) { /* true for both TRIG_NOW and TRIG_INT */ - cmd->start_arg=0; + cmd->start_arg = 0; err++; } } - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_arg < ni_min_ai_scan_period_ns(dev, cmd->chanlist_len)) - { - cmd->scan_begin_arg = ni_min_ai_scan_period_ns(dev, cmd->chanlist_len); + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < ni_min_ai_scan_period_ns(dev, + cmd->chanlist_len)) { + cmd->scan_begin_arg = + ni_min_ai_scan_period_ns(dev, + cmd->chanlist_len); err++; } - if(cmd->scan_begin_arg > devpriv->clock_ns * 0xffffff){ + if (cmd->scan_begin_arg > devpriv->clock_ns * 0xffffff) { cmd->scan_begin_arg = devpriv->clock_ns * 0xffffff; err++; } - }else if(cmd->scan_begin_src==TRIG_EXT){ + } else if (cmd->scan_begin_src == TRIG_EXT) { /* external trigger */ unsigned int tmp = CR_CHAN(cmd->scan_begin_arg); - if(tmp>16)tmp=16; + if (tmp > 16) + tmp = 16; tmp |= (cmd->scan_begin_arg & (CR_INVERT | CR_EDGE)); - if(cmd->scan_begin_arg!=tmp){ + if (cmd->scan_begin_arg != tmp) { cmd->scan_begin_arg = tmp; err++; } - }else{ /* TRIG_OTHER */ - if(cmd->scan_begin_arg){ - cmd->scan_begin_arg=0; + } else { /* TRIG_OTHER */ + if (cmd->scan_begin_arg) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->convert_src==TRIG_TIMER){ - if((boardtype.reg_type == ni_reg_611x) || (boardtype.reg_type == ni_reg_6143)){ - if(cmd->convert_arg != 0){ + if (cmd->convert_src == TRIG_TIMER) { + if ((boardtype.reg_type == ni_reg_611x) + || (boardtype.reg_type == ni_reg_6143)) { + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - }else{ - if(cmd->convert_argconvert_arg=boardtype.ai_speed; + } else { + if (cmd->convert_arg < boardtype.ai_speed) { + cmd->convert_arg = boardtype.ai_speed; err++; } - if(cmd->convert_arg>devpriv->clock_ns*0xffff){ - cmd->convert_arg=devpriv->clock_ns*0xffff; + if (cmd->convert_arg > devpriv->clock_ns * 0xffff) { + cmd->convert_arg = devpriv->clock_ns * 0xffff; err++; } } - }else if(cmd->convert_src == TRIG_EXT){ + } else if (cmd->convert_src == TRIG_EXT) { /* external trigger */ unsigned int tmp = CR_CHAN(cmd->convert_arg); - if(tmp>16)tmp=16; - tmp |= (cmd->convert_arg&(CR_ALT_FILTER|CR_INVERT)); - if(cmd->convert_arg!=tmp){ + if (tmp > 16) + tmp = 16; + tmp |= (cmd->convert_arg & (CR_ALT_FILTER | CR_INVERT)); + if (cmd->convert_arg != tmp) { cmd->convert_arg = tmp; err++; } - }else if(cmd->convert_src == TRIG_NOW){ - if(cmd->convert_arg != 0){ + } else if (cmd->convert_src == TRIG_NOW) { + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { unsigned int max_count = 0x01000000; - if(boardtype.reg_type == ni_reg_611x ) + if (boardtype.reg_type == ni_reg_611x) max_count -= num_adc_stages_611x; - if(cmd->stop_arg > max_count){ + if (cmd->stop_arg > max_count) { cmd->stop_arg = max_count; err++; } - if(cmd->stop_arg < 1){ + if (cmd->stop_arg < 1) { cmd->stop_arg = 1; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; - cmd->scan_begin_arg = ni_timer_to_ns(dev, ni_ns_to_timer(dev, cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK)); - if(tmp!=cmd->scan_begin_arg)err++; - } - if(cmd->convert_src==TRIG_TIMER){ - if((boardtype.reg_type != ni_reg_611x) && (boardtype.reg_type != ni_reg_6143)){ - tmp=cmd->convert_arg; - cmd->convert_arg = ni_timer_to_ns(dev, ni_ns_to_timer(dev, cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK)); - if(tmp!=cmd->convert_arg)err++; - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg) - { - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + cmd->scan_begin_arg = + ni_timer_to_ns(dev, ni_ns_to_timer(dev, + cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK)); + if (tmp != cmd->scan_begin_arg) + err++; + } + if (cmd->convert_src == TRIG_TIMER) { + if ((boardtype.reg_type != ni_reg_611x) + && (boardtype.reg_type != ni_reg_6143)) { + tmp = cmd->convert_arg; + cmd->convert_arg = + ni_timer_to_ns(dev, ni_ns_to_timer(dev, + cmd->convert_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; + if (err) + return 4; return 0; } -static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int ni_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - const comedi_cmd *cmd=&s->async->cmd; + const comedi_cmd *cmd = &s->async->cmd; int timer; - int mode1=0; /* mode1 is needed for both stop and convert */ - int mode2=0; - int start_stop_select=0; + int mode1 = 0; /* mode1 is needed for both stop and convert */ + int mode2 = 0; + int start_stop_select = 0; unsigned int stop_count; - int interrupt_a_enable=0; + int interrupt_a_enable = 0; MDPRINTK("ni_ai_cmd\n"); - if(dev->irq == 0) - { + if (dev->irq == 0) { comedi_error(dev, "cannot run command without an irq"); return -EIO; } ni_clear_ai_fifo(dev); - ni_load_channelgain_list(dev,cmd->chanlist_len,cmd->chanlist); + ni_load_channelgain_list(dev, cmd->chanlist_len, cmd->chanlist); /* start configuration */ - devpriv->stc_writew(dev, AI_Configuration_Start,Joint_Reset_Register); + devpriv->stc_writew(dev, AI_Configuration_Start, Joint_Reset_Register); /* disable analog triggering for now, since it * interferes with the use of pfi0 */ devpriv->an_trig_etc_reg &= ~Analog_Trigger_Enable; - devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, Analog_Trigger_Etc_Register); + devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, + Analog_Trigger_Etc_Register); - switch(cmd->start_src){ - case TRIG_INT: - case TRIG_NOW: - devpriv->stc_writew(dev, AI_START2_Select(0)| - AI_START1_Sync|AI_START1_Edge|AI_START1_Select(0), - AI_Trigger_Select_Register); - break; - case TRIG_EXT: + switch (cmd->start_src) { + case TRIG_INT: + case TRIG_NOW: + devpriv->stc_writew(dev, AI_START2_Select(0) | + AI_START1_Sync | AI_START1_Edge | AI_START1_Select(0), + AI_Trigger_Select_Register); + break; + case TRIG_EXT: { int chan = CR_CHAN(cmd->start_arg); - unsigned int bits = AI_START2_Select(0)| - AI_START1_Sync | - AI_START1_Select(chan + 1); + unsigned int bits = AI_START2_Select(0) | + AI_START1_Sync | AI_START1_Select(chan + 1); - if(cmd->start_arg & CR_INVERT) + if (cmd->start_arg & CR_INVERT) bits |= AI_START1_Polarity; - if(cmd->start_arg & CR_EDGE) + if (cmd->start_arg & CR_EDGE) bits |= AI_START1_Edge; - devpriv->stc_writew(dev, bits, AI_Trigger_Select_Register); + devpriv->stc_writew(dev, bits, + AI_Trigger_Select_Register); break; } } @@ -2231,75 +2352,78 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) mode2 &= ~AI_SC_Reload_Mode; devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); - if(cmd->chanlist_len == 1 || (boardtype.reg_type == ni_reg_611x) || (boardtype.reg_type == ni_reg_6143)){ + if (cmd->chanlist_len == 1 || (boardtype.reg_type == ni_reg_611x) + || (boardtype.reg_type == ni_reg_6143)) { start_stop_select |= AI_STOP_Polarity; - start_stop_select |= AI_STOP_Select( 31 ); // logic low + start_stop_select |= AI_STOP_Select(31); // logic low start_stop_select |= AI_STOP_Sync; - }else - { - start_stop_select |= AI_STOP_Select(19); // ai configuration memory + } else { + start_stop_select |= AI_STOP_Select(19); // ai configuration memory } - devpriv->stc_writew(dev, start_stop_select, AI_START_STOP_Select_Register); + devpriv->stc_writew(dev, start_stop_select, + AI_START_STOP_Select_Register); devpriv->ai_cmd2 = 0; - switch(cmd->stop_src){ + switch (cmd->stop_src) { case TRIG_COUNT: stop_count = cmd->stop_arg - 1; - if(boardtype.reg_type == ni_reg_611x){ + if (boardtype.reg_type == ni_reg_611x) { // have to take 3 stage adc pipeline into account stop_count += num_adc_stages_611x; } /* stage number of scans */ - devpriv->stc_writel(dev, stop_count, AI_SC_Load_A_Registers); + devpriv->stc_writel(dev, stop_count, AI_SC_Load_A_Registers); mode1 |= AI_Start_Stop | AI_Mode_1_Reserved | AI_Trigger_Once; - devpriv->stc_writew(dev, mode1,AI_Mode_1_Register); + devpriv->stc_writew(dev, mode1, AI_Mode_1_Register); /* load SC (Scan Count) */ - devpriv->stc_writew(dev, AI_SC_Load,AI_Command_1_Register); + devpriv->stc_writew(dev, AI_SC_Load, AI_Command_1_Register); devpriv->ai_continuous = 0; - if( stop_count == 0 ){ + if (stop_count == 0) { devpriv->ai_cmd2 |= AI_End_On_End_Of_Scan; interrupt_a_enable |= AI_STOP_Interrupt_Enable; // this is required to get the last sample for chanlist_len > 1, not sure why - if(cmd->chanlist_len > 1) - start_stop_select |= AI_STOP_Polarity | AI_STOP_Edge; + if (cmd->chanlist_len > 1) + start_stop_select |= + AI_STOP_Polarity | AI_STOP_Edge; } break; case TRIG_NONE: /* stage number of scans */ - devpriv->stc_writel(dev, 0,AI_SC_Load_A_Registers); + devpriv->stc_writel(dev, 0, AI_SC_Load_A_Registers); mode1 |= AI_Start_Stop | AI_Mode_1_Reserved | AI_Continuous; - devpriv->stc_writew(dev, mode1,AI_Mode_1_Register); + devpriv->stc_writew(dev, mode1, AI_Mode_1_Register); /* load SC (Scan Count) */ - devpriv->stc_writew(dev, AI_SC_Load,AI_Command_1_Register); + devpriv->stc_writew(dev, AI_SC_Load, AI_Command_1_Register); devpriv->ai_continuous = 1; break; } - switch(cmd->scan_begin_src){ + switch (cmd->scan_begin_src) { case TRIG_TIMER: /* - stop bits for non 611x boards - AI_SI_Special_Trigger_Delay=0 - AI_Pre_Trigger=0 - AI_START_STOP_Select_Register: - AI_START_Polarity=0 (?) rising edge - AI_START_Edge=1 edge triggered - AI_START_Sync=1 (?) - AI_START_Select=0 SI_TC - AI_STOP_Polarity=0 rising edge - AI_STOP_Edge=0 level - AI_STOP_Sync=1 - AI_STOP_Select=19 external pin (configuration mem) + stop bits for non 611x boards + AI_SI_Special_Trigger_Delay=0 + AI_Pre_Trigger=0 + AI_START_STOP_Select_Register: + AI_START_Polarity=0 (?) rising edge + AI_START_Edge=1 edge triggered + AI_START_Sync=1 (?) + AI_START_Select=0 SI_TC + AI_STOP_Polarity=0 rising edge + AI_STOP_Edge=0 level + AI_STOP_Sync=1 + AI_STOP_Select=19 external pin (configuration mem) */ start_stop_select |= AI_START_Edge | AI_START_Sync; - devpriv->stc_writew(dev, start_stop_select, AI_START_STOP_Select_Register); + devpriv->stc_writew(dev, start_stop_select, + AI_START_STOP_Select_Register); mode2 |= AI_SI_Reload_Mode(0); /* AI_SI_Initial_Load_Source=A */ @@ -2308,53 +2432,58 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); /* load SI */ - timer = ni_ns_to_timer(dev, cmd->scan_begin_arg, TRIG_ROUND_NEAREST); - devpriv->stc_writel(dev, timer,AI_SI_Load_A_Registers); - devpriv->stc_writew(dev, AI_SI_Load,AI_Command_1_Register); + timer = ni_ns_to_timer(dev, cmd->scan_begin_arg, + TRIG_ROUND_NEAREST); + devpriv->stc_writel(dev, timer, AI_SI_Load_A_Registers); + devpriv->stc_writew(dev, AI_SI_Load, AI_Command_1_Register); break; case TRIG_EXT: - if( cmd->scan_begin_arg & CR_EDGE ) + if (cmd->scan_begin_arg & CR_EDGE) start_stop_select |= AI_START_Edge; /* AI_START_Polarity==1 is falling edge */ - if( cmd->scan_begin_arg & CR_INVERT ) + if (cmd->scan_begin_arg & CR_INVERT) start_stop_select |= AI_START_Polarity; - if( cmd->scan_begin_src != cmd->convert_src || - ( cmd->scan_begin_arg & ~CR_EDGE ) != ( cmd->convert_arg & ~CR_EDGE ) ) + if (cmd->scan_begin_src != cmd->convert_src || + (cmd->scan_begin_arg & ~CR_EDGE) != + (cmd->convert_arg & ~CR_EDGE)) start_stop_select |= AI_START_Sync; - start_stop_select |= AI_START_Select(1 + CR_CHAN(cmd->scan_begin_arg)); - devpriv->stc_writew(dev, start_stop_select, AI_START_STOP_Select_Register); + start_stop_select |= + AI_START_Select(1 + CR_CHAN(cmd->scan_begin_arg)); + devpriv->stc_writew(dev, start_stop_select, + AI_START_STOP_Select_Register); break; } - switch(cmd->convert_src){ + switch (cmd->convert_src) { case TRIG_TIMER: case TRIG_NOW: - if( cmd->convert_arg == 0 || cmd->convert_src == TRIG_NOW ) + if (cmd->convert_arg == 0 || cmd->convert_src == TRIG_NOW) timer = 1; else - timer = ni_ns_to_timer(dev, cmd->convert_arg, TRIG_ROUND_NEAREST); - devpriv->stc_writew(dev, 1,AI_SI2_Load_A_Register); /* 0,0 does not work. */ - devpriv->stc_writew(dev, timer,AI_SI2_Load_B_Register); + timer = ni_ns_to_timer(dev, cmd->convert_arg, + TRIG_ROUND_NEAREST); + devpriv->stc_writew(dev, 1, AI_SI2_Load_A_Register); /* 0,0 does not work. */ + devpriv->stc_writew(dev, timer, AI_SI2_Load_B_Register); /* AI_SI2_Reload_Mode = alternate */ /* AI_SI2_Initial_Load_Source = A */ mode2 &= ~AI_SI2_Initial_Load_Source; mode2 |= AI_SI2_Reload_Mode; - devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); + devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); /* AI_SI2_Load */ - devpriv->stc_writew(dev, AI_SI2_Load,AI_Command_1_Register); + devpriv->stc_writew(dev, AI_SI2_Load, AI_Command_1_Register); - mode2 |= AI_SI2_Reload_Mode; // alternate - mode2 |= AI_SI2_Initial_Load_Source; // B + mode2 |= AI_SI2_Reload_Mode; // alternate + mode2 |= AI_SI2_Initial_Load_Source; // B - devpriv->stc_writew(dev, mode2,AI_Mode_2_Register); + devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); break; case TRIG_EXT: - mode1 |= AI_CONVERT_Source_Select(1+cmd->convert_arg); - if( ( cmd->convert_arg & CR_INVERT ) == 0 ) + mode1 |= AI_CONVERT_Source_Select(1 + cmd->convert_arg); + if ((cmd->convert_arg & CR_INVERT) == 0) mode1 |= AI_CONVERT_Source_Polarity; - devpriv->stc_writew(dev, mode1,AI_Mode_1_Register); + devpriv->stc_writew(dev, mode1, AI_Mode_1_Register); mode2 |= AI_Start_Stop_Gate_Enable | AI_SC_Gate_Enable; devpriv->stc_writew(dev, mode2, AI_Mode_2_Register); @@ -2362,41 +2491,47 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) break; } - if(dev->irq){ + if (dev->irq) { /* interrupt on FIFO, errors, SC_TC */ - interrupt_a_enable |= AI_Error_Interrupt_Enable| + interrupt_a_enable |= AI_Error_Interrupt_Enable | AI_SC_TC_Interrupt_Enable; #ifndef PCIDMA - interrupt_a_enable|=AI_FIFO_Interrupt_Enable; + interrupt_a_enable |= AI_FIFO_Interrupt_Enable; #endif - if(cmd->flags & TRIG_WAKE_EOS || (devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)){ + if (cmd->flags & TRIG_WAKE_EOS + || (devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)) { /* wake on end-of-scan */ - devpriv->aimode=AIMODE_SCAN; - }else{ - devpriv->aimode=AIMODE_HALF_FULL; + devpriv->aimode = AIMODE_SCAN; + } else { + devpriv->aimode = AIMODE_HALF_FULL; } - switch(devpriv->aimode){ + switch (devpriv->aimode) { case AIMODE_HALF_FULL: /*generate FIFO interrupts and DMA requests on half-full */ #ifdef PCIDMA - devpriv->stc_writew(dev, AI_FIFO_Mode_HF_to_E, AI_Mode_3_Register); + devpriv->stc_writew(dev, AI_FIFO_Mode_HF_to_E, + AI_Mode_3_Register); #else - devpriv->stc_writew(dev, AI_FIFO_Mode_HF, AI_Mode_3_Register); + devpriv->stc_writew(dev, AI_FIFO_Mode_HF, + AI_Mode_3_Register); #endif break; case AIMODE_SAMPLE: /*generate FIFO interrupts on non-empty */ - devpriv->stc_writew(dev, AI_FIFO_Mode_NE, AI_Mode_3_Register); + devpriv->stc_writew(dev, AI_FIFO_Mode_NE, + AI_Mode_3_Register); break; case AIMODE_SCAN: #ifdef PCIDMA - devpriv->stc_writew(dev, AI_FIFO_Mode_NE, AI_Mode_3_Register); + devpriv->stc_writew(dev, AI_FIFO_Mode_NE, + AI_Mode_3_Register); #else - devpriv->stc_writew(dev, AI_FIFO_Mode_HF, AI_Mode_3_Register); + devpriv->stc_writew(dev, AI_FIFO_Mode_HF, + AI_Mode_3_Register); #endif interrupt_a_enable |= AI_STOP_Interrupt_Enable; break; @@ -2404,19 +2539,14 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) break; } - devpriv->stc_writew(dev, AI_Error_Interrupt_Ack | - AI_STOP_Interrupt_Ack | - AI_START_Interrupt_Ack | - AI_START2_Interrupt_Ack | - AI_START1_Interrupt_Ack | - AI_SC_TC_Interrupt_Ack | - AI_SC_TC_Error_Confirm, - Interrupt_A_Ack_Register); /* clear interrupts */ + devpriv->stc_writew(dev, AI_Error_Interrupt_Ack | AI_STOP_Interrupt_Ack | AI_START_Interrupt_Ack | AI_START2_Interrupt_Ack | AI_START1_Interrupt_Ack | AI_SC_TC_Interrupt_Ack | AI_SC_TC_Error_Confirm, Interrupt_A_Ack_Register); /* clear interrupts */ - ni_set_bits(dev, Interrupt_A_Enable_Register, interrupt_a_enable, 1); + ni_set_bits(dev, Interrupt_A_Enable_Register, + interrupt_a_enable, 1); - MDPRINTK("Interrupt_A_Enable_Register = 0x%04x\n",devpriv->int_a_enable_reg); - }else{ + MDPRINTK("Interrupt_A_Enable_Register = 0x%04x\n", + devpriv->int_a_enable_reg); + } else { /* interrupt on nothing */ ni_set_bits(dev, Interrupt_A_Enable_Register, ~0, 0); @@ -2425,16 +2555,18 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) } /* end configuration */ - devpriv->stc_writew(dev, AI_Configuration_End,Joint_Reset_Register); + devpriv->stc_writew(dev, AI_Configuration_End, Joint_Reset_Register); - switch(cmd->scan_begin_src){ + switch (cmd->scan_begin_src) { case TRIG_TIMER: - devpriv->stc_writew(dev, AI_SI2_Arm | AI_SI_Arm | AI_DIV_Arm | AI_SC_Arm, + devpriv->stc_writew(dev, + AI_SI2_Arm | AI_SI_Arm | AI_DIV_Arm | AI_SC_Arm, AI_Command_1_Register); break; case TRIG_EXT: /* XXX AI_SI_Arm? */ - devpriv->stc_writew(dev, AI_SI2_Arm | AI_SI_Arm | AI_DIV_Arm | AI_SC_Arm, + devpriv->stc_writew(dev, + AI_SI2_Arm | AI_SI_Arm | AI_DIV_Arm | AI_SC_Arm, AI_Command_1_Register); break; } @@ -2442,19 +2574,21 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) #ifdef PCIDMA { int retval = ni_ai_setup_MITE_dma(dev); - if(retval) return retval; + if (retval) + return retval; } //mite_dump_regs(devpriv->mite); #endif - switch(cmd->start_src){ + switch (cmd->start_src) { case TRIG_NOW: /* AI_START1_Pulse */ - devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, AI_Command_2_Register ); - s->async->inttrig=NULL; + devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, + AI_Command_2_Register); + s->async->inttrig = NULL; break; case TRIG_EXT: - s->async->inttrig=NULL; + s->async->inttrig = NULL; break; case TRIG_INT: s->async->inttrig = &ni_ai_inttrig; @@ -2466,63 +2600,63 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int ni_ai_inttrig(comedi_device *dev,comedi_subdevice *s, +static int ni_ai_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { - if(trignum!=0)return -EINVAL; + if (trignum != 0) + return -EINVAL; - devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, AI_Command_2_Register ); - s->async->inttrig=NULL; + devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, + AI_Command_2_Register); + s->async->inttrig = NULL; return 1; } -static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static int ni_ai_config_analog_trig(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); -static int ni_ai_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_ai_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n<1)return -EINVAL; + if (insn->n < 1) + return -EINVAL; - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_ANALOG_TRIG: - return ni_ai_config_analog_trig(dev,s,insn,data); + return ni_ai_config_analog_trig(dev, s, insn, data); case INSN_CONFIG_ALT_SOURCE: - if(boardtype.reg_type & ni_reg_m_series_mask) - { - if(data[1] & ~(MSeries_AI_Bypass_Cal_Sel_Pos_Mask | - MSeries_AI_Bypass_Cal_Sel_Neg_Mask | MSeries_AI_Bypass_Mode_Mux_Mask | - MSeries_AO_Bypass_AO_Cal_Sel_Mask)) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { + if (data[1] & ~(MSeries_AI_Bypass_Cal_Sel_Pos_Mask | + MSeries_AI_Bypass_Cal_Sel_Neg_Mask | + MSeries_AI_Bypass_Mode_Mux_Mask | + MSeries_AO_Bypass_AO_Cal_Sel_Mask)) { return -EINVAL; } devpriv->ai_calib_source = data[1]; - } else if(boardtype.reg_type == ni_reg_6143) - { + } else if (boardtype.reg_type == ni_reg_6143) { unsigned int calib_source; calib_source = data[1] & 0xf; - - if(calib_source > 0xF) + if (calib_source > 0xF) return -EINVAL; devpriv->ai_calib_source = calib_source; ni_writew(calib_source, Calibration_Channel_6143); - }else - { + } else { unsigned int calib_source; unsigned int calib_source_adjust; calib_source = data[1] & 0xf; - calib_source_adjust = ( data[1] >> 4 ) & 0xff; + calib_source_adjust = (data[1] >> 4) & 0xff; - if(calib_source >= 8) + if (calib_source >= 8) return -EINVAL; devpriv->ai_calib_source = calib_source; - if(boardtype.reg_type == ni_reg_611x){ - ni_writeb( calib_source_adjust, Cal_Gain_Select_611x ); + if (boardtype.reg_type == ni_reg_611x) { + ni_writeb(calib_source_adjust, + Cal_Gain_Select_611x); } } return 2; @@ -2533,31 +2667,32 @@ static int ni_ai_insn_config(comedi_device *dev,comedi_subdevice *s, return -EINVAL; } -static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_ai_config_analog_trig(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - unsigned int a,b,modebits; - int err=0; + unsigned int a, b, modebits; + int err = 0; /* data[1] is flags * data[2] is analog line * data[3] is set level * data[4] is reset level */ - if(!boardtype.has_analog_trig)return -EINVAL; - if((data[1]&0xffff0000) != COMEDI_EV_SCAN_BEGIN){ - data[1]&= (COMEDI_EV_SCAN_BEGIN | 0xffff); + if (!boardtype.has_analog_trig) + return -EINVAL; + if ((data[1] & 0xffff0000) != COMEDI_EV_SCAN_BEGIN) { + data[1] &= (COMEDI_EV_SCAN_BEGIN | 0xffff); err++; } - if(data[2]>=boardtype.n_adchan){ - data[2]=boardtype.n_adchan-1; + if (data[2] >= boardtype.n_adchan) { + data[2] = boardtype.n_adchan - 1; err++; } - if(data[3]>255){ /* a */ - data[3]=255; + if (data[3] > 255) { /* a */ + data[3] = 255; err++; } - if(data[4]>255){ /* b */ - data[4]=255; + if (data[4] > 255) { /* b */ + data[4] = 255; err++; } /* @@ -2566,29 +2701,31 @@ static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, * 10 reset * * modes: - * 1 level: +b- +a- - * high mode 00 00 01 10 - * low mode 00 00 10 01 + * 1 level: +b- +a- + * high mode 00 00 01 10 + * low mode 00 00 10 01 * 2 level: (a>4); + a = data[4]; + b = data[3]; + modebits = + ((data[1] & 0xf) << 4) | ((data[1] & 0xf0) >> + 4); } devpriv->atrig_low = a; devpriv->atrig_high = b; - switch(modebits){ + switch (modebits) { case 0x81: /* low hysteresis mode */ devpriv->atrig_mode = 6; break; @@ -2599,16 +2736,16 @@ static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, devpriv->atrig_mode = 2; break; default: - data[1]&=~0xff; + data[1] &= ~0xff; err++; } - }else{ + } else { /* one level mode */ - if(b!=0){ - data[4]=0; + if (b != 0) { + data[4] = 0; err++; } - switch(modebits){ + switch (modebits) { case 0x06: /* high window mode */ devpriv->atrig_high = a; devpriv->atrig_mode = 0; @@ -2618,41 +2755,42 @@ static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, devpriv->atrig_mode = 1; break; default: - data[1]&=~0xff; + data[1] &= ~0xff; err++; } } - if(err)return -EAGAIN; + if (err) + return -EAGAIN; return 5; } /* munge data from unsigned to 2's complement for analog output bipolar modes */ -static void ni_ao_munge(comedi_device *dev, comedi_subdevice *s, - void *data, unsigned int num_bytes, unsigned int chan_index ) +static void ni_ao_munge(comedi_device * dev, comedi_subdevice * s, + void *data, unsigned int num_bytes, unsigned int chan_index) { comedi_async *async = s->async; unsigned int range; unsigned int i; unsigned int offset; - unsigned int length = num_bytes / sizeof( sampl_t ); + unsigned int length = num_bytes / sizeof(sampl_t); sampl_t *array = data; offset = 1 << (boardtype.aobits - 1); - for(i = 0; i < length; i++) - { - range = CR_RANGE( async->cmd.chanlist[ chan_index ] ); - if(boardtype.ao_unipolar == 0 || (range & 1) == 0 ) + for (i = 0; i < length; i++) { + range = CR_RANGE(async->cmd.chanlist[chan_index]); + if (boardtype.ao_unipolar == 0 || (range & 1) == 0) array[i] -= offset; #ifdef PCIDMA - array[i] = cpu_to_le16( array[i] ); + array[i] = cpu_to_le16(array[i]); #endif chan_index++; chan_index %= async->cmd.chanlist_len; } } -static int ni_m_series_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s, - unsigned int chanspec[], unsigned int n_chans, int timed) +static int ni_m_series_ao_config_chanlist(comedi_device * dev, + comedi_subdevice * s, unsigned int chanspec[], unsigned int n_chans, + int timed) { unsigned int range; unsigned int chan; @@ -2660,20 +2798,17 @@ static int ni_m_series_ao_config_chanlist(comedi_device *dev, comedi_subdevice * int i; int invert = 0; - for(i = 0; i < boardtype.n_aochan; ++i) - { + for (i = 0; i < boardtype.n_aochan; ++i) { ni_writeb(0xf, M_Offset_AO_Waveform_Order(i)); } - for(i=0;irange_table->range + range; invert = 0; conf = 0; - switch(krange->max - krange->min) - { + switch (krange->max - krange->min) { case 20000000: conf |= MSeries_AO_DAC_Reference_10V_Internal_Bits; ni_writeb(0, M_Offset_AO_Reference_Attenuation(chan)); @@ -2684,18 +2819,20 @@ static int ni_m_series_ao_config_chanlist(comedi_device *dev, comedi_subdevice * break; case 4000000: conf |= MSeries_AO_DAC_Reference_10V_Internal_Bits; - ni_writeb(MSeries_Attenuate_x5_Bit, M_Offset_AO_Reference_Attenuation(chan)); + ni_writeb(MSeries_Attenuate_x5_Bit, + M_Offset_AO_Reference_Attenuation(chan)); break; case 2000000: conf |= MSeries_AO_DAC_Reference_5V_Internal_Bits; - ni_writeb(MSeries_Attenuate_x5_Bit, M_Offset_AO_Reference_Attenuation(chan)); + ni_writeb(MSeries_Attenuate_x5_Bit, + M_Offset_AO_Reference_Attenuation(chan)); break; default: - rt_printk("%s: bug! unhandled ao reference voltage\n", __FUNCTION__); + rt_printk("%s: bug! unhandled ao reference voltage\n", + __FUNCTION__); break; } - switch(krange->max + krange->min) - { + switch (krange->max + krange->min) { case 0: conf |= MSeries_AO_DAC_Offset_0V_Bits; break; @@ -2703,10 +2840,12 @@ static int ni_m_series_ao_config_chanlist(comedi_device *dev, comedi_subdevice * conf |= MSeries_AO_DAC_Offset_5V_Bits; break; default: - rt_printk("%s: bug! unhandled ao offset voltage\n", __FUNCTION__); + rt_printk("%s: bug! unhandled ao offset voltage\n", + __FUNCTION__); break; } - if(timed) conf |= MSeries_AO_Update_Timed_Bit; + if (timed) + conf |= MSeries_AO_Update_Timed_Bit; ni_writeb(conf, M_Offset_AO_Config_Bank(chan)); devpriv->ao_conf[chan] = conf; ni_writeb(i, M_Offset_AO_Waveform_Order(chan)); @@ -2714,7 +2853,7 @@ static int ni_m_series_ao_config_chanlist(comedi_device *dev, comedi_subdevice * return invert; } -static int ni_old_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s, +static int ni_old_ao_config_chanlist(comedi_device * dev, comedi_subdevice * s, unsigned int chanspec[], unsigned int n_chans) { unsigned int range; @@ -2723,78 +2862,78 @@ static int ni_old_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s, int i; int invert = 0; - for(i=0;iao_conf[chan] = conf; } return invert; } -static int ni_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s, +static int ni_ao_config_chanlist(comedi_device * dev, comedi_subdevice * s, unsigned int chanspec[], unsigned int n_chans, int timed) { - if(boardtype.reg_type & ni_reg_m_series_mask) - return ni_m_series_ao_config_chanlist(dev, s, chanspec, n_chans, timed); + if (boardtype.reg_type & ni_reg_m_series_mask) + return ni_m_series_ao_config_chanlist(dev, s, chanspec, n_chans, + timed); else return ni_old_ao_config_chanlist(dev, s, chanspec, n_chans); } -static int ni_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->ao[CR_CHAN(insn->chanspec)]; return 1; } -static int ni_ao_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int chan = CR_CHAN(insn->chanspec); unsigned int invert; - invert = ni_ao_config_chanlist(dev,s,&insn->chanspec, 1, 0); + invert = ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0); devpriv->ao[chan] = data[0]; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { ni_writew(data[0], M_Offset_DAC_Direct_Data(chan)); - } - else - ni_writew(data[0] ^ invert,(chan)? DAC1_Direct_Data : DAC0_Direct_Data); + } else + ni_writew(data[0] ^ invert, + (chan) ? DAC1_Direct_Data : DAC0_Direct_Data); return 1; } -static int ni_ao_insn_write_671x(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_ao_insn_write_671x(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int chan = CR_CHAN(insn->chanspec); unsigned int invert; @@ -2802,7 +2941,7 @@ static int ni_ao_insn_write_671x(comedi_device *dev,comedi_subdevice *s, ao_win_out(1 << chan, AO_Immediate_671x); invert = 1 << (boardtype.aobits - 1); - ni_ao_config_chanlist(dev,s,&insn->chanspec, 1, 0); + ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0); devpriv->ao[chan] = data[0]; ao_win_out(data[0] ^ invert, DACx_Direct_Data_671x(chan)); @@ -2810,7 +2949,7 @@ static int ni_ao_insn_write_671x(comedi_device *dev,comedi_subdevice *s, return 1; } -static int ni_ao_inttrig(comedi_device *dev,comedi_subdevice *s, +static int ni_ao_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { int ret; @@ -2818,81 +2957,90 @@ static int ni_ao_inttrig(comedi_device *dev,comedi_subdevice *s, int i; static const int timeout = 1000; - if(trignum!=0) return -EINVAL; + if (trignum != 0) + return -EINVAL; /* Null trig at beginning prevent ao start trigger from executing more than - once per command (and doing things like trying to allocate the ao dma channel - multiple times) */ + once per command (and doing things like trying to allocate the ao dma channel + multiple times) */ s->async->inttrig = NULL; - ni_set_bits(dev, Interrupt_B_Enable_Register, AO_FIFO_Interrupt_Enable | AO_Error_Interrupt_Enable, 0); + ni_set_bits(dev, Interrupt_B_Enable_Register, + AO_FIFO_Interrupt_Enable | AO_Error_Interrupt_Enable, 0); interrupt_b_bits = AO_Error_Interrupt_Enable; #ifdef PCIDMA devpriv->stc_writew(dev, 1, DAC_FIFO_Clear); - if(boardtype.reg_type & ni_reg_6xxx_mask) + if (boardtype.reg_type & ni_reg_6xxx_mask) ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x); ret = ni_ao_setup_MITE_dma(dev); - if(ret) return ret; + if (ret) + return ret; ret = ni_ao_wait_for_dma_load(dev); - if(ret < 0) return ret; + if (ret < 0) + return ret; #else - ret = ni_ao_prep_fifo(dev,s); - if(ret==0)return -EPIPE; + ret = ni_ao_prep_fifo(dev, s); + if (ret == 0) + return -EPIPE; interrupt_b_bits |= AO_FIFO_Interrupt_Enable; #endif - devpriv->stc_writew(dev, devpriv->ao_mode3|AO_Not_An_UPDATE,AO_Mode_3_Register); - devpriv->stc_writew(dev, devpriv->ao_mode3,AO_Mode_3_Register); + devpriv->stc_writew(dev, devpriv->ao_mode3 | AO_Not_An_UPDATE, + AO_Mode_3_Register); + devpriv->stc_writew(dev, devpriv->ao_mode3, AO_Mode_3_Register); /* wait for DACs to be loaded */ - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { comedi_udelay(1); - if((devpriv->stc_readw(dev, Joint_Status_2_Register) & AO_TMRDACWRs_In_Progress_St) == 0) + if ((devpriv->stc_readw(dev, + Joint_Status_2_Register) & + AO_TMRDACWRs_In_Progress_St) == 0) break; } - if(i == timeout) - { - comedi_error(dev, "timed out waiting for AO_TMRDACWRs_In_Progress_St to clear"); + if (i == timeout) { + comedi_error(dev, + "timed out waiting for AO_TMRDACWRs_In_Progress_St to clear"); return -EIO; } // stc manual says we are need to clear error interrupt after AO_TMRDACWRs_In_Progress_St clears - devpriv->stc_writew(dev, AO_Error_Interrupt_Ack, Interrupt_B_Ack_Register); + devpriv->stc_writew(dev, AO_Error_Interrupt_Ack, + Interrupt_B_Ack_Register); ni_set_bits(dev, Interrupt_B_Enable_Register, interrupt_b_bits, 1); - devpriv->stc_writew(dev, devpriv->ao_cmd1|AO_UI_Arm|AO_UC_Arm|AO_BC_Arm|AO_DAC1_Update_Mode|AO_DAC0_Update_Mode, + devpriv->stc_writew(dev, + devpriv-> + ao_cmd1 | AO_UI_Arm | AO_UC_Arm | AO_BC_Arm | + AO_DAC1_Update_Mode | AO_DAC0_Update_Mode, AO_Command_1_Register); - devpriv->stc_writew(dev, devpriv->ao_cmd2|AO_START1_Pulse,AO_Command_2_Register); + devpriv->stc_writew(dev, devpriv->ao_cmd2 | AO_START1_Pulse, + AO_Command_2_Register); return 0; } -static int ni_ao_cmd(comedi_device *dev,comedi_subdevice *s) +static int ni_ao_cmd(comedi_device * dev, comedi_subdevice * s) { const comedi_cmd *cmd = &s->async->cmd; int bits; int i; unsigned trigvar; - if(dev->irq == 0) - { + if (dev->irq == 0) { comedi_error(dev, "cannot run command without an irq"); return -EIO; } - devpriv->stc_writew(dev, AO_Configuration_Start,Joint_Reset_Register); + devpriv->stc_writew(dev, AO_Configuration_Start, Joint_Reset_Register); - devpriv->stc_writew(dev, AO_Disarm,AO_Command_1_Register); + devpriv->stc_writew(dev, AO_Disarm, AO_Command_1_Register); - if(boardtype.reg_type & ni_reg_6xxx_mask) - { + if (boardtype.reg_type & ni_reg_6xxx_mask) { ao_win_out(CLEAR_WG, AO_Misc_611x); bits = 0; - for(i = 0; i < cmd->chanlist_len; i++) - { + for (i = 0; i < cmd->chanlist_len; i++) { int chan; chan = CR_CHAN(cmd->chanlist[i]); @@ -2904,62 +3052,68 @@ static int ni_ao_cmd(comedi_device *dev,comedi_subdevice *s) ni_ao_config_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len, 1); - if(cmd->stop_src==TRIG_NONE){ - devpriv->ao_mode1|=AO_Continuous; - devpriv->ao_mode1&=~AO_Trigger_Once; - }else{ - devpriv->ao_mode1&=~AO_Continuous; - devpriv->ao_mode1|=AO_Trigger_Once; - } - devpriv->stc_writew(dev, devpriv->ao_mode1,AO_Mode_1_Register); - devpriv->ao_trigger_select&=~(AO_START1_Polarity|AO_START1_Select(-1)); - devpriv->ao_trigger_select|=AO_START1_Edge|AO_START1_Sync; - devpriv->stc_writew(dev, devpriv->ao_trigger_select,AO_Trigger_Select_Register); - devpriv->ao_mode3&=~AO_Trigger_Length; - devpriv->stc_writew(dev, devpriv->ao_mode3,AO_Mode_3_Register); - - devpriv->stc_writew(dev, devpriv->ao_mode1,AO_Mode_1_Register); - devpriv->ao_mode2&=~AO_BC_Initial_Load_Source; - devpriv->stc_writew(dev, devpriv->ao_mode2,AO_Mode_2_Register); - if(cmd->stop_src==TRIG_NONE){ - devpriv->stc_writel(dev, 0xffffff,AO_BC_Load_A_Register); - }else{ - devpriv->stc_writel(dev, 0,AO_BC_Load_A_Register); - } - devpriv->stc_writew(dev, AO_BC_Load,AO_Command_1_Register); - devpriv->ao_mode2&=~AO_UC_Initial_Load_Source; - devpriv->stc_writew(dev, devpriv->ao_mode2,AO_Mode_2_Register); - switch(cmd->stop_src){ + if (cmd->stop_src == TRIG_NONE) { + devpriv->ao_mode1 |= AO_Continuous; + devpriv->ao_mode1 &= ~AO_Trigger_Once; + } else { + devpriv->ao_mode1 &= ~AO_Continuous; + devpriv->ao_mode1 |= AO_Trigger_Once; + } + devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register); + devpriv->ao_trigger_select &= + ~(AO_START1_Polarity | AO_START1_Select(-1)); + devpriv->ao_trigger_select |= AO_START1_Edge | AO_START1_Sync; + devpriv->stc_writew(dev, devpriv->ao_trigger_select, + AO_Trigger_Select_Register); + devpriv->ao_mode3 &= ~AO_Trigger_Length; + devpriv->stc_writew(dev, devpriv->ao_mode3, AO_Mode_3_Register); + + devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register); + devpriv->ao_mode2 &= ~AO_BC_Initial_Load_Source; + devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register); + if (cmd->stop_src == TRIG_NONE) { + devpriv->stc_writel(dev, 0xffffff, AO_BC_Load_A_Register); + } else { + devpriv->stc_writel(dev, 0, AO_BC_Load_A_Register); + } + devpriv->stc_writew(dev, AO_BC_Load, AO_Command_1_Register); + devpriv->ao_mode2 &= ~AO_UC_Initial_Load_Source; + devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register); + switch (cmd->stop_src) { case TRIG_COUNT: - devpriv->stc_writel(dev, cmd->stop_arg,AO_UC_Load_A_Register); - devpriv->stc_writew(dev, AO_UC_Load,AO_Command_1_Register); - devpriv->stc_writel(dev, cmd->stop_arg - 1,AO_UC_Load_A_Register); + devpriv->stc_writel(dev, cmd->stop_arg, AO_UC_Load_A_Register); + devpriv->stc_writew(dev, AO_UC_Load, AO_Command_1_Register); + devpriv->stc_writel(dev, cmd->stop_arg - 1, + AO_UC_Load_A_Register); break; case TRIG_NONE: - devpriv->stc_writel(dev, 0xffffff,AO_UC_Load_A_Register); - devpriv->stc_writew(dev, AO_UC_Load,AO_Command_1_Register); - devpriv->stc_writel(dev, 0xffffff,AO_UC_Load_A_Register); + devpriv->stc_writel(dev, 0xffffff, AO_UC_Load_A_Register); + devpriv->stc_writew(dev, AO_UC_Load, AO_Command_1_Register); + devpriv->stc_writel(dev, 0xffffff, AO_UC_Load_A_Register); break; default: - devpriv->stc_writel(dev, 0,AO_UC_Load_A_Register); - devpriv->stc_writew(dev, AO_UC_Load,AO_Command_1_Register); - devpriv->stc_writel(dev, cmd->stop_arg,AO_UC_Load_A_Register); + devpriv->stc_writel(dev, 0, AO_UC_Load_A_Register); + devpriv->stc_writew(dev, AO_UC_Load, AO_Command_1_Register); + devpriv->stc_writel(dev, cmd->stop_arg, AO_UC_Load_A_Register); } - devpriv->ao_mode1 &= ~(AO_UI_Source_Select(0x1f) | AO_UI_Source_Polarity | + devpriv->ao_mode1 &= + ~(AO_UI_Source_Select(0x1f) | AO_UI_Source_Polarity | AO_UPDATE_Source_Select(0x1f) | AO_UPDATE_Source_Polarity); - switch(cmd->scan_begin_src) - { + switch (cmd->scan_begin_src) { case TRIG_TIMER: devpriv->ao_cmd2 &= ~AO_BC_Gate_Enable; - trigvar = ni_ns_to_timer(dev, cmd->scan_begin_arg, TRIG_ROUND_NEAREST); + trigvar = + ni_ns_to_timer(dev, cmd->scan_begin_arg, + TRIG_ROUND_NEAREST); devpriv->stc_writel(dev, 1, AO_UI_Load_A_Register); devpriv->stc_writew(dev, AO_UI_Load, AO_Command_1_Register); devpriv->stc_writel(dev, trigvar, AO_UI_Load_A_Register); break; case TRIG_EXT: - devpriv->ao_mode1 |= AO_UPDATE_Source_Select(cmd->scan_begin_arg); - if(cmd->scan_begin_arg & CR_INVERT) + devpriv->ao_mode1 |= + AO_UPDATE_Source_Select(cmd->scan_begin_arg); + if (cmd->scan_begin_arg & CR_INVERT) devpriv->ao_mode1 |= AO_UPDATE_Source_Polarity; devpriv->ao_cmd2 |= AO_BC_Gate_Enable; break; @@ -2967,37 +3121,42 @@ static int ni_ao_cmd(comedi_device *dev,comedi_subdevice *s) BUG(); break; } - devpriv->stc_writew(dev, devpriv->ao_cmd2,AO_Command_2_Register); - devpriv->stc_writew(dev, devpriv->ao_mode1,AO_Mode_1_Register); - devpriv->ao_mode2&=~(AO_UI_Reload_Mode(3)|AO_UI_Initial_Load_Source); - devpriv->stc_writew(dev, devpriv->ao_mode2,AO_Mode_2_Register); + devpriv->stc_writew(dev, devpriv->ao_cmd2, AO_Command_2_Register); + devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register); + devpriv->ao_mode2 &= + ~(AO_UI_Reload_Mode(3) | AO_UI_Initial_Load_Source); + devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register); - if((boardtype.reg_type & ni_reg_6xxx_mask) == 0){ - if(cmd->scan_end_arg>1){ - devpriv->ao_mode1|=AO_Multiple_Channels; - devpriv->stc_writew(dev, AO_Number_Of_Channels(cmd->scan_end_arg-1)| - AO_UPDATE_Output_Select(AO_Update_Output_High_Z), + if ((boardtype.reg_type & ni_reg_6xxx_mask) == 0) { + if (cmd->scan_end_arg > 1) { + devpriv->ao_mode1 |= AO_Multiple_Channels; + devpriv->stc_writew(dev, + AO_Number_Of_Channels(cmd->scan_end_arg - + 1) | + AO_UPDATE_Output_Select + (AO_Update_Output_High_Z), AO_Output_Control_Register); - }else{ + } else { unsigned bits; - devpriv->ao_mode1&=~AO_Multiple_Channels; + devpriv->ao_mode1 &= ~AO_Multiple_Channels; bits = AO_UPDATE_Output_Select(AO_Update_Output_High_Z); - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { bits |= AO_Number_Of_Channels(0); - }else - { - bits |= AO_Number_Of_Channels(CR_CHAN(cmd->chanlist[0])); + } else { + bits |= AO_Number_Of_Channels(CR_CHAN(cmd-> + chanlist[0])); } - devpriv->stc_writew(dev, bits, AO_Output_Control_Register); + devpriv->stc_writew(dev, bits, + AO_Output_Control_Register); } - devpriv->stc_writew(dev, devpriv->ao_mode1,AO_Mode_1_Register); + devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register); } - devpriv->stc_writew(dev, AO_DAC0_Update_Mode|AO_DAC1_Update_Mode,AO_Command_1_Register); + devpriv->stc_writew(dev, AO_DAC0_Update_Mode | AO_DAC1_Update_Mode, + AO_Command_1_Register); - devpriv->ao_mode3|=AO_Stop_On_Overrun_Error; - devpriv->stc_writew(dev, devpriv->ao_mode3,AO_Mode_3_Register); + devpriv->ao_mode3 |= AO_Stop_On_Overrun_Error; + devpriv->stc_writew(dev, devpriv->ao_mode3, AO_Mode_3_Register); devpriv->ao_mode2 &= ~AO_FIFO_Mode_Mask; #ifdef PCIDMA @@ -3006,28 +3165,29 @@ static int ni_ao_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->ao_mode2 |= AO_FIFO_Mode_HF; #endif devpriv->ao_mode2 &= ~AO_FIFO_Retransmit_Enable; - devpriv->stc_writew(dev, devpriv->ao_mode2,AO_Mode_2_Register); + devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register); bits = AO_BC_Source_Select | AO_UPDATE_Pulse_Width | AO_TMRDACWR_Pulse_Width; - if( boardtype.ao_fifo_depth ) + if (boardtype.ao_fifo_depth) bits |= AO_FIFO_Enable; else bits |= AO_DMA_PIO_Control; #if 0 /* F Hess: windows driver does not set AO_Number_Of_DAC_Packages bit for 6281, - verified with bus analyzer. */ - if(boardtype.reg_type & ni_reg_m_series_mask) + verified with bus analyzer. */ + if (boardtype.reg_type & ni_reg_m_series_mask) bits |= AO_Number_Of_DAC_Packages; #endif devpriv->stc_writew(dev, bits, AO_Personal_Register); // enable sending of ao dma requests devpriv->stc_writew(dev, AO_AOFREQ_Enable, AO_Start_Select_Register); - devpriv->stc_writew(dev, AO_Configuration_End,Joint_Reset_Register); + devpriv->stc_writew(dev, AO_Configuration_End, Joint_Reset_Register); - if(cmd->stop_src==TRIG_COUNT) { - devpriv->stc_writew(dev, AO_BC_TC_Interrupt_Ack,Interrupt_B_Ack_Register); + if (cmd->stop_src == TRIG_COUNT) { + devpriv->stc_writew(dev, AO_BC_TC_Interrupt_Ack, + Interrupt_B_Ack_Register); ni_set_bits(dev, Interrupt_B_Enable_Register, AO_BC_TC_Interrupt_Enable, 1); } @@ -3037,105 +3197,116 @@ static int ni_ao_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int ni_ao_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int ni_ao_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - if((cmd->flags & CMDF_WRITE) == 0) - { + if ((cmd->flags & CMDF_WRITE) == 0) { cmd->flags |= CMDF_WRITE; } - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src == TRIG_TIMER) - { - if(cmd->scan_begin_arg < boardtype.ao_speed){ + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < boardtype.ao_speed) { cmd->scan_begin_arg = boardtype.ao_speed; err++; } - if(cmd->scan_begin_arg > devpriv->clock_ns * 0xffffff){ /* XXX check */ + if (cmd->scan_begin_arg > devpriv->clock_ns * 0xffffff) { /* XXX check */ cmd->scan_begin_arg = devpriv->clock_ns * 0xffffff; err++; } } - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + if (cmd->scan_end_arg != cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src==TRIG_COUNT){ /* XXX check */ - if(cmd->stop_arg>0x00ffffff){ - cmd->stop_arg=0x00ffffff; + if (cmd->stop_src == TRIG_COUNT) { /* XXX check */ + if (cmd->stop_arg > 0x00ffffff) { + cmd->stop_arg = 0x00ffffff; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; - cmd->scan_begin_arg = ni_timer_to_ns(dev, ni_ns_to_timer(dev, cmd->scan_begin_arg, cmd->flags&TRIG_ROUND_MASK)); - if(tmp!=cmd->scan_begin_arg)err++; + cmd->scan_begin_arg = + ni_timer_to_ns(dev, ni_ns_to_timer(dev, + cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK)); + if (tmp != cmd->scan_begin_arg) + err++; } - if(err)return 4; + if (err) + return 4; /* step 5: fix up chanlist */ - if(err)return 5; + if (err) + return 5; return 0; } - -static int ni_ao_reset(comedi_device *dev,comedi_subdevice *s) +static int ni_ao_reset(comedi_device * dev, comedi_subdevice * s) { //devpriv->ao0p=0x0000; //ni_writew(devpriv->ao0p,AO_Configuration); @@ -3145,31 +3316,32 @@ static int ni_ao_reset(comedi_device *dev,comedi_subdevice *s) ni_release_ao_mite_channel(dev); - devpriv->stc_writew(dev, AO_Configuration_Start,Joint_Reset_Register); - devpriv->stc_writew(dev, AO_Disarm,AO_Command_1_Register); - ni_set_bits(dev,Interrupt_B_Enable_Register,~0,0); + devpriv->stc_writew(dev, AO_Configuration_Start, Joint_Reset_Register); + devpriv->stc_writew(dev, AO_Disarm, AO_Command_1_Register); + ni_set_bits(dev, Interrupt_B_Enable_Register, ~0, 0); devpriv->stc_writew(dev, AO_BC_Source_Select, AO_Personal_Register); - devpriv->stc_writew(dev, 0x3f98,Interrupt_B_Ack_Register); + devpriv->stc_writew(dev, 0x3f98, Interrupt_B_Ack_Register); devpriv->stc_writew(dev, AO_BC_Source_Select | AO_UPDATE_Pulse_Width | AO_TMRDACWR_Pulse_Width, AO_Personal_Register); - devpriv->stc_writew(dev, 0,AO_Output_Control_Register); - devpriv->stc_writew(dev, 0,AO_Start_Select_Register); - devpriv->ao_cmd1=0; - devpriv->stc_writew(dev, devpriv->ao_cmd1,AO_Command_1_Register); - devpriv->ao_cmd2=0; + devpriv->stc_writew(dev, 0, AO_Output_Control_Register); + devpriv->stc_writew(dev, 0, AO_Start_Select_Register); + devpriv->ao_cmd1 = 0; + devpriv->stc_writew(dev, devpriv->ao_cmd1, AO_Command_1_Register); + devpriv->ao_cmd2 = 0; devpriv->stc_writew(dev, devpriv->ao_cmd2, AO_Command_2_Register); - devpriv->ao_mode1=0; + devpriv->ao_mode1 = 0; devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register); - devpriv->ao_mode2=0; + devpriv->ao_mode2 = 0; devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register); - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) devpriv->ao_mode3 = AO_Last_Gate_Disable; else devpriv->ao_mode3 = 0; devpriv->stc_writew(dev, devpriv->ao_mode3, AO_Mode_3_Register); devpriv->ao_trigger_select = 0; - devpriv->stc_writew(dev, devpriv->ao_trigger_select,AO_Trigger_Select_Register); - if(boardtype.reg_type & ni_reg_6xxx_mask){ + devpriv->stc_writew(dev, devpriv->ao_trigger_select, + AO_Trigger_Select_Register); + if (boardtype.reg_type & ni_reg_6xxx_mask) { ao_win_out(0x3, AO_Immediate_671x); ao_win_out(CLEAR_WG, AO_Misc_611x); } @@ -3180,22 +3352,25 @@ static int ni_ao_reset(comedi_device *dev,comedi_subdevice *s) // digital io -static int ni_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { #ifdef DEBUG_DIO rt_printk("ni_dio_insn_config() chan=%d io=%d\n", - CR_CHAN(insn->chanspec),data[0]); + CR_CHAN(insn->chanspec), data[0]); #endif - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<chanspec); + s->io_bits |= 1 << CR_CHAN(insn->chanspec); break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<chanspec)); + s->io_bits &= ~(1 << CR_CHAN(insn->chanspec)); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1<chanspec))) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s->io_bits & (1 << CR_CHAN(insn-> + chanspec))) ? COMEDI_OUTPUT : + COMEDI_INPUT; return insn->n; break; default: @@ -3204,44 +3379,46 @@ static int ni_dio_insn_config(comedi_device *dev,comedi_subdevice *s, devpriv->dio_control &= ~DIO_Pins_Dir_Mask; devpriv->dio_control |= DIO_Pins_Dir(s->io_bits); - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); + devpriv->stc_writew(dev, devpriv->dio_control, DIO_Control_Register); return 1; } -static int ni_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { #ifdef DEBUG_DIO - rt_printk("ni_dio_insn_bits() mask=0x%x bits=0x%x\n",data[0],data[1]); + rt_printk("ni_dio_insn_bits() mask=0x%x bits=0x%x\n", data[0], data[1]); #endif - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { /* Perform check to make sure we're not using the serial part of the dio */ - if((data[0] & (DIO_SDIN | DIO_SDOUT)) && devpriv->serial_interval_ns) + if ((data[0] & (DIO_SDIN | DIO_SDOUT)) + && devpriv->serial_interval_ns) return -EBUSY; s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); devpriv->dio_output &= ~DIO_Parallel_Data_Mask; devpriv->dio_output |= DIO_Parallel_Data_Out(s->state); - devpriv->stc_writew(dev, devpriv->dio_output,DIO_Output_Register); + devpriv->stc_writew(dev, devpriv->dio_output, + DIO_Output_Register); } data[1] = devpriv->stc_readw(dev, DIO_Parallel_Input_Register); return 2; } -static int ni_m_series_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_m_series_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { #ifdef DEBUG_DIO rt_printk("ni_m_series_dio_insn_config() chan=%d io=%d\n", CR_CHAN(insn->chanspec), data[0]); #endif - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: s->io_bits |= 1 << CR_CHAN(insn->chanspec); break; @@ -3249,7 +3426,10 @@ static int ni_m_series_dio_insn_config(comedi_device *dev,comedi_subdevice *s, s->io_bits &= ~(1 << CR_CHAN(insn->chanspec)); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1<chanspec))) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s->io_bits & (1 << CR_CHAN(insn-> + chanspec))) ? COMEDI_OUTPUT : + COMEDI_INPUT; return insn->n; break; default: @@ -3261,14 +3441,16 @@ static int ni_m_series_dio_insn_config(comedi_device *dev,comedi_subdevice *s, return 1; } -static int ni_m_series_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_m_series_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { #ifdef DEBUG_DIO - rt_printk("ni_m_series_dio_insn_bits() mask=0x%x bits=0x%x\n",data[0],data[1]); + rt_printk("ni_m_series_dio_insn_bits() mask=0x%x bits=0x%x\n", data[0], + data[1]); #endif - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; s->state |= (data[0] & data[1]); ni_writel(s->state, M_Offset_Static_Digital_Output); @@ -3278,9 +3460,10 @@ static int ni_m_series_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int ni_cdio_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) +static int ni_cdio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; int sources; unsigned i; @@ -3290,135 +3473,140 @@ static int ni_cdio_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd * tmp = cmd->start_src; sources = TRIG_INT; cmd->start_src &= sources; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; - /* step 2: make sure trigger sources are unique...*/ + /* step 2: make sure trigger sources are unique... */ - if(cmd->start_src != TRIG_INT) err++; - if(cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_NOW) err++; - if(cmd->stop_src != TRIG_NONE) err++; + if (cmd->start_src != TRIG_INT) + err++; + if (cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_NONE) + err++; /* ... and mutually compatible */ - if(err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_src == TRIG_INT) - { - if(cmd->start_arg != 0) - { + if (cmd->start_src == TRIG_INT) { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } } - if(cmd->scan_begin_src == TRIG_EXT) - { + if (cmd->scan_begin_src == TRIG_EXT) { tmp = cmd->scan_begin_arg; - tmp &= CR_PACK_FLAGS(CDO_Sample_Source_Select_Mask, 0, 0, CR_INVERT); - if(tmp != cmd->scan_begin_arg) - { + tmp &= CR_PACK_FLAGS(CDO_Sample_Source_Select_Mask, 0, 0, + CR_INVERT); + if (tmp != cmd->scan_begin_arg) { err++; } } - if(cmd->convert_src == TRIG_NOW) - { - if(cmd->convert_arg) - { + if (cmd->convert_src == TRIG_NOW) { + if (cmd->convert_arg) { cmd->convert_arg = 0; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src == TRIG_NONE) - { - if(cmd->stop_arg != 0) - { + if (cmd->stop_src == TRIG_NONE) { + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(err) return 4; + if (err) + return 4; /* step 5: check chanlist */ - for(i = 0; i < cmd->chanlist_len; ++i) - { - if(cmd->chanlist[i] != i) err = 1; + for (i = 0; i < cmd->chanlist_len; ++i) { + if (cmd->chanlist[i] != i) + err = 1; } - if(err) return 5; + if (err) + return 5; return 0; } -static int ni_cdio_cmd(comedi_device *dev, comedi_subdevice *s) +static int ni_cdio_cmd(comedi_device * dev, comedi_subdevice * s) { const comedi_cmd *cmd = &s->async->cmd; unsigned cdo_mode_bits = CDO_FIFO_Mode_Bit | CDO_Halt_On_Error_Bit; int retval; ni_writel(CDO_Reset_Bit, M_Offset_CDIO_Command); - switch(cmd->scan_begin_src) - { + switch (cmd->scan_begin_src) { case TRIG_EXT: - cdo_mode_bits |= CR_CHAN(cmd->scan_begin_arg) & CDO_Sample_Source_Select_Mask; + cdo_mode_bits |= + CR_CHAN(cmd-> + scan_begin_arg) & CDO_Sample_Source_Select_Mask; break; default: BUG(); break; } - if(cmd->scan_begin_arg & CR_INVERT) + if (cmd->scan_begin_arg & CR_INVERT) cdo_mode_bits |= CDO_Polarity_Bit; ni_writel(cdo_mode_bits, M_Offset_CDO_Mode); - if(s->io_bits) - { + if (s->io_bits) { ni_writel(s->state, M_Offset_CDO_FIFO_Data); ni_writel(CDO_SW_Update_Bit, M_Offset_CDIO_Command); ni_writel(s->io_bits, M_Offset_CDO_Mask_Enable); - }else - { - comedi_error(dev, "attempted to run digital output command with no lines configured as outputs"); + } else { + comedi_error(dev, + "attempted to run digital output command with no lines configured as outputs"); return -EIO; } retval = ni_request_cdo_mite_channel(dev); - if(retval < 0) - { + if (retval < 0) { return retval; } s->async->inttrig = &ni_cdo_inttrig; return 0; } -static int ni_cdo_inttrig(comedi_device *dev,comedi_subdevice *s, +static int ni_cdo_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { unsigned long flags; @@ -3432,96 +3620,94 @@ static int ni_cdo_inttrig(comedi_device *dev,comedi_subdevice *s, comedi_buf_read_alloc(s->async, s->async->prealloc_bufsz); comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->cdo_mite_chan) - { + if (devpriv->cdo_mite_chan) { mite_prep_dma(devpriv->cdo_mite_chan, 32, 32); mite_dma_arm(devpriv->cdo_mite_chan); - }else - { + } else { comedi_error(dev, "BUG: no cdo mite channel?"); retval = -EIO; } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); - if(retval < 0) return retval; + if (retval < 0) + return retval; // XXX not sure what interrupt C group does -// ni_writeb(Interrupt_Group_C_Enable_Bit, M_Offset_Interrupt_C_Enable); +// ni_writeb(Interrupt_Group_C_Enable_Bit, M_Offset_Interrupt_C_Enable); //wait for dma to fill output fifo - for(i = 0; i < timeout; ++i) - { - if(ni_readl(M_Offset_CDIO_Status) & CDO_FIFO_Full_Bit) break; + for (i = 0; i < timeout; ++i) { + if (ni_readl(M_Offset_CDIO_Status) & CDO_FIFO_Full_Bit) + break; comedi_udelay(10); } - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "dma failed to fill cdo fifo!"); ni_cdio_cancel(dev, s); return -EIO; } ni_writel(CDO_Arm_Bit | CDO_Error_Interrupt_Enable_Set_Bit | - CDO_Empty_FIFO_Interrupt_Enable_Set_Bit, - M_Offset_CDIO_Command); + CDO_Empty_FIFO_Interrupt_Enable_Set_Bit, M_Offset_CDIO_Command); return 0; } -static int ni_cdio_cancel(comedi_device *dev, comedi_subdevice *s) +static int ni_cdio_cancel(comedi_device * dev, comedi_subdevice * s) { ni_writel(CDO_Disarm_Bit | CDO_Error_Interrupt_Enable_Clear_Bit | - CDO_Empty_FIFO_Interrupt_Enable_Clear_Bit | CDO_FIFO_Request_Interrupt_Enable_Clear_Bit, + CDO_Empty_FIFO_Interrupt_Enable_Clear_Bit | + CDO_FIFO_Request_Interrupt_Enable_Clear_Bit, M_Offset_CDIO_Command); // XXX not sure what interrupt C group does -// ni_writeb(0, M_Offset_Interrupt_C_Enable); +// ni_writeb(0, M_Offset_Interrupt_C_Enable); ni_writel(0, M_Offset_CDO_Mask_Enable); ni_release_cdo_mite_channel(dev); return 0; } -static void handle_cdio_interrupt(comedi_device *dev) +static void handle_cdio_interrupt(comedi_device * dev) { unsigned cdio_status; comedi_subdevice *s = dev->subdevices + NI_DIO_SUBDEV; unsigned long flags; - if((boardtype.reg_type & ni_reg_m_series_mask) == 0) - { + if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) { return; } comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->cdo_mite_chan) - { - unsigned cdo_mite_status = mite_get_status(devpriv->cdo_mite_chan); - if(cdo_mite_status & CHSR_LINKC) - { - writel(CHOR_CLRLC, devpriv->mite->mite_io_addr + MITE_CHOR(devpriv->cdo_mite_chan->channel)); + if (devpriv->cdo_mite_chan) { + unsigned cdo_mite_status = + mite_get_status(devpriv->cdo_mite_chan); + if (cdo_mite_status & CHSR_LINKC) { + writel(CHOR_CLRLC, + devpriv->mite->mite_io_addr + + MITE_CHOR(devpriv->cdo_mite_chan->channel)); } mite_sync_output_dma(devpriv->cdo_mite_chan, s->async); } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); cdio_status = ni_readl(M_Offset_CDIO_Status); - if(cdio_status & (CDO_Overrun_Bit | CDO_Underflow_Bit)) - { -// rt_printk("cdio error: statux=0x%x\n", cdio_status); + if (cdio_status & (CDO_Overrun_Bit | CDO_Underflow_Bit)) { +// rt_printk("cdio error: statux=0x%x\n", cdio_status); ni_writel(CDO_Error_Interrupt_Confirm_Bit, M_Offset_CDIO_Command); // XXX just guessing this is needed and does something useful s->async->events |= COMEDI_CB_OVERFLOW; } - if(cdio_status & CDO_FIFO_Empty_Bit) - { -// rt_printk("cdio fifo empty\n"); - ni_writel(CDO_Empty_FIFO_Interrupt_Enable_Clear_Bit, M_Offset_CDIO_Command); -// s->async->events |= COMEDI_CB_EOA; + if (cdio_status & CDO_FIFO_Empty_Bit) { +// rt_printk("cdio fifo empty\n"); + ni_writel(CDO_Empty_FIFO_Interrupt_Enable_Clear_Bit, + M_Offset_CDIO_Command); +// s->async->events |= COMEDI_CB_EOA; } ni_event(dev, s); } -static int ni_serial_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_serial_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int err = insn->n; unsigned char byte_out, byte_in = 0; - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - switch(data[0]) { + switch (data[0]) { case INSN_CONFIG_SERIAL_CLOCK: #ifdef DEBUG_DIO @@ -3530,84 +3716,84 @@ static int ni_serial_insn_config(comedi_device *dev,comedi_subdevice *s, devpriv->serial_hw_mode = 1; devpriv->dio_control |= DIO_HW_Serial_Enable; - if(data[1] == SERIAL_DISABLED) { + if (data[1] == SERIAL_DISABLED) { devpriv->serial_hw_mode = 0; devpriv->dio_control &= ~(DIO_HW_Serial_Enable | - DIO_Software_Serial_Control); + DIO_Software_Serial_Control); data[1] = SERIAL_DISABLED; devpriv->serial_interval_ns = data[1]; - } - else if(data[1] <= SERIAL_600NS) { + } else if (data[1] <= SERIAL_600NS) { /* Warning: this clock speed is too fast to reliably - control SCXI. */ + control SCXI. */ devpriv->dio_control &= ~DIO_HW_Serial_Timebase; devpriv->clock_and_fout |= Slow_Internal_Timebase; devpriv->clock_and_fout &= ~DIO_Serial_Out_Divide_By_2; data[1] = SERIAL_600NS; devpriv->serial_interval_ns = data[1]; - } - else if(data[1] <= SERIAL_1_2US) { + } else if (data[1] <= SERIAL_1_2US) { devpriv->dio_control &= ~DIO_HW_Serial_Timebase; devpriv->clock_and_fout |= Slow_Internal_Timebase | DIO_Serial_Out_Divide_By_2; data[1] = SERIAL_1_2US; devpriv->serial_interval_ns = data[1]; - } - else if(data[1] <= SERIAL_10US) { + } else if (data[1] <= SERIAL_10US) { devpriv->dio_control |= DIO_HW_Serial_Timebase; devpriv->clock_and_fout |= Slow_Internal_Timebase | DIO_Serial_Out_Divide_By_2; /* Note: DIO_Serial_Out_Divide_By_2 only affects - 600ns/1.2us. If you turn divide_by_2 off with the - slow clock, you will still get 10us, except then - all your delays are wrong. */ + 600ns/1.2us. If you turn divide_by_2 off with the + slow clock, you will still get 10us, except then + all your delays are wrong. */ data[1] = SERIAL_10US; devpriv->serial_interval_ns = data[1]; - } - else { + } else { devpriv->dio_control &= ~(DIO_HW_Serial_Enable | - DIO_Software_Serial_Control); + DIO_Software_Serial_Control); devpriv->serial_hw_mode = 0; data[1] = (data[1] / 1000) * 1000; devpriv->serial_interval_ns = data[1]; } - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); - devpriv->stc_writew(dev, devpriv->clock_and_fout,Clock_and_FOUT_Register); + devpriv->stc_writew(dev, devpriv->dio_control, + DIO_Control_Register); + devpriv->stc_writew(dev, devpriv->clock_and_fout, + Clock_and_FOUT_Register); return 1; - break; + break; case INSN_CONFIG_BIDIRECTIONAL_DATA: - if(devpriv->serial_interval_ns == 0) { + if (devpriv->serial_interval_ns == 0) { return -EINVAL; } byte_out = data[1] & 0xFF; - if(devpriv->serial_hw_mode) { - err = ni_serial_hw_readwrite8(dev,s,byte_out,&byte_in); - } else if(devpriv->serial_interval_ns > 0) { - err = ni_serial_sw_readwrite8(dev,s,byte_out,&byte_in); + if (devpriv->serial_hw_mode) { + err = ni_serial_hw_readwrite8(dev, s, byte_out, + &byte_in); + } else if (devpriv->serial_interval_ns > 0) { + err = ni_serial_sw_readwrite8(dev, s, byte_out, + &byte_in); } else { rt_printk("ni_serial_insn_config: serial disabled!\n"); return -EINVAL; } - if(err < 0) return err; + if (err < 0) + return err; data[1] = byte_in & 0xFF; return insn->n; - break; + break; default: return -EINVAL; } } -static int ni_serial_hw_readwrite8(comedi_device *dev,comedi_subdevice *s, - unsigned char data_out, - unsigned char *data_in) +static int ni_serial_hw_readwrite8(comedi_device * dev, comedi_subdevice * s, + unsigned char data_out, unsigned char *data_in) { unsigned int status1; int err = 0, count = 20; @@ -3618,24 +3804,28 @@ static int ni_serial_hw_readwrite8(comedi_device *dev,comedi_subdevice *s, devpriv->dio_output &= ~DIO_Serial_Data_Mask; devpriv->dio_output |= DIO_Serial_Data_Out(data_out); - devpriv->stc_writew(dev, devpriv->dio_output,DIO_Output_Register); + devpriv->stc_writew(dev, devpriv->dio_output, DIO_Output_Register); status1 = devpriv->stc_readw(dev, Joint_Status_1_Register); - if(status1 & DIO_Serial_IO_In_Progress_St) { + if (status1 & DIO_Serial_IO_In_Progress_St) { err = -EBUSY; goto Error; } devpriv->dio_control |= DIO_HW_Serial_Start; - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); + devpriv->stc_writew(dev, devpriv->dio_control, DIO_Control_Register); devpriv->dio_control &= ~DIO_HW_Serial_Start; /* Wait until STC says we're done, but don't loop infinitely. */ - while((status1 = devpriv->stc_readw(dev, Joint_Status_1_Register)) & DIO_Serial_IO_In_Progress_St) { + while ((status1 = + devpriv->stc_readw(dev, + Joint_Status_1_Register)) & + DIO_Serial_IO_In_Progress_St) { /* Delay one bit per loop */ comedi_udelay((devpriv->serial_interval_ns + 999) / 1000); - if(--count < 0) { - rt_printk("ni_serial_hw_readwrite8: SPI serial I/O didn't finish in time!\n"); + if (--count < 0) { + rt_printk + ("ni_serial_hw_readwrite8: SPI serial I/O didn't finish in time!\n"); err = -ETIME; goto Error; } @@ -3645,22 +3835,21 @@ static int ni_serial_hw_readwrite8(comedi_device *dev,comedi_subdevice *s, DIO_Serial_IO_In_Progress_St goes high one bit too early. */ comedi_udelay((devpriv->serial_interval_ns + 999) / 1000); - if(data_in != NULL) { + if (data_in != NULL) { *data_in = devpriv->stc_readw(dev, DIO_Serial_Input_Register); #ifdef DEBUG_DIO rt_printk("ni_serial_hw_readwrite8: inputted 0x%x\n", *data_in); #endif } - Error: - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); + Error: + devpriv->stc_writew(dev, devpriv->dio_control, DIO_Control_Register); return err; } -static int ni_serial_sw_readwrite8(comedi_device *dev,comedi_subdevice *s, - unsigned char data_out, - unsigned char *data_in) +static int ni_serial_sw_readwrite8(comedi_device * dev, comedi_subdevice * s, + unsigned char data_out, unsigned char *data_in) { unsigned char mask, input = 0; @@ -3671,30 +3860,34 @@ static int ni_serial_sw_readwrite8(comedi_device *dev,comedi_subdevice *s, /* Wait for one bit before transfer */ comedi_udelay((devpriv->serial_interval_ns + 999) / 1000); - for(mask = 0x80; mask; mask >>= 1) { + for (mask = 0x80; mask; mask >>= 1) { /* Output current bit; note that we cannot touch s->state - because it is a per-subdevice field, and serial is + because it is a per-subdevice field, and serial is a separate subdevice from DIO. */ devpriv->dio_output &= ~DIO_SDOUT; - if(data_out & mask) { + if (data_out & mask) { devpriv->dio_output |= DIO_SDOUT; } - devpriv->stc_writew(dev, devpriv->dio_output,DIO_Output_Register); + devpriv->stc_writew(dev, devpriv->dio_output, + DIO_Output_Register); /* Assert SDCLK (active low, inverted), wait for half of the delay, deassert SDCLK, and wait for the other half. */ devpriv->dio_control |= DIO_Software_Serial_Control; - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); + devpriv->stc_writew(dev, devpriv->dio_control, + DIO_Control_Register); comedi_udelay((devpriv->serial_interval_ns + 999) / 2000); devpriv->dio_control &= ~DIO_Software_Serial_Control; - devpriv->stc_writew(dev, devpriv->dio_control,DIO_Control_Register); + devpriv->stc_writew(dev, devpriv->dio_control, + DIO_Control_Register); comedi_udelay((devpriv->serial_interval_ns + 999) / 2000); /* Input current bit */ - if(devpriv->stc_readw(dev, DIO_Parallel_Input_Register) & DIO_SDIN) { + if (devpriv->stc_readw(dev, + DIO_Parallel_Input_Register) & DIO_SDIN) { /* rt_printk("DIO_P_I_R: 0x%x\n", devpriv->stc_readw(dev, DIO_Parallel_Input_Register)); */ input |= mask; } @@ -3702,37 +3895,36 @@ static int ni_serial_sw_readwrite8(comedi_device *dev,comedi_subdevice *s, #ifdef DEBUG_DIO rt_printk("ni_serial_sw_readwrite8: inputted 0x%x\n", input); #endif - if(data_in) *data_in = input; + if (data_in) + *data_in = input; return 0; } -static void mio_common_detach(comedi_device *dev) +static void mio_common_detach(comedi_device * dev) { - if(dev->private) - { - if(devpriv->counter_dev) - { + if (dev->private) { + if (devpriv->counter_dev) { ni_gpct_device_destroy(devpriv->counter_dev); } } - if(dev->subdevices && boardtype.has_8255) + if (dev->subdevices && boardtype.has_8255) subdev_8255_cleanup(dev, dev->subdevices + NI_8255_DIO_SUBDEV); } -static void init_ao_67xx(comedi_device *dev, comedi_subdevice *s) +static void init_ao_67xx(comedi_device * dev, comedi_subdevice * s) { int i; - for(i = 0; i < s->n_chan; i++) - ni_ao_win_outw(dev, AO_Channel(i) | 0x0, AO_Configuration_2_67xx); + for (i = 0; i < s->n_chan; i++) + ni_ao_win_outw(dev, AO_Channel(i) | 0x0, + AO_Configuration_2_67xx); } static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg) { unsigned stc_register; - switch(reg) - { + switch (reg) { case NITIO_G0_Autoincrement_Reg: stc_register = G_Autoincrement_Register(0); break; @@ -3812,7 +4004,8 @@ static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg) stc_register = Interrupt_B_Enable_Register; break; default: - rt_printk("%s: unhandled register 0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: unhandled register 0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return 0; break; @@ -3820,18 +4013,20 @@ static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg) return stc_register; } -static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg) +static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, + enum ni_gpct_register reg) { comedi_device *dev = counter->counter_dev->dev; unsigned stc_register; /* bits in the join reset register which are relevant to counters */ static const unsigned gpct_joint_reset_mask = G0_Reset | G1_Reset; - static const unsigned gpct_interrupt_a_enable_mask = G0_Gate_Interrupt_Enable | G0_TC_Interrupt_Enable; - static const unsigned gpct_interrupt_b_enable_mask = G1_Gate_Interrupt_Enable | G1_TC_Interrupt_Enable; + static const unsigned gpct_interrupt_a_enable_mask = + G0_Gate_Interrupt_Enable | G0_TC_Interrupt_Enable; + static const unsigned gpct_interrupt_b_enable_mask = + G1_Gate_Interrupt_Enable | G1_TC_Interrupt_Enable; - switch(reg) - { - /* m-series-only registers */ + switch (reg) { + /* m-series-only registers */ case NITIO_G0_Counting_Mode_Reg: ni_writew(bits, M_Offset_G0_Counting_Mode); break; @@ -3857,7 +4052,7 @@ static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, enum ni_writew(bits, M_Offset_G1_MSeries_ABZ); break; - /* 32 bit registers */ + /* 32 bit registers */ case NITIO_G0_LoadA_Reg: case NITIO_G1_LoadA_Reg: case NITIO_G0_LoadB_Reg: @@ -3866,14 +4061,16 @@ static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, enum devpriv->stc_writel(dev, bits, stc_register); break; - /* 16 bit registers */ + /* 16 bit registers */ case NITIO_G0_Interrupt_Enable_Reg: BUG_ON(bits & ~gpct_interrupt_a_enable_mask); - ni_set_bitfield(dev, Interrupt_A_Enable_Register, gpct_interrupt_a_enable_mask, bits); + ni_set_bitfield(dev, Interrupt_A_Enable_Register, + gpct_interrupt_a_enable_mask, bits); break; case NITIO_G1_Interrupt_Enable_Reg: BUG_ON(bits & ~gpct_interrupt_b_enable_mask); - ni_set_bitfield(dev, Interrupt_B_Enable_Register, gpct_interrupt_b_enable_mask, bits); + ni_set_bitfield(dev, Interrupt_B_Enable_Register, + gpct_interrupt_b_enable_mask, bits); break; case NITIO_G01_Joint_Reset_Reg: BUG_ON(bits & ~gpct_joint_reset_mask); @@ -3884,13 +4081,13 @@ static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits, enum } } -static unsigned ni_gpct_read_register(struct ni_gpct *counter, enum ni_gpct_register reg) +static unsigned ni_gpct_read_register(struct ni_gpct *counter, + enum ni_gpct_register reg) { comedi_device *dev = counter->counter_dev->dev; unsigned stc_register; - switch(reg) - { - /* m-series only registers */ + switch (reg) { + /* m-series only registers */ case NITIO_G0_DMA_Status_Reg: return ni_readw(M_Offset_G0_DMA_Status); break; @@ -3898,7 +4095,7 @@ static unsigned ni_gpct_read_register(struct ni_gpct *counter, enum ni_gpct_regi return ni_readw(M_Offset_G1_DMA_Status); break; - /* 32 bit registers */ + /* 32 bit registers */ case NITIO_G0_HW_Save_Reg: case NITIO_G1_HW_Save_Reg: case NITIO_G0_SW_Save_Reg: @@ -3907,7 +4104,7 @@ static unsigned ni_gpct_read_register(struct ni_gpct *counter, enum ni_gpct_regi return devpriv->stc_readl(dev, stc_register); break; - /* 16 bit registers */ + /* 16 bit registers */ default: stc_register = ni_gpct_to_stc_register(reg); return devpriv->stc_readw(dev, stc_register); @@ -3916,29 +4113,30 @@ static unsigned ni_gpct_read_register(struct ni_gpct *counter, enum ni_gpct_regi return 0; } -static int ni_freq_out_insn_read(comedi_device *dev, - comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ni_freq_out_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->clock_and_fout & FOUT_Divider_mask; return 1; } -static int ni_freq_out_insn_write(comedi_device *dev, - comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ni_freq_out_insn_write(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { devpriv->clock_and_fout &= ~FOUT_Enable; - devpriv->stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register); + devpriv->stc_writew(dev, devpriv->clock_and_fout, + Clock_and_FOUT_Register); devpriv->clock_and_fout &= ~FOUT_Divider_mask; devpriv->clock_and_fout |= FOUT_Divider(data[0]); devpriv->clock_and_fout |= FOUT_Enable; - devpriv->stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register); + devpriv->stc_writew(dev, devpriv->clock_and_fout, + Clock_and_FOUT_Register); return insn->n; } -static int ni_set_freq_out_clock(comedi_device *dev, lsampl_t clock_source) +static int ni_set_freq_out_clock(comedi_device * dev, lsampl_t clock_source) { - switch(clock_source) - { + switch (clock_source) { case NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC: devpriv->clock_and_fout &= ~FOUT_Timebase_Select; break; @@ -3948,28 +4146,27 @@ static int ni_set_freq_out_clock(comedi_device *dev, lsampl_t clock_source) default: return -EINVAL; } - devpriv->stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register); + devpriv->stc_writew(dev, devpriv->clock_and_fout, + Clock_and_FOUT_Register); return 3; } -static void ni_get_freq_out_clock(comedi_device *dev, lsampl_t *clock_source, lsampl_t *clock_period_ns) +static void ni_get_freq_out_clock(comedi_device * dev, lsampl_t * clock_source, + lsampl_t * clock_period_ns) { - if(devpriv->clock_and_fout & FOUT_Timebase_Select) - { + if (devpriv->clock_and_fout & FOUT_Timebase_Select) { *clock_source = NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC; *clock_period_ns = TIMEBASE_2_NS; - }else - { + } else { *clock_source = NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC; *clock_period_ns = TIMEBASE_1_NS * 2; } } -static int ni_freq_out_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_freq_out_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_SET_CLOCK_SRC: return ni_set_freq_out_clock(dev, data[1]); break; @@ -3982,12 +4179,13 @@ static int ni_freq_out_insn_config(comedi_device *dev, comedi_subdevice *s, return -EINVAL; } -static int ni_alloc_private(comedi_device *dev) +static int ni_alloc_private(comedi_device * dev) { int ret; ret = alloc_private(dev, sizeof(ni_private)); - if(ret < 0) return ret; + if (ret < 0) + return ret; spin_lock_init(&devpriv->window_lock); spin_lock_init(&devpriv->soft_reg_copy_lock); @@ -3996,38 +4194,38 @@ static int ni_alloc_private(comedi_device *dev) return 0; }; -static int ni_E_init(comedi_device *dev,comedi_devconfig *it) +static int ni_E_init(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned j; enum ni_gpct_variant counter_variant; - if(boardtype.n_aochan > MAX_N_AO_CHAN) - { + if (boardtype.n_aochan > MAX_N_AO_CHAN) { printk("bug! boardtype.n_aochan > MAX_N_AO_CHAN\n"); return -EINVAL; } - if(alloc_subdevices(dev, NI_NUM_SUBDEVICES) < 0) + if (alloc_subdevices(dev, NI_NUM_SUBDEVICES) < 0) return -ENOMEM; /* analog input subdevice */ s = dev->subdevices + NI_AI_SUBDEV; - dev->read_subdev=s; - if(boardtype.n_adchan){ - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE | SDF_DIFF | SDF_DITHER | SDF_CMD_READ; - if(boardtype.reg_type != ni_reg_611x) + dev->read_subdev = s; + if (boardtype.n_adchan) { + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_DIFF | SDF_DITHER | SDF_CMD_READ; + if (boardtype.reg_type != ni_reg_611x) s->subdev_flags |= SDF_GROUND | SDF_COMMON | SDF_OTHER; - if(boardtype.adbits > 16) + if (boardtype.adbits > 16) s->subdev_flags |= SDF_LSAMPL; - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) s->subdev_flags |= SDF_SOFT_CALIBRATED; - s->n_chan=boardtype.n_adchan; - s->len_chanlist=512; - s->maxdata=(1<range_table=ni_range_lkup[boardtype.gainlkup]; + s->n_chan = boardtype.n_adchan; + s->len_chanlist = 512; + s->maxdata = (1 << boardtype.adbits) - 1; + s->range_table = ni_range_lkup[boardtype.gainlkup]; s->insn_read = &ni_ai_insn_read; s->insn_config = &ni_ai_insn_config; s->do_cmdtest = &ni_ai_cmdtest; @@ -4038,60 +4236,60 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) #ifdef PCIDMA s->async_dma_dir = DMA_FROM_DEVICE; #endif - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } /* analog output subdevice */ s = dev->subdevices + NI_AO_SUBDEV; - if(boardtype.n_aochan){ + if (boardtype.n_aochan) { s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE | SDF_DEGLITCH | SDF_GROUND; - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) s->subdev_flags |= SDF_SOFT_CALIBRATED; s->n_chan = boardtype.n_aochan; s->maxdata = (1 << boardtype.aobits) - 1; s->range_table = boardtype.ao_range_table; s->insn_read = &ni_ao_insn_read; - if(boardtype.reg_type & ni_reg_6xxx_mask){ + if (boardtype.reg_type & ni_reg_6xxx_mask) { s->insn_write = &ni_ao_insn_write_671x; - }else{ + } else { s->insn_write = &ni_ao_insn_write; } #ifdef PCIDMA - if(boardtype.n_aochan){ + if (boardtype.n_aochan) { s->async_dma_dir = DMA_TO_DEVICE; #else - if(boardtype.ao_fifo_depth){ + if (boardtype.ao_fifo_depth) { #endif - dev->write_subdev=s; + dev->write_subdev = s; s->subdev_flags |= SDF_CMD_WRITE; s->do_cmd = &ni_ao_cmd; s->do_cmdtest = &ni_ao_cmdtest; s->len_chanlist = boardtype.n_aochan; - if((boardtype.reg_type & ni_reg_m_series_mask) == 0) - s->munge=ni_ao_munge; + if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) + s->munge = ni_ao_munge; } s->cancel = &ni_ao_reset; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } - if((boardtype.reg_type & ni_reg_67xx_mask)) + if ((boardtype.reg_type & ni_reg_67xx_mask)) init_ao_67xx(dev, s); /* digital i/o subdevice */ s = dev->subdevices + NI_DIO_SUBDEV; - s->type=COMEDI_SUBD_DIO; + s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; - s->maxdata=1; - s->io_bits=0; /* all bits input */ - s->range_table=&range_digital; + s->maxdata = 1; + s->io_bits = 0; /* all bits input */ + s->range_table = &range_digital; s->n_chan = boardtype.num_p0_dio_channels; - if(boardtype.reg_type & ni_reg_m_series_mask) - { - s->subdev_flags |= SDF_LSAMPL | SDF_CMD_WRITE /* | SDF_CMD_READ */; + if (boardtype.reg_type & ni_reg_m_series_mask) { + s->subdev_flags |= + SDF_LSAMPL | SDF_CMD_WRITE /* | SDF_CMD_READ */ ; s->insn_bits = &ni_m_series_dio_insn_bits; s->insn_config = &ni_m_series_dio_insn_config; s->do_cmd = &ni_cdio_cmd; @@ -4102,8 +4300,7 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) ni_writel(CDO_Reset_Bit | CDI_Reset_Bit, M_Offset_CDIO_Command); ni_writel(s->io_bits, M_Offset_DIO_Direction); - }else - { + } else { s->insn_bits = &ni_dio_insn_bits; s->insn_config = &ni_dio_insn_config; devpriv->dio_control = DIO_Pins_Dir(s->io_bits); @@ -4112,10 +4309,10 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) /* 8255 device */ s = dev->subdevices + NI_8255_DIO_SUBDEV; - if(boardtype.has_8255){ - subdev_8255_init(dev,s,ni_8255_callback,(unsigned long)dev); - }else{ - s->type=COMEDI_SUBD_UNUSED; + if (boardtype.has_8255) { + subdev_8255_init(dev, s, ni_8255_callback, (unsigned long)dev); + } else { + s->type = COMEDI_SUBD_UNUSED; } /* formerly general purpose counter/timer device, but no longer used */ @@ -4124,24 +4321,21 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) /* calibration subdevice -- ai and ao */ s = dev->subdevices + NI_CALIBRATION_SUBDEV; - s->type=COMEDI_SUBD_CALIB; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + s->type = COMEDI_SUBD_CALIB; + if (boardtype.reg_type & ni_reg_m_series_mask) { // internal PWM analog output used for AI nonlinearity calibration s->subdev_flags = SDF_INTERNAL; s->insn_config = &ni_m_series_pwm_config; s->n_chan = 1; s->maxdata = 0; ni_writel(0x0, M_Offset_Cal_PWM); - } else if(boardtype.reg_type == ni_reg_6143) - { + } else if (boardtype.reg_type == ni_reg_6143) { // internal PWM analog output used for AI nonlinearity calibration s->subdev_flags = SDF_INTERNAL; s->insn_config = &ni_6143_pwm_config; s->n_chan = 1; s->maxdata = 0; - }else - { + } else { s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; s->insn_read = &ni_calib_insn_read; s->insn_write = &ni_calib_insn_write; @@ -4150,15 +4344,13 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) /* EEPROM */ s = dev->subdevices + NI_EEPROM_SUBDEV; - s->type=COMEDI_SUBD_MEMORY; - s->subdev_flags=SDF_READABLE|SDF_INTERNAL; - s->maxdata=0xff; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + s->type = COMEDI_SUBD_MEMORY; + s->subdev_flags = SDF_READABLE | SDF_INTERNAL; + s->maxdata = 0xff; + if (boardtype.reg_type & ni_reg_m_series_mask) { s->n_chan = M_SERIES_EEPROM_SIZE; s->insn_read = &ni_m_series_eeprom_insn_read; - }else - { + } else { s->n_chan = 512; s->insn_read = &ni_eeprom_insn_read; } @@ -4167,22 +4359,19 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s = dev->subdevices + NI_PFI_DIO_SUBDEV; s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { unsigned i; s->n_chan = 16; ni_writew(s->state, M_Offset_PFI_DO); - for(i = 0; i < NUM_PFI_OUTPUT_SELECT_REGS; ++i) - { - ni_writew(devpriv->pfi_output_select_reg[i], M_Offset_PFI_Output_Select(i + 1)); + for (i = 0; i < NUM_PFI_OUTPUT_SELECT_REGS; ++i) { + ni_writew(devpriv->pfi_output_select_reg[i], + M_Offset_PFI_Output_Select(i + 1)); } - }else - { + } else { s->n_chan = 10; } s->maxdata = 1; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { s->insn_bits = &ni_pfi_insn_bits; } s->insn_config = &ni_pfi_insn_config; @@ -4190,28 +4379,26 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) /* cs5529 calibration adc */ s = dev->subdevices + NI_CS5529_CALIBRATION_SUBDEV; - if(boardtype.reg_type & ni_reg_67xx_mask) - { + if (boardtype.reg_type & ni_reg_67xx_mask) { s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_INTERNAL; // one channel for each analog output channel s->n_chan = boardtype.n_aochan; s->maxdata = (1 << 16) - 1; - s->range_table = &range_unknown; /* XXX */ - s->insn_read=cs5529_ai_insn_read; - s->insn_config=NULL; + s->range_table = &range_unknown; /* XXX */ + s->insn_read = cs5529_ai_insn_read; + s->insn_config = NULL; init_cs5529(dev); - }else - { - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } /* Serial */ s = dev->subdevices + NI_SERIAL_SUBDEV; - s->type=COMEDI_SUBD_SERIAL; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE|SDF_INTERNAL; - s->n_chan=1; - s->maxdata=0xff; + s->type = COMEDI_SUBD_SERIAL; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; + s->n_chan = 1; + s->maxdata = 0xff; s->insn_config = ni_serial_insn_config; devpriv->serial_interval_ns = 0; devpriv->serial_hw_mode = 0; @@ -4226,24 +4413,23 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s->insn_config = ni_rtsi_insn_config; ni_rtsi_init(dev); - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { counter_variant = ni_gpct_variant_m_series; - }else - { + } else { counter_variant = ni_gpct_variant_e_series; } devpriv->counter_dev = ni_gpct_device_construct(dev, &ni_gpct_write_register, &ni_gpct_read_register, counter_variant, NUM_GPCT); /* General purpose counters */ - for(j = 0; j < NUM_GPCT; ++j) - { + for (j = 0; j < NUM_GPCT; ++j) { s = dev->subdevices + NI_GPCT_SUBDEV(j); s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_CMD_READ /* | SDF_CMD_WRITE */; + s->subdev_flags = + SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_CMD_READ + /* | SDF_CMD_WRITE */ ; s->n_chan = 3; - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) s->maxdata = 0xffffffff; else s->maxdata = 0xffffff; @@ -4273,53 +4459,50 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s->insn_config = &ni_freq_out_insn_config; /* ai configuration */ - ni_ai_reset(dev,dev->subdevices + NI_AI_SUBDEV); - if((boardtype.reg_type & ni_reg_6xxx_mask) == 0){ + ni_ai_reset(dev, dev->subdevices + NI_AI_SUBDEV); + if ((boardtype.reg_type & ni_reg_6xxx_mask) == 0) { // BEAM is this needed for PCI-6143 ?? devpriv->clock_and_fout = Slow_Internal_Time_Divide_By_2 | Slow_Internal_Timebase | Clock_To_Board_Divide_By_2 | Clock_To_Board | - AI_Output_Divide_By_2 | - AO_Output_Divide_By_2; - }else{ + AI_Output_Divide_By_2 | AO_Output_Divide_By_2; + } else { devpriv->clock_and_fout = Slow_Internal_Time_Divide_By_2 | Slow_Internal_Timebase | - Clock_To_Board_Divide_By_2 | - Clock_To_Board; + Clock_To_Board_Divide_By_2 | Clock_To_Board; } - devpriv->stc_writew(dev, devpriv->clock_and_fout, Clock_and_FOUT_Register); + devpriv->stc_writew(dev, devpriv->clock_and_fout, + Clock_and_FOUT_Register); /* analog output configuration */ - ni_ao_reset(dev,dev->subdevices + NI_AO_SUBDEV); + ni_ao_reset(dev, dev->subdevices + NI_AO_SUBDEV); - if(dev->irq){ - devpriv->stc_writew(dev, (IRQ_POLARITY?Interrupt_Output_Polarity:0) | - (Interrupt_Output_On_3_Pins&0) | - Interrupt_A_Enable | + if (dev->irq) { + devpriv->stc_writew(dev, + (IRQ_POLARITY ? Interrupt_Output_Polarity : 0) | + (Interrupt_Output_On_3_Pins & 0) | Interrupt_A_Enable | Interrupt_B_Enable | - Interrupt_A_Output_Select(interrupt_pin(dev->irq)) | + Interrupt_A_Output_Select(interrupt_pin(dev-> + irq)) | Interrupt_B_Output_Select(interrupt_pin(dev->irq)), - Interrupt_Control_Register - ); + Interrupt_Control_Register); } /* DMA setup */ ni_writeb(devpriv->ai_ao_select_reg, AI_AO_Select); ni_writeb(devpriv->g0_g1_select_reg, G0_G1_Select); - if(boardtype.reg_type & ni_reg_6xxx_mask) - { - ni_writeb( 0, Magic_611x ); - }else if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_6xxx_mask) { + ni_writeb(0, Magic_611x); + } else if (boardtype.reg_type & ni_reg_m_series_mask) { int channel; - for(channel = 0; channel < boardtype.n_aochan; ++channel) - { + for (channel = 0; channel < boardtype.n_aochan; ++channel) { ni_writeb(0xf, M_Offset_AO_Waveform_Order(channel)); - ni_writeb(0x0, M_Offset_AO_Reference_Attenuation(channel)); + ni_writeb(0x0, + M_Offset_AO_Reference_Attenuation(channel)); } ni_writeb(0x0, M_Offset_AO_Calibration); } @@ -4328,17 +4511,15 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) return 0; } - - -static int ni_8255_callback(int dir,int port,int data,unsigned long arg) +static int ni_8255_callback(int dir, int port, int data, unsigned long arg) { - comedi_device *dev=(comedi_device *)arg; + comedi_device *dev = (comedi_device *) arg; - if(dir){ - ni_writeb(data,Port_A+2*port); + if (dir) { + ni_writeb(data, Port_A + 2 * port); return 0; - }else{ - return ni_readb(Port_A+2*port); + } else { + return ni_readb(Port_A + 2 * port); } } @@ -4346,10 +4527,10 @@ static int ni_8255_callback(int dir,int port,int data,unsigned long arg) presents the EEPROM as a subdevice */ -static int ni_eeprom_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_eeprom_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - data[0]=ni_read_eeprom(dev,CR_CHAN(insn->chanspec)); + data[0] = ni_read_eeprom(dev, CR_CHAN(insn->chanspec)); return 1; } @@ -4358,88 +4539,96 @@ static int ni_eeprom_insn_read(comedi_device *dev,comedi_subdevice *s, reads bytes out of eeprom */ -static int ni_read_eeprom(comedi_device *dev,int addr) +static int ni_read_eeprom(comedi_device * dev, int addr) { int bit; int bitstring; - bitstring=0x0300|((addr&0x100)<<3)|(addr&0xff); - ni_writeb(0x04,Serial_Command); - for(bit=0x8000;bit;bit>>=1){ - ni_writeb(0x04|((bit&bitstring)?0x02:0),Serial_Command); - ni_writeb(0x05|((bit&bitstring)?0x02:0),Serial_Command); + bitstring = 0x0300 | ((addr & 0x100) << 3) | (addr & 0xff); + ni_writeb(0x04, Serial_Command); + for (bit = 0x8000; bit; bit >>= 1) { + ni_writeb(0x04 | ((bit & bitstring) ? 0x02 : 0), + Serial_Command); + ni_writeb(0x05 | ((bit & bitstring) ? 0x02 : 0), + Serial_Command); } - bitstring=0; - for(bit=0x80;bit;bit>>=1){ - ni_writeb(0x04,Serial_Command); - ni_writeb(0x05,Serial_Command); - bitstring|=((ni_readb(XXX_Status)&PROMOUT)?bit:0); + bitstring = 0; + for (bit = 0x80; bit; bit >>= 1) { + ni_writeb(0x04, Serial_Command); + ni_writeb(0x05, Serial_Command); + bitstring |= ((ni_readb(XXX_Status) & PROMOUT) ? bit : 0); } - ni_writeb(0x00,Serial_Command); + ni_writeb(0x00, Serial_Command); return bitstring; } -static int ni_m_series_eeprom_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_m_series_eeprom_insn_read(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->eeprom_buffer[CR_CHAN(insn->chanspec)]; return 1; } -static int ni_get_pwm_config(comedi_device *dev, lsampl_t *data) +static int ni_get_pwm_config(comedi_device * dev, lsampl_t * data) { data[1] = devpriv->pwm_up_count * devpriv->clock_ns; data[2] = devpriv->pwm_down_count * devpriv->clock_ns; return 3; } -static int ni_m_series_pwm_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_m_series_pwm_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned up_count, down_count; - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_PWM_OUTPUT: - switch(data[1]) - { + switch (data[1]) { case TRIG_ROUND_NEAREST: - up_count = (data[2] + devpriv->clock_ns / 2) / devpriv->clock_ns; + up_count = + (data[2] + + devpriv->clock_ns / 2) / devpriv->clock_ns; break; case TRIG_ROUND_DOWN: up_count = data[2] / devpriv->clock_ns; break; case TRIG_ROUND_UP: - up_count = (data[2] + devpriv->clock_ns - 1) / devpriv->clock_ns; + up_count = + (data[2] + devpriv->clock_ns - + 1) / devpriv->clock_ns; break; default: return -EINVAL; break; } - switch(data[3]) - { + switch (data[3]) { case TRIG_ROUND_NEAREST: - down_count = (data[4] + devpriv->clock_ns / 2) / devpriv->clock_ns; + down_count = + (data[4] + + devpriv->clock_ns / 2) / devpriv->clock_ns; break; case TRIG_ROUND_DOWN: down_count = data[4] / devpriv->clock_ns; break; case TRIG_ROUND_UP: - down_count = (data[4] + devpriv->clock_ns - 1) / devpriv->clock_ns; + down_count = + (data[4] + devpriv->clock_ns - + 1) / devpriv->clock_ns; break; default: return -EINVAL; break; } - if(up_count * devpriv->clock_ns != data[2] || - down_count * devpriv->clock_ns != data[4]) - { + if (up_count * devpriv->clock_ns != data[2] || + down_count * devpriv->clock_ns != data[4]) { data[2] = up_count * devpriv->clock_ns; data[4] = down_count * devpriv->clock_ns; return -EAGAIN; } - ni_writel(MSeries_Cal_PWM_High_Time_Bits(up_count) | MSeries_Cal_PWM_Low_Time_Bits(down_count), M_Offset_Cal_PWM); + ni_writel(MSeries_Cal_PWM_High_Time_Bits(up_count) | + MSeries_Cal_PWM_Low_Time_Bits(down_count), + M_Offset_Cal_PWM); devpriv->pwm_up_count = up_count; devpriv->pwm_down_count = down_count; return 5; @@ -4454,46 +4643,50 @@ static int ni_m_series_pwm_config(comedi_device *dev, comedi_subdevice *s, return 0; } -static int ni_6143_pwm_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_6143_pwm_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned up_count, down_count; - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_PWM_OUTPUT: - switch(data[1]) - { + switch (data[1]) { case TRIG_ROUND_NEAREST: - up_count = (data[2] + devpriv->clock_ns / 2) / devpriv->clock_ns; + up_count = + (data[2] + + devpriv->clock_ns / 2) / devpriv->clock_ns; break; case TRIG_ROUND_DOWN: up_count = data[2] / devpriv->clock_ns; break; case TRIG_ROUND_UP: - up_count = (data[2] + devpriv->clock_ns - 1) / devpriv->clock_ns; + up_count = + (data[2] + devpriv->clock_ns - + 1) / devpriv->clock_ns; break; default: return -EINVAL; break; } - switch(data[3]) - { + switch (data[3]) { case TRIG_ROUND_NEAREST: - down_count = (data[4] + devpriv->clock_ns / 2) / devpriv->clock_ns; + down_count = + (data[4] + + devpriv->clock_ns / 2) / devpriv->clock_ns; break; case TRIG_ROUND_DOWN: down_count = data[4] / devpriv->clock_ns; break; case TRIG_ROUND_UP: - down_count = (data[4] + devpriv->clock_ns - 1) / devpriv->clock_ns; + down_count = + (data[4] + devpriv->clock_ns - + 1) / devpriv->clock_ns; break; default: return -EINVAL; break; } - if(up_count * devpriv->clock_ns != data[2] || - down_count * devpriv->clock_ns != data[4]) - { + if (up_count * devpriv->clock_ns != data[2] || + down_count * devpriv->clock_ns != data[4]) { data[2] = up_count * devpriv->clock_ns; data[4] = down_count * devpriv->clock_ns; return -EAGAIN; @@ -4513,135 +4706,138 @@ static int ni_6143_pwm_config(comedi_device *dev, comedi_subdevice *s, return 0; } -static void ni_write_caldac(comedi_device *dev,int addr,int val); +static void ni_write_caldac(comedi_device * dev, int addr, int val); /* calibration subdevice */ -static int ni_calib_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_calib_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - ni_write_caldac(dev,CR_CHAN(insn->chanspec),data[0]); + ni_write_caldac(dev, CR_CHAN(insn->chanspec), data[0]); return 1; } -static int ni_calib_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_calib_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { data[0] = devpriv->caldacs[CR_CHAN(insn->chanspec)]; return 1; } -static int pack_mb88341(int addr,int val,int *bitstring); -static int pack_dac8800(int addr,int val,int *bitstring); -static int pack_dac8043(int addr,int val,int *bitstring); -static int pack_ad8522(int addr,int val,int *bitstring); -static int pack_ad8804(int addr,int val,int *bitstring); -static int pack_ad8842(int addr,int val,int *bitstring); +static int pack_mb88341(int addr, int val, int *bitstring); +static int pack_dac8800(int addr, int val, int *bitstring); +static int pack_dac8043(int addr, int val, int *bitstring); +static int pack_ad8522(int addr, int val, int *bitstring); +static int pack_ad8804(int addr, int val, int *bitstring); +static int pack_ad8842(int addr, int val, int *bitstring); -struct caldac_struct{ +struct caldac_struct { int n_chans; int n_bits; - int (*packbits)(int,int,int *); + int (*packbits) (int, int, int *); }; static struct caldac_struct caldacs[] = { - [mb88341] = { 12, 8, pack_mb88341 }, - [dac8800] = { 8, 8, pack_dac8800 }, - [dac8043] = { 1, 12, pack_dac8043 }, - [ad8522] = { 2, 12, pack_ad8522 }, - [ad8804] = { 12, 8, pack_ad8804 }, - [ad8842] = { 8, 8, pack_ad8842 }, - [ad8804_debug] = { 16, 8, pack_ad8804 }, + [mb88341] = {12, 8, pack_mb88341}, + [dac8800] = {8, 8, pack_dac8800}, + [dac8043] = {1, 12, pack_dac8043}, + [ad8522] = {2, 12, pack_ad8522}, + [ad8804] = {12, 8, pack_ad8804}, + [ad8842] = {8, 8, pack_ad8842}, + [ad8804_debug] = {16, 8, pack_ad8804}, }; -static void caldac_setup(comedi_device *dev,comedi_subdevice *s) +static void caldac_setup(comedi_device * dev, comedi_subdevice * s) { - int i,j; + int i, j; int n_dacs; - int n_chans=0; + int n_chans = 0; int n_bits; - int diffbits=0; + int diffbits = 0; int type; int chan; type = boardtype.caldac[0]; - if(type==caldac_none)return; - n_bits=caldacs[type].n_bits; - for(i=0;i<3;i++){ + if (type == caldac_none) + return; + n_bits = caldacs[type].n_bits; + for (i = 0; i < 3; i++) { type = boardtype.caldac[i]; - if(type==caldac_none)break; - if(caldacs[type].n_bits!=n_bits)diffbits=1; - n_chans+=caldacs[type].n_chans; + if (type == caldac_none) + break; + if (caldacs[type].n_bits != n_bits) + diffbits = 1; + n_chans += caldacs[type].n_chans; } - n_dacs=i; - s->n_chan=n_chans; + n_dacs = i; + s->n_chan = n_chans; - if(diffbits){ + if (diffbits) { unsigned int *maxdata_list; - if(n_chans>MAX_N_CALDACS){ + if (n_chans > MAX_N_CALDACS) { printk("BUG! MAX_N_CALDACS too small\n"); } - s->maxdata_list=maxdata_list=devpriv->caldac_maxdata_list; - chan=0; - for(i=0;imaxdata_list = maxdata_list = devpriv->caldac_maxdata_list; + chan = 0; + for (i = 0; i < n_dacs; i++) { type = boardtype.caldac[i]; - for(j=0;jn_chan; chan++ ) - ni_write_caldac( dev, i, s->maxdata_list[ i ] / 2 ); - }else{ + for (chan = 0; chan < s->n_chan; chan++) + ni_write_caldac(dev, i, s->maxdata_list[i] / 2); + } else { type = boardtype.caldac[0]; - s->maxdata=(1<maxdata = (1 << caldacs[type].n_bits) - 1; - for( chan = 0; chan < s->n_chan; chan++ ) - ni_write_caldac( dev, i, s->maxdata / 2 ); + for (chan = 0; chan < s->n_chan; chan++) + ni_write_caldac(dev, i, s->maxdata / 2); } } -static void ni_write_caldac(comedi_device *dev,int addr,int val) +static void ni_write_caldac(comedi_device * dev, int addr, int val) { - unsigned int loadbit=0,bits=0,bit,bitstring=0; + unsigned int loadbit = 0, bits = 0, bit, bitstring = 0; int i; int type; //printk("ni_write_caldac: chan=%d val=%d\n",addr,val); - if( devpriv->caldacs[ addr ] == val ) return; - devpriv->caldacs[ addr ] = val; + if (devpriv->caldacs[addr] == val) + return; + devpriv->caldacs[addr] = val; - for(i=0;i<3;i++){ + for (i = 0; i < 3; i++) { type = boardtype.caldac[i]; - if(type==caldac_none)break; - if(addr>=1){ - ni_writeb(((bit&bitstring)?0x02:0),Serial_Command); + for (bit = 1 << (bits - 1); bit; bit >>= 1) { + ni_writeb(((bit & bitstring) ? 0x02 : 0), Serial_Command); comedi_udelay(1); - ni_writeb(1|((bit&bitstring)?0x02:0),Serial_Command); + ni_writeb(1 | ((bit & bitstring) ? 0x02 : 0), Serial_Command); comedi_udelay(1); } - ni_writeb(loadbit,Serial_Command); + ni_writeb(loadbit, Serial_Command); comedi_udelay(1); - ni_writeb(0,Serial_Command); + ni_writeb(0, Serial_Command); } - - -static int pack_mb88341(int addr,int val,int *bitstring) +static int pack_mb88341(int addr, int val, int *bitstring) { /* Fujitsu MB 88341 @@ -4651,107 +4847,114 @@ static int pack_mb88341(int addr,int val,int *bitstring) Note also that the 88341 expects address values from 1-12, whereas we use channel numbers 0-11. The NI docs use 1-12, also, so be careful here. - */ + */ addr++; - *bitstring=((addr&0x1)<<11) | - ((addr&0x2)<<9) | - ((addr&0x4)<<7) | - ((addr&0x8)<<5) | - (val&0xff); + *bitstring = ((addr & 0x1) << 11) | + ((addr & 0x2) << 9) | + ((addr & 0x4) << 7) | ((addr & 0x8) << 5) | (val & 0xff); return 12; } -static int pack_dac8800(int addr,int val,int *bitstring) +static int pack_dac8800(int addr, int val, int *bitstring) { - *bitstring=((addr&0x7)<<8)|(val&0xff); + *bitstring = ((addr & 0x7) << 8) | (val & 0xff); return 11; } -static int pack_dac8043(int addr,int val,int *bitstring) +static int pack_dac8043(int addr, int val, int *bitstring) { - *bitstring=val&0xfff; + *bitstring = val & 0xfff; return 12; } -static int pack_ad8522(int addr,int val,int *bitstring) +static int pack_ad8522(int addr, int val, int *bitstring) { - *bitstring=(val&0xfff)|(addr ? 0xc000:0xa000); + *bitstring = (val & 0xfff) | (addr ? 0xc000 : 0xa000); return 16; } -static int pack_ad8804(int addr,int val,int *bitstring) +static int pack_ad8804(int addr, int val, int *bitstring) { - *bitstring=((addr&0xf)<<8) | (val&0xff); + *bitstring = ((addr & 0xf) << 8) | (val & 0xff); return 12; } -static int pack_ad8842(int addr,int val,int *bitstring) +static int pack_ad8842(int addr, int val, int *bitstring) { - *bitstring=((addr+1)<<8) | (val&0xff); + *bitstring = ((addr + 1) << 8) | (val & 0xff); return 12; } - #if 0 /* * Read the GPCTs current value. */ -static int GPCT_G_Watch(comedi_device *dev, int chan) +static int GPCT_G_Watch(comedi_device * dev, int chan) { - unsigned int hi1,hi2,lo; + unsigned int hi1, hi2, lo; devpriv->gpct_command[chan] &= ~G_Save_Trace; - devpriv->stc_writew(dev, devpriv->gpct_command[chan],G_Command_Register(chan)); + devpriv->stc_writew(dev, devpriv->gpct_command[chan], + G_Command_Register(chan)); devpriv->gpct_command[chan] |= G_Save_Trace; - devpriv->stc_writew(dev, devpriv->gpct_command[chan], G_Command_Register(chan)); + devpriv->stc_writew(dev, devpriv->gpct_command[chan], + G_Command_Register(chan)); /* This procedure is used because the two registers cannot * be read atomically. */ - do{ - hi1 = devpriv->stc_readw(dev, G_Save_Register_High(chan)); + do { + hi1 = devpriv->stc_readw(dev, G_Save_Register_High(chan)); lo = devpriv->stc_readw(dev, G_Save_Register_Low(chan)); - hi2 = devpriv->stc_readw(dev, G_Save_Register_High(chan)); - }while(hi1!=hi2); + hi2 = devpriv->stc_readw(dev, G_Save_Register_High(chan)); + } while (hi1 != hi2); - return (hi1<<16)|lo; + return (hi1 << 16) | lo; } -static void GPCT_Reset(comedi_device *dev, int chan) +static void GPCT_Reset(comedi_device * dev, int chan) { - int temp_ack_reg=0; + int temp_ack_reg = 0; //printk("GPCT_Reset..."); devpriv->gpct_cur_operation[chan] = GPCT_RESET; switch (chan) { - case 0: - devpriv->stc_writew(dev, G0_Reset,Joint_Reset_Register); - ni_set_bits(dev,Interrupt_A_Enable_Register,G0_TC_Interrupt_Enable, 0); - ni_set_bits(dev,Interrupt_A_Enable_Register,G0_Gate_Interrupt_Enable,0); - temp_ack_reg |= G0_Gate_Error_Confirm; - temp_ack_reg |= G0_TC_Error_Confirm; - temp_ack_reg |= G0_TC_Interrupt_Ack; - temp_ack_reg |= G0_Gate_Interrupt_Ack; - devpriv->stc_writew(dev, temp_ack_reg,Interrupt_A_Ack_Register); - - //problem...this interferes with the other ctr... - devpriv->an_trig_etc_reg |= GPFO_0_Output_Enable; - devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, Analog_Trigger_Etc_Register); - break; - case 1: - devpriv->stc_writew(dev, G1_Reset,Joint_Reset_Register); - ni_set_bits(dev,Interrupt_B_Enable_Register,G1_TC_Interrupt_Enable, 0); - ni_set_bits(dev,Interrupt_B_Enable_Register,G0_Gate_Interrupt_Enable,0); - temp_ack_reg |= G1_Gate_Error_Confirm; - temp_ack_reg |= G1_TC_Error_Confirm; - temp_ack_reg |= G1_TC_Interrupt_Ack; - temp_ack_reg |= G1_Gate_Interrupt_Ack; - devpriv->stc_writew(dev, temp_ack_reg,Interrupt_B_Ack_Register); - - devpriv->an_trig_etc_reg |= GPFO_1_Output_Enable; - devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, Analog_Trigger_Etc_Register); - break; + case 0: + devpriv->stc_writew(dev, G0_Reset, Joint_Reset_Register); + ni_set_bits(dev, Interrupt_A_Enable_Register, + G0_TC_Interrupt_Enable, 0); + ni_set_bits(dev, Interrupt_A_Enable_Register, + G0_Gate_Interrupt_Enable, 0); + temp_ack_reg |= G0_Gate_Error_Confirm; + temp_ack_reg |= G0_TC_Error_Confirm; + temp_ack_reg |= G0_TC_Interrupt_Ack; + temp_ack_reg |= G0_Gate_Interrupt_Ack; + devpriv->stc_writew(dev, temp_ack_reg, + Interrupt_A_Ack_Register); + + //problem...this interferes with the other ctr... + devpriv->an_trig_etc_reg |= GPFO_0_Output_Enable; + devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, + Analog_Trigger_Etc_Register); + break; + case 1: + devpriv->stc_writew(dev, G1_Reset, Joint_Reset_Register); + ni_set_bits(dev, Interrupt_B_Enable_Register, + G1_TC_Interrupt_Enable, 0); + ni_set_bits(dev, Interrupt_B_Enable_Register, + G0_Gate_Interrupt_Enable, 0); + temp_ack_reg |= G1_Gate_Error_Confirm; + temp_ack_reg |= G1_TC_Error_Confirm; + temp_ack_reg |= G1_TC_Interrupt_Ack; + temp_ack_reg |= G1_Gate_Interrupt_Ack; + devpriv->stc_writew(dev, temp_ack_reg, + Interrupt_B_Ack_Register); + + devpriv->an_trig_etc_reg |= GPFO_1_Output_Enable; + devpriv->stc_writew(dev, devpriv->an_trig_etc_reg, + Analog_Trigger_Etc_Register); + break; }; devpriv->gpct_mode[chan] = 0; @@ -4760,47 +4963,50 @@ static void GPCT_Reset(comedi_device *dev, int chan) devpriv->gpct_command[chan] |= G_Synchronized_Gate; - devpriv->stc_writew(dev, devpriv->gpct_mode[chan],G_Mode_Register(chan)); - devpriv->stc_writew(dev, devpriv->gpct_input_select[chan],G_Input_Select_Register(chan)); - devpriv->stc_writew(dev, 0,G_Autoincrement_Register(chan)); + devpriv->stc_writew(dev, devpriv->gpct_mode[chan], + G_Mode_Register(chan)); + devpriv->stc_writew(dev, devpriv->gpct_input_select[chan], + G_Input_Select_Register(chan)); + devpriv->stc_writew(dev, 0, G_Autoincrement_Register(chan)); //printk("exit GPCT_Reset\n"); } #endif -static int ni_gpct_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_gpct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { struct ni_gpct *counter = s->private; return ni_tio_insn_config(counter, insn, data); } -static int ni_gpct_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_gpct_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { struct ni_gpct *counter = s->private; return ni_tio_rinsn(counter, insn, data); } -static int ni_gpct_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int ni_gpct_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { struct ni_gpct *counter = s->private; return ni_tio_winsn(counter, insn, data); } -static int ni_gpct_cmd(comedi_device *dev, comedi_subdevice *s) +static int ni_gpct_cmd(comedi_device * dev, comedi_subdevice * s) { int retval; #ifdef PCIDMA struct ni_gpct *counter = s->private; -// const comedi_cmd *cmd = &s->async->cmd; +// const comedi_cmd *cmd = &s->async->cmd; - retval = ni_request_gpct_mite_channel(dev, counter->counter_index, COMEDI_INPUT); - if(retval) - { - comedi_error(dev, "no dma channel available for use by counter"); + retval = ni_request_gpct_mite_channel(dev, counter->counter_index, + COMEDI_INPUT); + if (retval) { + comedi_error(dev, + "no dma channel available for use by counter"); return retval; } ni_tio_acknowledge_and_confirm(counter, NULL, NULL, NULL, NULL); @@ -4812,14 +5018,15 @@ static int ni_gpct_cmd(comedi_device *dev, comedi_subdevice *s) return retval; } -static int ni_gpct_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd) +static int ni_gpct_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { struct ni_gpct *counter = s->private; return ni_tio_cmdtest(counter, cmd); } -static int ni_gpct_cancel(comedi_device *dev, comedi_subdevice *s) +static int ni_gpct_cancel(comedi_device * dev, comedi_subdevice * s) { struct ni_gpct *counter = s->private; int retval; @@ -4836,45 +5043,53 @@ static int ni_gpct_cancel(comedi_device *dev, comedi_subdevice *s) * */ -static int ni_m_series_set_pfi_routing(comedi_device *dev, unsigned chan, unsigned source) +static int ni_m_series_set_pfi_routing(comedi_device * dev, unsigned chan, + unsigned source) { unsigned pfi_reg_index; unsigned array_offset; - if((source & 0x1f) != source) return -EINVAL; + if ((source & 0x1f) != source) + return -EINVAL; pfi_reg_index = 1 + chan / 3; array_offset = pfi_reg_index - 1; - devpriv->pfi_output_select_reg[array_offset] &= ~MSeries_PFI_Output_Select_Mask(chan); - devpriv->pfi_output_select_reg[array_offset] |= MSeries_PFI_Output_Select_Bits(chan, source); - ni_writew(devpriv->pfi_output_select_reg[array_offset], M_Offset_PFI_Output_Select(pfi_reg_index)); + devpriv->pfi_output_select_reg[array_offset] &= + ~MSeries_PFI_Output_Select_Mask(chan); + devpriv->pfi_output_select_reg[array_offset] |= + MSeries_PFI_Output_Select_Bits(chan, source); + ni_writew(devpriv->pfi_output_select_reg[array_offset], + M_Offset_PFI_Output_Select(pfi_reg_index)); return 2; } -static int ni_old_set_pfi_routing(comedi_device *dev, unsigned chan, unsigned source) +static int ni_old_set_pfi_routing(comedi_device * dev, unsigned chan, + unsigned source) { // pre-m-series boards have fixed signals on pfi pins - if(source != ni_old_get_pfi_routing(dev, chan)) return -EINVAL; + if (source != ni_old_get_pfi_routing(dev, chan)) + return -EINVAL; return 2; } -static int ni_set_pfi_routing(comedi_device *dev, unsigned chan, unsigned source) +static int ni_set_pfi_routing(comedi_device * dev, unsigned chan, + unsigned source) { - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) return ni_m_series_set_pfi_routing(dev, chan, source); else return ni_old_set_pfi_routing(dev, chan, source); } -static unsigned ni_m_series_get_pfi_routing(comedi_device *dev, unsigned chan) +static unsigned ni_m_series_get_pfi_routing(comedi_device * dev, unsigned chan) { const unsigned array_offset = chan / 3; - return MSeries_PFI_Output_Select_Source(chan, devpriv->pfi_output_select_reg[array_offset]); + return MSeries_PFI_Output_Select_Source(chan, + devpriv->pfi_output_select_reg[array_offset]); } -static unsigned ni_old_get_pfi_routing(comedi_device *dev, unsigned chan) +static unsigned ni_old_get_pfi_routing(comedi_device * dev, unsigned chan) { // pre-m-series boards have fixed signals on pfi pins - switch(chan) - { + switch (chan) { case 0: return NI_PFI_OUTPUT_AI_START1; break; @@ -4912,19 +5127,19 @@ static unsigned ni_old_get_pfi_routing(comedi_device *dev, unsigned chan) return 0; } -static unsigned ni_get_pfi_routing(comedi_device *dev, unsigned chan) +static unsigned ni_get_pfi_routing(comedi_device * dev, unsigned chan) { - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) return ni_m_series_get_pfi_routing(dev, chan); else return ni_old_get_pfi_routing(dev, chan); } -static int ni_config_filter(comedi_device *dev, unsigned pfi_channel, enum ni_pfi_filter_select filter) +static int ni_config_filter(comedi_device * dev, unsigned pfi_channel, + enum ni_pfi_filter_select filter) { unsigned bits; - if((boardtype.reg_type & ni_reg_m_series_mask) == 0) - { + if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) { return -ENOTSUPP; } bits = ni_readl(M_Offset_PFI_Filter); @@ -4934,15 +5149,13 @@ static int ni_config_filter(comedi_device *dev, unsigned pfi_channel, enum ni_pf return 0; } -static int ni_pfi_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_pfi_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if((boardtype.reg_type & ni_reg_m_series_mask) == 0) - { + if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) { return -ENOTSUPP; } - if(data[0]) - { + if (data[0]) { s->state &= ~data[0]; s->state |= (data[0] & data[1]); ni_writew(s->state, M_Offset_PFI_DO); @@ -4951,24 +5164,28 @@ static int ni_pfi_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int ni_pfi_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_pfi_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int chan; - if(insn->n < 1)return -EINVAL; + if (insn->n < 1) + return -EINVAL; chan = CR_CHAN(insn->chanspec); - switch(data[0]){ + switch (data[0]) { case COMEDI_OUTPUT: - ni_set_bits(dev, IO_Bidirection_Pin_Register, 1<io_bidirection_pin_reg & (1< + io_bidirection_pin_reg & (1 << chan)) ? COMEDI_OUTPUT : + COMEDI_INPUT; return 0; break; case INSN_CONFIG_SET_ROUTING: @@ -4991,39 +5208,44 @@ static int ni_pfi_insn_config(comedi_device *dev,comedi_subdevice *s, * NI RTSI Bus Functions * */ -static void ni_rtsi_init(comedi_device *dev) +static void ni_rtsi_init(comedi_device * dev) { // Initialises the RTSI bus signal switch to a default state // Set clock mode to internal devpriv->clock_and_fout2 = MSeries_RTSI_10MHz_Bit; - if(ni_set_master_clock(dev, NI_MIO_INTERNAL_CLOCK, 0) < 0) - { + if (ni_set_master_clock(dev, NI_MIO_INTERNAL_CLOCK, 0) < 0) { rt_printk("ni_set_master_clock failed, bug?"); } // default internal lines routing to RTSI bus lines - devpriv->rtsi_trig_a_output_reg = RTSI_Trig_Output_Bits(0, NI_RTSI_OUTPUT_ADR_START1) | - RTSI_Trig_Output_Bits(1, NI_RTSI_OUTPUT_ADR_START2) | - RTSI_Trig_Output_Bits(2, NI_RTSI_OUTPUT_SCLKG) | - RTSI_Trig_Output_Bits(3, NI_RTSI_OUTPUT_DACUPDN); + devpriv->rtsi_trig_a_output_reg = + RTSI_Trig_Output_Bits(0, + NI_RTSI_OUTPUT_ADR_START1) | RTSI_Trig_Output_Bits(1, + NI_RTSI_OUTPUT_ADR_START2) | RTSI_Trig_Output_Bits(2, + NI_RTSI_OUTPUT_SCLKG) | RTSI_Trig_Output_Bits(3, + NI_RTSI_OUTPUT_DACUPDN); devpriv->stc_writew(dev, devpriv->rtsi_trig_a_output_reg, RTSI_Trig_A_Output_Register); - devpriv->rtsi_trig_b_output_reg = RTSI_Trig_Output_Bits(4, NI_RTSI_OUTPUT_DA_START1) | - RTSI_Trig_Output_Bits(5, NI_RTSI_OUTPUT_G_SRC0) | - RTSI_Trig_Output_Bits(6, NI_RTSI_OUTPUT_G_GATE0); - if(boardtype.reg_type & ni_reg_m_series_mask) - devpriv->rtsi_trig_b_output_reg |= RTSI_Trig_Output_Bits(7, NI_RTSI_OUTPUT_RTSI_OSC); + devpriv->rtsi_trig_b_output_reg = + RTSI_Trig_Output_Bits(4, + NI_RTSI_OUTPUT_DA_START1) | RTSI_Trig_Output_Bits(5, + NI_RTSI_OUTPUT_G_SRC0) | RTSI_Trig_Output_Bits(6, + NI_RTSI_OUTPUT_G_GATE0); + if (boardtype.reg_type & ni_reg_m_series_mask) + devpriv->rtsi_trig_b_output_reg |= + RTSI_Trig_Output_Bits(7, NI_RTSI_OUTPUT_RTSI_OSC); devpriv->stc_writew(dev, devpriv->rtsi_trig_b_output_reg, RTSI_Trig_B_Output_Register); // Sets the source and direction of the 4 on board lines -// devpriv->stc_writew(dev, 0x0000, RTSI_Board_Register); +// devpriv->stc_writew(dev, 0x0000, RTSI_Board_Register); } -static int ni_rtsi_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_rtsi_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n != 2) return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = 0; @@ -5033,7 +5255,8 @@ static int ni_rtsi_insn_bits(comedi_device *dev,comedi_subdevice *s, /* Find best multiplier/divider to try and get the PLL running at 80 MHz * given an arbitrary frequency input clock */ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns, - unsigned *freq_divider, unsigned *freq_multiplier, unsigned *actual_period_ns) + unsigned *freq_divider, unsigned *freq_multiplier, + unsigned *actual_period_ns) { unsigned div; unsigned best_div = 1; @@ -5049,37 +5272,41 @@ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns, static const unsigned target_picosec = 12500; static const unsigned fudge_factor_80_to_20Mhz = 4; int best_period_picosec = 0; - for(div = 1; div <= max_div; ++div) - { - for(mult = 1; mult <= max_mult; ++mult) - { - unsigned new_period_ps = (reference_picosec * div) / mult; - if(abs(new_period_ps - target_picosec) < abs(best_period_picosec - target_picosec)) - { + for (div = 1; div <= max_div; ++div) { + for (mult = 1; mult <= max_mult; ++mult) { + unsigned new_period_ps = + (reference_picosec * div) / mult; + if (abs(new_period_ps - target_picosec) < + abs(best_period_picosec - target_picosec)) { best_period_picosec = new_period_ps; best_div = div; best_mult = mult; } } } - if(best_period_picosec == 0) - { - rt_printk("%s: bug, failed to find pll parameters\n", __FUNCTION__); + if (best_period_picosec == 0) { + rt_printk("%s: bug, failed to find pll parameters\n", + __FUNCTION__); return -EIO; } *freq_divider = best_div; *freq_multiplier = best_mult; - *actual_period_ns = (best_period_picosec * fudge_factor_80_to_20Mhz + (pico_per_nano / 2)) / pico_per_nano; + *actual_period_ns = + (best_period_picosec * fudge_factor_80_to_20Mhz + + (pico_per_nano / 2)) / pico_per_nano; return 0; } -static inline unsigned num_configurable_rtsi_channels(comedi_device *dev) +static inline unsigned num_configurable_rtsi_channels(comedi_device * dev) { - if(boardtype.reg_type & ni_reg_m_series_mask) return 8; - else return 7; + if (boardtype.reg_type & ni_reg_m_series_mask) + return 8; + else + return 7; } -static int ni_mseries_set_pll_master_clock(comedi_device *dev, unsigned source, unsigned period_ns) +static int ni_mseries_set_pll_master_clock(comedi_device * dev, unsigned source, + unsigned period_ns) { static const unsigned min_period_ns = 50; static const unsigned max_period_ns = 1000; @@ -5089,137 +5316,152 @@ static int ni_mseries_set_pll_master_clock(comedi_device *dev, unsigned source, unsigned freq_multiplier; unsigned i; int retval; - if(source == NI_MIO_PLL_PXI10_CLOCK) period_ns = 100; + if (source == NI_MIO_PLL_PXI10_CLOCK) + period_ns = 100; // these limits are somewhat arbitrary, but NI advertises 1 to 20MHz range so we'll use that - if(period_ns < min_period_ns || period_ns > max_period_ns) - { - rt_printk("%s: you must specify an input clock frequency between %i and %i nanosec " - "for the phased-lock loop.\n", __FUNCTION__, min_period_ns, max_period_ns); + if (period_ns < min_period_ns || period_ns > max_period_ns) { + rt_printk + ("%s: you must specify an input clock frequency between %i and %i nanosec " + "for the phased-lock loop.\n", __FUNCTION__, + min_period_ns, max_period_ns); return -EINVAL; } devpriv->rtsi_trig_direction_reg &= ~Use_RTSI_Clock_Bit; - devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register); - pll_control_bits = MSeries_PLL_Enable_Bit | MSeries_PLL_VCO_Mode_75_150MHz_Bits; - devpriv->clock_and_fout2 |= MSeries_Timebase1_Select_Bit | MSeries_Timebase3_Select_Bit; + devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, + RTSI_Trig_Direction_Register); + pll_control_bits = + MSeries_PLL_Enable_Bit | MSeries_PLL_VCO_Mode_75_150MHz_Bits; + devpriv->clock_and_fout2 |= + MSeries_Timebase1_Select_Bit | MSeries_Timebase3_Select_Bit; devpriv->clock_and_fout2 &= ~MSeries_PLL_In_Source_Select_Mask; - switch(source) - { + switch (source) { case NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK: - devpriv->clock_and_fout2 |= MSeries_PLL_In_Source_Select_Star_Trigger_Bits; + devpriv->clock_and_fout2 |= + MSeries_PLL_In_Source_Select_Star_Trigger_Bits; retval = ni_mseries_get_pll_parameters(period_ns, &freq_divider, &freq_multiplier, &devpriv->clock_ns); - if(retval < 0) return retval; + if (retval < 0) + return retval; break; case NI_MIO_PLL_PXI10_CLOCK: /* pxi clock is 10MHz */ - devpriv->clock_and_fout2 |= MSeries_PLL_In_Source_Select_PXI_Clock10; + devpriv->clock_and_fout2 |= + MSeries_PLL_In_Source_Select_PXI_Clock10; retval = ni_mseries_get_pll_parameters(period_ns, &freq_divider, &freq_multiplier, &devpriv->clock_ns); - if(retval < 0) return retval; + if (retval < 0) + return retval; break; default: { unsigned rtsi_channel; static const unsigned max_rtsi_channel = 7; - for(rtsi_channel = 0; rtsi_channel <= max_rtsi_channel; ++rtsi_channel) - { - if(source == NI_MIO_PLL_RTSI_CLOCK(rtsi_channel)) - { - devpriv->clock_and_fout2 |= MSeries_PLL_In_Source_Select_RTSI_Bits(rtsi_channel); + for (rtsi_channel = 0; rtsi_channel <= max_rtsi_channel; + ++rtsi_channel) { + if (source == + NI_MIO_PLL_RTSI_CLOCK(rtsi_channel)) { + devpriv->clock_and_fout2 |= + MSeries_PLL_In_Source_Select_RTSI_Bits + (rtsi_channel); break; } } - if(rtsi_channel > max_rtsi_channel) return -EINVAL; - retval = ni_mseries_get_pll_parameters(period_ns, &freq_divider, - &freq_multiplier, &devpriv->clock_ns); - if(retval < 0) return retval; + if (rtsi_channel > max_rtsi_channel) + return -EINVAL; + retval = ni_mseries_get_pll_parameters(period_ns, + &freq_divider, &freq_multiplier, + &devpriv->clock_ns); + if (retval < 0) + return retval; } break; } ni_writew(devpriv->clock_and_fout2, M_Offset_Clock_and_Fout2); - pll_control_bits |= MSeries_PLL_Divisor_Bits(freq_divider) | MSeries_PLL_Multiplier_Bits(freq_multiplier); -// rt_printk("using divider=%i, multiplier=%i for PLL. pll_control_bits = 0x%x\n", freq_divider, freq_multiplier, pll_control_bits); -// rt_printk("clock_ns=%d\n", devpriv->clock_ns); + pll_control_bits |= + MSeries_PLL_Divisor_Bits(freq_divider) | + MSeries_PLL_Multiplier_Bits(freq_multiplier); +// rt_printk("using divider=%i, multiplier=%i for PLL. pll_control_bits = 0x%x\n", freq_divider, freq_multiplier, pll_control_bits); +// rt_printk("clock_ns=%d\n", devpriv->clock_ns); ni_writew(pll_control_bits, M_Offset_PLL_Control); devpriv->clock_source = source; /* it seems to typically take a few hundred microseconds for PLL to lock */ - for(i = 0; i < timeout; ++i) - { - if(ni_readw(M_Offset_PLL_Status) & MSeries_PLL_Locked_Bit) - { + for (i = 0; i < timeout; ++i) { + if (ni_readw(M_Offset_PLL_Status) & MSeries_PLL_Locked_Bit) { break; } udelay(1); } - if(i == timeout) - { - rt_printk("%s: timed out waiting for PLL to lock to reference clock source %i with period %i ns.\n", + if (i == timeout) { + rt_printk + ("%s: timed out waiting for PLL to lock to reference clock source %i with period %i ns.\n", __FUNCTION__, source, period_ns); return -ETIMEDOUT; } return 3; } -static int ni_set_master_clock(comedi_device *dev, unsigned source, unsigned period_ns) +static int ni_set_master_clock(comedi_device * dev, unsigned source, + unsigned period_ns) { - if(source == NI_MIO_INTERNAL_CLOCK) - { + if (source == NI_MIO_INTERNAL_CLOCK) { devpriv->rtsi_trig_direction_reg &= ~Use_RTSI_Clock_Bit; - devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register); + devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, + RTSI_Trig_Direction_Register); devpriv->clock_ns = TIMEBASE_1_NS; - if(boardtype.reg_type & ni_reg_m_series_mask) - { - devpriv->clock_and_fout2 &= ~(MSeries_Timebase1_Select_Bit | MSeries_Timebase3_Select_Bit); - ni_writew(devpriv->clock_and_fout2, M_Offset_Clock_and_Fout2); + if (boardtype.reg_type & ni_reg_m_series_mask) { + devpriv->clock_and_fout2 &= + ~(MSeries_Timebase1_Select_Bit | + MSeries_Timebase3_Select_Bit); + ni_writew(devpriv->clock_and_fout2, + M_Offset_Clock_and_Fout2); ni_writew(0, M_Offset_PLL_Control); } devpriv->clock_source = source; - }else - { - if(boardtype.reg_type & ni_reg_m_series_mask) - { - return ni_mseries_set_pll_master_clock(dev, source, period_ns); - }else - { - if(source == NI_MIO_RTSI_CLOCK) - { - devpriv->rtsi_trig_direction_reg |= Use_RTSI_Clock_Bit; - devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register); - if(devpriv->clock_ns == 0) - { - rt_printk("%s: we don't handle an unspecified clock period correctly yet, returning error.\n", + } else { + if (boardtype.reg_type & ni_reg_m_series_mask) { + return ni_mseries_set_pll_master_clock(dev, source, + period_ns); + } else { + if (source == NI_MIO_RTSI_CLOCK) { + devpriv->rtsi_trig_direction_reg |= + Use_RTSI_Clock_Bit; + devpriv->stc_writew(dev, + devpriv->rtsi_trig_direction_reg, + RTSI_Trig_Direction_Register); + if (devpriv->clock_ns == 0) { + rt_printk + ("%s: we don't handle an unspecified clock period correctly yet, returning error.\n", __FUNCTION__); return -EINVAL; - }else - { + } else { devpriv->clock_ns = period_ns; } devpriv->clock_source = source; - }else + } else return -EINVAL; } } return 3; } -static int ni_valid_rtsi_output_source(comedi_device *dev, unsigned chan, unsigned source) +static int ni_valid_rtsi_output_source(comedi_device * dev, unsigned chan, + unsigned source) { - if(chan >= num_configurable_rtsi_channels(dev)) - { - if(chan == old_RTSI_clock_channel) - { - if(source == NI_RTSI_OUTPUT_RTSI_OSC) return 1; - else - { - rt_printk("%s: invalid source for channel=%i, channel %i is always the RTSI clock for pre-m-series boards.\n", - __FUNCTION__, chan, old_RTSI_clock_channel); + if (chan >= num_configurable_rtsi_channels(dev)) { + if (chan == old_RTSI_clock_channel) { + if (source == NI_RTSI_OUTPUT_RTSI_OSC) + return 1; + else { + rt_printk + ("%s: invalid source for channel=%i, channel %i is always the RTSI clock for pre-m-series boards.\n", + __FUNCTION__, chan, + old_RTSI_clock_channel); return 0; } } return 0; } - switch(source) - { + switch (source) { case NI_RTSI_OUTPUT_ADR_START1: case NI_RTSI_OUTPUT_ADR_START2: case NI_RTSI_OUTPUT_SCLKG: @@ -5232,9 +5474,10 @@ static int ni_valid_rtsi_output_source(comedi_device *dev, unsigned chan, unsign return 1; break; case NI_RTSI_OUTPUT_RTSI_OSC: - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) return 1; - else return 0; + else + return 0; break; default: return 0; @@ -5242,75 +5485,90 @@ static int ni_valid_rtsi_output_source(comedi_device *dev, unsigned chan, unsign } } -static int ni_set_rtsi_routing(comedi_device *dev, unsigned chan, unsigned source) +static int ni_set_rtsi_routing(comedi_device * dev, unsigned chan, + unsigned source) { - if(ni_valid_rtsi_output_source(dev, chan, source) == 0) return -EINVAL; - if(chan < 4) - { + if (ni_valid_rtsi_output_source(dev, chan, source) == 0) + return -EINVAL; + if (chan < 4) { devpriv->rtsi_trig_a_output_reg &= ~RTSI_Trig_Output_Mask(chan); - devpriv->rtsi_trig_a_output_reg |= RTSI_Trig_Output_Bits(chan, source); + devpriv->rtsi_trig_a_output_reg |= + RTSI_Trig_Output_Bits(chan, source); devpriv->stc_writew(dev, devpriv->rtsi_trig_a_output_reg, RTSI_Trig_A_Output_Register); - }else if(chan < 8) - { + } else if (chan < 8) { devpriv->rtsi_trig_b_output_reg &= ~RTSI_Trig_Output_Mask(chan); - devpriv->rtsi_trig_b_output_reg |= RTSI_Trig_Output_Bits(chan, source); + devpriv->rtsi_trig_b_output_reg |= + RTSI_Trig_Output_Bits(chan, source); devpriv->stc_writew(dev, devpriv->rtsi_trig_b_output_reg, RTSI_Trig_B_Output_Register); } return 2; } -static unsigned ni_get_rtsi_routing(comedi_device *dev, unsigned chan) +static unsigned ni_get_rtsi_routing(comedi_device * dev, unsigned chan) { - if(chan < 4) - { - return RTSI_Trig_Output_Source(chan, devpriv->rtsi_trig_a_output_reg); - }else if(chan < num_configurable_rtsi_channels(dev)) - { - return RTSI_Trig_Output_Source(chan, devpriv->rtsi_trig_b_output_reg); - }else - { - if(chan == old_RTSI_clock_channel) + if (chan < 4) { + return RTSI_Trig_Output_Source(chan, + devpriv->rtsi_trig_a_output_reg); + } else if (chan < num_configurable_rtsi_channels(dev)) { + return RTSI_Trig_Output_Source(chan, + devpriv->rtsi_trig_b_output_reg); + } else { + if (chan == old_RTSI_clock_channel) return NI_RTSI_OUTPUT_RTSI_OSC; rt_printk("%s: bug! should never get here?\n", __FUNCTION__); return 0; } } -static int ni_rtsi_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_rtsi_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int chan = CR_CHAN(insn->chanspec); - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - if(chan < num_configurable_rtsi_channels(dev)) - { - devpriv->rtsi_trig_direction_reg |= RTSI_Output_Bit(chan, (boardtype.reg_type & ni_reg_m_series_mask) != 0); - }else if(chan == old_RTSI_clock_channel) - { - devpriv->rtsi_trig_direction_reg |= Drive_RTSI_Clock_Bit; + if (chan < num_configurable_rtsi_channels(dev)) { + devpriv->rtsi_trig_direction_reg |= + RTSI_Output_Bit(chan, + (boardtype.reg_type & ni_reg_m_series_mask) != + 0); + } else if (chan == old_RTSI_clock_channel) { + devpriv->rtsi_trig_direction_reg |= + Drive_RTSI_Clock_Bit; } - devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register); + devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, + RTSI_Trig_Direction_Register); break; case INSN_CONFIG_DIO_INPUT: - if(chan < num_configurable_rtsi_channels(dev)) - { - devpriv->rtsi_trig_direction_reg &= ~RTSI_Output_Bit(chan, (boardtype.reg_type & ni_reg_m_series_mask) != 0); - }else if(chan == old_RTSI_clock_channel) - { - devpriv->rtsi_trig_direction_reg &= ~Drive_RTSI_Clock_Bit; + if (chan < num_configurable_rtsi_channels(dev)) { + devpriv->rtsi_trig_direction_reg &= + ~RTSI_Output_Bit(chan, + (boardtype.reg_type & ni_reg_m_series_mask) != + 0); + } else if (chan == old_RTSI_clock_channel) { + devpriv->rtsi_trig_direction_reg &= + ~Drive_RTSI_Clock_Bit; } - devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register); + devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, + RTSI_Trig_Direction_Register); break; case INSN_CONFIG_DIO_QUERY: - if(chan < num_configurable_rtsi_channels(dev)) - { - data[1] = (devpriv->rtsi_trig_direction_reg & RTSI_Output_Bit(chan, (boardtype.reg_type & ni_reg_m_series_mask) != 0)) ? - INSN_CONFIG_DIO_OUTPUT : INSN_CONFIG_DIO_INPUT; - }else if(chan == old_RTSI_clock_channel) - { - data[1] = (devpriv->rtsi_trig_direction_reg & Drive_RTSI_Clock_Bit) ? INSN_CONFIG_DIO_OUTPUT : INSN_CONFIG_DIO_INPUT; + if (chan < num_configurable_rtsi_channels(dev)) { + data[1] = + (devpriv-> + rtsi_trig_direction_reg & RTSI_Output_Bit(chan, + (boardtype. + reg_type & ni_reg_m_series_mask) + != + 0)) ? INSN_CONFIG_DIO_OUTPUT : + INSN_CONFIG_DIO_INPUT; + } else if (chan == old_RTSI_clock_channel) { + data[1] = + (devpriv-> + rtsi_trig_direction_reg & Drive_RTSI_Clock_Bit) + ? INSN_CONFIG_DIO_OUTPUT : + INSN_CONFIG_DIO_INPUT; } return 2; break; @@ -5336,35 +5594,31 @@ static int ni_rtsi_insn_config(comedi_device *dev,comedi_subdevice *s, return 1; } -static int cs5529_wait_for_idle(comedi_device *dev) +static int cs5529_wait_for_idle(comedi_device * dev) { unsigned short status; const int timeout = HZ; int i; - for(i = 0; i < timeout; i++) - { + for (i = 0; i < timeout; i++) { status = ni_ao_win_inw(dev, CAL_ADC_Status_67xx); - if((status & CSS_ADC_BUSY) == 0) - { + if ((status & CSS_ADC_BUSY) == 0) { break; } set_current_state(TASK_INTERRUPTIBLE); - if(schedule_timeout(1)) - { + if (schedule_timeout(1)) { return -EIO; } } //printk("looped %i times waiting for idle\n", i); - if(i == timeout) - { + if (i == timeout) { rt_printk("%s: %s: timeout\n", __FILE__, __FUNCTION__); return -ETIME; } return 0; } -static void cs5529_command(comedi_device *dev, unsigned short value) +static void cs5529_command(comedi_device * dev, unsigned short value) { static const int timeout = 100; int i; @@ -5373,69 +5627,71 @@ static void cs5529_command(comedi_device *dev, unsigned short value) /* give time for command to start being serially clocked into cs5529. * this insures that the CSS_ADC_BUSY bit will get properly * set before we exit this function. - */ - for(i = 0; i < timeout; i++) - { - if((ni_ao_win_inw(dev, CAL_ADC_Status_67xx) & CSS_ADC_BUSY)) + */ + for (i = 0; i < timeout; i++) { + if ((ni_ao_win_inw(dev, CAL_ADC_Status_67xx) & CSS_ADC_BUSY)) break; comedi_udelay(1); } //printk("looped %i times writing command to cs5529\n", i); - if(i == timeout) - { + if (i == timeout) { comedi_error(dev, "possible problem - never saw adc go busy?"); } } /* write to cs5529 register */ -static void cs5529_config_write(comedi_device *dev, unsigned int value, unsigned int reg_select_bits) +static void cs5529_config_write(comedi_device * dev, unsigned int value, + unsigned int reg_select_bits) { - ni_ao_win_outw(dev, ((value >> 16) & 0xff), CAL_ADC_Config_Data_High_Word_67xx); - ni_ao_win_outw(dev, (value & 0xffff), CAL_ADC_Config_Data_Low_Word_67xx); + ni_ao_win_outw(dev, ((value >> 16) & 0xff), + CAL_ADC_Config_Data_High_Word_67xx); + ni_ao_win_outw(dev, (value & 0xffff), + CAL_ADC_Config_Data_Low_Word_67xx); reg_select_bits &= CSCMD_REGISTER_SELECT_MASK; cs5529_command(dev, CSCMD_COMMAND | reg_select_bits); - if(cs5529_wait_for_idle(dev)) + if (cs5529_wait_for_idle(dev)) comedi_error(dev, "time or signal in cs5529_config_write()"); } /* read from cs5529 register */ -static unsigned int cs5529_config_read(comedi_device *dev, unsigned int reg_select_bits) +static unsigned int cs5529_config_read(comedi_device * dev, + unsigned int reg_select_bits) { unsigned int value; reg_select_bits &= CSCMD_REGISTER_SELECT_MASK; cs5529_command(dev, CSCMD_COMMAND | CSCMD_READ | reg_select_bits); - if(cs5529_wait_for_idle(dev)) + if (cs5529_wait_for_idle(dev)) comedi_error(dev, "timeout or signal in cs5529_config_read()"); - value = (ni_ao_win_inw(dev, CAL_ADC_Config_Data_High_Word_67xx) << 16) & 0xff0000; + value = (ni_ao_win_inw(dev, + CAL_ADC_Config_Data_High_Word_67xx) << 16) & 0xff0000; value |= ni_ao_win_inw(dev, CAL_ADC_Config_Data_Low_Word_67xx) & 0xffff; return value; } -static int cs5529_do_conversion(comedi_device *dev, unsigned short *data) +static int cs5529_do_conversion(comedi_device * dev, unsigned short *data) { int retval; unsigned short status; cs5529_command(dev, CSCMD_COMMAND | CSCMD_SINGLE_CONVERSION); retval = cs5529_wait_for_idle(dev); - if(retval) - { - comedi_error(dev, "timeout or signal in cs5529_do_conversion()"); + if (retval) { + comedi_error(dev, + "timeout or signal in cs5529_do_conversion()"); return -ETIME; } status = ni_ao_win_inw(dev, CAL_ADC_Status_67xx); - if(status & CSS_OSC_DETECT) - { - rt_printk("ni_mio_common: cs5529 conversion error, status CSS_OSC_DETECT\n"); + if (status & CSS_OSC_DETECT) { + rt_printk + ("ni_mio_common: cs5529 conversion error, status CSS_OSC_DETECT\n"); return -EIO; } - if(status & CSS_OVERRANGE) - { - rt_printk("ni_mio_common: cs5529 conversion error, overrange (ignoring)\n"); + if (status & CSS_OVERRANGE) { + rt_printk + ("ni_mio_common: cs5529 conversion error, overrange (ignoring)\n"); } - if(data) - { + if (data) { *data = ni_ao_win_inw(dev, CAL_ADC_Data_67xx); /* cs5529 returns 16 bit signed data in bipolar mode */ *data ^= (1 << 15); @@ -5443,7 +5699,8 @@ static int cs5529_do_conversion(comedi_device *dev, unsigned short *data) return 0; } -static int cs5529_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int cs5529_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n, retval; unsigned short sample; @@ -5453,44 +5710,47 @@ static int cs5529_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_ins /* Set calibration adc source. Docs lie, reference select bits 8 to 11 * do nothing. bit 12 seems to chooses internal reference voltage, bit * 13 causes the adc input to go overrange (maybe reads external reference?) */ - if(insn->chanspec & CR_ALT_SOURCE) + if (insn->chanspec & CR_ALT_SOURCE) channel_select = INTERNAL_REF; else channel_select = CR_CHAN(insn->chanspec); ni_ao_win_outw(dev, channel_select, AO_Calibration_Channel_Select_67xx); - for(n = 0; n < insn->n; n++) - { + for (n = 0; n < insn->n; n++) { retval = cs5529_do_conversion(dev, &sample); - if(retval < 0) return retval; + if (retval < 0) + return retval; data[n] = sample; } return insn->n; } -static int init_cs5529(comedi_device *dev) +static int init_cs5529(comedi_device * dev) { - unsigned int config_bits = CSCFG_PORT_MODE | CSCFG_WORD_RATE_2180_CYCLES; + unsigned int config_bits = + CSCFG_PORT_MODE | CSCFG_WORD_RATE_2180_CYCLES; #if 1 /* do self-calibration */ - cs5529_config_write(dev, config_bits | CSCFG_SELF_CAL_OFFSET_GAIN, CSCMD_CONFIG_REGISTER); + cs5529_config_write(dev, config_bits | CSCFG_SELF_CAL_OFFSET_GAIN, + CSCMD_CONFIG_REGISTER); /* need to force a conversion for calibration to run */ cs5529_do_conversion(dev, NULL); #else /* force gain calibration to 1 */ cs5529_config_write(dev, 0x400000, CSCMD_GAIN_REGISTER); - cs5529_config_write(dev, config_bits | CSCFG_SELF_CAL_OFFSET, CSCMD_CONFIG_REGISTER); - if(cs5529_wait_for_idle(dev)) + cs5529_config_write(dev, config_bits | CSCFG_SELF_CAL_OFFSET, + CSCMD_CONFIG_REGISTER); + if (cs5529_wait_for_idle(dev)) comedi_error(dev, "timeout or signal in init_cs5529()\n"); #endif - if(0) - { - rt_printk("config: 0x%x\n", cs5529_config_read(dev, CSCMD_CONFIG_REGISTER)); - rt_printk("gain: 0x%x\n", cs5529_config_read(dev, CSCMD_GAIN_REGISTER)); - rt_printk("offset: 0x%x\n", cs5529_config_read(dev, CSCMD_OFFSET_REGISTER)); + if (0) { + rt_printk("config: 0x%x\n", cs5529_config_read(dev, + CSCMD_CONFIG_REGISTER)); + rt_printk("gain: 0x%x\n", cs5529_config_read(dev, + CSCMD_GAIN_REGISTER)); + rt_printk("offset: 0x%x\n", cs5529_config_read(dev, + CSCMD_OFFSET_REGISTER)); } return 0; } - - diff --git a/comedi/drivers/ni_mio_cs.c b/comedi/drivers/ni_mio_cs.c index 603a69c0..6cc5bc74 100644 --- a/comedi/drivers/ni_mio_cs.c +++ b/comedi/drivers/ni_mio_cs.c @@ -67,119 +67,117 @@ See the notes in the ni_atmio.o driver. #define MAX_N_CALDACS 32 -static const ni_board ni_boards[]={ - { device_id: 0x010d, - name: "DAQCard-ai-16xe-50", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 1024, - alwaysdither: 0, - gainlkup: ai_gain_8, - ai_speed: 5000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - has_8255: 0, - caldac: {dac8800,dac8043}, - }, - { device_id: 0x010c, - name: "DAQCard-ai-16e-4", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 1024, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 4000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - has_8255: 0, - caldac: {mb88341}, /* verified */ - }, - { device_id: 0x02c4, - name: "DAQCard-6062E", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 2000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 1176, - .num_p0_dio_channels = 8, - has_8255: 0, - caldac: {ad8804_debug}, /* verified */ - }, - { device_id: 0x075e, - name: "DAQCard-6024E", /* specs incorrect! */ - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 1024, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 5000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 1000000, - .num_p0_dio_channels = 8, - has_8255: 0, - caldac: {ad8804_debug}, - }, - { device_id: 0x0245, - name: "DAQCard-6036E", /* specs incorrect! */ - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 1024, - alwaysdither: 1, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 1000000, - .num_p0_dio_channels = 8, - has_8255: 0, - caldac: {ad8804_debug}, - }, +static const ni_board ni_boards[] = { + {device_id:0x010d, + name: "DAQCard-ai-16xe-50", + n_adchan:16, + adbits: 16, + ai_fifo_depth:1024, + alwaysdither:0, + gainlkup:ai_gain_8, + ai_speed:5000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + has_8255:0, + caldac: {dac8800, dac8043}, + }, + {device_id:0x010c, + name: "DAQCard-ai-16e-4", + n_adchan:16, + adbits: 12, + ai_fifo_depth:1024, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:4000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + has_8255:0, + caldac: {mb88341}, /* verified */ + }, + {device_id:0x02c4, + name: "DAQCard-6062E", + n_adchan:16, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:2000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:1176, + .num_p0_dio_channels = 8, + has_8255:0, + caldac: {ad8804_debug}, /* verified */ + }, + {device_id:0x075e, + name: "DAQCard-6024E", /* specs incorrect! */ + n_adchan:16, + adbits: 12, + ai_fifo_depth:1024, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:5000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:1000000, + .num_p0_dio_channels = 8, + has_8255:0, + caldac: {ad8804_debug}, + }, + {device_id:0x0245, + name: "DAQCard-6036E", /* specs incorrect! */ + n_adchan:16, + adbits: 16, + ai_fifo_depth:1024, + alwaysdither:1, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:1000000, + .num_p0_dio_channels = 8, + has_8255:0, + caldac: {ad8804_debug}, + }, #if 0 - { device_id: 0x0000, /* unknown */ - name: "DAQCard-6715", - n_adchan: 0, - n_aochan: 8, - aobits: 12, - ao_671x: 8192, - .num_p0_dio_channels = 8, - caldac: {mb88341,mb88341}, - }, + {device_id:0x0000, /* unknown */ + name: "DAQCard-6715", + n_adchan:0, + n_aochan:8, + aobits: 12, + ao_671x: 8192, + .num_p0_dio_channels = 8, + caldac: {mb88341, mb88341}, + }, #endif /* N.B. Update ni_mio_cs_ids[] when entries added above. */ }; - #define interrupt_pin(a) 0 #define IRQ_POLARITY 1 #define NI_E_IRQ_FLAGS IRQF_SHARED -typedef struct{ +typedef struct { struct pcmcia_device *link; - NI_PRIVATE_COMMON -}ni_private; + NI_PRIVATE_COMMON} ni_private; #define devpriv ((ni_private *)dev->private) /* How we access registers */ @@ -197,62 +195,60 @@ typedef struct{ * read/written directly in the I/O space of the board. The * DAQCard devices map the low 8 STC registers to iobase+addr*2. */ -static void mio_cs_win_out(comedi_device *dev, uint16_t data, int addr) +static void mio_cs_win_out(comedi_device * dev, uint16_t data, int addr) { unsigned long flags; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - if(addr<8){ - ni_writew(data,addr*2); - }else{ - ni_writew(addr,Window_Address); - ni_writew(data,Window_Data); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + if (addr < 8) { + ni_writew(data, addr * 2); + } else { + ni_writew(addr, Window_Address); + ni_writew(data, Window_Data); } - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); } -static uint16_t mio_cs_win_in(comedi_device *dev, int addr) +static uint16_t mio_cs_win_in(comedi_device * dev, int addr) { unsigned long flags; uint16_t ret; - comedi_spin_lock_irqsave(&devpriv->window_lock,flags); - if(addr<8){ - ret = ni_readw(addr*2); - }else{ - ni_writew(addr,Window_Address); + comedi_spin_lock_irqsave(&devpriv->window_lock, flags); + if (addr < 8) { + ret = ni_readw(addr * 2); + } else { + ni_writew(addr, Window_Address); ret = ni_readw(Window_Data); } - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); return ret; } -static int mio_cs_attach(comedi_device *dev,comedi_devconfig *it); -static int mio_cs_detach(comedi_device *dev); -static comedi_driver driver_ni_mio_cs={ - driver_name: "ni_mio_cs", - module: THIS_MODULE, - attach: mio_cs_attach, - detach: mio_cs_detach, +static int mio_cs_attach(comedi_device * dev, comedi_devconfig * it); +static int mio_cs_detach(comedi_device * dev); +static comedi_driver driver_ni_mio_cs = { + driver_name:"ni_mio_cs", + module:THIS_MODULE, + attach:mio_cs_attach, + detach:mio_cs_detach, }; - #include "ni_mio_common.c" - -static int ni_getboardtype(comedi_device *dev,struct pcmcia_device *link); +static int ni_getboardtype(comedi_device * dev, struct pcmcia_device *link); /* clean up allocated resources */ /* called when driver is removed */ -static int mio_cs_detach(comedi_device *dev) +static int mio_cs_detach(comedi_device * dev) { mio_common_detach(dev); /* PCMCIA layer frees the IO region */ - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } return 0; @@ -266,7 +262,7 @@ static struct pcmcia_device *cur_dev = NULL; static const dev_info_t dev_info = "ni_mio_cs"; static dev_node_t dev_node = { "ni_mio_cs", - COMEDI_MAJOR,0, + COMEDI_MAJOR, 0, NULL }; static int cs_attach(struct pcmcia_device *link) @@ -292,10 +288,9 @@ static void cs_release(struct pcmcia_device *link) static void cs_detach(struct pcmcia_device *link) { - DPRINTK("cs_detach(link=%p)\n",link); + DPRINTK("cs_detach(link=%p)\n", link); - if(link->dev_node) - { + if (link->dev_node) { cs_release(link); } } @@ -303,7 +298,7 @@ static void cs_detach(struct pcmcia_device *link) static int mio_cs_suspend(struct pcmcia_device *link) { DPRINTK("pm suspend\n"); - + return 0; } @@ -321,9 +316,9 @@ static void mio_cs_config(struct pcmcia_device *link) int manfid = 0, prodid = 0; int ret; - DPRINTK("mio_cs_config(link=%p)\n",link); + DPRINTK("mio_cs_config(link=%p)\n", link); - tuple.TupleData = (cisdata_t *)buf; + tuple.TupleData = (cisdata_t *) buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; tuple.Attributes = 0; @@ -338,13 +333,13 @@ static void mio_cs_config(struct pcmcia_device *link) #if 0 tuple.DesiredTuple = CISTPL_LONGLINK_MFC; tuple.Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK; - info->multi (first_tuple(link, &tuple, &parse) == CS_SUCCESS); + info->multi(first_tuple(link, &tuple, &parse) == CS_SUCCESS); #endif tuple.DesiredTuple = CISTPL_MANFID; tuple.Attributes = TUPLE_RETURN_COMMON; - if((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && - (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)){ + if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && + (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) { manfid = le16_to_cpu(buf[0]); prodid = le16_to_cpu(buf[1]); } @@ -357,49 +352,49 @@ static void mio_cs_config(struct pcmcia_device *link) ret = pcmcia_parse_tuple(link, &tuple, &parse); #if 0 - printk(" index: 0x%x\n",parse.cftable_entry.index); - printk(" flags: 0x%x\n",parse.cftable_entry.flags); - printk(" io flags: 0x%x\n",parse.cftable_entry.io.flags); - printk(" io nwin: 0x%x\n",parse.cftable_entry.io.nwin); - printk(" io base: 0x%x\n",parse.cftable_entry.io.win[0].base); - printk(" io len: 0x%x\n",parse.cftable_entry.io.win[0].len); - printk(" irq1: 0x%x\n",parse.cftable_entry.irq.IRQInfo1); - printk(" irq2: 0x%x\n",parse.cftable_entry.irq.IRQInfo2); - printk(" mem flags: 0x%x\n",parse.cftable_entry.mem.flags); - printk(" mem nwin: 0x%x\n",parse.cftable_entry.mem.nwin); - printk(" subtuples: 0x%x\n",parse.cftable_entry.subtuples); + printk(" index: 0x%x\n", parse.cftable_entry.index); + printk(" flags: 0x%x\n", parse.cftable_entry.flags); + printk(" io flags: 0x%x\n", parse.cftable_entry.io.flags); + printk(" io nwin: 0x%x\n", parse.cftable_entry.io.nwin); + printk(" io base: 0x%x\n", parse.cftable_entry.io.win[0].base); + printk(" io len: 0x%x\n", parse.cftable_entry.io.win[0].len); + printk(" irq1: 0x%x\n", parse.cftable_entry.irq.IRQInfo1); + printk(" irq2: 0x%x\n", parse.cftable_entry.irq.IRQInfo2); + printk(" mem flags: 0x%x\n", parse.cftable_entry.mem.flags); + printk(" mem nwin: 0x%x\n", parse.cftable_entry.mem.nwin); + printk(" subtuples: 0x%x\n", parse.cftable_entry.subtuples); #endif - #if 0 - link->io.NumPorts1=0x20; - link->io.IOAddrLines=5; - link->io.Attributes1=IO_DATA_PATH_WIDTH_AUTO; + link->io.NumPorts1 = 0x20; + link->io.IOAddrLines = 5; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; #endif - link->io.NumPorts1=parse.cftable_entry.io.win[0].len; - link->io.IOAddrLines=parse.cftable_entry.io.flags & CISTPL_IO_LINES_MASK; - link->io.NumPorts2=0; + link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; + link->io.IOAddrLines = + parse.cftable_entry.io.flags & CISTPL_IO_LINES_MASK; + link->io.NumPorts2 = 0; { int base; - for(base=0x000;base<0x400;base+=0x20){ - link->io.BasePort1=base; + for (base = 0x000; base < 0x400; base += 0x20) { + link->io.BasePort1 = base; ret = pcmcia_request_io(link, &link->io); //printk("RequestIO 0x%02x\n",ret); - if(!ret)break; + if (!ret) + break; } } - link->irq.IRQInfo1=parse.cftable_entry.irq.IRQInfo1; - link->irq.IRQInfo2=parse.cftable_entry.irq.IRQInfo2; + link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1; + link->irq.IRQInfo2 = parse.cftable_entry.irq.IRQInfo2; ret = pcmcia_request_irq(link, &link->irq); - if(ret) - { + if (ret) { printk("pcmcia_request_irq() returned error: %i\n", ret); } //printk("RequestIRQ 0x%02x\n",ret); - link->conf.ConfigIndex=1; + link->conf.ConfigIndex = 1; ret = pcmcia_request_configuration(link, &link->conf); //printk("RequestConfiguration %d\n",ret); @@ -407,126 +402,124 @@ static void mio_cs_config(struct pcmcia_device *link) link->dev_node = &dev_node; } -static int mio_cs_attach(comedi_device *dev,comedi_devconfig *it) +static int mio_cs_attach(comedi_device * dev, comedi_devconfig * it) { struct pcmcia_device *link; unsigned int irq; int ret; - DPRINTK("mio_cs_attach(dev=%p,it=%p)\n",dev,it); + DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev, it); - link = cur_dev; /* XXX hack */ - if(!link)return -EIO; + link = cur_dev; /* XXX hack */ + if (!link) + return -EIO; - dev->driver=&driver_ni_mio_cs; - dev->iobase=link->io.BasePort1; + dev->driver = &driver_ni_mio_cs; + dev->iobase = link->io.BasePort1; - irq=link->irq.AssignedIRQ; + irq = link->irq.AssignedIRQ; printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ", - dev->minor,dev->driver->driver_name,dev->iobase, - irq); + dev->minor, dev->driver->driver_name, dev->iobase, irq); #if 0 { int i; printk(" board fingerprint:"); - for(i=0;i<32;i+=2){ - printk(" %04x %02x",inw(dev->iobase+i),inb(dev->iobase+i+1)); + for (i = 0; i < 32; i += 2) { + printk(" %04x %02x", inw(dev->iobase + i), + inb(dev->iobase + i + 1)); } printk("\n"); printk(" board fingerprint (windowed):"); - for(i=0;i<10;i++){ - printk(" 0x%04x",win_in(i)); + for (i = 0; i < 10; i++) { + printk(" 0x%04x", win_in(i)); } printk("\n"); } #endif - dev->board_ptr = ni_boards + ni_getboardtype(dev,link); + dev->board_ptr = ni_boards + ni_getboardtype(dev, link); - printk(" %s",boardtype.name); - dev->board_name=boardtype.name; + printk(" %s", boardtype.name); + dev->board_name = boardtype.name; - if( (ret=comedi_request_irq(irq,ni_E_interrupt,NI_E_IRQ_FLAGS,"ni_mio_cs",dev))<0 ){ + if ((ret = comedi_request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS, + "ni_mio_cs", dev)) < 0) { printk(" irq not available\n"); return -EINVAL; } dev->irq = irq; /* allocate private area */ - if((ret=ni_alloc_private(dev))<0) + if ((ret = ni_alloc_private(dev)) < 0) return ret; devpriv->stc_writew = &mio_cs_win_out; devpriv->stc_readw = &mio_cs_win_in; devpriv->stc_writel = &win_out2; devpriv->stc_readl = &win_in2; - if( (ret=ni_E_init(dev,it))<0 ){ + if ((ret = ni_E_init(dev, it)) < 0) { return ret; } return 0; } - -static int get_prodid(comedi_device *dev,struct pcmcia_device *link) +static int get_prodid(comedi_device * dev, struct pcmcia_device *link) { tuple_t tuple; u_short buf[128]; int prodid = 0; - tuple.TupleData = (cisdata_t *)buf; + tuple.TupleData = (cisdata_t *) buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; tuple.DesiredTuple = CISTPL_MANFID; tuple.Attributes = TUPLE_RETURN_COMMON; - if((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && - (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)){ + if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && + (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) { prodid = le16_to_cpu(buf[1]); } return prodid; } -static int ni_getboardtype(comedi_device *dev,struct pcmcia_device *link) +static int ni_getboardtype(comedi_device * dev, struct pcmcia_device *link) { int id; int i; - id = get_prodid(dev,link); + id = get_prodid(dev, link); - for(i=0;ihandle); #endif comedi_driver_unregister(&driver_ni_mio_cs); diff --git a/comedi/drivers/ni_pcidio.c b/comedi/drivers/ni_pcidio.c index a95abef8..cf2b2fca 100644 --- a/comedi/drivers/ni_pcidio.c +++ b/comedi/drivers/ni_pcidio.c @@ -74,7 +74,6 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org #include "mite.h" #include "8255.h" - #undef DPRINTK #ifdef DEBUG #define DPRINTK(format, args...) printk(format, ## args) @@ -99,37 +98,37 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org #define Window_Address 4 /* W */ #define Interrupt_And_Window_Status 4 /* R */ - #define IntStatus1 (1<<0) - #define IntStatus2 (1<<1) - #define WindowAddressStatus_mask 0x7c +#define IntStatus1 (1<<0) +#define IntStatus2 (1<<1) +#define WindowAddressStatus_mask 0x7c #define Master_DMA_And_Interrupt_Control 5 /* W */ - #define InterruptLine(x) ((x)&3) - #define OpenInt (1<<2) +#define InterruptLine(x) ((x)&3) +#define OpenInt (1<<2) #define Group_Status 5 /* R */ - #define DataLeft (1<<0) - #define Req (1<<2) - #define StopTrig (1<<3) +#define DataLeft (1<<0) +#define Req (1<<2) +#define StopTrig (1<<3) #define Group_1_Flags 6 /* R */ #define Group_2_Flags 7 /* R */ - #define TransferReady (1<<0) - #define CountExpired (1<<1) - #define Waited (1<<5) - #define PrimaryTC (1<<6) - #define SecondaryTC (1<<7) +#define TransferReady (1<<0) +#define CountExpired (1<<1) +#define Waited (1<<5) +#define PrimaryTC (1<<6) +#define SecondaryTC (1<<7) //#define SerialRose //#define ReqRose //#define Paused #define Group_1_First_Clear 6 /* W */ #define Group_2_First_Clear 7 /* W */ - #define ClearWaited (1<<3) - #define ClearPrimaryTC (1<<4) - #define ClearSecondaryTC (1<<5) - #define DMAReset (1<<6) - #define FIFOReset (1<<7) - #define ClearAll 0xf8 +#define ClearWaited (1<<3) +#define ClearPrimaryTC (1<<4) +#define ClearSecondaryTC (1<<5) +#define DMAReset (1<<6) +#define FIFOReset (1<<7) +#define ClearAll 0xf8 #define Group_1_FIFO 8 /* W */ #define Group_2_FIFO 12 /* W */ @@ -145,62 +144,62 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org #define Port_Pin_Polarities(x) (40+(x)) #define Master_Clock_Routing 45 - #define RTSIClocking(x) (((x)&3)<<4) +#define RTSIClocking(x) (((x)&3)<<4) #define Group_1_Second_Clear 46 /* W */ #define Group_2_Second_Clear 47 /* W */ - #define ClearExpired (1<<0) +#define ClearExpired (1<<0) #define Port_Pattern(x) (48+(x)) #define Data_Path 64 - #define FIFOEnableA (1<<0) - #define FIFOEnableB (1<<1) - #define FIFOEnableC (1<<2) - #define FIFOEnableD (1<<3) - #define Funneling(x) (((x)&3)<<4) - #define GroupDirection (1<<7) +#define FIFOEnableA (1<<0) +#define FIFOEnableB (1<<1) +#define FIFOEnableC (1<<2) +#define FIFOEnableD (1<<3) +#define Funneling(x) (((x)&3)<<4) +#define GroupDirection (1<<7) #define Protocol_Register_1 65 #define OpMode Protocol_Register_1 - #define RunMode(x) ((x)&7) - #define Numbered (1<<3) +#define RunMode(x) ((x)&7) +#define Numbered (1<<3) #define Protocol_Register_2 66 #define ClockReg Protocol_Register_2 - #define ClockLine(x) (((x)&3)<<5) - #define InvertStopTrig (1<<7) - #define DataLatching(x) (((x)&3)<<5) +#define ClockLine(x) (((x)&3)<<5) +#define InvertStopTrig (1<<7) +#define DataLatching(x) (((x)&3)<<5) #define Protocol_Register_3 67 #define Sequence Protocol_Register_3 -#define Protocol_Register_14 68 /* 16 bit */ +#define Protocol_Register_14 68 /* 16 bit */ #define ClockSpeed Protocol_Register_14 #define Protocol_Register_4 70 #define ReqReg Protocol_Register_4 - #define ReqConditioning(x) (((x)&7)<<3) +#define ReqConditioning(x) (((x)&7)<<3) #define Protocol_Register_5 71 #define BlockMode Protocol_Register_5 #define FIFO_Control 72 - #define ReadyLevel(x) ((x)&7) +#define ReadyLevel(x) ((x)&7) #define Protocol_Register_6 73 #define LinePolarities Protocol_Register_6 - #define InvertAck (1<<0) - #define InvertReq (1<<1) - #define InvertClock (1<<2) - #define InvertSerial (1<<3) - #define OpenAck (1<<4) - #define OpenClock (1<<5) +#define InvertAck (1<<0) +#define InvertReq (1<<1) +#define InvertClock (1<<2) +#define InvertSerial (1<<3) +#define OpenAck (1<<4) +#define OpenClock (1<<5) #define Protocol_Register_7 74 #define AckSer Protocol_Register_7 - #define AckLine(x) (((x)&3)<<2) - #define ExchangePins (1<<7) +#define AckLine(x) (((x)&3)<<2) +#define ExchangePins (1<<7) #define Interrupt_Control 75 /* bits same as flags */ @@ -218,22 +217,22 @@ static inline unsigned secondary_DMAChannel_bits(unsigned channel) } #define Transfer_Size_Control 77 - #define TransferWidth(x) ((x)&3) - #define TransferLength(x) (((x)&3)<<3) - #define RequireRLevel (1<<5) +#define TransferWidth(x) ((x)&3) +#define TransferLength(x) (((x)&3)<<3) +#define RequireRLevel (1<<5) #define Protocol_Register_15 79 #define DAQOptions Protocol_Register_15 - #define StartSource(x) ((x)&0x3) - #define InvertStart (1<<2) - #define StopSource(x) (((x)&0x3)<<3) - #define ReqStart (1<<6) - #define PreStart (1<<7) +#define StartSource(x) ((x)&0x3) +#define InvertStart (1<<2) +#define StopSource(x) (((x)&0x3)<<3) +#define ReqStart (1<<6) +#define PreStart (1<<7) #define Pattern_Detection 81 - #define DetectionMethod (1<<0) - #define InvertMatch (1<<1) - #define IE_Pattern_Detection (1<<2) +#define DetectionMethod (1<<0) +#define InvertMatch (1<<1) +#define IE_Pattern_Detection (1<<2) #define Protocol_Register_9 82 #define ReqDelay Protocol_Register_9 @@ -250,11 +249,10 @@ static inline unsigned secondary_DMAChannel_bits(unsigned channel) #define Protocol_Register_13 86 #define Data1Delay Protocol_Register_13 -#define Protocol_Register_8 88 /* 32 bit */ +#define Protocol_Register_8 88 /* 32 bit */ #define StartDelay Protocol_Register_8 -enum pci_6534_firmware_registers /* 16 bit */ -{ +enum pci_6534_firmware_registers { /* 16 bit */ Firmware_Control_Register = 0x100, Firmware_Status_Register = 0x104, Firmware_Data_Register = 0x108, @@ -262,24 +260,22 @@ enum pci_6534_firmware_registers /* 16 bit */ Firmware_Debug_Register = 0x110, }; /* main fpga registers (32 bit)*/ -enum pci_6534_fpga_registers -{ +enum pci_6534_fpga_registers { FPGA_Control1_Register = 0x200, FPGA_Control2_Register = 0x204, FPGA_Irq_Mask_Register = 0x208, FPGA_Status_Register = 0x20c, FPGA_Signature_Register = 0x210, - FPGA_SCALS_Counter_Register = 0x280, /*write-clear*/ - FPGA_SCAMS_Counter_Register = 0x284, /*write-clear*/ - FPGA_SCBLS_Counter_Register = 0x288, /*write-clear*/ - FPGA_SCBMS_Counter_Register = 0x28c, /*write-clear*/ + FPGA_SCALS_Counter_Register = 0x280, /*write-clear */ + FPGA_SCAMS_Counter_Register = 0x284, /*write-clear */ + FPGA_SCBLS_Counter_Register = 0x288, /*write-clear */ + FPGA_SCBMS_Counter_Register = 0x28c, /*write-clear */ FPGA_Temp_Control_Register = 0x2a0, FPGA_DAR_Register = 0x2a8, FPGA_ELC_Read_Register = 0x2b8, FPGA_ELC_Write_Register = 0x2bc, }; -enum FPGA_Control_Bits -{ +enum FPGA_Control_Bits { FPGA_Enable_Bit = 0x8000, }; @@ -291,107 +287,110 @@ enum FPGA_Control_Bits #define IntEn (TransferReady|CountExpired|Waited|PrimaryTC|SecondaryTC) #endif -static int nidio_attach(comedi_device *dev,comedi_devconfig *it); -static int nidio_detach(comedi_device *dev); -static int ni_pcidio_cancel(comedi_device *dev, comedi_subdevice *s); +static int nidio_attach(comedi_device * dev, comedi_devconfig * it); +static int nidio_detach(comedi_device * dev); +static int ni_pcidio_cancel(comedi_device * dev, comedi_subdevice * s); -static comedi_driver driver_pcidio={ - driver_name: "ni_pcidio", - module: THIS_MODULE, - attach: nidio_attach, - detach: nidio_detach, +static comedi_driver driver_pcidio = { + driver_name:"ni_pcidio", + module:THIS_MODULE, + attach:nidio_attach, + detach:nidio_detach, }; + COMEDI_INITCLEANUP(driver_pcidio); -typedef struct{ +typedef struct { int dev_id; const char *name; int n_8255; - unsigned int is_diodaq : 1; - unsigned int uses_firmware : 1; -}nidio_board; -static const nidio_board nidio_boards[]={ + unsigned int is_diodaq:1; + unsigned int uses_firmware:1; +} nidio_board; +static const nidio_board nidio_boards[] = { { - dev_id: 0x1150, - name: "pci-dio-32hs", - n_8255: 0, - is_diodaq: 1, - }, + dev_id: 0x1150, + name: "pci-dio-32hs", + n_8255: 0, + is_diodaq:1, + }, { - dev_id: 0x1320, - name: "pxi-6533", - n_8255: 0, - is_diodaq: 1, - }, + dev_id: 0x1320, + name: "pxi-6533", + n_8255: 0, + is_diodaq:1, + }, { - dev_id: 0x12b0, - name: "pci-6534", - n_8255: 0, - is_diodaq: 1, - uses_firmware: 1, - }, + dev_id: 0x12b0, + name: "pci-6534", + n_8255: 0, + is_diodaq:1, + uses_firmware:1, + }, { - dev_id: 0x0160, - name: "pci-dio-96", - n_8255: 4, - is_diodaq: 0, - }, + dev_id: 0x0160, + name: "pci-dio-96", + n_8255: 4, + is_diodaq:0, + }, { - dev_id: 0x1630, - name: "pci-dio-96b", - n_8255: 4, - is_diodaq: 0, - }, + dev_id: 0x1630, + name: "pci-dio-96b", + n_8255: 4, + is_diodaq:0, + }, { - dev_id: 0x13c0, - name: "pxi-6508", - n_8255: 4, - is_diodaq: 0, - }, + dev_id: 0x13c0, + name: "pxi-6508", + n_8255: 4, + is_diodaq:0, + }, { - dev_id: 0x0400, - name: "pci-6503", - n_8255: 1, - is_diodaq: 0, - }, + dev_id: 0x0400, + name: "pci-6503", + n_8255: 1, + is_diodaq:0, + }, { - dev_id: 0x1250, - name: "pci-6503b", - n_8255: 1, - is_diodaq: 0, - }, + dev_id: 0x1250, + name: "pci-6503b", + n_8255: 1, + is_diodaq:0, + }, { - dev_id: 0x17d0, - name: "pci-6503x", - n_8255: 1, - is_diodaq: 0, - }, + dev_id: 0x17d0, + name: "pci-6503x", + n_8255: 1, + is_diodaq:0, + }, { - dev_id: 0x1800, - name: "pxi-6503", - n_8255: 1, - is_diodaq: 0, - }, + dev_id: 0x1800, + name: "pxi-6503", + n_8255: 1, + is_diodaq:0, + }, }; + #define n_nidio_boards (sizeof(nidio_boards)/sizeof(nidio_boards[0])) #define this_board ((const nidio_board *)dev->board_ptr) static struct pci_device_id ni_pcidio_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x1150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x12b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x0160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1630, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x13c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x0400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x17d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x1150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x12b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x0160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1630, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x13c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x0400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x17d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, ni_pcidio_pci_table); -typedef struct{ +typedef struct { struct mite_struct *mite; int boardtype; int dio; @@ -399,17 +398,17 @@ typedef struct{ struct mite_channel *di_mite_chan; struct mite_dma_descriptor_ring *di_mite_ring; spinlock_t mite_channel_lock; -}nidio96_private; +} nidio96_private; #define devpriv ((nidio96_private *)dev->private) -static int ni_pcidio_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int ni_pcidio_cmd(comedi_device *dev,comedi_subdevice *s); -static int ni_pcidio_inttrig(comedi_device *dev, comedi_subdevice *s, +static int ni_pcidio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int ni_pcidio_cmd(comedi_device * dev, comedi_subdevice * s); +static int ni_pcidio_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum); -static int nidio_find_device(comedi_device *dev,int bus,int slot); +static int nidio_find_device(comedi_device * dev, int bus, int slot); static int ni_pcidio_ns_to_timer(int *nanosec, int round_mode); -static int setup_mite_dma(comedi_device *dev,comedi_subdevice *s); +static int setup_mite_dma(comedi_device * dev, comedi_subdevice * s); #ifdef DEBUG_FLAGS static void ni_pcidio_print_flags(unsigned int flags); @@ -419,16 +418,18 @@ static void ni_pcidio_print_status(unsigned int status); #define ni_pcidio_print_status(x) #endif -static int ni_pcidio_request_di_mite_channel(comedi_device *dev) +static int ni_pcidio_request_di_mite_channel(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); BUG_ON(devpriv->di_mite_chan); - devpriv->di_mite_chan = mite_request_channel_in_range(devpriv->mite, devpriv->di_mite_ring, 1, 2); - if(devpriv->di_mite_chan == NULL) - { - comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); + devpriv->di_mite_chan = + mite_request_channel_in_range(devpriv->mite, + devpriv->di_mite_ring, 1, 2); + if (devpriv->di_mite_chan == NULL) { + comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, + flags); comedi_error(dev, "failed to reserve mite dma channel."); return -EBUSY; } @@ -440,13 +441,12 @@ static int ni_pcidio_request_di_mite_channel(comedi_device *dev) return 0; } -static void ni_pcidio_release_di_mite_channel(comedi_device *dev) +static void ni_pcidio_release_di_mite_channel(comedi_device * dev) { unsigned long flags; comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags); - if(devpriv->di_mite_chan) - { + if (devpriv->di_mite_chan) { mite_dma_disarm(devpriv->di_mite_chan); mite_dma_reset(devpriv->di_mite_chan); mite_release_channel(devpriv->di_mite_chan); @@ -458,19 +458,20 @@ static void ni_pcidio_release_di_mite_channel(comedi_device *dev) comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags); } -static int nidio96_8255_cb(int dir,int port,int data,unsigned long iobase) +static int nidio96_8255_cb(int dir, int port, int data, unsigned long iobase) { - if(dir){ - writeb(data,(void*)(iobase + port)); + if (dir) { + writeb(data, (void *)(iobase + port)); return 0; - }else{ - return readb((void*)(iobase + port)); + } else { + return readb((void *)(iobase + port)); } } -void ni_pcidio_event(comedi_device *dev, comedi_subdevice *s) +void ni_pcidio_event(comedi_device * dev, comedi_subdevice * s) { - if(s->async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) + if (s->async-> + events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) { ni_pcidio_cancel(dev, s); } @@ -479,7 +480,7 @@ void ni_pcidio_event(comedi_device *dev, comedi_subdevice *s) static irqreturn_t nidio_interrupt(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; + comedi_device *dev = d; comedi_subdevice *s = dev->subdevices; comedi_async *async = s->async; struct mite_struct *mite = devpriv->mite; @@ -495,16 +496,17 @@ static irqreturn_t nidio_interrupt(int irq, void *d PT_REGS_ARG) unsigned long irq_flags; //interrupcions parasites - if(dev->attached == 0){ + if (dev->attached == 0) { // assume it's from another card return IRQ_NONE; } - status = readb(devpriv->mite->daq_io_addr+Interrupt_And_Window_Status); - flags = readb(devpriv->mite->daq_io_addr+Group_1_Flags); + status = readb(devpriv->mite->daq_io_addr + + Interrupt_And_Window_Status); + flags = readb(devpriv->mite->daq_io_addr + Group_1_Flags); DPRINTK("ni_pcidio_interrupt: status=0x%02x,flags=0x%02x\n", - status,flags); + status, flags); ni_pcidio_print_flags(flags); ni_pcidio_print_status(status); @@ -512,20 +514,23 @@ static irqreturn_t nidio_interrupt(int irq, void *d PT_REGS_ARG) //printk("buf[4096]=%08x\n",*(unsigned int *)(async->prealloc_buf+4096)); comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, irq_flags); - if(devpriv->di_mite_chan) + if (devpriv->di_mite_chan) m_status = mite_get_status(devpriv->di_mite_chan); #ifdef MITE_DEBUG mite_print_chsr(m_status); #endif //printk("mite_bytes_transferred: %d\n",mite_bytes_transferred(mite,DI_DMA_CHAN)); //mite_dump_regs(mite); - if(m_status & CHSR_INT){ - if(m_status & CHSR_LINKC){ - writel(CHOR_CLRLC, mite->mite_io_addr + MITE_CHOR(devpriv->di_mite_chan->channel)); + if (m_status & CHSR_INT) { + if (m_status & CHSR_LINKC) { + writel(CHOR_CLRLC, + mite->mite_io_addr + + MITE_CHOR(devpriv->di_mite_chan->channel)); mite_sync_input_dma(devpriv->di_mite_chan, s->async); /* XXX need to byteswap */ } - if(m_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_DRDY | CHSR_DRQ1 | CHSR_MRDY)){ + if (m_status & ~(CHSR_INT | CHSR_LINKC | CHSR_DONE | CHSR_DRDY | + CHSR_DRQ1 | CHSR_MRDY)) { DPRINTK("unknown mite interrupt, disabling IRQ\n"); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; disable_irq(dev->irq); @@ -533,32 +538,39 @@ static irqreturn_t nidio_interrupt(int irq, void *d PT_REGS_ARG) } comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, irq_flags); - while(status&DataLeft){ + while (status & DataLeft) { work++; - if(work>20){ + if (work > 20) { DPRINTK("too much work in interrupt\n"); - writeb(0x00,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + writeb(0x00, + devpriv->mite->daq_io_addr + + Master_DMA_And_Interrupt_Control); break; } flags &= IntEn; - if(flags & TransferReady){ + if (flags & TransferReady) { //DPRINTK("TransferReady\n"); - while(flags & TransferReady){ + while (flags & TransferReady) { work++; - if(work>100){ + if (work > 100) { DPRINTK("too much work in interrupt\n"); - writeb(0x00,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + writeb(0x00, + devpriv->mite->daq_io_addr + + Master_DMA_And_Interrupt_Control); goto out; } - AuxData = readl(devpriv->mite->daq_io_addr+Group_1_FIFO); + AuxData = + readl(devpriv->mite->daq_io_addr + + Group_1_FIFO); data1 = AuxData & 0xffff; data2 = (AuxData & 0xffff0000) >> 16; - comedi_buf_put(async,data1); - comedi_buf_put(async,data2); + comedi_buf_put(async, data1); + comedi_buf_put(async, data2); //DPRINTK("read:%d, %d\n",data1,data2); - flags = readb(devpriv->mite->daq_io_addr+Group_1_Flags); + flags = readb(devpriv->mite->daq_io_addr + + Group_1_Flags); } //DPRINTK("buf_int_count: %d\n",async->buf_int_count); //DPRINTK("1) IntEn=%d,flags=%d,status=%d\n",IntEn,flags,status); @@ -567,54 +579,67 @@ static irqreturn_t nidio_interrupt(int irq, void *d PT_REGS_ARG) async->events |= COMEDI_CB_BLOCK; } - if(flags & CountExpired){ + if (flags & CountExpired) { DPRINTK("CountExpired\n"); - writeb(ClearExpired,devpriv->mite->daq_io_addr+Group_1_Second_Clear); + writeb(ClearExpired, + devpriv->mite->daq_io_addr + + Group_1_Second_Clear); async->events |= COMEDI_CB_EOA; - writeb(0x00,devpriv->mite->daq_io_addr+OpMode); + writeb(0x00, devpriv->mite->daq_io_addr + OpMode); break; - }else if(flags & Waited){ + } else if (flags & Waited) { DPRINTK("Waited\n"); - writeb(ClearWaited,devpriv->mite->daq_io_addr+Group_1_First_Clear); + writeb(ClearWaited, + devpriv->mite->daq_io_addr + + Group_1_First_Clear); async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; break; - }else if(flags & PrimaryTC){ + } else if (flags & PrimaryTC) { DPRINTK("PrimaryTC\n"); - writeb(ClearPrimaryTC,devpriv->mite->daq_io_addr+Group_1_First_Clear); + writeb(ClearPrimaryTC, + devpriv->mite->daq_io_addr + + Group_1_First_Clear); async->events |= COMEDI_CB_EOA; - }else if(flags & SecondaryTC){ + } else if (flags & SecondaryTC) { DPRINTK("SecondaryTC\n"); - writeb(ClearSecondaryTC,devpriv->mite->daq_io_addr+Group_1_First_Clear); + writeb(ClearSecondaryTC, + devpriv->mite->daq_io_addr + + Group_1_First_Clear); async->events |= COMEDI_CB_EOA; } #if 0 - else{ + else { printk("ni_pcidio: unknown interrupt\n"); - async->events |= COMEDI_CB_ERROR|COMEDI_CB_EOA; - writeb(0x00,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; + writeb(0x00, + devpriv->mite->daq_io_addr + + Master_DMA_And_Interrupt_Control); } #endif - flags = readb(devpriv->mite->daq_io_addr+Group_1_Flags); - status = readb(devpriv->mite->daq_io_addr+Interrupt_And_Window_Status); + flags = readb(devpriv->mite->daq_io_addr + Group_1_Flags); + status = readb(devpriv->mite->daq_io_addr + + Interrupt_And_Window_Status); //DPRINTK("loop end: IntEn=0x%02x,flags=0x%02x,status=0x%02x\n", - // IntEn,flags,status); + // IntEn,flags,status); //ni_pcidio_print_flags(flags); //ni_pcidio_print_status(status); } -out: + out: ni_pcidio_event(dev, s); #if 0 - if(!tag){ - writeb(0x03,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + if (!tag) { + writeb(0x03, + devpriv->mite->daq_io_addr + + Master_DMA_And_Interrupt_Control); } #endif return IRQ_HANDLED; } #ifdef DEBUG_FLAGS -static const char * const flags_strings[] = { +static const char *const flags_strings[] = { "TransferReady", "CountExpired", "2", "3", "4", "Waited", "PrimaryTC", "SecondaryTC", }; @@ -623,9 +648,9 @@ static void ni_pcidio_print_flags(unsigned int flags) int i; printk("group_1_flags:"); - for(i=7;i>=0;i--){ - if(flags&(1<= 0; i--) { + if (flags & (1 << i)) { + printk(" %s", flags_strings[i]); } } printk("\n"); @@ -639,9 +664,9 @@ static void ni_pcidio_print_status(unsigned int flags) int i; printk("group_status:"); - for(i=7;i>=0;i--){ - if(flags&(1<= 0; i--) { + if (flags & (1 << i)) { + printk(" %s", status_strings[i]); } } printk("\n"); @@ -649,188 +674,202 @@ static void ni_pcidio_print_status(unsigned int flags) #endif #ifdef unused -static void debug_int(comedi_device *dev) +static void debug_int(comedi_device * dev) { - int a,b; + int a, b; static int n_int = 0; struct timeval tv; do_gettimeofday(&tv); - a=readb(devpriv->mite->daq_io_addr+Group_Status); - b=readb(devpriv->mite->daq_io_addr+Group_1_Flags); + a = readb(devpriv->mite->daq_io_addr + Group_Status); + b = readb(devpriv->mite->daq_io_addr + Group_1_Flags); - if(n_int < 10){ - DPRINTK("status 0x%02x flags 0x%02x time %06d\n",a,b,(int)tv.tv_usec); + if (n_int < 10) { + DPRINTK("status 0x%02x flags 0x%02x time %06d\n", a, b, + (int)tv.tv_usec); } - while(b&1){ - writew(0xff,devpriv->mite->daq_io_addr+Group_1_FIFO); - b=readb(devpriv->mite->daq_io_addr+Group_1_Flags); + while (b & 1) { + writew(0xff, devpriv->mite->daq_io_addr + Group_1_FIFO); + b = readb(devpriv->mite->daq_io_addr + Group_1_Flags); } - b=readb(devpriv->mite->daq_io_addr+Group_1_Flags); + b = readb(devpriv->mite->daq_io_addr + Group_1_Flags); - if(n_int < 10){ - DPRINTK("new status 0x%02x\n",b); + if (n_int < 10) { + DPRINTK("new status 0x%02x\n", b); n_int++; } } #endif - -static int ni_pcidio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_pcidio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=1)return -EINVAL; - switch(data[0]){ + if (insn->n != 1) + return -EINVAL; + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<chanspec); + s->io_bits |= 1 << CR_CHAN(insn->chanspec); break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<chanspec)); + s->io_bits &= ~(1 << CR_CHAN(insn->chanspec)); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1<chanspec))) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s->io_bits & (1 << CR_CHAN(insn-> + chanspec))) ? COMEDI_OUTPUT : + COMEDI_INPUT; return insn->n; break; default: return -EINVAL; } - writel(s->io_bits,devpriv->mite->daq_io_addr+Port_Pin_Directions(0)); + writel(s->io_bits, devpriv->mite->daq_io_addr + Port_Pin_Directions(0)); return 1; } -static int ni_pcidio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int ni_pcidio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - writel(s->state,devpriv->mite->daq_io_addr+Port_IO(0)); + s->state |= (data[0] & data[1]); + writel(s->state, devpriv->mite->daq_io_addr + Port_IO(0)); } - data[1] = readl(devpriv->mite->daq_io_addr+Port_IO(0)); + data[1] = readl(devpriv->mite->daq_io_addr + Port_IO(0)); return 2; } -static int ni_pcidio_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int ni_pcidio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_INT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->start_src!=TRIG_NOW && - cmd->start_src!=TRIG_INT)err++; - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT)err++; + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_INT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ + if (cmd->start_arg != 0) { /* same for both TRIG_INT and TRIG_NOW */ - cmd->start_arg=0; + cmd->start_arg = 0; err++; } - #define MAX_SPEED (TIMER_BASE) /* in nanoseconds */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } /* no minumum speed */ - }else{ + } else { /* TRIG_EXT */ /* should be level/edge, hi/lo specification here */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->convert_arg!=0){ + if (cmd->convert_arg != 0) { cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { /* no limit */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src == TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; ni_pcidio_ns_to_timer(&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(err)return 4; + if (err) + return 4; return 0; } - static int ni_pcidio_ns_to_timer(int *nanosec, int round_mode) { int divider, base; base = TIMER_BASE; - switch(round_mode){ + switch (round_mode) { case TRIG_ROUND_NEAREST: default: - divider = (*nanosec + base/2)/base; + divider = (*nanosec + base / 2) / base; break; case TRIG_ROUND_DOWN: - divider = (*nanosec)/base; + divider = (*nanosec) / base; break; case TRIG_ROUND_UP: - divider = (*nanosec + base - 1)/base; + divider = (*nanosec + base - 1) / base; break; } @@ -838,70 +877,72 @@ static int ni_pcidio_ns_to_timer(int *nanosec, int round_mode) return divider; } -static int ni_pcidio_cmd(comedi_device *dev,comedi_subdevice *s) +static int ni_pcidio_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; - /* XXX configure ports for input*/ - writel(0x0000,devpriv->mite->daq_io_addr+Port_Pin_Directions(0)); + /* XXX configure ports for input */ + writel(0x0000, devpriv->mite->daq_io_addr + Port_Pin_Directions(0)); - if(1){ + if (1) { /* enable fifos A B C D */ - writeb(0x0f,devpriv->mite->daq_io_addr+Data_Path); + writeb(0x0f, devpriv->mite->daq_io_addr + Data_Path); - /* set transfer width a 32 bits*/ + /* set transfer width a 32 bits */ writeb(TransferWidth(0) | TransferLength(0), - devpriv->mite->daq_io_addr+Transfer_Size_Control); - }else{ - writeb(0x03,devpriv->mite->daq_io_addr+Data_Path); + devpriv->mite->daq_io_addr + Transfer_Size_Control); + } else { + writeb(0x03, devpriv->mite->daq_io_addr + Data_Path); writeb(TransferWidth(3) | TransferLength(0), - devpriv->mite->daq_io_addr+Transfer_Size_Control); + devpriv->mite->daq_io_addr + Transfer_Size_Control); } /* protocol configuration */ - if(cmd->scan_begin_src == TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { /* page 4-5, "input with internal REQs" */ - writeb( 0 ,devpriv->mite->daq_io_addr+OpMode); - writeb(0x00,devpriv->mite->daq_io_addr+ClockReg); - writeb( 1 ,devpriv->mite->daq_io_addr+Sequence); - writeb(0x04,devpriv->mite->daq_io_addr+ReqReg); - writeb( 4 ,devpriv->mite->daq_io_addr+BlockMode); - writeb( 3 ,devpriv->mite->daq_io_addr+LinePolarities); - writeb(0xc0,devpriv->mite->daq_io_addr+AckSer); + writeb(0, devpriv->mite->daq_io_addr + OpMode); + writeb(0x00, devpriv->mite->daq_io_addr + ClockReg); + writeb(1, devpriv->mite->daq_io_addr + Sequence); + writeb(0x04, devpriv->mite->daq_io_addr + ReqReg); + writeb(4, devpriv->mite->daq_io_addr + BlockMode); + writeb(3, devpriv->mite->daq_io_addr + LinePolarities); + writeb(0xc0, devpriv->mite->daq_io_addr + AckSer); writel(ni_pcidio_ns_to_timer(&cmd->scan_begin_arg, - TRIG_ROUND_NEAREST),devpriv->mite->daq_io_addr+StartDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+ReqDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+ReqNotDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+AckDelay); - writeb(0x0b,devpriv->mite->daq_io_addr+AckNotDelay); - writeb(0x01,devpriv->mite->daq_io_addr+Data1Delay); + TRIG_ROUND_NEAREST), + devpriv->mite->daq_io_addr + StartDelay); + writeb(1, devpriv->mite->daq_io_addr + ReqDelay); + writeb(1, devpriv->mite->daq_io_addr + ReqNotDelay); + writeb(1, devpriv->mite->daq_io_addr + AckDelay); + writeb(0x0b, devpriv->mite->daq_io_addr + AckNotDelay); + writeb(0x01, devpriv->mite->daq_io_addr + Data1Delay); /* manual, page 4-5: ClockSpeed comment is incorrectly listed - * on DAQOptions */ - writew(0 ,devpriv->mite->daq_io_addr+ClockSpeed); - writeb(0 ,devpriv->mite->daq_io_addr+DAQOptions); - }else{ + * on DAQOptions */ + writew(0, devpriv->mite->daq_io_addr + ClockSpeed); + writeb(0, devpriv->mite->daq_io_addr + DAQOptions); + } else { /* TRIG_EXT */ /* page 4-5, "input with external REQs" */ - writeb( 0 ,devpriv->mite->daq_io_addr+OpMode); - writeb(0x00,devpriv->mite->daq_io_addr+ClockReg); - writeb( 0 ,devpriv->mite->daq_io_addr+Sequence); - writeb(0x00,devpriv->mite->daq_io_addr+ReqReg); - writeb( 4 ,devpriv->mite->daq_io_addr+BlockMode); - writeb( 0 ,devpriv->mite->daq_io_addr+LinePolarities); - writeb(0x00,devpriv->mite->daq_io_addr+AckSer); - writel( 1 ,devpriv->mite->daq_io_addr+StartDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+ReqDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+ReqNotDelay); - writeb( 1 ,devpriv->mite->daq_io_addr+AckDelay); - writeb(0x0C,devpriv->mite->daq_io_addr+AckNotDelay); - writeb(0x10,devpriv->mite->daq_io_addr+Data1Delay); - writew( 0 ,devpriv->mite->daq_io_addr+ClockSpeed); - writeb(0x60,devpriv->mite->daq_io_addr+DAQOptions); + writeb(0, devpriv->mite->daq_io_addr + OpMode); + writeb(0x00, devpriv->mite->daq_io_addr + ClockReg); + writeb(0, devpriv->mite->daq_io_addr + Sequence); + writeb(0x00, devpriv->mite->daq_io_addr + ReqReg); + writeb(4, devpriv->mite->daq_io_addr + BlockMode); + writeb(0, devpriv->mite->daq_io_addr + LinePolarities); + writeb(0x00, devpriv->mite->daq_io_addr + AckSer); + writel(1, devpriv->mite->daq_io_addr + StartDelay); + writeb(1, devpriv->mite->daq_io_addr + ReqDelay); + writeb(1, devpriv->mite->daq_io_addr + ReqNotDelay); + writeb(1, devpriv->mite->daq_io_addr + AckDelay); + writeb(0x0C, devpriv->mite->daq_io_addr + AckNotDelay); + writeb(0x10, devpriv->mite->daq_io_addr + Data1Delay); + writew(0, devpriv->mite->daq_io_addr + ClockSpeed); + writeb(0x60, devpriv->mite->daq_io_addr + DAQOptions); } - if(cmd->stop_src == TRIG_COUNT){ - writel(cmd->stop_arg,devpriv->mite->daq_io_addr+Transfer_Count); - }else{ + if (cmd->stop_src == TRIG_COUNT) { + writel(cmd->stop_arg, + devpriv->mite->daq_io_addr + Transfer_Count); + } else { /* XXX */ } @@ -910,8 +951,9 @@ static int ni_pcidio_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->mite->daq_io_addr + Group_1_First_Clear); { - int retval = setup_mite_dma(dev,s); - if(retval) return retval; + int retval = setup_mite_dma(dev, s); + if (retval) + return retval; } #else writeb(0x00, devpriv->mite->daq_io_addr + DMA_Line_Control_Group1); @@ -919,22 +961,24 @@ static int ni_pcidio_cmd(comedi_device *dev,comedi_subdevice *s) writeb(0x00, devpriv->mite->daq_io_addr + DMA_Line_Control_Group2); /* clear and enable interrupts */ - writeb(0xff,devpriv->mite->daq_io_addr+Group_1_First_Clear); + writeb(0xff, devpriv->mite->daq_io_addr + Group_1_First_Clear); //writeb(ClearExpired,devpriv->mite->daq_io_addr+Group_1_Second_Clear); - writeb(IntEn,devpriv->mite->daq_io_addr+Interrupt_Control); - writeb(0x03,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + writeb(IntEn, devpriv->mite->daq_io_addr + Interrupt_Control); + writeb(0x03, + devpriv->mite->daq_io_addr + Master_DMA_And_Interrupt_Control); - if(cmd->stop_src == TRIG_NONE) { + if (cmd->stop_src == TRIG_NONE) { devpriv->OpModeBits = DataLatching(0) | RunMode(7); - } else { // TRIG_TIMER + } else { // TRIG_TIMER devpriv->OpModeBits = Numbered | RunMode(7); } - if(cmd->start_src == TRIG_NOW){ + if (cmd->start_src == TRIG_NOW) { /* start */ - writeb(devpriv->OpModeBits, devpriv->mite->daq_io_addr+OpMode); + writeb(devpriv->OpModeBits, + devpriv->mite->daq_io_addr + OpMode); s->async->inttrig = NULL; - }else{ + } else { /* TRIG_INT */ s->async->inttrig = ni_pcidio_inttrig; } @@ -943,12 +987,13 @@ static int ni_pcidio_cmd(comedi_device *dev,comedi_subdevice *s) return 0; } -static int setup_mite_dma(comedi_device *dev,comedi_subdevice *s) +static int setup_mite_dma(comedi_device * dev, comedi_subdevice * s) { int retval; retval = ni_pcidio_request_di_mite_channel(dev); - if(retval) return retval; + if (retval) + return retval; devpriv->di_mite_chan->dir = COMEDI_INPUT; @@ -958,107 +1003,114 @@ static int setup_mite_dma(comedi_device *dev,comedi_subdevice *s) return 0; } - -static int ni_pcidio_inttrig(comedi_device *dev, comedi_subdevice *s, +static int ni_pcidio_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { - if(trignum!=0)return -EINVAL; + if (trignum != 0) + return -EINVAL; - writeb(devpriv->OpModeBits, devpriv->mite->daq_io_addr+OpMode); + writeb(devpriv->OpModeBits, devpriv->mite->daq_io_addr + OpMode); s->async->inttrig = NULL; return 1; } - -static int ni_pcidio_cancel(comedi_device *dev, comedi_subdevice *s) +static int ni_pcidio_cancel(comedi_device * dev, comedi_subdevice * s) { - writeb(0x00, devpriv->mite->daq_io_addr + Master_DMA_And_Interrupt_Control); + writeb(0x00, + devpriv->mite->daq_io_addr + Master_DMA_And_Interrupt_Control); ni_pcidio_release_di_mite_channel(dev); return 0; } - -static int ni_pcidio_change(comedi_device *dev, comedi_subdevice *s, +static int ni_pcidio_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->di_mite_ring, s->async); - if(ret<0)return ret; + if (ret < 0) + return ret; memset(s->async->prealloc_buf, 0xaa, s->async->prealloc_bufsz); return 0; } -static int pci_6534_load_fpga(comedi_device *dev, int fpga_index, u8 *data, int data_len) +static int pci_6534_load_fpga(comedi_device * dev, int fpga_index, u8 * data, + int data_len) { static const int timeout = 1000; int i, j; - writew(0x80 | fpga_index, devpriv->mite->daq_io_addr + Firmware_Control_Register); - writew(0xc0 | fpga_index, devpriv->mite->daq_io_addr + Firmware_Control_Register); - for(i = 0; (readw(devpriv->mite->daq_io_addr + Firmware_Status_Register) & 0x2) == 0 && i < timeout; ++i) - { + writew(0x80 | fpga_index, + devpriv->mite->daq_io_addr + Firmware_Control_Register); + writew(0xc0 | fpga_index, + devpriv->mite->daq_io_addr + Firmware_Control_Register); + for (i = 0; + (readw(devpriv->mite->daq_io_addr + + Firmware_Status_Register) & 0x2) == 0 + && i < timeout; ++i) { udelay(1); } - if(i == timeout) - { + if (i == timeout) { printk("ni_pcidio: failed to load fpga %i, waiting for status 0x2\n", fpga_index); return -EIO; } - writew(0x80 | fpga_index, devpriv->mite->daq_io_addr + Firmware_Control_Register); - for(i = 0; readw(devpriv->mite->daq_io_addr + Firmware_Status_Register) != 0x3 && i < timeout; ++i) - { + writew(0x80 | fpga_index, + devpriv->mite->daq_io_addr + Firmware_Control_Register); + for (i = 0; + readw(devpriv->mite->daq_io_addr + Firmware_Status_Register) != + 0x3 && i < timeout; ++i) { udelay(1); } - if(i == timeout) - { + if (i == timeout) { printk("ni_pcidio: failed to load fpga %i, waiting for status 0x3\n", fpga_index); return -EIO; } - for(j = 0; j + 1 < data_len;) - { + for (j = 0; j + 1 < data_len;) { unsigned int value = data[j++]; value |= data[j++] << 8; - writew(value, devpriv->mite->daq_io_addr + Firmware_Data_Register); - for(i = 0; (readw(devpriv->mite->daq_io_addr + Firmware_Status_Register) & 0x2) == 0 && i < timeout; ++i) - { + writew(value, + devpriv->mite->daq_io_addr + Firmware_Data_Register); + for (i = 0; + (readw(devpriv->mite->daq_io_addr + + Firmware_Status_Register) & 0x2) == 0 + && i < timeout; ++i) { udelay(1); } - if(i == timeout) - { - printk("ni_pcidio: failed to load word into fpga %i\n", fpga_index); + if (i == timeout) { + printk("ni_pcidio: failed to load word into fpga %i\n", + fpga_index); return -EIO; } - if(need_resched()) + if (need_resched()) schedule(); } writew(0x0, devpriv->mite->daq_io_addr + Firmware_Control_Register); return 0; } -static int pci_6534_reset_fpga(comedi_device *dev, int fpga_index) +static int pci_6534_reset_fpga(comedi_device * dev, int fpga_index) { return pci_6534_load_fpga(dev, fpga_index, NULL, 0); } -static int pci_6534_reset_fpgas(comedi_device *dev) +static int pci_6534_reset_fpgas(comedi_device * dev) { int ret; int i; writew(0x0, devpriv->mite->daq_io_addr + Firmware_Control_Register); - for(i = 0; i < 3; ++i) - { + for (i = 0; i < 3; ++i) { ret = pci_6534_reset_fpga(dev, i); - if(ret < 0) break; + if (ret < 0) + break; } writew(0x0, devpriv->mite->daq_io_addr + Firmware_Mask_Register); return ret; } -static void pci_6534_init_main_fpga(comedi_device *dev) +static void pci_6534_init_main_fpga(comedi_device * dev) { writel(0, devpriv->mite->daq_io_addr + FPGA_Control1_Register); writel(0, devpriv->mite->daq_io_addr + FPGA_Control2_Register); @@ -1068,32 +1120,37 @@ static void pci_6534_init_main_fpga(comedi_device *dev) writel(0, devpriv->mite->daq_io_addr + FPGA_SCBMS_Counter_Register); } -static int pci_6534_upload_firmware(comedi_device *dev, int options[]) +static int pci_6534_upload_firmware(comedi_device * dev, int options[]) { int ret; void *main_fpga_data, *scarab_a_data, *scarab_b_data; int main_fpga_data_len, scarab_a_data_len, scarab_b_data_len; - if(options[COMEDI_DEVCONF_AUX_DATA_LENGTH] == 0) return 0; + if (options[COMEDI_DEVCONF_AUX_DATA_LENGTH] == 0) + return 0; ret = pci_6534_reset_fpgas(dev); - if(ret < 0) return ret; + if (ret < 0) + return ret; main_fpga_data = comedi_aux_data(options, 0); main_fpga_data_len = options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; ret = pci_6534_load_fpga(dev, 2, main_fpga_data, main_fpga_data_len); - if(ret < 0) return ret; + if (ret < 0) + return ret; pci_6534_init_main_fpga(dev); scarab_a_data = comedi_aux_data(options, 1); scarab_a_data_len = options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; ret = pci_6534_load_fpga(dev, 0, scarab_a_data, scarab_a_data_len); - if(ret < 0) return ret; + if (ret < 0) + return ret; scarab_b_data = comedi_aux_data(options, 2); scarab_b_data_len = options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; ret = pci_6534_load_fpga(dev, 1, scarab_b_data, scarab_b_data_len); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int nidio_attach(comedi_device *dev,comedi_devconfig *it) +static int nidio_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; int i; @@ -1101,77 +1158,85 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) int n_subdevices; unsigned int irq; - printk("comedi%d: nidio:",dev->minor); + printk("comedi%d: nidio:", dev->minor); - if((ret=alloc_private(dev,sizeof(nidio96_private)))<0) + if ((ret = alloc_private(dev, sizeof(nidio96_private))) < 0) return ret; spin_lock_init(&devpriv->mite_channel_lock); - ret=nidio_find_device(dev,it->options[0],it->options[1]); - if(ret<0)return ret; + ret = nidio_find_device(dev, it->options[0], it->options[1]); + if (ret < 0) + return ret; ret = mite_setup(devpriv->mite); - if(ret < 0) - { + if (ret < 0) { printk("error setting up mite\n"); return ret; } comedi_set_hw_dev(dev, &devpriv->mite->pcidev->dev); devpriv->di_mite_ring = mite_alloc_ring(devpriv->mite); - if(devpriv->di_mite_ring == NULL) return -ENOMEM; + if (devpriv->di_mite_ring == NULL) + return -ENOMEM; - dev->board_name=this_board->name; - irq=mite_irq(devpriv->mite); - printk(" %s",dev->board_name); - if(this_board->uses_firmware) - { + dev->board_name = this_board->name; + irq = mite_irq(devpriv->mite); + printk(" %s", dev->board_name); + if (this_board->uses_firmware) { ret = pci_6534_upload_firmware(dev, it->options); - if(ret < 0) + if (ret < 0) return ret; } - if(!this_board->is_diodaq){ - n_subdevices=this_board->n_8255; - }else{ - n_subdevices=1; + if (!this_board->is_diodaq) { + n_subdevices = this_board->n_8255; + } else { + n_subdevices = 1; } - if((ret=alloc_subdevices(dev, n_subdevices))<0) + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) return ret; - if(!this_board->is_diodaq){ - for(i=0;in_8255;i++){ - subdev_8255_init(dev,dev->subdevices+i, - nidio96_8255_cb,(unsigned long)(devpriv->mite->daq_io_addr+NIDIO_8255_BASE(i))); + if (!this_board->is_diodaq) { + for (i = 0; i < this_board->n_8255; i++) { + subdev_8255_init(dev, dev->subdevices + i, + nidio96_8255_cb, + (unsigned long)(devpriv->mite->daq_io_addr + + NIDIO_8255_BASE(i))); } - }else{ + } else { - printk(" rev=%d",readb(devpriv->mite->daq_io_addr+Chip_Version)); + printk(" rev=%d", + readb(devpriv->mite->daq_io_addr + Chip_Version)); - s=dev->subdevices+0; + s = dev->subdevices + 0; dev->read_subdev = s; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_PACKED | SDF_CMD_READ; - s->n_chan=32; - s->range_table=&range_digital; - s->maxdata=1; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = + SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_PACKED | + SDF_CMD_READ; + s->n_chan = 32; + s->range_table = &range_digital; + s->maxdata = 1; s->insn_config = &ni_pcidio_insn_config; s->insn_bits = &ni_pcidio_insn_bits; s->do_cmd = &ni_pcidio_cmd; s->do_cmdtest = &ni_pcidio_cmdtest; s->cancel = &ni_pcidio_cancel; - s->len_chanlist=32; /* XXX */ + s->len_chanlist = 32; /* XXX */ s->buf_change = &ni_pcidio_change; s->async_dma_dir = DMA_BIDIRECTIONAL; - writel(0,devpriv->mite->daq_io_addr+Port_IO(0)); - writel(0,devpriv->mite->daq_io_addr+Port_Pin_Directions(0)); - writel(0,devpriv->mite->daq_io_addr+Port_Pin_Mask(0)); + writel(0, devpriv->mite->daq_io_addr + Port_IO(0)); + writel(0, devpriv->mite->daq_io_addr + Port_Pin_Directions(0)); + writel(0, devpriv->mite->daq_io_addr + Port_Pin_Mask(0)); /* disable interrupts on board */ - writeb(0x00,devpriv->mite->daq_io_addr+Master_DMA_And_Interrupt_Control); + writeb(0x00, + devpriv->mite->daq_io_addr + + Master_DMA_And_Interrupt_Control); - ret=comedi_request_irq(irq,nidio_interrupt,IRQF_SHARED,"ni_pcidio",dev); - if(ret<0){ + ret = comedi_request_irq(irq, nidio_interrupt, IRQF_SHARED, + "ni_pcidio", dev); + if (ret < 0) { printk(" irq not available"); } dev->irq = irq; @@ -1182,49 +1247,47 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) return 0; } -static int nidio_detach(comedi_device *dev) +static int nidio_detach(comedi_device * dev) { int i; - if(this_board && !this_board->is_diodaq){ - for(i=0;in_8255;i++){ - subdev_8255_cleanup(dev,dev->subdevices+i); + if (this_board && !this_board->is_diodaq) { + for (i = 0; i < this_board->n_8255; i++) { + subdev_8255_cleanup(dev, dev->subdevices + i); } } - if(dev->irq) - comedi_free_irq(dev->irq,dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); - if(devpriv) - { - if(devpriv->di_mite_ring) - { + if (devpriv) { + if (devpriv->di_mite_ring) { mite_free_ring(devpriv->di_mite_ring); devpriv->di_mite_ring = NULL; } - if(devpriv->mite) + if (devpriv->mite) mite_unsetup(devpriv->mite); } return 0; } - -static int nidio_find_device(comedi_device *dev,int bus,int slot) +static int nidio_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for(mite=mite_devices;mite;mite=mite->next){ - if(mite->used)continue; - if(bus || slot){ - if(bus!=mite->pcidev->bus->number || - slot!=PCI_SLOT(mite->pcidev->devfn)) + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number || + slot != PCI_SLOT(mite->pcidev->devfn)) continue; } - for(i=0;iboard_ptr=nidio_boards+i; - devpriv->mite=mite; + for (i = 0; i < n_nidio_boards; i++) { + if (mite_device_id(mite) == nidio_boards[i].dev_id) { + dev->board_ptr = nidio_boards + i; + devpriv->mite = mite; return 0; } @@ -1234,4 +1297,3 @@ static int nidio_find_device(comedi_device *dev,int bus,int slot) mite_list_devices(); return -EIO; } - diff --git a/comedi/drivers/ni_pcimio.c b/comedi/drivers/ni_pcimio.c index 3fef450b..51693c65 100644 --- a/comedi/drivers/ni_pcimio.c +++ b/comedi/drivers/ni_pcimio.c @@ -80,7 +80,6 @@ Bugs: The PCI-MIO E series driver was originally written by Tomasz Motylewski <...>, and ported to comedi by ds. - References: 341079b.pdf PCI E Series Register-Level Programmer Manual @@ -128,59 +127,60 @@ Bugs: /* The following two tables must be in the same order */ static struct pci_device_id ni_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_NATINST, 0x0162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1170, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1190, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x11b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x11c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x11d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1270, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x14e0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x14f0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1580, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x15b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x1870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x18b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x18c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2890, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x28c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2a60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2a70, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2a80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2ab0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2b80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2b90, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2c80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x2ca0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70aa, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70ab, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70ac, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70af, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70b4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70b6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70b7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70bc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70bf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x70f2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x710d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x716c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x717f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x71bc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_NATINST, 0x717d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_NATINST, 0x0162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1170, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1190, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x11b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x11c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x11d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1270, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x14e0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x14f0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1580, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x15b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x1870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x18b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x18c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2890, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x28c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2a60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2a70, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2a80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2ab0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2b80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2b90, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2c80, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x2ca0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70aa, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70ab, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70ac, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70af, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70b4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70b6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70b7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70bc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70bf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x70f2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x710d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x716c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x717f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x71bc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_NATINST, 0x717d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, ni_pci_table); /* These are not all the possible ao ranges for 628x boards. @@ -191,957 +191,963 @@ MODULE_DEVICE_TABLE(pci, ni_pci_table); can not act as it's own OFFSET or REFERENCE. */ static const comedi_lrange range_ni_M_628x_ao = { 8, { - RANGE(-10, 10), - RANGE(-5, 5), - RANGE(-2, 2), - RANGE(-1, 1), - RANGE(-5, 15), - RANGE(0, 10), - RANGE(3, 7), - RANGE(4, 6), - RANGE_ext(-1, 1) -}}; + RANGE(-10, 10), + RANGE(-5, 5), + RANGE(-2, 2), + RANGE(-1, 1), + RANGE(-5, 15), + RANGE(0, 10), + RANGE(3, 7), + RANGE(4, 6), + RANGE_ext(-1, 1) + } +}; static const comedi_lrange range_ni_M_625x_ao = { 3, { - RANGE(-10, 10), - RANGE(-5, 5), - RANGE_ext(-1, 1) -}}; + RANGE(-10, 10), + RANGE(-5, 5), + RANGE_ext(-1, 1) + } +}; static const comedi_lrange range_ni_M_622x_ao = { 1, { - RANGE(-10, 10), -}}; - -static const ni_board ni_boards[]={ - { device_id: 0x0162, // NI also says 0x1620. typo? - name: "pci-mio-16xe-50", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 2048, - alwaysdither: 1, - gainlkup: ai_gain_8, - ai_speed: 50000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 50000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043}, - has_8255: 0, - }, - { device_id: 0x1170, - name: "pci-mio-16xe-10", // aka pci-6030E - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - { device_id: 0x28c0, - name: "pci-6014", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x11d0, - name: "pxi-6030e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - - { device_id: 0x1180, - name: "pci-mio-16e-1", /* aka pci-6070e */ - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 800, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {mb88341}, - has_8255: 0, - }, - { device_id: 0x1190, - name: "pci-mio-16e-4", /* aka pci-6040e */ - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_16, - /* Note: there have been reported problems with full speed - * on this board */ - ai_speed: 2000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 512, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, // doc says mb88341 - has_8255: 0, - }, - { device_id: 0x11c0, - name: "pxi-6040e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_16, - ai_speed: 2000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 512, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {mb88341}, - has_8255: 0, - }, - - { device_id: 0x1330, - name: "pci-6031e", - n_adchan: 64, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - { device_id: 0x1270, - name: "pci-6032e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - { device_id: 0x1340, - name: "pci-6033e", - n_adchan: 64, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - has_8255: 0, - }, - { device_id: 0x1350, - name: "pci-6071e", - n_adchan: 64, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_16, - ai_speed: 800, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x2a60, - name: "pci-6023e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 0, - aobits: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, /* manual is wrong */ - has_8255: 0, - }, - { device_id: 0x2a70, - name: "pci-6024e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, /* manual is wrong */ - has_8255: 0, - }, - { device_id: 0x2a80, - name: "pci-6025e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, /* manual is wrong */ - has_8255: 1, - }, - { device_id: 0x2ab0, - name: "pxi-6025e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 0, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, /* manual is wrong */ - has_8255: 1, - }, - - { device_id: 0x2ca0, - name: "pci-6034e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x2c80, - name: "pci-6035e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x18b0, - name: "pci-6052e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_16, - ai_speed: 3000, - n_aochan: 2, - aobits: 16, - ao_unipolar: 1, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_speed: 3000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug,ad8804_debug,ad8522}, /* manual is wrong */ - }, - { device_id: 0x14e0, - name: "pci-6110", - n_adchan: 4, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_611x, - ai_speed: 200, - n_aochan: 2, - aobits: 16, - reg_type: ni_reg_611x, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_fifo_depth: 2048, - ao_speed: 250, - .num_p0_dio_channels = 8, - caldac: {ad8804,ad8804}, - }, - { device_id: 0x14f0, - name: "pci-6111", - n_adchan: 2, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_611x, - ai_speed: 200, - n_aochan: 2, - aobits: 16, - reg_type: ni_reg_611x, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_fifo_depth: 2048, - ao_speed: 250, - .num_p0_dio_channels = 8, - caldac: {ad8804,ad8804}, - }, + RANGE(-10, 10), + } +}; + +static const ni_board ni_boards[] = { + {device_id:0x0162, // NI also says 0x1620. typo? + name: "pci-mio-16xe-50", + n_adchan:16, + adbits: 16, + ai_fifo_depth:2048, + alwaysdither:1, + gainlkup:ai_gain_8, + ai_speed:50000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:50000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043}, + has_8255:0, + }, + {device_id:0x1170, + name: "pci-mio-16xe-10", // aka pci-6030E + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + {device_id:0x28c0, + name: "pci-6014", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x11d0, + name: "pxi-6030e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + + {device_id:0x1180, + name: "pci-mio-16e-1", /* aka pci-6070e */ + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:800, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {mb88341}, + has_8255:0, + }, + {device_id:0x1190, + name: "pci-mio-16e-4", /* aka pci-6040e */ + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_16, + /* Note: there have been reported problems with full speed + * on this board */ + ai_speed:2000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:512, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, // doc says mb88341 + has_8255:0, + }, + {device_id:0x11c0, + name: "pxi-6040e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_16, + ai_speed:2000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:512, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {mb88341}, + has_8255:0, + }, + + {device_id:0x1330, + name: "pci-6031e", + n_adchan:64, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + {device_id:0x1270, + name: "pci-6032e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + {device_id:0x1340, + name: "pci-6033e", + n_adchan:64, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + has_8255:0, + }, + {device_id:0x1350, + name: "pci-6071e", + n_adchan:64, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_16, + ai_speed:800, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x2a60, + name: "pci-6023e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:0, + aobits: 0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, /* manual is wrong */ + has_8255:0, + }, + {device_id:0x2a70, + name: "pci-6024e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, /* manual is wrong */ + has_8255:0, + }, + {device_id:0x2a80, + name: "pci-6025e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, /* manual is wrong */ + has_8255:1, + }, + {device_id:0x2ab0, + name: "pxi-6025e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:0, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, /* manual is wrong */ + has_8255:1, + }, + + {device_id:0x2ca0, + name: "pci-6034e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + ao_unipolar:0, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x2c80, + name: "pci-6035e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 12, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x18b0, + name: "pci-6052e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_16, + ai_speed:3000, + n_aochan:2, + aobits: 16, + ao_unipolar:1, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_speed:3000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug, ad8804_debug, ad8522}, /* manual is wrong */ + }, + {device_id:0x14e0, + name: "pci-6110", + n_adchan:4, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_611x, + ai_speed:200, + n_aochan:2, + aobits: 16, + reg_type:ni_reg_611x, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_fifo_depth:2048, + ao_speed:250, + .num_p0_dio_channels = 8, + caldac: {ad8804, ad8804}, + }, + {device_id:0x14f0, + name: "pci-6111", + n_adchan:2, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_611x, + ai_speed:200, + n_aochan:2, + aobits: 16, + reg_type:ni_reg_611x, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_fifo_depth:2048, + ao_speed:250, + .num_p0_dio_channels = 8, + caldac: {ad8804, ad8804}, + }, #if 0 /* The 6115 boards probably need their own driver */ - { device_id: 0x2ed0, - name: "pci-6115", - n_adchan: 4, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_611x, - ai_speed: 100, - n_aochan: 2, - aobits: 16, - ao_671x: 1, - ao_unipolar: 0, - ao_fifo_depth: 2048, - ao_speed: 250, - .num_p0_dio_channels = 8, - reg_611x: 1, - caldac: {ad8804_debug,ad8804_debug,ad8804_debug},/* XXX */ - }, + {device_id:0x2ed0, + name: "pci-6115", + n_adchan:4, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_611x, + ai_speed:100, + n_aochan:2, + aobits: 16, + ao_671x: 1, + ao_unipolar:0, + ao_fifo_depth:2048, + ao_speed:250, + .num_p0_dio_channels = 8, + reg_611x:1, + caldac: {ad8804_debug, ad8804_debug, ad8804_debug}, /* XXX */ + }, #endif #if 0 - { device_id: 0x0000, - name: "pxi-6115", - n_adchan: 4, - adbits: 12, - ai_fifo_depth: 8192, - alwaysdither: 0, - gainlkup: ai_gain_611x, - ai_speed: 100, - n_aochan: 2, - aobits: 16, - ao_671x: 1, - ao_unipolar: 0, - ao_fifo_depth: 2048, - ao_speed: 250, - reg_611x: 1, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug,ad8804_debug,ad8804_debug},/* XXX */ - }, + {device_id:0x0000, + name: "pxi-6115", + n_adchan:4, + adbits: 12, + ai_fifo_depth:8192, + alwaysdither:0, + gainlkup:ai_gain_611x, + ai_speed:100, + n_aochan:2, + aobits: 16, + ao_671x: 1, + ao_unipolar:0, + ao_fifo_depth:2048, + ao_speed:250, + reg_611x:1, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug, ad8804_debug, ad8804_debug}, /* XXX */ + }, #endif - { device_id: 0x1880, - name: "pci-6711", - n_adchan: 0, /* no analog input */ - n_aochan: 4, - aobits: 12, - ao_unipolar: 0, - ao_fifo_depth: 16384, /* data sheet says 8192, but fifo really holds 16384 samples */ - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6711, - caldac: {ad8804_debug}, - }, - { device_id: 0x2b90, - name: "pxi-6711", - n_adchan: 0, /* no analog input */ - n_aochan: 4, - aobits: 12, - ao_unipolar: 0, - ao_fifo_depth: 16384, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6711, - caldac: {ad8804_debug}, - }, - { device_id: 0x1870, - name: "pci-6713", - n_adchan: 0, /* no analog input */ - n_aochan: 8, - aobits: 12, - ao_unipolar: 0, - ao_fifo_depth: 16384, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6713, - caldac: {ad8804_debug,ad8804_debug}, - }, - { device_id: 0x2b80, - name: "pxi-6713", - n_adchan: 0, /* no analog input */ - n_aochan: 8, - aobits: 12, - ao_unipolar: 0, - ao_fifo_depth: 16384, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6713, - caldac: {ad8804_debug,ad8804_debug}, - }, - { device_id: 0x2430, - name: "pci-6731", - n_adchan: 0, /* no analog input */ - n_aochan: 4, - aobits: 16, - ao_unipolar: 0, - ao_fifo_depth: 8192, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6711, - caldac: {ad8804_debug}, - }, -#if 0 /* need device ids */ - { device_id: 0x0, - name: "pxi-6731", - n_adchan: 0, /* no analog input */ - n_aochan: 4, - aobits: 16, - ao_unipolar: 0, - ao_fifo_depth: 8192, - .ao_range_table = &range_bipolar10, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6711, - caldac: {ad8804_debug}, - }, + {device_id:0x1880, + name: "pci-6711", + n_adchan:0, /* no analog input */ + n_aochan:4, + aobits: 12, + ao_unipolar:0, + ao_fifo_depth:16384, + /* data sheet says 8192, but fifo really holds 16384 samples */ + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6711, + caldac: {ad8804_debug}, + }, + {device_id:0x2b90, + name: "pxi-6711", + n_adchan:0, /* no analog input */ + n_aochan:4, + aobits: 12, + ao_unipolar:0, + ao_fifo_depth:16384, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6711, + caldac: {ad8804_debug}, + }, + {device_id:0x1870, + name: "pci-6713", + n_adchan:0, /* no analog input */ + n_aochan:8, + aobits: 12, + ao_unipolar:0, + ao_fifo_depth:16384, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6713, + caldac: {ad8804_debug, ad8804_debug}, + }, + {device_id:0x2b80, + name: "pxi-6713", + n_adchan:0, /* no analog input */ + n_aochan:8, + aobits: 12, + ao_unipolar:0, + ao_fifo_depth:16384, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6713, + caldac: {ad8804_debug, ad8804_debug}, + }, + {device_id:0x2430, + name: "pci-6731", + n_adchan:0, /* no analog input */ + n_aochan:4, + aobits: 16, + ao_unipolar:0, + ao_fifo_depth:8192, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6711, + caldac: {ad8804_debug}, + }, +#if 0 /* need device ids */ + {device_id:0x0, + name: "pxi-6731", + n_adchan:0, /* no analog input */ + n_aochan:4, + aobits: 16, + ao_unipolar:0, + ao_fifo_depth:8192, + .ao_range_table = &range_bipolar10, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6711, + caldac: {ad8804_debug}, + }, #endif - { device_id: 0x2410, - name: "pci-6733", - n_adchan: 0, /* no analog input */ - n_aochan: 8, - aobits: 16, - ao_unipolar: 0, - ao_fifo_depth: 16384, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6713, - caldac: {ad8804_debug,ad8804_debug}, - }, - { device_id: 0x2420, - name: "pxi-6733", - n_adchan: 0, /* no analog input */ - n_aochan: 8, - aobits: 16, - ao_unipolar: 0, - ao_fifo_depth: 16384, - .ao_range_table = &range_bipolar10, - ao_speed: 1000, - .num_p0_dio_channels = 8, - reg_type: ni_reg_6713, - caldac: {ad8804_debug,ad8804_debug}, - }, - { device_id: 0x15b0, - name: "pxi-6071e", - n_adchan: 64, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_16, - ai_speed: 800, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x11b0, - name: "pxi-6070e", - n_adchan: 16, - adbits: 12, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_16, - ai_speed: 800, - n_aochan: 2, - aobits: 12, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 1000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x18c0, - name: "pxi-6052e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_16, - ai_speed: 3000, - n_aochan: 2, - aobits: 16, - ao_unipolar: 1, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_speed: 3000, - .num_p0_dio_channels = 8, - caldac: {mb88341,mb88341,ad8522}, - }, - { device_id: 0x1580, - name: "pxi-6031e", - n_adchan: 64, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_14, - ai_speed: 10000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 2048, - .ao_range_table = &range_ni_E_ao_ext, - ao_unipolar: 1, - ao_speed: 10000, - .num_p0_dio_channels = 8, - caldac: {dac8800,dac8043,ad8522}, - }, - { device_id: 0x2890, - name: "pci-6036e", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, - alwaysdither: 1, - gainlkup: ai_gain_4, - ai_speed: 5000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 0, - .ao_range_table = &range_bipolar10, - ao_unipolar: 0, - ao_speed: 100000, - .num_p0_dio_channels = 8, - caldac: {ad8804_debug}, - has_8255: 0, - }, - { device_id: 0x70b0, - name: "pci-6220", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 512, //FIXME: guess - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - .num_p0_dio_channels = 8, - reg_type: ni_reg_622x, - ao_unipolar: 0, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70af, - name: "pci-6221", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 4095, - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_622x_ao, - reg_type: ni_reg_622x, - ao_unipolar: 0, - ao_speed: 1200, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x71bc, - name: "pci-6221_37pin", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 4095, - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_622x_ao, - reg_type: ni_reg_622x, - ao_unipolar: 0, - ao_speed: 1200, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70f2, - name: "pci-6224", - n_adchan: 32, - adbits: 16, - ai_fifo_depth: 4095, - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - reg_type: ni_reg_622x, - ao_unipolar: 0, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x716c, - name: "pci-6225", - n_adchan: 80, - adbits: 16, - ai_fifo_depth: 4095, - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_622x_ao, - reg_type: ni_reg_622x, - ao_unipolar: 0, - ao_speed: 1200, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70aa, - name: "pci-6229", - n_adchan: 32, - adbits: 16, - ai_fifo_depth: 4095, - gainlkup: ai_gain_622x, - ai_speed: 4000, - n_aochan: 4, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_622x_ao, - reg_type: ni_reg_622x, - ao_unipolar: 0, - ao_speed: 1200, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70b4, - name: "pci-6250", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - reg_type: ni_reg_625x, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70b8, - name: "pci-6251", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_625x_ao, - reg_type: ni_reg_625x, - ao_unipolar: 0, - ao_speed: 357, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x717d, - name: "pcie-6251", - n_adchan: 16, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_625x_ao, - reg_type: ni_reg_625x, - ao_unipolar: 0, - ao_speed: 357, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70b7, - name: "pci-6254", - n_adchan: 32, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - reg_type: ni_reg_625x, - ao_unipolar: 0, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70ab, - name: "pci-6259", - n_adchan: 32, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 4, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_625x_ao, - reg_type: ni_reg_625x, - ao_unipolar: 0, - ao_speed: 357, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x717f, - name: "pcie-6259", - n_adchan: 32, - adbits: 16, - ai_fifo_depth: 4095, - .gainlkup = ai_gain_628x, - ai_speed: 800, - n_aochan: 4, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_625x_ao, - reg_type: ni_reg_625x, - ao_unipolar: 0, - ao_speed: 357, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70b6, - name: "pci-6280", - n_adchan: 16, - adbits: 18, - ai_fifo_depth: 2047, - .gainlkup = ai_gain_628x, - ai_speed: 1600, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 8191, - reg_type: ni_reg_628x, - ao_unipolar: 0, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70bd, - name: "pci-6281", - n_adchan: 16, - adbits: 18, - ai_fifo_depth: 2047, - .gainlkup = ai_gain_628x, - ai_speed: 1600, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_628x_ao, - reg_type: ni_reg_628x, - ao_unipolar: 1, - ao_speed: 357, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70bf, - name: "pxi-6281", - n_adchan: 16, - adbits: 18, - ai_fifo_depth: 2047, - .gainlkup = ai_gain_628x, - ai_speed: 1600, - n_aochan: 2, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_628x_ao, - reg_type: ni_reg_628x, - ao_unipolar: 1, - ao_speed: 357, - .num_p0_dio_channels = 8, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70bc, - name: "pci-6284", - n_adchan: 32, - adbits: 18, - ai_fifo_depth: 2047, - .gainlkup = ai_gain_628x, - ai_speed: 1600, - n_aochan: 0, - aobits: 0, - ao_fifo_depth: 0, - reg_type: ni_reg_628x, - ao_unipolar: 0, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70ac, - name: "pci-6289", - n_adchan: 32, - adbits: 18, - ai_fifo_depth: 2047, - .gainlkup = ai_gain_628x, - ai_speed: 1600, - n_aochan: 4, - aobits: 16, - ao_fifo_depth: 8191, - .ao_range_table = &range_ni_M_628x_ao, - reg_type: ni_reg_628x, - ao_unipolar: 1, - ao_speed: 357, - .num_p0_dio_channels = 32, - .caldac = {caldac_none}, - has_8255: 0, - }, - { device_id: 0x70C0, - name: "pci-6143", - n_adchan: 8, - adbits: 16, - ai_fifo_depth: 1024, - alwaysdither: 0, - gainlkup: ai_gain_6143, - ai_speed: 4000, - n_aochan: 0, - aobits: 0, - reg_type: ni_reg_6143, - ao_unipolar: 0, - ao_fifo_depth: 0, - .num_p0_dio_channels = 8, - .caldac = {ad8804_debug,ad8804_debug}, - }, - { device_id: 0x710D, - name: "pxi-6143", - n_adchan: 8, - adbits: 16, - ai_fifo_depth: 1024, - alwaysdither: 0, - gainlkup: ai_gain_6143, - ai_speed: 4000, - n_aochan: 0, - aobits: 0, - reg_type: ni_reg_6143, - ao_unipolar: 0, - ao_fifo_depth: 0, - .num_p0_dio_channels = 8, - .caldac = {ad8804_debug,ad8804_debug}, - }, + {device_id:0x2410, + name: "pci-6733", + n_adchan:0, /* no analog input */ + n_aochan:8, + aobits: 16, + ao_unipolar:0, + ao_fifo_depth:16384, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6713, + caldac: {ad8804_debug, ad8804_debug}, + }, + {device_id:0x2420, + name: "pxi-6733", + n_adchan:0, /* no analog input */ + n_aochan:8, + aobits: 16, + ao_unipolar:0, + ao_fifo_depth:16384, + .ao_range_table = &range_bipolar10, + ao_speed:1000, + .num_p0_dio_channels = 8, + reg_type:ni_reg_6713, + caldac: {ad8804_debug, ad8804_debug}, + }, + {device_id:0x15b0, + name: "pxi-6071e", + n_adchan:64, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_16, + ai_speed:800, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x11b0, + name: "pxi-6070e", + n_adchan:16, + adbits: 12, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_16, + ai_speed:800, + n_aochan:2, + aobits: 12, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:1000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x18c0, + name: "pxi-6052e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_16, + ai_speed:3000, + n_aochan:2, + aobits: 16, + ao_unipolar:1, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_speed:3000, + .num_p0_dio_channels = 8, + caldac: {mb88341, mb88341, ad8522}, + }, + {device_id:0x1580, + name: "pxi-6031e", + n_adchan:64, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_14, + ai_speed:10000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:2048, + .ao_range_table = &range_ni_E_ao_ext, + ao_unipolar:1, + ao_speed:10000, + .num_p0_dio_channels = 8, + caldac: {dac8800, dac8043, ad8522}, + }, + {device_id:0x2890, + name: "pci-6036e", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + alwaysdither:1, + gainlkup:ai_gain_4, + ai_speed:5000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:0, + .ao_range_table = &range_bipolar10, + ao_unipolar:0, + ao_speed:100000, + .num_p0_dio_channels = 8, + caldac: {ad8804_debug}, + has_8255:0, + }, + {device_id:0x70b0, + name: "pci-6220", + n_adchan:16, + adbits: 16, + ai_fifo_depth:512, + //FIXME: guess + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + .num_p0_dio_channels = 8, + reg_type:ni_reg_622x, + ao_unipolar:0, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70af, + name: "pci-6221", + n_adchan:16, + adbits: 16, + ai_fifo_depth:4095, + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_622x_ao, + reg_type:ni_reg_622x, + ao_unipolar:0, + ao_speed:1200, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x71bc, + name: "pci-6221_37pin", + n_adchan:16, + adbits: 16, + ai_fifo_depth:4095, + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_622x_ao, + reg_type:ni_reg_622x, + ao_unipolar:0, + ao_speed:1200, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70f2, + name: "pci-6224", + n_adchan:32, + adbits: 16, + ai_fifo_depth:4095, + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + reg_type:ni_reg_622x, + ao_unipolar:0, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x716c, + name: "pci-6225", + n_adchan:80, + adbits: 16, + ai_fifo_depth:4095, + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_622x_ao, + reg_type:ni_reg_622x, + ao_unipolar:0, + ao_speed:1200, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70aa, + name: "pci-6229", + n_adchan:32, + adbits: 16, + ai_fifo_depth:4095, + gainlkup:ai_gain_622x, + ai_speed:4000, + n_aochan:4, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_622x_ao, + reg_type:ni_reg_622x, + ao_unipolar:0, + ao_speed:1200, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70b4, + name: "pci-6250", + n_adchan:16, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + reg_type:ni_reg_625x, + ao_unipolar:0, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70b8, + name: "pci-6251", + n_adchan:16, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_625x_ao, + reg_type:ni_reg_625x, + ao_unipolar:0, + ao_speed:357, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x717d, + name: "pcie-6251", + n_adchan:16, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_625x_ao, + reg_type:ni_reg_625x, + ao_unipolar:0, + ao_speed:357, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70b7, + name: "pci-6254", + n_adchan:32, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + reg_type:ni_reg_625x, + ao_unipolar:0, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70ab, + name: "pci-6259", + n_adchan:32, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:4, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_625x_ao, + reg_type:ni_reg_625x, + ao_unipolar:0, + ao_speed:357, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x717f, + name: "pcie-6259", + n_adchan:32, + adbits: 16, + ai_fifo_depth:4095, + .gainlkup = ai_gain_628x, + ai_speed:800, + n_aochan:4, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_625x_ao, + reg_type:ni_reg_625x, + ao_unipolar:0, + ao_speed:357, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70b6, + name: "pci-6280", + n_adchan:16, + adbits: 18, + ai_fifo_depth:2047, + .gainlkup = ai_gain_628x, + ai_speed:1600, + n_aochan:0, + aobits: 0, + ao_fifo_depth:8191, + reg_type:ni_reg_628x, + ao_unipolar:0, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70bd, + name: "pci-6281", + n_adchan:16, + adbits: 18, + ai_fifo_depth:2047, + .gainlkup = ai_gain_628x, + ai_speed:1600, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_628x_ao, + reg_type:ni_reg_628x, + ao_unipolar:1, + ao_speed:357, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70bf, + name: "pxi-6281", + n_adchan:16, + adbits: 18, + ai_fifo_depth:2047, + .gainlkup = ai_gain_628x, + ai_speed:1600, + n_aochan:2, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_628x_ao, + reg_type:ni_reg_628x, + ao_unipolar:1, + ao_speed:357, + .num_p0_dio_channels = 8, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70bc, + name: "pci-6284", + n_adchan:32, + adbits: 18, + ai_fifo_depth:2047, + .gainlkup = ai_gain_628x, + ai_speed:1600, + n_aochan:0, + aobits: 0, + ao_fifo_depth:0, + reg_type:ni_reg_628x, + ao_unipolar:0, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70ac, + name: "pci-6289", + n_adchan:32, + adbits: 18, + ai_fifo_depth:2047, + .gainlkup = ai_gain_628x, + ai_speed:1600, + n_aochan:4, + aobits: 16, + ao_fifo_depth:8191, + .ao_range_table = &range_ni_M_628x_ao, + reg_type:ni_reg_628x, + ao_unipolar:1, + ao_speed:357, + .num_p0_dio_channels = 32, + .caldac = {caldac_none}, + has_8255:0, + }, + {device_id:0x70C0, + name: "pci-6143", + n_adchan:8, + adbits: 16, + ai_fifo_depth:1024, + alwaysdither:0, + gainlkup:ai_gain_6143, + ai_speed:4000, + n_aochan:0, + aobits: 0, + reg_type:ni_reg_6143, + ao_unipolar:0, + ao_fifo_depth:0, + .num_p0_dio_channels = 8, + .caldac = {ad8804_debug, ad8804_debug}, + }, + {device_id:0x710D, + name: "pxi-6143", + n_adchan:8, + adbits: 16, + ai_fifo_depth:1024, + alwaysdither:0, + gainlkup:ai_gain_6143, + ai_speed:4000, + n_aochan:0, + aobits: 0, + reg_type:ni_reg_6143, + ao_unipolar:0, + ao_fifo_depth:0, + .num_p0_dio_channels = 8, + .caldac = {ad8804_debug, ad8804_debug}, + }, }; + #define n_pcimio_boards ((sizeof(ni_boards)/sizeof(ni_boards[0]))) -static int pcimio_attach(comedi_device *dev,comedi_devconfig *it); -static int pcimio_detach(comedi_device *dev); -static comedi_driver driver_pcimio={ - driver_name: "ni_pcimio", - module: THIS_MODULE, - attach: pcimio_attach, - detach: pcimio_detach, +static int pcimio_attach(comedi_device * dev, comedi_devconfig * it); +static int pcimio_detach(comedi_device * dev); +static comedi_driver driver_pcimio = { + driver_name:"ni_pcimio", + module:THIS_MODULE, + attach:pcimio_attach, + detach:pcimio_detach, }; + COMEDI_INITCLEANUP(driver_pcimio); -typedef struct{ - NI_PRIVATE_COMMON -}ni_private; +typedef struct { +NI_PRIVATE_COMMON} ni_private; #define devpriv ((ni_private *)dev->private) /* How we access registers */ @@ -1163,7 +1169,7 @@ typedef struct{ /* However, the 611x boards still aren't working, so I'm disabling * non-windowed STC access temporarily */ -static void e_series_win_out(comedi_device *dev, uint16_t data, int reg) +static void e_series_win_out(comedi_device * dev, uint16_t data, int reg) { unsigned long flags; @@ -1173,7 +1179,7 @@ static void e_series_win_out(comedi_device *dev, uint16_t data, int reg) comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); } -static uint16_t e_series_win_in(comedi_device *dev, int reg) +static uint16_t e_series_win_in(comedi_device * dev, int reg) { unsigned long flags; uint16_t ret; @@ -1181,16 +1187,15 @@ static uint16_t e_series_win_in(comedi_device *dev, int reg) comedi_spin_lock_irqsave(&devpriv->window_lock, flags); ni_writew(reg, Window_Address); ret = ni_readw(Window_Data); - comedi_spin_unlock_irqrestore(&devpriv->window_lock,flags); + comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags); return ret; } -static void m_series_stc_writew(comedi_device *dev, uint16_t data, int reg) +static void m_series_stc_writew(comedi_device * dev, uint16_t data, int reg) { unsigned offset; - switch(reg) - { + switch (reg) { case ADC_FIFO_Clear: offset = M_Offset_AI_FIFO_Clear; break; @@ -1271,7 +1276,9 @@ static void m_series_stc_writew(comedi_device *dev, uint16_t data, int reg) offset = M_Offset_AO_FIFO_Clear; break; case DIO_Control_Register: - rt_printk("%s: FIXME: register 0x%x does not map cleanly on to m-series boards.\n", __FUNCTION__, reg); + rt_printk + ("%s: FIXME: register 0x%x does not map cleanly on to m-series boards.\n", + __FUNCTION__, reg); return; break; case G_Autoincrement_Register(0): @@ -1328,10 +1335,11 @@ static void m_series_stc_writew(comedi_device *dev, uint16_t data, int reg) case RTSI_Trig_Direction_Register: offset = M_Offset_RTSI_Trig_Direction; break; - /* FIXME: DIO_Output_Register (16 bit reg) is replaced by M_Offset_Static_Digital_Output (32 bit) - and M_Offset_SCXI_Serial_Data_Out (8 bit) */ + /* FIXME: DIO_Output_Register (16 bit reg) is replaced by M_Offset_Static_Digital_Output (32 bit) + and M_Offset_SCXI_Serial_Data_Out (8 bit) */ default: - rt_printk("%s: bug! unhandled register=0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: bug! unhandled register=0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return; break; @@ -1339,11 +1347,10 @@ static void m_series_stc_writew(comedi_device *dev, uint16_t data, int reg) ni_writew(data, offset); } -static uint16_t m_series_stc_readw(comedi_device *dev, int reg) +static uint16_t m_series_stc_readw(comedi_device * dev, int reg) { unsigned offset; - switch(reg) - { + switch (reg) { case AI_Status_1_Register: offset = M_Offset_AI_Status_1; break; @@ -1366,7 +1373,8 @@ static uint16_t m_series_stc_readw(comedi_device *dev, int reg) offset = M_Offset_G01_Status; break; default: - rt_printk("%s: bug! unhandled register=0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: bug! unhandled register=0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return 0; break; @@ -1374,11 +1382,10 @@ static uint16_t m_series_stc_readw(comedi_device *dev, int reg) return ni_readw(offset); } -static void m_series_stc_writel(comedi_device *dev, uint32_t data, int reg) +static void m_series_stc_writel(comedi_device * dev, uint32_t data, int reg) { unsigned offset; - switch(reg) - { + switch (reg) { case AI_SC_Load_A_Registers: offset = M_Offset_AI_SC_Load_A; break; @@ -1407,7 +1414,8 @@ static void m_series_stc_writel(comedi_device *dev, uint32_t data, int reg) offset = M_Offset_G1_Load_B; break; default: - rt_printk("%s: bug! unhandled register=0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: bug! unhandled register=0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return; break; @@ -1415,11 +1423,10 @@ static void m_series_stc_writel(comedi_device *dev, uint32_t data, int reg) ni_writel(data, offset); } -static uint32_t m_series_stc_readl(comedi_device *dev, int reg) +static uint32_t m_series_stc_readl(comedi_device * dev, int reg) { unsigned offset; - switch(reg) - { + switch (reg) { case G_HW_Save_Register(0): offset = M_Offset_G0_HW_Save; break; @@ -1433,7 +1440,8 @@ static uint32_t m_series_stc_readl(comedi_device *dev, int reg) offset = M_Offset_G1_Save; break; default: - rt_printk("%s: bug! unhandled register=0x%x in switch.\n", __FUNCTION__, reg); + rt_printk("%s: bug! unhandled register=0x%x in switch.\n", + __FUNCTION__, reg); BUG(); return 0; break; @@ -1448,20 +1456,19 @@ static uint32_t m_series_stc_readl(comedi_device *dev, int reg) #include "ni_mio_common.c" - -static int pcimio_find_device(comedi_device *dev,int bus,int slot); -static int pcimio_ai_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_find_device(comedi_device * dev, int bus, int slot); +static int pcimio_ai_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); -static int pcimio_ao_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ao_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); -static int pcimio_gpct0_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_gpct0_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); -static int pcimio_gpct1_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_gpct1_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); -static int pcimio_dio_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_dio_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); -static void m_series_init_eeprom_buffer(comedi_device *dev) +static void m_series_init_eeprom_buffer(comedi_device * dev) { static const int Start_Cal_EEPROM = 0x400; static const unsigned window_size = 10; @@ -1474,12 +1481,12 @@ static void m_series_init_eeprom_buffer(comedi_device *dev) old_iodwbsr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWBSR_1); old_iodwcr1_bits = readl(devpriv->mite->mite_io_addr + MITE_IODWCR_1); writel(0x0, devpriv->mite->mite_io_addr + MITE_IODWBSR); - writel(((0x80 | window_size) | devpriv->mite->daq_phys_addr), devpriv->mite->mite_io_addr + MITE_IODWBSR_1); + writel(((0x80 | window_size) | devpriv->mite->daq_phys_addr), + devpriv->mite->mite_io_addr + MITE_IODWBSR_1); writel(0x0, devpriv->mite->mite_io_addr + MITE_IODWCR_1); writel(0xf, devpriv->mite->mite_io_addr + 0x30); - for(i = 0; i < M_SERIES_EEPROM_SIZE; ++i) - { + for (i = 0; i < M_SERIES_EEPROM_SIZE; ++i) { devpriv->eeprom_buffer[i] = ni_readb(Start_Cal_EEPROM + i); } @@ -1489,68 +1496,68 @@ static void m_series_init_eeprom_buffer(comedi_device *dev) writel(0x0, devpriv->mite->mite_io_addr + 0x30); } -static void init_6143(comedi_device *dev) +static void init_6143(comedi_device * dev) { // Disable interrupts devpriv->stc_writew(dev, 0, Interrupt_Control_Register); // Initialise 6143 AI specific bits - ni_writeb(0x00, Magic_6143); // Set G0,G1 DMA mode to E series version + ni_writeb(0x00, Magic_6143); // Set G0,G1 DMA mode to E series version ni_writeb(0x80, PipelineDelay_6143); // Set EOCMode, ADCMode and pipelinedelay - ni_writeb(0x00, EOC_Set_6143); // Set EOC Delay + ni_writeb(0x00, EOC_Set_6143); // Set EOC Delay ni_writel(boardtype.ai_fifo_depth / 2, AIFIFO_Flag_6143); // Set the FIFO half full level // Strobe Relay disable bit devpriv->ai_calib_source_enabled = 0; - ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOff, Calibration_Channel_6143); + ni_writew(devpriv->ai_calib_source | Calibration_Channel_6143_RelayOff, + Calibration_Channel_6143); ni_writew(devpriv->ai_calib_source, Calibration_Channel_6143); } /* cleans up allocated resources */ -static int pcimio_detach(comedi_device *dev) +static int pcimio_detach(comedi_device * dev) { mio_common_detach(dev); - if(dev->irq){ + if (dev->irq) { comedi_free_irq(dev->irq, dev); } - if(dev->private) - { + if (dev->private) { mite_free_ring(devpriv->ai_mite_ring); mite_free_ring(devpriv->ao_mite_ring); mite_free_ring(devpriv->cdo_mite_ring); mite_free_ring(devpriv->gpct_mite_ring[0]); mite_free_ring(devpriv->gpct_mite_ring[1]); - if(devpriv->mite) + if (devpriv->mite) mite_unsetup(devpriv->mite); } return 0; } -static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) +static int pcimio_attach(comedi_device * dev, comedi_devconfig * it) { - int ret; + int ret; - printk("comedi%d: ni_pcimio:",dev->minor); + printk("comedi%d: ni_pcimio:", dev->minor); - ret=ni_alloc_private(dev); - if(ret<0)return ret; + ret = ni_alloc_private(dev); + if (ret < 0) + return ret; - ret=pcimio_find_device(dev,it->options[0],it->options[1]); - if(ret<0)return ret; + ret = pcimio_find_device(dev, it->options[0], it->options[1]); + if (ret < 0) + return ret; - printk(" %s",boardtype.name); - dev->board_name=boardtype.name; + printk(" %s", boardtype.name); + dev->board_name = boardtype.name; - if(boardtype.reg_type & ni_reg_m_series_mask) - { + if (boardtype.reg_type & ni_reg_m_series_mask) { devpriv->stc_writew = &m_series_stc_writew; devpriv->stc_readw = &m_series_stc_readw; devpriv->stc_writel = &m_series_stc_writel; devpriv->stc_readl = &m_series_stc_readl; - }else - { + } else { devpriv->stc_writew = &e_series_win_out; devpriv->stc_readw = &e_series_win_in; devpriv->stc_writel = &win_out2; @@ -1558,42 +1565,49 @@ static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) } ret = mite_setup(devpriv->mite); - if(ret < 0) - { + if (ret < 0) { printk(" error setting up mite\n"); return ret; } comedi_set_hw_dev(dev, &devpriv->mite->pcidev->dev); devpriv->ai_mite_ring = mite_alloc_ring(devpriv->mite); - if(devpriv->ai_mite_ring == NULL) return -ENOMEM; + if (devpriv->ai_mite_ring == NULL) + return -ENOMEM; devpriv->ao_mite_ring = mite_alloc_ring(devpriv->mite); - if(devpriv->ao_mite_ring == NULL) return -ENOMEM; + if (devpriv->ao_mite_ring == NULL) + return -ENOMEM; devpriv->cdo_mite_ring = mite_alloc_ring(devpriv->mite); - if(devpriv->cdo_mite_ring == NULL) return -ENOMEM; + if (devpriv->cdo_mite_ring == NULL) + return -ENOMEM; devpriv->gpct_mite_ring[0] = mite_alloc_ring(devpriv->mite); - if(devpriv->gpct_mite_ring[0] == NULL) return -ENOMEM; + if (devpriv->gpct_mite_ring[0] == NULL) + return -ENOMEM; devpriv->gpct_mite_ring[1] = mite_alloc_ring(devpriv->mite); - if(devpriv->gpct_mite_ring[1] == NULL) return -ENOMEM; + if (devpriv->gpct_mite_ring[1] == NULL) + return -ENOMEM; - if(boardtype.reg_type & ni_reg_m_series_mask) + if (boardtype.reg_type & ni_reg_m_series_mask) m_series_init_eeprom_buffer(dev); - if(boardtype.reg_type == ni_reg_6143) + if (boardtype.reg_type == ni_reg_6143) init_6143(dev); - dev->irq=mite_irq(devpriv->mite); + dev->irq = mite_irq(devpriv->mite); - if(dev->irq==0){ + if (dev->irq == 0) { printk(" unknown irq (bad)\n"); - }else{ - printk(" ( irq = %u )",dev->irq); - if( (ret=comedi_request_irq(dev->irq,ni_E_interrupt,NI_E_IRQ_FLAGS,"ni_pcimio",dev))<0 ){ + } else { + printk(" ( irq = %u )", dev->irq); + if ((ret = comedi_request_irq(dev->irq, ni_E_interrupt, + NI_E_IRQ_FLAGS, "ni_pcimio", + dev)) < 0) { printk(" irq not available\n"); - dev->irq=0; + dev->irq = 0; } } - ret = ni_E_init(dev,it); - if(ret<0)return ret; + ret = ni_E_init(dev, it); + if (ret < 0) + return ret; dev->subdevices[NI_AI_SUBDEV].buf_change = &pcimio_ai_change; dev->subdevices[NI_AO_SUBDEV].buf_change = &pcimio_ao_change; @@ -1604,24 +1618,24 @@ static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) return ret; } - -static int pcimio_find_device(comedi_device *dev,int bus,int slot) +static int pcimio_find_device(comedi_device * dev, int bus, int slot) { struct mite_struct *mite; int i; - for(mite=mite_devices;mite;mite=mite->next){ - if(mite->used)continue; - if(bus || slot){ - if(bus!=mite->pcidev->bus->number || - slot!=PCI_SLOT(mite->pcidev->devfn)) + for (mite = mite_devices; mite; mite = mite->next) { + if (mite->used) + continue; + if (bus || slot) { + if (bus != mite->pcidev->bus->number || + slot != PCI_SLOT(mite->pcidev->devfn)) continue; } - for(i=0;iboard_ptr=ni_boards+i; - devpriv->mite=mite; + for (i = 0; i < n_pcimio_boards; i++) { + if (mite_device_id(mite) == ni_boards[i].device_id) { + dev->board_ptr = ni_boards + i; + devpriv->mite = mite; return 0; } @@ -1632,57 +1646,62 @@ static int pcimio_find_device(comedi_device *dev,int bus,int slot) return -EIO; } -static int pcimio_ai_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ai_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->ai_mite_ring, s->async); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int pcimio_ao_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ao_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->ao_mite_ring, s->async); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int pcimio_gpct0_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_gpct0_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->gpct_mite_ring[0], s->async); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int pcimio_gpct1_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_gpct1_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->gpct_mite_ring[1], s->async); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int pcimio_dio_change(comedi_device *dev, comedi_subdevice *s, +static int pcimio_dio_change(comedi_device * dev, comedi_subdevice * s, unsigned long new_size) { int ret; ret = mite_buf_change(devpriv->cdo_mite_ring, s->async); - if(ret < 0) return ret; + if (ret < 0) + return ret; return 0; } diff --git a/comedi/drivers/ni_stc.h b/comedi/drivers/ni_stc.h index 4fe7e3e8..040dda29 100644 --- a/comedi/drivers/ni_stc.h +++ b/comedi/drivers/ni_stc.h @@ -86,8 +86,7 @@ #define AI_Status_2_Register 5 #define Interrupt_B_Ack_Register 3 -enum Interrupt_B_Ack_Bits -{ +enum Interrupt_B_Ack_Bits { G1_Gate_Error_Confirm = _bit1, G1_TC_Error_Confirm = _bit2, AO_BC_TC_Trigger_Error_Confirm = _bit3, @@ -123,7 +122,6 @@ enum Interrupt_B_Ack_Bits #define AO_FIFO_Request_St _bit1 #define Pass_Thru_1_Interrupt_St _bit0 - #define AI_Command_2_Register 4 #define AI_End_On_SC_TC _bit15 #define AI_End_On_End_Of_Scan _bit14 @@ -194,7 +192,6 @@ enum Interrupt_B_Ack_Bits #define AO_LDAC0_Source_Select _bit1 #define AO_UPDATE_Pulse _bit0 - #define DIO_Output_Register 10 #define DIO_Parallel_Data_Out(a) ((a)&0xff) #define DIO_Parallel_Data_Mask 0xff @@ -250,8 +247,7 @@ enum Interrupt_B_Ack_Bits #define DIO_Serial_Input_Register 28 #define Joint_Status_2_Register 29 -enum Joint_Status_2_Bits -{ +enum Joint_Status_2_Bits { AO_TMRDACWRs_In_Progress_St = 0x20, }; @@ -267,12 +263,11 @@ enum Joint_Status_2_Bits #define AO_Mode_2_Register 39 #define AO_FIFO_Mode_Mask ( 0x3 << 14 ) -enum AO_FIFO_Mode_Bits -{ - AO_FIFO_Mode_HF_to_F = (3<<14), - AO_FIFO_Mode_F = (2<<14), - AO_FIFO_Mode_HF = (1<<14), - AO_FIFO_Mode_E = (0<<14), +enum AO_FIFO_Mode_Bits { + AO_FIFO_Mode_HF_to_F = (3 << 14), + AO_FIFO_Mode_F = (2 << 14), + AO_FIFO_Mode_HF = (1 << 14), + AO_FIFO_Mode_E = (0 << 14), }; #define AO_FIFO_Retransmit_Enable _bit13 #define AO_START1_Disable _bit12 @@ -306,8 +301,7 @@ enum AO_FIFO_Mode_Bits #define AO_UC_Save_Registers 20 #define Clock_and_FOUT_Register 56 -enum Clock_and_FOUT_bits -{ +enum Clock_and_FOUT_bits { FOUT_Enable = _bit15, FOUT_Timebase_Select = _bit14, DIO_Serial_Out_Divide_By_2 = _bit13, @@ -329,8 +323,7 @@ static inline unsigned FOUT_Divider(unsigned divider) #define IO_Bidirection_Pin_Register 57 #define RTSI_Trig_Direction_Register 58 -enum RTSI_Trig_Direction_Bits -{ +enum RTSI_Trig_Direction_Bits { Drive_RTSI_Clock_Bit = 0x1, Use_RTSI_Clock_Bit = 0x2, }; @@ -338,18 +331,16 @@ static inline unsigned RTSI_Output_Bit(unsigned channel, int is_mseries) { unsigned max_channel; unsigned base_bit_shift; - if(is_mseries) - { + if (is_mseries) { base_bit_shift = 8; max_channel = 7; - }else - { + } else { base_bit_shift = 9; max_channel = 6; } - if(channel > max_channel) - { - rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, channel); + if (channel > max_channel) { + rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, + channel); return 0; } return 1 << (base_bit_shift + channel); @@ -371,14 +362,14 @@ static inline unsigned RTSI_Output_Bit(unsigned channel, int is_mseries) #define AI_EXTMUX_CLK_Output_Select(x) (((x) & 0x3) << 6) #define AI_LOCALMUX_CLK_Output_Select(x) ((x)<<4) #define AI_SC_TC_Output_Select(x) ((x)<<2) -enum ai_convert_output_selection -{ +enum ai_convert_output_selection { AI_CONVERT_Output_High_Z = 0, AI_CONVERT_Output_Ground = 1, AI_CONVERT_Output_Enable_Low = 2, AI_CONVERT_Output_Enable_High = 3 }; -static unsigned AI_CONVERT_Output_Select(enum ai_convert_output_selection selection) +static unsigned AI_CONVERT_Output_Select(enum ai_convert_output_selection + selection) { return selection & 0x3; } @@ -474,8 +465,7 @@ static unsigned AI_CONVERT_Output_Select(enum ai_convert_output_selection select #define AO_BC_TC_Interrupt_Enable _bit0 #define Second_IRQ_A_Enable_Register 74 -enum Second_IRQ_A_Enable_Bits -{ +enum Second_IRQ_A_Enable_Bits { AI_SC_TC_Second_Irq_Enable = _bit0, AI_START1_Second_Irq_Enable = _bit1, AI_START2_Second_Irq_Enable = _bit2, @@ -489,8 +479,7 @@ enum Second_IRQ_A_Enable_Bits }; #define Second_IRQ_B_Enable_Register 76 -enum Second_IRQ_B_Enable_Bits -{ +enum Second_IRQ_B_Enable_Bits { AO_BC_TC_Second_Irq_Enable = _bit0, AO_START1_Second_Irq_Enable = _bit1, AO_UPDATE_Second_Irq_Enable = _bit2, @@ -520,8 +509,7 @@ enum Second_IRQ_B_Enable_Bits #define AI_AIFREQ_Polarity _bit4 #define AO_Personal_Register 78 -enum AO_Personal_Bits -{ +enum AO_Personal_Bits { AO_Interval_Buffer_Mode = 1 << 3, AO_BC_Source_Select = 1 << 4, AO_UPDATE_Pulse_Width = 1 << 5, @@ -538,11 +526,11 @@ enum AO_Personal_Bits }; #define RTSI_Trig_A_Output_Register 79 #define RTSI_Trig_B_Output_Register 80 -enum RTSI_Trig_B_Output_Bits -{ +enum RTSI_Trig_B_Output_Bits { RTSI_Sub_Selection_1_Bit = 0x8000 // not for m-series }; -static inline unsigned RTSI_Trig_Output_Bits(unsigned rtsi_channel, unsigned source) +static inline unsigned RTSI_Trig_Output_Bits(unsigned rtsi_channel, + unsigned source) { return (source & 0xf) << ((rtsi_channel % 4) * 4); }; @@ -550,8 +538,10 @@ static inline unsigned RTSI_Trig_Output_Mask(unsigned rtsi_channel) { return 0xf << ((rtsi_channel % 4) * 4); }; + // inverse to RTSI_Trig_Output_Bits() -static inline unsigned RTSI_Trig_Output_Source(unsigned rtsi_channel, unsigned bits) +static inline unsigned RTSI_Trig_Output_Source(unsigned rtsi_channel, + unsigned bits) { return (bits >> ((rtsi_channel % 4) * 4)) & 0xf; }; @@ -569,14 +559,14 @@ static inline unsigned RTSI_Trig_Output_Source(unsigned rtsi_channel, unsigned b #define AO_UPDATE2_Output_Select(x) (((x)&0x3)<<4) #define AO_External_Gate_Polarity _bit3 #define AO_UPDATE2_Output_Toggle _bit2 -enum ao_update_output_selection -{ +enum ao_update_output_selection { AO_Update_Output_High_Z = 0, AO_Update_Output_Ground = 1, AO_Update_Output_Enable_Low = 2, AO_Update_Output_Enable_High = 3 }; -static unsigned AO_UPDATE_Output_Select(enum ao_update_output_selection selection) +static unsigned AO_UPDATE_Output_Select(enum ao_update_output_selection + selection) { return selection & 0x3; } @@ -617,23 +607,23 @@ static unsigned AO_UPDATE_Output_Select(enum ao_update_output_selection selectio #define Analog_Trigger_Etc_Register 61 /* command register */ -#define G_Disarm_Copy _bit15 /* strobe */ +#define G_Disarm_Copy _bit15 /* strobe */ #define G_Save_Trace_Copy _bit14 -#define G_Arm_Copy _bit13 /* strobe */ -#define G_Bank_Switch_Start _bit10 /* strobe */ +#define G_Arm_Copy _bit13 /* strobe */ +#define G_Bank_Switch_Start _bit10 /* strobe */ #define G_Little_Big_Endian _bit9 #define G_Synchronized_Gate _bit8 #define G_Write_Switch _bit7 #define G_Up_Down(a) (((a)&0x03)<<5) -#define G_Disarm _bit4 /* strobe */ -#define G_Analog_Trigger_Reset _bit3 /* strobe */ +#define G_Disarm _bit4 /* strobe */ +#define G_Analog_Trigger_Reset _bit3 /* strobe */ #define G_Save_Trace _bit1 -#define G_Arm _bit0 /* strobe */ +#define G_Arm _bit0 /* strobe */ /*channel agnostic names for the command register #defines */ #define G_Bank_Switch_Enable _bit12 #define G_Bank_Switch_Mode _bit11 -#define G_Load _bit2 /* strobe */ +#define G_Load _bit2 /* strobe */ /* input select register */ #define G_Gate_Select(a) (((a)&0x1f)<<7) @@ -707,8 +697,7 @@ static unsigned AO_UPDATE_Output_Select(enum ao_update_output_selection selectio /* 8 bit registers */ #define XXX_Status 0x01 -enum XXX_Status_Bits -{ +enum XXX_Status_Bits { PROMOUT = 0x1, AI_FIFO_LOWER_NOT_EMPTY = 0x8, }; @@ -723,8 +712,7 @@ enum XXX_Status_Bits #define Channel_B_Mode 0x05 #define Channel_C_Mode 0x07 #define AI_AO_Select 0x09 -enum AI_AO_Select_Bits -{ +enum AI_AO_Select_Bits { AI_DMA_Select_Shift = 0, AI_DMA_Select_Mask = 0xf, AO_DMA_Select_Shift = 4, @@ -733,16 +721,21 @@ enum AI_AO_Select_Bits #define G0_G1_Select 0x0b static inline unsigned ni_stc_dma_channel_select_bitfield(unsigned channel) { - if(channel < 4) return 1 << channel; - if(channel == 4) return 0x3; - if(channel == 5) return 0x5; + if (channel < 4) + return 1 << channel; + if (channel == 4) + return 0x3; + if (channel == 5) + return 0x5; BUG(); return 0; } -static inline unsigned GPCT_DMA_Select_Bits(unsigned gpct_index, unsigned mite_channel) +static inline unsigned GPCT_DMA_Select_Bits(unsigned gpct_index, + unsigned mite_channel) { BUG_ON(gpct_index > 1); - return ni_stc_dma_channel_select_bitfield(mite_channel) << (4 * gpct_index); + return ni_stc_dma_channel_select_bitfield(mite_channel) << (4 * + gpct_index); } static inline unsigned GPCT_DMA_Select_Mask(unsigned gpct_index) { @@ -750,26 +743,23 @@ static inline unsigned GPCT_DMA_Select_Mask(unsigned gpct_index) return 0xf << (4 * gpct_index); } - /* 16 bit registers */ #define Configuration_Memory_Low 0x10 -enum Configuration_Memory_Low_Bits -{ - AI_DITHER = 0x200, - AI_LAST_CHANNEL = 0x8000, +enum Configuration_Memory_Low_Bits { + AI_DITHER = 0x200, + AI_LAST_CHANNEL = 0x8000, }; #define Configuration_Memory_High 0x12 -enum Configuration_Memory_High_Bits -{ - AI_AC_COUPLE = 0x800, +enum Configuration_Memory_High_Bits { + AI_AC_COUPLE = 0x800, AI_DIFFERENTIAL = 0x1000, AI_COMMON = 0x2000, AI_GROUND = 0x3000, }; -static inline unsigned int AI_CONFIG_CHANNEL( unsigned int channel ) +static inline unsigned int AI_CONFIG_CHANNEL(unsigned int channel) { - return ( channel & 0x3f ); + return (channel & 0x3f); } #define ADC_FIFO_Data_Register 0x1c @@ -785,39 +775,38 @@ static inline unsigned int AI_CONFIG_CHANNEL( unsigned int channel ) #define DAC0_Direct_Data 0x18 #define DAC1_Direct_Data 0x1a - /* 611x registers (these boards differ from the e-series) */ -#define Magic_611x 0x19 /* w8 (new) */ -#define Calibration_Channel_Select_611x 0x1a /* w16 (new) */ -#define ADC_FIFO_Data_611x 0x1c /* r32 (incompatible) */ -#define AI_FIFO_Offset_Load_611x 0x05 /* r8 (new) */ -#define DAC_FIFO_Data_611x 0x14 /* w32 (incompatible) */ -#define Cal_Gain_Select_611x 0x05 /* w8 (new) */ +#define Magic_611x 0x19 /* w8 (new) */ +#define Calibration_Channel_Select_611x 0x1a /* w16 (new) */ +#define ADC_FIFO_Data_611x 0x1c /* r32 (incompatible) */ +#define AI_FIFO_Offset_Load_611x 0x05 /* r8 (new) */ +#define DAC_FIFO_Data_611x 0x14 /* w32 (incompatible) */ +#define Cal_Gain_Select_611x 0x05 /* w8 (new) */ #define AO_Window_Address_611x 0x18 #define AO_Window_Data_611x 0x1e /* 6143 registers */ -#define Magic_6143 0x19 /* w8 */ -#define G0G1_DMA_Select_6143 0x0B /* w8 */ -#define PipelineDelay_6143 0x1f /* w8 */ -#define EOC_Set_6143 0x1D /* w8 */ -#define AIDMA_Select_6143 0x09 /* w8 */ -#define AIFIFO_Data_6143 0x8C /* w32 */ -#define AIFIFO_Flag_6143 0x84 /* w32 */ -#define AIFIFO_Control_6143 0x88 /* w32 */ -#define AIFIFO_Status_6143 0x88 /* w32 */ -#define AIFIFO_DMAThreshold_6143 0x90 /* w32 */ -#define AIFIFO_Words_Available_6143 0x94 /* w32 */ - -#define Calibration_Channel_6143 0x42 /* w16 */ -#define Calibration_LowTime_6143 0x20 /* w16 */ -#define Calibration_HighTime_6143 0x22 /* w16 */ -#define Relay_Counter_Load_Val__6143 0x4C /* w32 */ -#define Signature_6143 0x50 /* w32 */ -#define Release_Date_6143 0x54 /* w32 */ -#define Release_Oldest_Date_6143 0x58 /* w32 */ +#define Magic_6143 0x19 /* w8 */ +#define G0G1_DMA_Select_6143 0x0B /* w8 */ +#define PipelineDelay_6143 0x1f /* w8 */ +#define EOC_Set_6143 0x1D /* w8 */ +#define AIDMA_Select_6143 0x09 /* w8 */ +#define AIFIFO_Data_6143 0x8C /* w32 */ +#define AIFIFO_Flag_6143 0x84 /* w32 */ +#define AIFIFO_Control_6143 0x88 /* w32 */ +#define AIFIFO_Status_6143 0x88 /* w32 */ +#define AIFIFO_DMAThreshold_6143 0x90 /* w32 */ +#define AIFIFO_Words_Available_6143 0x94 /* w32 */ + +#define Calibration_Channel_6143 0x42 /* w16 */ +#define Calibration_LowTime_6143 0x20 /* w16 */ +#define Calibration_HighTime_6143 0x22 /* w16 */ +#define Relay_Counter_Load_Val__6143 0x4C /* w32 */ +#define Signature_6143 0x50 /* w32 */ +#define Release_Date_6143 0x54 /* w32 */ +#define Release_Oldest_Date_6143 0x58 /* w32 */ #define Calibration_Channel_6143_RelayOn 0x8000 /* Calibration relay switch On */ #define Calibration_Channel_6143_RelayOff 0x4000 /* Calibration relay switch Off */ @@ -831,32 +820,29 @@ static inline unsigned int AI_CONFIG_CHANNEL( unsigned int channel ) /* 671x, 611x registers */ /* 671xi, 611x windowed ao registers */ -enum windowed_regs_67xx_61xx -{ - AO_Immediate_671x = 0x11, /* W 16 */ - AO_Timed_611x = 0x10, /* W 16 */ - AO_FIFO_Offset_Load_611x = 0x13, /* W32 */ - AO_Later_Single_Point_Updates = 0x14, /* W 16 */ - AO_Waveform_Generation_611x = 0x15, /* W 16 */ - AO_Misc_611x = 0x16, /* W 16 */ - AO_Calibration_Channel_Select_67xx = 0x17, /* W 16 */ - AO_Configuration_2_67xx = 0x18, /* W 16 */ - CAL_ADC_Command_67xx = 0x19, /* W 8 */ - CAL_ADC_Status_67xx = 0x1a, /* R 8 */ - CAL_ADC_Data_67xx = 0x1b, /* R 16 */ - CAL_ADC_Config_Data_High_Word_67xx = 0x1c, /* RW 16 */ - CAL_ADC_Config_Data_Low_Word_67xx = 0x1d, /* RW 16 */ +enum windowed_regs_67xx_61xx { + AO_Immediate_671x = 0x11, /* W 16 */ + AO_Timed_611x = 0x10, /* W 16 */ + AO_FIFO_Offset_Load_611x = 0x13, /* W32 */ + AO_Later_Single_Point_Updates = 0x14, /* W 16 */ + AO_Waveform_Generation_611x = 0x15, /* W 16 */ + AO_Misc_611x = 0x16, /* W 16 */ + AO_Calibration_Channel_Select_67xx = 0x17, /* W 16 */ + AO_Configuration_2_67xx = 0x18, /* W 16 */ + CAL_ADC_Command_67xx = 0x19, /* W 8 */ + CAL_ADC_Status_67xx = 0x1a, /* R 8 */ + CAL_ADC_Data_67xx = 0x1b, /* R 16 */ + CAL_ADC_Config_Data_High_Word_67xx = 0x1c, /* RW 16 */ + CAL_ADC_Config_Data_Low_Word_67xx = 0x1d, /* RW 16 */ }; static inline unsigned int DACx_Direct_Data_671x(int channel) { return channel; } -enum AO_Misc_611x_Bits -{ +enum AO_Misc_611x_Bits { CLEAR_WG = 1, }; -enum cs5529_configuration_bits -{ +enum cs5529_configuration_bits { CSCFG_CAL_CONTROL_MASK = 0x7, CSCFG_SELF_CAL_OFFSET = 0x1, CSCFG_SELF_CAL_GAIN = 0x2, @@ -888,8 +874,7 @@ static inline unsigned int CS5529_CONFIG_AOUT(int output) { return 1 << (22 + output); } -enum cs5529_command_bits -{ +enum cs5529_command_bits { CSCMD_POWER_SAVE = 0x1, CSCMD_REGISTER_SELECT_MASK = 0xe, CSCMD_OFFSET_REGISTER = 0x0, @@ -900,10 +885,9 @@ enum cs5529_command_bits CSCMD_SINGLE_CONVERSION = 0x40, CSCMD_COMMAND = 0x80, }; -enum cs5529_status_bits -{ +enum cs5529_status_bits { CSS_ADC_BUSY = 0x1, - CSS_OSC_DETECT = 0x2, /* indicates adc error */ + CSS_OSC_DETECT = 0x2, /* indicates adc error */ CSS_OVERRANGE = 0x4, }; #define SerDacLd(x) (0x08<<(x)) @@ -913,9 +897,12 @@ enum cs5529_status_bits but I thought I'd put it here anyway. */ -enum{ ai_gain_16=0, ai_gain_8, ai_gain_14, ai_gain_4, ai_gain_611x, ai_gain_622x, ai_gain_628x, ai_gain_6143}; -enum caldac_enum { caldac_none=0, mb88341, dac8800, dac8043, ad8522, - ad8804, ad8842, ad8804_debug }; +enum { ai_gain_16 = + 0, ai_gain_8, ai_gain_14, ai_gain_4, ai_gain_611x, ai_gain_622x, + ai_gain_628x, ai_gain_6143 }; +enum caldac_enum { caldac_none = 0, mb88341, dac8800, dac8043, ad8522, + ad8804, ad8842, ad8804_debug +}; enum ni_reg_type { ni_reg_normal = 0x0, ni_reg_611x = 0x1, @@ -932,8 +919,7 @@ enum ni_reg_type { static const comedi_lrange range_ni_E_ao_ext; -enum m_series_register_offsets -{ +enum m_series_register_offsets { M_Offset_CDIO_DMA_Select = 0x7, // write M_Offset_SCXI_Status = 0x7, // read M_Offset_AI_AO_Select = 0x9, // write, same offset as e-series @@ -1092,15 +1078,13 @@ static inline int M_Offset_Gen_PWM(int channel) } static inline int M_Offset_Static_AI_Control(int i) { - int offset[] = - { + int offset[] = { 0x64, 0x261, 0x262, 0x263, }; - if(((unsigned)i) >= sizeof(offset) / sizeof(offset[0])) - { + if (((unsigned)i) >= sizeof(offset) / sizeof(offset[0])) { rt_printk("%s: invalid channel=%i\n", __FUNCTION__, i); return offset[0]; } @@ -1108,15 +1092,13 @@ static inline int M_Offset_Static_AI_Control(int i) }; static inline int M_Offset_AO_Reference_Attenuation(int channel) { - int offset[] = - { + int offset[] = { 0x264, 0x265, 0x266, 0x267 }; - if(((unsigned)channel) >= sizeof(offset) / sizeof(offset[0])) - { + if (((unsigned)channel) >= sizeof(offset) / sizeof(offset[0])) { rt_printk("%s: invalid channel=%i\n", __FUNCTION__, channel); return offset[0]; } @@ -1124,16 +1106,15 @@ static inline int M_Offset_AO_Reference_Attenuation(int channel) }; static inline unsigned M_Offset_PFI_Output_Select(unsigned n) { - if(n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS) - { - rt_printk("%s: invalid pfi output select register=%i\n", __FUNCTION__, n); + if (n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS) { + rt_printk("%s: invalid pfi output select register=%i\n", + __FUNCTION__, n); return M_Offset_PFI_Output_Select_1; } return M_Offset_PFI_Output_Select_1 + (n - 1) * 2; } -enum MSeries_AI_Config_FIFO_Data_Bits -{ +enum MSeries_AI_Config_FIFO_Data_Bits { MSeries_AI_Config_Channel_Type_Mask = 0x7 << 6, MSeries_AI_Config_Channel_Type_Calibration_Bits = 0x0, MSeries_AI_Config_Channel_Type_Differential_Bits = 0x1 << 6, @@ -1141,7 +1122,7 @@ enum MSeries_AI_Config_FIFO_Data_Bits MSeries_AI_Config_Channel_Type_Ground_Ref_Bits = 0x3 << 6, MSeries_AI_Config_Channel_Type_Aux_Bits = 0x5 << 6, MSeries_AI_Config_Channel_Type_Ghost_Bits = 0x7 << 6, - MSeries_AI_Config_Polarity_Bit = 0x1000, // 0 for 2's complement encoding + MSeries_AI_Config_Polarity_Bit = 0x1000, // 0 for 2's complement encoding MSeries_AI_Config_Dither_Bit = 0x2000, MSeries_AI_Config_Last_Channel_Bit = 0x4000, }; @@ -1149,12 +1130,12 @@ static inline unsigned MSeries_AI_Config_Channel_Bits(unsigned channel) { return channel & 0xf; } -static inline unsigned MSeries_AI_Config_Bank_Bits(enum ni_reg_type reg_type, unsigned channel) +static inline unsigned MSeries_AI_Config_Bank_Bits(enum ni_reg_type reg_type, + unsigned channel) { unsigned bits = channel & 0x30; - if(reg_type == ni_reg_622x) - { - if(channel & 0x40) + if (reg_type == ni_reg_622x) { + if (channel & 0x40) bits |= 0x400; } return bits; @@ -1164,8 +1145,7 @@ static inline unsigned MSeries_AI_Config_Gain_Bits(unsigned range) return (range & 0x7) << 9; } -enum MSeries_Clock_and_Fout2_Bits -{ +enum MSeries_Clock_and_Fout2_Bits { MSeries_PLL_In_Source_Select_RTSI0_Bits = 0xb, MSeries_PLL_In_Source_Select_Star_Trigger_Bits = 0x14, MSeries_PLL_In_Source_Select_RTSI7_Bits = 0x1b, @@ -1174,35 +1154,37 @@ enum MSeries_Clock_and_Fout2_Bits MSeries_Timebase1_Select_Bit = 0x20, // use PLL for timebase 1 MSeries_Timebase3_Select_Bit = 0x40, // use PLL for timebase 3 /* use 10MHz instead of 20MHz for RTSI clock frequency. Appears - to have no effect, at least on pxi-6281, which always uses - 20MHz rtsi clock frequency */ + to have no effect, at least on pxi-6281, which always uses + 20MHz rtsi clock frequency */ MSeries_RTSI_10MHz_Bit = 0x80 }; -static inline unsigned MSeries_PLL_In_Source_Select_RTSI_Bits(unsigned RTSI_channel) +static inline unsigned MSeries_PLL_In_Source_Select_RTSI_Bits(unsigned + RTSI_channel) { - if(RTSI_channel > 7) - { - rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, RTSI_channel); + if (RTSI_channel > 7) { + rt_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, + RTSI_channel); return 0; } - if(RTSI_channel == 7) return MSeries_PLL_In_Source_Select_RTSI7_Bits; - else return MSeries_PLL_In_Source_Select_RTSI0_Bits + RTSI_channel; + if (RTSI_channel == 7) + return MSeries_PLL_In_Source_Select_RTSI7_Bits; + else + return MSeries_PLL_In_Source_Select_RTSI0_Bits + RTSI_channel; } -enum MSeries_PLL_Control_Bits -{ +enum MSeries_PLL_Control_Bits { MSeries_PLL_Enable_Bit = 0x1000, MSeries_PLL_VCO_Mode_200_325MHz_Bits = 0x0, - MSeries_PLL_VCO_Mode_175_225MHz_Bits = 0x2000, - MSeries_PLL_VCO_Mode_100_225MHz_Bits = 0x4000, - MSeries_PLL_VCO_Mode_75_150MHz_Bits = 0x6000, + MSeries_PLL_VCO_Mode_175_225MHz_Bits = 0x2000, + MSeries_PLL_VCO_Mode_100_225MHz_Bits = 0x4000, + MSeries_PLL_VCO_Mode_75_150MHz_Bits = 0x6000, }; static inline unsigned MSeries_PLL_Divisor_Bits(unsigned divisor) { static const unsigned max_divisor = 0x10; - if(divisor < 1 || divisor > max_divisor) - { - rt_printk("%s: bug, invalid divisor=%i\n", __FUNCTION__, divisor); + if (divisor < 1 || divisor > max_divisor) { + rt_printk("%s: bug, invalid divisor=%i\n", __FUNCTION__, + divisor); return 0; } return (divisor & 0xf) << 8; @@ -1210,21 +1192,19 @@ static inline unsigned MSeries_PLL_Divisor_Bits(unsigned divisor) static inline unsigned MSeries_PLL_Multiplier_Bits(unsigned multiplier) { static const unsigned max_multiplier = 0x100; - if(multiplier < 1 || multiplier > max_multiplier) - { - rt_printk("%s: bug, invalid multiplier=%i\n", __FUNCTION__, multiplier); + if (multiplier < 1 || multiplier > max_multiplier) { + rt_printk("%s: bug, invalid multiplier=%i\n", __FUNCTION__, + multiplier); return 0; } return multiplier & 0xff; } -enum MSeries_PLL_Status -{ +enum MSeries_PLL_Status { MSeries_PLL_Locked_Bit = 0x1 }; -enum MSeries_AI_Config_FIFO_Bypass_Bits -{ +enum MSeries_AI_Config_FIFO_Bypass_Bits { MSeries_AI_Bypass_Channel_Mask = 0x7, MSeries_AI_Bypass_Bank_Mask = 0x78, MSeries_AI_Bypass_Cal_Sel_Pos_Mask = 0x380, @@ -1233,14 +1213,16 @@ enum MSeries_AI_Config_FIFO_Bypass_Bits MSeries_AO_Bypass_AO_Cal_Sel_Mask = 0x38000, MSeries_AI_Bypass_Gain_Mask = 0x1c0000, MSeries_AI_Bypass_Dither_Bit = 0x200000, - MSeries_AI_Bypass_Polarity_Bit = 0x400000, // 0 for 2's complement encoding + MSeries_AI_Bypass_Polarity_Bit = 0x400000, // 0 for 2's complement encoding MSeries_AI_Bypass_Config_FIFO_Bit = 0x80000000 }; -static inline unsigned MSeries_AI_Bypass_Cal_Sel_Pos_Bits(int calibration_source) +static inline unsigned MSeries_AI_Bypass_Cal_Sel_Pos_Bits(int + calibration_source) { return (calibration_source << 7) & MSeries_AI_Bypass_Cal_Sel_Pos_Mask; } -static inline unsigned MSeries_AI_Bypass_Cal_Sel_Neg_Bits(int calibration_source) +static inline unsigned MSeries_AI_Bypass_Cal_Sel_Neg_Bits(int + calibration_source) { return (calibration_source << 10) & MSeries_AI_Bypass_Cal_Sel_Pos_Mask; } @@ -1249,8 +1231,7 @@ static inline unsigned MSeries_AI_Bypass_Gain_Bits(int gain) return (gain << 18) & MSeries_AI_Bypass_Gain_Mask; } -enum MSeries_AO_Config_Bank_Bits -{ +enum MSeries_AO_Config_Bank_Bits { MSeries_AO_DAC_Offset_Select_Mask = 0x7, MSeries_AO_DAC_Offset_0V_Bits = 0x0, MSeries_AO_DAC_Offset_5V_Bits = 0x1, @@ -1261,8 +1242,7 @@ enum MSeries_AO_Config_Bank_Bits MSeries_AO_Bipolar_Bit = 0x80 // turns on 2's complement encoding }; -enum MSeries_AO_Reference_Attenuation_Bits -{ +enum MSeries_AO_Reference_Attenuation_Bits { MSeries_Attenuate_x5_Bit = 0x1 }; @@ -1280,18 +1260,20 @@ static inline unsigned MSeries_PFI_Output_Select_Mask(unsigned channel) { return 0x1f << (channel % 3) * 5; }; -static inline unsigned MSeries_PFI_Output_Select_Bits(unsigned channel, unsigned source) +static inline unsigned MSeries_PFI_Output_Select_Bits(unsigned channel, + unsigned source) { return (source & 0x1f) << ((channel % 3) * 5); }; + // inverse to MSeries_PFI_Output_Select_Bits -static inline unsigned MSeries_PFI_Output_Select_Source(unsigned channel, unsigned bits) +static inline unsigned MSeries_PFI_Output_Select_Source(unsigned channel, + unsigned bits) { return (bits >> ((channel % 3) * 5)) & 0x1f; }; -enum MSeries_Gi_DMA_Config_Bits -{ +enum MSeries_Gi_DMA_Config_Bits { Gi_DMA_BankSW_Error_Bit = 0x10, Gi_DMA_Reset_Bit = 0x8, Gi_DMA_Int_Enable_Bit = 0x4, @@ -1303,21 +1285,21 @@ static inline unsigned MSeries_PFI_Filter_Select_Mask(unsigned channel) { return 0x3 << (channel * 2); } -static inline unsigned MSeries_PFI_Filter_Select_Bits(unsigned channel, unsigned filter) +static inline unsigned MSeries_PFI_Filter_Select_Bits(unsigned channel, + unsigned filter) { - return (filter << (channel * 2)) & MSeries_PFI_Filter_Select_Mask(channel); + return (filter << (channel * + 2)) & MSeries_PFI_Filter_Select_Mask(channel); } -enum CDIO_DMA_Select_Bits -{ +enum CDIO_DMA_Select_Bits { CDI_DMA_Select_Shift = 0, CDI_DMA_Select_Mask = 0xf, CDO_DMA_Select_Shift = 4, CDO_DMA_Select_Mask = 0xf << CDO_DMA_Select_Shift }; -enum CDIO_Status_Bits -{ +enum CDIO_Status_Bits { CDO_FIFO_Empty_Bit = 0x1, CDO_FIFO_Full_Bit = 0x2, CDO_FIFO_Request_Bit = 0x4, @@ -1330,8 +1312,7 @@ enum CDIO_Status_Bits CDI_Overflow_Bit = 0x100000 }; -enum CDIO_Command_Bits -{ +enum CDIO_Command_Bits { CDO_Disarm_Bit = 0x1, CDO_Arm_Bit = 0x2, CDI_Disarm_Bit = 0x4, @@ -1354,8 +1335,7 @@ enum CDIO_Command_Bits CDI_SW_Update_Bit = 0x100000 }; -enum CDI_Mode_Bits -{ +enum CDI_Mode_Bits { CDI_Sample_Source_Select_Mask = 0x3f, CDI_Halt_On_Error_Bit = 0x200, CDI_Polarity_Bit = 0x400, // sample clock on falling edge @@ -1369,14 +1349,13 @@ enum CDI_Mode_Bits CDI_Data_Lane_24_31_Bits = 0x3000 }; -enum CDO_Mode_Bits -{ +enum CDO_Mode_Bits { CDO_Sample_Source_Select_Mask = 0x3f, CDO_Retransmit_Bit = 0x100, CDO_Halt_On_Error_Bit = 0x200, CDO_Polarity_Bit = 0x400, // sample clock on falling edge CDO_FIFO_Mode_Bit = 0x800, // set for half full mode, clear for not full mode - CDO_Data_Lane_Mask = 0x3000, // data lanes specify which dio channels map to byte or word accesses to the dio fifos + CDO_Data_Lane_Mask = 0x3000, // data lanes specify which dio channels map to byte or word accesses to the dio fifos CDO_Data_Lane_0_15_Bits = 0x0, CDO_Data_Lane_16_31_Bits = 0x1000, CDO_Data_Lane_0_7_Bits = 0x0, @@ -1385,19 +1364,17 @@ enum CDO_Mode_Bits CDO_Data_Lane_24_31_Bits = 0x3000 }; -enum Interrupt_C_Enable_Bits -{ +enum Interrupt_C_Enable_Bits { Interrupt_Group_C_Enable_Bit = 0x1 }; -enum Interrupt_C_Status_Bits -{ +enum Interrupt_C_Status_Bits { Interrupt_Group_C_Status_Bit = 0x1 }; #define M_SERIES_EEPROM_SIZE 1024 -typedef struct ni_board_struct{ +typedef struct ni_board_struct { int device_id; int isapnp_id; char *name; @@ -1406,7 +1383,7 @@ typedef struct ni_board_struct{ int adbits; int ai_fifo_depth; - unsigned int alwaysdither : 1; + unsigned int alwaysdither:1; int gainlkup; int ai_speed; @@ -1419,12 +1396,12 @@ typedef struct ni_board_struct{ unsigned num_p0_dio_channels; int reg_type; - unsigned int ao_unipolar : 1; - unsigned int has_8255 : 1; - unsigned int has_analog_trig : 1; + unsigned int ao_unipolar:1; + unsigned int has_8255:1; + unsigned int has_analog_trig:1; enum caldac_enum caldac[3]; -}ni_board; +} ni_board; #define n_ni_boards (sizeof(ni_boards)/sizeof(ni_board)) @@ -1517,6 +1494,4 @@ typedef struct ni_board_struct{ struct mite_dma_descriptor_ring *cdo_mite_ring; \ struct mite_dma_descriptor_ring *gpct_mite_ring[NUM_GPCT]; - #endif /* _COMEDI_NI_STC_H */ - diff --git a/comedi/drivers/ni_tio.c b/comedi/drivers/ni_tio.c index eb83b9ca..d9b47f75 100644 --- a/comedi/drivers/ni_tio.c +++ b/comedi/drivers/ni_tio.c @@ -51,17 +51,18 @@ TODO: #include "ni_tio.h" #include "mite.h" -static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, unsigned generic_clock_source); +static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, + unsigned generic_clock_source); static unsigned ni_tio_generic_clock_src_select(const struct ni_gpct *counter); MODULE_AUTHOR("Comedi "); MODULE_DESCRIPTION("Comedi support for NI general-purpose counters"); MODULE_LICENSE("GPL"); -static inline enum ni_gpct_register NITIO_Gi_Autoincrement_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gi_Autoincrement_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Autoincrement_Reg; break; @@ -83,8 +84,7 @@ static inline enum ni_gpct_register NITIO_Gi_Autoincrement_Reg(unsigned counter_ static inline enum ni_gpct_register NITIO_Gi_Command_Reg(unsigned counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Command_Reg; break; @@ -104,10 +104,10 @@ static inline enum ni_gpct_register NITIO_Gi_Command_Reg(unsigned counter_index) return 0; } -static inline enum ni_gpct_register NITIO_Gi_Counting_Mode_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gi_Counting_Mode_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Counting_Mode_Reg; break; @@ -127,10 +127,10 @@ static inline enum ni_gpct_register NITIO_Gi_Counting_Mode_Reg(unsigned counter_ return 0; } -static inline enum ni_gpct_register NITIO_Gi_Input_Select_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gi_Input_Select_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Input_Select_Reg; break; @@ -150,10 +150,10 @@ static inline enum ni_gpct_register NITIO_Gi_Input_Select_Reg(unsigned counter_i return 0; } -static inline enum ni_gpct_register NITIO_Gxx_Joint_Reset_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gxx_Joint_Reset_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: case 1: return NITIO_G01_Joint_Reset_Reg; @@ -169,10 +169,10 @@ static inline enum ni_gpct_register NITIO_Gxx_Joint_Reset_Reg(unsigned counter_i return 0; } -static inline enum ni_gpct_register NITIO_Gxx_Joint_Status1_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gxx_Joint_Status1_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: case 1: return NITIO_G01_Joint_Status1_Reg; @@ -188,10 +188,10 @@ static inline enum ni_gpct_register NITIO_Gxx_Joint_Status1_Reg(unsigned counter return 0; } -static inline enum ni_gpct_register NITIO_Gxx_Joint_Status2_Reg(unsigned counter_index) +static inline enum ni_gpct_register NITIO_Gxx_Joint_Status2_Reg(unsigned + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: case 1: return NITIO_G01_Joint_Status2_Reg; @@ -209,8 +209,7 @@ static inline enum ni_gpct_register NITIO_Gxx_Joint_Status2_Reg(unsigned counter static inline enum ni_gpct_register NITIO_Gxx_Status_Reg(unsigned counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: case 1: return NITIO_G01_Status_Reg; @@ -228,8 +227,7 @@ static inline enum ni_gpct_register NITIO_Gxx_Status_Reg(unsigned counter_index) static inline enum ni_gpct_register NITIO_Gi_LoadA_Reg(unsigned counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_LoadA_Reg; break; @@ -251,8 +249,7 @@ static inline enum ni_gpct_register NITIO_Gi_LoadA_Reg(unsigned counter_index) static inline enum ni_gpct_register NITIO_Gi_LoadB_Reg(unsigned counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_LoadB_Reg; break; @@ -274,8 +271,7 @@ static inline enum ni_gpct_register NITIO_Gi_LoadB_Reg(unsigned counter_index) static inline enum ni_gpct_register NITIO_Gi_Mode_Reg(unsigned counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Mode_Reg; break; @@ -297,8 +293,7 @@ static inline enum ni_gpct_register NITIO_Gi_Mode_Reg(unsigned counter_index) static inline enum ni_gpct_register NITIO_Gi_SW_Save_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_SW_Save_Reg; break; @@ -320,8 +315,7 @@ static inline enum ni_gpct_register NITIO_Gi_SW_Save_Reg(int counter_index) static inline enum ni_gpct_register NITIO_Gi_Second_Gate_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Second_Gate_Reg; break; @@ -343,8 +337,7 @@ static inline enum ni_gpct_register NITIO_Gi_Second_Gate_Reg(int counter_index) static inline enum ni_gpct_register NITIO_Gi_DMA_Config_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_DMA_Config_Reg; break; @@ -366,8 +359,7 @@ static inline enum ni_gpct_register NITIO_Gi_DMA_Config_Reg(int counter_index) static inline enum ni_gpct_register NITIO_Gi_DMA_Status_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_DMA_Status_Reg; break; @@ -389,8 +381,7 @@ static inline enum ni_gpct_register NITIO_Gi_DMA_Status_Reg(int counter_index) static inline enum ni_gpct_register NITIO_Gi_ABZ_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_ABZ_Reg; break; @@ -404,10 +395,10 @@ static inline enum ni_gpct_register NITIO_Gi_ABZ_Reg(int counter_index) return 0; } -static inline enum ni_gpct_register NITIO_Gi_Interrupt_Acknowledge_Reg(int counter_index) +static inline enum ni_gpct_register NITIO_Gi_Interrupt_Acknowledge_Reg(int + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Interrupt_Acknowledge_Reg; break; @@ -429,8 +420,7 @@ static inline enum ni_gpct_register NITIO_Gi_Interrupt_Acknowledge_Reg(int count static inline enum ni_gpct_register NITIO_Gi_Status_Reg(int counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Status_Reg; break; @@ -450,10 +440,10 @@ static inline enum ni_gpct_register NITIO_Gi_Status_Reg(int counter_index) return 0; } -static inline enum ni_gpct_register NITIO_Gi_Interrupt_Enable_Reg(int counter_index) +static inline enum ni_gpct_register NITIO_Gi_Interrupt_Enable_Reg(int + counter_index) { - switch(counter_index) - { + switch (counter_index) { case 0: return NITIO_G0_Interrupt_Enable_Reg; break; @@ -473,14 +463,12 @@ static inline enum ni_gpct_register NITIO_Gi_Interrupt_Enable_Reg(int counter_in return 0; } -enum Gi_Auto_Increment_Reg_Bits -{ +enum Gi_Auto_Increment_Reg_Bits { Gi_Auto_Increment_Mask = 0xff }; #define Gi_Up_Down_Shift 5 -enum Gi_Command_Reg_Bits -{ +enum Gi_Command_Reg_Bits { Gi_Arm_Bit = 0x1, Gi_Save_Trace_Bit = 0x2, Gi_Load_Bit = 0x4, @@ -489,7 +477,7 @@ enum Gi_Command_Reg_Bits Gi_Always_Down_Bits = 0x0 << Gi_Up_Down_Shift, Gi_Always_Up_Bits = 0x1 << Gi_Up_Down_Shift, Gi_Up_Down_Hardware_IO_Bits = 0x2 << Gi_Up_Down_Shift, - Gi_Up_Down_Hardware_Gate_Bits = 0x3 << Gi_Up_Down_Shift, + Gi_Up_Down_Hardware_Gate_Bits = 0x3 << Gi_Up_Down_Shift, Gi_Write_Switch_Bit = 0x80, Gi_Synchronize_Gate_Bit = 0x100, Gi_Little_Big_Endian_Bit = 0x200, @@ -503,8 +491,7 @@ enum Gi_Command_Reg_Bits #define Gi_Index_Phase_Bitshift 5 #define Gi_HW_Arm_Select_Shift 8 -enum Gi_Counting_Mode_Reg_Bits -{ +enum Gi_Counting_Mode_Reg_Bits { Gi_Counting_Mode_Mask = 0x7, Gi_Counting_Mode_Normal_Bits = 0x0, Gi_Counting_Mode_QuadratureX1_Bits = 0x1, @@ -518,21 +505,21 @@ enum Gi_Counting_Mode_Reg_Bits Gi_Index_Phase_LowA_HighB = 0x1 << Gi_Index_Phase_Bitshift, Gi_Index_Phase_HighA_LowB = 0x2 << Gi_Index_Phase_Bitshift, Gi_Index_Phase_HighA_HighB = 0x3 << Gi_Index_Phase_Bitshift, - Gi_HW_Arm_Enable_Bit = 0x80, /* from m-series example code, not documented in 660x register level manual */ - Gi_660x_HW_Arm_Select_Mask = 0x7 << Gi_HW_Arm_Select_Shift, /* from m-series example code, not documented in 660x register level manual */ + Gi_HW_Arm_Enable_Bit = 0x80, /* from m-series example code, not documented in 660x register level manual */ + Gi_660x_HW_Arm_Select_Mask = 0x7 << Gi_HW_Arm_Select_Shift, /* from m-series example code, not documented in 660x register level manual */ Gi_660x_Prescale_X8_Bit = 0x1000, Gi_M_Series_Prescale_X8_Bit = 0x2000, Gi_M_Series_HW_Arm_Select_Mask = 0x1f << Gi_HW_Arm_Select_Shift, /* must be set for clocks over 40MHz, which includes synchronous counting and quadrature modes */ Gi_660x_Alternate_Sync_Bit = 0x2000, Gi_M_Series_Alternate_Sync_Bit = 0x4000, - Gi_660x_Prescale_X2_Bit = 0x4000, /* from m-series example code, not documented in 660x register level manual */ + Gi_660x_Prescale_X2_Bit = 0x4000, /* from m-series example code, not documented in 660x register level manual */ Gi_M_Series_Prescale_X2_Bit = 0x8000, }; -static inline enum Gi_Counting_Mode_Reg_Bits Gi_Alternate_Sync_Bit(enum ni_gpct_variant variant) +static inline enum Gi_Counting_Mode_Reg_Bits Gi_Alternate_Sync_Bit(enum + ni_gpct_variant variant) { - switch(variant) - { + switch (variant) { case ni_gpct_variant_e_series: return 0; break; @@ -548,10 +535,10 @@ static inline enum Gi_Counting_Mode_Reg_Bits Gi_Alternate_Sync_Bit(enum ni_gpct_ } return 0; } -static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X2_Bit(enum ni_gpct_variant variant) +static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X2_Bit(enum + ni_gpct_variant variant) { - switch(variant) - { + switch (variant) { case ni_gpct_variant_e_series: return 0; break; @@ -567,10 +554,10 @@ static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X2_Bit(enum ni_gpct_var } return 0; } -static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X8_Bit(enum ni_gpct_variant variant) +static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X8_Bit(enum + ni_gpct_variant variant) { - switch(variant) - { + switch (variant) { case ni_gpct_variant_e_series: return 0; break; @@ -586,10 +573,10 @@ static inline enum Gi_Counting_Mode_Reg_Bits Gi_Prescale_X8_Bit(enum ni_gpct_var } return 0; } -static inline enum Gi_Counting_Mode_Reg_Bits Gi_HW_Arm_Select_Mask(enum ni_gpct_variant variant) +static inline enum Gi_Counting_Mode_Reg_Bits Gi_HW_Arm_Select_Mask(enum + ni_gpct_variant variant) { - switch(variant) - { + switch (variant) { case ni_gpct_variant_e_series: return 0; break; @@ -607,8 +594,7 @@ static inline enum Gi_Counting_Mode_Reg_Bits Gi_HW_Arm_Select_Mask(enum ni_gpct_ } /* clock sources for ni_660x boards, get bits with Gi_Source_Select_Bits() */ -enum ni_660x_clock_source -{ +enum ni_660x_clock_source { NI_660x_Timebase_1_Clock = 0x0, /* 20MHz */ NI_660x_Source_Pin_i_Clock = 0x1, NI_660x_Next_Gate_Clock = 0xa, @@ -631,8 +617,7 @@ static inline unsigned NI_660x_Source_Pin_Clock(unsigned n) } /* clock sources for ni e and m series boards, get bits with Gi_Source_Select_Bits() */ -enum ni_m_series_clock_source -{ +enum ni_m_series_clock_source { NI_M_Series_Timebase_1_Clock = 0x0, /* 20MHz */ NI_M_Series_Timebase_2_Clock = 0x12, /* 100KHz */ NI_M_Series_Next_TC_Clock = 0x13, @@ -647,19 +632,22 @@ static const unsigned ni_m_series_max_pfi_channel = 15; static inline unsigned NI_M_Series_PFI_Clock(unsigned n) { BUG_ON(n > ni_m_series_max_pfi_channel); - if(n < 10) return 1 + n; - else return 0xb + n; + if (n < 10) + return 1 + n; + else + return 0xb + n; } static const unsigned ni_m_series_max_rtsi_channel = 7; static inline unsigned NI_M_Series_RTSI_Clock(unsigned n) { BUG_ON(n > ni_m_series_max_rtsi_channel); - if(n == 7) return 0x1b; - else return 0xb + n; + if (n == 7) + return 0x1b; + else + return 0xb + n; } -enum ni_660x_gate_select -{ +enum ni_660x_gate_select { NI_660x_Source_Pin_i_Gate_Select = 0x0, NI_660x_Gate_Pin_i_Gate_Select = 0x1, NI_660x_Next_SRC_Gate_Select = 0xa, @@ -678,8 +666,7 @@ static inline unsigned NI_660x_RTSI_Gate_Select(unsigned n) return 0xb + n; } -enum ni_m_series_gate_select -{ +enum ni_m_series_gate_select { NI_M_Series_Timestamp_Mux_Gate_Select = 0x0, NI_M_Series_AI_START2_Gate_Select = 0x12, NI_M_Series_PXI_Star_Trigger_Gate_Select = 0x13, @@ -692,22 +679,21 @@ enum ni_m_series_gate_select static inline unsigned NI_M_Series_RTSI_Gate_Select(unsigned n) { BUG_ON(n > ni_m_series_max_rtsi_channel); - if(n == 7) + if (n == 7) return 0x1b; return 0xb + n; } static inline unsigned NI_M_Series_PFI_Gate_Select(unsigned n) { BUG_ON(n > ni_m_series_max_pfi_channel); - if(n < 10) + if (n < 10) return 1 + n; return 0xb + n; } #define Gi_Source_Select_Shift 2 #define Gi_Gate_Select_Shift 7 -enum Gi_Input_Select_Bits -{ +enum Gi_Input_Select_Bits { Gi_Read_Acknowledges_Irq = 0x1, // not present on 660x Gi_Write_Acknowledges_Irq = 0x2, // not present on 660x Gi_Source_Select_Mask = 0x7c, @@ -726,14 +712,13 @@ static inline unsigned Gi_Gate_Select_Bits(unsigned gate_select) return (gate_select << Gi_Gate_Select_Shift) & Gi_Gate_Select_Mask; } -enum Gi_Mode_Bits -{ +enum Gi_Mode_Bits { Gi_Gating_Mode_Mask = 0x3, Gi_Gating_Disabled_Bits = 0x0, Gi_Level_Gating_Bits = 0x1, Gi_Rising_Edge_Gating_Bits = 0x2, Gi_Falling_Edge_Gating_Bits = 0x3, - Gi_Gate_On_Both_Edges_Bit = 0x4, /* used in conjunction with rising edge gating mode */ + Gi_Gate_On_Both_Edges_Bit = 0x4, /* used in conjunction with rising edge gating mode */ Gi_Trigger_Mode_for_Edge_Gate_Mask = 0x18, Gi_Edge_Gate_Starts_Stops_Bits = 0x0, Gi_Edge_Gate_Stops_Starts_Bits = 0x8, @@ -759,8 +744,7 @@ enum Gi_Mode_Bits Gi_Reload_Source_Switching_Bit = 0x8000 }; -enum ni_660x_second_gate_select -{ +enum ni_660x_second_gate_select { NI_660x_Source_Pin_i_Second_Gate_Select = 0x0, NI_660x_Up_Down_Pin_i_Second_Gate_Select = 0x1, NI_660x_Next_SRC_Second_Gate_Select = 0xa, @@ -776,15 +760,14 @@ static inline unsigned NI_660x_Up_Down_Pin_Second_Gate_Select(unsigned n) } static inline unsigned NI_660x_RTSI_Second_Gate_Select(unsigned n) { - BUG_ON(n > ni_660x_max_rtsi_channel); + BUG_ON(n > ni_660x_max_rtsi_channel); return 0xb + n; } #define Gi_Second_Gate_Select_Shift 7 /*FIXME: m-series has a second gate subselect bit */ /*FIXME: m-series second gate sources are undocumented (by NI)*/ -enum Gi_Second_Gate_Bits -{ +enum Gi_Second_Gate_Bits { Gi_Second_Gate_Mode_Bit = 0x1, Gi_Second_Gate_Select_Mask = 0x1f << Gi_Second_Gate_Select_Shift, Gi_Second_Gate_Polarity_Bit = 0x2000, @@ -793,11 +776,11 @@ enum Gi_Second_Gate_Bits }; static inline unsigned Gi_Second_Gate_Select_Bits(unsigned second_gate_select) { - return (second_gate_select << Gi_Second_Gate_Select_Shift) & Gi_Second_Gate_Select_Mask; + return (second_gate_select << Gi_Second_Gate_Select_Shift) & + Gi_Second_Gate_Select_Mask; } -enum Gxx_Status_Bits -{ +enum Gxx_Status_Bits { G0_Save_Bit = 0x1, G1_Save_Bit = 0x2, G0_Counting_Bit = 0x4, @@ -817,32 +800,39 @@ enum Gxx_Status_Bits }; static inline enum Gxx_Status_Bits Gi_Counting_Bit(unsigned counter_index) { - if(counter_index % 2) return G1_Counting_Bit; + if (counter_index % 2) + return G1_Counting_Bit; return G0_Counting_Bit; } static inline enum Gxx_Status_Bits Gi_Armed_Bit(unsigned counter_index) { - if(counter_index % 2) return G1_Armed_Bit; + if (counter_index % 2) + return G1_Armed_Bit; return G0_Armed_Bit; } -static inline enum Gxx_Status_Bits Gi_Next_Load_Source_Bit(unsigned counter_index) +static inline enum Gxx_Status_Bits Gi_Next_Load_Source_Bit(unsigned + counter_index) { - if(counter_index % 2) return G1_Next_Load_Source_Bit; + if (counter_index % 2) + return G1_Next_Load_Source_Bit; return G0_Next_Load_Source_Bit; } static inline enum Gxx_Status_Bits Gi_Stale_Data_Bit(unsigned counter_index) { - if(counter_index % 2) return G1_Stale_Data_Bit; + if (counter_index % 2) + return G1_Stale_Data_Bit; return G0_Stale_Data_Bit; } static inline enum Gxx_Status_Bits Gi_TC_Error_Bit(unsigned counter_index) { - if(counter_index % 2) return G1_TC_Error_Bit; + if (counter_index % 2) + return G1_TC_Error_Bit; return G0_TC_Error_Bit; } static inline enum Gxx_Status_Bits Gi_Gate_Error_Bit(unsigned counter_index) { - if(counter_index % 2) return G1_Gate_Error_Bit; + if (counter_index % 2) + return G1_Gate_Error_Bit; return G0_Gate_Error_Bit; } @@ -852,8 +842,7 @@ static inline unsigned Gi_Reset_Bit(unsigned counter_index) return 0x1 << (2 + (counter_index % 2)); } -enum Gxx_Joint_Status2_Bits -{ +enum Gxx_Joint_Status2_Bits { G0_Output_Bit = 0x1, G1_Output_Bit = 0x2, G0_HW_Save_Bit = 0x1000, @@ -861,69 +850,64 @@ enum Gxx_Joint_Status2_Bits G0_Permanent_Stale_Bit = 0x4000, G1_Permanent_Stale_Bit = 0x8000 }; -static inline enum Gxx_Joint_Status2_Bits Gi_Permanent_Stale_Bit(unsigned counter_index) +static inline enum Gxx_Joint_Status2_Bits Gi_Permanent_Stale_Bit(unsigned + counter_index) { - if(counter_index % 2) return G1_Permanent_Stale_Bit; + if (counter_index % 2) + return G1_Permanent_Stale_Bit; return G0_Permanent_Stale_Bit; } -enum Gi_DMA_Config_Reg_Bits -{ +enum Gi_DMA_Config_Reg_Bits { Gi_DMA_Enable_Bit = 0x1, Gi_DMA_Write_Bit = 0x2, Gi_DMA_Int_Bit = 0x4 }; -enum Gi_DMA_Status_Reg_Bits -{ +enum Gi_DMA_Status_Reg_Bits { Gi_DMA_Readbank_Bit = 0x2000, Gi_DRQ_Error_Bit = 0x4000, Gi_DRQ_Status_Bit = 0x8000 }; -enum G02_Interrupt_Acknowledge_Bits -{ +enum G02_Interrupt_Acknowledge_Bits { G0_Gate_Error_Confirm_Bit = 0x20, G0_TC_Error_Confirm_Bit = 0x40 }; -enum G13_Interrupt_Acknowledge_Bits -{ +enum G13_Interrupt_Acknowledge_Bits { G1_Gate_Error_Confirm_Bit = 0x2, G1_TC_Error_Confirm_Bit = 0x4 }; static inline unsigned Gi_Gate_Error_Confirm_Bit(unsigned counter_index) { - if(counter_index % 2) + if (counter_index % 2) return G1_Gate_Error_Confirm_Bit; return G0_Gate_Error_Confirm_Bit; } static inline unsigned Gi_TC_Error_Confirm_Bit(unsigned counter_index) { - if(counter_index % 2) + if (counter_index % 2) return G1_TC_Error_Confirm_Bit; return G0_TC_Error_Confirm_Bit; } + // bits that are the same in G0/G2 and G1/G3 interrupt acknowledge registers -enum Gxx_Interrupt_Acknowledge_Bits -{ +enum Gxx_Interrupt_Acknowledge_Bits { Gi_TC_Interrupt_Ack_Bit = 0x4000, Gi_Gate_Interrupt_Ack_Bit = 0x8000 }; -enum Gi_Status_Bits -{ +enum Gi_Status_Bits { Gi_Gate_Interrupt_Bit = 0x4, Gi_TC_Bit = 0x8, Gi_Interrupt_Bit = 0x8000 }; -enum G02_Interrupt_Enable_Bits -{ +enum G02_Interrupt_Enable_Bits { G0_TC_Interrupt_Enable_Bit = 0x40, G0_Gate_Interrupt_Enable_Bit = 0x100 }; -enum G13_Interrupt_Enable_Bits -{ +enum G13_Interrupt_Enable_Bits { G1_TC_Interrupt_Enable_Bit = 0x200, G1_Gate_Interrupt_Enable_Bit = 0x400 }; @@ -931,25 +915,25 @@ static inline unsigned Gi_Gate_Interrupt_Enable_Bit(unsigned counter_index) { unsigned bit; - if(counter_index % 2) - { + if (counter_index % 2) { bit = G1_Gate_Interrupt_Enable_Bit; - }else - { + } else { bit = G0_Gate_Interrupt_Enable_Bit; } return bit; } +static const lsampl_t counter_status_mask = + COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING; -static const lsampl_t counter_status_mask = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING; - -static inline void write_register(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg) +static inline void write_register(struct ni_gpct *counter, unsigned bits, + enum ni_gpct_register reg) { BUG_ON(reg >= NITIO_Num_Registers); counter->counter_dev->write_register(counter, bits, reg); } -static inline unsigned read_register(struct ni_gpct *counter, enum ni_gpct_register reg) +static inline unsigned read_register(struct ni_gpct *counter, + enum ni_gpct_register reg) { BUG_ON(reg >= NITIO_Num_Registers); return counter->counter_dev->read_register(counter, reg); @@ -959,36 +943,41 @@ static int __init ni_tio_init_module(void) { return 0; } + module_init(ni_tio_init_module); static void __exit ni_tio_cleanup_module(void) { } + module_exit(ni_tio_cleanup_module); -struct ni_gpct_device* ni_gpct_device_construct(comedi_device *dev, - void (*write_register)(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg), - unsigned (*read_register)(struct ni_gpct *counter, enum ni_gpct_register reg), - enum ni_gpct_variant variant, unsigned num_counters) +struct ni_gpct_device *ni_gpct_device_construct(comedi_device * dev, + void (*write_register) (struct ni_gpct * counter, unsigned bits, + enum ni_gpct_register reg), + unsigned (*read_register) (struct ni_gpct * counter, + enum ni_gpct_register reg), enum ni_gpct_variant variant, + unsigned num_counters) { unsigned i; - struct ni_gpct_device *counter_dev = kzalloc(sizeof(struct ni_gpct_device), GFP_KERNEL); - if(counter_dev == NULL) return NULL; + struct ni_gpct_device *counter_dev = + kzalloc(sizeof(struct ni_gpct_device), GFP_KERNEL); + if (counter_dev == NULL) + return NULL; counter_dev->dev = dev; counter_dev->write_register = write_register; counter_dev->read_register = read_register; counter_dev->variant = variant; spin_lock_init(&counter_dev->regs_lock); BUG_ON(num_counters == 0); - counter_dev->counters = kzalloc(sizeof(struct ni_gpct) * num_counters, GFP_KERNEL); - if(counter_dev->counters == NULL) - { + counter_dev->counters = + kzalloc(sizeof(struct ni_gpct) * num_counters, GFP_KERNEL); + if (counter_dev->counters == NULL) { kfree(counter_dev); return NULL; } - for(i = 0; i < num_counters; ++i) - { + for (i = 0; i < num_counters; ++i) { counter_dev->counters[i].counter_dev = counter_dev; spin_lock_init(&counter_dev->counters[i].lock); } @@ -998,15 +987,16 @@ struct ni_gpct_device* ni_gpct_device_construct(comedi_device *dev, void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev) { - if(counter_dev->counters == NULL) return; + if (counter_dev->counters == NULL) + return; kfree(counter_dev->counters); kfree(counter_dev); } -static int ni_tio_counting_mode_registers_present(const struct ni_gpct_device *counter_dev) +static int ni_tio_counting_mode_registers_present(const struct ni_gpct_device + *counter_dev) { - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_e_series: return 0; break; @@ -1021,10 +1011,10 @@ static int ni_tio_counting_mode_registers_present(const struct ni_gpct_device *c return 0; } -static int ni_tio_second_gate_registers_present(const struct ni_gpct_device *counter_dev) +static int ni_tio_second_gate_registers_present(const struct ni_gpct_device + *counter_dev) { - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_e_series: return 0; break; @@ -1039,8 +1029,9 @@ static int ni_tio_second_gate_registers_present(const struct ni_gpct_device *cou return 0; } -static inline void ni_tio_set_bits_transient(struct ni_gpct *counter, enum ni_gpct_register register_index, - unsigned bit_mask, unsigned bit_values, unsigned transient_bit_values) +static inline void ni_tio_set_bits_transient(struct ni_gpct *counter, + enum ni_gpct_register register_index, unsigned bit_mask, + unsigned bit_values, unsigned transient_bit_values) { struct ni_gpct_device *counter_dev = counter->counter_dev; unsigned long flags; @@ -1049,25 +1040,30 @@ static inline void ni_tio_set_bits_transient(struct ni_gpct *counter, enum ni_gp comedi_spin_lock_irqsave(&counter_dev->regs_lock, flags); counter_dev->regs[register_index] &= ~bit_mask; counter_dev->regs[register_index] |= (bit_values & bit_mask); - write_register(counter, counter_dev->regs[register_index] | transient_bit_values, register_index); + write_register(counter, + counter_dev->regs[register_index] | transient_bit_values, + register_index); mmiowb(); - comedi_spin_unlock_irqrestore(&counter_dev->regs_lock, flags ); + comedi_spin_unlock_irqrestore(&counter_dev->regs_lock, flags); } /* ni_tio_set_bits( ) is for safely writing to registers whose bits may be twiddled in interrupt context, or whose software copy may be read in interrupt context. */ -static inline void ni_tio_set_bits(struct ni_gpct *counter, enum ni_gpct_register register_index, - unsigned bit_mask, unsigned bit_values) +static inline void ni_tio_set_bits(struct ni_gpct *counter, + enum ni_gpct_register register_index, unsigned bit_mask, + unsigned bit_values) { - ni_tio_set_bits_transient(counter, register_index, bit_mask, bit_values, 0x0); + ni_tio_set_bits_transient(counter, register_index, bit_mask, bit_values, + 0x0); } /* ni_tio_get_soft_copy( ) is for safely reading the software copy of a register whose bits might be modified in interrupt context, or whose software copy might need to be read in interrupt context. */ -static inline unsigned ni_tio_get_soft_copy(const struct ni_gpct *counter, enum ni_gpct_register register_index) +static inline unsigned ni_tio_get_soft_copy(const struct ni_gpct *counter, + enum ni_gpct_register register_index) { struct ni_gpct_device *counter_dev = counter->counter_dev; unsigned long flags; @@ -1092,60 +1088,72 @@ void ni_tio_init_counter(struct ni_gpct *counter) ni_tio_reset_count_and_disarm(counter); /* initialize counter registers */ - counter_dev->regs[NITIO_Gi_Autoincrement_Reg(counter->counter_index)] = 0x0; - write_register(counter, counter_dev->regs[NITIO_Gi_Autoincrement_Reg(counter->counter_index)], + counter_dev->regs[NITIO_Gi_Autoincrement_Reg(counter->counter_index)] = + 0x0; + write_register(counter, + counter_dev->regs[NITIO_Gi_Autoincrement_Reg(counter-> + counter_index)], NITIO_Gi_Autoincrement_Reg(counter->counter_index)); - ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), ~0, Gi_Synchronize_Gate_Bit); - ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), ~0, 0); + ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), + ~0, Gi_Synchronize_Gate_Bit); + ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), ~0, + 0); counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)] = 0x0; - write_register(counter, counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)], + write_register(counter, + counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)], NITIO_Gi_LoadA_Reg(counter->counter_index)); counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)] = 0x0; - write_register(counter, counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)], + write_register(counter, + counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)], NITIO_Gi_LoadB_Reg(counter->counter_index)); - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), ~0, 0); - if(ni_tio_counting_mode_registers_present(counter_dev)) - { - ni_tio_set_bits(counter, NITIO_Gi_Counting_Mode_Reg(counter->counter_index), ~0, 0); - } - if(ni_tio_second_gate_registers_present(counter_dev)) - { - counter_dev->regs[NITIO_Gi_Second_Gate_Reg(counter->counter_index)] = 0x0; - write_register(counter, counter_dev->regs[NITIO_Gi_Second_Gate_Reg(counter->counter_index)], + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), ~0, 0); + if (ni_tio_counting_mode_registers_present(counter_dev)) { + ni_tio_set_bits(counter, + NITIO_Gi_Counting_Mode_Reg(counter->counter_index), ~0, + 0); + } + if (ni_tio_second_gate_registers_present(counter_dev)) { + counter_dev->regs[NITIO_Gi_Second_Gate_Reg(counter-> + counter_index)] = 0x0; + write_register(counter, + counter_dev->regs[NITIO_Gi_Second_Gate_Reg(counter-> + counter_index)], NITIO_Gi_Second_Gate_Reg(counter->counter_index)); } - ni_tio_set_bits(counter, NITIO_Gi_DMA_Config_Reg(counter->counter_index), - ~0, 0x0); - ni_tio_set_bits(counter, NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), - ~0, 0x0); + ni_tio_set_bits(counter, + NITIO_Gi_DMA_Config_Reg(counter->counter_index), ~0, 0x0); + ni_tio_set_bits(counter, + NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), ~0, 0x0); } static lsampl_t ni_tio_counter_status(struct ni_gpct *counter) { lsampl_t status = 0; - const unsigned bits = read_register(counter, NITIO_Gxx_Status_Reg(counter->counter_index)); - if(bits & Gi_Armed_Bit(counter->counter_index)) - { + const unsigned bits = read_register(counter, + NITIO_Gxx_Status_Reg(counter->counter_index)); + if (bits & Gi_Armed_Bit(counter->counter_index)) { status |= COMEDI_COUNTER_ARMED; - if(bits & Gi_Counting_Bit(counter->counter_index)) + if (bits & Gi_Counting_Bit(counter->counter_index)) status |= COMEDI_COUNTER_COUNTING; } return status; } -static void ni_tio_set_sync_mode(struct ni_gpct *counter, - int force_alt_sync) +static void ni_tio_set_sync_mode(struct ni_gpct *counter, int force_alt_sync) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned counting_mode_reg = NITIO_Gi_Counting_Mode_Reg(counter->counter_index); + const unsigned counting_mode_reg = + NITIO_Gi_Counting_Mode_Reg(counter->counter_index); static const uint64_t min_normal_sync_period_ps = 25000; const uint64_t clock_period_ps = ni_tio_clock_period_ps(counter, ni_tio_generic_clock_src_select(counter)); - if(ni_tio_counting_mode_registers_present(counter_dev) == 0) return; + if (ni_tio_counting_mode_registers_present(counter_dev) == 0) + return; - switch(ni_tio_get_soft_copy(counter, counting_mode_reg) & Gi_Counting_Mode_Mask) - { + switch (ni_tio_get_soft_copy(counter, + counting_mode_reg) & Gi_Counting_Mode_Mask) { case Gi_Counting_Mode_QuadratureX1_Bits: case Gi_Counting_Mode_QuadratureX2_Bits: case Gi_Counting_Mode_QuadratureX4_Bits: @@ -1156,15 +1164,15 @@ static void ni_tio_set_sync_mode(struct ni_gpct *counter, break; } /* It's not clear what we should do if clock_period is unknown, so we are not - using the alt sync bit in that case, but allow the caller to decide by using the - force_alt_sync parameter. */ - if(force_alt_sync || - (clock_period_ps && clock_period_ps < min_normal_sync_period_ps)) - { + using the alt sync bit in that case, but allow the caller to decide by using the + force_alt_sync parameter. */ + if (force_alt_sync || + (clock_period_ps + && clock_period_ps < min_normal_sync_period_ps)) { ni_tio_set_bits(counter, counting_mode_reg, - Gi_Alternate_Sync_Bit(counter_dev->variant), Gi_Alternate_Sync_Bit(counter_dev->variant)); - }else - { + Gi_Alternate_Sync_Bit(counter_dev->variant), + Gi_Alternate_Sync_Bit(counter_dev->variant)); + } else { ni_tio_set_bits(counter, counting_mode_reg, Gi_Alternate_Sync_Bit(counter_dev->variant), 0x0); } @@ -1177,16 +1185,15 @@ static int ni_tio_set_counter_mode(struct ni_gpct *counter, unsigned mode) unsigned mode_reg_values; unsigned input_select_bits = 0; /* these bits map directly on to the mode register */ - static const unsigned mode_reg_direct_mask = NI_GPCT_GATE_ON_BOTH_EDGES_BIT | - NI_GPCT_EDGE_GATE_MODE_MASK | NI_GPCT_STOP_MODE_MASK | - NI_GPCT_OUTPUT_MODE_MASK | NI_GPCT_HARDWARE_DISARM_MASK | - NI_GPCT_LOADING_ON_TC_BIT | NI_GPCT_LOADING_ON_GATE_BIT | - NI_GPCT_LOAD_B_SELECT_BIT; + static const unsigned mode_reg_direct_mask = + NI_GPCT_GATE_ON_BOTH_EDGES_BIT | NI_GPCT_EDGE_GATE_MODE_MASK | + NI_GPCT_STOP_MODE_MASK | NI_GPCT_OUTPUT_MODE_MASK | + NI_GPCT_HARDWARE_DISARM_MASK | NI_GPCT_LOADING_ON_TC_BIT | + NI_GPCT_LOADING_ON_GATE_BIT | NI_GPCT_LOAD_B_SELECT_BIT; mode_reg_mask = mode_reg_direct_mask | Gi_Reload_Source_Switching_Bit; mode_reg_values = mode & mode_reg_direct_mask; - switch(mode & NI_GPCT_RELOAD_SOURCE_MASK) - { + switch (mode & NI_GPCT_RELOAD_SOURCE_MASK) { case NI_GPCT_RELOAD_SOURCE_FIXED_BITS: break; case NI_GPCT_RELOAD_SOURCE_SWITCHING_BITS: @@ -1200,52 +1207,53 @@ static int ni_tio_set_counter_mode(struct ni_gpct *counter, unsigned mode) default: break; } - ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), mode_reg_mask, mode_reg_values); + ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), + mode_reg_mask, mode_reg_values); - if(ni_tio_counting_mode_registers_present(counter_dev)) - { + if (ni_tio_counting_mode_registers_present(counter_dev)) { unsigned counting_mode_bits = 0; - counting_mode_bits |= (mode >> NI_GPCT_COUNTING_MODE_SHIFT) & Gi_Counting_Mode_Mask; - counting_mode_bits |= ((mode >> NI_GPCT_INDEX_PHASE_BITSHIFT) << Gi_Index_Phase_Bitshift) & Gi_Index_Phase_Mask; - if(mode & NI_GPCT_INDEX_ENABLE_BIT) - { + counting_mode_bits |= + (mode >> NI_GPCT_COUNTING_MODE_SHIFT) & + Gi_Counting_Mode_Mask; + counting_mode_bits |= + ((mode >> NI_GPCT_INDEX_PHASE_BITSHIFT) << + Gi_Index_Phase_Bitshift) & Gi_Index_Phase_Mask; + if (mode & NI_GPCT_INDEX_ENABLE_BIT) { counting_mode_bits |= Gi_Index_Mode_Bit; } - ni_tio_set_bits(counter, NITIO_Gi_Counting_Mode_Reg(counter->counter_index), - Gi_Counting_Mode_Mask | Gi_Index_Phase_Mask | Gi_Index_Mode_Bit, - counting_mode_bits); + ni_tio_set_bits(counter, + NITIO_Gi_Counting_Mode_Reg(counter->counter_index), + Gi_Counting_Mode_Mask | Gi_Index_Phase_Mask | + Gi_Index_Mode_Bit, counting_mode_bits); ni_tio_set_sync_mode(counter, 0); } ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), - Gi_Up_Down_Mask, (mode >> NI_GPCT_COUNTING_DIRECTION_SHIFT) << Gi_Up_Down_Shift); + Gi_Up_Down_Mask, + (mode >> NI_GPCT_COUNTING_DIRECTION_SHIFT) << Gi_Up_Down_Shift); - if(mode & NI_GPCT_OR_GATE_BIT) - { + if (mode & NI_GPCT_OR_GATE_BIT) { input_select_bits |= Gi_Or_Gate_Bit; } - if(mode & NI_GPCT_INVERT_OUTPUT_BIT) - { + if (mode & NI_GPCT_INVERT_OUTPUT_BIT) { input_select_bits |= Gi_Output_Polarity_Bit; } - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), - Gi_Gate_Select_Load_Source_Bit| Gi_Or_Gate_Bit | Gi_Output_Polarity_Bit, - input_select_bits); + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), + Gi_Gate_Select_Load_Source_Bit | Gi_Or_Gate_Bit | + Gi_Output_Polarity_Bit, input_select_bits); return 0; } -static int ni_tio_arm(struct ni_gpct *counter, - int arm, unsigned start_trigger) +static int ni_tio_arm(struct ni_gpct *counter, int arm, unsigned start_trigger) { struct ni_gpct_device *counter_dev = counter->counter_dev; unsigned command_transient_bits = 0; - if(arm) - { - switch(start_trigger) - { + if (arm) { + switch (start_trigger) { case NI_GPCT_ARM_IMMEDIATE: command_transient_bits |= Gi_Arm_Bit; break; @@ -1255,38 +1263,43 @@ static int ni_tio_arm(struct ni_gpct *counter, default: break; } - if(ni_tio_counting_mode_registers_present(counter_dev)) - { + if (ni_tio_counting_mode_registers_present(counter_dev)) { unsigned counting_mode_bits = 0; - switch(start_trigger) - { + switch (start_trigger) { case NI_GPCT_ARM_IMMEDIATE: case NI_GPCT_ARM_PAIRED_IMMEDIATE: break; default: - if(start_trigger & NI_GPCT_ARM_UNKNOWN) - { + if (start_trigger & NI_GPCT_ARM_UNKNOWN) { /* pass-through the least significant bits so we can figure out what select later */ - unsigned hw_arm_select_bits = (start_trigger << Gi_HW_Arm_Select_Shift) & Gi_HW_Arm_Select_Mask(counter_dev->variant); - - counting_mode_bits |= Gi_HW_Arm_Enable_Bit | hw_arm_select_bits; - }else - { + unsigned hw_arm_select_bits = + (start_trigger << + Gi_HW_Arm_Select_Shift) & + Gi_HW_Arm_Select_Mask + (counter_dev->variant); + + counting_mode_bits |= + Gi_HW_Arm_Enable_Bit | + hw_arm_select_bits; + } else { return -EINVAL; } break; } - ni_tio_set_bits(counter, NITIO_Gi_Counting_Mode_Reg(counter->counter_index), - Gi_HW_Arm_Select_Mask(counter_dev->variant) | Gi_HW_Arm_Enable_Bit, + ni_tio_set_bits(counter, + NITIO_Gi_Counting_Mode_Reg(counter-> + counter_index), + Gi_HW_Arm_Select_Mask(counter_dev-> + variant) | Gi_HW_Arm_Enable_Bit, counting_mode_bits); } - }else - { + } else { command_transient_bits |= Gi_Disarm_Bit; } - ni_tio_set_bits_transient(counter, NITIO_Gi_Command_Reg(counter->counter_index), - 0, 0, command_transient_bits); + ni_tio_set_bits_transient(counter, + NITIO_Gi_Command_Reg(counter->counter_index), 0, 0, + command_transient_bits); return 0; } @@ -1294,10 +1307,10 @@ static unsigned ni_660x_source_select_bits(lsampl_t clock_source) { unsigned ni_660x_clock; unsigned i; - const unsigned clock_select_bits = clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK; + const unsigned clock_select_bits = + clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK; - switch(clock_select_bits) - { + switch (clock_select_bits) { case NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS: ni_660x_clock = NI_660x_Timebase_1_Clock; break; @@ -1320,24 +1333,23 @@ static unsigned ni_660x_source_select_bits(lsampl_t clock_source) ni_660x_clock = NI_660x_Next_TC_Clock; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(clock_select_bits == NI_GPCT_RTSI_CLOCK_SRC_BITS(i)) - { + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (clock_select_bits == NI_GPCT_RTSI_CLOCK_SRC_BITS(i)) { ni_660x_clock = NI_660x_RTSI_Clock(i); break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_source_pin; ++i) - { - if(clock_select_bits == NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(i)) - { + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_source_pin; ++i) { + if (clock_select_bits == + NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(i)) { ni_660x_clock = NI_660x_Source_Pin_Clock(i); break; } } - if(i <= ni_660x_max_source_pin) break; + if (i <= ni_660x_max_source_pin) + break; ni_660x_clock = 0; BUG(); break; @@ -1349,9 +1361,9 @@ static unsigned ni_m_series_source_select_bits(lsampl_t clock_source) { unsigned ni_m_series_clock; unsigned i; - const unsigned clock_select_bits = clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK; - switch(clock_select_bits) - { + const unsigned clock_select_bits = + clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK; + switch (clock_select_bits) { case NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS: ni_m_series_clock = NI_M_Series_Timebase_1_Clock; break; @@ -1380,25 +1392,24 @@ static unsigned ni_m_series_source_select_bits(lsampl_t clock_source) ni_m_series_clock = NI_M_Series_Analog_Trigger_Out_Clock; break; default: - for(i = 0; i <= ni_m_series_max_rtsi_channel; ++i) - { - if(clock_select_bits == NI_GPCT_RTSI_CLOCK_SRC_BITS(i)) - { + for (i = 0; i <= ni_m_series_max_rtsi_channel; ++i) { + if (clock_select_bits == NI_GPCT_RTSI_CLOCK_SRC_BITS(i)) { ni_m_series_clock = NI_M_Series_RTSI_Clock(i); break; } } - if(i <= ni_m_series_max_rtsi_channel) break; - for(i = 0; i <= ni_m_series_max_pfi_channel; ++i) - { - if(clock_select_bits == NI_GPCT_PFI_CLOCK_SRC_BITS(i)) - { + if (i <= ni_m_series_max_rtsi_channel) + break; + for (i = 0; i <= ni_m_series_max_pfi_channel; ++i) { + if (clock_select_bits == NI_GPCT_PFI_CLOCK_SRC_BITS(i)) { ni_m_series_clock = NI_M_Series_PFI_Clock(i); break; } } - if(i <= ni_m_series_max_pfi_channel) break; - rt_printk("invalid clock source 0x%lx\n", (unsigned long)clock_source); + if (i <= ni_m_series_max_pfi_channel) + break; + rt_printk("invalid clock source 0x%lx\n", + (unsigned long)clock_source); BUG(); ni_m_series_clock = 0; break; @@ -1406,30 +1417,33 @@ static unsigned ni_m_series_source_select_bits(lsampl_t clock_source) return Gi_Source_Select_Bits(ni_m_series_clock); }; -static void ni_tio_set_source_subselect(struct ni_gpct *counter, lsampl_t clock_source) +static void ni_tio_set_source_subselect(struct ni_gpct *counter, + lsampl_t clock_source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); - if(counter_dev->variant != ni_gpct_variant_m_series) return; - switch(clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK) - { - /* Gi_Source_Subselect is zero */ + if (counter_dev->variant != ni_gpct_variant_m_series) + return; + switch (clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK) { + /* Gi_Source_Subselect is zero */ case NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS: case NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS: counter_dev->regs[second_gate_reg] &= ~Gi_Source_Subselect_Bit; break; - /* Gi_Source_Subselect is one */ + /* Gi_Source_Subselect is one */ case NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS: case NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS: counter_dev->regs[second_gate_reg] |= Gi_Source_Subselect_Bit; break; - /* Gi_Source_Subselect doesn't matter */ + /* Gi_Source_Subselect doesn't matter */ default: return; break; } - write_register(counter, counter_dev->regs[second_gate_reg], second_gate_reg); + write_register(counter, counter_dev->regs[second_gate_reg], + second_gate_reg); } static int ni_tio_set_clock_src(struct ni_gpct *counter, @@ -1440,46 +1454,51 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter, static const uint64_t pico_per_nano = 1000; /*FIXME: validate clock source */ - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_660x: input_select_bits |= ni_660x_source_select_bits(clock_source); break; case ni_gpct_variant_e_series: case ni_gpct_variant_m_series: - input_select_bits |= ni_m_series_source_select_bits(clock_source); + input_select_bits |= + ni_m_series_source_select_bits(clock_source); break; default: BUG(); break; } - if(clock_source & NI_GPCT_INVERT_CLOCK_SRC_BIT) + if (clock_source & NI_GPCT_INVERT_CLOCK_SRC_BIT) input_select_bits |= Gi_Source_Polarity_Bit; - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), - Gi_Source_Select_Mask | Gi_Source_Polarity_Bit, input_select_bits); + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), + Gi_Source_Select_Mask | Gi_Source_Polarity_Bit, + input_select_bits); ni_tio_set_source_subselect(counter, clock_source); - if(ni_tio_counting_mode_registers_present(counter_dev)) - { - const unsigned prescaling_mode = clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK; + if (ni_tio_counting_mode_registers_present(counter_dev)) { + const unsigned prescaling_mode = + clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK; unsigned counting_mode_bits = 0; - switch(prescaling_mode) - { + switch (prescaling_mode) { case NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS: break; case NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS: - counting_mode_bits |= Gi_Prescale_X2_Bit(counter_dev->variant); + counting_mode_bits |= + Gi_Prescale_X2_Bit(counter_dev->variant); break; case NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS: - counting_mode_bits |= Gi_Prescale_X8_Bit(counter_dev->variant); + counting_mode_bits |= + Gi_Prescale_X8_Bit(counter_dev->variant); break; default: return -EINVAL; break; } - ni_tio_set_bits(counter, NITIO_Gi_Counting_Mode_Reg(counter->counter_index), - Gi_Prescale_X2_Bit(counter_dev->variant) | Gi_Prescale_X8_Bit(counter_dev->variant), - counting_mode_bits); + ni_tio_set_bits(counter, + NITIO_Gi_Counting_Mode_Reg(counter->counter_index), + Gi_Prescale_X2_Bit(counter_dev-> + variant) | Gi_Prescale_X8_Bit(counter_dev-> + variant), counting_mode_bits); } counter->clock_period_ps = pico_per_nano * period_ns; ni_tio_set_sync_mode(counter, 0); @@ -1489,14 +1508,17 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter, static unsigned ni_tio_clock_src_modifiers(const struct ni_gpct *counter) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned counting_mode_bits = ni_tio_get_soft_copy(counter, NITIO_Gi_Counting_Mode_Reg(counter->counter_index)); + const unsigned counting_mode_bits = ni_tio_get_soft_copy(counter, + NITIO_Gi_Counting_Mode_Reg(counter->counter_index)); unsigned bits = 0; - if(ni_tio_get_soft_copy(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index)) & Gi_Source_Polarity_Bit) + if (ni_tio_get_soft_copy(counter, + NITIO_Gi_Input_Select_Reg(counter-> + counter_index)) & Gi_Source_Polarity_Bit) bits |= NI_GPCT_INVERT_CLOCK_SRC_BIT; - if(counting_mode_bits & Gi_Prescale_X2_Bit(counter_dev->variant)) + if (counting_mode_bits & Gi_Prescale_X2_Bit(counter_dev->variant)) bits |= NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS; - if(counting_mode_bits & Gi_Prescale_X8_Bit(counter_dev->variant)) + if (counting_mode_bits & Gi_Prescale_X8_Bit(counter_dev->variant)) bits |= NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS; return bits; } @@ -1504,14 +1526,16 @@ static unsigned ni_tio_clock_src_modifiers(const struct ni_gpct *counter) static unsigned ni_m_series_clock_src_select(const struct ni_gpct *counter) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); unsigned clock_source = 0; unsigned i; - const unsigned input_select = (ni_tio_get_soft_copy(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index)) & Gi_Source_Select_Mask) >> + const unsigned input_select = (ni_tio_get_soft_copy(counter, + NITIO_Gi_Input_Select_Reg(counter-> + counter_index)) & Gi_Source_Select_Mask) >> Gi_Source_Select_Shift; - switch(input_select) - { + switch (input_select) { case NI_M_Series_Timebase_1_Clock: clock_source = NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS; break; @@ -1519,8 +1543,10 @@ static unsigned ni_m_series_clock_src_select(const struct ni_gpct *counter) clock_source = NI_GPCT_TIMEBASE_2_CLOCK_SRC_BITS; break; case NI_M_Series_Timebase_3_Clock: - if(counter_dev->regs[second_gate_reg] & Gi_Source_Subselect_Bit) - clock_source = NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS; + if (counter_dev-> + regs[second_gate_reg] & Gi_Source_Subselect_Bit) + clock_source = + NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS; else clock_source = NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS; break; @@ -1528,7 +1554,8 @@ static unsigned ni_m_series_clock_src_select(const struct ni_gpct *counter) clock_source = NI_GPCT_LOGIC_LOW_CLOCK_SRC_BITS; break; case NI_M_Series_Next_Gate_Clock: - if(counter_dev->regs[second_gate_reg] & Gi_Source_Subselect_Bit) + if (counter_dev-> + regs[second_gate_reg] & Gi_Source_Subselect_Bit) clock_source = NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS; else clock_source = NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS; @@ -1540,24 +1567,22 @@ static unsigned ni_m_series_clock_src_select(const struct ni_gpct *counter) clock_source = NI_GPCT_NEXT_TC_CLOCK_SRC_BITS; break; default: - for(i = 0; i <= ni_m_series_max_rtsi_channel; ++i) - { - if(input_select == NI_M_Series_RTSI_Clock(i)) - { + for (i = 0; i <= ni_m_series_max_rtsi_channel; ++i) { + if (input_select == NI_M_Series_RTSI_Clock(i)) { clock_source = NI_GPCT_RTSI_CLOCK_SRC_BITS(i); break; } } - if(i <= ni_m_series_max_rtsi_channel) break; - for(i = 0; i <= ni_m_series_max_pfi_channel; ++i) - { - if(input_select == NI_M_Series_PFI_Clock(i)) - { + if (i <= ni_m_series_max_rtsi_channel) + break; + for (i = 0; i <= ni_m_series_max_pfi_channel; ++i) { + if (input_select == NI_M_Series_PFI_Clock(i)) { clock_source = NI_GPCT_PFI_CLOCK_SRC_BITS(i); break; } } - if(i <= ni_m_series_max_pfi_channel) break; + if (i <= ni_m_series_max_pfi_channel) + break; BUG(); break; } @@ -1569,11 +1594,12 @@ static unsigned ni_660x_clock_src_select(const struct ni_gpct *counter) { unsigned clock_source = 0; unsigned i; - const unsigned input_select = (ni_tio_get_soft_copy(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index)) & Gi_Source_Select_Mask) >> + const unsigned input_select = (ni_tio_get_soft_copy(counter, + NITIO_Gi_Input_Select_Reg(counter-> + counter_index)) & Gi_Source_Select_Mask) >> Gi_Source_Select_Shift; - switch(input_select) - { + switch (input_select) { case NI_660x_Timebase_1_Clock: clock_source = NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS; break; @@ -1596,24 +1622,23 @@ static unsigned ni_660x_clock_src_select(const struct ni_gpct *counter) clock_source = NI_GPCT_NEXT_TC_CLOCK_SRC_BITS; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(input_select == NI_660x_RTSI_Clock(i)) - { + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (input_select == NI_660x_RTSI_Clock(i)) { clock_source = NI_GPCT_RTSI_CLOCK_SRC_BITS(i); break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_source_pin; ++i) - { - if(input_select == NI_660x_Source_Pin_Clock(i)) - { - clock_source = NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(i); + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_source_pin; ++i) { + if (input_select == NI_660x_Source_Pin_Clock(i)) { + clock_source = + NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(i); break; } } - if(i <= ni_660x_max_source_pin) break; + if (i <= ni_660x_max_source_pin) + break; BUG(); break; } @@ -1623,8 +1648,7 @@ static unsigned ni_660x_clock_src_select(const struct ni_gpct *counter) static unsigned ni_tio_generic_clock_src_select(const struct ni_gpct *counter) { - switch(counter->counter_dev->variant) - { + switch (counter->counter_dev->variant) { case ni_gpct_variant_e_series: case ni_gpct_variant_m_series: return ni_m_series_clock_src_select(counter); @@ -1639,12 +1663,12 @@ static unsigned ni_tio_generic_clock_src_select(const struct ni_gpct *counter) return 0; } -static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, unsigned generic_clock_source) +static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, + unsigned generic_clock_source) { uint64_t clock_period_ps; - switch(generic_clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK) - { + switch (generic_clock_source & NI_GPCT_CLOCK_SRC_SELECT_MASK) { case NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS: clock_period_ps = 50000; break; @@ -1663,8 +1687,7 @@ static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, unsigned g break; } - switch(generic_clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK) - { + switch (generic_clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK) { case NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS: break; case NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS: @@ -1681,7 +1704,7 @@ static uint64_t ni_tio_clock_period_ps(const struct ni_gpct *counter, unsigned g } static void ni_tio_get_clock_src(struct ni_gpct *counter, - lsampl_t *clock_source, lsampl_t *period_ns) + lsampl_t * clock_source, lsampl_t * period_ns) { static const unsigned pico_per_nano = 1000; uint64_t temp64; @@ -1691,23 +1714,22 @@ static void ni_tio_get_clock_src(struct ni_gpct *counter, *period_ns = temp64; } -static void ni_tio_set_first_gate_modifiers(struct ni_gpct *counter, lsampl_t gate_source) +static void ni_tio_set_first_gate_modifiers(struct ni_gpct *counter, + lsampl_t gate_source) { const unsigned mode_mask = Gi_Gate_Polarity_Bit | Gi_Gating_Mode_Mask; unsigned mode_values = 0; - if(gate_source & CR_INVERT) - { + if (gate_source & CR_INVERT) { mode_values |= Gi_Gate_Polarity_Bit; } - if(gate_source & CR_EDGE) - { + if (gate_source & CR_EDGE) { mode_values |= Gi_Rising_Edge_Gating_Bits; - }else - { + } else { mode_values |= Gi_Level_Gating_Bits; } - ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), mode_mask, mode_values); + ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), + mode_mask, mode_values); } static int ni_660x_set_first_gate(struct ni_gpct *counter, lsampl_t gate_source) @@ -1718,8 +1740,7 @@ static int ni_660x_set_first_gate(struct ni_gpct *counter, lsampl_t gate_source) unsigned ni_660x_gate_select; unsigned i; - switch(selected_gate) - { + switch (selected_gate) { case NI_GPCT_NEXT_SOURCE_GATE_SELECT: ni_660x_gate_select = NI_660x_Next_SRC_Gate_Select; break; @@ -1730,33 +1751,35 @@ static int ni_660x_set_first_gate(struct ni_gpct *counter, lsampl_t gate_source) ni_660x_gate_select = selected_gate & selected_gate_mask; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(selected_gate == NI_GPCT_RTSI_GATE_SELECT(i)) - { - ni_660x_gate_select = selected_gate & selected_gate_mask; + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (selected_gate == NI_GPCT_RTSI_GATE_SELECT(i)) { + ni_660x_gate_select = + selected_gate & selected_gate_mask; break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_gate_pin; ++i) - { - if(selected_gate == NI_GPCT_GATE_PIN_GATE_SELECT(i)) - { - ni_660x_gate_select = selected_gate & selected_gate_mask; + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_gate_pin; ++i) { + if (selected_gate == NI_GPCT_GATE_PIN_GATE_SELECT(i)) { + ni_660x_gate_select = + selected_gate & selected_gate_mask; break; } } - if(i <= ni_660x_max_gate_pin) break; + if (i <= ni_660x_max_gate_pin) + break; return -EINVAL; break; } - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), Gi_Gate_Select_Mask, Gi_Gate_Select_Bits(ni_660x_gate_select)); return 0; } -static int ni_m_series_set_first_gate(struct ni_gpct *counter, lsampl_t gate_source) +static int ni_m_series_set_first_gate(struct ni_gpct *counter, + lsampl_t gate_source) { const unsigned selected_gate = CR_CHAN(gate_source); /* bits of selected_gate that may be meaningful to input select register */ @@ -1764,8 +1787,7 @@ static int ni_m_series_set_first_gate(struct ni_gpct *counter, lsampl_t gate_sou unsigned ni_m_series_gate_select; unsigned i; - switch(selected_gate) - { + switch (selected_gate) { case NI_GPCT_TIMESTAMP_MUX_GATE_SELECT: case NI_GPCT_AI_START2_GATE_SELECT: case NI_GPCT_PXI_STAR_TRIGGER_GATE_SELECT: @@ -1777,123 +1799,138 @@ static int ni_m_series_set_first_gate(struct ni_gpct *counter, lsampl_t gate_sou ni_m_series_gate_select = selected_gate & selected_gate_mask; break; default: - for(i = 0; i <= ni_m_series_max_rtsi_channel; ++i) - { - if(selected_gate == NI_GPCT_RTSI_GATE_SELECT(i)) - { - ni_m_series_gate_select = selected_gate & selected_gate_mask; + for (i = 0; i <= ni_m_series_max_rtsi_channel; ++i) { + if (selected_gate == NI_GPCT_RTSI_GATE_SELECT(i)) { + ni_m_series_gate_select = + selected_gate & selected_gate_mask; break; } } - if(i <= ni_m_series_max_rtsi_channel) break; - for(i = 0; i <= ni_m_series_max_pfi_channel; ++i) - { - if(selected_gate == NI_GPCT_PFI_GATE_SELECT(i)) - { - ni_m_series_gate_select = selected_gate & selected_gate_mask; + if (i <= ni_m_series_max_rtsi_channel) + break; + for (i = 0; i <= ni_m_series_max_pfi_channel; ++i) { + if (selected_gate == NI_GPCT_PFI_GATE_SELECT(i)) { + ni_m_series_gate_select = + selected_gate & selected_gate_mask; break; } } - if(i <= ni_m_series_max_pfi_channel) break; + if (i <= ni_m_series_max_pfi_channel) + break; return -EINVAL; break; } - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), - Gi_Gate_Select_Mask, Gi_Gate_Select_Bits(ni_m_series_gate_select)); + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), + Gi_Gate_Select_Mask, + Gi_Gate_Select_Bits(ni_m_series_gate_select)); return 0; } -static int ni_660x_set_second_gate(struct ni_gpct *counter, lsampl_t gate_source) +static int ni_660x_set_second_gate(struct ni_gpct *counter, + lsampl_t gate_source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); const unsigned selected_second_gate = CR_CHAN(gate_source); /* bits of second_gate that may be meaningful to second gate register */ static const unsigned selected_second_gate_mask = 0x1f; unsigned ni_660x_second_gate_select; unsigned i; - switch(selected_second_gate) - { + switch (selected_second_gate) { case NI_GPCT_SOURCE_PIN_i_GATE_SELECT: case NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT: case NI_GPCT_SELECTED_GATE_GATE_SELECT: case NI_GPCT_NEXT_OUT_GATE_SELECT: case NI_GPCT_LOGIC_LOW_GATE_SELECT: - ni_660x_second_gate_select = selected_second_gate & selected_second_gate_mask; + ni_660x_second_gate_select = + selected_second_gate & selected_second_gate_mask; break; case NI_GPCT_NEXT_SOURCE_GATE_SELECT: - ni_660x_second_gate_select = NI_660x_Next_SRC_Second_Gate_Select; + ni_660x_second_gate_select = + NI_660x_Next_SRC_Second_Gate_Select; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(selected_second_gate == NI_GPCT_RTSI_GATE_SELECT(i)) - { - ni_660x_second_gate_select = selected_second_gate & selected_second_gate_mask; + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (selected_second_gate == NI_GPCT_RTSI_GATE_SELECT(i)) { + ni_660x_second_gate_select = + selected_second_gate & + selected_second_gate_mask; break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_up_down_pin; ++i) - { - if(selected_second_gate == NI_GPCT_UP_DOWN_PIN_GATE_SELECT(i)) - { - ni_660x_second_gate_select = selected_second_gate & selected_second_gate_mask; + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_up_down_pin; ++i) { + if (selected_second_gate == + NI_GPCT_UP_DOWN_PIN_GATE_SELECT(i)) { + ni_660x_second_gate_select = + selected_second_gate & + selected_second_gate_mask; break; } } - if(i <= ni_660x_max_up_down_pin) break; + if (i <= ni_660x_max_up_down_pin) + break; return -EINVAL; break; }; counter_dev->regs[second_gate_reg] |= Gi_Second_Gate_Mode_Bit; counter_dev->regs[second_gate_reg] &= ~Gi_Second_Gate_Select_Mask; - counter_dev->regs[second_gate_reg] |= Gi_Second_Gate_Select_Bits(ni_660x_second_gate_select); - write_register(counter, counter_dev->regs[second_gate_reg], second_gate_reg); + counter_dev->regs[second_gate_reg] |= + Gi_Second_Gate_Select_Bits(ni_660x_second_gate_select); + write_register(counter, counter_dev->regs[second_gate_reg], + second_gate_reg); return 0; } -static int ni_m_series_set_second_gate(struct ni_gpct *counter, lsampl_t gate_source) +static int ni_m_series_set_second_gate(struct ni_gpct *counter, + lsampl_t gate_source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); const unsigned selected_second_gate = CR_CHAN(gate_source); /* bits of second_gate that may be meaningful to second gate register */ static const unsigned selected_second_gate_mask = 0x1f; unsigned ni_m_series_second_gate_select; /* FIXME: We don't know what the m-series second gate codes are, so we'll just pass - the bits through for now. */ - switch(selected_second_gate) - { + the bits through for now. */ + switch (selected_second_gate) { default: - ni_m_series_second_gate_select = selected_second_gate & selected_second_gate_mask; + ni_m_series_second_gate_select = + selected_second_gate & selected_second_gate_mask; break; }; counter_dev->regs[second_gate_reg] |= Gi_Second_Gate_Mode_Bit; counter_dev->regs[second_gate_reg] &= ~Gi_Second_Gate_Select_Mask; - counter_dev->regs[second_gate_reg] |= Gi_Second_Gate_Select_Bits(ni_m_series_second_gate_select); - write_register(counter, counter_dev->regs[second_gate_reg], second_gate_reg); + counter_dev->regs[second_gate_reg] |= + Gi_Second_Gate_Select_Bits(ni_m_series_second_gate_select); + write_register(counter, counter_dev->regs[second_gate_reg], + second_gate_reg); return 0; } -static int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned gate_index, lsampl_t gate_source) +static int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned gate_index, + lsampl_t gate_source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); - switch(gate_index) - { + switch (gate_index) { case 0: - if(CR_CHAN(gate_source) == NI_GPCT_DISABLED_GATE_SELECT) - { - ni_tio_set_bits(counter, NITIO_Gi_Mode_Reg(counter->counter_index), Gi_Gating_Mode_Mask, Gi_Gating_Disabled_Bits); + if (CR_CHAN(gate_source) == NI_GPCT_DISABLED_GATE_SELECT) { + ni_tio_set_bits(counter, + NITIO_Gi_Mode_Reg(counter->counter_index), + Gi_Gating_Mode_Mask, Gi_Gating_Disabled_Bits); return 0; } ni_tio_set_first_gate_modifiers(counter, gate_source); - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_e_series: case ni_gpct_variant_m_series: return ni_m_series_set_first_gate(counter, gate_source); @@ -1907,24 +1944,27 @@ static int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned gate_index, lsa } break; case 1: - if(ni_tio_second_gate_registers_present(counter_dev) == 0) return -EINVAL; - if(CR_CHAN(gate_source) == NI_GPCT_DISABLED_GATE_SELECT) - { - counter_dev->regs[second_gate_reg] &= ~Gi_Second_Gate_Mode_Bit; - write_register(counter, counter_dev->regs[second_gate_reg], second_gate_reg); + if (ni_tio_second_gate_registers_present(counter_dev) == 0) + return -EINVAL; + if (CR_CHAN(gate_source) == NI_GPCT_DISABLED_GATE_SELECT) { + counter_dev->regs[second_gate_reg] &= + ~Gi_Second_Gate_Mode_Bit; + write_register(counter, + counter_dev->regs[second_gate_reg], + second_gate_reg); return 0; } - if(gate_source & CR_INVERT) - { - counter_dev->regs[second_gate_reg] |= Gi_Second_Gate_Polarity_Bit; - }else - { - counter_dev->regs[second_gate_reg] &= ~Gi_Second_Gate_Polarity_Bit; + if (gate_source & CR_INVERT) { + counter_dev->regs[second_gate_reg] |= + Gi_Second_Gate_Polarity_Bit; + } else { + counter_dev->regs[second_gate_reg] &= + ~Gi_Second_Gate_Polarity_Bit; } - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_m_series: - return ni_m_series_set_second_gate(counter, gate_source); + return ni_m_series_set_second_gate(counter, + gate_source); break; case ni_gpct_variant_660x: return ni_660x_set_second_gate(counter, gate_source); @@ -1941,16 +1981,16 @@ static int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned gate_index, lsa return 0; } -static int ni_tio_set_other_src(struct ni_gpct *counter, unsigned index, lsampl_t source) +static int ni_tio_set_other_src(struct ni_gpct *counter, unsigned index, + lsampl_t source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - if(counter_dev->variant == ni_gpct_variant_m_series) - { + if (counter_dev->variant == ni_gpct_variant_m_series) { unsigned int abz_reg, shift, mask; abz_reg = NITIO_Gi_ABZ_Reg(counter->counter_index); - switch(index) { + switch (index) { case NI_GPCT_SOURCE_ENCODER_A: shift = 10; break; @@ -1965,26 +2005,25 @@ static int ni_tio_set_other_src(struct ni_gpct *counter, unsigned index, lsampl_ break; } mask = 0x1f << shift; - if(source > 0x1f) - { + if (source > 0x1f) { /* Disable gate */ source = 0x1f; } counter_dev->regs[abz_reg] &= ~mask; counter_dev->regs[abz_reg] |= (source << shift) & mask; write_register(counter, counter_dev->regs[abz_reg], abz_reg); -// rt_printk("%s %x %d %d\n", __FUNCTION__, counter_dev->regs[abz_reg], index, source); +// rt_printk("%s %x %d %d\n", __FUNCTION__, counter_dev->regs[abz_reg], index, source); return 0; } return -EINVAL; } -static unsigned ni_660x_first_gate_to_generic_gate_source(unsigned ni_660x_gate_select) +static unsigned ni_660x_first_gate_to_generic_gate_source(unsigned + ni_660x_gate_select) { unsigned i; - switch(ni_660x_gate_select) - { + switch (ni_660x_gate_select) { case NI_660x_Source_Pin_i_Gate_Select: return NI_GPCT_SOURCE_PIN_i_GATE_SELECT; break; @@ -2001,36 +2040,35 @@ static unsigned ni_660x_first_gate_to_generic_gate_source(unsigned ni_660x_gate_ return NI_GPCT_LOGIC_LOW_GATE_SELECT; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(ni_660x_gate_select == NI_660x_RTSI_Gate_Select(i)) - { + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (ni_660x_gate_select == NI_660x_RTSI_Gate_Select(i)) { return NI_GPCT_RTSI_GATE_SELECT(i); break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_gate_pin; ++i) - { - if(ni_660x_gate_select == NI_660x_Gate_Pin_Gate_Select(i)) - { + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_gate_pin; ++i) { + if (ni_660x_gate_select == + NI_660x_Gate_Pin_Gate_Select(i)) { return NI_GPCT_GATE_PIN_GATE_SELECT(i); break; } } - if(i <= ni_660x_max_gate_pin) break; + if (i <= ni_660x_max_gate_pin) + break; BUG(); break; } return 0; }; -static unsigned ni_m_series_first_gate_to_generic_gate_source(unsigned ni_m_series_gate_select) +static unsigned ni_m_series_first_gate_to_generic_gate_source(unsigned + ni_m_series_gate_select) { unsigned i; - switch(ni_m_series_gate_select) - { + switch (ni_m_series_gate_select) { case NI_M_Series_Timestamp_Mux_Gate_Select: return NI_GPCT_TIMESTAMP_MUX_GATE_SELECT; break; @@ -2056,36 +2094,36 @@ static unsigned ni_m_series_first_gate_to_generic_gate_source(unsigned ni_m_seri return NI_GPCT_LOGIC_LOW_GATE_SELECT; break; default: - for(i = 0; i <= ni_m_series_max_rtsi_channel; ++i) - { - if(ni_m_series_gate_select == NI_M_Series_RTSI_Gate_Select(i)) - { + for (i = 0; i <= ni_m_series_max_rtsi_channel; ++i) { + if (ni_m_series_gate_select == + NI_M_Series_RTSI_Gate_Select(i)) { return NI_GPCT_RTSI_GATE_SELECT(i); break; } } - if(i <= ni_m_series_max_rtsi_channel) break; - for(i = 0; i <= ni_m_series_max_pfi_channel; ++i) - { - if(ni_m_series_gate_select == NI_M_Series_PFI_Gate_Select(i)) - { + if (i <= ni_m_series_max_rtsi_channel) + break; + for (i = 0; i <= ni_m_series_max_pfi_channel; ++i) { + if (ni_m_series_gate_select == + NI_M_Series_PFI_Gate_Select(i)) { return NI_GPCT_PFI_GATE_SELECT(i); break; } } - if(i <= ni_m_series_max_pfi_channel) break; + if (i <= ni_m_series_max_pfi_channel) + break; BUG(); break; } return 0; }; -static unsigned ni_660x_second_gate_to_generic_gate_source(unsigned ni_660x_gate_select) +static unsigned ni_660x_second_gate_to_generic_gate_source(unsigned + ni_660x_gate_select) { unsigned i; - switch(ni_660x_gate_select) - { + switch (ni_660x_gate_select) { case NI_660x_Source_Pin_i_Second_Gate_Select: return NI_GPCT_SOURCE_PIN_i_GATE_SELECT; break; @@ -2105,36 +2143,36 @@ static unsigned ni_660x_second_gate_to_generic_gate_source(unsigned ni_660x_gate return NI_GPCT_LOGIC_LOW_GATE_SELECT; break; default: - for(i = 0; i <= ni_660x_max_rtsi_channel; ++i) - { - if(ni_660x_gate_select == NI_660x_RTSI_Second_Gate_Select(i)) - { + for (i = 0; i <= ni_660x_max_rtsi_channel; ++i) { + if (ni_660x_gate_select == + NI_660x_RTSI_Second_Gate_Select(i)) { return NI_GPCT_RTSI_GATE_SELECT(i); break; } } - if(i <= ni_660x_max_rtsi_channel) break; - for(i = 0; i <= ni_660x_max_up_down_pin; ++i) - { - if(ni_660x_gate_select == NI_660x_Up_Down_Pin_Second_Gate_Select(i)) - { + if (i <= ni_660x_max_rtsi_channel) + break; + for (i = 0; i <= ni_660x_max_up_down_pin; ++i) { + if (ni_660x_gate_select == + NI_660x_Up_Down_Pin_Second_Gate_Select(i)) { return NI_GPCT_UP_DOWN_PIN_GATE_SELECT(i); break; } } - if(i <= ni_660x_max_up_down_pin) break; + if (i <= ni_660x_max_up_down_pin) + break; BUG(); break; } return 0; }; -static unsigned ni_m_series_second_gate_to_generic_gate_source(unsigned ni_m_series_gate_select) +static unsigned ni_m_series_second_gate_to_generic_gate_source(unsigned + ni_m_series_gate_select) { /*FIXME: the second gate sources for the m series are undocumented, so we just return - * the raw bits for now. */ - switch(ni_m_series_gate_select) - { + * the raw bits for now. */ + switch (ni_m_series_gate_select) { default: return ni_m_series_gate_select; break; @@ -2142,77 +2180,88 @@ static unsigned ni_m_series_second_gate_to_generic_gate_source(unsigned ni_m_ser return 0; }; -static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned gate_index, lsampl_t *gate_source) +static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned gate_index, + lsampl_t * gate_source) { struct ni_gpct_device *counter_dev = counter->counter_dev; - const unsigned mode_bits = ni_tio_get_soft_copy(counter, NITIO_Gi_Mode_Reg(counter->counter_index)); - const unsigned second_gate_reg = NITIO_Gi_Second_Gate_Reg(counter->counter_index); + const unsigned mode_bits = ni_tio_get_soft_copy(counter, + NITIO_Gi_Mode_Reg(counter->counter_index)); + const unsigned second_gate_reg = + NITIO_Gi_Second_Gate_Reg(counter->counter_index); unsigned gate_select_bits; - switch(gate_index) - { + switch (gate_index) { case 0: - if((mode_bits & Gi_Gating_Mode_Mask) == Gi_Gating_Disabled_Bits) - { + if ((mode_bits & Gi_Gating_Mode_Mask) == + Gi_Gating_Disabled_Bits) { *gate_source = NI_GPCT_DISABLED_GATE_SELECT; return 0; - }else - { - gate_select_bits = (ni_tio_get_soft_copy(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index)) & Gi_Gate_Select_Mask) >> - Gi_Gate_Select_Shift; + } else { + gate_select_bits = + (ni_tio_get_soft_copy(counter, + NITIO_Gi_Input_Select_Reg(counter-> + counter_index)) & + Gi_Gate_Select_Mask) >> Gi_Gate_Select_Shift; } - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_e_series: case ni_gpct_variant_m_series: - *gate_source = ni_m_series_first_gate_to_generic_gate_source(gate_select_bits); + *gate_source = + ni_m_series_first_gate_to_generic_gate_source + (gate_select_bits); break; case ni_gpct_variant_660x: - *gate_source = ni_660x_first_gate_to_generic_gate_source(gate_select_bits); + *gate_source = + ni_660x_first_gate_to_generic_gate_source + (gate_select_bits); break; default: BUG(); break; } - if(mode_bits & Gi_Gate_Polarity_Bit) - { + if (mode_bits & Gi_Gate_Polarity_Bit) { *gate_source |= CR_INVERT; } - if((mode_bits & Gi_Gating_Mode_Mask) != Gi_Level_Gating_Bits) - { + if ((mode_bits & Gi_Gating_Mode_Mask) != Gi_Level_Gating_Bits) { *gate_source |= CR_EDGE; } break; case 1: - if((mode_bits & Gi_Gating_Mode_Mask) == Gi_Gating_Disabled_Bits || - (counter_dev->regs[second_gate_reg] & Gi_Second_Gate_Mode_Bit) == 0) - { + if ((mode_bits & Gi_Gating_Mode_Mask) == Gi_Gating_Disabled_Bits + || (counter_dev-> + regs[second_gate_reg] & Gi_Second_Gate_Mode_Bit) + == 0) { *gate_source = NI_GPCT_DISABLED_GATE_SELECT; return 0; - }else - { - gate_select_bits = (counter_dev->regs[second_gate_reg] & Gi_Second_Gate_Select_Mask) >> Gi_Second_Gate_Select_Shift; + } else { + gate_select_bits = + (counter_dev-> + regs[second_gate_reg] & + Gi_Second_Gate_Select_Mask) >> + Gi_Second_Gate_Select_Shift; } - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_e_series: case ni_gpct_variant_m_series: - *gate_source = ni_m_series_second_gate_to_generic_gate_source(gate_select_bits); + *gate_source = + ni_m_series_second_gate_to_generic_gate_source + (gate_select_bits); break; case ni_gpct_variant_660x: - *gate_source = ni_660x_second_gate_to_generic_gate_source(gate_select_bits); + *gate_source = + ni_660x_second_gate_to_generic_gate_source + (gate_select_bits); break; default: BUG(); break; } - if(counter_dev->regs[second_gate_reg] & Gi_Second_Gate_Polarity_Bit) - { + if (counter_dev-> + regs[second_gate_reg] & Gi_Second_Gate_Polarity_Bit) { *gate_source |= CR_INVERT; } /* second gate can't have edge/level mode set independently */ - if((mode_bits & Gi_Gating_Mode_Mask) != Gi_Level_Gating_Bits) - { + if ((mode_bits & Gi_Gating_Mode_Mask) != Gi_Level_Gating_Bits) { *gate_source |= CR_EDGE; } break; @@ -2224,10 +2273,9 @@ static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned gate_index, lsa } int ni_tio_insn_config(struct ni_gpct *counter, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_SET_COUNTER_MODE: return ni_tio_set_counter_mode(counter, data[1]); break; @@ -2269,8 +2317,7 @@ int ni_tio_insn_config(struct ni_gpct *counter, return -EINVAL; } -int ni_tio_rinsn(struct ni_gpct *counter, - comedi_insn *insn, lsampl_t *data) +int ni_tio_rinsn(struct ni_gpct *counter, comedi_insn * insn, lsampl_t * data) { struct ni_gpct_device *counter_dev = counter->counter_dev; const unsigned channel = CR_CHAN(insn->chanspec); @@ -2278,31 +2325,45 @@ int ni_tio_rinsn(struct ni_gpct *counter, unsigned second_read; unsigned correct_read; - if(insn->n < 1) return 0; - switch(channel) - { + if (insn->n < 1) + return 0; + switch (channel) { case 0: - ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), Gi_Save_Trace_Bit, 0); - ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), Gi_Save_Trace_Bit, Gi_Save_Trace_Bit); + ni_tio_set_bits(counter, + NITIO_Gi_Command_Reg(counter->counter_index), + Gi_Save_Trace_Bit, 0); + ni_tio_set_bits(counter, + NITIO_Gi_Command_Reg(counter->counter_index), + Gi_Save_Trace_Bit, Gi_Save_Trace_Bit); /* The count doesn't get latched until the next clock edge, so it is possible the count - may change (once) while we are reading. Since the read of the SW_Save_Reg isn't - atomic (apparently even when it's a 32 bit register according to 660x docs), - we need to read twice and make sure the reading hasn't changed. If it has, - a third read will be correct since the count value will definitely have latched by then. */ - first_read = read_register(counter, NITIO_Gi_SW_Save_Reg(counter->counter_index)); - second_read = read_register(counter, NITIO_Gi_SW_Save_Reg(counter->counter_index)); - if(first_read != second_read) - correct_read = read_register(counter, NITIO_Gi_SW_Save_Reg(counter->counter_index)); + may change (once) while we are reading. Since the read of the SW_Save_Reg isn't + atomic (apparently even when it's a 32 bit register according to 660x docs), + we need to read twice and make sure the reading hasn't changed. If it has, + a third read will be correct since the count value will definitely have latched by then. */ + first_read = + read_register(counter, + NITIO_Gi_SW_Save_Reg(counter->counter_index)); + second_read = + read_register(counter, + NITIO_Gi_SW_Save_Reg(counter->counter_index)); + if (first_read != second_read) + correct_read = + read_register(counter, + NITIO_Gi_SW_Save_Reg(counter->counter_index)); else correct_read = first_read; data[0] = correct_read; return 0; break; case 1: - data[0] = counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)]; + data[0] = + counter_dev->regs[NITIO_Gi_LoadA_Reg(counter-> + counter_index)]; break; case 2: - data[0] = counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)]; + data[0] = + counter_dev->regs[NITIO_Gi_LoadB_Reg(counter-> + counter_index)]; break; }; return 0; @@ -2310,45 +2371,47 @@ int ni_tio_rinsn(struct ni_gpct *counter, static unsigned ni_tio_next_load_register(struct ni_gpct *counter) { - const unsigned bits = read_register(counter, NITIO_Gxx_Status_Reg(counter->counter_index)); + const unsigned bits = read_register(counter, + NITIO_Gxx_Status_Reg(counter->counter_index)); - if(bits & Gi_Next_Load_Source_Bit(counter->counter_index)) - { + if (bits & Gi_Next_Load_Source_Bit(counter->counter_index)) { return NITIO_Gi_LoadB_Reg(counter->counter_index); - }else - { + } else { return NITIO_Gi_LoadA_Reg(counter->counter_index); } } -int ni_tio_winsn(struct ni_gpct *counter, - comedi_insn *insn, - lsampl_t * data) +int ni_tio_winsn(struct ni_gpct *counter, comedi_insn * insn, lsampl_t * data) { struct ni_gpct_device *counter_dev = counter->counter_dev; const unsigned channel = CR_CHAN(insn->chanspec); unsigned load_reg; - if(insn->n < 1) return 0; - switch(channel) - { + if (insn->n < 1) + return 0; + switch (channel) { case 0: /* Unsafe if counter is armed. Should probably check status and return -EBUSY if armed. */ /* Don't disturb load source select, just use whichever load register is already selected. */ load_reg = ni_tio_next_load_register(counter); write_register(counter, data[0], load_reg); - ni_tio_set_bits_transient(counter, NITIO_Gi_Command_Reg(counter->counter_index), - 0, 0, Gi_Load_Bit); + ni_tio_set_bits_transient(counter, + NITIO_Gi_Command_Reg(counter->counter_index), 0, 0, + Gi_Load_Bit); /* restore state of load reg to whatever the user set last set it to */ write_register(counter, counter_dev->regs[load_reg], load_reg); break; case 1: - counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)] = data[0]; - write_register(counter, data[0], NITIO_Gi_LoadA_Reg(counter->counter_index)); + counter_dev->regs[NITIO_Gi_LoadA_Reg(counter->counter_index)] = + data[0]; + write_register(counter, data[0], + NITIO_Gi_LoadA_Reg(counter->counter_index)); break; case 2: - counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)] = data[0]; - write_register(counter, data[0], NITIO_Gi_LoadB_Reg(counter->counter_index)); + counter_dev->regs[NITIO_Gi_LoadB_Reg(counter->counter_index)] = + data[0]; + write_register(counter, data[0], + NITIO_Gi_LoadB_Reg(counter->counter_index)); break; default: return -EINVAL; @@ -2357,49 +2420,48 @@ int ni_tio_winsn(struct ni_gpct *counter, return 0; } -static void ni_tio_configure_dma(struct ni_gpct *counter, short enable, short read_not_write) +static void ni_tio_configure_dma(struct ni_gpct *counter, short enable, + short read_not_write) { struct ni_gpct_device *counter_dev = counter->counter_dev; unsigned input_select_bits = 0; - if(enable) - { - if(read_not_write) - { + if (enable) { + if (read_not_write) { input_select_bits |= Gi_Read_Acknowledges_Irq; - }else - { + } else { input_select_bits |= Gi_Write_Acknowledges_Irq; } } - ni_tio_set_bits(counter, NITIO_Gi_Input_Select_Reg(counter->counter_index), - Gi_Read_Acknowledges_Irq | Gi_Write_Acknowledges_Irq, input_select_bits); - switch(counter_dev->variant) - { + ni_tio_set_bits(counter, + NITIO_Gi_Input_Select_Reg(counter->counter_index), + Gi_Read_Acknowledges_Irq | Gi_Write_Acknowledges_Irq, + input_select_bits); + switch (counter_dev->variant) { case ni_gpct_variant_e_series: break; case ni_gpct_variant_m_series: case ni_gpct_variant_660x: { - unsigned gi_dma_config_bits = 0; + unsigned gi_dma_config_bits = 0; - if(enable) - { + if (enable) { gi_dma_config_bits |= Gi_DMA_Enable_Bit; gi_dma_config_bits |= Gi_DMA_Int_Bit; } - if(read_not_write == 0) - { + if (read_not_write == 0) { gi_dma_config_bits |= Gi_DMA_Write_Bit; } - ni_tio_set_bits(counter, NITIO_Gi_DMA_Config_Reg(counter->counter_index), - Gi_DMA_Enable_Bit | Gi_DMA_Int_Bit | Gi_DMA_Write_Bit, gi_dma_config_bits); + ni_tio_set_bits(counter, + NITIO_Gi_DMA_Config_Reg(counter->counter_index), + Gi_DMA_Enable_Bit | Gi_DMA_Int_Bit | + Gi_DMA_Write_Bit, gi_dma_config_bits); } break; } } -static int ni_tio_input_inttrig(comedi_device *dev, comedi_subdevice *s, +static int ni_tio_input_inttrig(comedi_device * dev, comedi_subdevice * s, unsigned int trignum) { unsigned long flags; @@ -2407,20 +2469,24 @@ static int ni_tio_input_inttrig(comedi_device *dev, comedi_subdevice *s, struct ni_gpct *counter = s->private; BUG_ON(counter == NULL); - if(trignum != 0) return -EINVAL; + if (trignum != 0) + return -EINVAL; comedi_spin_lock_irqsave(&counter->lock, flags); - if(counter->mite_chan) mite_dma_arm(counter->mite_chan); - else retval = -EIO; + if (counter->mite_chan) + mite_dma_arm(counter->mite_chan); + else + retval = -EIO; comedi_spin_unlock_irqrestore(&counter->lock, flags); - if(retval < 0) return retval; + if (retval < 0) + return retval; retval = ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE); s->async->inttrig = NULL; return retval; } -static int ni_tio_input_cmd(struct ni_gpct *counter, comedi_async *async) +static int ni_tio_input_cmd(struct ni_gpct *counter, comedi_async * async) { struct ni_gpct_device *counter_dev = counter->counter_dev; comedi_cmd *cmd = &async->cmd; @@ -2429,8 +2495,7 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, comedi_async *async) /* write alloc the entire buffer */ comedi_buf_write_alloc(async, async->prealloc_bufsz); counter->mite_chan->dir = COMEDI_INPUT; - switch(counter_dev->variant) - { + switch (counter_dev->variant) { case ni_gpct_variant_m_series: case ni_gpct_variant_660x: mite_prep_dma(counter->mite_chan, 32, 32); @@ -2442,10 +2507,10 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, comedi_async *async) BUG(); break; } - ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), Gi_Save_Trace_Bit, 0); + ni_tio_set_bits(counter, NITIO_Gi_Command_Reg(counter->counter_index), + Gi_Save_Trace_Bit, 0); ni_tio_configure_dma(counter, 1, 1); - switch(cmd->start_src) - { + switch (cmd->start_src) { case TRIG_NOW: async->inttrig = NULL; mite_dma_arm(counter->mite_chan); @@ -2469,7 +2534,7 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, comedi_async *async) return retval; } -static int ni_tio_output_cmd(struct ni_gpct *counter, comedi_async *async) +static int ni_tio_output_cmd(struct ni_gpct *counter, comedi_async * async) { rt_printk("ni_tio: output commands not yet implemented.\n"); return -ENOTSUPP; @@ -2481,55 +2546,49 @@ static int ni_tio_output_cmd(struct ni_gpct *counter, comedi_async *async) return ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE); } -static int ni_tio_cmd_setup(struct ni_gpct *counter, comedi_async *async) +static int ni_tio_cmd_setup(struct ni_gpct *counter, comedi_async * async) { comedi_cmd *cmd = &async->cmd; int set_gate_source = 0; unsigned gate_source; int retval = 0; - if(cmd->scan_begin_src == TRIG_EXT) - { + if (cmd->scan_begin_src == TRIG_EXT) { set_gate_source = 1; gate_source = cmd->scan_begin_arg; - }else if(cmd->convert_src == TRIG_EXT) - { + } else if (cmd->convert_src == TRIG_EXT) { set_gate_source = 1; gate_source = cmd->convert_arg; } - if(set_gate_source) - { + if (set_gate_source) { retval = ni_tio_set_gate_src(counter, 0, gate_source); } - if(cmd->flags & TRIG_WAKE_EOS) - { - ni_tio_set_bits(counter, NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), - Gi_Gate_Interrupt_Enable_Bit(counter->counter_index), Gi_Gate_Interrupt_Enable_Bit(counter->counter_index)); + if (cmd->flags & TRIG_WAKE_EOS) { + ni_tio_set_bits(counter, + NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), + Gi_Gate_Interrupt_Enable_Bit(counter->counter_index), + Gi_Gate_Interrupt_Enable_Bit(counter->counter_index)); } return retval; } -int ni_tio_cmd(struct ni_gpct *counter, comedi_async *async) +int ni_tio_cmd(struct ni_gpct *counter, comedi_async * async) { comedi_cmd *cmd = &async->cmd; int retval = 0; unsigned long flags; comedi_spin_lock_irqsave(&counter->lock, flags); - if(counter->mite_chan == NULL) - { - rt_printk("ni_tio: commands only supported with DMA. Interrupt-driven commands not yet implemented.\n"); + if (counter->mite_chan == NULL) { + rt_printk + ("ni_tio: commands only supported with DMA. Interrupt-driven commands not yet implemented.\n"); retval = -EIO; - }else - { + } else { retval = ni_tio_cmd_setup(counter, async); - if(retval == 0) - { - if(cmd->flags & CMDF_WRITE) - { + if (retval == 0) { + if (cmd->flags & CMDF_WRITE) { retval = ni_tio_output_cmd(counter, async); - }else - { + } else { retval = ni_tio_input_cmd(counter, async); } } @@ -2538,9 +2597,9 @@ int ni_tio_cmd(struct ni_gpct *counter, comedi_async *async) return retval; } -int ni_tio_cmdtest(struct ni_gpct *counter, comedi_cmd *cmd) +int ni_tio_cmdtest(struct ni_gpct *counter, comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; int sources; @@ -2548,95 +2607,97 @@ int ni_tio_cmdtest(struct ni_gpct *counter, comedi_cmd *cmd) tmp = cmd->start_src; sources = TRIG_NOW | TRIG_INT | TRIG_OTHER; - if(ni_tio_counting_mode_registers_present(counter->counter_dev)) + if (ni_tio_counting_mode_registers_present(counter->counter_dev)) sources |= TRIG_EXT; cmd->start_src &= sources; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_EXT | TRIG_OTHER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; sources = TRIG_NOW | TRIG_EXT | TRIG_OTHER; cmd->convert_src &= sources; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; cmd->stop_src &= TRIG_NONE; - if(!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; - /* step 2: make sure trigger sources are unique...*/ + /* step 2: make sure trigger sources are unique... */ - if(cmd->start_src != TRIG_NOW && + if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_INT && - cmd->start_src != TRIG_EXT && - cmd->start_src != TRIG_OTHER) err++; - if(cmd->scan_begin_src != TRIG_FOLLOW && - cmd->scan_begin_src != TRIG_EXT && - cmd->scan_begin_src != TRIG_OTHER) err++; - if(cmd->convert_src != TRIG_OTHER && - cmd->convert_src != TRIG_EXT && - cmd->convert_src != TRIG_NOW) err++; - if(cmd->stop_src != TRIG_NONE) err++; + cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_OTHER) + err++; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_OTHER) + err++; + if (cmd->convert_src != TRIG_OTHER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_NONE) + err++; /* ... and mutually compatible */ - if(cmd->convert_src != TRIG_NOW && - cmd->scan_begin_src != TRIG_FOLLOW) err++; + if (cmd->convert_src != TRIG_NOW && cmd->scan_begin_src != TRIG_FOLLOW) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_src != TRIG_EXT) - { - if(cmd->start_arg != 0) - { + if (cmd->start_src != TRIG_EXT) { + if (cmd->start_arg != 0) { cmd->start_arg = 0; err++; } } - if(cmd->scan_begin_src != TRIG_EXT) - { - if(cmd->scan_begin_arg) - { + if (cmd->scan_begin_src != TRIG_EXT) { + if (cmd->scan_begin_arg) { cmd->scan_begin_arg = 0; err++; } } - if(cmd->convert_src != TRIG_EXT) - { - if(cmd->convert_arg) - { + if (cmd->convert_src != TRIG_EXT) { + if (cmd->convert_arg) { cmd->convert_arg = 0; err++; } } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src == TRIG_NONE) - { - if(cmd->stop_arg != 0) - { + if (cmd->stop_src == TRIG_NONE) { + if (cmd->stop_arg != 0) { cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(err)return 4; + if (err) + return 4; return 0; } @@ -2647,28 +2708,27 @@ int ni_tio_cancel(struct ni_gpct *counter) ni_tio_arm(counter, 0, 0); comedi_spin_lock_irqsave(&counter->lock, flags); - if(counter->mite_chan) - { + if (counter->mite_chan) { mite_dma_disarm(counter->mite_chan); } comedi_spin_unlock_irqrestore(&counter->lock, flags); ni_tio_configure_dma(counter, 0, 0); - ni_tio_set_bits(counter, NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), + ni_tio_set_bits(counter, + NITIO_Gi_Interrupt_Enable_Reg(counter->counter_index), Gi_Gate_Interrupt_Enable_Bit(counter->counter_index), 0x0); return 0; } /* During buffered input counter operation for e-series, the gate interrupt is acked - automatically by the dma controller, due to the Gi_Read/Write_Acknowledges_IRQ bits - in the input select register. */ + automatically by the dma controller, due to the Gi_Read/Write_Acknowledges_IRQ bits + in the input select register. */ static int should_ack_gate(struct ni_gpct *counter) { unsigned long flags; int retval = 0; - switch(counter->counter_dev->variant) - { + switch (counter->counter_dev->variant) { case ni_gpct_variant_m_series: case ni_gpct_variant_660x: // not sure if 660x really supports gate interrupts (the bits are not listed in register-level manual) return 1; @@ -2676,10 +2736,9 @@ static int should_ack_gate(struct ni_gpct *counter) case ni_gpct_variant_e_series: comedi_spin_lock_irqsave(&counter->lock, flags); { - if(counter->mite_chan == NULL || + if (counter->mite_chan == NULL || counter->mite_chan->dir != COMEDI_INPUT || - (mite_done(counter->mite_chan))) - { + (mite_done(counter->mite_chan))) { retval = 1; } } @@ -2689,61 +2748,71 @@ static int should_ack_gate(struct ni_gpct *counter) return retval; } -void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error, int *tc_error, - int *perm_stale_data, int *stale_data) +void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error, + int *tc_error, int *perm_stale_data, int *stale_data) { - const unsigned short gxx_status = read_register(counter, NITIO_Gxx_Status_Reg(counter->counter_index)); - const unsigned short gi_status = read_register(counter, NITIO_Gi_Status_Reg(counter->counter_index)); + const unsigned short gxx_status = read_register(counter, + NITIO_Gxx_Status_Reg(counter->counter_index)); + const unsigned short gi_status = read_register(counter, + NITIO_Gi_Status_Reg(counter->counter_index)); unsigned ack = 0; - if(gate_error) *gate_error = 0; - if(tc_error) *tc_error = 0; - if(perm_stale_data) *perm_stale_data = 0; - if(stale_data) *stale_data = 0; + if (gate_error) + *gate_error = 0; + if (tc_error) + *tc_error = 0; + if (perm_stale_data) + *perm_stale_data = 0; + if (stale_data) + *stale_data = 0; - if(gxx_status & Gi_Gate_Error_Bit(counter->counter_index)) - { + if (gxx_status & Gi_Gate_Error_Bit(counter->counter_index)) { ack |= Gi_Gate_Error_Confirm_Bit(counter->counter_index); - if(gate_error) - { + if (gate_error) { /*660x don't support automatic acknowledgement of gate interrupt via dma read/write - and report bogus gate errors */ - if(counter->counter_dev->variant != ni_gpct_variant_660x) - { + and report bogus gate errors */ + if (counter->counter_dev->variant != + ni_gpct_variant_660x) { *gate_error = 1; } } } - if(gxx_status & Gi_TC_Error_Bit(counter->counter_index)) - { + if (gxx_status & Gi_TC_Error_Bit(counter->counter_index)) { ack |= Gi_TC_Error_Confirm_Bit(counter->counter_index); - if(tc_error) *tc_error = 1; + if (tc_error) + *tc_error = 1; } - if(gi_status & Gi_TC_Bit) - { + if (gi_status & Gi_TC_Bit) { ack |= Gi_TC_Interrupt_Ack_Bit; } - if(gi_status & Gi_Gate_Interrupt_Bit) - { - if(should_ack_gate(counter)) + if (gi_status & Gi_Gate_Interrupt_Bit) { + if (should_ack_gate(counter)) ack |= Gi_Gate_Interrupt_Ack_Bit; } - if(ack) write_register(counter, ack, NITIO_Gi_Interrupt_Acknowledge_Reg(counter->counter_index)); - if(ni_tio_get_soft_copy(counter, NITIO_Gi_Mode_Reg(counter->counter_index)) & Gi_Loading_On_Gate_Bit) - { - if(gxx_status & Gi_Stale_Data_Bit(counter->counter_index)) - { - if(stale_data) *stale_data = 1; + if (ack) + write_register(counter, ack, + NITIO_Gi_Interrupt_Acknowledge_Reg(counter-> + counter_index)); + if (ni_tio_get_soft_copy(counter, + NITIO_Gi_Mode_Reg(counter-> + counter_index)) & Gi_Loading_On_Gate_Bit) { + if (gxx_status & Gi_Stale_Data_Bit(counter->counter_index)) { + if (stale_data) + *stale_data = 1; } - if(read_register(counter, NITIO_Gxx_Joint_Status2_Reg(counter->counter_index)) & Gi_Permanent_Stale_Bit(counter->counter_index)) - { - rt_printk("%s: Gi_Permanent_Stale_Data detected.\n", __FUNCTION__); - if(perm_stale_data) *perm_stale_data = 1; + if (read_register(counter, + NITIO_Gxx_Joint_Status2_Reg(counter-> + counter_index)) & + Gi_Permanent_Stale_Bit(counter->counter_index)) { + rt_printk("%s: Gi_Permanent_Stale_Data detected.\n", + __FUNCTION__); + if (perm_stale_data) + *perm_stale_data = 1; } } } -void ni_tio_handle_interrupt(struct ni_gpct *counter, comedi_subdevice *s) +void ni_tio_handle_interrupt(struct ni_gpct *counter, comedi_subdevice * s) { unsigned gpct_mite_status; unsigned long flags; @@ -2751,23 +2820,21 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter, comedi_subdevice *s) int tc_error; int perm_stale_data; - ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error, &perm_stale_data, NULL); - if(gate_error) - { + ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error, + &perm_stale_data, NULL); + if (gate_error) { rt_printk("%s: Gi_Gate_Error detected.\n", __FUNCTION__); s->async->events |= COMEDI_CB_OVERFLOW; } - if(perm_stale_data) - { + if (perm_stale_data) { s->async->events |= COMEDI_CB_ERROR; } - switch(counter->counter_dev->variant) - { + switch (counter->counter_dev->variant) { case ni_gpct_variant_m_series: case ni_gpct_variant_660x: - if(read_register(counter, NITIO_Gi_DMA_Status_Reg(counter->counter_index)) & - Gi_DRQ_Error_Bit) - { + if (read_register(counter, + NITIO_Gi_DMA_Status_Reg(counter-> + counter_index)) & Gi_DRQ_Error_Bit) { rt_printk("%s: Gi_DRQ_Error detected.\n", __FUNCTION__); s->async->events |= COMEDI_CB_OVERFLOW; } @@ -2776,21 +2843,22 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter, comedi_subdevice *s) break; } comedi_spin_lock_irqsave(&counter->lock, flags); - if(counter->mite_chan == NULL) - { + if (counter->mite_chan == NULL) { comedi_spin_unlock_irqrestore(&counter->lock, flags); return; } gpct_mite_status = mite_get_status(counter->mite_chan); - if(gpct_mite_status & CHSR_LINKC) - { - writel(CHOR_CLRLC, counter->mite_chan->mite->mite_io_addr + MITE_CHOR(counter->mite_chan->channel)); + if (gpct_mite_status & CHSR_LINKC) { + writel(CHOR_CLRLC, + counter->mite_chan->mite->mite_io_addr + + MITE_CHOR(counter->mite_chan->channel)); } mite_sync_input_dma(counter->mite_chan, s->async); comedi_spin_unlock_irqrestore(&counter->lock, flags); } -void ni_tio_set_mite_channel(struct ni_gpct *counter, struct mite_channel *mite_chan) +void ni_tio_set_mite_channel(struct ni_gpct *counter, + struct mite_channel *mite_chan) { unsigned long flags; diff --git a/comedi/drivers/ni_tio.h b/comedi/drivers/ni_tio.h index 6e3e3ba4..31010746 100644 --- a/comedi/drivers/ni_tio.h +++ b/comedi/drivers/ni_tio.h @@ -29,8 +29,7 @@ struct mite_struct; struct ni_gpct_device; -enum ni_gpct_register -{ +enum ni_gpct_register { NITIO_G0_Autoincrement_Reg, NITIO_G1_Autoincrement_Reg, NITIO_G2_Autoincrement_Reg, @@ -104,28 +103,27 @@ enum ni_gpct_register NITIO_Num_Registers, }; -enum ni_gpct_variant -{ +enum ni_gpct_variant { ni_gpct_variant_e_series, ni_gpct_variant_m_series, ni_gpct_variant_660x }; -struct ni_gpct -{ +struct ni_gpct { struct ni_gpct_device *counter_dev; unsigned counter_index; unsigned chip_index; - uint64_t clock_period_ps; /* clock period in picoseconds */ + uint64_t clock_period_ps; /* clock period in picoseconds */ struct mite_channel *mite_chan; spinlock_t lock; }; -struct ni_gpct_device -{ +struct ni_gpct_device { comedi_device *dev; - void (*write_register)(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg); - unsigned (*read_register)(struct ni_gpct *counter, enum ni_gpct_register reg); + void (*write_register) (struct ni_gpct * counter, unsigned bits, + enum ni_gpct_register reg); + unsigned (*read_register) (struct ni_gpct * counter, + enum ni_gpct_register reg); enum ni_gpct_variant variant; struct ni_gpct *counters; unsigned num_counters; @@ -133,33 +131,33 @@ struct ni_gpct_device spinlock_t regs_lock; }; -extern struct ni_gpct_device* ni_gpct_device_construct(comedi_device *dev, - void (*write_register)(struct ni_gpct *counter, unsigned bits, enum ni_gpct_register reg), - unsigned (*read_register)(struct ni_gpct *counter, enum ni_gpct_register reg), - enum ni_gpct_variant variant, unsigned num_counters); +extern struct ni_gpct_device *ni_gpct_device_construct(comedi_device * dev, + void (*write_register) (struct ni_gpct * counter, unsigned bits, + enum ni_gpct_register reg), + unsigned (*read_register) (struct ni_gpct * counter, + enum ni_gpct_register reg), enum ni_gpct_variant variant, + unsigned num_counters); extern void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev); extern void ni_tio_init_counter(struct ni_gpct *counter); extern int ni_tio_rinsn(struct ni_gpct *counter, - comedi_insn *insn, - lsampl_t *data); + comedi_insn * insn, lsampl_t * data); extern int ni_tio_insn_config(struct ni_gpct *counter, - comedi_insn *insn, - lsampl_t *data); + comedi_insn * insn, lsampl_t * data); extern int ni_tio_winsn(struct ni_gpct *counter, - comedi_insn *insn, - lsampl_t * data); -extern int ni_tio_cmd(struct ni_gpct *counter, comedi_async *async); -extern int ni_tio_cmdtest(struct ni_gpct *counter, comedi_cmd *cmd); + comedi_insn * insn, lsampl_t * data); +extern int ni_tio_cmd(struct ni_gpct *counter, comedi_async * async); +extern int ni_tio_cmdtest(struct ni_gpct *counter, comedi_cmd * cmd); extern int ni_tio_cancel(struct ni_gpct *counter); -extern void ni_tio_handle_interrupt(struct ni_gpct *counter, comedi_subdevice *s); -extern void ni_tio_set_mite_channel(struct ni_gpct *counter, struct mite_channel *mite_chan); -extern void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error, int *tc_error, - int *perm_stale_data, int *stale_data); - -static inline struct ni_gpct* subdev_to_counter(comedi_subdevice *s) +extern void ni_tio_handle_interrupt(struct ni_gpct *counter, + comedi_subdevice * s); +extern void ni_tio_set_mite_channel(struct ni_gpct *counter, + struct mite_channel *mite_chan); +extern void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, + int *gate_error, int *tc_error, int *perm_stale_data, int *stale_data); + +static inline struct ni_gpct *subdev_to_counter(comedi_subdevice * s) { return s->private; } #endif /* _COMEDI_NI_TIO_H */ - diff --git a/comedi/drivers/pcl711.c b/comedi/drivers/pcl711.c index 54f961e8..625c2d40 100644 --- a/comedi/drivers/pcl711.c +++ b/comedi/drivers/pcl711.c @@ -65,8 +65,6 @@ supported. #include "8253.h" - - #define PCL711_SIZE 16 #define PCL711_CTR0 0 @@ -90,37 +88,40 @@ supported. #define PCL711_DO_HI 14 static const comedi_lrange range_pcl711b_ai = { 5, { - BIP_RANGE( 5 ), - BIP_RANGE( 2.5 ), - BIP_RANGE( 1.25 ), - BIP_RANGE( 0.625 ), - BIP_RANGE( 0.3125 ) -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + BIP_RANGE(0.3125) + } +}; static const comedi_lrange range_acl8112hg_ai = { 12, { - BIP_RANGE( 5 ), - BIP_RANGE( 0.5 ), - BIP_RANGE( 0.05 ), - BIP_RANGE( 0.005 ), - UNI_RANGE( 10 ), - UNI_RANGE( 1 ), - UNI_RANGE( 0.1 ), - UNI_RANGE( 0.01 ), - BIP_RANGE( 10 ), - BIP_RANGE( 1 ), - BIP_RANGE( 0.1 ), - BIP_RANGE( 0.01 ) -}}; + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01), + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01) + } +}; static const comedi_lrange range_acl8112dg_ai = { 9, { - 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 ), - 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), + BIP_RANGE(10) + } +}; /* * flags @@ -140,30 +141,31 @@ typedef struct { int n_aichan; int n_aochan; int maxirq; - const comedi_lrange * ai_range_type; + const comedi_lrange *ai_range_type; } boardtype; -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"pcl711", 0, 0, 0, 5, 8, 1, 0, &range_bipolar5}, {"pcl711b", 1, 0, 0, 5, 8, 1, 7, &range_pcl711b_ai}, {"acl8112hg", 0, 1, 0, 12, 16, 2, 15, &range_acl8112hg_ai}, {"acl8112dg", 0, 1, 1, 9, 16, 2, 15, &range_acl8112dg_ai}, }; + #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) -static int pcl711_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl711_detach(comedi_device *dev); -static comedi_driver driver_pcl711={ - driver_name: "pcl711", - module: THIS_MODULE, - attach: pcl711_attach, - detach: pcl711_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static int pcl711_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl711_detach(comedi_device * dev); +static comedi_driver driver_pcl711 = { + driver_name:"pcl711", + module:THIS_MODULE, + attach:pcl711_attach, + detach:pcl711_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pcl711); typedef struct { @@ -217,7 +219,7 @@ static void pcl711_set_changain(comedi_device * dev, int chan) outb(CR_RANGE(chan), dev->iobase + PCL711_GAIN); - chan_register=CR_CHAN(chan); + chan_register = CR_CHAN(chan); if (this_board->is_8112) { @@ -228,9 +230,9 @@ static void pcl711_set_changain(comedi_device * dev, int chan) * but I haven't written the support for this yet. /JJ */ - if (chan_register >= 8){ + if (chan_register >= 8) { chan_register = 0x20 | (chan_register & 0x7); - }else{ + } else { chan_register |= 0x10; } } else { @@ -238,15 +240,15 @@ static void pcl711_set_changain(comedi_device * dev, int chan) } } -static int pcl711_ai_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl711_ai_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,n; - int hi,lo; + int i, n; + int hi, lo; - pcl711_set_changain(dev,insn->chanspec); + pcl711_set_changain(dev, insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* * Write the correct mode (software polling) and start polling by writing * to the trigger register @@ -254,12 +256,12 @@ static int pcl711_ai_insn(comedi_device *dev,comedi_subdevice *s, outb(1, dev->iobase + PCL711_MODE); if (this_board->is_8112) { - }else{ + } else { outb(0, dev->iobase + PCL711_SOFTTRIG); } - i=PCL711_TIMEOUT; - while(--i){ + i = PCL711_TIMEOUT; + while (--i) { hi = inb(dev->iobase + PCL711_AD_HI); if (!(hi & PCL711_DRDY)) goto ok; @@ -268,7 +270,7 @@ static int pcl711_ai_insn(comedi_device *dev,comedi_subdevice *s, rt_printk("comedi%d: pcl711: A/D timeout\n", dev->minor); return -ETIME; -ok: + ok: lo = inb(dev->iobase + PCL711_AD_LO); data[n] = ((hi & 0xf) << 8) | lo; @@ -277,118 +279,128 @@ ok: return n; } -static int pcl711_ai_cmdtest(comedi_device *dev, comedi_subdevice *s, - comedi_cmd *cmd) +static int pcl711_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { int tmp; int err = 0; /* step 1 */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2 */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3 */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_EXT){ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_src == TRIG_EXT) { + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - }else{ + } else { #define MAX_SPEED 1000 #define TIMER_BASE 100 - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } } - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + if (cmd->scan_end_arg != cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; err++; } - if(cmd->stop_src==TRIG_NONE){ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_src == TRIG_NONE) { + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } - }else{ + } else { /* ignore */ } - if(err)return 3; + if (err) + return 3; /* step 4 */ - if(cmd->scan_begin_src==TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { tmp = cmd->scan_begin_arg; i8253_cascade_ns_to_timer_2div(TIMER_BASE, - &devpriv->divisor1,&devpriv->divisor2, - &cmd->scan_begin_arg, cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg) + &devpriv->divisor1, &devpriv->divisor2, + &cmd->scan_begin_arg, cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) err++; } - if(err)return 4; + if (err) + return 4; return 0; } -static int pcl711_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int pcl711_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - int timer1,timer2; + int timer1, timer2; comedi_cmd *cmd = &s->async->cmd; - pcl711_set_changain(dev,cmd->chanlist[0]); + pcl711_set_changain(dev, cmd->chanlist[0]); - if(cmd->scan_begin_src==TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { /* * Set timers - * timer chip is an 8253, with timers 1 and 2 - * cascaded + * timer chip is an 8253, with timers 1 and 2 + * cascaded * 0x74 = Select Counter 1 | LSB/MSB | Mode=2 | Binary * Mode 2 = Rate generator * * 0xb4 = Select Counter 2 | LSB/MSB | Mode=2 | Binary */ - i8253_cascade_ns_to_timer(i8253_osc_base,&timer1,&timer2, - &cmd->scan_begin_arg,TRIG_ROUND_NEAREST); + i8253_cascade_ns_to_timer(i8253_osc_base, &timer1, &timer2, + &cmd->scan_begin_arg, TRIG_ROUND_NEAREST); outb(0x74, dev->iobase + PCL711_CTRCTL); outb(timer1 & 0xff, dev->iobase + PCL711_CTR1); @@ -404,7 +416,7 @@ static int pcl711_ai_cmd(comedi_device *dev, comedi_subdevice *s) * Set mode to IRQ transfer */ outb(devpriv->mode | 6, dev->iobase + PCL711_MODE); - }else{ + } else { /* external trigger */ outb(devpriv->mode | 3, dev->iobase + PCL711_MODE); } @@ -415,15 +427,17 @@ static int pcl711_ai_cmd(comedi_device *dev, comedi_subdevice *s) /* analog output */ -static int pcl711_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl711_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ - outb((data[n] & 0xff), dev->iobase + (chan ? PCL711_DA1_LO : PCL711_DA0_LO)); - outb((data[n] >> 8), dev->iobase + (chan ? PCL711_DA1_HI : PCL711_DA0_HI)); + for (n = 0; n < insn->n; n++) { + outb((data[n] & 0xff), + dev->iobase + (chan ? PCL711_DA1_LO : PCL711_DA0_LO)); + outb((data[n] >> 8), + dev->iobase + (chan ? PCL711_DA1_HI : PCL711_DA0_HI)); devpriv->ao_readback[chan] = data[n]; } @@ -431,13 +445,13 @@ static int pcl711_ao_insn(comedi_device *dev,comedi_subdevice *s, return n; } -static int pcl711_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl711_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { data[n] = devpriv->ao_readback[chan]; } @@ -447,32 +461,34 @@ static int pcl711_ao_insn_read(comedi_device *dev,comedi_subdevice *s, /* Digital port read - Untested on 8112 */ static int pcl711_di_insn_bits(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn,lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + PCL711_DI_LO) | - (inb(dev->iobase + PCL711_DI_HI) << 8); + (inb(dev->iobase + PCL711_DI_HI) << 8); return 2; } /* Digital port write - Untested on 8112 */ static int pcl711_do_insn_bits(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn,lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; } - if(data[0]&0x00ff) + if (data[0] & 0x00ff) outb(s->state & 0xff, dev->iobase + PCL711_DO_LO); - if(data[0]&0xff00) + if (data[0] & 0xff00) outb((s->state >> 8), dev->iobase + PCL711_DO_HI); - data[1]=s->state; + data[1] = s->state; return 2; } @@ -530,9 +546,9 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) } dev->irq = irq; - if((ret=alloc_subdevices(dev, 4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(pcl711_private)))<0) + if ((ret = alloc_private(dev, sizeof(pcl711_private))) < 0) return ret; s = dev->subdevices + 0; @@ -544,7 +560,7 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) s->len_chanlist = 1; s->range_table = this_board->ai_range_type; s->insn_read = pcl711_ai_insn; - if(irq){ + if (irq) { dev->read_subdev = s; s->subdev_flags |= SDF_CMD_READ; s->do_cmdtest = pcl711_ai_cmdtest; @@ -580,15 +596,15 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = 1; s->len_chanlist = 16; s->range_table = &range_digital; - s->state=0; + s->state = 0; s->insn_bits = pcl711_do_insn_bits; /* this is the "base value" for the mode register, which is used for the irq on the PCL711 */ - if(this_board->is_pcl711b){ - devpriv->mode=(dev->irq<<4); + if (this_board->is_pcl711b) { + devpriv->mode = (dev->irq << 4); } /* clear DAC */ @@ -601,4 +617,3 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) return 0; } - diff --git a/comedi/drivers/pcl724.c b/comedi/drivers/pcl724.c index ee15d76a..1e98ac19 100644 --- a/comedi/drivers/pcl724.c +++ b/comedi/drivers/pcl724.c @@ -54,110 +54,116 @@ See the source for configuration details. #define SIZE_8255 4 -// #define PCL724_IRQ 1 /* no IRQ support now */ +// #define PCL724_IRQ 1 /* no IRQ support now */ -static int pcl724_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl724_detach(comedi_device *dev); +static int pcl724_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl724_detach(comedi_device * dev); typedef struct { - const char *name; // board name - int dio; // num of DIO - int numofports; // num of 8255 subdevices - unsigned int IRQbits; // allowed interrupts - unsigned int io_range; // len of IO space - char can_have96; - char is_pet48; + const char *name; // board name + int dio; // num of DIO + int numofports; // num of 8255 subdevices + unsigned int IRQbits; // allowed interrupts + unsigned int io_range; // len of IO space + char can_have96; + char is_pet48; } boardtype; -static const boardtype boardtypes[] = -{ - {"pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, }, - {"pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0, }, - {"pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0, }, - {"acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0, }, - {"acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, }, - {"pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1, }, +static const boardtype boardtypes[] = { + {"pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0,}, + {"pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0,}, + {"pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0,}, + {"acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0,}, + {"acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0,}, + {"pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1,}, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) -static comedi_driver driver_pcl724={ - driver_name: "pcl724", - module: THIS_MODULE, - attach: pcl724_attach, - detach: pcl724_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static comedi_driver driver_pcl724 = { + driver_name:"pcl724", + module:THIS_MODULE, + attach:pcl724_attach, + detach:pcl724_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; -COMEDI_INITCLEANUP(driver_pcl724); +COMEDI_INITCLEANUP(driver_pcl724); -static int subdev_8255_cb(int dir,int port,int data,unsigned long arg) +static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) { - unsigned long iobase=arg; + unsigned long iobase = arg; - if(dir){ - outb(data,iobase+port); + if (dir) { + outb(data, iobase + port); return 0; - }else{ - return inb(iobase+port); + } else { + return inb(iobase + port); } } -static int subdev_8255mapped_cb(int dir,int port,int data,unsigned long iobase) +static int subdev_8255mapped_cb(int dir, int port, int data, + unsigned long iobase) { - int movport=SIZE_8255*(iobase>>12); + int movport = SIZE_8255 * (iobase >> 12); - iobase&=0x0fff; + iobase &= 0x0fff; - if(dir){ - outb(port+movport,iobase); - outb(data,iobase+1); + if (dir) { + outb(port + movport, iobase); + outb(data, iobase + 1); return 0; - }else{ - outb(port+movport,iobase); - return inb(iobase+1); + } else { + outb(port + movport, iobase); + return inb(iobase + 1); } } -static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) +static int pcl724_attach(comedi_device * dev, comedi_devconfig * it) { - unsigned long iobase; + unsigned long iobase; unsigned int iorange; - int ret,i,n_subdevices; + int ret, i, n_subdevices; #ifdef PCL724_IRQ unsigned int irq; #endif - iobase=it->options[0]; - iorange=this_board->io_range; - if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) - iorange=PCL722_96_SIZE; // PCL-724 in 96 DIO configuration - printk("comedi%d: pcl724: board=%s, 0x%03lx ",dev->minor, - this_board->name,iobase); - if(!request_region(iobase, iorange, "pcl724")){ + iobase = it->options[0]; + iorange = this_board->io_range; + if ((this_board->can_have96) && ((it->options[1] == 1) + || (it->options[1] == 96))) + iorange = PCL722_96_SIZE; // PCL-724 in 96 DIO configuration + printk("comedi%d: pcl724: board=%s, 0x%03lx ", dev->minor, + this_board->name, iobase); + if (!request_region(iobase, iorange, "pcl724")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; dev->board_name = this_board->name; #ifdef PCL724_IRQ - irq=0; - if (this_board->IRQbits!=0) { /* board support IRQ */ - irq=it->options[1]; - if (irq) {/* we want to use IRQ */ - if (((1<IRQbits)==0) { - rt_printk(", IRQ %u is out of allowed range, DISABLING IT",irq); - irq=0; /* Bad IRQ */ + irq = 0; + if (this_board->IRQbits != 0) { /* board support IRQ */ + irq = it->options[1]; + if (irq) { /* we want to use IRQ */ + if (((1 << irq) & this_board->IRQbits) == 0) { + rt_printk + (", IRQ %u is out of allowed range, DISABLING IT", + irq); + irq = 0; /* Bad IRQ */ } else { - if (comedi_request_irq(irq, interrupt_pcl724, 0, "pcl724", dev)) { - rt_printk(", unable to allocate IRQ %u, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ + if (comedi_request_irq(irq, interrupt_pcl724, 0, + "pcl724", dev)) { + rt_printk + (", unable to allocate IRQ %u, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ } else { rt_printk(", irq=%u", irq); } @@ -165,50 +171,50 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) } } - dev->irq = irq; + dev->irq = irq; #endif printk("\n"); - n_subdevices=this_board->numofports; - if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) - n_subdevices=4; // PCL-724 in 96 DIO configuration + n_subdevices = this_board->numofports; + if ((this_board->can_have96) && ((it->options[1] == 1) + || (it->options[1] == 96))) + n_subdevices = 4; // PCL-724 in 96 DIO configuration - if((ret=alloc_subdevices(dev, n_subdevices))<0) + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) return ret; - for(i=0;in_subdevices;i++){ + for (i = 0; i < dev->n_subdevices; i++) { if (this_board->is_pet48) { - subdev_8255_init(dev,dev->subdevices+i, - subdev_8255mapped_cb,(unsigned long)(dev->iobase+i*0x1000)); + subdev_8255_init(dev, dev->subdevices + i, + subdev_8255mapped_cb, + (unsigned long)(dev->iobase + i * 0x1000)); } else - subdev_8255_init(dev,dev->subdevices+i, - subdev_8255_cb,(unsigned long)(dev->iobase+SIZE_8255*i)); + subdev_8255_init(dev, dev->subdevices + i, + subdev_8255_cb, + (unsigned long)(dev->iobase + SIZE_8255 * i)); }; return 0; } - -static int pcl724_detach(comedi_device *dev) +static int pcl724_detach(comedi_device * dev) { int i; -// printk("comedi%d: pcl724: remove\n",dev->minor); +// printk("comedi%d: pcl724: remove\n",dev->minor); - for(i=0;in_subdevices;i++){ - subdev_8255_cleanup(dev,dev->subdevices+i); + for (i = 0; i < dev->n_subdevices; i++) { + subdev_8255_cleanup(dev, dev->subdevices + i); } #ifdef PCL724_IRQ - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } #endif - release_region(dev->iobase,this_board->io_range); + release_region(dev->iobase, this_board->io_range); return 0; } - - diff --git a/comedi/drivers/pcl725.c b/comedi/drivers/pcl725.c index 6186a64f..5df11700 100644 --- a/comedi/drivers/pcl725.c +++ b/comedi/drivers/pcl725.c @@ -15,97 +15,97 @@ Devices: [Advantech] PCL-725 (pcl725) #include - - #define PCL725_SIZE 2 #define PCL725_DO 0 #define PCL725_DI 1 -static int pcl725_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl725_detach(comedi_device *dev); -static comedi_driver driver_pcl725={ - driver_name: "pcl725", - module: THIS_MODULE, - attach: pcl725_attach, - detach: pcl725_detach, +static int pcl725_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl725_detach(comedi_device * dev); +static comedi_driver driver_pcl725 = { + driver_name:"pcl725", + module:THIS_MODULE, + attach:pcl725_attach, + detach:pcl725_detach, }; + COMEDI_INITCLEANUP(driver_pcl725); -static int pcl725_do_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl725_do_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - outb(s->state,dev->iobase+PCL725_DO); + s->state |= (data[0] & data[1]); + outb(s->state, dev->iobase + PCL725_DO); } - - data[1]=s->state; + + data[1] = s->state; return 2; } -static int pcl725_di_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl725_di_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1]=inb(dev->iobase+PCL725_DI); + data[1] = inb(dev->iobase + PCL725_DI); return 2; } -static int pcl725_attach(comedi_device *dev,comedi_devconfig *it) +static int pcl725_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; - iobase=it->options[0]; - printk("comedi%d: pcl725: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,PCL725_SIZE,"pcl725")){ + iobase = it->options[0]; + printk("comedi%d: pcl725: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, PCL725_SIZE, "pcl725")) { printk("I/O port conflict\n"); return -EIO; } - dev->board_name="pcl725"; - dev->iobase=iobase; - dev->irq=0; + dev->board_name = "pcl725"; + dev->iobase = iobase; + dev->irq = 0; - if(alloc_subdevices(dev, 2)<0) + if (alloc_subdevices(dev, 2) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* do */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=8; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcl725_do_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* di */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=8; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcl725_di_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; printk("\n"); return 0; } - -static int pcl725_detach(comedi_device *dev) +static int pcl725_detach(comedi_device * dev) { - printk("comedi%d: pcl725: remove\n",dev->minor); + printk("comedi%d: pcl725: remove\n", dev->minor); + + if (dev->iobase) + release_region(dev->iobase, PCL725_SIZE); - if(dev->iobase)release_region(dev->iobase,PCL725_SIZE); - return 0; } - diff --git a/comedi/drivers/pcl726.c b/comedi/drivers/pcl726.c index 5e38b8b3..d53967ba 100644 --- a/comedi/drivers/pcl726.c +++ b/comedi/drivers/pcl726.c @@ -71,9 +71,7 @@ Interrupts are not supported. #include - -#undef ACL6126_IRQ /* no interrupt support (yet) */ - +#undef ACL6126_IRQ /* no interrupt support (yet) */ #define PCL726_SIZE 16 #define PCL727_SIZE 32 @@ -92,193 +90,202 @@ Interrupts are not supported. #define PCL727_DI_HI 0 #define PCL727_DI_LO 1 -static const comedi_lrange range_4_20mA={ 1, {RANGE_mA(4,20)}}; -static const comedi_lrange range_0_20mA={ 1, {RANGE_mA(0,20)}}; +static const comedi_lrange range_4_20mA = { 1, {RANGE_mA(4, 20)} }; +static const comedi_lrange range_0_20mA = { 1, {RANGE_mA(0, 20)} }; -static const comedi_lrange * const rangelist_726[]={ +static const comedi_lrange *const rangelist_726[] = { &range_unipolar5, &range_unipolar10, - &range_bipolar5, &range_bipolar10, - &range_4_20mA, &range_unknown + &range_bipolar5, &range_bipolar10, + &range_4_20mA, &range_unknown }; -static const comedi_lrange * const rangelist_727[]={ +static const comedi_lrange *const rangelist_727[] = { &range_unipolar5, &range_unipolar10, &range_bipolar5, &range_4_20mA }; -static const comedi_lrange * const rangelist_728[]={ +static const comedi_lrange *const rangelist_728[] = { &range_unipolar5, &range_unipolar10, - &range_bipolar5, &range_bipolar10, - &range_4_20mA, &range_0_20mA + &range_bipolar5, &range_bipolar10, + &range_4_20mA, &range_0_20mA }; -static int pcl726_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl726_detach(comedi_device *dev); +static int pcl726_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl726_detach(comedi_device * dev); typedef struct { - const char *name; // driver name - int n_aochan; // num of D/A chans - int num_of_ranges; // num of ranges - unsigned int IRQbits; // allowed interrupts - unsigned int io_range; // len of IO space - char have_dio; // 1=card have DI/DO ports - int di_hi; // ports for DI/DO operations - int di_lo; - int do_hi; - int do_lo; - const comedi_lrange * const *range_type_list;// list of supported ranges + const char *name; // driver name + int n_aochan; // num of D/A chans + int num_of_ranges; // num of ranges + unsigned int IRQbits; // allowed interrupts + unsigned int io_range; // len of IO space + char have_dio; // 1=card have DI/DO ports + int di_hi; // ports for DI/DO operations + int di_lo; + int do_hi; + int do_lo; + const comedi_lrange *const *range_type_list; // list of supported ranges } boardtype; -static const boardtype boardtypes[] = -{ - {"pcl726", 6, 6, 0x0000, PCL726_SIZE, 1, - PCL726_DI_HI, PCL726_DI_LO, PCL726_DO_HI, PCL726_DO_LO, - &rangelist_726[0], }, - {"pcl727", 12, 4, 0x0000, PCL727_SIZE, 1, - PCL727_DI_HI, PCL727_DI_LO, PCL727_DO_HI, PCL727_DO_LO, - &rangelist_727[0], }, - {"pcl728", 2, 6, 0x0000, PCL728_SIZE, 0, - 0, 0, 0, 0, - &rangelist_728[0], }, - {"acl6126", 6, 5, 0x96e8, PCL726_SIZE, 1, - PCL726_DI_HI, PCL726_DI_LO, PCL726_DO_HI, PCL726_DO_LO, - &rangelist_726[0], }, - {"acl6128", 2, 6, 0x0000, PCL728_SIZE, 0, - 0, 0, 0, 0, - &rangelist_728[0], }, +static const boardtype boardtypes[] = { + {"pcl726", 6, 6, 0x0000, PCL726_SIZE, 1, + PCL726_DI_HI, PCL726_DI_LO, PCL726_DO_HI, PCL726_DO_LO, + &rangelist_726[0],}, + {"pcl727", 12, 4, 0x0000, PCL727_SIZE, 1, + PCL727_DI_HI, PCL727_DI_LO, PCL727_DO_HI, PCL727_DO_LO, + &rangelist_727[0],}, + {"pcl728", 2, 6, 0x0000, PCL728_SIZE, 0, + 0, 0, 0, 0, + &rangelist_728[0],}, + {"acl6126", 6, 5, 0x96e8, PCL726_SIZE, 1, + PCL726_DI_HI, PCL726_DI_LO, PCL726_DO_HI, PCL726_DO_LO, + &rangelist_726[0],}, + {"acl6128", 2, 6, 0x0000, PCL728_SIZE, 0, + 0, 0, 0, 0, + &rangelist_728[0],}, }; + #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) -static comedi_driver driver_pcl726={ - driver_name: "pcl726", - module: THIS_MODULE, - attach: pcl726_attach, - detach: pcl726_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static comedi_driver driver_pcl726 = { + driver_name:"pcl726", + module:THIS_MODULE, + attach:pcl726_attach, + detach:pcl726_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pcl726); -typedef struct{ +typedef struct { int bipolar[12]; const comedi_lrange *rangelist[12]; lsampl_t ao_readback[12]; -}pcl726_private; +} pcl726_private; #define devpriv ((pcl726_private *)dev->private) - -static int pcl726_ao_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl726_ao_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int hi,lo; + int hi, lo; int n; - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ - lo=data[n]&0xff; - hi=(data[n]>>8)&0xf; - if(devpriv->bipolar[chan])hi^=0x8; + for (n = 0; n < insn->n; n++) { + lo = data[n] & 0xff; + hi = (data[n] >> 8) & 0xf; + if (devpriv->bipolar[chan]) + hi ^= 0x8; /* * the programming info did not say which order * to write bytes. switch the order of the next * two lines if you get glitches. */ - outb(hi,dev->iobase+PCL726_DAC0_HI + 2*chan); - outb(lo,dev->iobase+PCL726_DAC0_LO + 2*chan); - devpriv->ao_readback[chan]=data[n]; + outb(hi, dev->iobase + PCL726_DAC0_HI + 2 * chan); + outb(lo, dev->iobase + PCL726_DAC0_LO + 2 * chan); + devpriv->ao_readback[chan] = data[n]; } return n; } -static int pcl726_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl726_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); int n; - for(n=0;nn;n++){ - data[n]=devpriv->ao_readback[chan]; + for (n = 0; n < insn->n; n++) { + data[n] = devpriv->ao_readback[chan]; } return n; } -static int pcl726_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl726_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1]=inb(dev->iobase+this_board->di_lo)| - (inb(dev->iobase+this_board->di_hi)<<8); + data[1] = inb(dev->iobase + this_board->di_lo) | + (inb(dev->iobase + this_board->di_hi) << 8); return 2; } -static int pcl726_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl726_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; } - if(data[1]&0x00ff) - outb(s->state&0xff,dev->iobase+this_board->do_lo); - if(data[1]&0xff00) - outb((s->state>>8),dev->iobase+this_board->do_hi); + if (data[1] & 0x00ff) + outb(s->state & 0xff, dev->iobase + this_board->do_lo); + if (data[1] & 0xff00) + outb((s->state >> 8), dev->iobase + this_board->do_hi); data[1] = s->state; return 2; } -static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) +static int pcl726_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - unsigned long iobase; + unsigned long iobase; unsigned int iorange; - int ret,i; + int ret, i; #ifdef ACL6126_IRQ unsigned int irq; #endif - iobase=it->options[0]; - iorange=this_board->io_range; - printk("comedi%d: pcl726: board=%s, 0x%03lx ",dev->minor,this_board->name,iobase); - if(!request_region(iobase, iorange, "pcl726")){ + iobase = it->options[0]; + iorange = this_board->io_range; + printk("comedi%d: pcl726: board=%s, 0x%03lx ", dev->minor, + this_board->name, iobase); + if (!request_region(iobase, iorange, "pcl726")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; dev->board_name = this_board->name; - if((ret=alloc_private(dev,sizeof(pcl726_private)))<0) + if ((ret = alloc_private(dev, sizeof(pcl726_private))) < 0) return -ENOMEM; - for (i=0; i<12; i++) { - devpriv->bipolar[i]=0; - devpriv->rangelist[i]=&range_unknown; + for (i = 0; i < 12; i++) { + devpriv->bipolar[i] = 0; + devpriv->rangelist[i] = &range_unknown; } #ifdef ACL6126_IRQ - irq=0; - if (boardtypes[board].IRQbits!=0) { /* board support IRQ */ - irq=it->options[1]; - devpriv->first_chan=2; - if (irq) {/* we want to use IRQ */ - if (((1<options[1]; + devpriv->first_chan = 2; + if (irq) { /* we want to use IRQ */ + if (((1 << irq) & boardtypes[board].IRQbits) == 0) { + rt_printk + (", IRQ %d is out of allowed range, DISABLING IT", + irq); + irq = 0; /* Bad IRQ */ } else { - if (comedi_request_irq(irq, interrupt_pcl818, 0, "pcl726", dev)) { - rt_printk(", unable to allocate IRQ %d, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ + if (comedi_request_irq(irq, interrupt_pcl818, 0, + "pcl726", dev)) { + rt_printk + (", unable to allocate IRQ %d, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ } else { rt_printk(", irq=%d", irq); } @@ -286,84 +293,81 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) } } - dev->irq = irq; + dev->irq = irq; #endif printk("\n"); - if((ret=alloc_subdevices(dev, 3))<0) + if ((ret = alloc_subdevices(dev, 3)) < 0) return ret; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* ao */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE|SDF_GROUND; - s->n_chan=this_board->n_aochan; - s->maxdata=0xfff; - s->len_chanlist=1; - s->insn_write=pcl726_ao_insn; - s->insn_read=pcl726_ao_insn_read; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = this_board->n_aochan; + s->maxdata = 0xfff; + s->len_chanlist = 1; + s->insn_write = pcl726_ao_insn; + s->insn_read = pcl726_ao_insn_read; s->range_table_list = devpriv->rangelist; - for (i=0; in_aochan; i++) { + for (i = 0; i < this_board->n_aochan; i++) { int j; - j = it->options[2+1]; - if ((j<0)||(j>=this_board->num_of_ranges)) { - printk("Invalid range for channel %d! Must be 0<=%d<%d\n", - i,j,this_board->num_of_ranges-1); - j=0; + j = it->options[2 + 1]; + if ((j < 0) || (j >= this_board->num_of_ranges)) { + printk("Invalid range for channel %d! Must be 0<=%d<%d\n", i, j, this_board->num_of_ranges - 1); + j = 0; } - devpriv->rangelist[i]=this_board->range_type_list[j]; - if (devpriv->rangelist[i]->range[0].min==-devpriv->rangelist[i]->range[0].max) - devpriv->bipolar[i]=1; /* bipolar range */ + devpriv->rangelist[i] = this_board->range_type_list[j]; + if (devpriv->rangelist[i]->range[0].min == + -devpriv->rangelist[i]->range[0].max) + devpriv->bipolar[i] = 1; /* bipolar range */ } - s=dev->subdevices+1; + s = dev->subdevices + 1; /* di */ - if (!this_board->have_dio){ + if (!this_board->have_dio) { s->type = COMEDI_SUBD_UNUSED; - }else{ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; - s->n_chan=16; - s->maxdata=1; - s->len_chanlist=1; - s->insn_bits=pcl726_di_insn_bits; - s->range_table=&range_digital; + } else { + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 16; + s->maxdata = 1; + s->len_chanlist = 1; + s->insn_bits = pcl726_di_insn_bits; + s->range_table = &range_digital; } - s=dev->subdevices+2; + s = dev->subdevices + 2; /* do */ - if (!this_board->have_dio){ + if (!this_board->have_dio) { s->type = COMEDI_SUBD_UNUSED; - }else{ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE|SDF_GROUND; - s->n_chan=16; - s->maxdata=1; - s->len_chanlist=1; - s->insn_bits=pcl726_do_insn_bits; - s->range_table=&range_digital; + } else { + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = 16; + s->maxdata = 1; + s->len_chanlist = 1; + s->insn_bits = pcl726_do_insn_bits; + s->range_table = &range_digital; } return 0; } - -static int pcl726_detach(comedi_device *dev) +static int pcl726_detach(comedi_device * dev) { -// printk("comedi%d: pcl726: remove\n",dev->minor); +// printk("comedi%d: pcl726: remove\n",dev->minor); #ifdef ACL6126_IRQ - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } #endif - if(dev->iobase) - release_region(dev->iobase,this_board->io_range); + if (dev->iobase) + release_region(dev->iobase, this_board->io_range); return 0; } - - diff --git a/comedi/drivers/pcl730.c b/comedi/drivers/pcl730.c index 7f1dab0c..e6e6b8fb 100644 --- a/comedi/drivers/pcl730.c +++ b/comedi/drivers/pcl730.c @@ -21,131 +21,133 @@ The ACL-7130 card have an 8254 timer/counter not supported by this driver. #define PCL730_SIZE 4 #define ACL7130_SIZE 8 -#define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */ -#define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */ -#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */ -#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */ +#define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */ +#define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */ +#define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */ +#define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */ -static int pcl730_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl730_detach(comedi_device *dev); +static int pcl730_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl730_detach(comedi_device * dev); typedef struct { - const char *name; // board name - unsigned int io_range; // len of I/O space + const char *name; // board name + unsigned int io_range; // len of I/O space } boardtype; -static const boardtype boardtypes[] = -{ - { "pcl730", PCL730_SIZE, }, - { "iso730", PCL730_SIZE, }, - { "acl7130", ACL7130_SIZE, }, +static const boardtype boardtypes[] = { + {"pcl730", PCL730_SIZE,}, + {"iso730", PCL730_SIZE,}, + {"acl7130", ACL7130_SIZE,}, }; + #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) static comedi_driver driver_pcl730 = { - driver_name: "pcl730", - module: THIS_MODULE, - attach: pcl730_attach, - detach: pcl730_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), + driver_name:"pcl730", + module:THIS_MODULE, + attach:pcl730_attach, + detach:pcl730_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pcl730); -static int pcl730_do_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl730_do_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if( insn->n != 2 ) - return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]) - { + if (data[0]) { s->state &= ~data[0]; s->state |= (data[0] & data[1]); } - if( data[0] & 0x00ff ) - outb(s->state & 0xff, dev->iobase+((unsigned long)s->private)); - if( data[0] & 0xff00 ) - outb((s->state >> 8), dev->iobase+((unsigned long)s->private)+1); + if (data[0] & 0x00ff) + outb(s->state & 0xff, + dev->iobase + ((unsigned long)s->private)); + if (data[0] & 0xff00) + outb((s->state >> 8), + dev->iobase + ((unsigned long)s->private) + 1); - data[1]=s->state; + data[1] = s->state; return 2; } -static int pcl730_di_insn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl730_di_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if( insn->n != 2 ) - return -EINVAL; + if (insn->n != 2) + return -EINVAL; - data[1]=inb(dev->iobase+((unsigned long)s->private)) | - (inb(dev->iobase+((unsigned long)s->private)+1)<<8); + data[1] = inb(dev->iobase + ((unsigned long)s->private)) | + (inb(dev->iobase + ((unsigned long)s->private) + 1) << 8); return 2; } -static int pcl730_attach(comedi_device *dev,comedi_devconfig *it) +static int pcl730_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; unsigned int iorange; - iobase=it->options[0]; - iorange=this_board->io_range; + iobase = it->options[0]; + iorange = this_board->io_range; printk("comedi%d: pcl730: board=%s 0x%04lx ", dev->minor, - this_board->name, iobase); - if( !request_region(iobase, iorange, "pcl730") ) { + this_board->name, iobase); + if (!request_region(iobase, iorange, "pcl730")) { printk("I/O port conflict\n"); return -EIO; } - dev->board_name=this_board->name; - dev->iobase=iobase; - dev->irq=0; + dev->board_name = this_board->name; + dev->iobase = iobase; + dev->irq = 0; - if( alloc_subdevices(dev, 4) < 0 ) + if (alloc_subdevices(dev, 4) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; /* Isolated do */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = pcl730_do_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; s->private = (void *)PCL730_IDIO_LO; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* Isolated di */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = pcl730_di_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; s->private = (void *)PCL730_IDIO_LO; - s=dev->subdevices+2; + s = dev->subdevices + 2; /* TTL do */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = pcl730_do_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; s->private = (void *)PCL730_DIO_LO; - s=dev->subdevices+3; + s = dev->subdevices + 3; /* TTL di */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=16; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 16; s->insn_bits = pcl730_di_insn; - s->range_table=&range_digital; + s->range_table = &range_digital; s->private = (void *)PCL730_DIO_LO; printk("\n"); @@ -153,12 +155,12 @@ static int pcl730_attach(comedi_device *dev,comedi_devconfig *it) return 0; } -static int pcl730_detach(comedi_device *dev) +static int pcl730_detach(comedi_device * dev) { - printk("comedi%d: pcl730: remove\n",dev->minor); + printk("comedi%d: pcl730: remove\n", dev->minor); - if(dev->iobase) - release_region(dev->iobase, this_board->io_range); + if (dev->iobase) + release_region(dev->iobase, this_board->io_range); return 0; } diff --git a/comedi/drivers/pcl812.c b/comedi/drivers/pcl812.c index d23930dc..b8bf8250 100644 --- a/comedi/drivers/pcl812.c +++ b/comedi/drivers/pcl812.c @@ -115,19 +115,17 @@ Options for ACL-8113, ISO-813: #include "8253.h" - #undef PCL812_EXTDEBUG /* if this is defined then a lot of messages is printed */ - // hardware types of the cards -#define boardPCL812PG 0 /* and ACL-8112PG */ +#define boardPCL812PG 0 /* and ACL-8112PG */ #define boardPCL813B 1 #define boardPCL812 2 #define boardPCL813 3 #define boardISO813 5 #define boardACL8113 6 -#define boardACL8112 7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */ -#define boardACL8216 8 /* and ICP DAS A-826PG */ +#define boardACL8112 7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */ +#define boardACL8216 8 /* and ICP DAS A-826PG */ #define boardA821 9 /* PGH, PGL, PGL/NDA versions */ #define PCLx1x_IORANGE 16 @@ -162,247 +160,264 @@ Options for ACL-8113, ISO-813: #define MAX_CHANLIST_LEN 256 /* length of scan list */ static const comedi_lrange range_pcl812pg_ai = { 5, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), - BIP_RANGE(0.3125), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + BIP_RANGE(0.3125), + } +}; static const comedi_lrange range_pcl812pg2_ai = { 5, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + } +}; static const comedi_lrange range812_bipolar1_25 = { 1, { - BIP_RANGE(1.25), -}}; + BIP_RANGE(1.25), + } +}; static const comedi_lrange range812_bipolar0_625 = { 1, { - BIP_RANGE(0.625), -}}; + BIP_RANGE(0.625), + } +}; static const comedi_lrange range812_bipolar0_3125 = { 1, { - BIP_RANGE(0.3125), -}}; + BIP_RANGE(0.3125), + } +}; static const comedi_lrange range_pcl813b_ai = { 4, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + } +}; static const comedi_lrange range_pcl813b2_ai = { 4, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } +}; static const comedi_lrange range_iso813_1_ai = { 5, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), - BIP_RANGE(0.3125), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + BIP_RANGE(0.3125), + } +}; static const comedi_lrange range_iso813_1_2_ai = { 5, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25), - UNI_RANGE(0.625), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + UNI_RANGE(0.625), + } +}; static const comedi_lrange range_iso813_2_ai = { 4, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + } +}; static const comedi_lrange range_iso813_2_2_ai = { 4, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } +}; static const comedi_lrange range_acl8113_1_ai = { 4, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + } +}; static const comedi_lrange range_acl8113_1_2_ai = { 4, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), - UNI_RANGE(1.25), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } +}; static const comedi_lrange range_acl8113_2_ai = { 3, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + } +}; static const comedi_lrange range_acl8113_2_2_ai = { 3, { - UNI_RANGE(10), - UNI_RANGE(5), - UNI_RANGE(2.5), -}}; + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + } +}; static const comedi_lrange range_acl8112dg_ai = { 9, { - 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), - 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), + BIP_RANGE(10), + } +}; static const comedi_lrange range_acl8112hg_ai = { 12, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01), - BIP_RANGE(10), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.01), -}}; + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01), + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01), + } +}; static const comedi_lrange range_a821pgh_ai = { 4, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), -}}; - -static int pcl812_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl812_detach(comedi_device *dev); + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + } +}; +static int pcl812_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl812_detach(comedi_device * dev); typedef struct { - const char *name; // board name - int board_type; // type of this board - int n_aichan; // num of AI chans in S.E. - int n_aichan_diff; // DIFF num of chans - int n_aochan; // num of DA chans - int n_dichan; // DI and DO chans - int n_dochan; - int ai_maxdata; // AI resolution - unsigned int ai_ns_min; // max sample speed of card v ns - unsigned int i8254_osc_base; // clock base - const comedi_lrange *rangelist_ai; // rangelist for A/D - const comedi_lrange *rangelist_ao; // rangelist for D/A - unsigned int IRQbits; // allowed IRQ - unsigned char DMAbits; // allowed DMA chans - unsigned char io_range; // iorange for this board - unsigned char haveMPC508; // 1=board use MPC508A multiplexor + const char *name; // board name + int board_type; // type of this board + int n_aichan; // num of AI chans in S.E. + int n_aichan_diff; // DIFF num of chans + int n_aochan; // num of DA chans + int n_dichan; // DI and DO chans + int n_dochan; + int ai_maxdata; // AI resolution + unsigned int ai_ns_min; // max sample speed of card v ns + unsigned int i8254_osc_base; // clock base + const comedi_lrange *rangelist_ai; // rangelist for A/D + const comedi_lrange *rangelist_ao; // rangelist for D/A + unsigned int IRQbits; // allowed IRQ + unsigned char DMAbits; // allowed DMA chans + unsigned char io_range; // iorange for this board + unsigned char haveMPC508; // 1=board use MPC508A multiplexor } boardtype; -static const boardtype boardtypes[] = -{ +static const boardtype boardtypes[] = { {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff, - 33000, 500, &range_bipolar10, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 33000, 500, &range_bipolar10, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff, - 33000, 500, &range_pcl812pg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 33000, 500, &range_pcl812pg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff, - 10000, 500, &range_pcl812pg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 10000, 500, &range_pcl812pg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 10000, 500, &range_acl8112dg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, + 10000, 500, &range_acl8112dg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 10000, 500, &range_acl8112hg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, + 10000, 500, &range_acl8112hg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff, - 10000, 500, &range_pcl813b_ai, &range_unipolar5, - 0x000c, 0x00, PCLx1x_IORANGE, 0}, + 10000, 500, &range_pcl813b_ai, &range_unipolar5, + 0x000c, 0x00, PCLx1x_IORANGE, 0}, {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff, - 10000, 500, &range_pcl813b_ai, NULL, - 0x000c, 0x00, PCLx1x_IORANGE, 0}, + 10000, 500, &range_pcl813b_ai, NULL, + 0x000c, 0x00, PCLx1x_IORANGE, 0}, {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff, - 10000, 500, &range_a821pgh_ai, &range_unipolar5, - 0x000c, 0x00, PCLx1x_IORANGE, 0}, + 10000, 500, &range_a821pgh_ai, &range_unipolar5, + 0x000c, 0x00, PCLx1x_IORANGE, 0}, {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 10000, 500, &range_acl8112dg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 10000, 500, &range_acl8112dg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 10000, 500, &range_acl8112hg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 10000, 500, &range_acl8112hg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 8000, 500, &range_acl8112dg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 8000, 500, &range_acl8112dg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff, - 8000, 500, &range_acl8112hg_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 8000, 500, &range_acl8112hg_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff, - 0, 0, &range_pcl813b_ai, NULL, - 0x0000, 0x00, PCLx1x_IORANGE, 0}, + 0, 0, &range_pcl813b_ai, NULL, + 0x0000, 0x00, PCLx1x_IORANGE, 0}, {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff, - 0, 0, &range_pcl813b_ai, NULL, - 0x0000, 0x00, PCLx1x_IORANGE, 0}, + 0, 0, &range_pcl813b_ai, NULL, + 0x0000, 0x00, PCLx1x_IORANGE, 0}, {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff, - 0, 0, &range_acl8113_1_ai, NULL, - 0x0000, 0x00, PCLx1x_IORANGE, 0}, + 0, 0, &range_acl8113_1_ai, NULL, + 0x0000, 0x00, PCLx1x_IORANGE, 0}, {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff, - 0, 0, &range_iso813_1_ai, NULL, - 0x0000, 0x00, PCLx1x_IORANGE, 0}, + 0, 0, &range_iso813_1_ai, NULL, + 0x0000, 0x00, PCLx1x_IORANGE, 0}, {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff, - 10000, 500, &range_pcl813b2_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, + 10000, 500, &range_pcl813b2_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 1}, {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff, - 10000, 500, &range_pcl813b2_ai, &range_unipolar5, - 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, + 10000, 500, &range_pcl813b2_ai, &range_unipolar5, + 0xdcfc, 0x0a, PCLx1x_IORANGE, 0}, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) -static comedi_driver driver_pcl812={ - driver_name: "pcl812", - module: THIS_MODULE, - attach: pcl812_attach, - detach: pcl812_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static comedi_driver driver_pcl812 = { + driver_name:"pcl812", + module:THIS_MODULE, + attach:pcl812_attach, + detach:pcl812_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pcl812); typedef struct { - unsigned char valid; // =1 device is OK - unsigned char dma; // >0 use dma ( usedDMA channel) - unsigned char use_diff; // =1 diff inputs - unsigned char use_MPC; // 1=board uses MPC508A multiplexor - unsigned char use_ext_trg; // 1=board uses external trigger - unsigned char range_correction; // =1 we must add 1 to range number - unsigned char old_chan_reg; // lastly used chan/gain pair - unsigned char old_gain_reg; - unsigned char mode_reg_int; // there is stored INT number for some card - unsigned char ai_neverending; // =1 we do unlimited AI - unsigned char ai_eos; // 1=EOS wake up - unsigned char ai_dma; // =1 we use DMA - unsigned int ai_poll_ptr; // how many sampes transfer poll - unsigned int ai_scans; // len of scanlist - unsigned int ai_act_scan; // how many scans we finished - unsigned int ai_chanlist[MAX_CHANLIST_LEN];// our copy of channel/range list - unsigned int ai_n_chan; // how many channels is measured - unsigned int ai_flags; // flaglist - unsigned int ai_data_len; // len of data buffer - sampl_t *ai_data; // data buffer - unsigned int ai_is16b; // =1 we have 16 bit card - unsigned long dmabuf[2]; // PTR to DMA buf - unsigned int dmapages[2]; // how many pages we have allocated - unsigned int hwdmaptr[2]; // HW PTR to DMA buf - unsigned int hwdmasize[2]; // DMA buf size in bytes - unsigned int dmabytestomove[2]; // how many bytes DMA transfer - int next_dma_buf; // which buffer is next to use - unsigned int dma_runs_to_end; // how many times we must switch DMA buffers - unsigned int last_dma_run; // how many bytes to transfer on last DMA buffer - unsigned int max_812_ai_mode0_rangewait;// setling time for gain - lsampl_t ao_readback[2]; // data for AO readback + unsigned char valid; // =1 device is OK + unsigned char dma; // >0 use dma ( usedDMA channel) + unsigned char use_diff; // =1 diff inputs + unsigned char use_MPC; // 1=board uses MPC508A multiplexor + unsigned char use_ext_trg; // 1=board uses external trigger + unsigned char range_correction; // =1 we must add 1 to range number + unsigned char old_chan_reg; // lastly used chan/gain pair + unsigned char old_gain_reg; + unsigned char mode_reg_int; // there is stored INT number for some card + unsigned char ai_neverending; // =1 we do unlimited AI + unsigned char ai_eos; // 1=EOS wake up + unsigned char ai_dma; // =1 we use DMA + unsigned int ai_poll_ptr; // how many sampes transfer poll + unsigned int ai_scans; // len of scanlist + unsigned int ai_act_scan; // how many scans we finished + unsigned int ai_chanlist[MAX_CHANLIST_LEN]; // our copy of channel/range list + unsigned int ai_n_chan; // how many channels is measured + unsigned int ai_flags; // flaglist + unsigned int ai_data_len; // len of data buffer + sampl_t *ai_data; // data buffer + unsigned int ai_is16b; // =1 we have 16 bit card + unsigned long dmabuf[2]; // PTR to DMA buf + unsigned int dmapages[2]; // how many pages we have allocated + unsigned int hwdmaptr[2]; // HW PTR to DMA buf + unsigned int hwdmasize[2]; // DMA buf size in bytes + unsigned int dmabytestomove[2]; // how many bytes DMA transfer + int next_dma_buf; // which buffer is next to use + unsigned int dma_runs_to_end; // how many times we must switch DMA buffers + unsigned int last_dma_run; // how many bytes to transfer on last DMA buffer + unsigned int max_812_ai_mode0_rangewait; // setling time for gain + lsampl_t ao_readback[2]; // data for AO readback } pcl812_private; #define devpriv ((pcl812_private *)dev->private) @@ -410,22 +425,23 @@ typedef struct { /* ============================================================================== */ -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2); +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2); static void setup_range_channel(comedi_device * dev, comedi_subdevice * s, unsigned int rangechan, char wait); static int pcl812_ai_cancel(comedi_device * dev, comedi_subdevice * s); /* ============================================================================== */ -static int pcl812_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl812_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int timeout, hi; - outb(devpriv->mode_reg_int|1, dev->iobase + PCL812_MODE); /* select software trigger */ - setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge - for(n=0;nn;n++){ + outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); /* select software trigger */ + setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge + for (n = 0; n < insn->n; n++) { outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */ comedi_udelay(5); timeout = 50; /* wait max 50us, it must finish under 33us */ @@ -435,29 +451,31 @@ static int pcl812_ai_insn_read(comedi_device *dev,comedi_subdevice *s, goto conv_finish; comedi_udelay(1); } - rt_printk("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n", dev->minor, dev->board_name, dev->iobase); - outb(devpriv->mode_reg_int|0, dev->iobase + PCL812_MODE); + rt_printk + ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n", + dev->minor, dev->board_name, dev->iobase); + outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); return -ETIME; conv_finish: data[n] = ((hi & 0xf) << 8) | inb(dev->iobase + PCL812_AD_LO); } - outb(devpriv->mode_reg_int|0, dev->iobase + PCL812_MODE); + outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); return n; } /* ============================================================================== */ -static int acl8216_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int acl8216_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int timeout; outb(1, dev->iobase + PCL812_MODE); /* select software trigger */ - setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge - for(n=0;nn;n++){ + setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge + for (n = 0; n < insn->n; n++) { outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */ comedi_udelay(5); timeout = 50; /* wait max 50us, it must finish under 33us */ @@ -466,12 +484,17 @@ static int acl8216_ai_insn_read(comedi_device *dev,comedi_subdevice *s, goto conv_finish; comedi_udelay(1); } - rt_printk("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n", dev->minor, dev->board_name, dev->iobase); + rt_printk + ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n", + dev->minor, dev->board_name, dev->iobase); outb(0, dev->iobase + PCL812_MODE); return -ETIME; conv_finish: - data[n] = (inb(dev->iobase + PCL812_AD_HI) << 8) | inb(dev->iobase + PCL812_AD_LO); + data[n] = + (inb(dev->iobase + + PCL812_AD_HI) << 8) | inb(dev->iobase + + PCL812_AD_LO); } outb(0, dev->iobase + PCL812_MODE); return n; @@ -480,16 +503,18 @@ static int acl8216_ai_insn_read(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static int pcl812_ao_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl812_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); int i; - for(i=0;in;i++){ - outb((data[i] & 0xff), dev->iobase + (chan ? PCL812_DA2_LO : PCL812_DA1_LO)); - outb((data[i] >> 8) & 0x0f, dev->iobase + (chan ? PCL812_DA2_HI : PCL812_DA1_HI)); - devpriv->ao_readback[chan]=data[i]; + for (i = 0; i < insn->n; i++) { + outb((data[i] & 0xff), + dev->iobase + (chan ? PCL812_DA2_LO : PCL812_DA1_LO)); + outb((data[i] >> 8) & 0x0f, + dev->iobase + (chan ? PCL812_DA2_HI : PCL812_DA1_HI)); + devpriv->ao_readback[chan] = data[i]; } return i; @@ -498,13 +523,13 @@ static int pcl812_ao_insn_write(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static int pcl812_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl812_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan = CR_CHAN(insn->chanspec); int i; - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { data[i] = devpriv->ao_readback[chan]; } @@ -514,10 +539,11 @@ static int pcl812_ao_insn_read(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static int pcl812_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl812_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + PCL812_DI_LO); data[1] |= inb(dev->iobase + PCL812_DI_HI) << 8; @@ -528,18 +554,19 @@ static int pcl812_di_insn_bits(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static int pcl812_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl812_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; outb(s->state & 0xff, dev->iobase + PCL812_DO_LO); outb((s->state >> 8), dev->iobase + PCL812_DO_HI); } - data[1]=s->state; + data[1] = s->state; return 2; } @@ -548,21 +575,27 @@ static int pcl812_do_insn_bits(comedi_device *dev,comedi_subdevice *s, /* ============================================================================== */ -static void pcl812_cmdtest_out(int e,comedi_cmd *cmd) { - rt_printk("pcl812 e=%d startsrc=%x scansrc=%x convsrc=%x\n",e,cmd->start_src,cmd->scan_begin_src,cmd->convert_src); - rt_printk("pcl812 e=%d startarg=%d scanarg=%d convarg=%d\n",e,cmd->start_arg,cmd->scan_begin_arg,cmd->convert_arg); - rt_printk("pcl812 e=%d stopsrc=%x scanend=%x\n",e,cmd->stop_src,cmd->scan_end_src); - rt_printk("pcl812 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n",e,cmd->stop_arg,cmd->scan_end_arg,cmd->chanlist_len); +static void pcl812_cmdtest_out(int e, comedi_cmd * cmd) +{ + rt_printk("pcl812 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e, + cmd->start_src, cmd->scan_begin_src, cmd->convert_src); + rt_printk("pcl812 e=%d startarg=%d scanarg=%d convarg=%d\n", e, + cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg); + rt_printk("pcl812 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src, + cmd->scan_end_src); + rt_printk("pcl812 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", e, + cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len); } #endif /* ============================================================================== */ -static int pcl812_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int pcl812_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; - int tmp,divisor1,divisor2; + int err = 0; + int tmp, divisor1, divisor2; #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...)\n"); @@ -570,144 +603,163 @@ static int pcl812_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd * #endif /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - if (devpriv->use_ext_trg) { cmd->convert_src &= TRIG_EXT; } - else { cmd->convert_src &= TRIG_TIMER; } - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + if (devpriv->use_ext_trg) { + cmd->convert_src &= TRIG_EXT; + } else { + cmd->convert_src &= TRIG_TIMER; + } + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) { + if (err) { #ifdef PCL812_EXTDEBUG pcl812_cmdtest_out(1, cmd); - rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=1\n",err); + rt_printk + ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=1\n", + err); #endif return 1; } /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src!=TRIG_NOW) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src != TRIG_NOW) { + cmd->start_src = TRIG_NOW; err++; } - if(cmd->scan_begin_src!=TRIG_FOLLOW) { - cmd->scan_begin_src=TRIG_FOLLOW; + if (cmd->scan_begin_src != TRIG_FOLLOW) { + cmd->scan_begin_src = TRIG_FOLLOW; err++; } if (devpriv->use_ext_trg) { - if(cmd->convert_src!=TRIG_EXT) { - cmd->convert_src=TRIG_EXT; + if (cmd->convert_src != TRIG_EXT) { + cmd->convert_src = TRIG_EXT; err++; } } else { - if(cmd->convert_src!=TRIG_TIMER) { - cmd->convert_src=TRIG_TIMER; + if (cmd->convert_src != TRIG_TIMER) { + cmd->convert_src = TRIG_TIMER; err++; } } - if(cmd->scan_end_src!=TRIG_COUNT) { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT) err++; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; - if(err) { + if (err) { #ifdef PCL812_EXTDEBUG pcl812_cmdtest_out(2, cmd); - rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=2\n",err); + rt_printk + ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=2\n", + err); #endif return 2; } /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argai_ns_min){ - cmd->convert_arg=this_board->ai_ns_min; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_ns_min) { + cmd->convert_arg = this_board->ai_ns_min; err++; } - } else { /* TRIG_EXT */ - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + } else { /* TRIG_EXT */ + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } } - if(!cmd->chanlist_len){ - cmd->chanlist_len=1; + if (!cmd->chanlist_len) { + cmd->chanlist_len = 1; err++; } - if(cmd->chanlist_len>MAX_CHANLIST_LEN){ - cmd->chanlist_len=this_board->n_aichan; + if (cmd->chanlist_len > MAX_CHANLIST_LEN) { + cmd->chanlist_len = this_board->n_aichan; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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){ - cmd->stop_arg=1; + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { + cmd->stop_arg = 1; err++; } - } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err) { + if (err) { #ifdef PCL812_EXTDEBUG pcl812_cmdtest_out(3, cmd); - rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=3\n",err); + rt_printk + ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=3\n", + err); #endif return 3; } /* step 4: fix up any arguments */ - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - i8253_cascade_ns_to_timer(this_board->i8254_osc_base,&divisor1,&divisor2,&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(cmd->convert_argai_ns_min) - cmd->convert_arg=this_board->ai_ns_min; - if(tmp!=cmd->convert_arg)err++; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + if (tmp != cmd->convert_arg) + err++; } - if(err) { + if (err) { #ifdef PCL812_EXTDEBUG - rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=4\n",err); + rt_printk + ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=4\n", + err); #endif return 4; } @@ -718,108 +770,129 @@ static int pcl812_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd * /* ============================================================================== */ -static int pcl812_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int pcl812_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - unsigned int divisor1=0, divisor2=0, i, dma_flags, bytes; - comedi_cmd *cmd=&s->async->cmd; + unsigned int divisor1 = 0, divisor2 = 0, i, dma_flags, bytes; + comedi_cmd *cmd = &s->async->cmd; #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmd(...)\n"); #endif - if(cmd->start_src!=TRIG_NOW) return -EINVAL; - if(cmd->scan_begin_src!=TRIG_FOLLOW) return -EINVAL; + if (cmd->start_src != TRIG_NOW) + return -EINVAL; + if (cmd->scan_begin_src != TRIG_FOLLOW) + return -EINVAL; if (devpriv->use_ext_trg) { - if(cmd->convert_src!=TRIG_EXT) return -EINVAL; + if (cmd->convert_src != TRIG_EXT) + return -EINVAL; } else { - if(cmd->convert_src!=TRIG_TIMER) return -EINVAL; + if (cmd->convert_src != TRIG_TIMER) + return -EINVAL; } - if(cmd->scan_end_src!=TRIG_COUNT) return -EINVAL; - if(cmd->scan_end_arg!=cmd->chanlist_len) return -EINVAL; - if(cmd->chanlist_len>MAX_CHANLIST_LEN) return -EINVAL; - - if (cmd->convert_src==TRIG_TIMER) { - if(cmd->convert_argai_ns_min) cmd->convert_arg=this_board->ai_ns_min; + if (cmd->scan_end_src != TRIG_COUNT) + return -EINVAL; + if (cmd->scan_end_arg != cmd->chanlist_len) + return -EINVAL; + if (cmd->chanlist_len > MAX_CHANLIST_LEN) + return -EINVAL; + + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1, &divisor2, &cmd->convert_arg, - cmd->flags&TRIG_ROUND_MASK); + cmd->flags & TRIG_ROUND_MASK); } - start_pacer(dev, -1, 0, 0); // stop pacer + start_pacer(dev, -1, 0, 0); // stop pacer - devpriv->ai_n_chan=cmd->chanlist_len; - memcpy(devpriv->ai_chanlist,cmd->chanlist,sizeof(unsigned int)*cmd->scan_end_arg); - setup_range_channel(dev, s, devpriv->ai_chanlist[0], 1); // select first channel and range + devpriv->ai_n_chan = cmd->chanlist_len; + memcpy(devpriv->ai_chanlist, cmd->chanlist, + sizeof(unsigned int) * cmd->scan_end_arg); + setup_range_channel(dev, s, devpriv->ai_chanlist[0], 1); // select first channel and range - if (devpriv->dma) { // check if we can use DMA transfer - devpriv->ai_dma=1; - for (i=1; iai_n_chan; i++) - if (devpriv->ai_chanlist[0]!=devpriv->ai_chanlist[i]) { - devpriv->ai_dma=0; // we cann't use DMA :-( + if (devpriv->dma) { // check if we can use DMA transfer + devpriv->ai_dma = 1; + for (i = 1; i < devpriv->ai_n_chan; i++) + if (devpriv->ai_chanlist[0] != devpriv->ai_chanlist[i]) { + devpriv->ai_dma = 0; // we cann't use DMA :-( break; } - } else devpriv->ai_dma=0; - - devpriv->ai_flags=cmd->flags; - devpriv->ai_data_len=s->async->prealloc_bufsz; - devpriv->ai_data=s->async->prealloc_buf; - if (cmd->stop_src==TRIG_COUNT) { devpriv->ai_scans=cmd->stop_arg; devpriv->ai_neverending=0; } - else { devpriv->ai_scans=0; devpriv->ai_neverending=1; } + } else + devpriv->ai_dma = 0; + + devpriv->ai_flags = cmd->flags; + devpriv->ai_data_len = s->async->prealloc_bufsz; + devpriv->ai_data = s->async->prealloc_buf; + if (cmd->stop_src == TRIG_COUNT) { + devpriv->ai_scans = cmd->stop_arg; + devpriv->ai_neverending = 0; + } else { + devpriv->ai_scans = 0; + devpriv->ai_neverending = 1; + } - devpriv->ai_act_scan=0; - devpriv->ai_poll_ptr=0; - s->async->cur_chan=0; + devpriv->ai_act_scan = 0; + devpriv->ai_poll_ptr = 0; + s->async->cur_chan = 0; - if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? - devpriv->ai_eos=1; - if (devpriv->ai_n_chan==1) - devpriv->ai_dma=0; // DMA is useless for this situation + if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? + devpriv->ai_eos = 1; + if (devpriv->ai_n_chan == 1) + devpriv->ai_dma = 0; // DMA is useless for this situation } if (devpriv->ai_dma) { - if (devpriv->ai_eos) { // we use EOS, so adapt DMA buffer to one scan - devpriv->dmabytestomove[0]=devpriv->ai_n_chan*sizeof(sampl_t); - devpriv->dmabytestomove[1]=devpriv->ai_n_chan*sizeof(sampl_t); - devpriv->dma_runs_to_end=1; + if (devpriv->ai_eos) { // we use EOS, so adapt DMA buffer to one scan + devpriv->dmabytestomove[0] = + devpriv->ai_n_chan * sizeof(sampl_t); + devpriv->dmabytestomove[1] = + devpriv->ai_n_chan * sizeof(sampl_t); + devpriv->dma_runs_to_end = 1; } else { - devpriv->dmabytestomove[0]=devpriv->hwdmasize[0]; - devpriv->dmabytestomove[1]=devpriv->hwdmasize[1]; - if (devpriv->ai_data_lenhwdmasize[0]) - devpriv->dmabytestomove[0]=devpriv->ai_data_len; - if (devpriv->ai_data_lenhwdmasize[1]) - devpriv->dmabytestomove[1]=devpriv->ai_data_len; + devpriv->dmabytestomove[0] = devpriv->hwdmasize[0]; + devpriv->dmabytestomove[1] = devpriv->hwdmasize[1]; + if (devpriv->ai_data_len < devpriv->hwdmasize[0]) + devpriv->dmabytestomove[0] = + devpriv->ai_data_len; + if (devpriv->ai_data_len < devpriv->hwdmasize[1]) + devpriv->dmabytestomove[1] = + devpriv->ai_data_len; if (devpriv->ai_neverending) { - devpriv->dma_runs_to_end=1; + devpriv->dma_runs_to_end = 1; } else { - bytes=devpriv->ai_n_chan*devpriv->ai_scans*sizeof(sampl_t); // how many samples we must transfer? - devpriv->dma_runs_to_end=bytes / devpriv->dmabytestomove[0]; // how many DMA pages we must fill - devpriv->last_dma_run=bytes % devpriv->dmabytestomove[0]; //on last dma transfer must be moved - if (devpriv->dma_runs_to_end==0) - devpriv->dmabytestomove[0]=devpriv->last_dma_run; + bytes = devpriv->ai_n_chan * devpriv->ai_scans * sizeof(sampl_t); // how many samples we must transfer? + devpriv->dma_runs_to_end = bytes / devpriv->dmabytestomove[0]; // how many DMA pages we must fill + devpriv->last_dma_run = bytes % devpriv->dmabytestomove[0]; //on last dma transfer must be moved + if (devpriv->dma_runs_to_end == 0) + devpriv->dmabytestomove[0] = + devpriv->last_dma_run; devpriv->dma_runs_to_end--; } } - if (devpriv->dmabytestomove[0]>devpriv->hwdmasize[0]) { - devpriv->dmabytestomove[0]=devpriv->hwdmasize[0]; - devpriv->ai_eos=0; + if (devpriv->dmabytestomove[0] > devpriv->hwdmasize[0]) { + devpriv->dmabytestomove[0] = devpriv->hwdmasize[0]; + devpriv->ai_eos = 0; } - if (devpriv->dmabytestomove[1]>devpriv->hwdmasize[1]) { - devpriv->dmabytestomove[1]=devpriv->hwdmasize[1]; - devpriv->ai_eos=0; + if (devpriv->dmabytestomove[1] > devpriv->hwdmasize[1]) { + devpriv->dmabytestomove[1] = devpriv->hwdmasize[1]; + devpriv->ai_eos = 0; } - devpriv->next_dma_buf=0; + devpriv->next_dma_buf = 0; set_dma_mode(devpriv->dma, DMA_MODE_READ); - dma_flags=claim_dma_lock(); - clear_dma_ff(devpriv->dma); - set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); - set_dma_count(devpriv->dma, devpriv->dmabytestomove[0]); - release_dma_lock(dma_flags); - enable_dma(devpriv->dma); + dma_flags = claim_dma_lock(); + clear_dma_ff(devpriv->dma); + set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); + set_dma_count(devpriv->dma, devpriv->dmabytestomove[0]); + release_dma_lock(dma_flags); + enable_dma(devpriv->dma); #ifdef PCL812_EXTDEBUG - rt_printk("pcl812 EDBG: DMA %d PTR 0x%0x/0x%0x LEN %u/%u EOS %d\n", - devpriv->dma,devpriv->hwdmaptr[0],devpriv->hwdmaptr[1], - devpriv->dmabytestomove[0],devpriv->dmabytestomove[1], - devpriv->ai_eos); + rt_printk + ("pcl812 EDBG: DMA %d PTR 0x%0x/0x%0x LEN %u/%u EOS %d\n", + devpriv->dma, devpriv->hwdmaptr[0], + devpriv->hwdmaptr[1], devpriv->dmabytestomove[0], + devpriv->dmabytestomove[1], devpriv->ai_eos); #endif } @@ -830,16 +903,16 @@ static int pcl812_ai_cmd(comedi_device *dev,comedi_subdevice *s) } if (devpriv->ai_dma) { - outb(devpriv->mode_reg_int|2, dev->iobase + PCL812_MODE); // let's go! + outb(devpriv->mode_reg_int | 2, dev->iobase + PCL812_MODE); // let's go! } else { - outb(devpriv->mode_reg_int|6, dev->iobase + PCL812_MODE); // let's go! + outb(devpriv->mode_reg_int | 6, dev->iobase + PCL812_MODE); // let's go! } #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: END: pcl812_ai_cmd(...)\n"); #endif - return 0; + return 0; } /* @@ -847,50 +920,55 @@ static int pcl812_ai_cmd(comedi_device *dev,comedi_subdevice *s) */ static irqreturn_t interrupt_pcl812_ai_int(int irq, void *d) { - char err=1; + char err = 1; unsigned int mask, timeout; comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; s->async->events = 0; - timeout = 50; /* wait max 50us, it must finish under 33us */ + timeout = 50; /* wait max 50us, it must finish under 33us */ if (devpriv->ai_is16b) { - mask=0xffff; + mask = 0xffff; while (timeout--) { if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY)) { - err=0; break; + err = 0; + break; } comedi_udelay(1); } } else { - mask=0x0fff; + mask = 0x0fff; while (timeout--) { if (!(inb(dev->iobase + PCL812_AD_HI) & PCL812_DRDY)) { - err=0; break; + err = 0; + break; } comedi_udelay(1); } } if (err) { - rt_printk("comedi%d: pcl812: (%s at 0x%lx) A/D cmd IRQ without DRDY!\n", dev->minor, dev->board_name, dev->iobase); - pcl812_ai_cancel(dev,s); - s->async->events |= COMEDI_CB_EOA|COMEDI_CB_ERROR; + rt_printk + ("comedi%d: pcl812: (%s at 0x%lx) A/D cmd IRQ without DRDY!\n", + dev->minor, dev->board_name, dev->iobase); + pcl812_ai_cancel(dev, s); + s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - comedi_buf_put( s->async, - ((inb(dev->iobase + PCL812_AD_HI) << 8) | inb(dev->iobase + PCL812_AD_LO)) & mask); + comedi_buf_put(s->async, + ((inb(dev->iobase + PCL812_AD_HI) << 8) | inb(dev->iobase + + PCL812_AD_LO)) & mask); outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */ - if (s->async->cur_chan == 0 ) { /* one scan done */ + if (s->async->cur_chan == 0) { /* one scan done */ devpriv->ai_act_scan++; if (!(devpriv->ai_neverending)) - if (devpriv->ai_act_scan>=devpriv->ai_scans) { /* all data sampled */ - pcl812_ai_cancel(dev,s); + if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ + pcl812_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; } } @@ -902,20 +980,20 @@ static irqreturn_t interrupt_pcl812_ai_int(int irq, void *d) /* ============================================================================== */ -static void transfer_from_dma_buf(comedi_device *dev,comedi_subdevice *s, - sampl_t *ptr, unsigned int bufptr, unsigned int len) +static void transfer_from_dma_buf(comedi_device * dev, comedi_subdevice * s, + sampl_t * ptr, unsigned int bufptr, unsigned int len) { unsigned int i; s->async->events = 0; - for (i=len; i; i--) { - comedi_buf_put( s->async, ptr[bufptr++] ); // get one sample + for (i = len; i; i--) { + comedi_buf_put(s->async, ptr[bufptr++]); // get one sample - if(s->async->cur_chan == 0){ + if (s->async->cur_chan == 0) { devpriv->ai_act_scan++; if (!devpriv->ai_neverending) - if (devpriv->ai_act_scan>=devpriv->ai_scans) { /* all data sampled */ - pcl812_ai_cancel(dev,s); + if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ + pcl812_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; break; } @@ -933,34 +1011,40 @@ static irqreturn_t interrupt_pcl812_ai_dma(int irq, void *d) comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; unsigned long dma_flags; - int len,bufptr; + int len, bufptr; sampl_t *ptr; #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: BGN: interrupt_pcl812_ai_dma(...)\n"); #endif - ptr=(sampl_t *)devpriv->dmabuf[devpriv->next_dma_buf]; - len=(devpriv->dmabytestomove[devpriv->next_dma_buf] >> 1) - devpriv->ai_poll_ptr; + ptr = (sampl_t *) devpriv->dmabuf[devpriv->next_dma_buf]; + len = (devpriv->dmabytestomove[devpriv->next_dma_buf] >> 1) - + devpriv->ai_poll_ptr; - devpriv->next_dma_buf=1-devpriv->next_dma_buf; + devpriv->next_dma_buf = 1 - devpriv->next_dma_buf; disable_dma(devpriv->dma); set_dma_mode(devpriv->dma, DMA_MODE_READ); - dma_flags=claim_dma_lock(); + dma_flags = claim_dma_lock(); set_dma_addr(devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]); if (devpriv->ai_eos) { - set_dma_count(devpriv->dma, devpriv->dmabytestomove[devpriv->next_dma_buf]); + set_dma_count(devpriv->dma, + devpriv->dmabytestomove[devpriv->next_dma_buf]); } else { - if (devpriv->dma_runs_to_end) { set_dma_count(devpriv->dma, devpriv->dmabytestomove[devpriv->next_dma_buf]); } - else { set_dma_count(devpriv->dma, devpriv->last_dma_run); } + if (devpriv->dma_runs_to_end) { + set_dma_count(devpriv->dma, + devpriv->dmabytestomove[devpriv->next_dma_buf]); + } else { + set_dma_count(devpriv->dma, devpriv->last_dma_run); + } devpriv->dma_runs_to_end--; } release_dma_lock(dma_flags); enable_dma(devpriv->dma); - outb(0,dev->iobase+PCL812_CLRINT); /* clear INT request */ + outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */ - bufptr=devpriv->ai_poll_ptr; - devpriv->ai_poll_ptr=0; + bufptr = devpriv->ai_poll_ptr; + devpriv->ai_poll_ptr = 0; transfer_from_dma_buf(dev, s, ptr, bufptr, len); @@ -981,49 +1065,55 @@ static irqreturn_t interrupt_pcl812(int irq, void *d PT_REGS_ARG) comedi_error(dev, "spurious interrupt"); return IRQ_HANDLED; } - if (devpriv->ai_dma) { return interrupt_pcl812_ai_dma(irq, d); } - else { return interrupt_pcl812_ai_int(irq, d); }; + if (devpriv->ai_dma) { + return interrupt_pcl812_ai_dma(irq, d); + } else { + return interrupt_pcl812_ai_int(irq, d); + }; } /* ============================================================================== */ -static int pcl812_ai_poll(comedi_device *dev,comedi_subdevice *s) +static int pcl812_ai_poll(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - unsigned int top1,top2,i; + unsigned int top1, top2, i; - if (!devpriv->ai_dma) return 0; // poll is valid only for DMA transfer + if (!devpriv->ai_dma) + return 0; // poll is valid only for DMA transfer - comedi_spin_lock_irqsave(&dev->spinlock,flags); + comedi_spin_lock_irqsave(&dev->spinlock, flags); - for (i=0; i<10; i++) { - top1=get_dma_residue(devpriv->ai_dma); // where is now DMA - top2=get_dma_residue(devpriv->ai_dma); - if (top1==top2) break; + for (i = 0; i < 10; i++) { + top1 = get_dma_residue(devpriv->ai_dma); // where is now DMA + top2 = get_dma_residue(devpriv->ai_dma); + if (top1 == top2) + break; } - if (top1!=top2) { - comedi_spin_unlock_irqrestore(&dev->spinlock,flags); + if (top1 != top2) { + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } - top1=devpriv->dmabytestomove[1-devpriv->next_dma_buf]-top1; // where is now DMA in buffer - top1>>=1; // sample position - top2=top1-devpriv->ai_poll_ptr; - if (top2<1) { // no new samples - comedi_spin_unlock_irqrestore(&dev->spinlock,flags); + top1 = devpriv->dmabytestomove[1 - devpriv->next_dma_buf] - top1; // where is now DMA in buffer + top1 >>= 1; // sample position + top2 = top1 - devpriv->ai_poll_ptr; + if (top2 < 1) { // no new samples + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } - transfer_from_dma_buf(dev, s, (void *)devpriv->dmabuf[1-devpriv->next_dma_buf], - devpriv->ai_poll_ptr, top2); + transfer_from_dma_buf(dev, s, + (void *)devpriv->dmabuf[1 - devpriv->next_dma_buf], + devpriv->ai_poll_ptr, top2); - devpriv->ai_poll_ptr=top1; // new buffer position + devpriv->ai_poll_ptr = top1; // new buffer position - comedi_spin_unlock_irqrestore(&dev->spinlock,flags); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - return s->async->buf_write_count-s->async->buf_read_count; + return s->async->buf_write_count - s->async->buf_read_count; } /* @@ -1032,54 +1122,56 @@ static int pcl812_ai_poll(comedi_device *dev,comedi_subdevice *s) static void setup_range_channel(comedi_device * dev, comedi_subdevice * s, unsigned int rangechan, char wait) { - unsigned char chan_reg=CR_CHAN(rangechan); // normal board - unsigned char gain_reg=CR_RANGE(rangechan)+devpriv->range_correction; // gain index + unsigned char chan_reg = CR_CHAN(rangechan); // normal board + unsigned char gain_reg = CR_RANGE(rangechan) + devpriv->range_correction; // gain index - if ((chan_reg==devpriv->old_chan_reg)&&(gain_reg==devpriv->old_gain_reg)) - return; // we can return, no change + if ((chan_reg == devpriv->old_chan_reg) + && (gain_reg == devpriv->old_gain_reg)) + return; // we can return, no change - devpriv->old_chan_reg=chan_reg; - devpriv->old_gain_reg=gain_reg; + devpriv->old_chan_reg = chan_reg; + devpriv->old_gain_reg = gain_reg; if (devpriv->use_MPC) { if (devpriv->use_diff) { - chan_reg=chan_reg | 0x30; // DIFF inputs + chan_reg = chan_reg | 0x30; // DIFF inputs } else { - if (chan_reg&0x80) { - chan_reg=chan_reg | 0x20; // SE inputs 8-15 + if (chan_reg & 0x80) { + chan_reg = chan_reg | 0x20; // SE inputs 8-15 } else { - chan_reg=chan_reg | 0x10; // SE inputs 0-7 + chan_reg = chan_reg | 0x10; // SE inputs 0-7 } } } - outb(chan_reg, dev->iobase + PCL812_MUX); /* select channel */ - outb(gain_reg, dev->iobase + PCL812_GAIN); /* select gain */ + outb(chan_reg, dev->iobase + PCL812_MUX); /* select channel */ + outb(gain_reg, dev->iobase + PCL812_GAIN); /* select gain */ - if (wait) { - comedi_udelay(devpriv->max_812_ai_mode0_rangewait); // XXX this depends on selected range and can be very long for some high gain ranges! - } + if (wait) { + comedi_udelay(devpriv->max_812_ai_mode0_rangewait); // XXX this depends on selected range and can be very long for some high gain ranges! + } } - /* ============================================================================== */ -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2) +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2) { #ifdef PCL812_EXTDEBUG - rt_printk("pcl812 EDBG: BGN: start_pacer(%d,%u,%u)\n",mode,divisor1,divisor2); + rt_printk("pcl812 EDBG: BGN: start_pacer(%d,%u,%u)\n", mode, divisor1, + divisor2); #endif - outb(0xb4, dev->iobase + PCL812_CTRCTL); - outb(0x74, dev->iobase + PCL812_CTRCTL); - comedi_udelay(1); + outb(0xb4, dev->iobase + PCL812_CTRCTL); + outb(0x74, dev->iobase + PCL812_CTRCTL); + comedi_udelay(1); - if (mode==1) { + if (mode == 1) { outb(divisor2 & 0xff, dev->iobase + PCL812_CTR2); outb((divisor2 >> 8) & 0xff, dev->iobase + PCL812_CTR2); - outb(divisor1 & 0xff, dev->iobase + PCL812_CTR1); + outb(divisor1 & 0xff, dev->iobase + PCL812_CTR1); outb((divisor1 >> 8) & 0xff, dev->iobase + PCL812_CTR1); - } + } #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: END: start_pacer(...)\n"); #endif @@ -1113,10 +1205,11 @@ static int pcl812_ai_cancel(comedi_device * dev, comedi_subdevice * s) #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: BGN: pcl812_ai_cancel(...)\n"); #endif - if (devpriv->ai_dma) disable_dma(devpriv->dma); + if (devpriv->ai_dma) + disable_dma(devpriv->dma); outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */ - outb(devpriv->mode_reg_int|0, dev->iobase + PCL812_MODE); /* Stop A/D */ - start_pacer(dev,-1,0,0); // stop 8254 + outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); /* Stop A/D */ + start_pacer(dev, -1, 0, 0); // stop 8254 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */ #ifdef PCL812_EXTDEBUG rt_printk("pcl812 EDBG: END: pcl812_ai_cancel(...)\n"); @@ -1133,9 +1226,9 @@ static void pcl812_reset(comedi_device * dev) rt_printk("pcl812 EDBG: BGN: pcl812_reset(...)\n"); #endif outb(0, dev->iobase + PCL812_MUX); - outb(0+devpriv->range_correction, dev->iobase + PCL812_GAIN); - devpriv->old_chan_reg=-1; // invalidate chain/gain memory - devpriv->old_gain_reg=-1; + outb(0 + devpriv->range_correction, dev->iobase + PCL812_GAIN); + devpriv->old_chan_reg = -1; // invalidate chain/gain memory + devpriv->old_gain_reg = -1; switch (this_board->board_type) { case boardPCL812PG: @@ -1147,10 +1240,10 @@ static void pcl812_reset(comedi_device * dev) case boardA821: outb(0, dev->iobase + PCL812_DA1_LO); outb(0, dev->iobase + PCL812_DA1_HI); - start_pacer(dev,-1,0,0); // stop 8254 + start_pacer(dev, -1, 0, 0); // stop 8254 outb(0, dev->iobase + PCL812_DO_HI); outb(0, dev->iobase + PCL812_DO_LO); - outb(devpriv->mode_reg_int|0, dev->iobase + PCL812_MODE); + outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); outb(0, dev->iobase + PCL812_CLRINT); break; case boardPCL813B: @@ -1166,13 +1259,12 @@ static void pcl812_reset(comedi_device * dev) #endif } - /* ============================================================================== */ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) { - int ret,subdev; + int ret, subdev; unsigned long iobase; unsigned int irq; unsigned int dma; @@ -1205,7 +1297,8 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) printk(", IRQ %u is out of allowed range, DISABLING IT", irq); irq = 0; /* Bad IRQ */ } else { - if (comedi_request_irq(irq, interrupt_pcl812, 0, "pcl812", dev)) { + if (comedi_request_irq(irq, interrupt_pcl812, 0, + "pcl812", dev)) { printk(", unable to allocate IRQ %u, DISABLING IT", irq); irq = 0; /* Can't use IRQ */ } else { @@ -1243,8 +1336,8 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) return -EBUSY; /* no buffer :-( */ } devpriv->dmapages[0] = pages; - devpriv->hwdmaptr[0] = virt_to_bus((void *) devpriv->dmabuf[0]); - devpriv->hwdmasize[0] = PAGE_SIZE * (1<hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]); + devpriv->hwdmasize[0] = PAGE_SIZE * (1 << pages); devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages); if (!devpriv->dmabuf[1]) { printk(", unable to allocate DMA buffer, FAIL!\n"); @@ -1252,26 +1345,30 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) return -EBUSY; } devpriv->dmapages[1] = pages; - devpriv->hwdmaptr[1] = virt_to_bus((void *) devpriv->dmabuf[1]); - devpriv->hwdmasize[1] = PAGE_SIZE * (1<hwdmaptr[1] = virt_to_bus((void *)devpriv->dmabuf[1]); + devpriv->hwdmasize[1] = PAGE_SIZE * (1 << pages); } no_dma: - n_subdevices=0; - if (this_board->n_aichan > 0) n_subdevices++; - if (this_board->n_aochan > 0) n_subdevices++; - if (this_board->n_dichan > 0) n_subdevices++; - if (this_board->n_dochan > 0) n_subdevices++; + n_subdevices = 0; + if (this_board->n_aichan > 0) + n_subdevices++; + if (this_board->n_aochan > 0) + n_subdevices++; + if (this_board->n_dichan > 0) + n_subdevices++; + if (this_board->n_dochan > 0) + n_subdevices++; if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) { free_resources(dev); return ret; } - subdev=0; + subdev = 0; /* analog input */ - if (this_board->n_aichan>0) { + if (this_board->n_aichan > 0) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE; @@ -1280,7 +1377,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) if (it->options[2] == 1) { s->n_chan = this_board->n_aichan_diff; s->subdev_flags |= SDF_DIFF; - devpriv->use_diff=1; + devpriv->use_diff = 1; } else { s->n_chan = this_board->n_aichan; s->subdev_flags |= SDF_GROUND; @@ -1291,7 +1388,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) if (it->options[4] == 1) { s->n_chan = this_board->n_aichan_diff; s->subdev_flags |= SDF_DIFF; - devpriv->use_diff=1; + devpriv->use_diff = 1; } else { s->n_chan = this_board->n_aichan; s->subdev_flags |= SDF_GROUND; @@ -1305,7 +1402,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = this_board->ai_maxdata; s->len_chanlist = MAX_CHANLIST_LEN; s->range_table = this_board->rangelist_ai; - if (this_board->board_type==boardACL8216) { + if (this_board->board_type == boardACL8216) { s->insn_read = acl8216_ai_insn_read; } else { s->insn_read = pcl812_ai_insn_read; @@ -1326,14 +1423,27 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) break; case boardPCL812: switch (it->options[4]) { - case 0: s->range_table = &range_bipolar10; break; - case 1: s->range_table = &range_bipolar5; break; - case 2: s->range_table = &range_bipolar2_5; break; - case 3: s->range_table = &range812_bipolar1_25; break; - case 4: s->range_table = &range812_bipolar0_625; break; - case 5: s->range_table = &range812_bipolar0_3125; break; + case 0: + s->range_table = &range_bipolar10; + break; + case 1: + s->range_table = &range_bipolar5; + break; + case 2: + s->range_table = &range_bipolar2_5; + break; + case 3: + s->range_table = &range812_bipolar1_25; + break; + case 4: + s->range_table = &range812_bipolar0_625; + break; + case 5: + s->range_table = &range812_bipolar0_3125; + break; default: - s->range_table = &range_bipolar10; break; + s->range_table = &range_bipolar10; + break; printk(", incorrect range number %d, changing to 0 (+/-10V)", it->options[4]); break; } @@ -1345,24 +1455,46 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) break; case boardISO813: switch (it->options[1]) { - case 0: s->range_table = &range_iso813_1_ai; break; - case 1: s->range_table = &range_iso813_1_2_ai; break; - case 2: s->range_table = &range_iso813_2_ai; devpriv->range_correction=1; break; - case 3: s->range_table = &range_iso813_2_2_ai; devpriv->range_correction=1; break; + case 0: + s->range_table = &range_iso813_1_ai; + break; + case 1: + s->range_table = &range_iso813_1_2_ai; + break; + case 2: + s->range_table = &range_iso813_2_ai; + devpriv->range_correction = 1; + break; + case 3: + s->range_table = &range_iso813_2_2_ai; + devpriv->range_correction = 1; + break; default: - s->range_table = &range_iso813_1_ai; break; + s->range_table = &range_iso813_1_ai; + break; printk(", incorrect range number %d, changing to 0 ", it->options[1]); break; } break; case boardACL8113: switch (it->options[1]) { - case 0: s->range_table = &range_acl8113_1_ai; break; - case 1: s->range_table = &range_acl8113_1_2_ai; break; - case 2: s->range_table = &range_acl8113_2_ai; devpriv->range_correction=1; break; - case 3: s->range_table = &range_acl8113_2_2_ai; devpriv->range_correction=1; break; + case 0: + s->range_table = &range_acl8113_1_ai; + break; + case 1: + s->range_table = &range_acl8113_1_2_ai; + break; + case 2: + s->range_table = &range_acl8113_2_ai; + devpriv->range_correction = 1; + break; + case 3: + s->range_table = &range_acl8113_2_2_ai; + devpriv->range_correction = 1; + break; default: - s->range_table = &range_acl8113_1_ai; break; + s->range_table = &range_acl8113_1_ai; + break; printk(", incorrect range number %d, changing to 0 ", it->options[1]); break; } @@ -1372,10 +1504,10 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) } /* analog output */ - if (this_board->n_aochan>0) { + if (this_board->n_aochan > 0) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; s->n_chan = this_board->n_aochan; s->maxdata = 0xfff; s->len_chanlist = 1; @@ -1401,7 +1533,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) } /* digital input */ - if (this_board->n_dichan>0) { + if (this_board->n_dichan > 0) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; @@ -1414,7 +1546,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) } /* digital output */ - if (this_board->n_dochan>0) { + if (this_board->n_dochan > 0) { s = dev->subdevices + subdev; s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE; @@ -1428,15 +1560,16 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) switch (this_board->board_type) { case boardACL8216: - devpriv->ai_is16b=1; + devpriv->ai_is16b = 1; case boardPCL812PG: case boardPCL812: case boardACL8112: devpriv->max_812_ai_mode0_rangewait = 1; - if (it->options[3] > 0) devpriv->use_ext_trg=1; // we use external trigger + if (it->options[3] > 0) + devpriv->use_ext_trg = 1; // we use external trigger case boardA821: devpriv->max_812_ai_mode0_rangewait = 1; - devpriv->mode_reg_int=(irq<<4) & 0xf0; + devpriv->mode_reg_int = (irq << 4) & 0xf0; break; case boardPCL813B: case boardPCL813: @@ -1447,14 +1580,13 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) } printk("\n"); - devpriv->valid=1; + devpriv->valid = 1; pcl812_reset(dev); return 0; } - /* ============================================================================== */ @@ -1467,4 +1599,3 @@ static int pcl812_detach(comedi_device * dev) free_resources(dev); return 0; } - diff --git a/comedi/drivers/pcl816.c b/comedi/drivers/pcl816.c index 3fd7e232..3d1b1bd0 100644 --- a/comedi/drivers/pcl816.c +++ b/comedi/drivers/pcl816.c @@ -32,7 +32,6 @@ Configuration Options: */ - #include #include @@ -75,7 +74,6 @@ Configuration Options: // R: high byte of A/D W: A/D range control #define PCL816_AD_HI 9 - // type of interrupt handler #define INT_TYPE_AI1_INT 1 #define INT_TYPE_AI1_DMA 2 @@ -85,7 +83,6 @@ Configuration Options: #define INT_TYPE_AI1_DMA_RTC 9 #define INT_TYPE_AI3_DMA_RTC 10 - // RTC stuff... #define RTC_IRQ 8 #define RTC_IO_EXTENT 0x10 @@ -94,55 +91,54 @@ Configuration Options: #define MAGIC_DMA_WORD 0x5a5a static const comedi_lrange range_pcl816 = { 8, { - BIP_RANGE (10), - BIP_RANGE (5), - BIP_RANGE (2.5), - BIP_RANGE (1.25), - UNI_RANGE (10), - UNI_RANGE (5), - UNI_RANGE (2.5), - UNI_RANGE (1.25), - } + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + UNI_RANGE(10), + UNI_RANGE(5), + UNI_RANGE(2.5), + UNI_RANGE(1.25), + } }; typedef struct { - const char *name; // board name - int n_ranges; // len of range list - int n_aichan; // num of A/D chans in diferencial mode - unsigned int ai_ns_min; // minimal alllowed delay between samples (in ns) - int n_aochan; // num of D/A chans - int n_dichan; // num of DI chans - int n_dochan; // num of DO chans - const comedi_lrange *ai_range_type; // default A/D rangelist - const comedi_lrange *ao_range_type; // dafault D/A rangelist - unsigned int io_range; // len of IO space - unsigned int IRQbits; // allowed interrupts - unsigned int DMAbits; // allowed DMA chans - int ai_maxdata; // maxdata for A/D - int ao_maxdata; // maxdata for D/A - int ai_chanlist; // allowed len of channel list A/D - int ao_chanlist; // allowed len of channel list D/A - int i8254_osc_base; // 1/frequency of on board oscilator in ns -} -boardtype; + const char *name; // board name + int n_ranges; // len of range list + int n_aichan; // num of A/D chans in diferencial mode + unsigned int ai_ns_min; // minimal alllowed delay between samples (in ns) + int n_aochan; // num of D/A chans + int n_dichan; // num of DI chans + int n_dochan; // num of DO chans + const comedi_lrange *ai_range_type; // default A/D rangelist + const comedi_lrange *ao_range_type; // dafault D/A rangelist + unsigned int io_range; // len of IO space + unsigned int IRQbits; // allowed interrupts + unsigned int DMAbits; // allowed DMA chans + int ai_maxdata; // maxdata for A/D + int ao_maxdata; // maxdata for D/A + int ai_chanlist; // allowed len of channel list A/D + int ao_chanlist; // allowed len of channel list D/A + int i8254_osc_base; // 1/frequency of on board oscilator in ns +} boardtype; static const boardtype boardtypes[] = { - {"pcl816", 8, 16, 10000, 1, 16, 16, &range_pcl816, - &range_pcl816, PCLx1x_RANGE, - 0x00fc, // IRQ mask - 0x0a, // DMA mask - 0xffff, // 16-bit card - 0xffff, // D/A maxdata - 1024, - 1, // ao chan list - 100 }, - {"pcl814b", 8, 16, 10000, 1, 16, 16, &range_pcl816, - &range_pcl816, PCLx1x_RANGE, - 0x00fc, - 0x0a, - 0x3fff, /* 14 bit card */ - 0x3fff, - 1024, - 1, + {"pcl816", 8, 16, 10000, 1, 16, 16, &range_pcl816, + &range_pcl816, PCLx1x_RANGE, + 0x00fc, // IRQ mask + 0x0a, // DMA mask + 0xffff, // 16-bit card + 0xffff, // D/A maxdata + 1024, + 1, // ao chan list + 100}, + {"pcl814b", 8, 16, 10000, 1, 16, 16, &range_pcl816, + &range_pcl816, PCLx1x_RANGE, + 0x00fc, + 0x0a, + 0x3fff, /* 14 bit card */ + 0x3fff, + 1024, + 1, 100}, }; @@ -150,8 +146,8 @@ static const boardtype boardtypes[] = { #define devpriv ((pcl816_private *)dev->private) #define this_board ((const boardtype *)dev->board_ptr) -static int pcl816_attach (comedi_device * dev, comedi_devconfig * it); -static int pcl816_detach (comedi_device * dev); +static int pcl816_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl816_detach(comedi_device * dev); #ifdef unused static int RTC_lock = 0; /* RTC lock */ @@ -159,119 +155,117 @@ static int RTC_timer_lock = 0; /* RTC int lock */ #endif static comedi_driver driver_pcl816 = { - driver_name: "pcl816", - module: THIS_MODULE, - attach: pcl816_attach, - detach: pcl816_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), + driver_name:"pcl816", + module:THIS_MODULE, + attach:pcl816_attach, + detach:pcl816_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; -COMEDI_INITCLEANUP(driver_pcl816); +COMEDI_INITCLEANUP(driver_pcl816); -typedef struct -{ - unsigned int dma; // used DMA, 0=don't use DMA - int dma_rtc; // 1=RTC used with DMA, 0=no RTC alloc +typedef struct { + unsigned int dma; // used DMA, 0=don't use DMA + int dma_rtc; // 1=RTC used with DMA, 0=no RTC alloc #ifdef unused - unsigned long rtc_iobase; // RTC port region - unsigned int rtc_iosize; - unsigned int rtc_irq; + unsigned long rtc_iobase; // RTC port region + unsigned int rtc_iosize; + unsigned int rtc_irq; #endif - unsigned long dmabuf[2]; // pointers to begin of DMA buffers - unsigned int dmapages[2]; // len of DMA buffers in PAGE_SIZEs - unsigned int hwdmaptr[2]; // hardware address of DMA buffers - unsigned int hwdmasize[2]; // len of DMA buffers in Bytes - unsigned int dmasamplsize; // size in samples hwdmasize[0]/2 - unsigned int last_top_dma; // DMA pointer in last RTC int - int next_dma_buf; // which DMA buffer will be used next round - long dma_runs_to_end; // how many we must permorm DMA transfer to end of record - unsigned long last_dma_run; // how many bytes we must transfer on last DMA page - - unsigned int ai_scans; // len of scanlist - unsigned char ai_neverending; // if=1, then we do neverending record (you must use cancel()) - int irq_free; // 1=have allocated IRQ - int irq_blocked; // 1=IRQ now uses any subdev + unsigned long dmabuf[2]; // pointers to begin of DMA buffers + unsigned int dmapages[2]; // len of DMA buffers in PAGE_SIZEs + unsigned int hwdmaptr[2]; // hardware address of DMA buffers + unsigned int hwdmasize[2]; // len of DMA buffers in Bytes + unsigned int dmasamplsize; // size in samples hwdmasize[0]/2 + unsigned int last_top_dma; // DMA pointer in last RTC int + int next_dma_buf; // which DMA buffer will be used next round + long dma_runs_to_end; // how many we must permorm DMA transfer to end of record + unsigned long last_dma_run; // how many bytes we must transfer on last DMA page + + unsigned int ai_scans; // len of scanlist + unsigned char ai_neverending; // if=1, then we do neverending record (you must use cancel()) + int irq_free; // 1=have allocated IRQ + int irq_blocked; // 1=IRQ now uses any subdev #ifdef unused - int rtc_irq_blocked; // 1=we now do AI with DMA&RTC + int rtc_irq_blocked; // 1=we now do AI with DMA&RTC #endif - int irq_was_now_closed; // when IRQ finish, there's stored int816_mode for last interrupt - int int816_mode; // who now uses IRQ - 1=AI1 int, 2=AI1 dma, 3=AI3 int, 4AI3 dma - comedi_subdevice *last_int_sub; // ptr to subdevice which now finish - int ai_act_scan; // how many scans we finished - unsigned int ai_act_chanlist[16]; // MUX setting for actual AI operations - unsigned int ai_act_chanlist_len; // how long is actual MUX list - unsigned int ai_act_chanlist_pos; // actual position in MUX list - unsigned int ai_poll_ptr; // how many sampes transfer poll - comedi_subdevice *sub_ai; // ptr to AI subdevice + int irq_was_now_closed; // when IRQ finish, there's stored int816_mode for last interrupt + int int816_mode; // who now uses IRQ - 1=AI1 int, 2=AI1 dma, 3=AI3 int, 4AI3 dma + comedi_subdevice *last_int_sub; // ptr to subdevice which now finish + int ai_act_scan; // how many scans we finished + unsigned int ai_act_chanlist[16]; // MUX setting for actual AI operations + unsigned int ai_act_chanlist_len; // how long is actual MUX list + unsigned int ai_act_chanlist_pos; // actual position in MUX list + unsigned int ai_poll_ptr; // how many sampes transfer poll + comedi_subdevice *sub_ai; // ptr to AI subdevice #ifdef unused - struct timer_list rtc_irq_timer; // timer for RTC sanity check - unsigned long rtc_freq; // RTC int freq + struct timer_list rtc_irq_timer; // timer for RTC sanity check + unsigned long rtc_freq; // RTC int freq #endif } pcl816_private; - - - /* ============================================================================== */ -static int check_and_setup_channel_list (comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, int chanlen); -static int pcl816_ai_cancel (comedi_device * dev, comedi_subdevice * s); -static void start_pacer (comedi_device * dev, int mode, unsigned int divisor1, - unsigned int divisor2); +static int check_and_setup_channel_list(comedi_device * dev, + comedi_subdevice * s, unsigned int *chanlist, int chanlen); +static int pcl816_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2); #ifdef unused -static int set_rtc_irq_bit (unsigned char bit); +static int set_rtc_irq_bit(unsigned char bit); #endif -static int pcl816_ai_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); -static int pcl816_ai_cmd(comedi_device *dev, comedi_subdevice *s); - +static int pcl816_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int pcl816_ai_cmd(comedi_device * dev, comedi_subdevice * s); /* ============================================================================== ANALOG INPUT MODE0, 816 cards, slow version */ -static int pcl816_ai_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl816_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int timeout; DPRINTK("mode 0 analog input\n"); // software trigger, DMA and INT off - outb (0, dev->iobase + PCL816_CONTROL); + outb(0, dev->iobase + PCL816_CONTROL); // clear INT (conversion end) flag - outb (0, dev->iobase + PCL816_CLRINT); + outb(0, dev->iobase + PCL816_CLRINT); // Set the input channel - outb (CR_CHAN(insn->chanspec) & 0xf, dev->iobase + PCL816_MUX); - outb (CR_RANGE(insn->chanspec), dev->iobase + PCL816_RANGE); /* select gain */ + outb(CR_CHAN(insn->chanspec) & 0xf, dev->iobase + PCL816_MUX); + outb(CR_RANGE(insn->chanspec), dev->iobase + PCL816_RANGE); /* select gain */ - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { + outb(0, dev->iobase + PCL816_AD_LO); /* start conversion */ - outb (0, dev->iobase + PCL816_AD_LO); /* start conversion */ - - timeout=100; + timeout = 100; while (timeout--) { - if (!(inb (dev->iobase + PCL816_STATUS) & PCL816_STATUS_DRDY_MASK)) { - // return read value + if (!(inb(dev->iobase + PCL816_STATUS) & + PCL816_STATUS_DRDY_MASK)) { + // return read value data[n] = - ((inb (dev->iobase + PCL816_AD_HI) << 8 ) | - (inb (dev->iobase + PCL816_AD_LO))); + ((inb(dev->iobase + + PCL816_AD_HI) << 8) | + (inb(dev->iobase + PCL816_AD_LO))); - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT (conversion end) flag */ + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT (conversion end) flag */ break; } - comedi_udelay (1); + comedi_udelay(1); } // Return timeout error - if(!timeout) { - comedi_error (dev, "A/D insn timeout\n"); + if (!timeout) { + comedi_error(dev, "A/D insn timeout\n"); data[0] = 0; - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT (conversion end) flag */ + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT (conversion end) flag */ return -EIO; } @@ -284,54 +278,50 @@ static int pcl816_ai_insn_read(comedi_device *dev, comedi_subdevice *s, analog input interrupt mode 1 & 3, 818 cards one sample per interrupt version */ -static irqreturn_t -interrupt_pcl816_ai_mode13_int (int irq, void *d) +static irqreturn_t interrupt_pcl816_ai_mode13_int(int irq, void *d) { comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; int low, hi; - int timeout = 50; /* wait max 50us */ + int timeout = 50; /* wait max 50us */ while (timeout--) { - if (!(inb (dev->iobase + PCL816_STATUS) & PCL816_STATUS_DRDY_MASK)) - break; - comedi_udelay (1); - } - if(!timeout) { // timeout, bail error - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT request */ - comedi_error (dev, "A/D mode1/3 IRQ without DRDY!"); - pcl816_ai_cancel (dev, s); + if (!(inb(dev->iobase + PCL816_STATUS) & + PCL816_STATUS_DRDY_MASK)) + break; + comedi_udelay(1); + } + if (!timeout) { // timeout, bail error + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT request */ + comedi_error(dev, "A/D mode1/3 IRQ without DRDY!"); + pcl816_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; - } - + } // get the sample - low = inb (dev->iobase + PCL816_AD_LO); - hi = inb (dev->iobase + PCL816_AD_HI); - - comedi_buf_put( s->async, (hi << 8)|low ); + low = inb(dev->iobase + PCL816_AD_LO); + hi = inb(dev->iobase + PCL816_AD_HI); - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT request */ + comedi_buf_put(s->async, (hi << 8) | low); + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT request */ if (++devpriv->ai_act_chanlist_pos >= devpriv->ai_act_chanlist_len) devpriv->ai_act_chanlist_pos = 0; - - if (s->async->cur_chan == 0){ + if (s->async->cur_chan == 0) { devpriv->ai_act_scan++; } - if (!devpriv->ai_neverending) - if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ - /* all data sampled */ - pcl816_ai_cancel (dev, s); - s->async->events |= COMEDI_CB_EOA; - } + if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */ + /* all data sampled */ + pcl816_ai_cancel(dev, s); + s->async->events |= COMEDI_CB_EOA; + } comedi_event(dev, s); return IRQ_HANDLED; } @@ -340,26 +330,26 @@ interrupt_pcl816_ai_mode13_int (int irq, void *d) ============================================================================== analog input dma mode 1 & 3, 816 cards */ -static void transfer_from_dma_buf(comedi_device *dev,comedi_subdevice *s, - sampl_t *ptr, unsigned int bufptr, unsigned int len) +static void transfer_from_dma_buf(comedi_device * dev, comedi_subdevice * s, + sampl_t * ptr, unsigned int bufptr, unsigned int len) { int i; s->async->events = 0; - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) { - comedi_buf_put( s->async, ptr[bufptr++] ); + comedi_buf_put(s->async, ptr[bufptr++]); - - if (++devpriv->ai_act_chanlist_pos >= devpriv->ai_act_chanlist_len) { - devpriv->ai_act_chanlist_pos = 0; - devpriv->ai_act_scan++; + if (++devpriv->ai_act_chanlist_pos >= + devpriv->ai_act_chanlist_len) { + devpriv->ai_act_chanlist_pos = 0; + devpriv->ai_act_scan++; } if (!devpriv->ai_neverending) if (devpriv->ai_act_scan >= devpriv->ai_scans) { // all data sampled - pcl816_ai_cancel(dev,s); + pcl816_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_BLOCK; break; @@ -369,283 +359,288 @@ static void transfer_from_dma_buf(comedi_device *dev,comedi_subdevice *s, comedi_event(dev, s); } - static irqreturn_t interrupt_pcl816_ai_mode13_dma(int irq, void *d) { - comedi_device *dev = d; - comedi_subdevice *s = dev->subdevices + 0; - int len, bufptr, this_dma_buf; - unsigned long dma_flags; - sampl_t *ptr; + comedi_device *dev = d; + comedi_subdevice *s = dev->subdevices + 0; + int len, bufptr, this_dma_buf; + unsigned long dma_flags; + sampl_t *ptr; - disable_dma (devpriv->dma); - this_dma_buf = devpriv->next_dma_buf; + disable_dma(devpriv->dma); + this_dma_buf = devpriv->next_dma_buf; - if((devpriv->dma_runs_to_end > -1) || - devpriv->ai_neverending) { // switch dma bufs + if ((devpriv->dma_runs_to_end > -1) || devpriv->ai_neverending) { // switch dma bufs - devpriv->next_dma_buf = 1 - devpriv->next_dma_buf; - set_dma_mode (devpriv->dma, DMA_MODE_READ); - dma_flags = claim_dma_lock (); + devpriv->next_dma_buf = 1 - devpriv->next_dma_buf; + set_dma_mode(devpriv->dma, DMA_MODE_READ); + dma_flags = claim_dma_lock(); // clear_dma_ff (devpriv->dma); - set_dma_addr (devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]); - if (devpriv->dma_runs_to_end) { - set_dma_count (devpriv->dma, devpriv->hwdmasize[devpriv->next_dma_buf]); - } else { - set_dma_count (devpriv->dma, devpriv->last_dma_run); - } - release_dma_lock (dma_flags); - enable_dma (devpriv->dma); - } - - devpriv->dma_runs_to_end--; - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT request */ - - ptr = (sampl_t *) devpriv->dmabuf[this_dma_buf]; - - len = (devpriv->hwdmasize[0] >> 1) - devpriv->ai_poll_ptr; - bufptr = devpriv->ai_poll_ptr; - devpriv->ai_poll_ptr = 0; - - transfer_from_dma_buf(dev, s, ptr, bufptr, len); + set_dma_addr(devpriv->dma, + devpriv->hwdmaptr[devpriv->next_dma_buf]); + if (devpriv->dma_runs_to_end) { + set_dma_count(devpriv->dma, + devpriv->hwdmasize[devpriv->next_dma_buf]); + } else { + set_dma_count(devpriv->dma, devpriv->last_dma_run); + } + release_dma_lock(dma_flags); + enable_dma(devpriv->dma); + } + + devpriv->dma_runs_to_end--; + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT request */ + + ptr = (sampl_t *) devpriv->dmabuf[this_dma_buf]; + + len = (devpriv->hwdmasize[0] >> 1) - devpriv->ai_poll_ptr; + bufptr = devpriv->ai_poll_ptr; + devpriv->ai_poll_ptr = 0; + + transfer_from_dma_buf(dev, s, ptr, bufptr, len); return IRQ_HANDLED; } - /* ============================================================================== INT procedure */ -static irqreturn_t -interrupt_pcl816 (int irq, void *d PT_REGS_ARG) +static irqreturn_t interrupt_pcl816(int irq, void *d PT_REGS_ARG) { comedi_device *dev = d; DPRINTK(""); - if(!dev->attached) { + if (!dev->attached) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } + switch (devpriv->int816_mode) { + case INT_TYPE_AI1_DMA: + case INT_TYPE_AI3_DMA: + return interrupt_pcl816_ai_mode13_dma(irq, d); + case INT_TYPE_AI1_INT: + case INT_TYPE_AI3_INT: + return interrupt_pcl816_ai_mode13_int(irq, d); + } - switch (devpriv->int816_mode) { - case INT_TYPE_AI1_DMA: - case INT_TYPE_AI3_DMA: - return interrupt_pcl816_ai_mode13_dma (irq, d); - case INT_TYPE_AI1_INT: - case INT_TYPE_AI3_INT: - return interrupt_pcl816_ai_mode13_int (irq, d); - } - - - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT request */ + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT request */ if ((!dev->irq) | (!devpriv->irq_free) | (!devpriv->irq_blocked) | - (!devpriv->int816_mode)) - { - if (devpriv->irq_was_now_closed) { + (!devpriv->int816_mode)) { + if (devpriv->irq_was_now_closed) { devpriv->irq_was_now_closed = 0; // comedi_error(dev,"last IRQ.."); return IRQ_HANDLED; } - comedi_error (dev, "bad IRQ!"); + comedi_error(dev, "bad IRQ!"); return IRQ_NONE; - } - comedi_error (dev, "IRQ from unknow source!"); + } + comedi_error(dev, "IRQ from unknow source!"); return IRQ_NONE; } - /* ============================================================================== COMMAND MODE */ -static void pcl816_cmdtest_out(int e,comedi_cmd *cmd) { - rt_printk("pcl816 e=%d startsrc=%x scansrc=%x convsrc=%x\n",e,cmd->start_src,cmd->scan_begin_src,cmd->convert_src); - rt_printk("pcl816 e=%d startarg=%d scanarg=%d convarg=%d\n",e,cmd->start_arg,cmd->scan_begin_arg,cmd->convert_arg); - rt_printk("pcl816 e=%d stopsrc=%x scanend=%x\n",e,cmd->stop_src,cmd->scan_end_src); - rt_printk("pcl816 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n",e,cmd->stop_arg,cmd->scan_end_arg,cmd->chanlist_len); +static void pcl816_cmdtest_out(int e, comedi_cmd * cmd) +{ + rt_printk("pcl816 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e, + cmd->start_src, cmd->scan_begin_src, cmd->convert_src); + rt_printk("pcl816 e=%d startarg=%d scanarg=%d convarg=%d\n", e, + cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg); + rt_printk("pcl816 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src, + cmd->scan_end_src); + rt_printk("pcl816 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", e, + cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len); } /* ============================================================================== */ -static int pcl816_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) +static int pcl816_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; - int tmp,divisor1,divisor2; + int err = 0; + int tmp, divisor1, divisor2; -DEBUG( - rt_printk("pcl816 pcl812_ai_cmdtest\n"); - pcl816_cmdtest_out(-1, cmd); -); + DEBUG(rt_printk("pcl816 pcl812_ai_cmdtest\n"); + pcl816_cmdtest_out(-1, cmd);); /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; - + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - if(!cmd->convert_src & (TRIG_EXT | TRIG_TIMER)) err++; + if (!cmd->convert_src & (TRIG_EXT | TRIG_TIMER)) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) { + if (err) { return 1; } /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src!=TRIG_NOW) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src != TRIG_NOW) { + cmd->start_src = TRIG_NOW; err++; } - if(cmd->scan_begin_src!=TRIG_FOLLOW) { - cmd->scan_begin_src=TRIG_FOLLOW; + if (cmd->scan_begin_src != TRIG_FOLLOW) { + cmd->scan_begin_src = TRIG_FOLLOW; err++; } - if(cmd->convert_src!=TRIG_EXT && - cmd->convert_src!=TRIG_TIMER) { - cmd->convert_src=TRIG_TIMER; - err++; + if (cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_TIMER) { + cmd->convert_src = TRIG_TIMER; + err++; } - - if(cmd->scan_end_src!=TRIG_COUNT) { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT) err++; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; - if(err) { + if (err) { return 2; } /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argai_ns_min){ - cmd->convert_arg=this_board->ai_ns_min; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_ns_min) { + cmd->convert_arg = this_board->ai_ns_min; err++; } - } else { /* TRIG_EXT */ - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + } else { /* TRIG_EXT */ + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } } - if(!cmd->chanlist_len){ - cmd->chanlist_len=1; + if (!cmd->chanlist_len) { + cmd->chanlist_len = 1; err++; } - if(cmd->chanlist_len > this_board->n_aichan){ - cmd->chanlist_len=this_board->n_aichan; + if (cmd->chanlist_len > this_board->n_aichan) { + cmd->chanlist_len = this_board->n_aichan; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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){ - cmd->stop_arg=1; + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { + cmd->stop_arg = 1; err++; } - } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err) { + if (err) { return 3; } /* step 4: fix up any arguments */ - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - i8253_cascade_ns_to_timer (this_board->i8254_osc_base, + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1, &divisor2, &cmd->convert_arg, cmd->flags & TRIG_ROUND_MASK); - if(cmd->convert_argai_ns_min) - cmd->convert_arg=this_board->ai_ns_min; - if(tmp!=cmd->convert_arg)err++; + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + if (tmp != cmd->convert_arg) + err++; } - if(err) { + if (err) { return 4; } return 0; } -static int pcl816_ai_cmd(comedi_device *dev,comedi_subdevice *s) +static int pcl816_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - unsigned int divisor1=0, divisor2=0, dma_flags, bytes, dmairq; - comedi_cmd *cmd=&s->async->cmd; - - - if(cmd->start_src!=TRIG_NOW) return -EINVAL; - if(cmd->scan_begin_src!=TRIG_FOLLOW) return -EINVAL; - if(cmd->scan_end_src!=TRIG_COUNT) return -EINVAL; - if(cmd->scan_end_arg!=cmd->chanlist_len) return -EINVAL; -// if(cmd->chanlist_len>MAX_CHANLIST_LEN) return -EINVAL; - if (devpriv->irq_blocked) - return -EBUSY; - - if (cmd->convert_src==TRIG_TIMER) { - if(cmd->convert_arg < this_board->ai_ns_min) - cmd->convert_arg=this_board->ai_ns_min; - - i8253_cascade_ns_to_timer (this_board->i8254_osc_base, &divisor1, - &divisor2, &cmd->convert_arg, cmd->flags&TRIG_ROUND_MASK); - if (divisor1 == 1) { // PCL816 crash if any divisor is set to 1 - divisor1 = 2; - divisor2 /= 2; - } - if (divisor2 == 1) { - divisor2 = 2; - divisor1 /= 2; - } + unsigned int divisor1 = 0, divisor2 = 0, dma_flags, bytes, dmairq; + comedi_cmd *cmd = &s->async->cmd; + + if (cmd->start_src != TRIG_NOW) + return -EINVAL; + if (cmd->scan_begin_src != TRIG_FOLLOW) + return -EINVAL; + if (cmd->scan_end_src != TRIG_COUNT) + return -EINVAL; + if (cmd->scan_end_arg != cmd->chanlist_len) + return -EINVAL; +// if(cmd->chanlist_len>MAX_CHANLIST_LEN) return -EINVAL; + if (devpriv->irq_blocked) + return -EBUSY; + + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ai_ns_min) + cmd->convert_arg = this_board->ai_ns_min; + + i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (divisor1 == 1) { // PCL816 crash if any divisor is set to 1 + divisor1 = 2; + divisor2 /= 2; + } + if (divisor2 == 1) { + divisor2 = 2; + divisor1 /= 2; + } } - start_pacer(dev, -1, 0, 0); // stop pacer - - if (!check_and_setup_channel_list (dev, s, cmd->chanlist, cmd->chanlist_len)) - return -EINVAL; - comedi_udelay (1); + start_pacer(dev, -1, 0, 0); // stop pacer + if (!check_and_setup_channel_list(dev, s, cmd->chanlist, + cmd->chanlist_len)) + return -EINVAL; + comedi_udelay(1); - devpriv->ai_act_scan=0; - s->async->cur_chan=0; + devpriv->ai_act_scan = 0; + s->async->cur_chan = 0; devpriv->irq_blocked = 1; - devpriv->ai_poll_ptr=0; + devpriv->ai_poll_ptr = 0; devpriv->irq_was_now_closed = 0; - if (cmd->stop_src==TRIG_COUNT) { + if (cmd->stop_src == TRIG_COUNT) { devpriv->ai_scans = cmd->stop_arg; devpriv->ai_neverending = 0; } else { @@ -653,214 +648,211 @@ static int pcl816_ai_cmd(comedi_device *dev,comedi_subdevice *s) devpriv->ai_neverending = 1; } - - if ((cmd->flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? + if ((cmd->flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan? printk("pl816: You wankt WAKE_EOS but I dont want handle it"); - // devpriv->ai_eos=1; + // devpriv->ai_eos=1; //if (devpriv->ai_n_chan==1) - // devpriv->dma=0; // DMA is useless for this situation + // devpriv->dma=0; // DMA is useless for this situation } if (devpriv->dma) { - bytes = devpriv->hwdmasize[0]; + bytes = devpriv->hwdmasize[0]; if (!devpriv->ai_neverending) { - bytes = s->async->cmd.chanlist_len * s->async->cmd.chanlist_len * sizeof (sampl_t); // how many - devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize[0]; // how many DMA pages we must fill - devpriv->last_dma_run = bytes % devpriv->hwdmasize[0]; //on last dma transfer must be moved - devpriv->dma_runs_to_end--; - if (devpriv->dma_runs_to_end >= 0) - bytes = devpriv->hwdmasize[0]; + bytes = s->async->cmd.chanlist_len * s->async->cmd.chanlist_len * sizeof(sampl_t); // how many + devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize[0]; // how many DMA pages we must fill + devpriv->last_dma_run = bytes % devpriv->hwdmasize[0]; //on last dma transfer must be moved + devpriv->dma_runs_to_end--; + if (devpriv->dma_runs_to_end >= 0) + bytes = devpriv->hwdmasize[0]; } else devpriv->dma_runs_to_end = -1; devpriv->next_dma_buf = 0; - set_dma_mode (devpriv->dma, DMA_MODE_READ); - dma_flags = claim_dma_lock (); - clear_dma_ff (devpriv->dma); - set_dma_addr (devpriv->dma, devpriv->hwdmaptr[0]); - set_dma_count (devpriv->dma, bytes); - release_dma_lock (dma_flags); - enable_dma (devpriv->dma); + set_dma_mode(devpriv->dma, DMA_MODE_READ); + dma_flags = claim_dma_lock(); + clear_dma_ff(devpriv->dma); + set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); + set_dma_count(devpriv->dma, bytes); + release_dma_lock(dma_flags); + enable_dma(devpriv->dma); } - start_pacer(dev, 1, divisor1, divisor2); - dmairq = ((devpriv->dma & 0x3)<<4) | (dev->irq & 0x7); + dmairq = ((devpriv->dma & 0x3) << 4) | (dev->irq & 0x7); switch (cmd->convert_src) { case TRIG_TIMER: - devpriv->int816_mode = INT_TYPE_AI1_DMA; - outb (0x32, dev->iobase + PCL816_CONTROL); // Pacer+IRQ+DMA - outb(dmairq, dev->iobase + PCL816_STATUS); // write irq and DMA to card + devpriv->int816_mode = INT_TYPE_AI1_DMA; + outb(0x32, dev->iobase + PCL816_CONTROL); // Pacer+IRQ+DMA + outb(dmairq, dev->iobase + PCL816_STATUS); // write irq and DMA to card break; default: devpriv->int816_mode = INT_TYPE_AI3_DMA; - outb (0x34, dev->iobase + PCL816_CONTROL); // Ext trig+IRQ+DMA - outb(dmairq, dev->iobase + PCL816_STATUS); // write irq to card + outb(0x34, dev->iobase + PCL816_CONTROL); // Ext trig+IRQ+DMA + outb(dmairq, dev->iobase + PCL816_STATUS); // write irq to card break; } - - DPRINTK("pcl816 END: pcl812_ai_cmd()\n"); - return 0; + DPRINTK("pcl816 END: pcl812_ai_cmd()\n"); + return 0; } - -static int pcl816_ai_poll(comedi_device *dev,comedi_subdevice *s) +static int pcl816_ai_poll(comedi_device * dev, comedi_subdevice * s) { unsigned long flags; - unsigned int top1,top2,i; + unsigned int top1, top2, i; - if (!devpriv->dma) return 0; // poll is valid only for DMA transfer + if (!devpriv->dma) + return 0; // poll is valid only for DMA transfer comedi_spin_lock_irqsave(&dev->spinlock, flags); - for (i=0; i<20; i++) { - top1 = get_dma_residue(devpriv->dma); // where is now DMA + for (i = 0; i < 20; i++) { + top1 = get_dma_residue(devpriv->dma); // where is now DMA top2 = get_dma_residue(devpriv->dma); - if (top1 == top2) break; + if (top1 == top2) + break; } if (top1 != top2) { comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } - top1 = devpriv->hwdmasize [0] - top1; // where is now DMA in buffer - top1 >>= 1; // sample position + top1 = devpriv->hwdmasize[0] - top1; // where is now DMA in buffer + top1 >>= 1; // sample position top2 = top1 - devpriv->ai_poll_ptr; - if (top2 < 1) { // no new samples - comedi_spin_unlock_irqrestore(&dev->spinlock,flags); + if (top2 < 1) { // no new samples + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } - transfer_from_dma_buf(dev, s, (sampl_t*)devpriv->dmabuf[devpriv->next_dma_buf], - devpriv->ai_poll_ptr, top2); + transfer_from_dma_buf(dev, s, + (sampl_t *) devpriv->dmabuf[devpriv->next_dma_buf], + devpriv->ai_poll_ptr, top2); - devpriv->ai_poll_ptr = top1; // new buffer position - comedi_spin_unlock_irqrestore(&dev->spinlock,flags); + devpriv->ai_poll_ptr = top1; // new buffer position + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return s->async->buf_write_count - s->async->buf_read_count; } - /* ============================================================================== cancel any mode 1-4 AI */ -static int -pcl816_ai_cancel (comedi_device * dev, comedi_subdevice * s) +static int pcl816_ai_cancel(comedi_device * dev, comedi_subdevice * s) { // DEBUG(rt_printk("pcl816_ai_cancel()\n");) - if (devpriv->irq_blocked > 0) { - switch (devpriv->int816_mode) { + if (devpriv->irq_blocked > 0) { + switch (devpriv->int816_mode) { #ifdef unused - case INT_TYPE_AI1_DMA_RTC: - case INT_TYPE_AI3_DMA_RTC: - set_rtc_irq_bit (0); // stop RTC - del_timer (&devpriv->rtc_irq_timer); + case INT_TYPE_AI1_DMA_RTC: + case INT_TYPE_AI3_DMA_RTC: + set_rtc_irq_bit(0); // stop RTC + del_timer(&devpriv->rtc_irq_timer); #endif - case INT_TYPE_AI1_DMA: - case INT_TYPE_AI3_DMA: - disable_dma (devpriv->dma); - case INT_TYPE_AI1_INT: - case INT_TYPE_AI3_INT: - outb (inb (dev->iobase + PCL816_CONTROL) & 0x73, dev->iobase + PCL816_CONTROL); /* Stop A/D */ - comedi_udelay (1); - outb (0, dev->iobase + PCL816_CONTROL); /* Stop A/D */ - outb (0xb0, dev->iobase + PCL816_CTRCTL); /* Stop pacer */ - outb (0x70, dev->iobase + PCL816_CTRCTL); - outb (0, dev->iobase + PCL816_AD_LO); - inb (dev->iobase + PCL816_AD_LO); - inb (dev->iobase + PCL816_AD_HI); - outb (0, dev->iobase + PCL816_CLRINT); /* clear INT request */ - outb (0, dev->iobase + PCL816_CONTROL); /* Stop A/D */ - devpriv->irq_blocked = 0; - devpriv->irq_was_now_closed = devpriv->int816_mode; - devpriv->int816_mode = 0; - devpriv->last_int_sub = s; -// s->busy = 0; - break; - } + case INT_TYPE_AI1_DMA: + case INT_TYPE_AI3_DMA: + disable_dma(devpriv->dma); + case INT_TYPE_AI1_INT: + case INT_TYPE_AI3_INT: + outb(inb(dev->iobase + PCL816_CONTROL) & 0x73, dev->iobase + PCL816_CONTROL); /* Stop A/D */ + comedi_udelay(1); + outb(0, dev->iobase + PCL816_CONTROL); /* Stop A/D */ + outb(0xb0, dev->iobase + PCL816_CTRCTL); /* Stop pacer */ + outb(0x70, dev->iobase + PCL816_CTRCTL); + outb(0, dev->iobase + PCL816_AD_LO); + inb(dev->iobase + PCL816_AD_LO); + inb(dev->iobase + PCL816_AD_HI); + outb(0, dev->iobase + PCL816_CLRINT); /* clear INT request */ + outb(0, dev->iobase + PCL816_CONTROL); /* Stop A/D */ + devpriv->irq_blocked = 0; + devpriv->irq_was_now_closed = devpriv->int816_mode; + devpriv->int816_mode = 0; + devpriv->last_int_sub = s; +// s->busy = 0; + break; + } } - DEBUG(rt_printk("comedi: pcl816_ai_cancel() successful\n");) - return 0; + DEBUG(rt_printk("comedi: pcl816_ai_cancel() successful\n"); + ) + return 0; } /* ============================================================================== chech for PCL816 */ -static int pcl816_check (unsigned long iobase) +static int pcl816_check(unsigned long iobase) { - outb (0x00, iobase + PCL816_MUX); - comedi_udelay (1); - if (inb (iobase + PCL816_MUX) != 0x00) - return 1; //there isn't card - outb (0x55, iobase + PCL816_MUX); - comedi_udelay (1); - if (inb (iobase + PCL816_MUX) != 0x55) - return 1; //there isn't card - outb (0x00, iobase + PCL816_MUX); - comedi_udelay (1); - outb (0x18, iobase + PCL816_CONTROL); - comedi_udelay (1); - if (inb (iobase + PCL816_CONTROL) != 0x18) - return 1; //there isn't card - return 0; // ok, card exist + outb(0x00, iobase + PCL816_MUX); + comedi_udelay(1); + if (inb(iobase + PCL816_MUX) != 0x00) + return 1; //there isn't card + outb(0x55, iobase + PCL816_MUX); + comedi_udelay(1); + if (inb(iobase + PCL816_MUX) != 0x55) + return 1; //there isn't card + outb(0x00, iobase + PCL816_MUX); + comedi_udelay(1); + outb(0x18, iobase + PCL816_CONTROL); + comedi_udelay(1); + if (inb(iobase + PCL816_CONTROL) != 0x18) + return 1; //there isn't card + return 0; // ok, card exist } /* ============================================================================== reset whole PCL-816 cards */ -static void -pcl816_reset (comedi_device * dev) +static void pcl816_reset(comedi_device * dev) { -// outb (0, dev->iobase + PCL818_DA_LO); // DAC=0V +// outb (0, dev->iobase + PCL818_DA_LO); // DAC=0V // outb (0, dev->iobase + PCL818_DA_HI); // comedi_udelay (1); -// outb (0, dev->iobase + PCL818_DO_HI); // DO=$0000 +// outb (0, dev->iobase + PCL818_DO_HI); // DO=$0000 // outb (0, dev->iobase + PCL818_DO_LO); // comedi_udelay (1); - outb (0, dev->iobase + PCL816_CONTROL); - outb (0, dev->iobase + PCL816_MUX); - outb (0, dev->iobase + PCL816_CLRINT); - outb (0xb0, dev->iobase + PCL816_CTRCTL); /* Stop pacer */ - outb (0x70, dev->iobase + PCL816_CTRCTL); - outb (0x30, dev->iobase + PCL816_CTRCTL); - outb (0, dev->iobase + PCL816_RANGE); + outb(0, dev->iobase + PCL816_CONTROL); + outb(0, dev->iobase + PCL816_MUX); + outb(0, dev->iobase + PCL816_CLRINT); + outb(0xb0, dev->iobase + PCL816_CTRCTL); /* Stop pacer */ + outb(0x70, dev->iobase + PCL816_CTRCTL); + outb(0x30, dev->iobase + PCL816_CTRCTL); + outb(0, dev->iobase + PCL816_RANGE); } - /* ============================================================================== Start/stop pacer onboard pacer */ static void -start_pacer (comedi_device * dev, int mode, unsigned int divisor1, - unsigned int divisor2) +start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2) { - outb (0x32, dev->iobase + PCL816_CTRCTL); - outb (0xff, dev->iobase + PCL816_CTR0); - outb (0x00, dev->iobase + PCL816_CTR0); - comedi_udelay (1); - outb(0xb4, dev->iobase + PCL816_CTRCTL); // set counter 2 as mode 3 - outb(0x74, dev->iobase + PCL816_CTRCTL); // set counter 1 as mode 3 - comedi_udelay(1); + outb(0x32, dev->iobase + PCL816_CTRCTL); + outb(0xff, dev->iobase + PCL816_CTR0); + outb(0x00, dev->iobase + PCL816_CTR0); + comedi_udelay(1); + outb(0xb4, dev->iobase + PCL816_CTRCTL); // set counter 2 as mode 3 + outb(0x74, dev->iobase + PCL816_CTRCTL); // set counter 1 as mode 3 + comedi_udelay(1); if (mode == 1) { - DPRINTK("mode %d, divisor1 %d, divisor2 %d\n", mode, divisor1, divisor2); + DPRINTK("mode %d, divisor1 %d, divisor2 %d\n", mode, divisor1, + divisor2); outb(divisor2 & 0xff, dev->iobase + PCL816_CTR2); outb((divisor2 >> 8) & 0xff, dev->iobase + PCL816_CTR2); - outb(divisor1 & 0xff, dev->iobase + PCL816_CTR1); + outb(divisor1 & 0xff, dev->iobase + PCL816_CTR1); outb((divisor1 >> 8) & 0xff, dev->iobase + PCL816_CTR1); - } + } /* clear pending interrupts (just in case) */ -// outb(0, dev->iobase + PCL816_CLRINT); +// outb(0, dev->iobase + PCL816_CLRINT); } /* @@ -869,69 +861,77 @@ start_pacer (comedi_device * dev, int mode, unsigned int divisor1, If it's ok, then program scan/gain logic */ static int -check_and_setup_channel_list (comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, int chanlen) +check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, int chanlen) { - unsigned int chansegment[16]; - unsigned int i, nowmustbechan, seglen, segpos; - - // correct channel and range number check itself comedi/range.c - if (chanlen < 1) { - comedi_error (dev, "range/channel list is empty!"); - return 0; - } - - if (chanlen > 1) - { - chansegment[0] = chanlist[0]; // first channel is everytime ok - for (i = 1, seglen = 1; i < chanlen; i++, seglen++) { - // build part of chanlist - DEBUG(rt_printk("%d. %d %d\n",i,CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i]));) - if (chanlist[0] == chanlist[i]) - break; // we detect loop, this must by finish - nowmustbechan = (CR_CHAN (chansegment[i - 1]) + 1) % chanlen; - if (nowmustbechan != CR_CHAN (chanlist[i])) { - // channel list isn't continous :-( - rt_printk("comedi%d: pcl816: channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", - dev->minor, i, CR_CHAN (chanlist[i]), nowmustbechan, CR_CHAN (chanlist[0])); - return 0; - } - chansegment[i] = chanlist[i]; // well, this is next correct channel in list + unsigned int chansegment[16]; + unsigned int i, nowmustbechan, seglen, segpos; + + // correct channel and range number check itself comedi/range.c + if (chanlen < 1) { + comedi_error(dev, "range/channel list is empty!"); + return 0; } - for (i = 0, segpos = 0; i < chanlen; i++) - { // check whole chanlist - DEBUG(rt_printk("%d %d=%d %d\n",CR_CHAN(chansegment[i%seglen]),CR_RANGE(chansegment[i%seglen]),CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i]));) - if (chanlist[i] != chansegment[i % seglen]) { - rt_printk("comedi%d: pcl816: bad channel or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", - dev->minor, i, CR_CHAN (chansegment[i]), - CR_RANGE (chansegment[i]), CR_AREF (chansegment[i]), - CR_CHAN (chanlist[i % seglen]), - CR_RANGE(chanlist[i % seglen]), - CR_AREF (chansegment[i % seglen])); - return 0; // chan/gain list is strange - } + if (chanlen > 1) { + chansegment[0] = chanlist[0]; // first channel is everytime ok + for (i = 1, seglen = 1; i < chanlen; i++, seglen++) { + // build part of chanlist + DEBUG(rt_printk("%d. %d %d\n", i, CR_CHAN(chanlist[i]), + CR_RANGE(chanlist[i])); + ) + if (chanlist[0] == chanlist[i]) + break; // we detect loop, this must by finish + nowmustbechan = + (CR_CHAN(chansegment[i - 1]) + 1) % chanlen; + if (nowmustbechan != CR_CHAN(chanlist[i])) { + // channel list isn't continous :-( + rt_printk + ("comedi%d: pcl816: channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", + dev->minor, i, CR_CHAN(chanlist[i]), + nowmustbechan, CR_CHAN(chanlist[0])); + return 0; + } + chansegment[i] = chanlist[i]; // well, this is next correct channel in list + } + + for (i = 0, segpos = 0; i < chanlen; i++) { // check whole chanlist + DEBUG(rt_printk("%d %d=%d %d\n", + CR_CHAN(chansegment[i % seglen]), + CR_RANGE(chansegment[i % seglen]), + CR_CHAN(chanlist[i]), + CR_RANGE(chanlist[i])); + ) + if (chanlist[i] != chansegment[i % seglen]) { + rt_printk + ("comedi%d: pcl816: bad channel or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", + dev->minor, i, CR_CHAN(chansegment[i]), + CR_RANGE(chansegment[i]), + CR_AREF(chansegment[i]), + CR_CHAN(chanlist[i % seglen]), + CR_RANGE(chanlist[i % seglen]), + CR_AREF(chansegment[i % seglen])); + return 0; // chan/gain list is strange + } + } + } else { + seglen = 1; } - } - else - { - seglen = 1; - } - devpriv->ai_act_chanlist_len = seglen; - devpriv->ai_act_chanlist_pos = 0; + devpriv->ai_act_chanlist_len = seglen; + devpriv->ai_act_chanlist_pos = 0; - for (i = 0; i < seglen; i++) { // store range list to card - devpriv->ai_act_chanlist[i] = CR_CHAN (chanlist[i]); - outb (CR_CHAN(chanlist[0]) & 0xf, dev->iobase + PCL816_MUX); - outb (CR_RANGE(chanlist[0]), dev->iobase + PCL816_RANGE); /* select gain */ - } + for (i = 0; i < seglen; i++) { // store range list to card + devpriv->ai_act_chanlist[i] = CR_CHAN(chanlist[i]); + outb(CR_CHAN(chanlist[0]) & 0xf, dev->iobase + PCL816_MUX); + outb(CR_RANGE(chanlist[0]), dev->iobase + PCL816_RANGE); /* select gain */ + } - comedi_udelay (1); + comedi_udelay(1); - outb (devpriv->ai_act_chanlist[0] | (devpriv->ai_act_chanlist[seglen - 1] << 4), - dev->iobase + PCL816_MUX); /* select channel interval to scan */ + outb(devpriv->ai_act_chanlist[0] | (devpriv->ai_act_chanlist[seglen - 1] << 4), dev->iobase + PCL816_MUX); /* select channel interval to scan */ - return 1; // we can serve this with MUX logic + return 1; // we can serve this with MUX logic } #ifdef unused @@ -941,227 +941,230 @@ check_and_setup_channel_list (comedi_device * dev, comedi_subdevice * s, unsigne */ static int set_rtc_irq_bit(unsigned char bit) { - unsigned char val; - unsigned long flags; + unsigned char val; + unsigned long flags; - if (bit==1) { + if (bit == 1) { RTC_timer_lock++; - if (RTC_timer_lock>1) return 0; + if (RTC_timer_lock > 1) + return 0; } else { RTC_timer_lock--; - if (RTC_timer_lock<0) RTC_timer_lock=0; - if (RTC_timer_lock>0) return 0; + if (RTC_timer_lock < 0) + RTC_timer_lock = 0; + if (RTC_timer_lock > 0) + return 0; } - save_flags(flags); - cli(); - val = CMOS_READ(RTC_CONTROL); - if (bit) { val |= RTC_PIE; } - else { val &= ~RTC_PIE; } - CMOS_WRITE(val, RTC_CONTROL); - CMOS_READ(RTC_INTR_FLAGS); - restore_flags(flags); - return 0; + save_flags(flags); + cli(); + val = CMOS_READ(RTC_CONTROL); + if (bit) { + val |= RTC_PIE; + } else { + val &= ~RTC_PIE; + } + CMOS_WRITE(val, RTC_CONTROL); + CMOS_READ(RTC_INTR_FLAGS); + restore_flags(flags); + return 0; } #endif - /* ============================================================================== Free any resources that we have claimed */ -static void -free_resources (comedi_device * dev) +static void free_resources(comedi_device * dev) { - //rt_printk("free_resource()\n"); - if (dev->private) - { - pcl816_ai_cancel (dev, devpriv->sub_ai); - pcl816_reset (dev); - if (devpriv->dma) - free_dma (devpriv->dma); - if (devpriv->dmabuf[0]) - free_pages (devpriv->dmabuf[0], devpriv->dmapages[0]); - if (devpriv->dmabuf[1]) - free_pages (devpriv->dmabuf[1], devpriv->dmapages[1]); + //rt_printk("free_resource()\n"); + if (dev->private) { + pcl816_ai_cancel(dev, devpriv->sub_ai); + pcl816_reset(dev); + if (devpriv->dma) + free_dma(devpriv->dma); + if (devpriv->dmabuf[0]) + free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]); + if (devpriv->dmabuf[1]) + free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]); #ifdef unused - if (devpriv->rtc_irq) - comedi_free_irq (devpriv->rtc_irq, dev); - if ((devpriv->dma_rtc) && (RTC_lock == 1)) - { - if (devpriv->rtc_iobase) - release_region (devpriv->rtc_iobase, devpriv->rtc_iosize); - } + if (devpriv->rtc_irq) + comedi_free_irq(devpriv->rtc_irq, dev); + if ((devpriv->dma_rtc) && (RTC_lock == 1)) { + if (devpriv->rtc_iobase) + release_region(devpriv->rtc_iobase, + devpriv->rtc_iosize); + } #endif - } + } - if (dev->irq) - free_irq (dev->irq, dev); - if (dev->iobase) - release_region (dev->iobase, this_board->io_range); - //rt_printk("free_resource() end\n"); + if (dev->irq) + free_irq(dev->irq, dev); + if (dev->iobase) + release_region(dev->iobase, this_board->io_range); + //rt_printk("free_resource() end\n"); } - /* ============================================================================== Initialization */ -static int -pcl816_attach (comedi_device * dev, comedi_devconfig * it) +static int pcl816_attach(comedi_device * dev, comedi_devconfig * it) { - int ret; - unsigned long iobase; - unsigned int irq, dma; - unsigned long pages; - //int i; - comedi_subdevice *s; - - /* claim our I/O space */ - iobase = it->options[0]; - printk("comedi%d: pcl816: board=%s, ioport=0x%03lx", dev->minor, + int ret; + unsigned long iobase; + unsigned int irq, dma; + unsigned long pages; + //int i; + comedi_subdevice *s; + + /* claim our I/O space */ + iobase = it->options[0]; + printk("comedi%d: pcl816: board=%s, ioport=0x%03lx", dev->minor, this_board->name, iobase); - if (!request_region (iobase, this_board->io_range, "pcl816")) { - rt_printk ("I/O port conflict\n"); - return -EIO; - } + if (!request_region(iobase, this_board->io_range, "pcl816")) { + rt_printk("I/O port conflict\n"); + return -EIO; + } - dev->iobase = iobase; + dev->iobase = iobase; - if (pcl816_check (iobase)) { - rt_printk (", I cann't detect board. FAIL!\n"); - return -EIO; - } + if (pcl816_check(iobase)) { + rt_printk(", I cann't detect board. FAIL!\n"); + return -EIO; + } - if ((ret = alloc_private (dev, sizeof (pcl816_private))) < 0) - return ret; /* Can't alloc mem */ + if ((ret = alloc_private(dev, sizeof(pcl816_private))) < 0) + return ret; /* Can't alloc mem */ - /* set up some name stuff */ - dev->board_name = this_board->name; + /* set up some name stuff */ + dev->board_name = this_board->name; - /* grab our IRQ */ - irq = 0; - if (this_board->IRQbits != 0) { /* board support IRQ */ + /* grab our IRQ */ + irq = 0; + if (this_board->IRQbits != 0) { /* board support IRQ */ irq = it->options[1]; - if (irq) - { /* we want to use IRQ */ - if (((1 << irq) & this_board->IRQbits) == 0) - { - rt_printk (", IRQ %u is out of allowed range, DISABLING IT", irq); - irq = 0; /* Bad IRQ */ - } - else - { - if (comedi_request_irq(irq, interrupt_pcl816, 0, "pcl816", dev)) { - rt_printk (", unable to allocate IRQ %u, DISABLING IT",irq); - irq = 0; /* Can't use IRQ */ + if (irq) { /* we want to use IRQ */ + if (((1 << irq) & this_board->IRQbits) == 0) { + rt_printk + (", IRQ %u is out of allowed range, DISABLING IT", + irq); + irq = 0; /* Bad IRQ */ + } else { + if (comedi_request_irq(irq, interrupt_pcl816, 0, + "pcl816", dev)) { + rt_printk + (", unable to allocate IRQ %u, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ + } else { + rt_printk(", irq=%u", irq); + } } - else { - rt_printk (", irq=%u", irq); } - } } - } - - dev->irq = irq; - if (irq) { - devpriv->irq_free = 1; - } /* 1=we have allocated irq */ - else { - devpriv->irq_free = 0; - } - devpriv->irq_blocked = 0; /* number of subdevice which use IRQ */ - devpriv->int816_mode = 0; /* mode of irq */ -#ifdef unused - /* grab RTC for DMA operations */ - devpriv->dma_rtc = 0; - if (it->options[2] > 0) - { // we want to use DMA - if (RTC_lock == 0) - { - if (!request_region (RTC_PORT (0), RTC_IO_EXTENT, "pcl816 (RTC)")) - goto no_rtc; + dev->irq = irq; + if (irq) { + devpriv->irq_free = 1; + } /* 1=we have allocated irq */ + else { + devpriv->irq_free = 0; } - devpriv->rtc_iobase = RTC_PORT (0); - devpriv->rtc_iosize = RTC_IO_EXTENT; - RTC_lock++; + devpriv->irq_blocked = 0; /* number of subdevice which use IRQ */ + devpriv->int816_mode = 0; /* mode of irq */ + +#ifdef unused + /* grab RTC for DMA operations */ + devpriv->dma_rtc = 0; + if (it->options[2] > 0) { // we want to use DMA + if (RTC_lock == 0) { + if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, + "pcl816 (RTC)")) + goto no_rtc; + } + devpriv->rtc_iobase = RTC_PORT(0); + devpriv->rtc_iosize = RTC_IO_EXTENT; + RTC_lock++; #ifdef UNTESTED_CODE - if (!comedi_request_irq (RTC_IRQ, interrupt_pcl816_ai_mode13_dma_rtc, - 0, "pcl816 DMA (RTC)", dev)) { - devpriv->dma_rtc = 1; - devpriv->rtc_irq = RTC_IRQ; - rt_printk (", dma_irq=%u", devpriv->rtc_irq); - } else { - RTC_lock--; - if (RTC_lock == 0) - { - if (devpriv->rtc_iobase) - release_region (devpriv->rtc_iobase, devpriv->rtc_iosize); - } - devpriv->rtc_iobase = 0; - devpriv->rtc_iosize = 0; - } + if (!comedi_request_irq(RTC_IRQ, + interrupt_pcl816_ai_mode13_dma_rtc, 0, + "pcl816 DMA (RTC)", dev)) { + devpriv->dma_rtc = 1; + devpriv->rtc_irq = RTC_IRQ; + rt_printk(", dma_irq=%u", devpriv->rtc_irq); + } else { + RTC_lock--; + if (RTC_lock == 0) { + if (devpriv->rtc_iobase) + release_region(devpriv->rtc_iobase, + devpriv->rtc_iosize); + } + devpriv->rtc_iobase = 0; + devpriv->rtc_iosize = 0; + } #else - printk("pcl816: RTC code missing"); + printk("pcl816: RTC code missing"); #endif - } + } -no_rtc: + no_rtc: #endif - /* grab our DMA */ - dma = 0; - devpriv->dma = dma; - if ((devpriv->irq_free == 0) && (devpriv->dma_rtc == 0)) - goto no_dma; /* if we haven't IRQ, we can't use DMA */ - - if (this_board->DMAbits != 0) { /* board support DMA */ - dma = it->options[2]; - if (dma < 1) - goto no_dma; /* DMA disabled */ - - if (((1 << dma) & this_board->DMAbits) == 0) { - rt_printk (", DMA is out of allowed range, FAIL!\n"); - return -EINVAL; /* Bad DMA */ - } - ret = request_dma (dma, "pcl816"); - if (ret) { - rt_printk (", unable to allocate DMA %u, FAIL!\n", dma); - return -EBUSY; /* DMA isn't free */ - } - - devpriv->dma = dma; - rt_printk (", dma=%u", dma); - pages = 2; /* we need 16KB */ - devpriv->dmabuf[0] = __get_dma_pages (GFP_KERNEL, pages); - - if (!devpriv->dmabuf[0]) { - rt_printk (", unable to allocate DMA buffer, FAIL!\n"); - /* maybe experiment with try_to_free_pages() will help .... */ - return -EBUSY; /* no buffer :-( */ - } - devpriv->dmapages[0] = pages; - devpriv->hwdmaptr[0] = virt_to_bus ((void *) devpriv->dmabuf[0]); - devpriv->hwdmasize[0] = (1 << pages) * PAGE_SIZE; - //rt_printk("%d %d %ld, ",devpriv->dmapages[0],devpriv->hwdmasize[0],PAGE_SIZE); - - if (devpriv->dma_rtc == 0) { // we must do duble buff :-( - devpriv->dmabuf[1] = __get_dma_pages (GFP_KERNEL, pages); - if (!devpriv->dmabuf[1]) { - rt_printk (", unable to allocate DMA buffer, FAIL!\n"); - return -EBUSY; - } - devpriv->dmapages[1] = pages; - devpriv->hwdmaptr[1] = virt_to_bus ((void *) devpriv->dmabuf[1]); - devpriv->hwdmasize[1] = (1 << pages) * PAGE_SIZE; + /* grab our DMA */ + dma = 0; + devpriv->dma = dma; + if ((devpriv->irq_free == 0) && (devpriv->dma_rtc == 0)) + goto no_dma; /* if we haven't IRQ, we can't use DMA */ + + if (this_board->DMAbits != 0) { /* board support DMA */ + dma = it->options[2]; + if (dma < 1) + goto no_dma; /* DMA disabled */ + + if (((1 << dma) & this_board->DMAbits) == 0) { + rt_printk(", DMA is out of allowed range, FAIL!\n"); + return -EINVAL; /* Bad DMA */ + } + ret = request_dma(dma, "pcl816"); + if (ret) { + rt_printk(", unable to allocate DMA %u, FAIL!\n", dma); + return -EBUSY; /* DMA isn't free */ + } + + devpriv->dma = dma; + rt_printk(", dma=%u", dma); + pages = 2; /* we need 16KB */ + devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages); + + if (!devpriv->dmabuf[0]) { + rt_printk(", unable to allocate DMA buffer, FAIL!\n"); + /* maybe experiment with try_to_free_pages() will help .... */ + return -EBUSY; /* no buffer :-( */ + } + devpriv->dmapages[0] = pages; + devpriv->hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]); + devpriv->hwdmasize[0] = (1 << pages) * PAGE_SIZE; + //rt_printk("%d %d %ld, ",devpriv->dmapages[0],devpriv->hwdmasize[0],PAGE_SIZE); + + if (devpriv->dma_rtc == 0) { // we must do duble buff :-( + devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages); + if (!devpriv->dmabuf[1]) { + rt_printk + (", unable to allocate DMA buffer, FAIL!\n"); + return -EBUSY; + } + devpriv->dmapages[1] = pages; + devpriv->hwdmaptr[1] = + virt_to_bus((void *)devpriv->dmabuf[1]); + devpriv->hwdmasize[1] = (1 << pages) * PAGE_SIZE; + } } - } -no_dma: + no_dma: /* if (this_board->n_aochan > 0) subdevs[1] = COMEDI_SUBD_AO; @@ -1170,76 +1173,75 @@ no_dma: if (this_board->n_dochan > 0) subdevs[3] = COMEDI_SUBD_DO; */ - if ((ret = alloc_subdevices (dev, 1)) < 0) - return ret; - - s = dev->subdevices + 0; - if (this_board->n_aichan > 0){ - s->type = COMEDI_SUBD_AI; - devpriv->sub_ai = s; - dev->read_subdev = s; - s->subdev_flags = SDF_READABLE | SDF_CMD_READ; - s->n_chan = this_board->n_aichan; - s->subdev_flags |= SDF_DIFF; - //printk (", %dchans DIFF DAC - %d", s->n_chan, i); - s->maxdata = this_board->ai_maxdata; - s->len_chanlist = this_board->ai_chanlist; - s->range_table = this_board->ai_range_type; - s->cancel = pcl816_ai_cancel; - s->do_cmdtest = pcl816_ai_cmdtest; - s->do_cmd = pcl816_ai_cmd; - s->poll = pcl816_ai_poll; - s->insn_read = pcl816_ai_insn_read; - }else{ - s->type = COMEDI_SUBD_UNUSED; - } + if ((ret = alloc_subdevices(dev, 1)) < 0) + return ret; + + s = dev->subdevices + 0; + if (this_board->n_aichan > 0) { + s->type = COMEDI_SUBD_AI; + devpriv->sub_ai = s; + dev->read_subdev = s; + s->subdev_flags = SDF_READABLE | SDF_CMD_READ; + s->n_chan = this_board->n_aichan; + s->subdev_flags |= SDF_DIFF; + //printk (", %dchans DIFF DAC - %d", s->n_chan, i); + s->maxdata = this_board->ai_maxdata; + s->len_chanlist = this_board->ai_chanlist; + s->range_table = this_board->ai_range_type; + s->cancel = pcl816_ai_cancel; + s->do_cmdtest = pcl816_ai_cmdtest; + s->do_cmd = pcl816_ai_cmd; + s->poll = pcl816_ai_poll; + s->insn_read = pcl816_ai_insn_read; + } else { + s->type = COMEDI_SUBD_UNUSED; + } #if 0 - case COMEDI_SUBD_AO: - s->subdev_flags = SDF_WRITABLE | SDF_GROUND; - s->n_chan = this_board->n_aochan; - s->maxdata = this_board->ao_maxdata; - s->len_chanlist = this_board->ao_chanlist; - s->range_table = this_board->ao_range_type; - break; - - case COMEDI_SUBD_DI: - s->subdev_flags = SDF_READABLE; - s->n_chan = this_board->n_dichan; - s->maxdata = 1; - s->len_chanlist = this_board->n_dichan; - s->range_table = &range_digital; - break; - - case COMEDI_SUBD_DO: - s->subdev_flags = SDF_WRITABLE; - s->n_chan = this_board->n_dochan; - s->maxdata = 1; - s->len_chanlist = this_board->n_dochan; - s->range_table = &range_digital; - break; +case COMEDI_SUBD_AO: + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = this_board->n_aochan; + s->maxdata = this_board->ao_maxdata; + s->len_chanlist = this_board->ao_chanlist; + s->range_table = this_board->ao_range_type; + break; + +case COMEDI_SUBD_DI: + s->subdev_flags = SDF_READABLE; + s->n_chan = this_board->n_dichan; + s->maxdata = 1; + s->len_chanlist = this_board->n_dichan; + s->range_table = &range_digital; + break; + +case COMEDI_SUBD_DO: + s->subdev_flags = SDF_WRITABLE; + s->n_chan = this_board->n_dochan; + s->maxdata = 1; + s->len_chanlist = this_board->n_dochan; + s->range_table = &range_digital; + break; #endif - pcl816_reset (dev); + pcl816_reset(dev); - rt_printk ("\n"); + rt_printk("\n"); - return 0; + return 0; } - /* ============================================================================== Removes device */ -static int -pcl816_detach (comedi_device * dev) +static int pcl816_detach(comedi_device * dev) { - DEBUG(rt_printk("comedi%d: pcl816: remove\n", dev->minor);) - free_resources (dev); + DEBUG(rt_printk("comedi%d: pcl816: remove\n", dev->minor); + ) + free_resources(dev); #ifdef unused - if (devpriv->dma_rtc) - RTC_lock--; + if (devpriv->dma_rtc) + RTC_lock--; #endif - return 0; + return 0; } diff --git a/comedi/drivers/pcl818.c b/comedi/drivers/pcl818.c index 73753331..263dc6a1 100644 --- a/comedi/drivers/pcl818.c +++ b/comedi/drivers/pcl818.c @@ -195,162 +195,172 @@ A word or two about DMA. Driver support DMA operations at two ways: #define MAGIC_DMA_WORD 0x5a5a static const comedi_lrange range_pcl818h_ai = { 9, { - 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), - 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), + BIP_RANGE(10), + } +}; static const comedi_lrange range_pcl818hg_ai = { 10, { - BIP_RANGE(5), - BIP_RANGE(0.5), - BIP_RANGE(0.05), - BIP_RANGE(0.005), - UNI_RANGE(10), - UNI_RANGE(1), - UNI_RANGE(0.1), - UNI_RANGE(0.01), - BIP_RANGE(10), - BIP_RANGE(1), - BIP_RANGE(0.1), - BIP_RANGE(0.01), -}}; + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.005), + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.01), + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.01), + } +}; static const comedi_lrange range_pcl818l_l_ai = { 4, { - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), - BIP_RANGE(0.625), -}}; + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + BIP_RANGE(0.625), + } +}; static const comedi_lrange range_pcl818l_h_ai = { 4, { - BIP_RANGE(10), - BIP_RANGE(5), - BIP_RANGE(2.5), - BIP_RANGE(1.25), -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25), + } +}; -static const comedi_lrange range718_bipolar1 = { 1, { BIP_RANGE(1), }}; -static const comedi_lrange range718_bipolar0_5 = { 1, { BIP_RANGE(0.5), }}; -static const comedi_lrange range718_unipolar2 = { 1, { UNI_RANGE(2), }}; -static const comedi_lrange range718_unipolar1 = { 1, { BIP_RANGE(1), }}; +static const comedi_lrange range718_bipolar1 = { 1, {BIP_RANGE(1),} }; +static const comedi_lrange range718_bipolar0_5 = { 1, {BIP_RANGE(0.5),} }; +static const comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} }; +static const comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} }; -static int pcl818_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl818_detach(comedi_device *dev); +static int pcl818_attach(comedi_device * dev, comedi_devconfig * it); +static int pcl818_detach(comedi_device * dev); #ifdef unused -static int RTC_lock = 0; /* RTC lock */ -static int RTC_timer_lock = 0; /* RTC int lock */ +static int RTC_lock = 0; /* RTC lock */ +static int RTC_timer_lock = 0; /* RTC int lock */ #endif typedef struct { - const char *name; // driver name - int n_ranges; // len of range list - int n_aichan_se; // num of A/D chans in single ended mode - int n_aichan_diff; // num of A/D chans in diferencial mode - unsigned int ns_min; // minimal alllowed delay between samples (in ns) - int n_aochan; // num of D/A chans - int n_dichan; // num of DI chans - int n_dochan; // num of DO chans - const comedi_lrange *ai_range_type; // default A/D rangelist - const comedi_lrange *ao_range_type; // default D/A rangelist - unsigned int io_range; // len of IO space - unsigned int IRQbits; // allowed interrupts - unsigned int DMAbits; // allowed DMA chans - int ai_maxdata; // maxdata for A/D - int ao_maxdata; // maxdata for D/A - unsigned char fifo; // 1=board has FIFO - int is_818; + const char *name; // driver name + int n_ranges; // len of range list + int n_aichan_se; // num of A/D chans in single ended mode + int n_aichan_diff; // num of A/D chans in diferencial mode + unsigned int ns_min; // minimal alllowed delay between samples (in ns) + int n_aochan; // num of D/A chans + int n_dichan; // num of DI chans + int n_dochan; // num of DO chans + const comedi_lrange *ai_range_type; // default A/D rangelist + const comedi_lrange *ao_range_type; // default D/A rangelist + unsigned int io_range; // len of IO space + unsigned int IRQbits; // allowed interrupts + unsigned int DMAbits; // allowed DMA chans + int ai_maxdata; // maxdata for A/D + int ao_maxdata; // maxdata for D/A + unsigned char fifo; // 1=board has FIFO + int is_818; } boardtype; -static const boardtype boardtypes[] = -{ - {"pcl818l", 4, 16, 8, 25000, 1, 16, 16, &range_pcl818l_l_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 0, 1 }, - {"pcl818h", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 0, 1 }, - {"pcl818hd", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1, 1 }, - {"pcl818hg", 12, 16, 8, 10000, 1, 16, 16, &range_pcl818hg_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1, 1 }, - {"pcl818", 9, 16, 8, 10000, 2, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 0, 1 }, - {"pcl718", 1, 16, 8, 16000, 2, 16, 16, &range_unipolar5, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 0, 0 }, +static const boardtype boardtypes[] = { + {"pcl818l", 4, 16, 8, 25000, 1, 16, 16, &range_pcl818l_l_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 0, 1}, + {"pcl818h", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 0, 1}, + {"pcl818hd", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 1, 1}, + {"pcl818hg", 12, 16, 8, 10000, 1, 16, 16, &range_pcl818hg_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 1, 1}, + {"pcl818", 9, 16, 8, 10000, 2, 16, 16, &range_pcl818h_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 0, 1}, + {"pcl718", 1, 16, 8, 16000, 2, 16, 16, &range_unipolar5, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 0, 0}, /* pcm3718 */ - {"pcm3718", 9, 16, 8, 10000, 0, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 0, 1 /* XXX ? */ }, + {"pcm3718", 9, 16, 8, 10000, 0, 16, 16, &range_pcl818h_ai, + &range_unipolar5, PCLx1x_RANGE, 0x00fc, + 0x0a, 0xfff, 0xfff, 0, 1 /* XXX ? */ }, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) -static comedi_driver driver_pcl818={ - driver_name: "pcl818", - module: THIS_MODULE, - attach: pcl818_attach, - detach: pcl818_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static comedi_driver driver_pcl818 = { + driver_name:"pcl818", + module:THIS_MODULE, + attach:pcl818_attach, + detach:pcl818_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; -COMEDI_INITCLEANUP(driver_pcl818); +COMEDI_INITCLEANUP(driver_pcl818); typedef struct { - unsigned int dma; // used DMA, 0=don't use DMA - int dma_rtc; // 1=RTC used with DMA, 0=no RTC alloc - unsigned int io_range; + unsigned int dma; // used DMA, 0=don't use DMA + int dma_rtc; // 1=RTC used with DMA, 0=no RTC alloc + unsigned int io_range; #ifdef unused - unsigned long rtc_iobase; // RTC port region - unsigned int rtc_iosize; - unsigned int rtc_irq; - struct timer_list rtc_irq_timer;// timer for RTC sanity check - unsigned long rtc_freq; // RTC int freq - int rtc_irq_blocked;// 1=we now do AI with DMA&RTC + unsigned long rtc_iobase; // RTC port region + unsigned int rtc_iosize; + unsigned int rtc_irq; + struct timer_list rtc_irq_timer; // timer for RTC sanity check + unsigned long rtc_freq; // RTC int freq + int rtc_irq_blocked; // 1=we now do AI with DMA&RTC #endif - unsigned long dmabuf[2]; // pointers to begin of DMA buffers - unsigned int dmapages[2]; // len of DMA buffers in PAGE_SIZEs - unsigned int hwdmaptr[2]; // hardware address of DMA buffers - unsigned int hwdmasize[2]; // len of DMA buffers in Bytes - unsigned int dmasamplsize; // size in samples hwdmasize[0]/2 - unsigned int last_top_dma; // DMA pointer in last RTC int - int next_dma_buf; // which DMA buffer will be used next round - long dma_runs_to_end;// how many we must permorm DMA transfer to end of record - unsigned long last_dma_run; // how many bytes we must transfer on last DMA page - unsigned char neverending_ai; // if=1, then we do neverending record (you must use cancel()) - unsigned int ns_min; // manimal alllowed delay between samples (in us) for actual card - int i8253_osc_base; // 1/frequency of on board oscilator in ns - int irq_free; // 1=have allocated IRQ - int irq_blocked; // 1=IRQ now uses any subdev - int irq_was_now_closed;// when IRQ finish, there's stored int818_mode for last interrupt - int ai_mode; // who now uses IRQ - 1=AI1 int, 2=AI1 dma, 3=AI3 int, 4AI3 dma + unsigned long dmabuf[2]; // pointers to begin of DMA buffers + unsigned int dmapages[2]; // len of DMA buffers in PAGE_SIZEs + unsigned int hwdmaptr[2]; // hardware address of DMA buffers + unsigned int hwdmasize[2]; // len of DMA buffers in Bytes + unsigned int dmasamplsize; // size in samples hwdmasize[0]/2 + unsigned int last_top_dma; // DMA pointer in last RTC int + int next_dma_buf; // which DMA buffer will be used next round + long dma_runs_to_end; // how many we must permorm DMA transfer to end of record + unsigned long last_dma_run; // how many bytes we must transfer on last DMA page + unsigned char neverending_ai; // if=1, then we do neverending record (you must use cancel()) + unsigned int ns_min; // manimal alllowed delay between samples (in us) for actual card + int i8253_osc_base; // 1/frequency of on board oscilator in ns + int irq_free; // 1=have allocated IRQ + int irq_blocked; // 1=IRQ now uses any subdev + int irq_was_now_closed; // when IRQ finish, there's stored int818_mode for last interrupt + int ai_mode; // who now uses IRQ - 1=AI1 int, 2=AI1 dma, 3=AI3 int, 4AI3 dma comedi_subdevice *last_int_sub; // ptr to subdevice which now finish - int ai_act_scan; // how many scans we finished - int ai_act_chan; // actual position in actual scan - unsigned int act_chanlist[16];// MUX setting for actual AI operations - unsigned int act_chanlist_len;// how long is actual MUX list - unsigned int act_chanlist_pos;// actual position in MUX list - unsigned int ai_scans; // len of scanlist - unsigned int ai_n_chan; // how many channels is measured - unsigned int *ai_chanlist; // actaul chanlist - unsigned int ai_flags; // flaglist - unsigned int ai_data_len; // len of data buffer - sampl_t *ai_data; // data buffer - unsigned int ai_timer1; // timers - unsigned int ai_timer2; + int ai_act_scan; // how many scans we finished + int ai_act_chan; // actual position in actual scan + unsigned int act_chanlist[16]; // MUX setting for actual AI operations + unsigned int act_chanlist_len; // how long is actual MUX list + unsigned int act_chanlist_pos; // actual position in MUX list + unsigned int ai_scans; // len of scanlist + unsigned int ai_n_chan; // how many channels is measured + unsigned int *ai_chanlist; // actaul chanlist + unsigned int ai_flags; // flaglist + unsigned int ai_data_len; // len of data buffer + sampl_t *ai_data; // data buffer + unsigned int ai_timer1; // timers + unsigned int ai_timer2; comedi_subdevice *sub_ai; // ptr to AI subdevice - unsigned char usefifo; // 1=use fifo - lsampl_t ao_readback[2]; + unsigned char usefifo; // 1=use fifo + lsampl_t ao_readback[2]; } pcl818_private; - -static const unsigned int muxonechan[] ={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, // used for gain list programming - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; +static const unsigned int muxonechan[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, // used for gain list programming + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff +}; #define devpriv ((pcl818_private *)dev->private) #define this_board ((const boardtype *)dev->board_ptr) @@ -358,13 +368,14 @@ static const unsigned int muxonechan[] ={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x /* ============================================================================== */ -static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan, unsigned int seglen); -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan); +static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan, unsigned int seglen); +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan); static int pcl818_ai_cancel(comedi_device * dev, comedi_subdevice * s); -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2); +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2); #ifdef unused static int set_rtc_irq_bit(unsigned char bit); @@ -376,44 +387,42 @@ static int rtc_setfreq_irq(int freq); ============================================================================== ANALOG INPUT MODE0, 818 cards, slow version */ -static int pcl818_ai_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl818_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; - int timeout; + int timeout; /* software trigger, DMA and INT off */ - outb(0, dev->iobase+PCL818_CONTROL); + outb(0, dev->iobase + PCL818_CONTROL); /* select channel */ - outb(muxonechan[CR_CHAN(insn->chanspec)], - dev->iobase+PCL818_MUX); + outb(muxonechan[CR_CHAN(insn->chanspec)], dev->iobase + PCL818_MUX); /* select gain */ - outb(CR_RANGE(insn->chanspec), - dev->iobase+PCL818_RANGE); + outb(CR_RANGE(insn->chanspec), dev->iobase + PCL818_RANGE); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* clear INT (conversion end) flag */ - outb(0, dev->iobase+PCL818_CLRINT); + outb(0, dev->iobase + PCL818_CLRINT); /* start conversion */ - outb(0, dev->iobase+PCL818_AD_LO); + outb(0, dev->iobase + PCL818_AD_LO); - timeout=100; - while (timeout--) { + timeout = 100; + while (timeout--) { if (inb(dev->iobase + PCL818_STATUS) & 0x10) goto conv_finish; comedi_udelay(1); - } - comedi_error(dev,"A/D insn timeout"); + } + comedi_error(dev, "A/D insn timeout"); /* clear INT (conversion end) flag */ - outb(0, dev->iobase+PCL818_CLRINT); - return -EIO; + outb(0, dev->iobase + PCL818_CLRINT); + return -EIO; -conv_finish: - data[n] = ((inb(dev->iobase + PCL818_AD_HI) << 4) | + conv_finish: + data[n] = ((inb(dev->iobase + PCL818_AD_HI) << 4) | (inb(dev->iobase + PCL818_AD_LO) >> 4)); } @@ -425,31 +434,31 @@ conv_finish: ANALOG OUTPUT MODE0, 818 cards only one sample per call is supported */ -static int pcl818_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl818_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { data[n] = devpriv->ao_readback[chan]; } return n; } -static int pcl818_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl818_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int n; int chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { devpriv->ao_readback[chan] = data[n]; - outb((data[n] & 0x000f) << 4, dev->iobase+ - (chan)?PCL718_DA2_LO:PCL818_DA_LO); - outb((data[n] & 0x0ff0) >> 4, dev->iobase+ - (chan)?PCL718_DA2_HI:PCL818_DA_HI); + outb((data[n] & 0x000f) << 4, dev->iobase + + (chan) ? PCL718_DA2_LO : PCL818_DA_LO); + outb((data[n] & 0x0ff0) >> 4, dev->iobase + + (chan) ? PCL718_DA2_HI : PCL818_DA_HI); } return n; @@ -461,13 +470,14 @@ static int pcl818_ao_insn_write(comedi_device *dev, comedi_subdevice *s, only one sample per call is supported */ -static int pcl818_di_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl818_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + PCL818_DI_LO) | - (inb(dev->iobase + PCL818_DI_HI) << 8); + (inb(dev->iobase + PCL818_DI_HI) << 8); return 2; } @@ -478,16 +488,17 @@ static int pcl818_di_insn_bits(comedi_device *dev, comedi_subdevice *s, only one sample per call is supported */ -static int pcl818_do_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcl818_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; s->state &= ~data[0]; - s->state |= (data[0]&data[1]); + s->state |= (data[0] & data[1]); outb(s->state & 0xff, dev->iobase + PCL818_DO_LO); - outb((s->state >> 8), dev->iobase + PCL818_DO_HI); + outb((s->state >> 8), dev->iobase + PCL818_DO_HI); data[1] = s->state; @@ -504,28 +515,31 @@ static irqreturn_t interrupt_pcl818_ai_mode13_int(int irq, void *d) comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; int low; - int timeout=50; /* wait max 50us */ + int timeout = 50; /* wait max 50us */ while (timeout--) { - if (inb(dev->iobase + PCL818_STATUS) & 0x10) goto conv_finish; + if (inb(dev->iobase + PCL818_STATUS) & 0x10) + goto conv_finish; comedi_udelay(1); } - outb(0,dev->iobase+PCL818_STATUS); /* clear INT request */ - comedi_error(dev,"A/D mode1/3 IRQ without DRDY!"); - pcl818_ai_cancel(dev,s); + outb(0, dev->iobase + PCL818_STATUS); /* clear INT request */ + comedi_error(dev, "A/D mode1/3 IRQ without DRDY!"); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; -conv_finish: - low=inb(dev->iobase + PCL818_AD_LO); - comedi_buf_put( s->async, - ((inb(dev->iobase + PCL818_AD_HI) << 4) | (low >> 4)) ); // get one sample - outb(0,dev->iobase+PCL818_CLRINT); /* clear INT request */ - - if ((low & 0xf)!=devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! - rt_printk("comedi: A/D mode1/3 IRQ - channel dropout %x!=%x !\n",(low & 0xf),devpriv->act_chanlist[devpriv->act_chanlist_pos]); - pcl818_ai_cancel(dev,s); + conv_finish: + low = inb(dev->iobase + PCL818_AD_LO); + comedi_buf_put(s->async, ((inb(dev->iobase + PCL818_AD_HI) << 4) | (low >> 4))); // get one sample + outb(0, dev->iobase + PCL818_CLRINT); /* clear INT request */ + + if ((low & 0xf) != devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! + rt_printk + ("comedi: A/D mode1/3 IRQ - channel dropout %x!=%x !\n", + (low & 0xf), + devpriv->act_chanlist[devpriv->act_chanlist_pos]); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; @@ -535,9 +549,9 @@ conv_finish: devpriv->ai_act_scan--; } - if (!devpriv->neverending_ai){ - if ( devpriv->ai_act_scan == 0 ) { /* all data sampled */ - pcl818_ai_cancel(dev,s); + if (!devpriv->neverending_ai) { + if (devpriv->ai_act_scan == 0) { /* all data sampled */ + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; } } @@ -553,50 +567,60 @@ static irqreturn_t interrupt_pcl818_ai_mode13_dma(int irq, void *d) { comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; - int i,len,bufptr; + int i, len, bufptr; unsigned long flags; sampl_t *ptr; disable_dma(devpriv->dma); - devpriv->next_dma_buf=1-devpriv->next_dma_buf; - if ((devpriv->dma_runs_to_end)>-1 || devpriv->neverending_ai) { // switch dma bufs + devpriv->next_dma_buf = 1 - devpriv->next_dma_buf; + if ((devpriv->dma_runs_to_end) > -1 || devpriv->neverending_ai) { // switch dma bufs set_dma_mode(devpriv->dma, DMA_MODE_READ); - flags=claim_dma_lock(); - set_dma_addr(devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]); - if (devpriv->dma_runs_to_end || devpriv->neverending_ai) { set_dma_count(devpriv->dma, devpriv->hwdmasize[devpriv->next_dma_buf]); } - else { set_dma_count(devpriv->dma, devpriv->last_dma_run); } + flags = claim_dma_lock(); + set_dma_addr(devpriv->dma, + devpriv->hwdmaptr[devpriv->next_dma_buf]); + if (devpriv->dma_runs_to_end || devpriv->neverending_ai) { + set_dma_count(devpriv->dma, + devpriv->hwdmasize[devpriv->next_dma_buf]); + } else { + set_dma_count(devpriv->dma, devpriv->last_dma_run); + } release_dma_lock(flags); enable_dma(devpriv->dma); } rt_printk("comedi: A/D mode1/3 IRQ \n"); devpriv->dma_runs_to_end--; - outb(0,dev->iobase+PCL818_CLRINT); /* clear INT request */ - ptr=(sampl_t *)devpriv->dmabuf[1-devpriv->next_dma_buf]; - - len=devpriv->hwdmasize[0] >> 1; - bufptr=0; - - for (i=0;iact_chanlist[devpriv->act_chanlist_pos]) { // dropout! - rt_printk("comedi: A/D mode1/3 DMA - channel dropout %d(card)!=%d(chanlist) at %d !\n",(ptr[bufptr] & 0xf),devpriv->act_chanlist[devpriv->act_chanlist_pos], devpriv->act_chanlist_pos); - pcl818_ai_cancel(dev,s); + outb(0, dev->iobase + PCL818_CLRINT); /* clear INT request */ + ptr = (sampl_t *) devpriv->dmabuf[1 - devpriv->next_dma_buf]; + + len = devpriv->hwdmasize[0] >> 1; + bufptr = 0; + + for (i = 0; i < len; i++) { + if ((ptr[bufptr] & 0xf) != devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! + rt_printk + ("comedi: A/D mode1/3 DMA - channel dropout %d(card)!=%d(chanlist) at %d !\n", + (ptr[bufptr] & 0xf), + devpriv->act_chanlist[devpriv-> + act_chanlist_pos], + devpriv->act_chanlist_pos); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - comedi_buf_put( s->async, ptr[bufptr++] >> 4 ); // get one sample + comedi_buf_put(s->async, ptr[bufptr++] >> 4); // get one sample devpriv->act_chanlist_pos++; - if ( devpriv->act_chanlist_pos >= devpriv->act_chanlist_len ) { - devpriv->ai_act_scan--; - devpriv->act_chanlist_pos = 0; + if (devpriv->act_chanlist_pos >= devpriv->act_chanlist_len) { + devpriv->ai_act_scan--; + devpriv->act_chanlist_pos = 0; } if (!devpriv->neverending_ai) - if ( devpriv->ai_act_scan == 0 ) { /* all data sampled */ - pcl818_ai_cancel(dev,s); + if (devpriv->ai_act_scan == 0) { /* all data sampled */ + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); // printk("done int ai13 dma\n"); @@ -604,7 +628,8 @@ static irqreturn_t interrupt_pcl818_ai_mode13_dma(int irq, void *d) } } - if (len>0) comedi_event(dev, s); + if (len > 0) + comedi_event(dev, s); return IRQ_HANDLED; } @@ -618,64 +643,74 @@ static irqreturn_t interrupt_pcl818_ai_mode13_dma_rtc(int irq, void *d) comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; unsigned long tmp; - unsigned int top1,top2,i,bufptr; + unsigned int top1, top2, i, bufptr; long ofs_dats; - sampl_t *dmabuf=(sampl_t *)devpriv->dmabuf[0]; + sampl_t *dmabuf = (sampl_t *) devpriv->dmabuf[0]; //outb(2,0x378); - switch(devpriv->ai_mode) { + switch (devpriv->ai_mode) { case INT_TYPE_AI1_DMA_RTC: case INT_TYPE_AI3_DMA_RTC: tmp = (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); - mod_timer(&devpriv->rtc_irq_timer, jiffies + HZ/devpriv->rtc_freq + 2*HZ/100); - - for (i=0; i<10; i++) { - top1=get_dma_residue(devpriv->dma); - top2=get_dma_residue(devpriv->dma); - if (top1==top2) break; + mod_timer(&devpriv->rtc_irq_timer, + jiffies + HZ / devpriv->rtc_freq + 2 * HZ / 100); + + for (i = 0; i < 10; i++) { + top1 = get_dma_residue(devpriv->dma); + top2 = get_dma_residue(devpriv->dma); + if (top1 == top2) + break; } - if (top1!=top2) return IRQ_HANDLED; - top1=devpriv->hwdmasize[0]-top1; // where is now DMA in buffer - top1>>=1; - ofs_dats=top1-devpriv->last_top_dma; // new samples from last call - if (ofs_dats<0) ofs_dats=(devpriv->dmasamplsize)+ofs_dats; - if (!ofs_dats) return IRQ_HANDLED; // exit=no new samples from last call + if (top1 != top2) + return IRQ_HANDLED; + top1 = devpriv->hwdmasize[0] - top1; // where is now DMA in buffer + top1 >>= 1; + ofs_dats = top1 - devpriv->last_top_dma; // new samples from last call + if (ofs_dats < 0) + ofs_dats = (devpriv->dmasamplsize) + ofs_dats; + if (!ofs_dats) + return IRQ_HANDLED; // exit=no new samples from last call // obsluz data - i=devpriv->last_top_dma-1; - i&=(devpriv->dmasamplsize-1); + i = devpriv->last_top_dma - 1; + i &= (devpriv->dmasamplsize - 1); - if (dmabuf[i]!=MAGIC_DMA_WORD) { // DMA overflow! - comedi_error(dev,"A/D mode1/3 DMA buffer overflow!"); + if (dmabuf[i] != MAGIC_DMA_WORD) { // DMA overflow! + comedi_error(dev, "A/D mode1/3 DMA buffer overflow!"); //rt_printk("I %d dmabuf[i] %d %d\n",i,dmabuf[i],devpriv->dmasamplsize); - pcl818_ai_cancel(dev,s); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } //rt_printk("r %ld ",ofs_dats); - bufptr=devpriv->last_top_dma; + bufptr = devpriv->last_top_dma; - for (i=0; iact_chanlist[devpriv->act_chanlist_pos]) { // dropout! - rt_printk("comedi: A/D mode1/3 DMA - channel dropout %d!=%d !\n",(dmabuf[bufptr] & 0xf),devpriv->act_chanlist[devpriv->act_chanlist_pos]); - pcl818_ai_cancel(dev,s); - s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; + for (i = 0; i < ofs_dats; i++) { + if ((dmabuf[bufptr] & 0xf) != devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! + rt_printk + ("comedi: A/D mode1/3 DMA - channel dropout %d!=%d !\n", + (dmabuf[bufptr] & 0xf), + devpriv->act_chanlist[devpriv-> + act_chanlist_pos]); + pcl818_ai_cancel(dev, s); + s->async->events |= + COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - comedi_buf_put( s->async, dmabuf[bufptr++] >> 4); // get one sample - bufptr&=(devpriv->dmasamplsize-1); + comedi_buf_put(s->async, dmabuf[bufptr++] >> 4); // get one sample + bufptr &= (devpriv->dmasamplsize - 1); - if(s->async->cur_chan == 0){ + if (s->async->cur_chan == 0) { devpriv->ai_act_scan--; } if (!devpriv->neverending_ai) - if ( devpriv->ai_act_scan == 0 ) { /* all data sampled */ - pcl818_ai_cancel(dev,s); + if (devpriv->ai_act_scan == 0) { /* all data sampled */ + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); //printk("done int ai13 dma\n"); @@ -683,10 +718,10 @@ static irqreturn_t interrupt_pcl818_ai_mode13_dma_rtc(int irq, void *d) } } - devpriv->last_top_dma=bufptr; + devpriv->last_top_dma = bufptr; bufptr--; - bufptr&=(devpriv->dmasamplsize-1); - dmabuf[bufptr]=MAGIC_DMA_WORD; + bufptr &= (devpriv->dmasamplsize - 1); + dmabuf[bufptr] = MAGIC_DMA_WORD; comedi_event(dev, s); //outb(0,0x378); return IRQ_HANDLED; @@ -705,57 +740,65 @@ static irqreturn_t interrupt_pcl818_ai_mode13_fifo(int irq, void *d) { comedi_device *dev = d; comedi_subdevice *s = dev->subdevices + 0; - int i,len,lo; + int i, len, lo; - outb(0, dev->iobase + PCL818_FI_INTCLR); // clear fifo int request + outb(0, dev->iobase + PCL818_FI_INTCLR); // clear fifo int request - lo=inb(dev->iobase + PCL818_FI_STATUS); + lo = inb(dev->iobase + PCL818_FI_STATUS); - if (lo&4) { - comedi_error(dev,"A/D mode1/3 FIFO overflow!"); - pcl818_ai_cancel(dev,s); + if (lo & 4) { + comedi_error(dev, "A/D mode1/3 FIFO overflow!"); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - if (lo&1) { - comedi_error(dev,"A/D mode1/3 FIFO interrupt without data!"); - pcl818_ai_cancel(dev,s); + if (lo & 1) { + comedi_error(dev, "A/D mode1/3 FIFO interrupt without data!"); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - if (lo&2) { len=512; } - else { len=0; } + if (lo & 2) { + len = 512; + } else { + len = 0; + } - for (i=0;iiobase + PCL818_FI_DATALO); - if ((lo & 0xf)!=devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! - rt_printk("comedi: A/D mode1/3 FIFO - channel dropout %d!=%d !\n",(lo & 0xf),devpriv->act_chanlist[devpriv->act_chanlist_pos]); - pcl818_ai_cancel(dev,s); + for (i = 0; i < len; i++) { + lo = inb(dev->iobase + PCL818_FI_DATALO); + if ((lo & 0xf) != devpriv->act_chanlist[devpriv->act_chanlist_pos]) { // dropout! + rt_printk + ("comedi: A/D mode1/3 FIFO - channel dropout %d!=%d !\n", + (lo & 0xf), + devpriv->act_chanlist[devpriv-> + act_chanlist_pos]); + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; comedi_event(dev, s); return IRQ_HANDLED; } - comedi_buf_put( s->async, (lo >> 4)|(inb(dev->iobase + PCL818_FI_DATAHI) << 4) ); // get one sample + comedi_buf_put(s->async, (lo >> 4) | (inb(dev->iobase + PCL818_FI_DATAHI) << 4)); // get one sample - if(s->async->cur_chan == 0){ + if (s->async->cur_chan == 0) { devpriv->ai_act_scan--; } if (!devpriv->neverending_ai) - if ( devpriv->ai_act_scan == 0 ) { /* all data sampled */ - pcl818_ai_cancel(dev,s); + if (devpriv->ai_act_scan == 0) { /* all data sampled */ + pcl818_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; comedi_event(dev, s); return IRQ_HANDLED; } } - if (len>0) comedi_event(dev, s); + if (len > 0) + comedi_event(dev, s); return IRQ_HANDLED; } @@ -767,12 +810,10 @@ static irqreturn_t interrupt_pcl818(int irq, void *d PT_REGS_ARG) { comedi_device *dev = d; - if(!dev->attached) - { + if (!dev->attached) { comedi_error(dev, "premature interrupt"); return IRQ_HANDLED; } - //rt_printk("I\n"); switch (devpriv->ai_mode) { @@ -794,31 +835,34 @@ static irqreturn_t interrupt_pcl818(int irq, void *d PT_REGS_ARG) break; } - outb(0,dev->iobase+PCL818_CLRINT); /* clear INT request */ + outb(0, dev->iobase + PCL818_CLRINT); /* clear INT request */ - if ((!dev->irq)||(!devpriv->irq_free)||(!devpriv->irq_blocked)||(!devpriv->ai_mode)) { + if ((!dev->irq) || (!devpriv->irq_free) || (!devpriv->irq_blocked) + || (!devpriv->ai_mode)) { if (devpriv->irq_was_now_closed) { - if ( devpriv->neverending_ai && - (devpriv->ai_mode == INT_TYPE_AI1_DMA || devpriv->ai_mode == INT_TYPE_AI3_DMA) ) { + if (devpriv->neverending_ai && + (devpriv->ai_mode == INT_TYPE_AI1_DMA + || devpriv->ai_mode == + INT_TYPE_AI3_DMA)) { /* we had neverending ai but ai_cancel() has been called the cleanup from ai_cancel() has been delayed until know because the card doesn't seem to like being reprogrammed while a DMA transfer is in progress - */ + */ comedi_subdevice *s = dev->subdevices + 0; devpriv->ai_mode = devpriv->irq_was_now_closed; - devpriv->irq_was_now_closed=0; + devpriv->irq_was_now_closed = 0; devpriv->neverending_ai = 0; pcl818_ai_cancel(dev, s); } - devpriv->irq_was_now_closed=0; + devpriv->irq_was_now_closed = 0; return IRQ_HANDLED; } - comedi_error(dev,"bad IRQ!"); + comedi_error(dev, "bad IRQ!"); return IRQ_NONE; } - comedi_error(dev,"IRQ from unknow source!"); + comedi_error(dev, "IRQ from unknow source!"); return IRQ_NONE; } @@ -826,38 +870,40 @@ static irqreturn_t interrupt_pcl818(int irq, void *d PT_REGS_ARG) ============================================================================== ANALOG INPUT MODE 1 or 3 DMA , 818 cards */ -static void pcl818_ai_mode13dma_int(int mode, comedi_device * dev, comedi_subdevice * s) +static void pcl818_ai_mode13dma_int(int mode, comedi_device * dev, + comedi_subdevice * s) { - unsigned int flags; - unsigned int bytes; + unsigned int flags; + unsigned int bytes; rt_printk("mode13dma_int, mode: %d\n", mode); - disable_dma(devpriv->dma); // disable dma - bytes=devpriv->hwdmasize[0]; - if (!devpriv->neverending_ai) { - bytes=devpriv->ai_n_chan*devpriv->ai_scans*sizeof(sampl_t); // how many - devpriv->dma_runs_to_end=bytes / devpriv->hwdmasize[0]; // how many DMA pages we must fiil - devpriv->last_dma_run=bytes % devpriv->hwdmasize[0]; //on last dma transfer must be moved + disable_dma(devpriv->dma); // disable dma + bytes = devpriv->hwdmasize[0]; + if (!devpriv->neverending_ai) { + bytes = devpriv->ai_n_chan * devpriv->ai_scans * sizeof(sampl_t); // how many + devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize[0]; // how many DMA pages we must fiil + devpriv->last_dma_run = bytes % devpriv->hwdmasize[0]; //on last dma transfer must be moved devpriv->dma_runs_to_end--; - if (devpriv->dma_runs_to_end>=0) bytes=devpriv->hwdmasize[0]; + if (devpriv->dma_runs_to_end >= 0) + bytes = devpriv->hwdmasize[0]; } - devpriv->next_dma_buf=0; + devpriv->next_dma_buf = 0; set_dma_mode(devpriv->dma, DMA_MODE_READ); - flags=claim_dma_lock(); - clear_dma_ff(devpriv->dma); - set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); - set_dma_count(devpriv->dma, bytes); - release_dma_lock(flags); - enable_dma(devpriv->dma); - - if (mode==1) { - devpriv->ai_mode=INT_TYPE_AI1_DMA; - outb(0x87 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ+DMA */ - } else { - devpriv->ai_mode=INT_TYPE_AI3_DMA; - outb(0x86 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ+DMA */ - }; + flags = claim_dma_lock(); + clear_dma_ff(devpriv->dma); + set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); + set_dma_count(devpriv->dma, bytes); + release_dma_lock(flags); + enable_dma(devpriv->dma); + + if (mode == 1) { + devpriv->ai_mode = INT_TYPE_AI1_DMA; + outb(0x87 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ+DMA */ + } else { + devpriv->ai_mode = INT_TYPE_AI3_DMA; + outb(0x86 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ+DMA */ + }; } #ifdef unused @@ -865,38 +911,40 @@ static void pcl818_ai_mode13dma_int(int mode, comedi_device * dev, comedi_subdev ============================================================================== ANALOG INPUT MODE 1 or 3 DMA rtc, 818 cards */ -static void pcl818_ai_mode13dma_rtc(int mode, comedi_device * dev, comedi_subdevice * s) +static void pcl818_ai_mode13dma_rtc(int mode, comedi_device * dev, + comedi_subdevice * s) { - unsigned int flags; - sampl_t *pole; - - set_dma_mode(devpriv->dma, DMA_MODE_READ|DMA_AUTOINIT); - flags=claim_dma_lock(); - clear_dma_ff(devpriv->dma); - set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); - set_dma_count(devpriv->dma, devpriv->hwdmasize[0]); - release_dma_lock(flags); - enable_dma(devpriv->dma); - devpriv->last_top_dma=0; //devpriv->hwdmasize[0]; - pole=(sampl_t *)devpriv->dmabuf[0]; - devpriv->dmasamplsize=devpriv->hwdmasize[0]/2; - pole[devpriv->dmasamplsize-1]=MAGIC_DMA_WORD; + unsigned int flags; + sampl_t *pole; + + set_dma_mode(devpriv->dma, DMA_MODE_READ | DMA_AUTOINIT); + flags = claim_dma_lock(); + clear_dma_ff(devpriv->dma); + set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]); + set_dma_count(devpriv->dma, devpriv->hwdmasize[0]); + release_dma_lock(flags); + enable_dma(devpriv->dma); + devpriv->last_top_dma = 0; //devpriv->hwdmasize[0]; + pole = (sampl_t *) devpriv->dmabuf[0]; + devpriv->dmasamplsize = devpriv->hwdmasize[0] / 2; + pole[devpriv->dmasamplsize - 1] = MAGIC_DMA_WORD; #ifdef unused - devpriv->rtc_freq=rtc_setfreq_irq(2048); - devpriv->rtc_irq_timer.expires=jiffies + HZ/devpriv->rtc_freq + 2*HZ/100; - devpriv->rtc_irq_timer.data=(unsigned long)dev; - devpriv->rtc_irq_timer.function=rtc_dropped_irq; + devpriv->rtc_freq = rtc_setfreq_irq(2048); + devpriv->rtc_irq_timer.expires = + jiffies + HZ / devpriv->rtc_freq + 2 * HZ / 100; + devpriv->rtc_irq_timer.data = (unsigned long)dev; + devpriv->rtc_irq_timer.function = rtc_dropped_irq; - add_timer(&devpriv->rtc_irq_timer); + add_timer(&devpriv->rtc_irq_timer); #endif - if (mode==1) { - devpriv->int818_mode=INT_TYPE_AI1_DMA_RTC; - outb(0x07 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+DMA */ - } else { - devpriv->int818_mode=INT_TYPE_AI3_DMA_RTC; - outb(0x06 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+DMA */ - }; + if (mode == 1) { + devpriv->int818_mode = INT_TYPE_AI1_DMA_RTC; + outb(0x07 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+DMA */ + } else { + devpriv->int818_mode = INT_TYPE_AI3_DMA_RTC; + outb(0x06 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+DMA */ + }; } #endif @@ -904,172 +952,184 @@ static void pcl818_ai_mode13dma_rtc(int mode, comedi_device * dev, comedi_subdev ============================================================================== ANALOG INPUT MODE 1 or 3, 818 cards */ -static int pcl818_ai_cmd_mode(int mode, comedi_device * dev, comedi_subdevice * s) +static int pcl818_ai_cmd_mode(int mode, comedi_device * dev, + comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; - int divisor1, divisor2; + comedi_cmd *cmd = &s->async->cmd; + int divisor1, divisor2; unsigned int seglen; - rt_printk("pcl818_ai_cmd_mode()\n"); - if ((!dev->irq)&&(!devpriv->dma_rtc)) { - comedi_error(dev,"IRQ not defined!"); + rt_printk("pcl818_ai_cmd_mode()\n"); + if ((!dev->irq) && (!devpriv->dma_rtc)) { + comedi_error(dev, "IRQ not defined!"); return -EINVAL; - } + } - if (devpriv->irq_blocked) + if (devpriv->irq_blocked) return -EBUSY; - start_pacer(dev, -1, 0, 0); // stop pacer + start_pacer(dev, -1, 0, 0); // stop pacer seglen = check_channel_list(dev, s, devpriv->ai_chanlist, - devpriv->ai_n_chan); - if(seglen<1)return -EINVAL; - setup_channel_list(dev, s, devpriv->ai_chanlist, - devpriv->ai_n_chan,seglen); + devpriv->ai_n_chan); + if (seglen < 1) + return -EINVAL; + setup_channel_list(dev, s, devpriv->ai_chanlist, + devpriv->ai_n_chan, seglen); comedi_udelay(1); - devpriv->ai_act_scan=devpriv->ai_scans; - devpriv->ai_act_chan=0; - devpriv->irq_blocked=1; - devpriv->irq_was_now_closed=0; - devpriv->neverending_ai=0; - devpriv->act_chanlist_pos=0; - devpriv->dma_runs_to_end=0; - - if ((devpriv->ai_scans==0)||(devpriv->ai_scans==-1)) devpriv->neverending_ai=1; //well, user want neverending - - if (mode==1) { - i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,&divisor1,&divisor2,&cmd->convert_arg,TRIG_ROUND_NEAREST); - if (divisor1==1) { /* PCL718/818 crash if any divisor is set to 1 */ - divisor1=2; - divisor2/=2; + devpriv->ai_act_scan = devpriv->ai_scans; + devpriv->ai_act_chan = 0; + devpriv->irq_blocked = 1; + devpriv->irq_was_now_closed = 0; + devpriv->neverending_ai = 0; + devpriv->act_chanlist_pos = 0; + devpriv->dma_runs_to_end = 0; + + if ((devpriv->ai_scans == 0) || (devpriv->ai_scans == -1)) + devpriv->neverending_ai = 1; //well, user want neverending + + if (mode == 1) { + i8253_cascade_ns_to_timer(devpriv->i8253_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, TRIG_ROUND_NEAREST); + if (divisor1 == 1) { /* PCL718/818 crash if any divisor is set to 1 */ + divisor1 = 2; + divisor2 /= 2; } - if (divisor2==1) { - divisor2=2; - divisor1/=2; + if (divisor2 == 1) { + divisor2 = 2; + divisor1 /= 2; } } - outb(0 , dev->iobase + PCL818_CNTENABLE); /* enable pacer */ + outb(0, dev->iobase + PCL818_CNTENABLE); /* enable pacer */ - switch (devpriv->dma) { + switch (devpriv->dma) { case 1: // DMA case 3: - if (devpriv->dma_rtc==0) { pcl818_ai_mode13dma_int(mode, dev, s); } + if (devpriv->dma_rtc == 0) { + pcl818_ai_mode13dma_int(mode, dev, s); + } #ifdef unused - else { pcl818_ai_mode13dma_rtc(mode, dev, s); } + else { + pcl818_ai_mode13dma_rtc(mode, dev, s); + } #else - else { return -EINVAL; } + else { + return -EINVAL; + } #endif break; case 0: // IRQ // rt_printk("IRQ\n"); - if (mode==1) { - devpriv->ai_mode=INT_TYPE_AI1_INT; - outb(0x83 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ */ + if (mode == 1) { + devpriv->ai_mode = INT_TYPE_AI1_INT; + outb(0x83 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ */ } else { - devpriv->ai_mode=INT_TYPE_AI3_INT; - outb(0x82 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ */ + devpriv->ai_mode = INT_TYPE_AI3_INT; + outb(0x82 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ */ }; break; case -1: // FIFO outb(1, dev->iobase + PCL818_FI_ENABLE); // enable FIFO - if (mode==1) { - devpriv->ai_mode=INT_TYPE_AI1_FIFO; - outb(0x03, dev->iobase + PCL818_CONTROL); /* Pacer */ + if (mode == 1) { + devpriv->ai_mode = INT_TYPE_AI1_FIFO; + outb(0x03, dev->iobase + PCL818_CONTROL); /* Pacer */ } else { - devpriv->ai_mode=INT_TYPE_AI3_FIFO; + devpriv->ai_mode = INT_TYPE_AI3_FIFO; outb(0x02, dev->iobase + PCL818_CONTROL); - }; /* Ext trig */ + }; /* Ext trig */ break; - } + } - start_pacer(dev, mode, divisor1, divisor2); + start_pacer(dev, mode, divisor1, divisor2); #ifdef unused - switch(devpriv->ai_mode) { + switch (devpriv->ai_mode) { case INT_TYPE_AI1_DMA_RTC: case INT_TYPE_AI3_DMA_RTC: - set_rtc_irq_bit(1); /* start RTC */ + set_rtc_irq_bit(1); /* start RTC */ break; } #endif - rt_printk("pcl818_ai_cmd_mode() end\n"); + rt_printk("pcl818_ai_cmd_mode() end\n"); return 0; } - #ifdef unused /* ============================================================================== ANALOG OUTPUT MODE 1 or 3, 818 cards */ #ifdef PCL818_MODE13_AO -static int pcl818_ao_mode13(int mode, comedi_device * dev, comedi_subdevice * s, comedi_trig * it) +static int pcl818_ao_mode13(int mode, comedi_device * dev, comedi_subdevice * s, + comedi_trig * it) { - int divisor1, divisor2; - + int divisor1, divisor2; if (!dev->irq) { - comedi_error(dev,"IRQ not defined!"); + comedi_error(dev, "IRQ not defined!"); return -EINVAL; - } + } - if (devpriv->irq_blocked) + if (devpriv->irq_blocked) return -EBUSY; - start_pacer(dev, -1, 0, 0); // stop pacer - - devpriv->int13_act_scan=it->n; - devpriv->int13_act_chan=0; - devpriv->irq_blocked=1; - devpriv->irq_was_now_closed=0; - devpriv->neverending_ai=0; - devpriv->act_chanlist_pos=0; - - if (mode==1) { - i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,&divisor1,&divisor2,&it->trigvar,TRIG_ROUND_NEAREST); - if (divisor1==1) { /* PCL818 crash if any divisor is set to 1 */ - divisor1=2; - divisor2/=2; + start_pacer(dev, -1, 0, 0); // stop pacer + + devpriv->int13_act_scan = it->n; + devpriv->int13_act_chan = 0; + devpriv->irq_blocked = 1; + devpriv->irq_was_now_closed = 0; + devpriv->neverending_ai = 0; + devpriv->act_chanlist_pos = 0; + + if (mode == 1) { + i8253_cascade_ns_to_timer(devpriv->i8253_osc_base, &divisor1, + &divisor2, &it->trigvar, TRIG_ROUND_NEAREST); + if (divisor1 == 1) { /* PCL818 crash if any divisor is set to 1 */ + divisor1 = 2; + divisor2 /= 2; } - if (divisor2==1) { - divisor2=2; - divisor1/=2; + if (divisor2 == 1) { + divisor2 = 2; + divisor1 /= 2; } } - outb(0 , dev->iobase + PCL818_CNTENABLE); /* enable pacer */ - if (mode==1) { - devpriv->int818_mode=INT_TYPE_AO1_INT; - outb(0x83 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ */ + outb(0, dev->iobase + PCL818_CNTENABLE); /* enable pacer */ + if (mode == 1) { + devpriv->int818_mode = INT_TYPE_AO1_INT; + outb(0x83 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Pacer+IRQ */ } else { - devpriv->int818_mode=INT_TYPE_AO3_INT; - outb(0x82 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ */ + devpriv->int818_mode = INT_TYPE_AO3_INT; + outb(0x82 | (dev->irq << 4), dev->iobase + PCL818_CONTROL); /* Ext trig+IRQ */ }; - start_pacer(dev, mode, divisor1, divisor2); + start_pacer(dev, mode, divisor1, divisor2); - return 0; + return 0; } /* ============================================================================== ANALOG OUTPUT MODE 1, 818 cards */ -static int pcl818_ao_mode1(comedi_device * dev, comedi_subdevice * s, comedi_trig * it) +static int pcl818_ao_mode1(comedi_device * dev, comedi_subdevice * s, + comedi_trig * it) { - return pcl818_ao_mode13(1, dev, s, it); + return pcl818_ao_mode13(1, dev, s, it); } /* ============================================================================== ANALOG OUTPUT MODE 3, 818 cards */ -static int pcl818_ao_mode3(comedi_device * dev, comedi_subdevice * s, comedi_trig * it) +static int pcl818_ao_mode3(comedi_device * dev, comedi_subdevice * s, + comedi_trig * it) { - return pcl818_ao_mode13(3, dev, s, it); + return pcl818_ao_mode13(3, dev, s, it); } #endif #endif @@ -1078,18 +1138,19 @@ static int pcl818_ao_mode3(comedi_device * dev, comedi_subdevice * s, comedi_tri ============================================================================== Start/stop pacer onboard pacer */ -static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2) +static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, + unsigned int divisor2) { - outb(0xb4, dev->iobase + PCL818_CTRCTL); - outb(0x74, dev->iobase + PCL818_CTRCTL); - comedi_udelay(1); + outb(0xb4, dev->iobase + PCL818_CTRCTL); + outb(0x74, dev->iobase + PCL818_CTRCTL); + comedi_udelay(1); - if (mode==1) { + if (mode == 1) { outb(divisor2 & 0xff, dev->iobase + PCL818_CTR2); outb((divisor2 >> 8) & 0xff, dev->iobase + PCL818_CTR2); - outb(divisor1 & 0xff, dev->iobase + PCL818_CTR1); + outb(divisor1 & 0xff, dev->iobase + PCL818_CTR1); outb((divisor1 >> 8) & 0xff, dev->iobase + PCL818_CTR1); - } + } } /* @@ -1097,77 +1158,81 @@ static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, un Check if channel list from user is builded correctly If it's ok, then program scan/gain logic */ -static int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan) +static int check_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan) { - unsigned int chansegment[16]; - unsigned int i, nowmustbechan, seglen, segpos; + unsigned int chansegment[16]; + unsigned int i, nowmustbechan, seglen, segpos; - /* correct channel and range number check itself comedi/range.c */ - if (n_chan<1) { - comedi_error(dev,"range/channel list is empty!"); + /* correct channel and range number check itself comedi/range.c */ + if (n_chan < 1) { + comedi_error(dev, "range/channel list is empty!"); return 0; - } + } - if (n_chan > 1) { + if (n_chan > 1) { // first channel is everytime ok - chansegment[0]=chanlist[0]; + chansegment[0] = chanlist[0]; // build part of chanlist - for (i=1, seglen=1; ichanlist[i]),CR_RANGE(it->chanlist[i])); // we detect loop, this must by finish - if (chanlist[0]==chanlist[i]) break; - nowmustbechan=(CR_CHAN(chansegment[i-1])+1) % s->n_chan; - if (nowmustbechan!=CR_CHAN(chanlist[i])) { // channel list isn't continous :-( - rt_printk("comedi%d: pcl818: channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", - dev->minor,i,CR_CHAN(chanlist[i]), - nowmustbechan,CR_CHAN(chanlist[0]) ); + if (chanlist[0] == chanlist[i]) + break; + nowmustbechan = + (CR_CHAN(chansegment[i - 1]) + 1) % s->n_chan; + if (nowmustbechan != CR_CHAN(chanlist[i])) { // channel list isn't continous :-( + rt_printk + ("comedi%d: pcl818: channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n", + dev->minor, i, CR_CHAN(chanlist[i]), + nowmustbechan, CR_CHAN(chanlist[0])); return 0; } // well, this is next correct channel in list - chansegment[i]=chanlist[i]; + chansegment[i] = chanlist[i]; } // check whole chanlist - for (i=0, segpos=0; ichanlist[i]),CR_RANGE(it->chanlist[i])); - if (chanlist[i]!=chansegment[i%seglen]) { - rt_printk("comedi%d: pcl818: bad channel or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", - dev->minor,i,CR_CHAN(chansegment[i]), - CR_RANGE(chansegment[i]), - CR_AREF(chansegment[i]), - CR_CHAN(chanlist[i%seglen]), - CR_RANGE(chanlist[i%seglen]), - CR_AREF(chansegment[i%seglen])); - return 0; // chan/gain list is strange + if (chanlist[i] != chansegment[i % seglen]) { + rt_printk + ("comedi%d: pcl818: bad channel or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n", + dev->minor, i, CR_CHAN(chansegment[i]), + CR_RANGE(chansegment[i]), + CR_AREF(chansegment[i]), + CR_CHAN(chanlist[i % seglen]), + CR_RANGE(chanlist[i % seglen]), + CR_AREF(chansegment[i % seglen])); + return 0; // chan/gain list is strange } } } else { - seglen=1; + seglen = 1; } rt_printk("check_channel_list: seglen %d\n", seglen); return seglen; } -static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, - unsigned int n_chan, unsigned int seglen) +static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, + unsigned int *chanlist, unsigned int n_chan, unsigned int seglen) { int i; - devpriv->act_chanlist_len=seglen; - devpriv->act_chanlist_pos=0; + devpriv->act_chanlist_len = seglen; + devpriv->act_chanlist_pos = 0; - for (i=0; iact_chanlist[i]=CR_CHAN(chanlist[i]); - outb(muxonechan[CR_CHAN(chanlist[i])], dev->iobase+PCL818_MUX); /* select channel */ - outb(CR_RANGE(chanlist[i]), dev->iobase+PCL818_RANGE); /* select gain */ + for (i = 0; i < seglen; i++) { // store range list to card + devpriv->act_chanlist[i] = CR_CHAN(chanlist[i]); + outb(muxonechan[CR_CHAN(chanlist[i])], dev->iobase + PCL818_MUX); /* select channel */ + outb(CR_RANGE(chanlist[i]), dev->iobase + PCL818_RANGE); /* select gain */ } comedi_udelay(1); - /* select channel interval to scan*/ - outb(devpriv->act_chanlist[0] | (devpriv->act_chanlist[seglen-1] << 4), - dev->iobase+PCL818_MUX); + /* select channel interval to scan */ + outb(devpriv->act_chanlist[0] | (devpriv->act_chanlist[seglen - + 1] << 4), dev->iobase + PCL818_MUX); } /* @@ -1176,139 +1241,153 @@ static void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsign */ static int check_single_ended(unsigned int port) { - if (inb(port+PCL818_STATUS)&0x20) { return 1; } - else { return 0; } + if (inb(port + PCL818_STATUS) & 0x20) { + return 1; + } else { + return 0; + } } /* ============================================================================== */ -static int ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) { - int err=0; - int tmp,divisor1,divisor2; +static int ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) +{ + int err = 0; + int tmp, divisor1, divisor2; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) { + if (err) { return 1; } /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src!=TRIG_NOW) { - cmd->start_src=TRIG_NOW; + if (cmd->start_src != TRIG_NOW) { + cmd->start_src = TRIG_NOW; err++; } - if(cmd->scan_begin_src!=TRIG_FOLLOW) { - cmd->scan_begin_src=TRIG_FOLLOW; + if (cmd->scan_begin_src != TRIG_FOLLOW) { + cmd->scan_begin_src = TRIG_FOLLOW; err++; } - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT) err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; - if(cmd->scan_end_src!=TRIG_COUNT) { - cmd->scan_end_src=TRIG_COUNT; + if (cmd->scan_end_src != TRIG_COUNT) { + cmd->scan_end_src = TRIG_COUNT; err++; } - if(cmd->stop_src!=TRIG_NONE && - cmd->stop_src!=TRIG_COUNT) err++; + if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT) + err++; - if(err) { + if (err) { return 2; } /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argns_min){ - cmd->convert_arg=this_board->ns_min; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < this_board->ns_min) { + cmd->convert_arg = this_board->ns_min; err++; } - } else { /* TRIG_EXT */ - if(cmd->convert_arg!=0){ - cmd->convert_arg=0; + } else { /* TRIG_EXT */ + if (cmd->convert_arg != 0) { + cmd->convert_arg = 0; err++; } } - if(!cmd->chanlist_len){ - cmd->chanlist_len=1; + if (!cmd->chanlist_len) { + cmd->chanlist_len = 1; err++; } - if(cmd->chanlist_len>s->n_chan){ - cmd->chanlist_len=s->n_chan; + if (cmd->chanlist_len > s->n_chan) { + cmd->chanlist_len = s->n_chan; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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){ - cmd->stop_arg=1; + if (cmd->stop_src == TRIG_COUNT) { + if (!cmd->stop_arg) { + cmd->stop_arg = 1; err++; } - } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + } else { /* TRIG_NONE */ + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err) { + if (err) { return 3; } /* step 4: fix up any arguments */ - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,&divisor1,&divisor2,&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(cmd->convert_argns_min) - cmd->convert_arg=this_board->ns_min; - if(tmp!=cmd->convert_arg)err++; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + i8253_cascade_ns_to_timer(devpriv->i8253_osc_base, &divisor1, + &divisor2, &cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + if (cmd->convert_arg < this_board->ns_min) + cmd->convert_arg = this_board->ns_min; + if (tmp != cmd->convert_arg) + err++; } - if(err) { + if (err) { return 4; } /* step 5: complain about special chanlist considerations */ - if (cmd->chanlist){ + if (cmd->chanlist) { if (!check_channel_list(dev, s, cmd->chanlist, - cmd->chanlist_len)) return 5; // incorrect channels list + cmd->chanlist_len)) + return 5; // incorrect channels list } return 0; @@ -1317,60 +1396,62 @@ static int ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) { /* ============================================================================== */ -static int ai_cmd(comedi_device *dev,comedi_subdevice *s) { - comedi_cmd *cmd=&s->async->cmd; +static int ai_cmd(comedi_device * dev, comedi_subdevice * s) +{ + comedi_cmd *cmd = &s->async->cmd; int retval; - rt_printk("pcl818_ai_cmd()\n"); - devpriv->ai_n_chan=cmd->chanlist_len; - devpriv->ai_chanlist=cmd->chanlist; - devpriv->ai_flags=cmd->flags; - devpriv->ai_data_len=s->async->prealloc_bufsz; - devpriv->ai_data=s->async->prealloc_buf; - devpriv->ai_timer1=0; - devpriv->ai_timer2=0; - - if (cmd->stop_src==TRIG_COUNT) { devpriv->ai_scans=cmd->stop_arg; } - else { devpriv->ai_scans=0; } - - if(cmd->scan_begin_src==TRIG_FOLLOW){ // mode 1, 3 - if (cmd->convert_src==TRIG_TIMER) { // mode 1 - devpriv->ai_timer1=cmd->convert_arg; - retval = pcl818_ai_cmd_mode(1,dev,s); + rt_printk("pcl818_ai_cmd()\n"); + devpriv->ai_n_chan = cmd->chanlist_len; + devpriv->ai_chanlist = cmd->chanlist; + devpriv->ai_flags = cmd->flags; + devpriv->ai_data_len = s->async->prealloc_bufsz; + devpriv->ai_data = s->async->prealloc_buf; + devpriv->ai_timer1 = 0; + devpriv->ai_timer2 = 0; + + if (cmd->stop_src == TRIG_COUNT) { + devpriv->ai_scans = cmd->stop_arg; + } else { + devpriv->ai_scans = 0; + } + + if (cmd->scan_begin_src == TRIG_FOLLOW) { // mode 1, 3 + if (cmd->convert_src == TRIG_TIMER) { // mode 1 + devpriv->ai_timer1 = cmd->convert_arg; + retval = pcl818_ai_cmd_mode(1, dev, s); rt_printk("pcl818_ai_cmd() end\n"); return retval; } - if (cmd->convert_src==TRIG_EXT) { // mode 3 - return pcl818_ai_cmd_mode(3,dev,s); + if (cmd->convert_src == TRIG_EXT) { // mode 3 + return pcl818_ai_cmd_mode(3, dev, s); } - } + } return -1; } - - /* ============================================================================== cancel any mode 1-4 AI */ static int pcl818_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - if (devpriv->irq_blocked>0) { + if (devpriv->irq_blocked > 0) { rt_printk("pcl818_ai_cancel()\n"); - devpriv->irq_was_now_closed=devpriv->ai_mode; - devpriv->ai_mode=0; + devpriv->irq_was_now_closed = devpriv->ai_mode; + devpriv->ai_mode = 0; switch (devpriv->irq_was_now_closed) { #ifdef unused case INT_TYPE_AI1_DMA_RTC: case INT_TYPE_AI3_DMA_RTC: - set_rtc_irq_bit(0); // stop RTC + set_rtc_irq_bit(0); // stop RTC del_timer(&devpriv->rtc_irq_timer); #endif case INT_TYPE_AI1_DMA: case INT_TYPE_AI3_DMA: - if ( devpriv->neverending_ai ) { + if (devpriv->neverending_ai) { /* wait for running dma transfer to end, do cleanup in interrupt */ goto end; } @@ -1383,29 +1464,29 @@ static int pcl818_ai_cancel(comedi_device * dev, comedi_subdevice * s) case INT_TYPE_AO1_INT: case INT_TYPE_AO3_INT: #endif - outb(inb(dev->iobase+PCL818_CONTROL)& 0x73, dev->iobase+PCL818_CONTROL); /* Stop A/D */ + outb(inb(dev->iobase + PCL818_CONTROL) & 0x73, dev->iobase + PCL818_CONTROL); /* Stop A/D */ comedi_udelay(1); - start_pacer(dev,-1,0,0); - outb(0, dev->iobase+PCL818_AD_LO); - inb(dev->iobase+PCL818_AD_LO); - inb(dev->iobase+PCL818_AD_HI); - outb(0, dev->iobase+PCL818_CLRINT); /* clear INT request */ - outb(0, dev->iobase+PCL818_CONTROL); /* Stop A/D */ - if (devpriv->usefifo) { // FIFO shutdown - outb(0, dev->iobase + PCL818_FI_INTCLR); + start_pacer(dev, -1, 0, 0); + outb(0, dev->iobase + PCL818_AD_LO); + inb(dev->iobase + PCL818_AD_LO); + inb(dev->iobase + PCL818_AD_HI); + outb(0, dev->iobase + PCL818_CLRINT); /* clear INT request */ + outb(0, dev->iobase + PCL818_CONTROL); /* Stop A/D */ + if (devpriv->usefifo) { // FIFO shutdown + outb(0, dev->iobase + PCL818_FI_INTCLR); outb(0, dev->iobase + PCL818_FI_FLUSH); outb(0, dev->iobase + PCL818_FI_ENABLE); } - devpriv->irq_blocked=0; - devpriv->last_int_sub=s; - devpriv->neverending_ai=0; + devpriv->irq_blocked = 0; + devpriv->last_int_sub = s; + devpriv->neverending_ai = 0; break; } - } + } - end: - rt_printk("pcl818_ai_cancel() end\n"); - return 0; + end: + rt_printk("pcl818_ai_cancel() end\n"); + return 0; } /* @@ -1414,18 +1495,21 @@ static int pcl818_ai_cancel(comedi_device * dev, comedi_subdevice * s) */ static int pcl818_check(unsigned long iobase) { - outb(0x00, iobase + PCL818_MUX); - comedi_udelay(1); - if (inb(iobase + PCL818_MUX)!=0x00) return 1; //there isn't card - outb(0x55, iobase + PCL818_MUX); - comedi_udelay(1); - if (inb(iobase + PCL818_MUX)!=0x55) return 1; //there isn't card - outb(0x00, iobase + PCL818_MUX); - comedi_udelay(1); - outb(0x18, iobase + PCL818_CONTROL); - comedi_udelay(1); - if (inb(iobase + PCL818_CONTROL)!=0x18) return 1; //there isn't card - return 0; // ok, card exist + outb(0x00, iobase + PCL818_MUX); + comedi_udelay(1); + if (inb(iobase + PCL818_MUX) != 0x00) + return 1; //there isn't card + outb(0x55, iobase + PCL818_MUX); + comedi_udelay(1); + if (inb(iobase + PCL818_MUX) != 0x55) + return 1; //there isn't card + outb(0x00, iobase + PCL818_MUX); + comedi_udelay(1); + outb(0x18, iobase + PCL818_CONTROL); + comedi_udelay(1); + if (inb(iobase + PCL818_CONTROL) != 0x18) + return 1; //there isn't card + return 0; // ok, card exist } /* @@ -1434,27 +1518,27 @@ static int pcl818_check(unsigned long iobase) */ static void pcl818_reset(comedi_device * dev) { - if (devpriv->usefifo) { // FIFO shutdown + if (devpriv->usefifo) { // FIFO shutdown outb(0, dev->iobase + PCL818_FI_INTCLR); outb(0, dev->iobase + PCL818_FI_FLUSH); outb(0, dev->iobase + PCL818_FI_ENABLE); - } - outb(0, dev->iobase + PCL818_DA_LO); // DAC=0V - outb(0, dev->iobase + PCL818_DA_HI); - comedi_udelay(1); - outb(0, dev->iobase + PCL818_DO_HI); // DO=$0000 - outb(0, dev->iobase + PCL818_DO_LO); - comedi_udelay(1); - outb(0, dev->iobase + PCL818_CONTROL); - outb(0, dev->iobase + PCL818_CNTENABLE); - outb(0, dev->iobase + PCL818_MUX); - outb(0, dev->iobase + PCL818_CLRINT); - outb(0xb0, dev->iobase + PCL818_CTRCTL);/* Stop pacer */ - outb(0x70, dev->iobase + PCL818_CTRCTL); - outb(0x30, dev->iobase + PCL818_CTRCTL); - if(this_board->is_818){ - outb(0, dev->iobase + PCL818_RANGE); - }else{ + } + outb(0, dev->iobase + PCL818_DA_LO); // DAC=0V + outb(0, dev->iobase + PCL818_DA_HI); + comedi_udelay(1); + outb(0, dev->iobase + PCL818_DO_HI); // DO=$0000 + outb(0, dev->iobase + PCL818_DO_LO); + comedi_udelay(1); + outb(0, dev->iobase + PCL818_CONTROL); + outb(0, dev->iobase + PCL818_CNTENABLE); + outb(0, dev->iobase + PCL818_MUX); + outb(0, dev->iobase + PCL818_CLRINT); + outb(0xb0, dev->iobase + PCL818_CTRCTL); /* Stop pacer */ + outb(0x70, dev->iobase + PCL818_CTRCTL); + outb(0x30, dev->iobase + PCL818_CTRCTL); + if (this_board->is_818) { + outb(0, dev->iobase + PCL818_RANGE); + } else { outb(0, dev->iobase + PCL718_DA2_LO); outb(0, dev->iobase + PCL718_DA2_HI); } @@ -1467,27 +1551,33 @@ static void pcl818_reset(comedi_device * dev) */ static int set_rtc_irq_bit(unsigned char bit) { - unsigned char val; - unsigned long flags; + unsigned char val; + unsigned long flags; - if (bit==1) { + if (bit == 1) { RTC_timer_lock++; - if (RTC_timer_lock>1) return 0; + if (RTC_timer_lock > 1) + return 0; } else { RTC_timer_lock--; - if (RTC_timer_lock<0) RTC_timer_lock=0; - if (RTC_timer_lock>0) return 0; - } - - save_flags(flags); - cli(); - val = CMOS_READ(RTC_CONTROL); - if (bit) { val |= RTC_PIE; } - else { val &= ~RTC_PIE; } - CMOS_WRITE(val, RTC_CONTROL); - CMOS_READ(RTC_INTR_FLAGS); - restore_flags(flags); - return 0; + if (RTC_timer_lock < 0) + RTC_timer_lock = 0; + if (RTC_timer_lock > 0) + return 0; + } + + save_flags(flags); + cli(); + val = CMOS_READ(RTC_CONTROL); + if (bit) { + val |= RTC_PIE; + } else { + val &= ~RTC_PIE; + } + CMOS_WRITE(val, RTC_CONTROL); + CMOS_READ(RTC_INTR_FLAGS); + restore_flags(flags); + return 0; } /* @@ -1496,48 +1586,50 @@ static int set_rtc_irq_bit(unsigned char bit) */ static void rtc_dropped_irq(unsigned long data) { - comedi_device *dev = (void *)data; - unsigned long flags,tmp; + comedi_device *dev = (void *)data; + unsigned long flags, tmp; - switch(devpriv->int818_mode) { - case INT_TYPE_AI1_DMA_RTC: + switch (devpriv->int818_mode) { + case INT_TYPE_AI1_DMA_RTC: case INT_TYPE_AI3_DMA_RTC: - mod_timer(&devpriv->rtc_irq_timer, jiffies + HZ/devpriv->rtc_freq + 2*HZ/100); + mod_timer(&devpriv->rtc_irq_timer, + jiffies + HZ / devpriv->rtc_freq + 2 * HZ / 100); save_flags(flags); cli(); - tmp=(CMOS_READ(RTC_INTR_FLAGS) & 0xF0); /* restart */ + tmp = (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); /* restart */ restore_flags(flags); break; - }; + }; } - /* ============================================================================== Set frequency of interrupts from RTC */ static int rtc_setfreq_irq(int freq) { - int tmp = 0; - int rtc_freq; - unsigned char val; - unsigned long flags; + int tmp = 0; + int rtc_freq; + unsigned char val; + unsigned long flags; - if (freq<2) freq=2; - if (freq>8192) freq=8192; + if (freq < 2) + freq = 2; + if (freq > 8192) + freq = 8192; - while (freq>(1< (1 << tmp)) tmp++; - rtc_freq = 1<private) { + //rt_printk("free_resource()\n"); + if (dev->private) { pcl818_ai_cancel(dev, devpriv->sub_ai); pcl818_reset(dev); - if (devpriv->dma) free_dma(devpriv->dma); - if (devpriv->dmabuf[0]) free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]); - if (devpriv->dmabuf[1]) free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]); + if (devpriv->dma) + free_dma(devpriv->dma); + if (devpriv->dmabuf[0]) + free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]); + if (devpriv->dmabuf[1]) + free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]); #ifdef unused - if (devpriv->rtc_irq) comedi_free_irq(devpriv->rtc_irq, dev); - if ((devpriv->dma_rtc)&&(RTC_lock==1)) { + if (devpriv->rtc_irq) + comedi_free_irq(devpriv->rtc_irq, dev); + if ((devpriv->dma_rtc) && (RTC_lock == 1)) { if (devpriv->rtc_iobase) - release_region(devpriv->rtc_iobase, devpriv->rtc_iosize); + release_region(devpriv->rtc_iobase, + devpriv->rtc_iosize); } if (devpriv->dma_rtc) RTC_lock--; #endif } - if (dev->irq) free_irq(dev->irq, dev); - if (dev->iobase) release_region(dev->iobase, devpriv->io_range); + if (dev->irq) + free_irq(dev->irq, dev); + if (dev->iobase) + release_region(dev->iobase, devpriv->io_range); //rt_printk("free_resource() end\n"); } @@ -1580,21 +1679,20 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) { int ret; unsigned long iobase; - unsigned int irq,dma; + unsigned int irq, dma; unsigned long pages; comedi_subdevice *s; - - if((ret=alloc_private(dev,sizeof(pcl818_private)))<0) - return ret; /* Can't alloc mem */ + if ((ret = alloc_private(dev, sizeof(pcl818_private))) < 0) + return ret; /* Can't alloc mem */ /* claim our I/O space */ iobase = it->options[0]; printk("comedi%d: pcl818: board=%s, ioport=0x%03lx", dev->minor, this_board->name, iobase); - devpriv->io_range=this_board->io_range; - if ((this_board->fifo)&&(it->options[2]==-1)) { // we've board with FIFO and we want to use FIFO - devpriv->io_range=PCLx1xFIFO_RANGE; + devpriv->io_range = this_board->io_range; + if ((this_board->fifo) && (it->options[2] == -1)) { // we've board with FIFO and we want to use FIFO + devpriv->io_range = PCLx1xFIFO_RANGE; devpriv->usefifo = 1; } if (!request_region(iobase, devpriv->io_range, "pcl818")) { @@ -1602,27 +1700,32 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; if (pcl818_check(iobase)) { rt_printk(", I can't detect board. FAIL!\n"); return -EIO; } - /* set up some name stuff */ + /* set up some name stuff */ dev->board_name = this_board->name; - /* grab our IRQ */ - irq=0; - if (this_board->IRQbits!=0) { /* board support IRQ */ - irq=it->options[1]; - if (irq) {/* we want to use IRQ */ - if (((1<IRQbits)==0) { - rt_printk(", IRQ %u is out of allowed range, DISABLING IT",irq); - irq=0; /* Bad IRQ */ + /* grab our IRQ */ + irq = 0; + if (this_board->IRQbits != 0) { /* board support IRQ */ + irq = it->options[1]; + if (irq) { /* we want to use IRQ */ + if (((1 << irq) & this_board->IRQbits) == 0) { + rt_printk + (", IRQ %u is out of allowed range, DISABLING IT", + irq); + irq = 0; /* Bad IRQ */ } else { - if (comedi_request_irq(irq, interrupt_pcl818, 0, "pcl818", dev)) { - rt_printk(", unable to allocate IRQ %u, DISABLING IT", irq); - irq=0; /* Can't use IRQ */ + if (comedi_request_irq(irq, interrupt_pcl818, 0, + "pcl818", dev)) { + rt_printk + (", unable to allocate IRQ %u, DISABLING IT", + irq); + irq = 0; /* Can't use IRQ */ } else { rt_printk(", irq=%u", irq); } @@ -1630,136 +1733,170 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) } } - dev->irq = irq; - if (irq) { devpriv->irq_free=1; } /* 1=we have allocated irq */ - else { devpriv->irq_free=0; } - devpriv->irq_blocked=0; /* number of subdevice which use IRQ */ - devpriv->ai_mode=0; /* mode of irq */ + dev->irq = irq; + if (irq) { + devpriv->irq_free = 1; + } /* 1=we have allocated irq */ + else { + devpriv->irq_free = 0; + } + devpriv->irq_blocked = 0; /* number of subdevice which use IRQ */ + devpriv->ai_mode = 0; /* mode of irq */ #ifdef unused - /* grab RTC for DMA operations */ - devpriv->dma_rtc=0; - if (it->options[2]>0) { // we want to use DMA - if (RTC_lock==0) { - if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, "pcl818 (RTC)")) + /* grab RTC for DMA operations */ + devpriv->dma_rtc = 0; + if (it->options[2] > 0) { // we want to use DMA + if (RTC_lock == 0) { + if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, + "pcl818 (RTC)")) goto no_rtc; } - devpriv->rtc_iobase=RTC_PORT(0); - devpriv->rtc_iosize=RTC_IO_EXTENT; + devpriv->rtc_iobase = RTC_PORT(0); + devpriv->rtc_iosize = RTC_IO_EXTENT; RTC_lock++; - if (!comedi_request_irq(RTC_IRQ, interrupt_pcl818_ai_mode13_dma_rtc, 0, "pcl818 DMA (RTC)", dev)) { - devpriv->dma_rtc=1; - devpriv->rtc_irq=RTC_IRQ; + if (!comedi_request_irq(RTC_IRQ, + interrupt_pcl818_ai_mode13_dma_rtc, 0, + "pcl818 DMA (RTC)", dev)) { + devpriv->dma_rtc = 1; + devpriv->rtc_irq = RTC_IRQ; rt_printk(", dma_irq=%u", devpriv->rtc_irq); } else { RTC_lock--; - if (RTC_lock==0) { - if (devpriv->rtc_iobase) release_region(devpriv->rtc_iobase, devpriv->rtc_iosize); + if (RTC_lock == 0) { + if (devpriv->rtc_iobase) + release_region(devpriv->rtc_iobase, + devpriv->rtc_iosize); } - devpriv->rtc_iobase=0; - devpriv->rtc_iosize=0; + devpriv->rtc_iobase = 0; + devpriv->rtc_iosize = 0; } } -no_rtc: + no_rtc: #endif - /* grab our DMA */ - dma=0; - devpriv->dma=dma; - if ((devpriv->irq_free==0)&&(devpriv->dma_rtc==0)) goto no_dma; /* if we haven't IRQ, we can't use DMA */ - if (this_board->DMAbits!=0) { /* board support DMA */ - dma=it->options[2]; - if (dma<1) goto no_dma; /* DMA disabled */ - if (((1<DMAbits)==0) { - rt_printk(", DMA is out of allowed range, FAIL!\n"); - return -EINVAL; /* Bad DMA */ + /* grab our DMA */ + dma = 0; + devpriv->dma = dma; + if ((devpriv->irq_free == 0) && (devpriv->dma_rtc == 0)) + goto no_dma; /* if we haven't IRQ, we can't use DMA */ + if (this_board->DMAbits != 0) { /* board support DMA */ + dma = it->options[2]; + if (dma < 1) + goto no_dma; /* DMA disabled */ + if (((1 << dma) & this_board->DMAbits) == 0) { + rt_printk(", DMA is out of allowed range, FAIL!\n"); + return -EINVAL; /* Bad DMA */ } - ret=request_dma(dma, "pcl818"); + ret = request_dma(dma, "pcl818"); if (ret) { - rt_printk(", unable to allocate DMA %u, FAIL!\n",dma); - return -EBUSY; /* DMA isn't free */ + rt_printk(", unable to allocate DMA %u, FAIL!\n", dma); + return -EBUSY; /* DMA isn't free */ } - devpriv->dma=dma; + devpriv->dma = dma; rt_printk(", dma=%u", dma); - pages=2; /* we need 16KB */ - devpriv->dmabuf[0]=__get_dma_pages(GFP_KERNEL, pages); + pages = 2; /* we need 16KB */ + devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages); if (!devpriv->dmabuf[0]) { rt_printk(", unable to allocate DMA buffer, FAIL!\n"); /* maybe experiment with try_to_free_pages() will help .... */ - return -EBUSY; /* no buffer :-( */ + return -EBUSY; /* no buffer :-( */ } - devpriv->dmapages[0]=pages; + devpriv->dmapages[0] = pages; devpriv->hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]); - devpriv->hwdmasize[0]=(1<hwdmasize[0] = (1 << pages) * PAGE_SIZE; //rt_printk("%d %d %ld, ",devpriv->dmapages[0],devpriv->hwdmasize[0],PAGE_SIZE); - if (devpriv->dma_rtc==0) { // we must do duble buff :-( - devpriv->dmabuf[1]=__get_dma_pages(GFP_KERNEL, pages); + if (devpriv->dma_rtc == 0) { // we must do duble buff :-( + devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages); if (!devpriv->dmabuf[1]) { - rt_printk(", unable to allocate DMA buffer, FAIL!\n"); + rt_printk + (", unable to allocate DMA buffer, FAIL!\n"); return -EBUSY; } - devpriv->dmapages[1]=pages; - devpriv->hwdmaptr[1] = virt_to_bus((void *)devpriv->dmabuf[1]); - devpriv->hwdmasize[1]=(1<dmapages[1] = pages; + devpriv->hwdmaptr[1] = + virt_to_bus((void *)devpriv->dmabuf[1]); + devpriv->hwdmasize[1] = (1 << pages) * PAGE_SIZE; } } -no_dma: + no_dma: - if((ret=alloc_subdevices(dev, 4))<0) return ret; + if ((ret = alloc_subdevices(dev, 4)) < 0) + return ret; s = dev->subdevices + 0; - if(!this_board->n_aichan_se){ + if (!this_board->n_aichan_se) { s->type = COMEDI_SUBD_UNUSED; - }else{ + } else { dev->read_subdev = s; s->type = COMEDI_SUBD_AI; - devpriv->sub_ai=s; + devpriv->sub_ai = s; s->subdev_flags = SDF_READABLE; if (check_single_ended(dev->iobase)) { s->n_chan = this_board->n_aichan_se; - s->subdev_flags|=SDF_COMMON|SDF_GROUND; - printk(", %dchans S.E. DAC",s->n_chan); + s->subdev_flags |= SDF_COMMON | SDF_GROUND; + printk(", %dchans S.E. DAC", s->n_chan); } else { s->n_chan = this_board->n_aichan_diff; - s->subdev_flags|=SDF_DIFF; - printk(", %dchans DIFF DAC",s->n_chan); + s->subdev_flags |= SDF_DIFF; + printk(", %dchans DIFF DAC", s->n_chan); } s->maxdata = this_board->ai_maxdata; s->len_chanlist = s->n_chan; s->range_table = this_board->ai_range_type; - s->cancel=pcl818_ai_cancel; + s->cancel = pcl818_ai_cancel; s->insn_read = pcl818_ai_insn_read; - if ((irq)||(devpriv->dma_rtc)) { - s->do_cmdtest=ai_cmdtest; - s->do_cmd=ai_cmd; + if ((irq) || (devpriv->dma_rtc)) { + s->do_cmdtest = ai_cmdtest; + s->do_cmd = ai_cmd; } - if(this_board->is_818){ - if ((it->options[4]==1)||(it->options[4]==10)) - s->range_table=&range_pcl818l_h_ai; // secondary range list jumper selectable - }else{ + if (this_board->is_818) { + if ((it->options[4] == 1) || (it->options[4] == 10)) + s->range_table = &range_pcl818l_h_ai; // secondary range list jumper selectable + } else { switch (it->options[4]) { - case 0: s->range_table=&range_bipolar10; break; - case 1: s->range_table=&range_bipolar5; break; - case 2: s->range_table=&range_bipolar2_5; break; - case 3: s->range_table=&range718_bipolar1; break; - case 4: s->range_table=&range718_bipolar0_5; break; - case 6: s->range_table=&range_unipolar10; break; - case 7: s->range_table=&range_unipolar5; break; - case 8: s->range_table=&range718_unipolar2; break; - case 9: s->range_table=&range718_unipolar1; break; - default: s->range_table=&range_unknown; break; + case 0: + s->range_table = &range_bipolar10; + break; + case 1: + s->range_table = &range_bipolar5; + break; + case 2: + s->range_table = &range_bipolar2_5; + break; + case 3: + s->range_table = &range718_bipolar1; + break; + case 4: + s->range_table = &range718_bipolar0_5; + break; + case 6: + s->range_table = &range_unipolar10; + break; + case 7: + s->range_table = &range_unipolar5; + break; + case 8: + s->range_table = &range718_unipolar2; + break; + case 9: + s->range_table = &range718_unipolar1; + break; + default: + s->range_table = &range_unknown; + break; } } } s = dev->subdevices + 1; - if(!this_board->n_aochan){ + if (!this_board->n_aochan) { s->type = COMEDI_SUBD_UNUSED; - }else{ + } else { dev->write_subdev = s; s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE|SDF_GROUND; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; s->n_chan = this_board->n_aochan; s->maxdata = this_board->ao_maxdata; s->len_chanlist = this_board->n_aochan; @@ -1769,28 +1906,28 @@ no_dma: #ifdef unused #ifdef PCL818_MODE13_AO if (irq) { - s->trig[1] = pcl818_ao_mode1; + s->trig[1] = pcl818_ao_mode1; s->trig[3] = pcl818_ao_mode3; } #endif #endif - if(this_board->is_818){ - if ((it->options[4]==1)||(it->options[4]==10)) - s->range_table=&range_unipolar10; - if (it->options[4]==2) - s->range_table=&range_unknown; - }else{ - if ((it->options[5]==1)||(it->options[5]==10)) - s->range_table=&range_unipolar10; - if (it->options[5]==2) - s->range_table=&range_unknown; + if (this_board->is_818) { + if ((it->options[4] == 1) || (it->options[4] == 10)) + s->range_table = &range_unipolar10; + if (it->options[4] == 2) + s->range_table = &range_unknown; + } else { + if ((it->options[5] == 1) || (it->options[5] == 10)) + s->range_table = &range_unipolar10; + if (it->options[5] == 2) + s->range_table = &range_unknown; } } s = dev->subdevices + 2; - if(!this_board->n_dichan){ + if (!this_board->n_dichan) { s->type = COMEDI_SUBD_UNUSED; - }else{ + } else { s->type = COMEDI_SUBD_DI; s->subdev_flags = SDF_READABLE; s->n_chan = this_board->n_dichan; @@ -1801,9 +1938,9 @@ no_dma: } s = dev->subdevices + 3; - if(!this_board->n_dochan){ + if (!this_board->n_dochan) { s->type = COMEDI_SUBD_UNUSED; - }else{ + } else { s->type = COMEDI_SUBD_DO; s->subdev_flags = SDF_WRITABLE; s->n_chan = this_board->n_dochan; @@ -1814,18 +1951,18 @@ no_dma: } /* select 1/10MHz oscilator */ - if ((it->options[3]==0)||(it->options[3]==10)) { - devpriv->i8253_osc_base= 100; + if ((it->options[3] == 0) || (it->options[3] == 10)) { + devpriv->i8253_osc_base = 100; } else { - devpriv->i8253_osc_base=1000; + devpriv->i8253_osc_base = 1000; } - /* max sampling speed */ - devpriv->ns_min=this_board->ns_min; + /* max sampling speed */ + devpriv->ns_min = this_board->ns_min; - if(!this_board->is_818){ - if ((it->options[6]==1)||(it->options[6]==100)) - devpriv->ns_min=10000; /* extended PCL718 to 100kHz DAC */ + if (!this_board->is_818) { + if ((it->options[6] == 1) || (it->options[6] == 100)) + devpriv->ns_min = 10000; /* extended PCL718 to 100kHz DAC */ } pcl818_reset(dev); @@ -1835,15 +1972,13 @@ no_dma: return 0; } - /* ============================================================================== Removes device */ static int pcl818_detach(comedi_device * dev) { - // rt_printk("comedi%d: pcl818: remove\n", dev->minor); - free_resources(dev); - return 0; + // rt_printk("comedi%d: pcl818: remove\n", dev->minor); + free_resources(dev); + return 0; } - diff --git a/comedi/drivers/pcm3724.c b/comedi/drivers/pcm3724.c index 1b36df55..e115714a 100644 --- a/comedi/drivers/pcm3724.c +++ b/comedi/drivers/pcm3724.c @@ -62,15 +62,15 @@ Copy/pasted/hacked from pcm724.c #define CR_A_MODE(a) ((a)<<5) #define CR_CW 0x80 -static int pcm3724_attach(comedi_device *dev,comedi_devconfig *it); -static int pcm3724_detach(comedi_device *dev); +static int pcm3724_attach(comedi_device * dev, comedi_devconfig * it); +static int pcm3724_detach(comedi_device * dev); typedef struct { - const char *name; // driver name - int dio; // num of DIO - int numofports; // num of 8255 subdevices - unsigned int IRQbits; // allowed interrupts - unsigned int io_range; // len of IO space + const char *name; // driver name + int dio; // num of DIO + int numofports; // num of 8255 subdevices + unsigned int IRQbits; // allowed interrupts + unsigned int io_range; // len of IO space } boardtype; //used to track configured dios @@ -78,171 +78,165 @@ typedef struct { int dio_1; int dio_2; } priv_pcm3724; -static const boardtype boardtypes[] = -{ - {"pcm3724", 48, 2, 0x00fc, PCM3724_SIZE,}, +static const boardtype boardtypes[] = { + {"pcm3724", 48, 2, 0x00fc, PCM3724_SIZE,}, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) #define this_board ((const boardtype *)dev->board_ptr) -static comedi_driver driver_pcm3724={ - driver_name: "pcm3724", - module: THIS_MODULE, - attach: pcm3724_attach, - detach: pcm3724_detach, - board_name: &boardtypes[0].name, - num_names: n_boardtypes, - offset: sizeof(boardtype), +static comedi_driver driver_pcm3724 = { + driver_name:"pcm3724", + module:THIS_MODULE, + attach:pcm3724_attach, + detach:pcm3724_detach, + board_name:&boardtypes[0].name, + num_names:n_boardtypes, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_pcm3724); -// (setq c-basic-offset 8) +// (setq c-basic-offset 8) -static int subdev_8255_cb(int dir,int port,int data,unsigned long arg) +static int subdev_8255_cb(int dir, int port, int data, unsigned long arg) { - unsigned long iobase=arg; + unsigned long iobase = arg; unsigned char inbres; //printk("8255cb %d %d %d %lx\n", dir,port,data,arg); - if(dir){ + if (dir) { //printk("8255 cb outb(%x, %lx)\n", data, iobase+port); - outb(data,iobase+port); + outb(data, iobase + port); return 0; - }else{ - inbres = inb(iobase+port); + } else { + inbres = inb(iobase + port); //printk("8255 cb inb(%lx) = %x\n", iobase+port, inbres); return inbres; } } -static int compute_buffer(int config, int devno, comedi_subdevice *s) +static int compute_buffer(int config, int devno, comedi_subdevice * s) { /* 1 in io_bits indicates output */ - if(s->io_bits&0x0000ff) { + if (s->io_bits & 0x0000ff) { if (devno == 0) { config |= BUF_A0; - } - else { + } else { config |= BUF_A1; } } - if(s->io_bits&0x00ff00) { + if (s->io_bits & 0x00ff00) { if (devno == 0) { config |= BUF_B0; - } - else { + } else { config |= BUF_B1; } } - if(s->io_bits&0xff0000) { + if (s->io_bits & 0xff0000) { if (devno == 0) { config |= BUF_C0; - } - else { + } else { config |= BUF_C1; } } return config; } -static void do_3724_config(comedi_device *dev,comedi_subdevice *s, - int chanspec) +static void do_3724_config(comedi_device * dev, comedi_subdevice * s, + int chanspec) { int config; int buffer_config; unsigned long port_8255_cfg; - config=CR_CW; + config = CR_CW; buffer_config = 0; /* 1 in io_bits indicates output, 1 in config indicates input */ - if(!(s->io_bits&0x0000ff)) { - config|=CR_A_IO; + if (!(s->io_bits & 0x0000ff)) { + config |= CR_A_IO; } - if(!(s->io_bits&0x00ff00)) { - config|=CR_B_IO; + if (!(s->io_bits & 0x00ff00)) { + config |= CR_B_IO; } - if(!(s->io_bits&0xff0000)) { - config|=CR_C_IO; + if (!(s->io_bits & 0xff0000)) { + config |= CR_C_IO; } buffer_config = compute_buffer(0, 0, dev->subdevices); - buffer_config = compute_buffer(buffer_config, 1, (dev->subdevices)+1); + buffer_config = compute_buffer(buffer_config, 1, (dev->subdevices) + 1); if (s == dev->subdevices) { port_8255_cfg = dev->iobase + _8255_CR; - } - else { + } else { port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR; } - outb(buffer_config, dev->iobase + 8); /* update buffer register */ + outb(buffer_config, dev->iobase + 8); /* update buffer register */ //printk("pcm3724 buffer_config (%lx) %d, %x\n", dev->iobase + _8255_CR, chanspec, buffer_config); outb(config, port_8255_cfg); } -static void enable_chan(comedi_device *dev, comedi_subdevice *s, - int chanspec) +static void enable_chan(comedi_device * dev, comedi_subdevice * s, int chanspec) { unsigned int mask; int gatecfg; priv_pcm3724 *priv; gatecfg = 0; - priv = (priv_pcm3724*)(dev->private); + priv = (priv_pcm3724 *) (dev->private); mask = 1 << CR_CHAN(chanspec); - if (s == dev->subdevices){ // subdev 0 + if (s == dev->subdevices) { // subdev 0 priv->dio_1 |= mask; - } - else { //subdev 1 + } else { //subdev 1 priv->dio_2 |= mask; } - if (priv->dio_1 & 0xff0000){ + if (priv->dio_1 & 0xff0000) { gatecfg |= GATE_C0; } - if (priv->dio_1 & 0xff00){ + if (priv->dio_1 & 0xff00) { gatecfg |= GATE_B0; } - if (priv->dio_1 & 0xff){ + if (priv->dio_1 & 0xff) { gatecfg |= GATE_A0; } - if (priv->dio_2 & 0xff0000){ + if (priv->dio_2 & 0xff0000) { gatecfg |= GATE_C1; } - if (priv->dio_2 & 0xff00){ + if (priv->dio_2 & 0xff00) { gatecfg |= GATE_B1; } - if (priv->dio_2 & 0xff){ + if (priv->dio_2 & 0xff) { gatecfg |= GATE_A1; } - // printk("gate control %x\n", gatecfg); + // printk("gate control %x\n", gatecfg); outb(gatecfg, dev->iobase + 9); } /* overriding the 8255 insn config */ -static int subdev_3724_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int subdev_3724_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { unsigned int mask; unsigned int bits; - mask=1<chanspec); - if(mask&0x0000ff){ - bits=0x0000ff; - }else if(mask&0x00ff00){ - bits=0x00ff00; - }else if(mask&0x0f0000){ - bits=0x0f0000; - }else{ - bits=0xf00000; + mask = 1 << CR_CHAN(insn->chanspec); + if (mask & 0x0000ff) { + bits = 0x0000ff; + } else if (mask & 0x00ff00) { + bits = 0x00ff00; + } else if (mask & 0x0f0000) { + bits = 0x0f0000; + } else { + bits = 0xf00000; } - switch(data[0]){ + switch (data[0]) { case INSN_CONFIG_DIO_INPUT: - s->io_bits&=~bits; + s->io_bits &= ~bits; break; case INSN_CONFIG_DIO_OUTPUT: - s->io_bits|=bits; + s->io_bits |= bits; break; case INSN_CONFIG_DIO_QUERY: data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT; @@ -252,63 +246,61 @@ static int subdev_3724_insn_config(comedi_device *dev, comedi_subdevice *s, return -EINVAL; } - do_3724_config(dev,s, insn->chanspec); + do_3724_config(dev, s, insn->chanspec); enable_chan(dev, s, insn->chanspec); return 1; } -static int pcm3724_attach(comedi_device *dev,comedi_devconfig *it) +static int pcm3724_attach(comedi_device * dev, comedi_devconfig * it) { - unsigned long iobase; + unsigned long iobase; unsigned int iorange; - int ret,i,n_subdevices; + int ret, i, n_subdevices; - iobase=it->options[0]; - iorange=this_board->io_range; - if((ret=alloc_private(dev,sizeof(priv_pcm3724)))<0) + iobase = it->options[0]; + iorange = this_board->io_range; + if ((ret = alloc_private(dev, sizeof(priv_pcm3724))) < 0) return -ENOMEM; - ((priv_pcm3724*)(dev->private))->dio_1 = 0; - ((priv_pcm3724*)(dev->private))->dio_2 = 0; + ((priv_pcm3724 *) (dev->private))->dio_1 = 0; + ((priv_pcm3724 *) (dev->private))->dio_2 = 0; - printk("comedi%d: pcm3724: board=%s, 0x%03lx ",dev->minor, - this_board->name,iobase); - if(!iobase || !request_region(iobase, iorange, "pcm3724")){ + printk("comedi%d: pcm3724: board=%s, 0x%03lx ", dev->minor, + this_board->name, iobase); + if (!iobase || !request_region(iobase, iorange, "pcm3724")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; dev->board_name = this_board->name; printk("\n"); - n_subdevices=this_board->numofports; + n_subdevices = this_board->numofports; - if((ret=alloc_subdevices(dev, n_subdevices))<0) + if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) return ret; - for(i=0;in_subdevices;i++){ - subdev_8255_init(dev, dev->subdevices+i, subdev_8255_cb, - (unsigned long)(dev->iobase+SIZE_8255*i)); - ((dev->subdevices)+i)->insn_config = subdev_3724_insn_config; + for (i = 0; i < dev->n_subdevices; i++) { + subdev_8255_init(dev, dev->subdevices + i, subdev_8255_cb, + (unsigned long)(dev->iobase + SIZE_8255 * i)); + ((dev->subdevices) + i)->insn_config = subdev_3724_insn_config; }; return 0; } -static int pcm3724_detach(comedi_device *dev) +static int pcm3724_detach(comedi_device * dev) { int i; - if(dev->subdevices){ - for(i=0;in_subdevices;i++){ - subdev_8255_cleanup(dev,dev->subdevices+i); + if (dev->subdevices) { + for (i = 0; i < dev->n_subdevices; i++) { + subdev_8255_cleanup(dev, dev->subdevices + i); } } - if(dev->iobase){ - release_region(dev->iobase,this_board->io_range); + if (dev->iobase) { + release_region(dev->iobase, this_board->io_range); } return 0; } - - diff --git a/comedi/drivers/pcm3730.c b/comedi/drivers/pcm3730.c index be822da2..6b8c1196 100644 --- a/comedi/drivers/pcm3730.c +++ b/comedi/drivers/pcm3730.c @@ -19,136 +19,134 @@ Configuration options: #include +#define PCM3730_SIZE 4 // consecutive io port addresses - -#define PCM3730_SIZE 4 // consecutive io port addresses - -#define PCM3730_DOA 0 // offsets for each port +#define PCM3730_DOA 0 // offsets for each port #define PCM3730_DOB 2 #define PCM3730_DOC 3 #define PCM3730_DIA 0 #define PCM3730_DIB 2 #define PCM3730_DIC 3 -static int pcm3730_attach(comedi_device *dev,comedi_devconfig *it); -static int pcm3730_detach(comedi_device *dev); -static comedi_driver driver_pcm3730={ - driver_name: "pcm3730", - module: THIS_MODULE, - attach: pcm3730_attach, - detach: pcm3730_detach, +static int pcm3730_attach(comedi_device * dev, comedi_devconfig * it); +static int pcm3730_detach(comedi_device * dev); +static comedi_driver driver_pcm3730 = { + driver_name:"pcm3730", + module:THIS_MODULE, + attach:pcm3730_attach, + detach:pcm3730_detach, }; -COMEDI_INITCLEANUP(driver_pcm3730); +COMEDI_INITCLEANUP(driver_pcm3730); -static int pcm3730_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcm3730_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - outb(s->state,dev->iobase+(unsigned long)(s->private)); + s->state |= (data[0] & data[1]); + outb(s->state, dev->iobase + (unsigned long)(s->private)); } data[1] = s->state; return 2; } -static int pcm3730_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcm3730_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; - data[1] = inb(dev->iobase+(unsigned long)(s->private)); + if (insn->n != 2) + return -EINVAL; + data[1] = inb(dev->iobase + (unsigned long)(s->private)); return 2; } -static int pcm3730_attach(comedi_device *dev,comedi_devconfig *it) +static int pcm3730_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; - iobase=it->options[0]; - printk("comedi%d: pcm3730: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,PCM3730_SIZE,"pcm3730")){ + iobase = it->options[0]; + printk("comedi%d: pcm3730: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, PCM3730_SIZE, "pcm3730")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; - dev->board_name="pcm3730"; - dev->iobase=dev->iobase; - dev->irq=0; + dev->iobase = iobase; + dev->board_name = "pcm3730"; + dev->iobase = dev->iobase; + dev->irq = 0; - if(alloc_subdevices(dev, 6)<0) + if (alloc_subdevices(dev, 6) < 0) return -ENOMEM; - s=dev->subdevices+0; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=8; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_do_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DOA; - - s=dev->subdevices+1; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=8; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DOA; + + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_do_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DOB; - - s=dev->subdevices+2; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=1; - s->n_chan=8; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DOB; + + s = dev->subdevices + 2; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_do_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DOC; - - s=dev->subdevices+3; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=8; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DOC; + + s = dev->subdevices + 3; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_di_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DIA; - - s=dev->subdevices+4; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=8; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DIA; + + s = dev->subdevices + 4; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_di_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DIB; - - s=dev->subdevices+5; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->maxdata=1; - s->n_chan=8; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DIB; + + s = dev->subdevices + 5; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->maxdata = 1; + s->n_chan = 8; s->insn_bits = pcm3730_di_insn_bits; - s->range_table=&range_digital; - s->private = (void *) PCM3730_DIC; + s->range_table = &range_digital; + s->private = (void *)PCM3730_DIC; printk("\n"); return 0; } - -static int pcm3730_detach(comedi_device *dev) +static int pcm3730_detach(comedi_device * dev) { - printk("comedi%d: pcm3730: remove\n",dev->minor); + printk("comedi%d: pcm3730: remove\n", dev->minor); + + if (dev->iobase) + release_region(dev->iobase, PCM3730_SIZE); - if(dev->iobase) - release_region(dev->iobase,PCM3730_SIZE); - return 0; } - diff --git a/comedi/drivers/pcmad.c b/comedi/drivers/pcmad.c index c0b54fdb..12da69cb 100644 --- a/comedi/drivers/pcmad.c +++ b/comedi/drivers/pcmad.c @@ -41,12 +41,10 @@ Configuration options: 1 = two's complement */ - #include #include - #define PCMAD_SIZE 4 #define PCMAD_STATUS 0 @@ -54,66 +52,67 @@ Configuration options: #define PCMAD_MSB 2 #define PCMAD_CONVERT 1 -struct pcmad_board_struct{ +struct pcmad_board_struct { const char *name; int n_ai_bits; }; -static const struct pcmad_board_struct pcmad_boards[]={ +static const struct pcmad_board_struct pcmad_boards[] = { { - name: "pcmad12", - n_ai_bits: 12, - }, + name: "pcmad12", + n_ai_bits:12, + }, { - name: "pcmad16", - n_ai_bits: 16, - }, + name: "pcmad16", + n_ai_bits:16, + }, }; + #define this_board ((const struct pcmad_board_struct *)(dev->board_ptr)) #define n_pcmad_boards (sizeof(pcmad_boards)/sizeof(pcmad_boards[0])) -struct pcmad_priv_struct{ +struct pcmad_priv_struct { int differential; int twos_comp; }; #define devpriv ((struct pcmad_priv_struct *)dev->private) -static int pcmad_attach(comedi_device *dev,comedi_devconfig *it); -static int pcmad_detach(comedi_device *dev); -static comedi_driver driver_pcmad={ - driver_name: "pcmad", - module: THIS_MODULE, - attach: pcmad_attach, - detach: pcmad_detach, - board_name: &pcmad_boards[0].name, - num_names: n_pcmad_boards, - offset: sizeof(pcmad_boards[0]), +static int pcmad_attach(comedi_device * dev, comedi_devconfig * it); +static int pcmad_detach(comedi_device * dev); +static comedi_driver driver_pcmad = { + driver_name:"pcmad", + module:THIS_MODULE, + attach:pcmad_attach, + detach:pcmad_detach, + board_name:&pcmad_boards[0].name, + num_names:n_pcmad_boards, + offset:sizeof(pcmad_boards[0]), }; -COMEDI_INITCLEANUP(driver_pcmad); +COMEDI_INITCLEANUP(driver_pcmad); #define TIMEOUT 100 -static int pcmad_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcmad_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan; int n; - chan=CR_CHAN(insn->chanspec); + chan = CR_CHAN(insn->chanspec); - for(n=0;nn;n++){ - outb(chan,dev->iobase+PCMAD_CONVERT); + for (n = 0; n < insn->n; n++) { + outb(chan, dev->iobase + PCMAD_CONVERT); - for(i=0;iiobase+PCMAD_STATUS)&0x3) == 0x3) + for (i = 0; i < TIMEOUT; i++) { + if ((inb(dev->iobase + PCMAD_STATUS) & 0x3) == 0x3) break; } - data[n]=inb(dev->iobase+PCMAD_LSB); - data[n]|=(inb(dev->iobase+PCMAD_MSB)<<8); + data[n] = inb(dev->iobase + PCMAD_LSB); + data[n] |= (inb(dev->iobase + PCMAD_MSB) << 8); - if(devpriv->twos_comp){ - data[n] ^= (1<<(this_board->n_ai_bits-1)); + if (devpriv->twos_comp) { + data[n] ^= (1 << (this_board->n_ai_bits - 1)); } } @@ -127,50 +126,48 @@ static int pcmad_ai_insn_read(comedi_device *dev,comedi_subdevice *s, * 2 0=single ended 1=differential * 3 0=straight binary 1=two's comp */ -static int pcmad_attach(comedi_device *dev,comedi_devconfig *it) +static int pcmad_attach(comedi_device * dev, comedi_devconfig * it) { int ret; comedi_subdevice *s; unsigned long iobase; - iobase=it->options[0]; - printk("comedi%d: pcmad: 0x%04lx ",dev->minor,iobase); - if(!request_region(iobase,PCMAD_SIZE,"pcmad")){ + iobase = it->options[0]; + printk("comedi%d: pcmad: 0x%04lx ", dev->minor, iobase); + if (!request_region(iobase, PCMAD_SIZE, "pcmad")) { printk("I/O port conflict\n"); return -EIO; } - dev->iobase=iobase; + dev->iobase = iobase; - if((ret=alloc_subdevices(dev, 1))<0) + if ((ret = alloc_subdevices(dev, 1)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(struct pcmad_priv_struct)))<0) + if ((ret = alloc_private(dev, sizeof(struct pcmad_priv_struct))) < 0) return ret; dev->board_name = this_board->name; - s=dev->subdevices+0; - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|AREF_GROUND; - s->n_chan=16; /* XXX */ - s->len_chanlist=1; - s->insn_read=pcmad_ai_insn_read; - s->maxdata=(1<n_ai_bits)-1; - s->range_table=&range_unknown; + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | AREF_GROUND; + s->n_chan = 16; /* XXX */ + s->len_chanlist = 1; + s->insn_read = pcmad_ai_insn_read; + s->maxdata = (1 << this_board->n_ai_bits) - 1; + s->range_table = &range_unknown; return 0; } - -static int pcmad_detach(comedi_device *dev) +static int pcmad_detach(comedi_device * dev) { - printk("comedi%d: pcmad: remove\n",dev->minor); + printk("comedi%d: pcmad: remove\n", dev->minor); - if(dev->irq){ - free_irq(dev->irq,dev); + if (dev->irq) { + free_irq(dev->irq, dev); } - if(dev->iobase) - release_region(dev->iobase,PCMAD_SIZE); + if (dev->iobase) + release_region(dev->iobase, PCMAD_SIZE); return 0; } - diff --git a/comedi/drivers/pcmda12.c b/comedi/drivers/pcmda12.c index 0f708d47..1112b5b0 100644 --- a/comedi/drivers/pcmda12.c +++ b/comedi/drivers/pcmda12.c @@ -51,10 +51,9 @@ Configuration Options: [1] - Do Simultaneous Xfer (see description) */ - #include -#include /* for PCI devices */ +#include /* for PCI devices */ #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) ) #define SDEV_NO ((int)(s - dev->subdevices)) @@ -69,26 +68,23 @@ Configuration Options: /* * Bords */ -typedef struct pcmda12_board_struct -{ +typedef struct pcmda12_board_struct { const char *name; } pcmda12_board; /* note these have no effect and are merely here for reference.. these are configured by jumpering the board! */ -static const comedi_lrange pcmda12_ranges = -{ - 3, - { - UNI_RANGE( 5 ), UNI_RANGE( 10 ), BIP_RANGE( 5 ) - } +static const comedi_lrange pcmda12_ranges = { + 3, + { + UNI_RANGE(5), UNI_RANGE(10), BIP_RANGE(5) + } }; -static const pcmda12_board pcmda12_boards[] = -{ +static const pcmda12_board pcmda12_boards[] = { { - name: "pcmda12", - }, + name: "pcmda12", + }, }; /* @@ -96,10 +92,9 @@ static const pcmda12_board pcmda12_boards[] = */ #define thisboard ((const pcmda12_board *)dev->board_ptr) -typedef struct -{ - lsampl_t ao_readback[CHANS]; - int simultaneous_xfer_mode; +typedef struct { + lsampl_t ao_readback[CHANS]; + int simultaneous_xfer_mode; } pcmda12_private; #define devpriv ((pcmda12_private *)(dev->private)) @@ -110,17 +105,16 @@ typedef struct * the board, and also about the kernel module that contains * the device code. */ -static int pcmda12_attach(comedi_device *dev, comedi_devconfig *it); -static int pcmda12_detach(comedi_device *dev); +static int pcmda12_attach(comedi_device * dev, comedi_devconfig * it); +static int pcmda12_detach(comedi_device * dev); -static void zero_chans(comedi_device *dev); +static void zero_chans(comedi_device * dev); -static comedi_driver driver = -{ - driver_name: "pcmda12", - module: THIS_MODULE, - attach: pcmda12_attach, - detach: pcmda12_detach, +static comedi_driver driver = { + driver_name:"pcmda12", + module:THIS_MODULE, + attach:pcmda12_attach, + detach:pcmda12_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -139,15 +133,15 @@ static comedi_driver driver = * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &pcmda12_boards[0].name, - offset: sizeof(pcmda12_board), - num_names: sizeof(pcmda12_boards) / sizeof(pcmda12_board), + board_name:&pcmda12_boards[0].name, + offset:sizeof(pcmda12_board), + num_names:sizeof(pcmda12_boards) / sizeof(pcmda12_board), }; -static int ao_winsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int ao_rinsn(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* * Attach is called by the Comedi core to configure the driver @@ -155,22 +149,20 @@ static int ao_rinsn(comedi_device *dev,comedi_subdevice *s, * in the driver structure, dev->board_ptr contains that * address. */ -static int pcmda12_attach(comedi_device *dev, comedi_devconfig *it) +static int pcmda12_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - unsigned long iobase; - - iobase = it->options[0]; - printk("comedi%d: %s: io: %lx %s ", dev->minor, driver.driver_name, iobase, it->options[1] ? "simultaneous xfer mode enabled" : ""); + unsigned long iobase; - if ( !request_region(iobase, - IOSIZE, - driver.driver_name) ) { - printk("I/O port conflict\n"); - return -EIO; - } - dev->iobase = iobase; + iobase = it->options[0]; + printk("comedi%d: %s: io: %lx %s ", dev->minor, driver.driver_name, + iobase, it->options[1] ? "simultaneous xfer mode enabled" : ""); + if (!request_region(iobase, IOSIZE, driver.driver_name)) { + printk("I/O port conflict\n"); + return -EIO; + } + dev->iobase = iobase; /* * Initialize dev->board_name. Note that we can use the "thisboard" @@ -183,42 +175,41 @@ static int pcmda12_attach(comedi_device *dev, comedi_devconfig *it) * convenient macro defined in comedidev.h. */ if (alloc_private(dev, sizeof(pcmda12_private)) < 0) { - printk("cannot allocate private data structure\n"); - return -ENOMEM; - } - - devpriv->simultaneous_xfer_mode = it->options[1]; - - /* - * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. - * - * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the - * 96-channel version of the board. - */ - if ( alloc_subdevices(dev, 1) < 0 ) { - printk("cannot allocate subdevice data structures\n"); - return -ENOMEM; - } - - s = dev->subdevices; - s->private = NULL; - s->maxdata = (0x1<range_table = &pcmda12_ranges; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->n_chan = CHANS; - s->insn_write = &ao_winsn; - s->insn_read = &ao_rinsn; - - zero_chans(dev); /* clear out all the registers, basically */ + printk("cannot allocate private data structure\n"); + return -ENOMEM; + } + + devpriv->simultaneous_xfer_mode = it->options[1]; + + /* + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. + * + * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the + * 96-channel version of the board. + */ + if (alloc_subdevices(dev, 1) < 0) { + printk("cannot allocate subdevice data structures\n"); + return -ENOMEM; + } + + s = dev->subdevices; + s->private = NULL; + s->maxdata = (0x1 << BITS) - 1; + s->range_table = &pcmda12_ranges; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = CHANS; + s->insn_write = &ao_winsn; + s->insn_read = &ao_rinsn; + + zero_chans(dev); /* clear out all the registers, basically */ printk("attached\n"); return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -227,56 +218,55 @@ static int pcmda12_attach(comedi_device *dev, comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pcmda12_detach(comedi_device *dev) +static int pcmda12_detach(comedi_device * dev) { - printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); + printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); if (dev->iobase) - release_region(dev->iobase, IOSIZE); + release_region(dev->iobase, IOSIZE); return 0; } -static void zero_chans(comedi_device *dev) /* sets up an - ASIC chip to defaults */ -{ - int i; - for (i = 0; i < CHANS; ++i) { +static void zero_chans(comedi_device * dev) +{ /* sets up an + ASIC chip to defaults */ + int i; + for (i = 0; i < CHANS; ++i) { /* /\* do this as one instruction?? *\/ */ /* outw(0, LSB_PORT(chan)); */ - outb(0, LSB_PORT(i)); - outb(0, MSB_PORT(i)); - } - inb(LSB_PORT(0)); /* update chans. */ + outb(0, LSB_PORT(i)); + outb(0, MSB_PORT(i)); + } + inb(LSB_PORT(0)); /* update chans. */ } - -static int ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, - lsampl_t *data) +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); + int i; + int chan = CR_CHAN(insn->chanspec); /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for (i = 0; i < insn->n ; ++i) { + for (i = 0; i < insn->n; ++i) { /* /\* do this as one instruction?? *\/ */ /* outw(data[i], LSB_PORT(chan)); */ - /* Need to do this as two instructions due to 8-bit bus?? */ - /* first, load the low byte */ - outb(LSB(data[i]), LSB_PORT(chan)); - /* next, write the high byte */ - outb(MSB(data[i]), MSB_PORT(chan)); + /* Need to do this as two instructions due to 8-bit bus?? */ + /* first, load the low byte */ + outb(LSB(data[i]), LSB_PORT(chan)); + /* next, write the high byte */ + outb(MSB(data[i]), MSB_PORT(chan)); - /* save shadow register */ - devpriv->ao_readback[chan] = data[i]; + /* save shadow register */ + devpriv->ao_readback[chan] = data[i]; - if (!devpriv->simultaneous_xfer_mode) - inb(LSB_PORT(chan)); - } + if (!devpriv->simultaneous_xfer_mode) + inb(LSB_PORT(chan)); + } - /* return the number of samples written */ - return i; + /* return the number of samples written */ + return i; } /* AO subdevices should have a read insn as well as a write insn. @@ -291,29 +281,24 @@ static int ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, DAC outputs, which makes all AO channels update simultaneously. This is useful for some control applications, I would imagine. */ -static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, - lsampl_t *data) +static int ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); + int i; + int chan = CR_CHAN(insn->chanspec); + for (i = 0; i < insn->n; i++) { + if (devpriv->simultaneous_xfer_mode) + inb(LSB_PORT(chan)); + /* read back shadow register */ + data[i] = devpriv->ao_readback[chan]; + } - for (i = 0; i < insn->n; i++) { - if (devpriv->simultaneous_xfer_mode) - inb(LSB_PORT(chan)); - /* read back shadow register */ - data[i] = devpriv->ao_readback[chan]; - } - - return i; + return i; } - - /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. */ COMEDI_INITCLEANUP(driver); - - diff --git a/comedi/drivers/pcmmio.c b/comedi/drivers/pcmmio.c index 2c493c79..04b37a6d 100644 --- a/comedi/drivers/pcmmio.c +++ b/comedi/drivers/pcmmio.c @@ -68,14 +68,13 @@ four subdevices: for either CR_RANGE or CR_AREF for edge-up polarity, or a zero value for both CR_RANGE and CR_AREF if you want edge-down polarity. - Configuration Options: [0] - I/O port base address [1] - IRQ (optional -- for edge-detect interrupt support only, leave out if you don't need this feature) */ #include -#include /* for PCI devices */ +#include /* for PCI devices */ #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) ) @@ -83,7 +82,7 @@ Configuration Options: #define CHANS_PER_PORT 8 #define PORTS_PER_ASIC 6 #define INTR_PORTS_PER_ASIC 3 -#define MAX_CHANS_PER_SUBDEV 24 /* number of channels per comedi subdevice */ +#define MAX_CHANS_PER_SUBDEV 24 /* number of channels per comedi subdevice */ #define PORTS_PER_SUBDEV (MAX_CHANS_PER_SUBDEV/CHANS_PER_PORT) #define CHANS_PER_ASIC (CHANS_PER_PORT*PORTS_PER_ASIC) #define INTR_CHANS_PER_ASIC 24 @@ -116,9 +115,9 @@ Configuration Options: #define REG_PORT4 0x4 #define REG_PORT5 0x5 #define REG_INT_PENDING 0x6 -#define REG_PAGELOCK 0x7 /* page selector register, upper 2 bits select a page - and bits 0-5 are used to 'lock down' a particular - port above to make it readonly. */ +#define REG_PAGELOCK 0x7 /* page selector register, upper 2 bits select a page + and bits 0-5 are used to 'lock down' a particular + port above to make it readonly. */ #define REG_POL0 0x8 #define REG_POL1 0x9 #define REG_POL2 0xA @@ -140,54 +139,59 @@ Configuration Options: #define PAGE_ENAB 2 #define PAGE_INT_ID 3 -typedef int (*comedi_insn_fn_t)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); +typedef int (*comedi_insn_fn_t) (comedi_device *, comedi_subdevice *, + comedi_insn *, lsampl_t *); -static int ai_rinsn(comedi_device *, comedi_subdevice *, comedi_insn *, lsampl_t *); -static int ao_rinsn(comedi_device *, comedi_subdevice *, comedi_insn *, lsampl_t *); -static int ao_winsn(comedi_device *, comedi_subdevice *, comedi_insn *, lsampl_t *); +static int ai_rinsn(comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); +static int ao_rinsn(comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); +static int ao_winsn(comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); /* * Board descriptions for two imaginary boards. Describing the * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct pcmmio_board_struct -{ +typedef struct pcmmio_board_struct { const char *name; const int dio_num_asics; const int dio_num_ports; - const int total_iosize; - const int ai_bits; - const int ao_bits; - const int n_ai_chans; - const int n_ao_chans; - const comedi_lrange *ai_range_table, *ao_range_table; - comedi_insn_fn_t ai_rinsn, ao_rinsn, ao_winsn; + const int total_iosize; + const int ai_bits; + const int ao_bits; + const int n_ai_chans; + const int n_ao_chans; + const comedi_lrange *ai_range_table, *ao_range_table; + comedi_insn_fn_t ai_rinsn, ao_rinsn, ao_winsn; } pcmmio_board; static const comedi_lrange ranges_ai = -{ 4, { RANGE(-5.,5.), RANGE(-10.,10.), RANGE(0.,5.), RANGE(0.,10.) } }; + { 4, {RANGE(-5., 5.), RANGE(-10., 10.), RANGE(0., 5.), RANGE(0., + 10.)} +}; static const comedi_lrange ranges_ao = -{ 6, { RANGE(0.,5.), RANGE(0.,10.) , RANGE(-5.,5.), RANGE(-10.,10.), RANGE(-2.5, 2.5), RANGE(-2.5, 7.5) } }; + { 6, {RANGE(0., 5.), RANGE(0., 10.), RANGE(-5., 5.), RANGE(-10., 10.), + RANGE(-2.5, 2.5), RANGE(-2.5, 7.5)} +}; -static const pcmmio_board pcmmio_boards[] = -{ +static const pcmmio_board pcmmio_boards[] = { { - name: "pcmmio", - dio_num_asics: 1, - dio_num_ports: 6, - total_iosize: 32, - ai_bits: 16, - ao_bits: 16, - n_ai_chans: 16, - n_ao_chans: 8, - ai_range_table: &ranges_ai, - ao_range_table: &ranges_ao, - ai_rinsn: ai_rinsn, - ao_rinsn: ao_rinsn, - ao_winsn: ao_winsn - }, + name: "pcmmio", + dio_num_asics:1, + dio_num_ports:6, + total_iosize:32, + ai_bits: 16, + ao_bits: 16, + n_ai_chans:16, + n_ao_chans:8, + ai_range_table:&ranges_ai, + ao_range_table:&ranges_ao, + ai_rinsn:ai_rinsn, + ao_rinsn:ao_rinsn, + ao_winsn:ao_winsn}, }; /* @@ -196,59 +200,56 @@ static const pcmmio_board pcmmio_boards[] = #define thisboard ((const pcmmio_board *)dev->board_ptr) /* this structure is for data unique to this subdevice. */ -typedef struct -{ - - union { - /* for DIO: mapping of halfwords (bytes) in port/chanarray to iobase */ - unsigned long iobases[PORTS_PER_SUBDEV]; - - /* for AI/AO */ - unsigned long iobase; - }; - union { - struct { - - /* The below is only used for intr subdevices */ - struct { - int asic; /* if non-negative, this subdev has an interrupt asic */ - int first_chan; /* if nonnegative, the first channel id for - interrupts. */ - int num_asic_chans; /* the number of asic channels in this subdev - that have interrutps */ - int asic_chan; /* if nonnegative, the first channel id with - respect to the asic that has interrupts */ - int enabled_mask; /* subdev-relative channel mask for channels - we are interested in */ - int active; - int stop_count; - int continuous; - spinlock_t spinlock; - } intr; - } dio; - struct { - lsampl_t shadow_samples[8]; /* the last lsampl_t data written */ - } ao; - }; +typedef struct { + + union { + /* for DIO: mapping of halfwords (bytes) in port/chanarray to iobase */ + unsigned long iobases[PORTS_PER_SUBDEV]; + + /* for AI/AO */ + unsigned long iobase; + }; + union { + struct { + + /* The below is only used for intr subdevices */ + struct { + int asic; /* if non-negative, this subdev has an interrupt asic */ + int first_chan; /* if nonnegative, the first channel id for + interrupts. */ + int num_asic_chans; /* the number of asic channels in this subdev + that have interrutps */ + int asic_chan; /* if nonnegative, the first channel id with + respect to the asic that has interrupts */ + int enabled_mask; /* subdev-relative channel mask for channels + we are interested in */ + int active; + int stop_count; + int continuous; + spinlock_t spinlock; + } intr; + } dio; + struct { + lsampl_t shadow_samples[8]; /* the last lsampl_t data written */ + } ao; + }; } pcmmio_subdev_private; /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct -{ - /* stuff for DIO */ - struct - { - unsigned char pagelock; /* current page and lock*/ - unsigned char pol [NUM_PAGED_REGS]; /* shadow of POLx registers */ - unsigned char enab[NUM_PAGED_REGS]; /* shadow of ENABx registers */ - int num; - unsigned long iobase; - unsigned int irq; - spinlock_t spinlock; - } asics[MAX_ASICS]; - pcmmio_subdev_private *sprivs; +typedef struct { + /* stuff for DIO */ + struct { + unsigned char pagelock; /* current page and lock */ + unsigned char pol[NUM_PAGED_REGS]; /* shadow of POLx registers */ + unsigned char enab[NUM_PAGED_REGS]; /* shadow of ENABx registers */ + int num; + unsigned long iobase; + unsigned int irq; + spinlock_t spinlock; + } asics[MAX_ASICS]; + pcmmio_subdev_private *sprivs; } pcmmio_private; /* @@ -263,15 +264,14 @@ typedef struct * the board, and also about the kernel module that contains * the device code. */ -static int pcmmio_attach(comedi_device *dev, comedi_devconfig *it); -static int pcmmio_detach(comedi_device *dev); - -static comedi_driver driver = -{ - driver_name: "pcmmio", - module: THIS_MODULE, - attach: pcmmio_attach, - detach: pcmmio_detach, +static int pcmmio_attach(comedi_device * dev, comedi_devconfig * it); +static int pcmmio_detach(comedi_device * dev); + +static comedi_driver driver = { + driver_name:"pcmmio", + module:THIS_MODULE, + attach:pcmmio_attach, + detach:pcmmio_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -290,27 +290,28 @@ static comedi_driver driver = * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &pcmmio_boards[0].name, - offset: sizeof(pcmmio_board), - num_names: sizeof(pcmmio_boards) / sizeof(pcmmio_board), + board_name:&pcmmio_boards[0].name, + offset:sizeof(pcmmio_board), + num_names:sizeof(pcmmio_boards) / sizeof(pcmmio_board), }; -static int pcmmio_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pcmmio_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int pcmmio_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pcmmio_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); static irqreturn_t interrupt_pcmmio(int irq, void *d PT_REGS_ARG); static void pcmmio_stop_intr(comedi_device *, comedi_subdevice *); -static int pcmmio_cancel(comedi_device *dev, comedi_subdevice *s); -static int pcmmio_cmd(comedi_device *dev, comedi_subdevice *s); -static int pcmmio_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); +static int pcmmio_cancel(comedi_device * dev, comedi_subdevice * s); +static int pcmmio_cmd(comedi_device * dev, comedi_subdevice * s); +static int pcmmio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); /* some helper functions to deal with specifics of this device's registers */ -static void init_asics(comedi_device *dev); /* sets up/clears ASIC chips to defaults */ -static void switch_page(comedi_device *dev, int asic, int page); -static void lock_port(comedi_device *dev, int asic, int port); -static void unlock_port(comedi_device *dev, int asic, int port); +static void init_asics(comedi_device * dev); /* sets up/clears ASIC chips to defaults */ +static void switch_page(comedi_device * dev, int asic, int page); +static void lock_port(comedi_device * dev, int asic, int port); +static void unlock_port(comedi_device * dev, int asic, int port); /* * Attach is called by the Comedi core to configure the driver @@ -318,194 +319,202 @@ static void unlock_port(comedi_device *dev, int asic, int port); * in the driver structure, dev->board_ptr contains that * address. */ -static int pcmmio_attach(comedi_device *dev, comedi_devconfig *it) +static int pcmmio_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int sdev_no, chans_left, n_dio_subdevs, n_subdevs, port, asic, thisasic_chanct = 0; + int sdev_no, chans_left, n_dio_subdevs, n_subdevs, port, asic, + thisasic_chanct = 0; unsigned long iobase; unsigned int irq[MAX_ASICS]; - iobase = it->options[0]; - irq[0] = it->options[1]; + iobase = it->options[0]; + irq[0] = it->options[1]; - printk("comedi%d: %s: io: %lx ", dev->minor, driver.driver_name, iobase); + printk("comedi%d: %s: io: %lx ", dev->minor, driver.driver_name, + iobase); - dev->iobase = iobase; + dev->iobase = iobase; - if ( !iobase || !request_region(iobase, - thisboard->total_iosize, - driver.driver_name) ) { - printk("I/O port conflict\n"); - return -EIO; - } + if (!iobase || !request_region(iobase, + thisboard->total_iosize, driver.driver_name)) { + printk("I/O port conflict\n"); + return -EIO; + } /* * Initialize dev->board_name. Note that we can use the "thisboard" * macro now, since we just initialized it in the last line. */ - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; /* * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if (alloc_private(dev,sizeof(pcmmio_private)) < 0) { - printk("cannot allocate private data structure\n"); - return -ENOMEM; - } - - for (asic = 0; asic < MAX_ASICS; ++asic) { - devpriv->asics[asic].num = asic; - devpriv->asics[asic].iobase = dev->iobase + 16 + asic*ASIC_IOSIZE; - devpriv->asics[asic].irq = 0; /* this gets actually set at the end of - this function when we - comedi_request_irqs */ - spin_lock_init(&devpriv->asics[asic].spinlock); - } - - chans_left = CHANS_PER_ASIC * thisboard->dio_num_asics; - n_dio_subdevs = CALC_N_DIO_SUBDEVS(chans_left); - n_subdevs = n_dio_subdevs + 2; - devpriv->sprivs = kcalloc(n_subdevs, sizeof(pcmmio_subdev_private), GFP_KERNEL); - if (!devpriv->sprivs) { - printk("cannot allocate subdevice private data structures\n"); - return -ENOMEM; - } - /* - * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. - * - * Allocate 1 AI + 1 AO + 2 DIO subdevs (24 lines per DIO) - */ - if ( alloc_subdevices(dev, n_subdevs ) < 0 ) { - printk("cannot allocate subdevice data structures\n"); - return -ENOMEM; - } - - /* First, AI */ - sdev_no = 0; - s = dev->subdevices + sdev_no; - s->private = devpriv->sprivs + sdev_no; - s->maxdata = (1<ai_bits)-1; - s->range_table = thisboard->ai_range_table; - s->subdev_flags = SDF_READABLE|SDF_GROUND|SDF_DIFF; - s->type = COMEDI_SUBD_AI; - s->n_chan = thisboard->n_ai_chans; - s->len_chanlist = s->n_chan; - s->insn_read = thisboard->ai_rinsn; - subpriv->iobase = dev->iobase+0; - /* initialize the resource enable register by clearing it */ - outb(0, subpriv->iobase + 3); - outb(0, subpriv->iobase+4 + 3); - - /* Next, AO */ - ++sdev_no; - s = dev->subdevices + sdev_no; - s->private = devpriv->sprivs + sdev_no; - s->maxdata = (1<ao_bits)-1; - s->range_table = thisboard->ao_range_table; - s->subdev_flags = SDF_READABLE; - s->type = COMEDI_SUBD_AO; - s->n_chan = thisboard->n_ao_chans; - s->len_chanlist = s->n_chan; - s->insn_read = thisboard->ao_rinsn; - s->insn_write = thisboard->ao_winsn; - subpriv->iobase = dev->iobase+8; - /* initialize the resource enable register by clearing it */ - outb(0, subpriv->iobase + 3); - outb(0, subpriv->iobase+4 + 3); - - ++sdev_no; - port = 0; - asic = 0; - for (; sdev_no < (int)dev->n_subdevices; ++sdev_no) - { - int byte_no; - - s = dev->subdevices + sdev_no; - s->private = devpriv->sprivs + sdev_no; - s->maxdata = 1; - s->range_table = &range_digital; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->type = COMEDI_SUBD_DIO; - s->insn_bits = pcmmio_dio_insn_bits; - s->insn_config = pcmmio_dio_insn_config; - s->n_chan = MIN(chans_left, MAX_CHANS_PER_SUBDEV); - subpriv->dio.intr.asic = -1; - subpriv->dio.intr.first_chan = -1; - subpriv->dio.intr.asic_chan = -1; - subpriv->dio.intr.num_asic_chans = -1; - subpriv->dio.intr.active = 0; - s->len_chanlist = 1; - - /* save the ioport address for each 'port' of 8 channels in the - subdevice */ - for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) { - if (port >= PORTS_PER_ASIC) { - port = 0; - ++asic; - thisasic_chanct = 0; - } - subpriv->iobases[byte_no] = devpriv->asics[asic].iobase + port; - - if (thisasic_chanct < CHANS_PER_PORT*INTR_PORTS_PER_ASIC - && subpriv->dio.intr.asic < 0) { - /* this is an interrupt subdevice, so setup the struct */ - subpriv->dio.intr.asic = asic; - subpriv->dio.intr.active = 0; - subpriv->dio.intr.stop_count = 0; - subpriv->dio.intr.first_chan = byte_no * 8; - subpriv->dio.intr.asic_chan = thisasic_chanct; - subpriv->dio.intr.num_asic_chans = s->n_chan - subpriv->dio.intr.first_chan; - s->cancel = pcmmio_cancel; - s->do_cmd = pcmmio_cmd; - s->do_cmdtest = pcmmio_cmdtest; - s->len_chanlist = subpriv->dio.intr.num_asic_chans; - } - thisasic_chanct += CHANS_PER_PORT; - } - spin_lock_init(&subpriv->dio.intr.spinlock); - - chans_left -= s->n_chan; - - if (!chans_left) { - asic = 0; /* reset the asic to our first asic, to do intr subdevs */ - port = 0; - } - - } - - init_asics(dev); /* clear out all the registers, basically */ - - for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) { - if (irq[asic] && comedi_request_irq(irq[asic], interrupt_pcmmio, IRQF_SHARED, thisboard->name, dev)) { - int i; - /* unroll the allocated irqs.. */ - for (i = asic-1; i >= 0; --i) { - comedi_free_irq(irq[i], dev); - devpriv->asics[i].irq = irq[i] = 0; - } - irq[asic] = 0; - } - devpriv->asics[asic].irq = irq[asic]; - } - - dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple - irqs.. */ - - if (irq[0]) { - printk("irq: %u ", irq[0]); - if (irq[1] && thisboard->dio_num_asics == 2) - printk("second ASIC irq: %u ", irq[1]); - } else { - printk("(IRQ mode disabled) "); - } - - printk("attached\n"); - - return 1; -} + if (alloc_private(dev, sizeof(pcmmio_private)) < 0) { + printk("cannot allocate private data structure\n"); + return -ENOMEM; + } + for (asic = 0; asic < MAX_ASICS; ++asic) { + devpriv->asics[asic].num = asic; + devpriv->asics[asic].iobase = + dev->iobase + 16 + asic * ASIC_IOSIZE; + devpriv->asics[asic].irq = 0; /* this gets actually set at the end of + this function when we + comedi_request_irqs */ + spin_lock_init(&devpriv->asics[asic].spinlock); + } + + chans_left = CHANS_PER_ASIC * thisboard->dio_num_asics; + n_dio_subdevs = CALC_N_DIO_SUBDEVS(chans_left); + n_subdevs = n_dio_subdevs + 2; + devpriv->sprivs = + kcalloc(n_subdevs, sizeof(pcmmio_subdev_private), GFP_KERNEL); + if (!devpriv->sprivs) { + printk("cannot allocate subdevice private data structures\n"); + return -ENOMEM; + } + /* + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. + * + * Allocate 1 AI + 1 AO + 2 DIO subdevs (24 lines per DIO) + */ + if (alloc_subdevices(dev, n_subdevs) < 0) { + printk("cannot allocate subdevice data structures\n"); + return -ENOMEM; + } + + /* First, AI */ + sdev_no = 0; + s = dev->subdevices + sdev_no; + s->private = devpriv->sprivs + sdev_no; + s->maxdata = (1 << thisboard->ai_bits) - 1; + s->range_table = thisboard->ai_range_table; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; + s->type = COMEDI_SUBD_AI; + s->n_chan = thisboard->n_ai_chans; + s->len_chanlist = s->n_chan; + s->insn_read = thisboard->ai_rinsn; + subpriv->iobase = dev->iobase + 0; + /* initialize the resource enable register by clearing it */ + outb(0, subpriv->iobase + 3); + outb(0, subpriv->iobase + 4 + 3); + + /* Next, AO */ + ++sdev_no; + s = dev->subdevices + sdev_no; + s->private = devpriv->sprivs + sdev_no; + s->maxdata = (1 << thisboard->ao_bits) - 1; + s->range_table = thisboard->ao_range_table; + s->subdev_flags = SDF_READABLE; + s->type = COMEDI_SUBD_AO; + s->n_chan = thisboard->n_ao_chans; + s->len_chanlist = s->n_chan; + s->insn_read = thisboard->ao_rinsn; + s->insn_write = thisboard->ao_winsn; + subpriv->iobase = dev->iobase + 8; + /* initialize the resource enable register by clearing it */ + outb(0, subpriv->iobase + 3); + outb(0, subpriv->iobase + 4 + 3); + + ++sdev_no; + port = 0; + asic = 0; + for (; sdev_no < (int)dev->n_subdevices; ++sdev_no) { + int byte_no; + + s = dev->subdevices + sdev_no; + s->private = devpriv->sprivs + sdev_no; + s->maxdata = 1; + s->range_table = &range_digital; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->type = COMEDI_SUBD_DIO; + s->insn_bits = pcmmio_dio_insn_bits; + s->insn_config = pcmmio_dio_insn_config; + s->n_chan = MIN(chans_left, MAX_CHANS_PER_SUBDEV); + subpriv->dio.intr.asic = -1; + subpriv->dio.intr.first_chan = -1; + subpriv->dio.intr.asic_chan = -1; + subpriv->dio.intr.num_asic_chans = -1; + subpriv->dio.intr.active = 0; + s->len_chanlist = 1; + + /* save the ioport address for each 'port' of 8 channels in the + subdevice */ + for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) { + if (port >= PORTS_PER_ASIC) { + port = 0; + ++asic; + thisasic_chanct = 0; + } + subpriv->iobases[byte_no] = + devpriv->asics[asic].iobase + port; + + if (thisasic_chanct < + CHANS_PER_PORT * INTR_PORTS_PER_ASIC + && subpriv->dio.intr.asic < 0) { + /* this is an interrupt subdevice, so setup the struct */ + subpriv->dio.intr.asic = asic; + subpriv->dio.intr.active = 0; + subpriv->dio.intr.stop_count = 0; + subpriv->dio.intr.first_chan = byte_no * 8; + subpriv->dio.intr.asic_chan = thisasic_chanct; + subpriv->dio.intr.num_asic_chans = + s->n_chan - + subpriv->dio.intr.first_chan; + s->cancel = pcmmio_cancel; + s->do_cmd = pcmmio_cmd; + s->do_cmdtest = pcmmio_cmdtest; + s->len_chanlist = + subpriv->dio.intr.num_asic_chans; + } + thisasic_chanct += CHANS_PER_PORT; + } + spin_lock_init(&subpriv->dio.intr.spinlock); + + chans_left -= s->n_chan; + + if (!chans_left) { + asic = 0; /* reset the asic to our first asic, to do intr subdevs */ + port = 0; + } + + } + + init_asics(dev); /* clear out all the registers, basically */ + + for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) { + if (irq[asic] + && comedi_request_irq(irq[asic], interrupt_pcmmio, + IRQF_SHARED, thisboard->name, dev)) { + int i; + /* unroll the allocated irqs.. */ + for (i = asic - 1; i >= 0; --i) { + comedi_free_irq(irq[i], dev); + devpriv->asics[i].irq = irq[i] = 0; + } + irq[asic] = 0; + } + devpriv->asics[asic].irq = irq[asic]; + } + + dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple + irqs.. */ + + if (irq[0]) { + printk("irq: %u ", irq[0]); + if (irq[1] && thisboard->dio_num_asics == 2) + printk("second ASIC irq: %u ", irq[1]); + } else { + printk("(IRQ mode disabled) "); + } + + printk("attached\n"); + + return 1; +} /* * _detach is called to deconfigure a device. It should deallocate @@ -515,435 +524,499 @@ static int pcmmio_attach(comedi_device *dev, comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pcmmio_detach(comedi_device *dev) +static int pcmmio_detach(comedi_device * dev) { - int i; + int i; - printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); - if (dev->iobase) - release_region(dev->iobase, thisboard->total_iosize); + printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); + if (dev->iobase) + release_region(dev->iobase, thisboard->total_iosize); - for (i = 0; i < MAX_ASICS; ++i) { - if (devpriv && devpriv->asics[i].irq) - comedi_free_irq(devpriv->asics[i].irq, dev); - } + for (i = 0; i < MAX_ASICS; ++i) { + if (devpriv && devpriv->asics[i].irq) + comedi_free_irq(devpriv->asics[i].irq, dev); + } - if (devpriv && devpriv->sprivs) - kfree(devpriv->sprivs); + if (devpriv && devpriv->sprivs) + kfree(devpriv->sprivs); - return 0; + return 0; } - /* 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 pcmmio_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcmmio_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int byte_no; - if (insn->n != 2) return -EINVAL; + int byte_no; + if (insn->n != 2) + return -EINVAL; - /* NOTE: - reading a 0 means this channel was high - writine a 0 sets the channel high - reading a 1 means this channel was low - writing a 1 means set this channel low + /* NOTE: + reading a 0 means this channel was high + writine a 0 sets the channel high + reading a 1 means this channel was low + writing a 1 means set this channel low - Therefore everything is always inverted. */ + Therefore everything is always inverted. */ /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("write mask: %08x data: %08x\n", data[0], data[1]); + /* DEBUG */ + printk("write mask: %08x data: %08x\n", data[0], data[1]); #endif - s->state = 0; + s->state = 0; - for (byte_no = 0; byte_no < s->n_chan/CHANS_PER_PORT; ++byte_no) { - /* address of 8-bit port */ - unsigned long ioaddr = subpriv->iobases[byte_no], - /* bit offset of port in 32-bit doubleword */ - offset = byte_no * 8; - /* this 8-bit port's data */ - unsigned char byte = 0, - /* The write mask for this port (if any) */ - write_mask_byte = (data[0] >> offset) & 0xff, - /* The data byte for this port */ - data_byte = (data[1] >> offset) & 0xff; + for (byte_no = 0; byte_no < s->n_chan / CHANS_PER_PORT; ++byte_no) { + /* address of 8-bit port */ + unsigned long ioaddr = subpriv->iobases[byte_no], + /* bit offset of port in 32-bit doubleword */ + offset = byte_no * 8; + /* this 8-bit port's data */ + unsigned char byte = 0, + /* The write mask for this port (if any) */ + write_mask_byte = (data[0] >> offset) & 0xff, + /* The data byte for this port */ + data_byte = (data[1] >> offset) & 0xff; - byte = inb(ioaddr); /* read all 8-bits for this port */ + byte = inb(ioaddr); /* read all 8-bits for this port */ #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ", byte_no, (unsigned)write_mask_byte, (unsigned)data_byte, offset, ioaddr, (unsigned)byte); + /* DEBUG */ + printk("byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ", byte_no, (unsigned)write_mask_byte, (unsigned)data_byte, offset, ioaddr, (unsigned)byte); #endif - if ( write_mask_byte ) { - /* this byte has some write_bits -- so set the output lines */ - byte &= ~write_mask_byte; /* clear bits for write mask */ - byte |= ~data_byte & write_mask_byte; /* set to inverted data_byte */ - /* Write out the new digital output state */ - outb(byte, ioaddr); - } - + if (write_mask_byte) { + /* this byte has some write_bits -- so set the output lines */ + byte &= ~write_mask_byte; /* clear bits for write mask */ + byte |= ~data_byte & write_mask_byte; /* set to inverted data_byte */ + /* Write out the new digital output state */ + outb(byte, ioaddr); + } #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("data_out_byte %02x\n", (unsigned)byte); + /* DEBUG */ + printk("data_out_byte %02x\n", (unsigned)byte); #endif - /* save the digital input lines for this byte.. */ - s->state |= ((unsigned int)byte) << offset; - } + /* save the digital input lines for this byte.. */ + s->state |= ((unsigned int)byte) << offset; + } - /* now return the DIO lines to data[1] - note they came inverted! */ - data[1] = ~s->state; + /* now return the DIO lines to data[1] - note they came inverted! */ + data[1] = ~s->state; #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("s->state %08x data_out %08x\n", s->state, data[1]); + /* DEBUG */ + printk("s->state %08x data_out %08x\n", s->state, data[1]); #endif - return 2; + return 2; } /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ -static int pcmmio_dio_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcmmio_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan = CR_CHAN(insn->chanspec), byte_no = chan/8, bit_no = chan % 8; - unsigned long ioaddr; - unsigned char byte; + int chan = CR_CHAN(insn->chanspec), byte_no = chan / 8, bit_no = + chan % 8; + unsigned long ioaddr; + unsigned char byte; - /* Compute ioaddr for this channel */ - ioaddr = subpriv->iobases[byte_no]; + /* Compute ioaddr for this channel */ + ioaddr = subpriv->iobases[byte_no]; - /* NOTE: - writing a 0 an IO channel's bit sets the channel to INPUT - and pulls the line high as well + /* NOTE: + writing a 0 an IO channel's bit sets the channel to INPUT + and pulls the line high as well - writing a 1 to an IO channel's bit pulls the line low + writing a 1 to an IO channel's bit pulls the line low - All channels are implicitly always in OUTPUT mode -- but when - they are high they can be considered to be in INPUT mode.. + All channels are implicitly always in OUTPUT mode -- but when + they are high they can be considered to be in INPUT mode.. - Thus, we only force channels low if the config request was INPUT, - otherwise we do nothing to the hardware. */ + Thus, we only force channels low if the config request was INPUT, + otherwise we do nothing to the hardware. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - /* save to io_bits -- don't actually do anything since - all input channels are also output channels... */ - s->io_bits |= 1<io_bits |= 1 << chan; + break; case INSN_CONFIG_DIO_INPUT: - /* write a 0 to the actual register representing the channel - to set it to 'input'. 0 means "float high". */ - byte = inb(ioaddr); - byte &= ~(1<io_bits &= ~(1<io_bits &= ~(1 << chan); + break; case INSN_CONFIG_DIO_QUERY: - /* retreive from shadow register */ - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; - break; + /* retreive from shadow register */ + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + return insn->n; + break; default: - return -EINVAL; - break; + return -EINVAL; + break; } return insn->n; } -static void init_asics(comedi_device *dev) /* sets up an - ASIC chip to defaults */ -{ - int asic; - - for (asic = 0; asic < thisboard->dio_num_asics; ++asic) - { - int port, page; - unsigned long baseaddr = devpriv->asics[asic].iobase; - - switch_page(dev, asic, 0); /* switch back to page 0 */ - - /* first, clear all the DIO port bits */ - for (port = 0; port < PORTS_PER_ASIC; ++port) - outb(0, baseaddr + REG_PORT0 + port); - - /* Next, clear all the paged registers for each page */ - for (page = 1; page < NUM_PAGES; ++page) - { - int reg; - /* now clear all the paged registers*/ - switch_page(dev, asic, page); - for (reg = FIRST_PAGED_REG; reg < FIRST_PAGED_REG+NUM_PAGED_REGS; ++reg) - outb(0, baseaddr + reg); - } - - /* DEBUG set rising edge interrupts on port0 of both asics*/ - /*switch_page(dev, asic, PAGE_POL); - outb(0xff, baseaddr + REG_POL0); - switch_page(dev, asic, PAGE_ENAB); - outb(0xff, baseaddr + REG_ENAB0);*/ - /* END DEBUG */ - - switch_page(dev, asic, 0); /* switch back to default page 0 */ - - } -} +static void init_asics(comedi_device * dev) +{ /* sets up an + ASIC chip to defaults */ + int asic; + + for (asic = 0; asic < thisboard->dio_num_asics; ++asic) { + int port, page; + unsigned long baseaddr = devpriv->asics[asic].iobase; + + switch_page(dev, asic, 0); /* switch back to page 0 */ + + /* first, clear all the DIO port bits */ + for (port = 0; port < PORTS_PER_ASIC; ++port) + outb(0, baseaddr + REG_PORT0 + port); + + /* Next, clear all the paged registers for each page */ + for (page = 1; page < NUM_PAGES; ++page) { + int reg; + /* now clear all the paged registers */ + switch_page(dev, asic, page); + for (reg = FIRST_PAGED_REG; + reg < FIRST_PAGED_REG + NUM_PAGED_REGS; ++reg) + outb(0, baseaddr + reg); + } + + /* DEBUG set rising edge interrupts on port0 of both asics */ + /*switch_page(dev, asic, PAGE_POL); + outb(0xff, baseaddr + REG_POL0); + switch_page(dev, asic, PAGE_ENAB); + outb(0xff, baseaddr + REG_ENAB0); */ + /* END DEBUG */ + switch_page(dev, asic, 0); /* switch back to default page 0 */ -static void switch_page(comedi_device *dev, int asic, int page) + } +} + +static void switch_page(comedi_device * dev, int asic, int page) { - if (asic < 0 || asic >= thisboard->dio_num_asics) return; /* paranoia */ - if (page < 0 || page >= NUM_PAGES) return; /* more paranoia */ + if (asic < 0 || asic >= thisboard->dio_num_asics) + return; /* paranoia */ + if (page < 0 || page >= NUM_PAGES) + return; /* more paranoia */ - devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK; - devpriv->asics[asic].pagelock |= page<asics[asic].pagelock &= ~REG_PAGE_MASK; + devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET; - /* now write out the shadow register */ - outb(devpriv->asics[asic].pagelock, - devpriv->asics[asic].iobase + REG_PAGELOCK); + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + devpriv->asics[asic].iobase + REG_PAGELOCK); } -static void lock_port(comedi_device *dev, int asic, int port) +static void lock_port(comedi_device * dev, int asic, int port) { - if (asic < 0 || asic >= thisboard->dio_num_asics) return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) return; /* more paranoia */ - - devpriv->asics[asic].pagelock |= 0x1<asics[asic].pagelock, devpriv->asics[asic].iobase + REG_PAGELOCK); - return; - (void)lock_port(dev, asic, port); /* not reached, suppress compiler warnings*/ + if (asic < 0 || asic >= thisboard->dio_num_asics) + return; /* paranoia */ + if (port < 0 || port >= PORTS_PER_ASIC) + return; /* more paranoia */ + + devpriv->asics[asic].pagelock |= 0x1 << port; + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + devpriv->asics[asic].iobase + REG_PAGELOCK); + return; + (void)lock_port(dev, asic, port); /* not reached, suppress compiler warnings */ } -static void unlock_port(comedi_device *dev, int asic, int port) +static void unlock_port(comedi_device * dev, int asic, int port) { - if (asic < 0 || asic >= thisboard->dio_num_asics) return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) return; /* more paranoia */ - devpriv->asics[asic].pagelock &= ~(0x1<asics[asic].pagelock, devpriv->asics[asic].iobase + REG_PAGELOCK); - (void)unlock_port(dev, asic, port); /* not reached, suppress compiler warnings*/ + if (asic < 0 || asic >= thisboard->dio_num_asics) + return; /* paranoia */ + if (port < 0 || port >= PORTS_PER_ASIC) + return; /* more paranoia */ + devpriv->asics[asic].pagelock &= ~(0x1 << port) | REG_LOCK_MASK; + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + devpriv->asics[asic].iobase + REG_PAGELOCK); + (void)unlock_port(dev, asic, port); /* not reached, suppress compiler warnings */ } static irqreturn_t interrupt_pcmmio(int irq, void *d PT_REGS_ARG) { - int asic, got1 = 0; - comedi_device *dev = (comedi_device *)d; - - for (asic = 0; asic < MAX_ASICS; ++asic) { - if (irq == devpriv->asics[asic].irq) { - unsigned long flags; - unsigned triggered = 0; - unsigned long iobase = devpriv->asics[asic].iobase; - /* it is an interrupt for ASIC #asic */ - unsigned char int_pend; - - comedi_spin_lock_irqsave(&devpriv->asics[asic].spinlock, flags); - - int_pend = inb(iobase + REG_INT_PENDING) & 0x07; - - if (int_pend) { - int port; - for (port = 0; port < INTR_PORTS_PER_ASIC; ++port) { - if (int_pend & (0x1<asics[asic].spinlock, flags); - - if (triggered) { - comedi_subdevice *s; - /* TODO here: dispatch io lines to subdevs with commands.. */ - printk("PCMMIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n", irq, asic, triggered); - for (s = dev->subdevices+2; s < dev->subdevices + dev->n_subdevices; ++s) { - if (subpriv->dio.intr.asic == asic) { /* this is an interrupt subdev, and it matches this asic! */ - unsigned long flags; - unsigned oldevents; - - comedi_spin_lock_irqsave(&subpriv->dio.intr.spinlock, flags); - - oldevents = s->async->events; - - if (subpriv->dio.intr.active) { - unsigned mytrig = ((triggered >> subpriv->dio.intr.asic_chan) & ((0x1<dio.intr.num_asic_chans)-1)) << subpriv->dio.intr.first_chan; - if (mytrig & subpriv->dio.intr.enabled_mask) { - lsampl_t val = 0; - unsigned int n, ch, len; - - len = s->async->cmd.chanlist_len; - for (n = 0; n < len; n++) { - ch = CR_CHAN(s->async->cmd.chanlist[n]); - if (mytrig & (1U << ch)) { - val |= (1U << n); - } - } - /* Write the scan to the buffer. */ - if (comedi_buf_put(s->async, ((sampl_t *)&val)[0]) - && comedi_buf_put(s->async, ((sampl_t *)&val)[1]) ) { - s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); - } else { - /* Overflow! Stop acquisition!! */ - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmmio_stop_intr(dev, s); - } - - /* Check for end of acquisition. */ - if (!subpriv->dio.intr.continuous) { - /* stop_src == TRIG_COUNT */ - if (subpriv->dio.intr.stop_count > 0) { - subpriv->dio.intr.stop_count--; - if (subpriv->dio.intr.stop_count == 0) { - s->async->events |= COMEDI_CB_EOA; - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmmio_stop_intr(dev, s); - } - } - } - } - } - - comedi_spin_unlock_irqrestore(&subpriv->dio.intr.spinlock, flags); - - if (oldevents != s->async->events) { - comedi_event(dev, s); - } - - } - - } - } - - } - } - if (!got1) return IRQ_NONE; /* interrupt from other source */ - return IRQ_HANDLED; -} + int asic, got1 = 0; + comedi_device *dev = (comedi_device *) d; + + for (asic = 0; asic < MAX_ASICS; ++asic) { + if (irq == devpriv->asics[asic].irq) { + unsigned long flags; + unsigned triggered = 0; + unsigned long iobase = devpriv->asics[asic].iobase; + /* it is an interrupt for ASIC #asic */ + unsigned char int_pend; + + comedi_spin_lock_irqsave(&devpriv->asics[asic].spinlock, + flags); + + int_pend = inb(iobase + REG_INT_PENDING) & 0x07; + + if (int_pend) { + int port; + for (port = 0; port < INTR_PORTS_PER_ASIC; + ++port) { + if (int_pend & (0x1 << port)) { + unsigned char + io_lines_with_edges = 0; + switch_page(dev, asic, + PAGE_INT_ID); + io_lines_with_edges = + inb(iobase + + REG_INT_ID0 + port); + + if (io_lines_with_edges) + /* clear pending interrupt */ + outb(0, iobase + + REG_INT_ID0 + + port); + + triggered |= + io_lines_with_edges << + port * 8; + } + } + + ++got1; + } + + comedi_spin_unlock_irqrestore(&devpriv->asics[asic]. + spinlock, flags); + + if (triggered) { + comedi_subdevice *s; + /* TODO here: dispatch io lines to subdevs with commands.. */ + printk("PCMMIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n", irq, asic, triggered); + for (s = dev->subdevices + 2; + s < dev->subdevices + dev->n_subdevices; + ++s) { + if (subpriv->dio.intr.asic == asic) { /* this is an interrupt subdev, and it matches this asic! */ + unsigned long flags; + unsigned oldevents; + + comedi_spin_lock_irqsave + (&subpriv->dio.intr. + spinlock, flags); + + oldevents = s->async->events; + + if (subpriv->dio.intr.active) { + unsigned mytrig = + ((triggered >> + subpriv-> + dio. + intr. + asic_chan) + & ((0x1 << subpriv->dio.intr.num_asic_chans) - 1)) << subpriv->dio.intr.first_chan; + if (mytrig & subpriv-> + dio.intr. + enabled_mask) { + lsampl_t val = + 0; + unsigned int n, + ch, len; + + len = s->async-> + cmd. + chanlist_len; + for (n = 0; + n < len; + n++) { + ch = CR_CHAN(s->async->cmd.chanlist[n]); + if (mytrig & (1U << ch)) { + val |= (1U << n); + } + } + /* Write the scan to the buffer. */ + if (comedi_buf_put(s->async, ((sampl_t *) & val)[0]) + && + comedi_buf_put + (s->async, ((sampl_t *) & val)[1])) { + s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); + } else { + /* Overflow! Stop acquisition!! */ + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmmio_stop_intr + (dev, + s); + } + + /* Check for end of acquisition. */ + if (!subpriv-> + dio. + intr. + continuous) + { + /* stop_src == TRIG_COUNT */ + if (subpriv->dio.intr.stop_count > 0) { + subpriv-> + dio. + intr. + stop_count--; + if (subpriv->dio.intr.stop_count == 0) { + s->async->events |= COMEDI_CB_EOA; + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmmio_stop_intr + (dev, + s); + } + } + } + } + } + + comedi_spin_unlock_irqrestore + (&subpriv->dio.intr. + spinlock, flags); + + if (oldevents != + s->async->events) { + comedi_event(dev, s); + } + + } + + } + } + } + } + if (!got1) + return IRQ_NONE; /* interrupt from other source */ + return IRQ_HANDLED; +} -static void pcmmio_stop_intr(comedi_device *dev, comedi_subdevice *s) +static void pcmmio_stop_intr(comedi_device * dev, comedi_subdevice * s) { - int nports, firstport, asic, port; - - if ( (asic = subpriv->dio.intr.asic) < 0 ) return; /* not an interrupt subdev */ - - subpriv->dio.intr.enabled_mask = 0; - subpriv->dio.intr.active = 0; - s->async->inttrig = 0; - nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT; - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport+nports; ++port) { - /* disable all intrs for this subdev.. */ - outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); - } + int nports, firstport, asic, port; + + if ((asic = subpriv->dio.intr.asic) < 0) + return; /* not an interrupt subdev */ + + subpriv->dio.intr.enabled_mask = 0; + subpriv->dio.intr.active = 0; + s->async->inttrig = 0; + nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT; + firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT; + switch_page(dev, asic, PAGE_ENAB); + for (port = firstport; port < firstport + nports; ++port) { + /* disable all intrs for this subdev.. */ + outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); + } } -static int pcmmio_start_intr(comedi_device *dev, comedi_subdevice *s) +static int pcmmio_start_intr(comedi_device * dev, comedi_subdevice * s) { - if (!subpriv->dio.intr.continuous && subpriv->dio.intr.stop_count == 0) { - /* An empty acquisition! */ - s->async->events |= COMEDI_CB_EOA; - subpriv->dio.intr.active = 0; - return 1; - } else { - unsigned bits = 0, pol_bits = 0, n; - int nports, firstport, asic, port; - comedi_cmd *cmd = &s->async->cmd; - - if ( (asic = subpriv->dio.intr.asic) < 0 ) return 1; /* not an interrupt - subdev */ - subpriv->dio.intr.enabled_mask = 0; - subpriv->dio.intr.active = 1; - nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT; - if (cmd->chanlist) { - for (n = 0; n < cmd->chanlist_len; n++) { - bits |= (1U << CR_CHAN(cmd->chanlist[n])); - pol_bits |= - (CR_AREF(cmd->chanlist[n]) || CR_RANGE(cmd->chanlist[n]) ? 1U : 0U) - << CR_CHAN(cmd->chanlist[n]); - } - } - bits &= ((0x1<dio.intr.num_asic_chans)-1) << subpriv->dio.intr.first_chan; - subpriv->dio.intr.enabled_mask = bits; - - { /* the below code configures the board to use a specific IRQ from 0-15. */ - unsigned char b; - /* set resource enable register to enable IRQ operation */ - outb(1<<4, dev->iobase+3); - /* set bits 0-3 of b to the irq number from 0-15 */ - b = dev->irq & ((1<<4)-1); - outb(b, dev->iobase+2); - /* done, we told the board what irq to use */ - } - - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport+nports; ++port) { - unsigned enab = bits >> (subpriv->dio.intr.first_chan + (port-firstport)*8) & 0xff, - pol = pol_bits >> (subpriv->dio.intr.first_chan + (port-firstport)*8) & 0xff ; - /* set enab intrs for this subdev.. */ - outb(enab, devpriv->asics[asic].iobase + REG_ENAB0 + port); - switch_page(dev, asic, PAGE_POL); - outb(pol, devpriv->asics[asic].iobase + REG_ENAB0 + port); - } - } - return 0; + if (!subpriv->dio.intr.continuous && subpriv->dio.intr.stop_count == 0) { + /* An empty acquisition! */ + s->async->events |= COMEDI_CB_EOA; + subpriv->dio.intr.active = 0; + return 1; + } else { + unsigned bits = 0, pol_bits = 0, n; + int nports, firstport, asic, port; + comedi_cmd *cmd = &s->async->cmd; + + if ((asic = subpriv->dio.intr.asic) < 0) + return 1; /* not an interrupt + subdev */ + subpriv->dio.intr.enabled_mask = 0; + subpriv->dio.intr.active = 1; + nports = subpriv->dio.intr.num_asic_chans / CHANS_PER_PORT; + firstport = subpriv->dio.intr.asic_chan / CHANS_PER_PORT; + if (cmd->chanlist) { + for (n = 0; n < cmd->chanlist_len; n++) { + bits |= (1U << CR_CHAN(cmd->chanlist[n])); + pol_bits |= (CR_AREF(cmd->chanlist[n]) + || CR_RANGE(cmd->chanlist[n]) ? 1U : 0U) + << CR_CHAN(cmd->chanlist[n]); + } + } + bits &= ((0x1 << subpriv->dio.intr.num_asic_chans) - + 1) << subpriv->dio.intr.first_chan; + subpriv->dio.intr.enabled_mask = bits; + + { /* the below code configures the board to use a specific IRQ from 0-15. */ + unsigned char b; + /* set resource enable register to enable IRQ operation */ + outb(1 << 4, dev->iobase + 3); + /* set bits 0-3 of b to the irq number from 0-15 */ + b = dev->irq & ((1 << 4) - 1); + outb(b, dev->iobase + 2); + /* done, we told the board what irq to use */ + } + + switch_page(dev, asic, PAGE_ENAB); + for (port = firstport; port < firstport + nports; ++port) { + unsigned enab = + bits >> (subpriv->dio.intr.first_chan + (port - + firstport) * 8) & 0xff, pol = + pol_bits >> (subpriv->dio.intr.first_chan + + (port - firstport) * 8) & 0xff; + /* set enab intrs for this subdev.. */ + outb(enab, + devpriv->asics[asic].iobase + REG_ENAB0 + port); + switch_page(dev, asic, PAGE_POL); + outb(pol, + devpriv->asics[asic].iobase + REG_ENAB0 + port); + } + } + return 0; } -static int pcmmio_cancel(comedi_device *dev, comedi_subdevice *s) +static int pcmmio_cancel(comedi_device * dev, comedi_subdevice * s) { - unsigned long flags; + unsigned long flags; - comedi_spin_lock_irqsave(&subpriv->dio.intr.spinlock, flags); - if (subpriv->dio.intr.active) pcmmio_stop_intr(dev, s); - comedi_spin_unlock_irqrestore(&subpriv->dio.intr.spinlock, flags); + comedi_spin_lock_irqsave(&subpriv->dio.intr.spinlock, flags); + if (subpriv->dio.intr.active) + pcmmio_stop_intr(dev, s); + comedi_spin_unlock_irqrestore(&subpriv->dio.intr.spinlock, flags); - return 0; + return 0; } /* * Internal trigger function to start acquisition for an 'INTERRUPT' subdevice. */ static int -pcmmio_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, unsigned int trignum) +pcmmio_inttrig_start_intr(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) { unsigned long flags; int event = 0; - if (trignum != 0) return -EINVAL; + if (trignum != 0) + return -EINVAL; comedi_spin_lock_irqsave(&subpriv->dio.intr.spinlock, flags); s->async->inttrig = 0; @@ -959,12 +1032,10 @@ pcmmio_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, unsigned int return 1; } - /* * 'do_cmd' function for an 'INTERRUPT' subdevice. */ -static int -pcmmio_cmd(comedi_device *dev, comedi_subdevice *s) +static int pcmmio_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned long flags; @@ -1009,8 +1080,7 @@ pcmmio_cmd(comedi_device *dev, comedi_subdevice *s) * 'do_cmdtest' function for an 'INTERRUPT' subdevice. */ static int -pcmmio_cmdtest(comedi_device *dev, comedi_subdevice *s, - comedi_cmd *cmd) +pcmmio_cmdtest(comedi_device * dev, comedi_subdevice * s, comedi_cmd * cmd) { int err = 0; unsigned int tmp; @@ -1019,36 +1089,48 @@ pcmmio_cmdtest(comedi_device *dev, comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= (TRIG_NOW | TRIG_INT); - if (!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if (!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= (TRIG_COUNT | TRIG_NONE); - if (!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if (err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* these tests are true if more than one _src bit is set */ - if ((cmd->start_src & (cmd->start_src - 1)) != 0) err++; - if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) err++; - if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) err++; - if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) err++; - if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) err++; + if ((cmd->start_src & (cmd->start_src - 1)) != 0) + err++; + if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) + err++; + if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) + err++; + if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) + err++; + if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) + err++; - if (err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ @@ -1082,15 +1164,16 @@ pcmmio_cmdtest(comedi_device *dev, comedi_subdevice *s, break; case TRIG_NONE: if (cmd->stop_arg != 0) { - cmd->stop_arg = 0; - err++; + cmd->stop_arg = 0; + err++; } break; default: break; } - if (err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ @@ -1101,144 +1184,148 @@ pcmmio_cmdtest(comedi_device *dev, comedi_subdevice *s, static int adc_wait_ready(unsigned long iobase) { - unsigned long retry = 100000; - while (retry--) - if (inb(iobase + 3) & 0x80) return 0; - return 1; + unsigned long retry = 100000; + while (retry--) + if (inb(iobase + 3) & 0x80) + return 0; + return 1; } /* All this is for AI and AO */ -static int ai_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - unsigned long iobase = subpriv->iobase; - - /* - 1. write the CMD byte (to BASE+2) - 2. read junk lo byte (BASE+0) - 3. read junk hi byte (BASE+1) - 4. (mux settled so) write CMD byte again (BASE+2) - 5. read valid lo byte(BASE+0) - 6. read valid hi byte(BASE+1) - - Additionally note that the BASE += 4 if the channel >= 8 - */ - - - /* convert n samples */ - for(n = 0; n < insn->n; n++) { - unsigned chan = CR_CHAN(insn->chanspec), range = CR_RANGE(insn->chanspec), aref = CR_AREF(insn->chanspec); - unsigned char command_byte = 0; - unsigned iooffset = 0; - sampl_t sample, adc_adjust = 0; - - if (chan > 7) chan -= 8, iooffset = 4; /* use the second dword for channels > 7 */ - - if (aref != AREF_DIFF) { - aref = AREF_GROUND; - command_byte |= 1<<7; /* set bit 7 to indicate single-ended */ - } - if (range < 2) adc_adjust = 0x8000; /* bipolar ranges (-5,5 .. -10,10 need to be adjusted -- that is.. they need to wrap around by adding 0x8000 */ + int n; + unsigned long iobase = subpriv->iobase; + + /* + 1. write the CMD byte (to BASE+2) + 2. read junk lo byte (BASE+0) + 3. read junk hi byte (BASE+1) + 4. (mux settled so) write CMD byte again (BASE+2) + 5. read valid lo byte(BASE+0) + 6. read valid hi byte(BASE+1) + + Additionally note that the BASE += 4 if the channel >= 8 + */ - if (chan % 2) { - command_byte |= 1<<6; /* odd-numbered channels have bit 6 set */ - } + /* convert n samples */ + for (n = 0; n < insn->n; n++) { + unsigned chan = CR_CHAN(insn->chanspec), range = + CR_RANGE(insn->chanspec), aref = + CR_AREF(insn->chanspec); + unsigned char command_byte = 0; + unsigned iooffset = 0; + sampl_t sample, adc_adjust = 0; + + if (chan > 7) + chan -= 8, iooffset = 4; /* use the second dword for channels > 7 */ + + if (aref != AREF_DIFF) { + aref = AREF_GROUND; + command_byte |= 1 << 7; /* set bit 7 to indicate single-ended */ + } + if (range < 2) + adc_adjust = 0x8000; /* bipolar ranges (-5,5 .. -10,10 need to be adjusted -- that is.. they need to wrap around by adding 0x8000 */ - /* select the channel, bits 4-5 == chan/2 */ - command_byte |= ((chan/2) & 0x3)<<4; + if (chan % 2) { + command_byte |= 1 << 6; /* odd-numbered channels have bit 6 set */ + } + /* select the channel, bits 4-5 == chan/2 */ + command_byte |= ((chan / 2) & 0x3) << 4; - /* set the range, bits 2-3 */ - command_byte |= (range & 0x3) << 2; + /* set the range, bits 2-3 */ + command_byte |= (range & 0x3) << 2; - /* need to do this twice to make sure mux settled */ - outb(command_byte, iobase + iooffset + 2); /* chan/range/aref select */ + /* need to do this twice to make sure mux settled */ + outb(command_byte, iobase + iooffset + 2); /* chan/range/aref select */ - adc_wait_ready(iobase + iooffset); /* wait for the adc to say it finised the conversion */ + adc_wait_ready(iobase + iooffset); /* wait for the adc to say it finised the conversion */ - outb(command_byte, iobase + iooffset + 2); /* select the chan/range/aref AGAIN */ + outb(command_byte, iobase + iooffset + 2); /* select the chan/range/aref AGAIN */ - adc_wait_ready(iobase + iooffset); + adc_wait_ready(iobase + iooffset); - sample = inb(iobase+iooffset+0); /* read data lo byte */ - sample |= inb(iobase+iooffset+1)<<8; /* read data hi byte */ - sample += adc_adjust; /* adjustment .. munge data */ - data[n] = sample; - } - /* return the number of samples read/written */ - return n; + sample = inb(iobase + iooffset + 0); /* read data lo byte */ + sample |= inb(iobase + iooffset + 1) << 8; /* read data hi byte */ + sample += adc_adjust; /* adjustment .. munge data */ + data[n] = sample; + } + /* return the number of samples read/written */ + return n; } -static int ao_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - for(n = 0; n < insn->n; n++) { - unsigned chan = CR_CHAN(insn->chanspec); - if (chan < s->n_chan) - data[n] = subpriv->ao.shadow_samples[chan]; - } - return n; + int n; + for (n = 0; n < insn->n; n++) { + unsigned chan = CR_CHAN(insn->chanspec); + if (chan < s->n_chan) + data[n] = subpriv->ao.shadow_samples[chan]; + } + return n; } static int wait_dac_ready(unsigned long iobase) { - unsigned long retry = 100000L; + unsigned long retry = 100000L; - /* This may seem like an absurd way to handle waiting and violates the - "no busy waiting" policy. The fact is that the hardware is - normally so fast that we usually only need one time through the loop - anyway. The longer timeout is for rare occasions and for detecting - non-existant hardware. */ + /* This may seem like an absurd way to handle waiting and violates the + "no busy waiting" policy. The fact is that the hardware is + normally so fast that we usually only need one time through the loop + anyway. The longer timeout is for rare occasions and for detecting + non-existant hardware. */ - while(retry--) - { - if (inb(iobase+3) & 0x80) - return 0; + while (retry--) { + if (inb(iobase + 3) & 0x80) + return 0; - } - return 1; + } + return 1; } -static int ao_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - unsigned iobase = subpriv->iobase, iooffset = 0; - - for(n = 0; n < insn->n; n++) { - unsigned chan = CR_CHAN(insn->chanspec), range = CR_RANGE(insn->chanspec); - if (chan < s->n_chan) { - unsigned char command_byte = 0, range_byte = range&((1<<4)-1); - if (chan >= 4) chan -=4, iooffset += 4; - /* set the range.. */ - outb(range_byte, iobase+iooffset+0); - outb(0, iobase+iooffset+1); - - /* tell it to begin */ - command_byte = (chan << 1) | 0x60; - outb(command_byte, iobase+iooffset+2); - - wait_dac_ready(iobase+iooffset); - - outb(data[n] & 0xff, iobase+iooffset+0); /* low order byte */ - outb((data[n]>>8) & 0xff, iobase+iooffset+1); /* high order byte */ - command_byte = 0x70 | (chan<<1); /* set bit 4 of command byte to indicate data is loaded and trigger conversion */ - /* trigger converion */ - outb(command_byte, iobase+iooffset+2); - - wait_dac_ready(iobase+iooffset); - - subpriv->ao.shadow_samples[chan] = data[n]; /* save to shadow register for ao_rinsn */ - } - } - return n; + int n; + unsigned iobase = subpriv->iobase, iooffset = 0; + + for (n = 0; n < insn->n; n++) { + unsigned chan = CR_CHAN(insn->chanspec), range = + CR_RANGE(insn->chanspec); + if (chan < s->n_chan) { + unsigned char command_byte = 0, range_byte = + range & ((1 << 4) - 1); + if (chan >= 4) + chan -= 4, iooffset += 4; + /* set the range.. */ + outb(range_byte, iobase + iooffset + 0); + outb(0, iobase + iooffset + 1); + + /* tell it to begin */ + command_byte = (chan << 1) | 0x60; + outb(command_byte, iobase + iooffset + 2); + + wait_dac_ready(iobase + iooffset); + + outb(data[n] & 0xff, iobase + iooffset + 0); /* low order byte */ + outb((data[n] >> 8) & 0xff, iobase + iooffset + 1); /* high order byte */ + command_byte = 0x70 | (chan << 1); /* set bit 4 of command byte to indicate data is loaded and trigger conversion */ + /* trigger converion */ + outb(command_byte, iobase + iooffset + 2); + + wait_dac_ready(iobase + iooffset); + + subpriv->ao.shadow_samples[chan] = data[n]; /* save to shadow register for ao_rinsn */ + } + } + return n; } - /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. */ COMEDI_INITCLEANUP(driver); - - - diff --git a/comedi/drivers/pcmuio.c b/comedi/drivers/pcmuio.c index 13b24462..5cdc2e9f 100644 --- a/comedi/drivers/pcmuio.c +++ b/comedi/drivers/pcmuio.c @@ -75,16 +75,15 @@ Configuration Options: [2] - IRQ for second ASIC (pcmuio96 only - IRQ for chans 48-72 .. can be the same as first irq!) */ - #include -#include /* for PCI devices */ +#include /* for PCI devices */ #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) ) #define CHANS_PER_PORT 8 #define PORTS_PER_ASIC 6 #define INTR_PORTS_PER_ASIC 3 -#define MAX_CHANS_PER_SUBDEV 24 /* number of channels per comedi subdevice */ +#define MAX_CHANS_PER_SUBDEV 24 /* number of channels per comedi subdevice */ #define PORTS_PER_SUBDEV (MAX_CHANS_PER_SUBDEV/CHANS_PER_PORT) #define CHANS_PER_ASIC (CHANS_PER_PORT*PORTS_PER_ASIC) #define INTR_CHANS_PER_ASIC 24 @@ -118,9 +117,9 @@ Configuration Options: #define REG_PORT4 0x4 #define REG_PORT5 0x5 #define REG_INT_PENDING 0x6 -#define REG_PAGELOCK 0x7 /* page selector register, upper 2 bits select a page - and bits 0-5 are used to 'lock down' a particular - port above to make it readonly. */ +#define REG_PAGELOCK 0x7 /* page selector register, upper 2 bits select a page + and bits 0-5 are used to 'lock down' a particular + port above to make it readonly. */ #define REG_POL0 0x8 #define REG_POL1 0x9 #define REG_POL2 0xA @@ -147,26 +146,24 @@ Configuration Options: * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct pcmuio_board_struct -{ +typedef struct pcmuio_board_struct { const char *name; const int num_asics; const int num_channels_per_port; const int num_ports; } pcmuio_board; -static const pcmuio_board pcmuio_boards[] = -{ +static const pcmuio_board pcmuio_boards[] = { { - name: "pcmuio48", - num_asics: 1, - num_ports: 6, - }, + name: "pcmuio48", + num_asics:1, + num_ports:6, + }, { - name: "pcmuio96", - num_asics: 2, - num_ports: 12, - }, + name: "pcmuio96", + num_asics:2, + num_ports:12, + }, }; /* @@ -175,45 +172,42 @@ static const pcmuio_board pcmuio_boards[] = #define thisboard ((const pcmuio_board *)dev->board_ptr) /* this structure is for data unique to this subdevice. */ -typedef struct -{ - /* mapping of halfwords (bytes) in port/chanarray to iobase */ - unsigned long iobases[PORTS_PER_SUBDEV]; - - /* The below is only used for intr subdevices */ - struct { - int asic; /* if non-negative, this subdev has an interrupt asic */ - int first_chan; /* if nonnegative, the first channel id for - interrupts. */ - int num_asic_chans; /* the number of asic channels in this subdev - that have interrutps */ - int asic_chan; /* if nonnegative, the first channel id with - respect to the asic that has interrupts */ - int enabled_mask; /* subdev-relative channel mask for channels - we are interested in */ - int active; - int stop_count; - int continuous; - spinlock_t spinlock; - } intr; +typedef struct { + /* mapping of halfwords (bytes) in port/chanarray to iobase */ + unsigned long iobases[PORTS_PER_SUBDEV]; + + /* The below is only used for intr subdevices */ + struct { + int asic; /* if non-negative, this subdev has an interrupt asic */ + int first_chan; /* if nonnegative, the first channel id for + interrupts. */ + int num_asic_chans; /* the number of asic channels in this subdev + that have interrutps */ + int asic_chan; /* if nonnegative, the first channel id with + respect to the asic that has interrupts */ + int enabled_mask; /* subdev-relative channel mask for channels + we are interested in */ + int active; + int stop_count; + int continuous; + spinlock_t spinlock; + } intr; } pcmuio_subdev_private; /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct -{ - struct - { - unsigned char pagelock; /* current page and lock*/ - unsigned char pol [NUM_PAGED_REGS]; /* shadow of POLx registers */ - unsigned char enab[NUM_PAGED_REGS]; /* shadow of ENABx registers */ - int num; - unsigned long iobase; - unsigned int irq; - spinlock_t spinlock; - } asics[MAX_ASICS]; - pcmuio_subdev_private *sprivs; +typedef struct { + struct { + unsigned char pagelock; /* current page and lock */ + unsigned char pol[NUM_PAGED_REGS]; /* shadow of POLx registers */ + unsigned char enab[NUM_PAGED_REGS]; /* shadow of ENABx registers */ + int num; + unsigned long iobase; + unsigned int irq; + spinlock_t spinlock; + } asics[MAX_ASICS]; + pcmuio_subdev_private *sprivs; } pcmuio_private; /* @@ -228,15 +222,14 @@ typedef struct * the board, and also about the kernel module that contains * the device code. */ -static int pcmuio_attach(comedi_device *dev, comedi_devconfig *it); -static int pcmuio_detach(comedi_device *dev); - -static comedi_driver driver = -{ - driver_name: "pcmuio", - module: THIS_MODULE, - attach: pcmuio_attach, - detach: pcmuio_detach, +static int pcmuio_attach(comedi_device * dev, comedi_devconfig * it); +static int pcmuio_detach(comedi_device * dev); + +static comedi_driver driver = { + driver_name:"pcmuio", + module:THIS_MODULE, + attach:pcmuio_attach, + detach:pcmuio_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -255,27 +248,28 @@ static comedi_driver driver = * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &pcmuio_boards[0].name, - offset: sizeof(pcmuio_board), - num_names: sizeof(pcmuio_boards) / sizeof(pcmuio_board), + board_name:&pcmuio_boards[0].name, + offset:sizeof(pcmuio_board), + num_names:sizeof(pcmuio_boards) / sizeof(pcmuio_board), }; -static int pcmuio_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pcmuio_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); +static int pcmuio_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pcmuio_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); static irqreturn_t interrupt_pcmuio(int irq, void *d PT_REGS_ARG); static void pcmuio_stop_intr(comedi_device *, comedi_subdevice *); -static int pcmuio_cancel(comedi_device *dev, comedi_subdevice *s); -static int pcmuio_cmd(comedi_device *dev, comedi_subdevice *s); -static int pcmuio_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); +static int pcmuio_cancel(comedi_device * dev, comedi_subdevice * s); +static int pcmuio_cmd(comedi_device * dev, comedi_subdevice * s); +static int pcmuio_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); /* some helper functions to deal with specifics of this device's registers */ -static void init_asics(comedi_device *dev); /* sets up/clears ASIC chips to defaults */ -static void switch_page(comedi_device *dev, int asic, int page); -static void lock_port(comedi_device *dev, int asic, int port); -static void unlock_port(comedi_device *dev, int asic, int port); +static void init_asics(comedi_device * dev); /* sets up/clears ASIC chips to defaults */ +static void switch_page(comedi_device * dev, int asic, int page); +static void lock_port(comedi_device * dev, int asic, int port); +static void unlock_port(comedi_device * dev, int asic, int port); /* * Attach is called by the Comedi core to configure the driver @@ -283,163 +277,168 @@ static void unlock_port(comedi_device *dev, int asic, int port); * in the driver structure, dev->board_ptr contains that * address. */ -static int pcmuio_attach(comedi_device *dev, comedi_devconfig *it) +static int pcmuio_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int sdev_no, chans_left, n_subdevs, port, asic, thisasic_chanct = 0; + int sdev_no, chans_left, n_subdevs, port, asic, thisasic_chanct = 0; unsigned long iobase; unsigned int irq[MAX_ASICS]; - iobase = it->options[0]; - irq[0] = it->options[1]; - irq[1] = it->options[2]; + iobase = it->options[0]; + irq[0] = it->options[1]; + irq[1] = it->options[2]; - printk("comedi%d: %s: io: %lx ", dev->minor, driver.driver_name, iobase); + printk("comedi%d: %s: io: %lx ", dev->minor, driver.driver_name, + iobase); - dev->iobase = iobase; + dev->iobase = iobase; - if ( !iobase || !request_region(iobase, - thisboard->num_asics*ASIC_IOSIZE, - driver.driver_name) ) { - printk("I/O port conflict\n"); - return -EIO; - } + if (!iobase || !request_region(iobase, + thisboard->num_asics * ASIC_IOSIZE, + driver.driver_name)) { + printk("I/O port conflict\n"); + return -EIO; + } /* * Initialize dev->board_name. Note that we can use the "thisboard" * macro now, since we just initialized it in the last line. */ - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; /* * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if (alloc_private(dev,sizeof(pcmuio_private)) < 0) { - printk("cannot allocate private data structure\n"); - return -ENOMEM; - } - - for (asic = 0; asic < MAX_ASICS; ++asic) { - devpriv->asics[asic].num = asic; - devpriv->asics[asic].iobase = dev->iobase + asic*ASIC_IOSIZE; - devpriv->asics[asic].irq = 0; /* this gets actually set at the end of - this function when we - comedi_request_irqs */ - spin_lock_init(&devpriv->asics[asic].spinlock); - } - - chans_left = CHANS_PER_ASIC * thisboard->num_asics; - n_subdevs = CALC_N_SUBDEVS(chans_left); - devpriv->sprivs = kcalloc(n_subdevs, sizeof(pcmuio_subdev_private), GFP_KERNEL); - if (!devpriv->sprivs) { - printk("cannot allocate subdevice private data structures\n"); - return -ENOMEM; - } - /* - * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. - * - * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the - * 96-channel version of the board. - */ - if ( alloc_subdevices(dev, n_subdevs ) < 0 ) { - printk("cannot allocate subdevice data structures\n"); - return -ENOMEM; - } - - port = 0; - asic = 0; - for (sdev_no = 0; sdev_no < (int)dev->n_subdevices; ++sdev_no) - { - int byte_no; - - s = dev->subdevices + sdev_no; - s->private = devpriv->sprivs + sdev_no; - s->maxdata = 1; - s->range_table = &range_digital; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->type = COMEDI_SUBD_DIO; - s->insn_bits = pcmuio_dio_insn_bits; - s->insn_config = pcmuio_dio_insn_config; - s->n_chan = MIN(chans_left, MAX_CHANS_PER_SUBDEV); - subpriv->intr.asic = -1; - subpriv->intr.first_chan = -1; - subpriv->intr.asic_chan = -1; - subpriv->intr.num_asic_chans = -1; - subpriv->intr.active = 0; - s->len_chanlist = 1; - - /* save the ioport address for each 'port' of 8 channels in the - subdevice */ - for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) { - if (port >= PORTS_PER_ASIC) { - port = 0; - ++asic; - thisasic_chanct = 0; - } - subpriv->iobases[byte_no] = devpriv->asics[asic].iobase + port; - - if (thisasic_chanct < CHANS_PER_PORT*INTR_PORTS_PER_ASIC - && subpriv->intr.asic < 0) { - /* this is an interrupt subdevice, so setup the struct */ - subpriv->intr.asic = asic; - subpriv->intr.active = 0; - subpriv->intr.stop_count = 0; - subpriv->intr.first_chan = byte_no * 8; - subpriv->intr.asic_chan = thisasic_chanct; - subpriv->intr.num_asic_chans = s->n_chan - subpriv->intr.first_chan; - dev->read_subdev = s; - s->subdev_flags |= SDF_CMD_READ; - s->cancel = pcmuio_cancel; - s->do_cmd = pcmuio_cmd; - s->do_cmdtest = pcmuio_cmdtest; - s->len_chanlist = subpriv->intr.num_asic_chans; - } - thisasic_chanct += CHANS_PER_PORT; - } - spin_lock_init(&subpriv->intr.spinlock); - - chans_left -= s->n_chan; - - if (!chans_left) { - asic = 0; /* reset the asic to our first asic, to do intr subdevs */ - port = 0; - } - - } - - init_asics(dev); /* clear out all the registers, basically */ - - for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) { - if (irq[asic] && comedi_request_irq(irq[asic], interrupt_pcmuio, IRQF_SHARED, thisboard->name, dev)) { - int i; - /* unroll the allocated irqs.. */ - for (i = asic-1; i >= 0; --i) { - comedi_free_irq(irq[i], dev); - devpriv->asics[i].irq = irq[i] = 0; - } - irq[asic] = 0; - } - devpriv->asics[asic].irq = irq[asic]; - } - - dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple - irqs.. */ - - if (irq[0]) { - printk("irq: %u ", irq[0]); - if (irq[1] && thisboard->num_asics == 2) - printk("second ASIC irq: %u ", irq[1]); - } else { - printk("(IRQ mode disabled) "); - } - - printk("attached\n"); - - return 1; -} + if (alloc_private(dev, sizeof(pcmuio_private)) < 0) { + printk("cannot allocate private data structure\n"); + return -ENOMEM; + } + + for (asic = 0; asic < MAX_ASICS; ++asic) { + devpriv->asics[asic].num = asic; + devpriv->asics[asic].iobase = dev->iobase + asic * ASIC_IOSIZE; + devpriv->asics[asic].irq = 0; /* this gets actually set at the end of + this function when we + comedi_request_irqs */ + spin_lock_init(&devpriv->asics[asic].spinlock); + } + + chans_left = CHANS_PER_ASIC * thisboard->num_asics; + n_subdevs = CALC_N_SUBDEVS(chans_left); + devpriv->sprivs = + kcalloc(n_subdevs, sizeof(pcmuio_subdev_private), GFP_KERNEL); + if (!devpriv->sprivs) { + printk("cannot allocate subdevice private data structures\n"); + return -ENOMEM; + } + /* + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. + * + * Allocate 2 subdevs (32 + 16 DIO lines) or 3 32 DIO subdevs for the + * 96-channel version of the board. + */ + if (alloc_subdevices(dev, n_subdevs) < 0) { + printk("cannot allocate subdevice data structures\n"); + return -ENOMEM; + } + + port = 0; + asic = 0; + for (sdev_no = 0; sdev_no < (int)dev->n_subdevices; ++sdev_no) { + int byte_no; + + s = dev->subdevices + sdev_no; + s->private = devpriv->sprivs + sdev_no; + s->maxdata = 1; + s->range_table = &range_digital; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->type = COMEDI_SUBD_DIO; + s->insn_bits = pcmuio_dio_insn_bits; + s->insn_config = pcmuio_dio_insn_config; + s->n_chan = MIN(chans_left, MAX_CHANS_PER_SUBDEV); + subpriv->intr.asic = -1; + subpriv->intr.first_chan = -1; + subpriv->intr.asic_chan = -1; + subpriv->intr.num_asic_chans = -1; + subpriv->intr.active = 0; + s->len_chanlist = 1; + + /* save the ioport address for each 'port' of 8 channels in the + subdevice */ + for (byte_no = 0; byte_no < PORTS_PER_SUBDEV; ++byte_no, ++port) { + if (port >= PORTS_PER_ASIC) { + port = 0; + ++asic; + thisasic_chanct = 0; + } + subpriv->iobases[byte_no] = + devpriv->asics[asic].iobase + port; + + if (thisasic_chanct < + CHANS_PER_PORT * INTR_PORTS_PER_ASIC + && subpriv->intr.asic < 0) { + /* this is an interrupt subdevice, so setup the struct */ + subpriv->intr.asic = asic; + subpriv->intr.active = 0; + subpriv->intr.stop_count = 0; + subpriv->intr.first_chan = byte_no * 8; + subpriv->intr.asic_chan = thisasic_chanct; + subpriv->intr.num_asic_chans = + s->n_chan - subpriv->intr.first_chan; + dev->read_subdev = s; + s->subdev_flags |= SDF_CMD_READ; + s->cancel = pcmuio_cancel; + s->do_cmd = pcmuio_cmd; + s->do_cmdtest = pcmuio_cmdtest; + s->len_chanlist = subpriv->intr.num_asic_chans; + } + thisasic_chanct += CHANS_PER_PORT; + } + spin_lock_init(&subpriv->intr.spinlock); + + chans_left -= s->n_chan; + + if (!chans_left) { + asic = 0; /* reset the asic to our first asic, to do intr subdevs */ + port = 0; + } + + } + + init_asics(dev); /* clear out all the registers, basically */ + + for (asic = 0; irq[0] && asic < MAX_ASICS; ++asic) { + if (irq[asic] + && comedi_request_irq(irq[asic], interrupt_pcmuio, + IRQF_SHARED, thisboard->name, dev)) { + int i; + /* unroll the allocated irqs.. */ + for (i = asic - 1; i >= 0; --i) { + comedi_free_irq(irq[i], dev); + devpriv->asics[i].irq = irq[i] = 0; + } + irq[asic] = 0; + } + devpriv->asics[asic].irq = irq[asic]; + } + dev->irq = irq[0]; /* grr.. wish comedi dev struct supported multiple + irqs.. */ + + if (irq[0]) { + printk("irq: %u ", irq[0]); + if (irq[1] && thisboard->num_asics == 2) + printk("second ASIC irq: %u ", irq[1]); + } else { + printk("(IRQ mode disabled) "); + } + + printk("attached\n"); + + return 1; +} /* * _detach is called to deconfigure a device. It should deallocate @@ -449,425 +448,486 @@ static int pcmuio_attach(comedi_device *dev, comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int pcmuio_detach(comedi_device *dev) +static int pcmuio_detach(comedi_device * dev) { - int i; + int i; - printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); - if (dev->iobase) - release_region(dev->iobase, ASIC_IOSIZE * thisboard->num_asics); + printk("comedi%d: %s: remove\n", dev->minor, driver.driver_name); + if (dev->iobase) + release_region(dev->iobase, ASIC_IOSIZE * thisboard->num_asics); - for (i = 0; i < MAX_ASICS; ++i) { - if (devpriv->asics[i].irq) - comedi_free_irq(devpriv->asics[i].irq, dev); - } + for (i = 0; i < MAX_ASICS; ++i) { + if (devpriv->asics[i].irq) + comedi_free_irq(devpriv->asics[i].irq, dev); + } - if (devpriv && devpriv->sprivs) - kfree(devpriv->sprivs); + if (devpriv && devpriv->sprivs) + kfree(devpriv->sprivs); - return 0; + return 0; } - /* 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 pcmuio_dio_insn_bits(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcmuio_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int byte_no; - if (insn->n != 2) return -EINVAL; + int byte_no; + if (insn->n != 2) + return -EINVAL; - /* NOTE: - reading a 0 means this channel was high - writine a 0 sets the channel high - reading a 1 means this channel was low - writing a 1 means set this channel low + /* NOTE: + reading a 0 means this channel was high + writine a 0 sets the channel high + reading a 1 means this channel was low + writing a 1 means set this channel low - Therefore everything is always inverted. */ + Therefore everything is always inverted. */ /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("write mask: %08x data: %08x\n", data[0], data[1]); + /* DEBUG */ + printk("write mask: %08x data: %08x\n", data[0], data[1]); #endif - s->state = 0; + s->state = 0; - for (byte_no = 0; byte_no < s->n_chan/CHANS_PER_PORT; ++byte_no) { - /* address of 8-bit port */ - unsigned long ioaddr = subpriv->iobases[byte_no], - /* bit offset of port in 32-bit doubleword */ - offset = byte_no * 8; - /* this 8-bit port's data */ - unsigned char byte = 0, - /* The write mask for this port (if any) */ - write_mask_byte = (data[0] >> offset) & 0xff, - /* The data byte for this port */ - data_byte = (data[1] >> offset) & 0xff; + for (byte_no = 0; byte_no < s->n_chan / CHANS_PER_PORT; ++byte_no) { + /* address of 8-bit port */ + unsigned long ioaddr = subpriv->iobases[byte_no], + /* bit offset of port in 32-bit doubleword */ + offset = byte_no * 8; + /* this 8-bit port's data */ + unsigned char byte = 0, + /* The write mask for this port (if any) */ + write_mask_byte = (data[0] >> offset) & 0xff, + /* The data byte for this port */ + data_byte = (data[1] >> offset) & 0xff; - byte = inb(ioaddr); /* read all 8-bits for this port */ + byte = inb(ioaddr); /* read all 8-bits for this port */ #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ", byte_no, (unsigned)write_mask_byte, (unsigned)data_byte, offset, ioaddr, (unsigned)byte); + /* DEBUG */ + printk("byte %d wmb %02x db %02x offset %02d io %04x, data_in %02x ", byte_no, (unsigned)write_mask_byte, (unsigned)data_byte, offset, ioaddr, (unsigned)byte); #endif - if ( write_mask_byte ) { - /* this byte has some write_bits -- so set the output lines */ - byte &= ~write_mask_byte; /* clear bits for write mask */ - byte |= ~data_byte & write_mask_byte; /* set to inverted data_byte */ - /* Write out the new digital output state */ - outb(byte, ioaddr); - } - + if (write_mask_byte) { + /* this byte has some write_bits -- so set the output lines */ + byte &= ~write_mask_byte; /* clear bits for write mask */ + byte |= ~data_byte & write_mask_byte; /* set to inverted data_byte */ + /* Write out the new digital output state */ + outb(byte, ioaddr); + } #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("data_out_byte %02x\n", (unsigned)byte); + /* DEBUG */ + printk("data_out_byte %02x\n", (unsigned)byte); #endif - /* save the digital input lines for this byte.. */ - s->state |= ((unsigned int)byte) << offset; - } + /* save the digital input lines for this byte.. */ + s->state |= ((unsigned int)byte) << offset; + } - /* now return the DIO lines to data[1] - note they came inverted! */ - data[1] = ~s->state; + /* now return the DIO lines to data[1] - note they came inverted! */ + data[1] = ~s->state; #ifdef DAMMIT_ITS_BROKEN - /* DEBUG */ - printk("s->state %08x data_out %08x\n", s->state, data[1]); + /* DEBUG */ + printk("s->state %08x data_out %08x\n", s->state, data[1]); #endif - return 2; + return 2; } /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ -static int pcmuio_dio_insn_config(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int pcmuio_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan = CR_CHAN(insn->chanspec), byte_no = chan/8, bit_no = chan % 8; - unsigned long ioaddr; - unsigned char byte; + int chan = CR_CHAN(insn->chanspec), byte_no = chan / 8, bit_no = + chan % 8; + unsigned long ioaddr; + unsigned char byte; - /* Compute ioaddr for this channel */ - ioaddr = subpriv->iobases[byte_no]; + /* Compute ioaddr for this channel */ + ioaddr = subpriv->iobases[byte_no]; - /* NOTE: - writing a 0 an IO channel's bit sets the channel to INPUT - and pulls the line high as well + /* NOTE: + writing a 0 an IO channel's bit sets the channel to INPUT + and pulls the line high as well - writing a 1 to an IO channel's bit pulls the line low + writing a 1 to an IO channel's bit pulls the line low - All channels are implicitly always in OUTPUT mode -- but when - they are high they can be considered to be in INPUT mode.. + All channels are implicitly always in OUTPUT mode -- but when + they are high they can be considered to be in INPUT mode.. - Thus, we only force channels low if the config request was INPUT, - otherwise we do nothing to the hardware. */ + Thus, we only force channels low if the config request was INPUT, + otherwise we do nothing to the hardware. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - /* save to io_bits -- don't actually do anything since - all input channels are also output channels... */ - s->io_bits |= 1<io_bits |= 1 << chan; + break; case INSN_CONFIG_DIO_INPUT: - /* write a 0 to the actual register representing the channel - to set it to 'input'. 0 means "float high". */ - byte = inb(ioaddr); - byte &= ~(1<io_bits &= ~(1<io_bits &= ~(1 << chan); + break; case INSN_CONFIG_DIO_QUERY: - /* retreive from shadow register */ - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; - break; + /* retreive from shadow register */ + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + return insn->n; + break; default: - return -EINVAL; - break; + return -EINVAL; + break; } return insn->n; } -static void init_asics(comedi_device *dev) /* sets up an - ASIC chip to defaults */ -{ - int asic; - - for (asic = 0; asic < thisboard->num_asics; ++asic) - { - int port, page; - unsigned long baseaddr = dev->iobase + asic*ASIC_IOSIZE; - - switch_page(dev, asic, 0); /* switch back to page 0 */ - - /* first, clear all the DIO port bits */ - for (port = 0; port < PORTS_PER_ASIC; ++port) - outb(0, baseaddr + REG_PORT0 + port); - - /* Next, clear all the paged registers for each page */ - for (page = 1; page < NUM_PAGES; ++page) - { - int reg; - /* now clear all the paged registers*/ - switch_page(dev, asic, page); - for (reg = FIRST_PAGED_REG; reg < FIRST_PAGED_REG+NUM_PAGED_REGS; ++reg) - outb(0, baseaddr + reg); - } - - /* DEBUG set rising edge interrupts on port0 of both asics*/ - /*switch_page(dev, asic, PAGE_POL); - outb(0xff, baseaddr + REG_POL0); - switch_page(dev, asic, PAGE_ENAB); - outb(0xff, baseaddr + REG_ENAB0);*/ - /* END DEBUG */ - - switch_page(dev, asic, 0); /* switch back to default page 0 */ - - } -} +static void init_asics(comedi_device * dev) +{ /* sets up an + ASIC chip to defaults */ + int asic; + + for (asic = 0; asic < thisboard->num_asics; ++asic) { + int port, page; + unsigned long baseaddr = dev->iobase + asic * ASIC_IOSIZE; + + switch_page(dev, asic, 0); /* switch back to page 0 */ + + /* first, clear all the DIO port bits */ + for (port = 0; port < PORTS_PER_ASIC; ++port) + outb(0, baseaddr + REG_PORT0 + port); + + /* Next, clear all the paged registers for each page */ + for (page = 1; page < NUM_PAGES; ++page) { + int reg; + /* now clear all the paged registers */ + switch_page(dev, asic, page); + for (reg = FIRST_PAGED_REG; + reg < FIRST_PAGED_REG + NUM_PAGED_REGS; ++reg) + outb(0, baseaddr + reg); + } + + /* DEBUG set rising edge interrupts on port0 of both asics */ + /*switch_page(dev, asic, PAGE_POL); + outb(0xff, baseaddr + REG_POL0); + switch_page(dev, asic, PAGE_ENAB); + outb(0xff, baseaddr + REG_ENAB0); */ + /* END DEBUG */ + + switch_page(dev, asic, 0); /* switch back to default page 0 */ + } +} -static void switch_page(comedi_device *dev, int asic, int page) +static void switch_page(comedi_device * dev, int asic, int page) { - if (asic < 0 || asic >= thisboard->num_asics) return; /* paranoia */ - if (page < 0 || page >= NUM_PAGES) return; /* more paranoia */ + if (asic < 0 || asic >= thisboard->num_asics) + return; /* paranoia */ + if (page < 0 || page >= NUM_PAGES) + return; /* more paranoia */ - devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK; - devpriv->asics[asic].pagelock |= page<asics[asic].pagelock &= ~REG_PAGE_MASK; + devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET; - /* now write out the shadow register */ - outb(devpriv->asics[asic].pagelock, - dev->iobase + ASIC_IOSIZE*asic + REG_PAGELOCK); + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); } -static void lock_port(comedi_device *dev, int asic, int port) +static void lock_port(comedi_device * dev, int asic, int port) { - if (asic < 0 || asic >= thisboard->num_asics) return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) return; /* more paranoia */ - - devpriv->asics[asic].pagelock |= 0x1<asics[asic].pagelock, dev->iobase + ASIC_IOSIZE*asic + REG_PAGELOCK); - return; - (void)lock_port(dev, asic, port); /* not reached, suppress compiler warnings*/ + if (asic < 0 || asic >= thisboard->num_asics) + return; /* paranoia */ + if (port < 0 || port >= PORTS_PER_ASIC) + return; /* more paranoia */ + + devpriv->asics[asic].pagelock |= 0x1 << port; + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); + return; + (void)lock_port(dev, asic, port); /* not reached, suppress compiler warnings */ } -static void unlock_port(comedi_device *dev, int asic, int port) +static void unlock_port(comedi_device * dev, int asic, int port) { - if (asic < 0 || asic >= thisboard->num_asics) return; /* paranoia */ - if (port < 0 || port >= PORTS_PER_ASIC) return; /* more paranoia */ - devpriv->asics[asic].pagelock &= ~(0x1<asics[asic].pagelock, dev->iobase + ASIC_IOSIZE*asic + REG_PAGELOCK); - (void)unlock_port(dev, asic, port); /* not reached, suppress compiler warnings*/ + if (asic < 0 || asic >= thisboard->num_asics) + return; /* paranoia */ + if (port < 0 || port >= PORTS_PER_ASIC) + return; /* more paranoia */ + devpriv->asics[asic].pagelock &= ~(0x1 << port) | REG_LOCK_MASK; + /* now write out the shadow register */ + outb(devpriv->asics[asic].pagelock, + dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); + (void)unlock_port(dev, asic, port); /* not reached, suppress compiler warnings */ } static irqreturn_t interrupt_pcmuio(int irq, void *d PT_REGS_ARG) { - int asic, got1 = 0; - comedi_device *dev = (comedi_device *)d; - - for (asic = 0; asic < MAX_ASICS; ++asic) { - if (irq == devpriv->asics[asic].irq) { - unsigned long flags; - unsigned triggered = 0; - unsigned long iobase = devpriv->asics[asic].iobase; - /* it is an interrupt for ASIC #asic */ - unsigned char int_pend; - - comedi_spin_lock_irqsave(&devpriv->asics[asic].spinlock, flags); - - int_pend = inb(iobase + REG_INT_PENDING) & 0x07; - - if (int_pend) { - int port; - for (port = 0; port < INTR_PORTS_PER_ASIC; ++port) { - if (int_pend & (0x1<asics[asic].spinlock, flags); - - if (triggered) { - comedi_subdevice *s; - /* TODO here: dispatch io lines to subdevs with commands.. */ - printk("PCMUIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n", irq, asic, triggered); - for (s = dev->subdevices; s < dev->subdevices + dev->n_subdevices; ++s) { - if (subpriv->intr.asic == asic) { /* this is an interrupt subdev, and it matches this asic! */ - unsigned long flags; - unsigned oldevents; - - comedi_spin_lock_irqsave(&subpriv->intr.spinlock, flags); - - oldevents = s->async->events; - - if (subpriv->intr.active) { - unsigned mytrig = ((triggered >> subpriv->intr.asic_chan) & ((0x1<intr.num_asic_chans)-1)) << subpriv->intr.first_chan; - if (mytrig & subpriv->intr.enabled_mask) { - lsampl_t val = 0; - unsigned int n, ch, len; - - len = s->async->cmd.chanlist_len; - for (n = 0; n < len; n++) { - ch = CR_CHAN(s->async->cmd.chanlist[n]); - if (mytrig & (1U << ch)) { - val |= (1U << n); - } - } - /* Write the scan to the buffer. */ - if (comedi_buf_put(s->async, ((sampl_t *)&val)[0]) - && comedi_buf_put(s->async, ((sampl_t *)&val)[1]) ) { - s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); - } else { - /* Overflow! Stop acquisition!! */ - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmuio_stop_intr(dev, s); - } - - /* Check for end of acquisition. */ - if (!subpriv->intr.continuous) { - /* stop_src == TRIG_COUNT */ - if (subpriv->intr.stop_count > 0) { - subpriv->intr.stop_count--; - if (subpriv->intr.stop_count == 0) { - s->async->events |= COMEDI_CB_EOA; - /* TODO: STOP_ACQUISITION_CALL_HERE!! */ - pcmuio_stop_intr(dev, s); - } - } - } - } - } - - comedi_spin_unlock_irqrestore(&subpriv->intr.spinlock, flags); - - if (oldevents != s->async->events) { - comedi_event(dev, s); - } - - } - - } - } - - } - } - if (!got1) return IRQ_NONE; /* interrupt from other source */ - return IRQ_HANDLED; -} + int asic, got1 = 0; + comedi_device *dev = (comedi_device *) d; + + for (asic = 0; asic < MAX_ASICS; ++asic) { + if (irq == devpriv->asics[asic].irq) { + unsigned long flags; + unsigned triggered = 0; + unsigned long iobase = devpriv->asics[asic].iobase; + /* it is an interrupt for ASIC #asic */ + unsigned char int_pend; + + comedi_spin_lock_irqsave(&devpriv->asics[asic].spinlock, + flags); + + int_pend = inb(iobase + REG_INT_PENDING) & 0x07; + + if (int_pend) { + int port; + for (port = 0; port < INTR_PORTS_PER_ASIC; + ++port) { + if (int_pend & (0x1 << port)) { + unsigned char + io_lines_with_edges = 0; + switch_page(dev, asic, + PAGE_INT_ID); + io_lines_with_edges = + inb(iobase + + REG_INT_ID0 + port); + + if (io_lines_with_edges) + /* clear pending interrupt */ + outb(0, iobase + + REG_INT_ID0 + + port); + + triggered |= + io_lines_with_edges << + port * 8; + } + } + + ++got1; + } + + comedi_spin_unlock_irqrestore(&devpriv->asics[asic]. + spinlock, flags); + + if (triggered) { + comedi_subdevice *s; + /* TODO here: dispatch io lines to subdevs with commands.. */ + printk("PCMUIO DEBUG: got edge detect interrupt %d asic %d which_chans: %06x\n", irq, asic, triggered); + for (s = dev->subdevices; + s < dev->subdevices + dev->n_subdevices; + ++s) { + if (subpriv->intr.asic == asic) { /* this is an interrupt subdev, and it matches this asic! */ + unsigned long flags; + unsigned oldevents; + + comedi_spin_lock_irqsave + (&subpriv->intr. + spinlock, flags); + + oldevents = s->async->events; + + if (subpriv->intr.active) { + unsigned mytrig = + ((triggered >> + subpriv-> + intr. + asic_chan) + & ((0x1 << subpriv->intr.num_asic_chans) - 1)) << subpriv->intr.first_chan; + if (mytrig & subpriv-> + intr. + enabled_mask) { + lsampl_t val = + 0; + unsigned int n, + ch, len; + + len = s->async-> + cmd. + chanlist_len; + for (n = 0; + n < len; + n++) { + ch = CR_CHAN(s->async->cmd.chanlist[n]); + if (mytrig & (1U << ch)) { + val |= (1U << n); + } + } + /* Write the scan to the buffer. */ + if (comedi_buf_put(s->async, ((sampl_t *) & val)[0]) + && + comedi_buf_put + (s->async, ((sampl_t *) & val)[1])) { + s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); + } else { + /* Overflow! Stop acquisition!! */ + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmuio_stop_intr + (dev, + s); + } + + /* Check for end of acquisition. */ + if (!subpriv-> + intr. + continuous) + { + /* stop_src == TRIG_COUNT */ + if (subpriv->intr.stop_count > 0) { + subpriv-> + intr. + stop_count--; + if (subpriv->intr.stop_count == 0) { + s->async->events |= COMEDI_CB_EOA; + /* TODO: STOP_ACQUISITION_CALL_HERE!! */ + pcmuio_stop_intr + (dev, + s); + } + } + } + } + } + + comedi_spin_unlock_irqrestore + (&subpriv->intr. + spinlock, flags); + + if (oldevents != + s->async->events) { + comedi_event(dev, s); + } + + } + + } + } + } + } + if (!got1) + return IRQ_NONE; /* interrupt from other source */ + return IRQ_HANDLED; +} -static void pcmuio_stop_intr(comedi_device *dev, comedi_subdevice *s) +static void pcmuio_stop_intr(comedi_device * dev, comedi_subdevice * s) { - int nports, firstport, asic, port; - - if ( (asic = subpriv->intr.asic) < 0 ) return; /* not an interrupt subdev */ - - subpriv->intr.enabled_mask = 0; - subpriv->intr.active = 0; - s->async->inttrig = 0; - nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport+nports; ++port) { - /* disable all intrs for this subdev.. */ - outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); - } + int nports, firstport, asic, port; + + if ((asic = subpriv->intr.asic) < 0) + return; /* not an interrupt subdev */ + + subpriv->intr.enabled_mask = 0; + subpriv->intr.active = 0; + s->async->inttrig = 0; + nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; + firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; + switch_page(dev, asic, PAGE_ENAB); + for (port = firstport; port < firstport + nports; ++port) { + /* disable all intrs for this subdev.. */ + outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); + } } -static int pcmuio_start_intr(comedi_device *dev, comedi_subdevice *s) +static int pcmuio_start_intr(comedi_device * dev, comedi_subdevice * s) { - if (!subpriv->intr.continuous && subpriv->intr.stop_count == 0) { - /* An empty acquisition! */ - s->async->events |= COMEDI_CB_EOA; - subpriv->intr.active = 0; - return 1; - } else { - unsigned bits = 0, pol_bits = 0, n; - int nports, firstport, asic, port; - comedi_cmd *cmd = &s->async->cmd; - - if ( (asic = subpriv->intr.asic) < 0 ) return 1; /* not an interrupt - subdev */ - subpriv->intr.enabled_mask = 0; - subpriv->intr.active = 1; - nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; - firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; - if (cmd->chanlist) { - for (n = 0; n < cmd->chanlist_len; n++) { - bits |= (1U << CR_CHAN(cmd->chanlist[n])); - pol_bits |= - (CR_AREF(cmd->chanlist[n]) || CR_RANGE(cmd->chanlist[n]) ? 1U : 0U) - << CR_CHAN(cmd->chanlist[n]); - } - } - bits &= ((0x1<intr.num_asic_chans)-1) << subpriv->intr.first_chan; - subpriv->intr.enabled_mask = bits; - - switch_page(dev, asic, PAGE_ENAB); - for (port = firstport; port < firstport+nports; ++port) { - unsigned enab = bits >> (subpriv->intr.first_chan + (port-firstport)*8) & 0xff, - pol = pol_bits >> (subpriv->intr.first_chan + (port-firstport)*8) & 0xff ; - /* set enab intrs for this subdev.. */ - outb(enab, devpriv->asics[asic].iobase + REG_ENAB0 + port); - switch_page(dev, asic, PAGE_POL); - outb(pol, devpriv->asics[asic].iobase + REG_ENAB0 + port); - } - } - return 0; + if (!subpriv->intr.continuous && subpriv->intr.stop_count == 0) { + /* An empty acquisition! */ + s->async->events |= COMEDI_CB_EOA; + subpriv->intr.active = 0; + return 1; + } else { + unsigned bits = 0, pol_bits = 0, n; + int nports, firstport, asic, port; + comedi_cmd *cmd = &s->async->cmd; + + if ((asic = subpriv->intr.asic) < 0) + return 1; /* not an interrupt + subdev */ + subpriv->intr.enabled_mask = 0; + subpriv->intr.active = 1; + nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; + firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; + if (cmd->chanlist) { + for (n = 0; n < cmd->chanlist_len; n++) { + bits |= (1U << CR_CHAN(cmd->chanlist[n])); + pol_bits |= (CR_AREF(cmd->chanlist[n]) + || CR_RANGE(cmd->chanlist[n]) ? 1U : 0U) + << CR_CHAN(cmd->chanlist[n]); + } + } + bits &= ((0x1 << subpriv->intr.num_asic_chans) - + 1) << subpriv->intr.first_chan; + subpriv->intr.enabled_mask = bits; + + switch_page(dev, asic, PAGE_ENAB); + for (port = firstport; port < firstport + nports; ++port) { + unsigned enab = + bits >> (subpriv->intr.first_chan + (port - + firstport) * 8) & 0xff, pol = + pol_bits >> (subpriv->intr.first_chan + (port - + firstport) * 8) & 0xff; + /* set enab intrs for this subdev.. */ + outb(enab, + devpriv->asics[asic].iobase + REG_ENAB0 + port); + switch_page(dev, asic, PAGE_POL); + outb(pol, + devpriv->asics[asic].iobase + REG_ENAB0 + port); + } + } + return 0; } -static int pcmuio_cancel(comedi_device *dev, comedi_subdevice *s) +static int pcmuio_cancel(comedi_device * dev, comedi_subdevice * s) { - unsigned long flags; + unsigned long flags; - comedi_spin_lock_irqsave(&subpriv->intr.spinlock, flags); - if (subpriv->intr.active) pcmuio_stop_intr(dev, s); - comedi_spin_unlock_irqrestore(&subpriv->intr.spinlock, flags); + comedi_spin_lock_irqsave(&subpriv->intr.spinlock, flags); + if (subpriv->intr.active) + pcmuio_stop_intr(dev, s); + comedi_spin_unlock_irqrestore(&subpriv->intr.spinlock, flags); - return 0; + return 0; } /* * Internal trigger function to start acquisition for an 'INTERRUPT' subdevice. */ static int -pcmuio_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, unsigned int trignum) +pcmuio_inttrig_start_intr(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) { unsigned long flags; int event = 0; - if (trignum != 0) return -EINVAL; + if (trignum != 0) + return -EINVAL; comedi_spin_lock_irqsave(&subpriv->intr.spinlock, flags); s->async->inttrig = 0; @@ -883,12 +943,10 @@ pcmuio_inttrig_start_intr(comedi_device *dev, comedi_subdevice *s, unsigned int return 1; } - /* * 'do_cmd' function for an 'INTERRUPT' subdevice. */ -static int -pcmuio_cmd(comedi_device *dev, comedi_subdevice *s) +static int pcmuio_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned long flags; @@ -933,8 +991,7 @@ pcmuio_cmd(comedi_device *dev, comedi_subdevice *s) * 'do_cmdtest' function for an 'INTERRUPT' subdevice. */ static int -pcmuio_cmdtest(comedi_device *dev, comedi_subdevice *s, - comedi_cmd *cmd) +pcmuio_cmdtest(comedi_device * dev, comedi_subdevice * s, comedi_cmd * cmd) { int err = 0; unsigned int tmp; @@ -943,36 +1000,48 @@ pcmuio_cmdtest(comedi_device *dev, comedi_subdevice *s, tmp = cmd->start_src; cmd->start_src &= (TRIG_NOW | TRIG_INT); - if (!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_EXT; - if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if (!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; tmp = cmd->stop_src; cmd->stop_src &= (TRIG_COUNT | TRIG_NONE); - if (!cmd->stop_src || tmp != cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if (err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* these tests are true if more than one _src bit is set */ - if ((cmd->start_src & (cmd->start_src - 1)) != 0) err++; - if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) err++; - if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) err++; - if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) err++; - if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) err++; + if ((cmd->start_src & (cmd->start_src - 1)) != 0) + err++; + if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0) + err++; + if ((cmd->convert_src & (cmd->convert_src - 1)) != 0) + err++; + if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0) + err++; + if ((cmd->stop_src & (cmd->stop_src - 1)) != 0) + err++; - if (err) return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ @@ -1006,15 +1075,16 @@ pcmuio_cmdtest(comedi_device *dev, comedi_subdevice *s, break; case TRIG_NONE: if (cmd->stop_arg != 0) { - cmd->stop_arg = 0; - err++; + cmd->stop_arg = 0; + err++; } break; default: break; } - if (err) return 3; + if (err) + return 3; /* step 4: fix up any arguments */ @@ -1028,5 +1098,3 @@ pcmuio_cmdtest(comedi_device *dev, comedi_subdevice *s, * as necessary. */ COMEDI_INITCLEANUP(driver); - - diff --git a/comedi/drivers/plx9080.h b/comedi/drivers/plx9080.h index eed2ac55..a5a1a680 100644 --- a/comedi/drivers/plx9080.h +++ b/comedi/drivers/plx9080.h @@ -28,8 +28,7 @@ #define __COMEDI_PLX9080_H // descriptor block used for chained dma transfers -struct plx_dma_desc -{ +struct plx_dma_desc { volatile uint32_t pci_start_addr; volatile uint32_t local_start_addr; /* transfer_size is in bytes, only first 23 bits of register are used */ @@ -47,53 +46,50 @@ struct plx_dma_desc ** **********************************************************************/ -#define PLX_LAS0RNG_REG 0x0000 /* L, Local Addr Space 0 Range Register */ -#define PLX_LAS1RNG_REG 0x00f0 /* L, Local Addr Space 1 Range Register */ -#define LRNG_IO 0x00000001 /* Map to: 1=I/O, 0=Mem */ -#define LRNG_ANY32 0x00000000 /* Locate anywhere in 32 bit */ -#define LRNG_LT1MB 0x00000002 /* Locate in 1st meg */ -#define LRNG_ANY64 0x00000004 /* Locate anywhere in 64 bit */ +#define PLX_LAS0RNG_REG 0x0000 /* L, Local Addr Space 0 Range Register */ +#define PLX_LAS1RNG_REG 0x00f0 /* L, Local Addr Space 1 Range Register */ +#define LRNG_IO 0x00000001 /* Map to: 1=I/O, 0=Mem */ +#define LRNG_ANY32 0x00000000 /* Locate anywhere in 32 bit */ +#define LRNG_LT1MB 0x00000002 /* Locate in 1st meg */ +#define LRNG_ANY64 0x00000004 /* Locate anywhere in 64 bit */ #define LRNG_MEM_MASK 0xfffffff0 // bits that specify range for memory io #define LRNG_IO_MASK 0xfffffffa // bits that specify range for normal io -#define PLX_LAS0MAP_REG 0x0004 /* L, Local Addr Space 0 Remap Register */ -#define PLX_LAS1MAP_REG 0x00f4 /* L, Local Addr Space 1 Remap Register */ -#define LMAP_EN 0x00000001 /* Enable slave decode */ +#define PLX_LAS0MAP_REG 0x0004 /* L, Local Addr Space 0 Remap Register */ +#define PLX_LAS1MAP_REG 0x00f4 /* L, Local Addr Space 1 Remap Register */ +#define LMAP_EN 0x00000001 /* Enable slave decode */ #define LMAP_MEM_MASK 0xfffffff0 // bits that specify decode for memory io #define LMAP_IO_MASK 0xfffffffa // bits that specify decode bits for normal io - /* Mode/Arbitration Register. */ -#define PLX_MARB_REG 0x8 /* L, Local Arbitration Register */ +#define PLX_MARB_REG 0x8 /* L, Local Arbitration Register */ #define PLX_DMAARB_REG 0xac -enum marb_bits -{ - MARB_LLT_MASK = 0x000000ff, /* Local Bus Latency Timer */ - MARB_LPT_MASK = 0x0000ff00, /* Local Bus Pause Timer */ - MARB_LTEN = 0x00010000, /* Latency Timer Enable */ - MARB_LPEN = 0x00020000, /* Pause Timer Enable */ - MARB_BREQ = 0x00040000, /* Local Bus BREQ Enable */ +enum marb_bits { + MARB_LLT_MASK = 0x000000ff, /* Local Bus Latency Timer */ + MARB_LPT_MASK = 0x0000ff00, /* Local Bus Pause Timer */ + MARB_LTEN = 0x00010000, /* Latency Timer Enable */ + MARB_LPEN = 0x00020000, /* Pause Timer Enable */ + MARB_BREQ = 0x00040000, /* Local Bus BREQ Enable */ MARB_DMA_PRIORITY_MASK = 0x00180000, - MARB_LBDS_GIVE_UP_BUS_MODE = 0x00200000, /* local bus direct slave give up bus mode */ - MARB_DS_LLOCK_ENABLE = 0x00400000, /* direct slave LLOCKo# enable */ + MARB_LBDS_GIVE_UP_BUS_MODE = 0x00200000, /* local bus direct slave give up bus mode */ + MARB_DS_LLOCK_ENABLE = 0x00400000, /* direct slave LLOCKo# enable */ MARB_PCI_REQUEST_MODE = 0x00800000, - MARB_PCIv21_MODE = 0x01000000, /* pci specification v2.1 mode */ + MARB_PCIv21_MODE = 0x01000000, /* pci specification v2.1 mode */ MARB_PCI_READ_NO_WRITE_MODE = 0x02000000, MARB_PCI_READ_WITH_WRITE_FLUSH_MODE = 0x04000000, - MARB_GATE_TIMER_WITH_BREQ = 0x08000000, /* gate local bus latency timer with BREQ */ + MARB_GATE_TIMER_WITH_BREQ = 0x08000000, /* gate local bus latency timer with BREQ */ MARB_PCI_READ_NO_FLUSH_MODE = 0x10000000, MARB_USE_SUBSYSTEM_IDS = 0x20000000, }; #define PLX_BIGEND_REG 0xc -enum bigend_bits -{ - BIGEND_CONFIG = 0x1, /* use big endian ordering for configuration register accesses*/ +enum bigend_bits { + BIGEND_CONFIG = 0x1, /* use big endian ordering for configuration register accesses */ BIGEND_DIRECT_MASTER = 0x2, BIGEND_DIRECT_SLAVE_LOCAL0 = 0x4, BIGEND_ROM = 0x8, - BIGEND_BYTE_LANE = 0x10, /* use byte lane consisting of most significant bits instead of least significant */ + BIGEND_BYTE_LANE = 0x10, /* use byte lane consisting of most significant bits instead of least significant */ BIGEND_DIRECT_SLAVE_LOCAL1 = 0x20, BIGEND_DMA1 = 0x40, BIGEND_DMA0 = 0x80, @@ -103,16 +99,15 @@ enum bigend_bits ** This expansion ROM code is executed by the host CPU at boot time. ** For this reason no bit definitions are provided here. */ -#define PLX_ROMRNG_REG 0x0010 /* L, Expn ROM Space Range Register */ -#define PLX_ROMMAP_REG 0x0014 /* L, Local Addr Space Range Register */ - - -#define PLX_REGION0_REG 0x0018 /* L, Local Bus Region 0 Descriptor */ -#define RGN_WIDTH 0x00000002 /* Local bus width bits */ -#define RGN_8BITS 0x00000000 /* 08 bit Local Bus */ -#define RGN_16BITS 0x00000001 /* 16 bit Local Bus */ -#define RGN_32BITS 0x00000002 /* 32 bit Local Bus */ -#define RGN_MWS 0x0000003C /* Memory Access Wait States */ +#define PLX_ROMRNG_REG 0x0010 /* L, Expn ROM Space Range Register */ +#define PLX_ROMMAP_REG 0x0014 /* L, Local Addr Space Range Register */ + +#define PLX_REGION0_REG 0x0018 /* L, Local Bus Region 0 Descriptor */ +#define RGN_WIDTH 0x00000002 /* Local bus width bits */ +#define RGN_8BITS 0x00000000 /* 08 bit Local Bus */ +#define RGN_16BITS 0x00000001 /* 16 bit Local Bus */ +#define RGN_32BITS 0x00000002 /* 32 bit Local Bus */ +#define RGN_MWS 0x0000003C /* Memory Access Wait States */ #define RGN_0MWS 0x00000000 #define RGN_1MWS 0x00000004 #define RGN_2MWS 0x00000008 @@ -120,99 +115,98 @@ enum bigend_bits #define RGN_4MWS 0x00000010 #define RGN_6MWS 0x00000018 #define RGN_8MWS 0x00000020 -#define RGN_MRE 0x00000040 /* Memory Space Ready Input Enable */ -#define RGN_MBE 0x00000080 /* Memory Space Bterm Input Enable */ +#define RGN_MRE 0x00000040 /* Memory Space Ready Input Enable */ +#define RGN_MBE 0x00000080 /* Memory Space Bterm Input Enable */ #define RGN_READ_PREFETCH_DISABLE 0x00000100 #define RGN_ROM_PREFETCH_DISABLE 0x00000200 #define RGN_READ_PREFETCH_COUNT_ENABLE 0x00000400 -#define RGN_RWS 0x003C0000 /* Expn ROM Wait States */ -#define RGN_RRE 0x00400000 /* ROM Space Ready Input Enable */ -#define RGN_RBE 0x00800000 /* ROM Space Bterm Input Enable */ -#define RGN_MBEN 0x01000000 /* Memory Space Burst Enable */ -#define RGN_RBEN 0x04000000 /* ROM Space Burst Enable */ -#define RGN_THROT 0x08000000 /* De-assert TRDY when FIFO full */ -#define RGN_TRD 0xF0000000 /* Target Ready Delay /8 */ - -#define PLX_REGION1_REG 0x00f8 /* L, Local Bus Region 1 Descriptor */ - -#define PLX_DMRNG_REG 0x001C /* L, Direct Master Range Register */ - -#define PLX_LBAPMEM_REG 0x0020 /* L, Lcl Base Addr for PCI mem space */ - -#define PLX_LBAPIO_REG 0x0024 /* L, Lcl Base Addr for PCI I/O space */ - -#define PLX_DMMAP_REG 0x0028 /* L, Direct Master Remap Register */ -#define DMM_MAE 0x00000001 /* Direct Mstr Memory Acc Enable */ -#define DMM_IAE 0x00000002 /* Direct Mstr I/O Acc Enable */ -#define DMM_LCK 0x00000004 /* LOCK Input Enable */ -#define DMM_PF4 0x00000008 /* Prefetch 4 Mode Enable */ -#define DMM_THROT 0x00000010 /* Assert IRDY when read FIFO full */ -#define DMM_PAF0 0x00000000 /* Programmable Almost fill level */ -#define DMM_PAF1 0x00000020 /* Programmable Almost fill level */ -#define DMM_PAF2 0x00000040 /* Programmable Almost fill level */ -#define DMM_PAF3 0x00000060 /* Programmable Almost fill level */ -#define DMM_PAF4 0x00000080 /* Programmable Almost fill level */ -#define DMM_PAF5 0x000000A0 /* Programmable Almost fill level */ -#define DMM_PAF6 0x000000C0 /* Programmable Almost fill level */ -#define DMM_PAF7 0x000000D0 /* Programmable Almost fill level */ -#define DMM_MAP 0xFFFF0000 /* Remap Address Bits */ - -#define PLX_CAR_REG 0x002C /* L, Configuration Address Register */ -#define CAR_CT0 0x00000000 /* Config Type 0 */ -#define CAR_CT1 0x00000001 /* Config Type 1 */ -#define CAR_REG 0x000000FC /* Register Number Bits */ -#define CAR_FUN 0x00000700 /* Function Number Bits */ -#define CAR_DEV 0x0000F800 /* Device Number Bits */ -#define CAR_BUS 0x00FF0000 /* Bus Number Bits */ -#define CAR_CFG 0x80000000 /* Config Spc Access Enable */ - - -#define PLX_DBR_IN_REG 0x0060 /* L, PCI to Local Doorbell Register */ - -#define PLX_DBR_OUT_REG 0x0064 /* L, Local to PCI Doorbell Register */ - -#define PLX_INTRCS_REG 0x0068 /* L, Interrupt Control/Status Reg */ -#define ICS_AERR 0x00000001 /* Assert LSERR on ABORT */ -#define ICS_PERR 0x00000002 /* Assert LSERR on Parity Error */ -#define ICS_SERR 0x00000004 /* Generate PCI SERR# */ -#define ICS_MBIE 0x00000008 // mailbox interrupt enable -#define ICS_PIE 0x00000100 /* PCI Interrupt Enable */ -#define ICS_PDIE 0x00000200 /* PCI Doorbell Interrupt Enable */ -#define ICS_PAIE 0x00000400 /* PCI Abort Interrupt Enable */ -#define ICS_PLIE 0x00000800 /* PCI Local Int Enable */ -#define ICS_RAE 0x00001000 /* Retry Abort Enable */ -#define ICS_PDIA 0x00002000 /* PCI Doorbell Interrupt Active */ -#define ICS_PAIA 0x00004000 /* PCI Abort Interrupt Active */ -#define ICS_LIA 0x00008000 /* Local Interrupt Active */ -#define ICS_LIE 0x00010000 /* Local Interrupt Enable */ -#define ICS_LDIE 0x00020000 /* Local Doorbell Int Enable */ -#define ICS_DMA0_E 0x00040000 /* DMA #0 Interrupt Enable */ -#define ICS_DMA1_E 0x00080000 /* DMA #1 Interrupt Enable */ -#define ICS_LDIA 0x00100000 /* Local Doorbell Int Active */ -#define ICS_DMA0_A 0x00200000 /* DMA #0 Interrupt Active */ -#define ICS_DMA1_A 0x00400000 /* DMA #1 Interrupt Active */ -#define ICS_BIA 0x00800000 /* BIST Interrupt Active */ -#define ICS_TA_DM 0x01000000 /* Target Abort - Direct Master */ -#define ICS_TA_DMA0 0x02000000 /* Target Abort - DMA #0 */ -#define ICS_TA_DMA1 0x04000000 /* Target Abort - DMA #1 */ -#define ICS_TA_RA 0x08000000 /* Target Abort - Retry Timeout */ -#define ICS_MBIA(x) (0x10000000 << ((x) & 0x3)) // mailbox x is active - -#define PLX_CONTROL_REG 0x006C /* L, EEPROM Cntl & PCI Cmd Codes */ -#define CTL_RDMA 0x0000000E /* DMA Read Command */ -#define CTL_WDMA 0x00000070 /* DMA Write Command */ -#define CTL_RMEM 0x00000600 /* Memory Read Command */ -#define CTL_WMEM 0x00007000 /* Memory Write Command */ -#define CTL_USERO 0x00010000 /* USERO output pin control bit */ -#define CTL_USERI 0x00020000 /* USERI input pin bit */ -#define CTL_EE_CLK 0x01000000 /* EEPROM Clock line */ -#define CTL_EE_CS 0x02000000 /* EEPROM Chip Select */ -#define CTL_EE_W 0x04000000 /* EEPROM Write bit */ -#define CTL_EE_R 0x08000000 /* EEPROM Read bit */ -#define CTL_EECHK 0x10000000 /* EEPROM Present bit */ -#define CTL_EERLD 0x20000000 /* EEPROM Reload Register */ -#define CTL_RESET 0x40000000 /* !! Adapter Reset !! */ -#define CTL_READY 0x80000000 /* Local Init Done */ +#define RGN_RWS 0x003C0000 /* Expn ROM Wait States */ +#define RGN_RRE 0x00400000 /* ROM Space Ready Input Enable */ +#define RGN_RBE 0x00800000 /* ROM Space Bterm Input Enable */ +#define RGN_MBEN 0x01000000 /* Memory Space Burst Enable */ +#define RGN_RBEN 0x04000000 /* ROM Space Burst Enable */ +#define RGN_THROT 0x08000000 /* De-assert TRDY when FIFO full */ +#define RGN_TRD 0xF0000000 /* Target Ready Delay /8 */ + +#define PLX_REGION1_REG 0x00f8 /* L, Local Bus Region 1 Descriptor */ + +#define PLX_DMRNG_REG 0x001C /* L, Direct Master Range Register */ + +#define PLX_LBAPMEM_REG 0x0020 /* L, Lcl Base Addr for PCI mem space */ + +#define PLX_LBAPIO_REG 0x0024 /* L, Lcl Base Addr for PCI I/O space */ + +#define PLX_DMMAP_REG 0x0028 /* L, Direct Master Remap Register */ +#define DMM_MAE 0x00000001 /* Direct Mstr Memory Acc Enable */ +#define DMM_IAE 0x00000002 /* Direct Mstr I/O Acc Enable */ +#define DMM_LCK 0x00000004 /* LOCK Input Enable */ +#define DMM_PF4 0x00000008 /* Prefetch 4 Mode Enable */ +#define DMM_THROT 0x00000010 /* Assert IRDY when read FIFO full */ +#define DMM_PAF0 0x00000000 /* Programmable Almost fill level */ +#define DMM_PAF1 0x00000020 /* Programmable Almost fill level */ +#define DMM_PAF2 0x00000040 /* Programmable Almost fill level */ +#define DMM_PAF3 0x00000060 /* Programmable Almost fill level */ +#define DMM_PAF4 0x00000080 /* Programmable Almost fill level */ +#define DMM_PAF5 0x000000A0 /* Programmable Almost fill level */ +#define DMM_PAF6 0x000000C0 /* Programmable Almost fill level */ +#define DMM_PAF7 0x000000D0 /* Programmable Almost fill level */ +#define DMM_MAP 0xFFFF0000 /* Remap Address Bits */ + +#define PLX_CAR_REG 0x002C /* L, Configuration Address Register */ +#define CAR_CT0 0x00000000 /* Config Type 0 */ +#define CAR_CT1 0x00000001 /* Config Type 1 */ +#define CAR_REG 0x000000FC /* Register Number Bits */ +#define CAR_FUN 0x00000700 /* Function Number Bits */ +#define CAR_DEV 0x0000F800 /* Device Number Bits */ +#define CAR_BUS 0x00FF0000 /* Bus Number Bits */ +#define CAR_CFG 0x80000000 /* Config Spc Access Enable */ + +#define PLX_DBR_IN_REG 0x0060 /* L, PCI to Local Doorbell Register */ + +#define PLX_DBR_OUT_REG 0x0064 /* L, Local to PCI Doorbell Register */ + +#define PLX_INTRCS_REG 0x0068 /* L, Interrupt Control/Status Reg */ +#define ICS_AERR 0x00000001 /* Assert LSERR on ABORT */ +#define ICS_PERR 0x00000002 /* Assert LSERR on Parity Error */ +#define ICS_SERR 0x00000004 /* Generate PCI SERR# */ +#define ICS_MBIE 0x00000008 // mailbox interrupt enable +#define ICS_PIE 0x00000100 /* PCI Interrupt Enable */ +#define ICS_PDIE 0x00000200 /* PCI Doorbell Interrupt Enable */ +#define ICS_PAIE 0x00000400 /* PCI Abort Interrupt Enable */ +#define ICS_PLIE 0x00000800 /* PCI Local Int Enable */ +#define ICS_RAE 0x00001000 /* Retry Abort Enable */ +#define ICS_PDIA 0x00002000 /* PCI Doorbell Interrupt Active */ +#define ICS_PAIA 0x00004000 /* PCI Abort Interrupt Active */ +#define ICS_LIA 0x00008000 /* Local Interrupt Active */ +#define ICS_LIE 0x00010000 /* Local Interrupt Enable */ +#define ICS_LDIE 0x00020000 /* Local Doorbell Int Enable */ +#define ICS_DMA0_E 0x00040000 /* DMA #0 Interrupt Enable */ +#define ICS_DMA1_E 0x00080000 /* DMA #1 Interrupt Enable */ +#define ICS_LDIA 0x00100000 /* Local Doorbell Int Active */ +#define ICS_DMA0_A 0x00200000 /* DMA #0 Interrupt Active */ +#define ICS_DMA1_A 0x00400000 /* DMA #1 Interrupt Active */ +#define ICS_BIA 0x00800000 /* BIST Interrupt Active */ +#define ICS_TA_DM 0x01000000 /* Target Abort - Direct Master */ +#define ICS_TA_DMA0 0x02000000 /* Target Abort - DMA #0 */ +#define ICS_TA_DMA1 0x04000000 /* Target Abort - DMA #1 */ +#define ICS_TA_RA 0x08000000 /* Target Abort - Retry Timeout */ +#define ICS_MBIA(x) (0x10000000 << ((x) & 0x3)) // mailbox x is active + +#define PLX_CONTROL_REG 0x006C /* L, EEPROM Cntl & PCI Cmd Codes */ +#define CTL_RDMA 0x0000000E /* DMA Read Command */ +#define CTL_WDMA 0x00000070 /* DMA Write Command */ +#define CTL_RMEM 0x00000600 /* Memory Read Command */ +#define CTL_WMEM 0x00007000 /* Memory Write Command */ +#define CTL_USERO 0x00010000 /* USERO output pin control bit */ +#define CTL_USERI 0x00020000 /* USERI input pin bit */ +#define CTL_EE_CLK 0x01000000 /* EEPROM Clock line */ +#define CTL_EE_CS 0x02000000 /* EEPROM Chip Select */ +#define CTL_EE_W 0x04000000 /* EEPROM Write bit */ +#define CTL_EE_R 0x08000000 /* EEPROM Read bit */ +#define CTL_EECHK 0x10000000 /* EEPROM Present bit */ +#define CTL_EERLD 0x20000000 /* EEPROM Reload Register */ +#define CTL_RESET 0x40000000 /* !! Adapter Reset !! */ +#define CTL_READY 0x80000000 /* Local Init Done */ #define PLX_ID_REG 0x70 // hard-coded plx vendor and device ids @@ -277,32 +271,30 @@ enum bigend_bits * uses a subset of the full PUTS interface. */ - /*****************************************/ /*** MAILBOX #(-1) - MEM ACCESS STS ***/ /*****************************************/ -#define MBX_STS_VALID 0x57584744 /* 'WXGD' */ -#define MBX_STS_DILAV 0x44475857 /* swapped = 'DGXW' */ +#define MBX_STS_VALID 0x57584744 /* 'WXGD' */ +#define MBX_STS_DILAV 0x44475857 /* swapped = 'DGXW' */ /*****************************************/ /*** MAILBOX #0 - PUTS STATUS ***/ /*****************************************/ -#define MBX_STS_MASK 0x000000ff /* PUTS Status Register bits */ -#define MBX_STS_TMASK 0x0000000f /* register bits for TEST number */ - -#define MBX_STS_PCIRESET 0x00000100 /* Host issued PCI reset request */ -#define MBX_STS_BUSY 0x00000080 /* PUTS is in progress */ -#define MBX_STS_ERROR 0x00000040 /* PUTS has failed */ -#define MBX_STS_RESERVED 0x000000c0 /* Undefined -> status in transition. - We are in process of changing - bits; we SET Error bit before - RESET of Busy bit */ +#define MBX_STS_MASK 0x000000ff /* PUTS Status Register bits */ +#define MBX_STS_TMASK 0x0000000f /* register bits for TEST number */ -#define MBX_RESERVED_5 0x00000020 /* FYI: reserved/unused bit */ -#define MBX_RESERVED_4 0x00000010 /* FYI: reserved/unused bit */ +#define MBX_STS_PCIRESET 0x00000100 /* Host issued PCI reset request */ +#define MBX_STS_BUSY 0x00000080 /* PUTS is in progress */ +#define MBX_STS_ERROR 0x00000040 /* PUTS has failed */ +#define MBX_STS_RESERVED 0x000000c0 /* Undefined -> status in transition. + We are in process of changing + bits; we SET Error bit before + RESET of Busy bit */ +#define MBX_RESERVED_5 0x00000020 /* FYI: reserved/unused bit */ +#define MBX_RESERVED_4 0x00000010 /* FYI: reserved/unused bit */ /******************************************/ /*** MAILBOX #1 - PUTS COMMANDS ***/ @@ -315,66 +307,63 @@ enum bigend_bits * mailbox command processing functionality. */ -#define MBX_CMD_MASK 0xffff0000 /* PUTS Command Register bits */ +#define MBX_CMD_MASK 0xffff0000 /* PUTS Command Register bits */ -#define MBX_CMD_ABORTJ 0x85000000 /* abort and jump */ -#define MBX_CMD_RESETP 0x86000000 /* reset and pause at start */ -#define MBX_CMD_PAUSE 0x87000000 /* pause immediately */ -#define MBX_CMD_PAUSEC 0x88000000 /* pause on completion */ -#define MBX_CMD_RESUME 0x89000000 /* resume operation */ -#define MBX_CMD_STEP 0x8a000000 /* single step tests */ +#define MBX_CMD_ABORTJ 0x85000000 /* abort and jump */ +#define MBX_CMD_RESETP 0x86000000 /* reset and pause at start */ +#define MBX_CMD_PAUSE 0x87000000 /* pause immediately */ +#define MBX_CMD_PAUSEC 0x88000000 /* pause on completion */ +#define MBX_CMD_RESUME 0x89000000 /* resume operation */ +#define MBX_CMD_STEP 0x8a000000 /* single step tests */ -#define MBX_CMD_BSWAP 0x8c000000 /* identify byte swap scheme */ -#define MBX_CMD_BSWAP_0 0x8c000000 /* use scheme 0 */ -#define MBX_CMD_BSWAP_1 0x8c000001 /* use scheme 1 */ +#define MBX_CMD_BSWAP 0x8c000000 /* identify byte swap scheme */ +#define MBX_CMD_BSWAP_0 0x8c000000 /* use scheme 0 */ +#define MBX_CMD_BSWAP_1 0x8c000001 /* use scheme 1 */ -#define MBX_CMD_SETHMS 0x8d000000 /* setup host memory access window - size */ -#define MBX_CMD_SETHBA 0x8e000000 /* setup host memory access base - address */ -#define MBX_CMD_MGO 0x8f000000 /* perform memory setup and continue - (IE. Done) */ -#define MBX_CMD_NOOP 0xFF000000 /* dummy, illegal command */ +#define MBX_CMD_SETHMS 0x8d000000 /* setup host memory access window + size */ +#define MBX_CMD_SETHBA 0x8e000000 /* setup host memory access base + address */ +#define MBX_CMD_MGO 0x8f000000 /* perform memory setup and continue + (IE. Done) */ +#define MBX_CMD_NOOP 0xFF000000 /* dummy, illegal command */ /*****************************************/ /*** MAILBOX #2 - MEMORY SIZE ***/ /*****************************************/ -#define MBX_MEMSZ_MASK 0xffff0000 /* PUTS Memory Size Register bits */ - -#define MBX_MEMSZ_128KB 0x00020000 /* 128 kilobyte board */ -#define MBX_MEMSZ_256KB 0x00040000 /* 256 kilobyte board */ -#define MBX_MEMSZ_512KB 0x00080000 /* 512 kilobyte board */ -#define MBX_MEMSZ_1MB 0x00100000 /* 1 megabyte board */ -#define MBX_MEMSZ_2MB 0x00200000 /* 2 megabyte board */ -#define MBX_MEMSZ_4MB 0x00400000 /* 4 megabyte board */ -#define MBX_MEMSZ_8MB 0x00800000 /* 8 megabyte board */ -#define MBX_MEMSZ_16MB 0x01000000 /* 16 megabyte board */ +#define MBX_MEMSZ_MASK 0xffff0000 /* PUTS Memory Size Register bits */ +#define MBX_MEMSZ_128KB 0x00020000 /* 128 kilobyte board */ +#define MBX_MEMSZ_256KB 0x00040000 /* 256 kilobyte board */ +#define MBX_MEMSZ_512KB 0x00080000 /* 512 kilobyte board */ +#define MBX_MEMSZ_1MB 0x00100000 /* 1 megabyte board */ +#define MBX_MEMSZ_2MB 0x00200000 /* 2 megabyte board */ +#define MBX_MEMSZ_4MB 0x00400000 /* 4 megabyte board */ +#define MBX_MEMSZ_8MB 0x00800000 /* 8 megabyte board */ +#define MBX_MEMSZ_16MB 0x01000000 /* 16 megabyte board */ /***************************************/ /*** MAILBOX #2 - BOARD TYPE ***/ /***************************************/ -#define MBX_BTYPE_MASK 0x0000ffff /* PUTS Board Type Register */ -#define MBX_BTYPE_FAMILY_MASK 0x0000ff00 /* PUTS Board Family Register */ -#define MBX_BTYPE_SUBTYPE_MASK 0x000000ff /* PUTS Board Subtype */ +#define MBX_BTYPE_MASK 0x0000ffff /* PUTS Board Type Register */ +#define MBX_BTYPE_FAMILY_MASK 0x0000ff00 /* PUTS Board Family Register */ +#define MBX_BTYPE_SUBTYPE_MASK 0x000000ff /* PUTS Board Subtype */ -#define MBX_BTYPE_PLX9060 0x00000100 /* PLX family type */ -#define MBX_BTYPE_PLX9080 0x00000300 /* PLX wanXL100s family type */ - -#define MBX_BTYPE_WANXL_4 0x00000104 /* wanXL400, 4-port */ -#define MBX_BTYPE_WANXL_2 0x00000102 /* wanXL200, 2-port */ -#define MBX_BTYPE_WANXL_1s 0x00000301 /* wanXL100s, 1-port */ -#define MBX_BTYPE_WANXL_1t 0x00000401 /* wanXL100T1, 1-port */ +#define MBX_BTYPE_PLX9060 0x00000100 /* PLX family type */ +#define MBX_BTYPE_PLX9080 0x00000300 /* PLX wanXL100s family type */ +#define MBX_BTYPE_WANXL_4 0x00000104 /* wanXL400, 4-port */ +#define MBX_BTYPE_WANXL_2 0x00000102 /* wanXL200, 2-port */ +#define MBX_BTYPE_WANXL_1s 0x00000301 /* wanXL100s, 1-port */ +#define MBX_BTYPE_WANXL_1t 0x00000401 /* wanXL100T1, 1-port */ /*****************************************/ /*** MAILBOX #3 - SHMQ MAILBOX ***/ /*****************************************/ -#define MBX_SMBX_MASK 0x000000ff /* PUTS SHMQ Mailbox bits */ - +#define MBX_SMBX_MASK 0x000000ff /* PUTS SHMQ Mailbox bits */ /***************************************/ /*** GENERIC HOST-SIDE DRIVER ***/ @@ -384,55 +373,53 @@ enum bigend_bits #define MBX_OK 1 /* mailbox check routine - type of testing */ -#define MBXCHK_STS 0x00 /* check for PUTS status */ -#define MBXCHK_NOWAIT 0x01 /* dont care about PUTS status */ +#define MBXCHK_STS 0x00 /* check for PUTS status */ +#define MBXCHK_NOWAIT 0x01 /* dont care about PUTS status */ /* system allocates this many bytes for address mapping mailbox space */ #define MBX_ADDR_SPACE_360 0x80 /* wanXL100s/200/400 */ #define MBX_ADDR_MASK_360 (MBX_ADDR_SPACE_360-1) -static inline int plx9080_abort_dma(void *iobase, unsigned int channel ) +static inline int plx9080_abort_dma(void *iobase, unsigned int channel) { void *dma_cs_addr; uint8_t dma_status; const int timeout = 10000; unsigned int i; - if( channel ) + if (channel) dma_cs_addr = iobase + PLX_DMA1_CS_REG; else dma_cs_addr = iobase + PLX_DMA0_CS_REG; // abort dma transfer if necessary - dma_status = readb( dma_cs_addr ); - if( ( dma_status & PLX_DMA_EN_BIT ) == 0 ) - { + dma_status = readb(dma_cs_addr); + if ((dma_status & PLX_DMA_EN_BIT) == 0) { return 0; } - // wait to make sure done bit is zero - for( i = 0; ( dma_status & PLX_DMA_DONE_BIT ) && i < timeout; i++ ) - { - comedi_udelay( 1 ); - dma_status = readb( dma_cs_addr ); + for (i = 0; (dma_status & PLX_DMA_DONE_BIT) && i < timeout; i++) { + comedi_udelay(1); + dma_status = readb(dma_cs_addr); } - if( i == timeout ) - { - rt_printk("plx9080: cancel() timed out waiting for dma %i done clear\n", channel); + if (i == timeout) { + rt_printk + ("plx9080: cancel() timed out waiting for dma %i done clear\n", + channel); return -ETIMEDOUT; } // disable and abort channel - writeb( PLX_DMA_ABORT_BIT, dma_cs_addr ); + writeb(PLX_DMA_ABORT_BIT, dma_cs_addr); // wait for dma done bit - dma_status = readb( dma_cs_addr ); - for( i = 0; ( dma_status & PLX_DMA_DONE_BIT ) == 0 && i < timeout; i++ ) - { - comedi_udelay( 1 ); - dma_status = readb( dma_cs_addr ); + dma_status = readb(dma_cs_addr); + for (i = 0; (dma_status & PLX_DMA_DONE_BIT) == 0 && i < timeout; i++) { + comedi_udelay(1); + dma_status = readb(dma_cs_addr); } - if( i == timeout ) - { - rt_printk("plx9080: cancel() timed out waiting for dma %i done set\n", channel); + if (i == timeout) { + rt_printk + ("plx9080: cancel() timed out waiting for dma %i done set\n", + channel); return -ETIMEDOUT; } diff --git a/comedi/drivers/poc.c b/comedi/drivers/poc.c index ac1f291d..4aa14762 100644 --- a/comedi/drivers/poc.c +++ b/comedi/drivers/poc.c @@ -41,74 +41,79 @@ Configuration options: #include -static int poc_attach(comedi_device *dev,comedi_devconfig *it); -static int poc_detach(comedi_device *dev); -static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); - -static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); - -struct boarddef_struct{ +static int poc_attach(comedi_device * dev, comedi_devconfig * it); +static int poc_detach(comedi_device * dev); +static int readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +static int dac02_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pcl733_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int pcl734_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); + +struct boarddef_struct { const char *name; unsigned int iosize; - int (*setup)(comedi_device *); + int (*setup) (comedi_device *); int type; int n_chan; int n_bits; - int (*winsn)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - int (*rinsn)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - int (*insnbits)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); + int (*winsn) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + int (*rinsn) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + int (*insnbits) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); const comedi_lrange *range; }; -static const struct boarddef_struct boards[]={ +static const struct boarddef_struct boards[] = { { - name: "dac02", - iosize: 8, - //setup: dac02_setup, - type: COMEDI_SUBD_AO, - n_chan: 2, - n_bits: 12, - winsn: dac02_ao_winsn, - rinsn: readback_insn, - range: &range_unknown, - }, + name: "dac02", + iosize: 8, + //setup: dac02_setup, + type: COMEDI_SUBD_AO, + n_chan: 2, + n_bits: 12, + winsn: dac02_ao_winsn, + rinsn: readback_insn, + range: &range_unknown, + }, { - name: "pcl733", - iosize: 4, - type: COMEDI_SUBD_DI, - n_chan: 32, - n_bits: 1, - insnbits: pcl733_insn_bits, - range: &range_digital, - }, + name: "pcl733", + iosize: 4, + type: COMEDI_SUBD_DI, + n_chan: 32, + n_bits: 1, + insnbits:pcl733_insn_bits, + range: &range_digital, + }, { - name: "pcl734", - iosize: 4, - type: COMEDI_SUBD_DO, - n_chan: 32, - n_bits: 1, - insnbits: pcl734_insn_bits, - range: &range_digital, - }, + name: "pcl734", + iosize: 4, + type: COMEDI_SUBD_DO, + n_chan: 32, + n_bits: 1, + insnbits:pcl734_insn_bits, + range: &range_digital, + }, }; + #define n_boards (sizeof(boards)/sizeof(boards[0])) #define this_board ((const struct boarddef_struct *)dev->board_ptr) -static comedi_driver driver_poc= -{ - driver_name: "poc", - module: THIS_MODULE, - attach: poc_attach, - detach: poc_detach, - board_name: &boards[0].name, - num_names: n_boards, - offset: sizeof(boards[0]), +static comedi_driver driver_poc = { + driver_name:"poc", + module:THIS_MODULE, + attach:poc_attach, + detach:poc_detach, + board_name:&boards[0].name, + num_names:n_boards, + offset:sizeof(boards[0]), }; -static int poc_attach(comedi_device *dev, comedi_devconfig *it) +static int poc_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; unsigned long iobase; @@ -120,47 +125,44 @@ static int poc_attach(comedi_device *dev, comedi_devconfig *it) dev->board_name = this_board->name; - if(iobase == 0) - { + if (iobase == 0) { printk("io base address required\n"); return -EINVAL; } iosize = this_board->iosize; /* check if io addresses are available */ - if(!request_region(iobase, iosize, "dac02")) - { - printk("I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", - iobase, iobase + iosize - 1); + if (!request_region(iobase, iosize, "dac02")) { + printk("I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n", iobase, iobase + iosize - 1); return -EIO; } dev->iobase = iobase; - if(alloc_subdevices(dev, 1) < 0) + if (alloc_subdevices(dev, 1) < 0) return -ENOMEM; - if(alloc_private(dev,sizeof(lsampl_t)*this_board->n_chan) < 0) + if (alloc_private(dev, sizeof(lsampl_t) * this_board->n_chan) < 0) return -ENOMEM; /* analog output subdevice */ - s=dev->subdevices + 0; + s = dev->subdevices + 0; s->type = this_board->type; s->n_chan = this_board->n_chan; - s->maxdata = (1<n_bits)-1; + s->maxdata = (1 << this_board->n_bits) - 1; s->range_table = this_board->range; s->insn_write = this_board->winsn; s->insn_read = this_board->rinsn; s->insn_bits = this_board->insnbits; - if(s->type==COMEDI_SUBD_AO || s->type==COMEDI_SUBD_DO){ + if (s->type == COMEDI_SUBD_AO || s->type == COMEDI_SUBD_DO) { s->subdev_flags = SDF_WRITABLE; } return 0; } -static int poc_detach(comedi_device *dev) +static int poc_detach(comedi_device * dev) { /* only free stuff if it has been allocated by _attach */ - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, this_board->iosize); printk("comedi%d: dac02: remove\n", dev->minor); @@ -168,12 +170,13 @@ static int poc_detach(comedi_device *dev) return 0; } -static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int readback_insn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int chan; chan = CR_CHAN(insn->chanspec); - data[0]=((lsampl_t *)dev->private)[chan]; + data[0] = ((lsampl_t *) dev->private)[chan]; return 1; } @@ -182,18 +185,19 @@ static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins #define DAC02_LSB(a) (2 * a) #define DAC02_MSB(a) (2 * a + 1) -static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int dac02_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int temp; int chan; int output; chan = CR_CHAN(insn->chanspec); - ((lsampl_t *)dev->private)[chan] = data[0]; + ((lsampl_t *) dev->private)[chan] = data[0]; output = data[0]; #ifdef wrong // convert to complementary binary if range is bipolar - if((CR_RANGE(insn->chanspec) & 0x2) == 0) + if ((CR_RANGE(insn->chanspec) & 0x2) == 0) output = ~output; #endif temp = (output << 4) & 0xf0; @@ -204,10 +208,11 @@ static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *in return 1; } -static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl733_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + 0); data[1] |= (inb(dev->iobase + 1) << 8); @@ -217,21 +222,22 @@ static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int pcl734_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; - if(data[0]){ + if (insn->n != 2) + return -EINVAL; + if (data[0]) { s->state &= ~data[0]; - s->state |= (data[0]&data[1]); - if((data[0]>>0)&0xff) - outb((s->state>>0)&0xff, dev->iobase + 0); - if((data[0]>>8)&0xff) - outb((s->state>>8)&0xff, dev->iobase + 1); - if((data[0]>>16)&0xff) - outb((s->state>>16)&0xff, dev->iobase + 2); - if((data[0]>>24)&0xff) - outb((s->state>>24)&0xff, dev->iobase + 3); + s->state |= (data[0] & data[1]); + if ((data[0] >> 0) & 0xff) + outb((s->state >> 0) & 0xff, dev->iobase + 0); + if ((data[0] >> 8) & 0xff) + outb((s->state >> 8) & 0xff, dev->iobase + 1); + if ((data[0] >> 16) & 0xff) + outb((s->state >> 16) & 0xff, dev->iobase + 2); + if ((data[0] >> 24) & 0xff) + outb((s->state >> 24) & 0xff, dev->iobase + 3); } data[1] = s->state; @@ -239,4 +245,3 @@ static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s, } COMEDI_INITCLEANUP(driver_poc); - diff --git a/comedi/drivers/quatech_daqp_cs.c b/comedi/drivers/quatech_daqp_cs.c index 0b5db681..e8308fe8 100644 --- a/comedi/drivers/quatech_daqp_cs.c +++ b/comedi/drivers/quatech_daqp_cs.c @@ -12,8 +12,6 @@ quatech_daqp_cs.c 1.10 - - Documentation for the DAQP PCMCIA cards can be found on Quatech's site: ftp://ftp.quatech.com/Manuals/daqp-208.pdf @@ -58,7 +56,6 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308 #include #include - /* 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 @@ -71,8 +68,7 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308 static int pc_debug = PCMCIA_DEBUG; module_param(pc_debug, int, 0644); #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) -static char *version = -"quatech_daqp_cs.c 1.10 2003/04/21 (Brent Baccala)"; +static char *version = "quatech_daqp_cs.c 1.10 2003/04/21 (Brent Baccala)"; #else #define DEBUG(n, args...) #endif @@ -82,23 +78,23 @@ static char *version = typedef struct local_info_t { struct pcmcia_device *link; - dev_node_t node; - int stop; - int table_index; - char board_name[32]; + dev_node_t node; + int stop; + int table_index; + char board_name[32]; - enum {semaphore, buffer} interrupt_mode; + enum { semaphore, buffer } interrupt_mode; - struct semaphore eos; + struct semaphore eos; - comedi_device *dev; - comedi_subdevice *s; - int count; + comedi_device *dev; + comedi_subdevice *s; + int count; } local_info_t; /* A list of "instances" of the device. */ -static local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ }; +static local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ }; /* The DAQP communicates with the system through a 16 byte I/O window. */ @@ -189,44 +185,45 @@ static local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ }; */ static const comedi_lrange range_daqp_ai = { 4, { - BIP_RANGE( 10 ), - BIP_RANGE( 5 ), - BIP_RANGE( 2.5 ), - BIP_RANGE( 1.25 ) -}}; + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + BIP_RANGE(1.25) + } +}; -static const comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)}}; +static const comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} }; /*====================================================================*/ /* 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: "quatech_daqp_cs", - module: THIS_MODULE, - attach: daqp_attach, - detach: daqp_detach, +static int daqp_attach(comedi_device * dev, comedi_devconfig * it); +static int daqp_detach(comedi_device * dev); +static comedi_driver driver_daqp = { + driver_name:"quatech_daqp_cs", + module:THIS_MODULE, + attach:daqp_attach, + detach:daqp_detach, }; #ifdef DAQP_DEBUG -static void daqp_dump(comedi_device *dev) +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)); + inb(dev->iobase + DAQP_STATUS), inb(dev->iobase + DAQP_AUX)); } static void hex_dump(char *str, void *ptr, int len) { - unsigned char * cptr = ptr; + unsigned char *cptr = ptr; int i; printk(str); - for (i=0; iprivate; + local_info_t *local = (local_info_t *) s->private; if (local->stop) { return -EIO; } - outb(DAQP_COMMAND_STOP, dev->iobase+DAQP_COMMAND); + outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND); /* flush any linguring data in FIFO - superfluous here */ /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */ @@ -266,9 +263,9 @@ static int daqp_ai_cancel(comedi_device *dev, comedi_subdevice *s) * which run pretty quick. */ -static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) +static void daqp_interrupt(int irq, void *dev_id PT_REGS_ARG) { - local_info_t *local = (local_info_t *)dev_id; + local_info_t *local = (local_info_t *) dev_id; comedi_device *dev; comedi_subdevice *s; int loop_limit = 10000; @@ -276,33 +273,32 @@ static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) if (local == NULL) { printk(KERN_WARNING - "daqp_interrupt(): irq %d for unknown device.\n", irq); + "daqp_interrupt(): irq %d for unknown device.\n", irq); return; } dev = local->dev; if (dev == NULL) { - printk(KERN_WARNING - "daqp_interrupt(): NULL comedi_device.\n"); + printk(KERN_WARNING "daqp_interrupt(): NULL comedi_device.\n"); return; } if (!dev->attached) { printk(KERN_WARNING - "daqp_interrupt(): comedi_device not yet attached.\n"); + "daqp_interrupt(): comedi_device not yet attached.\n"); return; } s = local->s; if (s == NULL) { printk(KERN_WARNING - "daqp_interrupt(): NULL comedi_subdevice.\n"); + "daqp_interrupt(): NULL comedi_subdevice.\n"); return; } if ((local_info_t *) s->private != local) { printk(KERN_WARNING - "daqp_interrupt(): invalid comedi_subdevice.\n"); + "daqp_interrupt(): invalid comedi_subdevice.\n"); return; } @@ -315,14 +311,14 @@ static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) case buffer: - while ( ! ((status = inb(dev->iobase + DAQP_STATUS)) - & DAQP_STATUS_FIFO_EMPTY)) { + while (!((status = inb(dev->iobase + DAQP_STATUS)) + & DAQP_STATUS_FIFO_EMPTY)) { sampl_t data; if (status & DAQP_STATUS_DATA_LOST) { s->async->events |= - COMEDI_CB_EOA | COMEDI_CB_OVERFLOW; + COMEDI_CB_EOA | COMEDI_CB_OVERFLOW; printk("daqp: data lost\n"); daqp_ai_cancel(dev, s); break; @@ -339,7 +335,7 @@ static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) */ if (local->count > 0) { - local->count --; + local->count--; if (local->count == 0) { daqp_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA; @@ -347,12 +343,13 @@ static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) } } - if ((loop_limit --) <= 0) break; + if ((loop_limit--) <= 0) + break; } if (loop_limit <= 0) { printk(KERN_WARNING - "loop_limit reached in daqp_interrupt()\n"); + "loop_limit reached in daqp_interrupt()\n"); daqp_ai_cancel(dev, s); s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; } @@ -365,13 +362,13 @@ static void daqp_interrupt(int irq, void * dev_id PT_REGS_ARG) /* One-shot analog data acquisition routine */ -static int daqp_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int daqp_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - local_info_t *local = (local_info_t *)s->private; + local_info_t *local = (local_info_t *) s->private; int i; int v; - int counter=10000; + int counter = 10000; if (local->stop) { return -EIO; @@ -380,10 +377,10 @@ static int daqp_ai_insn_read(comedi_device *dev,comedi_subdevice *s, /* Stop any running conversion */ daqp_ai_cancel(dev, s); - outb(0, dev->iobase+DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX); /* Reset scan list queue */ - outb(DAQP_COMMAND_RSTQ, dev->iobase+DAQP_COMMAND); + outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); /* Program one scan list entry */ @@ -406,34 +403,32 @@ static int daqp_ai_insn_read(comedi_device *dev,comedi_subdevice *s, /* Set trigger */ v = DAQP_CONTROL_TRIGGER_ONESHOT | DAQP_CONTROL_TRIGGER_INTERNAL - | DAQP_CONTROL_PACER_100kHz | DAQP_CONTROL_EOS_INT_ENABLE; + | DAQP_CONTROL_PACER_100kHz | DAQP_CONTROL_EOS_INT_ENABLE; outb(v, dev->iobase + DAQP_CONTROL); - /* Reset any pending interrupts (my card has a tendancy to require * require multiple reads on the status register to achieve this) */ while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)); + && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) ; if (!counter) { printk("daqp: couldn't clear interrupts in status register\n"); return -1; } - /* Make sure semaphore is blocked */ sema_init(&local->eos, 0); local->interrupt_mode = semaphore; local->dev = dev; local->s = s; - for (i=0; i < insn->n; i++) { + for (i = 0; i < insn->n; i++) { /* Start conversion */ outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, - dev->iobase + DAQP_COMMAND); + dev->iobase + DAQP_COMMAND); /* Wait for interrupt service routine to unblock semaphore */ /* Maybe could use a timeout here, but it's interruptible */ @@ -458,13 +453,12 @@ static int daqp_ns_to_timer(unsigned int *ns, int round) { int timer; - timer = *ns/200; - *ns = timer*200; + timer = *ns / 200; + *ns = timer * 200; return timer; } - /* cmdtest tests a particular command to see if it is valid. * Using the cmdtest ioctl, a user can create a valid cmd * and then have it executed by the cmd ioctl. @@ -473,61 +467,69 @@ static int daqp_ns_to_timer(unsigned int *ns, int round) * the command passes. */ -static int daqp_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int daqp_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_NOW; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_FOLLOW) err++; - if(cmd->convert_src!=TRIG_NOW && - cmd->convert_src!=TRIG_TIMER) err++; - if(cmd->scan_begin_src==TRIG_FOLLOW && - cmd->convert_src==TRIG_NOW) err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_FOLLOW) + err++; + if (cmd->convert_src != TRIG_NOW && cmd->convert_src != TRIG_TIMER) + err++; + if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } +#define MAX_SPEED 10000 /* 100 kHz - in nanoseconds */ -#define MAX_SPEED 10000 /* 100 kHz - in nanoseconds */ - - if(cmd->scan_begin_src==TRIG_TIMER && cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER + && cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } @@ -536,59 +538,64 @@ static int daqp_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, * conversions times the convert time */ - if(cmd->scan_begin_src==TRIG_TIMER && cmd->convert_src==TRIG_TIMER - && cmd->scan_begin_arg != cmd->convert_arg * cmd->scan_end_arg){ + if (cmd->scan_begin_src == TRIG_TIMER && cmd->convert_src == TRIG_TIMER + && cmd->scan_begin_arg != + cmd->convert_arg * cmd->scan_end_arg) { err++; } - if(cmd->convert_src==TRIG_TIMER && cmd->convert_argconvert_arg=MAX_SPEED; + if (cmd->convert_src == TRIG_TIMER && cmd->convert_arg < MAX_SPEED) { + cmd->convert_arg = MAX_SPEED; err++; } - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0x00ffffff) { + cmd->stop_arg = 0x00ffffff; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; daqp_ns_to_timer(&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; daqp_ns_to_timer(&cmd->convert_arg, - cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->convert_arg) + err++; } - if(err)return 4; + if (err) + return 4; return 0; } -static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int daqp_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - local_info_t *local = (local_info_t *)s->private; + local_info_t *local = (local_info_t *) s->private; comedi_cmd *cmd = &s->async->cmd; int counter = 100; int scanlist_start_on_every_entry; @@ -604,10 +611,10 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) /* Stop any running conversion */ daqp_ai_cancel(dev, s); - outb(0, dev->iobase+DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX); /* Reset scan list queue */ - outb(DAQP_COMMAND_RSTQ, dev->iobase+DAQP_COMMAND); + outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); /* Program pacer clock * @@ -624,23 +631,23 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) if (cmd->convert_src == TRIG_TIMER) { int counter = daqp_ns_to_timer(&cmd->convert_arg, - cmd->flags&TRIG_ROUND_MASK); - outb(counter&0xff, dev->iobase + DAQP_PACER_LOW); - outb((counter>>8)&0xff, dev->iobase + DAQP_PACER_MID); - outb((counter>>16)&0xff, dev->iobase + DAQP_PACER_HIGH); + cmd->flags & TRIG_ROUND_MASK); + outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW); + outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID); + outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH); scanlist_start_on_every_entry = 1; } else { int counter = daqp_ns_to_timer(&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - outb(counter&0xff, dev->iobase + DAQP_PACER_LOW); - outb((counter>>8)&0xff, dev->iobase + DAQP_PACER_MID); - outb((counter>>16)&0xff, dev->iobase + DAQP_PACER_HIGH); + cmd->flags & TRIG_ROUND_MASK); + outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW); + outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID); + outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH); scanlist_start_on_every_entry = 0; } /* Program scan list */ - for (i=0; i < cmd->chanlist_len; i++) { + for (i = 0; i < cmd->chanlist_len; i++) { int chanspec = cmd->chanlist[i]; @@ -730,10 +737,11 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) if (cmd->stop_src == TRIG_COUNT) { local->count = cmd->stop_arg * cmd->scan_end_arg; threshold = 2 * local->count; - while (threshold > DAQP_FIFO_SIZE*3/4) threshold /= 2; + while (threshold > DAQP_FIFO_SIZE * 3 / 4) + threshold /= 2; } else { local->count = -1; - threshold = DAQP_FIFO_SIZE/2; + threshold = DAQP_FIFO_SIZE / 2; } /* Reset data FIFO (see page 28 of DAQP User's Manual) */ @@ -766,7 +774,7 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) */ while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)); + && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) ; if (!counter) { printk("daqp: couldn't clear interrupts in status register\n"); return -1; @@ -778,7 +786,7 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) /* Start conversion */ outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, - dev->iobase + DAQP_COMMAND); + dev->iobase + DAQP_COMMAND); return 0; } @@ -786,9 +794,9 @@ static int daqp_ai_cmd(comedi_device *dev, comedi_subdevice *s) /* Single-shot analog output routine */ static int daqp_ao_insn_write(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - local_info_t *local = (local_info_t *)s->private; + local_info_t *local = (local_info_t *) s->private; int d; unsigned int chan; @@ -799,13 +807,13 @@ static int daqp_ao_insn_write(comedi_device * dev, comedi_subdevice * s, chan = CR_CHAN(insn->chanspec); d = data[0]; d &= 0x0fff; - d ^= 0x0800; /* Flip the sign */ - d |= chan<<12; + d ^= 0x0800; /* Flip the sign */ + d |= chan << 12; /* Make sure D/A update mode is direct update */ - outb(0, dev->iobase+DAQP_AUX); + outb(0, dev->iobase + DAQP_AUX); - outw(d, dev->iobase+DAQP_DA); + outw(d, dev->iobase + DAQP_DA); return 1; } @@ -813,15 +821,15 @@ static int daqp_ao_insn_write(comedi_device * dev, comedi_subdevice * s, /* Digital input routine */ static int daqp_di_insn_read(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - local_info_t *local = (local_info_t *)s->private; + local_info_t *local = (local_info_t *) s->private; if (local->stop) { return -EIO; } - data[0] = inb(dev->iobase+DAQP_DIGITAL_IO); + data[0] = inb(dev->iobase + DAQP_DIGITAL_IO); return 1; } @@ -829,15 +837,15 @@ static int daqp_di_insn_read(comedi_device * dev, comedi_subdevice * s, /* Digital output routine */ static int daqp_do_insn_write(comedi_device * dev, comedi_subdevice * s, - comedi_insn *insn, lsampl_t *data) + comedi_insn * insn, lsampl_t * data) { - local_info_t *local = (local_info_t *)s->private; + local_info_t *local = (local_info_t *) s->private; if (local->stop) { return -EIO; } - outw(data[0] & 0xf, dev->iobase+DAQP_DIGITAL_IO); + outw(data[0] & 0xf, dev->iobase + DAQP_DIGITAL_IO); return 1; } @@ -848,7 +856,7 @@ static int daqp_do_insn_write(comedi_device * dev, comedi_subdevice * s, * when it is inserted. */ -static int daqp_attach(comedi_device *dev, comedi_devconfig *it) +static int daqp_attach(comedi_device * dev, comedi_devconfig * it) { int ret; local_info_t *local = dev_table[it->options[0]]; @@ -856,10 +864,10 @@ static int daqp_attach(comedi_device *dev, comedi_devconfig *it) int i; comedi_subdevice *s; - if (it->options[0] < 0 || it->options[0] >= MAX_DEV || ! local) { - printk("comedi%d: No such daqp device %d\n", - dev->minor, it->options[0]); - return -EIO; + if (it->options[0] < 0 || it->options[0] >= MAX_DEV || !local) { + printk("comedi%d: No such daqp device %d\n", + dev->minor, it->options[0]); + return -EIO; } /* Typically brittle code that I don't completely understand, @@ -877,20 +885,22 @@ static int daqp_attach(comedi_device *dev, comedi_devconfig *it) if (pcmcia_get_first_tuple(local->link, &tuple) == 0) { u_char buf[128]; - buf[0] = buf[sizeof(buf)-1] = 0; + buf[0] = buf[sizeof(buf) - 1] = 0; tuple.TupleData = buf; tuple.TupleDataMax = sizeof(buf); tuple.TupleOffset = 2; if (pcmcia_get_tuple_data(local->link, &tuple) == 0) { - for (i=0; iboard_name, buf+i, + && (strncmp(buf + i, "DAQP", 4) == 0)) { + strncpy(local->board_name, buf + i, sizeof(local->board_name)); } } @@ -898,64 +908,63 @@ static int daqp_attach(comedi_device *dev, comedi_devconfig *it) dev->iobase = local->link->io.BasePort1; - if((ret=alloc_subdevices(dev,4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; printk("comedi%d: attaching daqp%d (io 0x%04lx)\n", - dev->minor, it->options[0], dev->iobase); + dev->minor, it->options[0], dev->iobase); - s=dev->subdevices+0; + s = dev->subdevices + 0; dev->read_subdev = s; s->private = local; - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; - s->n_chan=8; - s->len_chanlist=2048; - s->maxdata=0xffff; - s->range_table=&range_daqp_ai; - s->insn_read=daqp_ai_insn_read; - s->do_cmdtest=daqp_ai_cmdtest; - s->do_cmd=daqp_ai_cmd; - s->cancel=daqp_ai_cancel; - - s=dev->subdevices+1; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; + s->n_chan = 8; + s->len_chanlist = 2048; + s->maxdata = 0xffff; + s->range_table = &range_daqp_ai; + s->insn_read = daqp_ai_insn_read; + s->do_cmdtest = daqp_ai_cmdtest; + s->do_cmd = daqp_ai_cmd; + s->cancel = daqp_ai_cancel; + + s = dev->subdevices + 1; dev->write_subdev = s; s->private = local; - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITEABLE; - s->n_chan=2; - s->len_chanlist=1; - s->maxdata=0x0fff; - s->range_table=&range_daqp_ao; - s->insn_write=daqp_ao_insn_write; - - s=dev->subdevices+2; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + s->len_chanlist = 1; + s->maxdata = 0x0fff; + s->range_table = &range_daqp_ao; + s->insn_write = daqp_ao_insn_write; + + s = dev->subdevices + 2; s->private = local; - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->n_chan=1; - s->len_chanlist=1; - s->insn_read=daqp_di_insn_read; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 1; + s->len_chanlist = 1; + s->insn_read = daqp_di_insn_read; - s=dev->subdevices+3; + s = dev->subdevices + 3; s->private = local; - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITEABLE; - s->n_chan=1; - s->len_chanlist=1; - s->insn_write=daqp_do_insn_write; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 1; + s->len_chanlist = 1; + s->insn_write = daqp_do_insn_write; 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) +static int daqp_detach(comedi_device * dev) { - printk("comedi%d: detaching daqp\n",dev->minor); + printk("comedi%d: detaching daqp\n", dev->minor); return 0; } @@ -1017,7 +1026,7 @@ static int daqp_cs_resume(struct pcmcia_device *p_dev); needed to manage one actual PCMCIA card. */ -static int daqp_cs_attach(struct pcmcia_device *); +static int daqp_cs_attach(struct pcmcia_device *); static void daqp_cs_detach(struct pcmcia_device *); /* @@ -1028,7 +1037,6 @@ static void daqp_cs_detach(struct pcmcia_device *); static const dev_info_t dev_info = "quatech_daqp_cs"; - /*====================================================================== daqp_cs_attach() creates an "instance" of the driver, allocating @@ -1041,49 +1049,51 @@ static const dev_info_t dev_info = "quatech_daqp_cs"; ======================================================================*/ -static int daqp_cs_attach(struct pcmcia_device *link) +static int daqp_cs_attach(struct pcmcia_device *link) { - local_info_t *local; - int i; + local_info_t *local; + int i; - DEBUG(0, "daqp_cs_attach()\n"); + DEBUG(0, "daqp_cs_attach()\n"); - for (i = 0; i < MAX_DEV; i++) - if (dev_table[i] == NULL) break; - if (i == MAX_DEV) { - printk(KERN_NOTICE "daqp_cs: no devices available\n"); - return -ENODEV; - } + for (i = 0; i < MAX_DEV; i++) + if (dev_table[i] == NULL) + break; + if (i == MAX_DEV) { + printk(KERN_NOTICE "daqp_cs: no devices available\n"); + return -ENODEV; + } - /* Allocate space for private device-specific data */ - local = kzalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return -ENOMEM; + /* Allocate space for private device-specific data */ + local = kzalloc(sizeof(local_info_t), GFP_KERNEL); + if (!local) + return -ENOMEM; - local->table_index = i; - dev_table[i] = local; - local->link = link; - link->priv = local; + local->table_index = i; + dev_table[i] = local; + local->link = link; + link->priv = local; /* Interrupt setup */ - link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; - link->irq.IRQInfo1 = IRQ_LEVEL_ID; - link->irq.Handler = daqp_interrupt; - link->irq.Instance = local; - - /* - 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.IntType = INT_MEMORY_AND_IO; - - daqp_cs_config(link); - - return 0; -} /* daqp_cs_attach */ + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; + link->irq.IRQInfo1 = IRQ_LEVEL_ID; + link->irq.Handler = daqp_interrupt; + link->irq.Instance = local; + + /* + 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.IntType = INT_MEMORY_AND_IO; + + daqp_cs_config(link); + + return 0; +} /* daqp_cs_attach */ /*====================================================================== @@ -1096,21 +1106,21 @@ static int daqp_cs_attach(struct pcmcia_device *link) static void daqp_cs_detach(struct pcmcia_device *link) { - local_info_t *dev = link->priv; + local_info_t *dev = link->priv; - DEBUG(0, "daqp_cs_detach(0x%p)\n", link); + DEBUG(0, "daqp_cs_detach(0x%p)\n", link); - if (link->dev_node) { + if (link->dev_node) { dev->stop = 1; daqp_cs_release(link); - } + } - /* Unlink device structure, and free it */ - dev_table[dev->table_index] = NULL; - if(dev) + /* Unlink device structure, and free it */ + dev_table[dev->table_index] = NULL; + if (dev) kfree(dev); -} /* daqp_cs_detach */ +} /* daqp_cs_detach */ /*====================================================================== @@ -1122,167 +1132,165 @@ static void daqp_cs_detach(struct pcmcia_device *link) static void daqp_cs_config(struct pcmcia_device *link) { - local_info_t *dev = link->priv; - tuple_t tuple; - cisparse_t parse; - int last_ret; - u_char buf[64]; - - DEBUG(0, "daqp_cs_config(0x%p)\n", link); - - /* - This reads the card's CONFIG tuple to find its configuration - registers. - */ - tuple.DesiredTuple = CISTPL_CONFIG; - tuple.Attributes = 0; - tuple.TupleData = buf; - tuple.TupleDataMax = sizeof(buf); - tuple.TupleOffset = 0; - if((last_ret = pcmcia_get_first_tuple(link, &tuple))) - { + local_info_t *dev = link->priv; + tuple_t tuple; + cisparse_t parse; + int last_ret; + u_char buf[64]; + + DEBUG(0, "daqp_cs_config(0x%p)\n", link); + + /* + This reads the card's CONFIG tuple to find its configuration + registers. + */ + tuple.DesiredTuple = CISTPL_CONFIG; + tuple.Attributes = 0; + tuple.TupleData = buf; + tuple.TupleDataMax = sizeof(buf); + tuple.TupleOffset = 0; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple))) { cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - if((last_ret = pcmcia_get_tuple_data(link, &tuple))) - { + if ((last_ret = pcmcia_get_tuple_data(link, &tuple))) { cs_error(link, GetTupleData, last_ret); goto cs_failed; } - if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse))) - { + if ((last_ret = pcmcia_parse_tuple(link, &tuple, &parse))) { cs_error(link, ParseTuple, last_ret); goto cs_failed; } - link->conf.ConfigBase = parse.config.base; - link->conf.Present = parse.config.rmask[0]; - - /* - In this loop, we scan the CIS for configuration table entries, - each of which describes a valid card configuration, including - voltage, IO window, memory window, and interrupt settings. - - We make no assumptions about the card to be configured: we use - just the information available in the CIS. In an ideal world, - this would work for any PCMCIA card, but it requires a complete - and accurate CIS. In practice, a driver usually "knows" most of - these things without consulting the CIS, and most client drivers - will only use the CIS to fill in implementation-defined details. - */ - tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; - if((last_ret = pcmcia_get_first_tuple(link, &tuple))) - { + link->conf.ConfigBase = parse.config.base; + link->conf.Present = parse.config.rmask[0]; + + /* + In this loop, we scan the CIS for configuration table entries, + each of which describes a valid card configuration, including + voltage, IO window, memory window, and interrupt settings. + + We make no assumptions about the card to be configured: we use + just the information available in the CIS. In an ideal world, + this would work for any PCMCIA card, but it requires a complete + and accurate CIS. In practice, a driver usually "knows" most of + these things without consulting the CIS, and most client drivers + will only use the CIS to fill in implementation-defined details. + */ + tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; + if ((last_ret = pcmcia_get_first_tuple(link, &tuple))) { cs_error(link, GetFirstTuple, last_ret); goto cs_failed; } - while (1) { - cistpl_cftable_entry_t dflt = { 0 }; - cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); - if(pcmcia_get_tuple_data(link, &tuple)) goto next_entry; - if(pcmcia_parse_tuple(link, &tuple, &parse)) goto next_entry; - - if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; - if (cfg->index == 0) goto next_entry; - link->conf.ConfigIndex = cfg->index; - - /* Do we need to allocate an interrupt? */ - if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) - link->conf.Attributes |= CONF_ENABLE_IRQ; - - /* IO window settings */ - link->io.NumPorts1 = link->io.NumPorts2 = 0; - if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { - cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; - link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; - if (!(io->flags & CISTPL_IO_8BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; - if (!(io->flags & CISTPL_IO_16BIT)) - link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; - link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; - link->io.BasePort1 = io->win[0].base; - link->io.NumPorts1 = io->win[0].len; - if (io->nwin > 1) { - link->io.Attributes2 = link->io.Attributes1; - link->io.BasePort2 = io->win[1].base; - link->io.NumPorts2 = io->win[1].len; - } - } + while (1) { + cistpl_cftable_entry_t dflt = { 0 }; + cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); + if (pcmcia_get_tuple_data(link, &tuple)) + goto next_entry; + if (pcmcia_parse_tuple(link, &tuple, &parse)) + goto next_entry; + + if (cfg->flags & CISTPL_CFTABLE_DEFAULT) + dflt = *cfg; + if (cfg->index == 0) + goto next_entry; + link->conf.ConfigIndex = cfg->index; + + /* Do we need to allocate an interrupt? */ + if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) + link->conf.Attributes |= CONF_ENABLE_IRQ; + + /* IO window settings */ + link->io.NumPorts1 = link->io.NumPorts2 = 0; + if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { + cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; + link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; + if (!(io->flags & CISTPL_IO_8BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; + if (!(io->flags & CISTPL_IO_16BIT)) + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; + link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; + link->io.BasePort1 = io->win[0].base; + link->io.NumPorts1 = io->win[0].len; + if (io->nwin > 1) { + link->io.Attributes2 = link->io.Attributes1; + link->io.BasePort2 = io->win[1].base; + link->io.NumPorts2 = io->win[1].len; + } + } - /* This reserves IO space but doesn't actually enable it */ - if(pcmcia_request_io(link, &link->io)) goto next_entry; + /* This reserves IO space but doesn't actually enable it */ + if (pcmcia_request_io(link, &link->io)) + goto next_entry; - /* If we got this far, we're cool! */ - break; + /* If we got this far, we're cool! */ + break; -next_entry: - if((last_ret = pcmcia_get_next_tuple(link, &tuple))) - { - cs_error(link, GetNextTuple, last_ret); - goto cs_failed; + next_entry: + if ((last_ret = pcmcia_get_next_tuple(link, &tuple))) { + cs_error(link, GetNextTuple, last_ret); + goto cs_failed; + } } - } - - /* - Allocate an interrupt line. Note that this does not assign a - handler to the interrupt, unless the 'Handler' member of the - irq structure is initialized. - */ - if (link->conf.Attributes & CONF_ENABLE_IRQ) - if((last_ret = pcmcia_request_irq(link, &link->irq))) - { + + /* + Allocate an interrupt line. Note that this does not assign a + handler to the interrupt, unless the 'Handler' member of the + irq structure is initialized. + */ + if (link->conf.Attributes & CONF_ENABLE_IRQ) + if ((last_ret = pcmcia_request_irq(link, &link->irq))) { cs_error(link, RequestIRQ, last_ret); goto cs_failed; } - /* - This actually configures the PCMCIA socket -- setting up - the I/O windows and the interrupt mapping, and putting the - card and host interface into "Memory and IO" mode. - */ - if((last_ret = pcmcia_request_configuration(link, &link->conf))) - { + /* + This actually configures the PCMCIA socket -- setting up + the I/O windows and the interrupt mapping, and putting the + card and host interface into "Memory and IO" mode. + */ + if ((last_ret = pcmcia_request_configuration(link, &link->conf))) { cs_error(link, RequestConfiguration, last_ret); goto cs_failed; } - /* - At this point, the dev_node_t structure(s) need to be - initialized and arranged in a linked list at link->dev. - */ - /* Comedi's PCMCIA script uses this device name (extracted - * from /var/lib/pcmcia/stab) to pass to comedi_config - */ - /* sprintf(dev->node.dev_name, "daqp%d", dev->table_index); */ - sprintf(dev->node.dev_name, "quatech_daqp_cs"); - dev->node.major = dev->node.minor = 0; - link->dev_node = &dev->node; - - /* Finally, report what we've done */ - printk(KERN_INFO "%s: index 0x%02x", - dev->node.dev_name, link->conf.ConfigIndex); - if (link->conf.Attributes & CONF_ENABLE_IRQ) + /* + At this point, the dev_node_t structure(s) need to be + initialized and arranged in a linked list at link->dev. + */ + /* Comedi's PCMCIA script uses this device name (extracted + * from /var/lib/pcmcia/stab) to pass to comedi_config + */ + /* sprintf(dev->node.dev_name, "daqp%d", dev->table_index); */ + sprintf(dev->node.dev_name, "quatech_daqp_cs"); + dev->node.major = dev->node.minor = 0; + link->dev_node = &dev->node; + + /* Finally, report what we've done */ + printk(KERN_INFO "%s: index 0x%02x", + dev->node.dev_name, link->conf.ConfigIndex); + if (link->conf.Attributes & CONF_ENABLE_IRQ) printk(", irq %u", link->irq.AssignedIRQ); - if (link->io.NumPorts1) + if (link->io.NumPorts1) printk(", io 0x%04x-0x%04x", link->io.BasePort1, - link->io.BasePort1+link->io.NumPorts1-1); - if (link->io.NumPorts2) + link->io.BasePort1 + link->io.NumPorts1 - 1); + if (link->io.NumPorts2) printk(" & 0x%04x-0x%04x", link->io.BasePort2, - link->io.BasePort2+link->io.NumPorts2-1); - printk("\n"); + link->io.BasePort2 + link->io.NumPorts2 - 1); + printk("\n"); - return; + return; -cs_failed: - daqp_cs_release(link); + cs_failed: + daqp_cs_release(link); -} /* daqp_cs_config */ +} /* daqp_cs_config */ static void daqp_cs_release(struct pcmcia_device *link) { - DEBUG(0, "daqp_cs_release(0x%p)\n", link); + DEBUG(0, "daqp_cs_release(0x%p)\n", link); pcmcia_disable_device(link); -} /* daqp_cs_release */ +} /* daqp_cs_release */ /*====================================================================== @@ -1298,35 +1306,34 @@ static void daqp_cs_release(struct pcmcia_device *link) static int daqp_cs_suspend(struct pcmcia_device *link) { - local_info_t *local = link->priv; + local_info_t *local = link->priv; - /* Mark the device as stopped, to block IO until later */ - local->stop = 1; - return 0; + /* Mark the device as stopped, to block IO until later */ + local->stop = 1; + return 0; } static int daqp_cs_resume(struct pcmcia_device *link) { - local_info_t *local = link->priv; + local_info_t *local = link->priv; - local->stop = 0; + local->stop = 0; - return 0; + return 0; } /*====================================================================*/ #ifdef MODULE -static struct pcmcia_device_id daqp_cs_id_table[] = -{ +static struct pcmcia_device_id daqp_cs_id_table[] = { PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027), PCMCIA_DEVICE_NULL }; + MODULE_DEVICE_TABLE(pcmcia, daqp_cs_id_table); -struct pcmcia_driver daqp_cs_driver = -{ +struct pcmcia_driver daqp_cs_driver = { .probe = daqp_cs_attach, .remove = daqp_cs_detach, .suspend = daqp_cs_suspend, @@ -1334,22 +1341,22 @@ struct pcmcia_driver daqp_cs_driver = .id_table = daqp_cs_id_table, .owner = THIS_MODULE, .drv = { - .name = dev_info, - }, + .name = dev_info, + }, }; int __init init_module(void) { - DEBUG(0, "%s\n", version); + DEBUG(0, "%s\n", version); pcmcia_register_driver(&daqp_cs_driver); - comedi_driver_register(&driver_daqp); - return 0; + comedi_driver_register(&driver_daqp); + return 0; } void __exit cleanup_module(void) { - DEBUG(0, "daqp_cs: unloading\n"); - comedi_driver_unregister(&driver_daqp); + DEBUG(0, "daqp_cs: unloading\n"); + comedi_driver_unregister(&driver_daqp); pcmcia_unregister_driver(&daqp_cs_driver); } diff --git a/comedi/drivers/rtd520.c b/comedi/drivers/rtd520.c index 1684fe6e..727fff5f 100644 --- a/comedi/drivers/rtd520.c +++ b/comedi/drivers/rtd520.c @@ -106,8 +106,6 @@ Configuration options: #include "comedi_pci.h" - - /*====================================================================== Driver specific stuff (tunable) ======================================================================*/ @@ -116,7 +114,7 @@ Configuration options: /* We really only need 2 buffers. More than that means being much smarter about knowing which ones are full. */ -#define DMA_CHAIN_COUNT 2 /* max DMA segments/buffers in a ring (min 2)*/ +#define DMA_CHAIN_COUNT 2 /* max DMA segments/buffers in a ring (min 2) */ /* Target period for periodic transfers. This sets the user read latency. */ /* Note: There are certain rates where we give this up and transfer 1/2 FIFO */ @@ -129,16 +127,16 @@ Configuration options: /* tuning for ai/ao instruction done polling */ #ifdef FAST_SPIN -#define WAIT_QUIETLY /* as nothing, spin on done bit */ -#define RTD_ADC_TIMEOUT 66000 /* 2 msec at 33mhz bus rate */ +#define WAIT_QUIETLY /* as nothing, spin on done bit */ +#define RTD_ADC_TIMEOUT 66000 /* 2 msec at 33mhz bus rate */ #define RTD_DAC_TIMEOUT 66000 -#define RTD_DMA_TIMEOUT 33000 /* 1 msec */ +#define RTD_DMA_TIMEOUT 33000 /* 1 msec */ #else /* by delaying, power and electrical noise are reduced somewhat */ #define WAIT_QUIETLY comedi_udelay (1) -#define RTD_ADC_TIMEOUT 2000 /* in usec */ -#define RTD_DAC_TIMEOUT 2000 /* in usec */ -#define RTD_DMA_TIMEOUT 1000 /* in usec */ +#define RTD_ADC_TIMEOUT 2000 /* in usec */ +#define RTD_DAC_TIMEOUT 2000 /* in usec */ +#define RTD_DMA_TIMEOUT 1000 /* in usec */ #endif /*====================================================================== @@ -153,24 +151,23 @@ Configuration options: */ #define LCFG_PCIINDEX 0 /* PCI region 1 is a 256 byte IO space mapping. Use??? */ -#define LAS0_PCIINDEX 2 /* PCI memory resources */ +#define LAS0_PCIINDEX 2 /* PCI memory resources */ #define LAS1_PCIINDEX 3 #define LCFG_PCISIZE 0x100 #define LAS0_PCISIZE 0x200 #define LAS1_PCISIZE 0x10 -#define RTD_CLOCK_RATE 8000000 /* 8Mhz onboard clock */ -#define RTD_CLOCK_BASE 125 /* clock period in ns */ +#define RTD_CLOCK_RATE 8000000 /* 8Mhz onboard clock */ +#define RTD_CLOCK_BASE 125 /* clock period in ns */ /* Note: these speed are slower than the spec, but fit the counter resolution*/ -#define RTD_MAX_SPEED 1625 /* when sampling, in nanoseconds */ +#define RTD_MAX_SPEED 1625 /* when sampling, in nanoseconds */ /* max speed if we don't have to wait for settling */ -#define RTD_MAX_SPEED_1 875 /* if single channel, in nanoseconds */ +#define RTD_MAX_SPEED_1 875 /* if single channel, in nanoseconds */ #define RTD_MIN_SPEED 2097151875 /* (24bit counter) in nanoseconds */ /* min speed when only 1 channel (no burst counter) */ -#define RTD_MIN_SPEED_1 5000000 /* 200Hz, in nanoseconds */ - +#define RTD_MIN_SPEED_1 5000000 /* 200Hz, in nanoseconds */ #include "rtd520.h" #include "plx9080.h" @@ -198,131 +195,135 @@ Configuration options: The board has 3 input modes and the gains of 1,2,4,...32 (, 64, 128) */ static const comedi_lrange rtd_ai_7520_range = { 18, { - /* +-5V input range gain steps */ - BIP_RANGE(5.0), - BIP_RANGE(5.0/2), - BIP_RANGE(5.0/4), - BIP_RANGE(5.0/8), - BIP_RANGE(5.0/16), - BIP_RANGE(5.0/32), - /* +-10V input range gain steps */ - BIP_RANGE(10.0), - BIP_RANGE(10.0/2), - BIP_RANGE(10.0/4), - BIP_RANGE(10.0/8), - BIP_RANGE(10.0/16), - BIP_RANGE(10.0/32), - /* +10V input range gain steps */ - UNI_RANGE(10.0), - UNI_RANGE(10.0/2), - UNI_RANGE(10.0/4), - UNI_RANGE(10.0/8), - UNI_RANGE(10.0/16), - UNI_RANGE(10.0/32), - -}}; + /* +-5V input range gain steps */ + BIP_RANGE(5.0), + BIP_RANGE(5.0 / 2), + BIP_RANGE(5.0 / 4), + BIP_RANGE(5.0 / 8), + BIP_RANGE(5.0 / 16), + BIP_RANGE(5.0 / 32), + /* +-10V input range gain steps */ + BIP_RANGE(10.0), + BIP_RANGE(10.0 / 2), + BIP_RANGE(10.0 / 4), + BIP_RANGE(10.0 / 8), + BIP_RANGE(10.0 / 16), + BIP_RANGE(10.0 / 32), + /* +10V input range gain steps */ + UNI_RANGE(10.0), + UNI_RANGE(10.0 / 2), + UNI_RANGE(10.0 / 4), + UNI_RANGE(10.0 / 8), + UNI_RANGE(10.0 / 16), + UNI_RANGE(10.0 / 32), + + } +}; /* PCI4520 has two more gains (6 more entries) */ static const comedi_lrange rtd_ai_4520_range = { 24, { - /* +-5V input range gain steps */ - BIP_RANGE(5.0), - BIP_RANGE(5.0/2), - BIP_RANGE(5.0/4), - BIP_RANGE(5.0/8), - BIP_RANGE(5.0/16), - BIP_RANGE(5.0/32), - BIP_RANGE(5.0/64), - BIP_RANGE(5.0/128), - /* +-10V input range gain steps */ - BIP_RANGE(10.0), - BIP_RANGE(10.0/2), - BIP_RANGE(10.0/4), - BIP_RANGE(10.0/8), - BIP_RANGE(10.0/16), - BIP_RANGE(10.0/32), - BIP_RANGE(10.0/64), - BIP_RANGE(10.0/128), - /* +10V input range gain steps */ - UNI_RANGE(10.0), - UNI_RANGE(10.0/2), - UNI_RANGE(10.0/4), - UNI_RANGE(10.0/8), - UNI_RANGE(10.0/16), - UNI_RANGE(10.0/32), - UNI_RANGE(10.0/64), - UNI_RANGE(10.0/128), -}}; + /* +-5V input range gain steps */ + BIP_RANGE(5.0), + BIP_RANGE(5.0 / 2), + BIP_RANGE(5.0 / 4), + BIP_RANGE(5.0 / 8), + BIP_RANGE(5.0 / 16), + BIP_RANGE(5.0 / 32), + BIP_RANGE(5.0 / 64), + BIP_RANGE(5.0 / 128), + /* +-10V input range gain steps */ + BIP_RANGE(10.0), + BIP_RANGE(10.0 / 2), + BIP_RANGE(10.0 / 4), + BIP_RANGE(10.0 / 8), + BIP_RANGE(10.0 / 16), + BIP_RANGE(10.0 / 32), + BIP_RANGE(10.0 / 64), + BIP_RANGE(10.0 / 128), + /* +10V input range gain steps */ + UNI_RANGE(10.0), + UNI_RANGE(10.0 / 2), + UNI_RANGE(10.0 / 4), + UNI_RANGE(10.0 / 8), + UNI_RANGE(10.0 / 16), + UNI_RANGE(10.0 / 32), + UNI_RANGE(10.0 / 64), + UNI_RANGE(10.0 / 128), + } +}; /* Table order matches range values */ static const comedi_lrange rtd_ao_range = { 4, { - RANGE(0, 5), - RANGE(0, 10), - RANGE(-5, 5), - RANGE(-10, 10), -}}; + RANGE(0, 5), + RANGE(0, 10), + RANGE(-5, 5), + RANGE(-10, 10), + } +}; /* Board descriptions */ -typedef struct rtdBoard_struct{ - const char *name; /* must be first */ - int device_id; - int aiChans; - int aiBits; - int aiMaxGain; - int fifoLen; - int range10Start; /* start of +-10V range */ - int rangeUniStart; /* start of +10V range */ +typedef struct rtdBoard_struct { + const char *name; /* must be first */ + int device_id; + int aiChans; + int aiBits; + int aiMaxGain; + int fifoLen; + int range10Start; /* start of +-10V range */ + int rangeUniStart; /* start of +10V range */ } rtdBoard; static const rtdBoard rtd520Boards[] = { - { - name: "DM7520", - device_id: 0x7520, - aiChans: 16, - aiBits: 12, - aiMaxGain: 32, - fifoLen: 1024, - range10Start: 6, - rangeUniStart: 12, - }, - { - name: "DM7520-8", - device_id: 0x7520, - aiChans: 16, - aiBits: 12, - aiMaxGain: 32, - fifoLen: 8192, - range10Start: 6, - rangeUniStart: 12, - }, - { - name: "PCI4520", - device_id: 0x4520, - aiChans: 16, - aiBits: 12, - aiMaxGain: 128, - fifoLen: 1024, - range10Start: 8, - rangeUniStart: 16, - }, - { - name: "PCI4520-8", - device_id: 0x4520, - aiChans: 16, - aiBits: 12, - aiMaxGain: 128, - fifoLen: 8192, - range10Start: 8, - rangeUniStart: 16, - }, + { + name: "DM7520", + device_id:0x7520, + aiChans: 16, + aiBits: 12, + aiMaxGain:32, + fifoLen: 1024, + range10Start:6, + rangeUniStart:12, + }, + { + name: "DM7520-8", + device_id:0x7520, + aiChans: 16, + aiBits: 12, + aiMaxGain:32, + fifoLen: 8192, + range10Start:6, + rangeUniStart:12, + }, + { + name: "PCI4520", + device_id:0x4520, + aiChans: 16, + aiBits: 12, + aiMaxGain:128, + fifoLen: 1024, + range10Start:8, + rangeUniStart:16, + }, + { + name: "PCI4520-8", + device_id:0x4520, + aiChans: 16, + aiBits: 12, + aiMaxGain:128, + fifoLen: 8192, + range10Start:8, + rangeUniStart:16, + }, }; static struct pci_device_id rtd520_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_RTD, 0x7520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_RTD, 0x4520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_RTD, 0x7520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_RTD, 0x4520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, rtd520_pci_table); /* @@ -334,55 +335,55 @@ MODULE_DEVICE_TABLE(pci, rtd520_pci_table); This structure is for data unique to this hardware driver. This is also unique for each board in the system. */ -typedef struct{ - /* memory mapped board structures */ - void *las0; - void *las1; - void *lcfg; - - unsigned long intCount; /* interrupt count */ - long aiCount; /* total transfer size (samples) */ - int transCount; /* # to tranfer data. 0->1/2FIFO*/ - int flags; /* flag event modes */ - - /* PCI device info */ - struct pci_dev *pci_dev; - int got_regions; /* non-zero if PCI regions owned */ - - /* channel list info */ - /* chanBipolar tracks whether a channel is bipolar (and needs +2048) */ - unsigned char chanBipolar[RTD_MAX_CHANLIST/8]; /* bit array */ - - /* read back data */ - lsampl_t aoValue[2]; /* Used for AO read back */ - - /* timer gate (when enabled) */ - u8 utcGate[4]; /* 1 extra allows simple range check */ - - /* shadow registers affect other registers, but cant be read back */ - /* The macros below update these on writes */ - u16 intMask; /* interrupt mask */ - u16 intClearMask; /* interrupt clear mask */ - u8 utcCtrl[4]; /* crtl mode for 3 utc + read back */ - u8 dioStatus; /* could be read back (dio0Ctrl) */ +typedef struct { + /* memory mapped board structures */ + void *las0; + void *las1; + void *lcfg; + + unsigned long intCount; /* interrupt count */ + long aiCount; /* total transfer size (samples) */ + int transCount; /* # to tranfer data. 0->1/2FIFO */ + int flags; /* flag event modes */ + + /* PCI device info */ + struct pci_dev *pci_dev; + int got_regions; /* non-zero if PCI regions owned */ + + /* channel list info */ + /* chanBipolar tracks whether a channel is bipolar (and needs +2048) */ + unsigned char chanBipolar[RTD_MAX_CHANLIST / 8]; /* bit array */ + + /* read back data */ + lsampl_t aoValue[2]; /* Used for AO read back */ + + /* timer gate (when enabled) */ + u8 utcGate[4]; /* 1 extra allows simple range check */ + + /* shadow registers affect other registers, but cant be read back */ + /* The macros below update these on writes */ + u16 intMask; /* interrupt mask */ + u16 intClearMask; /* interrupt clear mask */ + u8 utcCtrl[4]; /* crtl mode for 3 utc + read back */ + u8 dioStatus; /* could be read back (dio0Ctrl) */ #ifdef USE_DMA - /* Always DMA 1/2 FIFO. Buffer (dmaBuff?) is (at least) twice that size. - After transferring, interrupt processes 1/2 FIFO and passes to comedi */ - s16 dma0Offset; /* current processing offset (0, 1/2)*/ - uint16_t *dma0Buff[DMA_CHAIN_COUNT]; /* DMA buffers (for ADC) */ - dma_addr_t dma0BuffPhysAddr[DMA_CHAIN_COUNT]; /* physical addresses */ - struct plx_dma_desc *dma0Chain; /* DMA descriptor ring for dmaBuff*/ - dma_addr_t dma0ChainPhysAddr; /* physical addresses */ - /* shadow registers */ - u8 dma0Control; - u8 dma1Control; -#endif /* USE_DMA */ + /* Always DMA 1/2 FIFO. Buffer (dmaBuff?) is (at least) twice that size. + After transferring, interrupt processes 1/2 FIFO and passes to comedi */ + s16 dma0Offset; /* current processing offset (0, 1/2) */ + uint16_t *dma0Buff[DMA_CHAIN_COUNT]; /* DMA buffers (for ADC) */ + dma_addr_t dma0BuffPhysAddr[DMA_CHAIN_COUNT]; /* physical addresses */ + struct plx_dma_desc *dma0Chain; /* DMA descriptor ring for dmaBuff */ + dma_addr_t dma0ChainPhysAddr; /* physical addresses */ + /* shadow registers */ + u8 dma0Control; + u8 dma1Control; +#endif /* USE_DMA */ } rtdPrivate; /* bit defines for "flags" */ -#define SEND_EOS 0x01 /* send End Of Scan events */ -#define DMA0_ACTIVE 0x02 /* DMA0 is active */ -#define DMA1_ACTIVE 0x04 /* DMA1 is active */ +#define SEND_EOS 0x01 /* send End Of Scan events */ +#define DMA0_ACTIVE 0x02 /* DMA0 is active */ +#define DMA1_ACTIVE 0x04 /* DMA1 is active */ /* Macros for accessing channel list bit array */ #define CHAN_ARRAY_TEST(array,index) \ @@ -398,7 +399,6 @@ typedef struct{ */ #define devpriv ((rtdPrivate *)dev->private) - /* Macros to access registers */ /* Reset board */ @@ -542,7 +542,6 @@ typedef struct{ #define RtdAdcSampleCounter(dev,v) \ writel ((v) & 0x3ff, devpriv->las0+LAS0_ADC_SCNT) - /* User Timer/Counter (8254) */ #define RtdUtcCounterGet(dev,n) \ readb (devpriv->las0 \ @@ -569,12 +568,10 @@ typedef struct{ + ((n <= 0) ? LAS0_UTC0_GATE : \ ((1 == n) ? LAS0_UTC1_GATE : LAS0_UTC2_GATE))) - /* User output N source select (write only) */ #define RtdUsrOutSource(dev,n,v) \ writel (v,devpriv->las0+((n <= 0) ? LAS0_UOUT0_SELECT : LAS0_UOUT1_SELECT)) - /* Digital IO */ #define RtdDio0Read(dev) \ (readw (devpriv->las0+LAS0_DIO0) & 0xff) @@ -596,7 +593,6 @@ typedef struct{ #define RtdDio0CtrlWrite(dev,v) \ writew ((v) & 0xff, devpriv->las0+LAS0_DIO0_CTRL) - /* Digital to Analog converter */ /* Write one data value (sign + 12bit + marker bits) */ /* Note: matches what DMA would put. Actual value << 3 */ @@ -636,7 +632,6 @@ typedef struct{ #define RtdDma1Reset(dev) \ writel (0, devpriv->las0+LAS0_DMA1_SRC) - /* PLX9080 interrupt mask and status */ #define RtdPlxInterruptRead(dev) \ readl (devpriv->lcfg+LCFG_ITCSR) @@ -705,37 +700,36 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int rtd_attach (comedi_device *dev, comedi_devconfig *it); -static int rtd_detach (comedi_device *dev); - -static comedi_driver rtd520Driver={ - driver_name: "rtd520", - module: THIS_MODULE, - attach: rtd_attach, - detach: rtd_detach, - board_name: &rtd520Boards[0].name, - offset: sizeof(rtdBoard), - num_names: sizeof(rtd520Boards) / sizeof(rtdBoard), +static int rtd_attach(comedi_device * dev, comedi_devconfig * it); +static int rtd_detach(comedi_device * dev); + +static comedi_driver rtd520Driver = { + driver_name:"rtd520", + module:THIS_MODULE, + attach:rtd_attach, + detach:rtd_detach, + board_name:&rtd520Boards[0].name, + offset:sizeof(rtdBoard), + num_names:sizeof(rtd520Boards) / sizeof(rtdBoard), }; -static int rtd_ai_rinsn (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int rtd_ao_winsn (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int rtd_ao_rinsn (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int rtd_dio_insn_bits (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int rtd_dio_insn_config (comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int rtd_ai_cmdtest (comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int rtd_ai_cmd ( comedi_device *dev, comedi_subdevice *s); -static int rtd_ai_cancel ( comedi_device *dev, comedi_subdevice *s); +static int rtd_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int rtd_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int rtd_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int rtd_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int rtd_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int rtd_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int rtd_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int rtd_ai_cancel(comedi_device * dev, comedi_subdevice * s); //static int rtd_ai_poll (comedi_device *dev,comedi_subdevice *s); -static int rtd_ns_to_timer (unsigned int *ns, int roundMode); -static irqreturn_t rtd_interrupt ( int irq, void *d PT_REGS_ARG); - +static int rtd_ns_to_timer(unsigned int *ns, int roundMode); +static irqreturn_t rtd_interrupt(int irq, void *d PT_REGS_ARG); /* * Attach is called by the Comedi core to configure the driver @@ -743,331 +737,333 @@ static irqreturn_t rtd_interrupt ( int irq, void *d PT_REGS_ARG); * in the driver structure, dev->board_ptr contains that * address. */ -static int rtd_attach ( - comedi_device *dev, - comedi_devconfig *it) /* board name and options flags */ -{ - comedi_subdevice *s; - struct pci_dev* pcidev; - int ret; - resource_size_t physLas0; /* configuation */ - resource_size_t physLas1; /* data area */ - resource_size_t physLcfg; /* PLX9080 */ +static int rtd_attach(comedi_device * dev, comedi_devconfig * it) +{ /* board name and options flags */ + comedi_subdevice *s; + struct pci_dev *pcidev; + int ret; + resource_size_t physLas0; /* configuation */ + resource_size_t physLas1; /* data area */ + resource_size_t physLcfg; /* PLX9080 */ #ifdef USE_DMA - int index; + int index; #endif - printk ("comedi%d: rtd520 attaching.\n", dev->minor); + printk("comedi%d: rtd520 attaching.\n", dev->minor); #if defined (CONFIG_COMEDI_DEBUG) && defined (USE_DMA) - /* You can set this a load time: modprobe comedi comedi_debug=1 */ - if (0 == comedi_debug) /* force DMA debug printks */ - comedi_debug = 1; + /* You can set this a load time: modprobe comedi comedi_debug=1 */ + if (0 == comedi_debug) /* force DMA debug printks */ + comedi_debug = 1; #endif - /* - * Allocate the private structure area. alloc_private() is a - * convenient macro defined in comedidev.h. - */ - if (alloc_private (dev, sizeof(rtdPrivate))<0) - return -ENOMEM; - - /* - * Probe the device to determine what device in the series it is. - */ - for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ; + /* + * Allocate the private structure area. alloc_private() is a + * convenient macro defined in comedidev.h. + */ + if (alloc_private(dev, sizeof(rtdPrivate)) < 0) + return -ENOMEM; + + /* + * Probe the device to determine what device in the series it is. + */ + for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); + pcidev != NULL; pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { if (pcidev->vendor == PCI_VENDOR_ID_RTD) { if (it->options[0] || it->options[1]) { if (pcidev->bus->number != it->options[0] - || PCI_SLOT(pcidev->devfn) != it->options[1]) { + || PCI_SLOT(pcidev->devfn) != + it->options[1]) { continue; } } - break; /* found one */ + break; /* found one */ } } - if (!pcidev) { + if (!pcidev) { if (it->options[0] && it->options[1]) { - printk ("No RTD card at bus=%d slot=%d.\n", + printk("No RTD card at bus=%d slot=%d.\n", it->options[0], it->options[1]); } else { - printk ("No RTD card found.\n"); + printk("No RTD card found.\n"); } return -EIO; } devpriv->pci_dev = pcidev; if (pcidev->device != thisboard->device_id) { - printk ("Found an RTD card, but not the supported type (%x).\n", + printk("Found an RTD card, but not the supported type (%x).\n", pcidev->device); return -EIO; } - dev->board_name = thisboard->name; + dev->board_name = thisboard->name; - if((ret=comedi_pci_enable(pcidev, "rtd520"))<0){ + if ((ret = comedi_pci_enable(pcidev, "rtd520")) < 0) { printk("Failed to enable PCI device and request regions.\n"); return ret; } devpriv->got_regions = 1; - /* - * Initialize base addresses - */ - /* Get the physical address from PCI config */ + /* + * Initialize base addresses + */ + /* Get the physical address from PCI config */ physLas0 = pci_resource_start(devpriv->pci_dev, LAS0_PCIINDEX); physLas1 = pci_resource_start(devpriv->pci_dev, LAS1_PCIINDEX); physLcfg = pci_resource_start(devpriv->pci_dev, LCFG_PCIINDEX); - /* Now have the kernel map this into memory */ - /* ASSUME page aligned */ - devpriv->las0 = ioremap_nocache(physLas0, LAS0_PCISIZE); - devpriv->las1 = ioremap_nocache(physLas1, LAS1_PCISIZE); - devpriv->lcfg = ioremap_nocache(physLcfg, LCFG_PCISIZE); - - if(!devpriv->las0 || !devpriv->las1 || !devpriv->lcfg){ - return -ENOMEM; - } - - DPRINTK ("%s: LAS0=%llx, LAS1=%llx, CFG=%llx.\n", dev->board_name, - (unsigned long long)physLas0, (unsigned long long)physLas1, - (unsigned long long)physLcfg); - { /* The RTD driver does this */ - unsigned char pci_latency; - u16 revision; - /*uint32_t epld_version;*/ - - pci_read_config_word(devpriv->pci_dev, PCI_REVISION_ID, &revision); - DPRINTK("%s: PCI revision %d.\n", dev->board_name, revision); - - pci_read_config_byte(devpriv->pci_dev, - PCI_LATENCY_TIMER, &pci_latency); - if (pci_latency < 32) { - printk ("%s: PCI latency changed from %d to %d\n", dev->board_name, - pci_latency, 32); - pci_write_config_byte(devpriv->pci_dev, PCI_LATENCY_TIMER, 32); - } else { - DPRINTK ("rtd520: PCI latency = %d\n", pci_latency); + /* Now have the kernel map this into memory */ + /* ASSUME page aligned */ + devpriv->las0 = ioremap_nocache(physLas0, LAS0_PCISIZE); + devpriv->las1 = ioremap_nocache(physLas1, LAS1_PCISIZE); + devpriv->lcfg = ioremap_nocache(physLcfg, LCFG_PCISIZE); + + if (!devpriv->las0 || !devpriv->las1 || !devpriv->lcfg) { + return -ENOMEM; + } + + DPRINTK("%s: LAS0=%llx, LAS1=%llx, CFG=%llx.\n", dev->board_name, + (unsigned long long)physLas0, (unsigned long long)physLas1, + (unsigned long long)physLcfg); + { /* The RTD driver does this */ + unsigned char pci_latency; + u16 revision; + /*uint32_t epld_version; */ + + pci_read_config_word(devpriv->pci_dev, PCI_REVISION_ID, + &revision); + DPRINTK("%s: PCI revision %d.\n", dev->board_name, revision); + + pci_read_config_byte(devpriv->pci_dev, + PCI_LATENCY_TIMER, &pci_latency); + if (pci_latency < 32) { + printk("%s: PCI latency changed from %d to %d\n", + dev->board_name, pci_latency, 32); + pci_write_config_byte(devpriv->pci_dev, + PCI_LATENCY_TIMER, 32); + } else { + DPRINTK("rtd520: PCI latency = %d\n", pci_latency); + } + + /* Undocumented EPLD version (doesnt match RTD driver results) */ + /*DPRINTK ("rtd520: Reading epld from %p\n", + devpriv->las0+0); + epld_version = readl (devpriv->las0+0); + if ((epld_version & 0xF0) >> 4 == 0x0F) { + DPRINTK("rtd520: pre-v8 EPLD. (%x)\n", epld_version); + } else { + DPRINTK("rtd520: EPLD version %x.\n", epld_version >> 4); + } */ + } + + /* Show board configuration */ + /* It is critical that the FIFO length matches the board. Otherwise, + data transfers and DMA will either read 0s or overwrite memory! + It is possible to probe for FIFO size. */ + printk("%s: ( fifoLen=%d )", dev->board_name, thisboard->fifoLen); + + /* + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. + */ + if (alloc_subdevices(dev, 4) < 0) { + return -ENOMEM; } - /* Undocumented EPLD version (doesnt match RTD driver results) */ - /*DPRINTK ("rtd520: Reading epld from %p\n", - devpriv->las0+0); - epld_version = readl (devpriv->las0+0); - if ((epld_version & 0xF0) >> 4 == 0x0F) { - DPRINTK("rtd520: pre-v8 EPLD. (%x)\n", epld_version); + s = dev->subdevices + 0; + dev->read_subdev = s; + /* analog input subdevice */ + s->type = COMEDI_SUBD_AI; + s->subdev_flags = + SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF | + SDF_CMD_READ; + s->n_chan = thisboard->aiChans; + s->maxdata = (1 << thisboard->aiBits) - 1; + if (thisboard->aiMaxGain <= 32) { + s->range_table = &rtd_ai_7520_range; } else { - DPRINTK("rtd520: EPLD version %x.\n", epld_version >> 4); - }*/ - } - - /* Show board configuration */ - /* It is critical that the FIFO length matches the board. Otherwise, - data transfers and DMA will either read 0s or overwrite memory! - It is possible to probe for FIFO size. */ - printk ("%s: ( fifoLen=%d )" , dev->board_name, thisboard->fifoLen); - - /* - * Allocate the subdevice structures. alloc_subdevice() is a - * convenient macro defined in comedidev.h. - */ - if (alloc_subdevices(dev, 4)<0) { - return -ENOMEM; - } - - s=dev->subdevices+0; - dev->read_subdev=s; - /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF | SDF_CMD_READ; - s->n_chan=thisboard->aiChans; - s->maxdata=(1<aiBits)-1; - if (thisboard->aiMaxGain <= 32) { - s->range_table = &rtd_ai_7520_range; - } else { - s->range_table = &rtd_ai_4520_range; - } - s->len_chanlist = RTD_MAX_CHANLIST; /* thisboard->fifoLen */ - s->insn_read = rtd_ai_rinsn; - s->do_cmd = rtd_ai_cmd; - s->do_cmdtest = rtd_ai_cmdtest; - s->cancel = rtd_ai_cancel; - /*s->poll = rtd_ai_poll;*/ /* not ready yet */ - - s=dev->subdevices+1; - /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan = 2; - s->maxdata =(1<aiBits)-1; - s->range_table = &rtd_ao_range; - s->insn_write = rtd_ao_winsn; - s->insn_read = rtd_ao_rinsn; - - s=dev->subdevices+2; - /* digital i/o subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - /* we only support port 0 right now. Ignoring port 1 and user IO */ - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; - s->insn_bits = rtd_dio_insn_bits; - s->insn_config = rtd_dio_insn_config; - - /* timer/counter subdevices (not currently supported) */ - s=dev->subdevices+3; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=3; - s->maxdata=0xffff; - - /* initialize board, per RTD spec */ - /* also, initialize shadow registers */ - RtdResetBoard (dev); - comedi_udelay (100); /* needed? */ - RtdPlxInterruptWrite (dev, 0); - RtdInterruptMask (dev,0); /* and sets shadow */ - RtdInterruptClearMask (dev,~0); /* and sets shadow */ - RtdInterruptClear(dev); /* clears bits set by mask */ - RtdInterruptOverrunClear(dev); - RtdClearCGT (dev); - RtdAdcClearFifo (dev); - RtdDacClearFifo (dev,0); - RtdDacClearFifo (dev,1); - /* clear digital IO fifo*/ - RtdDioStatusWrite (dev, 0); /* safe state, set shadow */ - RtdUtcCtrlPut (dev, 0, 0x30); /* safe state, set shadow */ - RtdUtcCtrlPut (dev, 1, 0x30); /* safe state, set shadow */ - RtdUtcCtrlPut (dev, 2, 0x30); /* safe state, set shadow */ - RtdUtcCtrlPut (dev, 3, 0); /* safe state, set shadow */ - /* TODO: set user out source ??? */ + s->range_table = &rtd_ai_4520_range; + } + s->len_chanlist = RTD_MAX_CHANLIST; /* thisboard->fifoLen */ + s->insn_read = rtd_ai_rinsn; + s->do_cmd = rtd_ai_cmd; + s->do_cmdtest = rtd_ai_cmdtest; + s->cancel = rtd_ai_cancel; + /*s->poll = rtd_ai_poll; *//* not ready yet */ + + s = dev->subdevices + 1; + /* analog output subdevice */ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->maxdata = (1 << thisboard->aiBits) - 1; + s->range_table = &rtd_ao_range; + s->insn_write = rtd_ao_winsn; + s->insn_read = rtd_ao_rinsn; + + s = dev->subdevices + 2; + /* digital i/o subdevice */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + /* we only support port 0 right now. Ignoring port 1 and user IO */ + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = rtd_dio_insn_bits; + s->insn_config = rtd_dio_insn_config; + + /* timer/counter subdevices (not currently supported) */ + s = dev->subdevices + 3; + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 3; + s->maxdata = 0xffff; + + /* initialize board, per RTD spec */ + /* also, initialize shadow registers */ + RtdResetBoard(dev); + comedi_udelay(100); /* needed? */ + RtdPlxInterruptWrite(dev, 0); + RtdInterruptMask(dev, 0); /* and sets shadow */ + RtdInterruptClearMask(dev, ~0); /* and sets shadow */ + RtdInterruptClear(dev); /* clears bits set by mask */ + RtdInterruptOverrunClear(dev); + RtdClearCGT(dev); + RtdAdcClearFifo(dev); + RtdDacClearFifo(dev, 0); + RtdDacClearFifo(dev, 1); + /* clear digital IO fifo */ + RtdDioStatusWrite(dev, 0); /* safe state, set shadow */ + RtdUtcCtrlPut(dev, 0, 0x30); /* safe state, set shadow */ + RtdUtcCtrlPut(dev, 1, 0x30); /* safe state, set shadow */ + RtdUtcCtrlPut(dev, 2, 0x30); /* safe state, set shadow */ + RtdUtcCtrlPut(dev, 3, 0); /* safe state, set shadow */ + /* TODO: set user out source ??? */ /* check if our interrupt is available and get it */ - if((ret=comedi_request_irq (devpriv->pci_dev->irq, rtd_interrupt, - IRQF_SHARED, "rtd520", dev)) < 0) { - printk("Could not get interrupt! (%u)\n", devpriv->pci_dev->irq); + if ((ret = comedi_request_irq(devpriv->pci_dev->irq, rtd_interrupt, + IRQF_SHARED, "rtd520", dev)) < 0) { + printk("Could not get interrupt! (%u)\n", + devpriv->pci_dev->irq); return ret; } dev->irq = devpriv->pci_dev->irq; printk("( irq=%u )", dev->irq); #ifdef USE_DMA - if (dev->irq > 0) { - printk("( DMA buff=%d )\n", DMA_CHAIN_COUNT); - /* The PLX9080 has 2 DMA controllers, but there could be 4 sources: - ADC, digital, DAC1, and DAC2. Since only the ADC supports cmd mode - right now, this isn't an issue (yet) */ - devpriv->dma0Offset = 0; - - for(index = 0; index < DMA_CHAIN_COUNT; index++) { - devpriv->dma0Buff[index] = - pci_alloc_consistent(devpriv->pci_dev, - sizeof (u16) * thisboard->fifoLen/2, - &devpriv->dma0BuffPhysAddr[index]); - if (devpriv->dma0Buff[index] == NULL) { - ret = -ENOMEM; - goto rtd_attach_die_error; - } - /*DPRINTK ("buff[%d] @ %p virtual, %x PCI\n", - index, - devpriv->dma0Buff[index], devpriv->dma0BuffPhysAddr[index]);*/ - } - - /* setup DMA descriptor ring (use cpu_to_le32 for byte ordering?) */ - devpriv->dma0Chain = - pci_alloc_consistent (devpriv->pci_dev, - sizeof(struct plx_dma_desc) * DMA_CHAIN_COUNT, - &devpriv->dma0ChainPhysAddr); - for (index = 0; index < DMA_CHAIN_COUNT; index++) { - devpriv->dma0Chain[index].pci_start_addr = - devpriv->dma0BuffPhysAddr[index]; - devpriv->dma0Chain[index].local_start_addr = - DMALADDR_ADC; - devpriv->dma0Chain[index].transfer_size = - sizeof (u16) * thisboard->fifoLen/2; - devpriv->dma0Chain[index].next = - (devpriv->dma0ChainPhysAddr + ((index + 1) % (DMA_CHAIN_COUNT)) - * sizeof(devpriv->dma0Chain[0])) - | DMA_TRANSFER_BITS; - /*DPRINTK ("ring[%d] @%lx PCI: %x, local: %x, N: 0x%x, next: %x\n", - index, - ((long)devpriv->dma0ChainPhysAddr - + (index * sizeof(devpriv->dma0Chain[0]))), - devpriv->dma0Chain[index].pci_start_addr, - devpriv->dma0Chain[index].local_start_addr, - devpriv->dma0Chain[index].transfer_size, - devpriv->dma0Chain[index].next);*/ - } - - if (devpriv->dma0Chain == NULL) { - ret = -ENOMEM; - goto rtd_attach_die_error; - } - - RtdDma0Mode (dev, DMA_MODE_BITS); - RtdDma0Source (dev, DMAS_ADFIFO_HALF_FULL); /* set DMA trigger source*/ - } else { - printk("( no IRQ->no DMA )\n"); - } + if (dev->irq > 0) { + printk("( DMA buff=%d )\n", DMA_CHAIN_COUNT); + /* The PLX9080 has 2 DMA controllers, but there could be 4 sources: + ADC, digital, DAC1, and DAC2. Since only the ADC supports cmd mode + right now, this isn't an issue (yet) */ + devpriv->dma0Offset = 0; + + for (index = 0; index < DMA_CHAIN_COUNT; index++) { + devpriv->dma0Buff[index] = + pci_alloc_consistent(devpriv->pci_dev, + sizeof(u16) * thisboard->fifoLen / 2, + &devpriv->dma0BuffPhysAddr[index]); + if (devpriv->dma0Buff[index] == NULL) { + ret = -ENOMEM; + goto rtd_attach_die_error; + } + /*DPRINTK ("buff[%d] @ %p virtual, %x PCI\n", + index, + devpriv->dma0Buff[index], devpriv->dma0BuffPhysAddr[index]); */ + } + + /* setup DMA descriptor ring (use cpu_to_le32 for byte ordering?) */ + devpriv->dma0Chain = + pci_alloc_consistent(devpriv->pci_dev, + sizeof(struct plx_dma_desc) * DMA_CHAIN_COUNT, + &devpriv->dma0ChainPhysAddr); + for (index = 0; index < DMA_CHAIN_COUNT; index++) { + devpriv->dma0Chain[index].pci_start_addr = + devpriv->dma0BuffPhysAddr[index]; + devpriv->dma0Chain[index].local_start_addr = + DMALADDR_ADC; + devpriv->dma0Chain[index].transfer_size = + sizeof(u16) * thisboard->fifoLen / 2; + devpriv->dma0Chain[index].next = + (devpriv->dma0ChainPhysAddr + ((index + + 1) % (DMA_CHAIN_COUNT)) + * sizeof(devpriv->dma0Chain[0])) + | DMA_TRANSFER_BITS; + /*DPRINTK ("ring[%d] @%lx PCI: %x, local: %x, N: 0x%x, next: %x\n", + index, + ((long)devpriv->dma0ChainPhysAddr + + (index * sizeof(devpriv->dma0Chain[0]))), + devpriv->dma0Chain[index].pci_start_addr, + devpriv->dma0Chain[index].local_start_addr, + devpriv->dma0Chain[index].transfer_size, + devpriv->dma0Chain[index].next); */ + } + + if (devpriv->dma0Chain == NULL) { + ret = -ENOMEM; + goto rtd_attach_die_error; + } + + RtdDma0Mode(dev, DMA_MODE_BITS); + RtdDma0Source(dev, DMAS_ADFIFO_HALF_FULL); /* set DMA trigger source */ + } else { + printk("( no IRQ->no DMA )\n"); + } #else /* USE_DMA */ - printk("\n"); /* end configuration line */ + printk("\n"); /* end configuration line */ #endif /* USE_DMA */ - if (dev->irq) { /* enable plx9080 interrupts */ - RtdPlxInterruptWrite (dev, ICS_PIE | ICS_PLIE); - } - + if (dev->irq) { /* enable plx9080 interrupts */ + RtdPlxInterruptWrite(dev, ICS_PIE | ICS_PLIE); + } - printk("comedi%d: rtd520 driver attached.\n", dev->minor); + printk("comedi%d: rtd520 driver attached.\n", dev->minor); - return 1; + return 1; #if 0 - /* hit an error, clean up memory and return ret */ + /* hit an error, clean up memory and return ret */ //rtd_attach_die_error: #ifdef USE_DMA - for(index = 0; index < DMA_CHAIN_COUNT; index++) { - if (NULL != devpriv->dma0Buff[index]) { /* free buffer memory*/ - pci_free_consistent (devpriv->pci_dev, - sizeof (u16) * thisboard->fifoLen/2, - devpriv->dma0Buff[index], - devpriv->dma0BuffPhysAddr[index]); - devpriv->dma0Buff[index] = NULL; - } - } - if (NULL != devpriv->dma0Chain) { - pci_free_consistent (devpriv->pci_dev, - sizeof(struct plx_dma_desc) - * DMA_CHAIN_COUNT, - devpriv->dma0Chain, - devpriv->dma0ChainPhysAddr); - devpriv->dma0Chain = NULL; - } + for (index = 0; index < DMA_CHAIN_COUNT; index++) { + if (NULL != devpriv->dma0Buff[index]) { /* free buffer memory */ + pci_free_consistent(devpriv->pci_dev, + sizeof(u16) * thisboard->fifoLen / 2, + devpriv->dma0Buff[index], + devpriv->dma0BuffPhysAddr[index]); + devpriv->dma0Buff[index] = NULL; + } + } + if (NULL != devpriv->dma0Chain) { + pci_free_consistent(devpriv->pci_dev, + sizeof(struct plx_dma_desc) + * DMA_CHAIN_COUNT, + devpriv->dma0Chain, devpriv->dma0ChainPhysAddr); + devpriv->dma0Chain = NULL; + } #endif /* USE_DMA */ - /* subdevices and priv are freed by the core */ - if (dev->irq) { - /* disable interrupt controller */ - RtdPlxInterruptWrite ( - dev, - RtdPlxInterruptRead (dev) - & ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E)); - comedi_free_irq (dev->irq, dev); - } - - /* release all regions that were allocated */ - if (devpriv->las0) { - iounmap (devpriv->las0); - } - if (devpriv->las1) { - iounmap (devpriv->las1); - } - if (devpriv->lcfg) { - iounmap (devpriv->lcfg); - } - if (devpriv->pci_dev) { - pci_dev_put(devpriv->pci_dev); - } - return ret; + /* subdevices and priv are freed by the core */ + if (dev->irq) { + /* disable interrupt controller */ + RtdPlxInterruptWrite(dev, RtdPlxInterruptRead(dev) + & ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E)); + comedi_free_irq(dev->irq, dev); + } + + /* release all regions that were allocated */ + if (devpriv->las0) { + iounmap(devpriv->las0); + } + if (devpriv->las1) { + iounmap(devpriv->las1); + } + if (devpriv->lcfg) { + iounmap(devpriv->lcfg); + } + if (devpriv->pci_dev) { + pci_dev_put(devpriv->pci_dev); + } + return ret; #endif } @@ -1079,163 +1075,151 @@ static int rtd_attach ( * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int rtd_detach ( - comedi_device *dev) +static int rtd_detach(comedi_device * dev) { #ifdef USE_DMA - int index; + int index; #endif - DPRINTK("comedi%d: rtd520: removing (%ld ints)\n", - dev->minor, (devpriv ? devpriv->intCount : 0L)); - if (devpriv && devpriv->lcfg) { - DPRINTK("(int status 0x%x, overrun status 0x%x, fifo status 0x%x)...\n", - 0xffff & RtdInterruptStatus (dev), - 0xffff & RtdInterruptOverrunStatus (dev), - (0xffff & RtdFifoStatus (dev)) ^ 0x6666); - } - - if (devpriv) { - /* Shut down any board ops by resetting it */ -#ifdef USE_DMA - if (devpriv->lcfg) { - RtdDma0Control (dev, 0); /* disable DMA */ - RtdDma1Control (dev, 0); /* disable DMA */ - RtdPlxInterruptWrite (dev, ICS_PIE | ICS_PLIE); - } -#endif /* USE_DMA */ - if (devpriv->las0) { - RtdResetBoard (dev); - RtdInterruptMask (dev, 0); - RtdInterruptClearMask (dev,~0); - RtdInterruptClear(dev); /* clears bits set by mask */ + DPRINTK("comedi%d: rtd520: removing (%ld ints)\n", + dev->minor, (devpriv ? devpriv->intCount : 0L)); + if (devpriv && devpriv->lcfg) { + DPRINTK("(int status 0x%x, overrun status 0x%x, fifo status 0x%x)...\n", 0xffff & RtdInterruptStatus(dev), 0xffff & RtdInterruptOverrunStatus(dev), (0xffff & RtdFifoStatus(dev)) ^ 0x6666); } + if (devpriv) { + /* Shut down any board ops by resetting it */ #ifdef USE_DMA - /* release DMA */ - for(index = 0; index < DMA_CHAIN_COUNT; index++) { - if (NULL != devpriv->dma0Buff[index]) { - pci_free_consistent (devpriv->pci_dev, - sizeof (u16) * thisboard->fifoLen/2, - devpriv->dma0Buff[index], - devpriv->dma0BuffPhysAddr[index]); - devpriv->dma0Buff[index] = NULL; - } - } - if (NULL != devpriv->dma0Chain) { - pci_free_consistent (devpriv->pci_dev, - sizeof(struct plx_dma_desc) * DMA_CHAIN_COUNT, - devpriv->dma0Chain, - devpriv->dma0ChainPhysAddr); - devpriv->dma0Chain = NULL; - } + if (devpriv->lcfg) { + RtdDma0Control(dev, 0); /* disable DMA */ + RtdDma1Control(dev, 0); /* disable DMA */ + RtdPlxInterruptWrite(dev, ICS_PIE | ICS_PLIE); + } +#endif /* USE_DMA */ + if (devpriv->las0) { + RtdResetBoard(dev); + RtdInterruptMask(dev, 0); + RtdInterruptClearMask(dev, ~0); + RtdInterruptClear(dev); /* clears bits set by mask */ + } +#ifdef USE_DMA + /* release DMA */ + for (index = 0; index < DMA_CHAIN_COUNT; index++) { + if (NULL != devpriv->dma0Buff[index]) { + pci_free_consistent(devpriv->pci_dev, + sizeof(u16) * thisboard->fifoLen / 2, + devpriv->dma0Buff[index], + devpriv->dma0BuffPhysAddr[index]); + devpriv->dma0Buff[index] = NULL; + } + } + if (NULL != devpriv->dma0Chain) { + pci_free_consistent(devpriv->pci_dev, + sizeof(struct plx_dma_desc) * DMA_CHAIN_COUNT, + devpriv->dma0Chain, devpriv->dma0ChainPhysAddr); + devpriv->dma0Chain = NULL; + } #endif /* USE_DMA */ - /* release IRQ */ - if (dev->irq) { - /* disable interrupt controller */ - RtdPlxInterruptWrite ( - dev, - RtdPlxInterruptRead (dev) - & ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E)); - comedi_free_irq (dev->irq, dev); - } + /* release IRQ */ + if (dev->irq) { + /* disable interrupt controller */ + RtdPlxInterruptWrite(dev, RtdPlxInterruptRead(dev) + & ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E)); + comedi_free_irq(dev->irq, dev); + } - /* release all regions that were allocated */ - if (devpriv->las0) { - iounmap (devpriv->las0); - } - if (devpriv->las1) { - iounmap (devpriv->las1); - } - if (devpriv->lcfg) { - iounmap (devpriv->lcfg); - } - if (devpriv->pci_dev) { - if(devpriv->got_regions) - { - comedi_pci_disable(devpriv->pci_dev); + /* release all regions that were allocated */ + if (devpriv->las0) { + iounmap(devpriv->las0); + } + if (devpriv->las1) { + iounmap(devpriv->las1); + } + if (devpriv->lcfg) { + iounmap(devpriv->lcfg); + } + if (devpriv->pci_dev) { + if (devpriv->got_regions) { + comedi_pci_disable(devpriv->pci_dev); + } + pci_dev_put(devpriv->pci_dev); } - pci_dev_put(devpriv->pci_dev); } - } - printk("comedi%d: rtd520: removed.\n",dev->minor); + printk("comedi%d: rtd520: removed.\n", dev->minor); - return 0; + return 0; } /* Convert a single comedi channel-gain entry to a RTD520 table entry */ -static unsigned short rtdConvertChanGain ( - comedi_device *dev, - unsigned int comediChan, - int chanIndex) /* index in channel list */ -{ - unsigned int chan, range, aref; - unsigned short r=0; - - chan = CR_CHAN (comediChan); - range = CR_RANGE (comediChan); - aref = CR_AREF (comediChan); - - r |= chan & 0xf; - - /* Note: we also setup the channel list bipolar flag array */ - if (range < thisboard->range10Start) {/* first batch are +-5 */ - r |= 0x000; /* +-5 range */ - r |= (range & 0x7) << 4; /* gain */ - CHAN_ARRAY_SET (devpriv->chanBipolar, chanIndex); - } else if (range < thisboard->rangeUniStart) {/* second batch are +-10 */ - r |= 0x100; /* +-10 range */ - r |= ((range - thisboard->range10Start) & 0x7) << 4; /* gain */ - CHAN_ARRAY_SET (devpriv->chanBipolar, chanIndex); - } else { /* last batch is +10 */ - r |= 0x200; /* +10 range */ - r |= ((range-thisboard->rangeUniStart) & 0x7) << 4; /* gain */ - CHAN_ARRAY_CLEAR (devpriv->chanBipolar, chanIndex); - } - - switch (aref) { - case AREF_GROUND: /* on-board ground */ - break; - - case AREF_COMMON: - r |= 0x80; /* ref external analog common */ - break; - - case AREF_DIFF: - r |= 0x400; /* differential inputs */ - break; - - case AREF_OTHER: /* ??? */ - break; - } - /*printk ("chan=%d r=%d a=%d -> 0x%x\n", - chan, range, aref, r);*/ - return r; +static unsigned short rtdConvertChanGain(comedi_device * dev, + unsigned int comediChan, int chanIndex) +{ /* index in channel list */ + unsigned int chan, range, aref; + unsigned short r = 0; + + chan = CR_CHAN(comediChan); + range = CR_RANGE(comediChan); + aref = CR_AREF(comediChan); + + r |= chan & 0xf; + + /* Note: we also setup the channel list bipolar flag array */ + if (range < thisboard->range10Start) { /* first batch are +-5 */ + r |= 0x000; /* +-5 range */ + r |= (range & 0x7) << 4; /* gain */ + CHAN_ARRAY_SET(devpriv->chanBipolar, chanIndex); + } else if (range < thisboard->rangeUniStart) { /* second batch are +-10 */ + r |= 0x100; /* +-10 range */ + r |= ((range - thisboard->range10Start) & 0x7) << 4; /* gain */ + CHAN_ARRAY_SET(devpriv->chanBipolar, chanIndex); + } else { /* last batch is +10 */ + r |= 0x200; /* +10 range */ + r |= ((range - thisboard->rangeUniStart) & 0x7) << 4; /* gain */ + CHAN_ARRAY_CLEAR(devpriv->chanBipolar, chanIndex); + } + + switch (aref) { + case AREF_GROUND: /* on-board ground */ + break; + + case AREF_COMMON: + r |= 0x80; /* ref external analog common */ + break; + + case AREF_DIFF: + r |= 0x400; /* differential inputs */ + break; + + case AREF_OTHER: /* ??? */ + break; + } + /*printk ("chan=%d r=%d a=%d -> 0x%x\n", + chan, range, aref, r); */ + return r; } /* Setup the channel-gain table from a comedi list */ -static void rtd_load_channelgain_list ( - comedi_device *dev, - unsigned int n_chan, - unsigned int *list) +static void rtd_load_channelgain_list(comedi_device * dev, + unsigned int n_chan, unsigned int *list) { - if (n_chan > 1) { /* setup channel gain table */ - int ii; - RtdClearCGT (dev); - RtdEnableCGT(dev, 1); /* enable table */ - for(ii=0; ii < n_chan; ii++){ - RtdWriteCGTable (dev, rtdConvertChanGain (dev, list[ii], ii)); - } - } else { /* just use the channel gain latch */ - RtdEnableCGT(dev, 0); /* disable table, enable latch */ - RtdWriteCGLatch (dev, rtdConvertChanGain (dev, list[0], 0)); - } + if (n_chan > 1) { /* setup channel gain table */ + int ii; + RtdClearCGT(dev); + RtdEnableCGT(dev, 1); /* enable table */ + for (ii = 0; ii < n_chan; ii++) { + RtdWriteCGTable(dev, rtdConvertChanGain(dev, list[ii], + ii)); + } + } else { /* just use the channel gain latch */ + RtdEnableCGT(dev, 0); /* disable table, enable latch */ + RtdWriteCGLatch(dev, rtdConvertChanGain(dev, list[0], 0)); + } } /* @@ -1246,55 +1230,51 @@ static void rtd_load_channelgain_list ( Note, we don't do any settling delays. Use a instruction list to select, delay, then read. */ -static int rtd_ai_rinsn ( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int rtd_ai_rinsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int n, ii; - int stat; + int n, ii; + int stat; - /* clear any old fifo data */ - RtdAdcClearFifo (dev); + /* clear any old fifo data */ + RtdAdcClearFifo(dev); - /* write channel to multiplexer and clear channel gain table */ - rtd_load_channelgain_list (dev, 1, &insn->chanspec); + /* write channel to multiplexer and clear channel gain table */ + rtd_load_channelgain_list(dev, 1, &insn->chanspec); - /* set conversion source */ - RtdAdcConversionSource (dev, 0); /* software */ + /* set conversion source */ + RtdAdcConversionSource(dev, 0); /* software */ - /* convert n samples */ - for (n=0; n < insn->n; n++) { - s16 d; - /* trigger conversion */ - RtdAdcStart (dev); + /* convert n samples */ + for (n = 0; n < insn->n; n++) { + s16 d; + /* trigger conversion */ + RtdAdcStart(dev); - for (ii = 0; ii < RTD_ADC_TIMEOUT; ++ii) { - stat = RtdFifoStatus (dev); - if (stat & FS_ADC_EMPTY) /* 1 -> not empty */ - break; - WAIT_QUIETLY; - } - if (ii >= RTD_ADC_TIMEOUT) { - DPRINTK ("rtd520: Error: ADC never finished! FifoStatus=0x%x\n", - stat ^ 0x6666); - return -ETIMEDOUT; - } + for (ii = 0; ii < RTD_ADC_TIMEOUT; ++ii) { + stat = RtdFifoStatus(dev); + if (stat & FS_ADC_EMPTY) /* 1 -> not empty */ + break; + WAIT_QUIETLY; + } + if (ii >= RTD_ADC_TIMEOUT) { + DPRINTK("rtd520: Error: ADC never finished! FifoStatus=0x%x\n", stat ^ 0x6666); + return -ETIMEDOUT; + } - /* read data */ - d = RtdAdcFifoGet (dev); /* get 2s comp value */ - /*printk ("rtd520: Got 0x%x after %d usec\n", d, ii+1);*/ - d = d >> 3; /* low 3 bits are marker lines */ - if (CHAN_ARRAY_TEST (devpriv->chanBipolar,0)) { - data[n] = d + 2048; /* convert to comedi unsigned data */ - } else { - data[n] = d; + /* read data */ + d = RtdAdcFifoGet(dev); /* get 2s comp value */ + /*printk ("rtd520: Got 0x%x after %d usec\n", d, ii+1); */ + d = d >> 3; /* low 3 bits are marker lines */ + if (CHAN_ARRAY_TEST(devpriv->chanBipolar, 0)) { + data[n] = d + 2048; /* convert to comedi unsigned data */ + } else { + data[n] = d; + } } - } - /* return the number of samples read/written */ - return n; + /* return the number of samples read/written */ + return n; } /* @@ -1303,191 +1283,183 @@ static int rtd_ai_rinsn ( The manual claims that we can do a lword read, but it doesn't work here. */ -static int ai_read_n ( - comedi_device *dev, - comedi_subdevice *s, - int count) +static int ai_read_n(comedi_device * dev, comedi_subdevice * s, int count) { - int ii; + int ii; - for (ii = 0; ii < count; ii++) { - sampl_t sample; - s16 d; + for (ii = 0; ii < count; ii++) { + sampl_t sample; + s16 d; - if (0 == devpriv->aiCount) { /* done */ - d = RtdAdcFifoGet (dev); /* Read N and discard */ - continue; - } + if (0 == devpriv->aiCount) { /* done */ + d = RtdAdcFifoGet(dev); /* Read N and discard */ + continue; + } #if 0 - if (0 == (RtdFifoStatus (dev) & FS_ADC_EMPTY)) { /* DEBUG */ - DPRINTK("comedi: READ OOPS on %d of %d\n", ii+1, count); - break; - } + if (0 == (RtdFifoStatus(dev) & FS_ADC_EMPTY)) { /* DEBUG */ + DPRINTK("comedi: READ OOPS on %d of %d\n", ii + 1, + count); + break; + } #endif - d = RtdAdcFifoGet (dev); /* get 2s comp value */ + d = RtdAdcFifoGet(dev); /* get 2s comp value */ - d = d >> 3; /* low 3 bits are marker lines */ - if (CHAN_ARRAY_TEST (devpriv->chanBipolar, s->async->cur_chan)) { - sample = d + 2048; /* convert to comedi unsigned data */ - } else { - sample = d; - } - if (!comedi_buf_put (s->async, sample)) - return -1; + d = d >> 3; /* low 3 bits are marker lines */ + if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) { + sample = d + 2048; /* convert to comedi unsigned data */ + } else { + sample = d; + } + if (!comedi_buf_put(s->async, sample)) + return -1; - if (devpriv->aiCount > 0) /* < 0, means read forever */ - devpriv->aiCount--; - } - return 0; + if (devpriv->aiCount > 0) /* < 0, means read forever */ + devpriv->aiCount--; + } + return 0; } /* unknown amout of data is waiting in fifo. */ -static int ai_read_dregs ( - comedi_device *dev, - comedi_subdevice *s) +static int ai_read_dregs(comedi_device * dev, comedi_subdevice * s) { - while (RtdFifoStatus (dev) & FS_ADC_EMPTY) { /* 1 -> not empty */ - sampl_t sample; - s16 d = RtdAdcFifoGet (dev); /* get 2s comp value */ + while (RtdFifoStatus(dev) & FS_ADC_EMPTY) { /* 1 -> not empty */ + sampl_t sample; + s16 d = RtdAdcFifoGet(dev); /* get 2s comp value */ - if (0 == devpriv->aiCount) { /* done */ - continue; /* read rest */ - } + if (0 == devpriv->aiCount) { /* done */ + continue; /* read rest */ + } - d = d >> 3; /* low 3 bits are marker lines */ - if (CHAN_ARRAY_TEST (devpriv->chanBipolar, s->async->cur_chan)) { - sample = d + 2048; /* convert to comedi unsigned data */ - } else { - sample = d; - } - if (!comedi_buf_put (s->async, sample)) - return -1; + d = d >> 3; /* low 3 bits are marker lines */ + if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) { + sample = d + 2048; /* convert to comedi unsigned data */ + } else { + sample = d; + } + if (!comedi_buf_put(s->async, sample)) + return -1; - if (devpriv->aiCount > 0) /* < 0, means read forever */ - devpriv->aiCount--; - } - return 0; + if (devpriv->aiCount > 0) /* < 0, means read forever */ + devpriv->aiCount--; + } + return 0; } #ifdef USE_DMA /* Terminate a DMA transfer and wait for everything to quiet down */ -void abort_dma ( - comedi_device *dev, - unsigned int channel) /* DMA channel 0, 1 */ -{ - unsigned long dma_cs_addr; /* the control/status register */ - uint8_t status; - unsigned int ii; - //unsigned long flags; - - dma_cs_addr = (unsigned long)devpriv->lcfg - + ((channel == 0) ? LCFG_DMACSR0 : LCFG_DMACSR1); - - // spinlock for plx dma control/status reg - //comedi_spin_lock_irqsave( &dev->spinlock, flags ); - - // abort dma transfer if necessary - status = readb(dma_cs_addr); - if((status & PLX_DMA_EN_BIT) == 0) { /* not enabled (Error?) */ - DPRINTK ("rtd520: AbortDma on non-active channel %d (0x%x)\n", - channel, status); - goto abortDmaExit; - } - - /* wait to make sure done bit is zero (needed?) */ - for (ii = 0; - (status & PLX_DMA_DONE_BIT) && ii < RTD_DMA_TIMEOUT; - ii++) { - WAIT_QUIETLY; +void abort_dma(comedi_device * dev, unsigned int channel) +{ /* DMA channel 0, 1 */ + unsigned long dma_cs_addr; /* the control/status register */ + uint8_t status; + unsigned int ii; + //unsigned long flags; + + dma_cs_addr = (unsigned long)devpriv->lcfg + + ((channel == 0) ? LCFG_DMACSR0 : LCFG_DMACSR1); + + // spinlock for plx dma control/status reg + //comedi_spin_lock_irqsave( &dev->spinlock, flags ); + + // abort dma transfer if necessary status = readb(dma_cs_addr); - } - if (status & PLX_DMA_DONE_BIT) { - printk("rtd520: Timeout waiting for dma %i done clear\n", channel); - goto abortDmaExit; - } - - /* disable channel (required) */ - writeb(0, dma_cs_addr); - comedi_udelay(1); /* needed?? */ - /* set abort bit for channel */ - writeb(PLX_DMA_ABORT_BIT, dma_cs_addr); - - // wait for dma done bit to be set - status = readb(dma_cs_addr); - for(ii = 0; - (status & PLX_DMA_DONE_BIT) == 0 && ii < RTD_DMA_TIMEOUT; - ii++) { + if ((status & PLX_DMA_EN_BIT) == 0) { /* not enabled (Error?) */ + DPRINTK("rtd520: AbortDma on non-active channel %d (0x%x)\n", + channel, status); + goto abortDmaExit; + } + + /* wait to make sure done bit is zero (needed?) */ + for (ii = 0; (status & PLX_DMA_DONE_BIT) && ii < RTD_DMA_TIMEOUT; ii++) { + WAIT_QUIETLY; + status = readb(dma_cs_addr); + } + if (status & PLX_DMA_DONE_BIT) { + printk("rtd520: Timeout waiting for dma %i done clear\n", + channel); + goto abortDmaExit; + } + + /* disable channel (required) */ + writeb(0, dma_cs_addr); + comedi_udelay(1); /* needed?? */ + /* set abort bit for channel */ + writeb(PLX_DMA_ABORT_BIT, dma_cs_addr); + + // wait for dma done bit to be set status = readb(dma_cs_addr); - WAIT_QUIETLY; - } - if ((status & PLX_DMA_DONE_BIT) == 0) { - printk("rtd520: Timeout waiting for dma %i done set\n", channel); - } - -abortDmaExit: - //comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + for (ii = 0; + (status & PLX_DMA_DONE_BIT) == 0 && ii < RTD_DMA_TIMEOUT; + ii++) { + status = readb(dma_cs_addr); + WAIT_QUIETLY; + } + if ((status & PLX_DMA_DONE_BIT) == 0) { + printk("rtd520: Timeout waiting for dma %i done set\n", + channel); + } + + abortDmaExit: + //comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); } /* Process what is in the DMA transfer buffer and pass to comedi Note: this is not re-entrant */ -static int ai_process_dma ( - comedi_device *dev, - comedi_subdevice *s) +static int ai_process_dma(comedi_device * dev, comedi_subdevice * s) { - int ii, n; - s16 *dp; + int ii, n; + s16 *dp; - if (devpriv->aiCount == 0) /* transfer already complete */ - return 0; + if (devpriv->aiCount == 0) /* transfer already complete */ + return 0; - dp = devpriv->dma0Buff[devpriv->dma0Offset]; - for (ii = 0; ii < thisboard->fifoLen/2;) { /* convert samples */ - sampl_t sample; + dp = devpriv->dma0Buff[devpriv->dma0Offset]; + for (ii = 0; ii < thisboard->fifoLen / 2;) { /* convert samples */ + sampl_t sample; - if (CHAN_ARRAY_TEST (devpriv->chanBipolar, s->async->cur_chan)) { - sample = (*dp >> 3) + 2048; /* convert to comedi unsigned data */ - } else { - sample = *dp >> 3; /* low 3 bits are marker lines */ - } - *dp++ = sample; /* put processed value back */ + if (CHAN_ARRAY_TEST(devpriv->chanBipolar, s->async->cur_chan)) { + sample = (*dp >> 3) + 2048; /* convert to comedi unsigned data */ + } else { + sample = *dp >> 3; /* low 3 bits are marker lines */ + } + *dp++ = sample; /* put processed value back */ - if (++s->async->cur_chan >= s->async->cmd.chanlist_len) - s->async->cur_chan = 0; + if (++s->async->cur_chan >= s->async->cmd.chanlist_len) + s->async->cur_chan = 0; - ++ii; /* number ready to transfer */ - if (devpriv->aiCount > 0) { /* < 0, means read forever */ - if (--devpriv->aiCount == 0) { /* done */ - /*DPRINTK ("rtd520: Final %d samples\n", ii);*/ - break; - } + ++ii; /* number ready to transfer */ + if (devpriv->aiCount > 0) { /* < 0, means read forever */ + if (--devpriv->aiCount == 0) { /* done */ + /*DPRINTK ("rtd520: Final %d samples\n", ii); */ + break; + } + } } - } - /* now pass the whole array to the comedi buffer */ - dp = devpriv->dma0Buff[devpriv->dma0Offset]; - n = comedi_buf_write_alloc (s->async, ii * sizeof (s16)); - if (n < (ii * sizeof (s16))) { /* any residual is an error */ - DPRINTK ("rtd520:ai_process_dma buffer overflow %d samples!\n", - ii - (n / sizeof (s16))); - s->async->events |= COMEDI_CB_ERROR; - return -1; - } - comedi_buf_memcpy_to (s->async, 0, dp, n); - comedi_buf_write_free (s->async, n); - - /* always at least 1 scan -- 1/2 FIFO is larger than our max scan list */ - s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; - - if (++devpriv->dma0Offset >= DMA_CHAIN_COUNT) { /* next buffer */ - devpriv->dma0Offset = 0; - } - return 0; + /* now pass the whole array to the comedi buffer */ + dp = devpriv->dma0Buff[devpriv->dma0Offset]; + n = comedi_buf_write_alloc(s->async, ii * sizeof(s16)); + if (n < (ii * sizeof(s16))) { /* any residual is an error */ + DPRINTK("rtd520:ai_process_dma buffer overflow %d samples!\n", + ii - (n / sizeof(s16))); + s->async->events |= COMEDI_CB_ERROR; + return -1; + } + comedi_buf_memcpy_to(s->async, 0, dp, n); + comedi_buf_write_free(s->async, n); + + /* always at least 1 scan -- 1/2 FIFO is larger than our max scan list */ + s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; + + if (++devpriv->dma0Offset >= DMA_CHAIN_COUNT) { /* next buffer */ + devpriv->dma0Offset = 0; + } + return 0; } #endif /* USE_DMA */ @@ -1497,167 +1469,153 @@ static int ai_process_dma ( This is a "slow handler"; other interrupts may be active. The data conversion may someday happen in a "bottom half". */ -static irqreturn_t rtd_interrupt ( - int irq, /* interrupt number (ignored) */ - void *d /* our data */ - PT_REGS_ARG) /* cpu context (ignored) */ -{ - comedi_device *dev = d; /* must be called "dev" for devpriv */ +static irqreturn_t rtd_interrupt(int irq, /* interrupt number (ignored) */ + void *d /* our data */ + PT_REGS_ARG) +{ /* cpu context (ignored) */ + comedi_device *dev = d; /* must be called "dev" for devpriv */ u16 status; u16 fifoStatus; - comedi_subdevice *s = dev->subdevices + 0; /* analog in subdevice */ + comedi_subdevice *s = dev->subdevices + 0; /* analog in subdevice */ if (!dev->attached) { return IRQ_NONE; } - devpriv->intCount++; /* DEBUG statistics */ + devpriv->intCount++; /* DEBUG statistics */ - fifoStatus = RtdFifoStatus (dev); + fifoStatus = RtdFifoStatus(dev); /* check for FIFO full, this automatically halts the ADC! */ if (!(fifoStatus & FS_ADC_FULL)) { /* 0 -> full */ - DPRINTK("rtd520: FIFO full! fifo_status=0x%x\n", - (fifoStatus ^ 0x6666) & 0x7777); /* should be all 0s */ + DPRINTK("rtd520: FIFO full! fifo_status=0x%x\n", (fifoStatus ^ 0x6666) & 0x7777); /* should be all 0s */ goto abortTransfer; } - #ifdef USE_DMA - if (devpriv->flags & DMA0_ACTIVE) { /* Check DMA */ - u32 istatus = RtdPlxInterruptRead (dev); - - if (istatus & ICS_DMA0_A) { - if (ai_process_dma (dev, s) < 0) { - DPRINTK("rtd520: comedi read buffer overflow (DMA) with %ld to go!\n", - devpriv->aiCount); - RtdDma0Control (dev, + if (devpriv->flags & DMA0_ACTIVE) { /* Check DMA */ + u32 istatus = RtdPlxInterruptRead(dev); + + if (istatus & ICS_DMA0_A) { + if (ai_process_dma(dev, s) < 0) { + DPRINTK("rtd520: comedi read buffer overflow (DMA) with %ld to go!\n", devpriv->aiCount); + RtdDma0Control(dev, + (devpriv-> + dma0Control & + ~PLX_DMA_START_BIT) + | PLX_CLEAR_DMA_INTR_BIT); + goto abortTransfer; + } + + /*DPRINTK ("rtd520: DMA transfer: %ld to go, istatus %x\n", + devpriv->aiCount, istatus); */ + RtdDma0Control(dev, (devpriv->dma0Control & ~PLX_DMA_START_BIT) | PLX_CLEAR_DMA_INTR_BIT); - goto abortTransfer; - } - - /*DPRINTK ("rtd520: DMA transfer: %ld to go, istatus %x\n", - devpriv->aiCount, istatus);*/ - RtdDma0Control (dev, (devpriv->dma0Control & ~PLX_DMA_START_BIT) - | PLX_CLEAR_DMA_INTR_BIT); - if (0 == devpriv->aiCount) { /* counted down */ - DPRINTK("rtd520: Samples Done (DMA).\n"); - goto transferDone; - } - comedi_event (dev, s); - } else { - /*DPRINTK ("rtd520: No DMA ready: istatus %x\n", istatus);*/ + if (0 == devpriv->aiCount) { /* counted down */ + DPRINTK("rtd520: Samples Done (DMA).\n"); + goto transferDone; + } + comedi_event(dev, s); + } else { + /*DPRINTK ("rtd520: No DMA ready: istatus %x\n", istatus); */ + } } - } - /* Fall through and check for other interrupt sources */ + /* Fall through and check for other interrupt sources */ #endif /* USE_DMA */ - status = RtdInterruptStatus (dev); - /* if interrupt was not caused by our board, or handled above */ - if (0 == status) { + status = RtdInterruptStatus(dev); + /* if interrupt was not caused by our board, or handled above */ + if (0 == status) { return IRQ_HANDLED; - } - - if (status & IRQM_ADC_ABOUT_CNT) { /* sample count -> read FIFO */ - /* since the priority interrupt controller may have queued a sample - counter interrupt, even though we have already finished, - we must handle the possibility that there is no data here */ - if (!(fifoStatus & FS_ADC_HEMPTY)) { /* 0 -> 1/2 full */ - /*DPRINTK("rtd520: Sample int, reading 1/2FIFO. fifo_status 0x%x\n", - (fifoStatus ^ 0x6666) & 0x7777);*/ - if (ai_read_n (dev, s, thisboard->fifoLen / 2) < 0) { - DPRINTK("rtd520: comedi read buffer overflow (1/2FIFO) with %ld to go!\n", - devpriv->aiCount); - goto abortTransfer; - } - if (0 == devpriv->aiCount) { /* counted down */ - DPRINTK("rtd520: Samples Done (1/2). fifo_status was 0x%x\n", - (fifoStatus ^ 0x6666) & 0x7777); /* should be all 0s */ - goto transferDone; - } - comedi_event (dev, s); - } else if (devpriv->transCount > 0) { /* read often */ - /*DPRINTK("rtd520: Sample int, reading %d fifo_status 0x%x\n", - devpriv->transCount, (fifoStatus ^ 0x6666) & 0x7777);*/ - if (fifoStatus & FS_ADC_EMPTY) { /* 1 -> not empty */ - if (ai_read_n (dev, s, devpriv->transCount) < 0) { - DPRINTK("rtd520: comedi read buffer overflow (N) with %ld to go!\n", - devpriv->aiCount); - goto abortTransfer; - } - if (0 == devpriv->aiCount) { /* counted down */ - DPRINTK("rtd520: Samples Done (N). fifo_status was 0x%x\n", - (fifoStatus ^ 0x6666) & 0x7777); - goto transferDone; + } + + if (status & IRQM_ADC_ABOUT_CNT) { /* sample count -> read FIFO */ + /* since the priority interrupt controller may have queued a sample + counter interrupt, even though we have already finished, + we must handle the possibility that there is no data here */ + if (!(fifoStatus & FS_ADC_HEMPTY)) { /* 0 -> 1/2 full */ + /*DPRINTK("rtd520: Sample int, reading 1/2FIFO. fifo_status 0x%x\n", + (fifoStatus ^ 0x6666) & 0x7777); */ + if (ai_read_n(dev, s, thisboard->fifoLen / 2) < 0) { + DPRINTK("rtd520: comedi read buffer overflow (1/2FIFO) with %ld to go!\n", devpriv->aiCount); + goto abortTransfer; + } + if (0 == devpriv->aiCount) { /* counted down */ + DPRINTK("rtd520: Samples Done (1/2). fifo_status was 0x%x\n", (fifoStatus ^ 0x6666) & 0x7777); /* should be all 0s */ + goto transferDone; + } + comedi_event(dev, s); + } else if (devpriv->transCount > 0) { /* read often */ + /*DPRINTK("rtd520: Sample int, reading %d fifo_status 0x%x\n", + devpriv->transCount, (fifoStatus ^ 0x6666) & 0x7777); */ + if (fifoStatus & FS_ADC_EMPTY) { /* 1 -> not empty */ + if (ai_read_n(dev, s, devpriv->transCount) < 0) { + DPRINTK("rtd520: comedi read buffer overflow (N) with %ld to go!\n", devpriv->aiCount); + goto abortTransfer; + } + if (0 == devpriv->aiCount) { /* counted down */ + DPRINTK("rtd520: Samples Done (N). fifo_status was 0x%x\n", (fifoStatus ^ 0x6666) & 0x7777); + goto transferDone; + } + comedi_event(dev, s); + } + } else { /* wait for 1/2 FIFO (old) */ + DPRINTK("rtd520: Sample int. Wait for 1/2. fifo_status 0x%x\n", (fifoStatus ^ 0x6666) & 0x7777); } - comedi_event (dev, s); - } - } else { /* wait for 1/2 FIFO (old)*/ - DPRINTK("rtd520: Sample int. Wait for 1/2. fifo_status 0x%x\n", - (fifoStatus ^ 0x6666) & 0x7777); - } - } - else { - DPRINTK ("rtd520: unknown interrupt source!\n"); - } - - if (0xffff & RtdInterruptOverrunStatus (dev)) { /* interrupt overrun */ - DPRINTK("rtd520: Interrupt overrun with %ld to go! over_status=0x%x\n", - devpriv->aiCount, - 0xffff & RtdInterruptOverrunStatus (dev)); - goto abortTransfer; - } - - /* clear the interrupt */ - RtdInterruptClearMask (dev, status); - RtdInterruptClear (dev); - return IRQ_HANDLED; - -abortTransfer: - RtdAdcClearFifo (dev); /* clears full flag */ - s->async->events |= COMEDI_CB_ERROR; - devpriv->aiCount = 0; /* stop and don't transfer any more */ - /* fall into transferDone */ - -transferDone: - RtdPacerStopSource (dev, 0); /* stop on SOFTWARE stop */ - RtdPacerStop (dev); /* Stop PACER */ - RtdAdcConversionSource (dev, 0); /* software trigger only */ - RtdInterruptMask (dev, 0); /* mask out SAMPLE */ + } else { + DPRINTK("rtd520: unknown interrupt source!\n"); + } + + if (0xffff & RtdInterruptOverrunStatus(dev)) { /* interrupt overrun */ + DPRINTK("rtd520: Interrupt overrun with %ld to go! over_status=0x%x\n", devpriv->aiCount, 0xffff & RtdInterruptOverrunStatus(dev)); + goto abortTransfer; + } + + /* clear the interrupt */ + RtdInterruptClearMask(dev, status); + RtdInterruptClear(dev); + return IRQ_HANDLED; + + abortTransfer: + RtdAdcClearFifo(dev); /* clears full flag */ + s->async->events |= COMEDI_CB_ERROR; + devpriv->aiCount = 0; /* stop and don't transfer any more */ + /* fall into transferDone */ + + transferDone: + RtdPacerStopSource(dev, 0); /* stop on SOFTWARE stop */ + RtdPacerStop(dev); /* Stop PACER */ + RtdAdcConversionSource(dev, 0); /* software trigger only */ + RtdInterruptMask(dev, 0); /* mask out SAMPLE */ #ifdef USE_DMA - if (devpriv->flags & DMA0_ACTIVE) { - RtdPlxInterruptWrite (dev, /* disable any more interrupts */ - RtdPlxInterruptRead (dev) & ~ICS_DMA0_E); - abort_dma (dev, 0); - devpriv->flags &= ~DMA0_ACTIVE; - /* if Using DMA, then we should have read everything by now */ - if (devpriv->aiCount > 0) { - DPRINTK ("rtd520: Lost DMA data! %ld remain\n", - devpriv->aiCount); - } - } + if (devpriv->flags & DMA0_ACTIVE) { + RtdPlxInterruptWrite(dev, /* disable any more interrupts */ + RtdPlxInterruptRead(dev) & ~ICS_DMA0_E); + abort_dma(dev, 0); + devpriv->flags &= ~DMA0_ACTIVE; + /* if Using DMA, then we should have read everything by now */ + if (devpriv->aiCount > 0) { + DPRINTK("rtd520: Lost DMA data! %ld remain\n", + devpriv->aiCount); + } + } #endif /* USE_DMA */ - if (devpriv->aiCount > 0) { /* there shouldn't be anything left */ - fifoStatus = RtdFifoStatus (dev); - DPRINTK("rtd520: Finishing up. %ld remain, fifoStat=%x\n", - devpriv->aiCount, - (fifoStatus ^ 0x6666) & 0x7777); /* should read all 0s */ - ai_read_dregs (dev, s); /* read anything left in FIFO */ - } + if (devpriv->aiCount > 0) { /* there shouldn't be anything left */ + fifoStatus = RtdFifoStatus(dev); + DPRINTK("rtd520: Finishing up. %ld remain, fifoStat=%x\n", devpriv->aiCount, (fifoStatus ^ 0x6666) & 0x7777); /* should read all 0s */ + ai_read_dregs(dev, s); /* read anything left in FIFO */ + } - s->async->events |= COMEDI_CB_EOA;/* signal end to comedi */ - comedi_event (dev, s); + s->async->events |= COMEDI_CB_EOA; /* signal end to comedi */ + comedi_event(dev, s); - /* clear the interrupt */ - status = RtdInterruptStatus (dev); - RtdInterruptClearMask (dev, status); - RtdInterruptClear (dev); + /* clear the interrupt */ + status = RtdInterruptStatus(dev); + RtdInterruptClearMask(dev, status); + RtdInterruptClear(dev); - fifoStatus = RtdFifoStatus (dev); /* DEBUG */ - DPRINTK("rtd520: Acquisition complete. %ld ints, intStat=%x, overStat=%x\n", - devpriv->intCount, - status, - 0xffff & RtdInterruptOverrunStatus (dev)); + fifoStatus = RtdFifoStatus(dev); /* DEBUG */ + DPRINTK("rtd520: Acquisition complete. %ld ints, intStat=%x, overStat=%x\n", devpriv->intCount, status, 0xffff & RtdInterruptOverrunStatus(dev)); return IRQ_HANDLED; } @@ -1666,11 +1624,11 @@ transferDone: /* return the number of samples available */ -static int rtd_ai_poll (comedi_device *dev,comedi_subdevice *s) +static int rtd_ai_poll(comedi_device * dev, comedi_subdevice * s) { - /* TODO: This needs to mask interrupts, read_dregs, and then re-enable */ - /* Not sure what to do if DMA is active */ - return s->async->buf_write_count - s->async->buf_read_count; + /* TODO: This needs to mask interrupts, read_dregs, and then re-enable */ + /* Not sure what to do if DMA is active */ + return s->async->buf_write_count - s->async->buf_read_count; } #endif @@ -1683,198 +1641,203 @@ static int rtd_ai_poll (comedi_device *dev,comedi_subdevice *s) the command passes. */ -static int rtd_ai_cmdtest ( - comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +static int rtd_ai_cmdtest(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - int err=0; - int tmp; - - /* step 1: make sure trigger sources are trivially valid */ - - tmp = cmd->start_src; - cmd->start_src &= TRIG_NOW; - if (!cmd->start_src || tmp != cmd->start_src) { - err++; - } - - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) { - err++; - } - - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; - if (!cmd->convert_src || tmp != cmd->convert_src) { - err++; - } - - tmp=cmd->scan_end_src; - cmd->scan_end_src &= TRIG_COUNT; - if (!cmd->scan_end_src || tmp != cmd->scan_end_src) { - err++; - } - - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if (!cmd->stop_src || tmp != cmd->stop_src) { - err++; - } - - if (err) - return 1; - - /* step 2: make sure trigger sources are unique - and mutually compatible */ - /* note that mutual compatiblity is not an issue here */ - if (cmd->scan_begin_src !=TRIG_TIMER && - cmd->scan_begin_src !=TRIG_EXT) { - err++; - } - if (cmd->convert_src !=TRIG_TIMER && - cmd->convert_src !=TRIG_EXT) { - err++; - } - if (cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_NONE) { - err++; - } - - if (err) { - return 2; - } + int err = 0; + int tmp; - /* step 3: make sure arguments are trivially compatible */ + /* step 1: make sure trigger sources are trivially valid */ - if (cmd->start_arg != 0) { - cmd->start_arg = 0; - err++; - } + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW; + if (!cmd->start_src || tmp != cmd->start_src) { + err++; + } - if (cmd->scan_begin_src == TRIG_TIMER){ - /* Note: these are time periods, not actual rates */ - if (1 == cmd->chanlist_len) { /* no scanning */ - if (cmd->scan_begin_arg < RTD_MAX_SPEED_1) { - cmd->scan_begin_arg = RTD_MAX_SPEED_1; - rtd_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_UP); + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) { err++; - } - if (cmd->scan_begin_arg > RTD_MIN_SPEED_1) { - cmd->scan_begin_arg = RTD_MIN_SPEED_1; - rtd_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_DOWN); + } + + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->convert_src || tmp != cmd->convert_src) { err++; - } - } else { - if (cmd->scan_begin_arg < RTD_MAX_SPEED) { - cmd->scan_begin_arg = RTD_MAX_SPEED; - rtd_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_UP); + } + + tmp = cmd->scan_end_src; + cmd->scan_end_src &= TRIG_COUNT; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) { err++; - } - if (cmd->scan_begin_arg > RTD_MIN_SPEED) { - cmd->scan_begin_arg = RTD_MIN_SPEED; - rtd_ns_to_timer(&cmd->scan_begin_arg, TRIG_ROUND_DOWN); + } + + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) { err++; - } - } - } 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 (1 == cmd->chanlist_len) { /* no scanning */ - if (cmd->convert_arg < RTD_MAX_SPEED_1) { - cmd->convert_arg = RTD_MAX_SPEED_1; - rtd_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_UP); + } + + if (err) + return 1; + + /* step 2: make sure trigger sources are unique + and mutually compatible */ + /* note that mutual compatiblity is not an issue here */ + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) { err++; - } - if (cmd->convert_arg > RTD_MIN_SPEED_1) { - cmd->convert_arg = RTD_MIN_SPEED_1; - rtd_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_DOWN); + } + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) { err++; - } - } else { - if (cmd->convert_arg < RTD_MAX_SPEED) { - cmd->convert_arg = RTD_MAX_SPEED; - rtd_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_UP); + } + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) { err++; - } - if (cmd->convert_arg > RTD_MIN_SPEED) { - cmd->convert_arg = RTD_MIN_SPEED; - rtd_ns_to_timer(&cmd->convert_arg, TRIG_ROUND_DOWN); + } + + if (err) { + return 2; + } + + /* step 3: make sure arguments are trivially compatible */ + + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; - } } - } else { - /* external trigger */ - /* see above */ - if (cmd->convert_arg > 9) { - cmd->convert_arg = 9; - err++; + + if (cmd->scan_begin_src == TRIG_TIMER) { + /* Note: these are time periods, not actual rates */ + if (1 == cmd->chanlist_len) { /* no scanning */ + if (cmd->scan_begin_arg < RTD_MAX_SPEED_1) { + cmd->scan_begin_arg = RTD_MAX_SPEED_1; + rtd_ns_to_timer(&cmd->scan_begin_arg, + TRIG_ROUND_UP); + err++; + } + if (cmd->scan_begin_arg > RTD_MIN_SPEED_1) { + cmd->scan_begin_arg = RTD_MIN_SPEED_1; + rtd_ns_to_timer(&cmd->scan_begin_arg, + TRIG_ROUND_DOWN); + err++; + } + } else { + if (cmd->scan_begin_arg < RTD_MAX_SPEED) { + cmd->scan_begin_arg = RTD_MAX_SPEED; + rtd_ns_to_timer(&cmd->scan_begin_arg, + TRIG_ROUND_UP); + err++; + } + if (cmd->scan_begin_arg > RTD_MIN_SPEED) { + cmd->scan_begin_arg = RTD_MIN_SPEED; + rtd_ns_to_timer(&cmd->scan_begin_arg, + TRIG_ROUND_DOWN); + err++; + } + } + } 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 (1 == cmd->chanlist_len) { /* no scanning */ + if (cmd->convert_arg < RTD_MAX_SPEED_1) { + cmd->convert_arg = RTD_MAX_SPEED_1; + rtd_ns_to_timer(&cmd->convert_arg, + TRIG_ROUND_UP); + err++; + } + if (cmd->convert_arg > RTD_MIN_SPEED_1) { + cmd->convert_arg = RTD_MIN_SPEED_1; + rtd_ns_to_timer(&cmd->convert_arg, + TRIG_ROUND_DOWN); + err++; + } + } else { + if (cmd->convert_arg < RTD_MAX_SPEED) { + cmd->convert_arg = RTD_MAX_SPEED; + rtd_ns_to_timer(&cmd->convert_arg, + TRIG_ROUND_UP); + err++; + } + if (cmd->convert_arg > RTD_MIN_SPEED) { + cmd->convert_arg = RTD_MIN_SPEED; + rtd_ns_to_timer(&cmd->convert_arg, + TRIG_ROUND_DOWN); + err++; + } + } + } else { + /* external trigger */ + /* see above */ + if (cmd->convert_arg > 9) { + cmd->convert_arg = 9; + err++; + } } - } #if 0 - if (cmd->scan_end_arg != cmd->chanlist_len) { - cmd->scan_end_arg = cmd->chanlist_len; - err++; - } + if (cmd->scan_end_arg != cmd->chanlist_len) { + cmd->scan_end_arg = cmd->chanlist_len; + err++; + } #endif - if (cmd->stop_src==TRIG_COUNT) { - /* TODO check for rounding error due to counter wrap */ - - } 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->chanlist_len > RTD_MAX_CHANLIST) { - cmd->chanlist_len = RTD_MAX_CHANLIST; - err++; - } - if (cmd->scan_begin_src == TRIG_TIMER) { - tmp=cmd->scan_begin_arg; - rtd_ns_to_timer(&cmd->scan_begin_arg, - cmd->flags&TRIG_ROUND_MASK); - if (tmp!=cmd->scan_begin_arg) { - err++; - } - } - if (cmd->convert_src == TRIG_TIMER){ - tmp=cmd->convert_arg; - rtd_ns_to_timer(&cmd->convert_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; + if (cmd->stop_src == TRIG_COUNT) { + /* TODO check for rounding error due to counter wrap */ + + } 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->chanlist_len > RTD_MAX_CHANLIST) { + cmd->chanlist_len = RTD_MAX_CHANLIST; + err++; + } + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + rtd_ns_to_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) { + err++; + } + } + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + rtd_ns_to_timer(&cmd->convert_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; } /* @@ -1883,231 +1846,223 @@ static int rtd_ai_cmdtest ( This is usually done by an interrupt handler. Userland gets to the data using read calls. */ -static int rtd_ai_cmd ( - comedi_device *dev, - comedi_subdevice *s) +static int rtd_ai_cmd(comedi_device * dev, comedi_subdevice * s) { - comedi_cmd *cmd=&s->async->cmd; - int timer; - - /* stop anything currently running */ - RtdPacerStopSource (dev, 0); /* stop on SOFTWARE stop */ - RtdPacerStop (dev); /* make sure PACER is stopped */ - RtdAdcConversionSource (dev, 0); /* software trigger only */ - RtdInterruptMask (dev, 0); + comedi_cmd *cmd = &s->async->cmd; + int timer; + + /* stop anything currently running */ + RtdPacerStopSource(dev, 0); /* stop on SOFTWARE stop */ + RtdPacerStop(dev); /* make sure PACER is stopped */ + RtdAdcConversionSource(dev, 0); /* software trigger only */ + RtdInterruptMask(dev, 0); #ifdef USE_DMA - if (devpriv->flags & DMA0_ACTIVE) { /* cancel anything running */ - RtdPlxInterruptWrite (dev, /* disable any more interrupts */ - RtdPlxInterruptRead (dev) & ~ICS_DMA0_E); - abort_dma (dev, 0); - devpriv->flags &= ~DMA0_ACTIVE; - if (RtdPlxInterruptRead (dev) & ICS_DMA0_A) { /*clear pending int*/ - RtdDma0Control (dev, PLX_CLEAR_DMA_INTR_BIT); - } - } - RtdDma0Reset (dev); /* reset onboard state */ + if (devpriv->flags & DMA0_ACTIVE) { /* cancel anything running */ + RtdPlxInterruptWrite(dev, /* disable any more interrupts */ + RtdPlxInterruptRead(dev) & ~ICS_DMA0_E); + abort_dma(dev, 0); + devpriv->flags &= ~DMA0_ACTIVE; + if (RtdPlxInterruptRead(dev) & ICS_DMA0_A) { /*clear pending int */ + RtdDma0Control(dev, PLX_CLEAR_DMA_INTR_BIT); + } + } + RtdDma0Reset(dev); /* reset onboard state */ #endif /* USE_DMA */ - RtdAdcClearFifo (dev); /* clear any old data */ - RtdInterruptOverrunClear(dev); - devpriv->intCount = 0; - - if (! dev->irq) { /* we need interrupts for this */ - DPRINTK ("rtd520: ERROR! No interrupt available!\n"); - return -ENXIO; - } - - /* start configuration */ - /* load channel list and reset CGT */ - rtd_load_channelgain_list (dev, cmd->chanlist_len, cmd->chanlist); - - /* setup the common case and override if needed */ - if (cmd->chanlist_len > 1) { - /*DPRINTK ("rtd520: Multi channel setup\n");*/ - RtdPacerStartSource (dev, 0); /* software triggers pacer */ - RtdBurstStartSource (dev, 1); /* PACER triggers burst */ - RtdAdcConversionSource (dev, 2); /* BURST triggers ADC */ - } else { /* single channel */ - /*DPRINTK ("rtd520: single channel setup\n");*/ - RtdPacerStartSource (dev, 0); /* software triggers pacer */ - RtdAdcConversionSource (dev, 1); /* PACER triggers ADC */ - } - RtdAboutCounter (dev, thisboard->fifoLen/2 - 1); /* 1/2 FIFO */ - - if (TRIG_TIMER == cmd->scan_begin_src) { - /* scan_begin_arg is in nanoseconds */ - /* find out how many samples to wait before transferring */ - if (cmd->flags & TRIG_WAKE_EOS) { - /* this may generate un-sustainable interrupt rates */ - /* the application is responsible for doing the right thing */ - devpriv->transCount = cmd->chanlist_len; - devpriv->flags |= SEND_EOS; - } else { - /* arrange to transfer data periodically */ - devpriv->transCount - = (TRANS_TARGET_PERIOD*cmd->chanlist_len)/cmd->scan_begin_arg; - if (devpriv->transCount < cmd->chanlist_len) { - /* tranfer after each scan (and avoid 0) */ - devpriv->transCount = cmd->chanlist_len; - } else { /* make a multiple of scan length */ - devpriv->transCount = - (devpriv->transCount + cmd->chanlist_len - 1) - / cmd->chanlist_len; - devpriv->transCount *= cmd->chanlist_len; - } - devpriv->flags |= SEND_EOS; - } - if (devpriv->transCount >= (thisboard->fifoLen /2)) { - /* out of counter range, use 1/2 fifo instead */ - devpriv->transCount = 0; - devpriv->flags &= ~SEND_EOS; - } else { - /* interrupt for each tranfer */ - RtdAboutCounter (dev, devpriv->transCount-1); - } - - DPRINTK ("rtd520: scanLen=%d tranferCount=%d fifoLen=%d\n scanTime(ns)=%d flags=0x%x\n", - cmd->chanlist_len, devpriv->transCount, thisboard->fifoLen, - cmd->scan_begin_arg, devpriv->flags); - } else { /* unknown timing, just use 1/2 FIFO */ - devpriv->transCount = 0; - devpriv->flags &= ~SEND_EOS; - } - RtdPacerClockSource (dev, 1); /* use INTERNAL 8Mhz clock source */ - RtdAboutStopEnable (dev, 1); /* just interrupt, dont stop */ - - /* BUG??? these look like enumerated values, but they are bit fields */ - - /* First, setup when to stop */ - switch(cmd->stop_src){ - case TRIG_COUNT: /* stop after N scans */ - devpriv->aiCount = cmd->stop_arg * cmd->chanlist_len; - if ((devpriv->transCount > 0) - && (devpriv->transCount > devpriv->aiCount)) { - devpriv->transCount = devpriv->aiCount; - } - break; - - case TRIG_NONE: /* stop when cancel is called */ - devpriv->aiCount = -1; /* read forever */ - break; - - default: - DPRINTK ("rtd520: Warning! ignoring stop_src mode %d\n", - cmd->stop_src); - } - - - /* Scan timing */ - switch (cmd->scan_begin_src) { - case TRIG_TIMER: /* periodic scanning */ - timer=rtd_ns_to_timer(&cmd->scan_begin_arg,TRIG_ROUND_NEAREST); - /* set PACER clock */ - /*DPRINTK ("rtd520: loading %d into pacer\n", timer);*/ - RtdPacerCounter (dev, timer); - - break; - - case TRIG_EXT: - RtdPacerStartSource (dev, 1); /* EXTERNALy trigger pacer */ - break; - - default: - DPRINTK ("rtd520: Warning! ignoring scan_begin_src mode %d\n", - cmd->scan_begin_src); - } - - /* Sample timing within a scan */ - switch(cmd->convert_src){ - case TRIG_TIMER: /* periodic */ - if (cmd->chanlist_len > 1) { /* only needed for multi-channel */ - timer=rtd_ns_to_timer(&cmd->convert_arg,TRIG_ROUND_NEAREST); - /* setup BURST clock */ - /*DPRINTK ("rtd520: loading %d into burst\n", timer);*/ - RtdBurstCounter (dev, timer); - } - - break; - - case TRIG_EXT: /* external */ - RtdBurstStartSource (dev, 2); /* EXTERNALy trigger burst */ - break; - - default: - DPRINTK ("rtd520: Warning! ignoring convert_src mode %d\n", - cmd->convert_src); - } - /* end configuration */ - - - /* This doesn't seem to work. There is no way to clear an interrupt - that the priority controller has queued! */ - RtdInterruptClearMask (dev, ~0); /* clear any existing flags */ - RtdInterruptClear (dev); - - /* TODO: allow multiple interrupt sources */ - if (devpriv->transCount > 0) { /* transfer every N samples */ - RtdInterruptMask (dev, IRQM_ADC_ABOUT_CNT); - DPRINTK ("rtd520: Transferring every %d\n", devpriv->transCount); - } - else { /* 1/2 FIFO transfers */ + RtdAdcClearFifo(dev); /* clear any old data */ + RtdInterruptOverrunClear(dev); + devpriv->intCount = 0; + + if (!dev->irq) { /* we need interrupts for this */ + DPRINTK("rtd520: ERROR! No interrupt available!\n"); + return -ENXIO; + } + + /* start configuration */ + /* load channel list and reset CGT */ + rtd_load_channelgain_list(dev, cmd->chanlist_len, cmd->chanlist); + + /* setup the common case and override if needed */ + if (cmd->chanlist_len > 1) { + /*DPRINTK ("rtd520: Multi channel setup\n"); */ + RtdPacerStartSource(dev, 0); /* software triggers pacer */ + RtdBurstStartSource(dev, 1); /* PACER triggers burst */ + RtdAdcConversionSource(dev, 2); /* BURST triggers ADC */ + } else { /* single channel */ + /*DPRINTK ("rtd520: single channel setup\n"); */ + RtdPacerStartSource(dev, 0); /* software triggers pacer */ + RtdAdcConversionSource(dev, 1); /* PACER triggers ADC */ + } + RtdAboutCounter(dev, thisboard->fifoLen / 2 - 1); /* 1/2 FIFO */ + + if (TRIG_TIMER == cmd->scan_begin_src) { + /* scan_begin_arg is in nanoseconds */ + /* find out how many samples to wait before transferring */ + if (cmd->flags & TRIG_WAKE_EOS) { + /* this may generate un-sustainable interrupt rates */ + /* the application is responsible for doing the right thing */ + devpriv->transCount = cmd->chanlist_len; + devpriv->flags |= SEND_EOS; + } else { + /* arrange to transfer data periodically */ + devpriv->transCount + = + (TRANS_TARGET_PERIOD * cmd->chanlist_len) / + cmd->scan_begin_arg; + if (devpriv->transCount < cmd->chanlist_len) { + /* tranfer after each scan (and avoid 0) */ + devpriv->transCount = cmd->chanlist_len; + } else { /* make a multiple of scan length */ + devpriv->transCount = + (devpriv->transCount + + cmd->chanlist_len - 1) + / cmd->chanlist_len; + devpriv->transCount *= cmd->chanlist_len; + } + devpriv->flags |= SEND_EOS; + } + if (devpriv->transCount >= (thisboard->fifoLen / 2)) { + /* out of counter range, use 1/2 fifo instead */ + devpriv->transCount = 0; + devpriv->flags &= ~SEND_EOS; + } else { + /* interrupt for each tranfer */ + RtdAboutCounter(dev, devpriv->transCount - 1); + } + + DPRINTK("rtd520: scanLen=%d tranferCount=%d fifoLen=%d\n scanTime(ns)=%d flags=0x%x\n", cmd->chanlist_len, devpriv->transCount, thisboard->fifoLen, cmd->scan_begin_arg, devpriv->flags); + } else { /* unknown timing, just use 1/2 FIFO */ + devpriv->transCount = 0; + devpriv->flags &= ~SEND_EOS; + } + RtdPacerClockSource(dev, 1); /* use INTERNAL 8Mhz clock source */ + RtdAboutStopEnable(dev, 1); /* just interrupt, dont stop */ + + /* BUG??? these look like enumerated values, but they are bit fields */ + + /* First, setup when to stop */ + switch (cmd->stop_src) { + case TRIG_COUNT: /* stop after N scans */ + devpriv->aiCount = cmd->stop_arg * cmd->chanlist_len; + if ((devpriv->transCount > 0) + && (devpriv->transCount > devpriv->aiCount)) { + devpriv->transCount = devpriv->aiCount; + } + break; + + case TRIG_NONE: /* stop when cancel is called */ + devpriv->aiCount = -1; /* read forever */ + break; + + default: + DPRINTK("rtd520: Warning! ignoring stop_src mode %d\n", + cmd->stop_src); + } + + /* Scan timing */ + switch (cmd->scan_begin_src) { + case TRIG_TIMER: /* periodic scanning */ + timer = rtd_ns_to_timer(&cmd->scan_begin_arg, + TRIG_ROUND_NEAREST); + /* set PACER clock */ + /*DPRINTK ("rtd520: loading %d into pacer\n", timer); */ + RtdPacerCounter(dev, timer); + + break; + + case TRIG_EXT: + RtdPacerStartSource(dev, 1); /* EXTERNALy trigger pacer */ + break; + + default: + DPRINTK("rtd520: Warning! ignoring scan_begin_src mode %d\n", + cmd->scan_begin_src); + } + + /* Sample timing within a scan */ + switch (cmd->convert_src) { + case TRIG_TIMER: /* periodic */ + if (cmd->chanlist_len > 1) { /* only needed for multi-channel */ + timer = rtd_ns_to_timer(&cmd->convert_arg, + TRIG_ROUND_NEAREST); + /* setup BURST clock */ + /*DPRINTK ("rtd520: loading %d into burst\n", timer); */ + RtdBurstCounter(dev, timer); + } + + break; + + case TRIG_EXT: /* external */ + RtdBurstStartSource(dev, 2); /* EXTERNALy trigger burst */ + break; + + default: + DPRINTK("rtd520: Warning! ignoring convert_src mode %d\n", + cmd->convert_src); + } + /* end configuration */ + + /* This doesn't seem to work. There is no way to clear an interrupt + that the priority controller has queued! */ + RtdInterruptClearMask(dev, ~0); /* clear any existing flags */ + RtdInterruptClear(dev); + + /* TODO: allow multiple interrupt sources */ + if (devpriv->transCount > 0) { /* transfer every N samples */ + RtdInterruptMask(dev, IRQM_ADC_ABOUT_CNT); + DPRINTK("rtd520: Transferring every %d\n", devpriv->transCount); + } else { /* 1/2 FIFO transfers */ #ifdef USE_DMA - devpriv->flags |= DMA0_ACTIVE; - - /* point to first transfer in ring */ - devpriv->dma0Offset = 0; - RtdDma0Mode (dev, DMA_MODE_BITS); - RtdDma0Next (dev, /* point to first block */ - devpriv->dma0Chain[DMA_CHAIN_COUNT-1].next); - RtdDma0Source (dev, DMAS_ADFIFO_HALF_FULL); /* set DMA trigger source*/ - - - RtdPlxInterruptWrite (dev, /* enable interrupt */ - RtdPlxInterruptRead (dev) | ICS_DMA0_E); - /* Must be 2 steps. See PLX app note about "Starting a DMA transfer"*/ - RtdDma0Control (dev, PLX_DMA_EN_BIT); /* enable DMA (clear INTR?) */ - RtdDma0Control (dev, PLX_DMA_EN_BIT | PLX_DMA_START_BIT); /*start DMA*/ - DPRINTK ("rtd520: Using DMA0 transfers. plxInt %x RtdInt %x\n", - RtdPlxInterruptRead (dev), devpriv->intMask); + devpriv->flags |= DMA0_ACTIVE; + + /* point to first transfer in ring */ + devpriv->dma0Offset = 0; + RtdDma0Mode(dev, DMA_MODE_BITS); + RtdDma0Next(dev, /* point to first block */ + devpriv->dma0Chain[DMA_CHAIN_COUNT - 1].next); + RtdDma0Source(dev, DMAS_ADFIFO_HALF_FULL); /* set DMA trigger source */ + + RtdPlxInterruptWrite(dev, /* enable interrupt */ + RtdPlxInterruptRead(dev) | ICS_DMA0_E); + /* Must be 2 steps. See PLX app note about "Starting a DMA transfer" */ + RtdDma0Control(dev, PLX_DMA_EN_BIT); /* enable DMA (clear INTR?) */ + RtdDma0Control(dev, PLX_DMA_EN_BIT | PLX_DMA_START_BIT); /*start DMA */ + DPRINTK("rtd520: Using DMA0 transfers. plxInt %x RtdInt %x\n", + RtdPlxInterruptRead(dev), devpriv->intMask); #else /* USE_DMA */ - RtdInterruptMask (dev, IRQM_ADC_ABOUT_CNT ); - DPRINTK ("rtd520: Transferring every 1/2 FIFO\n"); + RtdInterruptMask(dev, IRQM_ADC_ABOUT_CNT); + DPRINTK("rtd520: Transferring every 1/2 FIFO\n"); #endif /* USE_DMA */ - } + } - /* BUG: start_src is ASSUMED to be TRIG_NOW */ - /* BUG? it seems like things are running before the "start" */ - RtdPacerStart (dev); /* Start PACER */ - return 0; + /* BUG: start_src is ASSUMED to be TRIG_NOW */ + /* BUG? it seems like things are running before the "start" */ + RtdPacerStart(dev); /* Start PACER */ + return 0; } /* Stop a running data aquisition. */ -static int rtd_ai_cancel ( - comedi_device *dev, - comedi_subdevice *s) +static int rtd_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - u16 status; + u16 status; - RtdPacerStopSource (dev, 0); /* stop on SOFTWARE stop */ - RtdPacerStop (dev); /* Stop PACER */ - RtdAdcConversionSource (dev, 0); /* software trigger only */ - RtdInterruptMask (dev, 0); - devpriv->aiCount = 0; /* stop and don't transfer any more */ + RtdPacerStopSource(dev, 0); /* stop on SOFTWARE stop */ + RtdPacerStop(dev); /* Stop PACER */ + RtdAdcConversionSource(dev, 0); /* software trigger only */ + RtdInterruptMask(dev, 0); + devpriv->aiCount = 0; /* stop and don't transfer any more */ #ifdef USE_DMA - if (devpriv->flags & DMA0_ACTIVE) { - RtdPlxInterruptWrite (dev, /* disable any more interrupts */ - RtdPlxInterruptRead (dev) & ~ICS_DMA0_E); - abort_dma (dev, 0); - devpriv->flags &= ~DMA0_ACTIVE; - } + if (devpriv->flags & DMA0_ACTIVE) { + RtdPlxInterruptWrite(dev, /* disable any more interrupts */ + RtdPlxInterruptRead(dev) & ~ICS_DMA0_E); + abort_dma(dev, 0); + devpriv->flags &= ~DMA0_ACTIVE; + } #endif /* USE_DMA */ - status = RtdInterruptStatus (dev); - DPRINTK("rtd520: Acquisition canceled. %ld ints, intStat=%x, overStat=%x\n", - devpriv->intCount, - status, - 0xffff & RtdInterruptOverrunStatus (dev)); - return 0; + status = RtdInterruptStatus(dev); + DPRINTK("rtd520: Acquisition canceled. %ld ints, intStat=%x, overStat=%x\n", devpriv->intCount, status, 0xffff & RtdInterruptOverrunStatus(dev)); + return 0; } /* @@ -2116,32 +2071,31 @@ static int rtd_ai_cancel ( Sets the original period to be the true value. Note: you have to check if the value is larger than the counter range! */ -static int rtd_ns_to_timer_base ( - unsigned int *nanosec, /* desired period (in ns) */ - int round_mode, - int base) /* clock period (in ns) */ -{ - int divider; - - switch(round_mode){ - case TRIG_ROUND_NEAREST: - default: - divider=(*nanosec+base/2)/base; - break; - case TRIG_ROUND_DOWN: - divider=(*nanosec)/base; - break; - case TRIG_ROUND_UP: - divider=(*nanosec+base-1)/base; - break; - } - if (divider < 2) divider = 2; /* min is divide by 2 */ - - /* Note: we don't check for max, because different timers - have different ranges */ - - *nanosec=base*divider; - return divider - 1; /* countdown is divisor+1 */ +static int rtd_ns_to_timer_base(unsigned int *nanosec, /* desired period (in ns) */ + int round_mode, int base) +{ /* clock period (in ns) */ + int divider; + + switch (round_mode) { + case TRIG_ROUND_NEAREST: + default: + divider = (*nanosec + base / 2) / base; + break; + case TRIG_ROUND_DOWN: + divider = (*nanosec) / base; + break; + case TRIG_ROUND_UP: + divider = (*nanosec + base - 1) / base; + break; + } + if (divider < 2) + divider = 2; /* min is divide by 2 */ + + /* Note: we don't check for max, because different timers + have different ranges */ + + *nanosec = base * divider; + return divider - 1; /* countdown is divisor+1 */ } /* @@ -2149,89 +2103,80 @@ static int rtd_ns_to_timer_base ( return the proper counter value (divider-1) for the internal clock. Sets the original period to be the true value. */ -static int rtd_ns_to_timer ( - unsigned int *ns, - int round_mode) +static int rtd_ns_to_timer(unsigned int *ns, int round_mode) { - return rtd_ns_to_timer_base (ns, round_mode, RTD_CLOCK_BASE); + return rtd_ns_to_timer_base(ns, round_mode, RTD_CLOCK_BASE); } /* Output one (or more) analog values to a single port as fast as possible. */ -static int rtd_ao_winsn ( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int rtd_ao_winsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN (insn->chanspec); - int range = CR_RANGE (insn->chanspec); - - /* Configure the output range (table index matches the range values) */ - RtdDacRange (dev, chan, range); - - /* Writing a list of values to an AO channel is probably not - * very useful, but that's how the interface is defined. */ - for (i=0; i < insn->n; ++i){ - int val = data[i] << 3; - int stat = 0; /* initialize to avoid bogus warning */ - int ii; - - /* VERIFY: comedi range and offset conversions */ - - if ((range > 1) /* bipolar */ - && (data[i] < 2048)) { - /* offset and sign extend */ - val = (((int)data[i]) - 2048) << 3; - } else { /* unipolor */ - val = data[i] << 3; - } + int i; + int chan = CR_CHAN(insn->chanspec); + int range = CR_RANGE(insn->chanspec); + + /* Configure the output range (table index matches the range values) */ + RtdDacRange(dev, chan, range); + + /* Writing a list of values to an AO channel is probably not + * very useful, but that's how the interface is defined. */ + for (i = 0; i < insn->n; ++i) { + int val = data[i] << 3; + int stat = 0; /* initialize to avoid bogus warning */ + int ii; + + /* VERIFY: comedi range and offset conversions */ + + if ((range > 1) /* bipolar */ + &&(data[i] < 2048)) { + /* offset and sign extend */ + val = (((int)data[i]) - 2048) << 3; + } else { /* unipolor */ + val = data[i] << 3; + } - DPRINTK("comedi: rtd520 DAC chan=%d range=%d writing %d as 0x%x\n", - chan, range, data[i], val); + DPRINTK("comedi: rtd520 DAC chan=%d range=%d writing %d as 0x%x\n", chan, range, data[i], val); - /* a typical programming sequence */ - RtdDacFifoPut (dev, chan, val); /* put the value in */ - RtdDacUpdate (dev, chan); /* trigger the conversion */ + /* a typical programming sequence */ + RtdDacFifoPut(dev, chan, val); /* put the value in */ + RtdDacUpdate(dev, chan); /* trigger the conversion */ - devpriv->aoValue[chan] = data[i]; /* save for read back */ + devpriv->aoValue[chan] = data[i]; /* save for read back */ - for (ii = 0; ii < RTD_DAC_TIMEOUT; ++ii) { - stat = RtdFifoStatus (dev); - /* 1 -> not empty */ - if (stat & ((0 == chan) ? FS_DAC1_EMPTY : FS_DAC2_EMPTY)) - break; - WAIT_QUIETLY; - } - if (ii >= RTD_DAC_TIMEOUT) { - DPRINTK("rtd520: Error: DAC never finished! FifoStatus=0x%x\n", - stat ^ 0x6666); - return -ETIMEDOUT; + for (ii = 0; ii < RTD_DAC_TIMEOUT; ++ii) { + stat = RtdFifoStatus(dev); + /* 1 -> not empty */ + if (stat & ((0 == chan) ? FS_DAC1_EMPTY : + FS_DAC2_EMPTY)) + break; + WAIT_QUIETLY; + } + if (ii >= RTD_DAC_TIMEOUT) { + DPRINTK("rtd520: Error: DAC never finished! FifoStatus=0x%x\n", stat ^ 0x6666); + return -ETIMEDOUT; + } } - } - /* return the number of samples read/written */ - return i; + /* return the number of samples read/written */ + 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 rtd_ao_rinsn ( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int rtd_ao_rinsn(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i; - int chan = CR_CHAN(insn->chanspec); + int i; + int chan = CR_CHAN(insn->chanspec); - for (i=0; i < insn->n; i++) { - data[i] = devpriv->aoValue[chan]; - } + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->aoValue[chan]; + } - return i; + return i; } /* @@ -2244,80 +2189,74 @@ static int rtd_ao_rinsn ( * This allows packed reading/writing of the DIO channels. The * comedi core can convert between insn_bits and insn_read/write */ -static int rtd_dio_insn_bits ( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int rtd_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - if (insn->n!=2) return -EINVAL; + if (insn->n != 2) + return -EINVAL; - /* The insn data is a mask in data[0] and the new data - * in data[1], each channel cooresponding to a bit. */ - if (data[0]) { - s->state &= ~data[0]; - s->state |= data[0]&data[1]; + /* The insn data is a mask in data[0] and the new data + * in data[1], each channel cooresponding to a bit. */ + if (data[0]) { + s->state &= ~data[0]; + s->state |= data[0] & data[1]; - /* Write out the new digital output lines */ - RtdDio0Write (dev, s->state); - } - /* on return, data[1] contains the value of the digital - * input lines. */ - data[1] = RtdDio0Read (dev); + /* Write out the new digital output lines */ + RtdDio0Write(dev, s->state); + } + /* on return, data[1] contains the value of the digital + * input lines. */ + data[1] = RtdDio0Read(dev); - /*DPRINTK("rtd520:port_0 wrote: 0x%x read: 0x%x\n", s->state, data[1]);*/ + /*DPRINTK("rtd520:port_0 wrote: 0x%x read: 0x%x\n", s->state, data[1]); */ - return 2; + return 2; } /* Configure one bit on a IO port as Input or Output (hence the name :-). */ -static int rtd_dio_insn_config ( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int rtd_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); - /* The input or output configuration of each digital line is - * configured by a special insn_config instruction. chanspec - * contains the channel to be changed, and data[0] contains the - * value COMEDI_INPUT or COMEDI_OUTPUT. */ - switch(data[0]) - { + /* The input or output configuration of each digital line is + * configured by a special insn_config instruction. chanspec + * contains the channel to be changed, and data[0] contains the + * value COMEDI_INPUT or COMEDI_OUTPUT. */ + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<io_bits |= 1 << chan; /* 1 means Out */ break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<io_bits &= ~(1 << chan); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1< + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: return -EINVAL; } - DPRINTK("rtd520: port_0_direction=0x%x (1 means out)\n", s->io_bits); - /* TODO support digital match interrupts and strobes */ - RtdDioStatusWrite (dev, 0x01); /* make Dio0Ctrl point to direction */ - RtdDio0CtrlWrite (dev, s->io_bits); /* set direction 1 means Out */ - RtdDioStatusWrite (dev, 0); /* make Dio0Ctrl clear interrupts */ + DPRINTK("rtd520: port_0_direction=0x%x (1 means out)\n", s->io_bits); + /* TODO support digital match interrupts and strobes */ + RtdDioStatusWrite(dev, 0x01); /* make Dio0Ctrl point to direction */ + RtdDio0CtrlWrite(dev, s->io_bits); /* set direction 1 means Out */ + RtdDioStatusWrite(dev, 0); /* make Dio0Ctrl clear interrupts */ - /* port1 can only be all input or all output */ + /* port1 can only be all input or all output */ - /* there are also 2 user input lines and 2 user output lines */ + /* there are also 2 user input lines and 2 user output lines */ - return 1; + return 1; } - /* * A convenient macro that defines init_module() and cleanup_module(), * as necessary. */ COMEDI_INITCLEANUP(rtd520Driver); - diff --git a/comedi/drivers/rtd520.h b/comedi/drivers/rtd520.h index df674ab4..78c90a26 100644 --- a/comedi/drivers/rtd520.h +++ b/comedi/drivers/rtd520.h @@ -29,147 +29,145 @@ LAS0 Runtime Area Local Address Space 0 Offset Read Function Write Function */ -#define LAS0_SPARE_00 0x0000 // - - -#define LAS0_SPARE_04 0x0004 // - - -#define LAS0_USER_IO 0x0008 // Read User Inputs Write User Outputs -#define LAS0_SPARE_0C 0x000C // - - -#define LAS0_ADC 0x0010 // Read FIFO Status Software A/D Start -#define LAS0_DAC1 0x0014 // - Software D/A1 Update -#define LAS0_DAC2 0x0018 // - Software D/A2 Update -#define LAS0_SPARE_1C 0x001C // - - -#define LAS0_SPARE_20 0x0020 // - - -#define LAS0_DAC 0x0024 // - Software Simultaneous D/A1 and D/A2 Update -#define LAS0_PACER 0x0028 // Software Pacer Start Software Pacer Stop -#define LAS0_TIMER 0x002C // Read Timer Counters Status HDIN Software Trigger -#define LAS0_IT 0x0030 // Read Interrupt Status Write Interrupt Enable Mask Register -#define LAS0_CLEAR 0x0034 // Clear ITs set by Clear Mask Set Interrupt Clear Mask -#define LAS0_OVERRUN 0x0038 // Read pending interrupts Clear Overrun Register -#define LAS0_SPARE_3C 0x003C // - - +#define LAS0_SPARE_00 0x0000 // - - +#define LAS0_SPARE_04 0x0004 // - - +#define LAS0_USER_IO 0x0008 // Read User Inputs Write User Outputs +#define LAS0_SPARE_0C 0x000C // - - +#define LAS0_ADC 0x0010 // Read FIFO Status Software A/D Start +#define LAS0_DAC1 0x0014 // - Software D/A1 Update +#define LAS0_DAC2 0x0018 // - Software D/A2 Update +#define LAS0_SPARE_1C 0x001C // - - +#define LAS0_SPARE_20 0x0020 // - - +#define LAS0_DAC 0x0024 // - Software Simultaneous D/A1 and D/A2 Update +#define LAS0_PACER 0x0028 // Software Pacer Start Software Pacer Stop +#define LAS0_TIMER 0x002C // Read Timer Counters Status HDIN Software Trigger +#define LAS0_IT 0x0030 // Read Interrupt Status Write Interrupt Enable Mask Register +#define LAS0_CLEAR 0x0034 // Clear ITs set by Clear Mask Set Interrupt Clear Mask +#define LAS0_OVERRUN 0x0038 // Read pending interrupts Clear Overrun Register +#define LAS0_SPARE_3C 0x003C // - - /* LAS0 Runtime Area Timer/Counter,Dig.IO Name Local Address Function */ -#define LAS0_PCLK 0x0040 // Pacer Clock value (24bit) Pacer Clock load (24bit) -#define LAS0_BCLK 0x0044 // Burst Clock value (10bit) Burst Clock load (10bit) -#define LAS0_ADC_SCNT 0x0048 // A/D Sample counter value (10bit) A/D Sample counter load (10bit) -#define LAS0_DAC1_UCNT 0x004C // D/A1 Update counter value (10 bit) D/A1 Update counter load (10bit) -#define LAS0_DAC2_UCNT 0x0050 // D/A2 Update counter value (10 bit) D/A2 Update counter load (10bit) -#define LAS0_DCNT 0x0054 // Delay counter value (16 bit) Delay counter load (16bit) -#define LAS0_ACNT 0x0058 // About counter value (16 bit) About counter load (16bit) -#define LAS0_DAC_CLK 0x005C // DAC clock value (16bit) DAC clock load (16bit) -#define LAS0_UTC0 0x0060 // 8254 TC Counter 0 User TC 0 value Load count in TC Counter 0 -#define LAS0_UTC1 0x0064 // 8254 TC Counter 1 User TC 1 value Load count in TC Counter 1 -#define LAS0_UTC2 0x0068 // 8254 TC Counter 2 User TC 2 value Load count in TC Counter 2 -#define LAS0_UTC_CTRL 0x006C // 8254 TC Control Word Program counter mode for TC -#define LAS0_DIO0 0x0070 // Digital I/O Port 0 Read Port Digital I/O Port 0 Write Port -#define LAS0_DIO1 0x0074 // Digital I/O Port 1 Read Port Digital I/O Port 1 Write Port -#define LAS0_DIO0_CTRL 0x0078 // Clear digital IRQ status flag/read Clear digital chip/program Port 0 -#define LAS0_DIO_STATUS 0x007C // Read Digital I/O Status word Program digital control register & +#define LAS0_PCLK 0x0040 // Pacer Clock value (24bit) Pacer Clock load (24bit) +#define LAS0_BCLK 0x0044 // Burst Clock value (10bit) Burst Clock load (10bit) +#define LAS0_ADC_SCNT 0x0048 // A/D Sample counter value (10bit) A/D Sample counter load (10bit) +#define LAS0_DAC1_UCNT 0x004C // D/A1 Update counter value (10 bit) D/A1 Update counter load (10bit) +#define LAS0_DAC2_UCNT 0x0050 // D/A2 Update counter value (10 bit) D/A2 Update counter load (10bit) +#define LAS0_DCNT 0x0054 // Delay counter value (16 bit) Delay counter load (16bit) +#define LAS0_ACNT 0x0058 // About counter value (16 bit) About counter load (16bit) +#define LAS0_DAC_CLK 0x005C // DAC clock value (16bit) DAC clock load (16bit) +#define LAS0_UTC0 0x0060 // 8254 TC Counter 0 User TC 0 value Load count in TC Counter 0 +#define LAS0_UTC1 0x0064 // 8254 TC Counter 1 User TC 1 value Load count in TC Counter 1 +#define LAS0_UTC2 0x0068 // 8254 TC Counter 2 User TC 2 value Load count in TC Counter 2 +#define LAS0_UTC_CTRL 0x006C // 8254 TC Control Word Program counter mode for TC +#define LAS0_DIO0 0x0070 // Digital I/O Port 0 Read Port Digital I/O Port 0 Write Port +#define LAS0_DIO1 0x0074 // Digital I/O Port 1 Read Port Digital I/O Port 1 Write Port +#define LAS0_DIO0_CTRL 0x0078 // Clear digital IRQ status flag/read Clear digital chip/program Port 0 +#define LAS0_DIO_STATUS 0x007C // Read Digital I/O Status word Program digital control register & /* LAS0 Setup Area Name Local Address Function */ -#define LAS0_BOARD_RESET 0x0100 // Board reset -#define LAS0_DMA0_SRC 0x0104 // DMA 0 Sources select -#define LAS0_DMA1_SRC 0x0108 // DMA 1 Sources select -#define LAS0_ADC_CONVERSION 0x010C // A/D Conversion Signal select -#define LAS0_BURST_START 0x0110 // Burst Clock Start Trigger select -#define LAS0_PACER_START 0x0114 // Pacer Clock Start Trigger select -#define LAS0_PACER_STOP 0x0118 // Pacer Clock Stop Trigger select -#define LAS0_ACNT_STOP_ENABLE 0x011C // About Counter Stop Enable -#define LAS0_PACER_REPEAT 0x0120 // Pacer Start Trigger Mode select -#define LAS0_DIN_START 0x0124 // High Speed Digital Input Sampling Signal select -#define LAS0_DIN_FIFO_CLEAR 0x0128 // Digital Input FIFO Clear -#define LAS0_ADC_FIFO_CLEAR 0x012C // A/D FIFO Clear -#define LAS0_CGT_WRITE 0x0130 // Channel Gain Table Write -#define LAS0_CGL_WRITE 0x0134 // Channel Gain Latch Write -#define LAS0_CG_DATA 0x0138 // Digital Table Write -#define LAS0_CGT_ENABLE 0x013C // Channel Gain Table Enable -#define LAS0_CG_ENABLE 0x0140 // Digital Table Enable -#define LAS0_CGT_PAUSE 0x0144 // Table Pause Enable -#define LAS0_CGT_RESET 0x0148 // Reset Channel Gain Table -#define LAS0_CGT_CLEAR 0x014C // Clear Channel Gain Table -#define LAS0_DAC1_CTRL 0x0150 // D/A1 output type/range -#define LAS0_DAC1_SRC 0x0154 // D/A1 update source -#define LAS0_DAC1_CYCLE 0x0158 // D/A1 cycle mode -#define LAS0_DAC1_RESET 0x015C // D/A1 FIFO reset -#define LAS0_DAC1_FIFO_CLEAR 0x0160 // D/A1 FIFO clear -#define LAS0_DAC2_CTRL 0x0164 // D/A2 output type/range -#define LAS0_DAC2_SRC 0x0168 // D/A2 update source -#define LAS0_DAC2_CYCLE 0x016C // D/A2 cycle mode -#define LAS0_DAC2_RESET 0x0170 // D/A2 FIFO reset -#define LAS0_DAC2_FIFO_CLEAR 0x0174 // D/A2 FIFO clear -#define LAS0_ADC_SCNT_SRC 0x0178 // A/D Sample Counter Source select -#define LAS0_PACER_SELECT 0x0180 // Pacer Clock select -#define LAS0_SBUS0_SRC 0x0184 // SyncBus 0 Source select -#define LAS0_SBUS0_ENABLE 0x0188 // SyncBus 0 enable -#define LAS0_SBUS1_SRC 0x018C // SyncBus 1 Source select -#define LAS0_SBUS1_ENABLE 0x0190 // SyncBus 1 enable -#define LAS0_SBUS2_SRC 0x0198 // SyncBus 2 Source select -#define LAS0_SBUS2_ENABLE 0x019C // SyncBus 2 enable -#define LAS0_ETRG_POLARITY 0x01A4 // External Trigger polarity select -#define LAS0_EINT_POLARITY 0x01A8 // External Interrupt polarity select -#define LAS0_UTC0_CLOCK 0x01AC // UTC0 Clock select -#define LAS0_UTC0_GATE 0x01B0 // UTC0 Gate select -#define LAS0_UTC1_CLOCK 0x01B4 // UTC1 Clock select -#define LAS0_UTC1_GATE 0x01B8 // UTC1 Gate select -#define LAS0_UTC2_CLOCK 0x01BC // UTC2 Clock select -#define LAS0_UTC2_GATE 0x01C0 // UTC2 Gate select -#define LAS0_UOUT0_SELECT 0x01C4 // User Output 0 source select -#define LAS0_UOUT1_SELECT 0x01C8 // User Output 1 source select -#define LAS0_DMA0_RESET 0x01CC // DMA0 Request state machine reset -#define LAS0_DMA1_RESET 0x01D0 // DMA1 Request state machine reset +#define LAS0_BOARD_RESET 0x0100 // Board reset +#define LAS0_DMA0_SRC 0x0104 // DMA 0 Sources select +#define LAS0_DMA1_SRC 0x0108 // DMA 1 Sources select +#define LAS0_ADC_CONVERSION 0x010C // A/D Conversion Signal select +#define LAS0_BURST_START 0x0110 // Burst Clock Start Trigger select +#define LAS0_PACER_START 0x0114 // Pacer Clock Start Trigger select +#define LAS0_PACER_STOP 0x0118 // Pacer Clock Stop Trigger select +#define LAS0_ACNT_STOP_ENABLE 0x011C // About Counter Stop Enable +#define LAS0_PACER_REPEAT 0x0120 // Pacer Start Trigger Mode select +#define LAS0_DIN_START 0x0124 // High Speed Digital Input Sampling Signal select +#define LAS0_DIN_FIFO_CLEAR 0x0128 // Digital Input FIFO Clear +#define LAS0_ADC_FIFO_CLEAR 0x012C // A/D FIFO Clear +#define LAS0_CGT_WRITE 0x0130 // Channel Gain Table Write +#define LAS0_CGL_WRITE 0x0134 // Channel Gain Latch Write +#define LAS0_CG_DATA 0x0138 // Digital Table Write +#define LAS0_CGT_ENABLE 0x013C // Channel Gain Table Enable +#define LAS0_CG_ENABLE 0x0140 // Digital Table Enable +#define LAS0_CGT_PAUSE 0x0144 // Table Pause Enable +#define LAS0_CGT_RESET 0x0148 // Reset Channel Gain Table +#define LAS0_CGT_CLEAR 0x014C // Clear Channel Gain Table +#define LAS0_DAC1_CTRL 0x0150 // D/A1 output type/range +#define LAS0_DAC1_SRC 0x0154 // D/A1 update source +#define LAS0_DAC1_CYCLE 0x0158 // D/A1 cycle mode +#define LAS0_DAC1_RESET 0x015C // D/A1 FIFO reset +#define LAS0_DAC1_FIFO_CLEAR 0x0160 // D/A1 FIFO clear +#define LAS0_DAC2_CTRL 0x0164 // D/A2 output type/range +#define LAS0_DAC2_SRC 0x0168 // D/A2 update source +#define LAS0_DAC2_CYCLE 0x016C // D/A2 cycle mode +#define LAS0_DAC2_RESET 0x0170 // D/A2 FIFO reset +#define LAS0_DAC2_FIFO_CLEAR 0x0174 // D/A2 FIFO clear +#define LAS0_ADC_SCNT_SRC 0x0178 // A/D Sample Counter Source select +#define LAS0_PACER_SELECT 0x0180 // Pacer Clock select +#define LAS0_SBUS0_SRC 0x0184 // SyncBus 0 Source select +#define LAS0_SBUS0_ENABLE 0x0188 // SyncBus 0 enable +#define LAS0_SBUS1_SRC 0x018C // SyncBus 1 Source select +#define LAS0_SBUS1_ENABLE 0x0190 // SyncBus 1 enable +#define LAS0_SBUS2_SRC 0x0198 // SyncBus 2 Source select +#define LAS0_SBUS2_ENABLE 0x019C // SyncBus 2 enable +#define LAS0_ETRG_POLARITY 0x01A4 // External Trigger polarity select +#define LAS0_EINT_POLARITY 0x01A8 // External Interrupt polarity select +#define LAS0_UTC0_CLOCK 0x01AC // UTC0 Clock select +#define LAS0_UTC0_GATE 0x01B0 // UTC0 Gate select +#define LAS0_UTC1_CLOCK 0x01B4 // UTC1 Clock select +#define LAS0_UTC1_GATE 0x01B8 // UTC1 Gate select +#define LAS0_UTC2_CLOCK 0x01BC // UTC2 Clock select +#define LAS0_UTC2_GATE 0x01C0 // UTC2 Gate select +#define LAS0_UOUT0_SELECT 0x01C4 // User Output 0 source select +#define LAS0_UOUT1_SELECT 0x01C8 // User Output 1 source select +#define LAS0_DMA0_RESET 0x01CC // DMA0 Request state machine reset +#define LAS0_DMA1_RESET 0x01D0 // DMA1 Request state machine reset /* LAS1 Name Local Address Function */ -#define LAS1_ADC_FIFO 0x0000 // Read A/D FIFO (16bit) - -#define LAS1_HDIO_FIFO 0x0004 // Read High Speed Digital Input FIFO (16bit) - -#define LAS1_DAC1_FIFO 0x0008 // - Write D/A1 FIFO (16bit) -#define LAS1_DAC2_FIFO 0x000C // - Write D/A2 FIFO (16bit) +#define LAS1_ADC_FIFO 0x0000 // Read A/D FIFO (16bit) - +#define LAS1_HDIO_FIFO 0x0004 // Read High Speed Digital Input FIFO (16bit) - +#define LAS1_DAC1_FIFO 0x0008 // - Write D/A1 FIFO (16bit) +#define LAS1_DAC2_FIFO 0x000C // - Write D/A2 FIFO (16bit) /* LCFG: PLX 9080 local config & runtime registers Name Local Address Function */ -#define LCFG_ITCSR 0x0068 // INTCSR, Interrupt Control/Status Register -#define LCFG_DMAMODE0 0x0080 // DMA Channel 0 Mode Register -#define LCFG_DMAPADR0 0x0084 // DMA Channel 0 PCI Address Register -#define LCFG_DMALADR0 0x0088 // DMA Channel 0 Local Address Reg -#define LCFG_DMASIZ0 0x008C // DMA Channel 0 Transfer Size (Bytes) Register -#define LCFG_DMADPR0 0x0090 // DMA Channel 0 Descriptor Pointer Register -#define LCFG_DMAMODE1 0x0094 // DMA Channel 1 Mode Register -#define LCFG_DMAPADR1 0x0098 // DMA Channel 1 PCI Address Register -#define LCFG_DMALADR1 0x009C // DMA Channel 1 Local Address Register -#define LCFG_DMASIZ1 0x00A0 // DMA Channel 1 Transfer Size (Bytes) Register -#define LCFG_DMADPR1 0x00A4 // DMA Channel 1 Descriptor Pointer Register -#define LCFG_DMACSR0 0x00A8 // DMA Channel 0 Command/Status Register -#define LCFG_DMACSR1 0x00A9 // DMA Channel 0 Command/Status Register -#define LCFG_DMAARB 0x00AC // DMA Arbitration Register -#define LCFG_DMATHR 0x00B0 // DMA Threshold Register - - +#define LCFG_ITCSR 0x0068 // INTCSR, Interrupt Control/Status Register +#define LCFG_DMAMODE0 0x0080 // DMA Channel 0 Mode Register +#define LCFG_DMAPADR0 0x0084 // DMA Channel 0 PCI Address Register +#define LCFG_DMALADR0 0x0088 // DMA Channel 0 Local Address Reg +#define LCFG_DMASIZ0 0x008C // DMA Channel 0 Transfer Size (Bytes) Register +#define LCFG_DMADPR0 0x0090 // DMA Channel 0 Descriptor Pointer Register +#define LCFG_DMAMODE1 0x0094 // DMA Channel 1 Mode Register +#define LCFG_DMAPADR1 0x0098 // DMA Channel 1 PCI Address Register +#define LCFG_DMALADR1 0x009C // DMA Channel 1 Local Address Register +#define LCFG_DMASIZ1 0x00A0 // DMA Channel 1 Transfer Size (Bytes) Register +#define LCFG_DMADPR1 0x00A4 // DMA Channel 1 Descriptor Pointer Register +#define LCFG_DMACSR0 0x00A8 // DMA Channel 0 Command/Status Register +#define LCFG_DMACSR1 0x00A9 // DMA Channel 0 Command/Status Register +#define LCFG_DMAARB 0x00AC // DMA Arbitration Register +#define LCFG_DMATHR 0x00B0 // DMA Threshold Register /*====================================================================== Resister bit definitions ======================================================================*/ // FIFO Status Word Bits (RtdFifoStatus) -#define FS_DAC1_EMPTY 0x0001 // D0 - DAC1 FIFO not empty -#define FS_DAC1_HEMPTY 0x0002 // D1 - DAC1 FIFO not half empty -#define FS_DAC1_FULL 0x0004 // D2 - DAC1 FIFO not full -#define FS_DAC2_EMPTY 0x0010 // D4 - DAC2 FIFO not empty -#define FS_DAC2_HEMPTY 0x0020 // D5 - DAC2 FIFO not half empty -#define FS_DAC2_FULL 0x0040 // D6 - DAC2 FIFO not full -#define FS_ADC_EMPTY 0x0100 // D8 - ADC FIFO not empty -#define FS_ADC_HEMPTY 0x0200 // D9 - ADC FIFO not half empty -#define FS_ADC_FULL 0x0400 // D10 - ADC FIFO not full -#define FS_DIN_EMPTY 0x1000 // D12 - DIN FIFO not empty -#define FS_DIN_HEMPTY 0x2000 // D13 - DIN FIFO not half empty -#define FS_DIN_FULL 0x4000 // D14 - DIN FIFO not full +#define FS_DAC1_EMPTY 0x0001 // D0 - DAC1 FIFO not empty +#define FS_DAC1_HEMPTY 0x0002 // D1 - DAC1 FIFO not half empty +#define FS_DAC1_FULL 0x0004 // D2 - DAC1 FIFO not full +#define FS_DAC2_EMPTY 0x0010 // D4 - DAC2 FIFO not empty +#define FS_DAC2_HEMPTY 0x0020 // D5 - DAC2 FIFO not half empty +#define FS_DAC2_FULL 0x0040 // D6 - DAC2 FIFO not full +#define FS_ADC_EMPTY 0x0100 // D8 - ADC FIFO not empty +#define FS_ADC_HEMPTY 0x0200 // D9 - ADC FIFO not half empty +#define FS_ADC_FULL 0x0400 // D10 - ADC FIFO not full +#define FS_DIN_EMPTY 0x1000 // D12 - DIN FIFO not empty +#define FS_DIN_HEMPTY 0x2000 // D13 - DIN FIFO not half empty +#define FS_DIN_FULL 0x4000 // D14 - DIN FIFO not full // Timer Status Word Bits (GetTimerStatus) #define TS_PCLK_GATE 0x0001 @@ -186,172 +184,171 @@ // triggered only by Software Pacer Start Command, 1 - Pacer Clock can // be start triggered] - // External Trigger polarity select // External Interrupt polarity select #define POL_POSITIVE 0x0 // positive edge #define POL_NEGATIVE 0x1 // negative edge // User Output Signal select (SetUout0Source, SetUout1Source) -#define UOUT_ADC 0x0 // A/D Conversion Signal -#define UOUT_DAC1 0x1 // D/A1 Update -#define UOUT_DAC2 0x2 // D/A2 Update -#define UOUT_SOFTWARE 0x3 // Software Programmable +#define UOUT_ADC 0x0 // A/D Conversion Signal +#define UOUT_DAC1 0x1 // D/A1 Update +#define UOUT_DAC2 0x2 // D/A2 Update +#define UOUT_SOFTWARE 0x3 // Software Programmable // Pacer clock select (SetPacerSource) -#define PCLK_INTERNAL 1 // Internal Pacer Clock -#define PCLK_EXTERNAL 0 // External Pacer Clock +#define PCLK_INTERNAL 1 // Internal Pacer Clock +#define PCLK_EXTERNAL 0 // External Pacer Clock // A/D Sample Counter Sources (SetAdcntSource, SetupSampleCounter) -#define ADC_SCNT_CGT_RESET 0x0 // needs restart with StartPacer +#define ADC_SCNT_CGT_RESET 0x0 // needs restart with StartPacer #define ADC_SCNT_FIFO_WRITE 0x1 // A/D Conversion Signal Select (for SetConversionSelect) -#define ADC_START_SOFTWARE 0x0 // Software A/D Start -#define ADC_START_PCLK 0x1 // Pacer Clock (Ext. Int. see Func.509) -#define ADC_START_BCLK 0x2 // Burst Clock -#define ADC_START_DIGITAL_IT 0x3 // Digital Interrupt -#define ADC_START_DAC1_MARKER1 0x4 // D/A 1 Data Marker 1 -#define ADC_START_DAC2_MARKER1 0x5 // D/A 2 Data Marker 1 -#define ADC_START_SBUS0 0x6 // SyncBus 0 -#define ADC_START_SBUS1 0x7 // SyncBus 1 -#define ADC_START_SBUS2 0x8 // SyncBus 2 +#define ADC_START_SOFTWARE 0x0 // Software A/D Start +#define ADC_START_PCLK 0x1 // Pacer Clock (Ext. Int. see Func.509) +#define ADC_START_BCLK 0x2 // Burst Clock +#define ADC_START_DIGITAL_IT 0x3 // Digital Interrupt +#define ADC_START_DAC1_MARKER1 0x4 // D/A 1 Data Marker 1 +#define ADC_START_DAC2_MARKER1 0x5 // D/A 2 Data Marker 1 +#define ADC_START_SBUS0 0x6 // SyncBus 0 +#define ADC_START_SBUS1 0x7 // SyncBus 1 +#define ADC_START_SBUS2 0x8 // SyncBus 2 // Burst Clock start trigger select (SetBurstStart) -#define BCLK_START_SOFTWARE 0x0 // Software A/D Start (StartBurst) -#define BCLK_START_PCLK 0x1 // Pacer Clock -#define BCLK_START_ETRIG 0x2 // External Trigger -#define BCLK_START_DIGITAL_IT 0x3 // Digital Interrupt -#define BCLK_START_SBUS0 0x4 // SyncBus 0 -#define BCLK_START_SBUS1 0x5 // SyncBus 1 -#define BCLK_START_SBUS2 0x6 // SyncBus 2 +#define BCLK_START_SOFTWARE 0x0 // Software A/D Start (StartBurst) +#define BCLK_START_PCLK 0x1 // Pacer Clock +#define BCLK_START_ETRIG 0x2 // External Trigger +#define BCLK_START_DIGITAL_IT 0x3 // Digital Interrupt +#define BCLK_START_SBUS0 0x4 // SyncBus 0 +#define BCLK_START_SBUS1 0x5 // SyncBus 1 +#define BCLK_START_SBUS2 0x6 // SyncBus 2 // Pacer Clock start trigger select (SetPacerStart) -#define PCLK_START_SOFTWARE 0x0 // Software Pacer Start (StartPacer) -#define PCLK_START_ETRIG 0x1 // External trigger -#define PCLK_START_DIGITAL_IT 0x2 // Digital interrupt -#define PCLK_START_UTC2 0x3 // User TC 2 out -#define PCLK_START_SBUS0 0x4 // SyncBus 0 -#define PCLK_START_SBUS1 0x5 // SyncBus 1 -#define PCLK_START_SBUS2 0x6 // SyncBus 2 -#define PCLK_START_D_SOFTWARE 0x8 // Delayed Software Pacer Start -#define PCLK_START_D_ETRIG 0x9 // Delayed external trigger -#define PCLK_START_D_DIGITAL_IT 0xA // Delayed digital interrupt -#define PCLK_START_D_UTC2 0xB // Delayed User TC 2 out -#define PCLK_START_D_SBUS0 0xC // Delayed SyncBus 0 -#define PCLK_START_D_SBUS1 0xD // Delayed SyncBus 1 -#define PCLK_START_D_SBUS2 0xE // Delayed SyncBus 2 -#define PCLK_START_ETRIG_GATED 0xF // External Trigger Gated controlled mode +#define PCLK_START_SOFTWARE 0x0 // Software Pacer Start (StartPacer) +#define PCLK_START_ETRIG 0x1 // External trigger +#define PCLK_START_DIGITAL_IT 0x2 // Digital interrupt +#define PCLK_START_UTC2 0x3 // User TC 2 out +#define PCLK_START_SBUS0 0x4 // SyncBus 0 +#define PCLK_START_SBUS1 0x5 // SyncBus 1 +#define PCLK_START_SBUS2 0x6 // SyncBus 2 +#define PCLK_START_D_SOFTWARE 0x8 // Delayed Software Pacer Start +#define PCLK_START_D_ETRIG 0x9 // Delayed external trigger +#define PCLK_START_D_DIGITAL_IT 0xA // Delayed digital interrupt +#define PCLK_START_D_UTC2 0xB // Delayed User TC 2 out +#define PCLK_START_D_SBUS0 0xC // Delayed SyncBus 0 +#define PCLK_START_D_SBUS1 0xD // Delayed SyncBus 1 +#define PCLK_START_D_SBUS2 0xE // Delayed SyncBus 2 +#define PCLK_START_ETRIG_GATED 0xF // External Trigger Gated controlled mode // Pacer Clock Stop Trigger select (SetPacerStop) -#define PCLK_STOP_SOFTWARE 0x0 // Software Pacer Stop (StopPacer) -#define PCLK_STOP_ETRIG 0x1 // External Trigger -#define PCLK_STOP_DIGITAL_IT 0x2 // Digital Interrupt -#define PCLK_STOP_ACNT 0x3 // About Counter -#define PCLK_STOP_UTC2 0x4 // User TC2 out -#define PCLK_STOP_SBUS0 0x5 // SyncBus 0 -#define PCLK_STOP_SBUS1 0x6 // SyncBus 1 -#define PCLK_STOP_SBUS2 0x7 // SyncBus 2 -#define PCLK_STOP_A_SOFTWARE 0x8 // About Software Pacer Stop -#define PCLK_STOP_A_ETRIG 0x9 // About External Trigger -#define PCLK_STOP_A_DIGITAL_IT 0xA // About Digital Interrupt -#define PCLK_STOP_A_UTC2 0xC // About User TC2 out -#define PCLK_STOP_A_SBUS0 0xD // About SyncBus 0 -#define PCLK_STOP_A_SBUS1 0xE // About SyncBus 1 -#define PCLK_STOP_A_SBUS2 0xF // About SyncBus 2 +#define PCLK_STOP_SOFTWARE 0x0 // Software Pacer Stop (StopPacer) +#define PCLK_STOP_ETRIG 0x1 // External Trigger +#define PCLK_STOP_DIGITAL_IT 0x2 // Digital Interrupt +#define PCLK_STOP_ACNT 0x3 // About Counter +#define PCLK_STOP_UTC2 0x4 // User TC2 out +#define PCLK_STOP_SBUS0 0x5 // SyncBus 0 +#define PCLK_STOP_SBUS1 0x6 // SyncBus 1 +#define PCLK_STOP_SBUS2 0x7 // SyncBus 2 +#define PCLK_STOP_A_SOFTWARE 0x8 // About Software Pacer Stop +#define PCLK_STOP_A_ETRIG 0x9 // About External Trigger +#define PCLK_STOP_A_DIGITAL_IT 0xA // About Digital Interrupt +#define PCLK_STOP_A_UTC2 0xC // About User TC2 out +#define PCLK_STOP_A_SBUS0 0xD // About SyncBus 0 +#define PCLK_STOP_A_SBUS1 0xE // About SyncBus 1 +#define PCLK_STOP_A_SBUS2 0xF // About SyncBus 2 // About Counter Stop Enable -#define ACNT_STOP 0x0 // stop enable -#define ACNT_NO_STOP 0x1 // stop disabled +#define ACNT_STOP 0x0 // stop enable +#define ACNT_NO_STOP 0x1 // stop disabled // DAC update source (SetDAC1Start & SetDAC2Start) -#define DAC_START_SOFTWARE 0x0 // Software Update -#define DAC_START_CGT 0x1 // CGT controlled Update -#define DAC_START_DAC_CLK 0x2 // D/A Clock -#define DAC_START_EPCLK 0x3 // External Pacer Clock -#define DAC_START_SBUS0 0x4 // SyncBus 0 -#define DAC_START_SBUS1 0x5 // SyncBus 1 -#define DAC_START_SBUS2 0x6 // SyncBus 2 +#define DAC_START_SOFTWARE 0x0 // Software Update +#define DAC_START_CGT 0x1 // CGT controlled Update +#define DAC_START_DAC_CLK 0x2 // D/A Clock +#define DAC_START_EPCLK 0x3 // External Pacer Clock +#define DAC_START_SBUS0 0x4 // SyncBus 0 +#define DAC_START_SBUS1 0x5 // SyncBus 1 +#define DAC_START_SBUS2 0x6 // SyncBus 2 // DAC Cycle Mode (SetDAC1Cycle, SetDAC2Cycle, SetupDAC) -#define DAC_CYCLE_SINGLE 0x0 // not cycle -#define DAC_CYCLE_MULTI 0x1 // cycle +#define DAC_CYCLE_SINGLE 0x0 // not cycle +#define DAC_CYCLE_MULTI 0x1 // cycle // 8254 Operation Modes (Set8254Mode, SetupTimerCounter) -#define M8254_EVENT_COUNTER 0 // Event Counter -#define M8254_HW_ONE_SHOT 1 // Hardware-Retriggerable One-Shot -#define M8254_RATE_GENERATOR 2 // Rate Generator -#define M8254_SQUARE_WAVE 3 // Square Wave Mode -#define M8254_SW_STROBE 4 // Software Triggered Strobe -#define M8254_HW_STROBE 5 // Hardware Triggered Strobe (Retriggerable) +#define M8254_EVENT_COUNTER 0 // Event Counter +#define M8254_HW_ONE_SHOT 1 // Hardware-Retriggerable One-Shot +#define M8254_RATE_GENERATOR 2 // Rate Generator +#define M8254_SQUARE_WAVE 3 // Square Wave Mode +#define M8254_SW_STROBE 4 // Software Triggered Strobe +#define M8254_HW_STROBE 5 // Hardware Triggered Strobe (Retriggerable) // User Timer/Counter 0 Clock Select (SetUtc0Clock) -#define CUTC0_8MHZ 0x0 // 8MHz -#define CUTC0_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 -#define CUTC0_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 -#define CUTC0_EXT_PCLK 0x3 // Ext. Pacer Clock +#define CUTC0_8MHZ 0x0 // 8MHz +#define CUTC0_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 +#define CUTC0_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 +#define CUTC0_EXT_PCLK 0x3 // Ext. Pacer Clock // User Timer/Counter 1 Clock Select (SetUtc1Clock) -#define CUTC1_8MHZ 0x0 // 8MHz -#define CUTC1_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 -#define CUTC1_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 -#define CUTC1_EXT_PCLK 0x3 // Ext. Pacer Clock -#define CUTC1_UTC0_OUT 0x4 // User Timer/Counter 0 out -#define CUTC1_DIN_SIGNAL 0x5 // High-Speed Digital Input Sampling signal +#define CUTC1_8MHZ 0x0 // 8MHz +#define CUTC1_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 +#define CUTC1_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 +#define CUTC1_EXT_PCLK 0x3 // Ext. Pacer Clock +#define CUTC1_UTC0_OUT 0x4 // User Timer/Counter 0 out +#define CUTC1_DIN_SIGNAL 0x5 // High-Speed Digital Input Sampling signal // User Timer/Counter 2 Clock Select (SetUtc2Clock) -#define CUTC2_8MHZ 0x0 // 8MHz -#define CUTC2_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 -#define CUTC2_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 -#define CUTC2_EXT_PCLK 0x3 // Ext. Pacer Clock -#define CUTC2_UTC1_OUT 0x4 // User Timer/Counter 1 out +#define CUTC2_8MHZ 0x0 // 8MHz +#define CUTC2_EXT_TC_CLOCK1 0x1 // Ext. TC Clock 1 +#define CUTC2_EXT_TC_CLOCK2 0x2 // Ext. TC Clock 2 +#define CUTC2_EXT_PCLK 0x3 // Ext. Pacer Clock +#define CUTC2_UTC1_OUT 0x4 // User Timer/Counter 1 out // User Timer/Counter 0 Gate Select (SetUtc0Gate) -#define GUTC0_NOT_GATED 0x0 // Not gated -#define GUTC0_GATED 0x1 // Gated -#define GUTC0_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 -#define GUTC0_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 +#define GUTC0_NOT_GATED 0x0 // Not gated +#define GUTC0_GATED 0x1 // Gated +#define GUTC0_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 +#define GUTC0_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 // User Timer/Counter 1 Gate Select (SetUtc1Gate) -#define GUTC1_NOT_GATED 0x0 // Not gated -#define GUTC1_GATED 0x1 // Gated -#define GUTC1_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 -#define GUTC1_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 -#define GUTC1_UTC0_OUT 0x4 // User Timer/Counter 0 out +#define GUTC1_NOT_GATED 0x0 // Not gated +#define GUTC1_GATED 0x1 // Gated +#define GUTC1_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 +#define GUTC1_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 +#define GUTC1_UTC0_OUT 0x4 // User Timer/Counter 0 out // User Timer/Counter 2 Gate Select (SetUtc2Gate) -#define GUTC2_NOT_GATED 0x0 // Not gated -#define GUTC2_GATED 0x1 // Gated -#define GUTC2_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 -#define GUTC2_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 -#define GUTC2_UTC1_OUT 0x4 // User Timer/Counter 1 out +#define GUTC2_NOT_GATED 0x0 // Not gated +#define GUTC2_GATED 0x1 // Gated +#define GUTC2_EXT_TC_GATE1 0x2 // Ext. TC Gate 1 +#define GUTC2_EXT_TC_GATE2 0x3 // Ext. TC Gate 2 +#define GUTC2_UTC1_OUT 0x4 // User Timer/Counter 1 out // Interrupt Source Masks (SetITMask, ClearITMask, GetITStatus) -#define IRQM_ADC_FIFO_WRITE 0x0001 // ADC FIFO Write -#define IRQM_CGT_RESET 0x0002 // Reset CGT -#define IRQM_CGT_PAUSE 0x0008 // Pause CGT -#define IRQM_ADC_ABOUT_CNT 0x0010 // About Counter out -#define IRQM_ADC_DELAY_CNT 0x0020 // Delay Counter out -#define IRQM_ADC_SAMPLE_CNT 0x0040 // ADC Sample Counter -#define IRQM_DAC1_UCNT 0x0080 // DAC1 Update Counter -#define IRQM_DAC2_UCNT 0x0100 // DAC2 Update Counter -#define IRQM_UTC1 0x0200 // User TC1 out -#define IRQM_UTC1_INV 0x0400 // User TC1 out, inverted -#define IRQM_UTC2 0x0800 // User TC2 out -#define IRQM_DIGITAL_IT 0x1000 // Digital Interrupt -#define IRQM_EXTERNAL_IT 0x2000 // External Interrupt -#define IRQM_ETRIG_RISING 0x4000 // External Trigger rising-edge -#define IRQM_ETRIG_FALLING 0x8000 // External Trigger falling-edge +#define IRQM_ADC_FIFO_WRITE 0x0001 // ADC FIFO Write +#define IRQM_CGT_RESET 0x0002 // Reset CGT +#define IRQM_CGT_PAUSE 0x0008 // Pause CGT +#define IRQM_ADC_ABOUT_CNT 0x0010 // About Counter out +#define IRQM_ADC_DELAY_CNT 0x0020 // Delay Counter out +#define IRQM_ADC_SAMPLE_CNT 0x0040 // ADC Sample Counter +#define IRQM_DAC1_UCNT 0x0080 // DAC1 Update Counter +#define IRQM_DAC2_UCNT 0x0100 // DAC2 Update Counter +#define IRQM_UTC1 0x0200 // User TC1 out +#define IRQM_UTC1_INV 0x0400 // User TC1 out, inverted +#define IRQM_UTC2 0x0800 // User TC2 out +#define IRQM_DIGITAL_IT 0x1000 // Digital Interrupt +#define IRQM_EXTERNAL_IT 0x2000 // External Interrupt +#define IRQM_ETRIG_RISING 0x4000 // External Trigger rising-edge +#define IRQM_ETRIG_FALLING 0x8000 // External Trigger falling-edge // DMA Request Sources (LAS0) -#define DMAS_DISABLED 0x0 // DMA Disabled -#define DMAS_ADC_SCNT 0x1 // ADC Sample Counter -#define DMAS_DAC1_UCNT 0x2 // D/A1 Update Counter -#define DMAS_DAC2_UCNT 0x3 // D/A2 Update Counter -#define DMAS_UTC1 0x4 // User TC1 out -#define DMAS_ADFIFO_HALF_FULL 0x8 // A/D FIFO half full -#define DMAS_DAC1_FIFO_HALF_EMPTY 0x9 // D/A1 FIFO half empty -#define DMAS_DAC2_FIFO_HALF_EMPTY 0xA // D/A2 FIFO half empty +#define DMAS_DISABLED 0x0 // DMA Disabled +#define DMAS_ADC_SCNT 0x1 // ADC Sample Counter +#define DMAS_DAC1_UCNT 0x2 // D/A1 Update Counter +#define DMAS_DAC2_UCNT 0x3 // D/A2 Update Counter +#define DMAS_UTC1 0x4 // User TC1 out +#define DMAS_ADFIFO_HALF_FULL 0x8 // A/D FIFO half full +#define DMAS_DAC1_FIFO_HALF_EMPTY 0x9 // D/A1 FIFO half empty +#define DMAS_DAC2_FIFO_HALF_EMPTY 0xA // D/A2 FIFO half empty // DMA Local Addresses (0x40000000+LAS1 offset) #define DMALADDR_ADC 0x40000000 // A/D FIFO @@ -359,37 +356,36 @@ #define DMALADDR_DAC1 0x40000008 // D/A1 FIFO #define DMALADDR_DAC2 0x4000000C // D/A2 FIFO - // Port 0 compare modes (SetDIO0CompareMode) -#define DIO_MODE_EVENT 0 // Event Mode -#define DIO_MODE_MATCH 1 // Match Mode +#define DIO_MODE_EVENT 0 // Event Mode +#define DIO_MODE_MATCH 1 // Match Mode // Digital Table Enable (Port 1 disable) -#define DTBL_DISABLE 0 // Enable Digital Table -#define DTBL_ENABLE 1 // Disable Digital Table +#define DTBL_DISABLE 0 // Enable Digital Table +#define DTBL_ENABLE 1 // Disable Digital Table // Sampling Signal for High Speed Digital Input (SetHdinStart) -#define HDIN_SOFTWARE 0x0 // Software Trigger -#define HDIN_ADC 0x1 // A/D Conversion Signal -#define HDIN_UTC0 0x2 // User TC out 0 -#define HDIN_UTC1 0x3 // User TC out 1 -#define HDIN_UTC2 0x4 // User TC out 2 -#define HDIN_EPCLK 0x5 // External Pacer Clock -#define HDIN_ETRG 0x6 // External Trigger +#define HDIN_SOFTWARE 0x0 // Software Trigger +#define HDIN_ADC 0x1 // A/D Conversion Signal +#define HDIN_UTC0 0x2 // User TC out 0 +#define HDIN_UTC1 0x3 // User TC out 1 +#define HDIN_UTC2 0x4 // User TC out 2 +#define HDIN_EPCLK 0x5 // External Pacer Clock +#define HDIN_ETRG 0x6 // External Trigger // Channel Gain Table / Channel Gain Latch -#define CSC_LATCH 0 // Channel Gain Latch mode -#define CSC_CGT 1 // Channel Gain Table mode +#define CSC_LATCH 0 // Channel Gain Latch mode +#define CSC_CGT 1 // Channel Gain Table mode // Channel Gain Table Pause Enable -#define CGT_PAUSE_DISABLE 0 // Channel Gain Table Pause Disable -#define CGT_PAUSE_ENABLE 1 // Channel Gain Table Pause Enable +#define CGT_PAUSE_DISABLE 0 // Channel Gain Table Pause Disable +#define CGT_PAUSE_ENABLE 1 // Channel Gain Table Pause Enable // DAC output type/range (p63) -#define AOUT_UNIP5 0 // 0..+5 Volt -#define AOUT_UNIP10 1 // 0..+10 Volt -#define AOUT_BIP5 2 // -5..+5 Volt -#define AOUT_BIP10 3 // -10..+10 Volt +#define AOUT_UNIP5 0 // 0..+5 Volt +#define AOUT_UNIP10 1 // 0..+10 Volt +#define AOUT_BIP5 2 // -5..+5 Volt +#define AOUT_BIP10 3 // -10..+10 Volt // Ghannel Gain Table field definitions (p61) // Gain @@ -403,14 +399,14 @@ #define GAIN128 7 // Input range/polarity -#define AIN_BIP5 0 // -5..+5 Volt -#define AIN_BIP10 1 // -10..+10 Volt -#define AIN_UNIP10 2 // 0..+10 Volt +#define AIN_BIP5 0 // -5..+5 Volt +#define AIN_BIP10 1 // -10..+10 Volt +#define AIN_UNIP10 2 // 0..+10 Volt // non referenced single ended select bit -#define NRSE_AGND 0 // AGND referenced SE input -#define NRSE_AINS 1 // AIN SENSE referenced SE input +#define NRSE_AGND 0 // AGND referenced SE input +#define NRSE_AINS 1 // AIN SENSE referenced SE input // single ended vs differential -#define GND_SE 0 // Single-Ended -#define GND_DIFF 1 // Differential +#define GND_SE 0 // Single-Ended +#define GND_DIFF 1 // Differential diff --git a/comedi/drivers/rti800.c b/comedi/drivers/rti800.c index b2297e78..a73a992a 100644 --- a/comedi/drivers/rti800.c +++ b/comedi/drivers/rti800.c @@ -55,7 +55,6 @@ Configuration options: #include - #define RTI800_SIZE 16 #define RTI800_CSR 0 @@ -74,7 +73,6 @@ Configuration options: #define RTI800_9513A_CNTRL 13 #define RTI800_9513A_STATUS 13 - /* * flags for CSR register */ @@ -98,45 +96,50 @@ Configuration options: #include "am9513.h" static const comedi_lrange range_rti800_ai_10_bipolar = { 4, { - BIP_RANGE( 10 ), - BIP_RANGE( 1 ), - BIP_RANGE( 0.1 ), - BIP_RANGE( 0.02 ) -}}; + BIP_RANGE(10), + BIP_RANGE(1), + BIP_RANGE(0.1), + BIP_RANGE(0.02) + } +}; static const comedi_lrange range_rti800_ai_5_bipolar = { 4, { - BIP_RANGE( 5 ), - BIP_RANGE( 0.5 ), - BIP_RANGE( 0.05 ), - BIP_RANGE( 0.01 ) -}}; + BIP_RANGE(5), + BIP_RANGE(0.5), + BIP_RANGE(0.05), + BIP_RANGE(0.01) + } +}; static const comedi_lrange range_rti800_ai_unipolar = { 4, { - UNI_RANGE( 10 ), - UNI_RANGE( 1 ), - UNI_RANGE( 0.1 ), - UNI_RANGE( 0.02 ) -}}; + UNI_RANGE(10), + UNI_RANGE(1), + UNI_RANGE(0.1), + UNI_RANGE(0.02) + } +}; -typedef struct{ +typedef struct { const char *name; int has_ao; -}boardtype; -static const boardtype boardtypes[]={ - { "rti800", 0 }, - { "rti815", 1 }, +} boardtype; +static const boardtype boardtypes[] = { + {"rti800", 0}, + {"rti815", 1}, }; + #define this_board ((const boardtype *)dev->board_ptr) -static int rti800_attach(comedi_device *dev,comedi_devconfig *it); -static int rti800_detach(comedi_device *dev); -static comedi_driver driver_rti800={ - driver_name: "rti800", - module: THIS_MODULE, - attach: rti800_attach, - detach: rti800_detach, - num_names: sizeof(boardtypes)/sizeof(boardtype), - board_name: &boardtypes[0].name, - offset: sizeof(boardtype), +static int rti800_attach(comedi_device * dev, comedi_devconfig * it); +static int rti800_detach(comedi_device * dev); +static comedi_driver driver_rti800 = { + driver_name:"rti800", + module:THIS_MODULE, + attach:rti800_attach, + detach:rti800_detach, + num_names:sizeof(boardtypes) / sizeof(boardtype), + board_name:&boardtypes[0].name, + offset:sizeof(boardtype), }; + COMEDI_INITCLEANUP(driver_rti800); static irqreturn_t rti800_interrupt(int irq, void *dev PT_REGS_ARG); @@ -157,7 +160,7 @@ typedef struct { enum { dac_2comp, dac_straight } dac0_coding, dac1_coding; - const comedi_lrange * ao_range_type_list[2]; + const comedi_lrange *ao_range_type_list[2]; lsampl_t ao_readback[2]; int muxgain_bits; } rti800_private; @@ -172,52 +175,52 @@ static irqreturn_t rti800_interrupt(int irq, void *dev PT_REGS_ARG) } // settling delay times in usec for different gains -static const int gaindelay[]={10,20,40,80}; +static const int gaindelay[] = { 10, 20, 40, 80 }; -static int rti800_ai_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti800_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,t; + int i, t; int status; int chan = CR_CHAN(insn->chanspec); unsigned gain = CR_RANGE(insn->chanspec); unsigned muxgain_bits; - + inb(dev->iobase + RTI800_ADCHI); - outb(0,dev->iobase+RTI800_CLRFLAGS); + outb(0, dev->iobase + RTI800_CLRFLAGS); muxgain_bits = chan | (gain << 5); - if(muxgain_bits != devpriv->muxgain_bits) - { + if (muxgain_bits != devpriv->muxgain_bits) { devpriv->muxgain_bits = muxgain_bits; outb(devpriv->muxgain_bits, dev->iobase + RTI800_MUXGAIN); /* without a delay here, the RTI_OVERRUN bit * gets set, and you will have an error. */ - if(insn->n > 0) - { - BUG_ON(gain >= sizeof(gaindelay) / sizeof(gaindelay[0])); + if (insn->n > 0) { + BUG_ON(gain >= + sizeof(gaindelay) / sizeof(gaindelay[0])); comedi_udelay(gaindelay[gain]); } } - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { outb(0, dev->iobase + RTI800_CONVERT); for (t = RTI800_TIMEOUT; t; t--) { - status=inb(dev->iobase+RTI800_CSR); - if(status & RTI800_OVERRUN){ + status = inb(dev->iobase + RTI800_CSR); + if (status & RTI800_OVERRUN) { rt_printk("rti800: a/d overrun\n"); - outb(0,dev->iobase+RTI800_CLRFLAGS); + outb(0, dev->iobase + RTI800_CLRFLAGS); return -EIO; } - if (status & RTI800_DONE)break; + if (status & RTI800_DONE) + break; comedi_udelay(1); } - if(t == 0){ + if (t == 0) { rt_printk("rti800: timeout\n"); return -ETIME; } data[i] = inb(dev->iobase + RTI800_ADCLO); - data[i] |= (0xf & inb(dev->iobase + RTI800_ADCHI))<<8; + data[i] |= (0xf & inb(dev->iobase + RTI800_ADCHI)) << 8; if (devpriv->adc_coding == adc_2comp) { data[i] ^= 0x800; @@ -227,52 +230,56 @@ static int rti800_ai_insn_read(comedi_device *dev,comedi_subdevice *s, return i; } -static int rti800_ao_insn_read(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti800_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; } -static int rti800_ao_insn_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti800_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); int d; int i; - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { devpriv->ao_readback[chan] = d = data[i]; if (devpriv->dac0_coding == dac_2comp) { d ^= 0x800; } - outb(d & 0xff, dev->iobase + (chan?RTI800_DAC1LO:RTI800_DAC0LO)); - outb(d >> 8, dev->iobase + (chan?RTI800_DAC1HI:RTI800_DAC0HI)); + outb(d & 0xff, + dev->iobase + (chan ? RTI800_DAC1LO : RTI800_DAC0LO)); + outb(d >> 8, + dev->iobase + (chan ? RTI800_DAC1HI : RTI800_DAC0HI)); } return i; } -static int rti800_di_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti800_di_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; data[1] = inb(dev->iobase + RTI800_DI); return 2; } -static int rti800_do_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti800_do_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; /* Outputs are inverted... */ outb(s->state ^ 0xff, dev->iobase + RTI800_DO); } @@ -282,7 +289,6 @@ static int rti800_do_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } - /* options[0] - I/O port options[1] - irq @@ -320,31 +326,31 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) inb(dev->iobase + 0), inb(dev->iobase + 1), inb(dev->iobase + 2), - inb(dev->iobase + 3), - inb(dev->iobase + 4)); + inb(dev->iobase + 3), inb(dev->iobase + 4)); #endif - outb(0,dev->iobase+RTI800_CSR); - inb(dev->iobase+RTI800_ADCHI); - outb(0,dev->iobase+RTI800_CLRFLAGS); + outb(0, dev->iobase + RTI800_CSR); + inb(dev->iobase + RTI800_ADCHI); + outb(0, dev->iobase + RTI800_CLRFLAGS); - irq=it->options[1]; - if(irq){ - printk("( irq = %u )",irq); - if((ret=comedi_request_irq(irq,rti800_interrupt, 0, "rti800", dev))<0){ + irq = it->options[1]; + if (irq) { + printk("( irq = %u )", irq); + if ((ret = comedi_request_irq(irq, rti800_interrupt, 0, + "rti800", dev)) < 0) { printk(" Failed to allocate IRQ\n"); return ret; } - dev->irq=irq; - }else{ + dev->irq = irq; + } else { printk("( no irq )"); } dev->board_name = this_board->name; - if((ret=alloc_subdevices(dev, 4))<0) + if ((ret = alloc_subdevices(dev, 4)) < 0) return ret; - if((ret=alloc_private(dev,sizeof(rti800_private)))<0) + if ((ret = alloc_private(dev, sizeof(rti800_private))) < 0) return ret; devpriv->adc_mux = it->options[2]; @@ -355,14 +361,14 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) devpriv->dac1_range = it->options[7]; devpriv->dac1_coding = it->options[8]; devpriv->muxgain_bits = -1; - - s=dev->subdevices+0; + + s = dev->subdevices + 0; /* ai subdevice */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; - s->n_chan=(devpriv->adc_mux? 16 : 8); - s->insn_read=rti800_ai_insn_read; - s->maxdata=0xfff; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = (devpriv->adc_mux ? 16 : 8); + s->insn_read = rti800_ai_insn_read; + s->maxdata = 0xfff; switch (devpriv->adc_range) { case adc_bipolar10: s->range_table = &range_rti800_ai_10_bipolar; @@ -376,15 +382,15 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) } s++; - if (this_board->has_ao){ + if (this_board->has_ao) { /* ao subdevice (only on rti815) */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=2; - s->insn_read=rti800_ao_insn_read; - s->insn_write=rti800_ao_insn_write; - s->maxdata=0xfff; - s->range_table_list=devpriv->ao_range_type_list; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 2; + s->insn_read = rti800_ao_insn_read; + s->insn_write = rti800_ao_insn_write; + s->maxdata = 0xfff; + s->range_table_list = devpriv->ao_range_type_list; switch (devpriv->dac0_range) { case dac_bipolar10: devpriv->ao_range_type_list[0] = &range_bipolar10; @@ -401,34 +407,33 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) devpriv->ao_range_type_list[1] = &range_unipolar10; break; } - }else{ - s->type=COMEDI_SUBD_UNUSED; + } else { + s->type = COMEDI_SUBD_UNUSED; } s++; /* di */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE; - s->n_chan=8; - s->insn_bits=rti800_di_insn_bits; - s->maxdata=1; - s->range_table=&range_digital; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 8; + s->insn_bits = rti800_di_insn_bits; + s->maxdata = 1; + s->range_table = &range_digital; s++; /* do */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=8; - s->insn_bits=rti800_do_insn_bits; - s->maxdata=1; - s->range_table=&range_digital; - + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 8; + s->insn_bits = rti800_do_insn_bits; + s->maxdata = 1; + s->range_table = &range_digital; /* don't yet know how to deal with counter/timers */ #if 0 s++; /* do */ - s->type=COMEDI_SUBD_TIMER; + s->type = COMEDI_SUBD_TIMER; #endif printk("\n"); @@ -436,17 +441,15 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) return 0; } - static int rti800_detach(comedi_device * dev) { printk("comedi%d: rti800: remove\n", dev->minor); - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, RTI800_SIZE); - if(dev->irq) - comedi_free_irq(dev->irq,dev); + if (dev->irq) + comedi_free_irq(dev->irq, dev); return 0; } - diff --git a/comedi/drivers/rti802.c b/comedi/drivers/rti802.c index a9c416dc..1456e741 100644 --- a/comedi/drivers/rti802.c +++ b/comedi/drivers/rti802.c @@ -41,53 +41,54 @@ Configuration Options: #include - #define RTI802_SIZE 4 #define RTI802_SELECT 0 #define RTI802_DATALOW 1 #define RTI802_DATAHIGH 2 -static int rti802_attach(comedi_device *dev,comedi_devconfig *it); -static int rti802_detach(comedi_device *dev); -static comedi_driver driver_rti802={ - driver_name: "rti802", - module: THIS_MODULE, - attach: rti802_attach, - detach: rti802_detach, +static int rti802_attach(comedi_device * dev, comedi_devconfig * it); +static int rti802_detach(comedi_device * dev); +static comedi_driver driver_rti802 = { + driver_name:"rti802", + module:THIS_MODULE, + attach:rti802_attach, + detach:rti802_detach, }; + COMEDI_INITCLEANUP(driver_rti802); typedef struct { enum { dac_2comp, dac_straight } dac_coding[8]; - const comedi_lrange * range_type_list[8]; + const comedi_lrange *range_type_list[8]; lsampl_t ao_readback[8]; } rti802_private; #define devpriv ((rti802_private *)dev->private) -static int rti802_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti802_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; - for(i=0;in;i++) - data[i]=devpriv->ao_readback[CR_CHAN(insn->chanspec)]; + for (i = 0; i < insn->n; i++) + data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; return i; } -static int rti802_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int rti802_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,d; + int i, d; int chan = CR_CHAN(insn->chanspec); - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { d = devpriv->ao_readback[chan] = data[i]; - if (devpriv->dac_coding[chan] == dac_2comp) d ^= 0x800; + if (devpriv->dac_coding[chan] == dac_2comp) + d ^= 0x800; outb(chan, dev->iobase + RTI802_SELECT); outb(d & 0xff, dev->iobase + RTI802_DATALOW); outb(d >> 8, dev->iobase + RTI802_DATAHIGH); @@ -95,8 +96,6 @@ static int rti802_ao_insn_write(comedi_device *dev, comedi_subdevice *s, return i; } - - static int rti802_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; @@ -113,27 +112,27 @@ static int rti802_attach(comedi_device * dev, comedi_devconfig * it) dev->board_name = "rti802"; - if(alloc_subdevices(dev, 1)<0 || alloc_private(dev,sizeof(rti802_private))){ + if (alloc_subdevices(dev, 1) < 0 + || alloc_private(dev, sizeof(rti802_private))) { return -ENOMEM; } - s=dev->subdevices; + s = dev->subdevices; /* ao subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->maxdata=0xfff; - s->n_chan=8; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->maxdata = 0xfff; + s->n_chan = 8; s->insn_read = rti802_ao_insn_read; s->insn_write = rti802_ao_insn_write; - s->range_table_list=devpriv->range_type_list; + s->range_table_list = devpriv->range_type_list; for (i = 0; i < 8; i++) { devpriv->dac_coding[i] = (it->options[3 + 2 * i]) - ? (dac_straight) - : (dac_2comp); + ? (dac_straight) + : (dac_2comp); devpriv->range_type_list[i] = (it->options[2 + 2 * i]) - ? &range_unipolar10 - : &range_bipolar10; + ? &range_unipolar10 : &range_bipolar10; } printk("\n"); @@ -145,9 +144,8 @@ static int rti802_detach(comedi_device * dev) { printk("comedi%d: rti802: remove\n", dev->minor); - if(dev->iobase) + if (dev->iobase) release_region(dev->iobase, RTI802_SIZE); return 0; } - diff --git a/comedi/drivers/s526.c b/comedi/drivers/s526.c index 82cdf10d..a1ea5c14 100644 --- a/comedi/drivers/s526.c +++ b/comedi/drivers/s526.c @@ -49,7 +49,6 @@ comedi_config /dev/comedi0 s526 0x2C0,0x3 #define S526_START_AI_CONV 0 #define S526_AI_READ 0 - /* Ports */ #define S526_IOSIZE 0x40 #define S526_NUM_PORTS 27 @@ -83,51 +82,48 @@ comedi_config /dev/comedi0 s526 0x2C0,0x3 #define REG_EED 0x32 #define REG_EEC 0x34 - -static const int s526_ports[] = -{ -REG_TCR, -REG_WDC, -REG_DAC, -REG_ADC, -REG_ADD, -REG_DIO, -REG_IER, -REG_ISR, -REG_MSC, -REG_C0L, -REG_C0H, -REG_C0M, -REG_C0C, -REG_C1L, -REG_C1H, -REG_C1M, -REG_C1C, -REG_C2L, -REG_C2H, -REG_C2M, -REG_C2C, -REG_C3L, -REG_C3H, -REG_C3M, -REG_C3C, -REG_EED, -REG_EEC +static const int s526_ports[] = { + REG_TCR, + REG_WDC, + REG_DAC, + REG_ADC, + REG_ADD, + REG_DIO, + REG_IER, + REG_ISR, + REG_MSC, + REG_C0L, + REG_C0H, + REG_C0M, + REG_C0C, + REG_C1L, + REG_C1H, + REG_C1M, + REG_C1C, + REG_C2L, + REG_C2H, + REG_C2M, + REG_C2C, + REG_C3L, + REG_C3H, + REG_C3M, + REG_C3C, + REG_EED, + REG_EEC }; -typedef struct -{ - unsigned short coutSource: 1; - unsigned short coutPolarity: 1; - unsigned short autoLoadResetRcap: 3; - unsigned short hwCtEnableSource: 2; - unsigned short ctEnableCtrl: 2; - unsigned short clockSource: 2; - unsigned short countDir: 1; - unsigned short countDirCtrl: 1; - unsigned short outputRegLatchCtrl: 1; - unsigned short preloadRegSel: 1; - unsigned short reserved: 1; +typedef struct { + unsigned short coutSource:1; + unsigned short coutPolarity:1; + unsigned short autoLoadResetRcap:3; + unsigned short hwCtEnableSource:2; + unsigned short ctEnableCtrl:2; + unsigned short clockSource:2; + unsigned short countDir:1; + unsigned short countDirCtrl:1; + unsigned short outputRegLatchCtrl:1; + unsigned short preloadRegSel:1; + unsigned short reserved:1; } counter_mode_register_t; union { @@ -139,32 +135,28 @@ union { /* Different Application Classes for GPCT Subdevices */ /* The list is not exhaustive and needs discussion! */ -typedef enum -{ - CountingAndTimeMeasurement, - SinglePulseGeneration, - PulseTrainGeneration, - PositionMeasurement, - Miscellaneous +typedef enum { + CountingAndTimeMeasurement, + SinglePulseGeneration, + PulseTrainGeneration, + PositionMeasurement, + Miscellaneous } S526_GPCT_APP_CLASS; - /* Config struct for different GPCT subdevice Application Classes and their options */ -typedef struct s526GPCTConfig -{ +typedef struct s526GPCTConfig { S526_GPCT_APP_CLASS app; int data[MAX_GPCT_CONFIG_DATA]; } s526_gpct_config_t; - /* * Board descriptions for two imaginary boards. Describing the * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct s526_board_struct{ +typedef struct s526_board_struct { const char *name; int gpct_chans; int gpct_bits; @@ -173,19 +165,19 @@ typedef struct s526_board_struct{ int da_chans; int da_bits; int have_dio; -}s526_board; +} s526_board; static const s526_board s526_boards[] = { { - name: "s526", - gpct_chans: 4, - gpct_bits: 24, - ad_chans: 8, - ad_bits: 16, - da_chans: 4, - da_bits: 16, - have_dio: 1, - } + name: "s526", + gpct_chans:4, + gpct_bits:24, + ad_chans:8, + ad_bits: 16, + da_chans:4, + da_bits: 16, + have_dio:1, + } }; #define ADDR_REG(reg) (dev->iobase + (reg)) @@ -199,7 +191,7 @@ static const s526_board s526_boards[] = { /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ +typedef struct { int data; /* would be useful for a PCI device */ @@ -210,7 +202,7 @@ typedef struct{ s526_gpct_config_t s526_gpct_config[4]; unsigned short s526_ai_config; -}s526_private; +} s526_private; /* * most drivers define the following macro to make it easy to * access the private structure. @@ -223,45 +215,54 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int s526_attach(comedi_device *dev,comedi_devconfig *it); -static int s526_detach(comedi_device *dev); -static comedi_driver driver_s526={ - driver_name: "s526", - module: THIS_MODULE, - attach: s526_attach, - detach: s526_detach, +static int s526_attach(comedi_device * dev, comedi_devconfig * it); +static int s526_detach(comedi_device * dev); +static comedi_driver driver_s526 = { + driver_name:"s526", + module:THIS_MODULE, + attach:s526_attach, + detach:s526_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ - /* Most drivers will support multiple types of boards by - * having an array of board structures. These were defined - * in s526_boards[] above. Note that the element 'name' - * was first in the structure -- Comedi uses this fact to - * extract the name of the board without knowing any details - * about the structure except for its length. - * When a device is attached (by comedi_config), the name - * of the device is given to Comedi, and Comedi tries to - * match it by going through the list of board names. If - * there is a match, the address of the pointer is put - * into dev->board_ptr and driver->attach() is called. - * - * Note that these are not necessary if you can determine - * the type of board in software. ISA PnP, PCI, and PCMCIA - * devices are such boards. - */ - board_name: &s526_boards[0].name, - offset: sizeof(s526_board), - num_names: sizeof(s526_boards) / sizeof(s526_board), + /* Most drivers will support multiple types of boards by + * having an array of board structures. These were defined + * in s526_boards[] above. Note that the element 'name' + * was first in the structure -- Comedi uses this fact to + * extract the name of the board without knowing any details + * about the structure except for its length. + * When a device is attached (by comedi_config), the name + * of the device is given to Comedi, and Comedi tries to + * match it by going through the list of board names. If + * there is a match, the address of the pointer is put + * into dev->board_ptr and driver->attach() is called. + * + * Note that these are not necessary if you can determine + * the type of board in software. ISA PnP, PCI, and PCMCIA + * devices are such boards. + */ + board_name:&s526_boards[0].name, + offset:sizeof(s526_board), + num_names:sizeof(s526_boards) / sizeof(s526_board), }; -static int s526_gpct_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int s526_gpct_insn_config(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int s526_gpct_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int s526_ai_insn_config(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int s526_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s526_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s526_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s526_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); -static int s526_dio_insn_config(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); +static int s526_gpct_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_gpct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_gpct_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_ai_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s526_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* * Attach is called by the Comedi core to configure the driver @@ -269,22 +270,22 @@ static int s526_dio_insn_config(comedi_device *dev,comedi_subdevice *s, comedi_i * in the driver structure, dev->board_ptr contains that * address. */ -static int s526_attach(comedi_device *dev,comedi_devconfig *it) +static int s526_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - int iobase; + int iobase; int i, n; -// sampl_t value; +// sampl_t value; // int subdev_channel = 0; printk("comedi%d: s526: ", dev->minor); - iobase=it->options[0]; - if(!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)){ - comedi_error(dev,"I/O port conflict"); - return -EIO; - } - dev->iobase=iobase; + iobase = it->options[0]; + if (!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)) { + comedi_error(dev, "I/O port conflict"); + return -EIO; + } + dev->iobase = iobase; printk("iobase=0x%lx\n", dev->iobase); @@ -298,7 +299,7 @@ static int s526_attach(comedi_device *dev,comedi_devconfig *it) * Initialize dev->board_name. Note that we can use the "thisboard" * macro now, since we just initialized it in the last line. */ - dev->board_ptr = &s526_boards[0]; + dev->board_ptr = &s526_boards[0]; dev->board_name = thisboard->name; @@ -306,70 +307,70 @@ static int s526_attach(comedi_device *dev,comedi_devconfig *it) * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if(alloc_private(dev, sizeof(s526_private)) < 0) + if (alloc_private(dev, sizeof(s526_private)) < 0) return -ENOMEM; /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - dev->n_subdevices = 4; - if(alloc_subdevices(dev, dev->n_subdevices) < 0) + dev->n_subdevices = 4; + if (alloc_subdevices(dev, dev->n_subdevices) < 0) return -ENOMEM; - s=dev->subdevices+0; - /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL; - /* KG: What does SDF_LSAMPL (see multiq3.c) mean? */ - s->n_chan = thisboard->gpct_chans; - s->maxdata = 0x00ffffff; /* 24 bit counter */ - s->insn_read = s526_gpct_rinsn; - s->insn_config = s526_gpct_insn_config; - s->insn_write = s526_gpct_winsn; - - /* Command are not implemented yet, however they are necessary to - allocate the necessary memory for the comedi_async struct (used - to trigger the GPCT in case of pulsegenerator function */ - //s->do_cmd = s526_gpct_cmd; - //s->do_cmdtest = s526_gpct_cmdtest; - //s->cancel = s526_gpct_cancel; - - s=dev->subdevices+1; + s = dev->subdevices + 0; + /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */ + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL; + /* KG: What does SDF_LSAMPL (see multiq3.c) mean? */ + s->n_chan = thisboard->gpct_chans; + s->maxdata = 0x00ffffff; /* 24 bit counter */ + s->insn_read = s526_gpct_rinsn; + s->insn_config = s526_gpct_insn_config; + s->insn_write = s526_gpct_winsn; + + /* Command are not implemented yet, however they are necessary to + allocate the necessary memory for the comedi_async struct (used + to trigger the GPCT in case of pulsegenerator function */ + //s->do_cmd = s526_gpct_cmd; + //s->do_cmdtest = s526_gpct_cmdtest; + //s->cancel = s526_gpct_cancel; + + s = dev->subdevices + 1; //dev->read_subdev=s; /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; /* we support single-ended (ground) and differential */ - s->subdev_flags=SDF_READABLE|SDF_DIFF; - s->n_chan=8; - s->maxdata=0x3fff; - s->range_table=&range_bipolar10; - s->len_chanlist=16; /* This is the maximum chanlist length that - the board can handle */ - s->insn_read = s526_ai_rinsn; - s->insn_config = s526_ai_insn_config; - - s=dev->subdevices+2; + s->subdev_flags = SDF_READABLE | SDF_DIFF; + s->n_chan = 8; + s->maxdata = 0x3fff; + s->range_table = &range_bipolar10; + s->len_chanlist = 16; /* This is the maximum chanlist length that + the board can handle */ + s->insn_read = s526_ai_rinsn; + s->insn_config = s526_ai_insn_config; + + s = dev->subdevices + 2; /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=4; - s->maxdata=0xffff; - s->range_table=&range_bipolar10; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 4; + s->maxdata = 0xffff; + s->range_table = &range_bipolar10; s->insn_write = s526_ao_winsn; s->insn_read = s526_ao_rinsn; - s=dev->subdevices+3; + s = dev->subdevices + 3; /* digital i/o subdevice */ - if(thisboard->have_dio){ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=2; - s->maxdata=1; - s->range_table=&range_digital; + if (thisboard->have_dio) { + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 2; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = s526_dio_insn_bits; s->insn_config = s526_dio_insn_config; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -378,84 +379,83 @@ static int s526_attach(comedi_device *dev,comedi_devconfig *it) return 1; #if 0 - // Example of Counter Application - //One-shot (software trigger) - cmReg.reg.coutSource = 0; // out RCAP - cmReg.reg.coutPolarity = 1; // Polarity inverted - cmReg.reg.autoLoadResetRcap = 1; // Auto load 0:disabled, 1:enabled - cmReg.reg.hwCtEnableSource = 3; // NOT RCAP - cmReg.reg.ctEnableCtrl = 2; // Hardware - cmReg.reg.clockSource = 2; // Internal - cmReg.reg.countDir = 1; // Down - cmReg.reg.countDirCtrl = 1; // Software - cmReg.reg.outputRegLatchCtrl = 0; // latch on read - cmReg.reg.preloadRegSel = 0; // PR0 - cmReg.reg.reserved = 0; - - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter - outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 - - outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset RCAP (fires one-shot) + // Example of Counter Application + //One-shot (software trigger) + cmReg.reg.coutSource = 0; // out RCAP + cmReg.reg.coutPolarity = 1; // Polarity inverted + cmReg.reg.autoLoadResetRcap = 1; // Auto load 0:disabled, 1:enabled + cmReg.reg.hwCtEnableSource = 3; // NOT RCAP + cmReg.reg.ctEnableCtrl = 2; // Hardware + cmReg.reg.clockSource = 2; // Internal + cmReg.reg.countDir = 1; // Down + cmReg.reg.countDirCtrl = 1; // Software + cmReg.reg.outputRegLatchCtrl = 0; // latch on read + cmReg.reg.preloadRegSel = 0; // PR0 + cmReg.reg.reserved = 0; + + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter + outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 + + outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset RCAP (fires one-shot) #else + // Set Counter Mode Register + cmReg.reg.coutSource = 0; // out RCAP + cmReg.reg.coutPolarity = 0; // Polarity inverted + cmReg.reg.autoLoadResetRcap = 0; // Auto load disabled + cmReg.reg.hwCtEnableSource = 2; // NOT RCAP + cmReg.reg.ctEnableCtrl = 1; // 1: Software, >1 : Hardware + cmReg.reg.clockSource = 3; // x4 + cmReg.reg.countDir = 0; // up + cmReg.reg.countDirCtrl = 0; // quadrature + cmReg.reg.outputRegLatchCtrl = 0; // latch on read + cmReg.reg.preloadRegSel = 0; // PR0 + cmReg.reg.reserved = 0; + + n = 0; + printk("Mode reg=0x%04x, 0x%04lx\n", cmReg.value, ADDR_CHAN_REG(REG_C0M, + n)); + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); + udelay(1000); + printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); + + // Load the pre-laod register high word +// value = (sampl_t) (0x55); +// outw(value, ADDR_CHAN_REG(REG_C0H, n)); + + // Load the pre-laod register low word +// value = (sampl_t)(0xaa55); +// outw(value, ADDR_CHAN_REG(REG_C0L, n)); + + // Write the Counter Control Register +// outw(value, ADDR_CHAN_REG(REG_C0C, 0)); + + // Reset the counter if it is software preload + if (cmReg.reg.autoLoadResetRcap == 0) { + outw(0x8000, ADDR_CHAN_REG(REG_C0C, n)); // Reset the counter + outw(0x4000, ADDR_CHAN_REG(REG_C0C, n)); // Load the counter from PR0 + } - // Set Counter Mode Register - cmReg.reg.coutSource = 0; // out RCAP - cmReg.reg.coutPolarity = 0; // Polarity inverted - cmReg.reg.autoLoadResetRcap = 0; // Auto load disabled - cmReg.reg.hwCtEnableSource = 2; // NOT RCAP - cmReg.reg.ctEnableCtrl = 1; // 1: Software, >1 : Hardware - cmReg.reg.clockSource = 3; // x4 - cmReg.reg.countDir = 0; // up - cmReg.reg.countDirCtrl = 0; // quadrature - cmReg.reg.outputRegLatchCtrl = 0; // latch on read - cmReg.reg.preloadRegSel = 0; // PR0 - cmReg.reg.reserved = 0; - - n = 0; - printk("Mode reg=0x%04x, 0x%04lx\n", cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); - udelay(1000); - printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); - - // Load the pre-laod register high word -// value = (sampl_t) (0x55); -// outw(value, ADDR_CHAN_REG(REG_C0H, n)); - - // Load the pre-laod register low word -// value = (sampl_t)(0xaa55); -// outw(value, ADDR_CHAN_REG(REG_C0L, n)); - - // Write the Counter Control Register -// outw(value, ADDR_CHAN_REG(REG_C0C, 0)); - - - // Reset the counter if it is software preload - if (cmReg.reg.autoLoadResetRcap == 0) { - outw(0x8000, ADDR_CHAN_REG(REG_C0C, n)); // Reset the counter - outw(0x4000, ADDR_CHAN_REG(REG_C0C, n)); // Load the counter from PR0 - } - - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); - udelay(1000); - printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); + udelay(1000); + printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); #endif printk("Current registres:\n"); for (i = 0; i < S526_NUM_PORTS; i++) { - printk("0x%02lx: 0x%04x\n", ADDR_REG(s526_ports[i]), inw(ADDR_REG(s526_ports[i]))); + printk("0x%02lx: 0x%04x\n", ADDR_REG(s526_ports[i]), + inw(ADDR_REG(s526_ports[i]))); } return 1; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -464,7 +464,7 @@ static int s526_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int s526_detach(comedi_device *dev) +static int s526_detach(comedi_device * dev) { printk("comedi%d: s526: remove\n", dev->minor); @@ -474,57 +474,58 @@ static int s526_detach(comedi_device *dev) return 0; } -static int s526_gpct_rinsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int s526_gpct_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; // counts the Data - int counter_channel = CR_CHAN(insn->chanspec); - unsigned short datalow; - unsigned short datahigh; + int i; // counts the Data + int counter_channel = CR_CHAN(insn->chanspec); + unsigned short datalow; + unsigned short datahigh; // Check if (n > 0) - if (insn->n <= 0) - { + if (insn->n <= 0) { printk("s526: INSN_READ: n should be > 0\n"); - return -EINVAL; - } - // Read the low word first - for ( i=0 ; i < insn->n ; i++ ) - { - datalow = inw(ADDR_CHAN_REG(REG_C0L, counter_channel)); + return -EINVAL; + } + // Read the low word first + for (i = 0; i < insn->n; i++) { + datalow = inw(ADDR_CHAN_REG(REG_C0L, counter_channel)); datahigh = inw(ADDR_CHAN_REG(REG_C0H, counter_channel)); data[i] = (int)(datahigh & 0x00FF); data[i] = (data[i] << 16) | (datalow & 0xFFFF); -// printk("s526 GPCT[%d]: %x(0x%04x, 0x%04x)\n", counter_channel, data[i], datahigh, datalow); +// printk("s526 GPCT[%d]: %x(0x%04x, 0x%04x)\n", counter_channel, data[i], datahigh, datalow); } return i; } -static int s526_gpct_insn_config(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int s526_gpct_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int subdev_channel = CR_CHAN(insn->chanspec);// Unpack chanspec + int subdev_channel = CR_CHAN(insn->chanspec); // Unpack chanspec int i; sampl_t value; // printk("s526: GPCT_INSN_CONFIG: Configuring Channel %d\n", subdev_channel); - for(i = 0; i < MAX_GPCT_CONFIG_DATA; i++) { - devpriv->s526_gpct_config[subdev_channel].data[i] = insn->data[i]; -// printk("data[%d]=%x\n", i, insn->data[i]); + for (i = 0; i < MAX_GPCT_CONFIG_DATA; i++) { + devpriv->s526_gpct_config[subdev_channel].data[i] = + insn->data[i]; +// printk("data[%d]=%x\n", i, insn->data[i]); } - // Check what type of Counter the user requested, data[0] contains - // the Application type - switch(insn->data[0]) - { - case INSN_CONFIG_GPCT_QUADRATURE_ENCODER: - /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register Value - data[3]: Conter Control Register - */ - printk("s526: GPCT_INSN_CONFIG: Configuring Encoder\n"); - devpriv->s526_gpct_config[subdev_channel].app = PositionMeasurement; + // Check what type of Counter the user requested, data[0] contains + // the Application type + switch (insn->data[0]) { + case INSN_CONFIG_GPCT_QUADRATURE_ENCODER: + /* + data[0]: Application Type + data[1]: Counter Mode Register Value + data[2]: Pre-load Register Value + data[3]: Conter Control Register + */ + printk("s526: GPCT_INSN_CONFIG: Configuring Encoder\n"); + devpriv->s526_gpct_config[subdev_channel].app = + PositionMeasurement; /* // Example of Counter Application @@ -554,267 +555,267 @@ static int s526_gpct_insn_config(comedi_device *dev, comedi_subdevice *s, comedi */ #if 1 - // Set Counter Mode Register - cmReg.reg.coutSource = 0; // out RCAP - cmReg.reg.coutPolarity = 0; // Polarity inverted - cmReg.reg.autoLoadResetRcap = 0; // Auto load disabled - cmReg.reg.hwCtEnableSource = 2; // NOT RCAP - cmReg.reg.ctEnableCtrl = 1; // 1: Software, >1 : Hardware - cmReg.reg.clockSource = 3; // x4 - cmReg.reg.countDir = 0; // up - cmReg.reg.countDirCtrl = 0; // quadrature - cmReg.reg.outputRegLatchCtrl = 0; // latch on read - cmReg.reg.preloadRegSel = 0; // PR0 - cmReg.reg.reserved = 0; - - // Set Counter Mode Register -// printk("s526: Counter Mode register=%x\n", cmReg.value); - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Reset the counter if it is software preload - if (cmReg.reg.autoLoadResetRcap == 0) { - outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter -// outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 - } + // Set Counter Mode Register + cmReg.reg.coutSource = 0; // out RCAP + cmReg.reg.coutPolarity = 0; // Polarity inverted + cmReg.reg.autoLoadResetRcap = 0; // Auto load disabled + cmReg.reg.hwCtEnableSource = 2; // NOT RCAP + cmReg.reg.ctEnableCtrl = 1; // 1: Software, >1 : Hardware + cmReg.reg.clockSource = 3; // x4 + cmReg.reg.countDir = 0; // up + cmReg.reg.countDirCtrl = 0; // quadrature + cmReg.reg.outputRegLatchCtrl = 0; // latch on read + cmReg.reg.preloadRegSel = 0; // PR0 + cmReg.reg.reserved = 0; + + // Set Counter Mode Register +// printk("s526: Counter Mode register=%x\n", cmReg.value); + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Reset the counter if it is software preload + if (cmReg.reg.autoLoadResetRcap == 0) { + outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter +// outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 + } #else - cmReg.reg.countDirCtrl = 0; // 0 quadrature, 1 software control - - // data[1] contains GPCT_X1, GPCT_X2 or GPCT_X4 - if(insn->data[1] == GPCT_X2) { - cmReg.reg.clockSource = 1; - }else if(insn->data[1] == GPCT_X4) { - cmReg.reg.clockSource = 2; - }else { - cmReg.reg.clockSource = 0; - } - - // When to take into account the indexpulse: - if(insn->data[2] == GPCT_IndexPhaseLowLow) { - }else if(insn->data[2] == GPCT_IndexPhaseLowHigh) { - }else if(insn->data[2] == GPCT_IndexPhaseHighLow) { - }else if(insn->data[2] == GPCT_IndexPhaseHighHigh) { - } - - // Take into account the index pulse? - if(insn->data[3] == GPCT_RESET_COUNTER_ON_INDEX) - cmReg.reg.autoLoadResetRcap = 4; // Auto load with INDEX^ - - - // Set Counter Mode Register - cmReg.value = (sampl_t)(insn->data[1] & 0xFFFF); - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Load the pre-laod register high word - value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - - // Load the pre-laod register low word - value = (sampl_t)(insn->data[2] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - // Write the Counter Control Register - if (insn->data[3] != 0) { - value = (sampl_t)(insn->data[3] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); - } + cmReg.reg.countDirCtrl = 0; // 0 quadrature, 1 software control + + // data[1] contains GPCT_X1, GPCT_X2 or GPCT_X4 + if (insn->data[1] == GPCT_X2) { + cmReg.reg.clockSource = 1; + } else if (insn->data[1] == GPCT_X4) { + cmReg.reg.clockSource = 2; + } else { + cmReg.reg.clockSource = 0; + } - // Reset the counter if it is software preload - if (cmReg.reg.autoLoadResetRcap == 0) { - outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter - outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 - } + // When to take into account the indexpulse: + if (insn->data[2] == GPCT_IndexPhaseLowLow) { + } else if (insn->data[2] == GPCT_IndexPhaseLowHigh) { + } else if (insn->data[2] == GPCT_IndexPhaseHighLow) { + } else if (insn->data[2] == GPCT_IndexPhaseHighHigh) { + } + // Take into account the index pulse? + if (insn->data[3] == GPCT_RESET_COUNTER_ON_INDEX) + cmReg.reg.autoLoadResetRcap = 4; // Auto load with INDEX^ + + // Set Counter Mode Register + cmReg.value = (sampl_t) (insn->data[1] & 0xFFFF); + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Load the pre-laod register high word + value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + + // Load the pre-laod register low word + value = (sampl_t) (insn->data[2] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + // Write the Counter Control Register + if (insn->data[3] != 0) { + value = (sampl_t) (insn->data[3] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); + } + // Reset the counter if it is software preload + if (cmReg.reg.autoLoadResetRcap == 0) { + outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Reset the counter + outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); // Load the counter from PR0 + } #endif - break; - - case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: - /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register 0 Value - data[3]: Pre-load Register 1 Value - data[4]: Conter Control Register - */ - printk("s526: GPCT_INSN_CONFIG: Configuring SPG\n"); - devpriv->s526_gpct_config[subdev_channel].app = SinglePulseGeneration; - - // Set Counter Mode Register - cmReg.value = (sampl_t)(insn->data[1] & 0xFFFF); - cmReg.reg.preloadRegSel = 0; // PR0 - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Load the pre-laod register 0 high word - value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - - // Load the pre-laod register 0 low word - value = (sampl_t)(insn->data[2] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - // Set Counter Mode Register - cmReg.value = (sampl_t)(insn->data[1] & 0xFFFF); - cmReg.reg.preloadRegSel = 1; // PR1 - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Load the pre-laod register 1 high word - value = (sampl_t) ((insn->data[3] >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - - // Load the pre-laod register 1 low word - value = (sampl_t)(insn->data[3] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - // Write the Counter Control Register - if (insn->data[3] != 0) { - value = (sampl_t)(insn->data[3] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); - } - break; - - case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: - /* - data[0]: Application Type - data[1]: Counter Mode Register Value - data[2]: Pre-load Register 0 Value - data[3]: Pre-load Register 1 Value - data[4]: Conter Control Register - */ - printk("s526: GPCT_INSN_CONFIG: Configuring PTG\n"); - devpriv->s526_gpct_config[subdev_channel].app = PulseTrainGeneration; - - // Set Counter Mode Register - cmReg.value = (sampl_t)(insn->data[1] & 0xFFFF); - cmReg.reg.preloadRegSel = 0; // PR0 - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Load the pre-laod register 0 high word - value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - - // Load the pre-laod register 0 low word - value = (sampl_t)(insn->data[2] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - // Set Counter Mode Register - cmReg.value = (sampl_t)(insn->data[1] & 0xFFFF); - cmReg.reg.preloadRegSel = 1; // PR1 - outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); - - // Load the pre-laod register 1 high word - value = (sampl_t) ((insn->data[3] >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - - // Load the pre-laod register 1 low word - value = (sampl_t)(insn->data[3] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - - // Write the Counter Control Register - if (insn->data[3] != 0) { - value = (sampl_t)(insn->data[3] & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); - } - break; + break; + + case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: + /* + data[0]: Application Type + data[1]: Counter Mode Register Value + data[2]: Pre-load Register 0 Value + data[3]: Pre-load Register 1 Value + data[4]: Conter Control Register + */ + printk("s526: GPCT_INSN_CONFIG: Configuring SPG\n"); + devpriv->s526_gpct_config[subdev_channel].app = + SinglePulseGeneration; + + // Set Counter Mode Register + cmReg.value = (sampl_t) (insn->data[1] & 0xFFFF); + cmReg.reg.preloadRegSel = 0; // PR0 + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Load the pre-laod register 0 high word + value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + + // Load the pre-laod register 0 low word + value = (sampl_t) (insn->data[2] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + // Set Counter Mode Register + cmReg.value = (sampl_t) (insn->data[1] & 0xFFFF); + cmReg.reg.preloadRegSel = 1; // PR1 + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Load the pre-laod register 1 high word + value = (sampl_t) ((insn->data[3] >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + + // Load the pre-laod register 1 low word + value = (sampl_t) (insn->data[3] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + // Write the Counter Control Register + if (insn->data[3] != 0) { + value = (sampl_t) (insn->data[3] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); + } + break; + + case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: + /* + data[0]: Application Type + data[1]: Counter Mode Register Value + data[2]: Pre-load Register 0 Value + data[3]: Pre-load Register 1 Value + data[4]: Conter Control Register + */ + printk("s526: GPCT_INSN_CONFIG: Configuring PTG\n"); + devpriv->s526_gpct_config[subdev_channel].app = + PulseTrainGeneration; + + // Set Counter Mode Register + cmReg.value = (sampl_t) (insn->data[1] & 0xFFFF); + cmReg.reg.preloadRegSel = 0; // PR0 + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Load the pre-laod register 0 high word + value = (sampl_t) ((insn->data[2] >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + + // Load the pre-laod register 0 low word + value = (sampl_t) (insn->data[2] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + // Set Counter Mode Register + cmReg.value = (sampl_t) (insn->data[1] & 0xFFFF); + cmReg.reg.preloadRegSel = 1; // PR1 + outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, subdev_channel)); + + // Load the pre-laod register 1 high word + value = (sampl_t) ((insn->data[3] >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + + // Load the pre-laod register 1 low word + value = (sampl_t) (insn->data[3] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + + // Write the Counter Control Register + if (insn->data[3] != 0) { + value = (sampl_t) (insn->data[3] & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0C, subdev_channel)); + } + break; - default: - printk("s526: unsupported GPCT_insn_config\n"); - return -EINVAL; - break; - } + default: + printk("s526: unsupported GPCT_insn_config\n"); + return -EINVAL; + break; + } - return insn->n; + return insn->n; } -static int s526_gpct_winsn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) +static int s526_gpct_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int subdev_channel = CR_CHAN(insn->chanspec);// Unpack chanspec + int subdev_channel = CR_CHAN(insn->chanspec); // Unpack chanspec sampl_t value; - printk("s526: GPCT_INSN_WRITE on channel %d\n", subdev_channel); + printk("s526: GPCT_INSN_WRITE on channel %d\n", subdev_channel); cmReg.value = inw(ADDR_CHAN_REG(REG_C0M, subdev_channel)); printk("s526: Counter Mode Register: %x\n", cmReg.value); - // Check what Application of Counter this channel is configured for - switch(devpriv->s526_gpct_config[subdev_channel].app) - { - case PositionMeasurement: - printk("S526: INSN_WRITE: PM\n"); - outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, subdev_channel)); - outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); - break; - - case SinglePulseGeneration: - printk("S526: INSN_WRITE: SPG\n"); - outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, subdev_channel)); - outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); - break; - - case PulseTrainGeneration: - /* data[0] contains the PULSE_WIDTH - data[1] contains the PULSE_PERIOD - @pre PULSE_PERIOD > PULSE_WIDTH > 0 - The above periods must be expressed as a multiple of the - pulse frequency on the selected source - */ - printk("S526: INSN_WRITE: PTG\n"); - if ( (insn->data[1] > insn->data[0]) && (insn->data[0] > 0 ) ) - { - (devpriv->s526_gpct_config[subdev_channel]).data[0] = insn->data[0]; - (devpriv->s526_gpct_config[subdev_channel]).data[1] = insn->data[1]; - } - else - { - printk("%d \t %d\n",insn->data[1],insn->data[2]); - printk("s526: INSN_WRITE: PTG: Problem with Pulse params\n"); - return -EINVAL; - } - - value = (sampl_t)((*data >> 16) & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); - value = (sampl_t)(*data & 0xFFFF); - outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); - break; - default: // Impossible - printk("s526: INSN_WRITE: Functionality %d not implemented yet\n", - devpriv->s526_gpct_config[subdev_channel].app); - return -EINVAL; - break; - } + // Check what Application of Counter this channel is configured for + switch (devpriv->s526_gpct_config[subdev_channel].app) { + case PositionMeasurement: + printk("S526: INSN_WRITE: PM\n"); + outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, + subdev_channel)); + outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); + break; + + case SinglePulseGeneration: + printk("S526: INSN_WRITE: SPG\n"); + outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, + subdev_channel)); + outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); + break; + + case PulseTrainGeneration: + /* data[0] contains the PULSE_WIDTH + data[1] contains the PULSE_PERIOD + @pre PULSE_PERIOD > PULSE_WIDTH > 0 + The above periods must be expressed as a multiple of the + pulse frequency on the selected source + */ + printk("S526: INSN_WRITE: PTG\n"); + if ((insn->data[1] > insn->data[0]) && (insn->data[0] > 0)) { + (devpriv->s526_gpct_config[subdev_channel]).data[0] = + insn->data[0]; + (devpriv->s526_gpct_config[subdev_channel]).data[1] = + insn->data[1]; + } else { + printk("%d \t %d\n", insn->data[1], insn->data[2]); + printk("s526: INSN_WRITE: PTG: Problem with Pulse params\n"); + return -EINVAL; + } + + value = (sampl_t) ((*data >> 16) & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0H, subdev_channel)); + value = (sampl_t) (*data & 0xFFFF); + outw(value, ADDR_CHAN_REG(REG_C0L, subdev_channel)); + break; + default: // Impossible + printk("s526: INSN_WRITE: Functionality %d not implemented yet\n", devpriv->s526_gpct_config[subdev_channel].app); + return -EINVAL; + break; + } // return the number of samples written - return insn->n ; + return insn->n; } #define ISR_ADC_DONE 0x4 -static int s526_ai_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int s526_ai_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int result = -EINVAL; - if (insn->n < 1) return result; + if (insn->n < 1) + return result; result = insn->n; /* data[0] : channels was set in relevant bits. data[1] : delay - */ + */ // Enable ADC interrupt outw(ISR_ADC_DONE, ADDR_REG(REG_IER)); -// printk("s526: ADC current value: 0x%04x\n", inw(ADDR_REG(REG_ADC))); +// printk("s526: ADC current value: 0x%04x\n", inw(ADDR_REG(REG_ADC))); devpriv->s526_ai_config = (data[0] & 0x3FF) << 5; if (data[1] > 0) - devpriv->s526_ai_config |= 0x8000; //set the delay + devpriv->s526_ai_config |= 0x8000; //set the delay - devpriv->s526_ai_config |= 0x0001; // ADC start bit. + devpriv->s526_ai_config |= 0x0001; // ADC start bit. - return result; + return result; } - /* * "instructions" read/write data in "one-shot" or "software-triggered" * mode. */ -static int s526_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s526_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; int chan = CR_CHAN(insn->chanspec); unsigned short value; unsigned int d; @@ -823,34 +824,34 @@ static int s526_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins value = devpriv->s526_ai_config | (chan << 1); // outw(value, ADDR_REG(REG_ADC)); do it with ADC start - /* convert n samples */ - for(n=0; nn; n++){ + for (n = 0; n < insn->n; n++) { /* trigger conversion */ - value |= 0x0001; // ADC start - outw(value, ADDR_REG(REG_ADC)); -// printk("s526: Wrote 0x%04x to ADC\n", value); -// printk("s526: ADC reg=0x%04x\n", inw(ADDR_REG(REG_ADC))); + value |= 0x0001; // ADC start + outw(value, ADDR_REG(REG_ADC)); +// printk("s526: Wrote 0x%04x to ADC\n", value); +// printk("s526: ADC reg=0x%04x\n", inw(ADDR_REG(REG_ADC))); #define TIMEOUT 100 /* wait for conversion to end */ - for(i=0;ichanspec); unsigned short val; -// printk("s526_ao_winsn\n"); +// printk("s526_ao_winsn\n"); val = chan << 1; -// outw(val, dev->iobase + REG_DAC); +// outw(val, dev->iobase + REG_DAC); outw(val, ADDR_REG(REG_DAC)); /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { /* a typical programming sequence */ -// outw(data[i], dev->iobase + REG_ADD); // write the data to preload register - outw(data[i], ADDR_REG(REG_ADD)); // write the data to preload register +// outw(data[i], dev->iobase + REG_ADD); // write the data to preload register + outw(data[i], ADDR_REG(REG_ADD)); // write the data to preload register devpriv->ao_readback[chan] = data[i]; -// outw(val + 1, dev->iobase + REG_DAC); // starts the D/A conversion. - outw(val + 1, ADDR_REG(REG_DAC)); // starts the D/A conversion. +// outw(val + 1, dev->iobase + REG_DAC); // starts the D/A conversion. + outw(val + 1, ADDR_REG(REG_DAC)); // starts the D/A conversion. } /* return the number of samples read/written */ @@ -888,12 +889,13 @@ static int s526_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins /* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */ -static int s526_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s526_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -904,23 +906,24 @@ static int s526_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins * 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 s526_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int s526_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; /* Write out the new digital output lines */ outw(s->state, ADDR_REG(REG_DIO)); } /* on return, data[1] contains the value of the digital * input and output lines. */ - data[1]=inw(ADDR_REG(REG_DIO)) & 0xFF; // low 8 bits are the data + data[1] = inw(ADDR_REG(REG_DIO)) & 0xFF; // low 8 bits are the data /* or we could just return the software copy of the output values if * it was a purely digital output subdevice */ //data[1]=s->state; @@ -928,15 +931,16 @@ static int s526_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int s526_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int s526_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); sampl_t value; printk("S526 DIO insn_config\n"); - if(insn->n!=1)return -EINVAL; + if (insn->n != 1) + return -EINVAL; value = inw(ADDR_REG(REG_DIO)); @@ -945,11 +949,11 @@ static int s526_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ - if(data[0]==COMEDI_OUTPUT){ - value |= 1 << (chan + 10); // bit 10/11 set the group 1/2's mode + if (data[0] == COMEDI_OUTPUT) { + value |= 1 << (chan + 10); // bit 10/11 set the group 1/2's mode s->io_bits |= (0xF << chan); - }else{ - value &= ~(1 << (chan + 10)); // 1 is output, 0 is input. + } else { + value &= ~(1 << (chan + 10)); // 1 is output, 0 is input. s->io_bits &= ~(0xF << chan); } outw(value, ADDR_REG(REG_DIO)); @@ -962,4 +966,3 @@ static int s526_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * as necessary. */ COMEDI_INITCLEANUP(driver_s526); - diff --git a/comedi/drivers/s626.c b/comedi/drivers/s626.c index e8d2dc89..a7d2ffa6 100644 --- a/comedi/drivers/s626.c +++ b/comedi/drivers/s626.c @@ -76,28 +76,28 @@ MODULE_AUTHOR("Gianluca Palli "); MODULE_DESCRIPTION("Sensoray 626 Comedi driver module"); MODULE_LICENSE("GPL"); -typedef struct s626_board_struct{ - const char *name; - int ai_chans; - int ai_bits; - int ao_chans; - int ao_bits; - int dio_chans; - int dio_banks; - int enc_chans; +typedef struct s626_board_struct { + const char *name; + int ai_chans; + int ai_bits; + int ao_chans; + int ao_bits; + int dio_chans; + int dio_banks; + int enc_chans; } s626_board; static const s626_board s626_boards[] = { - { - name: "s626", - ai_chans: S626_ADC_CHANNELS, - ai_bits: 14, - ao_chans: S626_DAC_CHANNELS, - ao_bits: 13, - dio_chans: S626_DIO_CHANNELS, - dio_banks: S626_DIO_BANKS, - enc_chans: S626_ENCODER_CHANNELS, - } + { + name: "s626", + ai_chans:S626_ADC_CHANNELS, + ai_bits: 14, + ao_chans:S626_DAC_CHANNELS, + ao_bits: 13, + dio_chans:S626_DIO_CHANNELS, + dio_banks:S626_DIO_BANKS, + enc_chans:S626_ENCODER_CHANNELS, + } }; #define thisboard ((const s626_board *)dev->board_ptr) @@ -105,108 +105,109 @@ static const s626_board s626_boards[] = { #define PCI_DEVICE_ID_S626 0x7146 static struct pci_device_id s626_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + 0}, + {0} }; MODULE_DEVICE_TABLE(pci, s626_pci_table); -static int s626_attach(comedi_device *dev,comedi_devconfig *it); -static int s626_detach(comedi_device *dev); +static int s626_attach(comedi_device * dev, comedi_devconfig * it); +static int s626_detach(comedi_device * dev); -static comedi_driver driver_s626={ - driver_name: "s626", - module: THIS_MODULE, - attach: s626_attach, - detach: s626_detach, +static comedi_driver driver_s626 = { + driver_name:"s626", + module:THIS_MODULE, + attach:s626_attach, + detach:s626_detach, }; -typedef struct{ - struct pci_dev *pdev; - void *base_addr; - int got_regions; - short allocatedBuf; - uint8_t ai_cmd_running; // ai_cmd is running - uint8_t ai_continous; // continous aquisition - int ai_sample_count; // number of samples to aquire - unsigned int ai_sample_timer; // time between samples in - // units of the timer - int ai_convert_count; // conversion counter - unsigned int ai_convert_timer; // time between conversion in - // units of the timer - uint16_t CounterIntEnabs; //Counter interrupt enable - //mask for MISC2 register. - uint8_t AdcItems; //Number of items in ADC poll - //list. - DMABUF RPSBuf; //DMA buffer used to hold ADC - //(RPS1) program. - DMABUF ANABuf; //DMA buffer used to receive - //ADC data and hold DAC data. - uint32_t *pDacWBuf; //Pointer to logical adrs of - //DMA buffer used to hold DAC - //data. - uint16_t Dacpol; //Image of DAC polarity - //register. - uint8_t TrimSetpoint[12]; //Images of TrimDAC setpoints. - //registers. - uint16_t ChargeEnabled; //Image of MISC2 Battery - //Charge Enabled (0 or - //WRMISC2_CHARGE_ENABLE). - uint16_t WDInterval; //Image of MISC2 watchdog - //interval control bits. - uint32_t I2CAdrs; //I2C device address for - //onboard EEPROM (board rev - //dependent). - // short I2Cards; - lsampl_t ao_readback[S626_DAC_CHANNELS]; -}s626_private; +typedef struct { + struct pci_dev *pdev; + void *base_addr; + int got_regions; + short allocatedBuf; + uint8_t ai_cmd_running; // ai_cmd is running + uint8_t ai_continous; // continous aquisition + int ai_sample_count; // number of samples to aquire + unsigned int ai_sample_timer; // time between samples in + // units of the timer + int ai_convert_count; // conversion counter + unsigned int ai_convert_timer; // time between conversion in + // units of the timer + uint16_t CounterIntEnabs; //Counter interrupt enable + //mask for MISC2 register. + uint8_t AdcItems; //Number of items in ADC poll + //list. + DMABUF RPSBuf; //DMA buffer used to hold ADC + //(RPS1) program. + DMABUF ANABuf; //DMA buffer used to receive + //ADC data and hold DAC data. + uint32_t *pDacWBuf; //Pointer to logical adrs of + //DMA buffer used to hold DAC + //data. + uint16_t Dacpol; //Image of DAC polarity + //register. + uint8_t TrimSetpoint[12]; //Images of TrimDAC setpoints. + //registers. + uint16_t ChargeEnabled; //Image of MISC2 Battery + //Charge Enabled (0 or + //WRMISC2_CHARGE_ENABLE). + uint16_t WDInterval; //Image of MISC2 watchdog + //interval control bits. + uint32_t I2CAdrs; //I2C device address for + //onboard EEPROM (board rev + //dependent). + // short I2Cards; + lsampl_t ao_readback[S626_DAC_CHANNELS]; +} s626_private; typedef struct { - uint16_t RDDIn; - uint16_t WRDOut; - uint16_t RDEdgSel; - uint16_t WREdgSel; - uint16_t RDCapSel; - uint16_t WRCapSel; - uint16_t RDCapFlg; - uint16_t RDIntSel; - uint16_t WRIntSel; + uint16_t RDDIn; + uint16_t WRDOut; + uint16_t RDEdgSel; + uint16_t WREdgSel; + uint16_t RDCapSel; + uint16_t WRCapSel; + uint16_t RDCapFlg; + uint16_t RDIntSel; + uint16_t WRIntSel; } dio_private; -static dio_private dio_private_A={ - RDDIn: LP_RDDINA, - WRDOut: LP_WRDOUTA, - RDEdgSel: LP_RDEDGSELA, - WREdgSel: LP_WREDGSELA, - RDCapSel: LP_RDCAPSELA, - WRCapSel: LP_WRCAPSELA, - RDCapFlg: LP_RDCAPFLGA, - RDIntSel: LP_RDINTSELA, - WRIntSel: LP_WRINTSELA, +static dio_private dio_private_A = { + RDDIn:LP_RDDINA, + WRDOut:LP_WRDOUTA, + RDEdgSel:LP_RDEDGSELA, + WREdgSel:LP_WREDGSELA, + RDCapSel:LP_RDCAPSELA, + WRCapSel:LP_WRCAPSELA, + RDCapFlg:LP_RDCAPFLGA, + RDIntSel:LP_RDINTSELA, + WRIntSel:LP_WRINTSELA, }; -static dio_private dio_private_B={ - RDDIn: LP_RDDINB, - WRDOut: LP_WRDOUTB, - RDEdgSel: LP_RDEDGSELB, - WREdgSel: LP_WREDGSELB, - RDCapSel: LP_RDCAPSELB, - WRCapSel: LP_WRCAPSELB, - RDCapFlg: LP_RDCAPFLGB, - RDIntSel: LP_RDINTSELB, - WRIntSel: LP_WRINTSELB, +static dio_private dio_private_B = { + RDDIn:LP_RDDINB, + WRDOut:LP_WRDOUTB, + RDEdgSel:LP_RDEDGSELB, + WREdgSel:LP_WREDGSELB, + RDCapSel:LP_RDCAPSELB, + WRCapSel:LP_WRCAPSELB, + RDCapFlg:LP_RDCAPFLGB, + RDIntSel:LP_RDINTSELB, + WRIntSel:LP_WRINTSELB, }; -static dio_private dio_private_C={ - RDDIn: LP_RDDINC, - WRDOut: LP_WRDOUTC, - RDEdgSel: LP_RDEDGSELC, - WREdgSel: LP_WREDGSELC, - RDCapSel: LP_RDCAPSELC, - WRCapSel: LP_WRCAPSELC, - RDCapFlg: LP_RDCAPFLGC, - RDIntSel: LP_RDINTSELC, - WRIntSel: LP_WRINTSELC, +static dio_private dio_private_C = { + RDDIn:LP_RDDINC, + WRDOut:LP_WRDOUTC, + RDEdgSel:LP_RDEDGSELC, + WREdgSel:LP_WREDGSELC, + RDCapSel:LP_RDCAPSELC, + WRCapSel:LP_WRCAPSELC, + RDCapFlg:LP_RDCAPFLGC, + RDIntSel:LP_RDINTSELC, + WRIntSel:LP_WRINTSELC, }; /* to group dio devices (48 bits mask and data are not allowed ???) @@ -223,94 +224,112 @@ static dio_private *dio_private_word[]={ COMEDI_INITCLEANUP_NOMODULE(driver_s626); //ioctl routines -static int s626_ai_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int s626_ai_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); /* static int s626_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); */ -static int s626_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_ai_cmd(comedi_device *dev,comedi_subdevice *s); -static int s626_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd); -static int s626_ai_cancel(comedi_device *dev,comedi_subdevice *s); -static int s626_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_dio_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_dio_set_irq(comedi_device *dev, unsigned int chan); -static int s626_dio_reset_irq(comedi_device *dev, unsigned int gruop, unsigned int mask); -static int s626_dio_clear_irq(comedi_device *dev); -static int s626_enc_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_enc_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_enc_insn_write(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int s626_ns_to_timer(int *nanosec,int round_mode); -static int s626_ai_load_polllist(uint8_t *ppl, comedi_cmd *cmd); -static int s626_ai_inttrig(comedi_device *dev,comedi_subdevice *s, - unsigned int trignum); -static irqreturn_t s626_irq_handler(int irq,void *d PT_REGS_ARG); +static int s626_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_ai_cmd(comedi_device * dev, comedi_subdevice * s); +static int s626_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int s626_ai_cancel(comedi_device * dev, comedi_subdevice * s); +static int s626_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_dio_set_irq(comedi_device * dev, unsigned int chan); +static int s626_dio_reset_irq(comedi_device * dev, unsigned int gruop, + unsigned int mask); +static int s626_dio_clear_irq(comedi_device * dev); +static int s626_enc_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_enc_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_enc_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int s626_ns_to_timer(int *nanosec, int round_mode); +static int s626_ai_load_polllist(uint8_t * ppl, comedi_cmd * cmd); +static int s626_ai_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum); +static irqreturn_t s626_irq_handler(int irq, void *d PT_REGS_ARG); static lsampl_t s626_ai_reg_to_uint(int data); /* static lsampl_t s626_uint_to_reg(comedi_subdevice *s, int data); */ //end ioctl routines //internal routines -static void s626_dio_init(comedi_device *dev); -static void ResetADC(comedi_device *dev,uint8_t *ppl ); -static void LoadTrimDACs(comedi_device *dev); -static void WriteTrimDAC(comedi_device *dev,uint8_t LogicalChan, uint8_t DacData ); -static uint8_t I2Cread(comedi_device *dev, uint8_t addr ); -static uint32_t I2Chandshake(comedi_device *dev,uint32_t val ); -static void SetDAC(comedi_device *dev,uint16_t chan, short dacdata ); -static void SendDAC(comedi_device *dev,uint32_t val ); -static void WriteMISC2(comedi_device *dev,uint16_t NewImage ); -static void DEBItransfer(comedi_device *dev); -static uint16_t DEBIread(comedi_device *dev,uint16_t addr ); -static void DEBIwrite(comedi_device *dev,uint16_t addr, uint16_t wdata ); -static void DEBIreplace(comedi_device *dev, uint16_t addr, uint16_t mask, uint16_t wdata ); -static void CloseDMAB (comedi_device *dev,DMABUF * pdma,size_t bsize); +static void s626_dio_init(comedi_device * dev); +static void ResetADC(comedi_device * dev, uint8_t * ppl); +static void LoadTrimDACs(comedi_device * dev); +static void WriteTrimDAC(comedi_device * dev, uint8_t LogicalChan, + uint8_t DacData); +static uint8_t I2Cread(comedi_device * dev, uint8_t addr); +static uint32_t I2Chandshake(comedi_device * dev, uint32_t val); +static void SetDAC(comedi_device * dev, uint16_t chan, short dacdata); +static void SendDAC(comedi_device * dev, uint32_t val); +static void WriteMISC2(comedi_device * dev, uint16_t NewImage); +static void DEBItransfer(comedi_device * dev); +static uint16_t DEBIread(comedi_device * dev, uint16_t addr); +static void DEBIwrite(comedi_device * dev, uint16_t addr, uint16_t wdata); +static void DEBIreplace(comedi_device * dev, uint16_t addr, uint16_t mask, + uint16_t wdata); +static void CloseDMAB(comedi_device * dev, DMABUF * pdma, size_t bsize); // COUNTER OBJECT ------------------------------------------------ typedef struct enc_private_struct { - // Pointers to functions that differ for A and B counters: - uint16_t (*GetEnable)(comedi_device *dev,struct enc_private_struct *); //Return clock enable. - uint16_t (*GetIntSrc)(comedi_device *dev,struct enc_private_struct *); //Return interrupt source. - uint16_t (*GetLoadTrig)(comedi_device *dev,struct enc_private_struct *); //Return preload trigger source. - uint16_t (*GetMode)(comedi_device *dev,struct enc_private_struct *); //Return standardized operating mode. - void (*PulseIndex)(comedi_device *dev,struct enc_private_struct *); //Generate soft index strobe. - void (*SetEnable)(comedi_device *dev,struct enc_private_struct *,uint16_t enab); //Program clock enable. - void (*SetIntSrc)(comedi_device *dev,struct enc_private_struct *,uint16_t IntSource); //Program interrupt source. - void (*SetLoadTrig)(comedi_device *dev,struct enc_private_struct *,uint16_t Trig); //Program preload trigger source. - void (*SetMode)(comedi_device *dev,struct enc_private_struct *,uint16_t Setup,uint16_t DisableIntSrc); //Program standardized operating mode. - void (*ResetCapFlags)(comedi_device *dev,struct enc_private_struct *); //Reset event capture flags. - - uint16_t MyCRA; // Address of CRA register. - uint16_t MyCRB; // Address of CRB register. - uint16_t MyLatchLsw; // Address of Latch least-significant-word - // register. - uint16_t MyEventBits[4]; // Bit translations for IntSrc -->RDMISC2. -} enc_private; //counter object + // Pointers to functions that differ for A and B counters: + uint16_t(*GetEnable) (comedi_device * dev, struct enc_private_struct *); //Return clock enable. + uint16_t(*GetIntSrc) (comedi_device * dev, struct enc_private_struct *); //Return interrupt source. + uint16_t(*GetLoadTrig) (comedi_device * dev, struct enc_private_struct *); //Return preload trigger source. + uint16_t(*GetMode) (comedi_device * dev, struct enc_private_struct *); //Return standardized operating mode. + void (*PulseIndex) (comedi_device * dev, struct enc_private_struct *); //Generate soft index strobe. + void (*SetEnable) (comedi_device * dev, struct enc_private_struct *, uint16_t enab); //Program clock enable. + void (*SetIntSrc) (comedi_device * dev, struct enc_private_struct *, uint16_t IntSource); //Program interrupt source. + void (*SetLoadTrig) (comedi_device * dev, struct enc_private_struct *, uint16_t Trig); //Program preload trigger source. + void (*SetMode) (comedi_device * dev, struct enc_private_struct *, uint16_t Setup, uint16_t DisableIntSrc); //Program standardized operating mode. + void (*ResetCapFlags) (comedi_device * dev, struct enc_private_struct *); //Reset event capture flags. + + uint16_t MyCRA; // Address of CRA register. + uint16_t MyCRB; // Address of CRB register. + uint16_t MyLatchLsw; // Address of Latch least-significant-word + // register. + uint16_t MyEventBits[4]; // Bit translations for IntSrc -->RDMISC2. +} enc_private; //counter object #define encpriv ((enc_private *)(dev->subdevices+5)->private) //counters routines -static void s626_timer_load(comedi_device *dev, enc_private *k, int tick); -static uint32_t ReadLatch(comedi_device *dev, enc_private *k ); -static void ResetCapFlags_A( comedi_device *dev, enc_private *k ); -static void ResetCapFlags_B(comedi_device *dev, enc_private *k); -static uint16_t GetMode_A( comedi_device *dev, enc_private *k ); -static uint16_t GetMode_B(comedi_device *dev, enc_private *k); -static void SetMode_A(comedi_device *dev, enc_private *k, uint16_t Setup, uint16_t DisableIntSrc ); -static void SetMode_B(comedi_device *dev, enc_private *k, uint16_t Setup, uint16_t DisableIntSrc ); -static void SetEnable_A( comedi_device *dev,enc_private *k, uint16_t enab ); -static void SetEnable_B( comedi_device *dev,enc_private *k, uint16_t enab ); -static uint16_t GetEnable_A(comedi_device *dev, enc_private *k ); -static uint16_t GetEnable_B( comedi_device *dev,enc_private *k ); -static void SetLatchSource(comedi_device *dev, enc_private *k, uint16_t value ); +static void s626_timer_load(comedi_device * dev, enc_private * k, int tick); +static uint32_t ReadLatch(comedi_device * dev, enc_private * k); +static void ResetCapFlags_A(comedi_device * dev, enc_private * k); +static void ResetCapFlags_B(comedi_device * dev, enc_private * k); +static uint16_t GetMode_A(comedi_device * dev, enc_private * k); +static uint16_t GetMode_B(comedi_device * dev, enc_private * k); +static void SetMode_A(comedi_device * dev, enc_private * k, uint16_t Setup, + uint16_t DisableIntSrc); +static void SetMode_B(comedi_device * dev, enc_private * k, uint16_t Setup, + uint16_t DisableIntSrc); +static void SetEnable_A(comedi_device * dev, enc_private * k, uint16_t enab); +static void SetEnable_B(comedi_device * dev, enc_private * k, uint16_t enab); +static uint16_t GetEnable_A(comedi_device * dev, enc_private * k); +static uint16_t GetEnable_B(comedi_device * dev, enc_private * k); +static void SetLatchSource(comedi_device * dev, enc_private * k, + uint16_t value); /* static uint16_t GetLatchSource(comedi_device *dev, enc_private *k ); */ -static void SetLoadTrig_A(comedi_device *dev, enc_private *k, uint16_t Trig ); -static void SetLoadTrig_B(comedi_device *dev, enc_private *k, uint16_t Trig ); -static uint16_t GetLoadTrig_A(comedi_device *dev, enc_private *k ); -static uint16_t GetLoadTrig_B(comedi_device *dev, enc_private *k ); -static void SetIntSrc_B(comedi_device *dev, enc_private *k, uint16_t IntSource ); -static void SetIntSrc_A(comedi_device *dev, enc_private *k, uint16_t IntSource ); -static uint16_t GetIntSrc_A(comedi_device *dev, enc_private *k ); -static uint16_t GetIntSrc_B(comedi_device *dev, enc_private *k ); +static void SetLoadTrig_A(comedi_device * dev, enc_private * k, uint16_t Trig); +static void SetLoadTrig_B(comedi_device * dev, enc_private * k, uint16_t Trig); +static uint16_t GetLoadTrig_A(comedi_device * dev, enc_private * k); +static uint16_t GetLoadTrig_B(comedi_device * dev, enc_private * k); +static void SetIntSrc_B(comedi_device * dev, enc_private * k, + uint16_t IntSource); +static void SetIntSrc_A(comedi_device * dev, enc_private * k, + uint16_t IntSource); +static uint16_t GetIntSrc_A(comedi_device * dev, enc_private * k); +static uint16_t GetIntSrc_B(comedi_device * dev, enc_private * k); /* static void SetClkMult(comedi_device *dev, enc_private *k, uint16_t value ) ; */ /* static uint16_t GetClkMult(comedi_device *dev, enc_private *k ) ; */ /* static void SetIndexPol(comedi_device *dev, enc_private *k, uint16_t value ); */ @@ -319,10 +338,10 @@ static uint16_t GetIntSrc_B(comedi_device *dev, enc_private *k ); /* static uint16_t GetClkSrc( comedi_device *dev,enc_private *k ); */ /* static void SetIndexSrc( comedi_device *dev,enc_private *k, uint16_t value ); */ /* static uint16_t GetIndexSrc( comedi_device *dev,enc_private *k ); */ -static void PulseIndex_A(comedi_device *dev, enc_private *k ); -static void PulseIndex_B( comedi_device *dev,enc_private *k ); -static void Preload( comedi_device *dev,enc_private *k, uint32_t value ); -static void CountersInit(comedi_device *dev); +static void PulseIndex_A(comedi_device * dev, enc_private * k); +static void PulseIndex_B(comedi_device * dev, enc_private * k); +static void Preload(comedi_device * dev, enc_private * k, uint32_t value); +static void CountersInit(comedi_device * dev); //end internal routines ///////////////////////////////////////////////////////////////////////// @@ -338,103 +357,103 @@ static void CountersInit(comedi_device *dev); //static const uint16_t EventBits[][4] = { EVBITS(0), EVBITS(1), EVBITS(2), EVBITS(3), EVBITS(4), EVBITS(5) }; /* enc_private; */ -static enc_private enc_private_data[]={ - { - GetEnable: GetEnable_A, - GetIntSrc: GetIntSrc_A, - GetLoadTrig: GetLoadTrig_A, - GetMode: GetMode_A, - PulseIndex: PulseIndex_A, - SetEnable: SetEnable_A, - SetIntSrc: SetIntSrc_A, - SetLoadTrig: SetLoadTrig_A, - SetMode: SetMode_A, - ResetCapFlags: ResetCapFlags_A, - MyCRA: LP_CR0A, - MyCRB: LP_CR0B, - MyLatchLsw: LP_CNTR0ALSW, - MyEventBits: EVBITS(0), - }, - { - GetEnable: GetEnable_A, - GetIntSrc: GetIntSrc_A, - GetLoadTrig: GetLoadTrig_A, - GetMode: GetMode_A, - PulseIndex: PulseIndex_A, - SetEnable: SetEnable_A, - SetIntSrc: SetIntSrc_A, - SetLoadTrig: SetLoadTrig_A, - SetMode: SetMode_A, - ResetCapFlags: ResetCapFlags_A, - MyCRA: LP_CR1A, - MyCRB: LP_CR1B, - MyLatchLsw: LP_CNTR1ALSW, - MyEventBits: EVBITS(1), - }, - { - GetEnable: GetEnable_A, - GetIntSrc: GetIntSrc_A, - GetLoadTrig: GetLoadTrig_A, - GetMode: GetMode_A, - PulseIndex: PulseIndex_A, - SetEnable: SetEnable_A, - SetIntSrc: SetIntSrc_A, - SetLoadTrig: SetLoadTrig_A, - SetMode: SetMode_A, - ResetCapFlags: ResetCapFlags_A, - MyCRA: LP_CR2A, - MyCRB: LP_CR2B, - MyLatchLsw: LP_CNTR2ALSW, - MyEventBits: EVBITS(2), - }, - { - GetEnable: GetEnable_B, - GetIntSrc: GetIntSrc_B, - GetLoadTrig: GetLoadTrig_B, - GetMode: GetMode_B, - PulseIndex: PulseIndex_B, - SetEnable: SetEnable_B, - SetIntSrc: SetIntSrc_B, - SetLoadTrig: SetLoadTrig_B, - SetMode: SetMode_B, - ResetCapFlags: ResetCapFlags_B, - MyCRA: LP_CR0A, - MyCRB: LP_CR0B, - MyLatchLsw: LP_CNTR0BLSW, - MyEventBits: EVBITS(3), - }, - { - GetEnable: GetEnable_B, - GetIntSrc: GetIntSrc_B, - GetLoadTrig: GetLoadTrig_B, - GetMode: GetMode_B, - PulseIndex: PulseIndex_B, - SetEnable: SetEnable_B, - SetIntSrc: SetIntSrc_B, - SetLoadTrig: SetLoadTrig_B, - SetMode: SetMode_B, - ResetCapFlags: ResetCapFlags_B, - MyCRA: LP_CR1A, - MyCRB: LP_CR1B, - MyLatchLsw: LP_CNTR1BLSW, - MyEventBits: EVBITS(4), - }, - { - GetEnable: GetEnable_B, - GetIntSrc: GetIntSrc_B, - GetLoadTrig: GetLoadTrig_B, - GetMode: GetMode_B, - PulseIndex: PulseIndex_B, - SetEnable: SetEnable_B, - SetIntSrc: SetIntSrc_B, - SetLoadTrig: SetLoadTrig_B, - SetMode: SetMode_B, - ResetCapFlags: ResetCapFlags_B, - MyCRA: LP_CR2A, - MyCRB: LP_CR2B, - MyLatchLsw: LP_CNTR2BLSW, - MyEventBits: EVBITS(5), - }, +static enc_private enc_private_data[] = { + { + GetEnable:GetEnable_A, + GetIntSrc:GetIntSrc_A, + GetLoadTrig:GetLoadTrig_A, + GetMode: GetMode_A, + PulseIndex:PulseIndex_A, + SetEnable:SetEnable_A, + SetIntSrc:SetIntSrc_A, + SetLoadTrig:SetLoadTrig_A, + SetMode: SetMode_A, + ResetCapFlags:ResetCapFlags_A, + MyCRA: LP_CR0A, + MyCRB: LP_CR0B, + MyLatchLsw:LP_CNTR0ALSW, + MyEventBits:EVBITS(0), + }, + { + GetEnable:GetEnable_A, + GetIntSrc:GetIntSrc_A, + GetLoadTrig:GetLoadTrig_A, + GetMode: GetMode_A, + PulseIndex:PulseIndex_A, + SetEnable:SetEnable_A, + SetIntSrc:SetIntSrc_A, + SetLoadTrig:SetLoadTrig_A, + SetMode: SetMode_A, + ResetCapFlags:ResetCapFlags_A, + MyCRA: LP_CR1A, + MyCRB: LP_CR1B, + MyLatchLsw:LP_CNTR1ALSW, + MyEventBits:EVBITS(1), + }, + { + GetEnable:GetEnable_A, + GetIntSrc:GetIntSrc_A, + GetLoadTrig:GetLoadTrig_A, + GetMode: GetMode_A, + PulseIndex:PulseIndex_A, + SetEnable:SetEnable_A, + SetIntSrc:SetIntSrc_A, + SetLoadTrig:SetLoadTrig_A, + SetMode: SetMode_A, + ResetCapFlags:ResetCapFlags_A, + MyCRA: LP_CR2A, + MyCRB: LP_CR2B, + MyLatchLsw:LP_CNTR2ALSW, + MyEventBits:EVBITS(2), + }, + { + GetEnable:GetEnable_B, + GetIntSrc:GetIntSrc_B, + GetLoadTrig:GetLoadTrig_B, + GetMode: GetMode_B, + PulseIndex:PulseIndex_B, + SetEnable:SetEnable_B, + SetIntSrc:SetIntSrc_B, + SetLoadTrig:SetLoadTrig_B, + SetMode: SetMode_B, + ResetCapFlags:ResetCapFlags_B, + MyCRA: LP_CR0A, + MyCRB: LP_CR0B, + MyLatchLsw:LP_CNTR0BLSW, + MyEventBits:EVBITS(3), + }, + { + GetEnable:GetEnable_B, + GetIntSrc:GetIntSrc_B, + GetLoadTrig:GetLoadTrig_B, + GetMode: GetMode_B, + PulseIndex:PulseIndex_B, + SetEnable:SetEnable_B, + SetIntSrc:SetIntSrc_B, + SetLoadTrig:SetLoadTrig_B, + SetMode: SetMode_B, + ResetCapFlags:ResetCapFlags_B, + MyCRA: LP_CR1A, + MyCRB: LP_CR1B, + MyLatchLsw:LP_CNTR1BLSW, + MyEventBits:EVBITS(4), + }, + { + GetEnable:GetEnable_B, + GetIntSrc:GetIntSrc_B, + GetLoadTrig:GetLoadTrig_B, + GetMode: GetMode_B, + PulseIndex:PulseIndex_B, + SetEnable:SetEnable_B, + SetIntSrc:SetIntSrc_B, + SetLoadTrig:SetLoadTrig_B, + SetMode: SetMode_B, + ResetCapFlags:ResetCapFlags_B, + MyCRA: LP_CR2A, + MyCRB: LP_CR2B, + MyLatchLsw:LP_CNTR2BLSW, + MyEventBits:EVBITS(5), + }, }; // enab/disable a function or test status bit(s) that are accessed @@ -464,297 +483,304 @@ static enc_private enc_private_data[]={ #define I2C_B1(ATTR,VAL) ( ( (ATTR) << 4 ) | ( (VAL) << 16 ) ) #define I2C_B0(ATTR,VAL) ( ( (ATTR) << 2 ) | ( (VAL) << 8 ) ) -static const comedi_lrange s626_range_table={ 2,{ - RANGE(-5 , 5), - RANGE(-10, 10), -}}; +static const comedi_lrange s626_range_table = { 2, { + RANGE(-5, 5), + RANGE(-10, 10), + } +}; -static int s626_attach(comedi_device *dev,comedi_devconfig *it) +static int s626_attach(comedi_device * dev, comedi_devconfig * it) { /* uint8_t PollList; */ /* uint16_t AdcData; */ /* uint16_t StartVal; */ /* uint16_t index; */ /* unsigned int data[16]; */ - int result; - int i; - int ret; - resource_size_t resourceStart; - dma_addr_t appdma; - comedi_subdevice *s; - struct pci_dev *pdev; - - if(alloc_private(dev,sizeof(s626_private))<0) - return -ENOMEM; - - pdev=pci_get_device(PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626, NULL); + int result; + int i; + int ret; + resource_size_t resourceStart; + dma_addr_t appdma; + comedi_subdevice *s; + struct pci_dev *pdev; + + if (alloc_private(dev, sizeof(s626_private)) < 0) + return -ENOMEM; + + pdev = pci_get_device(PCI_VENDOR_ID_S626, PCI_DEVICE_ID_S626, NULL); devpriv->pdev = pdev; - if(pdev==NULL) { - printk("s626_attach: Board not present!!!"); - return -ENODEV; - } - - if((result = comedi_pci_enable(pdev, "s626"))<0){ - printk("s626_attach: comedi_pci_enable fails\n"); - return -ENODEV; - } - devpriv->got_regions = 1; - - resourceStart=pci_resource_start(devpriv->pdev,0); - - devpriv->base_addr=ioremap(resourceStart, SIZEOF_ADDRESS_SPACE); - if (devpriv->base_addr==NULL) { - printk("s626_attach: IOREMAP failed\n"); - return -ENODEV; - } - - if (devpriv->base_addr){ - //disable master interrupt - writel(0,devpriv->base_addr+P_IER); - - //soft reset - writel(MC1_SOFT_RESET,devpriv->base_addr+P_MC1); - - //DMA FIXME DMA// - DEBUG("s626_attach: DMA ALLOCATION\n"); - - //adc buffer allocation - devpriv->allocatedBuf=0; - - if((devpriv->ANABuf.LogicalBase = pci_alloc_consistent (devpriv->pdev, DMABUF_SIZE, &appdma))==NULL){ - printk("s626_attach: DMA Memory mapping error\n"); - return -ENOMEM; - } - - devpriv->ANABuf.PhysicalBase=appdma; - - DEBUG("s626_attach: AllocDMAB ADC Logical=%p, bsize=%d, Physical=0x%x\n", - devpriv->ANABuf.LogicalBase, DMABUF_SIZE, (uint32_t)devpriv->ANABuf.PhysicalBase); - - devpriv->allocatedBuf++; - - if((devpriv->RPSBuf.LogicalBase = pci_alloc_consistent (devpriv->pdev, DMABUF_SIZE, &appdma)) ==NULL){ - printk("s626_attach: DMA Memory mapping error\n"); - return -ENOMEM; - } - - devpriv->RPSBuf.PhysicalBase=appdma; - - DEBUG("s626_attach: AllocDMAB RPS Logical=%p, bsize=%d, Physical=0x%x\n", - devpriv->RPSBuf.LogicalBase, DMABUF_SIZE, (uint32_t)devpriv->RPSBuf.PhysicalBase); - - devpriv->allocatedBuf++; - - } - - dev->board_ptr = s626_boards; - dev->board_name = thisboard->name; - - if(alloc_subdevices(dev, 6)<0) - return -ENOMEM; - - dev->iobase = (unsigned long)devpriv->base_addr; - dev->irq = devpriv->pdev->irq; - - //set up interrupt handler - if(dev->irq==0){ - printk(" unknown irq (bad)\n"); - }else{ - if( (ret=comedi_request_irq(dev->irq,s626_irq_handler,IRQF_SHARED,"s626",dev))<0 ){ - printk(" irq not available\n"); - dev->irq=0; - } - } - - DEBUG("s626_attach: -- it opts %d -- \n",it->options[0]); - - s=dev->subdevices+0; - /* analog input subdevice */ - dev->read_subdev = s; - /* we support single-ended (ground) and differential */ - s->type=COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE | SDF_DIFF |SDF_CMD_READ; - s->n_chan=thisboard->ai_chans; - s->maxdata=(0xffff >> 2); - s->range_table=&s626_range_table; - s->len_chanlist=thisboard->ai_chans; /* This is the maximum chanlist - length that the board can - handle */ - s->insn_config = s626_ai_insn_config; - s->insn_read = s626_ai_insn_read; - s->do_cmd = s626_ai_cmd; - s->do_cmdtest = s626_ai_cmdtest; - s->cancel = s626_ai_cancel; - - s=dev->subdevices+1; - /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE|SDF_READABLE; - s->n_chan=thisboard->ao_chans; - s->maxdata=(0x3fff); - s->range_table=&range_bipolar10; - s->insn_write = s626_ao_winsn; - s->insn_read = s626_ao_rinsn; - - s=dev->subdevices+2; - /* digital I/O subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_WRITABLE|SDF_READABLE; - s->n_chan=S626_DIO_CHANNELS; - s->maxdata=1; - s->io_bits=0xffff; - s->private=&dio_private_A; - s->range_table=&range_digital; - s->insn_config=s626_dio_insn_config; - s->insn_bits = s626_dio_insn_bits; - - s=dev->subdevices+3; - /* digital I/O subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_WRITABLE|SDF_READABLE; - s->n_chan=16; - s->maxdata=1; - s->io_bits=0xffff; - s->private=&dio_private_B; - s->range_table=&range_digital; - s->insn_config=s626_dio_insn_config; - s->insn_bits = s626_dio_insn_bits; - - s=dev->subdevices+4; - /* digital I/O subdevice */ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_WRITABLE|SDF_READABLE; - s->n_chan=16; - s->maxdata=1; - s->io_bits=0xffff; - s->private=&dio_private_C; - s->range_table=&range_digital; - s->insn_config=s626_dio_insn_config; - s->insn_bits = s626_dio_insn_bits; - - s=dev->subdevices+5; - /* encoder (counter) subdevice */ - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL; - s->n_chan = thisboard->enc_chans; - s->private=enc_private_data; - s->insn_config = s626_enc_insn_config; - s->insn_read = s626_enc_insn_read; - s->insn_write = s626_enc_insn_write; - s->maxdata = 0xffffff; - s->range_table = &range_unknown; - - //stop ai_command - devpriv->ai_cmd_running=0; - - if (devpriv->base_addr && (devpriv->allocatedBuf==2)){ - dma_addr_t pPhysBuf; - uint16_t chan; - - // enab DEBI and audio pins, enable I2C interface. - MC_ENABLE( P_MC1, MC1_DEBI | MC1_AUDIO | MC1_I2C ); - // Configure DEBI operating mode. - WR7146( P_DEBICFG, DEBI_CFG_SLAVE16 // Local bus is 16 - // bits wide. - | ( DEBI_TOUT << DEBI_CFG_TOUT_BIT )// Declare DEBI - // transfer timeout - // interval. - | DEBI_SWAP // Set up byte lane - // steering. - | DEBI_CFG_INTEL ); // Intel-compatible - // local bus (DEBI - // never times out). - DEBUG("s626_attach: %d debi init -- %d\n", DEBI_CFG_SLAVE16| ( DEBI_TOUT << DEBI_CFG_TOUT_BIT )| DEBI_SWAP| DEBI_CFG_INTEL, DEBI_CFG_INTEL | DEBI_CFG_TOQ | DEBI_CFG_INCQ| DEBI_CFG_16Q); - - //DEBI INIT S626 WR7146( P_DEBICFG, DEBI_CFG_INTEL | DEBI_CFG_TOQ - //| DEBI_CFG_INCQ| DEBI_CFG_16Q); //end - - // Paging is disabled. - WR7146( P_DEBIPAGE, DEBI_PAGE_DISABLE ); // Disable MMU paging. - - // Init GPIO so that ADC Start* is negated. - WR7146( P_GPIO, GPIO_BASE | GPIO1_HI ); - - //IsBoardRevA is a boolean that indicates whether the board is - //RevA. - - // VERSION 2.01 CHANGE: REV A & B BOARDS NOW SUPPORTED BY DYNAMIC - // EEPROM ADDRESS SELECTION. Initialize the I2C interface, which - // is used to access the onboard serial EEPROM. The EEPROM's I2C - // DeviceAddress is hardwired to a value that is dependent on the - // 626 board revision. On all board revisions, the EEPROM stores - // TrimDAC calibration constants for analog I/O. On RevB and - // higher boards, the DeviceAddress is hardwired to 0 to enable - // the EEPROM to also store the PCI SubVendorID and SubDeviceID; - // this is the address at which the SAA7146 expects a - // configuration EEPROM to reside. On RevA boards, the EEPROM - // device address, which is hardwired to 4, prevents the SAA7146 - // from retrieving PCI sub-IDs, so the SAA7146 uses its built-in - // default values, instead. - - // devpriv->I2Cards= IsBoardRevA ? 0xA8 : 0xA0; // Set I2C EEPROM - // DeviceType (0xA0) - // and DeviceAddress<<1. - - devpriv->I2CAdrs=0xA0; // I2C device address for onboard - // eeprom(revb) - - // Issue an I2C ABORT command to halt any I2C operation in - //progress and reset BUSY flag. - WR7146( P_I2CSTAT, I2C_CLKSEL | I2C_ABORT );// Write I2C control: - // abort any I2C - // activity. - MC_ENABLE( P_MC2, MC2_UPLD_IIC ); // Invoke command - // upload - while ( ( RR7146(P_MC2) & MC2_UPLD_IIC ) == 0 );// and wait for - // upload to - // complete. - - // Per SAA7146 data sheet, write to STATUS reg twice to reset all - // I2C error flags. - for ( i = 0; i < 2; i++ ) - { - WR7146( P_I2CSTAT, I2C_CLKSEL ); // Write I2C control: reset - // error flags. - MC_ENABLE( P_MC2, MC2_UPLD_IIC ); // Invoke command upload - while ( !MC_TEST( P_MC2, MC2_UPLD_IIC ) ); // and wait for - // upload to - // complete. - } - - // Init audio interface functional attributes: set DAC/ADC serial - // clock rates, invert DAC serial clock so that DAC data setup - // times are satisfied, enable DAC serial clock out. - WR7146( P_ACON2, ACON2_INIT ); - - // Set up TSL1 slot list, which is used to control the - // accumulation of ADC data: RSD1 = shift data in on SD1. SIB_A1 - // = store data uint8_t at next available location in FB BUFFER1 - // register. - WR7146( P_TSL1 , RSD1 | SIB_A1 ); // Fetch ADC high data - // uint8_t. - WR7146( P_TSL1 + 4, RSD1 | SIB_A1 | EOS ); // Fetch ADC low data - // uint8_t; end of - // TSL1. - - // enab TSL1 slot list so that it executes all the time. - WR7146( P_ACON1, ACON1_ADCSTART ); - - // Initialize RPS registers used for ADC. - - //Physical start of RPS program. - WR7146( P_RPSADDR1, (uint32_t)devpriv->RPSBuf.PhysicalBase ); - - WR7146( P_RPSPAGE1, 0 ); // RPS program performs no - // explicit mem writes. - WR7146( P_RPS1_TOUT, 0 ); // Disable RPS timeouts. - - // SAA7146 BUG WORKAROUND. Initialize SAA7146 ADC interface to a - // known state by invoking ADCs until FB BUFFER 1 register shows - // that it is correctly receiving ADC data. This is necessary - // because the SAA7146 ADC interface does not start up in a - // defined state after a PCI reset. + if (pdev == NULL) { + printk("s626_attach: Board not present!!!"); + return -ENODEV; + } + + if ((result = comedi_pci_enable(pdev, "s626")) < 0) { + printk("s626_attach: comedi_pci_enable fails\n"); + return -ENODEV; + } + devpriv->got_regions = 1; + + resourceStart = pci_resource_start(devpriv->pdev, 0); + + devpriv->base_addr = ioremap(resourceStart, SIZEOF_ADDRESS_SPACE); + if (devpriv->base_addr == NULL) { + printk("s626_attach: IOREMAP failed\n"); + return -ENODEV; + } + + if (devpriv->base_addr) { + //disable master interrupt + writel(0, devpriv->base_addr + P_IER); + + //soft reset + writel(MC1_SOFT_RESET, devpriv->base_addr + P_MC1); + + //DMA FIXME DMA// + DEBUG("s626_attach: DMA ALLOCATION\n"); + + //adc buffer allocation + devpriv->allocatedBuf = 0; + + if ((devpriv->ANABuf.LogicalBase = + pci_alloc_consistent(devpriv->pdev, DMABUF_SIZE, + &appdma)) == NULL) { + printk("s626_attach: DMA Memory mapping error\n"); + return -ENOMEM; + } + + devpriv->ANABuf.PhysicalBase = appdma; + + DEBUG("s626_attach: AllocDMAB ADC Logical=%p, bsize=%d, Physical=0x%x\n", devpriv->ANABuf.LogicalBase, DMABUF_SIZE, (uint32_t) devpriv->ANABuf.PhysicalBase); + + devpriv->allocatedBuf++; + + if ((devpriv->RPSBuf.LogicalBase = + pci_alloc_consistent(devpriv->pdev, DMABUF_SIZE, + &appdma)) == NULL) { + printk("s626_attach: DMA Memory mapping error\n"); + return -ENOMEM; + } + + devpriv->RPSBuf.PhysicalBase = appdma; + + DEBUG("s626_attach: AllocDMAB RPS Logical=%p, bsize=%d, Physical=0x%x\n", devpriv->RPSBuf.LogicalBase, DMABUF_SIZE, (uint32_t) devpriv->RPSBuf.PhysicalBase); + + devpriv->allocatedBuf++; + + } + + dev->board_ptr = s626_boards; + dev->board_name = thisboard->name; + + if (alloc_subdevices(dev, 6) < 0) + return -ENOMEM; + + dev->iobase = (unsigned long)devpriv->base_addr; + dev->irq = devpriv->pdev->irq; + + //set up interrupt handler + if (dev->irq == 0) { + printk(" unknown irq (bad)\n"); + } else { + if ((ret = comedi_request_irq(dev->irq, s626_irq_handler, + IRQF_SHARED, "s626", dev)) < 0) { + printk(" irq not available\n"); + dev->irq = 0; + } + } + + DEBUG("s626_attach: -- it opts %d -- \n", it->options[0]); + + s = dev->subdevices + 0; + /* analog input subdevice */ + dev->read_subdev = s; + /* we support single-ended (ground) and differential */ + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_CMD_READ; + s->n_chan = thisboard->ai_chans; + s->maxdata = (0xffff >> 2); + s->range_table = &s626_range_table; + s->len_chanlist = thisboard->ai_chans; /* This is the maximum chanlist + length that the board can + handle */ + s->insn_config = s626_ai_insn_config; + s->insn_read = s626_ai_insn_read; + s->do_cmd = s626_ai_cmd; + s->do_cmdtest = s626_ai_cmdtest; + s->cancel = s626_ai_cancel; + + s = dev->subdevices + 1; + /* analog output subdevice */ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE; + s->n_chan = thisboard->ao_chans; + s->maxdata = (0x3fff); + s->range_table = &range_bipolar10; + s->insn_write = s626_ao_winsn; + s->insn_read = s626_ao_rinsn; + + s = dev->subdevices + 2; + /* digital I/O subdevice */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE; + s->n_chan = S626_DIO_CHANNELS; + s->maxdata = 1; + s->io_bits = 0xffff; + s->private = &dio_private_A; + s->range_table = &range_digital; + s->insn_config = s626_dio_insn_config; + s->insn_bits = s626_dio_insn_bits; + + s = dev->subdevices + 3; + /* digital I/O subdevice */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->io_bits = 0xffff; + s->private = &dio_private_B; + s->range_table = &range_digital; + s->insn_config = s626_dio_insn_config; + s->insn_bits = s626_dio_insn_bits; + + s = dev->subdevices + 4; + /* digital I/O subdevice */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->io_bits = 0xffff; + s->private = &dio_private_C; + s->range_table = &range_digital; + s->insn_config = s626_dio_insn_config; + s->insn_bits = s626_dio_insn_bits; + + s = dev->subdevices + 5; + /* encoder (counter) subdevice */ + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL; + s->n_chan = thisboard->enc_chans; + s->private = enc_private_data; + s->insn_config = s626_enc_insn_config; + s->insn_read = s626_enc_insn_read; + s->insn_write = s626_enc_insn_write; + s->maxdata = 0xffffff; + s->range_table = &range_unknown; + + //stop ai_command + devpriv->ai_cmd_running = 0; + + if (devpriv->base_addr && (devpriv->allocatedBuf == 2)) { + dma_addr_t pPhysBuf; + uint16_t chan; + + // enab DEBI and audio pins, enable I2C interface. + MC_ENABLE(P_MC1, MC1_DEBI | MC1_AUDIO | MC1_I2C); + // Configure DEBI operating mode. + WR7146(P_DEBICFG, DEBI_CFG_SLAVE16 // Local bus is 16 + // bits wide. + | (DEBI_TOUT << DEBI_CFG_TOUT_BIT) // Declare DEBI + // transfer timeout + // interval. + | DEBI_SWAP // Set up byte lane + // steering. + | DEBI_CFG_INTEL); // Intel-compatible + // local bus (DEBI + // never times out). + DEBUG("s626_attach: %d debi init -- %d\n", + DEBI_CFG_SLAVE16 | (DEBI_TOUT << DEBI_CFG_TOUT_BIT) | + DEBI_SWAP | DEBI_CFG_INTEL, + DEBI_CFG_INTEL | DEBI_CFG_TOQ | DEBI_CFG_INCQ | + DEBI_CFG_16Q); + + //DEBI INIT S626 WR7146( P_DEBICFG, DEBI_CFG_INTEL | DEBI_CFG_TOQ + //| DEBI_CFG_INCQ| DEBI_CFG_16Q); //end + + // Paging is disabled. + WR7146(P_DEBIPAGE, DEBI_PAGE_DISABLE); // Disable MMU paging. + + // Init GPIO so that ADC Start* is negated. + WR7146(P_GPIO, GPIO_BASE | GPIO1_HI); + + //IsBoardRevA is a boolean that indicates whether the board is + //RevA. + + // VERSION 2.01 CHANGE: REV A & B BOARDS NOW SUPPORTED BY DYNAMIC + // EEPROM ADDRESS SELECTION. Initialize the I2C interface, which + // is used to access the onboard serial EEPROM. The EEPROM's I2C + // DeviceAddress is hardwired to a value that is dependent on the + // 626 board revision. On all board revisions, the EEPROM stores + // TrimDAC calibration constants for analog I/O. On RevB and + // higher boards, the DeviceAddress is hardwired to 0 to enable + // the EEPROM to also store the PCI SubVendorID and SubDeviceID; + // this is the address at which the SAA7146 expects a + // configuration EEPROM to reside. On RevA boards, the EEPROM + // device address, which is hardwired to 4, prevents the SAA7146 + // from retrieving PCI sub-IDs, so the SAA7146 uses its built-in + // default values, instead. + + // devpriv->I2Cards= IsBoardRevA ? 0xA8 : 0xA0; // Set I2C EEPROM + // DeviceType (0xA0) + // and DeviceAddress<<1. + + devpriv->I2CAdrs = 0xA0; // I2C device address for onboard + // eeprom(revb) + + // Issue an I2C ABORT command to halt any I2C operation in + //progress and reset BUSY flag. + WR7146(P_I2CSTAT, I2C_CLKSEL | I2C_ABORT); // Write I2C control: + // abort any I2C + // activity. + MC_ENABLE(P_MC2, MC2_UPLD_IIC); // Invoke command + // upload + while ((RR7146(P_MC2) & MC2_UPLD_IIC) == 0) ; // and wait for + // upload to + // complete. + + // Per SAA7146 data sheet, write to STATUS reg twice to reset all + // I2C error flags. + for (i = 0; i < 2; i++) { + WR7146(P_I2CSTAT, I2C_CLKSEL); // Write I2C control: reset + // error flags. + MC_ENABLE(P_MC2, MC2_UPLD_IIC); // Invoke command upload + while (!MC_TEST(P_MC2, MC2_UPLD_IIC)) ; // and wait for + // upload to + // complete. + } + + // Init audio interface functional attributes: set DAC/ADC serial + // clock rates, invert DAC serial clock so that DAC data setup + // times are satisfied, enable DAC serial clock out. + WR7146(P_ACON2, ACON2_INIT); + + // Set up TSL1 slot list, which is used to control the + // accumulation of ADC data: RSD1 = shift data in on SD1. SIB_A1 + // = store data uint8_t at next available location in FB BUFFER1 + // register. + WR7146(P_TSL1, RSD1 | SIB_A1); // Fetch ADC high data + // uint8_t. + WR7146(P_TSL1 + 4, RSD1 | SIB_A1 | EOS); // Fetch ADC low data + // uint8_t; end of + // TSL1. + + // enab TSL1 slot list so that it executes all the time. + WR7146(P_ACON1, ACON1_ADCSTART); + + // Initialize RPS registers used for ADC. + + //Physical start of RPS program. + WR7146(P_RPSADDR1, (uint32_t) devpriv->RPSBuf.PhysicalBase); + + WR7146(P_RPSPAGE1, 0); // RPS program performs no + // explicit mem writes. + WR7146(P_RPS1_TOUT, 0); // Disable RPS timeouts. + + // SAA7146 BUG WORKAROUND. Initialize SAA7146 ADC interface to a + // known state by invoking ADCs until FB BUFFER 1 register shows + // that it is correctly receiving ADC data. This is necessary + // because the SAA7146 ADC interface does not start up in a + // defined state after a PCI reset. /* PollList = EOPL; // Create a simple polling */ /* // list for analog input */ @@ -782,450 +808,491 @@ static int s626_attach(comedi_device *dev,comedi_devconfig *it) /* break; */ /* } */ - // end initADC - - // init the DAC interface - - // Init Audio2's output DMAC attributes: burst length = 1 DWORD, - // threshold = 1 DWORD. - WR7146( P_PCI_BT_A, 0 ); - - // Init Audio2's output DMA physical addresses. The protection - // address is set to 1 DWORD past the base address so that a - // single DWORD will be transferred each time a DMA transfer is - // enabled. - - pPhysBuf = devpriv->ANABuf.PhysicalBase + (DAC_WDMABUF_OS * sizeof(uint32_t)); - - WR7146( P_BASEA2_OUT, (uint32_t) pPhysBuf ); // Buffer base adrs. - WR7146( P_PROTA2_OUT, (uint32_t) (pPhysBuf + sizeof(uint32_t)) ); // Protection address. - - // Cache Audio2's output DMA buffer logical address. This is - // where DAC data is buffered for A2 output DMA transfers. - devpriv->pDacWBuf = (uint32_t *)devpriv->ANABuf.LogicalBase + DAC_WDMABUF_OS; - - // Audio2's output channels does not use paging. The protection - // violation handling bit is set so that the DMAC will - // automatically halt and its PCI address pointer will be reset - // when the protection address is reached. - WR7146( P_PAGEA2_OUT, 8 ); - - // Initialize time slot list 2 (TSL2), which is used to control - // the clock generation for and serialization of data to be sent - // to the DAC devices. Slot 0 is a NOP that is used to trap TSL - // execution; this permits other slots to be safely modified - // without first turning off the TSL sequencer (which is - // apparently impossible to do). Also, SD3 (which is driven by a - // pull-up resistor) is shifted in and stored to the MSB of - // FB_BUFFER2 to be used as evidence that the slot sequence has - // not yet finished executing. - SETVECT( 0, XSD2 | RSD3 | SIB_A2 | EOS ); // Slot 0: Trap TSL - // execution, shift 0xFF - // into FB_BUFFER2. - - // Initialize slot 1, which is constant. Slot 1 causes a DWORD to - // be transferred from audio channel 2's output FIFO to the FIFO's - // output buffer so that it can be serialized and sent to the DAC - // during subsequent slots. All remaining slots are dynamically - // populated as required by the target DAC device. - SETVECT( 1, LF_A2 ); // Slot 1: Fetch DWORD from Audio2's - // output FIFO. - - // Start DAC's audio interface (TSL2) running. - WR7146( P_ACON1, ACON1_DACSTART ); - - //////////////////////////////////////////////////////// - - // end init DAC interface - - // Init Trim DACs to calibrated values. Do it twice because the - // SAA7146 audio channel does not always reset properly and - // sometimes causes the first few TrimDAC writes to malfunction. - - LoadTrimDACs( dev); - LoadTrimDACs( dev); // Insurance. - - ////////////////////////////////////////////////////////////////// - // Manually init all gate array hardware in case this is a soft - // reset (we have no way of determining whether this is a warm or - // cold start). This is necessary because the gate array will - // reset only in response to a PCI hard reset; there is no soft - // reset function. - - // Init all DAC outputs to 0V and init all DAC setpoint and - // polarity images. - for ( chan = 0; chan < S626_DAC_CHANNELS; chan++) - SetDAC(dev,chan, 0 ); - - // Init image of WRMISC2 Battery Charger Enabled control bit. - // This image is used when the state of the charger control bit, - // which has no direct hardware readback mechanism, is queried. - devpriv->ChargeEnabled = 0; - - // Init image of watchdog timer interval in WRMISC2. This image - // maintains the value of the control bits of MISC2 are - // continuously reset to zero as long as the WD timer is disabled. - devpriv->WDInterval = 0; - - // Init Counter Interrupt enab mask for RDMISC2. This mask is - // applied against MISC2 when testing to determine which timer - // events are requesting interrupt service. - devpriv->CounterIntEnabs = 0; - - // Init counters. - CountersInit(dev); - - // Without modifying the state of the Battery Backup enab, disable - // the watchdog timer, set DIO channels 0-5 to operate in the - // standard DIO (vs. counter overflow) mode, disable the battery - // charger, and reset the watchdog interval selector to zero. - WriteMISC2(dev, (uint16_t)( DEBIread( dev,LP_RDMISC2 ) & MISC2_BATT_ENABLE ) ); - - // Initialize the digital I/O subsystem. - s626_dio_init(dev); - - //enable interrupt test - // writel(IRQ_GPIO3 | IRQ_RPS1,devpriv->base_addr+P_IER); - } - - DEBUG("s626_attach: comedi%d s626 attached %04x\n",dev->minor,(uint32_t)devpriv->base_addr); - - return 1; + // end initADC + + // init the DAC interface + + // Init Audio2's output DMAC attributes: burst length = 1 DWORD, + // threshold = 1 DWORD. + WR7146(P_PCI_BT_A, 0); + + // Init Audio2's output DMA physical addresses. The protection + // address is set to 1 DWORD past the base address so that a + // single DWORD will be transferred each time a DMA transfer is + // enabled. + + pPhysBuf = + devpriv->ANABuf.PhysicalBase + + (DAC_WDMABUF_OS * sizeof(uint32_t)); + + WR7146(P_BASEA2_OUT, (uint32_t) pPhysBuf); // Buffer base adrs. + WR7146(P_PROTA2_OUT, (uint32_t) (pPhysBuf + sizeof(uint32_t))); // Protection address. + + // Cache Audio2's output DMA buffer logical address. This is + // where DAC data is buffered for A2 output DMA transfers. + devpriv->pDacWBuf = + (uint32_t *) devpriv->ANABuf.LogicalBase + + DAC_WDMABUF_OS; + + // Audio2's output channels does not use paging. The protection + // violation handling bit is set so that the DMAC will + // automatically halt and its PCI address pointer will be reset + // when the protection address is reached. + WR7146(P_PAGEA2_OUT, 8); + + // Initialize time slot list 2 (TSL2), which is used to control + // the clock generation for and serialization of data to be sent + // to the DAC devices. Slot 0 is a NOP that is used to trap TSL + // execution; this permits other slots to be safely modified + // without first turning off the TSL sequencer (which is + // apparently impossible to do). Also, SD3 (which is driven by a + // pull-up resistor) is shifted in and stored to the MSB of + // FB_BUFFER2 to be used as evidence that the slot sequence has + // not yet finished executing. + SETVECT(0, XSD2 | RSD3 | SIB_A2 | EOS); // Slot 0: Trap TSL + // execution, shift 0xFF + // into FB_BUFFER2. + + // Initialize slot 1, which is constant. Slot 1 causes a DWORD to + // be transferred from audio channel 2's output FIFO to the FIFO's + // output buffer so that it can be serialized and sent to the DAC + // during subsequent slots. All remaining slots are dynamically + // populated as required by the target DAC device. + SETVECT(1, LF_A2); // Slot 1: Fetch DWORD from Audio2's + // output FIFO. + + // Start DAC's audio interface (TSL2) running. + WR7146(P_ACON1, ACON1_DACSTART); + + //////////////////////////////////////////////////////// + + // end init DAC interface + + // Init Trim DACs to calibrated values. Do it twice because the + // SAA7146 audio channel does not always reset properly and + // sometimes causes the first few TrimDAC writes to malfunction. + + LoadTrimDACs(dev); + LoadTrimDACs(dev); // Insurance. + + ////////////////////////////////////////////////////////////////// + // Manually init all gate array hardware in case this is a soft + // reset (we have no way of determining whether this is a warm or + // cold start). This is necessary because the gate array will + // reset only in response to a PCI hard reset; there is no soft + // reset function. + + // Init all DAC outputs to 0V and init all DAC setpoint and + // polarity images. + for (chan = 0; chan < S626_DAC_CHANNELS; chan++) + SetDAC(dev, chan, 0); + + // Init image of WRMISC2 Battery Charger Enabled control bit. + // This image is used when the state of the charger control bit, + // which has no direct hardware readback mechanism, is queried. + devpriv->ChargeEnabled = 0; + + // Init image of watchdog timer interval in WRMISC2. This image + // maintains the value of the control bits of MISC2 are + // continuously reset to zero as long as the WD timer is disabled. + devpriv->WDInterval = 0; + + // Init Counter Interrupt enab mask for RDMISC2. This mask is + // applied against MISC2 when testing to determine which timer + // events are requesting interrupt service. + devpriv->CounterIntEnabs = 0; + + // Init counters. + CountersInit(dev); + + // Without modifying the state of the Battery Backup enab, disable + // the watchdog timer, set DIO channels 0-5 to operate in the + // standard DIO (vs. counter overflow) mode, disable the battery + // charger, and reset the watchdog interval selector to zero. + WriteMISC2(dev, (uint16_t) (DEBIread(dev, + LP_RDMISC2) & MISC2_BATT_ENABLE)); + + // Initialize the digital I/O subsystem. + s626_dio_init(dev); + + //enable interrupt test + // writel(IRQ_GPIO3 | IRQ_RPS1,devpriv->base_addr+P_IER); + } + + DEBUG("s626_attach: comedi%d s626 attached %04x\n", dev->minor, + (uint32_t) devpriv->base_addr); + + return 1; } -static lsampl_t s626_ai_reg_to_uint(int data){ - lsampl_t tempdata; +static lsampl_t s626_ai_reg_to_uint(int data) +{ + lsampl_t tempdata; - tempdata=(data >> 18); - if(tempdata&0x2000) - tempdata&=0x1fff; - else - tempdata+=(1<<13); + tempdata = (data >> 18); + if (tempdata & 0x2000) + tempdata &= 0x1fff; + else + tempdata += (1 << 13); - return tempdata; + return tempdata; } /* static lsampl_t s626_uint_to_reg(comedi_subdevice *s, int data){ */ /* return 0; */ /* } */ -static irqreturn_t s626_irq_handler(int irq,void *d PT_REGS_ARG) +static irqreturn_t s626_irq_handler(int irq, void *d PT_REGS_ARG) { - comedi_device *dev=d; - comedi_subdevice *s; - comedi_cmd *cmd; - enc_private *k; - unsigned long flags; - int32_t *readaddr; - uint32_t irqtype,irqstatus,datacount; - int kernel_transfer=0; - int i=0; - sampl_t *databuf=NULL; - sampl_t tempdata; - uint8_t group; - uint16_t irqbit; - - DEBUG("s626_irq_handler: interrupt request recieved!!!\n"); - - if(dev->attached == 0) return IRQ_NONE; - // lock to avoid race with comedi_poll - comedi_spin_lock_irqsave(&dev->spinlock, flags); - - //save interrupt enable register state - irqstatus=readl(devpriv->base_addr+P_IER); - - //read interrupt type - irqtype=readl(devpriv->base_addr+P_ISR); - - //disable master interrupt - writel(0,devpriv->base_addr+P_IER); - - //clear interrupt - writel(irqtype,devpriv->base_addr+P_ISR); - - //do somethings - DEBUG("s626_irq_handler: interrupt type %d\n",irqtype); - - switch(irqtype){ - case IRQ_RPS1: // end_of_scan occurs - - DEBUG("s626_irq_handler: RPS1 irq detected\n"); - - // manage ai subdevice - s=dev->subdevices; - cmd=&(s->async->cmd); - - // verify if data buffer exists - if(s->async->cmd.data!=NULL){ - DEBUG("s626_irq_handler: Kernel transfer asserted\n"); - kernel_transfer=1; - databuf=s->async->cmd.data; - datacount=s->async->cmd.data_len; - } - - // Init ptr to DMA buffer that holds new ADC data. We skip the - // first uint16_t in the buffer because it contains junk data from - // the final ADC of the previous poll list scan. - readaddr = (int32_t *)devpriv->ANABuf.LogicalBase + 1; - - // get the data and hand it over to comedi - for(i=0;i<(s->async->cmd.chanlist_len);i++) { - // Convert ADC data to 16-bit integer values and copy to application - // buffer. - tempdata=s626_ai_reg_to_uint((int)*readaddr); - readaddr++; - - if(kernel_transfer){ - //send buffer overflow event - DEBUG("s626_irq_handler: in kernel transfer...\n"); - if(datacount<0){ - s->async->events|=COMEDI_CB_OVERFLOW; - } else { - datacount--; - // transfer data - *databuf++=tempdata; - } - } - - //put data into read buffer - // comedi_buf_put(s->async, tempdata); - if(cfc_write_to_buffer(s,tempdata)==0) printk("s626_irq_handler: cfc_write_to_buffer error!\n"); - - DEBUG("s626_irq_handler: ai channel %d acquired: %d\n",i,tempdata); - } - - //end of scan occurs - s->async->events|=COMEDI_CB_EOS; - - if(!(devpriv->ai_continous)) devpriv->ai_sample_count--; - if(devpriv->ai_sample_count<=0){ - devpriv->ai_cmd_running=0; - - // Stop RPS program. - MC_DISABLE( P_MC1, MC1_ERPS1 ); - - //send end of acquisition - s->async->events|=COMEDI_CB_EOA; - - //disable master interrupt - irqstatus=0; - } - - if(devpriv->ai_cmd_running && cmd->scan_begin_src==TRIG_EXT){ - DEBUG("s626_irq_handler: enable interrupt on dio channel %d\n",cmd->scan_begin_arg); + comedi_device *dev = d; + comedi_subdevice *s; + comedi_cmd *cmd; + enc_private *k; + unsigned long flags; + int32_t *readaddr; + uint32_t irqtype, irqstatus, datacount; + int kernel_transfer = 0; + int i = 0; + sampl_t *databuf = NULL; + sampl_t tempdata; + uint8_t group; + uint16_t irqbit; + + DEBUG("s626_irq_handler: interrupt request recieved!!!\n"); + + if (dev->attached == 0) + return IRQ_NONE; + // lock to avoid race with comedi_poll + comedi_spin_lock_irqsave(&dev->spinlock, flags); + + //save interrupt enable register state + irqstatus = readl(devpriv->base_addr + P_IER); + + //read interrupt type + irqtype = readl(devpriv->base_addr + P_ISR); + + //disable master interrupt + writel(0, devpriv->base_addr + P_IER); + + //clear interrupt + writel(irqtype, devpriv->base_addr + P_ISR); + + //do somethings + DEBUG("s626_irq_handler: interrupt type %d\n", irqtype); + + switch (irqtype) { + case IRQ_RPS1: // end_of_scan occurs + + DEBUG("s626_irq_handler: RPS1 irq detected\n"); + + // manage ai subdevice + s = dev->subdevices; + cmd = &(s->async->cmd); + + // verify if data buffer exists + if (s->async->cmd.data != NULL) { + DEBUG("s626_irq_handler: Kernel transfer asserted\n"); + kernel_transfer = 1; + databuf = s->async->cmd.data; + datacount = s->async->cmd.data_len; + } + // Init ptr to DMA buffer that holds new ADC data. We skip the + // first uint16_t in the buffer because it contains junk data from + // the final ADC of the previous poll list scan. + readaddr = (int32_t *) devpriv->ANABuf.LogicalBase + 1; + + // get the data and hand it over to comedi + for (i = 0; i < (s->async->cmd.chanlist_len); i++) { + // Convert ADC data to 16-bit integer values and copy to application + // buffer. + tempdata = s626_ai_reg_to_uint((int)*readaddr); + readaddr++; + + if (kernel_transfer) { + //send buffer overflow event + DEBUG("s626_irq_handler: in kernel transfer...\n"); + if (datacount < 0) { + s->async->events |= COMEDI_CB_OVERFLOW; + } else { + datacount--; + // transfer data + *databuf++ = tempdata; + } + } + //put data into read buffer + // comedi_buf_put(s->async, tempdata); + if (cfc_write_to_buffer(s, tempdata) == 0) + printk("s626_irq_handler: cfc_write_to_buffer error!\n"); - s626_dio_set_irq(dev,cmd->scan_begin_arg); + DEBUG("s626_irq_handler: ai channel %d acquired: %d\n", + i, tempdata); + } - DEBUG("s626_irq_handler: External trigger is set!!!\n"); - } + //end of scan occurs + s->async->events |= COMEDI_CB_EOS; - // tell comedi that data is there - DEBUG("s626_irq_handler: events %d\n",s->async->events); - comedi_event(dev, s); - break; - case IRQ_GPIO3: //check dio and conter interrupt + if (!(devpriv->ai_continous)) + devpriv->ai_sample_count--; + if (devpriv->ai_sample_count <= 0) { + devpriv->ai_cmd_running = 0; - DEBUG("s626_irq_handler: GPIO3 irq detected\n"); + // Stop RPS program. + MC_DISABLE(P_MC1, MC1_ERPS1); - // manage ai subdevice - s=dev->subdevices; - cmd=&(s->async->cmd); + //send end of acquisition + s->async->events |= COMEDI_CB_EOA; - //s626_dio_clear_irq(dev); + //disable master interrupt + irqstatus = 0; + } - for(group=0;groupsubdevices+2+group)->private)->RDCapFlg); + if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT) { + DEBUG("s626_irq_handler: enable interrupt on dio channel %d\n", cmd->scan_begin_arg); - //check if interrupt is generated from dio channels - if(irqbit){ - s626_dio_reset_irq(dev,group,irqbit); - DEBUG("s626_irq_handler: check interrupt on dio group %d %d\n",group,i); - if(devpriv->ai_cmd_running){ - //check if interrupt is an ai acquisition start trigger - if((irqbit>>(cmd->start_arg-(16*group)))==1 && cmd->start_src==TRIG_EXT){ - DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n",cmd->start_arg); + s626_dio_set_irq(dev, cmd->scan_begin_arg); - // Start executing the RPS program. - MC_ENABLE( P_MC1, MC1_ERPS1 ); + DEBUG("s626_irq_handler: External trigger is set!!!\n"); + } + // tell comedi that data is there + DEBUG("s626_irq_handler: events %d\n", s->async->events); + comedi_event(dev, s); + break; + case IRQ_GPIO3: //check dio and conter interrupt + + DEBUG("s626_irq_handler: GPIO3 irq detected\n"); + + // manage ai subdevice + s = dev->subdevices; + cmd = &(s->async->cmd); + + //s626_dio_clear_irq(dev); + + for (group = 0; group < S626_DIO_BANKS; group++) { + irqbit = 0; + //read interrupt type + irqbit = DEBIread(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->RDCapFlg); + + //check if interrupt is generated from dio channels + if (irqbit) { + s626_dio_reset_irq(dev, group, irqbit); + DEBUG("s626_irq_handler: check interrupt on dio group %d %d\n", group, i); + if (devpriv->ai_cmd_running) { + //check if interrupt is an ai acquisition start trigger + if ((irqbit >> (cmd->start_arg - + (16 * group))) + == 1 + && cmd->start_src == TRIG_EXT) { + DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n", cmd->start_arg); + + // Start executing the RPS program. + MC_ENABLE(P_MC1, MC1_ERPS1); + + DEBUG("s626_irq_handler: aquisition start triggered!!!\n"); + + if (cmd->scan_begin_src == + TRIG_EXT) { + DEBUG("s626_ai_cmd: enable interrupt on dio channel %d\n", cmd->scan_begin_arg); + + s626_dio_set_irq(dev, + cmd-> + scan_begin_arg); + + DEBUG("s626_irq_handler: External scan trigger is set!!!\n"); + } + } + if ((irqbit >> (cmd->scan_begin_arg - + (16 * group))) + == 1 + && cmd->scan_begin_src == + TRIG_EXT) { + DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n", cmd->scan_begin_arg); + + // Trigger ADC scan loop start by setting RPS Signal 0. + MC_ENABLE(P_MC2, MC2_ADC_RPS); + + DEBUG("s626_irq_handler: scan triggered!!! %d\n", devpriv->ai_sample_count); + if (cmd->convert_src == + TRIG_EXT) { + + DEBUG("s626_ai_cmd: enable interrupt on dio channel %d group %d\n", cmd->convert_arg - (16 * group), group); + + devpriv-> + ai_convert_count + = + cmd-> + chanlist_len; + + s626_dio_set_irq(dev, + cmd-> + convert_arg); + + DEBUG("s626_irq_handler: External convert trigger is set!!!\n"); + } + + if (cmd->convert_src == + TRIG_TIMER) { + k = &encpriv[5]; + devpriv-> + ai_convert_count + = + cmd-> + chanlist_len; + k->SetEnable(dev, k, + CLKENAB_ALWAYS); + } + } + if ((irqbit >> (cmd->convert_arg - + (16 * group))) + == 1 + && cmd->convert_src == + TRIG_EXT) { + DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n", cmd->convert_arg); + + // Trigger ADC scan loop start by setting RPS Signal 0. + MC_ENABLE(P_MC2, MC2_ADC_RPS); + + DEBUG("s626_irq_handler: adc convert triggered!!!\n"); + + devpriv->ai_convert_count--; + + if (devpriv->ai_convert_count > + 0) { + + DEBUG("s626_ai_cmd: enable interrupt on dio channel %d group %d\n", cmd->convert_arg - (16 * group), group); + + s626_dio_set_irq(dev, + cmd-> + convert_arg); + + DEBUG("s626_irq_handler: External trigger is set!!!\n"); + } + } + } + break; + } + } - DEBUG("s626_irq_handler: aquisition start triggered!!!\n"); + //read interrupt type + irqbit = DEBIread(dev, LP_RDMISC2); - if(cmd->scan_begin_src==TRIG_EXT){ - DEBUG("s626_ai_cmd: enable interrupt on dio channel %d\n",cmd->scan_begin_arg); + //check interrupt on counters + DEBUG("s626_irq_handler: check counters interrupt %d\n", + irqbit); - s626_dio_set_irq(dev,cmd->scan_begin_arg); + if (irqbit & IRQ_COINT1A) { + DEBUG("s626_irq_handler: interrupt on counter 1A overflow\n"); + k = &encpriv[0]; - DEBUG("s626_irq_handler: External scan trigger is set!!!\n"); - } - } - if((irqbit>>(cmd->scan_begin_arg-(16*group)))==1 && cmd->scan_begin_src==TRIG_EXT){ - DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n",cmd->scan_begin_arg); + //clear interrupt capture flag + k->ResetCapFlags(dev, k); + } + if (irqbit & IRQ_COINT2A) { + DEBUG("s626_irq_handler: interrupt on counter 2A overflow\n"); + k = &encpriv[1]; - // Trigger ADC scan loop start by setting RPS Signal 0. - MC_ENABLE( P_MC2, MC2_ADC_RPS ); + //clear interrupt capture flag + k->ResetCapFlags(dev, k); + } + if (irqbit & IRQ_COINT3A) { + DEBUG("s626_irq_handler: interrupt on counter 3A overflow\n"); + k = &encpriv[2]; - DEBUG("s626_irq_handler: scan triggered!!! %d\n",devpriv->ai_sample_count); - if(cmd->convert_src==TRIG_EXT){ + //clear interrupt capture flag + k->ResetCapFlags(dev, k); + } + if (irqbit & IRQ_COINT1B) { + DEBUG("s626_irq_handler: interrupt on counter 1B overflow\n"); + k = &encpriv[3]; - DEBUG("s626_ai_cmd: enable interrupt on dio channel %d group %d\n",cmd->convert_arg-(16*group),group); + //clear interrupt capture flag + k->ResetCapFlags(dev, k); + } + if (irqbit & IRQ_COINT2B) { + DEBUG("s626_irq_handler: interrupt on counter 2B overflow\n"); + k = &encpriv[4]; - devpriv->ai_convert_count=cmd->chanlist_len; + //clear interrupt capture flag + k->ResetCapFlags(dev, k); - s626_dio_set_irq(dev,cmd->convert_arg); + if (devpriv->ai_convert_count > 0) { + devpriv->ai_convert_count--; + if (devpriv->ai_convert_count == 0) + k->SetEnable(dev, k, CLKENAB_INDEX); - DEBUG("s626_irq_handler: External convert trigger is set!!!\n"); - } + if (cmd->convert_src == TRIG_TIMER) { + DEBUG("s626_irq_handler: conver timer trigger!!! %d\n", devpriv->ai_convert_count); - if(cmd->convert_src==TRIG_TIMER){ - k=&encpriv[5]; - devpriv->ai_convert_count=cmd->chanlist_len; - k->SetEnable(dev,k,CLKENAB_ALWAYS); - } - } - if((irqbit>>(cmd->convert_arg-(16*group)))==1 && cmd->convert_src==TRIG_EXT){ - DEBUG("s626_irq_handler: Edge capture interrupt recieved from channel %d\n",cmd->convert_arg); + // Trigger ADC scan loop start by setting RPS Signal 0. + MC_ENABLE(P_MC2, MC2_ADC_RPS); + } + } + } + if (irqbit & IRQ_COINT3B) { + DEBUG("s626_irq_handler: interrupt on counter 3B overflow\n"); + k = &encpriv[5]; - // Trigger ADC scan loop start by setting RPS Signal 0. - MC_ENABLE( P_MC2, MC2_ADC_RPS ); + //clear interrupt capture flag + k->ResetCapFlags(dev, k); - DEBUG("s626_irq_handler: adc convert triggered!!!\n"); + if (cmd->scan_begin_src == TRIG_TIMER) { + DEBUG("s626_irq_handler: scan timer trigger!!!\n"); - devpriv->ai_convert_count--; + // Trigger ADC scan loop start by setting RPS Signal 0. + MC_ENABLE(P_MC2, MC2_ADC_RPS); + } - if(devpriv->ai_convert_count>0){ + if (cmd->convert_src == TRIG_TIMER) { + DEBUG("s626_irq_handler: convert timer trigger is set\n"); + k = &encpriv[4]; + devpriv->ai_convert_count = cmd->chanlist_len; + k->SetEnable(dev, k, CLKENAB_ALWAYS); + } + } + } - DEBUG("s626_ai_cmd: enable interrupt on dio channel %d group %d\n",cmd->convert_arg-(16*group),group); + //enable interrupt + writel(irqstatus, devpriv->base_addr + P_IER); - s626_dio_set_irq(dev,cmd->convert_arg); + DEBUG("s626_irq_handler: exit interrupt service routine.\n"); - DEBUG("s626_irq_handler: External trigger is set!!!\n"); - } - } - } - break; - } - } - - //read interrupt type - irqbit=DEBIread(dev,LP_RDMISC2); - - //check interrupt on counters - DEBUG("s626_irq_handler: check counters interrupt %d\n",irqbit); - - if(irqbit&IRQ_COINT1A){ - DEBUG("s626_irq_handler: interrupt on counter 1A overflow\n"); - k=&encpriv[0]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - } - if(irqbit&IRQ_COINT2A){ - DEBUG("s626_irq_handler: interrupt on counter 2A overflow\n"); - k=&encpriv[1]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - } - if(irqbit&IRQ_COINT3A){ - DEBUG("s626_irq_handler: interrupt on counter 3A overflow\n"); - k=&encpriv[2]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - } - if(irqbit&IRQ_COINT1B){ - DEBUG("s626_irq_handler: interrupt on counter 1B overflow\n"); - k=&encpriv[3]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - } - if(irqbit&IRQ_COINT2B){ - DEBUG("s626_irq_handler: interrupt on counter 2B overflow\n"); - k=&encpriv[4]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - - if(devpriv->ai_convert_count>0){ - devpriv->ai_convert_count--; - if(devpriv->ai_convert_count==0) k->SetEnable(dev,k,CLKENAB_INDEX); - - if(cmd->convert_src==TRIG_TIMER){ - DEBUG("s626_irq_handler: conver timer trigger!!! %d\n",devpriv->ai_convert_count); - - // Trigger ADC scan loop start by setting RPS Signal 0. - MC_ENABLE( P_MC2, MC2_ADC_RPS ); - } - } - } - if(irqbit&IRQ_COINT3B){ - DEBUG("s626_irq_handler: interrupt on counter 3B overflow\n"); - k=&encpriv[5]; - - //clear interrupt capture flag - k->ResetCapFlags(dev,k); - - if(cmd->scan_begin_src==TRIG_TIMER){ - DEBUG("s626_irq_handler: scan timer trigger!!!\n"); - - // Trigger ADC scan loop start by setting RPS Signal 0. - MC_ENABLE( P_MC2, MC2_ADC_RPS ); - } - - if(cmd->convert_src==TRIG_TIMER){ - DEBUG("s626_irq_handler: convert timer trigger is set\n"); - k=&encpriv[4]; - devpriv->ai_convert_count=cmd->chanlist_len; - k->SetEnable(dev,k,CLKENAB_ALWAYS); - } - } - } - - //enable interrupt - writel(irqstatus,devpriv->base_addr+P_IER); - - DEBUG("s626_irq_handler: exit interrupt service routine.\n"); - - comedi_spin_unlock_irqrestore(&dev->spinlock, flags); - return IRQ_HANDLED; + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); + return IRQ_HANDLED; } -static int s626_detach(comedi_device *dev) +static int s626_detach(comedi_device * dev) { - if(devpriv){ + if (devpriv) { //stop ai_command - devpriv->ai_cmd_running=0; + devpriv->ai_cmd_running = 0; - if(devpriv->base_addr){ + if (devpriv->base_addr) { //interrupt mask - WR7146( P_IER, 0 ); // Disable master interrupt. - WR7146( P_ISR, IRQ_GPIO3 | IRQ_RPS1 ); // Clear board's IRQ status flag. + WR7146(P_IER, 0); // Disable master interrupt. + WR7146(P_ISR, IRQ_GPIO3 | IRQ_RPS1); // Clear board's IRQ status flag. // Disable the watchdog timer and battery charger. - WriteMISC2(dev,0); + WriteMISC2(dev, 0); // Close all interfaces on 7146 device. - WR7146( P_MC1, MC1_SHUTDOWN ); - WR7146( P_ACON1, ACON1_BASE ); + WR7146(P_MC1, MC1_SHUTDOWN); + WR7146(P_ACON1, ACON1_BASE); - CloseDMAB(dev,&devpriv->RPSBuf,DMABUF_SIZE); - CloseDMAB(dev,&devpriv->ANABuf,DMABUF_SIZE); + CloseDMAB(dev, &devpriv->RPSBuf, DMABUF_SIZE); + CloseDMAB(dev, &devpriv->ANABuf, DMABUF_SIZE); } - if(dev->irq){ - comedi_free_irq(dev->irq,dev); + if (dev->irq) { + comedi_free_irq(dev->irq, dev); } - if(devpriv->base_addr){ + if (devpriv->base_addr) { iounmap(devpriv->base_addr); } - if(devpriv->pdev){ - if(devpriv->got_regions) - { + if (devpriv->pdev) { + if (devpriv->got_regions) { comedi_pci_disable(devpriv->pdev); } pci_dev_put(devpriv->pdev); @@ -1240,182 +1307,191 @@ static int s626_detach(comedi_device *dev) /* * this functions build the RPS program for hardware driven acquistion */ -void ResetADC(comedi_device *dev,uint8_t *ppl ) +void ResetADC(comedi_device * dev, uint8_t * ppl) { - register uint32_t *pRPS; - uint32_t JmpAdrs; - uint16_t i; - uint16_t n; - uint32_t LocalPPL; - comedi_cmd *cmd=&(dev->subdevices->async->cmd); - - // Stop RPS program in case it is currently running. - MC_DISABLE( P_MC1, MC1_ERPS1 ); - - // Set starting logical address to write RPS commands. - pRPS = (uint32_t *)devpriv->RPSBuf.LogicalBase; - - // Initialize RPS instruction pointer. - WR7146( P_RPSADDR1, (uint32_t)devpriv->RPSBuf.PhysicalBase ); - - // Construct RPS program in RPSBuf DMA buffer - - if(cmd!=NULL && cmd->scan_begin_src!=TRIG_FOLLOW){ - DEBUG("ResetADC: scan_begin pause inserted\n"); - // Wait for Start trigger. - *pRPS++= RPS_PAUSE | RPS_SIGADC ; - *pRPS++= RPS_CLRSIGNAL | RPS_SIGADC ; - } - - // SAA7146 BUG WORKAROUND Do a dummy DEBI Write. This is necessary - // because the first RPS DEBI Write following a non-RPS DEBI write - // seems to always fail. If we don't do this dummy write, the ADC - // gain might not be set to the value required for the first slot in - // the poll list; the ADC gain would instead remain unchanged from - // the previously programmed value. - *pRPS++=RPS_LDREG | (P_DEBICMD >> 2) ; // Write DEBI Write command - // and address to shadow RAM. - *pRPS++= DEBI_CMD_WRWORD | LP_GSEL ; - *pRPS++= RPS_LDREG | (P_DEBIAD >> 2) ; // Write DEBI immediate data - // to shadow RAM: - *pRPS++= GSEL_BIPOLAR5V ; // arbitrary immediate data - // value. - *pRPS++= RPS_CLRSIGNAL | RPS_DEBI ; // Reset "shadow RAM - // uploaded" flag. - *pRPS++= RPS_UPLOAD | RPS_DEBI ; // Invoke shadow RAM upload. - *pRPS++= RPS_PAUSE | RPS_DEBI ; // Wait for shadow upload to finish. - - // Digitize all slots in the poll list. This is implemented as a - // for loop to limit the slot count to 16 in case the application - // forgot to set the EOPL flag in the final slot. - for ( devpriv->AdcItems = 0; devpriv->AdcItems < 16; devpriv->AdcItems++ ) { - // Convert application's poll list item to private board class - // format. Each app poll list item is an uint8_t with form - // (EOPL,x,x,RANGE,CHAN<3:0>), where RANGE code indicates 0 = - // +-10V, 1 = +-5V, and EOPL = End of Poll List marker. - LocalPPL = ( *ppl << 8 ) | ( *ppl & 0x10 ? GSEL_BIPOLAR5V : GSEL_BIPOLAR10V ); - - // Switch ADC analog gain. - *pRPS++= RPS_LDREG | (P_DEBICMD >> 2) ; // Write DEBI command - // and address to - // shadow RAM. - *pRPS++= DEBI_CMD_WRWORD | LP_GSEL ; - *pRPS++ =RPS_LDREG | (P_DEBIAD >> 2) ; // Write DEBI - // immediate data to - // shadow RAM. - *pRPS++= LocalPPL ; - *pRPS++= RPS_CLRSIGNAL | RPS_DEBI ; // Reset "shadow RAM uploaded" - // flag. - *pRPS++= RPS_UPLOAD | RPS_DEBI ; // Invoke shadow RAM upload. - *pRPS++= RPS_PAUSE | RPS_DEBI ; // Wait for shadow upload to - // finish. - - // Select ADC analog input channel. - *pRPS++= RPS_LDREG | (P_DEBICMD >> 2) ; // Write DEBI command - // and address to - // shadow RAM. - *pRPS++= DEBI_CMD_WRWORD | LP_ISEL ; - *pRPS++= RPS_LDREG | (P_DEBIAD >> 2) ; // Write DEBI - // immediate data to - // shadow RAM. - *pRPS++= LocalPPL ; - *pRPS++= RPS_CLRSIGNAL | RPS_DEBI ; // Reset "shadow RAM uploaded" - // flag. - *pRPS++= RPS_UPLOAD | RPS_DEBI ; // Invoke shadow RAM upload. - *pRPS++= RPS_PAUSE | RPS_DEBI ; // Wait for shadow upload to - // finish. - - // Delay at least 10 microseconds for analog input settling. - // Instead of padding with NOPs, we use RPS_JUMP instructions - // here; this allows us to produce a longer delay than is - // possible with NOPs because each RPS_JUMP flushes the RPS' - // instruction prefetch pipeline. - JmpAdrs = (uint32_t)devpriv->RPSBuf.PhysicalBase + (uint32_t)((unsigned long)pRPS - (unsigned long)devpriv->RPSBuf.LogicalBase); - for ( i = 0; i < ( 10 * RPSCLK_PER_US / 2); i++ ) { - JmpAdrs += 8; // Repeat to implement time delay: - * pRPS++= RPS_JUMP ; // Jump to next RPS instruction. - * pRPS++= JmpAdrs ; - } - - if(cmd!=NULL && cmd->convert_src!=TRIG_NOW){ - DEBUG("ResetADC: convert pause inserted\n"); - // Wait for Start trigger. - *pRPS++= RPS_PAUSE | RPS_SIGADC ; - *pRPS++= RPS_CLRSIGNAL | RPS_SIGADC ; - } - - // Start ADC by pulsing GPIO1. - *pRPS++= RPS_LDREG | (P_GPIO >> 2) ; // Begin ADC Start pulse. - *pRPS++= GPIO_BASE | GPIO1_LO ; - *pRPS++= RPS_NOP ; - // VERSION 2.03 CHANGE: STRETCH OUT ADC START PULSE. - *pRPS++= RPS_LDREG | (P_GPIO >> 2) ; // End ADC Start pulse. - *pRPS++= GPIO_BASE | GPIO1_HI ; - - // Wait for ADC to complete (GPIO2 is asserted high when ADC not - // busy) and for data from previous conversion to shift into FB - // BUFFER 1 register. - *pRPS++= RPS_PAUSE | RPS_GPIO2 ; // Wait for ADC done. - - // Transfer ADC data from FB BUFFER 1 register to DMA buffer. - *pRPS++=RPS_STREG | ( BUGFIX_STREG( P_FB_BUFFER1 ) >> 2 ) ; - *pRPS++= (uint32_t)devpriv->ANABuf.PhysicalBase + ( devpriv->AdcItems << 2 ) ; - - // If this slot's EndOfPollList flag is set, all channels have - // now been processed. - if ( *ppl++ & EOPL ) { - devpriv->AdcItems++; // Adjust poll list item count. - break; // Exit poll list processing loop. - } - } - DEBUG("ResetADC: ADC items %d \n",devpriv->AdcItems); - - // VERSION 2.01 CHANGE: DELAY CHANGED FROM 250NS to 2US. Allow the - // ADC to stabilize for 2 microseconds before starting the final - // (dummy) conversion. This delay is necessary to allow sufficient - // time between last conversion finished and the start of the dummy - // conversion. Without this delay, the last conversion's data value - // is sometimes set to the previous conversion's data value. - for ( n = 0; n < ( 2 * RPSCLK_PER_US ); n++ ) *pRPS++=RPS_NOP ; - - // Start a dummy conversion to cause the data from the last - // conversion of interest to be shifted in. - *pRPS++= RPS_LDREG | (P_GPIO >> 2) ; // Begin ADC Start pulse. - *pRPS++=GPIO_BASE | GPIO1_LO ; - *pRPS++=RPS_NOP ; - // VERSION 2.03 CHANGE: STRETCH OUT ADC START PULSE. - *pRPS++=RPS_LDREG | (P_GPIO >> 2) ; // End ADC Start pulse. - *pRPS++=GPIO_BASE | GPIO1_HI ; - - // Wait for the data from the last conversion of interest to arrive - // in FB BUFFER 1 register. - *pRPS++= RPS_PAUSE | RPS_GPIO2 ; // Wait for ADC done. - - // Transfer final ADC data from FB BUFFER 1 register to DMA buffer. - *pRPS++=RPS_STREG | ( BUGFIX_STREG( P_FB_BUFFER1 ) >> 2 ) ;// - *pRPS++=(uint32_t)devpriv->ANABuf.PhysicalBase + ( devpriv->AdcItems << 2 ) ; - - // Indicate ADC scan loop is finished. - // *pRPS++= RPS_CLRSIGNAL | RPS_SIGADC ; // Signal ReadADC() that scan is done. - - //invoke interrupt - if(devpriv->ai_cmd_running==1){ - DEBUG("ResetADC: insert irq in ADC RPS task\n"); - *pRPS++= RPS_IRQ ; - } - - // Restart RPS program at its beginning. - *pRPS++= RPS_JUMP ; // Branch to start of RPS program. - *pRPS++=(uint32_t)devpriv->RPSBuf.PhysicalBase ; - - // End of RPS program build - // ------------------------------------------------------------ + register uint32_t *pRPS; + uint32_t JmpAdrs; + uint16_t i; + uint16_t n; + uint32_t LocalPPL; + comedi_cmd *cmd = &(dev->subdevices->async->cmd); + + // Stop RPS program in case it is currently running. + MC_DISABLE(P_MC1, MC1_ERPS1); + + // Set starting logical address to write RPS commands. + pRPS = (uint32_t *) devpriv->RPSBuf.LogicalBase; + + // Initialize RPS instruction pointer. + WR7146(P_RPSADDR1, (uint32_t) devpriv->RPSBuf.PhysicalBase); + + // Construct RPS program in RPSBuf DMA buffer + + if (cmd != NULL && cmd->scan_begin_src != TRIG_FOLLOW) { + DEBUG("ResetADC: scan_begin pause inserted\n"); + // Wait for Start trigger. + *pRPS++ = RPS_PAUSE | RPS_SIGADC; + *pRPS++ = RPS_CLRSIGNAL | RPS_SIGADC; + } + // SAA7146 BUG WORKAROUND Do a dummy DEBI Write. This is necessary + // because the first RPS DEBI Write following a non-RPS DEBI write + // seems to always fail. If we don't do this dummy write, the ADC + // gain might not be set to the value required for the first slot in + // the poll list; the ADC gain would instead remain unchanged from + // the previously programmed value. + *pRPS++ = RPS_LDREG | (P_DEBICMD >> 2); // Write DEBI Write command + // and address to shadow RAM. + *pRPS++ = DEBI_CMD_WRWORD | LP_GSEL; + *pRPS++ = RPS_LDREG | (P_DEBIAD >> 2); // Write DEBI immediate data + // to shadow RAM: + *pRPS++ = GSEL_BIPOLAR5V; // arbitrary immediate data + // value. + *pRPS++ = RPS_CLRSIGNAL | RPS_DEBI; // Reset "shadow RAM + // uploaded" flag. + *pRPS++ = RPS_UPLOAD | RPS_DEBI; // Invoke shadow RAM upload. + *pRPS++ = RPS_PAUSE | RPS_DEBI; // Wait for shadow upload to finish. + + // Digitize all slots in the poll list. This is implemented as a + // for loop to limit the slot count to 16 in case the application + // forgot to set the EOPL flag in the final slot. + for (devpriv->AdcItems = 0; devpriv->AdcItems < 16; devpriv->AdcItems++) { + // Convert application's poll list item to private board class + // format. Each app poll list item is an uint8_t with form + // (EOPL,x,x,RANGE,CHAN<3:0>), where RANGE code indicates 0 = + // +-10V, 1 = +-5V, and EOPL = End of Poll List marker. + LocalPPL = + (*ppl << 8) | (*ppl & 0x10 ? GSEL_BIPOLAR5V : + GSEL_BIPOLAR10V); + + // Switch ADC analog gain. + *pRPS++ = RPS_LDREG | (P_DEBICMD >> 2); // Write DEBI command + // and address to + // shadow RAM. + *pRPS++ = DEBI_CMD_WRWORD | LP_GSEL; + *pRPS++ = RPS_LDREG | (P_DEBIAD >> 2); // Write DEBI + // immediate data to + // shadow RAM. + *pRPS++ = LocalPPL; + *pRPS++ = RPS_CLRSIGNAL | RPS_DEBI; // Reset "shadow RAM uploaded" + // flag. + *pRPS++ = RPS_UPLOAD | RPS_DEBI; // Invoke shadow RAM upload. + *pRPS++ = RPS_PAUSE | RPS_DEBI; // Wait for shadow upload to + // finish. + + // Select ADC analog input channel. + *pRPS++ = RPS_LDREG | (P_DEBICMD >> 2); // Write DEBI command + // and address to + // shadow RAM. + *pRPS++ = DEBI_CMD_WRWORD | LP_ISEL; + *pRPS++ = RPS_LDREG | (P_DEBIAD >> 2); // Write DEBI + // immediate data to + // shadow RAM. + *pRPS++ = LocalPPL; + *pRPS++ = RPS_CLRSIGNAL | RPS_DEBI; // Reset "shadow RAM uploaded" + // flag. + *pRPS++ = RPS_UPLOAD | RPS_DEBI; // Invoke shadow RAM upload. + *pRPS++ = RPS_PAUSE | RPS_DEBI; // Wait for shadow upload to + // finish. + + // Delay at least 10 microseconds for analog input settling. + // Instead of padding with NOPs, we use RPS_JUMP instructions + // here; this allows us to produce a longer delay than is + // possible with NOPs because each RPS_JUMP flushes the RPS' + // instruction prefetch pipeline. + JmpAdrs = + (uint32_t) devpriv->RPSBuf.PhysicalBase + + (uint32_t) ((unsigned long)pRPS - + (unsigned long)devpriv->RPSBuf.LogicalBase); + for (i = 0; i < (10 * RPSCLK_PER_US / 2); i++) { + JmpAdrs += 8; // Repeat to implement time delay: + *pRPS++ = RPS_JUMP; // Jump to next RPS instruction. + *pRPS++ = JmpAdrs; + } + + if (cmd != NULL && cmd->convert_src != TRIG_NOW) { + DEBUG("ResetADC: convert pause inserted\n"); + // Wait for Start trigger. + *pRPS++ = RPS_PAUSE | RPS_SIGADC; + *pRPS++ = RPS_CLRSIGNAL | RPS_SIGADC; + } + // Start ADC by pulsing GPIO1. + *pRPS++ = RPS_LDREG | (P_GPIO >> 2); // Begin ADC Start pulse. + *pRPS++ = GPIO_BASE | GPIO1_LO; + *pRPS++ = RPS_NOP; + // VERSION 2.03 CHANGE: STRETCH OUT ADC START PULSE. + *pRPS++ = RPS_LDREG | (P_GPIO >> 2); // End ADC Start pulse. + *pRPS++ = GPIO_BASE | GPIO1_HI; + + // Wait for ADC to complete (GPIO2 is asserted high when ADC not + // busy) and for data from previous conversion to shift into FB + // BUFFER 1 register. + *pRPS++ = RPS_PAUSE | RPS_GPIO2; // Wait for ADC done. + + // Transfer ADC data from FB BUFFER 1 register to DMA buffer. + *pRPS++ = RPS_STREG | (BUGFIX_STREG(P_FB_BUFFER1) >> 2); + *pRPS++ = + (uint32_t) devpriv->ANABuf.PhysicalBase + + (devpriv->AdcItems << 2); + + // If this slot's EndOfPollList flag is set, all channels have + // now been processed. + if (*ppl++ & EOPL) { + devpriv->AdcItems++; // Adjust poll list item count. + break; // Exit poll list processing loop. + } + } + DEBUG("ResetADC: ADC items %d \n", devpriv->AdcItems); + + // VERSION 2.01 CHANGE: DELAY CHANGED FROM 250NS to 2US. Allow the + // ADC to stabilize for 2 microseconds before starting the final + // (dummy) conversion. This delay is necessary to allow sufficient + // time between last conversion finished and the start of the dummy + // conversion. Without this delay, the last conversion's data value + // is sometimes set to the previous conversion's data value. + for (n = 0; n < (2 * RPSCLK_PER_US); n++) + *pRPS++ = RPS_NOP; + + // Start a dummy conversion to cause the data from the last + // conversion of interest to be shifted in. + *pRPS++ = RPS_LDREG | (P_GPIO >> 2); // Begin ADC Start pulse. + *pRPS++ = GPIO_BASE | GPIO1_LO; + *pRPS++ = RPS_NOP; + // VERSION 2.03 CHANGE: STRETCH OUT ADC START PULSE. + *pRPS++ = RPS_LDREG | (P_GPIO >> 2); // End ADC Start pulse. + *pRPS++ = GPIO_BASE | GPIO1_HI; + + // Wait for the data from the last conversion of interest to arrive + // in FB BUFFER 1 register. + *pRPS++ = RPS_PAUSE | RPS_GPIO2; // Wait for ADC done. + + // Transfer final ADC data from FB BUFFER 1 register to DMA buffer. + *pRPS++ = RPS_STREG | (BUGFIX_STREG(P_FB_BUFFER1) >> 2); // + *pRPS++ = + (uint32_t) devpriv->ANABuf.PhysicalBase + + (devpriv->AdcItems << 2); + + // Indicate ADC scan loop is finished. + // *pRPS++= RPS_CLRSIGNAL | RPS_SIGADC ; // Signal ReadADC() that scan is done. + + //invoke interrupt + if (devpriv->ai_cmd_running == 1) { + DEBUG("ResetADC: insert irq in ADC RPS task\n"); + *pRPS++ = RPS_IRQ; + } + // Restart RPS program at its beginning. + *pRPS++ = RPS_JUMP; // Branch to start of RPS program. + *pRPS++ = (uint32_t) devpriv->RPSBuf.PhysicalBase; + + // End of RPS program build + // ------------------------------------------------------------ } /* TO COMPLETE, IF NECESSARY */ -static int s626_ai_insn_config(comedi_device*dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ +static int s626_ai_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - return -EINVAL; + return -EINVAL; } /* static int s626_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) */ @@ -1448,13 +1524,14 @@ static int s626_ai_insn_config(comedi_device*dev,comedi_subdevice *s,comedi_insn /* return i; */ /* } */ -static int s626_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s626_ai_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - uint16_t chan = CR_CHAN(insn->chanspec); - uint16_t range = CR_RANGE(insn->chanspec); - uint16_t AdcSpec=0; - uint32_t GpioImage; - int n; + uint16_t chan = CR_CHAN(insn->chanspec); + uint16_t range = CR_RANGE(insn->chanspec); + uint16_t AdcSpec = 0; + uint32_t GpioImage; + int n; /* //interrupt call test */ /* writel(IRQ_GPIO3,devpriv->base_addr+P_PSR); //Writing a logical 1 */ @@ -1464,431 +1541,463 @@ static int s626_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn /* //to be generated if */ /* //enabled */ - DEBUG("s626_ai_insn_read: entering\n"); + DEBUG("s626_ai_insn_read: entering\n"); + + // Convert application's ADC specification into form + // appropriate for register programming. + if (range == 0) + AdcSpec = (chan << 8) | (GSEL_BIPOLAR5V); + else + AdcSpec = (chan << 8) | (GSEL_BIPOLAR10V); + + // Switch ADC analog gain. + DEBIwrite(dev, LP_GSEL, AdcSpec); // Set gain. + + // Select ADC analog input channel. + DEBIwrite(dev, LP_ISEL, AdcSpec); // Select channel. + + for (n = 0; n < insn->n; n++) { + + // Delay 10 microseconds for analog input settling. + comedi_udelay(10); + + // Start ADC by pulsing GPIO1 low. + GpioImage = RR7146(P_GPIO); + // Assert ADC Start command + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + // and stretch it out. + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + // Negate ADC Start command. + WR7146(P_GPIO, GpioImage | GPIO1_HI); + + // Wait for ADC to complete (GPIO2 is asserted high when + // ADC not busy) and for data from previous conversion to + // shift into FB BUFFER 1 register. + + // Wait for ADC done. + while (!(RR7146(P_PSR) & PSR_GPIO2)) ; + + // Fetch ADC data. + if (n != 0) + data[n - 1] = s626_ai_reg_to_uint(RR7146(P_FB_BUFFER1)); + + // Allow the ADC to stabilize for 4 microseconds before + // starting the next (final) conversion. This delay is + // necessary to allow sufficient time between last + // conversion finished and the start of the next + // conversion. Without this delay, the last conversion's + // data value is sometimes set to the previous + // conversion's data value. + comedi_udelay(4); + } - // Convert application's ADC specification into form - // appropriate for register programming. - if(range==0) AdcSpec = ( chan << 8 ) | ( GSEL_BIPOLAR5V ); - else AdcSpec = ( chan << 8 ) | ( GSEL_BIPOLAR10V ); + // Start a dummy conversion to cause the data from the + // previous conversion to be shifted in. + GpioImage = RR7146(P_GPIO); - // Switch ADC analog gain. - DEBIwrite( dev, LP_GSEL, AdcSpec ); // Set gain. + //Assert ADC Start command + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + // and stretch it out. + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + WR7146(P_GPIO, GpioImage & ~GPIO1_HI); + // Negate ADC Start command. + WR7146(P_GPIO, GpioImage | GPIO1_HI); - // Select ADC analog input channel. - DEBIwrite( dev, LP_ISEL, AdcSpec ); // Select channel. + // Wait for the data to arrive in FB BUFFER 1 register. - for(n=0; nn; n++){ + // Wait for ADC done. + while (!(RR7146(P_PSR) & PSR_GPIO2)) ; - // Delay 10 microseconds for analog input settling. - comedi_udelay(10); + // Fetch ADC data from audio interface's input shift + // register. - // Start ADC by pulsing GPIO1 low. - GpioImage = RR7146( P_GPIO ); - // Assert ADC Start command - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - // and stretch it out. - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - // Negate ADC Start command. - WR7146( P_GPIO, GpioImage | GPIO1_HI ); + // Fetch ADC data. + if (n != 0) + data[n - 1] = s626_ai_reg_to_uint(RR7146(P_FB_BUFFER1)); - // Wait for ADC to complete (GPIO2 is asserted high when - // ADC not busy) and for data from previous conversion to - // shift into FB BUFFER 1 register. + DEBUG("s626_ai_insn_read: samples %d, data %d\n", n, data[n - 1]); - // Wait for ADC done. - while ( !( RR7146( P_PSR ) & PSR_GPIO2 ) ); + return n; +} - // Fetch ADC data. - if(n!=0) data[n-1]=s626_ai_reg_to_uint(RR7146( P_FB_BUFFER1 )); +static int s626_ai_load_polllist(uint8_t * ppl, comedi_cmd * cmd) +{ - // Allow the ADC to stabilize for 4 microseconds before - // starting the next (final) conversion. This delay is - // necessary to allow sufficient time between last - // conversion finished and the start of the next - // conversion. Without this delay, the last conversion's - // data value is sometimes set to the previous - // conversion's data value. - comedi_udelay(4); - } + int n; - // Start a dummy conversion to cause the data from the - // previous conversion to be shifted in. - GpioImage = RR7146( P_GPIO ); + for (n = 0; n < cmd->chanlist_len; n++) { + if (CR_RANGE((cmd->chanlist)[n]) == 0) + ppl[n] = (CR_CHAN((cmd->chanlist)[n])) | (RANGE_5V); + else + ppl[n] = (CR_CHAN((cmd->chanlist)[n])) | (RANGE_10V); + } + ppl[n - 1] |= EOPL; - //Assert ADC Start command - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - // and stretch it out. - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - WR7146( P_GPIO, GpioImage & ~GPIO1_HI ); - // Negate ADC Start command. - WR7146( P_GPIO, GpioImage | GPIO1_HI ); + return n; +} - // Wait for the data to arrive in FB BUFFER 1 register. +static int s626_ai_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) +{ + if (trignum != 0) + return -EINVAL; - // Wait for ADC done. - while ( !( RR7146( P_PSR ) & PSR_GPIO2 ) ); + DEBUG("s626_ai_inttrig: trigger adc start..."); - // Fetch ADC data from audio interface's input shift - // register. + // Start executing the RPS program. + MC_ENABLE(P_MC1, MC1_ERPS1); - // Fetch ADC data. - if(n!=0) data[n-1]=s626_ai_reg_to_uint(RR7146( P_FB_BUFFER1 )); + s->async->inttrig = NULL; - DEBUG("s626_ai_insn_read: samples %d, data %d\n",n,data[n-1]); + DEBUG(" done\n"); - return n; + return 1; } -static int s626_ai_load_polllist(uint8_t *ppl, comedi_cmd *cmd){ +/* TO COMPLETE */ +static int s626_ai_cmd(comedi_device * dev, comedi_subdevice * s) +{ - int n; + uint8_t ppl[16]; + comedi_cmd *cmd = &s->async->cmd; + enc_private *k; + int tick; - for(n=0;nchanlist_len;n++){ - if(CR_RANGE((cmd->chanlist)[n])==0) ppl[n]= ( CR_CHAN((cmd->chanlist)[n]) ) | ( RANGE_5V ); - else ppl[n] = ( CR_CHAN((cmd->chanlist)[n]) ) | ( RANGE_10V ); - } - ppl[n-1] |= EOPL; + DEBUG("s626_ai_cmd: entering command function\n"); - return n; -} + if (devpriv->ai_cmd_running) { + printk("s626_ai_cmd: Another ai_cmd is running %d\n", + dev->minor); + return -EBUSY; + } + //disable interrupt + writel(0, devpriv->base_addr + P_IER); -static int s626_ai_inttrig(comedi_device *dev,comedi_subdevice *s, - unsigned int trignum) -{ - if(trignum!=0) return -EINVAL; + //clear interrupt request + writel(IRQ_RPS1 | IRQ_GPIO3, devpriv->base_addr + P_ISR); + + //clear any pending interrupt + s626_dio_clear_irq(dev); + // s626_enc_clear_irq(dev); + + //reset ai_cmd_running flag + devpriv->ai_cmd_running = 0; - DEBUG("s626_ai_inttrig: trigger adc start..."); + // test if cmd is valid + if (cmd == NULL) { + DEBUG("s626_ai_cmd: NULL command\n"); + return -EINVAL; + } else { + DEBUG("s626_ai_cmd: command recieved!!!\n"); + } + + if (dev->irq == 0) { + comedi_error(dev, + "s626_ai_cmd: cannot run command without an irq"); + return -EIO; + } - // Start executing the RPS program. - MC_ENABLE( P_MC1, MC1_ERPS1 ); + s626_ai_load_polllist(ppl, cmd); + devpriv->ai_cmd_running = 1; + devpriv->ai_convert_count = 0; - s->async->inttrig=NULL; + switch (cmd->scan_begin_src) { + case TRIG_FOLLOW: + break; + case TRIG_TIMER: + // set a conter to generate adc trigger at scan_begin_arg interval + k = &encpriv[5]; + tick = s626_ns_to_timer((int *)&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); - DEBUG(" done\n"); + //load timer value and enable interrupt + s626_timer_load(dev, k, tick); + k->SetEnable(dev, k, CLKENAB_ALWAYS); - return 1; -} + DEBUG("s626_ai_cmd: scan trigger timer is set with value %d\n", + tick); -/* TO COMPLETE */ -static int s626_ai_cmd(comedi_device *dev,comedi_subdevice *s){ - - uint8_t ppl[16]; - comedi_cmd *cmd=&s->async->cmd; - enc_private *k; - int tick; - - - DEBUG("s626_ai_cmd: entering command function\n"); - - if (devpriv->ai_cmd_running) { - printk("s626_ai_cmd: Another ai_cmd is running %d\n", dev->minor); - return -EBUSY; - } - - //disable interrupt - writel(0,devpriv->base_addr+P_IER); - - //clear interrupt request - writel(IRQ_RPS1|IRQ_GPIO3,devpriv->base_addr+P_ISR); - - //clear any pending interrupt - s626_dio_clear_irq(dev); - // s626_enc_clear_irq(dev); - - //reset ai_cmd_running flag - devpriv->ai_cmd_running=0; - - // test if cmd is valid - if(cmd==NULL){ - DEBUG("s626_ai_cmd: NULL command\n"); - return -EINVAL; - } else { - DEBUG("s626_ai_cmd: command recieved!!!\n"); - } - - if(dev->irq == 0){ - comedi_error(dev, "s626_ai_cmd: cannot run command without an irq"); - return -EIO; - } - - s626_ai_load_polllist(ppl,cmd); - devpriv->ai_cmd_running=1; - devpriv->ai_convert_count=0; - - switch(cmd->scan_begin_src){ - case TRIG_FOLLOW: - break; - case TRIG_TIMER: - // set a conter to generate adc trigger at scan_begin_arg interval - k=&encpriv[5]; - tick=s626_ns_to_timer((int *)&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - - //load timer value and enable interrupt - s626_timer_load(dev, k, tick); - k->SetEnable(dev,k,CLKENAB_ALWAYS); - - DEBUG("s626_ai_cmd: scan trigger timer is set with value %d\n",tick); - - break; - case TRIG_EXT: - // set the digital line and interrupt for scan trigger - if(cmd->start_src!=TRIG_EXT) s626_dio_set_irq(dev,cmd->scan_begin_arg); - - DEBUG("s626_ai_cmd: External scan trigger is set!!!\n"); - - break; - } - - switch(cmd->convert_src){ - case TRIG_NOW: - break; - case TRIG_TIMER: - // set a conter to generate adc trigger at convert_arg interval - k=&encpriv[4]; - tick=s626_ns_to_timer((int *)&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - - //load timer value and enable interrupt - s626_timer_load(dev, k, tick); - k->SetEnable(dev,k,CLKENAB_INDEX); - - DEBUG("s626_ai_cmd: convert trigger timer is set with value %d\n",tick); - break; - case TRIG_EXT: - // set the digital line and interrupt for convert trigger - if(cmd->scan_begin_src!=TRIG_EXT && cmd->start_src==TRIG_EXT) - s626_dio_set_irq(dev, cmd->convert_arg); - - DEBUG("s626_ai_cmd: External convert trigger is set!!!\n"); - - break; - } - - switch(cmd->stop_src){ - case TRIG_COUNT: - // data arrives as one packet - devpriv->ai_sample_count=cmd->stop_arg; - devpriv->ai_continous=0; - break; - case TRIG_NONE: - // continous aquisition - devpriv->ai_continous=1; - devpriv->ai_sample_count=0; - break; - } - - ResetADC(dev,ppl); - - switch(cmd->start_src){ - case TRIG_NOW: - // Trigger ADC scan loop start by setting RPS Signal 0. - // MC_ENABLE( P_MC2, MC2_ADC_RPS ); - - // Start executing the RPS program. - MC_ENABLE( P_MC1, MC1_ERPS1 ); - - DEBUG("s626_ai_cmd: ADC triggered\n"); - s->async->inttrig=NULL; - break; - case TRIG_EXT: - //configure DIO channel for acquisition trigger - s626_dio_set_irq(dev, cmd->start_arg); - - DEBUG("s626_ai_cmd: External start trigger is set!!!\n"); - - s->async->inttrig=NULL; - break; - case TRIG_INT: - s->async->inttrig=s626_ai_inttrig; - break; - } - - //enable interrupt - writel(IRQ_GPIO3 | IRQ_RPS1,devpriv->base_addr+P_IER); - - DEBUG("s626_ai_cmd: command function terminated\n"); - - return 0; + break; + case TRIG_EXT: + // set the digital line and interrupt for scan trigger + if (cmd->start_src != TRIG_EXT) + s626_dio_set_irq(dev, cmd->scan_begin_arg); + + DEBUG("s626_ai_cmd: External scan trigger is set!!!\n"); + + break; + } + + switch (cmd->convert_src) { + case TRIG_NOW: + break; + case TRIG_TIMER: + // set a conter to generate adc trigger at convert_arg interval + k = &encpriv[4]; + tick = s626_ns_to_timer((int *)&cmd->convert_arg, + cmd->flags & TRIG_ROUND_MASK); + + //load timer value and enable interrupt + s626_timer_load(dev, k, tick); + k->SetEnable(dev, k, CLKENAB_INDEX); + + DEBUG("s626_ai_cmd: convert trigger timer is set with value %d\n", tick); + break; + case TRIG_EXT: + // set the digital line and interrupt for convert trigger + if (cmd->scan_begin_src != TRIG_EXT + && cmd->start_src == TRIG_EXT) + s626_dio_set_irq(dev, cmd->convert_arg); + + DEBUG("s626_ai_cmd: External convert trigger is set!!!\n"); + + break; + } + + switch (cmd->stop_src) { + case TRIG_COUNT: + // data arrives as one packet + devpriv->ai_sample_count = cmd->stop_arg; + devpriv->ai_continous = 0; + break; + case TRIG_NONE: + // continous aquisition + devpriv->ai_continous = 1; + devpriv->ai_sample_count = 0; + break; + } + + ResetADC(dev, ppl); + + switch (cmd->start_src) { + case TRIG_NOW: + // Trigger ADC scan loop start by setting RPS Signal 0. + // MC_ENABLE( P_MC2, MC2_ADC_RPS ); + + // Start executing the RPS program. + MC_ENABLE(P_MC1, MC1_ERPS1); + + DEBUG("s626_ai_cmd: ADC triggered\n"); + s->async->inttrig = NULL; + break; + case TRIG_EXT: + //configure DIO channel for acquisition trigger + s626_dio_set_irq(dev, cmd->start_arg); + + DEBUG("s626_ai_cmd: External start trigger is set!!!\n"); + + s->async->inttrig = NULL; + break; + case TRIG_INT: + s->async->inttrig = s626_ai_inttrig; + break; + } + + //enable interrupt + writel(IRQ_GPIO3 | IRQ_RPS1, devpriv->base_addr + P_IER); + + DEBUG("s626_ai_cmd: command function terminated\n"); + + return 0; } -static int s626_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd){ - int err=0; - int tmp; - - /* cmdtest tests a particular command to see if it is valid. Using - * the cmdtest ioctl, a user can create a valid cmd and then have it - * executes by the cmd ioctl. - * - * cmdtest returns 1,2,3,4 or 0, depending on which tests the - * command passes. */ - - /* step 1: make sure trigger sources are trivially valid */ - - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_INT|TRIG_EXT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; - - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT|TRIG_FOLLOW; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; - - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT|TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; - - tmp=cmd->scan_end_src; - cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; - - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; - - if(err)return 1; - - /* step 2: make sure trigger sources are unique and mutually - compatible */ - - /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT && cmd->scan_begin_src!=TRIG_FOLLOW)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT && cmd->convert_src!=TRIG_NOW)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; - - /* step 3: make sure arguments are trivially compatible */ - - if(cmd->start_src!=TRIG_EXT && cmd->start_arg!=0){ - cmd->start_arg=0; - err++; - } - - if(cmd->start_src==TRIG_EXT && cmd->start_arg<0){ - cmd->start_arg=0; - err++; - } - - if(cmd->start_src==TRIG_EXT && cmd->start_arg>39){ - cmd->start_arg=39; - err++; - } - - if(cmd->scan_begin_src==TRIG_EXT && cmd->scan_begin_arg<0){ - cmd->scan_begin_arg=0; - err++; - } - - if(cmd->scan_begin_src==TRIG_EXT && cmd->scan_begin_arg>39){ - cmd->scan_begin_arg=39; - err++; - } - - if(cmd->convert_src==TRIG_EXT && cmd->convert_arg<0){ - cmd->convert_arg=0; - err++; - } - - if(cmd->convert_src==TRIG_EXT && cmd->convert_arg>39){ - cmd->convert_arg=39; - err++; - } - -#define MAX_SPEED 200000 /* in nanoseconds */ +static int s626_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) +{ + int err = 0; + int tmp; + + /* cmdtest tests a particular command to see if it is valid. Using + * the cmdtest ioctl, a user can create a valid cmd and then have it + * executes by the cmd ioctl. + * + * cmdtest returns 1,2,3,4 or 0, depending on which tests the + * command passes. */ + + /* step 1: make sure trigger sources are trivially valid */ + + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_INT | TRIG_EXT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; + + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; + + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT | TRIG_NOW; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; + + tmp = cmd->scan_end_src; + cmd->scan_end_src &= TRIG_COUNT; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; + + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; + + if (err) + return 1; + + /* step 2: make sure trigger sources are unique and mutually + compatible */ + + /* note that mutual compatiblity is not an issue here */ + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT + && cmd->scan_begin_src != TRIG_FOLLOW) + err++; + if (cmd->convert_src != TRIG_TIMER && + cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + + if (err) + return 2; + + /* step 3: make sure arguments are trivially compatible */ + + if (cmd->start_src != TRIG_EXT && cmd->start_arg != 0) { + cmd->start_arg = 0; + err++; + } + + if (cmd->start_src == TRIG_EXT && cmd->start_arg < 0) { + cmd->start_arg = 0; + err++; + } + + if (cmd->start_src == TRIG_EXT && cmd->start_arg > 39) { + cmd->start_arg = 39; + err++; + } + + if (cmd->scan_begin_src == TRIG_EXT && cmd->scan_begin_arg < 0) { + cmd->scan_begin_arg = 0; + err++; + } + + if (cmd->scan_begin_src == TRIG_EXT && cmd->scan_begin_arg > 39) { + cmd->scan_begin_arg = 39; + err++; + } + + if (cmd->convert_src == TRIG_EXT && cmd->convert_arg < 0) { + cmd->convert_arg = 0; + err++; + } + + if (cmd->convert_src == TRIG_EXT && cmd->convert_arg > 39) { + cmd->convert_arg = 39; + err++; + } +#define MAX_SPEED 200000 /* in nanoseconds */ #define MIN_SPEED 2000000000 /* in nanoseconds */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; - err++; - } - if(cmd->scan_begin_arg>MIN_SPEED){ - cmd->scan_begin_arg=MIN_SPEED; - err++; - } - }else{ - /* external trigger */ - /* should be level/edge, hi/lo specification here */ - /* should specify multiple external triggers */ + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; + err++; + } + if (cmd->scan_begin_arg > MIN_SPEED) { + cmd->scan_begin_arg = MIN_SPEED; + err++; + } + } 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_argconvert_arg=MAX_SPEED; - err++; - } - if(cmd->convert_arg>MIN_SPEED){ - cmd->convert_arg=MIN_SPEED; - err++; - } - }else{ - /* external trigger */ - /* see above */ + } + 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){ - tmp=cmd->scan_begin_arg; - s626_ns_to_timer((int *)&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; - } - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - s626_ns_to_timer((int *)&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg){ - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; - err++; - } - } - - if(err)return 4; - - return 0; + } + + 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) { + tmp = cmd->scan_begin_arg; + s626_ns_to_timer((int *)&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; + } + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + s626_ns_to_timer((int *)&cmd->convert_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 s626_ai_cancel(comedi_device *dev,comedi_subdevice *s) +static int s626_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - // Stop RPS program in case it is currently running. - MC_DISABLE( P_MC1, MC1_ERPS1 ); + // Stop RPS program in case it is currently running. + MC_DISABLE(P_MC1, MC1_ERPS1); - //disable master interrupt - writel(0,devpriv->base_addr+P_IER); + //disable master interrupt + writel(0, devpriv->base_addr + P_IER); - devpriv->ai_cmd_running=0; + devpriv->ai_cmd_running = 0; - return 0; + return 0; } /* This function doesn't require a particular form, this is just what @@ -1896,55 +2005,58 @@ static int s626_ai_cancel(comedi_device *dev,comedi_subdevice *s) * nanoseconds to a counter value suitable for programming the device. * Also, it should adjust ns so that it cooresponds to the actual time * that the device will use. */ -static int s626_ns_to_timer(int *nanosec,int round_mode) +static int s626_ns_to_timer(int *nanosec, int round_mode) { - int divider,base; + int divider, base; - base=500; //2MHz internal clock + base = 500; //2MHz internal clock - switch(round_mode){ + switch (round_mode) { case TRIG_ROUND_NEAREST: default: - divider=(*nanosec+base/2)/base; + divider = (*nanosec + base / 2) / base; break; case TRIG_ROUND_DOWN: - divider=(*nanosec)/base; + divider = (*nanosec) / base; break; case TRIG_ROUND_UP: - divider=(*nanosec+base-1)/base; + divider = (*nanosec + base - 1) / base; break; } - *nanosec=base*divider; - return divider-1; + *nanosec = base * divider; + return divider - 1; } -static int s626_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ +static int s626_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - int i; - uint16_t chan = CR_CHAN(insn->chanspec); - int16_t dacdata; + int i; + uint16_t chan = CR_CHAN(insn->chanspec); + int16_t dacdata; - for(i=0;in;i++){ - dacdata=(int16_t)data[i]; - devpriv->ao_readback[CR_CHAN(insn->chanspec)]=data[i]; - dacdata-= ( 0x1fff ); + for (i = 0; i < insn->n; i++) { + dacdata = (int16_t) data[i]; + devpriv->ao_readback[CR_CHAN(insn->chanspec)] = data[i]; + dacdata -= (0x1fff); - SetDAC(dev,chan,dacdata); - } + SetDAC(dev, chan, dacdata); + } - return i; + return i; } -static int s626_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s626_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i; + int i; - for(i=0;in;i++){ - data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; - } + for (i = 0; i < insn->n; i++) { + data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; + } - return i; + return i; } ///////////////////////////////////////////////////////////////////// @@ -1955,28 +2067,27 @@ static int s626_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins // ports A, B and C, respectively. ///////////////////////////////////////////////////////////////////// -static void s626_dio_init(comedi_device *dev) +static void s626_dio_init(comedi_device * dev) { - uint16_t group; - comedi_subdevice *s; - - // Prepare to treat writes to WRCapSel as capture disables. - DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP ); - - // For each group of sixteen channels ... - for ( group = 0; group < S626_DIO_BANKS ; group++ ) - { - s=dev->subdevices+2+group; - DEBIwrite(dev, diopriv->WRIntSel, 0 ); // Disable all interrupts. - DEBIwrite(dev, diopriv->WRCapSel, 0xFFFF ); // Disable all event - // captures. - DEBIwrite(dev, diopriv->WREdgSel, 0 ); // Init all DIOs to - // default edge - // polarity. - DEBIwrite(dev, diopriv->WRDOut, 0 ); // Program all outputs - // to inactive state. - } - DEBUG("s626_dio_init: DIO initialized \n"); + uint16_t group; + comedi_subdevice *s; + + // Prepare to treat writes to WRCapSel as capture disables. + DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP); + + // For each group of sixteen channels ... + for (group = 0; group < S626_DIO_BANKS; group++) { + s = dev->subdevices + 2 + group; + DEBIwrite(dev, diopriv->WRIntSel, 0); // Disable all interrupts. + DEBIwrite(dev, diopriv->WRCapSel, 0xFFFF); // Disable all event + // captures. + DEBIwrite(dev, diopriv->WREdgSel, 0); // Init all DIOs to + // default edge + // polarity. + DEBIwrite(dev, diopriv->WRDOut, 0); // Program all outputs + // to inactive state. + } + DEBUG("s626_dio_init: DIO initialized \n"); } /* DIO devices are slightly special. Although it is possible to @@ -1985,217 +2096,249 @@ static void s626_dio_init(comedi_device *dev) * This allows packed reading/writing of the DIO channels. The comedi * core can convert between insn_bits and insn_read/write */ -static int s626_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ - - /* Length of data must be 2 (mask and new data, see below) */ - if(insn->n == 0){ - return 0; - } - if(insn->n != 2){ - printk("comedi%d: s626: s626_dio_insn_bits(): Invalid instruction length\n", dev->minor); - return -EINVAL; - } - - /* - * The insn data consists of a mask in data[0] and the new data in - * data[1]. The mask defines which bits we are concerning about. - * The new data must be anded with the mask. Each channel - * corresponds to a bit. - */ - if(data[0]){ - /* Check if requested ports are configured for output */ - if((s->io_bits & data[0]) != data[0]) - return -EIO; - - s->state &= ~data[0]; - s->state |= data[0] & data[1]; - - /* Write out the new digital output lines */ - - DEBIwrite(dev,diopriv->WRDOut,s->state); - } - data[1]=DEBIread(dev,diopriv->RDDIn); - - return 2; -} - -static int s626_dio_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s626_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - switch(data[0]){ - case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1 << CR_CHAN(insn->chanspec))) ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; - break; - case COMEDI_INPUT: - s->io_bits&= ~(1 << CR_CHAN(insn->chanspec)); - break; - case COMEDI_OUTPUT: - s->io_bits|= 1 << CR_CHAN(insn->chanspec); - break; - default: - return -EINVAL; - break; - } - DEBIwrite(dev,diopriv->WRDOut,s->io_bits); - - return 1; -} + /* Length of data must be 2 (mask and new data, see below) */ + if (insn->n == 0) { + return 0; + } + if (insn->n != 2) { + printk("comedi%d: s626: s626_dio_insn_bits(): Invalid instruction length\n", dev->minor); + return -EINVAL; + } -static int s626_dio_set_irq(comedi_device *dev, unsigned int chan) -{ - unsigned int group; - unsigned int bitmask; - unsigned int status; + /* + * The insn data consists of a mask in data[0] and the new data in + * data[1]. The mask defines which bits we are concerning about. + * The new data must be anded with the mask. Each channel + * corresponds to a bit. + */ + if (data[0]) { + /* Check if requested ports are configured for output */ + if ((s->io_bits & data[0]) != data[0]) + return -EIO; + + s->state &= ~data[0]; + s->state |= data[0] & data[1]; + + /* Write out the new digital output lines */ + + DEBIwrite(dev, diopriv->WRDOut, s->state); + } + data[1] = DEBIread(dev, diopriv->RDDIn); - //select dio bank - group=chan/16; - bitmask=1<<(chan-(16*group)); - DEBUG("s626_dio_set_irq: enable interrupt on dio channel %d group %d\n",chan-(16*group),group); + return 2; +} - //set channel to capture positive edge - status=DEBIread(dev,((dio_private *)(dev->subdevices+2+group)->private)->RDEdgSel); - DEBIwrite(dev,((dio_private *)(dev->subdevices+2+group)->private)->WREdgSel,bitmask|status); +static int s626_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - //enable interrupt on selected channel - status=DEBIread(dev,((dio_private *)(dev->subdevices+2+group)->private)->RDIntSel); - DEBIwrite(dev,((dio_private *)(dev->subdevices+2+group)->private)->WRIntSel,bitmask|status); + switch (data[0]) { + case INSN_CONFIG_DIO_QUERY: + data[1] = + (s->io_bits & (1 << CR_CHAN(insn-> + chanspec))) ? COMEDI_OUTPUT : + COMEDI_INPUT; + return insn->n; + break; + case COMEDI_INPUT: + s->io_bits &= ~(1 << CR_CHAN(insn->chanspec)); + break; + case COMEDI_OUTPUT: + s->io_bits |= 1 << CR_CHAN(insn->chanspec); + break; + default: + return -EINVAL; + break; + } + DEBIwrite(dev, diopriv->WRDOut, s->io_bits); - //enable edge capture write command - DEBIwrite(dev,LP_MISC1,MISC1_EDCAP); + return 1; +} - //enable edge capture on selected channel - status=DEBIread(dev,((dio_private *)(dev->subdevices+2+group)->private)->RDCapSel); - DEBIwrite(dev,((dio_private *)(dev->subdevices+2+group)->private)->WRCapSel,bitmask|status); +static int s626_dio_set_irq(comedi_device * dev, unsigned int chan) +{ + unsigned int group; + unsigned int bitmask; + unsigned int status; + + //select dio bank + group = chan / 16; + bitmask = 1 << (chan - (16 * group)); + DEBUG("s626_dio_set_irq: enable interrupt on dio channel %d group %d\n", + chan - (16 * group), group); + + //set channel to capture positive edge + status = DEBIread(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->RDEdgSel); + DEBIwrite(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->WREdgSel, bitmask | status); + + //enable interrupt on selected channel + status = DEBIread(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->RDIntSel); + DEBIwrite(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->WRIntSel, bitmask | status); + + //enable edge capture write command + DEBIwrite(dev, LP_MISC1, MISC1_EDCAP); + + //enable edge capture on selected channel + status = DEBIread(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->RDCapSel); + DEBIwrite(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->WRCapSel, bitmask | status); - return 0; + return 0; } -static int s626_dio_reset_irq(comedi_device *dev, unsigned int group, unsigned int mask) +static int s626_dio_reset_irq(comedi_device * dev, unsigned int group, + unsigned int mask) { - DEBUG("s626_dio_reset_irq: disable interrupt on dio channel %d group %d\n",mask,group); + DEBUG("s626_dio_reset_irq: disable interrupt on dio channel %d group %d\n", mask, group); - //disable edge capture write command - DEBIwrite(dev,LP_MISC1,MISC1_NOEDCAP); + //disable edge capture write command + DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP); - //enable edge capture on selected channel - DEBIwrite(dev,((dio_private *)(dev->subdevices+2+group)->private)->WRCapSel,mask); + //enable edge capture on selected channel + DEBIwrite(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->WRCapSel, mask); - return 0; + return 0; } -static int s626_dio_clear_irq(comedi_device *dev) +static int s626_dio_clear_irq(comedi_device * dev) { - unsigned int group; + unsigned int group; - //disable edge capture write command - DEBIwrite(dev,LP_MISC1,MISC1_NOEDCAP); + //disable edge capture write command + DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP); - for(group=0;groupsubdevices+2+group)->private)->WRCapSel,0xffff); - } + for (group = 0; group < S626_DIO_BANKS; group++) { + //clear pending events and interrupt + DEBIwrite(dev, + ((dio_private *) (dev->subdevices + 2 + + group)->private)->WRCapSel, 0xffff); + } - return 0; + return 0; } /* Now this function initializes the value of the counter (data[0]) and set the subdevice. To complete with trigger and interrupt configuration */ -static int s626_enc_insn_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int s626_enc_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - uint16_t Setup = ( LOADSRC_INDX << BF_LOADSRC ) | // Preload upon - // index. - ( INDXSRC_SOFT << BF_INDXSRC ) | // Disable hardware index. - ( CLKSRC_COUNTER << BF_CLKSRC ) | // Operating mode is Counter. - ( CLKPOL_POS << BF_CLKPOL ) | // Active high clock. - //( CNTDIR_UP << BF_CLKPOL ) | // Count direction is Down. - ( CLKMULT_1X << BF_CLKMULT ) | // Clock multiplier is 1x. - ( CLKENAB_INDEX << BF_CLKENAB ); - /* uint16_t DisableIntSrc=TRUE; */ - // uint32_t Preloadvalue; //Counter initial value - uint16_t valueSrclatch=LATCHSRC_AB_READ ; - uint16_t enab=CLKENAB_ALWAYS; - enc_private *k=&encpriv[CR_CHAN(insn->chanspec)]; - - DEBUG("s626_enc_insn_config: encoder config\n"); - - // (data==NULL) ? (Preloadvalue=0) : (Preloadvalue=data[0]); - - k->SetMode(dev,k,Setup,TRUE); - Preload(dev,k,*(insn->data)); - k->PulseIndex(dev,k); - SetLatchSource(dev,k,valueSrclatch); - k->SetEnable(dev,k,(uint16_t)(enab != 0)); - - return insn->n; + uint16_t Setup = (LOADSRC_INDX << BF_LOADSRC) | // Preload upon + // index. + (INDXSRC_SOFT << BF_INDXSRC) | // Disable hardware index. + (CLKSRC_COUNTER << BF_CLKSRC) | // Operating mode is Counter. + (CLKPOL_POS << BF_CLKPOL) | // Active high clock. + //( CNTDIR_UP << BF_CLKPOL ) | // Count direction is Down. + (CLKMULT_1X << BF_CLKMULT) | // Clock multiplier is 1x. + (CLKENAB_INDEX << BF_CLKENAB); + /* uint16_t DisableIntSrc=TRUE; */ + // uint32_t Preloadvalue; //Counter initial value + uint16_t valueSrclatch = LATCHSRC_AB_READ; + uint16_t enab = CLKENAB_ALWAYS; + enc_private *k = &encpriv[CR_CHAN(insn->chanspec)]; + + DEBUG("s626_enc_insn_config: encoder config\n"); + + // (data==NULL) ? (Preloadvalue=0) : (Preloadvalue=data[0]); + + k->SetMode(dev, k, Setup, TRUE); + Preload(dev, k, *(insn->data)); + k->PulseIndex(dev, k); + SetLatchSource(dev, k, valueSrclatch); + k->SetEnable(dev, k, (uint16_t) (enab != 0)); + + return insn->n; } -static int s626_enc_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ +static int s626_enc_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - int n; - enc_private *k=&encpriv[CR_CHAN(insn->chanspec)]; + int n; + enc_private *k = &encpriv[CR_CHAN(insn->chanspec)]; - DEBUG("s626_enc_insn_read: encoder read channel %d \n",CR_CHAN(insn->chanspec)); + DEBUG("s626_enc_insn_read: encoder read channel %d \n", + CR_CHAN(insn->chanspec)); - for (n=0;nn;n++) data[n]=ReadLatch(dev,k); + for (n = 0; n < insn->n; n++) + data[n] = ReadLatch(dev, k); - DEBUG("s626_enc_insn_read: encoder sample %d\n",data[n]); + DEBUG("s626_enc_insn_read: encoder sample %d\n", data[n]); - return n; + return n; } -static int s626_enc_insn_write(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ +static int s626_enc_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ - enc_private *k=&encpriv[CR_CHAN(insn->chanspec)]; + enc_private *k = &encpriv[CR_CHAN(insn->chanspec)]; - DEBUG("s626_enc_insn_write: encoder write channel %d \n",CR_CHAN(insn->chanspec)); + DEBUG("s626_enc_insn_write: encoder write channel %d \n", + CR_CHAN(insn->chanspec)); - // Set the preload register - Preload(dev,k,data[0]); + // Set the preload register + Preload(dev, k, data[0]); - // Software index pulse forces the preload register to load - // into the counter - k->SetLoadTrig(dev, k, 0); - k->PulseIndex(dev, k); - k->SetLoadTrig(dev, k, 2); + // Software index pulse forces the preload register to load + // into the counter + k->SetLoadTrig(dev, k, 0); + k->PulseIndex(dev, k); + k->SetLoadTrig(dev, k, 2); - DEBUG("s626_enc_insn_write: End encoder write\n"); + DEBUG("s626_enc_insn_write: End encoder write\n"); - return 1; + return 1; } -static void s626_timer_load(comedi_device *dev, enc_private *k, int tick) +static void s626_timer_load(comedi_device * dev, enc_private * k, int tick) { - uint16_t Setup = ( LOADSRC_INDX << BF_LOADSRC ) | // Preload upon - // index. - ( INDXSRC_SOFT << BF_INDXSRC ) | // Disable hardware index. - ( CLKSRC_TIMER << BF_CLKSRC ) | // Operating mode is Timer. - ( CLKPOL_POS << BF_CLKPOL ) | // Active high clock. - ( CNTDIR_DOWN << BF_CLKPOL ) | // Count direction is Down. - ( CLKMULT_1X << BF_CLKMULT ) | // Clock multiplier is 1x. - ( CLKENAB_INDEX << BF_CLKENAB ); - uint16_t valueSrclatch=LATCHSRC_A_INDXA ; - // uint16_t enab=CLKENAB_ALWAYS; - - k->SetMode(dev,k,Setup,FALSE); - - // Set the preload register - Preload(dev,k,tick); - - // Software index pulse forces the preload register to load - // into the counter - k->SetLoadTrig(dev, k, 0); - k->PulseIndex(dev, k); - - //set reload on counter overflow - k->SetLoadTrig(dev, k, 1); - - //set interrupt on overflow - k->SetIntSrc(dev,k,INTSRC_OVER); - - SetLatchSource(dev,k,valueSrclatch); - // k->SetEnable(dev,k,(uint16_t)(enab != 0)); + uint16_t Setup = (LOADSRC_INDX << BF_LOADSRC) | // Preload upon + // index. + (INDXSRC_SOFT << BF_INDXSRC) | // Disable hardware index. + (CLKSRC_TIMER << BF_CLKSRC) | // Operating mode is Timer. + (CLKPOL_POS << BF_CLKPOL) | // Active high clock. + (CNTDIR_DOWN << BF_CLKPOL) | // Count direction is Down. + (CLKMULT_1X << BF_CLKMULT) | // Clock multiplier is 1x. + (CLKENAB_INDEX << BF_CLKENAB); + uint16_t valueSrclatch = LATCHSRC_A_INDXA; + // uint16_t enab=CLKENAB_ALWAYS; + + k->SetMode(dev, k, Setup, FALSE); + + // Set the preload register + Preload(dev, k, tick); + + // Software index pulse forces the preload register to load + // into the counter + k->SetLoadTrig(dev, k, 0); + k->PulseIndex(dev, k); + + //set reload on counter overflow + k->SetLoadTrig(dev, k, 1); + + //set interrupt on overflow + k->SetIntSrc(dev, k, INTSRC_OVER); + + SetLatchSource(dev, k, valueSrclatch); + // k->SetEnable(dev,k,(uint16_t)(enab != 0)); } /////////////////////////////////////////////////////////////////////// @@ -2203,7 +2346,7 @@ static void s626_timer_load(comedi_device *dev, enc_private *k, int tick) /////////////////////////////////////////////////////////////////////// // Slot 0 base settings. -#define VECT0 ( XSD2 | RSD3 | SIB_A2 ) // Slot 0 always shifts in +#define VECT0 ( XSD2 | RSD3 | SIB_A2 ) // Slot 0 always shifts in // 0xFF and store it to // FB_BUFFER2. @@ -2211,48 +2354,52 @@ static void s626_timer_load(comedi_device *dev, enc_private *k, int tick) static uint8_t trimchan[] = { 10, 9, 8, 3, 2, 7, 6, 1, 0, 5, 4 }; // TrimDac LogicalChan-to-EepromAdrs mapping table. -static uint8_t trimadrs[] = { 0x40, 0x41, 0x42, 0x50, 0x51, 0x52, 0x53, 0x60, 0x61, 0x62, 0x63 }; +static uint8_t trimadrs[] = + { 0x40, 0x41, 0x42, 0x50, 0x51, 0x52, 0x53, 0x60, 0x61, 0x62, 0x63 }; -static void LoadTrimDACs(comedi_device *dev){ - register uint8_t i; +static void LoadTrimDACs(comedi_device * dev) +{ + register uint8_t i; - // Copy TrimDac setpoint values from EEPROM to TrimDacs. - for ( i = 0; i < (sizeof(trimchan)/sizeof(trimchan[0])); i++ ) - WriteTrimDAC(dev, i, I2Cread(dev,trimadrs[i] ) ); + // Copy TrimDac setpoint values from EEPROM to TrimDacs. + for (i = 0; i < (sizeof(trimchan) / sizeof(trimchan[0])); i++) + WriteTrimDAC(dev, i, I2Cread(dev, trimadrs[i])); } -static void WriteTrimDAC(comedi_device *dev, uint8_t LogicalChan, uint8_t DacData ){ - uint32_t chan; - - // Save the new setpoint in case the application needs to read it back later. - devpriv->TrimSetpoint[LogicalChan] = (uint8_t)DacData; - - // Map logical channel number to physical channel number. - chan = (uint32_t)trimchan[LogicalChan]; - - // Set up TSL2 records for TrimDac write operation. All slots shift - // 0xFF in from pulled-up SD3 so that the end of the slot sequence - // can be detected. - SETVECT( 2, XSD2 | XFIFO_1 | WS3 ); // Slot 2: Send high uint8_t - // to target TrimDac. - SETVECT( 3, XSD2 | XFIFO_0 | WS3 ); // Slot 3: Send low uint8_t to - // target TrimDac. - SETVECT( 4, XSD2 | XFIFO_3 | WS1 ); // Slot 4: Send NOP high - // uint8_t to DAC0 to keep - // clock running. - SETVECT( 5, XSD2 | XFIFO_2 | WS1 | EOS ); // Slot 5: Send NOP low - // uint8_t to DAC0. - - // Construct and transmit target DAC's serial packet: ( 0000 AAAA - // ),( DDDD DDDD ),( 0x00 ),( 0x00 ) where A<3:0> is the DAC - // channel's address, and D<7:0> is the DAC setpoint. Append a WORD - // value (that writes a channel 0 NOP command to a non-existent main - // DAC channel) that serves to keep the clock running after the - // packet has been sent to the target DAC. - - SendDAC(dev, ( (uint32_t)chan << 8 ) // Address the DAC channel - // within the trimdac device. - | (uint32_t)DacData ); // Include DAC setpoint data. +static void WriteTrimDAC(comedi_device * dev, uint8_t LogicalChan, + uint8_t DacData) +{ + uint32_t chan; + + // Save the new setpoint in case the application needs to read it back later. + devpriv->TrimSetpoint[LogicalChan] = (uint8_t) DacData; + + // Map logical channel number to physical channel number. + chan = (uint32_t) trimchan[LogicalChan]; + + // Set up TSL2 records for TrimDac write operation. All slots shift + // 0xFF in from pulled-up SD3 so that the end of the slot sequence + // can be detected. + SETVECT(2, XSD2 | XFIFO_1 | WS3); // Slot 2: Send high uint8_t + // to target TrimDac. + SETVECT(3, XSD2 | XFIFO_0 | WS3); // Slot 3: Send low uint8_t to + // target TrimDac. + SETVECT(4, XSD2 | XFIFO_3 | WS1); // Slot 4: Send NOP high + // uint8_t to DAC0 to keep + // clock running. + SETVECT(5, XSD2 | XFIFO_2 | WS1 | EOS); // Slot 5: Send NOP low + // uint8_t to DAC0. + + // Construct and transmit target DAC's serial packet: ( 0000 AAAA + // ),( DDDD DDDD ),( 0x00 ),( 0x00 ) where A<3:0> is the DAC + // channel's address, and D<7:0> is the DAC setpoint. Append a WORD + // value (that writes a channel 0 NOP command to a non-existent main + // DAC channel) that serves to keep the clock running after the + // packet has been sent to the target DAC. + + SendDAC(dev, ((uint32_t) chan << 8) // Address the DAC channel + // within the trimdac device. + | (uint32_t) DacData); // Include DAC setpoint data. } ///////////////////////////////////////////////////////////////////////// @@ -2262,126 +2409,121 @@ static void WriteTrimDAC(comedi_device *dev, uint8_t LogicalChan, uint8_t DacDat /////////////////////////////////////////// // Read uint8_t from EEPROM. -static uint8_t I2Cread(comedi_device *dev, uint8_t addr ) +static uint8_t I2Cread(comedi_device * dev, uint8_t addr) { - uint8_t rtnval; - - // Send EEPROM target address. - if ( I2Chandshake(dev, I2C_B2( I2C_ATTRSTART, I2CW ) // Byte2 = I2C - // command: - // write to - // I2C EEPROM - // device. - | I2C_B1( I2C_ATTRSTOP, addr ) // Byte1 = EEPROM - // internal target - // address. - | I2C_B0( I2C_ATTRNOP, 0 ) ) ) // Byte0 = Not - // sent. - { - // Abort function and declare error if handshake failed. - DEBUG("I2Cread: error handshake I2Cread a\n"); - return 0; - } - - // Execute EEPROM read. - if ( I2Chandshake(dev, - I2C_B2( I2C_ATTRSTART, I2CR ) // Byte2 = I2C - // command: read - // from I2C EEPROM - // device. - | I2C_B1( I2C_ATTRSTOP, 0 ) // Byte1 receives - // uint8_t from - // EEPROM. - | I2C_B0( I2C_ATTRNOP, 0 ) ) ) // Byte0 = Not - // sent. - { - // Abort function and declare error if handshake failed. - DEBUG("I2Cread: error handshake I2Cread b\n"); - return 0; - } - - // Return copy of EEPROM value. - rtnval = (uint8_t)( RR7146(P_I2CCTRL) >> 16 ); - return rtnval; + uint8_t rtnval; + + // Send EEPROM target address. + if (I2Chandshake(dev, I2C_B2(I2C_ATTRSTART, I2CW) // Byte2 = I2C + // command: + // write to + // I2C EEPROM + // device. + | I2C_B1(I2C_ATTRSTOP, addr) // Byte1 = EEPROM + // internal target + // address. + | I2C_B0(I2C_ATTRNOP, 0))) // Byte0 = Not + // sent. + { + // Abort function and declare error if handshake failed. + DEBUG("I2Cread: error handshake I2Cread a\n"); + return 0; + } + // Execute EEPROM read. + if (I2Chandshake(dev, I2C_B2(I2C_ATTRSTART, I2CR) // Byte2 = I2C + // command: read + // from I2C EEPROM + // device. + | I2C_B1(I2C_ATTRSTOP, 0) // Byte1 receives + // uint8_t from + // EEPROM. + | I2C_B0(I2C_ATTRNOP, 0))) // Byte0 = Not + // sent. + { + // Abort function and declare error if handshake failed. + DEBUG("I2Cread: error handshake I2Cread b\n"); + return 0; + } + // Return copy of EEPROM value. + rtnval = (uint8_t) (RR7146(P_I2CCTRL) >> 16); + return rtnval; } -static uint32_t I2Chandshake(comedi_device *dev, uint32_t val ) +static uint32_t I2Chandshake(comedi_device * dev, uint32_t val) { - // Write I2C command to I2C Transfer Control shadow register. - WR7146( P_I2CCTRL, val ); + // Write I2C command to I2C Transfer Control shadow register. + WR7146(P_I2CCTRL, val); - // Upload I2C shadow registers into working registers and wait for - // upload confirmation. + // Upload I2C shadow registers into working registers and wait for + // upload confirmation. - MC_ENABLE( P_MC2, MC2_UPLD_IIC ); - while ( !MC_TEST( P_MC2, MC2_UPLD_IIC ) ); + MC_ENABLE(P_MC2, MC2_UPLD_IIC); + while (!MC_TEST(P_MC2, MC2_UPLD_IIC)) ; - // Wait until I2C bus transfer is finished or an error occurs. - while ( ( RR7146(P_I2CCTRL) & ( I2C_BUSY | I2C_ERR ) ) == I2C_BUSY ); + // Wait until I2C bus transfer is finished or an error occurs. + while ((RR7146(P_I2CCTRL) & (I2C_BUSY | I2C_ERR)) == I2C_BUSY) ; - // Return non-zero if I2C error occured. - return RR7146(P_I2CCTRL) & I2C_ERR; + // Return non-zero if I2C error occured. + return RR7146(P_I2CCTRL) & I2C_ERR; } // Private helper function: Write setpoint to an application DAC channel. -static void SetDAC(comedi_device *dev,uint16_t chan, short dacdata ) +static void SetDAC(comedi_device * dev, uint16_t chan, short dacdata) { - register uint16_t signmask; - register uint32_t WSImage; - - // Adjust DAC data polarity and set up Polarity Control Register - // image. - signmask = 1 << chan; - if ( dacdata < 0 ) - { - dacdata = -dacdata; - devpriv->Dacpol |= signmask; - } - else - devpriv->Dacpol &= ~signmask; - - // Limit DAC setpoint value to valid range. - if ( (uint16_t)dacdata > 0x1FFF ) - dacdata = 0x1FFF; - - // Set up TSL2 records (aka "vectors") for DAC update. Vectors V2 - // and V3 transmit the setpoint to the target DAC. V4 and V5 send - // data to a non-existent TrimDac channel just to keep the clock - // running after sending data to the target DAC. This is necessary - // to eliminate the clock glitch that would otherwise occur at the - // end of the target DAC's serial data stream. When the sequence - // restarts at V0 (after executing V5), the gate array automatically - // disables gating for the DAC clock and all DAC chip selects. - WSImage = ( chan & 2 ) ? WS1 : WS2; // Choose DAC chip select to - // be asserted. - SETVECT( 2, XSD2 | XFIFO_1 | WSImage ); // Slot 2: Transmit high - // data byte to target DAC. - SETVECT( 3, XSD2 | XFIFO_0 | WSImage ); // Slot 3: Transmit low data - // byte to target DAC. - SETVECT( 4, XSD2 | XFIFO_3 | WS3 ); // Slot 4: Transmit to - // non-existent TrimDac - // channel to keep clock - SETVECT( 5, XSD2 | XFIFO_2 | WS3 | EOS ); // Slot 5: running after - // writing target DAC's - // low data byte. - - // Construct and transmit target DAC's serial packet: ( A10D DDDD - // ),( DDDD DDDD ),( 0x0F ),( 0x00 ) where A is chan<0>, and D<12:0> - // is the DAC setpoint. Append a WORD value (that writes to a - // non-existent TrimDac channel) that serves to keep the clock - // running after the packet has been sent to the target DAC. - SendDAC( dev, 0x0F000000 //Continue clock after target DAC - //data (write to non-existent - //trimdac). - | 0x00004000 // Address the two main dual-DAC - // devices (TSL's chip select enables - // target device). - | ( (uint32_t)( chan & 1 ) << 15 ) // Address the DAC - // channel within the - // device. - | (uint32_t)dacdata ); // Include DAC setpoint data. + register uint16_t signmask; + register uint32_t WSImage; + + // Adjust DAC data polarity and set up Polarity Control Register + // image. + signmask = 1 << chan; + if (dacdata < 0) { + dacdata = -dacdata; + devpriv->Dacpol |= signmask; + } else + devpriv->Dacpol &= ~signmask; + + // Limit DAC setpoint value to valid range. + if ((uint16_t) dacdata > 0x1FFF) + dacdata = 0x1FFF; + + // Set up TSL2 records (aka "vectors") for DAC update. Vectors V2 + // and V3 transmit the setpoint to the target DAC. V4 and V5 send + // data to a non-existent TrimDac channel just to keep the clock + // running after sending data to the target DAC. This is necessary + // to eliminate the clock glitch that would otherwise occur at the + // end of the target DAC's serial data stream. When the sequence + // restarts at V0 (after executing V5), the gate array automatically + // disables gating for the DAC clock and all DAC chip selects. + WSImage = (chan & 2) ? WS1 : WS2; // Choose DAC chip select to + // be asserted. + SETVECT(2, XSD2 | XFIFO_1 | WSImage); // Slot 2: Transmit high + // data byte to target DAC. + SETVECT(3, XSD2 | XFIFO_0 | WSImage); // Slot 3: Transmit low data + // byte to target DAC. + SETVECT(4, XSD2 | XFIFO_3 | WS3); // Slot 4: Transmit to + // non-existent TrimDac + // channel to keep clock + SETVECT(5, XSD2 | XFIFO_2 | WS3 | EOS); // Slot 5: running after + // writing target DAC's + // low data byte. + + // Construct and transmit target DAC's serial packet: ( A10D DDDD + // ),( DDDD DDDD ),( 0x0F ),( 0x00 ) where A is chan<0>, and D<12:0> + // is the DAC setpoint. Append a WORD value (that writes to a + // non-existent TrimDac channel) that serves to keep the clock + // running after the packet has been sent to the target DAC. + SendDAC(dev, 0x0F000000 //Continue clock after target DAC + //data (write to non-existent + //trimdac). + | 0x00004000 // Address the two main dual-DAC + // devices (TSL's chip select enables + // target device). + | ((uint32_t) (chan & 1) << 15) // Address the DAC + // channel within the + // device. + | (uint32_t) dacdata); // Include DAC setpoint data. } @@ -2390,210 +2532,208 @@ static void SetDAC(comedi_device *dev,uint16_t chan, short dacdata ) // channel 2. Assumes: (1) TSL2 slot records initialized, and (2) // Dacpol contains valid target image. -static void SendDAC( comedi_device *dev, uint32_t val ) +static void SendDAC(comedi_device * dev, uint32_t val) { - - // START THE SERIAL CLOCK RUNNING ------------- - - // Assert DAC polarity control and enable gating of DAC serial clock - // and audio bit stream signals. At this point in time we must be - // assured of being in time slot 0. If we are not in slot 0, the - // serial clock and audio stream signals will be disabled; this is - // because the following DEBIwrite statement (which enables signals - // to be passed through the gate array) would execute before the - // trailing edge of WS1/WS3 (which turns off the signals), thus - // causing the signals to be inactive during the DAC write. - DEBIwrite(dev, LP_DACPOL, devpriv->Dacpol ); - - // TRANSFER OUTPUT DWORD VALUE INTO A2'S OUTPUT FIFO ---------------- - - // Copy DAC setpoint value to DAC's output DMA buffer. - - //WR7146( (uint32_t)devpriv->pDacWBuf, val ); - *devpriv->pDacWBuf=val; - - // enab the output DMA transfer. This will cause the DMAC to copy - // the DAC's data value to A2's output FIFO. The DMA transfer will - // then immediately terminate because the protection address is - // reached upon transfer of the first DWORD value. - MC_ENABLE( P_MC1, MC1_A2OUT ); - - // While the DMA transfer is executing ... - - // Reset Audio2 output FIFO's underflow flag (along with any other - // FIFO underflow/overflow flags). When set, this flag will - // indicate that we have emerged from slot 0. - WR7146( P_ISR, ISR_AFOU ); - - // Wait for the DMA transfer to finish so that there will be data - // available in the FIFO when time slot 1 tries to transfer a DWORD - // from the FIFO to the output buffer register. We test for DMA - // Done by polling the DMAC enable flag; this flag is automatically - // cleared when the transfer has finished. - while ( ( RR7146( P_MC1 ) & MC1_A2OUT ) != 0 ); - - // START THE OUTPUT STREAM TO THE TARGET DAC -------------------- - - // FIFO data is now available, so we enable execution of time slots - // 1 and higher by clearing the EOS flag in slot 0. Note that SD3 - // will be shifted in and stored in FB_BUFFER2 for end-of-slot-list - // detection. - SETVECT( 0, XSD2 | RSD3 | SIB_A2 ); - - // Wait for slot 1 to execute to ensure that the Packet will be - // transmitted. This is detected by polling the Audio2 output FIFO - // underflow flag, which will be set when slot 1 execution has - // finished transferring the DAC's data DWORD from the output FIFO - // to the output buffer register. - while ( ( RR7146( P_SSR ) & SSR_AF2_OUT ) == 0 ); - - // Set up to trap execution at slot 0 when the TSL sequencer cycles - // back to slot 0 after executing the EOS in slot 5. Also, - // simultaneously shift out and in the 0x00 that is ALWAYS the value - // stored in the last byte to be shifted out of the FIFO's DWORD - // buffer register. - SETVECT( 0, XSD2 | XFIFO_2 | RSD2 | SIB_A2 | EOS ); - - // WAIT FOR THE TRANSACTION TO FINISH ----------------------- - - // Wait for the TSL to finish executing all time slots before - // exiting this function. We must do this so that the next DAC - // write doesn't start, thereby enabling clock/chip select signals: - // 1. Before the TSL sequence cycles back to slot 0, which disables - // the clock/cs signal gating and traps slot // list execution. If - // we have not yet finished slot 5 then the clock/cs signals are - // still gated and we have // not finished transmitting the stream. - // 2. While slots 2-5 are executing due to a late slot 0 trap. In - // this case, the slot sequence is currently // repeating, but with - // clock/cs signals disabled. We must wait for slot 0 to trap - // execution before setting // up the next DAC setpoint DMA transfer - // and enabling the clock/cs signals. To detect the end of slot 5, - // we test for the FB_BUFFER2 MSB contents to be equal to 0xFF. If - // the TSL has not yet finished executing slot 5 ... - if ( ( RR7146( P_FB_BUFFER2 ) & 0xFF000000 ) != 0 ) - { - // The trap was set on time and we are still executing somewhere - // in slots 2-5, so we now wait for slot 0 to execute and trap - // TSL execution. This is detected when FB_BUFFER2 MSB changes - // from 0xFF to 0x00, which slot 0 causes to happen by shifting - // out/in on SD2 the 0x00 that is always referenced by slot 5. - while ( ( RR7146( P_FB_BUFFER2 ) & 0xFF000000 ) != 0 ); - } - - // Either (1) we were too late setting the slot 0 trap; the TSL - // sequencer restarted slot 0 before we could set the EOS trap flag, - // or (2) we were not late and execution is now trapped at slot 0. - // In either case, we must now change slot 0 so that it will store - // value 0xFF (instead of 0x00) to FB_BUFFER2 next time it executes. - // In order to do this, we reprogram slot 0 so that it will shift in - // SD3, which is driven only by a pull-up resistor. - SETVECT( 0, RSD3 | SIB_A2 | EOS ); - - // Wait for slot 0 to execute, at which time the TSL is setup for - // the next DAC write. This is detected when FB_BUFFER2 MSB changes - // from 0x00 to 0xFF. - while ( ( RR7146( P_FB_BUFFER2 ) & 0xFF000000 ) == 0 ); + // START THE SERIAL CLOCK RUNNING ------------- + + // Assert DAC polarity control and enable gating of DAC serial clock + // and audio bit stream signals. At this point in time we must be + // assured of being in time slot 0. If we are not in slot 0, the + // serial clock and audio stream signals will be disabled; this is + // because the following DEBIwrite statement (which enables signals + // to be passed through the gate array) would execute before the + // trailing edge of WS1/WS3 (which turns off the signals), thus + // causing the signals to be inactive during the DAC write. + DEBIwrite(dev, LP_DACPOL, devpriv->Dacpol); + + // TRANSFER OUTPUT DWORD VALUE INTO A2'S OUTPUT FIFO ---------------- + + // Copy DAC setpoint value to DAC's output DMA buffer. + + //WR7146( (uint32_t)devpriv->pDacWBuf, val ); + *devpriv->pDacWBuf = val; + + // enab the output DMA transfer. This will cause the DMAC to copy + // the DAC's data value to A2's output FIFO. The DMA transfer will + // then immediately terminate because the protection address is + // reached upon transfer of the first DWORD value. + MC_ENABLE(P_MC1, MC1_A2OUT); + + // While the DMA transfer is executing ... + + // Reset Audio2 output FIFO's underflow flag (along with any other + // FIFO underflow/overflow flags). When set, this flag will + // indicate that we have emerged from slot 0. + WR7146(P_ISR, ISR_AFOU); + + // Wait for the DMA transfer to finish so that there will be data + // available in the FIFO when time slot 1 tries to transfer a DWORD + // from the FIFO to the output buffer register. We test for DMA + // Done by polling the DMAC enable flag; this flag is automatically + // cleared when the transfer has finished. + while ((RR7146(P_MC1) & MC1_A2OUT) != 0) ; + + // START THE OUTPUT STREAM TO THE TARGET DAC -------------------- + + // FIFO data is now available, so we enable execution of time slots + // 1 and higher by clearing the EOS flag in slot 0. Note that SD3 + // will be shifted in and stored in FB_BUFFER2 for end-of-slot-list + // detection. + SETVECT(0, XSD2 | RSD3 | SIB_A2); + + // Wait for slot 1 to execute to ensure that the Packet will be + // transmitted. This is detected by polling the Audio2 output FIFO + // underflow flag, which will be set when slot 1 execution has + // finished transferring the DAC's data DWORD from the output FIFO + // to the output buffer register. + while ((RR7146(P_SSR) & SSR_AF2_OUT) == 0) ; + + // Set up to trap execution at slot 0 when the TSL sequencer cycles + // back to slot 0 after executing the EOS in slot 5. Also, + // simultaneously shift out and in the 0x00 that is ALWAYS the value + // stored in the last byte to be shifted out of the FIFO's DWORD + // buffer register. + SETVECT(0, XSD2 | XFIFO_2 | RSD2 | SIB_A2 | EOS); + + // WAIT FOR THE TRANSACTION TO FINISH ----------------------- + + // Wait for the TSL to finish executing all time slots before + // exiting this function. We must do this so that the next DAC + // write doesn't start, thereby enabling clock/chip select signals: + // 1. Before the TSL sequence cycles back to slot 0, which disables + // the clock/cs signal gating and traps slot // list execution. If + // we have not yet finished slot 5 then the clock/cs signals are + // still gated and we have // not finished transmitting the stream. + // 2. While slots 2-5 are executing due to a late slot 0 trap. In + // this case, the slot sequence is currently // repeating, but with + // clock/cs signals disabled. We must wait for slot 0 to trap + // execution before setting // up the next DAC setpoint DMA transfer + // and enabling the clock/cs signals. To detect the end of slot 5, + // we test for the FB_BUFFER2 MSB contents to be equal to 0xFF. If + // the TSL has not yet finished executing slot 5 ... + if ((RR7146(P_FB_BUFFER2) & 0xFF000000) != 0) { + // The trap was set on time and we are still executing somewhere + // in slots 2-5, so we now wait for slot 0 to execute and trap + // TSL execution. This is detected when FB_BUFFER2 MSB changes + // from 0xFF to 0x00, which slot 0 causes to happen by shifting + // out/in on SD2 the 0x00 that is always referenced by slot 5. + while ((RR7146(P_FB_BUFFER2) & 0xFF000000) != 0) ; + } + // Either (1) we were too late setting the slot 0 trap; the TSL + // sequencer restarted slot 0 before we could set the EOS trap flag, + // or (2) we were not late and execution is now trapped at slot 0. + // In either case, we must now change slot 0 so that it will store + // value 0xFF (instead of 0x00) to FB_BUFFER2 next time it executes. + // In order to do this, we reprogram slot 0 so that it will shift in + // SD3, which is driven only by a pull-up resistor. + SETVECT(0, RSD3 | SIB_A2 | EOS); + + // Wait for slot 0 to execute, at which time the TSL is setup for + // the next DAC write. This is detected when FB_BUFFER2 MSB changes + // from 0x00 to 0xFF. + while ((RR7146(P_FB_BUFFER2) & 0xFF000000) == 0) ; } -static void WriteMISC2( comedi_device *dev, uint16_t NewImage ) +static void WriteMISC2(comedi_device * dev, uint16_t NewImage) { - DEBIwrite( dev, LP_MISC1, MISC1_WENABLE ); // enab writes to - // MISC2 register. - DEBIwrite(dev, LP_WRMISC2, NewImage ); // Write new image to MISC2. - DEBIwrite(dev, LP_MISC1, MISC1_WDISABLE ); // Disable writes to MISC2. + DEBIwrite(dev, LP_MISC1, MISC1_WENABLE); // enab writes to + // MISC2 register. + DEBIwrite(dev, LP_WRMISC2, NewImage); // Write new image to MISC2. + DEBIwrite(dev, LP_MISC1, MISC1_WDISABLE); // Disable writes to MISC2. } ///////////////////////////////////////////////////////////////////// // Initialize the DEBI interface for all transfers. -static uint16_t DEBIread( comedi_device *dev, uint16_t addr ) +static uint16_t DEBIread(comedi_device * dev, uint16_t addr) { - uint16_t retval; + uint16_t retval; - // Set up DEBI control register value in shadow RAM. - WR7146( P_DEBICMD, DEBI_CMD_RDWORD | addr ); + // Set up DEBI control register value in shadow RAM. + WR7146(P_DEBICMD, DEBI_CMD_RDWORD | addr); - // Execute the DEBI transfer. - DEBItransfer( dev); + // Execute the DEBI transfer. + DEBItransfer(dev); - // Fetch target register value. - retval = (uint16_t)RR7146( P_DEBIAD ); + // Fetch target register value. + retval = (uint16_t) RR7146(P_DEBIAD); - // Return register value. - return retval; + // Return register value. + return retval; } // Execute a DEBI transfer. This must be called from within a // critical section. -static void DEBItransfer(comedi_device *dev ) +static void DEBItransfer(comedi_device * dev) { - // Initiate upload of shadow RAM to DEBI control register. - MC_ENABLE( P_MC2, MC2_UPLD_DEBI ); + // Initiate upload of shadow RAM to DEBI control register. + MC_ENABLE(P_MC2, MC2_UPLD_DEBI); - // Wait for completion of upload from shadow RAM to DEBI control - // register. - while ( !MC_TEST( P_MC2, MC2_UPLD_DEBI ) ); + // Wait for completion of upload from shadow RAM to DEBI control + // register. + while (!MC_TEST(P_MC2, MC2_UPLD_DEBI)) ; - // Wait until DEBI transfer is done. - while ( RR7146(P_PSR) & PSR_DEBI_S ); + // Wait until DEBI transfer is done. + while (RR7146(P_PSR) & PSR_DEBI_S) ; } // Write a value to a gate array register. -static void DEBIwrite(comedi_device *dev, uint16_t addr, uint16_t wdata ) +static void DEBIwrite(comedi_device * dev, uint16_t addr, uint16_t wdata) { - // Set up DEBI control register value in shadow RAM. - WR7146( P_DEBICMD, DEBI_CMD_WRWORD | addr ); - WR7146( P_DEBIAD, wdata ); + // Set up DEBI control register value in shadow RAM. + WR7146(P_DEBICMD, DEBI_CMD_WRWORD | addr); + WR7146(P_DEBIAD, wdata); - // Execute the DEBI transfer. - DEBItransfer(dev); + // Execute the DEBI transfer. + DEBItransfer(dev); } ///////////////////////////////////////////////////////////////////////////// // Replace the specified bits in a gate array register. Imports: mask // specifies bits that are to be preserved, wdata is new value to be // or'd with the masked original. -static void DEBIreplace(comedi_device *dev, uint16_t addr, uint16_t mask, uint16_t wdata ) +static void DEBIreplace(comedi_device * dev, uint16_t addr, uint16_t mask, + uint16_t wdata) { - // Copy target gate array register into P_DEBIAD register. - WR7146( P_DEBICMD, DEBI_CMD_RDWORD | addr ); // Set up DEBI control - // reg value in shadow - // RAM. - DEBItransfer( dev); // Execute the DEBI - // Read transfer. + // Copy target gate array register into P_DEBIAD register. + WR7146(P_DEBICMD, DEBI_CMD_RDWORD | addr); // Set up DEBI control + // reg value in shadow + // RAM. + DEBItransfer(dev); // Execute the DEBI + // Read transfer. - // Write back the modified image. - WR7146( P_DEBICMD, DEBI_CMD_WRWORD | addr ); // Set up DEBI control - // reg value in shadow - // RAM. + // Write back the modified image. + WR7146(P_DEBICMD, DEBI_CMD_WRWORD | addr); // Set up DEBI control + // reg value in shadow + // RAM. - WR7146( P_DEBIAD, wdata | ( (uint16_t)RR7146( P_DEBIAD ) & mask ) ); // Modify the register image. - DEBItransfer(dev ); // Execute the DEBI Write transfer. + WR7146(P_DEBIAD, wdata | ((uint16_t) RR7146(P_DEBIAD) & mask)); // Modify the register image. + DEBItransfer(dev); // Execute the DEBI Write transfer. } -static void CloseDMAB (comedi_device *dev,DMABUF * pdma,size_t bsize ) +static void CloseDMAB(comedi_device * dev, DMABUF * pdma, size_t bsize) { - void *vbptr; - dma_addr_t vpptr; - - DEBUG("CloseDMAB: Entering S626DRV_CloseDMAB():\n"); - if (pdma == NULL) - return; - //find the matching allocation from the board struct - - vbptr=pdma->LogicalBase; - vpptr=pdma->PhysicalBase; - if (vbptr) - { - pci_free_consistent (devpriv->pdev, bsize, vbptr, vpptr); - pdma->LogicalBase = 0; - pdma->PhysicalBase = 0; - - DEBUG ("CloseDMAB(): Logical=%p, bsize=%d, Physical=0x%x\n", vbptr, bsize, (uint32_t) vpptr); - } + void *vbptr; + dma_addr_t vpptr; + + DEBUG("CloseDMAB: Entering S626DRV_CloseDMAB():\n"); + if (pdma == NULL) + return; + //find the matching allocation from the board struct + + vbptr = pdma->LogicalBase; + vpptr = pdma->PhysicalBase; + if (vbptr) { + pci_free_consistent(devpriv->pdev, bsize, vbptr, vpptr); + pdma->LogicalBase = 0; + pdma->PhysicalBase = 0; + + DEBUG("CloseDMAB(): Logical=%p, bsize=%d, Physical=0x%x\n", + vbptr, bsize, (uint32_t) vpptr); + } } //////////////////////////////////////////////////////////////////////// @@ -2615,114 +2755,117 @@ static void CloseDMAB (comedi_device *dev,DMABUF * pdma,size_t bsize ) ///////////////////////////////////////////////////////////////// // Read a counter's output latch. -static uint32_t ReadLatch(comedi_device *dev, enc_private *k ) +static uint32_t ReadLatch(comedi_device * dev, enc_private * k) { - register uint32_t value; - //DEBUG FIXME DEBUG("ReadLatch: Read Latch enter\n"); + register uint32_t value; + //DEBUG FIXME DEBUG("ReadLatch: Read Latch enter\n"); - // Latch counts and fetch LSW of latched counts value. - value = (uint32_t)DEBIread(dev,k->MyLatchLsw ); + // Latch counts and fetch LSW of latched counts value. + value = (uint32_t) DEBIread(dev, k->MyLatchLsw); - // Fetch MSW of latched counts and combine with LSW. - value |= ( (uint32_t) DEBIread(dev,k->MyLatchLsw + 2 ) << 16 ); + // Fetch MSW of latched counts and combine with LSW. + value |= ((uint32_t) DEBIread(dev, k->MyLatchLsw + 2) << 16); - // DEBUG FIXME DEBUG("ReadLatch: Read Latch exit\n"); + // DEBUG FIXME DEBUG("ReadLatch: Read Latch exit\n"); - // Return latched counts. - return value; + // Return latched counts. + return value; } /////////////////////////////////////////////////////////////////// // Reset a counter's index and overflow event capture flags. -static void ResetCapFlags_A(comedi_device *dev, enc_private *k ) +static void ResetCapFlags_A(comedi_device * dev, enc_private * k) { - DEBIreplace(dev, k->MyCRB, (uint16_t)( ~CRBMSK_INTCTRL ), CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A ); + DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL), + CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A); } -static void ResetCapFlags_B(comedi_device *dev, enc_private *k ) +static void ResetCapFlags_B(comedi_device * dev, enc_private * k) { - DEBIreplace(dev, k->MyCRB, (uint16_t)( ~CRBMSK_INTCTRL ), CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B ); + DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL), + CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B); } ///////////////////////////////////////////////////////////////////////// // Return counter setup in a format (COUNTER_SETUP) that is consistent // for both A and B counters. -static uint16_t GetMode_A(comedi_device *dev, enc_private *k ) +static uint16_t GetMode_A(comedi_device * dev, enc_private * k) { - register uint16_t cra; - register uint16_t crb; - register uint16_t setup; - - // Fetch CRA and CRB register images. - cra = DEBIread(dev,k->MyCRA ); - crb = DEBIread(dev,k->MyCRB ); - - // Populate the standardized counter setup bit fields. Note: - // IndexSrc is restricted to ENC_X or IndxPol. - setup = ( ( cra & STDMSK_LOADSRC ) // LoadSrc = LoadSrcA. - | ( ( crb << ( STDBIT_LATCHSRC - CRBBIT_LATCHSRC ) ) & STDMSK_LATCHSRC ) // LatchSrc = LatchSrcA. - | ( ( cra << ( STDBIT_INTSRC - CRABIT_INTSRC_A ) ) & STDMSK_INTSRC ) // IntSrc = IntSrcA. - | ( ( cra << ( STDBIT_INDXSRC - (CRABIT_INDXSRC_A + 1) ) ) & STDMSK_INDXSRC ) // IndxSrc = IndxSrcA<1>. - | ( ( cra >> ( CRABIT_INDXPOL_A - STDBIT_INDXPOL ) ) & STDMSK_INDXPOL ) // IndxPol = IndxPolA. - | ( ( crb >> ( CRBBIT_CLKENAB_A - STDBIT_CLKENAB ) ) & STDMSK_CLKENAB ) ); // ClkEnab = ClkEnabA. - - // Adjust mode-dependent parameters. - if ( cra & ( 2 << CRABIT_CLKSRC_A ) ) // If Timer mode (ClkSrcA<1> == 1): - setup |= ( ( CLKSRC_TIMER << STDBIT_CLKSRC ) // Indicate Timer mode. - | ( ( cra << ( STDBIT_CLKPOL - CRABIT_CLKSRC_A ) ) & STDMSK_CLKPOL ) // Set ClkPol to indicate count direction (ClkSrcA<0>). - | ( MULT_X1 << STDBIT_CLKMULT ) ); // ClkMult must be 1x in Timer mode. - - else // If Counter mode (ClkSrcA<1> == 0): - setup |= ( ( CLKSRC_COUNTER << STDBIT_CLKSRC ) // Indicate Counter mode. - | ( ( cra >> ( CRABIT_CLKPOL_A - STDBIT_CLKPOL ) ) & STDMSK_CLKPOL ) // Pass through ClkPol. - | ( ( ( cra & CRAMSK_CLKMULT_A ) == ( MULT_X0 << CRABIT_CLKMULT_A ) ) ? // Force ClkMult to 1x if not legal, else pass through. - ( MULT_X1 << STDBIT_CLKMULT ) : - ( ( cra >> ( CRABIT_CLKMULT_A - STDBIT_CLKMULT ) ) & STDMSK_CLKMULT ) ) ); - - // Return adjusted counter setup. - return setup; + register uint16_t cra; + register uint16_t crb; + register uint16_t setup; + + // Fetch CRA and CRB register images. + cra = DEBIread(dev, k->MyCRA); + crb = DEBIread(dev, k->MyCRB); + + // Populate the standardized counter setup bit fields. Note: + // IndexSrc is restricted to ENC_X or IndxPol. + setup = ((cra & STDMSK_LOADSRC) // LoadSrc = LoadSrcA. + | ((crb << (STDBIT_LATCHSRC - CRBBIT_LATCHSRC)) & STDMSK_LATCHSRC) // LatchSrc = LatchSrcA. + | ((cra << (STDBIT_INTSRC - CRABIT_INTSRC_A)) & STDMSK_INTSRC) // IntSrc = IntSrcA. + | ((cra << (STDBIT_INDXSRC - (CRABIT_INDXSRC_A + 1))) & STDMSK_INDXSRC) // IndxSrc = IndxSrcA<1>. + | ((cra >> (CRABIT_INDXPOL_A - STDBIT_INDXPOL)) & STDMSK_INDXPOL) // IndxPol = IndxPolA. + | ((crb >> (CRBBIT_CLKENAB_A - STDBIT_CLKENAB)) & STDMSK_CLKENAB)); // ClkEnab = ClkEnabA. + + // Adjust mode-dependent parameters. + if (cra & (2 << CRABIT_CLKSRC_A)) // If Timer mode (ClkSrcA<1> == 1): + setup |= ((CLKSRC_TIMER << STDBIT_CLKSRC) // Indicate Timer mode. + | ((cra << (STDBIT_CLKPOL - CRABIT_CLKSRC_A)) & STDMSK_CLKPOL) // Set ClkPol to indicate count direction (ClkSrcA<0>). + | (MULT_X1 << STDBIT_CLKMULT)); // ClkMult must be 1x in Timer mode. + + else // If Counter mode (ClkSrcA<1> == 0): + setup |= ((CLKSRC_COUNTER << STDBIT_CLKSRC) // Indicate Counter mode. + | ((cra >> (CRABIT_CLKPOL_A - STDBIT_CLKPOL)) & STDMSK_CLKPOL) // Pass through ClkPol. + | (((cra & CRAMSK_CLKMULT_A) == (MULT_X0 << CRABIT_CLKMULT_A)) ? // Force ClkMult to 1x if not legal, else pass through. + (MULT_X1 << STDBIT_CLKMULT) : + ((cra >> (CRABIT_CLKMULT_A - + STDBIT_CLKMULT)) & + STDMSK_CLKMULT))); + + // Return adjusted counter setup. + return setup; } -static uint16_t GetMode_B(comedi_device *dev, enc_private *k ) +static uint16_t GetMode_B(comedi_device * dev, enc_private * k) { - register uint16_t cra; - register uint16_t crb; - register uint16_t setup; - - // Fetch CRA and CRB register images. - cra = DEBIread(dev,k->MyCRA ); - crb = DEBIread(dev,k->MyCRB ); - - // Populate the standardized counter setup bit fields. Note: - // IndexSrc is restricted to ENC_X or IndxPol. - setup = - ( ( ( crb << ( STDBIT_INTSRC - CRBBIT_INTSRC_B ) ) & STDMSK_INTSRC ) // IntSrc = IntSrcB. - | ( ( crb << ( STDBIT_LATCHSRC - CRBBIT_LATCHSRC ) ) & STDMSK_LATCHSRC ) // LatchSrc = LatchSrcB. - | ( ( crb << ( STDBIT_LOADSRC - CRBBIT_LOADSRC_B ) ) & STDMSK_LOADSRC ) // LoadSrc = LoadSrcB. - | ( ( crb << ( STDBIT_INDXPOL - CRBBIT_INDXPOL_B ) ) & STDMSK_INDXPOL ) // IndxPol = IndxPolB. - | ( ( crb >> ( CRBBIT_CLKENAB_B - STDBIT_CLKENAB ) ) & STDMSK_CLKENAB ) // ClkEnab = ClkEnabB. - | ( ( cra >> ( (CRABIT_INDXSRC_B + 1) - STDBIT_INDXSRC ) ) & STDMSK_INDXSRC ) ); // IndxSrc = IndxSrcB<1>. - - // Adjust mode-dependent parameters. - if ( ( crb & CRBMSK_CLKMULT_B ) == ( MULT_X0 << CRBBIT_CLKMULT_B ) ) // If Extender mode (ClkMultB == MULT_X0): - setup |= ( ( CLKSRC_EXTENDER << STDBIT_CLKSRC ) // Indicate Extender mode. - | ( MULT_X1 << STDBIT_CLKMULT ) // Indicate multiplier is 1x. - | ( ( cra >> ( CRABIT_CLKSRC_B - STDBIT_CLKPOL ) ) & STDMSK_CLKPOL ) ); // Set ClkPol equal to Timer count direction (ClkSrcB<0>). - - else if ( cra & ( 2 << CRABIT_CLKSRC_B ) ) // If Timer mode (ClkSrcB<1> == 1): - setup |= ( ( CLKSRC_TIMER << STDBIT_CLKSRC ) // Indicate Timer mode. - | ( MULT_X1 << STDBIT_CLKMULT ) // Indicate multiplier is 1x. - | ( ( cra >> ( CRABIT_CLKSRC_B - STDBIT_CLKPOL ) ) & STDMSK_CLKPOL ) ); // Set ClkPol equal to Timer count direction (ClkSrcB<0>). - - else // If Counter mode (ClkSrcB<1> == 0): - setup |= ( ( CLKSRC_COUNTER << STDBIT_CLKSRC ) // Indicate Timer mode. - | ( ( crb >> ( CRBBIT_CLKMULT_B - STDBIT_CLKMULT ) ) & STDMSK_CLKMULT ) // Clock multiplier is passed through. - | ( ( crb << ( STDBIT_CLKPOL - CRBBIT_CLKPOL_B ) ) & STDMSK_CLKPOL ) ); // Clock polarity is passed through. - - // Return adjusted counter setup. - return setup; + register uint16_t cra; + register uint16_t crb; + register uint16_t setup; + + // Fetch CRA and CRB register images. + cra = DEBIread(dev, k->MyCRA); + crb = DEBIread(dev, k->MyCRB); + + // Populate the standardized counter setup bit fields. Note: + // IndexSrc is restricted to ENC_X or IndxPol. + setup = (((crb << (STDBIT_INTSRC - CRBBIT_INTSRC_B)) & STDMSK_INTSRC) // IntSrc = IntSrcB. + | ((crb << (STDBIT_LATCHSRC - CRBBIT_LATCHSRC)) & STDMSK_LATCHSRC) // LatchSrc = LatchSrcB. + | ((crb << (STDBIT_LOADSRC - CRBBIT_LOADSRC_B)) & STDMSK_LOADSRC) // LoadSrc = LoadSrcB. + | ((crb << (STDBIT_INDXPOL - CRBBIT_INDXPOL_B)) & STDMSK_INDXPOL) // IndxPol = IndxPolB. + | ((crb >> (CRBBIT_CLKENAB_B - STDBIT_CLKENAB)) & STDMSK_CLKENAB) // ClkEnab = ClkEnabB. + | ((cra >> ((CRABIT_INDXSRC_B + 1) - STDBIT_INDXSRC)) & STDMSK_INDXSRC)); // IndxSrc = IndxSrcB<1>. + + // Adjust mode-dependent parameters. + if ((crb & CRBMSK_CLKMULT_B) == (MULT_X0 << CRBBIT_CLKMULT_B)) // If Extender mode (ClkMultB == MULT_X0): + setup |= ((CLKSRC_EXTENDER << STDBIT_CLKSRC) // Indicate Extender mode. + | (MULT_X1 << STDBIT_CLKMULT) // Indicate multiplier is 1x. + | ((cra >> (CRABIT_CLKSRC_B - STDBIT_CLKPOL)) & STDMSK_CLKPOL)); // Set ClkPol equal to Timer count direction (ClkSrcB<0>). + + else if (cra & (2 << CRABIT_CLKSRC_B)) // If Timer mode (ClkSrcB<1> == 1): + setup |= ((CLKSRC_TIMER << STDBIT_CLKSRC) // Indicate Timer mode. + | (MULT_X1 << STDBIT_CLKMULT) // Indicate multiplier is 1x. + | ((cra >> (CRABIT_CLKSRC_B - STDBIT_CLKPOL)) & STDMSK_CLKPOL)); // Set ClkPol equal to Timer count direction (ClkSrcB<0>). + + else // If Counter mode (ClkSrcB<1> == 0): + setup |= ((CLKSRC_COUNTER << STDBIT_CLKSRC) // Indicate Timer mode. + | ((crb >> (CRBBIT_CLKMULT_B - STDBIT_CLKMULT)) & STDMSK_CLKMULT) // Clock multiplier is passed through. + | ((crb << (STDBIT_CLKPOL - CRBBIT_CLKPOL_B)) & STDMSK_CLKPOL)); // Clock polarity is passed through. + + // Return adjusted counter setup. + return setup; } ///////////////////////////////////////////////////////////////////////////////////////////// @@ -2731,139 +2874,152 @@ static uint16_t GetMode_B(comedi_device *dev, enc_private *k ) // parameters are programmable (all other parms are ignored): ClkMult, // ClkPol, ClkEnab, IndexSrc, IndexPol, LoadSrc. -static void SetMode_A(comedi_device *dev, enc_private *k, uint16_t Setup, uint16_t DisableIntSrc ) +static void SetMode_A(comedi_device * dev, enc_private * k, uint16_t Setup, + uint16_t DisableIntSrc) { - register uint16_t cra; - register uint16_t crb; - register uint16_t setup = Setup; // Cache the Standard Setup. - - // Initialize CRA and CRB images. - cra = ( ( setup & CRAMSK_LOADSRC_A ) // Preload trigger is passed through. - | ( ( setup & STDMSK_INDXSRC ) >> ( STDBIT_INDXSRC - (CRABIT_INDXSRC_A + 1) ) ) ); // IndexSrc is restricted to ENC_X or IndxPol. - - crb = ( CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A // Reset any pending CounterA event captures. - | ( ( setup & STDMSK_CLKENAB ) << ( CRBBIT_CLKENAB_A - STDBIT_CLKENAB ) ) ); // Clock enable is passed through. - - // Force IntSrc to Disabled if DisableIntSrc is asserted. - if ( !DisableIntSrc ) - cra |= ( ( setup & STDMSK_INTSRC ) >> ( STDBIT_INTSRC - CRABIT_INTSRC_A ) ); - - // Populate all mode-dependent attributes of CRA & CRB images. - switch ( ( setup & STDMSK_CLKSRC ) >> STDBIT_CLKSRC ) - { - case CLKSRC_EXTENDER: // Extender Mode: Force to Timer mode - // (Extender valid only for B counters). - - case CLKSRC_TIMER: // Timer Mode: - cra |= ( ( 2 << CRABIT_CLKSRC_A ) // ClkSrcA<1> selects system clock - | ( ( setup & STDMSK_CLKPOL ) >> ( STDBIT_CLKPOL - CRABIT_CLKSRC_A ) ) // with count direction (ClkSrcA<0>) obtained from ClkPol. - | ( 1 << CRABIT_CLKPOL_A ) // ClkPolA behaves as always-on clock enable. - | ( MULT_X1 << CRABIT_CLKMULT_A ) ); // ClkMult must be 1x. - break; - - default: // Counter Mode: - cra |= ( CLKSRC_COUNTER // Select ENC_C and ENC_D as clock/direction inputs. - | ( ( setup & STDMSK_CLKPOL ) << ( CRABIT_CLKPOL_A - STDBIT_CLKPOL ) ) // Clock polarity is passed through. - | ( ( ( setup & STDMSK_CLKMULT ) == ( MULT_X0 << STDBIT_CLKMULT ) ) ? // Force multiplier to x1 if not legal, otherwise pass through. - ( MULT_X1 << CRABIT_CLKMULT_A ) : - ( ( setup & STDMSK_CLKMULT ) << ( CRABIT_CLKMULT_A - STDBIT_CLKMULT ) ) ) ); - } - - // Force positive index polarity if IndxSrc is software-driven only, - // otherwise pass it through. - if ( ~setup & STDMSK_INDXSRC ) - cra |= ( ( setup & STDMSK_INDXPOL ) << ( CRABIT_INDXPOL_A - STDBIT_INDXPOL ) ); - - // If IntSrc has been forced to Disabled, update the MISC2 interrupt - // enable mask to indicate the counter interrupt is disabled. - if ( DisableIntSrc ) - devpriv->CounterIntEnabs &= ~k->MyEventBits[3]; - - // While retaining CounterB and LatchSrc configurations, program the - // new counter operating mode. - DEBIreplace(dev, k->MyCRA, CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B, cra ); - DEBIreplace(dev, k->MyCRB, (uint16_t)( ~( CRBMSK_INTCTRL | CRBMSK_CLKENAB_A ) ), crb ); + register uint16_t cra; + register uint16_t crb; + register uint16_t setup = Setup; // Cache the Standard Setup. + + // Initialize CRA and CRB images. + cra = ((setup & CRAMSK_LOADSRC_A) // Preload trigger is passed through. + | ((setup & STDMSK_INDXSRC) >> (STDBIT_INDXSRC - (CRABIT_INDXSRC_A + 1)))); // IndexSrc is restricted to ENC_X or IndxPol. + + crb = (CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A // Reset any pending CounterA event captures. + | ((setup & STDMSK_CLKENAB) << (CRBBIT_CLKENAB_A - STDBIT_CLKENAB))); // Clock enable is passed through. + + // Force IntSrc to Disabled if DisableIntSrc is asserted. + if (!DisableIntSrc) + cra |= ((setup & STDMSK_INTSRC) >> (STDBIT_INTSRC - + CRABIT_INTSRC_A)); + + // Populate all mode-dependent attributes of CRA & CRB images. + switch ((setup & STDMSK_CLKSRC) >> STDBIT_CLKSRC) { + case CLKSRC_EXTENDER: // Extender Mode: Force to Timer mode + // (Extender valid only for B counters). + + case CLKSRC_TIMER: // Timer Mode: + cra |= ((2 << CRABIT_CLKSRC_A) // ClkSrcA<1> selects system clock + | ((setup & STDMSK_CLKPOL) >> (STDBIT_CLKPOL - CRABIT_CLKSRC_A)) // with count direction (ClkSrcA<0>) obtained from ClkPol. + | (1 << CRABIT_CLKPOL_A) // ClkPolA behaves as always-on clock enable. + | (MULT_X1 << CRABIT_CLKMULT_A)); // ClkMult must be 1x. + break; + + default: // Counter Mode: + cra |= (CLKSRC_COUNTER // Select ENC_C and ENC_D as clock/direction inputs. + | ((setup & STDMSK_CLKPOL) << (CRABIT_CLKPOL_A - STDBIT_CLKPOL)) // Clock polarity is passed through. + | (((setup & STDMSK_CLKMULT) == (MULT_X0 << STDBIT_CLKMULT)) ? // Force multiplier to x1 if not legal, otherwise pass through. + (MULT_X1 << CRABIT_CLKMULT_A) : + ((setup & STDMSK_CLKMULT) << (CRABIT_CLKMULT_A - + STDBIT_CLKMULT)))); + } + + // Force positive index polarity if IndxSrc is software-driven only, + // otherwise pass it through. + if (~setup & STDMSK_INDXSRC) + cra |= ((setup & STDMSK_INDXPOL) << (CRABIT_INDXPOL_A - + STDBIT_INDXPOL)); + + // If IntSrc has been forced to Disabled, update the MISC2 interrupt + // enable mask to indicate the counter interrupt is disabled. + if (DisableIntSrc) + devpriv->CounterIntEnabs &= ~k->MyEventBits[3]; + + // While retaining CounterB and LatchSrc configurations, program the + // new counter operating mode. + DEBIreplace(dev, k->MyCRA, CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B, cra); + DEBIreplace(dev, k->MyCRB, + (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A)), crb); } -static void SetMode_B(comedi_device *dev, enc_private *k, uint16_t Setup, uint16_t DisableIntSrc ) +static void SetMode_B(comedi_device * dev, enc_private * k, uint16_t Setup, + uint16_t DisableIntSrc) { - register uint16_t cra; - register uint16_t crb; - register uint16_t setup = Setup; // Cache the Standard Setup. - - // Initialize CRA and CRB images. - cra = ( ( setup & STDMSK_INDXSRC ) << ( (CRABIT_INDXSRC_B + 1) - STDBIT_INDXSRC ) ); // IndexSrc field is restricted to ENC_X or IndxPol. - - crb = ( CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B // Reset event captures and disable interrupts. - | ( ( setup & STDMSK_CLKENAB ) << ( CRBBIT_CLKENAB_B - STDBIT_CLKENAB ) ) // Clock enable is passed through. - | ( ( setup & STDMSK_LOADSRC ) >> ( STDBIT_LOADSRC - CRBBIT_LOADSRC_B ) ) ); // Preload trigger source is passed through. - - // Force IntSrc to Disabled if DisableIntSrc is asserted. - if ( !DisableIntSrc ) - crb |= ( ( setup & STDMSK_INTSRC ) >> ( STDBIT_INTSRC - CRBBIT_INTSRC_B ) ); - - // Populate all mode-dependent attributes of CRA & CRB images. - switch ( ( setup & STDMSK_CLKSRC ) >> STDBIT_CLKSRC ) - { - case CLKSRC_TIMER: // Timer Mode: - cra |= ( ( 2 << CRABIT_CLKSRC_B ) // ClkSrcB<1> selects system clock - | ( ( setup & STDMSK_CLKPOL ) << ( CRABIT_CLKSRC_B - STDBIT_CLKPOL ) ) ); // with direction (ClkSrcB<0>) obtained from ClkPol. - crb |= ( ( 1 << CRBBIT_CLKPOL_B ) // ClkPolB behaves as always-on clock enable. - | ( MULT_X1 << CRBBIT_CLKMULT_B ) ); // ClkMultB must be 1x. - break; - - case CLKSRC_EXTENDER: // Extender Mode: - cra |= ( ( 2 << CRABIT_CLKSRC_B ) // ClkSrcB source is OverflowA (same as "timer") - | ( ( setup & STDMSK_CLKPOL ) << ( CRABIT_CLKSRC_B - STDBIT_CLKPOL ) ) ); // with direction obtained from ClkPol. - crb |= ( ( 1 << CRBBIT_CLKPOL_B ) // ClkPolB controls IndexB -- always set to active. - | ( MULT_X0 << CRBBIT_CLKMULT_B ) ); // ClkMultB selects OverflowA as the clock source. - break; - - default: // Counter Mode: - cra |= ( CLKSRC_COUNTER << CRABIT_CLKSRC_B ); // Select ENC_C and ENC_D as clock/direction inputs. - crb |= ( ( ( setup & STDMSK_CLKPOL ) >> ( STDBIT_CLKPOL - CRBBIT_CLKPOL_B ) ) // ClkPol is passed through. - | ( ( ( setup & STDMSK_CLKMULT ) == ( MULT_X0 << STDBIT_CLKMULT ) ) ? // Force ClkMult to x1 if not legal, otherwise pass through. - ( MULT_X1 << CRBBIT_CLKMULT_B ) : - ( ( setup & STDMSK_CLKMULT ) << ( CRBBIT_CLKMULT_B - STDBIT_CLKMULT ) ) ) ); - } - - // Force positive index polarity if IndxSrc is software-driven only, - // otherwise pass it through. - if ( ~setup & STDMSK_INDXSRC ) - crb |= ( ( setup & STDMSK_INDXPOL ) >> ( STDBIT_INDXPOL - CRBBIT_INDXPOL_B ) ); - - // If IntSrc has been forced to Disabled, update the MISC2 interrupt - // enable mask to indicate the counter interrupt is disabled. - if ( DisableIntSrc ) - devpriv->CounterIntEnabs &= ~k->MyEventBits[3]; - - // While retaining CounterA and LatchSrc configurations, program the - // new counter operating mode. - DEBIreplace( dev, k->MyCRA, (uint16_t)( ~( CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B ) ), cra ); - DEBIreplace( dev, k->MyCRB, CRBMSK_CLKENAB_A | CRBMSK_LATCHSRC, crb ); + register uint16_t cra; + register uint16_t crb; + register uint16_t setup = Setup; // Cache the Standard Setup. + + // Initialize CRA and CRB images. + cra = ((setup & STDMSK_INDXSRC) << ((CRABIT_INDXSRC_B + 1) - STDBIT_INDXSRC)); // IndexSrc field is restricted to ENC_X or IndxPol. + + crb = (CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B // Reset event captures and disable interrupts. + | ((setup & STDMSK_CLKENAB) << (CRBBIT_CLKENAB_B - STDBIT_CLKENAB)) // Clock enable is passed through. + | ((setup & STDMSK_LOADSRC) >> (STDBIT_LOADSRC - CRBBIT_LOADSRC_B))); // Preload trigger source is passed through. + + // Force IntSrc to Disabled if DisableIntSrc is asserted. + if (!DisableIntSrc) + crb |= ((setup & STDMSK_INTSRC) >> (STDBIT_INTSRC - + CRBBIT_INTSRC_B)); + + // Populate all mode-dependent attributes of CRA & CRB images. + switch ((setup & STDMSK_CLKSRC) >> STDBIT_CLKSRC) { + case CLKSRC_TIMER: // Timer Mode: + cra |= ((2 << CRABIT_CLKSRC_B) // ClkSrcB<1> selects system clock + | ((setup & STDMSK_CLKPOL) << (CRABIT_CLKSRC_B - STDBIT_CLKPOL))); // with direction (ClkSrcB<0>) obtained from ClkPol. + crb |= ((1 << CRBBIT_CLKPOL_B) // ClkPolB behaves as always-on clock enable. + | (MULT_X1 << CRBBIT_CLKMULT_B)); // ClkMultB must be 1x. + break; + + case CLKSRC_EXTENDER: // Extender Mode: + cra |= ((2 << CRABIT_CLKSRC_B) // ClkSrcB source is OverflowA (same as "timer") + | ((setup & STDMSK_CLKPOL) << (CRABIT_CLKSRC_B - STDBIT_CLKPOL))); // with direction obtained from ClkPol. + crb |= ((1 << CRBBIT_CLKPOL_B) // ClkPolB controls IndexB -- always set to active. + | (MULT_X0 << CRBBIT_CLKMULT_B)); // ClkMultB selects OverflowA as the clock source. + break; + + default: // Counter Mode: + cra |= (CLKSRC_COUNTER << CRABIT_CLKSRC_B); // Select ENC_C and ENC_D as clock/direction inputs. + crb |= (((setup & STDMSK_CLKPOL) >> (STDBIT_CLKPOL - CRBBIT_CLKPOL_B)) // ClkPol is passed through. + | (((setup & STDMSK_CLKMULT) == (MULT_X0 << STDBIT_CLKMULT)) ? // Force ClkMult to x1 if not legal, otherwise pass through. + (MULT_X1 << CRBBIT_CLKMULT_B) : + ((setup & STDMSK_CLKMULT) << (CRBBIT_CLKMULT_B - + STDBIT_CLKMULT)))); + } + + // Force positive index polarity if IndxSrc is software-driven only, + // otherwise pass it through. + if (~setup & STDMSK_INDXSRC) + crb |= ((setup & STDMSK_INDXPOL) >> (STDBIT_INDXPOL - + CRBBIT_INDXPOL_B)); + + // If IntSrc has been forced to Disabled, update the MISC2 interrupt + // enable mask to indicate the counter interrupt is disabled. + if (DisableIntSrc) + devpriv->CounterIntEnabs &= ~k->MyEventBits[3]; + + // While retaining CounterA and LatchSrc configurations, program the + // new counter operating mode. + DEBIreplace(dev, k->MyCRA, + (uint16_t) (~(CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B)), cra); + DEBIreplace(dev, k->MyCRB, CRBMSK_CLKENAB_A | CRBMSK_LATCHSRC, crb); } //////////////////////////////////////////////////////////////////////// // Return/set a counter's enable. enab: 0=always enabled, 1=enabled by index. -static void SetEnable_A(comedi_device *dev, enc_private *k, uint16_t enab ) -{ DEBUG("SetEnable_A: SetEnable_A enter 3541\n"); - DEBIreplace( dev,k->MyCRB, (uint16_t)( ~( CRBMSK_INTCTRL | CRBMSK_CLKENAB_A ) ), (uint16_t)( enab << CRBBIT_CLKENAB_A ) ); +static void SetEnable_A(comedi_device * dev, enc_private * k, uint16_t enab) +{ + DEBUG("SetEnable_A: SetEnable_A enter 3541\n"); + DEBIreplace(dev, k->MyCRB, + (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A)), + (uint16_t) (enab << CRBBIT_CLKENAB_A)); } -static void SetEnable_B(comedi_device *dev, enc_private *k, uint16_t enab ) +static void SetEnable_B(comedi_device * dev, enc_private * k, uint16_t enab) { - DEBIreplace( dev,k->MyCRB, (uint16_t)( ~( CRBMSK_INTCTRL | CRBMSK_CLKENAB_B ) ), (uint16_t)( enab << CRBBIT_CLKENAB_B ) ); + DEBIreplace(dev, k->MyCRB, + (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_B)), + (uint16_t) (enab << CRBBIT_CLKENAB_B)); } -static uint16_t GetEnable_A( comedi_device *dev,enc_private *k ) +static uint16_t GetEnable_A(comedi_device * dev, enc_private * k) { - return ( DEBIread( dev, k->MyCRB) >> CRBBIT_CLKENAB_A ) & 1; + return (DEBIread(dev, k->MyCRB) >> CRBBIT_CLKENAB_A) & 1; } -static uint16_t GetEnable_B(comedi_device *dev, enc_private *k ) +static uint16_t GetEnable_B(comedi_device * dev, enc_private * k) { - return ( DEBIread(dev, k->MyCRB) >> CRBBIT_CLKENAB_B ) & 1; + return (DEBIread(dev, k->MyCRB) >> CRBBIT_CLKENAB_B) & 1; } //////////////////////////////////////////////////////////////////////// @@ -2871,11 +3027,14 @@ static uint16_t GetEnable_B(comedi_device *dev, enc_private *k ) // access, 1: A index latches A, 2: B index latches B, 3: A overflow // latches B. -static void SetLatchSource(comedi_device *dev, enc_private *k, uint16_t value ) -{ DEBUG("SetLatchSource: SetLatchSource enter 3550 \n"); - DEBIreplace(dev, k->MyCRB, (uint16_t)( ~( CRBMSK_INTCTRL | CRBMSK_LATCHSRC ) ), (uint16_t)( value << CRBBIT_LATCHSRC ) ); +static void SetLatchSource(comedi_device * dev, enc_private * k, uint16_t value) +{ + DEBUG("SetLatchSource: SetLatchSource enter 3550 \n"); + DEBIreplace(dev, k->MyCRB, + (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_LATCHSRC)), + (uint16_t) (value << CRBBIT_LATCHSRC)); - DEBUG("SetLatchSource: SetLatchSource exit \n"); + DEBUG("SetLatchSource: SetLatchSource exit \n"); } /* static uint16_t GetLatchSource(comedi_device *dev, enc_private *k ) */ @@ -2888,73 +3047,84 @@ static void SetLatchSource(comedi_device *dev, enc_private *k, uint16_t value ) // register into the counter. 0=ThisCntr_Index, 1=ThisCntr_Overflow, // 2=OverflowA (B counters only), 3=disabled. -static void SetLoadTrig_A(comedi_device *dev, enc_private *k, uint16_t Trig ) +static void SetLoadTrig_A(comedi_device * dev, enc_private * k, uint16_t Trig) { - DEBIreplace(dev, k->MyCRA, (uint16_t)( ~CRAMSK_LOADSRC_A ), (uint16_t)( Trig << CRABIT_LOADSRC_A ) ); + DEBIreplace(dev, k->MyCRA, (uint16_t) (~CRAMSK_LOADSRC_A), + (uint16_t) (Trig << CRABIT_LOADSRC_A)); } -static void SetLoadTrig_B(comedi_device *dev, enc_private *k, uint16_t Trig ) +static void SetLoadTrig_B(comedi_device * dev, enc_private * k, uint16_t Trig) { - DEBIreplace(dev, k->MyCRB, (uint16_t)( ~( CRBMSK_LOADSRC_B | CRBMSK_INTCTRL ) ), (uint16_t)( Trig << CRBBIT_LOADSRC_B ) ); + DEBIreplace(dev, k->MyCRB, + (uint16_t) (~(CRBMSK_LOADSRC_B | CRBMSK_INTCTRL)), + (uint16_t) (Trig << CRBBIT_LOADSRC_B)); } -static uint16_t GetLoadTrig_A(comedi_device *dev, enc_private *k ) +static uint16_t GetLoadTrig_A(comedi_device * dev, enc_private * k) { - return ( DEBIread( dev,k->MyCRA) >> CRABIT_LOADSRC_A ) & 3; + return (DEBIread(dev, k->MyCRA) >> CRABIT_LOADSRC_A) & 3; } -static uint16_t GetLoadTrig_B(comedi_device *dev, enc_private *k ) +static uint16_t GetLoadTrig_B(comedi_device * dev, enc_private * k) { - return ( DEBIread(dev,k->MyCRB) >> CRBBIT_LOADSRC_B ) & 3; + return (DEBIread(dev, k->MyCRB) >> CRBBIT_LOADSRC_B) & 3; } - //////////////////// // Return/set counter interrupt source and clear any captured // index/overflow events. IntSource: 0=Disabled, 1=OverflowOnly, // 2=IndexOnly, 3=IndexAndOverflow. -static void SetIntSrc_A(comedi_device *dev, enc_private *k, uint16_t IntSource ) +static void SetIntSrc_A(comedi_device * dev, enc_private * k, + uint16_t IntSource) { - // Reset any pending counter overflow or index captures. - DEBIreplace( dev, k->MyCRB, (uint16_t)( ~CRBMSK_INTCTRL ), CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A ); - - // Program counter interrupt source. - DEBIreplace( dev, k->MyCRA, ~CRAMSK_INTSRC_A, (uint16_t)( IntSource << CRABIT_INTSRC_A ) ); - - // Update MISC2 interrupt enable mask. - devpriv->CounterIntEnabs = ( devpriv->CounterIntEnabs & ~k->MyEventBits[3] ) | k->MyEventBits[IntSource]; + // Reset any pending counter overflow or index captures. + DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL), + CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A); + + // Program counter interrupt source. + DEBIreplace(dev, k->MyCRA, ~CRAMSK_INTSRC_A, + (uint16_t) (IntSource << CRABIT_INTSRC_A)); + + // Update MISC2 interrupt enable mask. + devpriv->CounterIntEnabs = + (devpriv->CounterIntEnabs & ~k->MyEventBits[3]) | k-> + MyEventBits[IntSource]; } -static void SetIntSrc_B( comedi_device *dev,enc_private *k, uint16_t IntSource ) +static void SetIntSrc_B(comedi_device * dev, enc_private * k, + uint16_t IntSource) { - uint16_t crb; + uint16_t crb; - // Cache writeable CRB register image. - crb = DEBIread(dev, k->MyCRB ) & ~CRBMSK_INTCTRL; + // Cache writeable CRB register image. + crb = DEBIread(dev, k->MyCRB) & ~CRBMSK_INTCTRL; - // Reset any pending counter overflow or index captures. - DEBIwrite(dev, k->MyCRB, (uint16_t)( crb | CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B ) ); + // Reset any pending counter overflow or index captures. + DEBIwrite(dev, k->MyCRB, + (uint16_t) (crb | CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B)); - // Program counter interrupt source. - DEBIwrite(dev, k->MyCRB, (uint16_t)( ( crb & ~CRBMSK_INTSRC_B ) | ( IntSource << CRBBIT_INTSRC_B ) ) ); + // Program counter interrupt source. + DEBIwrite(dev, k->MyCRB, + (uint16_t) ((crb & ~CRBMSK_INTSRC_B) | (IntSource << + CRBBIT_INTSRC_B))); - // Update MISC2 interrupt enable mask. - devpriv->CounterIntEnabs = ( devpriv->CounterIntEnabs & ~k->MyEventBits[3] ) | k->MyEventBits[IntSource]; + // Update MISC2 interrupt enable mask. + devpriv->CounterIntEnabs = + (devpriv->CounterIntEnabs & ~k->MyEventBits[3]) | k-> + MyEventBits[IntSource]; } - -static uint16_t GetIntSrc_A( comedi_device *dev,enc_private *k ) +static uint16_t GetIntSrc_A(comedi_device * dev, enc_private * k) { - return ( DEBIread(dev, k->MyCRA) >> CRABIT_INTSRC_A ) & 3; + return (DEBIread(dev, k->MyCRA) >> CRABIT_INTSRC_A) & 3; } -static uint16_t GetIntSrc_B( comedi_device *dev,enc_private *k ) +static uint16_t GetIntSrc_B(comedi_device * dev, enc_private * k) { - return ( DEBIread( dev, k->MyCRB) >> CRBBIT_INTSRC_B ) & 3; + return (DEBIread(dev, k->MyCRB) >> CRBBIT_INTSRC_B) & 3; } - ///////////////////////////////////////////////////////////////////////// // Return/set the clock multiplier. @@ -3024,63 +3194,60 @@ static uint16_t GetIntSrc_B( comedi_device *dev,enc_private *k ) /////////////////////////////////////////////////////////////////// // Generate an index pulse. -static void PulseIndex_A( comedi_device *dev,enc_private *k ) +static void PulseIndex_A(comedi_device * dev, enc_private * k) { - register uint16_t cra; - + register uint16_t cra; - DEBUG("PulseIndex_A: pulse index enter\n"); + DEBUG("PulseIndex_A: pulse index enter\n"); - cra = DEBIread(dev, k->MyCRA ); // Pulse index. - DEBIwrite( dev, k->MyCRA, (uint16_t)( cra ^ CRAMSK_INDXPOL_A ) ); - DEBUG("PulseIndex_A: pulse index step1\n"); - DEBIwrite( dev, k->MyCRA, cra ); + cra = DEBIread(dev, k->MyCRA); // Pulse index. + DEBIwrite(dev, k->MyCRA, (uint16_t) (cra ^ CRAMSK_INDXPOL_A)); + DEBUG("PulseIndex_A: pulse index step1\n"); + DEBIwrite(dev, k->MyCRA, cra); } -static void PulseIndex_B( comedi_device *dev,enc_private *k ) +static void PulseIndex_B(comedi_device * dev, enc_private * k) { - register uint16_t crb; + register uint16_t crb; - crb = DEBIread(dev, k->MyCRB ) & ~CRBMSK_INTCTRL; // Pulse index. - DEBIwrite(dev, k->MyCRB, (uint16_t)( crb ^ CRBMSK_INDXPOL_B ) ); - DEBIwrite(dev, k->MyCRB, crb); + crb = DEBIread(dev, k->MyCRB) & ~CRBMSK_INTCTRL; // Pulse index. + DEBIwrite(dev, k->MyCRB, (uint16_t) (crb ^ CRBMSK_INDXPOL_B)); + DEBIwrite(dev, k->MyCRB, crb); } ///////////////////////////////////////////////////////// // Write value into counter preload register. -static void Preload(comedi_device *dev, enc_private *k, uint32_t value ) +static void Preload(comedi_device * dev, enc_private * k, uint32_t value) { - DEBUG("Preload: preload enter\n"); - DEBIwrite(dev, (uint16_t)( k->MyLatchLsw ), (uint16_t) value ); // Write value to preload register. - DEBUG("Preload: preload step 1\n"); - DEBIwrite(dev, (uint16_t)( k->MyLatchLsw + 2 ), (uint16_t)( value >> 16 ) ); + DEBUG("Preload: preload enter\n"); + DEBIwrite(dev, (uint16_t) (k->MyLatchLsw), (uint16_t) value); // Write value to preload register. + DEBUG("Preload: preload step 1\n"); + DEBIwrite(dev, (uint16_t) (k->MyLatchLsw + 2), + (uint16_t) (value >> 16)); } -static void CountersInit(comedi_device *dev) +static void CountersInit(comedi_device * dev) { - int chan; - enc_private *k; - uint16_t Setup = ( LOADSRC_INDX << BF_LOADSRC ) | // Preload upon - // index. - ( INDXSRC_SOFT << BF_INDXSRC ) | // Disable hardware index. - ( CLKSRC_COUNTER << BF_CLKSRC ) | // Operating mode is counter. - ( CLKPOL_POS << BF_CLKPOL ) | // Active high clock. - ( CNTDIR_UP << BF_CLKPOL ) | // Count direction is up. - ( CLKMULT_1X << BF_CLKMULT ) | // Clock multiplier is 1x. - ( CLKENAB_INDEX << BF_CLKENAB ); // Enabled by index - - // Disable all counter interrupts and clear any captured counter events. - for ( chan = 0; chan < S626_ENCODER_CHANNELS; chan++ ) - { - k = &encpriv[chan]; - k->SetMode(dev,k,Setup,TRUE); - k->SetIntSrc( dev,k, 0 ); - k->ResetCapFlags(dev,k); - k->SetEnable(dev,k,CLKENAB_ALWAYS); - } - DEBUG("CountersInit: counters initialized \n"); + int chan; + enc_private *k; + uint16_t Setup = (LOADSRC_INDX << BF_LOADSRC) | // Preload upon + // index. + (INDXSRC_SOFT << BF_INDXSRC) | // Disable hardware index. + (CLKSRC_COUNTER << BF_CLKSRC) | // Operating mode is counter. + (CLKPOL_POS << BF_CLKPOL) | // Active high clock. + (CNTDIR_UP << BF_CLKPOL) | // Count direction is up. + (CLKMULT_1X << BF_CLKMULT) | // Clock multiplier is 1x. + (CLKENAB_INDEX << BF_CLKENAB); // Enabled by index + + // Disable all counter interrupts and clear any captured counter events. + for (chan = 0; chan < S626_ENCODER_CHANNELS; chan++) { + k = &encpriv[chan]; + k->SetMode(dev, k, Setup, TRUE); + k->SetIntSrc(dev, k, 0); + k->ResetCapFlags(dev, k); + k->SetEnable(dev, k, CLKENAB_ALWAYS); + } + DEBUG("CountersInit: counters initialized \n"); } - - diff --git a/comedi/drivers/s626.h b/comedi/drivers/s626.h index fee09e75..23b25b8f 100644 --- a/comedi/drivers/s626.h +++ b/comedi/drivers/s626.h @@ -64,7 +64,7 @@ #ifdef _DEBUG_ #define DEBUG(...); rt_printk(__VA_ARGS__); -#else +#else #define DEBUG(...) #endif @@ -93,7 +93,7 @@ #define S626_SIZE 0x0200 #define SIZEOF_ADDRESS_SPACE 0x0200 -#define DMABUF_SIZE 4096 // 4k pages +#define DMABUF_SIZE 4096 // 4k pages #define S626_ADC_CHANNELS 16 #define S626_DAC_CHANNELS 4 @@ -106,7 +106,6 @@ #define NUM_TRIMDACS 12 // Number of valid TrimDAC channels. - // PCI bus interface types. #define INTEL 1 // Intel bus type. #define MOTOROLA 2 // Motorola bus type. @@ -114,16 +113,15 @@ ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// -#define PLATFORM INTEL // *** SELECT PLATFORM TYPE *** +#define PLATFORM INTEL // *** SELECT PLATFORM TYPE *** ////////////////////////////////////////////////////////// -#define RANGE_5V 0x10 // +/-5V range -#define RANGE_10V 0x00 // +/-10V range +#define RANGE_5V 0x10 // +/-5V range +#define RANGE_10V 0x00 // +/-10V range - -#define EOPL 0x80 // End of ADC poll list marker. -#define GSEL_BIPOLAR5V 0x00F0 // LP_GSEL setting for 5V bipolar range. -#define GSEL_BIPOLAR10V 0x00A0 // LP_GSEL setting for 10V bipolar range. +#define EOPL 0x80 // End of ADC poll list marker. +#define GSEL_BIPOLAR5V 0x00F0 // LP_GSEL setting for 5V bipolar range. +#define GSEL_BIPOLAR10V 0x00A0 // LP_GSEL setting for 10V bipolar range. // Error codes that must be visible to this base class. #define ERR_ILLEGAL_PARM 0x00010000 // Illegal function parameter value was specified. @@ -131,10 +129,9 @@ #define ERR_COUNTERSETUP 0x00200000 // Illegal setup specified for counter channel. #define ERR_DEBI_TIMEOUT 0x00400000 // DEBI transfer timed out. - // Organization (physical order) and size (in DWORDs) of logical DMA buffers contained by ANA_DMABUF. -#define ADC_DMABUF_DWORDS 40 // ADC DMA buffer must hold 16 samples, plus pre/post garbage samples. -#define DAC_WDMABUF_DWORDS 1 // DAC output DMA buffer holds a single sample. +#define ADC_DMABUF_DWORDS 40 // ADC DMA buffer must hold 16 samples, plus pre/post garbage samples. +#define DAC_WDMABUF_DWORDS 1 // DAC output DMA buffer holds a single sample. // All remaining space in 4KB DMA buffer is available for the RPS1 program. @@ -147,20 +144,19 @@ #define ISR_AFOU 0x00000800 // Audio fifo // under/overflow // detected. -#define IRQ_COINT1A 0x0400 // conter 1A overflow +#define IRQ_COINT1A 0x0400 // conter 1A overflow // interrupt mask -#define IRQ_COINT1B 0x0800 // conter 1B overflow +#define IRQ_COINT1B 0x0800 // conter 1B overflow // interrupt mask -#define IRQ_COINT2A 0x1000 // conter 2A overflow +#define IRQ_COINT2A 0x1000 // conter 2A overflow // interrupt mask -#define IRQ_COINT2B 0x2000 // conter 2B overflow +#define IRQ_COINT2B 0x2000 // conter 2B overflow // interrupt mask -#define IRQ_COINT3A 0x4000 // conter 3A overflow +#define IRQ_COINT3A 0x4000 // conter 3A overflow // interrupt mask -#define IRQ_COINT3B 0x8000 // conter 3B overflow +#define IRQ_COINT3B 0x8000 // conter 3B overflow // interrupt mask - // RPS command codes. #define RPS_CLRSIGNAL 0x00000000 // CLEAR SIGNAL #define RPS_SETSIGNAL 0x10000000 // SET SIGNAL @@ -171,7 +167,7 @@ #define RPS_LDREG 0x90000100 // LDREG (1 uint32_t only) #define RPS_STREG 0xA0000100 // STREG (1 uint32_t only) #define RPS_STOP 0x50000000 // STOP -#define RPS_IRQ 0x60000000 // IRQ +#define RPS_IRQ 0x60000000 // IRQ #define RPS_LOGICAL_OR 0x08000000 // Logical OR conditionals. #define RPS_INVERT 0x04000000 // Test for negated semaphores. @@ -199,8 +195,8 @@ #define GPIO1_HI 0x00001000 // GPIO1 set to HIGH. // Primary Status Register (PSR) constants. -#define PSR_DEBI_E 0x00040000 // DEBI event flag. -#define PSR_DEBI_S 0x00080000 // DEBI status flag. +#define PSR_DEBI_E 0x00040000 // DEBI event flag. +#define PSR_DEBI_S 0x00080000 // DEBI status flag. #define PSR_A2_IN 0x00008000 // Audio output DMA2 protection address reached. #define PSR_AFOU 0x00000800 // Audio FIFO under/overflow detected. #define PSR_GPIO2 0x00000020 // GPIO2 input pin: 0=AdcBusy, 1=AdcIdle. @@ -213,14 +209,14 @@ #define MC1_SOFT_RESET 0x80000000 // Invoke 7146 soft reset. #define MC1_SHUTDOWN 0x3FFF0000 // Shut down all MC1-controlled enables. -#define MC1_ERPS1 0x2000 // enab/disable RPS task 1. -#define MC1_ERPS0 0x1000 // enab/disable RPS task 0. -#define MC1_DEBI 0x0800 // enab/disable DEBI pins. -#define MC1_AUDIO 0x0200 // enab/disable audio port pins. -#define MC1_I2C 0x0100 // enab/disable I2C interface. -#define MC1_A2OUT 0x0008 // enab/disable transfer on A2 out. -#define MC1_A2IN 0x0004 // enab/disable transfer on A2 in. -#define MC1_A1IN 0x0001 // enab/disable transfer on A1 in. +#define MC1_ERPS1 0x2000 // enab/disable RPS task 1. +#define MC1_ERPS0 0x1000 // enab/disable RPS task 0. +#define MC1_DEBI 0x0800 // enab/disable DEBI pins. +#define MC1_AUDIO 0x0200 // enab/disable audio port pins. +#define MC1_I2C 0x0100 // enab/disable I2C interface. +#define MC1_A2OUT 0x0008 // enab/disable transfer on A2 out. +#define MC1_A2IN 0x0004 // enab/disable transfer on A2 in. +#define MC1_A1IN 0x0001 // enab/disable transfer on A1 in. // Master Control Register 2 (MC2) constants. #define MC2_UPLD_DEBIq 0x00020002 // Upload DEBI registers. @@ -240,12 +236,11 @@ #define MC2_DELAYTRIG_6USq MC2_RPSSIG2_ON #define MC2_DELAYBUSY_6USq MC2_RPSSIG2_MASK - -#define MC2_UPLD_DEBI 0x0002 // Upload DEBI. -#define MC2_UPLD_IIC 0x0001 // Upload I2C. -#define MC2_RPSSIG2 0x2000 // RPS signal 2 (not used). -#define MC2_RPSSIG1 0x1000 // RPS signal 1 (DAC RPS busy). -#define MC2_RPSSIG0 0x0800 // RPS signal 0 (ADC RPS busy). +#define MC2_UPLD_DEBI 0x0002 // Upload DEBI. +#define MC2_UPLD_IIC 0x0001 // Upload I2C. +#define MC2_RPSSIG2 0x2000 // RPS signal 2 (not used). +#define MC2_RPSSIG1 0x1000 // RPS signal 1 (DAC RPS busy). +#define MC2_RPSSIG0 0x0800 // RPS signal 0 (ADC RPS busy). #define MC2_ADC_RPS MC2_RPSSIG0 // ADC RPS busy. #define MC2_DAC_RPS MC2_RPSSIG1 // DAC RPS busy. @@ -255,160 +250,159 @@ #define MC2_UPLD_IICQ 0x00010001 // Upload I2C registers. //////////////////////////////////////// - // PCI BUS (SAA7146) REGISTER ADDRESS OFFSETS //////////////////////// -#define P_PCI_BT_A 0x004C // Audio DMA +#define P_PCI_BT_A 0x004C // Audio DMA // burst/threshold // control. -#define P_DEBICFG 0x007C // DEBI configuration. -#define P_DEBICMD 0x0080 // DEBI command. -#define P_DEBIPAGE 0x0084 // DEBI page. -#define P_DEBIAD 0x0088 // DEBI target address. -#define P_I2CCTRL 0x008C // I2C control. -#define P_I2CSTAT 0x0090 // I2C status. -#define P_BASEA2_IN 0x00AC // Audio input 2 base +#define P_DEBICFG 0x007C // DEBI configuration. +#define P_DEBICMD 0x0080 // DEBI command. +#define P_DEBIPAGE 0x0084 // DEBI page. +#define P_DEBIAD 0x0088 // DEBI target address. +#define P_I2CCTRL 0x008C // I2C control. +#define P_I2CSTAT 0x0090 // I2C status. +#define P_BASEA2_IN 0x00AC // Audio input 2 base // physical DMAbuf // address. -#define P_PROTA2_IN 0x00B0 // Audio input 2 +#define P_PROTA2_IN 0x00B0 // Audio input 2 // physical DMAbuf // protection address. -#define P_PAGEA2_IN 0x00B4 // Audio input 2 +#define P_PAGEA2_IN 0x00B4 // Audio input 2 // paging attributes. -#define P_BASEA2_OUT 0x00B8 // Audio output 2 base +#define P_BASEA2_OUT 0x00B8 // Audio output 2 base // physical DMAbuf // address. -#define P_PROTA2_OUT 0x00BC // Audio output 2 +#define P_PROTA2_OUT 0x00BC // Audio output 2 // physical DMAbuf // protection address. -#define P_PAGEA2_OUT 0x00C0 // Audio output 2 +#define P_PAGEA2_OUT 0x00C0 // Audio output 2 // paging attributes. -#define P_RPSPAGE0 0x00C4 // RPS0 page. -#define P_RPSPAGE1 0x00C8 // RPS1 page. -#define P_RPS0_TOUT 0x00D4 // RPS0 time-out. -#define P_RPS1_TOUT 0x00D8 // RPS1 time-out. -#define P_IER 0x00DC // Interrupt enable. -#define P_GPIO 0x00E0 // General-purpose I/O. -#define P_EC1SSR 0x00E4 // Event counter set 1 +#define P_RPSPAGE0 0x00C4 // RPS0 page. +#define P_RPSPAGE1 0x00C8 // RPS1 page. +#define P_RPS0_TOUT 0x00D4 // RPS0 time-out. +#define P_RPS1_TOUT 0x00D8 // RPS1 time-out. +#define P_IER 0x00DC // Interrupt enable. +#define P_GPIO 0x00E0 // General-purpose I/O. +#define P_EC1SSR 0x00E4 // Event counter set 1 // source select. -#define P_ECT1R 0x00EC // Event counter +#define P_ECT1R 0x00EC // Event counter // threshold set 1. -#define P_ACON1 0x00F4 // Audio control 1. -#define P_ACON2 0x00F8 // Audio control 2. -#define P_MC1 0x00FC // Master control 1. -#define P_MC2 0x0100 // Master control 2. -#define P_RPSADDR0 0x0104 // RPS0 instruction pointer. -#define P_RPSADDR1 0x0108 // RPS1 instruction pointer. -#define P_ISR 0x010C // Interrupt status. -#define P_PSR 0x0110 // Primary status. -#define P_SSR 0x0114 // Secondary status. -#define P_EC1R 0x0118 // Event counter set 1. -#define P_ADP4 0x0138 // Logical audio DMA +#define P_ACON1 0x00F4 // Audio control 1. +#define P_ACON2 0x00F8 // Audio control 2. +#define P_MC1 0x00FC // Master control 1. +#define P_MC2 0x0100 // Master control 2. +#define P_RPSADDR0 0x0104 // RPS0 instruction pointer. +#define P_RPSADDR1 0x0108 // RPS1 instruction pointer. +#define P_ISR 0x010C // Interrupt status. +#define P_PSR 0x0110 // Primary status. +#define P_SSR 0x0114 // Secondary status. +#define P_EC1R 0x0118 // Event counter set 1. +#define P_ADP4 0x0138 // Logical audio DMA // pointer of audio // input FIFO A2_IN. -#define P_FB_BUFFER1 0x0144 // Audio feedback buffer 1. -#define P_FB_BUFFER2 0x0148 // Audio feedback buffer 2. -#define P_TSL1 0x0180 // Audio time slot list 1. -#define P_TSL2 0x01C0 // Audio time slot list 2. +#define P_FB_BUFFER1 0x0144 // Audio feedback buffer 1. +#define P_FB_BUFFER2 0x0148 // Audio feedback buffer 2. +#define P_TSL1 0x0180 // Audio time slot list 1. +#define P_TSL2 0x01C0 // Audio time slot list 2. // LOCAL BUS (GATE ARRAY) REGISTER ADDRESS OFFSETS ///////////////// // Analog I/O registers: -#define LP_DACPOL 0x0082 // Write DAC polarity. -#define LP_GSEL 0x0084 // Write ADC gain. -#define LP_ISEL 0x0086 // Write ADC channel select. +#define LP_DACPOL 0x0082 // Write DAC polarity. +#define LP_GSEL 0x0084 // Write ADC gain. +#define LP_ISEL 0x0086 // Write ADC channel select. // Digital I/O (write only): -#define LP_WRINTSELA 0x0042 // Write A interrupt enable. -#define LP_WREDGSELA 0x0044 // Write A edge selection. -#define LP_WRCAPSELA 0x0046 // Write A capture enable. -#define LP_WRDOUTA 0x0048 // Write A digital output. -#define LP_WRINTSELB 0x0052 // Write B interrupt enable. -#define LP_WREDGSELB 0x0054 // Write B edge selection. -#define LP_WRCAPSELB 0x0056 // Write B capture enable. -#define LP_WRDOUTB 0x0058 // Write B digital output. -#define LP_WRINTSELC 0x0062 // Write C interrupt enable. -#define LP_WREDGSELC 0x0064 // Write C edge selection. -#define LP_WRCAPSELC 0x0066 // Write C capture enable. -#define LP_WRDOUTC 0x0068 // Write C digital output. - +#define LP_WRINTSELA 0x0042 // Write A interrupt enable. +#define LP_WREDGSELA 0x0044 // Write A edge selection. +#define LP_WRCAPSELA 0x0046 // Write A capture enable. +#define LP_WRDOUTA 0x0048 // Write A digital output. +#define LP_WRINTSELB 0x0052 // Write B interrupt enable. +#define LP_WREDGSELB 0x0054 // Write B edge selection. +#define LP_WRCAPSELB 0x0056 // Write B capture enable. +#define LP_WRDOUTB 0x0058 // Write B digital output. +#define LP_WRINTSELC 0x0062 // Write C interrupt enable. +#define LP_WREDGSELC 0x0064 // Write C edge selection. +#define LP_WRCAPSELC 0x0066 // Write C capture enable. +#define LP_WRDOUTC 0x0068 // Write C digital output. + // Digital I/O (read only): -#define LP_RDDINA 0x0040 // Read digital input. -#define LP_RDCAPFLGA 0x0048 // Read edges captured. -#define LP_RDINTSELA 0x004A // Read interrupt +#define LP_RDDINA 0x0040 // Read digital input. +#define LP_RDCAPFLGA 0x0048 // Read edges captured. +#define LP_RDINTSELA 0x004A // Read interrupt // enable register. -#define LP_RDEDGSELA 0x004C // Read edge +#define LP_RDEDGSELA 0x004C // Read edge // selection // register. -#define LP_RDCAPSELA 0x004E // Read capture +#define LP_RDCAPSELA 0x004E // Read capture // enable register. -#define LP_RDDINB 0x0050 // Read digital input. -#define LP_RDCAPFLGB 0x0058 // Read edges captured. -#define LP_RDINTSELB 0x005A // Read interrupt +#define LP_RDDINB 0x0050 // Read digital input. +#define LP_RDCAPFLGB 0x0058 // Read edges captured. +#define LP_RDINTSELB 0x005A // Read interrupt // enable register. -#define LP_RDEDGSELB 0x005C // Read edge +#define LP_RDEDGSELB 0x005C // Read edge // selection // register. -#define LP_RDCAPSELB 0x005E // Read capture +#define LP_RDCAPSELB 0x005E // Read capture // enable register. -#define LP_RDDINC 0x0060 // Read digital input. -#define LP_RDCAPFLGC 0x0068 // Read edges captured. -#define LP_RDINTSELC 0x006A // Read interrupt +#define LP_RDDINC 0x0060 // Read digital input. +#define LP_RDCAPFLGC 0x0068 // Read edges captured. +#define LP_RDINTSELC 0x006A // Read interrupt // enable register. -#define LP_RDEDGSELC 0x006C // Read edge +#define LP_RDEDGSELC 0x006C // Read edge // selection // register. -#define LP_RDCAPSELC 0x006E // Read capture +#define LP_RDCAPSELC 0x006E // Read capture // enable register. // Counter Registers (read/write): -#define LP_CR0A 0x0000 // 0A setup register. -#define LP_CR0B 0x0002 // 0B setup register. -#define LP_CR1A 0x0004 // 1A setup register. -#define LP_CR1B 0x0006 // 1B setup register. -#define LP_CR2A 0x0008 // 2A setup register. -#define LP_CR2B 0x000A // 2B setup register. +#define LP_CR0A 0x0000 // 0A setup register. +#define LP_CR0B 0x0002 // 0B setup register. +#define LP_CR1A 0x0004 // 1A setup register. +#define LP_CR1B 0x0006 // 1B setup register. +#define LP_CR2A 0x0008 // 2A setup register. +#define LP_CR2B 0x000A // 2B setup register. // Counter PreLoad (write) and Latch (read) Registers: -#define LP_CNTR0ALSW 0x000C // 0A lsw. -#define LP_CNTR0AMSW 0x000E // 0A msw. -#define LP_CNTR0BLSW 0x0010 // 0B lsw. -#define LP_CNTR0BMSW 0x0012 // 0B msw. -#define LP_CNTR1ALSW 0x0014 // 1A lsw. -#define LP_CNTR1AMSW 0x0016 // 1A msw. -#define LP_CNTR1BLSW 0x0018 // 1B lsw. -#define LP_CNTR1BMSW 0x001A // 1B msw. -#define LP_CNTR2ALSW 0x001C // 2A lsw. -#define LP_CNTR2AMSW 0x001E // 2A msw. -#define LP_CNTR2BLSW 0x0020 // 2B lsw. -#define LP_CNTR2BMSW 0x0022 // 2B msw. +#define LP_CNTR0ALSW 0x000C // 0A lsw. +#define LP_CNTR0AMSW 0x000E // 0A msw. +#define LP_CNTR0BLSW 0x0010 // 0B lsw. +#define LP_CNTR0BMSW 0x0012 // 0B msw. +#define LP_CNTR1ALSW 0x0014 // 1A lsw. +#define LP_CNTR1AMSW 0x0016 // 1A msw. +#define LP_CNTR1BLSW 0x0018 // 1B lsw. +#define LP_CNTR1BMSW 0x001A // 1B msw. +#define LP_CNTR2ALSW 0x001C // 2A lsw. +#define LP_CNTR2AMSW 0x001E // 2A msw. +#define LP_CNTR2BLSW 0x0020 // 2B lsw. +#define LP_CNTR2BMSW 0x0022 // 2B msw. // Miscellaneous Registers (read/write): -#define LP_MISC1 0x0088 // Read/write Misc1. -#define LP_WRMISC2 0x0090 // Write Misc2. -#define LP_RDMISC2 0x0082 // Read Misc2. +#define LP_MISC1 0x0088 // Read/write Misc1. +#define LP_WRMISC2 0x0090 // Write Misc2. +#define LP_RDMISC2 0x0082 // Read Misc2. // Bit masks for MISC1 register that are the same for reads and writes. -#define MISC1_WENABLE 0x8000 // enab writes to +#define MISC1_WENABLE 0x8000 // enab writes to // MISC2 (except Clear // Watchdog bit). -#define MISC1_WDISABLE 0x0000 // Disable writes to MISC2. -#define MISC1_EDCAP 0x1000 // enab edge capture +#define MISC1_WDISABLE 0x0000 // Disable writes to MISC2. +#define MISC1_EDCAP 0x1000 // enab edge capture // on DIO chans // specified by // LP_WRCAPSELx. -#define MISC1_NOEDCAP 0x0000 // Disable edge +#define MISC1_NOEDCAP 0x0000 // Disable edge // capture on // specified DIO // chans. // Bit masks for MISC1 register reads. -#define RDMISC1_WDTIMEOUT 0x4000 // Watchdog timer timed out. +#define RDMISC1_WDTIMEOUT 0x4000 // Watchdog timer timed out. // Bit masks for MISC2 register writes. -#define WRMISC2_WDCLEAR 0x8000 // Reset watchdog +#define WRMISC2_WDCLEAR 0x8000 // Reset watchdog // timer to zero. -#define WRMISC2_CHARGE_ENABLE 0x4000 // enab battery +#define WRMISC2_CHARGE_ENABLE 0x4000 // enab battery // trickle charging. // Bit masks for MISC2 register that are the same for reads and writes. -#define MISC2_BATT_ENABLE 0x0008 // Backup battery enable. -#define MISC2_WDENABLE 0x0004 // Watchdog timer enable. -#define MISC2_WDPERIOD_MASK 0x0003 // Watchdog interval +#define MISC2_BATT_ENABLE 0x0008 // Backup battery enable. +#define MISC2_WDENABLE 0x0004 // Watchdog timer enable. +#define MISC2_WDPERIOD_MASK 0x0003 // Watchdog interval // select mask. // Bit masks for ACON1 register. @@ -420,7 +414,7 @@ // input, WS1-WS4 = // CS* outputs. -#if PLATFORM == INTEL // Base ACON1 config: +#if PLATFORM == INTEL // Base ACON1 config: // always run A1 based // on TSL1. #define ACON1_BASE ( WS_MODES | A1_RUN ) @@ -495,33 +489,32 @@ // tri-state. #define EOS 0x00000001 // End of superframe. - ////////////////////// // I2C configuration constants. -#define I2C_CLKSEL 0x0400 // I2C bit rate = +#define I2C_CLKSEL 0x0400 // I2C bit rate = // PCIclk/480 = 68.75 // KHz. -#define I2C_BITRATE 68.75 // I2C bus data bit +#define I2C_BITRATE 68.75 // I2C bus data bit // rate (determined by // I2C_CLKSEL) in KHz. -#define I2C_WRTIME 15.0 // Worst case time,in +#define I2C_WRTIME 15.0 // Worst case time,in // msec, for EEPROM // internal write op. // I2C manifest constants. // Max retries to wait for EEPROM write. -#define I2C_RETRIES ( I2C_WRTIME * I2C_BITRATE / 9.0 ) -#define I2C_ERR 0x0002 // I2C control/status +#define I2C_RETRIES ( I2C_WRTIME * I2C_BITRATE / 9.0 ) +#define I2C_ERR 0x0002 // I2C control/status // flag ERROR. -#define I2C_BUSY 0x0001 // I2C control/status +#define I2C_BUSY 0x0001 // I2C control/status // flag BUSY. -#define I2C_ABORT 0x0080 // I2C status flag ABORT. -#define I2C_ATTRSTART 0x3 // I2C attribute START. -#define I2C_ATTRCONT 0x2 // I2C attribute CONT. -#define I2C_ATTRSTOP 0x1 // I2C attribute STOP. -#define I2C_ATTRNOP 0x0 // I2C attribute NOP. +#define I2C_ABORT 0x0080 // I2C status flag ABORT. +#define I2C_ATTRSTART 0x3 // I2C attribute START. +#define I2C_ATTRCONT 0x2 // I2C attribute CONT. +#define I2C_ATTRSTOP 0x1 // I2C attribute STOP. +#define I2C_ATTRNOP 0x0 // I2C attribute NOP. // I2C read command | EEPROM address. #define I2CR ( devpriv->I2CAdrs | 1 ) @@ -534,22 +527,21 @@ #define I2C_B1(ATTR,VAL) ( ( (ATTR) << 4 ) | ( (VAL) << 16 ) ) #define I2C_B0(ATTR,VAL) ( ( (ATTR) << 2 ) | ( (VAL) << 8 ) ) - //////////////////////////////////////////////////////// //oldest -#define P_DEBICFGq 0x007C // DEBI configuration. -#define P_DEBICMDq 0x0080 // DEBI command. -#define P_DEBIPAGEq 0x0084 // DEBI page. -#define P_DEBIADq 0x0088 // DEBI target address. - -#define DEBI_CFG_TOQ 0x03C00000 // timeout (15 PCI cycles) -#define DEBI_CFG_FASTQ 0x10000000 // fast mode enable -#define DEBI_CFG_16Q 0x00080000 // 16-bit access enable -#define DEBI_CFG_INCQ 0x00040000 // enable address increment -#define DEBI_CFG_TIMEROFFQ 0x00010000 // disable timer -#define DEBI_CMD_RDQ 0x00050000 // read immediate 2 bytes -#define DEBI_CMD_WRQ 0x00040000 // write immediate 2 bytes -#define DEBI_PAGE_DISABLEQ 0x00000000 // paging disable +#define P_DEBICFGq 0x007C // DEBI configuration. +#define P_DEBICMDq 0x0080 // DEBI command. +#define P_DEBIPAGEq 0x0084 // DEBI page. +#define P_DEBIADq 0x0088 // DEBI target address. + +#define DEBI_CFG_TOQ 0x03C00000 // timeout (15 PCI cycles) +#define DEBI_CFG_FASTQ 0x10000000 // fast mode enable +#define DEBI_CFG_16Q 0x00080000 // 16-bit access enable +#define DEBI_CFG_INCQ 0x00040000 // enable address increment +#define DEBI_CFG_TIMEROFFQ 0x00010000 // disable timer +#define DEBI_CMD_RDQ 0x00050000 // read immediate 2 bytes +#define DEBI_CMD_WRQ 0x00040000 // write immediate 2 bytes +#define DEBI_PAGE_DISABLEQ 0x00000000 // paging disable /////////////////////////////////////////// // DEBI command constants. @@ -597,12 +589,12 @@ #if PLATFORM == INTEL -#define DEBI_TOUT 7 // Wait 7 PCI clocks +#define DEBI_TOUT 7 // Wait 7 PCI clocks // (212 ns) before // polling RDY. // Intel byte lane steering (pass through all byte lanes). -#define DEBI_SWAP DEBI_CFG_SWAP_NONE +#define DEBI_SWAP DEBI_CFG_SWAP_NONE #elif PLATFORM == MOTOROLA @@ -626,7 +618,6 @@ // to A Overflow. #define LOADSRC_NONE 3 // Never preload core. - // IntSrc values: #define INTSRC_NONE 0 // Interrupts disabled. #define INTSRC_OVER 1 // Interrupt on Overflow. @@ -804,11 +795,8 @@ /* unsigned int enc; */ /* }CallCounter; */ -typedef struct bufferDMA -{ - dma_addr_t PhysicalBase; - void *LogicalBase; - uint32_t DMAHandle; +typedef struct bufferDMA { + dma_addr_t PhysicalBase; + void *LogicalBase; + uint32_t DMAHandle; } DMABUF; - - diff --git a/comedi/drivers/serial2002.c b/comedi/drivers/serial2002.c index 97f5eca6..b6a0d89a 100644 --- a/comedi/drivers/serial2002.c +++ b/comedi/drivers/serial2002.c @@ -51,32 +51,32 @@ typedef struct serial2002_board_struct { } serial2002_board; static const serial2002_board serial2002_boards[] = { - { - name: "serial2002" - } + { + name: "serial2002"} }; + /* * Useful for shorthand access to the particular board structure */ #define thisboard ((const serial2002_board *)dev->board_ptr) typedef struct { - // HACK... - int length; - comedi_krange range; + // HACK... + int length; + comedi_krange range; } serial2002_range_table_t; typedef struct { - int port; // /dev/ttyS - int speed; // baudrate - struct file *tty; - lsampl_t ao_readback[32]; - unsigned char digital_in_mapping[32]; - unsigned char digital_out_mapping[32]; - unsigned char analog_in_mapping[32]; - unsigned char analog_out_mapping[32]; - unsigned char encoder_in_mapping[32]; - serial2002_range_table_t in_range[32], out_range[32]; + int port; // /dev/ttyS + int speed; // baudrate + struct file *tty; + lsampl_t ao_readback[32]; + unsigned char digital_in_mapping[32]; + unsigned char digital_out_mapping[32]; + unsigned char analog_in_mapping[32]; + unsigned char analog_out_mapping[32]; + unsigned char encoder_in_mapping[32]; + serial2002_range_table_t in_range[32], out_range[32]; } serial2002_private; /* @@ -85,592 +85,762 @@ typedef struct { */ #define devpriv ((serial2002_private *)dev->private) -static int serial2002_attach(comedi_device *dev,comedi_devconfig *it); -static int serial2002_detach(comedi_device *dev); -comedi_driver driver_serial2002={ - driver_name: "serial2002", - module: THIS_MODULE, - attach: serial2002_attach, - detach: serial2002_detach, - board_name: &serial2002_boards[0].name, - offset: sizeof(serial2002_board), - num_names: sizeof(serial2002_boards) / sizeof(serial2002_board), +static int serial2002_attach(comedi_device * dev, comedi_devconfig * it); +static int serial2002_detach(comedi_device * dev); +comedi_driver driver_serial2002 = { + driver_name:"serial2002", + module:THIS_MODULE, + attach:serial2002_attach, + detach:serial2002_detach, + board_name:&serial2002_boards[0].name, + offset:sizeof(serial2002_board), + num_names:sizeof(serial2002_boards) / sizeof(serial2002_board), }; -static int serial2002_di_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int serial2002_do_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int serial2002_ai_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int serial2002_ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); -static int serial2002_ao_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data); +static int serial2002_di_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int serial2002_do_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int serial2002_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int serial2002_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int serial2002_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); struct serial_data { - enum { is_invalid, is_digital, is_channel } kind; - int index; - unsigned long value; + enum { is_invalid, is_digital, is_channel } kind; + int index; + unsigned long value; }; -static int tty_write(struct file *f, unsigned char *buf, int count) { - int result; - mm_segment_t oldfs; +static int tty_write(struct file *f, unsigned char *buf, int count) +{ + int result; + mm_segment_t oldfs; - oldfs = get_fs(); - set_fs(KERNEL_DS); - f->f_pos = 0; - result = f->f_op->write(f, buf, count, &f->f_pos); - set_fs(oldfs); - return result; + oldfs = get_fs(); + set_fs(KERNEL_DS); + f->f_pos = 0; + result = f->f_op->write(f, buf, count, &f->f_pos); + set_fs(oldfs); + return result; } - static int tty_available(struct file *f) { - long result = 0; - mm_segment_t oldfs; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - f->f_op->ioctl(f->f_dentry->d_inode, f, FIONREAD, (unsigned long)&result); - set_fs(oldfs); - return result; + long result = 0; + mm_segment_t oldfs; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + f->f_op->ioctl(f->f_dentry->d_inode, f, FIONREAD, + (unsigned long)&result); + set_fs(oldfs); + return result; } static int tty_read(struct file *f, int timeout) { - int result; - - result = -1; - if (!IS_ERR(f)) { - mm_segment_t oldfs; - - oldfs = get_fs(); - set_fs(KERNEL_DS); - if (f->f_op->poll) { - struct poll_wqueues table; - struct timeval start, now; - - do_gettimeofday(&start); - poll_initwait(&table); - while (1) { - long elapsed; - int mask; - - mask = f->f_op->poll(f, &table.pt); - if (mask & (POLLRDNORM|POLLRDBAND|POLLIN|POLLHUP|POLLERR)) { break; } - do_gettimeofday(&now); - elapsed = (1000000 * (now.tv_sec - start.tv_sec) + - now.tv_usec - start.tv_usec); - if (elapsed > timeout) { break; } - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(((timeout - elapsed)* HZ) / 10000); - } - poll_freewait(&table); - } else { - /* Device does not support poll, busy wait */ - int retries = 0; - while (1) { - retries++; - if (retries >= timeout) { break; } - if (tty_available(f) > 0) { break; } - comedi_udelay(100); - } - } - if (tty_available(f) > 0) { - unsigned char ch; - - f->f_pos = 0; - if (f->f_op->read(f, &ch, 1, &f->f_pos) == 1) { - result = ch; - } - } - set_fs(oldfs); - } - return result; + int result; + + result = -1; + if (!IS_ERR(f)) { + mm_segment_t oldfs; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + if (f->f_op->poll) { + struct poll_wqueues table; + struct timeval start, now; + + do_gettimeofday(&start); + poll_initwait(&table); + while (1) { + long elapsed; + int mask; + + mask = f->f_op->poll(f, &table.pt); + if (mask & (POLLRDNORM | POLLRDBAND | POLLIN | + POLLHUP | POLLERR)) { + break; + } + do_gettimeofday(&now); + elapsed = + (1000000 * (now.tv_sec - start.tv_sec) + + now.tv_usec - start.tv_usec); + if (elapsed > timeout) { + break; + } + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(((timeout - + elapsed) * HZ) / 10000); + } + poll_freewait(&table); + } else { + /* Device does not support poll, busy wait */ + int retries = 0; + while (1) { + retries++; + if (retries >= timeout) { + break; + } + if (tty_available(f) > 0) { + break; + } + comedi_udelay(100); + } + } + if (tty_available(f) > 0) { + unsigned char ch; + + f->f_pos = 0; + if (f->f_op->read(f, &ch, 1, &f->f_pos) == 1) { + result = ch; + } + } + set_fs(oldfs); + } + return result; } static void tty_setspeed(struct file *f, int speed) { - mm_segment_t oldfs; + mm_segment_t oldfs; - oldfs = get_fs(); - set_fs(KERNEL_DS); - { - // Set speed - struct termios settings; + oldfs = get_fs(); + set_fs(KERNEL_DS); + { + // Set speed + struct termios settings; - f->f_op->ioctl(f->f_dentry->d_inode, f, TCGETS, (unsigned long)&settings); + f->f_op->ioctl(f->f_dentry->d_inode, f, TCGETS, + (unsigned long)&settings); // printk("Speed: %d\n", settings.c_cflag & (CBAUD | CBAUDEX)); - settings.c_iflag = 0; - settings.c_oflag = 0; - settings.c_lflag = 0; - settings.c_cflag = CLOCAL | CS8 | CREAD; - settings.c_cc[VMIN] = 1; - settings.c_cc[VTIME] = 0; - switch (speed) { - case 2400: { settings.c_cflag |= B2400; } break; - case 4800: { settings.c_cflag |= B4800; } break; - case 9600: { settings.c_cflag |= B9600; } break; - case 19200: { settings.c_cflag |= B19200; } break; - case 38400: { settings.c_cflag |= B38400; } break; - case 57600: { settings.c_cflag |= B57600; } break; - case 115200: { settings.c_cflag |= B115200; } break; - default: { settings.c_cflag |= B9600; } break; - } - f->f_op->ioctl(f->f_dentry->d_inode, f, TCSETS, (unsigned long)&settings); + settings.c_iflag = 0; + settings.c_oflag = 0; + settings.c_lflag = 0; + settings.c_cflag = CLOCAL | CS8 | CREAD; + settings.c_cc[VMIN] = 1; + settings.c_cc[VTIME] = 0; + switch (speed) { + case 2400:{ + settings.c_cflag |= B2400; + } + break; + case 4800:{ + settings.c_cflag |= B4800; + } + break; + case 9600:{ + settings.c_cflag |= B9600; + } + break; + case 19200:{ + settings.c_cflag |= B19200; + } + break; + case 38400:{ + settings.c_cflag |= B38400; + } + break; + case 57600:{ + settings.c_cflag |= B57600; + } + break; + case 115200:{ + settings.c_cflag |= B115200; + } + break; + default:{ + settings.c_cflag |= B9600; + } + break; + } + f->f_op->ioctl(f->f_dentry->d_inode, f, TCSETS, + (unsigned long)&settings); // printk("Speed: %d\n", settings.c_cflag & (CBAUD | CBAUDEX)); - } - { - // Set low latency - struct serial_struct settings; - f->f_op->ioctl(f->f_dentry->d_inode, f, TIOCGSERIAL, (unsigned long)&settings); - settings.flags |= ASYNC_LOW_LATENCY; - f->f_op->ioctl(f->f_dentry->d_inode, f, TIOCSSERIAL, (unsigned long)&settings); - } - - set_fs(oldfs); + } + { + // Set low latency + struct serial_struct settings; + f->f_op->ioctl(f->f_dentry->d_inode, f, TIOCGSERIAL, + (unsigned long)&settings); + settings.flags |= ASYNC_LOW_LATENCY; + f->f_op->ioctl(f->f_dentry->d_inode, f, TIOCSSERIAL, + (unsigned long)&settings); + } + + set_fs(oldfs); } -static void poll_digital(struct file *f, int channel) { - char cmd; +static void poll_digital(struct file *f, int channel) +{ + char cmd; - cmd = 0x40 | (channel & 0x1f); - tty_write(f, &cmd, 1); + cmd = 0x40 | (channel & 0x1f); + tty_write(f, &cmd, 1); } -static void poll_channel(struct file *f, int channel) { - char cmd; +static void poll_channel(struct file *f, int channel) +{ + char cmd; - cmd = 0x60 | (channel & 0x1f); - tty_write(f, &cmd, 1); + cmd = 0x60 | (channel & 0x1f); + tty_write(f, &cmd, 1); } static struct serial_data serial_read(struct file *f, int timeout) { - struct serial_data result; - int length; - - result.kind = is_invalid; - result.index = 0; - result.value = 0; - length = 0; - while (1) { - int data = tty_read(f, timeout); - - length++; - if (data < 0) { - printk("serial2002 error\n"); - break; - } else if (data & 0x80) { - result.value = (result.value << 7) | (data & 0x7f); - } else { - if (length == 1) { - switch ((data>>5) & 0x03) { - case 0: { result.value = 0; result.kind = is_digital; } break; - case 1: { result.value = 1; result.kind = is_digital; } break; + struct serial_data result; + int length; + + result.kind = is_invalid; + result.index = 0; + result.value = 0; + length = 0; + while (1) { + int data = tty_read(f, timeout); + + length++; + if (data < 0) { + printk("serial2002 error\n"); + break; + } else if (data & 0x80) { + result.value = (result.value << 7) | (data & 0x7f); + } else { + if (length == 1) { + switch ((data >> 5) & 0x03) { + case 0:{ + result.value = 0; + result.kind = is_digital; + } + break; + case 1:{ + result.value = 1; + result.kind = is_digital; + } + break; + } + } else { + result.value = + (result. + value << 2) | ((data & 0x60) >> 5); + result.kind = is_channel; + } + result.index = data & 0x1f; + break; + } } - } else { - result.value = (result.value << 2) | ((data & 0x60) >> 5); - result.kind = is_channel; - } - result.index = data & 0x1f; - break; - } - } - return result; + return result; } static void serial_write(struct file *f, struct serial_data data) { - if (data.kind == is_digital) { - unsigned char ch = ((data.value<<5) & 0x20) | (data.index & 0x1f); - tty_write(f, &ch, 1); - } else { - unsigned char ch[6]; - int i = 0; - if (data.value >= (1L<<30)) { ch[i] = 0x80|((data.value>>30)&0x03); i++; } - if (data.value >= (1L<<23)) { ch[i] = 0x80|((data.value>>23)&0x7f); i++; } - if (data.value >= (1L<<16)) { ch[i] = 0x80|((data.value>>16)&0x7f); i++; } - if (data.value >= (1L<< 9)) { ch[i] = 0x80|((data.value>> 9)&0x7f); i++; } - ch[i] = 0x80|((data.value>> 2)&0x7f); i++; - ch[i] = ((data.value<< 5)&0x60)|(data.index & 0x1f); i++; - tty_write(f, ch, i); - } -} - -static void serial_2002_open(comedi_device *dev) { - char port[20]; - - sprintf(port, "/dev/ttyS%d", devpriv->port); - devpriv->tty = filp_open(port, 0, O_RDWR); - if (IS_ERR(devpriv->tty)) { - printk("serial_2002: file open error = %ld\n", PTR_ERR(devpriv->tty)); - } else { - typedef struct { - int kind; - int bits; - int min; - int max; - } config_t; - config_t dig_in_config[32]; - config_t dig_out_config[32]; - config_t chan_in_config[32]; - config_t chan_out_config[32]; - int i; - - for (i = 0 ; i < 32 ; i++) { - dig_in_config[i].kind = 0; dig_in_config[i].bits = 0; - dig_in_config[i].min = 0; dig_in_config[i].max = 0; - dig_out_config[i].kind = 0; dig_out_config[i].bits = 0; - dig_out_config[i].min = 0; dig_out_config[i].max = 0; - chan_in_config[i].kind = 0; chan_in_config[i].bits = 0; - chan_in_config[i].min = 0; chan_in_config[i].max = 0; - chan_out_config[i].kind = 0; chan_out_config[i].bits = 0; - chan_out_config[i].min = 0; chan_out_config[i].max = 0; - } - - tty_setspeed(devpriv->tty, devpriv->speed); - poll_channel(devpriv->tty, 31); // Start reading configuration - while (1) { - struct serial_data data; - - data = serial_read(devpriv->tty, 1000); - if (data.kind!=is_channel || data.index!=31 || !(data.value & 0xe0)) { - break; - } else { - int command, channel, kind; - config_t *cur_config = 0; - - channel = data.value & 0x1f; - kind = (data.value>>5) & 0x7; - command = (data.value>>8) & 0x3; - switch (kind) { - case 1: { cur_config = dig_in_config; } break; - case 2: { cur_config = dig_out_config; } break; - case 3: { cur_config = chan_in_config; } break; - case 4: { cur_config = chan_out_config; } break; - case 5: { cur_config = chan_in_config; } break; - } - - if (cur_config) { - cur_config[channel].kind = kind; - switch (command) { - case 0: { - cur_config[channel].bits = (data.value >> 10) & 0x3f; - } break; - case 1: { - int unit, sign, min; - unit = (data.value >> 10) & 0x7; - sign = (data.value >> 13) & 0x1; - min = (data.value >> 14) & 0xfffff; - - switch (unit) { - case 0: { min = min * 1000000; } break; - case 1: { min = min * 1000; } break; - case 2: { min = min * 1; } break; - } - if (sign) { min = -min; } - cur_config[channel].min = min; - } break; - case 2: { - int unit, sign, max; - unit = (data.value >> 10) & 0x7; - sign = (data.value >> 13) & 0x1; - max = (data.value >> 14) & 0xfffff; - - switch (unit) { - case 0: { max = max * 1000000; } break; - case 1: { max = max * 1000; } break; - case 2: { max = max * 1; } break; - } - if (sign) { max = -max; } - cur_config[channel].max = max; - } break; - } + if (data.kind == is_digital) { + unsigned char ch = + ((data.value << 5) & 0x20) | (data.index & 0x1f); + tty_write(f, &ch, 1); + } else { + unsigned char ch[6]; + int i = 0; + if (data.value >= (1L << 30)) { + ch[i] = 0x80 | ((data.value >> 30) & 0x03); + i++; + } + if (data.value >= (1L << 23)) { + ch[i] = 0x80 | ((data.value >> 23) & 0x7f); + i++; + } + if (data.value >= (1L << 16)) { + ch[i] = 0x80 | ((data.value >> 16) & 0x7f); + i++; + } + if (data.value >= (1L << 9)) { + ch[i] = 0x80 | ((data.value >> 9) & 0x7f); + i++; + } + ch[i] = 0x80 | ((data.value >> 2) & 0x7f); + i++; + ch[i] = ((data.value << 5) & 0x60) | (data.index & 0x1f); + i++; + tty_write(f, ch, i); } - } - } - for (i = 0 ; i <= 4 ; i++) { - // Fill in subdev data - config_t *c; - unsigned char *mapping = 0; - serial2002_range_table_t *range = 0; - int kind = 0; - - switch (i) { - case 0: { - c = dig_in_config; - mapping = devpriv->digital_in_mapping; - kind = 1; - } break; - case 1: { - c = dig_out_config; - mapping = devpriv->digital_out_mapping; - kind = 2; - } break; - case 2: { - c = chan_in_config; - mapping = devpriv->analog_in_mapping; - range = devpriv->in_range; - kind = 3; - } break; - case 3: { - c = chan_out_config; - mapping = devpriv->analog_out_mapping; - range = devpriv->out_range; - kind = 4; - } break; - case 4: { - c = chan_in_config; - mapping = devpriv->encoder_in_mapping; - range = devpriv->in_range; - kind = 5; - } break; - default: { c = 0; } break; - } - if (c) { - comedi_subdevice *s; - const comedi_lrange **range_table_list = NULL; - unsigned int *maxdata_list; - int j, chan; +} - for (chan = 0, j = 0 ; j < 32 ; j++) { - if (c[j].kind == kind) { chan++; } - } - s = &dev->subdevices[i]; - s->n_chan = chan; - s->maxdata = 0; - if (s->maxdata_list) { kfree(s->maxdata_list); } - s->maxdata_list = maxdata_list = - kmalloc(sizeof(lsampl_t)*s->n_chan, GFP_KERNEL); - if (s->range_table_list) { kfree(s->range_table_list); } - if (range) { - s->range_table = 0; - s->range_table_list = range_table_list = - kmalloc(sizeof(serial2002_range_table_t)*s->n_chan, GFP_KERNEL); - } - for (chan = 0, j = 0 ; j < 32 ; j++) { - if (c[j].kind == kind) { - if (mapping) { mapping[chan] = j; } - if (range) { - range[j].length = 1; - range[j].range.min = c[j].min; - range[j].range.max = c[j].max; - range_table_list[chan] = (const comedi_lrange*)&range[j]; - } - maxdata_list[chan] = ((long long)1<port); + devpriv->tty = filp_open(port, 0, O_RDWR); + if (IS_ERR(devpriv->tty)) { + printk("serial_2002: file open error = %ld\n", + PTR_ERR(devpriv->tty)); + } else { + typedef struct { + int kind; + int bits; + int min; + int max; + } config_t; + config_t dig_in_config[32]; + config_t dig_out_config[32]; + config_t chan_in_config[32]; + config_t chan_out_config[32]; + int i; + + for (i = 0; i < 32; i++) { + dig_in_config[i].kind = 0; + dig_in_config[i].bits = 0; + dig_in_config[i].min = 0; + dig_in_config[i].max = 0; + dig_out_config[i].kind = 0; + dig_out_config[i].bits = 0; + dig_out_config[i].min = 0; + dig_out_config[i].max = 0; + chan_in_config[i].kind = 0; + chan_in_config[i].bits = 0; + chan_in_config[i].min = 0; + chan_in_config[i].max = 0; + chan_out_config[i].kind = 0; + chan_out_config[i].bits = 0; + chan_out_config[i].min = 0; + chan_out_config[i].max = 0; + } + + tty_setspeed(devpriv->tty, devpriv->speed); + poll_channel(devpriv->tty, 31); // Start reading configuration + while (1) { + struct serial_data data; + + data = serial_read(devpriv->tty, 1000); + if (data.kind != is_channel || data.index != 31 + || !(data.value & 0xe0)) { + break; + } else { + int command, channel, kind; + config_t *cur_config = 0; + + channel = data.value & 0x1f; + kind = (data.value >> 5) & 0x7; + command = (data.value >> 8) & 0x3; + switch (kind) { + case 1:{ + cur_config = dig_in_config; + } + break; + case 2:{ + cur_config = dig_out_config; + } + break; + case 3:{ + cur_config = chan_in_config; + } + break; + case 4:{ + cur_config = chan_out_config; + } + break; + case 5:{ + cur_config = chan_in_config; + } + break; + } + + if (cur_config) { + cur_config[channel].kind = kind; + switch (command) { + case 0:{ + cur_config[channel]. + bits = + (data. + value >> 10) & + 0x3f; + } + break; + case 1:{ + int unit, sign, min; + unit = (data. + value >> 10) & + 0x7; + sign = (data. + value >> 13) & + 0x1; + min = (data. + value >> 14) & + 0xfffff; + + switch (unit) { + case 0:{ + min = min * 1000000; + } + break; + case 1:{ + min = min * 1000; + } + break; + case 2:{ + min = min * 1; + } + break; + } + if (sign) { + min = -min; + } + cur_config[channel]. + min = min; + } + break; + case 2:{ + int unit, sign, max; + unit = (data. + value >> 10) & + 0x7; + sign = (data. + value >> 13) & + 0x1; + max = (data. + value >> 14) & + 0xfffff; + + switch (unit) { + case 0:{ + max = max * 1000000; + } + break; + case 1:{ + max = max * 1000; + } + break; + case 2:{ + max = max * 1; + } + break; + } + if (sign) { + max = -max; + } + cur_config[channel]. + max = max; + } + break; + } + } + } + } + for (i = 0; i <= 4; i++) { + // Fill in subdev data + config_t *c; + unsigned char *mapping = 0; + serial2002_range_table_t *range = 0; + int kind = 0; + + switch (i) { + case 0:{ + c = dig_in_config; + mapping = devpriv->digital_in_mapping; + kind = 1; + } + break; + case 1:{ + c = dig_out_config; + mapping = devpriv->digital_out_mapping; + kind = 2; + } + break; + case 2:{ + c = chan_in_config; + mapping = devpriv->analog_in_mapping; + range = devpriv->in_range; + kind = 3; + } + break; + case 3:{ + c = chan_out_config; + mapping = devpriv->analog_out_mapping; + range = devpriv->out_range; + kind = 4; + } + break; + case 4:{ + c = chan_in_config; + mapping = devpriv->encoder_in_mapping; + range = devpriv->in_range; + kind = 5; + } + break; + default:{ + c = 0; + } + break; + } + if (c) { + comedi_subdevice *s; + const comedi_lrange **range_table_list = NULL; + unsigned int *maxdata_list; + int j, chan; + + for (chan = 0, j = 0; j < 32; j++) { + if (c[j].kind == kind) { + chan++; + } + } + s = &dev->subdevices[i]; + s->n_chan = chan; + s->maxdata = 0; + if (s->maxdata_list) { + kfree(s->maxdata_list); + } + s->maxdata_list = maxdata_list = + kmalloc(sizeof(lsampl_t) * s->n_chan, + GFP_KERNEL); + if (s->range_table_list) { + kfree(s->range_table_list); + } + if (range) { + s->range_table = 0; + s->range_table_list = range_table_list = + kmalloc(sizeof + (serial2002_range_table_t) * + s->n_chan, GFP_KERNEL); + } + for (chan = 0, j = 0; j < 32; j++) { + if (c[j].kind == kind) { + if (mapping) { + mapping[chan] = j; + } + if (range) { + range[j].length = 1; + range[j].range.min = + c[j].min; + range[j].range.max = + c[j].max; + range_table_list[chan] = + (const + comedi_lrange *) + &range[j]; + } + maxdata_list[chan] = + ((long long)1 << c[j]. + bits) - 1; + chan++; + } + } + } + } } - } - } - } } -static void serial_2002_close(comedi_device *dev) { - if (!IS_ERR(devpriv->tty) && (devpriv->tty != 0)) { - filp_close(devpriv->tty, 0); - } +static void serial_2002_close(comedi_device * dev) +{ + if (!IS_ERR(devpriv->tty) && (devpriv->tty != 0)) { + filp_close(devpriv->tty, 0); + } } -static int serial2002_di_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int serial2002_di_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan; - - chan = devpriv->digital_in_mapping[CR_CHAN(insn->chanspec)]; - for(n = 0 ; n < insn->n ; n++){ - struct serial_data read; - - poll_digital(devpriv->tty, chan); - while (1) { - read = serial_read(devpriv->tty, 1000); - if (read.kind != is_digital || read.index == chan) { break; } - } - data[n] = read.value; - } - return n; + int n; + int chan; + + chan = devpriv->digital_in_mapping[CR_CHAN(insn->chanspec)]; + for (n = 0; n < insn->n; n++) { + struct serial_data read; + + poll_digital(devpriv->tty, chan); + while (1) { + read = serial_read(devpriv->tty, 1000); + if (read.kind != is_digital || read.index == chan) { + break; + } + } + data[n] = read.value; + } + return n; } -static int serial2002_do_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int serial2002_do_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan; - - chan = devpriv->digital_out_mapping[CR_CHAN(insn->chanspec)]; - for(n = 0 ; n < insn->n ; n++){ - struct serial_data write; - - write.kind = is_digital; - write.index = chan; - write.value = data[n]; - serial_write(devpriv->tty, write); - } - return n; + int n; + int chan; + + chan = devpriv->digital_out_mapping[CR_CHAN(insn->chanspec)]; + for (n = 0; n < insn->n; n++) { + struct serial_data write; + + write.kind = is_digital; + write.index = chan; + write.value = data[n]; + serial_write(devpriv->tty, write); + } + return n; } -static int serial2002_ai_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int serial2002_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan; - - chan = devpriv->analog_in_mapping[CR_CHAN(insn->chanspec)]; - for(n = 0 ; n < insn->n ; n++){ - struct serial_data read; - - poll_channel(devpriv->tty, chan); - while (1) { - read = serial_read(devpriv->tty, 1000); - if (read.kind != is_channel || read.index == chan) { break; } - } - data[n] = read.value; - } - return n; + int n; + int chan; + + chan = devpriv->analog_in_mapping[CR_CHAN(insn->chanspec)]; + for (n = 0; n < insn->n; n++) { + struct serial_data read; + + poll_channel(devpriv->tty, chan); + while (1) { + read = serial_read(devpriv->tty, 1000); + if (read.kind != is_channel || read.index == chan) { + break; + } + } + data[n] = read.value; + } + return n; } -static int serial2002_ao_winsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int serial2002_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan; - - chan = devpriv->analog_out_mapping[CR_CHAN(insn->chanspec)]; - for(n = 0 ; n < insn->n ; n++){ - struct serial_data write; - - write.kind = is_channel; - write.index = chan; - write.value = data[n]; - serial_write(devpriv->tty, write); - devpriv->ao_readback[chan] = data[n]; - } - return n; + int n; + int chan; + + chan = devpriv->analog_out_mapping[CR_CHAN(insn->chanspec)]; + for (n = 0; n < insn->n; n++) { + struct serial_data write; + + write.kind = is_channel; + write.index = chan; + write.value = data[n]; + serial_write(devpriv->tty, write); + devpriv->ao_readback[chan] = data[n]; + } + return n; } -static int serial2002_ao_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int serial2002_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan = CR_CHAN(insn->chanspec); + int n; + int chan = CR_CHAN(insn->chanspec); - for(n = 0; n < insn->n ; n++) { - data[n] = devpriv->ao_readback[chan]; - } + for (n = 0; n < insn->n; n++) { + data[n] = devpriv->ao_readback[chan]; + } - return n; + return n; } -static int serial2002_ei_rinsn(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int serial2002_ei_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n; - int chan; - - chan = devpriv->encoder_in_mapping[CR_CHAN(insn->chanspec)]; - for(n = 0 ; n < insn->n ; n++){ - struct serial_data read; - - poll_channel(devpriv->tty, chan); - while (1) { - read = serial_read(devpriv->tty, 1000); - if (read.kind != is_channel || read.index == chan) { break; } - } - data[n] = read.value; - } - return n; + int n; + int chan; + + chan = devpriv->encoder_in_mapping[CR_CHAN(insn->chanspec)]; + for (n = 0; n < insn->n; n++) { + struct serial_data read; + + poll_channel(devpriv->tty, chan); + while (1) { + read = serial_read(devpriv->tty, 1000); + if (read.kind != is_channel || read.index == chan) { + break; + } + } + data[n] = read.value; + } + return n; } -static int serial2002_attach(comedi_device *dev, comedi_devconfig *it) +static int serial2002_attach(comedi_device * dev, comedi_devconfig * it) { - comedi_subdevice *s; - - printk("comedi%d: serial2002: ",dev->minor); - dev->board_name = thisboard->name; - if(alloc_private(dev,sizeof(serial2002_private)) < 0) { - return -ENOMEM; - } - dev->open = serial_2002_open; - dev->close = serial_2002_close; - devpriv->port = it->options[0]; - devpriv->speed = it->options[1]; - printk("/dev/ttyS%d @ %d\n", devpriv->port, devpriv->speed); - - if(alloc_subdevices(dev, 5)<0) - return -ENOMEM; - - /* digital input subdevice */ - s = dev->subdevices+0; - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_read = &serial2002_di_rinsn; - - /* digital output subdevice */ - s = dev->subdevices+1; - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = &range_digital; - s->insn_write = &serial2002_do_winsn; - - /* analog input subdevice */ - s=dev->subdevices+2; - s->type = COMEDI_SUBD_AI; - s->subdev_flags = SDF_READABLE|SDF_GROUND; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = 0; - s->insn_read = &serial2002_ai_rinsn; - - /* analog output subdevice */ - s=dev->subdevices+3; - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITEABLE; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = 0; - s->insn_write = &serial2002_ao_winsn; - s->insn_read = &serial2002_ao_rinsn; - - /* encoder input subdevice */ - s=dev->subdevices+4; - s->type = COMEDI_SUBD_COUNTER; - s->subdev_flags = SDF_READABLE | SDF_LSAMPL; - s->n_chan = 0; - s->maxdata = 1; - s->range_table = 0; - s->insn_read = &serial2002_ei_rinsn; - - printk("attached\n"); - - return 1; -} + comedi_subdevice *s; + printk("comedi%d: serial2002: ", dev->minor); + dev->board_name = thisboard->name; + if (alloc_private(dev, sizeof(serial2002_private)) < 0) { + return -ENOMEM; + } + dev->open = serial_2002_open; + dev->close = serial_2002_close; + devpriv->port = it->options[0]; + devpriv->speed = it->options[1]; + printk("/dev/ttyS%d @ %d\n", devpriv->port, devpriv->speed); + + if (alloc_subdevices(dev, 5) < 0) + return -ENOMEM; + + /* digital input subdevice */ + s = dev->subdevices + 0; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_read = &serial2002_di_rinsn; + + /* digital output subdevice */ + s = dev->subdevices + 1; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_write = &serial2002_do_winsn; + + /* analog input subdevice */ + s = dev->subdevices + 2; + s->type = COMEDI_SUBD_AI; + s->subdev_flags = SDF_READABLE | SDF_GROUND; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = 0; + s->insn_read = &serial2002_ai_rinsn; + + /* analog output subdevice */ + s = dev->subdevices + 3; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = 0; + s->insn_write = &serial2002_ao_winsn; + s->insn_read = &serial2002_ao_rinsn; + + /* encoder input subdevice */ + s = dev->subdevices + 4; + s->type = COMEDI_SUBD_COUNTER; + s->subdev_flags = SDF_READABLE | SDF_LSAMPL; + s->n_chan = 0; + s->maxdata = 1; + s->range_table = 0; + s->insn_read = &serial2002_ei_rinsn; + + printk("attached\n"); + + return 1; +} -static int serial2002_detach(comedi_device *dev) +static int serial2002_detach(comedi_device * dev) { - comedi_subdevice *s; - int i; - - printk("comedi%d: serial2002: remove\n",dev->minor); - for (i = 0 ; i < 4 ; i++) { - s = &dev->subdevices[i]; - if (s->maxdata_list) { kfree(s->maxdata_list); } - if (s->range_table_list) { kfree(s->range_table_list); } - } - return 0; + comedi_subdevice *s; + int i; + + printk("comedi%d: serial2002: remove\n", dev->minor); + for (i = 0; i < 4; i++) { + s = &dev->subdevices[i]; + if (s->maxdata_list) { + kfree(s->maxdata_list); + } + if (s->range_table_list) { + kfree(s->range_table_list); + } + } + return 0; } COMEDI_INITCLEANUP(driver_serial2002); - - diff --git a/comedi/drivers/skel.c b/comedi/drivers/skel.c index c5cdc2a4..619c124f 100644 --- a/comedi/drivers/skel.c +++ b/comedi/drivers/skel.c @@ -74,8 +74,7 @@ Configuration Options: #include -#include /* for PCI devices */ - +#include /* for PCI devices */ /* Imaginary registers for the imaginary board */ @@ -89,25 +88,25 @@ Configuration Options: * boards in this way is optional, and completely driver-dependent. * Some drivers use arrays such as this, other do not. */ -typedef struct skel_board_struct{ +typedef struct skel_board_struct { const char *name; int ai_chans; int ai_bits; int have_dio; -}skel_board; +} skel_board; static const skel_board skel_boards[] = { { - name: "skel-100", - ai_chans: 16, - ai_bits: 12, - have_dio: 1, - }, + name: "skel-100", + ai_chans:16, + ai_bits: 12, + have_dio:1, + }, { - name: "skel-200", - ai_chans: 8, - ai_bits: 16, - have_dio: 0, - }, + name: "skel-200", + ai_chans:8, + ai_bits: 16, + have_dio:0, + }, }; /* This is used by modprobe to translate PCI IDs to drivers. Should @@ -116,10 +115,11 @@ static const skel_board skel_boards[] = { * upstream. */ #define PCI_VENDOR_ID_SKEL 0xdafe static struct pci_device_id skel_pci_table[] __devinitdata = { - { PCI_VENDOR_ID_SKEL, 0x0100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { PCI_VENDOR_ID_SKEL, 0x0200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, - { 0 } + {PCI_VENDOR_ID_SKEL, 0x0100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_SKEL, 0x0200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {0} }; + MODULE_DEVICE_TABLE(pci, skel_pci_table); /* @@ -130,7 +130,7 @@ MODULE_DEVICE_TABLE(pci, skel_pci_table); /* this structure is for data unique to this hardware driver. If several hardware drivers keep similar information in this structure, feel free to suggest moving the variable to the comedi_device struct. */ -typedef struct{ +typedef struct { int data; /* would be useful for a PCI device */ @@ -138,7 +138,7 @@ typedef struct{ /* Used for AO readback */ lsampl_t ao_readback[2]; -}skel_private; +} skel_private; /* * most drivers define the following macro to make it easy to * access the private structure. @@ -151,13 +151,13 @@ typedef struct{ * the board, and also about the kernel module that contains * the device code. */ -static int skel_attach(comedi_device *dev,comedi_devconfig *it); -static int skel_detach(comedi_device *dev); -static comedi_driver driver_skel={ - driver_name: "dummy", - module: THIS_MODULE, - attach: skel_attach, - detach: skel_detach, +static int skel_attach(comedi_device * dev, comedi_devconfig * it); +static int skel_detach(comedi_device * dev); +static comedi_driver driver_skel = { + driver_name:"dummy", + module:THIS_MODULE, + attach:skel_attach, + detach:skel_detach, /* It is not necessary to implement the following members if you are * writing a driver for a ISA PnP or PCI card */ /* Most drivers will support multiple types of boards by @@ -176,21 +176,24 @@ static comedi_driver driver_skel={ * the type of board in software. ISA PnP, PCI, and PCMCIA * devices are such boards. */ - board_name: &skel_boards[0].name, - offset: sizeof(skel_board), - num_names: sizeof(skel_boards) / sizeof(skel_board), + board_name:&skel_boards[0].name, + offset:sizeof(skel_board), + num_names:sizeof(skel_boards) / sizeof(skel_board), }; -static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int skel_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int skel_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int skel_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int skel_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data); -static int skel_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd); -static int skel_ns_to_timer(unsigned int *ns,int round); +static int skel_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int skel_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int skel_ao_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int skel_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int skel_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data); +static int skel_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd); +static int skel_ns_to_timer(unsigned int *ns, int round); /* * Attach is called by the Comedi core to configure the driver @@ -198,11 +201,11 @@ static int skel_ns_to_timer(unsigned int *ns,int round); * in the driver structure, dev->board_ptr contains that * address. */ -static int skel_attach(comedi_device *dev,comedi_devconfig *it) +static int skel_attach(comedi_device * dev, comedi_devconfig * it) { comedi_subdevice *s; - printk("comedi%d: skel: ",dev->minor); + printk("comedi%d: skel: ", dev->minor); /* * If you can probe the device to determine what device in a series @@ -221,53 +224,53 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) * Allocate the private structure area. alloc_private() is a * convenient macro defined in comedidev.h. */ - if(alloc_private(dev,sizeof(skel_private))<0) + if (alloc_private(dev, sizeof(skel_private)) < 0) return -ENOMEM; /* * Allocate the subdevice structures. alloc_subdevice() is a * convenient macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 3)<0) + if (alloc_subdevices(dev, 3) < 0) return -ENOMEM; - s=dev->subdevices+0; + s = dev->subdevices + 0; //dev->read_subdev=s; /* analog input subdevice */ - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; /* we support single-ended (ground) and differential */ - s->subdev_flags=SDF_READABLE|SDF_GROUND|SDF_DIFF; - s->n_chan=thisboard->ai_chans; - s->maxdata=(1<ai_bits)-1; - s->range_table=&range_bipolar10; - s->len_chanlist=16; /* This is the maximum chanlist length that - the board can handle */ + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; + s->n_chan = thisboard->ai_chans; + s->maxdata = (1 << thisboard->ai_bits) - 1; + s->range_table = &range_bipolar10; + s->len_chanlist = 16; /* This is the maximum chanlist length that + the board can handle */ s->insn_read = skel_ai_rinsn; -// s->subdev_flags |= SDF_CMD_READ; -// s->do_cmd = skel_ai_cmd; +// s->subdev_flags |= SDF_CMD_READ; +// s->do_cmd = skel_ai_cmd; s->do_cmdtest = skel_ai_cmdtest; - s=dev->subdevices+1; + s = dev->subdevices + 1; /* analog output subdevice */ - s->type=COMEDI_SUBD_AO; - s->subdev_flags=SDF_WRITABLE; - s->n_chan=1; - s->maxdata=0xffff; - s->range_table=&range_bipolar5; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 1; + s->maxdata = 0xffff; + s->range_table = &range_bipolar5; s->insn_write = skel_ao_winsn; s->insn_read = skel_ao_rinsn; - s=dev->subdevices+2; + s = dev->subdevices + 2; /* digital i/o subdevice */ - if(thisboard->have_dio){ - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=16; - s->maxdata=1; - s->range_table=&range_digital; + if (thisboard->have_dio) { + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 16; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = skel_dio_insn_bits; s->insn_config = skel_dio_insn_config; - }else{ + } else { s->type = COMEDI_SUBD_UNUSED; } @@ -276,7 +279,6 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) return 0; } - /* * _detach is called to deconfigure a device. It should deallocate * resources. @@ -285,9 +287,9 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) * allocated by _attach(). dev->private and dev->subdevices are * deallocated automatically by the core. */ -static int skel_detach(comedi_device *dev) +static int skel_detach(comedi_device * dev) { - printk("comedi%d: skel: remove\n",dev->minor); + printk("comedi%d: skel: remove\n", dev->minor); return 0; } @@ -296,9 +298,10 @@ static int skel_detach(comedi_device *dev) * "instructions" read/write data in "one-shot" or "software-triggered" * mode. */ -static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int skel_ai_rinsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int n,i; + int n, i; unsigned int d; unsigned int status; @@ -310,18 +313,19 @@ static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins /* don't wait for mux to settle */ /* convert n samples */ - for(n=0;nn;n++){ + for (n = 0; n < insn->n; n++) { /* trigger conversion */ //outw(0,dev->iobase + SKEL_CONVERT); #define TIMEOUT 100 /* wait for conversion to end */ - for(i=0;iiobase + SKEL_STATUS); - if(status)break; + if (status) + break; } - if(i==TIMEOUT){ + if (i == TIMEOUT) { /* rt_printk() should be used instead of printk() * whenever the code can be called from real-time. */ rt_printk("timeout\n"); @@ -333,7 +337,7 @@ static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins d = 0; /* mangle the data as necessary */ - d ^= 1<<(thisboard->ai_bits-1); + d ^= 1 << (thisboard->ai_bits - 1); data[n] = d; } @@ -342,10 +346,10 @@ static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins return n; } -static int skel_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, - comedi_cmd *cmd) +static int skel_ai_cmdtest(comedi_device * dev, comedi_subdevice * s, + comedi_cmd * cmd) { - int err=0; + int err = 0; int tmp; /* cmdtest tests a particular command to see if it is valid. @@ -357,124 +361,139 @@ static int skel_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, /* step 1: make sure trigger sources are trivially valid */ - tmp=cmd->start_src; + tmp = cmd->start_src; cmd->start_src &= TRIG_NOW; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; - tmp=cmd->scan_begin_src; - cmd->scan_begin_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + tmp = cmd->scan_begin_src; + cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; - tmp=cmd->convert_src; - cmd->convert_src &= TRIG_TIMER|TRIG_EXT; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + tmp = cmd->convert_src; + cmd->convert_src &= TRIG_TIMER | TRIG_EXT; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_TIMER && - cmd->scan_begin_src!=TRIG_EXT)err++; - if(cmd->convert_src!=TRIG_TIMER && - cmd->convert_src!=TRIG_EXT)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; + if (cmd->scan_begin_src != TRIG_TIMER && + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - -#define MAX_SPEED 10000 /* in nanoseconds */ +#define MAX_SPEED 10000 /* in nanoseconds */ #define MIN_SPEED 1000000000 /* in nanoseconds */ - if(cmd->scan_begin_src==TRIG_TIMER){ - if(cmd->scan_begin_argscan_begin_arg=MAX_SPEED; + if (cmd->scan_begin_src == TRIG_TIMER) { + if (cmd->scan_begin_arg < MAX_SPEED) { + cmd->scan_begin_arg = MAX_SPEED; err++; } - if(cmd->scan_begin_arg>MIN_SPEED){ - cmd->scan_begin_arg=MIN_SPEED; + if (cmd->scan_begin_arg > MIN_SPEED) { + cmd->scan_begin_arg = MIN_SPEED; err++; } - }else{ + } 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; + if (cmd->scan_begin_arg > 9) { + cmd->scan_begin_arg = 9; err++; } } - if(cmd->convert_src==TRIG_TIMER){ - if(cmd->convert_argconvert_arg=MAX_SPEED; + 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; + if (cmd->convert_arg > MIN_SPEED) { + cmd->convert_arg = MIN_SPEED; err++; } - }else{ + } else { /* external trigger */ /* see above */ - if(cmd->convert_arg>9){ - cmd->convert_arg=9; + 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; + 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; + if (cmd->stop_src == TRIG_COUNT) { + if (cmd->stop_arg > 0x00ffffff) { + cmd->stop_arg = 0x00ffffff; err++; } - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ - if(cmd->scan_begin_src==TRIG_TIMER){ - tmp=cmd->scan_begin_arg; - skel_ns_to_timer(&cmd->scan_begin_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->scan_begin_arg)err++; + if (cmd->scan_begin_src == TRIG_TIMER) { + tmp = cmd->scan_begin_arg; + skel_ns_to_timer(&cmd->scan_begin_arg, + cmd->flags & TRIG_ROUND_MASK); + if (tmp != cmd->scan_begin_arg) + err++; } - if(cmd->convert_src==TRIG_TIMER){ - tmp=cmd->convert_arg; - skel_ns_to_timer(&cmd->convert_arg,cmd->flags&TRIG_ROUND_MASK); - if(tmp!=cmd->convert_arg)err++; - if(cmd->scan_begin_src==TRIG_TIMER && - cmd->scan_begin_argconvert_arg*cmd->scan_end_arg){ - cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg; + if (cmd->convert_src == TRIG_TIMER) { + tmp = cmd->convert_arg; + skel_ns_to_timer(&cmd->convert_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; + if (err) + return 4; return 0; } @@ -484,7 +503,7 @@ static int skel_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, * convert ns nanoseconds to a counter value suitable for programming * the device. Also, it should adjust ns so that it cooresponds to * the actual time that the device will use. */ -static int skel_ns_to_timer(unsigned int *ns,int round) +static int skel_ns_to_timer(unsigned int *ns, int round) { /* trivial timer */ /* if your timing is done through two cascaded timers, the @@ -496,16 +515,16 @@ static int skel_ns_to_timer(unsigned int *ns,int round) return *ns; } - -static int skel_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int skel_ao_winsn(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); -printk("skel_ao_winsn\n"); + printk("skel_ao_winsn\n"); /* Writing a list of values to an AO channel is probably not * very useful, but that's how the interface is defined. */ - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { /* a typical programming sequence */ //outw(data[i],dev->iobase + SKEL_DA0 + chan); devpriv->ao_readback[chan] = data[i]; @@ -517,12 +536,13 @@ printk("skel_ao_winsn\n"); /* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */ -static int skel_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int skel_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;in;i++) + for (i = 0; i < insn->n; i++) data[i] = devpriv->ao_readback[chan]; return i; @@ -533,16 +553,17 @@ static int skel_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins * 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 skel_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int skel_dio_insn_bits(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - if(insn->n!=2)return -EINVAL; + if (insn->n != 2) + return -EINVAL; /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ - if(data[0]){ + if (data[0]) { s->state &= ~data[0]; - s->state |= data[0]&data[1]; + s->state |= data[0] & data[1]; /* Write out the new digital output lines */ //outw(s->state,dev->iobase + SKEL_DIO); } @@ -557,25 +578,26 @@ static int skel_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, return 2; } -static int skel_dio_insn_config(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) +static int skel_dio_insn_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int chan=CR_CHAN(insn->chanspec); + int chan = CR_CHAN(insn->chanspec); /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<io_bits |= 1 << chan; break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<io_bits &= ~(1 << chan); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; + data[1] = + (s-> + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; return insn->n; break; default: @@ -592,4 +614,3 @@ static int skel_dio_insn_config(comedi_device *dev,comedi_subdevice *s, * as necessary. */ COMEDI_INITCLEANUP(driver_skel); - diff --git a/comedi/drivers/ssv_dnp.c b/comedi/drivers/ssv_dnp.c index 06c21513..22630505 100644 --- a/comedi/drivers/ssv_dnp.c +++ b/comedi/drivers/ssv_dnp.c @@ -33,7 +33,6 @@ Status: unknown #include - /* Some global definitions: the registers of the DNP ----------------------- */ /* */ /* For port A and B the mode register has bits corresponding to the output */ @@ -42,48 +41,44 @@ Status: unknown /* 0..3 remain unchanged! For details about Port C Mode Register see */ /* the remarks in dnp_insn_config() below. */ -#define CSCIR 0x22 /* Chip Setup and Control Index Register */ -#define CSCDR 0x23 /* Chip Setup and Control Data Register */ -#define PAMR 0xa5 /* Port A Mode Register */ -#define PADR 0xa9 /* Port A Data Register */ -#define PBMR 0xa4 /* Port B Mode Register */ -#define PBDR 0xa8 /* Port B Data Register */ -#define PCMR 0xa3 /* Port C Mode Register */ -#define PCDR 0xa7 /* Port C Data Register */ - +#define CSCIR 0x22 /* Chip Setup and Control Index Register */ +#define CSCDR 0x23 /* Chip Setup and Control Data Register */ +#define PAMR 0xa5 /* Port A Mode Register */ +#define PADR 0xa9 /* Port A Data Register */ +#define PBMR 0xa4 /* Port B Mode Register */ +#define PBDR 0xa8 /* Port B Data Register */ +#define PCMR 0xa3 /* Port C Mode Register */ +#define PCDR 0xa7 /* Port C Data Register */ /* This data structure holds information about the supported boards -------- */ -typedef struct dnp_board_struct{ +typedef struct dnp_board_struct { const char *name; int ai_chans; int ai_bits; int have_dio; } dnp_board; -static const dnp_board dnp_boards[] = { /* we only support one DNP 'board' */ - { /* variant at the moment */ - name: "dnp-1486", - ai_chans: 16, - ai_bits: 12, - have_dio: 1, - }, +static const dnp_board dnp_boards[] = { /* we only support one DNP 'board' */ + { /* variant at the moment */ + name: "dnp-1486", + ai_chans:16, + ai_bits: 12, + have_dio:1, + }, }; - /* Useful for shorthand access to the particular board structure ----------- */ #define thisboard ((const dnp_board *)dev->board_ptr) - /* This structure is for data unique to the DNP driver --------------------- */ -typedef struct{ - // +typedef struct { + // } dnp_private_data; /* Shorthand macro for faster access to the private data ------------------- */ #define devpriv ((dnp_private *)dev->private) - /* ------------------------------------------------------------------------- */ /* The comedi_driver structure tells the Comedi core module which functions */ /* to call to configure/deconfigure (attach/detach) the board, and also */ @@ -92,34 +87,27 @@ typedef struct{ /* In the following section we define the API of this driver. */ /* ------------------------------------------------------------------------- */ -static int dnp_attach(comedi_device *dev,comedi_devconfig *it); -static int dnp_detach(comedi_device *dev); +static int dnp_attach(comedi_device * dev, comedi_devconfig * it); +static int dnp_detach(comedi_device * dev); static comedi_driver driver_dnp = { - driver_name: "ssv_dnp", - module: THIS_MODULE, - attach: dnp_attach, - detach: dnp_detach, - board_name: &dnp_boards[0].name, /* only necessary for non-PnP devs */ - offset: sizeof(dnp_board), /* like ISA-PnP, PCI or PCMCIA. */ - num_names: sizeof(dnp_boards) / sizeof(dnp_board), + driver_name:"ssv_dnp", + module:THIS_MODULE, + attach:dnp_attach, + detach:dnp_detach, + board_name:&dnp_boards[0].name, + /* only necessary for non-PnP devs */ + offset:sizeof(dnp_board),/* like ISA-PnP, PCI or PCMCIA. */ + num_names:sizeof(dnp_boards) / sizeof(dnp_board), }; -COMEDI_INITCLEANUP(driver_dnp); -static int dnp_dio_insn_bits( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data -); +COMEDI_INITCLEANUP(driver_dnp); -static int dnp_dio_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data -); +static int dnp_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); +static int dnp_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data); /* ------------------------------------------------------------------------- */ /* Attach is called by comedi core to configure the driver for a particular */ @@ -127,55 +115,59 @@ static int dnp_dio_insn_config( /* dev->board_ptr contains that address. */ /* ------------------------------------------------------------------------- */ -static int dnp_attach(comedi_device *dev,comedi_devconfig *it) +static int dnp_attach(comedi_device * dev, comedi_devconfig * it) { - comedi_subdevice *s; + comedi_subdevice *s; - printk("comedi%d: dnp: ",dev->minor); + printk("comedi%d: dnp: ", dev->minor); - /* Autoprobing: this should find out which board we have. Currently only */ - /* the 1486 board is supported and autoprobing is not implemented :-) */ - //dev->board_ptr = dnp_probe(dev); + /* Autoprobing: this should find out which board we have. Currently only */ + /* the 1486 board is supported and autoprobing is not implemented :-) */ + //dev->board_ptr = dnp_probe(dev); - /* Initialize the name of the board. We can use the "thisboard" macro now. */ - dev->board_name = thisboard->name; + /* Initialize the name of the board. We can use the "thisboard" macro now. */ + dev->board_name = thisboard->name; - /* Allocate the private structure area. alloc_private() is a convenient */ - /* macro defined in comedidev.h. */ - if(alloc_private(dev,sizeof(dnp_private_data))<0) return -ENOMEM; + /* Allocate the private structure area. alloc_private() is a convenient */ + /* macro defined in comedidev.h. */ + if (alloc_private(dev, sizeof(dnp_private_data)) < 0) + return -ENOMEM; - /* Allocate the subdevice structures. alloc_subdevice() is a convenient */ - /* macro defined in comedidev.h. */ + /* Allocate the subdevice structures. alloc_subdevice() is a convenient */ + /* macro defined in comedidev.h. */ - if(alloc_subdevices(dev, 1)<0) return -ENOMEM; + if (alloc_subdevices(dev, 1) < 0) + return -ENOMEM; - s=dev->subdevices+0; - /* digital i/o subdevice */ - s->type = COMEDI_SUBD_DIO; - s->subdev_flags = SDF_READABLE|SDF_WRITABLE; - s->n_chan = 20; - s->maxdata = 1; - s->range_table =& range_digital; - s->insn_bits = dnp_dio_insn_bits; - s->insn_config = dnp_dio_insn_config; + s = dev->subdevices + 0; + /* digital i/o subdevice */ + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 20; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = dnp_dio_insn_bits; + s->insn_config = dnp_dio_insn_config; - printk("attached\n"); + printk("attached\n"); - /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always - * allocated for the primary 8259, so we don't need to allocate them - * ourselves. */ + /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always + * allocated for the primary 8259, so we don't need to allocate them + * ourselves. */ - /* configure all ports as input (default) */ - outb(PAMR,CSCIR); outb(0x00,CSCDR); - outb(PBMR,CSCIR); outb(0x00,CSCDR); - outb(PCMR,CSCIR); outb((inb(CSCDR) & 0xAA),CSCDR); + /* configure all ports as input (default) */ + outb(PAMR, CSCIR); + outb(0x00, CSCDR); + outb(PBMR, CSCIR); + outb(0x00, CSCDR); + outb(PCMR, CSCIR); + outb((inb(CSCDR) & 0xAA), CSCDR); - return 1; + return 1; } - /* ------------------------------------------------------------------------- */ /* detach is called to deconfigure a device. It should deallocate the */ /* resources. This function is also called when _attach() fails, so it */ @@ -184,83 +176,73 @@ static int dnp_attach(comedi_device *dev,comedi_devconfig *it) /* deallocated automatically by the core. */ /* ------------------------------------------------------------------------- */ -static int dnp_detach(comedi_device *dev) +static int dnp_detach(comedi_device * dev) { - /* configure all ports as input (default) */ - outb(PAMR,CSCIR); outb(0x00,CSCDR); - outb(PBMR,CSCIR); outb(0x00,CSCDR); - outb(PCMR,CSCIR); outb((inb(CSCDR) & 0xAA),CSCDR); + /* configure all ports as input (default) */ + outb(PAMR, CSCIR); + outb(0x00, CSCDR); + outb(PBMR, CSCIR); + outb(0x00, CSCDR); + outb(PCMR, CSCIR); + outb((inb(CSCDR) & 0xAA), CSCDR); - /* announce that we are finished */ - printk("comedi%d: dnp: remove\n",dev->minor); + /* announce that we are finished */ + printk("comedi%d: dnp: remove\n", dev->minor); - return 0; + return 0; } - /* ------------------------------------------------------------------------- */ /* The insn_bits interface allows packed reading/writing of DIO channels. */ /* The comedi core can convert between insn_bits and insn_read/write, so you */ /* are able to use these instructions as well. */ /* ------------------------------------------------------------------------- */ -static int dnp_dio_insn_bits( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) +static int dnp_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - if (insn->n!=2) return -EINVAL; /* insn uses data[0] and data[1] */ - - /* The insn data is a mask in data[0] and the new data in data[1], each */ - /* channel cooresponding to a bit. */ - - /* Ports A and B are straight forward: each bit corresponds to an output */ - /* pin with the same order. Port C is different: bits 0...3 correspond to */ - /* bits 4...7 of the output register (PCDR). */ - - if(data[0]){ - - outb(PADR,CSCIR); - outb( - (inb(CSCDR) - & ~(u8)(data[0] & 0x0000FF)) - | (u8)(data[1] & 0x0000FF), - CSCDR - ); - - outb(PBDR,CSCIR); - outb( - (inb(CSCDR) - & ~(u8)((data[0] & 0x00FF00) >> 8)) - | (u8)((data[1] & 0x00FF00) >> 8), - CSCDR - ); - - outb(PCDR,CSCIR); - outb( - (inb(CSCDR) - & ~(u8)((data[0] & 0x0F0000) >> 12)) - | (u8)((data[1] & 0x0F0000) >> 12), - CSCDR - ); - } - - /* on return, data[1] contains the value of the digital input lines. */ - outb(PADR,CSCIR); - data[0] = inb(CSCDR); - outb(PBDR,CSCIR); - data[0] += inb(CSCDR) << 8; - outb(PCDR,CSCIR); - data[0] += ((inb(CSCDR) & 0xF0) << 12); - - return 2; + if (insn->n != 2) + return -EINVAL; /* insn uses data[0] and data[1] */ -} + /* The insn data is a mask in data[0] and the new data in data[1], each */ + /* channel cooresponding to a bit. */ + /* Ports A and B are straight forward: each bit corresponds to an output */ + /* pin with the same order. Port C is different: bits 0...3 correspond to */ + /* bits 4...7 of the output register (PCDR). */ + + if (data[0]) { + + outb(PADR, CSCIR); + outb((inb(CSCDR) + & ~(u8) (data[0] & 0x0000FF)) + | (u8) (data[1] & 0x0000FF), CSCDR); + + outb(PBDR, CSCIR); + outb((inb(CSCDR) + & ~(u8) ((data[0] & 0x00FF00) >> 8)) + | (u8) ((data[1] & 0x00FF00) >> 8), CSCDR); + + outb(PCDR, CSCIR); + outb((inb(CSCDR) + & ~(u8) ((data[0] & 0x0F0000) >> 12)) + | (u8) ((data[1] & 0x0F0000) >> 12), CSCDR); + } + + /* on return, data[1] contains the value of the digital input lines. */ + outb(PADR, CSCIR); + data[0] = inb(CSCDR); + outb(PBDR, CSCIR); + data[0] += inb(CSCDR) << 8; + outb(PCDR, CSCIR); + data[0] += ((inb(CSCDR) & 0xF0) << 12); + + return 2; + +} /* ------------------------------------------------------------------------- */ /* Configure the direction of the bidirectional digital i/o pins. chanspec */ @@ -268,62 +250,60 @@ static int dnp_dio_insn_bits( /* COMEDI_INPUT or COMEDI_OUTPUT. */ /* ------------------------------------------------------------------------- */ -static int dnp_dio_insn_config( - comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data -) +static int dnp_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - u8 register_buffer; - - int chan=CR_CHAN(insn->chanspec); /* reduces chanspec to lower 16 bits */ - - switch(data[0]) - { - case INSN_CONFIG_DIO_OUTPUT: - case INSN_CONFIG_DIO_INPUT: - break; - case INSN_CONFIG_DIO_QUERY: - data[1] = (inb(CSCDR) & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; - return insn->n; - break; - default: - return -EINVAL; - break; - } - /* Test: which port does the channel belong to? */ - - /* We have to pay attention with port C: this is the meaning of PCMR: */ - /* Bit in PCMR: 7 6 5 4 3 2 1 0 */ - /* Corresponding port C pin: d 3 d 2 d 1 d 0 d= don't touch */ - - if ((chan >= 0) && (chan <= 7)) { - /* this is port A */ - outb(PAMR,CSCIR); - } - else if ((chan >= 8) && (chan <= 15)) { - /* this is port B */ - chan -= 8; - outb(PBMR,CSCIR); - } - else if ((chan >= 16) && (chan <= 19)) { - /* this is port C; multiplication with 2 brings bits into correct */ - /* position for PCMR! */ - chan -= 16; - chan *= 2; - outb(PCMR,CSCIR); - } - else { return -EINVAL; } - - /* read 'old' direction of the port and set bits (out=1, in=0) */ - register_buffer = inb(CSCDR); - if (data[0] == COMEDI_OUTPUT) { register_buffer |= (1<chanspec); /* reduces chanspec to lower 16 bits */ + + switch (data[0]) { + case INSN_CONFIG_DIO_OUTPUT: + case INSN_CONFIG_DIO_INPUT: + break; + case INSN_CONFIG_DIO_QUERY: + data[1] = + (inb(CSCDR) & (1 << chan)) ? COMEDI_OUTPUT : + COMEDI_INPUT; + return insn->n; + break; + default: + return -EINVAL; + break; + } + /* Test: which port does the channel belong to? */ + + /* We have to pay attention with port C: this is the meaning of PCMR: */ + /* Bit in PCMR: 7 6 5 4 3 2 1 0 */ + /* Corresponding port C pin: d 3 d 2 d 1 d 0 d= don't touch */ + + if ((chan >= 0) && (chan <= 7)) { + /* this is port A */ + outb(PAMR, CSCIR); + } else if ((chan >= 8) && (chan <= 15)) { + /* this is port B */ + chan -= 8; + outb(PBMR, CSCIR); + } else if ((chan >= 16) && (chan <= 19)) { + /* this is port C; multiplication with 2 brings bits into correct */ + /* position for PCMR! */ + chan -= 16; + chan *= 2; + outb(PCMR, CSCIR); + } else { + return -EINVAL; + } + + /* read 'old' direction of the port and set bits (out=1, in=0) */ + register_buffer = inb(CSCDR); + if (data[0] == COMEDI_OUTPUT) { + register_buffer |= (1 << chan); + } else { + register_buffer &= ~(1 << chan); + } + outb(register_buffer, CSCDR); + + return 1; } - diff --git a/comedi/drivers/unioxx5.c b/comedi/drivers/unioxx5.c index 25e4589a..3dc865c8 100644 --- a/comedi/drivers/unioxx5.c +++ b/comedi/drivers/unioxx5.c @@ -47,447 +47,455 @@ Devices: [Fastwel] UNIOxx-5 (unioxx5), #define DRIVER_NAME "unioxx5" #define UNIOXX5_SIZE 0x10 -#define UNIOXX5_SUBDEV_BASE 0xA000 /* base addr of first subdev */ +#define UNIOXX5_SUBDEV_BASE 0xA000 /* base addr of first subdev */ #define UNIOXX5_SUBDEV_ODDS 0x400 /* modules types */ #define MODULE_DIGITAL 0 -#define MODULE_OUTPUT_MASK 0x80 /* analog input/output */ +#define MODULE_OUTPUT_MASK 0x80 /* analog input/output */ /* constants for digital i/o */ #define UNIOXX5_NUM_OF_CHANS 24 /* constants for analog i/o */ -#define TxBE 0x10 /* transmit buffer enable */ -#define RxCA 0x20 /* 1 receive character available */ -#define Rx2CA 0x40 /* 2 receive character available */ -#define Rx4CA 0x80 /* 4 receive character available */ +#define TxBE 0x10 /* transmit buffer enable */ +#define RxCA 0x20 /* 1 receive character available */ +#define Rx2CA 0x40 /* 2 receive character available */ +#define Rx4CA 0x80 /* 4 receive character available */ /* bytes mask errors */ -#define Rx2CA_ERR_MASK 0x04 /* 2 bytes receiving error */ -#define Rx4CA_ERR_MASK 0x08 /* 4 bytes receiving error */ +#define Rx2CA_ERR_MASK 0x04 /* 2 bytes receiving error */ +#define Rx4CA_ERR_MASK 0x08 /* 4 bytes receiving error */ /* channel modes */ -#define ALL_2_INPUT 0 /* config all digital channels to input */ -#define ALL_2_OUTPUT 1 /* config all digital channels to output */ +#define ALL_2_INPUT 0 /* config all digital channels to input */ +#define ALL_2_OUTPUT 1 /* config all digital channels to output */ /* 'private' structure for each subdevice */ typedef struct unioxx5_subd_priv { - int usp_iobase; - unsigned char usp_module_type[12]; /* 12 modules. each can be 70L or 73L */ - unsigned char usp_extra_data[12][4]; /* for saving previous written value for analog modules */ - unsigned char usp_prev_wr_val[3]; /* previous written value */ - unsigned char usp_prev_cn_val[3]; /* previous channel value */ + int usp_iobase; + unsigned char usp_module_type[12]; /* 12 modules. each can be 70L or 73L */ + unsigned char usp_extra_data[12][4]; /* for saving previous written value for analog modules */ + unsigned char usp_prev_wr_val[3]; /* previous written value */ + unsigned char usp_prev_cn_val[3]; /* previous channel value */ } unioxx5_subd_priv; -static int unioxx5_attach(comedi_device* dev, comedi_devconfig* it); -static int unioxx5_subdev_write(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data); -static int unioxx5_subdev_read(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data); -static int unioxx5_insn_config(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data); -static int unioxx5_detach(comedi_device* dev); -static int __unioxx5_subdev_init(comedi_subdevice* subdev, int subdev_iobase, int minor); -static int __unioxx5_digital_write(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor); -static int __unioxx5_digital_read(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor); +static int unioxx5_attach(comedi_device * dev, comedi_devconfig * it); +static int unioxx5_subdev_write(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data); +static int unioxx5_subdev_read(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data); +static int unioxx5_insn_config(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data); +static int unioxx5_detach(comedi_device * dev); +static int __unioxx5_subdev_init(comedi_subdevice * subdev, int subdev_iobase, + int minor); +static int __unioxx5_digital_write(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor); +static int __unioxx5_digital_read(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor); //static void __unioxx5_digital_config(unioxx5_subd_priv* usp, int mode); -static int __unioxx5_analog_write(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor); -static int __unioxx5_analog_read(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor); +static int __unioxx5_analog_write(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor); +static int __unioxx5_analog_read(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor); static int __unioxx5_define_chan_offset(int chan_num); -static void __unioxx5_analog_config(unioxx5_subd_priv* usp, int channel); - +static void __unioxx5_analog_config(unioxx5_subd_priv * usp, int channel); static comedi_driver unioxx5_driver = { - driver_name: DRIVER_NAME, - module: THIS_MODULE, - attach: unioxx5_attach, - detach: unioxx5_detach + driver_name:DRIVER_NAME, + module:THIS_MODULE, + attach:unioxx5_attach, + detach:unioxx5_detach }; COMEDI_INITCLEANUP(unioxx5_driver); -static int unioxx5_attach(comedi_device* dev, comedi_devconfig* it) +static int unioxx5_attach(comedi_device * dev, comedi_devconfig * it) { - int iobase, i, n_subd; - int id, num, ba; - - iobase = it->options[0]; - - dev->board_name = DRIVER_NAME; - dev->iobase = iobase; - iobase += UNIOXX5_SUBDEV_BASE; - - /* defining number of subdevices and getting they types (it must be 'g01') */ - for(i = n_subd = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) { - id = inb(ba + 0xE); - num = inb(ba + 0xF); - - if(id != 'g' || num != 1) - continue; - - n_subd++; - } - - /* unioxx5 can has from two to four subdevices */ - if(n_subd < 2) { - printk(KERN_ERR "your card must has at least 2 'g01' subdevices\n"); - return -1; - } - - if(alloc_subdevices(dev, n_subd) < 0) { - printk(KERN_ERR "out of memory\n"); - return -ENOMEM; - } - - /* initializing each of for same subdevices */ - for(i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) { - if(__unioxx5_subdev_init(&dev->subdevices[i], iobase, dev->minor) < 0) - return -1; - } - - printk("attached\n"); - return 0; + int iobase, i, n_subd; + int id, num, ba; + + iobase = it->options[0]; + + dev->board_name = DRIVER_NAME; + dev->iobase = iobase; + iobase += UNIOXX5_SUBDEV_BASE; + + /* defining number of subdevices and getting they types (it must be 'g01') */ + for (i = n_subd = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) { + id = inb(ba + 0xE); + num = inb(ba + 0xF); + + if (id != 'g' || num != 1) + continue; + + n_subd++; + } + + /* unioxx5 can has from two to four subdevices */ + if (n_subd < 2) { + printk(KERN_ERR + "your card must has at least 2 'g01' subdevices\n"); + return -1; + } + + if (alloc_subdevices(dev, n_subd) < 0) { + printk(KERN_ERR "out of memory\n"); + return -ENOMEM; + } + + /* initializing each of for same subdevices */ + for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) { + if (__unioxx5_subdev_init(&dev->subdevices[i], iobase, + dev->minor) < 0) + return -1; + } + + printk("attached\n"); + return 0; } -static int unioxx5_subdev_read(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data) +static int unioxx5_subdev_read(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data) { - unioxx5_subd_priv* usp = subdev->private; - int channel, type; - - channel = CR_CHAN(insn->chanspec); - type = usp->usp_module_type[channel / 2]; /* defining module type(analog or digital) */ - - if(type == MODULE_DIGITAL) { - if(!__unioxx5_digital_read(usp, data, channel, dev->minor)) - return -1; - } - else { - if(!__unioxx5_analog_read(usp, data, channel, dev->minor)) - return -1; - } - - return 1; + unioxx5_subd_priv *usp = subdev->private; + int channel, type; + + channel = CR_CHAN(insn->chanspec); + type = usp->usp_module_type[channel / 2]; /* defining module type(analog or digital) */ + + if (type == MODULE_DIGITAL) { + if (!__unioxx5_digital_read(usp, data, channel, dev->minor)) + return -1; + } else { + if (!__unioxx5_analog_read(usp, data, channel, dev->minor)) + return -1; + } + + return 1; } -static int unioxx5_subdev_write(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data) +static int unioxx5_subdev_write(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data) { - unioxx5_subd_priv* usp = subdev->private; - int channel, type; - - channel = CR_CHAN(insn->chanspec); - type = usp->usp_module_type[channel / 2]; /* defining module type(analog or digital) */ - - if(type == MODULE_DIGITAL) { - if(!__unioxx5_digital_write(usp, data, channel, dev->minor)) - return -1; - } - else { - if(!__unioxx5_analog_write(usp, data, channel, dev->minor)) - return -1; - } - - return 1; + unioxx5_subd_priv *usp = subdev->private; + int channel, type; + + channel = CR_CHAN(insn->chanspec); + type = usp->usp_module_type[channel / 2]; /* defining module type(analog or digital) */ + + if (type == MODULE_DIGITAL) { + if (!__unioxx5_digital_write(usp, data, channel, dev->minor)) + return -1; + } else { + if (!__unioxx5_analog_write(usp, data, channel, dev->minor)) + return -1; + } + + return 1; } /* for digital modules only */ -static int unioxx5_insn_config(comedi_device* dev, comedi_subdevice* subdev, - comedi_insn* insn, lsampl_t* data) +static int unioxx5_insn_config(comedi_device * dev, comedi_subdevice * subdev, + comedi_insn * insn, lsampl_t * data) { - int channel_offset, flags, channel = CR_CHAN(insn->chanspec), type; - unioxx5_subd_priv* usp = subdev->private; - int mask = 1 << (channel & 0x07); - - type = usp->usp_module_type[channel / 2]; - - if(type != MODULE_DIGITAL) { - printk(KERN_ERR "comedi%d: channel configuration accessible only for digital modules\n", dev->minor); - return -1; - } - - if((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { - printk(KERN_ERR "comedi%d: undefined channel %d. channel range is 0 .. 23\n", - dev->minor, channel); - return -1; - } - - /* gets previously written value */ - flags = usp->usp_prev_cn_val[channel_offset - 1]; - - switch(*data) { - case COMEDI_INPUT: - flags &= ~mask; - break; - case COMEDI_OUTPUT: - flags |= mask; - break; - default: - printk(KERN_ERR "comedi%d: unknown flag\n", dev->minor); - return -1; - } - - /* *\ - * sets channels buffer to 1(after this we are allowed to * - * change channel type on input or output) * - \* */ - outb(1, usp->usp_iobase + 0); - outb(flags, usp->usp_iobase + channel_offset); /* changes type of _one_ channel */ - outb(0, usp->usp_iobase + 0); /* sets channels bank to 0(allows directly input/output) */ - usp->usp_prev_cn_val[channel_offset - 1] = flags; /* saves written value */ - - return 0; + int channel_offset, flags, channel = CR_CHAN(insn->chanspec), type; + unioxx5_subd_priv *usp = subdev->private; + int mask = 1 << (channel & 0x07); + + type = usp->usp_module_type[channel / 2]; + + if (type != MODULE_DIGITAL) { + printk(KERN_ERR + "comedi%d: channel configuration accessible only for digital modules\n", + dev->minor); + return -1; + } + + if ((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { + printk(KERN_ERR + "comedi%d: undefined channel %d. channel range is 0 .. 23\n", + dev->minor, channel); + return -1; + } + + /* gets previously written value */ + flags = usp->usp_prev_cn_val[channel_offset - 1]; + + switch (*data) { + case COMEDI_INPUT: + flags &= ~mask; + break; + case COMEDI_OUTPUT: + flags |= mask; + break; + default: + printk(KERN_ERR "comedi%d: unknown flag\n", dev->minor); + return -1; + } + + /* *\ + * sets channels buffer to 1(after this we are allowed to * + * change channel type on input or output) * + \* */ + outb(1, usp->usp_iobase + 0); + outb(flags, usp->usp_iobase + channel_offset); /* changes type of _one_ channel */ + outb(0, usp->usp_iobase + 0); /* sets channels bank to 0(allows directly input/output) */ + usp->usp_prev_cn_val[channel_offset - 1] = flags; /* saves written value */ + + return 0; } -static int unioxx5_detach(comedi_device* dev) +static int unioxx5_detach(comedi_device * dev) { - int i; - comedi_subdevice* subdev; - unioxx5_subd_priv* usp; - - for(i = 0; i < dev->n_subdevices; i++) { - subdev = &dev->subdevices[i]; - usp = subdev->private; - release_region(usp->usp_iobase, UNIOXX5_SIZE); - kfree(subdev->private); - } - - return 0; + int i; + comedi_subdevice *subdev; + unioxx5_subd_priv *usp; + + for (i = 0; i < dev->n_subdevices; i++) { + subdev = &dev->subdevices[i]; + usp = subdev->private; + release_region(usp->usp_iobase, UNIOXX5_SIZE); + kfree(subdev->private); + } + + return 0; } /* initializing subdevice with given address */ -static int __unioxx5_subdev_init(comedi_subdevice* subdev, int subdev_iobase, int minor) +static int __unioxx5_subdev_init(comedi_subdevice * subdev, int subdev_iobase, + int minor) { - unioxx5_subd_priv* usp; - int i, to, ndef_flag = 0; - - if(!request_region(subdev_iobase, UNIOXX5_SIZE, DRIVER_NAME)) { - printk(KERN_ERR "comedi%d: I/O port conflict\n", minor); - return -EIO; - } - - if((usp = (unioxx5_subd_priv*)kzalloc(sizeof(*usp), GFP_KERNEL)) == NULL) { - printk(KERN_ERR "comedi%d: erorr! --> out of memory!\n", minor); - return -1; - } - - usp->usp_iobase = subdev_iobase; - printk("comedi%d: |", minor); - - /* defining modules types */ - for(i = 0; i < 12; i++) { - to = 10000; - - __unioxx5_analog_config(usp, i * 2); - outb(i + 1, subdev_iobase + 5); /* sends channel number to card */ - outb('H', subdev_iobase + 6); /* requests EEPROM world */ - while(!(inb(subdev_iobase + 0) & TxBE)); /* waits while writting will be allowed */ - outb(0, subdev_iobase + 6); - - /* waits while reading of two bytes will be allowed */ - while(!(inb(subdev_iobase + 0) & Rx2CA)) { - if(--to <= 0) { - ndef_flag = 1; - break; - } + unioxx5_subd_priv *usp; + int i, to, ndef_flag = 0; + + if (!request_region(subdev_iobase, UNIOXX5_SIZE, DRIVER_NAME)) { + printk(KERN_ERR "comedi%d: I/O port conflict\n", minor); + return -EIO; } - if(ndef_flag) { - usp->usp_module_type[i] = 0; - ndef_flag = 0; + if ((usp = (unioxx5_subd_priv *) kzalloc(sizeof(*usp), + GFP_KERNEL)) == NULL) { + printk(KERN_ERR "comedi%d: erorr! --> out of memory!\n", minor); + return -1; } - else - usp->usp_module_type[i] = inb(subdev_iobase + 6); - - printk(" [%d] 0x%02x |", i, usp->usp_module_type[i]); - comedi_udelay(1); - } - - printk("\n"); - - /* initial subdevice for digital or analog i/o */ - subdev->type = COMEDI_SUBD_DIO; - subdev->private = usp; - subdev->subdev_flags = SDF_READABLE | SDF_WRITABLE; - subdev->n_chan = UNIOXX5_NUM_OF_CHANS; - subdev->maxdata = 0xFFF; - subdev->range_table = &range_digital; - subdev->insn_read = unioxx5_subdev_read; - subdev->insn_write = unioxx5_subdev_write; - subdev->insn_config = unioxx5_insn_config; /* for digital modules only!!! */ - - printk("subdevice configured\n"); - - return 0; + + usp->usp_iobase = subdev_iobase; + printk("comedi%d: |", minor); + + /* defining modules types */ + for (i = 0; i < 12; i++) { + to = 10000; + + __unioxx5_analog_config(usp, i * 2); + outb(i + 1, subdev_iobase + 5); /* sends channel number to card */ + outb('H', subdev_iobase + 6); /* requests EEPROM world */ + while (!(inb(subdev_iobase + 0) & TxBE)) ; /* waits while writting will be allowed */ + outb(0, subdev_iobase + 6); + + /* waits while reading of two bytes will be allowed */ + while (!(inb(subdev_iobase + 0) & Rx2CA)) { + if (--to <= 0) { + ndef_flag = 1; + break; + } + } + + if (ndef_flag) { + usp->usp_module_type[i] = 0; + ndef_flag = 0; + } else + usp->usp_module_type[i] = inb(subdev_iobase + 6); + + printk(" [%d] 0x%02x |", i, usp->usp_module_type[i]); + comedi_udelay(1); + } + + printk("\n"); + + /* initial subdevice for digital or analog i/o */ + subdev->type = COMEDI_SUBD_DIO; + subdev->private = usp; + subdev->subdev_flags = SDF_READABLE | SDF_WRITABLE; + subdev->n_chan = UNIOXX5_NUM_OF_CHANS; + subdev->maxdata = 0xFFF; + subdev->range_table = &range_digital; + subdev->insn_read = unioxx5_subdev_read; + subdev->insn_write = unioxx5_subdev_write; + subdev->insn_config = unioxx5_insn_config; /* for digital modules only!!! */ + + printk("subdevice configured\n"); + + return 0; } -static int __unioxx5_digital_write(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor) +static int __unioxx5_digital_write(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor) { - int channel_offset, val; - int mask = 1 << (channel & 0x07); + int channel_offset, val; + int mask = 1 << (channel & 0x07); + + if ((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { + printk(KERN_ERR + "comedi%d: undefined channel %d. channel range is 0 .. 23\n", + minor, channel); + return 0; + } - if((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { - printk(KERN_ERR "comedi%d: undefined channel %d. channel range is 0 .. 23\n", minor, channel); - return 0; - } - - val = usp->usp_prev_wr_val[channel_offset - 1]; /* getting previous written value */ - - if(*data) - val |= mask; - else - val &= ~mask; - - outb(val, usp->usp_iobase + channel_offset); - usp->usp_prev_wr_val[channel_offset - 1] = val; /* saving new written value */ - - return 1; + val = usp->usp_prev_wr_val[channel_offset - 1]; /* getting previous written value */ + + if (*data) + val |= mask; + else + val &= ~mask; + + outb(val, usp->usp_iobase + channel_offset); + usp->usp_prev_wr_val[channel_offset - 1] = val; /* saving new written value */ + + return 1; } /* function for digital reading */ -static int __unioxx5_digital_read(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor) +static int __unioxx5_digital_read(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor) { - int channel_offset, mask = 1 << (channel & 0x07); + int channel_offset, mask = 1 << (channel & 0x07); + + if ((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { + printk(KERN_ERR + "comedi%d: undefined channel %d. channel range is 0 .. 23\n", + minor, channel); + return 0; + } - if((channel_offset = __unioxx5_define_chan_offset(channel)) < 0) { - printk(KERN_ERR "comedi%d: undefined channel %d. channel range is 0 .. 23\n", minor, channel); - return 0; - } + *data = inb(usp->usp_iobase + channel_offset); + *data &= mask; - *data = inb(usp->usp_iobase + channel_offset); - *data &= mask; + if (channel_offset > 1) + channel -= 2 << channel_offset; /* this operation is created for correct readed value to 0 or 1 */ - if(channel_offset > 1) - channel -= 2 << channel_offset; /* this operation is created for correct readed value to 0 or 1 */ - - *data >>= channel; - return 1; + *data >>= channel; + return 1; } -#if 0 /* not used? */ -static void __unioxx5_digital_config(unioxx5_subd_priv* usp, int mode) +#if 0 /* not used? */ +static void __unioxx5_digital_config(unioxx5_subd_priv * usp, int mode) { - int i, mask; + int i, mask; - mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00; - printk("COMEDI: mode = %d\n", mask); + mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00; + printk("COMEDI: mode = %d\n", mask); - outb(1, usp->usp_iobase + 0); + outb(1, usp->usp_iobase + 0); - for(i = 0; i < 3; i++) - outb(mask, usp->usp_iobase + i); + for (i = 0; i < 3; i++) + outb(mask, usp->usp_iobase + i); - outb(0, usp->usp_iobase + 0); + outb(0, usp->usp_iobase + 0); } #endif -static int __unioxx5_analog_write(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor) +static int __unioxx5_analog_write(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor) { - int module, i; + int module, i; - module = channel / 2; /* definig module number(0 .. 11) */ - i = (channel % 2) << 1; /* depends on type of channel (A or B) */ + module = channel / 2; /* definig module number(0 .. 11) */ + i = (channel % 2) << 1; /* depends on type of channel (A or B) */ - /* defining if given module can work on output */ - if(!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) { - printk(KERN_ERR "comedi%d: module in position %d with id 0x%0x is for input only!\n", - minor, module, usp->usp_module_type[module]); - return 0; - } - - __unioxx5_analog_config(usp, channel); - /* saving minor byte */ - usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF); - /* saving major byte */ - usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8); - - - //while(!((inb(usp->usp_iobase + 0)) & TxBE)); - outb(module + 1, usp->usp_iobase + 5); /* sending module number to card(1 .. 12) */ - outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */ - - /* sending for bytes to module(one byte per cycle iteration) */ - for(i = 0; i < 4; i++) { - while(!((inb(usp->usp_iobase + 0)) & TxBE)); /* waits while writting will be allowed */ - outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6); - } - - return 1; -} + /* defining if given module can work on output */ + if (!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) { + printk(KERN_ERR + "comedi%d: module in position %d with id 0x%0x is for input only!\n", + minor, module, usp->usp_module_type[module]); + return 0; + } -static int __unioxx5_analog_read(unioxx5_subd_priv* usp, lsampl_t* data, - int channel, int minor) -{ - int module_no, read_ch; - char control; + __unioxx5_analog_config(usp, channel); + /* saving minor byte */ + usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF); + /* saving major byte */ + usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8); - module_no = channel / 2; - read_ch = channel % 2; /* depend on type of channel (A or B) */ + //while(!((inb(usp->usp_iobase + 0)) & TxBE)); + outb(module + 1, usp->usp_iobase + 5); /* sending module number to card(1 .. 12) */ + outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */ - /* defining if given module can work on input */ - if(usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) { - printk(KERN_ERR "comedi%d: module in position %d with id 0x%02x is for output only", - minor, module_no, usp->usp_module_type[module_no]); - return 0; - } + /* sending for bytes to module(one byte per cycle iteration) */ + for (i = 0; i < 4; i++) { + while (!((inb(usp->usp_iobase + 0)) & TxBE)) ; /* waits while writting will be allowed */ + outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6); + } - __unioxx5_analog_config(usp, channel); - outb(module_no + 1, usp->usp_iobase + 5); /* sends module number to card(1 .. 12) */ - outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */ - control = inb(usp->usp_iobase); /* get control register byte */ + return 1; +} - /* waits while reading four bytes will be allowed */ - while(!((control = inb(usp->usp_iobase + 0)) & Rx4CA)); +static int __unioxx5_analog_read(unioxx5_subd_priv * usp, lsampl_t * data, + int channel, int minor) +{ + int module_no, read_ch; + char control; + + module_no = channel / 2; + read_ch = channel % 2; /* depend on type of channel (A or B) */ + + /* defining if given module can work on input */ + if (usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) { + printk(KERN_ERR + "comedi%d: module in position %d with id 0x%02x is for output only", + minor, module_no, usp->usp_module_type[module_no]); + return 0; + } - /* if four bytes readding error occurs - return 0(false) */ - if((control & Rx4CA_ERR_MASK)) { - printk("COMEDI: 4 bytes error\n"); - return 0; - } + __unioxx5_analog_config(usp, channel); + outb(module_no + 1, usp->usp_iobase + 5); /* sends module number to card(1 .. 12) */ + outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */ + control = inb(usp->usp_iobase); /* get control register byte */ - if(read_ch) - *data = inw(usp->usp_iobase + 6); /* channel B */ - else - *data = inw(usp->usp_iobase + 4); /* channel A */ + /* waits while reading four bytes will be allowed */ + while (!((control = inb(usp->usp_iobase + 0)) & Rx4CA)) ; - return 1; + /* if four bytes readding error occurs - return 0(false) */ + if ((control & Rx4CA_ERR_MASK)) { + printk("COMEDI: 4 bytes error\n"); + return 0; + } + + if (read_ch) + *data = inw(usp->usp_iobase + 6); /* channel B */ + else + *data = inw(usp->usp_iobase + 4); /* channel A */ + + return 1; } /* configure channels for analog i/o (even to output, odd to input) */ -static void __unioxx5_analog_config(unioxx5_subd_priv* usp, int channel) +static void __unioxx5_analog_config(unioxx5_subd_priv * usp, int channel) { - int chan_a, chan_b, conf, channel_offset; - - channel_offset = __unioxx5_define_chan_offset(channel); - conf = usp->usp_prev_cn_val[channel_offset - 1]; - chan_a = chan_b = 1; - - /* setting channel A and channel B mask */ - if(channel % 2 == 0) { - chan_a <<= channel & 0x07; - chan_b <<= (channel + 1) & 0x07; - } - else { - chan_a <<= (channel - 1) & 0x07; - chan_b <<= channel & 0x07; - } - - conf |= chan_a; /* even channel ot output */ - conf &= ~chan_b; /* odd channel to input */ - - outb(1, usp->usp_iobase + 0); - outb(conf, usp->usp_iobase + channel_offset); - outb(0, usp->usp_iobase + 0); - - usp->usp_prev_cn_val[channel_offset - 1] = conf; + int chan_a, chan_b, conf, channel_offset; + + channel_offset = __unioxx5_define_chan_offset(channel); + conf = usp->usp_prev_cn_val[channel_offset - 1]; + chan_a = chan_b = 1; + + /* setting channel A and channel B mask */ + if (channel % 2 == 0) { + chan_a <<= channel & 0x07; + chan_b <<= (channel + 1) & 0x07; + } else { + chan_a <<= (channel - 1) & 0x07; + chan_b <<= channel & 0x07; + } + + conf |= chan_a; /* even channel ot output */ + conf &= ~chan_b; /* odd channel to input */ + + outb(1, usp->usp_iobase + 0); + outb(conf, usp->usp_iobase + channel_offset); + outb(0, usp->usp_iobase + 0); + + usp->usp_prev_cn_val[channel_offset - 1] = conf; } /* *\ @@ -499,10 +507,9 @@ static void __unioxx5_analog_config(unioxx5_subd_priv* usp, int channel) static int __unioxx5_define_chan_offset(int chan_num) { - - - if(chan_num < 0 || chan_num > 23) - return -1; - return (chan_num >> 3) + 1; + if (chan_num < 0 || chan_num > 23) + return -1; + + return (chan_num >> 3) + 1; } diff --git a/comedi/drivers/usbdux.c b/comedi/drivers/usbdux.c index 4975059e..ca9c719d 100644 --- a/comedi/drivers/usbdux.c +++ b/comedi/drivers/usbdux.c @@ -164,10 +164,10 @@ sampling rate. If you sample two channels you get 4kHz and so on. #define NUMOFOUTBUFFERSFULL 5 // Number of in-URBs which receive the data: min=5 -#define NUMOFINBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr +#define NUMOFINBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr // Number of out-URBs which send the data: min=5 -#define NUMOFOUTBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr +#define NUMOFOUTBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr // Total number of usbdux devices #define NUMUSBDUX 16 @@ -187,28 +187,24 @@ sampling rate. If you sample two channels you get 4kHz and so on. // counter #define SUBDEV_COUNTER 3 - // number of retries to get the right dux command #define RETRIES 10 - ///////////////////////////////////////////// // comedi constants static const comedi_lrange range_usbdux_ai_range = { 4, { - BIP_RANGE( 4.096 ), - BIP_RANGE( 4.096/2 ), - UNI_RANGE( 4.096 ), - UNI_RANGE( 4.096/2 ) -} }; - + BIP_RANGE(4.096), + BIP_RANGE(4.096 / 2), + UNI_RANGE(4.096), + UNI_RANGE(4.096 / 2) + } +}; static const comedi_lrange range_usbdux_ao_range = { 2, { - BIP_RANGE( 4.096 ), - UNI_RANGE( 4.096 ), -} }; - - - + BIP_RANGE(4.096), + UNI_RANGE(4.096), + } +}; /* * private structure of one subdevice @@ -222,16 +218,16 @@ typedef struct { // is it associated with a subdevice? int probed; // pointer to the usb-device - struct usb_device *usbdev; + struct usb_device *usbdev; // actual number of in-buffers int numOfInBuffers; // actual number of out-buffers int numOfOutBuffers; - // ISO-transfer handling: buffers - struct urb **urbIn; + // ISO-transfer handling: buffers + struct urb **urbIn; struct urb **urbOut; // input buffer for the ISO-transfer - int16_t *inBuffer; + int16_t *inBuffer; // input buffer for single insn int16_t *insnBuffer; // output buffer for single DA outputs @@ -240,7 +236,7 @@ typedef struct { int ifnum; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) // interface structure in 2.6 - struct usb_interface * interface; + struct usb_interface *interface; #endif // comedi device for the interrupt context comedi_device *comedidev; @@ -270,8 +266,6 @@ typedef struct { struct semaphore sem; } usbduxsub_t; - - // The pointer to the private usb-data of the driver // is also the private data for the comedi-device. // This has to be global as the usb subsystem needs @@ -281,91 +275,79 @@ typedef struct { // initialised before comedi can access it. static usbduxsub_t usbduxsub[NUMUSBDUX]; - - - -static DECLARE_MUTEX (start_stop_sem); - - - +static DECLARE_MUTEX(start_stop_sem); // Stops the data acquision // It should be safe to call this function from any context -static int usbduxsub_unlink_InURBs(usbduxsub_t* usbduxsub_tmp) { - int i=0; +static int usbduxsub_unlink_InURBs(usbduxsub_t * usbduxsub_tmp) +{ + int i = 0; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) - int j=0; + int j = 0; #endif - int err=0; + int err = 0; if (usbduxsub_tmp && usbduxsub_tmp->urbIn) { - for (i=0; i < usbduxsub_tmp->numOfInBuffers; i++) { + for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) { if (usbduxsub_tmp->urbIn[i]) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) - j=usb_unlink_urb(usbduxsub_tmp->urbIn[i]); - if (j<0) { - err=j; - } + j = usb_unlink_urb(usbduxsub_tmp->urbIn[i]); + if (j < 0) { + err = j; + } #else // We wait here until all transfers // have been cancelled. - usb_kill_urb(usbduxsub_tmp->urbIn[i]); + usb_kill_urb(usbduxsub_tmp->urbIn[i]); #endif } #ifdef NOISY_DUX_DEBUGBUG printk("comedi: usbdux: unlinked InURB %d, err=%d\n", - i,err); + i, err); #endif } } return err; } - - /* This will stop a running acquisition operation */ // Is called from within this driver from both the // interrupt context and from comedi -static int usbdux_ai_stop(usbduxsub_t* this_usbduxsub, - int do_unlink) +static int usbdux_ai_stop(usbduxsub_t * this_usbduxsub, int do_unlink) { - int ret=0; + int ret = 0; if (!this_usbduxsub) { printk("comedi?: usbdux_ai_stop: this_usbduxsub=NULL!\n"); return -EFAULT; } - #ifdef NOISY_DUX_DEBUGBUG printk("comedi: usbdux_ai_stop\n"); #endif if (do_unlink) { // stop aquistion - ret=usbduxsub_unlink_InURBs(this_usbduxsub); + ret = usbduxsub_unlink_InURBs(this_usbduxsub); } - this_usbduxsub->ai_cmd_running=0; + this_usbduxsub->ai_cmd_running = 0; return ret; } - - // This will cancel a running acquisition operation. // This is called by comedi but never from inside the // driver. -static int usbdux_ai_cancel(comedi_device *dev, - comedi_subdevice *s) +static int usbdux_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - usbduxsub_t* this_usbduxsub; - int res=0; + usbduxsub_t *this_usbduxsub; + int res = 0; // force unlink of all urbs #ifdef NOISY_DUX_DEBUGBUG printk("comedi: usbdux_ai_cancel\n"); #endif - this_usbduxsub=dev->private; + this_usbduxsub = dev->private; if (!this_usbduxsub) { printk("comedi: usbdux_ai_cancel: this_usbduxsub=NULL\n"); return -EFAULT; @@ -377,14 +359,11 @@ static int usbdux_ai_cancel(comedi_device *dev, return -ENODEV; } // unlink only if the urb really has been submitted - res=usbdux_ai_stop(this_usbduxsub,this_usbduxsub->ai_cmd_running); + res = usbdux_ai_stop(this_usbduxsub, this_usbduxsub->ai_cmd_running); up(&this_usbduxsub->sem); return res; } - - - // analogue IN // interrupt service routine #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) @@ -393,8 +372,8 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb) static void usbduxsub_ai_IsocIrq(struct urb *urb PT_REGS_ARG) #endif { - int i,err,n; - usbduxsub_t* this_usbduxsub; + int i, err, n; + usbduxsub_t *this_usbduxsub; comedi_device *this_comedidev; comedi_subdevice *s; @@ -404,57 +383,52 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb PT_REGS_ARG) printk("comedi_: usbdux_: ao int-handler called with urb=NULL!\n"); return; } - // the context variable points to the subdevice - this_comedidev=urb->context; + this_comedidev = urb->context; if (unlikely(!this_comedidev)) { printk("comedi_: usbdux_: BUG! urb context is a NULL pointer!\n"); return; } - // the private structure of the subdevice is usbduxsub_t - this_usbduxsub=this_comedidev->private; + this_usbduxsub = this_comedidev->private; if (unlikely(!this_usbduxsub)) { printk("comedi_: usbdux_: BUG! private of comedi subdev is a NULL pointer!\n"); return; } - // subdevice which is the AD converter - s=this_comedidev->subdevices + SUBDEV_AD; + s = this_comedidev->subdevices + SUBDEV_AD; // first we test if something unusual has just happened switch (urb->status) { - case 0: + case 0: // copy the result in the transfer buffer memcpy(this_usbduxsub->inBuffer, - urb->transfer_buffer, - SIZEINBUF); + urb->transfer_buffer, SIZEINBUF); break; - case -EILSEQ: + case -EILSEQ: // error in the ISOchronous data // we don't copy the data into the transfer buffer // and recycle the last data byte #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbdux: CRC error in ISO IN stream.\n", - this_usbduxsub->comedidev->minor); + this_usbduxsub->comedidev->minor); #endif break; // happens after an unlink command - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: case -ECONNABORTED: if (this_usbduxsub->ai_cmd_running) { // we are still running a command // tell this comedi s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); // stop the transfer w/o unlink - usbdux_ai_stop(this_usbduxsub,0); + usbdux_ai_stop(this_usbduxsub, 0); } return; @@ -462,17 +436,15 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb PT_REGS_ARG) default: // pass error to comedi if we are really running a command if (this_usbduxsub->ai_cmd_running) { - printk("Non-zero urb status received in ai intr context: %d\n", - urb->status); + printk("Non-zero urb status received in ai intr context: %d\n", urb->status); s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); // don't do an unlink here - usbdux_ai_stop(this_usbduxsub,0); + usbdux_ai_stop(this_usbduxsub, 0); } return; - } + } // at this point we are reasonably sure that nothing dodgy has happened // are we running a command? @@ -486,113 +458,99 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb PT_REGS_ARG) urb->dev = this_usbduxsub->usbdev; // resubmit the urb - err=USB_SUBMIT_URB(urb); - if (unlikely(err<0)) { - printk("comedi_: usbdux_: urb resubmit failed in int-context! err=%d ", - err); - if (err==-EL2NSYNC) { + err = USB_SUBMIT_URB(urb); + if (unlikely(err < 0)) { + printk("comedi_: usbdux_: urb resubmit failed in int-context! err=%d ", err); + if (err == -EL2NSYNC) { printk("--> buggy USB host controller or bug in IRQ handler!\n"); } else { printk("\n"); } s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); // don't do an unlink here - usbdux_ai_stop(this_usbduxsub,0); + usbdux_ai_stop(this_usbduxsub, 0); return; } this_usbduxsub->ai_counter--; - if (likely(this_usbduxsub->ai_counter>0)) { + if (likely(this_usbduxsub->ai_counter > 0)) { return; } - // timer zero, transfer measurements to comedi - this_usbduxsub->ai_counter=this_usbduxsub->ai_timer; + this_usbduxsub->ai_counter = this_usbduxsub->ai_timer; // test, if we transmit only a fixed number of samples if (!(this_usbduxsub->ai_continous)) { // not continous, fixed number of samples this_usbduxsub->ai_sample_count--; // all samples received? - if (this_usbduxsub->ai_sample_count<0){ + if (this_usbduxsub->ai_sample_count < 0) { // prevent a resubmit next time - usbdux_ai_stop(this_usbduxsub, - 0); + usbdux_ai_stop(this_usbduxsub, 0); // say comedi that the acquistion is over s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); return; } } - - // get the data from the USB bus and hand it over + // get the data from the USB bus and hand it over // to comedi - n=s->async->cmd.chanlist_len; - for(i=0;iasync->cmd.chanlist_len; + for (i = 0; i < n; i++) { // transfer data - if (CR_RANGE(s->async->cmd.chanlist[i])<=1) { + if (CR_RANGE(s->async->cmd.chanlist[i]) <= 1) { comedi_buf_put (s->async, - le16_to_cpu(this_usbduxsub->inBuffer[i])^0x800); + le16_to_cpu(this_usbduxsub-> + inBuffer[i]) ^ 0x800); } else { comedi_buf_put (s->async, - le16_to_cpu(this_usbduxsub->inBuffer[i])); + le16_to_cpu(this_usbduxsub->inBuffer[i])); } } // tell comedi that data is there - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); } - - - - - -static int usbduxsub_unlink_OutURBs(usbduxsub_t* usbduxsub_tmp) { - int i=0; +static int usbduxsub_unlink_OutURBs(usbduxsub_t * usbduxsub_tmp) +{ + int i = 0; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) - int j=0; + int j = 0; #endif - int err=0; + int err = 0; if (usbduxsub_tmp && usbduxsub_tmp->urbOut) { - for (i=0; i < usbduxsub_tmp->numOfOutBuffers; i++) { + for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) { if (usbduxsub_tmp->urbOut[i]) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) - j=usb_unlink_urb(usbduxsub_tmp->urbOut[i]); - if (jurbOut[i]); + if (j < err) { + err = j; + } #else - usb_kill_urb(usbduxsub_tmp->urbOut[i]); + usb_kill_urb(usbduxsub_tmp->urbOut[i]); #endif } #ifdef NOISY_DUX_DEBUGBUG printk("comedi: usbdux: unlinked OutURB %d: res=%d\n", - i,err); + i, err); #endif } } return err; } - - - - /* This will cancel a running acquisition operation * in any context. */ -static int usbdux_ao_stop(usbduxsub_t* this_usbduxsub, - int do_unlink) { - int ret=0; +static int usbdux_ao_stop(usbduxsub_t * this_usbduxsub, int do_unlink) +{ + int ret = 0; if (!this_usbduxsub) { #ifdef NOISY_DUX_DEBUGBUG @@ -600,27 +558,24 @@ static int usbdux_ao_stop(usbduxsub_t* this_usbduxsub, #endif return -EFAULT; } - #ifdef NOISY_DUX_DEBUGBUG printk("comedi: usbdux_ao_cancel\n"); #endif if (do_unlink) { - ret=usbduxsub_unlink_OutURBs(this_usbduxsub); + ret = usbduxsub_unlink_OutURBs(this_usbduxsub); } - this_usbduxsub->ao_cmd_running=0; + this_usbduxsub->ao_cmd_running = 0; return ret; } - - // force unlink // is called by comedi -static int usbdux_ao_cancel(comedi_device *dev, - comedi_subdevice *s) { - usbduxsub_t* this_usbduxsub=dev->private; - int res=0; +static int usbdux_ao_cancel(comedi_device * dev, comedi_subdevice * s) +{ + usbduxsub_t *this_usbduxsub = dev->private; + int res = 0; if (!this_usbduxsub) { printk("comedi: usbdux_ao_cancel: this_usbduxsub=NULL\n"); @@ -633,27 +588,21 @@ static int usbdux_ao_cancel(comedi_device *dev, return -ENODEV; } // unlink only if it is really running - res=usbdux_ao_stop(this_usbduxsub,this_usbduxsub->ao_cmd_running); + res = usbdux_ao_stop(this_usbduxsub, this_usbduxsub->ao_cmd_running); up(&this_usbduxsub->sem); return res; } - - - - - - - - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -static void usbduxsub_ao_IsocIrq(struct urb *urb) { +static void usbduxsub_ao_IsocIrq(struct urb *urb) +{ #else -static void usbduxsub_ao_IsocIrq(struct urb *urb PT_REGS_ARG) { +static void usbduxsub_ao_IsocIrq(struct urb *urb PT_REGS_ARG) +{ #endif - int i,ret; - int8_t* datap; - usbduxsub_t* this_usbduxsub; + int i, ret; + int8_t *datap; + usbduxsub_t *this_usbduxsub; comedi_device *this_comedidev; comedi_subdevice *s; @@ -661,111 +610,100 @@ static void usbduxsub_ao_IsocIrq(struct urb *urb PT_REGS_ARG) { printk("comedi_: usbdux_: ao urb handler called with NULL ptr.\n"); return; } - // the context variable points to the subdevice - this_comedidev=urb->context; + this_comedidev = urb->context; if (!this_comedidev) { printk("comedi_: usbdux_: ao urb int-context is a NULL pointer.\n"); return; } - // the private structure of the subdevice is usbduxsub_t - this_usbduxsub=this_comedidev->private; + this_usbduxsub = this_comedidev->private; if (!this_usbduxsub) { printk("comedi_: usbdux_: private data structure of ao subdev is NULL p.\n"); return; } - s=this_comedidev->subdevices + SUBDEV_DA; + s = this_comedidev->subdevices + SUBDEV_DA; switch (urb->status) { - case 0: - /* success */ - break; + case 0: + /* success */ + break; // after an unlink command, unplug, ... etc // no unlink needed here. Already shutting down. - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: case -ECONNABORTED: if (this_usbduxsub->ao_cmd_running) { s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, - s); - usbdux_ao_stop(this_usbduxsub,0); + comedi_event(this_usbduxsub->comedidev, s); + usbdux_ao_stop(this_usbduxsub, 0); } return; // a real error - default: + default: if (this_usbduxsub->ao_cmd_running) { - printk("comedi_: usbdux_: Non-zero urb status received in ao intr context: %d\n", - urb->status); + printk("comedi_: usbdux_: Non-zero urb status received in ao intr context: %d\n", urb->status); s->async->events |= COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, - s); - // we do an unlink if we are in the high speed mode - usbdux_ao_stop(this_usbduxsub,0); + comedi_event(this_usbduxsub->comedidev, s); + // we do an unlink if we are in the high speed mode + usbdux_ao_stop(this_usbduxsub, 0); } return; - } + } // are we actually running? if (!(this_usbduxsub->ao_cmd_running)) { return; } - // normal operation: executing a command in this subdevice this_usbduxsub->ao_counter--; - if (this_usbduxsub->ao_counter<=0) { + if (this_usbduxsub->ao_counter <= 0) { // timer zero - this_usbduxsub->ao_counter=this_usbduxsub->ao_timer; + this_usbduxsub->ao_counter = this_usbduxsub->ao_timer; // handle non continous aquisition if (!(this_usbduxsub->ao_continous)) { // fixed number of samples this_usbduxsub->ao_sample_count--; - if (this_usbduxsub->ao_sample_count<0){ + if (this_usbduxsub->ao_sample_count < 0) { // all samples transmitted - usbdux_ao_stop(this_usbduxsub, - 0); + usbdux_ao_stop(this_usbduxsub, 0); s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); // no resubmit of the urb return; } } - // transmit data to the USB bus - ((uint8_t*)(urb->transfer_buffer))[0]= + ((uint8_t *) (urb->transfer_buffer))[0] = s->async->cmd.chanlist_len; - for(i=0;iasync->cmd.chanlist_len;i++) { + for (i = 0; i < s->async->cmd.chanlist_len; i++) { sampl_t temp; - if (i>=NUMOUTCHANNELS) { + if (i >= NUMOUTCHANNELS) { break; } // pointer to the DA - datap=&(((int8_t*)urb->transfer_buffer)[i*3+1]); + datap = &(((int8_t *) urb->transfer_buffer)[i * 3 + 1]); // get the data from comedi - ret=comedi_buf_get - (s->async, &temp); - datap[0]=temp; - datap[1]=temp >> 8; - datap[2]=this_usbduxsub->dac_commands[i]; + ret = comedi_buf_get(s->async, &temp); + datap[0] = temp; + datap[1] = temp >> 8; + datap[2] = this_usbduxsub->dac_commands[i]; /*printk("data[0]=%x, data[1]=%x, data[2]=%x\n", - datap[0],datap[1],datap[2]);*/ - if (ret<0) { + datap[0],datap[1],datap[2]); */ + if (ret < 0) { printk("comedi: usbdux: buffer underflow\n"); s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_OVERFLOW; } - // transmit data to comedi - s->async->events |= COMEDI_CB_BLOCK; - comedi_event(this_usbduxsub->comedidev, - s); + // transmit data to comedi + s->async->events |= COMEDI_CB_BLOCK; + comedi_event(this_usbduxsub->comedidev, s); } } urb->transfer_buffer_length = SIZEOUTBUF; @@ -774,71 +712,58 @@ static void usbduxsub_ao_IsocIrq(struct urb *urb PT_REGS_ARG) { if (this_usbduxsub->ao_cmd_running) { if (this_usbduxsub->high_speed) { // uframes - urb->interval=8; + urb->interval = 8; } else { // frames - urb->interval=1; + urb->interval = 1; } urb->number_of_packets = 1; urb->iso_frame_desc[0].offset = 0; urb->iso_frame_desc[0].length = SIZEOUTBUF; urb->iso_frame_desc[0].status = 0; - if ((ret=USB_SUBMIT_URB(urb))<0) { + if ((ret = USB_SUBMIT_URB(urb)) < 0) { printk("comedi_: usbdux_: ao urb resubm failed in int-cont."); - printk("ret=%d",ret); - if (ret==EL2NSYNC) { + printk("ret=%d", ret); + if (ret == EL2NSYNC) { printk("--> buggy USB host controller or bug in IRQ handling!\n"); } else { printk("\n"); } s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxsub->comedidev, - s); + comedi_event(this_usbduxsub->comedidev, s); // don't do an unlink here - usbdux_ao_stop(this_usbduxsub,0); + usbdux_ao_stop(this_usbduxsub, 0); } } } - - - - - - - - - - - -static int usbduxsub_start(usbduxsub_t* usbduxsub) { - int errcode=0; +static int usbduxsub_start(usbduxsub_t * usbduxsub) +{ + int errcode = 0; uint8_t local_transfer_buffer[16]; if (usbduxsub->probed) { // 7f92 to zero - local_transfer_buffer[0]=0; - errcode=USB_CONTROL_MSG - (usbduxsub->usbdev, - // create a pipe for a control transfer - usb_sndctrlpipe(usbduxsub->usbdev,0), - // bRequest, "Firmware" - USBDUXSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // Value - USBDUXSUB_CPUCS, - // Index - 0x0000, - // address of the transfer buffer - local_transfer_buffer, - // Length - 1, - // Timeout - EZTIMEOUT - ); - if (errcode<0) { + local_transfer_buffer[0] = 0; + errcode = USB_CONTROL_MSG(usbduxsub->usbdev, + // create a pipe for a control transfer + usb_sndctrlpipe(usbduxsub->usbdev, 0), + // bRequest, "Firmware" + USBDUXSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // Value + USBDUXSUB_CPUCS, + // Index + 0x0000, + // address of the transfer buffer + local_transfer_buffer, + // Length + 1, + // Timeout + EZTIMEOUT); + if (errcode < 0) { printk("comedi_: usbdux_: control msg failed (start)\n"); return errcode; } @@ -846,34 +771,30 @@ static int usbduxsub_start(usbduxsub_t* usbduxsub) { return 0; } - - - -static int usbduxsub_stop(usbduxsub_t* usbduxsub) { - int errcode=0; +static int usbduxsub_stop(usbduxsub_t * usbduxsub) +{ + int errcode = 0; uint8_t local_transfer_buffer[16]; if (usbduxsub->probed) { // 7f92 to one - local_transfer_buffer[0]=1; - errcode=USB_CONTROL_MSG + local_transfer_buffer[0] = 1; + errcode = USB_CONTROL_MSG (usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev,0), - // bRequest, "Firmware" - USBDUXSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // Value - USBDUXSUB_CPUCS, - // Index - 0x0000, - local_transfer_buffer, - // Length - 1, - // Timeout - EZTIMEOUT - ); - if (errcode<0) { + usb_sndctrlpipe(usbduxsub->usbdev, 0), + // bRequest, "Firmware" + USBDUXSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // Value + USBDUXSUB_CPUCS, + // Index + 0x0000, local_transfer_buffer, + // Length + 1, + // Timeout + EZTIMEOUT); + if (errcode < 0) { printk("comedi_: usbdux: control msg failed (stop)\n"); return errcode; } @@ -881,46 +802,40 @@ static int usbduxsub_stop(usbduxsub_t* usbduxsub) { return 0; } - - - - -static int usbduxsub_upload(usbduxsub_t* usbduxsub, - uint8_t* local_transfer_buffer, - unsigned int startAddr, - unsigned int len) { +static int usbduxsub_upload(usbduxsub_t * usbduxsub, + uint8_t * local_transfer_buffer, + unsigned int startAddr, unsigned int len) +{ int errcode; if (usbduxsub->probed) { #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbdux: uploading %d bytes", - usbduxsub->comedidev->minor,len); + usbduxsub->comedidev->minor, len); printk(" to addr %d, first byte=%d.\n", - startAddr, - local_transfer_buffer[0]); + startAddr, local_transfer_buffer[0]); #endif - errcode=USB_CONTROL_MSG + errcode = USB_CONTROL_MSG (usbduxsub->usbdev, - usb_sndctrlpipe(usbduxsub->usbdev, 0), - // brequest, firmware - USBDUXSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // value - startAddr, - // index - 0x0000, - // our local safe buffer - local_transfer_buffer, - // length - len, - // timeout - EZTIMEOUT - ); + usb_sndctrlpipe(usbduxsub->usbdev, 0), + // brequest, firmware + USBDUXSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // value + startAddr, + // index + 0x0000, + // our local safe buffer + local_transfer_buffer, + // length + len, + // timeout + EZTIMEOUT); #ifdef NOISY_DUX_DEBUGBUG - printk("comedi_: usbdux: result=%d\n",errcode); + printk("comedi_: usbdux: result=%d\n", errcode); #endif - if (errcode<0) { + if (errcode < 0) { printk("comedi_: usbdux: uppload failed\n"); return errcode; } @@ -928,213 +843,198 @@ static int usbduxsub_upload(usbduxsub_t* usbduxsub, // no device on the bus for this index return -EFAULT; } -return 0; + return 0; } - - - - -int firmwareUpload(usbduxsub_t* usbduxsub, - uint8_t* firmwareBinary, - int sizeFirmware) { +int firmwareUpload(usbduxsub_t * usbduxsub, + uint8_t * firmwareBinary, int sizeFirmware) +{ int ret; if (!firmwareBinary) { return 0; } - ret=usbduxsub_stop(usbduxsub); - if (ret<0) { - printk("comedi_: usbdux: can not stop firmware\n" - ); + ret = usbduxsub_stop(usbduxsub); + if (ret < 0) { + printk("comedi_: usbdux: can not stop firmware\n"); return ret; } - ret=usbduxsub_upload(usbduxsub, - firmwareBinary, - 0, - sizeFirmware); - if (ret<0) { - printk("comedi_: usbdux: firmware upload failed\n" - ); + ret = usbduxsub_upload(usbduxsub, firmwareBinary, 0, sizeFirmware); + if (ret < 0) { + printk("comedi_: usbdux: firmware upload failed\n"); return ret; } - ret=usbduxsub_start(usbduxsub); - if (ret<0) { - printk("comedi_: usbdux: can not start firmware\n" - ); + ret = usbduxsub_start(usbduxsub); + if (ret < 0) { + printk("comedi_: usbdux: can not start firmware\n"); return ret; } return 0; } - - -int usbduxsub_submit_InURBs(usbduxsub_t* usbduxsub) { - int i,errFlag; +int usbduxsub_submit_InURBs(usbduxsub_t * usbduxsub) +{ + int i, errFlag; if (!usbduxsub) { return -EFAULT; } /* Submit all URBs and start the transfer on the bus */ - for (i=0; i < usbduxsub->numOfInBuffers; i++) { + for (i = 0; i < usbduxsub->numOfInBuffers; i++) { // in case of a resubmission after an unlink... - usbduxsub->urbIn[i]->interval=usbduxsub->ai_interval; - usbduxsub->urbIn[i]->context=usbduxsub->comedidev; + usbduxsub->urbIn[i]->interval = usbduxsub->ai_interval; + usbduxsub->urbIn[i]->context = usbduxsub->comedidev; usbduxsub->urbIn[i]->dev = usbduxsub->usbdev; usbduxsub->urbIn[i]->status = 0; usbduxsub->urbIn[i]->transfer_flags = URB_ISO_ASAP; #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux: submitting in-urb[%d]: %p,%p intv=%d\n", - usbduxsub->comedidev->minor, - i, - (usbduxsub->urbIn[i]->context), - (usbduxsub->urbIn[i]->dev), - (usbduxsub->urbIn[i]->interval)); + printk("comedi%d: usbdux: submitting in-urb[%d]: %p,%p intv=%d\n", usbduxsub->comedidev->minor, i, (usbduxsub->urbIn[i]->context), (usbduxsub->urbIn[i]->dev), (usbduxsub->urbIn[i]->interval)); #endif - errFlag = USB_SUBMIT_URB - (usbduxsub->urbIn[i]); + errFlag = USB_SUBMIT_URB(usbduxsub->urbIn[i]); if (errFlag) { printk("comedi_: usbdux: ai: "); - printk("USB_SUBMIT_URB(%d)",i); - printk(" error %d\n",errFlag); + printk("USB_SUBMIT_URB(%d)", i); + printk(" error %d\n", errFlag); return errFlag; } } return 0; } - - - -int usbduxsub_submit_OutURBs(usbduxsub_t* usbduxsub) { - int i,errFlag; +int usbduxsub_submit_OutURBs(usbduxsub_t * usbduxsub) +{ + int i, errFlag; if (!usbduxsub) { return -EFAULT; } - for (i=0; i < usbduxsub->numOfOutBuffers; i++) { + for (i = 0; i < usbduxsub->numOfOutBuffers; i++) { #ifdef NOISY_DUX_DEBUGBUG - printk("comedi_: usbdux: submitting out-urb[%d]\n",i); + printk("comedi_: usbdux: submitting out-urb[%d]\n", i); #endif // in case of a resubmission after an unlink... - usbduxsub->urbOut[i]->context=usbduxsub->comedidev; + usbduxsub->urbOut[i]->context = usbduxsub->comedidev; usbduxsub->urbOut[i]->dev = usbduxsub->usbdev; usbduxsub->urbOut[i]->status = 0; usbduxsub->urbOut[i]->transfer_flags = URB_ISO_ASAP; - errFlag = USB_SUBMIT_URB - (usbduxsub->urbOut[i]); + errFlag = USB_SUBMIT_URB(usbduxsub->urbOut[i]); if (errFlag) { printk("comedi_: usbdux: ao: "); - printk("USB_SUBMIT_URB(%d)",i); - printk(" error %d\n",errFlag); + printk("USB_SUBMIT_URB(%d)", i); + printk(" error %d\n", errFlag); return errFlag; } } return 0; } - - - - -static int usbdux_ai_cmdtest(comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +static int usbdux_ai_cmdtest(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - int err=0,tmp,i; + int err = 0, tmp, i; unsigned int tmpTimer; - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; if (!(this_usbduxsub->probed)) { return -ENODEV; } - #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux_ai_cmdtest\n",dev->minor); + printk("comedi%d: usbdux_ai_cmdtest\n", dev->minor); #endif /* make sure triggers are valid */ // Only immediate triggers are allowed - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_INT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; // trigger should happen timed - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; // start a new _scan_ with a timer cmd->scan_begin_src &= TRIG_TIMER; - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; // scanning is continous - tmp=cmd->convert_src; + tmp = cmd->convert_src; cmd->convert_src &= TRIG_NOW; - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; // issue a trigger when scan is finished and start a new scan - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; // trigger at the end of count events or not, stop condition or not - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_FOLLOW && - cmd->scan_begin_src!=TRIG_EXT && - cmd->scan_begin_src!=TRIG_TIMER)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->scan_begin_src==TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { if (this_usbduxsub->high_speed) { // In high speed mode microframes are possible. // However, during one microframe we can roughly // sample one channel. Thus, the more channels // are in the channel list the more time we need. - i=1; + i = 1; // find a power of 2 for the number of channels - while (i<(cmd->chanlist_len)) { - i=i*2; + while (i < (cmd->chanlist_len)) { + i = i * 2; } - if(cmd->scan_begin_arg<(1000000/8*i)){ - cmd->scan_begin_arg=1000000/8*i; + if (cmd->scan_begin_arg < (1000000 / 8 * i)) { + cmd->scan_begin_arg = 1000000 / 8 * i; err++; } // now calc the real sampling rate with all the rounding errors - tmpTimer = ((unsigned int)(cmd->scan_begin_arg/125000))*125000; + tmpTimer = + ((unsigned int)(cmd->scan_begin_arg / 125000)) * + 125000; if (cmd->scan_begin_arg != tmpTimer) { cmd->scan_begin_arg = tmpTimer; err++; } - } else { // full speed + } else { // full speed // 1kHz scans every USB frame - if(cmd->scan_begin_arg<1000000){ - cmd->scan_begin_arg=1000000; + if (cmd->scan_begin_arg < 1000000) { + cmd->scan_begin_arg = 1000000; err++; } // calc the real sampling rate with the rounding errors - tmpTimer = ((unsigned int)(cmd->scan_begin_arg/1000000))*1000000; + tmpTimer = + ((unsigned int)(cmd->scan_begin_arg / + 1000000)) * 1000000; if (cmd->scan_begin_arg != tmpTimer) { cmd->scan_begin_arg = tmpTimer; err++; @@ -1142,40 +1042,36 @@ static int usbdux_ai_cmdtest(comedi_device *dev, } } // the same argument - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } - if(err)return 3; + if (err) + return 3; return 0; } - // creates the ADC command for the MAX1271 // range is the range value from comedi -static int8_t create_adc_command(unsigned int chan, int range) { - int8_t p=(range<=1); - int8_t r=((range%2)==0); - return (chan<<4)| - ((p==1)<<2)| - ((r==1)<<3); +static int8_t create_adc_command(unsigned int chan, int range) +{ + int8_t p = (range <= 1); + int8_t r = ((range % 2) == 0); + return (chan << 4) | ((p == 1) << 2) | ((r == 1) << 3); } - - // bulk transfers to usbdux #define SENDADCOMMANDS 0 @@ -1186,83 +1082,58 @@ static int8_t create_adc_command(unsigned int chan, int range) { #define READCOUNTERCOMMAND 5 #define WRITECOUNTERCOMMAND 6 +static int send_dux_commands(usbduxsub_t * this_usbduxsub, int cmd_type) +{ + int result, nsent; -static int send_dux_commands(usbduxsub_t* this_usbduxsub,int cmd_type) { - int result,nsent; - - this_usbduxsub->dux_commands[0]=cmd_type; + this_usbduxsub->dux_commands[0] = cmd_type; #ifdef NOISY_DUX_DEBUGBUG printk("comedi%d: usbdux: dux_commands: ", - this_usbduxsub->comedidev->minor); - for(result=0;resultdux_commands[result]); + this_usbduxsub->comedidev->minor); + for (result = 0; result < SIZEOFDUXBUFFER; result++) { + printk(" %02x", this_usbduxsub->dux_commands[result]); } printk("\n"); #endif result = USB_BULK_MSG(this_usbduxsub->usbdev, - usb_sndbulkpipe(this_usbduxsub->usbdev, - COMMAND_OUT_EP), - this_usbduxsub->dux_commands, - SIZEOFDUXBUFFER, - &nsent, - 10*HZ); - if (result<0) { - printk("comedi%d: could not transmit dux_command to the usb-device, err=%d\n", - this_usbduxsub->comedidev->minor,result); + usb_sndbulkpipe(this_usbduxsub->usbdev, + COMMAND_OUT_EP), + this_usbduxsub->dux_commands, SIZEOFDUXBUFFER, &nsent, 10 * HZ); + if (result < 0) { + printk("comedi%d: could not transmit dux_command to the usb-device, err=%d\n", this_usbduxsub->comedidev->minor, result); } return result; } - - - - - -static int receive_dux_commands(usbduxsub_t* this_usbduxsub,int command) { - int result=-EFAULT; +static int receive_dux_commands(usbduxsub_t * this_usbduxsub, int command) +{ + int result = -EFAULT; int nrec; int i; - for(i=0;iusbdev, - usb_rcvbulkpipe(this_usbduxsub->usbdev, - COMMAND_IN_EP), - this_usbduxsub->insnBuffer, - SIZEINSNBUF, - &nrec, - 1*HZ); - if (result<0) { - printk("comedi%d: insn: USB error %d while receiving DUX command\n", - this_usbduxsub->comedidev->minor,result); + usb_rcvbulkpipe(this_usbduxsub->usbdev, + COMMAND_IN_EP), + this_usbduxsub->insnBuffer, SIZEINSNBUF, &nrec, 1 * HZ); + if (result < 0) { + printk("comedi%d: insn: USB error %d while receiving DUX command\n", this_usbduxsub->comedidev->minor, result); return result; } - if (le16_to_cpu(this_usbduxsub->insnBuffer[0])==command) { + if (le16_to_cpu(this_usbduxsub->insnBuffer[0]) == command) { return result; } } // this is only reached if the data has been requested a couple of times - printk("comedi%d: insn: wrong data returned from firmware: want cmd %d, got cmd %d.\n", - this_usbduxsub->comedidev->minor, - command, - le16_to_cpu(this_usbduxsub->insnBuffer[0])); + printk("comedi%d: insn: wrong data returned from firmware: want cmd %d, got cmd %d.\n", this_usbduxsub->comedidev->minor, command, le16_to_cpu(this_usbduxsub->insnBuffer[0])); return -EFAULT; } - - - - - - - - - -static int usbdux_ai_inttrig(comedi_device *dev, - comedi_subdevice *s, - unsigned int trignum) +static int usbdux_ai_inttrig(comedi_device * dev, + comedi_subdevice * s, unsigned int trignum) { int ret; - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { return -EFAULT; } @@ -1271,58 +1142,48 @@ static int usbdux_ai_inttrig(comedi_device *dev, up(&this_usbduxsub->sem); return -ENODEV; } - #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux_ai_inttrig\n",dev->minor); + printk("comedi%d: usbdux_ai_inttrig\n", dev->minor); #endif - if (trignum!=0) { - printk("comedi%d: usbdux_ai_inttrig: invalid trignum\n",dev->minor); + if (trignum != 0) { + printk("comedi%d: usbdux_ai_inttrig: invalid trignum\n", + dev->minor); up(&this_usbduxsub->sem); return -EINVAL; } if (!(this_usbduxsub->ai_cmd_running)) { - this_usbduxsub->ai_cmd_running=1; - ret=usbduxsub_submit_InURBs(this_usbduxsub); - if (ret<0) { - printk("comedi%d: usbdux_ai_inttrig: urbSubmit: err=%d\n", - dev->minor,ret); - this_usbduxsub->ai_cmd_running=0; + this_usbduxsub->ai_cmd_running = 1; + ret = usbduxsub_submit_InURBs(this_usbduxsub); + if (ret < 0) { + printk("comedi%d: usbdux_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret); + this_usbduxsub->ai_cmd_running = 0; up(&this_usbduxsub->sem); return ret; } s->async->inttrig = NULL; } else { printk("comedi%d: ai_inttrig but acqu is already running\n", - dev->minor); + dev->minor); } up(&this_usbduxsub->sem); - return 1; + return 1; } - - - - - - - - -static int usbdux_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int usbdux_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned int chan, range; - int i,ret; - usbduxsub_t* this_usbduxsub=dev->private; + int i, ret; + usbduxsub_t *this_usbduxsub = dev->private; int result; #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux_ai_cmd\n",dev->minor); + printk("comedi%d: usbdux_ai_cmd\n", dev->minor); #endif if (!this_usbduxsub) { return -EFAULT; } - // block other CPUs from starting an ai_cmd down(&this_usbduxsub->sem); @@ -1331,34 +1192,30 @@ static int usbdux_ai_cmd(comedi_device *dev, comedi_subdevice *s) return -ENODEV; } if (this_usbduxsub->ai_cmd_running) { - printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", - dev->minor); + printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor); up(&this_usbduxsub->sem); return -EBUSY; } - // set current channel of the running aquisition to zero - s->async->cur_chan=0; + s->async->cur_chan = 0; - this_usbduxsub->dux_commands[1]=cmd->chanlist_len; - for(i=0; i < cmd->chanlist_len; ++i ) { + this_usbduxsub->dux_commands[1] = cmd->chanlist_len; + for (i = 0; i < cmd->chanlist_len; ++i) { chan = CR_CHAN(cmd->chanlist[i]); range = CR_RANGE(cmd->chanlist[i]); - if (i>=NUMCHANNELS) { - printk("comedi%d: channel list too long\n",dev->minor); + if (i >= NUMCHANNELS) { + printk("comedi%d: channel list too long\n", dev->minor); break; } - this_usbduxsub->dux_commands[i+2]=create_adc_command(chan,range); + this_usbduxsub->dux_commands[i + 2] = + create_adc_command(chan, range); } - #ifdef NOISY_DUX_DEBUGBUG - printk("comedi %d: sending commands to the usb device: ", - dev->minor); - printk("size=%u\n", - NUMCHANNELS); + printk("comedi %d: sending commands to the usb device: ", dev->minor); + printk("size=%u\n", NUMCHANNELS); #endif - if ((result=send_dux_commands(this_usbduxsub,SENDADCOMMANDS))<0) { + if ((result = send_dux_commands(this_usbduxsub, SENDADCOMMANDS)) < 0) { up(&this_usbduxsub->sem); return result; } @@ -1367,84 +1224,75 @@ static int usbdux_ai_cmd(comedi_device *dev, comedi_subdevice *s) // every channel gets a time window of 125us. Thus, if we // sample all 8 channels we need 1ms. If we sample only // one channel we need only 125us - this_usbduxsub->ai_interval=1; + this_usbduxsub->ai_interval = 1; // find a power of 2 for the interval - while ((this_usbduxsub->ai_interval)<(cmd->chanlist_len)) { - this_usbduxsub->ai_interval=(this_usbduxsub->ai_interval)*2; + while ((this_usbduxsub->ai_interval) < (cmd->chanlist_len)) { + this_usbduxsub->ai_interval = + (this_usbduxsub->ai_interval) * 2; } - this_usbduxsub->ai_timer = cmd->scan_begin_arg/(125000*(this_usbduxsub->ai_interval)); - } else { + this_usbduxsub->ai_timer = + cmd->scan_begin_arg / (125000 * + (this_usbduxsub->ai_interval)); + } else { // interval always 1ms - this_usbduxsub->ai_interval=1; - this_usbduxsub->ai_timer = cmd->scan_begin_arg/1000000; - } - if (this_usbduxsub->ai_timer<1) { - printk("comedi%d: usbdux: ai_cmd: timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", - dev->minor, - this_usbduxsub->ai_timer, - cmd->scan_begin_arg); + this_usbduxsub->ai_interval = 1; + this_usbduxsub->ai_timer = cmd->scan_begin_arg / 1000000; + } + if (this_usbduxsub->ai_timer < 1) { + printk("comedi%d: usbdux: ai_cmd: timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, this_usbduxsub->ai_timer, cmd->scan_begin_arg); up(&this_usbduxsub->sem); return -EINVAL; } - this_usbduxsub->ai_counter=this_usbduxsub->ai_timer; + this_usbduxsub->ai_counter = this_usbduxsub->ai_timer; - if(cmd->stop_src==TRIG_COUNT){ + if (cmd->stop_src == TRIG_COUNT) { // data arrives as one packet this_usbduxsub->ai_sample_count = cmd->stop_arg; - this_usbduxsub->ai_continous=0; + this_usbduxsub->ai_continous = 0; } else { // continous aquisition - this_usbduxsub->ai_continous=1; - this_usbduxsub->ai_sample_count=0; + this_usbduxsub->ai_continous = 1; + this_usbduxsub->ai_sample_count = 0; } - - if(cmd->start_src == TRIG_NOW){ + if (cmd->start_src == TRIG_NOW) { // enable this acquisition operation - this_usbduxsub->ai_cmd_running=1; - ret=usbduxsub_submit_InURBs(this_usbduxsub); - if (ret<0) { - this_usbduxsub->ai_cmd_running=0; + this_usbduxsub->ai_cmd_running = 1; + ret = usbduxsub_submit_InURBs(this_usbduxsub); + if (ret < 0) { + this_usbduxsub->ai_cmd_running = 0; // fixme: unlink here?? up(&this_usbduxsub->sem); return ret; } - s->async->inttrig = NULL; - }else{ - /* TRIG_INT */ + s->async->inttrig = NULL; + } else { + /* TRIG_INT */ // don't enable the acquision operation // wait for an internal signal - s->async->inttrig = usbdux_ai_inttrig; - } + s->async->inttrig = usbdux_ai_inttrig; + } up(&this_usbduxsub->sem); return 0; } - - - /* Mode 0 is used to get a single conversion on demand */ static int usbdux_ai_insn_read(comedi_device * dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { int i; - lsampl_t one=0; - int chan,range; + lsampl_t one = 0; + int chan, range; int err; - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { - printk("comedi%d: ai_insn_read: no usb dev.\n", - dev->minor); + printk("comedi%d: ai_insn_read: no usb dev.\n", dev->minor); return 0; } #ifdef NOISY_DUX_DEBUGBUG printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n", - dev->minor, - insn->n, - insn->subdev); + dev->minor, insn->n, insn->subdev); #endif down(&this_usbduxsub->sem); if (!(this_usbduxsub->probed)) { @@ -1452,57 +1300,47 @@ static int usbdux_ai_insn_read(comedi_device * dev, return -ENODEV; } if (this_usbduxsub->ai_cmd_running) { - printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", - dev->minor); + printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor); up(&this_usbduxsub->sem); return 0; } - - // sample one channel chan = CR_CHAN(insn->chanspec); range = CR_RANGE(insn->chanspec); // set command for the first channel - this_usbduxsub->dux_commands[1]=create_adc_command(chan,range); + this_usbduxsub->dux_commands[1] = create_adc_command(chan, range); // adc commands - if ((err=send_dux_commands(this_usbduxsub,SENDSINGLEAD))<0) { + if ((err = send_dux_commands(this_usbduxsub, SENDSINGLEAD)) < 0) { up(&this_usbduxsub->sem); return err; } - for(i=0 ; i < insn->n ; i++) { - if ((err=receive_dux_commands(this_usbduxsub,SENDSINGLEAD))<0) { + for (i = 0; i < insn->n; i++) { + if ((err = receive_dux_commands(this_usbduxsub, + SENDSINGLEAD)) < 0) { up(&this_usbduxsub->sem); return 0; } - one=le16_to_cpu(this_usbduxsub->insnBuffer[1]); - if (CR_RANGE(insn->chanspec)<=1) { - one=one^0x800; + one = le16_to_cpu(this_usbduxsub->insnBuffer[1]); + if (CR_RANGE(insn->chanspec) <= 1) { + one = one ^ 0x800; } - data[i]=one; + data[i] = one; } up(&this_usbduxsub->sem); return i; } - - - ////////////////// // analog out - - - - - -static int usbdux_ao_insn_read(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int usbdux_ao_insn_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { int i; int chan = CR_CHAN(insn->chanspec); - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { return -EFAULT; @@ -1512,24 +1350,22 @@ static int usbdux_ao_insn_read(comedi_device *dev, comedi_subdevice *s, up(&this_usbduxsub->sem); return -ENODEV; } - for(i=0;in;i++) { - data[i]=this_usbduxsub->outBuffer[chan]; + for (i = 0; i < insn->n; i++) { + data[i] = this_usbduxsub->outBuffer[chan]; } up(&this_usbduxsub->sem); return i; } - - -static int usbdux_ao_insn_write(comedi_device *dev, comedi_subdevice *s, - comedi_insn *insn, lsampl_t *data) +static int usbdux_ao_insn_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) { - int i,err; + int i, err; int chan = CR_CHAN(insn->chanspec); - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: ao_insn_write\n",dev->minor); + printk("comedi%d: ao_insn_write\n", dev->minor); #endif if (!this_usbduxsub) { return -EFAULT; @@ -1540,25 +1376,26 @@ static int usbdux_ao_insn_write(comedi_device *dev, comedi_subdevice *s, return -ENODEV; } if (this_usbduxsub->ao_cmd_running) { - printk("comedi%d: ao_insn_write: ERROR: asynchronous ao_cmd is running\n", - dev->minor - ); + printk("comedi%d: ao_insn_write: ERROR: asynchronous ao_cmd is running\n", dev->minor); up(&this_usbduxsub->sem); return 0; } - for(i=0;in;i++){ + for (i = 0; i < insn->n; i++) { #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n",dev->minor,chan,i,data[i]); + printk("comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n", + dev->minor, chan, i, data[i]); #endif // number of channels: 1 - this_usbduxsub->dux_commands[1]=1; + this_usbduxsub->dux_commands[1] = 1; // one 16 bit value - *((int16_t*)(this_usbduxsub->dux_commands+2))=cpu_to_le16(data[i]); - this_usbduxsub->outBuffer[chan]=data[i]; + *((int16_t *) (this_usbduxsub->dux_commands + 2)) = + cpu_to_le16(data[i]); + this_usbduxsub->outBuffer[chan] = data[i]; // channel number - this_usbduxsub->dux_commands[4]=(chan<<6); - if ((err=send_dux_commands(this_usbduxsub,SENDDACOMMANDS))<0) { + this_usbduxsub->dux_commands[4] = (chan << 6); + if ((err = send_dux_commands(this_usbduxsub, + SENDDACOMMANDS)) < 0) { up(&this_usbduxsub->sem); return err; } @@ -1568,19 +1405,11 @@ static int usbdux_ao_insn_write(comedi_device *dev, comedi_subdevice *s, return i; } - - - - - - - - -static int usbdux_ao_inttrig(comedi_device *dev, comedi_subdevice *s, - unsigned int trignum) +static int usbdux_ao_inttrig(comedi_device * dev, comedi_subdevice * s, + unsigned int trignum) { int ret; - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { return -EFAULT; @@ -1590,39 +1419,34 @@ static int usbdux_ao_inttrig(comedi_device *dev, comedi_subdevice *s, up(&this_usbduxsub->sem); return -ENODEV; } - if (trignum!=0) { - printk("comedi%d: usbdux_ao_inttrig: invalid trignum\n",dev->minor); + if (trignum != 0) { + printk("comedi%d: usbdux_ao_inttrig: invalid trignum\n", + dev->minor); return -EINVAL; } if (!(this_usbduxsub->ao_cmd_running)) { - this_usbduxsub->ao_cmd_running=1; - ret=usbduxsub_submit_OutURBs(this_usbduxsub); - if (ret<0) { - printk("comedi%d: usbdux_ao_inttrig: submitURB: err=%d\n", - dev->minor,ret); - this_usbduxsub->ao_cmd_running=0; + this_usbduxsub->ao_cmd_running = 1; + ret = usbduxsub_submit_OutURBs(this_usbduxsub); + if (ret < 0) { + printk("comedi%d: usbdux_ao_inttrig: submitURB: err=%d\n", dev->minor, ret); + this_usbduxsub->ao_cmd_running = 0; up(&this_usbduxsub->sem); return ret; } s->async->inttrig = NULL; - } else { + } else { printk("comedi%d: ao_inttrig but acqu is already running.\n", - dev->minor); + dev->minor); } up(&this_usbduxsub->sem); - return 1; + return 1; } - - - - -static int usbdux_ao_cmdtest(comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +static int usbdux_ao_cmdtest(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - int err=0, tmp; - usbduxsub_t* this_usbduxsub=dev->private; + int err = 0, tmp; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { return -EFAULT; @@ -1631,19 +1455,20 @@ static int usbdux_ao_cmdtest(comedi_device *dev, return -ENODEV; } #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux_ao_cmdtest\n",dev->minor); + printk("comedi%d: usbdux_ao_cmdtest\n", dev->minor); #endif /* make sure triggers are valid */ // Only immediate triggers are allowed - tmp=cmd->start_src; - cmd->start_src &= TRIG_NOW|TRIG_INT; - if(!cmd->start_src || tmp!=cmd->start_src)err++; + tmp = cmd->start_src; + cmd->start_src &= TRIG_NOW | TRIG_INT; + if (!cmd->start_src || tmp != cmd->start_src) + err++; // trigger should happen timed - tmp=cmd->scan_begin_src; + tmp = cmd->scan_begin_src; // just now we scan also in the high speed mode every frame // this is due to ehci driver limitations - if (0) /* (this_usbduxsub->high_speed) */ { + if (0) { /* (this_usbduxsub->high_speed) */ // start immidiately a new scan // the sampling rate is set by the coversion rate cmd->scan_begin_src &= TRIG_FOLLOW; @@ -1651,117 +1476,110 @@ static int usbdux_ao_cmdtest(comedi_device *dev, // start a new scan (output at once) with a timer cmd->scan_begin_src &= TRIG_TIMER; } - if(!cmd->scan_begin_src || tmp!=cmd->scan_begin_src)err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; // scanning is continous - tmp=cmd->convert_src; + tmp = cmd->convert_src; // we always output at 1kHz just now all channels at once - if (0) /* (this_usbduxsub->high_speed) */ { + if (0) { /* (this_usbduxsub->high_speed) */ // in usb-2.0 only one conversion it tranmitted but with 8kHz/n cmd->convert_src &= TRIG_TIMER; } else { // all conversion events happen simultaneously with a rate of 1kHz/n cmd->convert_src &= TRIG_NOW; } - if(!cmd->convert_src || tmp!=cmd->convert_src)err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; // issue a trigger when scan is finished and start a new scan - tmp=cmd->scan_end_src; + tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp!=cmd->scan_end_src)err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; // trigger at the end of count events or not, stop condition or not - tmp=cmd->stop_src; - cmd->stop_src &= TRIG_COUNT|TRIG_NONE; - if(!cmd->stop_src || tmp!=cmd->stop_src)err++; + tmp = cmd->stop_src; + cmd->stop_src &= TRIG_COUNT | TRIG_NONE; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err)return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ /* note that mutual compatiblity is not an issue here */ - if(cmd->scan_begin_src!=TRIG_FOLLOW && - cmd->scan_begin_src!=TRIG_EXT && - cmd->scan_begin_src!=TRIG_TIMER)err++; - if(cmd->stop_src!=TRIG_COUNT && - cmd->stop_src!=TRIG_NONE)err++; - - if(err)return 2; + if (cmd->scan_begin_src != TRIG_FOLLOW && + cmd->scan_begin_src != TRIG_EXT && + cmd->scan_begin_src != TRIG_TIMER) + err++; + if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE) + err++; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_arg!=0){ - cmd->start_arg=0; + if (cmd->start_arg != 0) { + cmd->start_arg = 0; err++; } - if(cmd->scan_begin_src==TRIG_FOLLOW){ + if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ - if(cmd->scan_begin_arg!=0){ - cmd->scan_begin_arg=0; + if (cmd->scan_begin_arg != 0) { + cmd->scan_begin_arg = 0; err++; } } - if(cmd->scan_begin_src==TRIG_TIMER){ + if (cmd->scan_begin_src == TRIG_TIMER) { /* timer */ - if(cmd->scan_begin_arg<1000000){ - cmd->scan_begin_arg=1000000; + if (cmd->scan_begin_arg < 1000000) { + cmd->scan_begin_arg = 1000000; err++; } } - // not used now, is for later use - if (cmd->convert_src==TRIG_TIMER) { - if(cmd->convert_arg<125000){ - cmd->convert_arg=125000; + if (cmd->convert_src == TRIG_TIMER) { + if (cmd->convert_arg < 125000) { + cmd->convert_arg = 125000; err++; } } - - - // the same argument - if(cmd->scan_end_arg!=cmd->chanlist_len){ - cmd->scan_end_arg=cmd->chanlist_len; + 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_src == TRIG_COUNT) { /* any count is allowed */ - }else{ + } else { /* TRIG_NONE */ - if(cmd->stop_arg!=0){ - cmd->stop_arg=0; + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; err++; } } #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: err=%d, scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", - dev->minor, - err, - cmd->scan_begin_src, - cmd->scan_begin_arg, - cmd->convert_src, - cmd->convert_arg); + printk("comedi%d: err=%d, scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", dev->minor, err, cmd->scan_begin_src, cmd->scan_begin_arg, cmd->convert_src, cmd->convert_arg); #endif - if(err)return 3; + if (err) + return 3; return 0; } - - - -static int usbdux_ao_cmd(comedi_device *dev, comedi_subdevice *s) +static int usbdux_ao_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; unsigned int chan, gain; - int i,ret; - usbduxsub_t* this_usbduxsub=dev->private; + int i, ret; + usbduxsub_t *this_usbduxsub = dev->private; if (!this_usbduxsub) { return -EFAULT; @@ -1772,129 +1590,111 @@ static int usbdux_ao_cmd(comedi_device *dev, comedi_subdevice *s) return -ENODEV; } #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux_ao_cmd\n",dev->minor); + printk("comedi%d: usbdux_ao_cmd\n", dev->minor); #endif // set current channel of the running aquisition to zero - s->async->cur_chan = 0; - for(i=0; i < cmd->chanlist_len; ++i ) { + s->async->cur_chan = 0; + for (i = 0; i < cmd->chanlist_len; ++i) { chan = CR_CHAN(cmd->chanlist[i]); gain = CR_RANGE(cmd->chanlist[i]); - if (i>=NUMOUTCHANNELS) { - printk("comedi%d: usbdux_ao_cmd: channel list too long\n",dev->minor); + if (i >= NUMOUTCHANNELS) { + printk("comedi%d: usbdux_ao_cmd: channel list too long\n", dev->minor); break; } - this_usbduxsub->dac_commands[i]=(chan<<6); + this_usbduxsub->dac_commands[i] = (chan << 6); #ifdef NOISY_DUX_DEBUGBUG printk("comedi%d: dac command for ch %d is %x\n", - dev->minor, - i, - this_usbduxsub->dac_commands[i]); + dev->minor, i, this_usbduxsub->dac_commands[i]); #endif } - // we count in steps of 1ms (125us) // 125us mode not used yet - if (0) /* (this_usbduxsub->high_speed) */ { + if (0) { /* (this_usbduxsub->high_speed) */ // 125us // timing of the conversion itself: every 125 us - this_usbduxsub->ao_timer = cmd->convert_arg/125000; - } else { + this_usbduxsub->ao_timer = cmd->convert_arg / 125000; + } else { // 1ms // timing of the scan: we get all channels at once - this_usbduxsub->ao_timer = cmd->scan_begin_arg/1000000; + this_usbduxsub->ao_timer = cmd->scan_begin_arg / 1000000; #ifdef NOISY_DUX_DEBUGBUG - printk("comedi%d: usbdux: scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", - dev->minor, - cmd->scan_begin_src, - cmd->scan_begin_arg, - cmd->convert_src, - cmd->convert_arg); + printk("comedi%d: usbdux: scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", dev->minor, cmd->scan_begin_src, cmd->scan_begin_arg, cmd->convert_src, cmd->convert_arg); printk("comedi%d: usbdux: ao_timer=%d (ms)\n", - dev->minor, - this_usbduxsub->ao_timer); + dev->minor, this_usbduxsub->ao_timer); #endif - if (this_usbduxsub->ao_timer<1) { - printk("comedi%d: usbdux: ao_timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", - dev->minor, - this_usbduxsub->ao_timer, - cmd->scan_begin_arg); - up(&this_usbduxsub->sem); - return -EINVAL; + if (this_usbduxsub->ao_timer < 1) { + printk("comedi%d: usbdux: ao_timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, this_usbduxsub->ao_timer, cmd->scan_begin_arg); + up(&this_usbduxsub->sem); + return -EINVAL; } } - this_usbduxsub->ao_counter=this_usbduxsub->ao_timer; + this_usbduxsub->ao_counter = this_usbduxsub->ao_timer; - if(cmd->stop_src==TRIG_COUNT){ + if (cmd->stop_src == TRIG_COUNT) { // not continous // counter - // high speed also scans everything at once - if (0) /* (this_usbduxsub->high_speed) */ { + // high speed also scans everything at once + if (0) { /* (this_usbduxsub->high_speed) */ this_usbduxsub->ao_sample_count = - (cmd->stop_arg)*(cmd->scan_end_arg); + (cmd->stop_arg) * (cmd->scan_end_arg); } else { // there's no scan as the scan has been // perf inside the FX2 // data arrives as one packet - this_usbduxsub->ao_sample_count = - cmd->stop_arg; + this_usbduxsub->ao_sample_count = cmd->stop_arg; } - this_usbduxsub->ao_continous=0; + this_usbduxsub->ao_continous = 0; } else { // continous aquisition - this_usbduxsub->ao_continous=1; - this_usbduxsub->ao_sample_count=0; + this_usbduxsub->ao_continous = 1; + this_usbduxsub->ao_sample_count = 0; } - - if(cmd->start_src == TRIG_NOW){ + if (cmd->start_src == TRIG_NOW) { // enable this acquisition operation - this_usbduxsub->ao_cmd_running=1; - ret=usbduxsub_submit_OutURBs(this_usbduxsub); - if (ret<0) { - this_usbduxsub->ao_cmd_running=0; + this_usbduxsub->ao_cmd_running = 1; + ret = usbduxsub_submit_OutURBs(this_usbduxsub); + if (ret < 0) { + this_usbduxsub->ao_cmd_running = 0; // fixme: unlink here?? up(&this_usbduxsub->sem); return ret; } - s->async->inttrig = NULL; - } else { - /* TRIG_INT */ + s->async->inttrig = NULL; + } else { + /* TRIG_INT */ // submit the urbs later // wait for an internal signal - s->async->inttrig = usbdux_ao_inttrig; - } - + s->async->inttrig = usbdux_ao_inttrig; + } up(&this_usbduxsub->sem); return 0; } - - - -static int usbdux_dio_insn_config (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) { - int chan=CR_CHAN(insn->chanspec); +static int usbdux_dio_insn_config(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ + int chan = CR_CHAN(insn->chanspec); /* The input or output configuration of each digital line is * configured by a special insn_config instruction. chanspec * contains the channel to be changed, and data[0] contains the * value COMEDI_INPUT or COMEDI_OUTPUT. */ - switch(data[0]) - { + switch (data[0]) { case INSN_CONFIG_DIO_OUTPUT: - s->io_bits |= 1<io_bits |= 1 << chan; /* 1 means Out */ break; case INSN_CONFIG_DIO_INPUT: - s->io_bits &= ~(1<io_bits &= ~(1 << chan); break; case INSN_CONFIG_DIO_QUERY: - data[1] = (s->io_bits & (1< + io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT; break; default: return -EINVAL; @@ -1905,21 +1705,19 @@ static int usbdux_dio_insn_config (comedi_device *dev, return insn->n; } +static int usbdux_dio_insn_bits(comedi_device * dev, + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) +{ - -static int usbdux_dio_insn_bits (comedi_device *dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) { - - usbduxsub_t* this_usbduxsub=dev->private; + usbduxsub_t *this_usbduxsub = dev->private; int err; if (!this_usbduxsub) { return -EFAULT; } - if (insn->n!=2) return -EINVAL; + if (insn->n != 2) + return -EINVAL; down(&this_usbduxsub->sem); @@ -1931,33 +1729,34 @@ static int usbdux_dio_insn_bits (comedi_device *dev, /* The insn data is a mask in data[0] and the new data * in data[1], each channel cooresponding to a bit. */ s->state &= ~data[0]; - s->state |= data[0]&data[1]; - this_usbduxsub->dux_commands[1]=s->io_bits; - this_usbduxsub->dux_commands[2]=s->state; + s->state |= data[0] & data[1]; + this_usbduxsub->dux_commands[1] = s->io_bits; + this_usbduxsub->dux_commands[2] = s->state; // This command also tells the firmware to return // the digital input lines - if ((err=send_dux_commands(this_usbduxsub,SENDDIOBITSCOMMAND))<0) { + if ((err = send_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND)) < 0) { up(&this_usbduxsub->sem); return err; } - if ((err=receive_dux_commands(this_usbduxsub,SENDDIOBITSCOMMAND))<0) { + if ((err = receive_dux_commands(this_usbduxsub, + SENDDIOBITSCOMMAND)) < 0) { up(&this_usbduxsub->sem); return err; } - data[1]=le16_to_cpu(this_usbduxsub->insnBuffer[1]); + data[1] = le16_to_cpu(this_usbduxsub->insnBuffer[1]); up(&this_usbduxsub->sem); return 2; } - - // reads the 4 counters // only two are used just now -static int usbdux_counter_read(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) { - usbduxsub_t* this_usbduxsub=dev->private; - int chan=insn->chanspec; +static int usbdux_counter_read(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + usbduxsub_t *this_usbduxsub = dev->private; + int chan = insn->chanspec; int err; if (!this_usbduxsub) { @@ -1971,25 +1770,26 @@ static int usbdux_counter_read(comedi_device *dev,comedi_subdevice *s, comedi_in return -ENODEV; } - if ((err=send_dux_commands(this_usbduxsub,READCOUNTERCOMMAND))<0) { + if ((err = send_dux_commands(this_usbduxsub, READCOUNTERCOMMAND)) < 0) { up(&this_usbduxsub->sem); return err; } - if ((err=receive_dux_commands(this_usbduxsub,READCOUNTERCOMMAND))<0) { + if ((err = receive_dux_commands(this_usbduxsub, + READCOUNTERCOMMAND)) < 0) { up(&this_usbduxsub->sem); return err; } - data[0]=le16_to_cpu(this_usbduxsub->insnBuffer[chan+1]); + data[0] = le16_to_cpu(this_usbduxsub->insnBuffer[chan + 1]); up(&this_usbduxsub->sem); return 1; } - -static int usbdux_counter_write(comedi_device *dev,comedi_subdevice *s, - comedi_insn *insn,lsampl_t *data) { - usbduxsub_t* this_usbduxsub=dev->private; +static int usbdux_counter_write(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ + usbduxsub_t *this_usbduxsub = dev->private; int err; if (!this_usbduxsub) { @@ -2003,33 +1803,28 @@ static int usbdux_counter_write(comedi_device *dev,comedi_subdevice *s, return -ENODEV; } - this_usbduxsub->dux_commands[1]=insn->chanspec; - *((int16_t*)(this_usbduxsub->dux_commands+2))=cpu_to_le16(*data); + this_usbduxsub->dux_commands[1] = insn->chanspec; + *((int16_t *) (this_usbduxsub->dux_commands + 2)) = cpu_to_le16(*data); - if ((err=send_dux_commands(this_usbduxsub,WRITECOUNTERCOMMAND))<0) { + if ((err = send_dux_commands(this_usbduxsub, WRITECOUNTERCOMMAND)) < 0) { up(&this_usbduxsub->sem); return err; } up(&this_usbduxsub->sem); - return 1; + return 1; } - -static int usbdux_counter_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) { +static int usbdux_counter_config(comedi_device * dev, comedi_subdevice * s, + comedi_insn * insn, lsampl_t * data) +{ // nothing to do so far - return 2; + return 2; } - - - - - - - -static void tidy_up(usbduxsub_t* usbduxsub_tmp) { +static void tidy_up(usbduxsub_t * usbduxsub_tmp) +{ int i; #ifdef CONFIG_COMEDI_DEBUG @@ -2038,146 +1833,141 @@ static void tidy_up(usbduxsub_t* usbduxsub_tmp) { if (!usbduxsub_tmp) { return; } - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) // shows the usb subsystem that the driver is down if (usbduxsub_tmp->interface) { - usb_set_intfdata(usbduxsub_tmp->interface,NULL); + usb_set_intfdata(usbduxsub_tmp->interface, NULL); } #endif - usbduxsub_tmp->probed=0; + usbduxsub_tmp->probed = 0; if (usbduxsub_tmp->urbIn) { if (usbduxsub_tmp->ai_cmd_running) { - usbduxsub_tmp->ai_cmd_running=0; + usbduxsub_tmp->ai_cmd_running = 0; usbduxsub_unlink_InURBs(usbduxsub_tmp); } - for (i=0; i < usbduxsub_tmp->numOfInBuffers; i++) { + for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) { if (usbduxsub_tmp->urbIn[i]->transfer_buffer) { kfree(usbduxsub_tmp->urbIn[i]->transfer_buffer); - usbduxsub_tmp->urbIn[i]->transfer_buffer=NULL; + usbduxsub_tmp->urbIn[i]->transfer_buffer = NULL; } if (usbduxsub_tmp->urbIn[i]) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8) usb_kill_urb(usbduxsub_tmp->urbIn[i]); #endif - usb_free_urb (usbduxsub_tmp->urbIn[i]); - usbduxsub_tmp->urbIn[i]=NULL; + usb_free_urb(usbduxsub_tmp->urbIn[i]); + usbduxsub_tmp->urbIn[i] = NULL; } } kfree(usbduxsub_tmp->urbIn); - usbduxsub_tmp->urbIn=NULL; + usbduxsub_tmp->urbIn = NULL; } if (usbduxsub_tmp->urbOut) { if (usbduxsub_tmp->ao_cmd_running) { - usbduxsub_tmp->ao_cmd_running=0; + usbduxsub_tmp->ao_cmd_running = 0; usbduxsub_unlink_OutURBs(usbduxsub_tmp); } - for (i=0; i < usbduxsub_tmp->numOfOutBuffers; i++) { + for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) { if (usbduxsub_tmp->urbOut[i]->transfer_buffer) { - kfree(usbduxsub_tmp->urbOut[i]->transfer_buffer); - usbduxsub_tmp->urbOut[i]->transfer_buffer=NULL; + kfree(usbduxsub_tmp->urbOut[i]-> + transfer_buffer); + usbduxsub_tmp->urbOut[i]->transfer_buffer = + NULL; } if (usbduxsub_tmp->urbOut[i]) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8) usb_kill_urb(usbduxsub_tmp->urbOut[i]); #endif - usb_free_urb (usbduxsub_tmp->urbOut[i]); - usbduxsub_tmp->urbOut[i]=NULL; + usb_free_urb(usbduxsub_tmp->urbOut[i]); + usbduxsub_tmp->urbOut[i] = NULL; } } kfree(usbduxsub_tmp->urbOut); - usbduxsub_tmp->urbOut=NULL; + usbduxsub_tmp->urbOut = NULL; } if (usbduxsub_tmp->inBuffer) { kfree(usbduxsub_tmp->inBuffer); - usbduxsub_tmp->inBuffer=NULL; + usbduxsub_tmp->inBuffer = NULL; } if (usbduxsub_tmp->insnBuffer) { kfree(usbduxsub_tmp->insnBuffer); - usbduxsub_tmp->insnBuffer=NULL; + usbduxsub_tmp->insnBuffer = NULL; } if (usbduxsub_tmp->inBuffer) { kfree(usbduxsub_tmp->inBuffer); - usbduxsub_tmp->inBuffer=NULL; + usbduxsub_tmp->inBuffer = NULL; } if (usbduxsub_tmp->dac_commands) { kfree(usbduxsub_tmp->dac_commands); - usbduxsub_tmp->dac_commands=NULL; + usbduxsub_tmp->dac_commands = NULL; } if (usbduxsub_tmp->dux_commands) { kfree(usbduxsub_tmp->dux_commands); - usbduxsub_tmp->dux_commands=NULL; + usbduxsub_tmp->dux_commands = NULL; } - usbduxsub_tmp->ai_cmd_running=0; - usbduxsub_tmp->ao_cmd_running=0; + usbduxsub_tmp->ai_cmd_running = 0; + usbduxsub_tmp->ao_cmd_running = 0; } - - - - - - - -static unsigned hex2unsigned(char *h) { - unsigned hi,lo; - if (h[0]>'9') { - hi=h[0]-'A'+0x0a; +static unsigned hex2unsigned(char *h) +{ + unsigned hi, lo; + if (h[0] > '9') { + hi = h[0] - 'A' + 0x0a; } else { - hi=h[0]-'0'; + hi = h[0] - '0'; } - if (h[1]>'9') { - lo=h[1]-'A'+0x0a; + if (h[1] > '9') { + lo = h[1] - 'A' + 0x0a; } else { - lo=h[1]-'0'; + lo = h[1] - '0'; } - return hi*0x10+lo; + return hi * 0x10 + lo; } - // for FX2 #define FIRMWARE_MAX_LEN 0x2000 // taken from David Brownell's fxload and adjusted for this driver -static int read_firmware(usbduxsub_t* usbduxsub,void *firmwarePtr,long size) { - int i=0; - unsigned char* fp=(char*)firmwarePtr; - unsigned char* firmwareBinary=NULL; - int res=0; - int maxAddr=0; - - firmwareBinary = kmalloc(FIRMWARE_MAX_LEN,GFP_KERNEL); - if(!firmwareBinary){ - printk("comedi_: usbdux: mem alloc for firmware failed\n" - ); +static int read_firmware(usbduxsub_t * usbduxsub, void *firmwarePtr, long size) +{ + int i = 0; + unsigned char *fp = (char *)firmwarePtr; + unsigned char *firmwareBinary = NULL; + int res = 0; + int maxAddr = 0; + + firmwareBinary = kmalloc(FIRMWARE_MAX_LEN, GFP_KERNEL); + if (!firmwareBinary) { + printk("comedi_: usbdux: mem alloc for firmware failed\n"); return -ENOMEM; } for (;;) { - char buf[256],*cp; - char type; - int len; - int idx, off; - int j=0; + char buf[256], *cp; + char type; + int len; + int idx, off; + int j = 0; // get one line - while ((i=sizeof(buf)) { + if (j >= sizeof(buf)) { printk("comedi_: usbdux: bogus firmware file!\n"); return -1; } } // get rid of LF/CR/... - while ((imaxAddr) { - maxAddr=off+len; + if ((off + len) > maxAddr) { + maxAddr = off + len; } - if (maxAddr>=FIRMWARE_MAX_LEN) { + if (maxAddr >= FIRMWARE_MAX_LEN) { printk("comedi_: usbdux: firmware upload goes beyond FX2 RAM boundaries."); return -EFAULT; } - //printk("comedi_: usbdux: off=%x, len=%x:",off,len); /* Read the record type */ - type = hex2unsigned(buf+7); + type = hex2unsigned(buf + 7); /* If this is an EOF record, then make it so. */ if (type == 1) { @@ -2215,48 +2004,40 @@ static int read_firmware(usbduxsub_t* usbduxsub,void *firmwarePtr,long size) { } if (type != 0) { - printk("comedi_: usbdux: unsupported record type: %u\n",type); + printk("comedi_: usbdux: unsupported record type: %u\n", + type); return -EFAULT; } - for (idx = 0, cp = buf+9 ; idx < len ; idx += 1, cp += 2) { - firmwareBinary[idx+off] = hex2unsigned(cp); + for (idx = 0, cp = buf + 9; idx < len; idx += 1, cp += 2) { + firmwareBinary[idx + off] = hex2unsigned(cp); //printk("%02x ",firmwareBinary[idx+off]); } //printk("\n"); - if (i>=size) { + if (i >= size) { printk("comedi_: usbdux: unexpected end of hex file\n"); break; } } - res=firmwareUpload(usbduxsub,firmwareBinary,maxAddr+1); + res = firmwareUpload(usbduxsub, firmwareBinary, maxAddr + 1); kfree(firmwareBinary); return res; } - - - - - - - - - - // allocate memory for the urbs and initialise them #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -static void* usbduxsub_probe(struct usb_device *udev, - unsigned int interfnum, - const struct usb_device_id *id) { +static void *usbduxsub_probe(struct usb_device *udev, + unsigned int interfnum, const struct usb_device_id *id) +{ #else static int usbduxsub_probe(struct usb_interface *uinterf, - const struct usb_device_id *id) { - struct usb_device *udev = interface_to_usbdev(uinterf); + const struct usb_device_id *id) +{ + struct usb_device *udev = interface_to_usbdev(uinterf); #endif - int i; + int i; int index; #ifdef CONFIG_COMEDI_DEBUG @@ -2264,26 +2045,25 @@ static int usbduxsub_probe(struct usb_interface *uinterf, #endif down(&start_stop_sem); // look for a free place in the usbdux array - index=-1; - for(i=0; ialtsetting->desc.bInterfaceNumber; // hand the private data over to the usb subsystem // will be needed for disconnect - usb_set_intfdata(uinterf,&(usbduxsub[index])); + usb_set_intfdata(uinterf, &(usbduxsub[index])); #endif #ifdef CONFIG_COMEDI_DEBUG - printk("comedi_: usbdux: ifnum=%d\n",usbduxsub[index].ifnum); + printk("comedi_: usbdux: ifnum=%d\n", usbduxsub[index].ifnum); #endif // test if it is high speed (USB 2.0) - usbduxsub[index].high_speed=(usbduxsub[index].usbdev->speed==USB_SPEED_HIGH); - + usbduxsub[index].high_speed = + (usbduxsub[index].usbdev->speed == USB_SPEED_HIGH); // create space for the commands of the DA converter - usbduxsub[index].dac_commands=kmalloc(NUMOUTCHANNELS, - GFP_KERNEL); + usbduxsub[index].dac_commands = kmalloc(NUMOUTCHANNELS, GFP_KERNEL); if (!usbduxsub[index].dac_commands) { printk("comedi_: usbdux: error alloc space for dac commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - // create space for the commands going to the usb device - usbduxsub[index].dux_commands=kmalloc(SIZEOFDUXBUFFER, - GFP_KERNEL); + usbduxsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, GFP_KERNEL); if (!usbduxsub[index].dux_commands) { printk("comedi_: usbdux: error alloc space for dac commands\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - // create space for the in buffer and zero it - usbduxsub[index].inBuffer=kzalloc(SIZEINBUF,GFP_KERNEL); + usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].inBuffer)) { printk("comedi_: usbdux: could not alloc space for inBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - // create space of the instruction buffer - usbduxsub[index].insnBuffer=kmalloc(SIZEINSNBUF,GFP_KERNEL); + usbduxsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); if (!(usbduxsub[index].insnBuffer)) { printk("comedi_: usbdux: could not alloc space for insnBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - // create space for the outbuffer and zero it - usbduxsub[index].outBuffer=kzalloc(SIZEOUTBUF,GFP_KERNEL); + usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].outBuffer)) { printk("comedi_: usbdux: could not alloc space for outBuffer\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - - - // setting to alternate setting 3: enabling iso ep and bulk ep. - i=usb_set_interface(usbduxsub[index].usbdev, - usbduxsub[index].ifnum, - 3); - if (i<0) { - printk("comedi_: usbdux%d: could not set alternate setting 3 in high speed.\n",index); + i = usb_set_interface(usbduxsub[index].usbdev, + usbduxsub[index].ifnum, 3); + if (i < 0) { + printk("comedi_: usbdux%d: could not set alternate setting 3 in high speed.\n", index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENODEV); + return PROBE_ERR_RETURN(-ENODEV); } if (usbduxsub[index].high_speed) { - usbduxsub[index].numOfInBuffers=NUMOFINBUFFERSHIGH; + usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSHIGH; } else { - usbduxsub[index].numOfInBuffers=NUMOFINBUFFERSFULL; + usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; } - usbduxsub[index].urbIn=kmalloc(sizeof(struct urb*)*usbduxsub[index].numOfInBuffers, - GFP_KERNEL); + usbduxsub[index].urbIn = + kmalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers, + GFP_KERNEL); if (!(usbduxsub[index].urbIn)) { printk("comedi_: usbdux: Could not alloc. urbIn array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - for (i=0; i < usbduxsub[index].numOfInBuffers; i++) { + for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) { // one frame: 1ms - usbduxsub[index].urbIn[i]=USB_ALLOC_URB(1); - if (usbduxsub[index].urbIn[i]==NULL) { - printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",index,i); + usbduxsub[index].urbIn[i] = USB_ALLOC_URB(1); + if (usbduxsub[index].urbIn[i] == NULL) { + printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n", + index, i); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev; // will be filled later with a pointer to the comedi-device @@ -2395,13 +2167,14 @@ static int usbduxsub_probe(struct usb_interface *uinterf, usbduxsub[index].urbIn[i]->pipe = usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP); usbduxsub[index].urbIn[i]->transfer_flags = URB_ISO_ASAP; - usbduxsub[index].urbIn[i]->transfer_buffer= - kmalloc(SIZEINBUF,GFP_KERNEL); + usbduxsub[index].urbIn[i]->transfer_buffer = + kmalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { - printk("comedi_: usbdux%d: could not alloc. transb.\n",index); + printk("comedi_: usbdux%d: could not alloc. transb.\n", + index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq; usbduxsub[index].urbIn[i]->number_of_packets = 1; @@ -2410,30 +2183,30 @@ static int usbduxsub_probe(struct usb_interface *uinterf, usbduxsub[index].urbIn[i]->iso_frame_desc[0].length = SIZEINBUF; } - // out if (usbduxsub[index].high_speed) { - usbduxsub[index].numOfOutBuffers=NUMOFOUTBUFFERSHIGH; + usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSHIGH; } else { - usbduxsub[index].numOfOutBuffers=NUMOFOUTBUFFERSFULL; + usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; } - usbduxsub[index].urbOut= - kmalloc(sizeof(struct urb*)*usbduxsub[index].numOfOutBuffers, - GFP_KERNEL); + usbduxsub[index].urbOut = + kmalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers, + GFP_KERNEL); if (!(usbduxsub[index].urbOut)) { printk("comedi_: usbdux: Could not alloc. urbOut array\n"); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - for (i=0; i < usbduxsub[index].numOfOutBuffers; i++) { + for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) { // one frame: 1ms - usbduxsub[index].urbOut[i]=USB_ALLOC_URB(1); - if (usbduxsub[index].urbOut[i]==NULL) { - printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",index,i); + usbduxsub[index].urbOut[i] = USB_ALLOC_URB(1); + if (usbduxsub[index].urbOut[i] == NULL) { + printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n", + index, i); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev; // will be filled later with a pointer to the comedi-device @@ -2442,60 +2215,57 @@ static int usbduxsub_probe(struct usb_interface *uinterf, usbduxsub[index].urbOut[i]->pipe = usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP); usbduxsub[index].urbOut[i]->transfer_flags = URB_ISO_ASAP; - usbduxsub[index].urbOut[i]->transfer_buffer= - kmalloc(SIZEOUTBUF,GFP_KERNEL); + usbduxsub[index].urbOut[i]->transfer_buffer = + kmalloc(SIZEOUTBUF, GFP_KERNEL); if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { - printk("comedi_: usbdux%d: could not alloc. transb.\n",index); + printk("comedi_: usbdux%d: could not alloc. transb.\n", + index); tidy_up(&(usbduxsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq; usbduxsub[index].urbOut[i]->number_of_packets = 1; - usbduxsub[index].urbOut[i]->transfer_buffer_length = - SIZEOUTBUF; + usbduxsub[index].urbOut[i]->transfer_buffer_length = SIZEOUTBUF; usbduxsub[index].urbOut[i]->iso_frame_desc[0].offset = 0; usbduxsub[index].urbOut[i]->iso_frame_desc[0].length = SIZEOUTBUF; if (usbduxsub[index].high_speed) { // uframes - usbduxsub[index].urbOut[i]->interval=8; + usbduxsub[index].urbOut[i]->interval = 8; } else { // frames - usbduxsub[index].urbOut[i]->interval=1; + usbduxsub[index].urbOut[i]->interval = 1; } } // we've reached the bottom of the function - usbduxsub[index].probed=1; + usbduxsub[index].probed = 1; up(&start_stop_sem); - printk("comedi_: usbdux%d has been successfully initialised.\n",index); + printk("comedi_: usbdux%d has been successfully initialised.\n", index); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) - return (void*)(&usbduxsub[index]); + return (void *)(&usbduxsub[index]); #else // success return 0; #endif } - - - - - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -static void usbduxsub_disconnect(struct usb_device *udev, void *ptr) { - usbduxsub_t* usbduxsub_tmp=(usbduxsub_t*)ptr; +static void usbduxsub_disconnect(struct usb_device *udev, void *ptr) +{ + usbduxsub_t *usbduxsub_tmp = (usbduxsub_t *) ptr; #else -static void usbduxsub_disconnect(struct usb_interface *intf) { - usbduxsub_t* usbduxsub_tmp= usb_get_intfdata(intf); - struct usb_device *udev = interface_to_usbdev(intf); +static void usbduxsub_disconnect(struct usb_interface *intf) +{ + usbduxsub_t *usbduxsub_tmp = usb_get_intfdata(intf); + struct usb_device *udev = interface_to_usbdev(intf); #endif if (!usbduxsub_tmp) { printk("comedi_: usbdux: disconnect called with null pointer.\n"); return; } - if (usbduxsub_tmp->usbdev!=udev) { + if (usbduxsub_tmp->usbdev != udev) { printk("comedi_: usbdux: BUG! called with wrong ptr!!!\n"); return; } @@ -2509,66 +2279,60 @@ static void usbduxsub_disconnect(struct usb_interface *intf) { #endif } - - - - // is called when comedi-config is called static int usbdux_attach(comedi_device * dev, comedi_devconfig * it) { int ret; int index; int i; - comedi_subdevice *s=NULL; - dev->private=NULL; + comedi_subdevice *s = NULL; + dev->private = NULL; down(&start_stop_sem); // find a valid device which has been detected by the probe function of the usb - index=-1; - for(i=0;iminor); + if (index < 0) { + printk("comedi%d: usbdux: error: attach failed, no usbdux devs connected to the usb bus.\n", dev->minor); up(&start_stop_sem); return -ENODEV; } down(&(usbduxsub[index].sem)); // pointer back to the corresponding comedi device - usbduxsub[index].comedidev=dev; + usbduxsub[index].comedidev = dev; // trying to upload the firmware into the chip - if(comedi_aux_data(it->options, 0) && - it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]){ - read_firmware(usbduxsub+index, - comedi_aux_data(it->options, 0), - it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]); + if (comedi_aux_data(it->options, 0) && + it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { + read_firmware(usbduxsub + index, + comedi_aux_data(it->options, 0), + it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]); } dev->board_name = BOARDNAME; /* set number of subdevices */ - dev->n_subdevices=N_SUBDEVICES; + dev->n_subdevices = N_SUBDEVICES; // allocate space for the subdevices - if((ret=alloc_subdevices(dev,N_SUBDEVICES))<0) { + if ((ret = alloc_subdevices(dev, N_SUBDEVICES)) < 0) { printk("comedi%d: usbdux: error alloc space for subdev\n", - dev->minor); + dev->minor); up(&start_stop_sem); return ret; } printk("comedi%d: usbdux: usb-device %d is attached to comedi.\n", - dev->minor,index); + dev->minor, index); // private structure is also simply the usb-structure - dev->private=usbduxsub+index; + dev->private = usbduxsub + index; // the first subdevice is the A/D converter s = dev->subdevices + SUBDEV_AD; // the URBs get the comedi subdevice @@ -2577,45 +2341,45 @@ static int usbdux_attach(comedi_device * dev, comedi_devconfig * it) dev->read_subdev = s; // the subdevice receives as private structure the // usb-structure - s->private=NULL; + s->private = NULL; // analog input - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; // readable and ref is to ground s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; // 8 channels - s->n_chan=8; + s->n_chan = 8; // length of the channellist - s->len_chanlist=8; + s->len_chanlist = 8; // callback functions s->insn_read = usbdux_ai_insn_read; - s->do_cmdtest=usbdux_ai_cmdtest; - s->do_cmd=usbdux_ai_cmd; - s->cancel=usbdux_ai_cancel; + s->do_cmdtest = usbdux_ai_cmdtest; + s->do_cmd = usbdux_ai_cmd; + s->cancel = usbdux_ai_cancel; // max value from the A/D converter (12bit) - s->maxdata=0xfff; + s->maxdata = 0xfff; // range table to convert to physical units s->range_table = &range_usbdux_ai_range; // // analog out - s=dev->subdevices + SUBDEV_DA; + s = dev->subdevices + SUBDEV_DA; // analog out - s->type=COMEDI_SUBD_AO; + s->type = COMEDI_SUBD_AO; // backward pointer - dev->write_subdev=s; + dev->write_subdev = s; // the subdevice receives as private structure the // usb-structure - s->private=NULL; + s->private = NULL; // are writable s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE; // 4 channels - s->n_chan=4; + s->n_chan = 4; // length of the channellist - s->len_chanlist=4; + s->len_chanlist = 4; // 12 bit resolution - s->maxdata=0x0fff; + s->maxdata = 0x0fff; // bipolar range - s->range_table=&range_usbdux_ao_range; + s->range_table = &range_usbdux_ao_range; // callback s->do_cmdtest = usbdux_ao_cmdtest; s->do_cmd = usbdux_ao_cmd; @@ -2624,19 +2388,19 @@ static int usbdux_attach(comedi_device * dev, comedi_devconfig * it) s->insn_write = usbdux_ao_insn_write; // digital I/O - s=dev->subdevices + SUBDEV_DIO; - s->type=COMEDI_SUBD_DIO; - s->subdev_flags=SDF_READABLE|SDF_WRITABLE; - s->n_chan=8; - s->maxdata=1; - s->range_table=&range_digital; + s = dev->subdevices + SUBDEV_DIO; + s->type = COMEDI_SUBD_DIO; + s->subdev_flags = SDF_READABLE | SDF_WRITABLE; + s->n_chan = 8; + s->maxdata = 1; + s->range_table = &range_digital; s->insn_bits = usbdux_dio_insn_bits; s->insn_config = usbdux_dio_insn_config; // we don't use it - s->private=NULL; + s->private = NULL; //counter - s=dev->subdevices + SUBDEV_COUNTER; + s = dev->subdevices + SUBDEV_COUNTER; s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_WRITABLE | SDF_READABLE; s->n_chan = 4; @@ -2646,29 +2410,23 @@ static int usbdux_attach(comedi_device * dev, comedi_devconfig * it) s->insn_config = usbdux_counter_config; // finally decide that it's attached - usbduxsub[index].attached=1; + usbduxsub[index].attached = 1; up(&(usbduxsub[index].sem)); up(&start_stop_sem); - printk("comedi%d: attached to usbdux.\n", - dev->minor); + printk("comedi%d: attached to usbdux.\n", dev->minor); return 0; } - - - - - -static int usbdux_detach(comedi_device * dev) { - usbduxsub_t* usbduxsub_tmp; +static int usbdux_detach(comedi_device * dev) +{ + usbduxsub_t *usbduxsub_tmp; #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbdux: detach usb device\n", - dev->minor); + printk("comedi%d: usbdux: detach usb device\n", dev->minor); #endif if (!dev) { @@ -2676,7 +2434,7 @@ static int usbdux_detach(comedi_device * dev) { return -EFAULT; } - usbduxsub_tmp=dev->private; + usbduxsub_tmp = dev->private; if (!usbduxsub_tmp) { printk("comedi?: usbdux: detach without ptr to usbduxsub[]\n"); return -EFAULT; @@ -2685,42 +2443,26 @@ static int usbdux_detach(comedi_device * dev) { down(&usbduxsub_tmp->sem); // Don't allow detach to free the private structure // It's one entry of of usbduxsub[] - dev->private=NULL; - usbduxsub_tmp->attached=0; - usbduxsub_tmp->comedidev=NULL; + dev->private = NULL; + usbduxsub_tmp->attached = 0; + usbduxsub_tmp->comedidev = NULL; #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbdux: detach: successfully removed\n", - dev->minor); + printk("comedi%d: usbdux: detach: successfully removed\n", dev->minor); #endif up(&usbduxsub_tmp->sem); return 0; } - - - - - - - /* main driver struct */ -static comedi_driver driver_usbdux={ - driver_name: "usbdux", - module: THIS_MODULE, - attach: usbdux_attach, - detach: usbdux_detach, +static comedi_driver driver_usbdux = { + driver_name:"usbdux", + module:THIS_MODULE, + attach:usbdux_attach, + detach:usbdux_detach, }; - - - - - - - - - -static void init_usb_devices(void) { +static void init_usb_devices(void) +{ int index; #ifdef CONFIG_COMEDI_DEBUG printk("comedi_: usbdux: setting all possible devs to invalid\n"); @@ -2728,65 +2470,56 @@ static void init_usb_devices(void) { // all devices entries are invalid to begin with // they will become valid by the probe function // and then finally by the attach-function - for(index=0;index #include #include @@ -103,7 +102,7 @@ Status: testing #define SIZEINSNBUF 512 // Size of the buffer for the dux commands -#define SIZEOFDUXBUFFER 256 // bytes +#define SIZEOFDUXBUFFER 256 // bytes // Number of in-URBs which receive the data: min=5 #define NUMOFINBUFFERSHIGH 10 @@ -119,7 +118,7 @@ Status: testing // min delay steps for more than one channel // basically when the mux gives up. ;-) -#define MIN_SAMPLING_PERIOD 9 // steps at 30MHz in the FX2 +#define MIN_SAMPLING_PERIOD 9 // steps at 30MHz in the FX2 // Max number of 1/30MHz delay steps: #define MAX_SAMPLING_PERIOD 500 @@ -131,10 +130,10 @@ Status: testing ///////////////////////////////////////////// // comedi constants static const comedi_lrange range_usbduxfast_ai_range = { 2, { - BIP_RANGE( 0.75 ), - BIP_RANGE( 0.5 ), -} }; - + BIP_RANGE(0.75), + BIP_RANGE(0.5), + } +}; /* * private structure of one subdevice @@ -148,9 +147,9 @@ typedef struct { // is it associated with a subdevice? int probed; // pointer to the usb-device - struct usb_device *usbdev; - // BULK-transfer handling: urb - struct urb *urbIn; + struct usb_device *usbdev; + // BULK-transfer handling: urb + struct urb *urbIn; int8_t *transfer_buffer; // input buffer for single insn int16_t *insnBuffer; @@ -158,7 +157,7 @@ typedef struct { int ifnum; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) // interface structure in 2.6 - struct usb_interface * interface; + struct usb_interface *interface; #endif // comedi device for the interrupt context comedi_device *comedidev; @@ -175,8 +174,6 @@ typedef struct { struct semaphore sem; } usbduxfastsub_t; - - // The pointer to the private usb-data of the driver // is also the private data for the comedi-device. // This has to be global as the usb subsystem needs @@ -186,121 +183,102 @@ typedef struct { // initialised before comedi can access it. static usbduxfastsub_t usbduxfastsub[NUMUSBDUXFAST]; - - - -static DECLARE_MUTEX (start_stop_sem); - - - +static DECLARE_MUTEX(start_stop_sem); // bulk transfers to usbduxfast #define SENDADCOMMANDS 0 #define SENDINITEP6 1 -static int send_dux_commands(usbduxfastsub_t* this_usbduxfastsub,int cmd_type) { - int result,nsent; - this_usbduxfastsub->dux_commands[0]=cmd_type; +static int send_dux_commands(usbduxfastsub_t * this_usbduxfastsub, int cmd_type) +{ + int result, nsent; + this_usbduxfastsub->dux_commands[0] = cmd_type; #ifdef CONFIG_COMEDI_DEBUG int i; printk("comedi%d: usbduxfast: dux_commands: ", - this_usbduxfastsub->comedidev->minor); - for(i=0;idux_commands[i]); + this_usbduxfastsub->comedidev->minor); + for (i = 0; i < SIZEOFDUXBUFFER; i++) { + printk(" %02x", this_usbduxfastsub->dux_commands[i]); } printk("\n"); #endif result = USB_BULK_MSG(this_usbduxfastsub->usbdev, - usb_sndbulkpipe(this_usbduxfastsub->usbdev, - CHANNELLISTEP), - this_usbduxfastsub->dux_commands, - SIZEOFDUXBUFFER, - &nsent, - 10000); - if (result<0) { - printk("comedi%d: could not transmit dux_commands to the usb-device, err=%d\n", - this_usbduxfastsub->comedidev->minor,result); + usb_sndbulkpipe(this_usbduxfastsub->usbdev, + CHANNELLISTEP), + this_usbduxfastsub->dux_commands, + SIZEOFDUXBUFFER, &nsent, 10000); + if (result < 0) { + printk("comedi%d: could not transmit dux_commands to the usb-device, err=%d\n", this_usbduxfastsub->comedidev->minor, result); } return result; } - - - - // Stops the data acquision // It should be safe to call this function from any context -static int usbduxfastsub_unlink_InURBs(usbduxfastsub_t* usbduxfastsub_tmp) { - int j=0; - int err=0; +static int usbduxfastsub_unlink_InURBs(usbduxfastsub_t * usbduxfastsub_tmp) +{ + int j = 0; + int err = 0; if (usbduxfastsub_tmp && usbduxfastsub_tmp->urbIn) { - usbduxfastsub_tmp->ai_cmd_running=0; + usbduxfastsub_tmp->ai_cmd_running = 0; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) - j=usb_unlink_urb(usbduxfastsub_tmp->urbIn); - if (j<0) { - err=j; + j = usb_unlink_urb(usbduxfastsub_tmp->urbIn); + if (j < 0) { + err = j; } #else // waits until a running transfer is over usb_kill_urb(usbduxfastsub_tmp->urbIn); - j=0; + j = 0; #endif } #ifdef CONFIG_COMEDI_DEBUG - printk("comedi: usbduxfast: unlinked InURB: res=%d\n", - j); + printk("comedi: usbduxfast: unlinked InURB: res=%d\n", j); #endif return err; } - - /* This will stop a running acquisition operation */ // Is called from within this driver from both the // interrupt context and from comedi -static int usbduxfast_ai_stop(usbduxfastsub_t* this_usbduxfastsub, - int do_unlink) +static int usbduxfast_ai_stop(usbduxfastsub_t * this_usbduxfastsub, + int do_unlink) { - int ret=0; + int ret = 0; if (!this_usbduxfastsub) { printk("comedi?: usbduxfast_ai_stop: this_usbduxfastsub=NULL!\n"); return -EFAULT; } - #ifdef CONFIG_COMEDI_DEBUG printk("comedi: usbduxfast_ai_stop\n"); #endif - - this_usbduxfastsub->ai_cmd_running=0; + this_usbduxfastsub->ai_cmd_running = 0; if (do_unlink) { // stop aquistion - ret=usbduxfastsub_unlink_InURBs(this_usbduxfastsub); + ret = usbduxfastsub_unlink_InURBs(this_usbduxfastsub); } return ret; } - - // This will cancel a running acquisition operation. // This is called by comedi but never from inside the // driver. -static int usbduxfast_ai_cancel(comedi_device *dev, - comedi_subdevice *s) +static int usbduxfast_ai_cancel(comedi_device * dev, comedi_subdevice * s) { - usbduxfastsub_t* this_usbduxfastsub; - int res=0; + usbduxfastsub_t *this_usbduxfastsub; + int res = 0; // force unlink of all urbs #ifdef CONFIG_COMEDI_DEBUG printk("comedi: usbduxfast_ai_cancel\n"); #endif - this_usbduxfastsub=dev->private; + this_usbduxfastsub = dev->private; if (!this_usbduxfastsub) { printk("comedi: usbduxfast_ai_cancel: this_usbduxfastsub=NULL\n"); return -EFAULT; @@ -311,15 +289,12 @@ static int usbduxfast_ai_cancel(comedi_device *dev, return -ENODEV; } // unlink - res=usbduxfast_ai_stop(this_usbduxfastsub,1); + res = usbduxfast_ai_stop(this_usbduxfastsub, 1); up(&this_usbduxfastsub->sem); return res; } - - - // analogue IN // interrupt service routine #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) @@ -328,11 +303,11 @@ static void usbduxfastsub_ai_Irq(struct urb *urb) static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG) #endif { - int n,err; - usbduxfastsub_t* this_usbduxfastsub; + int n, err; + usbduxfastsub_t *this_usbduxfastsub; comedi_device *this_comedidev; comedi_subdevice *s; - uint16_t* p; + uint16_t *p; // sanity checks // is the urb there? @@ -340,21 +315,18 @@ static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG) printk("comedi_: usbduxfast_: ao int-handler called with urb=NULL!\n"); return; } - // the context variable points to the subdevice - this_comedidev=urb->context; + this_comedidev = urb->context; if (!this_comedidev) { printk("comedi_: usbduxfast_: urb context is a NULL pointer!\n"); return; } - // the private structure of the subdevice is usbduxfastsub_t - this_usbduxfastsub=this_comedidev->private; + this_usbduxfastsub = this_comedidev->private; if (!this_usbduxfastsub) { printk("comedi_: usbduxfast_: private of comedi subdev is a NULL pointer!\n"); return; } - // are we running a command? if (unlikely(!(this_usbduxfastsub->ai_cmd_running))) { // not running a command @@ -367,70 +339,61 @@ static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG) // no comedi device there return; } - // subdevice which is the AD converter - s=this_comedidev->subdevices + SUBDEV_AD; + s = this_comedidev->subdevices + SUBDEV_AD; // first we test if something unusual has just happened switch (urb->status) { - case 0: + case 0: break; // happens after an unlink command or when the device is plugged out - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: case -ECONNABORTED: // tell this comedi s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxfastsub->comedidev, - s); + comedi_event(this_usbduxfastsub->comedidev, s); // stop the transfer w/o unlink - usbduxfast_ai_stop(this_usbduxfastsub,0); + usbduxfast_ai_stop(this_usbduxfastsub, 0); return; default: - printk("comedi%d: usbduxfast: non-zero urb status received in ai intr context: %d\n", - this_usbduxfastsub->comedidev->minor, - urb->status); + printk("comedi%d: usbduxfast: non-zero urb status received in ai intr context: %d\n", this_usbduxfastsub->comedidev->minor, urb->status); s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxfastsub->comedidev, - s); - usbduxfast_ai_stop(this_usbduxfastsub,0); + comedi_event(this_usbduxfastsub->comedidev, s); + usbduxfast_ai_stop(this_usbduxfastsub, 0); return; } - p=urb->transfer_buffer; + p = urb->transfer_buffer; if (!this_usbduxfastsub->ignore) { if (!(this_usbduxfastsub->ai_continous)) { // not continous, fixed number of samples - n=urb->actual_length/sizeof(uint16_t); - if (unlikely(this_usbduxfastsub->ai_sample_countactual_length / sizeof(uint16_t); + if (unlikely(this_usbduxfastsub->ai_sample_count < n)) { // we have send only a fraction of the bytes received cfc_write_array_to_buffer(s, - urb->transfer_buffer, - this_usbduxfastsub->ai_sample_count*sizeof(uint16_t)); - usbduxfast_ai_stop(this_usbduxfastsub, - 0); + urb->transfer_buffer, + this_usbduxfastsub->ai_sample_count * + sizeof(uint16_t)); + usbduxfast_ai_stop(this_usbduxfastsub, 0); // say comedi that the acquistion is over s->async->events |= COMEDI_CB_EOA; - comedi_event(this_usbduxfastsub->comedidev, - s); + comedi_event(this_usbduxfastsub->comedidev, s); return; } - this_usbduxfastsub->ai_sample_count-=n; + this_usbduxfastsub->ai_sample_count -= n; } - // write the full buffer to comedi cfc_write_array_to_buffer(s, - urb->transfer_buffer, - urb->actual_length); + urb->transfer_buffer, urb->actual_length); // tell comedi that data is there - comedi_event(this_usbduxfastsub->comedidev, - s); + comedi_event(this_usbduxfastsub->comedidev, s); } else { // ignore this packet @@ -441,49 +404,42 @@ static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG) // resubmit urb for BULK transfer urb->dev = this_usbduxfastsub->usbdev; urb->status = 0; - if ((err=USB_SUBMIT_URB(urb))<0) { + if ((err = USB_SUBMIT_URB(urb)) < 0) { printk("comedi%d: usbduxfast: urb resubm failed: %d", - this_usbduxfastsub->comedidev->minor, - err); + this_usbduxfastsub->comedidev->minor, err); s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_ERROR; - comedi_event(this_usbduxfastsub->comedidev, - s); - usbduxfast_ai_stop(this_usbduxfastsub,0); + comedi_event(this_usbduxfastsub->comedidev, s); + usbduxfast_ai_stop(this_usbduxfastsub, 0); } } - - - - -static int usbduxfastsub_start(usbduxfastsub_t* usbduxfastsub) { - int errcode=0; +static int usbduxfastsub_start(usbduxfastsub_t * usbduxfastsub) +{ + int errcode = 0; unsigned char local_transfer_buffer[16]; if (usbduxfastsub->probed) { // 7f92 to zero - local_transfer_buffer[0]=0; - errcode=USB_CONTROL_MSG - (usbduxfastsub->usbdev, - // create a pipe for a control transfer - usb_sndctrlpipe(usbduxfastsub->usbdev,0), - // bRequest, "Firmware" - USBDUXFASTSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // Value - USBDUXFASTSUB_CPUCS, - // Index - 0x0000, - // address of the transfer buffer - local_transfer_buffer, - // Length - 1, - // Timeout - EZTIMEOUT - ); - if (errcode<0) { + local_transfer_buffer[0] = 0; + errcode = USB_CONTROL_MSG(usbduxfastsub->usbdev, + // create a pipe for a control transfer + usb_sndctrlpipe(usbduxfastsub->usbdev, 0), + // bRequest, "Firmware" + USBDUXFASTSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // Value + USBDUXFASTSUB_CPUCS, + // Index + 0x0000, + // address of the transfer buffer + local_transfer_buffer, + // Length + 1, + // Timeout + EZTIMEOUT); + if (errcode < 0) { printk("comedi_: usbduxfast_: control msg failed (start)\n"); return errcode; } @@ -491,34 +447,30 @@ static int usbduxfastsub_start(usbduxfastsub_t* usbduxfastsub) { return 0; } - - - -static int usbduxfastsub_stop(usbduxfastsub_t* usbduxfastsub) { - int errcode=0; +static int usbduxfastsub_stop(usbduxfastsub_t * usbduxfastsub) +{ + int errcode = 0; unsigned char local_transfer_buffer[16]; if (usbduxfastsub->probed) { // 7f92 to one - local_transfer_buffer[0]=1; - errcode=USB_CONTROL_MSG + local_transfer_buffer[0] = 1; + errcode = USB_CONTROL_MSG (usbduxfastsub->usbdev, - usb_sndctrlpipe(usbduxfastsub->usbdev,0), - // bRequest, "Firmware" - USBDUXFASTSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // Value - USBDUXFASTSUB_CPUCS, - // Index - 0x0000, - local_transfer_buffer, - // Length - 1, - // Timeout - EZTIMEOUT - ); - if (errcode<0) { + usb_sndctrlpipe(usbduxfastsub->usbdev, 0), + // bRequest, "Firmware" + USBDUXFASTSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // Value + USBDUXFASTSUB_CPUCS, + // Index + 0x0000, local_transfer_buffer, + // Length + 1, + // Timeout + EZTIMEOUT); + if (errcode < 0) { printk("comedi_: usbduxfast: control msg failed (stop)\n"); return errcode; } @@ -526,46 +478,40 @@ static int usbduxfastsub_stop(usbduxfastsub_t* usbduxfastsub) { return 0; } - - - - -static int usbduxfastsub_upload(usbduxfastsub_t* usbduxfastsub, - unsigned char* local_transfer_buffer, - unsigned int startAddr, - unsigned int len) { +static int usbduxfastsub_upload(usbduxfastsub_t * usbduxfastsub, + unsigned char *local_transfer_buffer, + unsigned int startAddr, unsigned int len) +{ int errcode; if (usbduxfastsub->probed) { #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbduxfast: uploading %d bytes", - usbduxfastsub->comedidev->minor,len); + usbduxfastsub->comedidev->minor, len); printk(" to addr %d, first byte=%d.\n", - startAddr, - local_transfer_buffer[0]); + startAddr, local_transfer_buffer[0]); #endif - errcode=USB_CONTROL_MSG + errcode = USB_CONTROL_MSG (usbduxfastsub->usbdev, - usb_sndctrlpipe(usbduxfastsub->usbdev, 0), - // brequest, firmware - USBDUXFASTSUB_FIRMWARE, - // bmRequestType - VENDOR_DIR_OUT, - // value - startAddr, - // index - 0x0000, - // our local safe buffer - local_transfer_buffer, - // length - len, - // timeout - EZTIMEOUT - ); + usb_sndctrlpipe(usbduxfastsub->usbdev, 0), + // brequest, firmware + USBDUXFASTSUB_FIRMWARE, + // bmRequestType + VENDOR_DIR_OUT, + // value + startAddr, + // index + 0x0000, + // our local safe buffer + local_transfer_buffer, + // length + len, + // timeout + EZTIMEOUT); #ifdef CONFIG_COMEDI_DEBUG - printk("comedi_: usbduxfast: result=%d\n",errcode); + printk("comedi_: usbduxfast: result=%d\n", errcode); #endif - if (errcode<0) { + if (errcode < 0) { printk("comedi_: usbduxfast: uppload failed\n"); return errcode; } @@ -573,215 +519,194 @@ static int usbduxfastsub_upload(usbduxfastsub_t* usbduxfastsub, // no device on the bus for this index return -EFAULT; } -return 0; + return 0; } - - - - -int firmwareUpload(usbduxfastsub_t* usbduxfastsub, - unsigned char* firmwareBinary, - int sizeFirmware) { +int firmwareUpload(usbduxfastsub_t * usbduxfastsub, + unsigned char *firmwareBinary, int sizeFirmware) +{ int ret; if (!firmwareBinary) { return 0; } - ret=usbduxfastsub_stop(usbduxfastsub); - if (ret<0) { - printk("comedi_: usbduxfast: can not stop firmware\n" - ); + ret = usbduxfastsub_stop(usbduxfastsub); + if (ret < 0) { + printk("comedi_: usbduxfast: can not stop firmware\n"); return ret; } - ret=usbduxfastsub_upload(usbduxfastsub, - firmwareBinary, - 0, - sizeFirmware); - if (ret<0) { - printk("comedi_: usbduxfast: firmware upload failed\n" - ); + ret = usbduxfastsub_upload(usbduxfastsub, + firmwareBinary, 0, sizeFirmware); + if (ret < 0) { + printk("comedi_: usbduxfast: firmware upload failed\n"); return ret; } - ret=usbduxfastsub_start(usbduxfastsub); - if (ret<0) { - printk("comedi_: usbduxfast: can not start firmware\n" - ); + ret = usbduxfastsub_start(usbduxfastsub); + if (ret < 0) { + printk("comedi_: usbduxfast: can not start firmware\n"); return ret; } return 0; } - - -int usbduxfastsub_submit_InURBs(usbduxfastsub_t* usbduxfastsub) { +int usbduxfastsub_submit_InURBs(usbduxfastsub_t * usbduxfastsub) +{ int errFlag; if (!usbduxfastsub) { return -EFAULT; } - usb_fill_bulk_urb(usbduxfastsub->urbIn, - usbduxfastsub->usbdev, - usb_rcvbulkpipe(usbduxfastsub->usbdev,BULKINEP), - usbduxfastsub->transfer_buffer, - SIZEINBUF, - usbduxfastsub_ai_Irq, - usbduxfastsub->comedidev); + usb_fill_bulk_urb(usbduxfastsub->urbIn, + usbduxfastsub->usbdev, + usb_rcvbulkpipe(usbduxfastsub->usbdev, BULKINEP), + usbduxfastsub->transfer_buffer, + SIZEINBUF, usbduxfastsub_ai_Irq, usbduxfastsub->comedidev); #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbduxfast: submitting in-urb: %x,%x\n", - usbduxfastsub->comedidev->minor, - (int)(usbduxfastsub->urbIn->context), - (int)(usbduxfastsub->urbIn->dev)); + usbduxfastsub->comedidev->minor, + (int)(usbduxfastsub->urbIn->context), + (int)(usbduxfastsub->urbIn->dev)); #endif - errFlag = USB_SUBMIT_URB - (usbduxfastsub->urbIn); + errFlag = USB_SUBMIT_URB(usbduxfastsub->urbIn); if (errFlag) { printk("comedi_: usbduxfast: ai: "); printk("USB_SUBMIT_URB"); - printk(" error %d\n",errFlag); + printk(" error %d\n", errFlag); return errFlag; } return 0; } - - - -static int usbduxfast_ai_cmdtest(comedi_device *dev, - comedi_subdevice *s, - comedi_cmd *cmd) +static int usbduxfast_ai_cmdtest(comedi_device * dev, + comedi_subdevice * s, comedi_cmd * cmd) { - int err=0, stop_mask=0; - long int steps,tmp=0; + int err = 0, stop_mask = 0; + long int steps, tmp = 0; int minSamplPer; - usbduxfastsub_t* this_usbduxfastsub=dev->private; + usbduxfastsub_t *this_usbduxfastsub = dev->private; if (!(this_usbduxfastsub->probed)) { return -ENODEV; } - #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbduxfast_ai_cmdtest\n",dev->minor); + printk("comedi%d: usbduxfast_ai_cmdtest\n", dev->minor); printk("comedi%d: usbduxfast: convert_arg=%u scan_begin_arg=%u\n", - dev->minor, - cmd->convert_arg, - cmd->scan_begin_arg); + dev->minor, cmd->convert_arg, cmd->scan_begin_arg); #endif /* step 1: make sure trigger sources are trivially valid */ tmp = cmd->start_src; cmd->start_src &= TRIG_NOW | TRIG_EXT | TRIG_INT; - if(!cmd->start_src || tmp != cmd->start_src) err++; + if (!cmd->start_src || tmp != cmd->start_src) + err++; tmp = cmd->scan_begin_src; cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT; - if(!cmd->scan_begin_src || tmp != cmd->scan_begin_src) err++; + if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src) + err++; tmp = cmd->convert_src; cmd->convert_src &= TRIG_TIMER | TRIG_EXT; - if(!cmd->convert_src || tmp != cmd->convert_src) err++; + if (!cmd->convert_src || tmp != cmd->convert_src) + err++; tmp = cmd->scan_end_src; cmd->scan_end_src &= TRIG_COUNT; - if(!cmd->scan_end_src || tmp != cmd->scan_end_src) err++; + if (!cmd->scan_end_src || tmp != cmd->scan_end_src) + err++; - tmp=cmd->stop_src; + tmp = cmd->stop_src; stop_mask = TRIG_COUNT | TRIG_NONE; cmd->stop_src &= stop_mask; - if(!cmd->stop_src || tmp!=cmd->stop_src) err++; + if (!cmd->stop_src || tmp != cmd->stop_src) + err++; - if(err) return 1; + if (err) + return 1; /* step 2: make sure trigger sources are unique and mutually compatible */ - if(cmd->start_src != TRIG_NOW && - cmd->start_src != TRIG_EXT && - cmd->start_src != TRIG_INT) err++; - if(cmd->scan_begin_src != TRIG_TIMER && + if (cmd->start_src != TRIG_NOW && + cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT) + err++; + if (cmd->scan_begin_src != TRIG_TIMER && cmd->scan_begin_src != TRIG_FOLLOW && - cmd->scan_begin_src != TRIG_EXT) err++; - if(cmd->convert_src != TRIG_TIMER && - cmd->convert_src != TRIG_EXT) err++; - if(cmd->stop_src != TRIG_COUNT && - cmd->stop_src != TRIG_EXT && - cmd->stop_src != TRIG_NONE) err++; + cmd->scan_begin_src != TRIG_EXT) + err++; + if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT) + err++; + if (cmd->stop_src != TRIG_COUNT && + cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE) + err++; // can't have external stop and start triggers at once - if(cmd->start_src == TRIG_EXT && - cmd->stop_src == TRIG_EXT) err++; + if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) + err++; - if(err)return 2; + if (err) + return 2; /* step 3: make sure arguments are trivially compatible */ - if(cmd->start_src == TRIG_NOW && cmd->start_arg != 0) - { + if (cmd->start_src == TRIG_NOW && cmd->start_arg != 0) { cmd->start_arg = 0; err++; } - if(!cmd->chanlist_len) - { + if (!cmd->chanlist_len) { err++; } - if(cmd->scan_end_arg != cmd->chanlist_len) - { + if (cmd->scan_end_arg != cmd->chanlist_len) { cmd->scan_end_arg = cmd->chanlist_len; err++; } - if (cmd->chanlist_len==1) { - minSamplPer=1; + if (cmd->chanlist_len == 1) { + minSamplPer = 1; } else { - minSamplPer=MIN_SAMPLING_PERIOD; + minSamplPer = MIN_SAMPLING_PERIOD; } - if(cmd->convert_src == TRIG_TIMER) - { - steps=cmd->convert_arg*30; - if (steps<(minSamplPer*1000)) { - steps=minSamplPer*1000; + if (cmd->convert_src == TRIG_TIMER) { + steps = cmd->convert_arg * 30; + if (steps < (minSamplPer * 1000)) { + steps = minSamplPer * 1000; } - if (steps>(MAX_SAMPLING_PERIOD*1000)) { - steps=MAX_SAMPLING_PERIOD*1000; + if (steps > (MAX_SAMPLING_PERIOD * 1000)) { + steps = MAX_SAMPLING_PERIOD * 1000; } // calc arg again - tmp=steps/30; - if(cmd->convert_arg != tmp) - { + tmp = steps / 30; + if (cmd->convert_arg != tmp) { cmd->convert_arg = tmp; err++; } } - if(cmd->scan_begin_src == TRIG_TIMER) - { + if (cmd->scan_begin_src == TRIG_TIMER) { err++; } - // stop source - switch(cmd->stop_src) - { - case TRIG_COUNT: - if(!cmd->stop_arg) - { - cmd->stop_arg = 1; - err++; - } - break; - case TRIG_NONE: - if(cmd->stop_arg != 0) - { - cmd->stop_arg = 0; - err++; - } - break; + switch (cmd->stop_src) { + case TRIG_COUNT: + if (!cmd->stop_arg) { + cmd->stop_arg = 1; + err++; + } + break; + case TRIG_NONE: + if (cmd->stop_arg != 0) { + cmd->stop_arg = 0; + err++; + } + break; // TRIG_EXT doesn't care since it doesn't trigger off a numbered channel - default: - break; + default: + break; } - if(err)return 3; + if (err) + return 3; /* step 4: fix up any arguments */ @@ -789,15 +714,11 @@ static int usbduxfast_ai_cmdtest(comedi_device *dev, } - - - -static int usbduxfast_ai_inttrig(comedi_device *dev, - comedi_subdevice *s, - unsigned int trignum) +static int usbduxfast_ai_inttrig(comedi_device * dev, + comedi_subdevice * s, unsigned int trignum) { int ret; - usbduxfastsub_t* this_usbduxfastsub=dev->private; + usbduxfastsub_t *this_usbduxfastsub = dev->private; if (!this_usbduxfastsub) { return -EFAULT; } @@ -806,39 +727,34 @@ static int usbduxfast_ai_inttrig(comedi_device *dev, up(&this_usbduxfastsub->sem); return -ENODEV; } - #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbduxfast_ai_inttrig\n",dev->minor); + printk("comedi%d: usbduxfast_ai_inttrig\n", dev->minor); #endif - if (trignum!=0) { - printk("comedi%d: usbduxfast_ai_inttrig: invalid trignum\n",dev->minor); + if (trignum != 0) { + printk("comedi%d: usbduxfast_ai_inttrig: invalid trignum\n", + dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } if (!(this_usbduxfastsub->ai_cmd_running)) { - this_usbduxfastsub->ai_cmd_running=1; - ret=usbduxfastsub_submit_InURBs(this_usbduxfastsub); - if (ret<0) { - printk("comedi%d: usbduxfast_ai_inttrig: urbSubmit: err=%d\n", - dev->minor,ret); - this_usbduxfastsub->ai_cmd_running=0; + this_usbduxfastsub->ai_cmd_running = 1; + ret = usbduxfastsub_submit_InURBs(this_usbduxfastsub); + if (ret < 0) { + printk("comedi%d: usbduxfast_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret); + this_usbduxfastsub->ai_cmd_running = 0; up(&this_usbduxfastsub->sem); return ret; } s->async->inttrig = NULL; } else { printk("comedi%d: ai_inttrig but acqu is already running\n", - dev->minor); + dev->minor); } up(&this_usbduxfastsub->sem); - return 1; + return 1; } - - - - // offsets for the GPIF bytes // the first byte is the command byte #define LENBASE 1+0x00 @@ -846,18 +762,17 @@ static int usbduxfast_ai_inttrig(comedi_device *dev, #define OUTBASE 1+0x10 #define LOGBASE 1+0x18 - -static int usbduxfast_ai_cmd(comedi_device *dev, comedi_subdevice *s) +static int usbduxfast_ai_cmd(comedi_device * dev, comedi_subdevice * s) { comedi_cmd *cmd = &s->async->cmd; - unsigned int chan,gain,rngmask=0xff; - int i,j,ret; - usbduxfastsub_t* this_usbduxfastsub=dev->private; + unsigned int chan, gain, rngmask = 0xff; + int i, j, ret; + usbduxfastsub_t *this_usbduxfastsub = dev->private; int result; - long steps,steps_tmp; + long steps, steps_tmp; #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbduxfast_ai_cmd\n",dev->minor); + printk("comedi%d: usbduxfast_ai_cmd\n", dev->minor); #endif if (!this_usbduxfastsub) { return -EFAULT; @@ -868,472 +783,490 @@ static int usbduxfast_ai_cmd(comedi_device *dev, comedi_subdevice *s) return -ENODEV; } if (this_usbduxfastsub->ai_cmd_running) { - printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", - dev->minor); + printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EBUSY; } - // set current channel of the running aquisition to zero s->async->cur_chan = 0; // ignore the first buffers from the device if there is an error condition - this_usbduxfastsub->ignore=PACKETS_TO_IGNORE; + this_usbduxfastsub->ignore = PACKETS_TO_IGNORE; - if (cmd->chanlist_len>0) { + if (cmd->chanlist_len > 0) { gain = CR_RANGE(cmd->chanlist[0]); - for(i=0; i < cmd->chanlist_len; ++i ) { + for (i = 0; i < cmd->chanlist_len; ++i) { chan = CR_CHAN(cmd->chanlist[i]); - if (chan!=i) { - printk("comedi%d: cmd is accepting only consecutive channels.\n", - dev->minor); + if (chan != i) { + printk("comedi%d: cmd is accepting only consecutive channels.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } - if ((gain != CR_RANGE(cmd->chanlist[i]))&&(cmd->chanlist_len>3)) { - printk("comedi%d: the gain must be the same for all channels.\n", - dev->minor); + if ((gain != CR_RANGE(cmd->chanlist[i])) + && (cmd->chanlist_len > 3)) { + printk("comedi%d: the gain must be the same for all channels.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } - if (i>=NUMCHANNELS) { - printk("comedi%d: channel list too long\n",dev->minor); + if (i >= NUMCHANNELS) { + printk("comedi%d: channel list too long\n", + dev->minor); break; } } } - steps=0; - if(cmd->scan_begin_src == TRIG_TIMER) { - printk("comedi%d: usbduxfast: scan_begin_src==TRIG_TIMER not valid.\n", - dev->minor); + steps = 0; + if (cmd->scan_begin_src == TRIG_TIMER) { + printk("comedi%d: usbduxfast: scan_begin_src==TRIG_TIMER not valid.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } - if(cmd->convert_src == TRIG_TIMER) { - steps=(cmd->convert_arg*30)/1000; + if (cmd->convert_src == TRIG_TIMER) { + steps = (cmd->convert_arg * 30) / 1000; } - if ((stepschanlist_len!=1)) { - printk("comedi%d: usbduxfast: ai_cmd: steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", - dev->minor, - steps, - cmd->scan_begin_arg); + if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) { + printk("comedi%d: usbduxfast: ai_cmd: steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, steps, cmd->scan_begin_arg); up(&this_usbduxfastsub->sem); return -EINVAL; } - if (steps>MAX_SAMPLING_PERIOD) { + if (steps > MAX_SAMPLING_PERIOD) { printk("comedi%d: usbduxfast: ai_cmd: sampling rate too low.\n", - dev->minor); + dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } - if ((cmd->start_src == TRIG_EXT)&&(cmd->chanlist_len!=1)&&(cmd->chanlist_len!=16)) { - printk("comedi%d: usbduxfast: ai_cmd: TRIG_EXT only with 1 or 16 channels possible.\n", - dev->minor); + if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1) + && (cmd->chanlist_len != 16)) { + printk("comedi%d: usbduxfast: ai_cmd: TRIG_EXT only with 1 or 16 channels possible.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EINVAL; } #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbduxfast: steps=%ld, convert_arg=%u, ai_timer=%u\n", - dev->minor, - steps, - cmd->convert_arg, - this_usbduxfastsub->ai_timer); + dev->minor, + steps, cmd->convert_arg, this_usbduxfastsub->ai_timer); #endif - switch (cmd->chanlist_len) { // one channel case 1: - if (CR_RANGE(cmd->chanlist[0])>0) rngmask=0xff-0x04; else rngmask=0xff; + if (CR_RANGE(cmd->chanlist[0]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // for external trigger: looping in this state until the RDY0 pin // becomes zero - if(cmd->start_src == TRIG_EXT) { // we loop here until ready has been set - this_usbduxfastsub->dux_commands[LENBASE+0]=0x01; // branch back to state 0 - this_usbduxfastsub->dux_commands[OPBASE+0]=0x01; // deceision state w/o data - this_usbduxfastsub->dux_commands[OUTBASE+0]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+0]=0x00; // RDY0 = 0 - } else { // we just proceed to state 1 - this_usbduxfastsub->dux_commands[LENBASE+0]=1; - this_usbduxfastsub->dux_commands[OPBASE+0]=0; - this_usbduxfastsub->dux_commands[OUTBASE+0]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+0]=0; + if (cmd->start_src == TRIG_EXT) { // we loop here until ready has been set + this_usbduxfastsub->dux_commands[LENBASE + 0] = 0x01; // branch back to state 0 + this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x01; // deceision state w/o data + this_usbduxfastsub->dux_commands[OUTBASE + 0] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0x00; // RDY0 = 0 + } else { // we just proceed to state 1 + this_usbduxfastsub->dux_commands[LENBASE + 0] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 0] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 0] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0; } - if (stepsdux_commands[LENBASE+1]=0x89; // branch back to state 1 - this_usbduxfastsub->dux_commands[OPBASE+1]=0x03; // deceision state with data - this_usbduxfastsub->dux_commands[OUTBASE+1]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+1]=0xFF; // doesn't matter + this_usbduxfastsub->dux_commands[LENBASE + 1] = 0x89; // branch back to state 1 + this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x03; // deceision state with data + this_usbduxfastsub->dux_commands[OUTBASE + 1] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0xFF; // doesn't matter } else { // we loop through two states: data and delay: max rate is 15Mhz - this_usbduxfastsub->dux_commands[LENBASE+1]=steps-1; - this_usbduxfastsub->dux_commands[OPBASE+1]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+1]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+1]=0; // doesn't matter - - this_usbduxfastsub->dux_commands[LENBASE+2]=0x09; // branch back to state 1 - this_usbduxfastsub->dux_commands[OPBASE+2]=0x01; // deceision state w/o data - this_usbduxfastsub->dux_commands[OUTBASE+2]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+2]=0xFF; // doesn't matter + this_usbduxfastsub->dux_commands[LENBASE + 1] = + steps - 1; + this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + 1] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; // doesn't matter + + this_usbduxfastsub->dux_commands[LENBASE + 2] = 0x09; // branch back to state 1 + this_usbduxfastsub->dux_commands[OPBASE + 2] = 0x01; // deceision state w/o data + this_usbduxfastsub->dux_commands[OUTBASE + 2] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0xFF; // doesn't matter } } else { // we loop through 3 states: 2x delay and 1x data. This gives a min // sampling rate of 60kHz. // we have 1 state with duration 1 - steps=steps-1; + steps = steps - 1; // do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+1]=steps/2; - this_usbduxfastsub->dux_commands[OPBASE+1]=0; - this_usbduxfastsub->dux_commands[OUTBASE+1]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+1]=0; + this_usbduxfastsub->dux_commands[LENBASE + 1] = + steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + 1] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 1] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; // and the second part - this_usbduxfastsub->dux_commands[LENBASE+2]=steps-steps/2; - this_usbduxfastsub->dux_commands[OPBASE+2]=0; - this_usbduxfastsub->dux_commands[OUTBASE+2]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+2]=0; + this_usbduxfastsub->dux_commands[LENBASE + 2] = + steps - steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + 2] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 2] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; // get the data and branch back - this_usbduxfastsub->dux_commands[LENBASE+3]=0x09; // branch back to state 1 - this_usbduxfastsub->dux_commands[OPBASE+3]=0x03; // deceision state w data - this_usbduxfastsub->dux_commands[OUTBASE+3]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+3]=0xFF; // doesn't matter + this_usbduxfastsub->dux_commands[LENBASE + 3] = 0x09; // branch back to state 1 + this_usbduxfastsub->dux_commands[OPBASE + 3] = 0x03; // deceision state w data + this_usbduxfastsub->dux_commands[OUTBASE + 3] = + 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0xFF; // doesn't matter } break; case 2: // two channels // commit data to the FIFO - if (CR_RANGE(cmd->chanlist[0])>0) rngmask=0xff-0x04; else rngmask=0xff; - this_usbduxfastsub->dux_commands[LENBASE+0]=1; - this_usbduxfastsub->dux_commands[OPBASE+0]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+0]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+0]=0; + if (CR_RANGE(cmd->chanlist[0]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; + this_usbduxfastsub->dux_commands[LENBASE + 0] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + 0] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0; // we have 1 state with duration 1: state 0 - steps_tmp=steps-1; + steps_tmp = steps - 1; - if (CR_RANGE(cmd->chanlist[1])>0) rngmask=0xff-0x04; else rngmask=0xff; + if (CR_RANGE(cmd->chanlist[1]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+1]=steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+1]=0; - this_usbduxfastsub->dux_commands[OUTBASE+1]=0xFE & rngmask; //count - this_usbduxfastsub->dux_commands[LOGBASE+1]=0; + this_usbduxfastsub->dux_commands[LENBASE + 1] = steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 1] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFE & rngmask; //count + this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; // and the second part - this_usbduxfastsub->dux_commands[LENBASE+2]=steps_tmp-steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+2]=0; - this_usbduxfastsub->dux_commands[OUTBASE+2]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+2]=0; + this_usbduxfastsub->dux_commands[LENBASE + 2] = + steps_tmp - steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 2] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; - this_usbduxfastsub->dux_commands[LENBASE+3]=1; - this_usbduxfastsub->dux_commands[OPBASE+3]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+3]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+3]=0; + this_usbduxfastsub->dux_commands[LENBASE + 3] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 3] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0; // we have 2 states with duration 1: step 6 and the IDLE state - steps_tmp=steps-2; + steps_tmp = steps - 2; - if (CR_RANGE(cmd->chanlist[0])>0) rngmask=0xff-0x04; else rngmask=0xff; + if (CR_RANGE(cmd->chanlist[0]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+4]=steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+4]=0; - this_usbduxfastsub->dux_commands[OUTBASE+4]=(0xFF-0x02) & rngmask; //reset - this_usbduxfastsub->dux_commands[LOGBASE+4]=0; + this_usbduxfastsub->dux_commands[LENBASE + 4] = steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 4] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 4] = (0xFF - 0x02) & rngmask; //reset + this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0; // and the second part - this_usbduxfastsub->dux_commands[LENBASE+5]=steps_tmp-steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+5]=0; - this_usbduxfastsub->dux_commands[OUTBASE+5]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+5]=0; - - this_usbduxfastsub->dux_commands[LENBASE+6]=1; - this_usbduxfastsub->dux_commands[OPBASE+6]=0; - this_usbduxfastsub->dux_commands[OUTBASE+6]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+6]=0; + this_usbduxfastsub->dux_commands[LENBASE + 5] = + steps_tmp - steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 5] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 5] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 5] = 0; + + this_usbduxfastsub->dux_commands[LENBASE + 6] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 6] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 6] = 0; break; case 3: // three channels - for(j=0;j<1;j++) { - if (CR_RANGE(cmd->chanlist[j])>0) rngmask=0xff-0x04; else rngmask=0xff; + for (j = 0; j < 1; j++) { + if (CR_RANGE(cmd->chanlist[j]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // commit data to the FIFO and do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+j*2]=steps/2; - this_usbduxfastsub->dux_commands[OPBASE+j*2]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+j*2]=0xFF & rngmask; // no change - this_usbduxfastsub->dux_commands[LOGBASE+j*2]=0; - - if (CR_RANGE(cmd->chanlist[j+1])>0) rngmask=0xff-0x04; else rngmask=0xff; + this_usbduxfastsub->dux_commands[LENBASE + j * 2] = + steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + j * 2] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + j * 2] = 0xFF & rngmask; // no change + this_usbduxfastsub->dux_commands[LOGBASE + j * 2] = 0; + + if (CR_RANGE(cmd->chanlist[j + 1]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // do the second part of the delay - this_usbduxfastsub->dux_commands[LENBASE+j*2+1]=steps-steps/2; - this_usbduxfastsub->dux_commands[OPBASE+j*2+1]=0; // no data - this_usbduxfastsub->dux_commands[OUTBASE+j*2+1]=0xFE & rngmask; //count - this_usbduxfastsub->dux_commands[LOGBASE+j*2+1]=0; + this_usbduxfastsub->dux_commands[LENBASE + j * 2 + 1] = + steps - steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + j * 2 + 1] = 0; // no data + this_usbduxfastsub->dux_commands[OUTBASE + j * 2 + 1] = 0xFE & rngmask; //count + this_usbduxfastsub->dux_commands[LOGBASE + j * 2 + 1] = + 0; } // 2 steps with duration 1: the idele step and step 6: - steps_tmp=steps-2; + steps_tmp = steps - 2; // commit data to the FIFO and do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+4]=steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+4]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+4]=0xFF & rngmask; // no change - this_usbduxfastsub->dux_commands[LOGBASE+4]=0; - - if (CR_RANGE(cmd->chanlist[0])>0) rngmask=0xff-0x04; else rngmask=0xff; + this_usbduxfastsub->dux_commands[LENBASE + 4] = steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 4] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFF & rngmask; // no change + this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0; + + if (CR_RANGE(cmd->chanlist[0]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // do the second part of the delay - this_usbduxfastsub->dux_commands[LENBASE+5]=steps_tmp-steps_tmp/2; - this_usbduxfastsub->dux_commands[OPBASE+5]=0; // no data - this_usbduxfastsub->dux_commands[OUTBASE+5]=(0xFF-0x02) & rngmask; // reset - this_usbduxfastsub->dux_commands[LOGBASE+5]=0; + this_usbduxfastsub->dux_commands[LENBASE + 5] = + steps_tmp - steps_tmp / 2; + this_usbduxfastsub->dux_commands[OPBASE + 5] = 0; // no data + this_usbduxfastsub->dux_commands[OUTBASE + 5] = (0xFF - 0x02) & rngmask; // reset + this_usbduxfastsub->dux_commands[LOGBASE + 5] = 0; - this_usbduxfastsub->dux_commands[LENBASE+6]=1; - this_usbduxfastsub->dux_commands[OPBASE+6]=0; - this_usbduxfastsub->dux_commands[OUTBASE+6]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+6]=0; + this_usbduxfastsub->dux_commands[LENBASE + 6] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 6] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 6] = 0; case 16: - if (CR_RANGE(cmd->chanlist[0])>0) rngmask=0xff-0x04; else rngmask=0xff; - if(cmd->start_src == TRIG_EXT) { // we loop here until ready has been set - this_usbduxfastsub->dux_commands[LENBASE+0]=0x01; // branch back to state 0 - this_usbduxfastsub->dux_commands[OPBASE+0]=0x01; // deceision state w/o data - this_usbduxfastsub->dux_commands[OUTBASE+0]=(0xFF-0x02) & rngmask; // reset - this_usbduxfastsub->dux_commands[LOGBASE+0]=0x00; // RDY0 = 0 - } else { // we just proceed to state 1 - this_usbduxfastsub->dux_commands[LENBASE+0]=255; // 30us reset pulse - this_usbduxfastsub->dux_commands[OPBASE+0]=0; - this_usbduxfastsub->dux_commands[OUTBASE+0]=(0xFF-0x02) & rngmask; // reset - this_usbduxfastsub->dux_commands[LOGBASE+0]=0; + if (CR_RANGE(cmd->chanlist[0]) > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; + if (cmd->start_src == TRIG_EXT) { // we loop here until ready has been set + this_usbduxfastsub->dux_commands[LENBASE + 0] = 0x01; // branch back to state 0 + this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x01; // deceision state w/o data + this_usbduxfastsub->dux_commands[OUTBASE + 0] = (0xFF - 0x02) & rngmask; // reset + this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0x00; // RDY0 = 0 + } else { // we just proceed to state 1 + this_usbduxfastsub->dux_commands[LENBASE + 0] = 255; // 30us reset pulse + this_usbduxfastsub->dux_commands[OPBASE + 0] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 0] = (0xFF - 0x02) & rngmask; // reset + this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0; } // commit data to the FIFO - this_usbduxfastsub->dux_commands[LENBASE+1]=1; - this_usbduxfastsub->dux_commands[OPBASE+1]=0x02; // data - this_usbduxfastsub->dux_commands[OUTBASE+1]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+1]=0; + this_usbduxfastsub->dux_commands[LENBASE + 1] = 1; + this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x02; // data + this_usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; // we have 2 states with duration 1 - steps=steps-2; + steps = steps - 2; // do the first part of the delay - this_usbduxfastsub->dux_commands[LENBASE+2]=steps/2; - this_usbduxfastsub->dux_commands[OPBASE+2]=0; - this_usbduxfastsub->dux_commands[OUTBASE+2]=0xFE & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+2]=0; + this_usbduxfastsub->dux_commands[LENBASE + 2] = steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + 2] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFE & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; // and the second part - this_usbduxfastsub->dux_commands[LENBASE+3]=steps-steps/2; - this_usbduxfastsub->dux_commands[OPBASE+3]=0; - this_usbduxfastsub->dux_commands[OUTBASE+3]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+3]=0; + this_usbduxfastsub->dux_commands[LENBASE + 3] = + steps - steps / 2; + this_usbduxfastsub->dux_commands[OPBASE + 3] = 0; + this_usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0; - this_usbduxfastsub->dux_commands[LENBASE+4]=0x09; // branch back to state 1 - this_usbduxfastsub->dux_commands[OPBASE+4]=0x01; // deceision state w/o data - this_usbduxfastsub->dux_commands[OUTBASE+4]=0xFF & rngmask; - this_usbduxfastsub->dux_commands[LOGBASE+4]=0xFF; // doesn't matter + this_usbduxfastsub->dux_commands[LENBASE + 4] = 0x09; // branch back to state 1 + this_usbduxfastsub->dux_commands[OPBASE + 4] = 0x01; // deceision state w/o data + this_usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFF & rngmask; + this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0xFF; // doesn't matter break; default: printk("comedi %d: unsupported combination of channels\n", - dev->minor); + dev->minor); up(&this_usbduxfastsub->sem); return -EFAULT; } - #ifdef CONFIG_COMEDI_DEBUG - printk("comedi %d: sending commands to the usb device\n", - dev->minor); + printk("comedi %d: sending commands to the usb device\n", dev->minor); #endif // 0 means that the AD commands are sent - result=send_dux_commands(this_usbduxfastsub,SENDADCOMMANDS); - if (result<0) { - printk("comedi%d: adc command could not be submitted. Aborting...\n", - dev->minor); + result = send_dux_commands(this_usbduxfastsub, SENDADCOMMANDS); + if (result < 0) { + printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor); up(&this_usbduxfastsub->sem); return result; } - if(cmd->stop_src==TRIG_COUNT){ - this_usbduxfastsub->ai_sample_count = (cmd->stop_arg)*(cmd->scan_end_arg); - if (usbduxfastsub->ai_sample_count<1) { - printk("comedi%d: (cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting.\n", - dev->minor); + if (cmd->stop_src == TRIG_COUNT) { + this_usbduxfastsub->ai_sample_count = + (cmd->stop_arg) * (cmd->scan_end_arg); + if (usbduxfastsub->ai_sample_count < 1) { + printk("comedi%d: (cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting.\n", dev->minor); up(&this_usbduxfastsub->sem); return -EFAULT; } - this_usbduxfastsub->ai_continous=0; + this_usbduxfastsub->ai_continous = 0; } else { // continous aquisition - this_usbduxfastsub->ai_continous=1; - this_usbduxfastsub->ai_sample_count=0; + this_usbduxfastsub->ai_continous = 1; + this_usbduxfastsub->ai_sample_count = 0; } - if((cmd->start_src == TRIG_NOW)||(cmd->start_src == TRIG_EXT)) { + if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { // enable this acquisition operation - this_usbduxfastsub->ai_cmd_running=1; - ret=usbduxfastsub_submit_InURBs(this_usbduxfastsub); - if (ret<0) { - this_usbduxfastsub->ai_cmd_running=0; + this_usbduxfastsub->ai_cmd_running = 1; + ret = usbduxfastsub_submit_InURBs(this_usbduxfastsub); + if (ret < 0) { + this_usbduxfastsub->ai_cmd_running = 0; // fixme: unlink here?? up(&this_usbduxfastsub->sem); return ret; } - s->async->inttrig = NULL; - }else{ - /* TRIG_INT */ + s->async->inttrig = NULL; + } else { + /* TRIG_INT */ // don't enable the acquision operation // wait for an internal signal - s->async->inttrig = usbduxfast_ai_inttrig; - } + s->async->inttrig = usbduxfast_ai_inttrig; + } up(&this_usbduxfastsub->sem); return 0; } - - /* Mode 0 is used to get a single conversion on demand */ static int usbduxfast_ai_insn_read(comedi_device * dev, - comedi_subdevice *s, - comedi_insn *insn, - lsampl_t *data) + comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) { - int i,j,n,actual_length; - int chan,range,rngmask; - int err; - usbduxfastsub_t* usbduxfastsub=dev->private; - - if (!usbduxfastsub) { - printk("comedi%d: ai_insn_read: no usb dev.\n", - dev->minor); - return -ENODEV; - } + int i, j, n, actual_length; + int chan, range, rngmask; + int err; + usbduxfastsub_t *usbduxfastsub = dev->private; + if (!usbduxfastsub) { + printk("comedi%d: ai_insn_read: no usb dev.\n", dev->minor); + return -ENODEV; + } #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n", - dev->minor, - insn->n, - insn->subdev); + printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n", + dev->minor, insn->n, insn->subdev); #endif - down(&usbduxfastsub->sem); - if (!(usbduxfastsub->probed)) { - up(&usbduxfastsub->sem); - return -ENODEV; - } - if (usbduxfastsub->ai_cmd_running) { - printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", - dev->minor); - up(&usbduxfastsub->sem); - return -EBUSY; - } - - // sample one channel - chan = CR_CHAN(insn->chanspec); - range = CR_RANGE(insn->chanspec); - // set command for the first channel - - if (range>0) rngmask=0xff-0x04; else rngmask=0xff; + down(&usbduxfastsub->sem); + if (!(usbduxfastsub->probed)) { + up(&usbduxfastsub->sem); + return -ENODEV; + } + if (usbduxfastsub->ai_cmd_running) { + printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor); + up(&usbduxfastsub->sem); + return -EBUSY; + } + // sample one channel + chan = CR_CHAN(insn->chanspec); + range = CR_RANGE(insn->chanspec); + // set command for the first channel + + if (range > 0) + rngmask = 0xff - 0x04; + else + rngmask = 0xff; // commit data to the FIFO - usbduxfastsub->dux_commands[LENBASE+0]=1; - usbduxfastsub->dux_commands[OPBASE+0]=0x02; // data - usbduxfastsub->dux_commands[OUTBASE+0]=0xFF & rngmask; - usbduxfastsub->dux_commands[LOGBASE+0]=0; + usbduxfastsub->dux_commands[LENBASE + 0] = 1; + usbduxfastsub->dux_commands[OPBASE + 0] = 0x02; // data + usbduxfastsub->dux_commands[OUTBASE + 0] = 0xFF & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 0] = 0; // do the first part of the delay - usbduxfastsub->dux_commands[LENBASE+1]=12; - usbduxfastsub->dux_commands[OPBASE+1]=0; - usbduxfastsub->dux_commands[OUTBASE+1]=0xFE & rngmask; - usbduxfastsub->dux_commands[LOGBASE+1]=0; - - usbduxfastsub->dux_commands[LENBASE+2]=1; - usbduxfastsub->dux_commands[OPBASE+2]=0; - usbduxfastsub->dux_commands[OUTBASE+2]=0xFE & rngmask; - usbduxfastsub->dux_commands[LOGBASE+2]=0; - - usbduxfastsub->dux_commands[LENBASE+3]=1; - usbduxfastsub->dux_commands[OPBASE+3]=0; - usbduxfastsub->dux_commands[OUTBASE+3]=0xFE & rngmask; - usbduxfastsub->dux_commands[LOGBASE+3]=0; - - usbduxfastsub->dux_commands[LENBASE+4]=1; - usbduxfastsub->dux_commands[OPBASE+4]=0; - usbduxfastsub->dux_commands[OUTBASE+4]=0xFE & rngmask; - usbduxfastsub->dux_commands[LOGBASE+4]=0; + usbduxfastsub->dux_commands[LENBASE + 1] = 12; + usbduxfastsub->dux_commands[OPBASE + 1] = 0; + usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFE & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 1] = 0; + + usbduxfastsub->dux_commands[LENBASE + 2] = 1; + usbduxfastsub->dux_commands[OPBASE + 2] = 0; + usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFE & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 2] = 0; + + usbduxfastsub->dux_commands[LENBASE + 3] = 1; + usbduxfastsub->dux_commands[OPBASE + 3] = 0; + usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFE & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 3] = 0; + + usbduxfastsub->dux_commands[LENBASE + 4] = 1; + usbduxfastsub->dux_commands[OPBASE + 4] = 0; + usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFE & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 4] = 0; // second part - usbduxfastsub->dux_commands[LENBASE+5]=12; - usbduxfastsub->dux_commands[OPBASE+5]=0; - usbduxfastsub->dux_commands[OUTBASE+5]=0xFF & rngmask; - usbduxfastsub->dux_commands[LOGBASE+5]=0; + usbduxfastsub->dux_commands[LENBASE + 5] = 12; + usbduxfastsub->dux_commands[OPBASE + 5] = 0; + usbduxfastsub->dux_commands[OUTBASE + 5] = 0xFF & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 5] = 0; - usbduxfastsub->dux_commands[LENBASE+6]=1; - usbduxfastsub->dux_commands[OPBASE+6]=0; - usbduxfastsub->dux_commands[OUTBASE+6]=0xFF & rngmask; - usbduxfastsub->dux_commands[LOGBASE+0]=0; + usbduxfastsub->dux_commands[LENBASE + 6] = 1; + usbduxfastsub->dux_commands[OPBASE + 6] = 0; + usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; + usbduxfastsub->dux_commands[LOGBASE + 0] = 0; #ifdef CONFIG_COMEDI_DEBUG - printk("comedi %d: sending commands to the usb device\n", - dev->minor); + printk("comedi %d: sending commands to the usb device\n", dev->minor); #endif // 0 means that the AD commands are sent - err=send_dux_commands(usbduxfastsub,SENDADCOMMANDS); - if (err<0) { - printk("comedi%d: adc command could not be submitted. Aborting...\n", - dev->minor); + err = send_dux_commands(usbduxfastsub, SENDADCOMMANDS); + if (err < 0) { + printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor); up(&usbduxfastsub->sem); return err; } - #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbduxfast: submitting in-urb: %x,%x\n", - usbduxfastsub->comedidev->minor, - (int)(usbduxfastsub->urbIn->context), - (int)(usbduxfastsub->urbIn->dev)); + usbduxfastsub->comedidev->minor, + (int)(usbduxfastsub->urbIn->context), + (int)(usbduxfastsub->urbIn->dev)); #endif - for(i=0;iusbdev, - usb_rcvbulkpipe(usbduxfastsub->usbdev,BULKINEP), - usbduxfastsub->transfer_buffer, - SIZEINBUF, - &actual_length, - 10000); - if (err<0) { + for (i = 0; i < PACKETS_TO_IGNORE; i++) { + err = USB_BULK_MSG(usbduxfastsub->usbdev, + usb_rcvbulkpipe(usbduxfastsub->usbdev, BULKINEP), + usbduxfastsub->transfer_buffer, + SIZEINBUF, &actual_length, 10000); + if (err < 0) { printk("comedi%d: insn timeout. No data.\n", - dev->minor); + dev->minor); up(&usbduxfastsub->sem); return err; } } // data points - for(i=0;in;) { - err=USB_BULK_MSG(usbduxfastsub->usbdev, - usb_rcvbulkpipe(usbduxfastsub->usbdev,BULKINEP), - usbduxfastsub->transfer_buffer, - SIZEINBUF, - &actual_length, - 10000); - if (err<0) { + for (i = 0; i < insn->n;) { + err = USB_BULK_MSG(usbduxfastsub->usbdev, + usb_rcvbulkpipe(usbduxfastsub->usbdev, BULKINEP), + usbduxfastsub->transfer_buffer, + SIZEINBUF, &actual_length, 10000); + if (err < 0) { printk("comedi%d: insn data error: %d\n", - dev->minor,err); + dev->minor, err); up(&usbduxfastsub->sem); return err; } - n=actual_length/sizeof(uint16_t); - if ((n%16)!=0) { + n = actual_length / sizeof(uint16_t); + if ((n % 16) != 0) { printk("comedi%d: insn data packet corrupted.\n", - dev->minor); + dev->minor); up(&usbduxfastsub->sem); return -EINVAL; } - for(j=chan;(jn);j=j+16) { - data[i]=((uint16_t*)(usbduxfastsub->transfer_buffer))[j]; + for (j = chan; (j < n) && (i < insn->n); j = j + 16) { + data[i] = + ((uint16_t *) (usbduxfastsub-> + transfer_buffer))[j]; i++; } } @@ -1341,66 +1274,65 @@ static int usbduxfast_ai_insn_read(comedi_device * dev, return i; } - - - -static unsigned hex2unsigned(char *h) { - unsigned hi,lo; - if (h[0]>'9') { - hi=h[0]-'A'+0x0a; +static unsigned hex2unsigned(char *h) +{ + unsigned hi, lo; + if (h[0] > '9') { + hi = h[0] - 'A' + 0x0a; } else { - hi=h[0]-'0'; + hi = h[0] - '0'; } - if (h[1]>'9') { - lo=h[1]-'A'+0x0a; + if (h[1] > '9') { + lo = h[1] - 'A' + 0x0a; } else { - lo=h[1]-'0'; + lo = h[1] - '0'; } - return hi*0x10+lo; + return hi * 0x10 + lo; } - // for FX2 #define FIRMWARE_MAX_LEN 0x2000 // taken from David Brownell's fxload and adjusted for this driver -static int read_firmware(usbduxfastsub_t* usbduxfastsub, void *firmwarePtr,long size) { - int i=0; - unsigned char* fp=(char*)firmwarePtr; - unsigned char* firmwareBinary=NULL; - int res=0; - int maxAddr=0; - - firmwareBinary = kmalloc(FIRMWARE_MAX_LEN,GFP_KERNEL); - if(!firmwareBinary){ - printk("comedi_: usbduxfast: mem alloc for firmware failed\n" - ); +static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr, + long size) +{ + int i = 0; + unsigned char *fp = (char *)firmwarePtr; + unsigned char *firmwareBinary = NULL; + int res = 0; + int maxAddr = 0; + + firmwareBinary = kmalloc(FIRMWARE_MAX_LEN, GFP_KERNEL); + if (!firmwareBinary) { + printk("comedi_: usbduxfast: mem alloc for firmware failed\n"); return -ENOMEM; } for (;;) { - char buf[256],*cp; - char type; - int len; - int idx, off; - int j=0; + char buf[256], *cp; + char type; + int len; + int idx, off; + int j = 0; // get one line - while ((i=sizeof(buf)) { + if (j >= sizeof(buf)) { printk("comedi_: usbduxfast: bogus firmware file!\n"); return -1; } } // get rid of LF/CR/... - while ((imaxAddr) { - maxAddr=off+len; + if ((off + len) > maxAddr) { + maxAddr = off + len; } - if (maxAddr>=FIRMWARE_MAX_LEN) { + if (maxAddr >= FIRMWARE_MAX_LEN) { printk("comedi_: usbduxfast: firmware upload goes beyond FX2 RAM boundaries."); return -EFAULT; } - //printk("comedi_: usbduxfast: off=%x, len=%x:",off,len); /* Read the record type */ - type = hex2unsigned(buf+7); + type = hex2unsigned(buf + 7); /* If this is an EOF record, then make it so. */ if (type == 1) { @@ -1438,45 +1369,43 @@ static int read_firmware(usbduxfastsub_t* usbduxfastsub, void *firmwarePtr,long } if (type != 0) { - printk("comedi_: usbduxfast: unsupported record type: %u\n",type); + printk("comedi_: usbduxfast: unsupported record type: %u\n", type); return -EFAULT; } - for (idx = 0, cp = buf+9 ; idx < len ; idx += 1, cp += 2) { - firmwareBinary[idx+off] = hex2unsigned(cp); + for (idx = 0, cp = buf + 9; idx < len; idx += 1, cp += 2) { + firmwareBinary[idx + off] = hex2unsigned(cp); //printk("%02x ",firmwareBinary[idx+off]); } //printk("\n"); - if (i>=size) { + if (i >= size) { printk("comedi_: usbduxfast: unexpected end of hex file\n"); break; } } - res=firmwareUpload(usbduxfastsub,firmwareBinary,maxAddr+1); + res = firmwareUpload(usbduxfastsub, firmwareBinary, maxAddr + 1); kfree(firmwareBinary); return res; } - - -static void tidy_up(usbduxfastsub_t* usbduxfastsub_tmp) { +static void tidy_up(usbduxfastsub_t * usbduxfastsub_tmp) +{ #ifdef CONFIG_COMEDI_DEBUG printk("comedi_: usbduxfast: tiding up\n"); #endif if (!usbduxfastsub_tmp) { return; } - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) // shows the usb subsystem that the driver is down if (usbduxfastsub_tmp->interface) { - usb_set_intfdata(usbduxfastsub_tmp->interface,NULL); + usb_set_intfdata(usbduxfastsub_tmp->interface, NULL); } #endif - usbduxfastsub_tmp->probed=0; + usbduxfastsub_tmp->probed = 0; if (usbduxfastsub_tmp->urbIn) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8) @@ -1487,79 +1416,64 @@ static void tidy_up(usbduxfastsub_t* usbduxfastsub_tmp) { #endif if (usbduxfastsub_tmp->transfer_buffer) { kfree(usbduxfastsub_tmp->transfer_buffer); - usbduxfastsub_tmp->transfer_buffer=NULL; + usbduxfastsub_tmp->transfer_buffer = NULL; } usb_free_urb(usbduxfastsub_tmp->urbIn); - usbduxfastsub_tmp->urbIn=NULL; + usbduxfastsub_tmp->urbIn = NULL; } if (usbduxfastsub_tmp->insnBuffer) { kfree(usbduxfastsub_tmp->insnBuffer); - usbduxfastsub_tmp->insnBuffer=NULL; + usbduxfastsub_tmp->insnBuffer = NULL; } if (usbduxfastsub_tmp->dux_commands) { kfree(usbduxfastsub_tmp->dux_commands); - usbduxfastsub_tmp->dux_commands=NULL; + usbduxfastsub_tmp->dux_commands = NULL; } - usbduxfastsub_tmp->ai_cmd_running=0; + usbduxfastsub_tmp->ai_cmd_running = 0; } - - - - - - - - - - - - // allocate memory for the urbs and initialise them #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -static void* usbduxfastsub_probe(struct usb_device *udev, - unsigned int interfnum, - const struct usb_device_id *id) { +static void *usbduxfastsub_probe(struct usb_device *udev, + unsigned int interfnum, const struct usb_device_id *id) +{ #else static int usbduxfastsub_probe(struct usb_interface *uinterf, - const struct usb_device_id *id) { - struct usb_device *udev = interface_to_usbdev(uinterf); + const struct usb_device_id *id) +{ + struct usb_device *udev = interface_to_usbdev(uinterf); #endif - int i; + int i; int index; - - if (udev->speed!=USB_SPEED_HIGH) { + if (udev->speed != USB_SPEED_HIGH) { printk("comedi_: usbduxfast_: This driver needs USB 2.0 to operate. Aborting...\n"); return PROBE_ERR_RETURN(-ENODEV); } - - #ifdef CONFIG_COMEDI_DEBUG printk("comedi_: usbduxfast_: finding a free structure for the usb-device\n"); #endif down(&start_stop_sem); // look for a free place in the usbduxfast array - index=-1; - for(i=0; ialtsetting->desc.bInterfaceNumber; // hand the private data over to the usb subsystem // will be needed for disconnect - usb_set_intfdata(uinterf,&(usbduxfastsub[index])); + usb_set_intfdata(uinterf, &(usbduxfastsub[index])); #endif #ifdef CONFIG_COMEDI_DEBUG - printk("comedi_: usbduxfast: ifnum=%d\n",usbduxfastsub[index].ifnum); + printk("comedi_: usbduxfast: ifnum=%d\n", usbduxfastsub[index].ifnum); #endif // create space for the commands going to the usb device - usbduxfastsub[index].dux_commands=kmalloc(SIZEOFDUXBUFFER, - GFP_KERNEL); + usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, + GFP_KERNEL); if (!usbduxfastsub[index].dux_commands) { printk("comedi_: usbduxfast: error alloc space for dac commands\n"); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - // create space of the instruction buffer - usbduxfastsub[index].insnBuffer=kmalloc(SIZEINSNBUF,GFP_KERNEL); + usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); if (!(usbduxfastsub[index].insnBuffer)) { printk("comedi_: usbduxfast: could not alloc space for insnBuffer\n"); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } // setting to alternate setting 1: enabling bulk ep - i=usb_set_interface(usbduxfastsub[index].usbdev, - usbduxfastsub[index].ifnum, - 1); - if (i<0) { - printk("comedi_: usbduxfast%d: could not switch to alternate setting 1.\n",index); + i = usb_set_interface(usbduxfastsub[index].usbdev, + usbduxfastsub[index].ifnum, 1); + if (i < 0) { + printk("comedi_: usbduxfast%d: could not switch to alternate setting 1.\n", index); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENODEV); + return PROBE_ERR_RETURN(-ENODEV); } - usbduxfastsub[index].urbIn=USB_ALLOC_URB(0); - if (usbduxfastsub[index].urbIn==NULL) { - printk("comedi_: usbduxfast%d: Could not alloc. urb\n",index); + usbduxfastsub[index].urbIn = USB_ALLOC_URB(0); + if (usbduxfastsub[index].urbIn == NULL) { + printk("comedi_: usbduxfast%d: Could not alloc. urb\n", index); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } - usbduxfastsub[index].transfer_buffer= - kmalloc(SIZEINBUF,GFP_KERNEL); + usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); if (!(usbduxfastsub[index].transfer_buffer)) { - printk("comedi_: usbduxfast%d: could not alloc. transb.\n",index); + printk("comedi_: usbduxfast%d: could not alloc. transb.\n", + index); tidy_up(&(usbduxfastsub[index])); up(&start_stop_sem); - return PROBE_ERR_RETURN( -ENOMEM); + return PROBE_ERR_RETURN(-ENOMEM); } // we've reached the bottom of the function - usbduxfastsub[index].probed=1; + usbduxfastsub[index].probed = 1; up(&start_stop_sem); - printk("comedi_: usbduxfast%d has been successfully initialized.\n",index); + printk("comedi_: usbduxfast%d has been successfully initialized.\n", + index); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) - return (void*)(&usbduxfastsub[index]); + return (void *)(&usbduxfastsub[index]); #else // success return 0; #endif } - - - - - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) -static void usbduxfastsub_disconnect(struct usb_device *udev, void *ptr) { - usbduxfastsub_t* usbduxfastsub_tmp=(usbduxfastsub_t*)ptr; +static void usbduxfastsub_disconnect(struct usb_device *udev, void *ptr) +{ + usbduxfastsub_t *usbduxfastsub_tmp = (usbduxfastsub_t *) ptr; #else -static void usbduxfastsub_disconnect(struct usb_interface *intf) { - usbduxfastsub_t* usbduxfastsub_tmp= usb_get_intfdata(intf); - struct usb_device *udev = interface_to_usbdev(intf); +static void usbduxfastsub_disconnect(struct usb_interface *intf) +{ + usbduxfastsub_t *usbduxfastsub_tmp = usb_get_intfdata(intf); + struct usb_device *udev = interface_to_usbdev(intf); #endif if (!usbduxfastsub_tmp) { printk("comedi_: usbduxfast: disconnect called with null pointer.\n"); return; } - if (usbduxfastsub_tmp->usbdev!=udev) { + if (usbduxfastsub_tmp->usbdev != udev) { printk("comedi_: usbduxfast: BUG! called with wrong ptr!!!\n"); return; } @@ -1665,66 +1575,60 @@ static void usbduxfastsub_disconnect(struct usb_interface *intf) { #endif } - - - - // is called when comedi-config is called static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it) { int ret; int index; int i; - comedi_subdevice *s=NULL; - dev->private=NULL; + comedi_subdevice *s = NULL; + dev->private = NULL; down(&start_stop_sem); // find a valid device which has been detected by the probe function of the usb - index=-1; - for(i=0;iminor); + if (index < 0) { + printk("comedi%d: usbduxfast: error: attach failed, no usbduxfast devs connected to the usb bus.\n", dev->minor); up(&start_stop_sem); return -ENODEV; } down(&(usbduxfastsub[index].sem)); // pointer back to the corresponding comedi device - usbduxfastsub[index].comedidev=dev; + usbduxfastsub[index].comedidev = dev; // trying to upload the firmware into the chip - if(comedi_aux_data(it->options, 0) && - it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]){ + if (comedi_aux_data(it->options, 0) && + it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { read_firmware(usbduxfastsub, comedi_aux_data(it->options, 0), - it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]); + it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]); } dev->board_name = BOARDNAME; /* set number of subdevices */ - dev->n_subdevices=N_SUBDEVICES; + dev->n_subdevices = N_SUBDEVICES; // allocate space for the subdevices - if((ret=alloc_subdevices(dev,N_SUBDEVICES))<0) { + if ((ret = alloc_subdevices(dev, N_SUBDEVICES)) < 0) { printk("comedi%d: usbduxfast: error alloc space for subdev\n", - dev->minor); + dev->minor); up(&start_stop_sem); return ret; } printk("comedi%d: usbduxfast: usb-device %d is attached to comedi.\n", - dev->minor,index); + dev->minor, index); // private structure is also simply the usb-structure - dev->private=usbduxfastsub+index; + dev->private = usbduxfastsub + index; // the first subdevice is the A/D converter s = dev->subdevices + SUBDEV_AD; // the URBs get the comedi subdevice @@ -1733,49 +1637,43 @@ static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it) dev->read_subdev = s; // the subdevice receives as private structure the // usb-structure - s->private=NULL; + s->private = NULL; // analog input - s->type=COMEDI_SUBD_AI; + s->type = COMEDI_SUBD_AI; // readable and ref is to ground - s->subdev_flags=SDF_READABLE|SDF_GROUND|SDF_CMD_READ; + s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; // 16 channels - s->n_chan=16; + s->n_chan = 16; // length of the channellist - s->len_chanlist=16; + s->len_chanlist = 16; // callback functions s->insn_read = usbduxfast_ai_insn_read; - s->do_cmdtest=usbduxfast_ai_cmdtest; - s->do_cmd=usbduxfast_ai_cmd; - s->cancel=usbduxfast_ai_cancel; + s->do_cmdtest = usbduxfast_ai_cmdtest; + s->do_cmd = usbduxfast_ai_cmd; + s->cancel = usbduxfast_ai_cancel; // max value from the A/D converter (12bit+1 bit for overflow) - s->maxdata=0x1000; + s->maxdata = 0x1000; // range table to convert to physical units s->range_table = &range_usbduxfast_ai_range; // finally decide that it's attached - usbduxfastsub[index].attached=1; + usbduxfastsub[index].attached = 1; up(&(usbduxfastsub[index].sem)); up(&start_stop_sem); - printk("comedi%d: successfully attached to usbduxfast.\n", - dev->minor); + printk("comedi%d: successfully attached to usbduxfast.\n", dev->minor); return 0; } - - - - - -static int usbduxfast_detach(comedi_device * dev) { - usbduxfastsub_t* usbduxfastsub_tmp; +static int usbduxfast_detach(comedi_device * dev) +{ + usbduxfastsub_t *usbduxfastsub_tmp; #ifdef CONFIG_COMEDI_DEBUG - printk("comedi%d: usbduxfast: detach usb device\n", - dev->minor); + printk("comedi%d: usbduxfast: detach usb device\n", dev->minor); #endif if (!dev) { @@ -1783,7 +1681,7 @@ static int usbduxfast_detach(comedi_device * dev) { return -EFAULT; } - usbduxfastsub_tmp=dev->private; + usbduxfastsub_tmp = dev->private; if (!usbduxfastsub_tmp) { printk("comedi?: usbduxfast: detach without ptr to usbduxfastsub[]\n"); return -EFAULT; @@ -1793,43 +1691,28 @@ static int usbduxfast_detach(comedi_device * dev) { down(&start_stop_sem); // Don't allow detach to free the private structure // It's one entry of of usbduxfastsub[] - dev->private=NULL; - usbduxfastsub_tmp->attached=0; - usbduxfastsub_tmp->comedidev=NULL; + dev->private = NULL; + usbduxfastsub_tmp->attached = 0; + usbduxfastsub_tmp->comedidev = NULL; #ifdef CONFIG_COMEDI_DEBUG printk("comedi%d: usbduxfast: detach: successfully removed\n", - dev->minor); + dev->minor); #endif up(&start_stop_sem); up(&usbduxfastsub_tmp->sem); return 0; } - - - - - - - /* main driver struct */ -static comedi_driver driver_usbduxfast={ - driver_name: "usbduxfast", - module: THIS_MODULE, - attach: usbduxfast_attach, - detach: usbduxfast_detach, +static comedi_driver driver_usbduxfast = { + driver_name:"usbduxfast", + module:THIS_MODULE, + attach:usbduxfast_attach, + detach:usbduxfast_detach, }; - - - - - - - - - -static void init_usb_devices(void) { +static void init_usb_devices(void) +{ int index; #ifdef CONFIG_COMEDI_DEBUG printk("comedi_: usbduxfast: setting all possible devs to invalid\n"); @@ -1837,67 +1720,59 @@ static void init_usb_devices(void) { // all devices entries are invalid to begin with // they will become valid by the probe function // and then finally by the attach-function - for(index=0;index #include -#include /* for comedi_udelay() */ +#include /* for comedi_udelay() */ #include - -int comedi_data_write(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t data) +int comedi_data_write(comedi_t * dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t data) { comedi_insn insn; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_WRITE; insn.n = 1; insn.data = &data; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,range,aref); + insn.chanspec = CR_PACK(chan, range, aref); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_data_read(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data) +int comedi_data_read(comedi_t * dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t * data) { comedi_insn insn; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_READ; insn.n = 1; insn.data = data; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,range,aref); + insn.chanspec = CR_PACK(chan, range, aref); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_data_read_hint(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref) +int comedi_data_read_hint(comedi_t * dev, unsigned int subdev, + unsigned int chan, unsigned int range, unsigned int aref) { comedi_insn insn; lsampl_t dummy_data; - - memset(&insn,0,sizeof(insn)); + + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_READ; insn.n = 0; insn.data = &dummy_data; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,range,aref); + insn.chanspec = CR_PACK(chan, range, aref); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_data_read_delayed(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data, unsigned int nano_sec) +int comedi_data_read_delayed(comedi_t * dev, unsigned int subdev, + unsigned int chan, unsigned int range, unsigned int aref, + lsampl_t * data, unsigned int nano_sec) { int retval; - retval = comedi_data_read_hint( dev, subdev, chan, range, aref ); - if( retval < 0 ) return retval; + retval = comedi_data_read_hint(dev, subdev, chan, range, aref); + if (retval < 0) + return retval; - comedi_udelay( ( nano_sec + 999 ) / 1000 ); + comedi_udelay((nano_sec + 999) / 1000); - return comedi_data_read( dev, subdev, chan, range, aref, data ); + return comedi_data_read(dev, subdev, chan, range, aref, data); } diff --git a/comedi/kcomedilib/dio.c b/comedi/kcomedilib/dio.c index f4a87844..3a3ab02b 100644 --- a/comedi/kcomedilib/dio.c +++ b/comedi/kcomedilib/dio.c @@ -26,60 +26,59 @@ #include - -int comedi_dio_config(comedi_t * dev,unsigned int subdev,unsigned int chan, +int comedi_dio_config(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int io) { comedi_insn insn; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_CONFIG; insn.n = 1; insn.data = &io; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,0,0); + insn.chanspec = CR_PACK(chan, 0, 0); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_dio_read(comedi_t * dev,unsigned int subdev,unsigned int chan, +int comedi_dio_read(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int *val) { comedi_insn insn; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_READ; insn.n = 1; insn.data = val; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,0,0); + insn.chanspec = CR_PACK(chan, 0, 0); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_dio_write(comedi_t * dev,unsigned int subdev,unsigned int chan, +int comedi_dio_write(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int val) { comedi_insn insn; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_WRITE; insn.n = 1; insn.data = &val; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,0,0); + insn.chanspec = CR_PACK(chan, 0, 0); - return comedi_do_insn(dev,&insn); + return comedi_do_insn(dev, &insn); } -int comedi_dio_bitfield(comedi_t *dev,unsigned int subdev,unsigned int mask, +int comedi_dio_bitfield(comedi_t * dev, unsigned int subdev, unsigned int mask, unsigned int *bits) { comedi_insn insn; lsampl_t data[2]; int ret; - memset(&insn,0,sizeof(insn)); + memset(&insn, 0, sizeof(insn)); insn.insn = INSN_BITS; insn.n = 2; insn.data = data; @@ -88,12 +87,9 @@ int comedi_dio_bitfield(comedi_t *dev,unsigned int subdev,unsigned int mask, data[0] = mask; data[1] = *bits; - ret = comedi_do_insn(dev,&insn); + ret = comedi_do_insn(dev, &insn); *bits = data[1]; return ret; } - - - diff --git a/comedi/kcomedilib/get.c b/comedi/kcomedilib/get.c index 3c96995c..75310a63 100644 --- a/comedi/kcomedilib/get.c +++ b/comedi/kcomedilib/get.c @@ -26,82 +26,82 @@ #include #include - -int comedi_get_n_subdevices(comedi_t *d) +int comedi_get_n_subdevices(comedi_t * d) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; return dev->n_subdevices; } -int comedi_get_version_code(comedi_t *d) +int comedi_get_version_code(comedi_t * d) { return COMEDI_VERSION_CODE; } -const char *comedi_get_driver_name(comedi_t *d) +const char *comedi_get_driver_name(comedi_t * d) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; return dev->driver->driver_name; } -const char *comedi_get_board_name(comedi_t *d) +const char *comedi_get_board_name(comedi_t * d) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; return dev->board_name; } -int comedi_get_subdevice_type(comedi_t *d,unsigned int subdevice) +int comedi_get_subdevice_type(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; return s->type; } -unsigned int comedi_get_subdevice_flags(comedi_t *d,unsigned int subdevice) +unsigned int comedi_get_subdevice_flags(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; return s->subdev_flags; } -int comedi_find_subdevice_by_type(comedi_t *d,int type,unsigned int subd) +int comedi_find_subdevice_by_type(comedi_t * d, int type, unsigned int subd) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; - if (subd>dev->n_subdevices) + if (subd > dev->n_subdevices) return -ENODEV; - for(;subdn_subdevices;subd++){ - if(dev->subdevices[subd].type==type) + for (; subd < dev->n_subdevices; subd++) { + if (dev->subdevices[subd].type == type) return subd; } return -1; } -int comedi_get_n_channels(comedi_t *d,unsigned int subdevice) +int comedi_get_n_channels(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; return s->n_chan; } -int comedi_get_len_chanlist(comedi_t *d,unsigned int subdevice) +int comedi_get_len_chanlist(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; return s->len_chanlist; } -lsampl_t comedi_get_maxdata(comedi_t *d,unsigned int subdevice,unsigned int chan) +lsampl_t comedi_get_maxdata(comedi_t * d, unsigned int subdevice, + unsigned int chan) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; if (s->maxdata_list) @@ -111,34 +111,35 @@ lsampl_t comedi_get_maxdata(comedi_t *d,unsigned int subdevice,unsigned int chan } #ifdef KCOMEDILIB_DEPRECATED -int comedi_get_rangetype(comedi_t *d,unsigned int subdevice,unsigned int chan) +int comedi_get_rangetype(comedi_t * d, unsigned int subdevice, + unsigned int chan) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; int ret; if (s->range_table_list) { - ret=s->range_table_list[chan]->length; + ret = s->range_table_list[chan]->length; } else { - ret=s->range_table->length; + ret = s->range_table->length; } - ret=ret|(dev->minor<<28)|(subdevice<<24)|(chan<<16); + ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16); return ret; } #endif -int comedi_get_n_ranges(comedi_t *d,unsigned int subdevice,unsigned int chan) +int comedi_get_n_ranges(comedi_t * d, unsigned int subdevice, unsigned int chan) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; int ret; if (s->range_table_list) { - ret=s->range_table_list[chan]->length; + ret = s->range_table_list[chan]->length; } else { - ret=s->range_table->length; + ret = s->range_table->length; } return ret; @@ -147,21 +148,22 @@ int comedi_get_n_ranges(comedi_t *d,unsigned int subdevice,unsigned int chan) /* * ALPHA (non-portable) */ -int comedi_get_krange(comedi_t *d,unsigned int subdevice,unsigned int chan,unsigned int range,comedi_krange *krange) +int comedi_get_krange(comedi_t * d, unsigned int subdevice, unsigned int chan, + unsigned int range, comedi_krange * krange) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; const comedi_lrange *lr; if (s->range_table_list) { - lr=s->range_table_list[chan]; + lr = s->range_table_list[chan]; } else { - lr=s->range_table; + lr = s->range_table; } - if (range>=lr->length) { + if (range >= lr->length) { return -EINVAL; } - memcpy(krange,lr->range+range,sizeof(comedi_krange)); + memcpy(krange, lr->range + range, sizeof(comedi_krange)); return 0; } @@ -169,28 +171,31 @@ int comedi_get_krange(comedi_t *d,unsigned int subdevice,unsigned int chan,unsig /* * ALPHA (may be renamed) */ -unsigned int comedi_get_buf_head_pos(comedi_t *d,unsigned int subdevice) +unsigned int comedi_get_buf_head_pos(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; async = s->async; - if(async == NULL) return 0; + if (async == NULL) + return 0; return async->buf_write_count; } -int comedi_get_buffer_contents( comedi_t *d, unsigned int subdevice ) +int comedi_get_buffer_contents(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; unsigned int num_bytes; - if( subdevice >= dev->n_subdevices ) return -1; + if (subdevice >= dev->n_subdevices) + return -1; async = s->async; - if(async == NULL) return 0; + if (async == NULL) + return 0; num_bytes = comedi_buf_read_n_available(s->async); return num_bytes; } @@ -198,34 +203,39 @@ int comedi_get_buffer_contents( comedi_t *d, unsigned int subdevice ) /* * ALPHA */ -int comedi_set_user_int_count(comedi_t *d,unsigned int subdevice,unsigned int buf_user_count) +int comedi_set_user_int_count(comedi_t * d, unsigned int subdevice, + unsigned int buf_user_count) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; int num_bytes; async = s->async; - if( async == NULL ) return -1; + if (async == NULL) + return -1; - num_bytes = buf_user_count - async->buf_read_count; - if( num_bytes < 0 ) return -1; + num_bytes = buf_user_count - async->buf_read_count; + if (num_bytes < 0) + return -1; comedi_buf_read_alloc(async, num_bytes); comedi_buf_read_free(async, num_bytes); return 0; } -int comedi_mark_buffer_read( comedi_t *d, unsigned int subdevice, - unsigned int num_bytes ) +int comedi_mark_buffer_read(comedi_t * d, unsigned int subdevice, + unsigned int num_bytes) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; - if( subdevice >= dev->n_subdevices ) return -1; + if (subdevice >= dev->n_subdevices) + return -1; async = s->async; - if( async == NULL ) return -1; + if (async == NULL) + return -1; comedi_buf_read_alloc(async, num_bytes); comedi_buf_read_free(async, num_bytes); @@ -233,46 +243,52 @@ int comedi_mark_buffer_read( comedi_t *d, unsigned int subdevice, return 0; } -int comedi_mark_buffer_written( comedi_t *d, unsigned int subdevice, - unsigned int num_bytes ) +int comedi_mark_buffer_written(comedi_t * d, unsigned int subdevice, + unsigned int num_bytes) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; int bytes_written; - if( subdevice >= dev->n_subdevices ) return -1; + if (subdevice >= dev->n_subdevices) + return -1; async = s->async; - if( async == NULL ) return -1; + if (async == NULL) + return -1; bytes_written = comedi_buf_write_alloc(async, num_bytes); comedi_buf_write_free(async, bytes_written); - if(bytes_written != num_bytes) return -1; + if (bytes_written != num_bytes) + return -1; return 0; } - -int comedi_get_buffer_size(comedi_t *d,unsigned int subdev) +int comedi_get_buffer_size(comedi_t * d, unsigned int subdev) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdev; comedi_async *async; - if( subdev >= dev->n_subdevices ) return -1; + if (subdev >= dev->n_subdevices) + return -1; async = s->async; - if(async == NULL) return 0; + if (async == NULL) + return 0; return async->prealloc_bufsz; } -int comedi_get_buffer_offset( comedi_t *d, unsigned int subdevice) +int comedi_get_buffer_offset(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; - if( subdevice >= dev->n_subdevices ) return -1; + if (subdevice >= dev->n_subdevices) + return -1; async = s->async; - if(async == NULL) return 0; + if (async == NULL) + return 0; return async->buf_read_ptr; } diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index 3fe686ca..fecfecb7 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -21,8 +21,6 @@ */ - - #define __NO_VERSION__ #include @@ -40,53 +38,50 @@ #include #include - MODULE_AUTHOR("David Schleef "); MODULE_DESCRIPTION("Comedi kernel library"); MODULE_LICENSE("GPL"); - - comedi_t *comedi_open(const char *filename) { comedi_device *dev; unsigned int minor; - if(strncmp(filename,"/dev/comedi",11) != 0) + if (strncmp(filename, "/dev/comedi", 11) != 0) return NULL; - minor = simple_strtoul(filename+11,NULL,0); + minor = simple_strtoul(filename + 11, NULL, 0); - if(minor >= COMEDI_NDEVICES) + if (minor >= COMEDI_NDEVICES) return NULL; dev = comedi_get_device_by_minor(minor); - if(!dev->attached) + if (!dev->attached) return NULL; - if(!try_module_get(dev->driver->module)) + if (!try_module_get(dev->driver->module)) return NULL; - return (comedi_t *)dev; + return (comedi_t *) dev; } comedi_t *comedi_open_old(unsigned int minor) { comedi_device *dev; - if(minor>=COMEDI_NDEVICES) + if (minor >= COMEDI_NDEVICES) return NULL; dev = comedi_get_device_by_minor(minor); - if(!dev->attached) + if (!dev->attached) return NULL; - return (comedi_t *)dev; + return (comedi_t *) dev; } -int comedi_close(comedi_t *d) +int comedi_close(comedi_t * d) { comedi_device *dev = (comedi_device *) d; @@ -102,7 +97,7 @@ int comedi_loglevel(int newlevel) void comedi_perror(const char *message) { - rt_printk("%s: unknown error\n",message); + rt_printk("%s: unknown error\n", message); } char *comedi_strerror(int err) @@ -110,180 +105,183 @@ char *comedi_strerror(int err) return "unknown error"; } -int comedi_fileno(comedi_t *d) +int comedi_fileno(comedi_t * d) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; /* return something random */ return dev->minor; } -int comedi_command(comedi_t *d,comedi_cmd *cmd) +int comedi_command(comedi_t * d, comedi_cmd * cmd) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s; comedi_async *async; - if(cmd->subdev>=dev->n_subdevices) + if (cmd->subdev >= dev->n_subdevices) return -ENODEV; - s=dev->subdevices+cmd->subdev; - if(s->type==COMEDI_SUBD_UNUSED) + s = dev->subdevices + cmd->subdev; + if (s->type == COMEDI_SUBD_UNUSED) return -EIO; async = s->async; - if(async == NULL) + if (async == NULL) return -ENODEV; - if(s->busy) + if (s->busy) return -EBUSY; s->busy = d; - if(async->cb_mask & COMEDI_CB_EOS) + if (async->cb_mask & COMEDI_CB_EOS) cmd->flags |= TRIG_WAKE_EOS; - async->cmd=*cmd; + async->cmd = *cmd; s->runflags |= SRF_RT; comedi_switch_to_rt(dev); comedi_set_subdevice_runflags(s, SRF_RUNNING, SRF_RUNNING); - comedi_reset_async_buf( async ); + comedi_reset_async_buf(async); - return s->do_cmd(dev,s); + return s->do_cmd(dev, s); } -int comedi_command_test(comedi_t *d,comedi_cmd *cmd) +int comedi_command_test(comedi_t * d, comedi_cmd * cmd) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s; - if(cmd->subdev>=dev->n_subdevices) + if (cmd->subdev >= dev->n_subdevices) return -ENODEV; - s=dev->subdevices+cmd->subdev; - if(s->type==COMEDI_SUBD_UNUSED) + s = dev->subdevices + cmd->subdev; + if (s->type == COMEDI_SUBD_UNUSED) return -EIO; - if(s->async == NULL) + if (s->async == NULL) return -ENODEV; - return s->do_cmdtest(dev,s,cmd); + return s->do_cmdtest(dev, s, cmd); } /* * COMEDI_INSN * perform an instruction */ -int comedi_do_insn(comedi_t *d,comedi_insn *insn) +int comedi_do_insn(comedi_t * d, comedi_insn * insn) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s; - int ret=0; + int ret = 0; - if(insn->insn&INSN_MASK_SPECIAL){ - switch(insn->insn){ + if (insn->insn & INSN_MASK_SPECIAL) { + switch (insn->insn) { case INSN_GTOD: - { - struct timeval tv; + { + struct timeval tv; - do_gettimeofday(&tv); - insn->data[0] = tv.tv_sec; - insn->data[1] = tv.tv_usec; - ret = 2; + do_gettimeofday(&tv); + insn->data[0] = tv.tv_sec; + insn->data[1] = tv.tv_usec; + ret = 2; - break; - } + break; + } case INSN_WAIT: - if(insn->n<1 || insn->data[0]>=100){ + if (insn->n < 1 || insn->data[0] >= 100) { ret = -EINVAL; break; } comedi_udelay(insn->data[0]); - ret=1; + ret = 1; break; case INSN_INTTRIG: - if(insn->n!=1){ - ret=-EINVAL; + if (insn->n != 1) { + ret = -EINVAL; break; } - if(insn->subdev>=dev->n_subdevices){ - rt_printk("%d not usable subdevice\n",insn->subdev); - ret=-EINVAL; + if (insn->subdev >= dev->n_subdevices) { + rt_printk("%d not usable subdevice\n", + insn->subdev); + ret = -EINVAL; break; } - s=dev->subdevices+insn->subdev; - if(!s->async){ + s = dev->subdevices + insn->subdev; + if (!s->async) { rt_printk("no async\n"); - ret=-EINVAL; + ret = -EINVAL; break; } - if(!s->async->inttrig){ + if (!s->async->inttrig) { rt_printk("no inttrig\n"); - ret=-EAGAIN; + ret = -EAGAIN; break; } - ret = s->async->inttrig(dev,s,insn->data[0]); - if(ret>=0)ret = 1; + ret = s->async->inttrig(dev, s, insn->data[0]); + if (ret >= 0) + ret = 1; break; default: ret = -EINVAL; } - }else{ + } else { /* a subdevice instruction */ - if(insn->subdev>=dev->n_subdevices){ + if (insn->subdev >= dev->n_subdevices) { ret = -EINVAL; goto error; } - s = dev->subdevices+insn->subdev; + s = dev->subdevices + insn->subdev; - if(s->type==COMEDI_SUBD_UNUSED){ - rt_printk("%d not useable subdevice\n",insn->subdev); + if (s->type == COMEDI_SUBD_UNUSED) { + rt_printk("%d not useable subdevice\n", insn->subdev); /* XXX no return value is set! ret = ? */ goto error; } /* XXX check lock */ - if((ret=check_chanlist(s,1,&insn->chanspec))<0){ + if ((ret = check_chanlist(s, 1, &insn->chanspec)) < 0) { rt_printk("bad chanspec\n"); /* XXX no return value is set! ret = ? */ goto error; } - if(s->busy){ + if (s->busy) { ret = -EBUSY; goto error; } s->busy = d; - switch(insn->insn){ - case INSN_READ: - ret = s->insn_read(dev,s,insn,insn->data); - break; - case INSN_WRITE: - ret = s->insn_write(dev,s,insn,insn->data); - break; - case INSN_BITS: - ret = s->insn_bits(dev,s,insn,insn->data); - break; - case INSN_CONFIG: - ret = s->insn_config(dev,s,insn,insn->data); - break; - default: - ret=-EINVAL; - break; + switch (insn->insn) { + case INSN_READ: + ret = s->insn_read(dev, s, insn, insn->data); + break; + case INSN_WRITE: + ret = s->insn_write(dev, s, insn, insn->data); + break; + case INSN_BITS: + ret = s->insn_bits(dev, s, insn, insn->data); + break; + case INSN_CONFIG: + ret = s->insn_config(dev, s, insn, insn->data); + break; + default: + ret = -EINVAL; + break; } s->busy = NULL; } - if(ret<0)goto error; - if(ret!=insn->n){ + if (ret < 0) + goto error; + if (ret != insn->n) { rt_printk("BUG: result of insn != insn.n\n"); ret = -EINVAL; goto error; } -error: + error: return ret; } @@ -307,31 +305,30 @@ error: - lock while subdevice being programmed */ -int comedi_lock(comedi_t *d,unsigned int subdevice) +int comedi_lock(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; unsigned long flags; - int ret=0; + int ret = 0; - comedi_spin_lock_irqsave(&big_comedi_lock,flags); + comedi_spin_lock_irqsave(&big_comedi_lock, flags); - if(s->busy){ + if (s->busy) { ret = -EBUSY; - }else{ - if(s->lock){ + } else { + if (s->lock) { ret = -EBUSY; - }else{ + } else { s->lock = d; } } - comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); return ret; } - /* COMEDI_UNLOCK unlock subdevice @@ -346,36 +343,36 @@ int comedi_lock(comedi_t *d,unsigned int subdevice) none */ -int comedi_unlock(comedi_t *d,unsigned int subdevice) +int comedi_unlock(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; unsigned long flags; comedi_async *async; async = s->async; - comedi_spin_lock_irqsave(&big_comedi_lock,flags); + comedi_spin_lock_irqsave(&big_comedi_lock, flags); - if(s->busy){ - comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); + if (s->busy) { + comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); return -EBUSY; } - if(s->lock && s->lock!=(void *)d){ - comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); + if (s->lock && s->lock != (void *)d) { + comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); return -EACCES; } - s->lock=NULL; + s->lock = NULL; - if(async){ - async->cb_mask=0; - async->cb_func=NULL; - async->cb_arg=NULL; + if (async) { + async->cb_mask = 0; + async->cb_func = NULL; + async->cb_arg = NULL; } - comedi_spin_unlock_irqrestore(&big_comedi_lock,flags); + comedi_spin_unlock_irqrestore(&big_comedi_lock, flags); return 0; } @@ -394,36 +391,35 @@ int comedi_unlock(comedi_t *d,unsigned int subdevice) nothing */ -int comedi_cancel(comedi_t *d,unsigned int subdevice) +int comedi_cancel(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; - int ret=0; + int ret = 0; - if(s->lock && s->lock!=d) + if (s->lock && s->lock != d) return -EACCES; #if 0 - if(!s->busy) + if (!s->busy) return 0; - if(s->busy!=d) + if (s->busy != d) return -EBUSY; #endif - if(!s->cancel) + if (!s->cancel) return -EINVAL; - if((ret=s->cancel(dev,s))) + if ((ret = s->cancel(dev, s))) return ret; - if( s->runflags & SRF_RT ) - { + if (s->runflags & SRF_RT) { // XXX race s->runflags &= ~SRF_RT; comedi_switch_to_non_rt(dev); } - s->busy=NULL; + s->busy = NULL; return 0; } @@ -431,73 +427,70 @@ int comedi_cancel(comedi_t *d,unsigned int subdevice) /* registration of callback functions */ -int comedi_register_callback(comedi_t *d,unsigned int subdevice, - unsigned int mask,int (*cb)(unsigned int,void *),void *arg) +int comedi_register_callback(comedi_t * d, unsigned int subdevice, + unsigned int mask, int (*cb) (unsigned int, void *), void *arg) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; async = s->async; - if(s->type==COMEDI_SUBD_UNUSED) + if (s->type == COMEDI_SUBD_UNUSED) return -EIO; /* are we locked? (ioctl lock) */ - if(s->lock && s->lock!=d) + if (s->lock && s->lock != d) return -EACCES; /* are we busy? */ - if(s->busy) + if (s->busy) return -EBUSY; - if(!mask){ - async->cb_mask=0; - async->cb_func=NULL; - async->cb_arg=NULL; - }else{ - async->cb_mask=mask; - async->cb_func=cb; - async->cb_arg=arg; + if (!mask) { + async->cb_mask = 0; + async->cb_func = NULL; + async->cb_arg = NULL; + } else { + async->cb_mask = mask; + async->cb_func = cb; + async->cb_arg = arg; } return 0; } - -int comedi_poll(comedi_t *d, unsigned int subdevice) +int comedi_poll(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; comedi_async *async; async = s->async; - if(s->type==COMEDI_SUBD_UNUSED || !async) + if (s->type == COMEDI_SUBD_UNUSED || !async) return -EIO; /* are we locked? (ioctl lock) */ - if(s->lock && s->lock!=d) + if (s->lock && s->lock != d) return -EACCES; /* are we running? XXX wrong? */ - if(!s->busy) + if (!s->busy) return -EIO; - return s->poll(dev,s); + return s->poll(dev, s); } - /* WARNING: not portable */ -int comedi_map(comedi_t *d, unsigned int subdevice, void *ptr) +int comedi_map(comedi_t * d, unsigned int subdevice, void *ptr) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; - if(!s->async) + if (!s->async) return -EINVAL; - if(ptr) - { - *((void **) ptr) = s->async->prealloc_buf; + if (ptr) { + *((void **)ptr) = s->async->prealloc_buf; } /* XXX no reference counting */ @@ -506,16 +499,15 @@ int comedi_map(comedi_t *d, unsigned int subdevice, void *ptr) } /* WARNING: not portable */ -int comedi_unmap(comedi_t *d, unsigned int subdevice) +int comedi_unmap(comedi_t * d, unsigned int subdevice) { - comedi_device *dev = (comedi_device *)d; + comedi_device *dev = (comedi_device *) d; comedi_subdevice *s = dev->subdevices + subdevice; - if(!s->async) + if (!s->async) return -EINVAL; /* XXX no reference counting */ return 0; } - diff --git a/comedi/kcomedilib/ksyms.c b/comedi/kcomedilib/ksyms.c index b2d27171..2281ab86 100644 --- a/comedi/kcomedilib/ksyms.c +++ b/comedi/kcomedilib/ksyms.c @@ -21,7 +21,6 @@ */ - #ifndef EXPORT_SYMTAB #define EXPORT_SYMTAB #endif @@ -41,7 +40,6 @@ #include #include - #if LINUX_VERSION_CODE >= 0x020200 /* functions specific to kcomedilib */ @@ -136,7 +134,6 @@ EXPORT_SYMBOL(comedi_mark_buffer_written); //EXPORT_SYMBOL(comedi_get_range); EXPORT_SYMBOL(comedi_get_len_chanlist); - /* deprecated */ //EXPORT_SYMBOL(comedi_get_timer); //EXPORT_SYMBOL(comedi_timed_1chan); @@ -144,6 +141,4 @@ EXPORT_SYMBOL(comedi_get_len_chanlist); /* alpha */ //EXPORT_SYMBOL(comedi_set_global_oor_behavior); - #endif - diff --git a/comedi/proc.c b/comedi/proc.c index 6723c32c..472367a0 100644 --- a/comedi/proc.c +++ b/comedi/proc.c @@ -28,75 +28,70 @@ was cool. */ - #define __NO_VERSION__ #include #include //#include - -int comedi_read_procmem(char *buf,char **start,off_t offset,int len,int *eof,void *data); - +int comedi_read_procmem(char *buf, char **start, off_t offset, int len, + int *eof, void *data); extern comedi_driver *comedi_drivers; -int comedi_read_procmem(char *buf,char **start,off_t offset,int len,int *eof,void *data) +int comedi_read_procmem(char *buf, char **start, off_t offset, int len, + int *eof, void *data) { int i; - int devices_q=0; - int l=0; + int devices_q = 0; + int l = 0; comedi_driver *driv; - l+=sprintf(buf+l, + l += sprintf(buf + l, "comedi version " COMEDI_RELEASE "\n" "format string: %s\n", "\"%2d: %-20s %-20s %4d\",i,driver_name,board_name,n_subdevices"); - for(i=0;iattached){ - devices_q=1; - l+=sprintf(buf+l,"%2d: %-20s %-20s %4d\n", + if (dev->attached) { + devices_q = 1; + l += sprintf(buf + l, "%2d: %-20s %-20s %4d\n", i, dev->driver->driver_name, - dev->board_name, - dev->n_subdevices - ); + dev->board_name, dev->n_subdevices); } } - if(!devices_q){ - l+=sprintf(buf+l,"no devices\n"); + if (!devices_q) { + l += sprintf(buf + l, "no devices\n"); } - for(driv=comedi_drivers;driv;driv=driv->next){ - l += sprintf(buf+l,"%s:\n",driv->driver_name); - for(i=0;inum_names;i++){ - l+=sprintf(buf+l," %s\n", - *(char **)((char *)driv->board_name+i*driv->offset)); + for (driv = comedi_drivers; driv; driv = driv->next) { + l += sprintf(buf + l, "%s:\n", driv->driver_name); + for (i = 0; i < driv->num_names; i++) { + l += sprintf(buf + l, " %s\n", + *(char **)((char *)driv->board_name + + i * driv->offset)); } - if(!driv->num_names){ - l+=sprintf(buf+l," %s\n",driv->driver_name); + if (!driv->num_names) { + l += sprintf(buf + l, " %s\n", driv->driver_name); } } return l; } - void comedi_proc_init(void) { struct proc_dir_entry *comedi_proc; - comedi_proc = create_proc_entry("comedi",S_IFREG | S_IRUGO,0); - if(comedi_proc) + comedi_proc = create_proc_entry("comedi", S_IFREG | S_IRUGO, 0); + if (comedi_proc) comedi_proc->read_proc = comedi_read_procmem; } void comedi_proc_cleanup(void) { - remove_proc_entry("comedi",0); + remove_proc_entry("comedi", 0); } - - diff --git a/comedi/range.c b/comedi/range.c index 170370f6..09f54594 100644 --- a/comedi/range.c +++ b/comedi/range.c @@ -24,13 +24,12 @@ #include #include - -const comedi_lrange range_bipolar10={ 1, {BIP_RANGE(10)}}; -const comedi_lrange range_bipolar5={ 1, {BIP_RANGE(5)}}; -const comedi_lrange range_bipolar2_5={ 1, {BIP_RANGE(2.5)}}; -const comedi_lrange range_unipolar10={ 1, {UNI_RANGE(10)}}; -const comedi_lrange range_unipolar5={ 1, {UNI_RANGE(5)}}; -const comedi_lrange range_unknown={ 1, {{0,1000000,UNIT_none}}}; +const comedi_lrange range_bipolar10 = { 1, {BIP_RANGE(10)} }; +const comedi_lrange range_bipolar5 = { 1, {BIP_RANGE(5)} }; +const comedi_lrange range_bipolar2_5 = { 1, {BIP_RANGE(2.5)} }; +const comedi_lrange range_unipolar10 = { 1, {UNI_RANGE(10)} }; +const comedi_lrange range_unipolar5 = { 1, {UNI_RANGE(5)} }; +const comedi_lrange range_unknown = { 1, {{0, 1000000, UNIT_none}} }; /* COMEDI_RANGEINFO @@ -45,74 +44,80 @@ const comedi_lrange range_unknown={ 1, {{0,1000000,UNIT_none}}}; writes: n comedi_krange structures to rangeinfo->range_ptr */ -int do_rangeinfo_ioctl(comedi_device *dev, comedi_rangeinfo *arg) +int do_rangeinfo_ioctl(comedi_device * dev, comedi_rangeinfo * arg) { comedi_rangeinfo it; - int minor,subd,chan; + int minor, subd, chan; const comedi_lrange *lr; comedi_subdevice *s; comedi_device *query_dev; - if(copy_from_user(&it,arg,sizeof(comedi_rangeinfo))) + if (copy_from_user(&it, arg, sizeof(comedi_rangeinfo))) return -EFAULT; /* FIXME why do we have to support queries to devices that are different * than the one passed as the dev argument? */ - minor=(it.range_type>>28) & 0xf; - subd=(it.range_type>>24) & 0xf; - chan=(it.range_type>>16) & 0xff; + minor = (it.range_type >> 28) & 0xf; + subd = (it.range_type >> 24) & 0xf; + chan = (it.range_type >> 16) & 0xff; - if(minor > COMEDI_NDEVICES) + if (minor > COMEDI_NDEVICES) return -EINVAL; query_dev = comedi_devices + minor; - if(!query_dev->attached) return -EINVAL; - if(subd>=query_dev->n_subdevices) return -EINVAL; + if (!query_dev->attached) + return -EINVAL; + if (subd >= query_dev->n_subdevices) + return -EINVAL; s = query_dev->subdevices + subd; - if(s->range_table){ + if (s->range_table) { lr = s->range_table; - }else if(s->range_table_list){ - if(chan >= s->n_chan) return -EINVAL; + } else if (s->range_table_list) { + if (chan >= s->n_chan) + return -EINVAL; lr = s->range_table_list[chan]; - }else{ + } else { return -EINVAL; } - if( RANGE_LENGTH(it.range_type) != lr->length){ + if (RANGE_LENGTH(it.range_type) != lr->length) { DPRINTK("wrong length %d should be %d (0x%08x)\n", RANGE_LENGTH(it.range_type), lr->length, it.range_type); return -EINVAL; } - if(copy_to_user(it.range_ptr, lr->range, - sizeof(comedi_krange) * lr->length)) + if (copy_to_user(it.range_ptr, lr->range, + sizeof(comedi_krange) * lr->length)) return -EFAULT; return 0; } -static int aref_invalid( comedi_subdevice *s, unsigned int chanspec ) +static int aref_invalid(comedi_subdevice * s, unsigned int chanspec) { unsigned int aref; // disable reporting invalid arefs... maybe someday return 0; - aref = CR_AREF( chanspec ); - switch( aref ) - { - case AREF_DIFF: - if( s->subdev_flags & SDF_DIFF ) return 0; - break; - case AREF_COMMON: - if( s->subdev_flags & SDF_COMMON ) return 0; - break; - case AREF_GROUND: - if( s->subdev_flags & SDF_GROUND ) return 0; - break; - case AREF_OTHER: - if( s->subdev_flags & SDF_OTHER ) return 0; - break; - default: - break; + aref = CR_AREF(chanspec); + switch (aref) { + case AREF_DIFF: + if (s->subdev_flags & SDF_DIFF) + return 0; + break; + case AREF_COMMON: + if (s->subdev_flags & SDF_COMMON) + return 0; + break; + case AREF_GROUND: + if (s->subdev_flags & SDF_GROUND) + return 0; + break; + case AREF_OTHER: + if (s->subdev_flags & SDF_OTHER) + return 0; + break; + default: + break; } DPRINTK("subdevice does not support aref %i", aref); return 1; @@ -122,41 +127,42 @@ static int aref_invalid( comedi_subdevice *s, unsigned int chanspec ) This function checks each element in a channel/gain list to make make sure it is valid. */ -int check_chanlist(comedi_subdevice *s,int n,unsigned int *chanlist) +int check_chanlist(comedi_subdevice * s, int n, unsigned int *chanlist) { int i; int chan; - - if(s->range_table){ - for(i=0;i=s->n_chan || - CR_RANGE(chanlist[i])>=s->range_table->length || - aref_invalid( s, chanlist[i] ) ){ - rt_printk("bad chanlist[%d]=0x%08x n_chan=%d range length=%d\n", - i,chanlist[i],s->n_chan,s->range_table->length); + if (s->range_table) { + for (i = 0; i < n; i++) + if (CR_CHAN(chanlist[i]) >= s->n_chan || + CR_RANGE(chanlist[i]) >= s->range_table->length + || aref_invalid(s, chanlist[i])) { + rt_printk + ("bad chanlist[%d]=0x%08x n_chan=%d range length=%d\n", + i, chanlist[i], s->n_chan, + s->range_table->length); #if 0 -for(i=0;irange_table_list){ - for(i=0;i=s->n_chan || - CR_RANGE(chanlist[i])>=s->range_table_list[chan]->length || - aref_invalid( s, chanlist[i] ) ){ - rt_printk("bad chanlist[%d]=0x%08x\n",i,chanlist[i]); + } else if (s->range_table_list) { + for (i = 0; i < n; i++) { + chan = CR_CHAN(chanlist[i]); + if (chan >= s->n_chan || + CR_RANGE(chanlist[i]) >= + s->range_table_list[chan]->length + || aref_invalid(s, chanlist[i])) { + rt_printk("bad chanlist[%d]=0x%08x\n", i, + chanlist[i]); return -EINVAL; } } - }else{ + } else { rt_printk("comedi: (bug) no range type list!\n"); return -EINVAL; } return 0; } - - diff --git a/comedi/rt.c b/comedi/rt.c index 1f5c1ca5..385b81b9 100644 --- a/comedi/rt.c +++ b/comedi/rt.c @@ -54,7 +54,7 @@ struct comedi_irq_struct { int rt; int irq; - irqreturn_t (*handler)(int irq,void *dev_id PT_REGS_ARG); + irqreturn_t(*handler) (int irq, void *dev_id PT_REGS_ARG); unsigned long flags; const char *device; comedi_device *dev_id; @@ -65,54 +65,54 @@ static int comedi_rt_release_irq(struct comedi_irq_struct *it); static struct comedi_irq_struct *comedi_irqs[NR_IRQS]; -int comedi_request_irq(unsigned irq, irqreturn_t (*handler)(int, void * - PT_REGS_ARG), - unsigned long flags,const char *device,comedi_device *dev_id) +int comedi_request_irq(unsigned irq, irqreturn_t(*handler) (int, + void *PT_REGS_ARG), unsigned long flags, const char *device, + comedi_device * dev_id) { struct comedi_irq_struct *it; int ret; /* null shared interrupt flag, since rt interrupt handlers do not - * support it, and this version of comedi_request_irq() is only - * called for kernels with rt support */ + * support it, and this version of comedi_request_irq() is only + * called for kernels with rt support */ unsigned long unshared_flags = flags & ~IRQF_SHARED; - + ret = request_irq(irq, handler, unshared_flags, device, dev_id); - if(ret<0){ + if (ret < 0) { // we failed, so fall back on allowing shared interrupt (which we won't ever make RT) - if(flags & IRQF_SHARED) - { - rt_printk("comedi: cannot get unshared interrupt, will not use RT interrupts.\n"); - ret=request_irq(irq, handler, flags, device, dev_id); + if (flags & IRQF_SHARED) { + rt_printk + ("comedi: cannot get unshared interrupt, will not use RT interrupts.\n"); + ret = request_irq(irq, handler, flags, device, dev_id); } - if(ret<0){ + if (ret < 0) { return ret; } - }else - { + } else { it = kzalloc(sizeof(struct comedi_irq_struct), GFP_KERNEL); - if(!it) + if (!it) return -ENOMEM; - - it->handler=handler; - it->irq=irq; - it->dev_id=dev_id; - it->device=device; + + it->handler = handler; + it->irq = irq; + it->dev_id = dev_id; + it->device = device; it->flags = unshared_flags; comedi_irqs[irq] = it; } return 0; } -void comedi_free_irq(unsigned int irq,comedi_device *dev_id) +void comedi_free_irq(unsigned int irq, comedi_device * dev_id) { struct comedi_irq_struct *it; free_irq(irq, dev_id); it = comedi_irqs[irq]; - if( it == NULL ) return; + if (it == NULL) + return; - if(it->rt){ + if (it->rt) { printk("real-time IRQ allocated at board removal (ignore)\n"); comedi_rt_release_irq(it); } @@ -121,62 +121,60 @@ void comedi_free_irq(unsigned int irq,comedi_device *dev_id) comedi_irqs[irq] = NULL; } - - -int comedi_switch_to_rt(comedi_device *dev) +int comedi_switch_to_rt(comedi_device * dev) { struct comedi_irq_struct *it; unsigned long flags; it = comedi_irqs[dev->irq]; /* drivers might not be using an interrupt for commands, - or we might not have been able to get an unshared irq */ - if( it == NULL ) return -1; + or we might not have been able to get an unshared irq */ + if (it == NULL) + return -1; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); - if(!dev->rt) + if (!dev->rt) comedi_rt_get_irq(it); dev->rt++; - it->rt=1; + it->rt = 1; - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); return 0; } -void comedi_switch_to_non_rt(comedi_device *dev) +void comedi_switch_to_non_rt(comedi_device * dev) { struct comedi_irq_struct *it; unsigned long flags; it = comedi_irqs[dev->irq]; - if(it == NULL) + if (it == NULL) return; - comedi_spin_lock_irqsave( &dev->spinlock, flags ); + comedi_spin_lock_irqsave(&dev->spinlock, flags); dev->rt--; - if(!dev->rt) + if (!dev->rt) comedi_rt_release_irq(it); - it->rt=0; + it->rt = 0; - comedi_spin_unlock_irqrestore( &dev->spinlock, flags ); + comedi_spin_unlock_irqrestore(&dev->spinlock, flags); } -void wake_up_int_handler(int arg1, void * arg2) +void wake_up_int_handler(int arg1, void *arg2) { - wake_up_interruptible((wait_queue_head_t*)arg2); + wake_up_interruptible((wait_queue_head_t *) arg2); } -void comedi_rt_pend_wakeup(wait_queue_head_t *q) +void comedi_rt_pend_wakeup(wait_queue_head_t * q) { - rt_pend_call(wake_up_int_handler,0,q); + rt_pend_call(wake_up_int_handler, 0, q); } - /* RTAI section */ #ifdef CONFIG_COMEDI_RTAI @@ -189,8 +187,7 @@ static void handle_void_irq(int irq) struct comedi_irq_struct *it; it = comedi_irqs[irq]; - if(it == NULL) - { + if (it == NULL) { rt_printk("comedi: null irq struct?\n"); return; } @@ -223,8 +220,8 @@ DECLARE_VOID_IRQ(21); DECLARE_VOID_IRQ(22); DECLARE_VOID_IRQ(23); -typedef void (*V_FP_V)(void); -static V_FP_V handle_void_irq_ptrs[]={ +typedef void (*V_FP_V) (void); +static V_FP_V handle_void_irq_ptrs[] = { handle_void_irq_0, handle_void_irq_1, handle_void_irq_2, @@ -271,10 +268,10 @@ static int comedi_rt_get_irq(struct comedi_irq_struct *it) { int ret; - ret = rt_request_global_irq_arg(it->irq,it->handler,it->flags, - it->device,it->dev_id); - if(ret<0){ - rt_printk("rt_request_global_irq_arg() returned %d\n",ret); + ret = rt_request_global_irq_arg(it->irq, it->handler, it->flags, + it->device, it->dev_id); + if (ret < 0) { + rt_printk("rt_request_global_irq_arg() returned %d\n", ret); return ret; } rt_startup_irq(it->irq); @@ -290,7 +287,6 @@ static int comedi_rt_release_irq(struct comedi_irq_struct *it) } #endif - void comedi_rt_init(void) { rt_mount_rtai(); @@ -340,7 +336,7 @@ void comedi_rt_cleanup(void) rt_pend_tq_cleanup(); } -#endif /*CONFIG_COMEDI_FUSION*/ +#endif /*CONFIG_COMEDI_FUSION */ /* RTLinux section */ #ifdef CONFIG_COMEDI_RTL @@ -350,15 +346,16 @@ static unsigned int handle_rtl_irq(unsigned int irq PT_REGS_ARG) struct comedi_irq_struct *it; it = comedi_irqs[irq]; - if( it == NULL ) return 0; - it->handler( irq, it->dev_id PT_REGS_NULL ); + if (it == NULL) + return 0; + it->handler(irq, it->dev_id PT_REGS_NULL); rtl_hard_enable_irq(irq); return 0; } static int comedi_rt_get_irq(struct comedi_irq_struct *it) { - rtl_request_global_irq(it->irq,handle_rtl_irq); + rtl_request_global_irq(it->irq, handle_rtl_irq); return 0; } @@ -385,9 +382,9 @@ static int comedi_rt_get_irq(struct comedi_irq_struct *it) { int ret; - free_irq(it->irq,it->dev_id); - ret=request_irq(it->irq,it->handler,it->flags|SA_PRIORITY, - it->device,it->dev_id); + free_irq(it->irq, it->dev_id); + ret = request_irq(it->irq, it->handler, it->flags | SA_PRIORITY, + it->device, it->dev_id); return ret; } @@ -396,9 +393,9 @@ static int comedi_rt_release_irq(struct comedi_irq_struct *it) { int ret; - free_irq(it->irq,it->dev_id); - ret=request_irq(it->irq,it->handler,it->flags, - it->device,it->dev_id); + free_irq(it->irq, it->dev_id); + ret = request_irq(it->irq, it->handler, it->flags, + it->device, it->dev_id); return ret; } @@ -413,4 +410,3 @@ void comedi_rt_cleanup(void) //rt_pend_tq_cleanup(); } #endif - diff --git a/comedi/rt_pend_tq.c b/comedi/rt_pend_tq.c index a261169a..46c0e956 100644 --- a/comedi/rt_pend_tq.c +++ b/comedi/rt_pend_tq.c @@ -22,34 +22,34 @@ #endif volatile static struct rt_pend_tq rt_pend_tq[RT_PEND_TQ_SIZE]; -volatile static struct rt_pend_tq * volatile rt_pend_head= rt_pend_tq, - * volatile rt_pend_tail = rt_pend_tq; -int rt_pend_tq_irq=0; +volatile static struct rt_pend_tq *volatile rt_pend_head = rt_pend_tq, + *volatile rt_pend_tail = rt_pend_tq; +int rt_pend_tq_irq = 0; spinlock_t rt_pend_tq_lock = SPIN_LOCK_UNLOCKED; // WARNING: following code not checked against race conditions yet. #define INC_CIRCULAR_PTR(ptr,begin,size) do {if(++(ptr)>=(begin)+(size)) (ptr)=(begin); } while(0) #define DEC_CIRCULAR_PTR(ptr,begin,size) do {if(--(ptr)<(begin)) (ptr)=(begin)+(size)-1; } while(0) -int rt_pend_call(void (*func)(int arg1, void * arg2), int arg1, void * arg2) +int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1, void *arg2) { unsigned long flags; - if(func==NULL) + if (func == NULL) return -EINVAL; - if(rt_pend_tq_irq<=0) + if (rt_pend_tq_irq <= 0) return -ENODEV; comedi_spin_lock_irqsave(&rt_pend_tq_lock, flags); - INC_CIRCULAR_PTR(rt_pend_head,rt_pend_tq,RT_PEND_TQ_SIZE); - if(rt_pend_head==rt_pend_tail) { + INC_CIRCULAR_PTR(rt_pend_head, rt_pend_tq, RT_PEND_TQ_SIZE); + if (rt_pend_head == rt_pend_tail) { // overflow, we just refuse to take this request - DEC_CIRCULAR_PTR(rt_pend_head,rt_pend_tq,RT_PEND_TQ_SIZE); + DEC_CIRCULAR_PTR(rt_pend_head, rt_pend_tq, RT_PEND_TQ_SIZE); comedi_spin_unlock_irqrestore(&rt_pend_tq_lock, flags); return -EAGAIN; } - rt_pend_head->func=func; - rt_pend_head->arg1=arg1; - rt_pend_head->arg2=arg2; + rt_pend_head->func = func; + rt_pend_head->arg1 = arg1; + rt_pend_head->arg2 = arg2; comedi_spin_unlock_irqrestore(&rt_pend_tq_lock, flags); #ifdef CONFIG_COMEDI_RTAI rt_pend_linux_srq(rt_pend_tq_irq); @@ -67,30 +67,31 @@ int rt_pend_call(void (*func)(int arg1, void * arg2), int arg1, void * arg2) #ifdef CONFIG_COMEDI_RTAI void rt_pend_irq_handler(void) #elif defined(CONFIG_COMEDI_FUSION) -void rt_pend_irq_handler(void * cookie) +void rt_pend_irq_handler(void *cookie) #elif defined(CONFIG_COMEDI_RTL) void rt_pend_irq_handler(int irq, void *dev PT_REGS_ARG) #endif { - while(rt_pend_head!=rt_pend_tail) { - INC_CIRCULAR_PTR(rt_pend_tail,rt_pend_tq,RT_PEND_TQ_SIZE); - rt_pend_tail->func(rt_pend_tail->arg1,rt_pend_tail->arg2); + while (rt_pend_head != rt_pend_tail) { + INC_CIRCULAR_PTR(rt_pend_tail, rt_pend_tq, RT_PEND_TQ_SIZE); + rt_pend_tail->func(rt_pend_tail->arg1, rt_pend_tail->arg2); } } int rt_pend_tq_init(void) { - rt_pend_head=rt_pend_tail=rt_pend_tq; + rt_pend_head = rt_pend_tail = rt_pend_tq; #ifdef CONFIG_COMEDI_RTAI - rt_pend_tq_irq=rt_request_srq(0,rt_pend_irq_handler,NULL); + rt_pend_tq_irq = rt_request_srq(0, rt_pend_irq_handler, NULL); #endif #ifdef CONFIG_COMEDI_FUSION - rt_pend_tq_irq=rthal_apc_alloc("comedi APC" ,rt_pend_irq_handler, NULL); + rt_pend_tq_irq = + rthal_apc_alloc("comedi APC", rt_pend_irq_handler, NULL); #endif #ifdef CONFIG_COMEDI_RTL - rt_pend_tq_irq=rtl_get_soft_irq(rt_pend_irq_handler,"rt_pend_irq"); + rt_pend_tq_irq = rtl_get_soft_irq(rt_pend_irq_handler, "rt_pend_irq"); #endif - if(rt_pend_tq_irq>0) + if (rt_pend_tq_irq > 0) printk("rt_pend_tq: RT bottom half scheduler initialized OK\n"); else printk("rt_pend_tq: rtl_get_soft_irq failed\n"); @@ -107,7 +108,6 @@ void rt_pend_tq_cleanup(void) rthal_apc_free(rt_pend_tq_irq); #endif #ifdef CONFIG_COMEDI_RTL - free_irq(rt_pend_tq_irq,NULL); + free_irq(rt_pend_tq_irq, NULL); #endif } - diff --git a/comedi/rt_pend_tq.h b/comedi/rt_pend_tq.h index 5475a0cb..01ed71bf 100644 --- a/comedi/rt_pend_tq.h +++ b/comedi/rt_pend_tq.h @@ -1,9 +1,10 @@ #define RT_PEND_TQ_SIZE 16 struct rt_pend_tq { - void (*func)(int arg1, void * arg2); + void (*func) (int arg1, void *arg2); int arg1; void *arg2; -} ; -extern int rt_pend_call(void (*func)(int arg1, void * arg2), int arg1, void * arg2); +}; +extern int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1, + void *arg2); extern int rt_pend_tq_init(void); extern void rt_pend_tq_cleanup(void); diff --git a/include/asm/div64.h b/include/asm/div64.h index e9f9e5a2..9bf78ce5 100644 --- a/include/asm/div64.h +++ b/include/asm/div64.h @@ -2,7 +2,6 @@ asm/div64.h ------------------- - copyright : (C) 2002 by Frank Mori Hess email : fmhess@users.sourceforge.net ***************************************************************************/ @@ -32,22 +31,18 @@ static inline u64 my_ull_div(u64 numerator, unsigned long denominator) remainder = numerator; - while(remainder >= denominator) - { + while (remainder >= denominator) { shift = 0; numerator = remainder; // shift most significant bits into 32 bit variable - while( numerator > max_u32 ) - { + while (numerator > max_u32) { numerator >>= 1; shift++; } - if( numerator < denominator ) - { + if (numerator < denominator) { shift--; value = 1; - }else - { + } else { value = numerator; value /= denominator; } @@ -67,4 +62,4 @@ static inline u64 my_ull_div(u64 numerator, unsigned long denominator) #endif -#endif // _DIV64_COMPAT_H +#endif // _DIV64_COMPAT_H diff --git a/include/asm/dma.h b/include/asm/dma.h index 551af454..cb0f503d 100644 --- a/include/asm/dma.h +++ b/include/asm/dma.h @@ -16,10 +16,10 @@ static __inline__ unsigned long claim_dma_lock(void) cli(); return flags; } + #define release_dma_lock(x) restore_flags(x) #endif #include_next #endif - diff --git a/include/asm/page.h b/include/asm/page.h index 16805f19..f35f1f94 100644 --- a/include/asm/page.h +++ b/include/asm/page.h @@ -16,17 +16,16 @@ /* Pure 2^n version of get_order */ static __inline__ int get_order(unsigned long size) { - int order; + int order; - size = (size-1) >> (PAGE_SHIFT-1); - order = -1; - do { - size >>= 1; - order++; - } while (size); - return order; + size = (size - 1) >> (PAGE_SHIFT - 1); + order = -1; + do { + size >>= 1; + order++; + } while (size); + return order; } #endif #endif // __COMPAT_ASM_PAGE_H_ - diff --git a/include/asm/pgtable.h b/include/asm/pgtable.h index eeea07e9..2335bf9e 100644 --- a/include/asm/pgtable.h +++ b/include/asm/pgtable.h @@ -33,4 +33,3 @@ #endif #endif /* __COMPAT_ASM_PGTABLE_H_ */ - diff --git a/include/asm/semaphore.h b/include/asm/semaphore.h index 791c2e14..34c054f3 100644 --- a/include/asm/semaphore.h +++ b/include/asm/semaphore.h @@ -18,4 +18,3 @@ #include_next #endif // __COMPAT_ASM_SEMAPHORE_H_ - diff --git a/include/asm/types.h b/include/asm/types.h index f20ca188..7be7a804 100644 --- a/include/asm/types.h +++ b/include/asm/types.h @@ -14,4 +14,3 @@ typedef unsigned long dma_addr_t; #include_next #endif // __COMPAT_ASM_TYPES_H_ - diff --git a/include/asm/uaccess.h b/include/asm/uaccess.h index 01235476..3d9190fe 100644 --- a/include/asm/uaccess.h +++ b/include/asm/uaccess.h @@ -5,36 +5,40 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0) /* unknown, approx 2.1.4 */ - #include -static inline int copy_to_user(void * to,const void *from,unsigned long n_bytes) +static inline int copy_to_user(void *to, const void *from, + unsigned long n_bytes) { int i; - if((i=verify_area(VERIFY_WRITE,to,n_bytes)) != 0) + if ((i = verify_area(VERIFY_WRITE, to, n_bytes)) != 0) return i; - memcpy_tofs(to,from,n_bytes); + memcpy_tofs(to, from, n_bytes); return 0; } -static inline int copy_from_user(void * to,const void *from,unsigned long n_bytes) +static inline int copy_from_user(void *to, const void *from, + unsigned long n_bytes) { int i; - if((i=verify_area(VERIFY_READ,from,n_bytes))!=0) + if ((i = verify_area(VERIFY_READ, from, n_bytes)) != 0) return i; - memcpy_fromfs(to,from,n_bytes); + memcpy_fromfs(to, from, n_bytes); return 0; } -static inline int clear_user(void * mem,unsigned long len) +static inline int clear_user(void *mem, unsigned long len) { - char *cmem=mem; - - if(verify_area(VERIFY_WRITE,mem,len)) + char *cmem = mem; + + if (verify_area(VERIFY_WRITE, mem, len)) return len; /* this is slow, but I'm lazy */ - while(len--){put_user(0,cmem);cmem++;} + while (len--) { + put_user(0, cmem); + cmem++; + } return 0; } @@ -45,4 +49,3 @@ static inline int clear_user(void * mem,unsigned long len) #endif #endif - diff --git a/include/linux/comedi.h b/include/linux/comedi.h index d6e25efb..7130173c 100644 --- a/include/linux/comedi.h +++ b/include/linux/comedi.h @@ -21,7 +21,6 @@ */ - #ifndef _COMEDI_H #define _COMEDI_H @@ -46,16 +45,15 @@ extern "C" { #define COMEDI_DEVCONF_AUX_DATA2_LENGTH 26 #define COMEDI_DEVCONF_AUX_DATA1_LENGTH 27 #define COMEDI_DEVCONF_AUX_DATA0_LENGTH 28 -#define COMEDI_DEVCONF_AUX_DATA_HI 29 /*most significant 32 bits of pointer address (if needed)*/ -#define COMEDI_DEVCONF_AUX_DATA_LO 30 /*least significant 32 bits of pointer address*/ +#define COMEDI_DEVCONF_AUX_DATA_HI 29 /*most significant 32 bits of pointer address (if needed) */ +#define COMEDI_DEVCONF_AUX_DATA_LO 30 /*least significant 32 bits of pointer address */ #define COMEDI_DEVCONF_AUX_DATA_LENGTH 31 /* total data length */ /* max length of device and driver names */ #define COMEDI_NAMELEN 20 - -typedef unsigned int lsampl_t; -typedef unsigned short sampl_t; + typedef unsigned int lsampl_t; + typedef unsigned short sampl_t; /* packs and unpacks a channel/range number */ @@ -74,10 +72,10 @@ typedef unsigned short sampl_t; #define CR_EDGE (1<<30) #define CR_INVERT (1<<31) -#define AREF_GROUND 0x00 /* analog ref = analog ground */ -#define AREF_COMMON 0x01 /* analog ref = analog common */ -#define AREF_DIFF 0x02 /* analog ref = differential */ -#define AREF_OTHER 0x03 /* analog ref = other (undefined) */ +#define AREF_GROUND 0x00 /* analog ref = analog ground */ +#define AREF_COMMON 0x01 /* analog ref = analog common */ +#define AREF_DIFF 0x02 /* analog ref = differential */ +#define AREF_OTHER 0x03 /* analog ref = other (undefined) */ /* counters -- these are arbitrary values */ #define GPCT_RESET 0x0001 @@ -118,23 +116,23 @@ typedef unsigned short sampl_t; /* trigger flags */ /* These flags are used in comedi_trig structures */ -#define TRIG_BOGUS 0x0001 /* do the motions */ -#define TRIG_DITHER 0x0002 /* enable dithering */ -#define TRIG_DEGLITCH 0x0004 /* enable deglitching */ -//#define TRIG_RT 0x0008 /* perform op in real time */ -#define TRIG_CONFIG 0x0010 /* perform configuration, not triggering */ -#define TRIG_WAKE_EOS 0x0020 /* wake up on end-of-scan events */ -//#define TRIG_WRITE 0x0040 /* write to bidirectional devices */ +#define TRIG_BOGUS 0x0001 /* do the motions */ +#define TRIG_DITHER 0x0002 /* enable dithering */ +#define TRIG_DEGLITCH 0x0004 /* enable deglitching */ +//#define TRIG_RT 0x0008 /* perform op in real time */ +#define TRIG_CONFIG 0x0010 /* perform configuration, not triggering */ +#define TRIG_WAKE_EOS 0x0020 /* wake up on end-of-scan events */ +//#define TRIG_WRITE 0x0040 /* write to bidirectional devices */ /* command flags */ /* These flags are used in comedi_cmd structures */ -#define CMDF_PRIORITY 0x00000008 /* try to use a real-time interrupt while performing command */ +#define CMDF_PRIORITY 0x00000008 /* try to use a real-time interrupt while performing command */ -#define TRIG_RT CMDF_PRIORITY /* compatibility definition */ +#define TRIG_RT CMDF_PRIORITY /* compatibility definition */ #define CMDF_WRITE 0x00000040 -#define TRIG_WRITE CMDF_WRITE /* compatibility definition */ +#define TRIG_WRITE CMDF_WRITE /* compatibility definition */ #define CMDF_RAWDATA 0x00000080 @@ -167,22 +165,22 @@ typedef unsigned short sampl_t; /* subdevice flags */ -#define SDF_BUSY 0x0001 /* device is busy */ -#define SDF_BUSY_OWNER 0x0002 /* device is busy with your job */ -#define SDF_LOCKED 0x0004 /* subdevice is locked */ -#define SDF_LOCK_OWNER 0x0008 /* you own lock */ -#define SDF_MAXDATA 0x0010 /* maxdata depends on channel */ -#define SDF_FLAGS 0x0020 /* flags depend on channel */ -#define SDF_RANGETYPE 0x0040 /* range type depends on channel */ -#define SDF_MODE0 0x0080 /* can do mode 0 */ -#define SDF_MODE1 0x0100 /* can do mode 1 */ -#define SDF_MODE2 0x0200 /* can do mode 2 */ -#define SDF_MODE3 0x0400 /* can do mode 3 */ -#define SDF_MODE4 0x0800 /* can do mode 4 */ -#define SDF_CMD 0x1000 /* can do commands (deprecated) */ +#define SDF_BUSY 0x0001 /* device is busy */ +#define SDF_BUSY_OWNER 0x0002 /* device is busy with your job */ +#define SDF_LOCKED 0x0004 /* subdevice is locked */ +#define SDF_LOCK_OWNER 0x0008 /* you own lock */ +#define SDF_MAXDATA 0x0010 /* maxdata depends on channel */ +#define SDF_FLAGS 0x0020 /* flags depend on channel */ +#define SDF_RANGETYPE 0x0040 /* range type depends on channel */ +#define SDF_MODE0 0x0080 /* can do mode 0 */ +#define SDF_MODE1 0x0100 /* can do mode 1 */ +#define SDF_MODE2 0x0200 /* can do mode 2 */ +#define SDF_MODE3 0x0400 /* can do mode 3 */ +#define SDF_MODE4 0x0800 /* can do mode 4 */ +#define SDF_CMD 0x1000 /* can do commands (deprecated) */ #define SDF_SOFT_CALIBRATED 0x2000 /* subdevice uses software calibration */ -#define SDF_CMD_WRITE 0x4000 /* can do output commands */ -#define SDF_CMD_READ 0x8000 /* can do input commands */ +#define SDF_CMD_WRITE 0x4000 /* can do output commands */ +#define SDF_CMD_READ 0x8000 /* can do input commands */ #define SDF_READABLE 0x00010000 /* subdevice can be read (e.g. analog input) */ #define SDF_WRITABLE 0x00020000 /* subdevice can be written (e.g. analog output) */ @@ -202,72 +200,68 @@ typedef unsigned short sampl_t; /* subdevice types */ -enum comedi_subdevice_type -{ - COMEDI_SUBD_UNUSED, /* unused by driver */ - COMEDI_SUBD_AI, /* analog input */ - COMEDI_SUBD_AO, /* analog output */ - COMEDI_SUBD_DI, /* digital input */ - COMEDI_SUBD_DO, /* digital output */ - COMEDI_SUBD_DIO, /* digital input/output */ - COMEDI_SUBD_COUNTER, /* counter */ - COMEDI_SUBD_TIMER, /* timer */ - COMEDI_SUBD_MEMORY, /* memory, EEPROM, DPRAM */ - COMEDI_SUBD_CALIB, /* calibration DACs */ - COMEDI_SUBD_PROC, /* processor, DSP */ - COMEDI_SUBD_SERIAL /* serial IO */ -}; + enum comedi_subdevice_type { + COMEDI_SUBD_UNUSED, /* unused by driver */ + COMEDI_SUBD_AI, /* analog input */ + COMEDI_SUBD_AO, /* analog output */ + COMEDI_SUBD_DI, /* digital input */ + COMEDI_SUBD_DO, /* digital output */ + COMEDI_SUBD_DIO, /* digital input/output */ + COMEDI_SUBD_COUNTER, /* counter */ + COMEDI_SUBD_TIMER, /* timer */ + COMEDI_SUBD_MEMORY, /* memory, EEPROM, DPRAM */ + COMEDI_SUBD_CALIB, /* calibration DACs */ + COMEDI_SUBD_PROC, /* processor, DSP */ + COMEDI_SUBD_SERIAL /* serial IO */ + }; /* configuration instructions */ -enum configuration_ids -{ - INSN_CONFIG_DIO_INPUT = 0, - INSN_CONFIG_DIO_OUTPUT = 1, - INSN_CONFIG_DIO_OPENDRAIN = 2, - INSN_CONFIG_ANALOG_TRIG = 16, -// INSN_CONFIG_WAVEFORM = 17, -// INSN_CONFIG_TRIG = 18, -// INSN_CONFIG_COUNTER = 19, - INSN_CONFIG_ALT_SOURCE = 20, - INSN_CONFIG_DIGITAL_TRIG = 21, - INSN_CONFIG_BLOCK_SIZE = 22, - INSN_CONFIG_TIMER_1 = 23, - INSN_CONFIG_FILTER = 24, - INSN_CONFIG_CHANGE_NOTIFY = 25, - - /*ALPHA*/ - INSN_CONFIG_SERIAL_CLOCK = 26, - INSN_CONFIG_BIDIRECTIONAL_DATA = 27, - INSN_CONFIG_DIO_QUERY = 28, - INSN_CONFIG_PWM_OUTPUT = 29, - INSN_CONFIG_GET_PWM_OUTPUT = 30, - INSN_CONFIG_ARM = 31, - INSN_CONFIG_DISARM = 32, - INSN_CONFIG_GET_COUNTER_STATUS = 33, - INSN_CONFIG_RESET = 34, - INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001, // Use CTR as single pulsegenerator - INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002, // Use CTR as pulsetraingenerator - INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003, // Use the counter as encoder - INSN_CONFIG_SET_GATE_SRC = 2001, // Set gate source - INSN_CONFIG_GET_GATE_SRC = 2002, // Get gate source - INSN_CONFIG_SET_CLOCK_SRC = 2003, // Set master clock source - INSN_CONFIG_GET_CLOCK_SRC = 2004, // Get master clock source - INSN_CONFIG_SET_OTHER_SRC = 2005, // Set other source -// INSN_CONFIG_GET_OTHER_SRC = 2006, // Get other source - INSN_CONFIG_SET_COUNTER_MODE = 4097, - INSN_CONFIG_8254_SET_MODE = INSN_CONFIG_SET_COUNTER_MODE, /* deprecated */ - INSN_CONFIG_8254_READ_STATUS = 4098, - INSN_CONFIG_SET_ROUTING = 4099, - INSN_CONFIG_GET_ROUTING = 4109, -}; - -enum comedi_io_direction -{ - COMEDI_INPUT = 0, - COMEDI_OUTPUT = 1, - COMEDI_OPENDRAIN = 2 -}; + enum configuration_ids { + INSN_CONFIG_DIO_INPUT = 0, + INSN_CONFIG_DIO_OUTPUT = 1, + INSN_CONFIG_DIO_OPENDRAIN = 2, + INSN_CONFIG_ANALOG_TRIG = 16, +// INSN_CONFIG_WAVEFORM = 17, +// INSN_CONFIG_TRIG = 18, +// INSN_CONFIG_COUNTER = 19, + INSN_CONFIG_ALT_SOURCE = 20, + INSN_CONFIG_DIGITAL_TRIG = 21, + INSN_CONFIG_BLOCK_SIZE = 22, + INSN_CONFIG_TIMER_1 = 23, + INSN_CONFIG_FILTER = 24, + INSN_CONFIG_CHANGE_NOTIFY = 25, + + /*ALPHA*/ INSN_CONFIG_SERIAL_CLOCK = 26, + INSN_CONFIG_BIDIRECTIONAL_DATA = 27, + INSN_CONFIG_DIO_QUERY = 28, + INSN_CONFIG_PWM_OUTPUT = 29, + INSN_CONFIG_GET_PWM_OUTPUT = 30, + INSN_CONFIG_ARM = 31, + INSN_CONFIG_DISARM = 32, + INSN_CONFIG_GET_COUNTER_STATUS = 33, + INSN_CONFIG_RESET = 34, + INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001, // Use CTR as single pulsegenerator + INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002, // Use CTR as pulsetraingenerator + INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003, // Use the counter as encoder + INSN_CONFIG_SET_GATE_SRC = 2001, // Set gate source + INSN_CONFIG_GET_GATE_SRC = 2002, // Get gate source + INSN_CONFIG_SET_CLOCK_SRC = 2003, // Set master clock source + INSN_CONFIG_GET_CLOCK_SRC = 2004, // Get master clock source + INSN_CONFIG_SET_OTHER_SRC = 2005, // Set other source +// INSN_CONFIG_GET_OTHER_SRC = 2006, // Get other source + INSN_CONFIG_SET_COUNTER_MODE = 4097, + INSN_CONFIG_8254_SET_MODE = INSN_CONFIG_SET_COUNTER_MODE, /* deprecated */ + INSN_CONFIG_8254_READ_STATUS = 4098, + INSN_CONFIG_SET_ROUTING = 4099, + INSN_CONFIG_GET_ROUTING = 4109, + }; + + enum comedi_io_direction { + COMEDI_INPUT = 0, + COMEDI_OUTPUT = 1, + COMEDI_OPENDRAIN = 2 + }; /* ioctls */ @@ -289,147 +283,146 @@ enum comedi_io_direction #define COMEDI_BUFINFO _IOWR(CIO,14,comedi_bufinfo) #define COMEDI_POLL _IO(CIO,15) - /* structures */ -typedef struct comedi_trig_struct comedi_trig; -typedef struct comedi_cmd_struct comedi_cmd; -typedef struct comedi_insn_struct comedi_insn; -typedef struct comedi_insnlist_struct comedi_insnlist; -typedef struct comedi_chaninfo_struct comedi_chaninfo; -typedef struct comedi_subdinfo_struct comedi_subdinfo; -typedef struct comedi_devinfo_struct comedi_devinfo; -typedef struct comedi_devconfig_struct comedi_devconfig; -typedef struct comedi_rangeinfo_struct comedi_rangeinfo; -typedef struct comedi_krange_struct comedi_krange; -typedef struct comedi_bufconfig_struct comedi_bufconfig; -typedef struct comedi_bufinfo_struct comedi_bufinfo; - -struct comedi_trig_struct{ - unsigned int subdev; /* subdevice */ - unsigned int mode; /* mode */ - unsigned int flags; - unsigned int n_chan; /* number of channels */ - unsigned int *chanlist; /* channel/range list */ - sampl_t *data; /* data list, size depends on subd flags */ - unsigned int n; /* number of scans */ - unsigned int trigsrc; - unsigned int trigvar; - unsigned int trigvar1; - unsigned int data_len; - unsigned int unused[3]; -}; - -struct comedi_insn_struct{ - unsigned int insn; - unsigned int n; - lsampl_t *data; - unsigned int subdev; - unsigned int chanspec; - unsigned int unused[3]; -}; - -struct comedi_insnlist_struct{ - unsigned int n_insns; - comedi_insn *insns; -}; - -struct comedi_cmd_struct{ - unsigned int subdev; - unsigned int flags; - - unsigned int start_src; - unsigned int start_arg; - - unsigned int scan_begin_src; - unsigned int scan_begin_arg; - - unsigned int convert_src; - unsigned int convert_arg; - - unsigned int scan_end_src; - unsigned int scan_end_arg; - - unsigned int stop_src; - unsigned int stop_arg; - - unsigned int *chanlist; /* channel/range list */ - unsigned int chanlist_len; - - sampl_t *data; /* data list, size depends on subd flags */ - unsigned int data_len; -}; - -struct comedi_chaninfo_struct{ - unsigned int subdev; - lsampl_t *maxdata_list; - unsigned int *flaglist; - unsigned int *rangelist; - unsigned int unused[4]; -}; - -struct comedi_rangeinfo_struct{ - unsigned int range_type; - void *range_ptr; -}; - -struct comedi_krange_struct{ - int min; /* fixed point, multiply by 1e-6 */ - int max; /* fixed point, multiply by 1e-6 */ - unsigned int flags; -}; - -struct comedi_subdinfo_struct{ - unsigned int type; - unsigned int n_chan; - unsigned int subd_flags; - unsigned int timer_type; - unsigned int len_chanlist; - lsampl_t maxdata; - unsigned int flags; /* channel flags */ - unsigned int range_type; /* lookup in kernel */ - unsigned int settling_time_0; - unsigned int unused[9]; -}; - -struct comedi_devinfo_struct{ - unsigned int version_code; - unsigned int n_subdevs; - char driver_name[COMEDI_NAMELEN]; - char board_name[COMEDI_NAMELEN]; - int read_subdevice; - int write_subdevice; - int unused[30]; -}; - -struct comedi_devconfig_struct{ - char board_name[COMEDI_NAMELEN]; - int options[COMEDI_NDEVCONFOPTS]; -}; - -struct comedi_bufconfig_struct{ - unsigned int subdevice; - unsigned int flags; - - unsigned int maximum_size; - unsigned int size; - - unsigned int unused[4]; -}; - -struct comedi_bufinfo_struct{ - unsigned int subdevice; - unsigned int bytes_read; - - unsigned int buf_write_ptr; - unsigned int buf_read_ptr; - unsigned int buf_write_count; - unsigned int buf_read_count; - - unsigned int bytes_written; - - unsigned int unused[4]; -}; + typedef struct comedi_trig_struct comedi_trig; + typedef struct comedi_cmd_struct comedi_cmd; + typedef struct comedi_insn_struct comedi_insn; + typedef struct comedi_insnlist_struct comedi_insnlist; + typedef struct comedi_chaninfo_struct comedi_chaninfo; + typedef struct comedi_subdinfo_struct comedi_subdinfo; + typedef struct comedi_devinfo_struct comedi_devinfo; + typedef struct comedi_devconfig_struct comedi_devconfig; + typedef struct comedi_rangeinfo_struct comedi_rangeinfo; + typedef struct comedi_krange_struct comedi_krange; + typedef struct comedi_bufconfig_struct comedi_bufconfig; + typedef struct comedi_bufinfo_struct comedi_bufinfo; + + struct comedi_trig_struct { + unsigned int subdev; /* subdevice */ + unsigned int mode; /* mode */ + unsigned int flags; + unsigned int n_chan; /* number of channels */ + unsigned int *chanlist; /* channel/range list */ + sampl_t *data; /* data list, size depends on subd flags */ + unsigned int n; /* number of scans */ + unsigned int trigsrc; + unsigned int trigvar; + unsigned int trigvar1; + unsigned int data_len; + unsigned int unused[3]; + }; + + struct comedi_insn_struct { + unsigned int insn; + unsigned int n; + lsampl_t *data; + unsigned int subdev; + unsigned int chanspec; + unsigned int unused[3]; + }; + + struct comedi_insnlist_struct { + unsigned int n_insns; + comedi_insn *insns; + }; + + struct comedi_cmd_struct { + unsigned int subdev; + unsigned int flags; + + unsigned int start_src; + unsigned int start_arg; + + unsigned int scan_begin_src; + unsigned int scan_begin_arg; + + unsigned int convert_src; + unsigned int convert_arg; + + unsigned int scan_end_src; + unsigned int scan_end_arg; + + unsigned int stop_src; + unsigned int stop_arg; + + unsigned int *chanlist; /* channel/range list */ + unsigned int chanlist_len; + + sampl_t *data; /* data list, size depends on subd flags */ + unsigned int data_len; + }; + + struct comedi_chaninfo_struct { + unsigned int subdev; + lsampl_t *maxdata_list; + unsigned int *flaglist; + unsigned int *rangelist; + unsigned int unused[4]; + }; + + struct comedi_rangeinfo_struct { + unsigned int range_type; + void *range_ptr; + }; + + struct comedi_krange_struct { + int min; /* fixed point, multiply by 1e-6 */ + int max; /* fixed point, multiply by 1e-6 */ + unsigned int flags; + }; + + struct comedi_subdinfo_struct { + unsigned int type; + unsigned int n_chan; + unsigned int subd_flags; + unsigned int timer_type; + unsigned int len_chanlist; + lsampl_t maxdata; + unsigned int flags; /* channel flags */ + unsigned int range_type; /* lookup in kernel */ + unsigned int settling_time_0; + unsigned int unused[9]; + }; + + struct comedi_devinfo_struct { + unsigned int version_code; + unsigned int n_subdevs; + char driver_name[COMEDI_NAMELEN]; + char board_name[COMEDI_NAMELEN]; + int read_subdevice; + int write_subdevice; + int unused[30]; + }; + + struct comedi_devconfig_struct { + char board_name[COMEDI_NAMELEN]; + int options[COMEDI_NDEVCONFOPTS]; + }; + + struct comedi_bufconfig_struct { + unsigned int subdevice; + unsigned int flags; + + unsigned int maximum_size; + unsigned int size; + + unsigned int unused[4]; + }; + + struct comedi_bufinfo_struct { + unsigned int subdevice; + unsigned int bytes_read; + + unsigned int buf_write_ptr; + unsigned int buf_read_ptr; + unsigned int buf_write_count; + unsigned int buf_read_count; + + unsigned int bytes_written; + + unsigned int unused[4]; + }; /* range stuff */ @@ -480,249 +473,240 @@ struct comedi_bufinfo_struct{ */ -enum i8254_mode -{ - I8254_MODE0 = (0<<1), /* Interrupt on terminal count */ - I8254_MODE1 = (1<<1), /* Hardware retriggerable one-shot */ - I8254_MODE2 = (2<<1), /* Rate generator */ - I8254_MODE3 = (3<<1), /* Square wave mode */ - I8254_MODE4 = (4<<1), /* Software triggered strobe */ - I8254_MODE5 = (5<<1), /* Hardware triggered strobe (retriggerable) */ - I8254_BCD = 1, /* use binary-coded decimal instead of binary (pretty useless) */ - I8254_BINARY = 0 -}; - -static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel) -{ - if(pfi_channel < 10) - return 0x1 + pfi_channel; - else - return 0xb + pfi_channel; -} -static inline unsigned NI_USUAL_RTSI_SELECT(unsigned rtsi_channel) -{ - if(rtsi_channel < 7) - return 0xb + rtsi_channel; - else - return 0x1b; -} + enum i8254_mode { + I8254_MODE0 = (0 << 1), /* Interrupt on terminal count */ + I8254_MODE1 = (1 << 1), /* Hardware retriggerable one-shot */ + I8254_MODE2 = (2 << 1), /* Rate generator */ + I8254_MODE3 = (3 << 1), /* Square wave mode */ + I8254_MODE4 = (4 << 1), /* Software triggered strobe */ + I8254_MODE5 = (5 << 1), /* Hardware triggered strobe (retriggerable) */ + I8254_BCD = 1, /* use binary-coded decimal instead of binary (pretty useless) */ + I8254_BINARY = 0 + }; + + static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel) { + if (pfi_channel < 10) + return 0x1 + pfi_channel; + else + return 0xb + pfi_channel; + } static inline unsigned NI_USUAL_RTSI_SELECT(unsigned rtsi_channel) { + if (rtsi_channel < 7) + return 0xb + rtsi_channel; + else + return 0x1b; + } /* mode bits for NI general-purpose counters, set with INSN_CONFIG_SET_COUNTER_MODE */ #define NI_GPCT_COUNTING_MODE_SHIFT 16 #define NI_GPCT_INDEX_PHASE_BITSHIFT 20 #define NI_GPCT_COUNTING_DIRECTION_SHIFT 24 -enum ni_gpct_mode_bits -{ - NI_GPCT_GATE_ON_BOTH_EDGES_BIT = 0x4, - NI_GPCT_EDGE_GATE_MODE_MASK = 0x18, - NI_GPCT_EDGE_GATE_STARTS_STOPS_BITS = 0x0, - NI_GPCT_EDGE_GATE_STOPS_STARTS_BITS = 0x8, - NI_GPCT_EDGE_GATE_STARTS_BITS = 0x10, - NI_GPCT_EDGE_GATE_NO_STARTS_NO_STOPS_BITS = 0x18, - NI_GPCT_STOP_MODE_MASK = 0x60, - NI_GPCT_STOP_ON_GATE_BITS = 0x00, - NI_GPCT_STOP_ON_GATE_OR_TC_BITS = 0x20, - NI_GPCT_STOP_ON_GATE_OR_SECOND_TC_BITS = 0x40, - NI_GPCT_LOAD_B_SELECT_BIT = 0x80, - NI_GPCT_OUTPUT_MODE_MASK = 0x300, - NI_GPCT_OUTPUT_TC_PULSE_BITS = 0x100, - NI_GPCT_OUTPUT_TC_TOGGLE_BITS = 0x200, - NI_GPCT_OUTPUT_TC_OR_GATE_TOGGLE_BITS = 0x300, - NI_GPCT_HARDWARE_DISARM_MASK = 0xc00, - NI_GPCT_NO_HARDWARE_DISARM_BITS = 0x000, - NI_GPCT_DISARM_AT_TC_BITS = 0x400, - NI_GPCT_DISARM_AT_GATE_BITS = 0x800, - NI_GPCT_DISARM_AT_TC_OR_GATE_BITS = 0xc00, - NI_GPCT_LOADING_ON_TC_BIT = 0x1000, - NI_GPCT_LOADING_ON_GATE_BIT = 0x4000, - NI_GPCT_COUNTING_MODE_MASK = 0x7 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_NORMAL_BITS = 0x0 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_QUADRATURE_X1_BITS = 0x1 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_QUADRATURE_X2_BITS = 0x2 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_QUADRATURE_X4_BITS = 0x3 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_TWO_PULSE_BITS = 0x4 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_COUNTING_MODE_SYNC_SOURCE_BITS = 0x6 << NI_GPCT_COUNTING_MODE_SHIFT, - NI_GPCT_INDEX_PHASE_MASK = 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, - NI_GPCT_INDEX_PHASE_LOW_A_LOW_B_BITS = 0x0 << NI_GPCT_INDEX_PHASE_BITSHIFT, - NI_GPCT_INDEX_PHASE_LOW_A_HIGH_B_BITS = 0x1 << NI_GPCT_INDEX_PHASE_BITSHIFT, - NI_GPCT_INDEX_PHASE_HIGH_A_LOW_B_BITS = 0x2 << NI_GPCT_INDEX_PHASE_BITSHIFT, - NI_GPCT_INDEX_PHASE_HIGH_A_HIGH_B_BITS = 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, - NI_GPCT_INDEX_ENABLE_BIT = 0x400000, - NI_GPCT_COUNTING_DIRECTION_MASK = 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, - NI_GPCT_COUNTING_DIRECTION_DOWN_BITS = 0x00 << NI_GPCT_COUNTING_DIRECTION_SHIFT, - NI_GPCT_COUNTING_DIRECTION_UP_BITS = 0x1 << NI_GPCT_COUNTING_DIRECTION_SHIFT, - NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS = 0x2 << NI_GPCT_COUNTING_DIRECTION_SHIFT, - NI_GPCT_COUNTING_DIRECTION_HW_GATE_BITS = 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, - NI_GPCT_RELOAD_SOURCE_MASK = 0xc000000, - NI_GPCT_RELOAD_SOURCE_FIXED_BITS = 0x0, - NI_GPCT_RELOAD_SOURCE_SWITCHING_BITS = 0x4000000, - NI_GPCT_RELOAD_SOURCE_GATE_SELECT_BITS = 0x8000000, - NI_GPCT_OR_GATE_BIT = 0x10000000, - NI_GPCT_INVERT_OUTPUT_BIT = 0x20000000 -}; + enum ni_gpct_mode_bits { + NI_GPCT_GATE_ON_BOTH_EDGES_BIT = 0x4, + NI_GPCT_EDGE_GATE_MODE_MASK = 0x18, + NI_GPCT_EDGE_GATE_STARTS_STOPS_BITS = 0x0, + NI_GPCT_EDGE_GATE_STOPS_STARTS_BITS = 0x8, + NI_GPCT_EDGE_GATE_STARTS_BITS = 0x10, + NI_GPCT_EDGE_GATE_NO_STARTS_NO_STOPS_BITS = 0x18, + NI_GPCT_STOP_MODE_MASK = 0x60, + NI_GPCT_STOP_ON_GATE_BITS = 0x00, + NI_GPCT_STOP_ON_GATE_OR_TC_BITS = 0x20, + NI_GPCT_STOP_ON_GATE_OR_SECOND_TC_BITS = 0x40, + NI_GPCT_LOAD_B_SELECT_BIT = 0x80, + NI_GPCT_OUTPUT_MODE_MASK = 0x300, + NI_GPCT_OUTPUT_TC_PULSE_BITS = 0x100, + NI_GPCT_OUTPUT_TC_TOGGLE_BITS = 0x200, + NI_GPCT_OUTPUT_TC_OR_GATE_TOGGLE_BITS = 0x300, + NI_GPCT_HARDWARE_DISARM_MASK = 0xc00, + NI_GPCT_NO_HARDWARE_DISARM_BITS = 0x000, + NI_GPCT_DISARM_AT_TC_BITS = 0x400, + NI_GPCT_DISARM_AT_GATE_BITS = 0x800, + NI_GPCT_DISARM_AT_TC_OR_GATE_BITS = 0xc00, + NI_GPCT_LOADING_ON_TC_BIT = 0x1000, + NI_GPCT_LOADING_ON_GATE_BIT = 0x4000, + NI_GPCT_COUNTING_MODE_MASK = 0x7 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_NORMAL_BITS = + 0x0 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_QUADRATURE_X1_BITS = + 0x1 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_QUADRATURE_X2_BITS = + 0x2 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_QUADRATURE_X4_BITS = + 0x3 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_TWO_PULSE_BITS = + 0x4 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_COUNTING_MODE_SYNC_SOURCE_BITS = + 0x6 << NI_GPCT_COUNTING_MODE_SHIFT, + NI_GPCT_INDEX_PHASE_MASK = 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, + NI_GPCT_INDEX_PHASE_LOW_A_LOW_B_BITS = + 0x0 << NI_GPCT_INDEX_PHASE_BITSHIFT, + NI_GPCT_INDEX_PHASE_LOW_A_HIGH_B_BITS = + 0x1 << NI_GPCT_INDEX_PHASE_BITSHIFT, + NI_GPCT_INDEX_PHASE_HIGH_A_LOW_B_BITS = + 0x2 << NI_GPCT_INDEX_PHASE_BITSHIFT, + NI_GPCT_INDEX_PHASE_HIGH_A_HIGH_B_BITS = + 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, + NI_GPCT_INDEX_ENABLE_BIT = 0x400000, + NI_GPCT_COUNTING_DIRECTION_MASK = + 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, + NI_GPCT_COUNTING_DIRECTION_DOWN_BITS = + 0x00 << NI_GPCT_COUNTING_DIRECTION_SHIFT, + NI_GPCT_COUNTING_DIRECTION_UP_BITS = + 0x1 << NI_GPCT_COUNTING_DIRECTION_SHIFT, + NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS = + 0x2 << NI_GPCT_COUNTING_DIRECTION_SHIFT, + NI_GPCT_COUNTING_DIRECTION_HW_GATE_BITS = + 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, + NI_GPCT_RELOAD_SOURCE_MASK = 0xc000000, + NI_GPCT_RELOAD_SOURCE_FIXED_BITS = 0x0, + NI_GPCT_RELOAD_SOURCE_SWITCHING_BITS = 0x4000000, + NI_GPCT_RELOAD_SOURCE_GATE_SELECT_BITS = 0x8000000, + NI_GPCT_OR_GATE_BIT = 0x10000000, + NI_GPCT_INVERT_OUTPUT_BIT = 0x20000000 + }; /* Bits for setting a clock source with * INSN_CONFIG_SET_CLOCK_SRC when using NI general-purpose counters. */ -enum ni_gpct_clock_source_bits -{ - NI_GPCT_CLOCK_SRC_SELECT_MASK = 0x3f, - NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS = 0x0, - NI_GPCT_TIMEBASE_2_CLOCK_SRC_BITS = 0x1, - NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS = 0x2, - NI_GPCT_LOGIC_LOW_CLOCK_SRC_BITS = 0x3, - NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS = 0x4, - NI_GPCT_NEXT_TC_CLOCK_SRC_BITS = 0x5, - NI_GPCT_SOURCE_PIN_i_CLOCK_SRC_BITS = 0x6, /* NI 660x-specific */ - NI_GPCT_PXI10_CLOCK_SRC_BITS = 0x7, - NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS = 0x8, - NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS = 0x9, - NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK = 0x30000000, - NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS = 0x0, - NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS = 0x10000000, /* divide source by 2 */ - NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS = 0x20000000, /* divide source by 8 */ - NI_GPCT_INVERT_CLOCK_SRC_BIT = 0x80000000 -}; -static inline unsigned NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(unsigned n) /* NI 660x-specific */ -{ - return 0x10 + n; -} -static inline unsigned NI_GPCT_RTSI_CLOCK_SRC_BITS(unsigned n) -{ - return 0x18 + n; -} -static inline unsigned NI_GPCT_PFI_CLOCK_SRC_BITS(unsigned n) /* no pfi on NI 660x */ -{ - return 0x20 + n; -} + enum ni_gpct_clock_source_bits { + NI_GPCT_CLOCK_SRC_SELECT_MASK = 0x3f, + NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS = 0x0, + NI_GPCT_TIMEBASE_2_CLOCK_SRC_BITS = 0x1, + NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS = 0x2, + NI_GPCT_LOGIC_LOW_CLOCK_SRC_BITS = 0x3, + NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS = 0x4, + NI_GPCT_NEXT_TC_CLOCK_SRC_BITS = 0x5, + NI_GPCT_SOURCE_PIN_i_CLOCK_SRC_BITS = 0x6, /* NI 660x-specific */ + NI_GPCT_PXI10_CLOCK_SRC_BITS = 0x7, + NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS = 0x8, + NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS = 0x9, + NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK = 0x30000000, + NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS = 0x0, + NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS = 0x10000000, /* divide source by 2 */ + NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS = 0x20000000, /* divide source by 8 */ + NI_GPCT_INVERT_CLOCK_SRC_BIT = 0x80000000 + }; + static inline unsigned NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(unsigned n) { /* NI 660x-specific */ + return 0x10 + n; + } + static inline unsigned NI_GPCT_RTSI_CLOCK_SRC_BITS(unsigned n) { + return 0x18 + n; + } + static inline unsigned NI_GPCT_PFI_CLOCK_SRC_BITS(unsigned n) { /* no pfi on NI 660x */ + return 0x20 + n; + } /* Possibilities for setting a gate source with INSN_CONFIG_SET_GATE_SRC when using NI general-purpose counters. May be bitwise-or'd with CR_EDGE or CR_INVERT. */ -enum ni_gpct_gate_select -{ - /* m-series gates */ - NI_GPCT_TIMESTAMP_MUX_GATE_SELECT = 0x0, - NI_GPCT_AI_START2_GATE_SELECT = 0x12, - NI_GPCT_PXI_STAR_TRIGGER_GATE_SELECT = 0x13, - NI_GPCT_NEXT_OUT_GATE_SELECT = 0x14, - NI_GPCT_AI_START1_GATE_SELECT = 0x1c, - NI_GPCT_NEXT_SOURCE_GATE_SELECT = 0x1d, - NI_GPCT_ANALOG_TRIGGER_OUT_GATE_SELECT = 0x1e, - NI_GPCT_LOGIC_LOW_GATE_SELECT = 0x1f, - /* more gates for 660x */ - NI_GPCT_SOURCE_PIN_i_GATE_SELECT = 0x100, - NI_GPCT_GATE_PIN_i_GATE_SELECT = 0x101, - /* more gates for 660x "second gate" */ - NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT = 0x201, - NI_GPCT_SELECTED_GATE_GATE_SELECT = 0x21e, - /* m-series "second gate" sources are unknown, - we should add them here with an offset of 0x300 when known. */ - NI_GPCT_DISABLED_GATE_SELECT = 0x8000, -}; -static inline unsigned NI_GPCT_GATE_PIN_GATE_SELECT(unsigned n) -{ - return 0x102 + n; -} -static inline unsigned NI_GPCT_RTSI_GATE_SELECT(unsigned n) -{ - return NI_USUAL_RTSI_SELECT(n); -} -static inline unsigned NI_GPCT_PFI_GATE_SELECT(unsigned n) -{ - return NI_USUAL_PFI_SELECT(n); -} -static inline unsigned NI_GPCT_UP_DOWN_PIN_GATE_SELECT(unsigned n) -{ - return 0x202 + n; -} + enum ni_gpct_gate_select { + /* m-series gates */ + NI_GPCT_TIMESTAMP_MUX_GATE_SELECT = 0x0, + NI_GPCT_AI_START2_GATE_SELECT = 0x12, + NI_GPCT_PXI_STAR_TRIGGER_GATE_SELECT = 0x13, + NI_GPCT_NEXT_OUT_GATE_SELECT = 0x14, + NI_GPCT_AI_START1_GATE_SELECT = 0x1c, + NI_GPCT_NEXT_SOURCE_GATE_SELECT = 0x1d, + NI_GPCT_ANALOG_TRIGGER_OUT_GATE_SELECT = 0x1e, + NI_GPCT_LOGIC_LOW_GATE_SELECT = 0x1f, + /* more gates for 660x */ + NI_GPCT_SOURCE_PIN_i_GATE_SELECT = 0x100, + NI_GPCT_GATE_PIN_i_GATE_SELECT = 0x101, + /* more gates for 660x "second gate" */ + NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT = 0x201, + NI_GPCT_SELECTED_GATE_GATE_SELECT = 0x21e, + /* m-series "second gate" sources are unknown, + we should add them here with an offset of 0x300 when known. */ + NI_GPCT_DISABLED_GATE_SELECT = 0x8000, + }; + static inline unsigned NI_GPCT_GATE_PIN_GATE_SELECT(unsigned n) { + return 0x102 + n; + } + static inline unsigned NI_GPCT_RTSI_GATE_SELECT(unsigned n) { + return NI_USUAL_RTSI_SELECT(n); + } + static inline unsigned NI_GPCT_PFI_GATE_SELECT(unsigned n) { + return NI_USUAL_PFI_SELECT(n); + } + static inline unsigned NI_GPCT_UP_DOWN_PIN_GATE_SELECT(unsigned n) { + return 0x202 + n; + } /* Possibilities for setting a source with INSN_CONFIG_SET_OTHER_SRC when using NI general-purpose counters. */ -enum ni_gpct_other_index { - NI_GPCT_SOURCE_ENCODER_A, - NI_GPCT_SOURCE_ENCODER_B, - NI_GPCT_SOURCE_ENCODER_Z -}; -enum ni_gpct_other_select -{ - /* m-series gates */ - // Still unknown, probably only need NI_GPCT_PFI_OTHER_SELECT - NI_GPCT_DISABLED_OTHER_SELECT = 0x8000, -}; -static inline unsigned NI_GPCT_PFI_OTHER_SELECT(unsigned n) -{ - return NI_USUAL_PFI_SELECT(n); -} - + enum ni_gpct_other_index { + NI_GPCT_SOURCE_ENCODER_A, + NI_GPCT_SOURCE_ENCODER_B, + NI_GPCT_SOURCE_ENCODER_Z + }; + enum ni_gpct_other_select { + /* m-series gates */ + // Still unknown, probably only need NI_GPCT_PFI_OTHER_SELECT + NI_GPCT_DISABLED_OTHER_SELECT = 0x8000, + }; + static inline unsigned NI_GPCT_PFI_OTHER_SELECT(unsigned n) { + return NI_USUAL_PFI_SELECT(n); + } /* start sources for ni general-purpose counters for use with INSN_CONFIG_ARM */ -enum ni_gpct_arm_source -{ - NI_GPCT_ARM_IMMEDIATE = 0x0, - NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1, /* Start both the counter and the adjacent paired counter simultaneously */ - /* NI doesn't document bits for selecting hardware arm triggers. If - the NI_GPCT_ARM_UNKNOWN bit is set, we will pass the least significant - bits (3 bits for 660x or 5 bits for m-series) through to the hardware. - This will at least allow someone to figure out what the bits do later.*/ - NI_GPCT_ARM_UNKNOWN = 0x1000, -}; + enum ni_gpct_arm_source { + NI_GPCT_ARM_IMMEDIATE = 0x0, + NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1, /* Start both the counter and the adjacent paired counter simultaneously */ + /* NI doesn't document bits for selecting hardware arm triggers. If + the NI_GPCT_ARM_UNKNOWN bit is set, we will pass the least significant + bits (3 bits for 660x or 5 bits for m-series) through to the hardware. + This will at least allow someone to figure out what the bits do later. */ + NI_GPCT_ARM_UNKNOWN = 0x1000, + }; /* digital filtering options for ni 660x for use with INSN_CONFIG_FILTER. */ -enum ni_gpct_filter_select -{ - NI_GPCT_FILTER_OFF = 0x0, - NI_GPCT_FILTER_TIMEBASE_3_SYNC = 0x1, - NI_GPCT_FILTER_100x_TIMEBASE_1= 0x2, - NI_GPCT_FILTER_20x_TIMEBASE_1 = 0x3, - NI_GPCT_FILTER_10x_TIMEBASE_1 = 0x4, - NI_GPCT_FILTER_2x_TIMEBASE_1 = 0x5, - NI_GPCT_FILTER_2x_TIMEBASE_3 = 0x6 -}; + enum ni_gpct_filter_select { + NI_GPCT_FILTER_OFF = 0x0, + NI_GPCT_FILTER_TIMEBASE_3_SYNC = 0x1, + NI_GPCT_FILTER_100x_TIMEBASE_1 = 0x2, + NI_GPCT_FILTER_20x_TIMEBASE_1 = 0x3, + NI_GPCT_FILTER_10x_TIMEBASE_1 = 0x4, + NI_GPCT_FILTER_2x_TIMEBASE_1 = 0x5, + NI_GPCT_FILTER_2x_TIMEBASE_3 = 0x6 + }; /* PFI digital filtering options for ni m-series for use with INSN_CONFIG_FILTER. */ -enum ni_pfi_filter_select -{ - NI_PFI_FILTER_OFF = 0x0, - NI_PFI_FILTER_125ns = 0x1, - NI_PFI_FILTER_6425ns = 0x2, - NI_PFI_FILTER_2550us = 0x3 -}; + enum ni_pfi_filter_select { + NI_PFI_FILTER_OFF = 0x0, + NI_PFI_FILTER_125ns = 0x1, + NI_PFI_FILTER_6425ns = 0x2, + NI_PFI_FILTER_2550us = 0x3 + }; /* master clock sources for ni mio boards and INSN_CONFIG_SET_CLOCK_SRC */ -enum ni_mio_clock_source -{ - NI_MIO_INTERNAL_CLOCK = 0, - NI_MIO_RTSI_CLOCK = 1, /* doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK() */ - /* the NI_MIO_PLL_* sources are m-series only */ - NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2, - NI_MIO_PLL_PXI10_CLOCK = 3, - NI_MIO_PLL_RTSI0_CLOCK = 4 -}; -static inline unsigned NI_MIO_PLL_RTSI_CLOCK(unsigned rtsi_channel) -{ - return NI_MIO_PLL_RTSI0_CLOCK + rtsi_channel; -} + enum ni_mio_clock_source { + NI_MIO_INTERNAL_CLOCK = 0, + NI_MIO_RTSI_CLOCK = 1, /* doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK() */ + /* the NI_MIO_PLL_* sources are m-series only */ + NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2, + NI_MIO_PLL_PXI10_CLOCK = 3, + NI_MIO_PLL_RTSI0_CLOCK = 4 + }; + static inline unsigned NI_MIO_PLL_RTSI_CLOCK(unsigned rtsi_channel) { + return NI_MIO_PLL_RTSI0_CLOCK + rtsi_channel; + } /* Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING. The numbers assigned are not arbitrary, they correspond to the bits required to program the board. */ -enum ni_rtsi_routing -{ - NI_RTSI_OUTPUT_ADR_START1 = 0, - NI_RTSI_OUTPUT_ADR_START2 = 1, - NI_RTSI_OUTPUT_SCLKG = 2, - NI_RTSI_OUTPUT_DACUPDN = 3, - NI_RTSI_OUTPUT_DA_START1 = 4, - NI_RTSI_OUTPUT_G_SRC0 = 5, - NI_RTSI_OUTPUT_G_GATE0 = 6, - NI_RTSI_OUTPUT_RGOUT0 = 7, - NI_RTSI_OUTPUT_RTSI_BRD_0 = 8, - NI_RTSI_OUTPUT_RTSI_OSC = 12 /* pre-m-series always have RTSI clock on line 7 */ -}; -static inline unsigned NI_RTSI_OUTPUT_RTSI_BRD(unsigned n) -{ - return NI_RTSI_OUTPUT_RTSI_BRD_0 + n; -} + enum ni_rtsi_routing { + NI_RTSI_OUTPUT_ADR_START1 = 0, + NI_RTSI_OUTPUT_ADR_START2 = 1, + NI_RTSI_OUTPUT_SCLKG = 2, + NI_RTSI_OUTPUT_DACUPDN = 3, + NI_RTSI_OUTPUT_DA_START1 = 4, + NI_RTSI_OUTPUT_G_SRC0 = 5, + NI_RTSI_OUTPUT_G_GATE0 = 6, + NI_RTSI_OUTPUT_RGOUT0 = 7, + NI_RTSI_OUTPUT_RTSI_BRD_0 = 8, + NI_RTSI_OUTPUT_RTSI_OSC = 12 /* pre-m-series always have RTSI clock on line 7 */ + }; + static inline unsigned NI_RTSI_OUTPUT_RTSI_BRD(unsigned n) { + return NI_RTSI_OUTPUT_RTSI_BRD_0 + n; + } /* Signals which can be routed to an NI PFI pin on an m-series board with INSN_CONFIG_SET_ROUTING. These numbers are also returned @@ -730,37 +714,35 @@ static inline unsigned NI_RTSI_OUTPUT_RTSI_BRD(unsigned n) their routing cannot be changed. The numbers assigned are not arbitrary, they correspond to the bits required to program the board. */ -enum ni_pfi_routing -{ - NI_PFI_OUTPUT_PFI_DEFAULT = 0, - NI_PFI_OUTPUT_AI_START1 = 1, - NI_PFI_OUTPUT_AI_START2 = 2, - NI_PFI_OUTPUT_AI_CONVERT = 3, - NI_PFI_OUTPUT_G_SRC1 = 4, - NI_PFI_OUTPUT_G_GATE1 = 5, - NI_PFI_OUTPUT_AO_UPDATE_N = 6, - NI_PFI_OUTPUT_AO_START1 = 7, - NI_PFI_OUTPUT_AI_START_PULSE = 8, - NI_PFI_OUTPUT_G_SRC0 = 9, - NI_PFI_OUTPUT_G_GATE0 = 10, - NI_PFI_OUTPUT_EXT_STROBE = 11, - NI_PFI_OUTPUT_AI_EXT_MUX_CLK = 12, - NI_PFI_OUTPUT_GOUT0 = 13, - NI_PFI_OUTPUT_GOUT1 = 14, - NI_PFI_OUTPUT_FREQ_OUT = 15, - NI_PFI_OUTPUT_PFI_DO = 16, - NI_PFI_OUTPUT_I_ATRIG = 17, - NI_PFI_OUTPUT_RTSI0 = 18, - NI_PFI_OUTPUT_PXI_STAR_TRIGGER_IN = 26, - NI_PFI_OUTPUT_SCXI_TRIG1 = 27, - NI_PFI_OUTPUT_DIO_CHANGE_DETECT_RTSI = 28, - NI_PFI_OUTPUT_CDI_SAMPLE = 29, - NI_PFI_OUTPUT_CDO_UPDATE = 30 -}; -static inline unsigned NI_PFI_OUTPUT_RTSI(unsigned rtsi_channel) -{ - return NI_PFI_OUTPUT_RTSI0 + rtsi_channel; -} + enum ni_pfi_routing { + NI_PFI_OUTPUT_PFI_DEFAULT = 0, + NI_PFI_OUTPUT_AI_START1 = 1, + NI_PFI_OUTPUT_AI_START2 = 2, + NI_PFI_OUTPUT_AI_CONVERT = 3, + NI_PFI_OUTPUT_G_SRC1 = 4, + NI_PFI_OUTPUT_G_GATE1 = 5, + NI_PFI_OUTPUT_AO_UPDATE_N = 6, + NI_PFI_OUTPUT_AO_START1 = 7, + NI_PFI_OUTPUT_AI_START_PULSE = 8, + NI_PFI_OUTPUT_G_SRC0 = 9, + NI_PFI_OUTPUT_G_GATE0 = 10, + NI_PFI_OUTPUT_EXT_STROBE = 11, + NI_PFI_OUTPUT_AI_EXT_MUX_CLK = 12, + NI_PFI_OUTPUT_GOUT0 = 13, + NI_PFI_OUTPUT_GOUT1 = 14, + NI_PFI_OUTPUT_FREQ_OUT = 15, + NI_PFI_OUTPUT_PFI_DO = 16, + NI_PFI_OUTPUT_I_ATRIG = 17, + NI_PFI_OUTPUT_RTSI0 = 18, + NI_PFI_OUTPUT_PXI_STAR_TRIGGER_IN = 26, + NI_PFI_OUTPUT_SCXI_TRIG1 = 27, + NI_PFI_OUTPUT_DIO_CHANGE_DETECT_RTSI = 28, + NI_PFI_OUTPUT_CDI_SAMPLE = 29, + NI_PFI_OUTPUT_CDO_UPDATE = 30 + }; + static inline unsigned NI_PFI_OUTPUT_RTSI(unsigned rtsi_channel) { + return NI_PFI_OUTPUT_RTSI0 + rtsi_channel; + } /* Signals which can be routed to output on a NI PFI pin on a 660x board with INSN_CONFIG_SET_ROUTING. The numbers assigned are @@ -768,79 +750,69 @@ static inline unsigned NI_PFI_OUTPUT_RTSI(unsigned rtsi_channel) to program the board. Lines 0 to 7 can only be set to NI_660X_PFI_OUTPUT_DIO. Lines 32 to 39 can only be set to NI_660X_PFI_OUTPUT_COUNTER. */ -enum ni_660x_pfi_routing -{ - NI_660X_PFI_OUTPUT_COUNTER = 1, // counter - NI_660X_PFI_OUTPUT_DIO = 2, // static digital output -}; + enum ni_660x_pfi_routing { + NI_660X_PFI_OUTPUT_COUNTER = 1, // counter + NI_660X_PFI_OUTPUT_DIO = 2, // static digital output + }; /* NI External Trigger lines. These values are not arbitrary, but are related to the bits required to program the board (offset by 1 for historical reasons). */ -static inline unsigned NI_EXT_PFI(unsigned pfi_channel) -{ - return NI_USUAL_PFI_SELECT(pfi_channel) - 1; -} -static inline unsigned NI_EXT_RTSI(unsigned rtsi_channel) -{ - return NI_USUAL_RTSI_SELECT(rtsi_channel) - 1; -} + static inline unsigned NI_EXT_PFI(unsigned pfi_channel) { + return NI_USUAL_PFI_SELECT(pfi_channel) - 1; + } + static inline unsigned NI_EXT_RTSI(unsigned rtsi_channel) { + return NI_USUAL_RTSI_SELECT(rtsi_channel) - 1; + } /* status bits for INSN_CONFIG_GET_COUNTER_STATUS */ -enum comedi_counter_status_flags -{ - COMEDI_COUNTER_ARMED = 0x1, - COMEDI_COUNTER_COUNTING = 0x2, - COMEDI_COUNTER_TERMINAL_COUNT = 0x4, -}; + enum comedi_counter_status_flags { + COMEDI_COUNTER_ARMED = 0x1, + COMEDI_COUNTER_COUNTING = 0x2, + COMEDI_COUNTER_TERMINAL_COUNT = 0x4, + }; /* Clock sources for CDIO subdevice on NI m-series boards. Used as the scan_begin_arg for a comedi_command. These sources may also be bitwise-or'd with CR_INVERT to change polarity. */ -enum ni_m_series_cdio_scan_begin_src -{ - NI_CDIO_SCAN_BEGIN_SRC_GROUND = 0, - NI_CDIO_SCAN_BEGIN_SRC_AI_START = 18, - NI_CDIO_SCAN_BEGIN_SRC_AI_CONVERT = 19, - NI_CDIO_SCAN_BEGIN_SRC_PXI_STAR_TRIGGER = 20, - NI_CDIO_SCAN_BEGIN_SRC_G0_OUT = 28, - NI_CDIO_SCAN_BEGIN_SRC_G1_OUT = 29, - NI_CDIO_SCAN_BEGIN_SRC_ANALOG_TRIGGER = 30, - NI_CDIO_SCAN_BEGIN_SRC_AO_UPDATE = 31, - NI_CDIO_SCAN_BEGIN_SRC_FREQ_OUT = 32, - NI_CDIO_SCAN_BEGIN_SRC_DIO_CHANGE_DETECT_IRQ = 33 -}; -static inline unsigned NI_CDIO_SCAN_BEGIN_SRC_PFI(unsigned pfi_channel) -{ - return NI_USUAL_PFI_SELECT(pfi_channel); -} -static inline unsigned NI_CDIO_SCAN_BEGIN_SRC_RTSI(unsigned rtsi_channel) -{ - return NI_USUAL_RTSI_SELECT(rtsi_channel); -} + enum ni_m_series_cdio_scan_begin_src { + NI_CDIO_SCAN_BEGIN_SRC_GROUND = 0, + NI_CDIO_SCAN_BEGIN_SRC_AI_START = 18, + NI_CDIO_SCAN_BEGIN_SRC_AI_CONVERT = 19, + NI_CDIO_SCAN_BEGIN_SRC_PXI_STAR_TRIGGER = 20, + NI_CDIO_SCAN_BEGIN_SRC_G0_OUT = 28, + NI_CDIO_SCAN_BEGIN_SRC_G1_OUT = 29, + NI_CDIO_SCAN_BEGIN_SRC_ANALOG_TRIGGER = 30, + NI_CDIO_SCAN_BEGIN_SRC_AO_UPDATE = 31, + NI_CDIO_SCAN_BEGIN_SRC_FREQ_OUT = 32, + NI_CDIO_SCAN_BEGIN_SRC_DIO_CHANGE_DETECT_IRQ = 33 + }; + static inline unsigned NI_CDIO_SCAN_BEGIN_SRC_PFI(unsigned pfi_channel) { + return NI_USUAL_PFI_SELECT(pfi_channel); + } + static inline unsigned NI_CDIO_SCAN_BEGIN_SRC_RTSI(unsigned + rtsi_channel) { + return NI_USUAL_RTSI_SELECT(rtsi_channel); + } /* scan_begin_src for scan_begin_arg==TRIG_EXT with analog output command on NI boards. These scan begin sources can also be bitwise-or'd with CR_INVERT to change polarity. */ -static inline unsigned NI_AO_SCAN_BEGIN_SRC_PFI(unsigned pfi_channel) -{ - return NI_USUAL_PFI_SELECT(pfi_channel); -} -static inline unsigned NI_AO_SCAN_BEGIN_SRC_RTSI(unsigned rtsi_channel) -{ - return NI_USUAL_RTSI_SELECT(rtsi_channel); -} + static inline unsigned NI_AO_SCAN_BEGIN_SRC_PFI(unsigned pfi_channel) { + return NI_USUAL_PFI_SELECT(pfi_channel); + } + static inline unsigned NI_AO_SCAN_BEGIN_SRC_RTSI(unsigned rtsi_channel) { + return NI_USUAL_RTSI_SELECT(rtsi_channel); + } /* Bits for setting a clock source with * INSN_CONFIG_SET_CLOCK_SRC when using NI frequency output subdevice. */ -enum ni_freq_out_clock_source_bits -{ - NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC, // 10 MHz - NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC // 100 KHz -}; + enum ni_freq_out_clock_source_bits { + NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC, // 10 MHz + NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC // 100 KHz + }; #ifdef __cplusplus } #endif #endif /* _COMEDI_H */ - diff --git a/include/linux/comedi_rt.h b/include/linux/comedi_rt.h index 8fc06446..1e36abd5 100644 --- a/include/linux/comedi_rt.h +++ b/include/linux/comedi_rt.h @@ -57,16 +57,17 @@ #define rt_printk printk #endif -int comedi_request_irq(unsigned int irq,irqreturn_t (*handler)(int,void * - PT_REGS_ARG),unsigned long flags,const char *device, - comedi_device *dev_id); -void comedi_free_irq(unsigned int irq,comedi_device *dev_id); +int comedi_request_irq(unsigned int irq, irqreturn_t(*handler) (int, + void *PT_REGS_ARG), unsigned long flags, const char *device, + comedi_device * dev_id); +void comedi_free_irq(unsigned int irq, comedi_device * dev_id); void comedi_rt_init(void); void comedi_rt_cleanup(void); -int comedi_switch_to_rt(comedi_device *dev); -void comedi_switch_to_non_rt(comedi_device *dev); -void comedi_rt_pend_wakeup(wait_queue_head_t *q); -extern int rt_pend_call(void (*func)(int arg1, void * arg2), int arg1, void * arg2); +int comedi_switch_to_rt(comedi_device * dev); +void comedi_switch_to_non_rt(comedi_device * dev); +void comedi_rt_pend_wakeup(wait_queue_head_t * q); +extern int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1, + void *arg2); #else @@ -82,14 +83,13 @@ extern int rt_pend_call(void (*func)(int arg1, void * arg2), int arg1, void * ar #endif - /* Define a spin_lock_irqsave function that will work with rt or without. * Use inline functions instead of just macros to enforce some type checking. */ #define comedi_spin_lock_irqsave(lock_ptr, flags) \ (flags = __comedi_spin_lock_irqsave(lock_ptr)) -static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr) +static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t * lock_ptr) { unsigned long flags; @@ -112,7 +112,8 @@ static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr) return flags; } -static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr, unsigned long flags) +static inline void comedi_spin_unlock_irqrestore(spinlock_t * lock_ptr, + unsigned long flags) { #if defined(CONFIG_COMEDI_RTAI) @@ -133,7 +134,7 @@ static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr, unsigned } /* define a RT safe udelay */ -static inline void comedi_udelay( unsigned int usec ) +static inline void comedi_udelay(unsigned int usec) { #if defined(CONFIG_COMEDI_RTAI) static const int nanosec_per_usec = 1000; @@ -142,7 +143,7 @@ static inline void comedi_udelay( unsigned int usec ) static const int nanosec_per_usec = 1000; rtl_delay(usec * nanosec_per_usec); #else - udelay( usec ); + udelay(usec); #endif } diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index fe885f60..500d11d3 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -46,7 +46,6 @@ #include - #define DPRINTK(format, args...) do{ \ if(comedi_debug)printk("comedi: " format , ## args ); \ } while(0) @@ -87,22 +86,20 @@ #define PCI_VENDOR_ID_CONTEC 0x1221 #define PCI_VENDOR_ID_MEILHAUS 0x1402 - typedef struct comedi_device_struct comedi_device; typedef struct comedi_subdevice_struct comedi_subdevice; typedef struct comedi_async_struct comedi_async; typedef struct comedi_driver_struct comedi_driver; typedef struct comedi_lrange_struct comedi_lrange; - -struct comedi_subdevice_struct{ +struct comedi_subdevice_struct { comedi_device *device; int type; int n_chan; volatile int subdev_flags; - int len_chanlist; /* maximum length of channel/gain list */ + int len_chanlist; /* maximum length of channel/gain list */ - void *private; + void *private; comedi_async *async; @@ -113,7 +110,7 @@ struct comedi_subdevice_struct{ int io_bits; - lsampl_t maxdata; /* if maxdata==0, use list */ + lsampl_t maxdata; /* if maxdata==0, use list */ const lsampl_t *maxdata_list; /* list is channel specific */ unsigned int flags; @@ -122,27 +119,32 @@ struct comedi_subdevice_struct{ unsigned int settling_time_0; const comedi_lrange *range_table; - const comedi_lrange * const *range_table_list; - - unsigned int *chanlist; /* driver-owned chanlist (not used) */ - - int (*insn_read)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - int (*insn_write)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - int (*insn_bits)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - int (*insn_config)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *); - - int (*do_cmd)(comedi_device *,comedi_subdevice *); - int (*do_cmdtest)(comedi_device *,comedi_subdevice *,comedi_cmd *); - int (*poll)(comedi_device *,comedi_subdevice *); - int (*cancel)(comedi_device *,comedi_subdevice *); + const comedi_lrange *const *range_table_list; + + unsigned int *chanlist; /* driver-owned chanlist (not used) */ + + int (*insn_read) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + int (*insn_write) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + int (*insn_bits) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + int (*insn_config) (comedi_device *, comedi_subdevice *, comedi_insn *, + lsampl_t *); + + int (*do_cmd) (comedi_device *, comedi_subdevice *); + int (*do_cmdtest) (comedi_device *, comedi_subdevice *, comedi_cmd *); + int (*poll) (comedi_device *, comedi_subdevice *); + int (*cancel) (comedi_device *, comedi_subdevice *); //int (*do_lock)(comedi_device *,comedi_subdevice *); //int (*do_unlock)(comedi_device *,comedi_subdevice *); /* called when the buffer changes */ - int (*buf_change)(comedi_device *dev,comedi_subdevice *s,unsigned long new_size); + int (*buf_change) (comedi_device * dev, comedi_subdevice * s, + unsigned long new_size); - void (*munge)( comedi_device *dev, comedi_subdevice *s, void *data, - unsigned int num_bytes, unsigned int start_chan_index ); + void (*munge) (comedi_device * dev, comedi_subdevice * s, void *data, + unsigned int num_bytes, unsigned int start_chan_index); enum dma_data_direction async_dma_dir; unsigned int state; @@ -150,32 +152,31 @@ struct comedi_subdevice_struct{ struct class_device *class_dev; }; -struct comedi_buf_page -{ +struct comedi_buf_page { void *virt_addr; dma_addr_t dma_addr; }; -struct comedi_async_struct{ +struct comedi_async_struct { comedi_subdevice *subdevice; - void *prealloc_buf; /* pre-allocated buffer */ - unsigned int prealloc_bufsz; /* buffer size, in bytes */ - struct comedi_buf_page *buf_page_list; /* virtual and dma address of each page */ + void *prealloc_buf; /* pre-allocated buffer */ + unsigned int prealloc_bufsz; /* buffer size, in bytes */ + struct comedi_buf_page *buf_page_list; /* virtual and dma address of each page */ unsigned n_buf_pages; /* num elements in buf_page_list */ - unsigned int max_bufsize; /* maximum buffer size, bytes */ - unsigned int mmap_count; /* current number of mmaps of prealloc_buf */ + unsigned int max_bufsize; /* maximum buffer size, bytes */ + unsigned int mmap_count; /* current number of mmaps of prealloc_buf */ unsigned int buf_write_count; /* byte count for writer (write completed) */ unsigned int buf_write_alloc_count; /* byte count for writer (allocated for writing) */ - unsigned int buf_read_count; /* byte count for reader (read completed)*/ - unsigned int buf_read_alloc_count; /* byte count for reader (allocated for reading)*/ + unsigned int buf_read_count; /* byte count for reader (read completed) */ + unsigned int buf_read_alloc_count; /* byte count for reader (allocated for reading) */ unsigned int buf_write_ptr; /* buffer marker for writer */ unsigned int buf_read_ptr; /* buffer marker for reader */ - unsigned int cur_chan; /* useless channel marker for interrupt */ + unsigned int cur_chan; /* useless channel marker for interrupt */ /* number of bytes that have been received for current scan */ unsigned int scan_progress; /* keeps track of where we are in chanlist as for munging */ @@ -185,7 +186,7 @@ struct comedi_async_struct{ /* buffer marker for munging */ unsigned int munge_ptr; - unsigned int events; /* events that have occurred */ + unsigned int events; /* events that have occurred */ comedi_cmd cmd; @@ -193,28 +194,29 @@ struct comedi_async_struct{ // callback stuff unsigned int cb_mask; - int (*cb_func)(unsigned int flags,void *); + int (*cb_func) (unsigned int flags, void *); void *cb_arg; - int (*inttrig)(comedi_device *dev,comedi_subdevice *s,unsigned int x); + int (*inttrig) (comedi_device * dev, comedi_subdevice * s, + unsigned int x); }; -struct comedi_driver_struct{ +struct comedi_driver_struct { struct comedi_driver_struct *next; const char *driver_name; struct module *module; - int (*attach)(comedi_device *,comedi_devconfig *); - int (*detach)(comedi_device *); + int (*attach) (comedi_device *, comedi_devconfig *); + int (*detach) (comedi_device *); /* number of elements in board_name and board_id arrays */ unsigned int num_names; - const char * const *board_name; + const char *const *board_name; /* offset in bytes from one board name pointer to the next */ int offset; }; -struct comedi_device_struct{ +struct comedi_device_struct { int use_count; comedi_driver *driver; void *private; @@ -222,11 +224,11 @@ struct comedi_device_struct{ struct class_device *class_dev; unsigned minor; /* hw_dev is passed to dma_alloc_coherent when allocating async buffers for subdevices - that have async_dma_dir set to something other than DMA_NONE */ + that have async_dma_dir set to something other than DMA_NONE */ struct device *hw_dev; const char *board_name; - const void * board_ptr; + const void *board_ptr; int attached; int rt; spinlock_t spinlock; @@ -244,12 +246,11 @@ struct comedi_device_struct{ struct fasync_struct *async_queue; - void (*open)(comedi_device *dev); - void (*close)(comedi_device *dev); + void (*open) (comedi_device * dev); + void (*close) (comedi_device * dev); }; -struct comedi_inode_private -{ +struct comedi_inode_private { comedi_device *device; comedi_subdevice *subdevice; }; @@ -267,14 +268,13 @@ static const int comedi_debug = 0; * function prototypes */ -void comedi_event(comedi_device *dev, comedi_subdevice *s); -void comedi_error(const comedi_device *dev,const char *s); +void comedi_event(comedi_device * dev, comedi_subdevice * s); +void comedi_error(const comedi_device * dev, const char *s); /* we can expand the number of bits used to encode devices/subdevices into the minor number soon, after more distros support > 8 bit minor numbers (like after Debian Etch gets released) */ -enum comedi_minor_bits -{ +enum comedi_minor_bits { COMEDI_DEVICE_MINOR_MASK = 0xf, COMEDI_SUBDEVICE_MINOR_MASK = 0xf0 }; @@ -282,63 +282,75 @@ static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; static const unsigned COMEDI_NUM_MINORS = 0x100; -static inline comedi_device * comedi_get_device_by_minor(unsigned minor) +static inline comedi_device *comedi_get_device_by_minor(unsigned minor) { unsigned device_index; - if(minor >= COMEDI_NUM_MINORS) return NULL; + if (minor >= COMEDI_NUM_MINORS) + return NULL; device_index = minor & COMEDI_DEVICE_MINOR_MASK; - if(device_index >= COMEDI_NDEVICES) return NULL; + if (device_index >= COMEDI_NDEVICES) + return NULL; return comedi_devices + device_index; } -static inline comedi_subdevice * comedi_get_subdevice_by_minor(unsigned minor) +static inline comedi_subdevice *comedi_get_subdevice_by_minor(unsigned minor) { unsigned subdevice_index; - comedi_device * dev; + comedi_device *dev; - if((minor & COMEDI_SUBDEVICE_MINOR_MASK) == 0) return NULL; + if ((minor & COMEDI_SUBDEVICE_MINOR_MASK) == 0) + return NULL; dev = comedi_get_device_by_minor(minor); - if(dev == NULL) return NULL; - subdevice_index = ((minor & COMEDI_SUBDEVICE_MINOR_MASK) >> COMEDI_SUBDEVICE_MINOR_SHIFT) - COMEDI_SUBDEVICE_MINOR_OFFSET; - if(subdevice_index >= dev->n_subdevices) return NULL; + if (dev == NULL) + return NULL; + subdevice_index = + ((minor & COMEDI_SUBDEVICE_MINOR_MASK) >> + COMEDI_SUBDEVICE_MINOR_SHIFT) - COMEDI_SUBDEVICE_MINOR_OFFSET; + if (subdevice_index >= dev->n_subdevices) + return NULL; return dev->subdevices + subdevice_index; } -static inline comedi_subdevice* comedi_get_read_subdevice(comedi_device *dev, unsigned minor) +static inline comedi_subdevice *comedi_get_read_subdevice(comedi_device * dev, + unsigned minor) { comedi_subdevice *read_subdev = comedi_get_subdevice_by_minor(minor); - if(read_subdev == NULL) - { + if (read_subdev == NULL) { read_subdev = dev->read_subdev; } - if(read_subdev == NULL || read_subdev->async == NULL || (read_subdev->subdev_flags & SDF_CMD_READ) == 0) + if (read_subdev == NULL || read_subdev->async == NULL + || (read_subdev->subdev_flags & SDF_CMD_READ) == 0) return NULL; return read_subdev; } -static inline comedi_subdevice* comedi_get_write_subdevice(comedi_device *dev, unsigned minor) +static inline comedi_subdevice *comedi_get_write_subdevice(comedi_device * dev, + unsigned minor) { comedi_subdevice *write_subdev = comedi_get_subdevice_by_minor(minor); - if(write_subdev == NULL) - { + if (write_subdev == NULL) { write_subdev = dev->write_subdev; } - if(write_subdev == NULL || write_subdev->async == NULL || (write_subdev->subdev_flags & SDF_CMD_WRITE) == 0) + if (write_subdev == NULL || write_subdev->async == NULL + || (write_subdev->subdev_flags & SDF_CMD_WRITE) == 0) return NULL; return write_subdev; } -static inline unsigned comedi_construct_minor_for_subdevice(comedi_device *dev, unsigned subdevice_index) +static inline unsigned comedi_construct_minor_for_subdevice(comedi_device * dev, + unsigned subdevice_index) { unsigned minor = 0; minor |= dev->minor & COMEDI_DEVICE_MINOR_MASK; - minor |= ((subdevice_index + COMEDI_SUBDEVICE_MINOR_OFFSET) << COMEDI_SUBDEVICE_MINOR_SHIFT) & COMEDI_SUBDEVICE_MINOR_MASK; + minor |= ((subdevice_index + + COMEDI_SUBDEVICE_MINOR_OFFSET) << + COMEDI_SUBDEVICE_MINOR_SHIFT) & COMEDI_SUBDEVICE_MINOR_MASK; BUG_ON(minor >= COMEDI_NUM_MINORS); return minor; } -int comedi_device_detach(comedi_device *dev); -int comedi_device_attach(comedi_device *dev,comedi_devconfig *it); +int comedi_device_detach(comedi_device * dev); +int comedi_device_attach(comedi_device * dev, comedi_devconfig * it); int comedi_driver_register(comedi_driver *); int comedi_driver_unregister(comedi_driver *); @@ -350,20 +362,23 @@ void cleanup_polling(void); void start_polling(comedi_device *); void stop_polling(comedi_device *); -int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, unsigned long +int comedi_buf_alloc(comedi_device * dev, comedi_subdevice * s, unsigned long new_size); #ifdef CONFIG_PROC_FS void comedi_proc_init(void); void comedi_proc_cleanup(void); #else -static inline void comedi_proc_init(void) {} -static inline void comedi_proc_cleanup(void) {} +static inline void comedi_proc_init(void) +{ +} +static inline void comedi_proc_cleanup(void) +{ +} #endif /* subdevice runflags */ -enum subdevice_runflags -{ +enum subdevice_runflags { SRF_USER = 0x00000001, SRF_RT = 0x00000002, /* indicates an COMEDI_CB_ERROR event has occurred since the last command was started */ @@ -375,14 +390,14 @@ enum subdevice_runflags various internal comedi functions */ -int do_rangeinfo_ioctl(comedi_device *dev,comedi_rangeinfo *arg); -int check_chanlist(comedi_subdevice *s,int n,unsigned int *chanlist); -void comedi_set_subdevice_runflags(comedi_subdevice *s, unsigned mask, unsigned bits); -unsigned comedi_get_subdevice_runflags(comedi_subdevice *s); +int do_rangeinfo_ioctl(comedi_device * dev, comedi_rangeinfo * arg); +int check_chanlist(comedi_subdevice * s, int n, unsigned int *chanlist); +void comedi_set_subdevice_runflags(comedi_subdevice * s, unsigned mask, + unsigned bits); +unsigned comedi_get_subdevice_runflags(comedi_subdevice * s); /* range stuff */ - #define RANGE(a,b) {(a)*1e6,(b)*1e6,0} #define RANGE_ext(a,b) {(a)*1e6,(b)*1e6,RF_EXTERNAL} #define RANGE_mA(a,b) {(a)*1e6,(b)*1e6,UNIT_mA} @@ -405,25 +420,24 @@ extern const comedi_lrange range_unknown; #define GCC_ZERO_LENGTH_ARRAY 0 #endif -struct comedi_lrange_struct{ +struct comedi_lrange_struct { int length; - comedi_krange range[ GCC_ZERO_LENGTH_ARRAY ]; + comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; }; - - /* some silly little inline functions */ -static inline int alloc_subdevices(comedi_device *dev, unsigned int num_subdevices) +static inline int alloc_subdevices(comedi_device * dev, + unsigned int num_subdevices) { unsigned i; dev->n_subdevices = num_subdevices; - dev->subdevices = kcalloc(num_subdevices,sizeof(comedi_subdevice),GFP_KERNEL); - if(!dev->subdevices) + dev->subdevices = + kcalloc(num_subdevices, sizeof(comedi_subdevice), GFP_KERNEL); + if (!dev->subdevices) return -ENOMEM; - for(i = 0; i < num_subdevices; ++i) - { + for (i = 0; i < num_subdevices; ++i) { dev->subdevices[i].device = dev; dev->subdevices[i].async_dma_dir = DMA_NONE; spin_lock_init(&dev->subdevices[i].runflags_lock); @@ -431,72 +445,70 @@ static inline int alloc_subdevices(comedi_device *dev, unsigned int num_subdevic return 0; } -static inline int alloc_private(comedi_device *dev,int size) +static inline int alloc_private(comedi_device * dev, int size) { - dev->private=kzalloc(size,GFP_KERNEL); - if(!dev->private) + dev->private = kzalloc(size, GFP_KERNEL); + if (!dev->private) return -ENOMEM; return 0; } -static inline unsigned int bytes_per_sample( const comedi_subdevice *subd ) +static inline unsigned int bytes_per_sample(const comedi_subdevice * subd) { - if( subd->subdev_flags & SDF_LSAMPL ) - return sizeof( lsampl_t ); + if (subd->subdev_flags & SDF_LSAMPL) + return sizeof(lsampl_t); else - return sizeof( sampl_t ); + return sizeof(sampl_t); } /* must be used in attach to set dev->hw_dev if you wish to dma directly into comedi's buffer */ -static inline void comedi_set_hw_dev(comedi_device *dev, struct device *hw_dev) +static inline void comedi_set_hw_dev(comedi_device * dev, struct device *hw_dev) { - if(dev->hw_dev) - { + if (dev->hw_dev) { put_device(dev->hw_dev); } dev->hw_dev = hw_dev; - if(dev->hw_dev) - { + if (dev->hw_dev) { dev->hw_dev = get_device(dev->hw_dev); BUG_ON(dev->hw_dev == NULL); } } -int comedi_buf_put(comedi_async *async, sampl_t x); -int comedi_buf_get(comedi_async *async, sampl_t *x); - -unsigned int comedi_buf_write_n_available(comedi_async *async); -unsigned int comedi_buf_write_alloc(comedi_async *async, unsigned int nbytes); -unsigned int comedi_buf_write_alloc_strict(comedi_async *async, unsigned int nbytes); -unsigned comedi_buf_write_free(comedi_async *async, unsigned int nbytes); -unsigned comedi_buf_read_alloc(comedi_async *async, unsigned nbytes); -unsigned comedi_buf_read_free(comedi_async *async, unsigned int nbytes); -unsigned int comedi_buf_read_n_available(comedi_async *async); -void comedi_buf_memcpy_to( comedi_async *async, unsigned int offset, const void *source, - unsigned int num_bytes ); -void comedi_buf_memcpy_from( comedi_async *async, unsigned int offset, void *destination, - unsigned int num_bytes ); -static inline unsigned comedi_buf_write_n_allocated(comedi_async *async) +int comedi_buf_put(comedi_async * async, sampl_t x); +int comedi_buf_get(comedi_async * async, sampl_t * x); + +unsigned int comedi_buf_write_n_available(comedi_async * async); +unsigned int comedi_buf_write_alloc(comedi_async * async, unsigned int nbytes); +unsigned int comedi_buf_write_alloc_strict(comedi_async * async, + unsigned int nbytes); +unsigned comedi_buf_write_free(comedi_async * async, unsigned int nbytes); +unsigned comedi_buf_read_alloc(comedi_async * async, unsigned nbytes); +unsigned comedi_buf_read_free(comedi_async * async, unsigned int nbytes); +unsigned int comedi_buf_read_n_available(comedi_async * async); +void comedi_buf_memcpy_to(comedi_async * async, unsigned int offset, + const void *source, unsigned int num_bytes); +void comedi_buf_memcpy_from(comedi_async * async, unsigned int offset, + void *destination, unsigned int num_bytes); +static inline unsigned comedi_buf_write_n_allocated(comedi_async * async) { return async->buf_write_alloc_count - async->buf_write_count; } -static inline unsigned comedi_buf_read_n_allocated(comedi_async *async) +static inline unsigned comedi_buf_read_n_allocated(comedi_async * async) { return async->buf_read_alloc_count - async->buf_read_count; } -void comedi_reset_async_buf(comedi_async *async); +void comedi_reset_async_buf(comedi_async * async); -static inline void* comedi_aux_data(int options[], int n) +static inline void *comedi_aux_data(int options[], int n) { unsigned long address; unsigned long addressLow; int bit_shift; - if(sizeof(int) >= sizeof(void*)) + if (sizeof(int) >= sizeof(void *)) address = options[COMEDI_DEVCONF_AUX_DATA_LO]; - else - { + else { address = options[COMEDI_DEVCONF_AUX_DATA_HI]; bit_shift = sizeof(int) * 8; address <<= bit_shift; @@ -504,22 +516,18 @@ static inline void* comedi_aux_data(int options[], int n) addressLow &= (1UL << bit_shift) - 1; address |= addressLow; } - if(n >= 1) + if (n >= 1) address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; - if(n >= 2) + if (n >= 2) address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; - if(n >= 3) + if (n >= 3) address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; BUG_ON(n > 3); - return (void*) address; + return (void *)address; } + //#ifdef CONFIG_COMEDI_RT #include //#endif - #endif /* _COMEDIDEV_H */ - - - - diff --git a/include/linux/comedilib.h b/include/linux/comedilib.h index f7167dd8..e3813895 100644 --- a/include/linux/comedilib.h +++ b/include/linux/comedilib.h @@ -21,7 +21,6 @@ */ - #ifndef _LINUX_COMEDILIB_H #define _LINUX_COMEDILIB_H @@ -42,13 +41,13 @@ typedef void comedi_t; /* these functions may not be called at real-time priority */ comedi_t *comedi_open(const char *path); -int comedi_close(comedi_t *dev); +int comedi_close(comedi_t * dev); /* these functions may be called at any priority, but may fail at real-time priority */ -int comedi_lock(comedi_t *dev,unsigned int subdev); -int comedi_unlock(comedi_t *dev,unsigned int subdev); +int comedi_lock(comedi_t * dev, unsigned int subdev); +int comedi_unlock(comedi_t * dev, unsigned int subdev); /* these functions may be called at any priority, but you must hold the lock for the subdevice */ @@ -57,71 +56,68 @@ int comedi_loglevel(int loglevel); void comedi_perror(const char *s); char *comedi_strerror(int errnum); int comedi_errno(void); -int comedi_fileno(comedi_t *dev); - -int comedi_cancel(comedi_t *dev,unsigned int subdev); -int comedi_register_callback(comedi_t *dev,unsigned int subdev, - unsigned int mask,int (*cb)(unsigned int,void *),void *arg); - -int comedi_command(comedi_t *dev,comedi_cmd *cmd); -int comedi_command_test(comedi_t *dev,comedi_cmd *cmd); -int comedi_trigger(comedi_t *dev,unsigned int subdev,comedi_trig *it); -int __comedi_trigger(comedi_t *dev,unsigned int subdev,comedi_trig *it); -int comedi_data_write(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t data); -int comedi_data_read(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data); -int comedi_data_read_hint(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref); -int comedi_data_read_delayed(comedi_t *dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data,unsigned int nano_sec); -int comedi_dio_config(comedi_t *dev,unsigned int subdev,unsigned int chan, +int comedi_fileno(comedi_t * dev); + +int comedi_cancel(comedi_t * dev, unsigned int subdev); +int comedi_register_callback(comedi_t * dev, unsigned int subdev, + unsigned int mask, int (*cb) (unsigned int, void *), void *arg); + +int comedi_command(comedi_t * dev, comedi_cmd * cmd); +int comedi_command_test(comedi_t * dev, comedi_cmd * cmd); +int comedi_trigger(comedi_t * dev, unsigned int subdev, comedi_trig * it); +int __comedi_trigger(comedi_t * dev, unsigned int subdev, comedi_trig * it); +int comedi_data_write(comedi_t * dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t data); +int comedi_data_read(comedi_t * dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t * data); +int comedi_data_read_hint(comedi_t * dev, unsigned int subdev, + unsigned int chan, unsigned int range, unsigned int aref); +int comedi_data_read_delayed(comedi_t * dev, unsigned int subdev, + unsigned int chan, unsigned int range, unsigned int aref, + lsampl_t * data, unsigned int nano_sec); +int comedi_dio_config(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int io); -int comedi_dio_read(comedi_t *dev,unsigned int subdev,unsigned int chan, +int comedi_dio_read(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int *val); -int comedi_dio_write(comedi_t *dev,unsigned int subdev,unsigned int chan, +int comedi_dio_write(comedi_t * dev, unsigned int subdev, unsigned int chan, unsigned int val); -int comedi_dio_bitfield(comedi_t *dev,unsigned int subdev,unsigned int mask, +int comedi_dio_bitfield(comedi_t * dev, unsigned int subdev, unsigned int mask, unsigned int *bits); -int comedi_get_n_subdevices(comedi_t *dev); -int comedi_get_version_code(comedi_t *dev); -const char *comedi_get_driver_name(comedi_t *dev); -const char *comedi_get_board_name(comedi_t *dev); -int comedi_get_subdevice_type(comedi_t *dev,unsigned int subdevice); -int comedi_find_subdevice_by_type(comedi_t *dev,int type,unsigned int subd); -int comedi_get_n_channels(comedi_t *dev,unsigned int subdevice); -lsampl_t comedi_get_maxdata(comedi_t *dev,unsigned int subdevice,unsigned +int comedi_get_n_subdevices(comedi_t * dev); +int comedi_get_version_code(comedi_t * dev); +const char *comedi_get_driver_name(comedi_t * dev); +const char *comedi_get_board_name(comedi_t * dev); +int comedi_get_subdevice_type(comedi_t * dev, unsigned int subdevice); +int comedi_find_subdevice_by_type(comedi_t * dev, int type, unsigned int subd); +int comedi_get_n_channels(comedi_t * dev, unsigned int subdevice); +lsampl_t comedi_get_maxdata(comedi_t * dev, unsigned int subdevice, unsigned int chan); -int comedi_get_n_ranges(comedi_t *dev,unsigned int subdevice,unsigned int +int comedi_get_n_ranges(comedi_t * dev, unsigned int subdevice, unsigned int chan); -int comedi_do_insn(comedi_t *dev,comedi_insn *insn); -int comedi_poll(comedi_t *dev, unsigned int subdev); - +int comedi_do_insn(comedi_t * dev, comedi_insn * insn); +int comedi_poll(comedi_t * dev, unsigned int subdev); /* DEPRECATED functions */ -int comedi_get_rangetype(comedi_t *dev,unsigned int subdevice,unsigned int chan); - +int comedi_get_rangetype(comedi_t * dev, unsigned int subdevice, + unsigned int chan); /* ALPHA functions */ -unsigned int comedi_get_subdevice_flags(comedi_t *dev,unsigned int - subdevice); -int comedi_get_len_chanlist(comedi_t *dev,unsigned int subdevice); -int comedi_get_krange(comedi_t *dev,unsigned int subdevice,unsigned int - chan, unsigned int range, comedi_krange *krange); -unsigned int comedi_get_buf_head_pos(comedi_t *dev,unsigned int - subdevice); -int comedi_set_user_int_count(comedi_t *dev,unsigned int subdevice, +unsigned int comedi_get_subdevice_flags(comedi_t * dev, unsigned int subdevice); +int comedi_get_len_chanlist(comedi_t * dev, unsigned int subdevice); +int comedi_get_krange(comedi_t * dev, unsigned int subdevice, unsigned int + chan, unsigned int range, comedi_krange * krange); +unsigned int comedi_get_buf_head_pos(comedi_t * dev, unsigned int subdevice); +int comedi_set_user_int_count(comedi_t * dev, unsigned int subdevice, unsigned int buf_user_count); -int comedi_map(comedi_t *dev, unsigned int subdev, void *ptr); -int comedi_unmap(comedi_t *dev, unsigned int subdev); -int comedi_get_buffer_size(comedi_t *dev,unsigned int subdev); -int comedi_mark_buffer_read( comedi_t *dev, unsigned int subdevice, - unsigned int num_bytes ); -int comedi_mark_buffer_written( comedi_t *d, unsigned int subdevice, +int comedi_map(comedi_t * dev, unsigned int subdev, void *ptr); +int comedi_unmap(comedi_t * dev, unsigned int subdev); +int comedi_get_buffer_size(comedi_t * dev, unsigned int subdev); +int comedi_mark_buffer_read(comedi_t * dev, unsigned int subdevice, unsigned int num_bytes); -int comedi_get_buffer_contents( comedi_t *dev, unsigned int subdevice ); -int comedi_get_buffer_offset( comedi_t *dev, unsigned int subdevice ); - +int comedi_mark_buffer_written(comedi_t * d, unsigned int subdevice, + unsigned int num_bytes); +int comedi_get_buffer_contents(comedi_t * dev, unsigned int subdevice); +int comedi_get_buffer_offset(comedi_t * dev, unsigned int subdevice); #else @@ -133,60 +129,60 @@ void comedi_close(unsigned int minor); /* these functions may be called at any priority, but may fail at real-time priority */ -int comedi_lock(unsigned int minor,unsigned int subdev); -int comedi_unlock(unsigned int minor,unsigned int subdev); +int comedi_lock(unsigned int minor, unsigned int subdev); +int comedi_unlock(unsigned int minor, unsigned int subdev); /* these functions may be called at any priority, but you must hold the lock for the subdevice */ -int comedi_cancel(unsigned int minor,unsigned int subdev); -int comedi_register_callback(unsigned int minor,unsigned int subdev, - unsigned int mask,int (*cb)(unsigned int,void *),void *arg); - -int comedi_command(unsigned int minor,comedi_cmd *cmd); -int comedi_command_test(unsigned int minor,comedi_cmd *cmd); -int comedi_trigger(unsigned int minor,unsigned int subdev,comedi_trig *it); -int __comedi_trigger(unsigned int minor,unsigned int subdev,comedi_trig *it); -int comedi_data_write(unsigned int dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t data); -int comedi_data_read(unsigned int dev,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data); -int comedi_dio_config(unsigned int dev,unsigned int subdev,unsigned int chan, +int comedi_cancel(unsigned int minor, unsigned int subdev); +int comedi_register_callback(unsigned int minor, unsigned int subdev, + unsigned int mask, int (*cb) (unsigned int, void *), void *arg); + +int comedi_command(unsigned int minor, comedi_cmd * cmd); +int comedi_command_test(unsigned int minor, comedi_cmd * cmd); +int comedi_trigger(unsigned int minor, unsigned int subdev, comedi_trig * it); +int __comedi_trigger(unsigned int minor, unsigned int subdev, comedi_trig * it); +int comedi_data_write(unsigned int dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t data); +int comedi_data_read(unsigned int dev, unsigned int subdev, unsigned int chan, + unsigned int range, unsigned int aref, lsampl_t * data); +int comedi_dio_config(unsigned int dev, unsigned int subdev, unsigned int chan, unsigned int io); -int comedi_dio_read(unsigned int dev,unsigned int subdev,unsigned int chan, +int comedi_dio_read(unsigned int dev, unsigned int subdev, unsigned int chan, unsigned int *val); -int comedi_dio_write(unsigned int dev,unsigned int subdev,unsigned int chan, +int comedi_dio_write(unsigned int dev, unsigned int subdev, unsigned int chan, unsigned int val); -int comedi_dio_bitfield(unsigned int dev,unsigned int subdev,unsigned int mask, - unsigned int *bits); +int comedi_dio_bitfield(unsigned int dev, unsigned int subdev, + unsigned int mask, unsigned int *bits); int comedi_get_n_subdevices(unsigned int dev); int comedi_get_version_code(unsigned int dev); char *comedi_get_driver_name(unsigned int dev); char *comedi_get_board_name(unsigned int minor); -int comedi_get_subdevice_type(unsigned int minor,unsigned int subdevice); -int comedi_find_subdevice_by_type(unsigned int minor,int type,unsigned int subd); -int comedi_get_n_channels(unsigned int minor,unsigned int subdevice); -lsampl_t comedi_get_maxdata(unsigned int minor,unsigned int subdevice,unsigned +int comedi_get_subdevice_type(unsigned int minor, unsigned int subdevice); +int comedi_find_subdevice_by_type(unsigned int minor, int type, + unsigned int subd); +int comedi_get_n_channels(unsigned int minor, unsigned int subdevice); +lsampl_t comedi_get_maxdata(unsigned int minor, unsigned int subdevice, unsigned int chan); -int comedi_get_n_ranges(unsigned int minor,unsigned int subdevice,unsigned int +int comedi_get_n_ranges(unsigned int minor, unsigned int subdevice, unsigned int chan); -int comedi_do_insn(unsigned int minor,comedi_insn *insn); +int comedi_do_insn(unsigned int minor, comedi_insn * insn); int comedi_poll(unsigned int minor, unsigned int subdev); - /* DEPRECATED functions */ -int comedi_get_rangetype(unsigned int minor,unsigned int subdevice,unsigned int chan); - +int comedi_get_rangetype(unsigned int minor, unsigned int subdevice, + unsigned int chan); /* ALPHA functions */ -unsigned int comedi_get_subdevice_flags(unsigned int minor,unsigned int +unsigned int comedi_get_subdevice_flags(unsigned int minor, unsigned int subdevice); -int comedi_get_len_chanlist(unsigned int minor,unsigned int subdevice); -int comedi_get_krange(unsigned int minor,unsigned int subdevice,unsigned int - chan, unsigned int range, comedi_krange *krange); -unsigned int comedi_get_buf_head_pos(unsigned int minor,unsigned int +int comedi_get_len_chanlist(unsigned int minor, unsigned int subdevice); +int comedi_get_krange(unsigned int minor, unsigned int subdevice, unsigned int + chan, unsigned int range, comedi_krange * krange); +unsigned int comedi_get_buf_head_pos(unsigned int minor, unsigned int subdevice); -int comedi_set_user_int_count(unsigned int minor,unsigned int subdevice, +int comedi_set_user_int_count(unsigned int minor, unsigned int subdevice, unsigned int buf_user_count); int comedi_map(unsigned int minor, unsigned int subdev, void **ptr); int comedi_unmap(unsigned int minor, unsigned int subdev); @@ -194,4 +190,3 @@ int comedi_unmap(unsigned int minor, unsigned int subdev); #endif #endif - diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 2e0495e5..e84d7d85 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -30,5 +30,3 @@ #endif #endif /* _COMPAT_COMPILER_H */ - - diff --git a/include/linux/delay.h b/include/linux/delay.h index 4ef87686..12da6e2f 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -21,4 +21,3 @@ static inline unsigned long msleep_interruptible(unsigned int msecs) #endif #endif - diff --git a/include/linux/device.h b/include/linux/device.h index b031519a..5a384cd5 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -28,8 +28,7 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) #include -struct device_driver -{ +struct device_driver { char *name; }; @@ -43,7 +42,8 @@ static inline struct class *class_create(struct module *owner, char *name) }; static inline void class_destroy(struct class *cs) -{}; +{ +}; static inline struct class_device *COMEDI_CLASS_DEVICE_CREATE(struct class *cls, struct class_device *parent, dev_t devt, struct device *device, @@ -53,7 +53,8 @@ static inline struct class_device *COMEDI_CLASS_DEVICE_CREATE(struct class *cls, }; static inline void class_device_destroy(struct class *cs, dev_t dev) -{}; +{ +}; #else @@ -83,11 +84,10 @@ static inline void class_device_destroy(struct class *cs, dev_t dev) #define COMEDI_CLASS_DEVICE_CREATE(cs, parent, dev, device, fmt...) \ class_device_create(cs, parent, dev, device, fmt) -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) #endif // __COMPAT_LINUX_DEVICE_H_ - diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index 881f02b8..188465c5 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -65,4 +65,3 @@ typedef void irqreturn_t; #endif #endif - diff --git a/include/linux/isapnp.h b/include/linux/isapnp.h index 6889465f..4a2f699c 100644 --- a/include/linux/isapnp.h +++ b/include/linux/isapnp.h @@ -30,4 +30,4 @@ #define pnp_find_dev(...) NULL #endif -#endif // _ISAPNP_COMPAT_H +#endif // _ISAPNP_COMPAT_H diff --git a/include/linux/kernel.h b/include/linux/kernel.h index e13f5f85..46f78af1 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -31,4 +31,4 @@ #endif -#endif // _KERNEL_COMPAT_H +#endif // _KERNEL_COMPAT_H diff --git a/include/linux/kref.h b/include/linux/kref.h index 35ce9ec3..87ac9054 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h @@ -37,7 +37,7 @@ struct kref { static inline void kref_init(struct kref *kref) { - atomic_set(&kref->refcount,1); + atomic_set(&kref->refcount, 1); } static inline void kref_get(struct kref *kref) @@ -45,7 +45,8 @@ static inline void kref_get(struct kref *kref) atomic_inc(&kref->refcount); } -static inline int kref_put(struct kref *kref, void (*release) (struct kref *kref)) +static inline int kref_put(struct kref *kref, + void (*release) (struct kref * kref)) { if (atomic_dec_and_test(&kref->refcount)) { release(kref); @@ -54,12 +55,14 @@ static inline int kref_put(struct kref *kref, void (*release) (struct kref *kref return 0; } -static inline void KREF_INIT(struct kref *kref, void (*release) (struct kref *kref)) +static inline void KREF_INIT(struct kref *kref, + void (*release) (struct kref * kref)) { kref_init(kref); } -static inline int KREF_PUT(struct kref *kref, void (*release) (struct kref *kref)) +static inline int KREF_PUT(struct kref *kref, + void (*release) (struct kref * kref)) { return kref_put(kref, release); } @@ -70,19 +73,19 @@ static inline int KREF_PUT(struct kref *kref, void (*release) (struct kref *kref #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9) -static inline void KREF_INIT(struct kref *kref, void (*release) (struct kref *kref)) +static inline void KREF_INIT(struct kref *kref, + void (*release) (struct kref * kref)) { kref_init(kref, release); } -static inline int KREF_PUT(struct kref *kref, void (*release) (struct kref *kref)) +static inline int KREF_PUT(struct kref *kref, + void (*release) (struct kref * kref)) { int retval; - if(atomic_read(&kref->refcount) == 1) - { + if (atomic_read(&kref->refcount) == 1) { retval = 1; - }else - { + } else { retval = 0; } kref_put(kref); @@ -91,31 +94,31 @@ static inline int KREF_PUT(struct kref *kref, void (*release) (struct kref *kref #else -static inline void KREF_INIT(struct kref *kref, void (*release) (struct kref *kref)) +static inline void KREF_INIT(struct kref *kref, + void (*release) (struct kref * kref)) { kref_init(kref); } -static inline int KREF_PUT(struct kref *kref, void (*release) (struct kref *kref)) +static inline int KREF_PUT(struct kref *kref, + void (*release) (struct kref * kref)) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) int retval; - if(atomic_read(&kref->refcount) == 1) - { + if (atomic_read(&kref->refcount) == 1) { retval = 1; - }else - { + } else { retval = 0; } kref_put(kref, release); return retval; #else return kref_put(kref, release); -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) } -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9) -#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) #endif /* _KREF_COMPAT_H_ */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 7a330988..2e070c29 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -30,7 +30,7 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,10) \ && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,3) #include -#include /* look for tlb_vma() macro for "statm" patch */ +#include /* look for tlb_vma() macro for "statm" patch */ #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,3) && !defined(tlb_vma) @@ -40,8 +40,9 @@ #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) -static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, - unsigned long pfn, unsigned long size, pgprot_t prot) +static inline int remap_pfn_range(struct vm_area_struct *vma, + unsigned long from, unsigned long pfn, unsigned long size, + pgprot_t prot) { return REMAP_PAGE_RANGE(vma, from, pfn << PAGE_SHIFT, size, prot); }; @@ -49,7 +50,3 @@ static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long from #endif #endif /* _COMPAT_MM_H */ - - - - diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 0c4965f8..52396a6c 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -37,4 +37,4 @@ struct pnp_device_id { #include_next #endif -#endif // _MOD_DEVICETABLE_COMPAT_H +#endif // _MOD_DEVICETABLE_COMPAT_H diff --git a/include/linux/module.h b/include/linux/module.h index d692a17b..6d4f4fca 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -7,7 +7,6 @@ #include - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) #define MODULE_LICENSE(x) #endif @@ -21,14 +20,16 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) static inline int try_module_get(struct module *module) { - if( !module ) return 1; - __MOD_INC_USE_COUNT( module ); + if (!module) + return 1; + __MOD_INC_USE_COUNT(module); return 1; } static inline void module_put(struct module *module) { - if( !module ) return; - __MOD_DEC_USE_COUNT( module ); + if (!module) + return; + __MOD_DEC_USE_COUNT(module); } #else #define MOD_IN_USE (0) @@ -39,7 +40,3 @@ static inline void module_put(struct module *module) #endif #endif /* _COMPAT_MODULE_H */ - - - - diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index 4fbbdb7b..e80d8d29 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h @@ -28,7 +28,7 @@ #define _MODULE_PARM_STRING_ulong "l" #define _MODULE_PARM_STRING_bool "i" -#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,25) */ +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,25) */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) @@ -47,7 +47,7 @@ /* Support charp parameters */ #define _MODULE_PARM_STRING_charp "s" -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */ +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) && \ (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)) @@ -73,7 +73,7 @@ #define module_param_array(name, type, nump, perm) \ module_param_array_named(name, name, type, nump, perm) -#endif /* (L_V_C >= K_V(2,6,0)) && (L_V_C < K_V(2,6,10)) */ +#endif /* (L_V_C >= K_V(2,6,0)) && (L_V_C < K_V(2,6,10)) */ /* * Define a Comedi-specific macro MODULE_PARAM_ARRAY(name,type,len,perm) @@ -100,5 +100,4 @@ MODULE_PARM(name, "1-" __MODULE_STRING(len) _MODULE_PARM_STRING_##type) #endif /* module_param_array */ -#endif /* _COMPAT_MODULEPARAM_H */ - +#endif /* _COMPAT_MODULEPARAM_H */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 39f1639b..2fde73e8 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -24,7 +24,3 @@ static inline char *pci_name(struct pci_dev *pdev) #endif #endif /* _COMPAT_PCI_H */ - - - - diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 6585911e..e86f0239 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -23,10 +23,9 @@ #ifndef PCI_VENDOR_ID_QUANCOM #define PCI_VENDOR_ID_QUANCOM 0x8008 #endif - + #ifndef PCI_DEVICE_ID_QUANCOM_GPIB #define PCI_DEVICE_ID_QUANCOM_GPIB 0x3302 #endif -#endif // __COMPAT_LINUX_PCI_IDS_H - +#endif // __COMPAT_LINUX_PCI_IDS_H diff --git a/include/linux/pnp.h b/include/linux/pnp.h index b5515b22..714a8554 100644 --- a/include/linux/pnp.h +++ b/include/linux/pnp.h @@ -40,59 +40,159 @@ struct pnp_resource_table; struct pnp_id; struct pnp_card_link; struct pnp_card_driver; -struct pnp_dev -{ - struct pnp_card * card; +struct pnp_dev { + struct pnp_card *card; }; struct pnp_driver { - char * name; + char *name; const struct pnp_device_id *id_table; unsigned int flags; - int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id); - void (*remove) (struct pnp_dev *dev); + int (*probe) (struct pnp_dev * dev, + const struct pnp_device_id * dev_id); + void (*remove) (struct pnp_dev * dev); struct device_driver driver; }; /* device management */ -static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; } -static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { } -static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } -static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; } +static inline int pnp_register_protocol(struct pnp_protocol *protocol) +{ + return -ENODEV; +} +static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) +{ +} +static inline int pnp_init_device(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_add_device(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_device_attach(struct pnp_dev *pnp_dev) +{ + return -ENODEV; +} +static inline void pnp_device_detach(struct pnp_dev *pnp_dev) +{; +} /* multidevice card support */ -static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; } -static inline void pnp_remove_card(struct pnp_card *card) { ; } -static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; } -static inline void pnp_remove_card_device(struct pnp_dev *dev) { ; } -static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; } -static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from) { return NULL; } -static inline void pnp_release_card_device(struct pnp_dev * dev) { ; } -static inline int pnp_register_card_driver(struct pnp_card_driver * drv) { return -ENODEV; } -static inline void pnp_unregister_card_driver(struct pnp_card_driver * drv) { ; } +static inline int pnp_add_card(struct pnp_card *card) +{ + return -ENODEV; +} +static inline void pnp_remove_card(struct pnp_card *card) +{; +} +static inline int pnp_add_card_device(struct pnp_card *card, + struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline void pnp_remove_card_device(struct pnp_dev *dev) +{; +} +static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) +{ + return -ENODEV; +} +static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link + *clink, const char *id, struct pnp_dev *from) +{ + return NULL; +} +static inline void pnp_release_card_device(struct pnp_dev *dev) +{; +} +static inline int pnp_register_card_driver(struct pnp_card_driver *drv) +{ + return -ENODEV; +} +static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) +{; +} /* resource management */ -static inline struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev) { return NULL; } -static inline struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; } -static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; } -static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; } -static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; } -static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; } -static inline void pnp_init_resource_table(struct pnp_resource_table *table) { } -static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; } -static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } -static inline void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size) { } +static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev + *dev) +{ + return NULL; +} +static inline struct pnp_option *pnp_register_dependent_option(struct pnp_dev + *dev, int priority) +{ + return NULL; +} +static inline int pnp_register_irq_resource(struct pnp_option *option, + struct pnp_irq *data) +{ + return -ENODEV; +} +static inline int pnp_register_dma_resource(struct pnp_option *option, + struct pnp_dma *data) +{ + return -ENODEV; +} +static inline int pnp_register_port_resource(struct pnp_option *option, + struct pnp_port *data) +{ + return -ENODEV; +} +static inline int pnp_register_mem_resource(struct pnp_option *option, + struct pnp_mem *data) +{ + return -ENODEV; +} +static inline void pnp_init_resource_table(struct pnp_resource_table *table) +{ +} +static inline int pnp_manual_config_dev(struct pnp_dev *dev, + struct pnp_resource_table *res, int mode) +{ + return -ENODEV; +} +static inline int pnp_auto_config_dev(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_validate_config(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_activate_dev(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_disable_dev(struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline void pnp_resource_change(struct resource *resource, + unsigned long start, unsigned long size) +{ +} /* protocol helpers */ -static inline int pnp_is_active(struct pnp_dev * dev) { return 0; } -static inline int compare_pnp_id(struct pnp_id * pos, const char * id) { return -ENODEV; } -static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; } -static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } -static inline void pnp_unregister_driver(struct pnp_driver *drv) { ; } +static inline int pnp_is_active(struct pnp_dev *dev) +{ + return 0; +} +static inline int compare_pnp_id(struct pnp_id *pos, const char *id) +{ + return -ENODEV; +} +static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) +{ + return -ENODEV; +} +static inline int pnp_register_driver(struct pnp_driver *drv) +{ + return -ENODEV; +} +static inline void pnp_unregister_driver(struct pnp_driver *drv) +{; +} #define pnp_port_valid(dev, bar) (0) #define pnp_irq_valid(dev, bar) (0) @@ -103,4 +203,4 @@ static inline void pnp_unregister_driver(struct pnp_driver *drv) { ; } #include_next #endif -#endif // _PNP_COMPAT_H +#endif // _PNP_COMPAT_H diff --git a/include/linux/sched.h b/include/linux/sched.h index c10cc3ec..2d18e845 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -17,4 +17,3 @@ static inline int need_resched(void) #endif #endif - diff --git a/include/linux/slab.h b/include/linux/slab.h index 61e50513..4a1bfb3a 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -27,4 +27,3 @@ static inline void *kcalloc(size_t n, size_t size, unsigned int flags) #endif #endif - diff --git a/include/linux/stddef.h b/include/linux/stddef.h index 432648da..747ef183 100644 --- a/include/linux/stddef.h +++ b/include/linux/stddef.h @@ -22,10 +22,9 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) -typedef enum -{ - false, - true +typedef enum { + false, + true } bool; #endif diff --git a/include/linux/time.h b/include/linux/time.h index 4fdf7eb0..9188b88a 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -23,4 +23,3 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m) #endif #endif - diff --git a/include/linux/types.h b/include/linux/types.h index 31b7e409..98c012dc 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -30,4 +30,3 @@ typedef unsigned long resource_size_t; #include_next #endif - diff --git a/include/linux/usb.h b/include/linux/usb.h index 0ad40700..37b58873 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -42,7 +42,6 @@ #define PROBE_ERR_RETURN(x) (x) #endif - #include_next #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) @@ -54,10 +53,10 @@ static inline int USB_CONTROL_MSG(struct usb_device *dev, unsigned int pipe, data, size, msecs_to_jiffies(millisec_timeout)); } static inline int USB_BULK_MSG(struct usb_device *usb_dev, unsigned int pipe, - void *data, int len, int *actual_length, - int millisec_timeout) + void *data, int len, int *actual_length, int millisec_timeout) { - return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, msecs_to_jiffies(millisec_timeout)); + return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, + msecs_to_jiffies(millisec_timeout)); } #else #define USB_CONTROL_MSG usb_control_msg @@ -74,4 +73,3 @@ static inline int USB_BULK_MSG(struct usb_device *usb_dev, unsigned int pipe, #endif #endif - diff --git a/include/linux/version.h b/include/linux/version.h index d69556e8..9a51db61 100644 --- a/include/linux/version.h +++ b/include/linux/version.h @@ -16,4 +16,3 @@ #endif #endif - diff --git a/include/linux/wrapper.h b/include/linux/wrapper.h index 235d107a..81f8adb7 100644 --- a/include/linux/wrapper.h +++ b/include/linux/wrapper.h @@ -29,4 +29,3 @@ #endif #endif /* __COMPAT_LINUX_WRAPPER_H_ */ - diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index cf8223e5..e2ecf60e 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -11,31 +11,30 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) struct pcmcia_driver { - dev_link_t *(*attach)(void); - void (*detach)(dev_link_t *); - struct module *owner; - struct device_driver drv; + dev_link_t *(*attach) (void); + void (*detach) (dev_link_t *); + struct module *owner; + struct device_driver drv; }; /* driver registration */ static inline int pcmcia_register_driver(struct pcmcia_driver *driver) { - return register_pccard_driver((dev_info_t*)driver->drv.name, - driver->attach, driver->detach); + return register_pccard_driver((dev_info_t *) driver->drv.name, + driver->attach, driver->detach); }; static void inline pcmcia_unregister_driver(struct pcmcia_driver *driver) { - unregister_pccard_driver((dev_info_t*)driver->drv.name); + unregister_pccard_driver((dev_info_t *) driver->drv.name); }; static void inline cs_error(client_handle_t handle, int func, int ret) { - error_info_t err = { func, ret }; - CardServices(ReportError, handle, &err); + error_info_t err = { func, ret }; + CardServices(ReportError, handle, &err); }; #endif #endif // __COMPAT_PCMCIA_DS_H_ - -- 2.26.2