From 34b9800e40fe5dc950ab29535eae9fa353051fd7 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Tue, 17 Oct 2006 18:19:29 +0000 Subject: [PATCH] Added const qualifiers to some char* return values. Added new experimental comedi_dio_bitfield2() function which works with > 32 channels. Only works properly with ni_65xx currently. Will post a request for review by any interested parties to list before I bother making the rest of the drivers work with it. --- doc/funcref | 36 +++++++++++++++++----- include/comedilib.h | 10 ++++--- lib/calib.c | 5 ++-- lib/dio.c | 73 +++++++++++++++++++++++++-------------------- lib/get.c | 8 ++--- lib/version_script | 1 + 6 files changed, 82 insertions(+), 51 deletions(-) diff --git a/doc/funcref b/doc/funcref index 7c49f00..e00fbba 100644 --- a/doc/funcref +++ b/doc/funcref @@ -804,18 +804,38 @@ Param: comedi_t * device Param: unsigned int subdevice Param: unsigned int write_mask Param: unsigned int * bits +Status: deprecated +Description: + This function is deprecated. Use comedi_dio_bitfield2() instead. + +Function: comedi_dio_bitfield2 -- read/write multiple digital channels +Retval: int +Param: comedi_t * device +Param: unsigned int subdevice +Param: unsigned int write_mask +Param: unsigned int * bits +Param: unsigned int base_channel Description: - The function comedi_dio_bitfield() allows multiple channels to - be read simultaneously from a digital input or digital I/O device. - The parameter write_mask and the value pointed to by bits + The function comedi_dio_bitfield2() allows multiple channels to + be read or written together on a digital input, output, + or configurable digital I/O device. + The parameter write_mask + and the value pointed to by bits are interpreted as bit fields, with the least significant bit - representing channel 0. For each bit in write_mask that is - set to 1, the cooresponding bit in *bits is written to the digital + representing channel base_channel. + For each bit in write_mask that is + set to 1, the cooresponding bit in *bits + is written to the digital output channel. After writing all the output channels, each channel is read, and the result placed in the approprate bits in - *bits. The result of reading an output channel is undefined. - It is not possible to access channels greater than 31 using this - function. + *bits. The result of + reading an output channel is the last + value written to the output channel. + + All the channels may not be read or written at the exact same time. + For example, the driver may need to sequentially write to + several ports in order to set all the digital channels specified + by the write_mask. Function: comedi_sv_init -- slowly-varying inputs Retval: int diff --git a/include/comedilib.h b/include/comedilib.h index 37dda01..f58292b 100644 --- a/include/comedilib.h +++ b/include/comedilib.h @@ -82,8 +82,8 @@ enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior int comedi_get_n_subdevices(comedi_t *it); #define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c)) int comedi_get_version_code(comedi_t *it); -char *comedi_get_driver_name(comedi_t *it); -char *comedi_get_board_name(comedi_t *it); +const char *comedi_get_driver_name(comedi_t *it); +const char *comedi_get_board_name(comedi_t *it); int comedi_get_read_subdevice(comedi_t *dev); int comedi_get_write_subdevice(comedi_t *dev); @@ -147,8 +147,8 @@ int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan, unsigned int *bit); int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan, unsigned int bit); -int comedi_dio_bitfield(comedi_t *it,unsigned int subd, - unsigned int write_mask, unsigned int *bits); +int comedi_dio_bitfield2(comedi_t *it,unsigned int subd, + unsigned int write_mask, unsigned int *bits, unsigned int base_channel); /* slowly varying stuff */ int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan); @@ -188,6 +188,8 @@ int comedi_timed_1chan(comedi_t *it,unsigned int subdev,unsigned int chan, unsigned int n_samples,double *data); int comedi_get_rangetype(comedi_t *it,unsigned int subdevice, unsigned int chan); +int comedi_dio_bitfield(comedi_t *it,unsigned int subd, + unsigned int write_mask, unsigned int *bits); #endif diff --git a/lib/calib.c b/lib/calib.c index c43d672..52d281e 100644 --- a/lib/calib.c +++ b/lib/calib.c @@ -181,8 +181,9 @@ char* _comedi_get_default_calibration_path( comedi_t *dev ) { struct stat file_stats; char *file_path; - char *board_name, *temp; - char *driver_name; + const char *temp; + char *board_name; + const char *driver_name; if( fstat( comedi_fileno( dev ), &file_stats ) < 0 ) { diff --git a/lib/dio.c b/lib/dio.c index def2aba..874ab6e 100644 --- a/lib/dio.c +++ b/lib/dio.c @@ -41,7 +41,7 @@ int _comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsign if(!valid_chan(it,subdev,chan)) return -1; - + s=it->subdevices+subdev; if(s->type!=COMEDI_SUBD_DIO) return -1; @@ -52,7 +52,7 @@ int _comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsign if(it->has_insnlist_ioctl){ comedi_insn insn; lsampl_t data; - + memset(&insn,0,sizeof(insn)); insn.insn = INSN_CONFIG; insn.n = 1; @@ -86,17 +86,17 @@ int _comedi_dio_get_config(comedi_t *it,unsigned int subdev, unsigned int chan, comedi_insn insn; lsampl_t data[2]; int retval; - + if(!valid_chan(it,subdev,chan)) return -1; - + s=it->subdevices+subdev; if(s->type!=COMEDI_SUBD_DIO) return -1; if(it->has_insnlist_ioctl == 0) return -1; - + memset(&insn,0,sizeof(insn)); insn.insn = INSN_CONFIG; insn.n = sizeof(data) / sizeof(data[0]); @@ -130,7 +130,7 @@ int _comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan, if(it->has_insnlist_ioctl){ comedi_insn insn; lsampl_t data; - + memset(&insn,0,sizeof(insn)); insn.insn = INSN_READ; insn.n = 1; @@ -170,7 +170,7 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan, if(!valid_chan(it,subdev,chan)) return -1; - + s = it->subdevices+subdev; if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO) @@ -179,7 +179,7 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan, if(it->has_insnlist_ioctl){ comedi_insn insn; lsampl_t data; - + memset(&insn,0,sizeof(insn)); insn.insn = INSN_WRITE; insn.n = 1; @@ -208,60 +208,67 @@ int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan, } } -EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18); -int _comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits) +EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield2,comedi_dio_bitfield2,0.7.23); +int _comedi_dio_bitfield2(comedi_t *it, unsigned int subdev, unsigned int mask, unsigned int *bits, unsigned base_channel) { int ret; unsigned int m,bit; subdevice *s; - if(!valid_subd(it,subdev)) + if(!valid_subd(it, subdev)) return -1; - s=it->subdevices+subdev; + s = it->subdevices + subdev; - if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO && - s->type!=COMEDI_SUBD_DI) + if(s->type != COMEDI_SUBD_DIO && s->type != COMEDI_SUBD_DO && + s->type != COMEDI_SUBD_DI) return -1; - if(s->has_insn_bits){ + if(s->has_insn_bits) + { comedi_insn insn; lsampl_t data[2]; - + memset(&insn,0,sizeof(insn)); insn.insn = INSN_BITS; + insn.chanspec = base_channel; insn.n = 2; insn.data = data; insn.subdev = subdev; - data[0]=mask; - data[1]=*bits; + data[0] = mask; + data[1] = *bits; - ret = comedi_do_insn(it,&insn); + ret = comedi_do_insn(it, &insn); - if(ret<0)return ret; + if(ret < 0) return ret; *bits = data[1]; return 0; }else{ - unsigned int i,n_chan; - - n_chan=comedi_get_n_channels(it,subdev); - if(n_chan>32)n_chan=32; - for(i=0,m=1;in_subdevices); - if(s == NULL) + if(s == NULL) { __comedi_errno = errno; return -1; } ret = comedi_ioctl(it->fd, COMEDI_SUBDINFO, (unsigned long)s); - if(ret < 0) + if(ret < 0) { free(s); return -1; diff --git a/lib/version_script b/lib/version_script index 84755e5..3b238cc 100644 --- a/lib/version_script +++ b/lib/version_script @@ -84,6 +84,7 @@ v0.7.20 { v0.7.23 { global: comedi_from_physical; + comedi_dio_bitfield2; comedi_dio_get_config; comedi_get_hardcal_converter; comedi_get_softcal_converter; -- 2.26.2