From 5446b4a0304b9854c804d3e5ab7f0d7c7118e156 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 7 Nov 2000 20:24:43 +0000 Subject: [PATCH] addition of insn_config --- comedi/comedi_fops.c | 3 ++ comedi/comedi_module.h | 1 + comedi/drivers.c | 51 ++++++++++++++++++- comedi/drivers/8255.c | 31 ++++++++++++ comedi/drivers/mite.c | 26 ---------- comedi/drivers/ni_mio_common.c | 89 ++++++++++++++++++++++------------ include/comedi.h | 1 + 7 files changed, 144 insertions(+), 58 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 6c5f9f14..f633a924 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -689,6 +689,9 @@ static int do_insnlist_ioctl(comedi_device *dev,void *arg,void *file) case INSN_BITS: ret=s->insn_bits(dev,s,&insn,data); break; + case INSN_CONFIG: + ret=s->insn_config(dev,s,&insn,data); + break; default: ret=-EINVAL; break; diff --git a/comedi/comedi_module.h b/comedi/comedi_module.h index 719b26d8..bccd3be2 100644 --- a/comedi/comedi_module.h +++ b/comedi/comedi_module.h @@ -111,6 +111,7 @@ struct comedi_subdevice_struct{ 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 *); diff --git a/comedi/drivers.c b/comedi/drivers.c index af5b967e..a7835e86 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -236,6 +236,8 @@ static void postconfig(comedi_device *dev) if(!s->range_table && !s->range_table_list) s->range_table=&range_unknown; +#define EMULATE_INSN_WITH_TRIG +#ifdef EMULATE_INSN_WITH_TRIG if(!s->insn_read){ if(s->insn_bits){ s->insn_read = insn_emulate_bits; @@ -254,13 +256,26 @@ static void postconfig(comedi_device *dev) s->insn_write=insn_inval; } } - if(!s->insn_bits){ - s->insn_bits = insn_inval; + if(!s->insn_config){ + if(s->type==COMEDI_SUBD_DIO){ + s->insn_config = insn_emulate; + }else{ + s->insn_config = insn_inval; + } } if(!s->trig[0]){ s->trig[0]=mode0_emulate; } +#else + 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; +#endif + + if(!s->insn_bits){ + s->insn_bits = insn_inval; + } } } @@ -302,6 +317,7 @@ static int insn_inval(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,l return -EINVAL; } +#ifdef EMULATE_INSN_WITH_TRIG static int insn_emulate(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) { comedi_trig trig; @@ -309,6 +325,9 @@ static int insn_emulate(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn int ret; switch(insn->insn){ + case INSN_CONFIG: + trig.flags=TRIG_CONFIG; + break; case INSN_WRITE: if(!(s->subdev_flags & SDF_WRITEABLE)) return -EINVAL; @@ -349,6 +368,7 @@ static int insn_emulate(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn return insn->n; } +#endif static int insn_emulate_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) @@ -388,6 +408,9 @@ static int insn_emulate_bits(comedi_device *dev,comedi_subdevice *s, return 1; } +#define SUPPORT_TRIG +#define SUPPORT_TRIG0 +#ifdef SUPPORT_TRIG static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) { comedi_insn insn; @@ -399,6 +422,9 @@ static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *tri insn.n=1; insn.chanspec=trig->chanlist[0]; + if(trig->flags&TRIG_CONFIG) + return mode0_emulate_config(); + if(s->subdev_flags & SDF_WRITEABLE){ if(s->subdev_flags & SDF_READABLE){ if(trig->flags&TRIG_WRITE){ @@ -434,7 +460,27 @@ static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *tri return -EINVAL; } +#endif + +#ifdef SUPPORT_TRIG0 +static int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) +{ + comedi_insn insn; + lsampl_t ldata; + int ret; + + insn.subdev=trig->subdev; + insn.data=&ldata; + insn.n=1; + insn.chanspec=trig->chanlist[0]; + + ldata = trig->data[0]; + + return s->insn_config(dev,s,&insn,&ldata); +} +#endif +#ifdef SUPPORT_TRIG static int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { int ret; @@ -449,6 +495,7 @@ static int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) if(ret>0)return -EINVAL; return ret; } +#endif static int mode_to_command(comedi_cmd *cmd,comedi_trig *it) { diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index 504a8a33..45a4e416 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -103,6 +103,37 @@ static int subdev_8255_insn(comedi_device *dev,comedi_subdevice *s, return 2; } +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; + } + + switch(insn->data[0]){ + case COMEDI_INPUT: + s->io_bits&=~bits; + break; + case COMEDI_OUTPUT: + s->io_bits|=bits; + break; + default: + return -EINVAL; + } + + do_config(dev,s); +} + static int subdev_8255_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { int mask,data_in; diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 41a390fe..1b9dcc85 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -108,32 +108,8 @@ void mite_init(void) #else -#if LINUX_VERSION_CODE < 0x020300 - /* functions for the new PCI code (after 2.1.55) */ -void mite_init(void) -{ - struct pci_dev *pcidev; - struct mite_struct *mite; - - for(pcidev=pci_devices;pcidev;pcidev=pcidev->next){ - if(pcidev->vendor==PCI_VENDOR_ID_NATINST){ - mite=kmalloc(sizeof(*mite),GFP_KERNEL); - memset(mite,0,sizeof(*mite)); - - mite->pcidev=pcidev; - - mite->next=mite_devices; - mite_devices=mite; - } - } -} - -#else - -/* And after the pci_devices change */ - void mite_init(void) { struct pci_dev *pcidev; @@ -152,8 +128,6 @@ void mite_init(void) } } - -#endif #endif int mite_setup(struct mite_struct *mite) diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index a7d0ee83..8c51d719 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -149,7 +149,14 @@ static comedi_lrange *ni_range_lkup[]={ +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); +#if 0 static int ni_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); +#endif + static int ni_eeprom(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); static int ni_calib_insn_read(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); @@ -170,7 +177,10 @@ static int ni_8255_callback(int dir,int port,int data,void *arg); static int ni_ns_to_timer(int *nanosec,int round_mode); static int gpct_setup(comedi_device *dev,comedi_subdevice *s); -static int ni_gpct(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); +static int ni_gpct_insn_config(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); #undef DEBUG @@ -1500,6 +1510,7 @@ devpriv->ao_mode2|=AO_FIFO_Mode(1); +#if 0 /* digital i/o @@ -1537,6 +1548,26 @@ static int ni_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) return it->n_chan; } +#endif + +static int ni_dio_insn_config(comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data) +{ + if(insn->n!=1)return -EINVAL; + switch(data[0]){ + case COMEDI_OUTPUT: + s->io_bits &= ~(1<chanspec)); + break; + case COMEDI_INPUT: + s->io_bits |= 1<chanspec); + break; + default: + return -EINVAL; + } + win_out(s->io_bits,DIO_Control_Register); + + return 1; +} static int ni_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) @@ -1558,41 +1589,35 @@ static int ni_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, This reads the value of the counter */ -static int ni_gpct(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) +/* + * Each DAQ-STC counters have one transition input, a generic + * input, and an enable input. + * + * 31-30 type + * 00 disabled + * 01 transition pin + * 02 generic pin + * + * + */ +static int ni_gpct_insn_config(comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data) { - int data,mask; - int i; - int temp; + if(insn->n!=1)return -EINVAL; - /* rt stuff */ - temp=win_save(); + /* transition pin # */ + /* */ - if(it->flags & TRIG_CONFIG){ - data=s->io_bits; - for(i=0;in_chan;i++){ - mask=1<chanlist[i]); - data&= ~mask; - if(it->data[i]) - data|=mask; - } - s->io_bits=data; - win_out(s->io_bits,DIO_Control_Register); - }else{ - if(it->flags & TRIG_WRITE){ - do_pack(&s->state,it); - win_out(s->state,DIO_Output_Register); - }else{ - data=win_in(DIO_Input_Register); - di_unpack(data,it); - } - } + return 1; +} - win_restore(temp); +static int ni_gpct_insn_read(comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data) +{ - return it->n_chan; + return -EIO; } - static int ni_E_init(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; @@ -1654,7 +1679,10 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s->range_table=&range_digital; s->io_bits=0; /* all bits input */ s->insn_bits=ni_dio_insn_bits; + s->insn_config=ni_dio_insn_config; +#if 0 s->trig[0]=ni_dio; +#endif /* dio setup */ win_out(s->io_bits,DIO_Control_Register); @@ -1673,7 +1701,8 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s=dev->subdevices+4; s->type=COMEDI_SUBD_COUNTER; s->subdev_flags=SDF_READABLE|SDF_WRITEABLE; - s->trig[0]=ni_gpct; + s->insn_read=ni_gpct_insn_read; + s->insn_config=ni_gpct_insn_config; s->n_chan=1; /* XXX */ s->maxdata=1; gpct_setup(dev,s); diff --git a/include/comedi.h b/include/comedi.h index aa76dc99..487dbb2a 100644 --- a/include/comedi.h +++ b/include/comedi.h @@ -71,6 +71,7 @@ typedef unsigned short sampl_t; #define INSN_READ ( 0 | INSN_MASK_READ) #define INSN_WRITE ( 1 | INSN_MASK_WRITE) #define INSN_BITS ( 2 | INSN_MASK_READ|INSN_MASK_WRITE) +#define INSN_CONFIG ( 3 | INSN_MASK_READ|INSN_MASK_WRITE) #define INSN_GTOD ( 4 | INSN_MASK_READ|INSN_MASK_SPECIAL) #define INSN_WAIT ( 5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL) -- 2.26.2