From 9fe5447afff3fa674ce7593872a3d4155ed0a1ff Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 3 Sep 2000 01:49:16 +0000 Subject: [PATCH] instruction bits support --- comedi/comedi_fops.c | 3 +++ comedi/comedi_module.h | 1 + comedi/drivers.c | 6 ++++++ comedi/drivers/8255.c | 38 ++++++++++++++++++++++------------ comedi/drivers/dt282x.c | 15 ++++++++++++++ comedi/drivers/ni_mio_common.c | 13 ++++++++++++ 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 1e781231..ca687244 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -687,6 +687,9 @@ static int do_insnlist_ioctl(comedi_device *dev,void *arg,void *file) case INSN_WRITE: ret=s->insn_write(dev,s,&insn,data); break; + case INSN_BITS: + ret=s->insn_bits(dev,s,&insn,data); + break; default: ret=-EINVAL; break; diff --git a/comedi/comedi_module.h b/comedi/comedi_module.h index 4a1cfdbe..09468190 100644 --- a/comedi/comedi_module.h +++ b/comedi/comedi_module.h @@ -110,6 +110,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 (*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 f8aeca96..8f4bc650 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -172,6 +172,8 @@ comedi_device *comedi_allocate_dev(comedi_driver *driver) { comedi_device *dev; + // XXX we need to do actual allocation here. + dev=comedi_get_device_by_minor(0); dev->driver=driver; @@ -240,6 +242,9 @@ static void postconfig(comedi_device *dev) s->insn_write=insn_inval; } } + if(!s->insn_bits){ + s->insn_bits = insn_inval; + } if(!s->trig[0]){ s->trig[0]=mode0_emulate; @@ -332,6 +337,7 @@ static int insn_emulate(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn return -EINVAL; } + static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) { comedi_insn insn; diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index fd1661d4..504a8a33 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -81,7 +81,29 @@ static int subdev_8255_cb(int dir,int port,int data,void *arg) } } -int subdev_8255_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) +static int subdev_8255_insn(comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data) +{ + 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); + } + + 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_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { int mask,data_in; int i; @@ -162,6 +184,7 @@ int subdev_8255_init(comedi_device *dev,comedi_subdevice *s,int (*cb)(int,int,in CALLBACK_FUNC=cb; } s->trig[0]=subdev_8255_dio; + s->insn_bits = subdev_8255_insn; s->state=0; s->io_bits=0; @@ -242,16 +265,5 @@ static int dev_8255_detach(comedi_device *dev) return 0; } -#ifdef MODULE -int init_module(void) -{ - comedi_driver_register(&driver_8255); - - return 0; -} +COMEDI_INITCLEANUP(driver_8255); -void cleanup_module(void) -{ - comedi_driver_unregister(&driver_8255); -} -#endif diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index 578de19b..b328770a 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -1197,6 +1197,20 @@ 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) +{ + if(data[0]){ + s->state &= ~data[0]; + s->state |= (data[0]&data[1]); + + outw(s->state, dev->iobase + DT2821_DIODAT); + } + data[1] = inw(dev->iobase + DT2821_DIODAT); + + return 2; +} + static int dt282x_dio(comedi_device * dev, comedi_subdevice * s, comedi_trig * it) { if(it->flags&TRIG_CONFIG){ @@ -1434,6 +1448,7 @@ static int dt282x_attach(comedi_device * dev, comedi_devconfig * it) s->subdev_flags=SDF_READABLE|SDF_WRITEABLE; s->n_chan=16; s->trig[0]=dt282x_dio; + s->insn_bits = dt282x_dio_insn_bits; s->maxdata=1; s->range_table = &range_digital; diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index 81a07b02..66de7a46 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -1518,6 +1518,18 @@ static int ni_dio(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) return it->n_chan; } +static int ni_dio_insn_bits(comedi_device *dev,comedi_subdevice *s, + comedi_insn *insn,lsampl_t *data) +{ + if(data[0]){ + s->state &= ~data[0]; + s->state |= (data[0]&data[1]); + win_out(s->state,DIO_Output_Register); + } + data[1] = win_in(DIO_Input_Register); + + return 2; +} /* HACK! @@ -1621,6 +1633,7 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it) s->maxdata=1; s->range_table=&range_digital; s->io_bits=0; /* all bits input */ + s->insn_read=ni_dio_insn_bits; s->trig[0]=ni_dio; /* dio setup */ -- 2.26.2