From: Frank Mori Hess Date: Thu, 2 Aug 2007 19:46:44 +0000 (+0000) Subject: Fixed comedi_get_cmd_generic_timed() by adding a chanlist_len X-Git-Tag: r0_8_1~25 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c1082cee6537c797e7caf852c15163dfea177579;p=comedilib.git Fixed comedi_get_cmd_generic_timed() by adding a chanlist_len parameter. Old version is still available in library, thanks to the magic of the version_script. --- diff --git a/demo/cmd.c b/demo/cmd.c index 20d8b2d..adc046a 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) * This prepares a command in a pretty generic way. We ask the * library to create a stock command that supports periodic * sampling of data, then modify the parts we want. */ -int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned period_nanosec, comedi_cmd *cmd) +int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned scan_period_nanosec, comedi_cmd *cmd) { int ret; @@ -211,7 +211,7 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign /* This comedilib function will get us a generic timed * command for a particular board. If it returns -1, * that's bad. */ - ret = comedi_get_cmd_generic_timed(dev, subdevice,cmd, period_nanosec); + ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec); if(ret<0){ printf("comedi_get_cmd_generic_timed failed\n"); return ret; @@ -220,8 +220,6 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign /* Modify parts of the command */ cmd->chanlist = chanlist; cmd->chanlist_len = n_chan; - - cmd->scan_end_arg = n_chan; if(cmd->stop_src == TRIG_COUNT) cmd->stop_arg = n_scan; return 0; diff --git a/demo/info.c b/demo/info.c index bffc71c..2ad0a95 100644 --- a/demo/info.c +++ b/demo/info.c @@ -150,7 +150,7 @@ void probe_max_1chan(comedi_t *it,int s) char buf[100]; printf(" command fast 1chan:\n"); - if(comedi_get_cmd_generic_timed(it,s,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(it, s, &cmd, 1, 1)<0){ printf(" not supported\n"); }else{ printf(" start: %s %d\n", diff --git a/demo/mmap.c b/demo/mmap.c index ca3534f..55bf58d 100644 --- a/demo/mmap.c +++ b/demo/mmap.c @@ -120,11 +120,11 @@ int main(int argc, char *argv[]) return 0; } -int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned period_nanosec, comedi_cmd *cmd) +int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsigned scan_period_nanosec, comedi_cmd *cmd) { int ret; - ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, period_nanosec); + ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec); if(ret<0){ comedi_perror("comedi_get_cmd_generic_timed\n"); return ret; @@ -132,8 +132,6 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign cmd->chanlist = chanlist; cmd->chanlist_len = n_chan; - cmd->scan_end_arg = n_chan; - if(cmd->stop_src == TRIG_COUNT) cmd->stop_arg = n_scan; return 0; diff --git a/doc/funcref b/doc/funcref index e00fbba..920aaad 100644 --- a/doc/funcref +++ b/doc/funcref @@ -891,15 +891,18 @@ Retval: int Param: comedi_t * device Param: unsigned int subdevice Param: comedi_cmd * command -Param: unsigned int period_ns +Param: unsigned int chanlist_len +Param: unsigned int scan_period_ns Description: The command capabilities of the subdevice indicated by the parameters device and subdevice are probed, and the results placed in the command structure pointed to by the parameter command. The command structure pointed to by the parameter command is modified to be a - valid command that can be used as a parameter to comedi_command(). - The command measures samples at a rate that corresponds to the - period period_ns. The rate is adjusted to a rate that the device + valid command that can be used as a parameter to comedi_command() + (after the command has been assigned a valid chanlist array). + The command measures scans consisting of chanlist_len channels + at a scan rate that corresponds to the + period scan_period_ns. The rate is adjusted to a rate that the device can handle. If sucessful, 0 is returned, otherwise -1. Function: comedi_cancel -- stop streaming input/output in progress diff --git a/include/comedilib.h b/include/comedilib.h index b6b1ab2..478da91 100644 --- a/include/comedilib.h +++ b/include/comedilib.h @@ -164,7 +164,7 @@ int comedi_sv_measure(comedi_sv_t *it,double *data); int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice, comedi_cmd *cmd); int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice, - comedi_cmd *cmd,unsigned int ns); + comedi_cmd *cmd, unsigned chanlist_len, unsigned scan_period_ns); int comedi_cancel(comedi_t *it,unsigned int subdevice); int comedi_command(comedi_t *it,comedi_cmd *cmd); int comedi_command_test(comedi_t *it,comedi_cmd *cmd); diff --git a/lib/cmd.c b/lib/cmd.c index a08a1d1..27fd4cc 100644 --- a/lib/cmd.c +++ b/lib/cmd.c @@ -78,11 +78,13 @@ int _comedi_get_cmd_src_mask(comedi_t *it,unsigned int subd,comedi_cmd *cmd) return 0; } -static int __generic_timed(comedi_t *it,unsigned int s, - comedi_cmd *cmd, unsigned int ns) +static int __generic_timed(comedi_t *it, unsigned s, + comedi_cmd *cmd, unsigned chanlist_len, unsigned scan_period_ns) { int ret; + unsigned convert_period_ns; + if(chanlist_len < 1) return -EINVAL; ret = comedi_get_cmd_src_mask(it,s,cmd); if(ret<0)return ret; @@ -99,35 +101,35 @@ static int __generic_timed(comedi_t *it,unsigned int s, return -1; } - /* Potential bug: there is a possibility that the source mask may - * have * TRIG_TIMER set for both convert_src and scan_begin_src, - * but they may not be supported together. */ - if(cmd->convert_src&TRIG_TIMER){ - if(cmd->scan_begin_src&TRIG_FOLLOW){ - cmd->convert_src = TRIG_TIMER; - cmd->convert_arg = ns; - cmd->scan_begin_src = TRIG_FOLLOW; - cmd->scan_begin_arg = 0; - }else{ - cmd->convert_src = TRIG_TIMER; - cmd->convert_arg = ns; - cmd->scan_begin_src = TRIG_TIMER; - cmd->scan_begin_arg = ns; - } - }else if(cmd->convert_src & TRIG_NOW && - cmd->scan_begin_src & TRIG_TIMER) + convert_period_ns = (scan_period_ns + chanlist_len / 2) / chanlist_len; + if((cmd->convert_src & TRIG_TIMER) && + (cmd->scan_begin_src & TRIG_FOLLOW)) + { + cmd->convert_src = TRIG_TIMER; + cmd->convert_arg = convert_period_ns; + cmd->scan_begin_src = TRIG_FOLLOW; + cmd->scan_begin_arg = 0; + }else if((cmd->convert_src & TRIG_NOW) && + (cmd->scan_begin_src & TRIG_TIMER)) { cmd->convert_src = TRIG_NOW; cmd->convert_arg = 0; cmd->scan_begin_src = TRIG_TIMER; - cmd->scan_begin_arg = ns; + cmd->scan_begin_arg = scan_period_ns; + }else if((cmd->convert_src & TRIG_TIMER) && + (cmd->scan_begin_src & TRIG_TIMER)) + { + cmd->convert_src = TRIG_TIMER; + cmd->convert_arg = convert_period_ns; + cmd->scan_begin_src = TRIG_TIMER; + cmd->scan_begin_arg = scan_period_ns; }else{ COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: can't do timed?\n"); return -1; } cmd->scan_end_src = TRIG_COUNT; - cmd->scan_end_arg = 1; + cmd->scan_end_arg = chanlist_len; if(cmd->stop_src&TRIG_COUNT){ cmd->stop_src=TRIG_COUNT; @@ -140,7 +142,7 @@ static int __generic_timed(comedi_t *it,unsigned int s, return -1; } - cmd->chanlist_len = 1; + cmd->chanlist_len = chanlist_len; ret=comedi_command_test(it,cmd); COMEDILIB_DEBUG(3,"comedi_get_cmd_generic_timed: test 1 returned %d\n",ret); @@ -156,8 +158,8 @@ static int __generic_timed(comedi_t *it,unsigned int s, return -1; } -EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_generic_timed,comedi_get_cmd_generic_timed,0.7.18); -int _comedi_get_cmd_generic_timed(comedi_t *it,unsigned int subd,comedi_cmd *cmd, +EXPORT_ALIAS_VER(_comedi_get_cmd_generic_timed_obsolete,comedi_get_cmd_generic_timed,0.7.18); +int _comedi_get_cmd_generic_timed_obsolete(comedi_t *it,unsigned int subd,comedi_cmd *cmd, unsigned int ns) { subdevice *s; @@ -175,7 +177,35 @@ int _comedi_get_cmd_generic_timed(comedi_t *it,unsigned int subd,comedi_cmd *cmd if(!s->cmd_timed) s->cmd_timed = malloc(sizeof(comedi_cmd)); - ret = __generic_timed(it,subd,s->cmd_timed,ns); + ret = __generic_timed(it, subd, s->cmd_timed, 1, ns); + if(ret<0){ + s->cmd_mask_errno = errno; + return -1; + } + *cmd=*s->cmd_timed; + return 0; +} + +EXPORT_ALIAS_DEFAULT(_comedi_get_cmd_generic_timed,comedi_get_cmd_generic_timed,0.9.0); +int _comedi_get_cmd_generic_timed(comedi_t *it, unsigned subd, comedi_cmd *cmd, + unsigned chanlist_len, unsigned scan_period_ns) +{ + subdevice *s; + int ret; + + if(!valid_subd(it,subd)) return -1; + + s = it->subdevices + subd; + + if(s->cmd_timed_errno){ + errno = s->cmd_mask_errno; + return -1; + } + + if(!s->cmd_timed) + s->cmd_timed = malloc(sizeof(comedi_cmd)); + + ret = __generic_timed(it, subd, s->cmd_timed, chanlist_len, scan_period_ns); if(ret<0){ s->cmd_mask_errno = errno; return -1; diff --git a/lib/version_script b/lib/version_script index fc40d3a..357ec0c 100644 --- a/lib/version_script +++ b/lib/version_script @@ -92,3 +92,8 @@ v0.8.0 { comedi_mark_buffer_written; comedi_to_physical; } v0.7.20; + +v0.9.0 { + global: + comedi_get_cmd_generic_timed; +} v0.8.0; diff --git a/swig/comedi.i b/swig/comedi.i index c1bba44..3fd68ef 100644 --- a/swig/comedi.i +++ b/swig/comedi.i @@ -506,6 +506,8 @@ 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 *INOUT); +int comedi_dio_bitfield2(comedi_t *it, unsigned int subd, + unsigned int write_mask, unsigned int *INOUT, unsigned base_channel); /* slowly varying stuff */ int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan); @@ -517,7 +519,7 @@ int comedi_sv_measure(comedi_sv_t *it,double *data); int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice, comedi_cmd *INOUT); int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice, - comedi_cmd *INOUT,unsigned int ns); + comedi_cmd *INOUT, unsigned chanlist_len, unsigned int scan_period_ns); int comedi_cancel(comedi_t *it,unsigned int subdevice); int comedi_command(comedi_t *it,comedi_cmd *cmd); int comedi_command_test(comedi_t *it,comedi_cmd *INOUT); diff --git a/testing/cmd_1.c b/testing/cmd_1.c index f43ee27..8e28f49 100644 --- a/testing/cmd_1.c +++ b/testing/cmd_1.c @@ -82,7 +82,7 @@ int test_cmd_probe_fast_1chan(void) } printf("command fast 1chan:\n"); - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device,subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } @@ -117,7 +117,7 @@ int test_cmd_read_fast_1chan(void) return 0; } - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } @@ -164,7 +164,7 @@ int test_cmd_write_fast_1chan(void) static const int num_samples = 100000; int num_bytes; int wc; - + if((flags & SDF_LSAMPL)) { num_bytes = num_samples * sizeof(lsampl_t); @@ -177,7 +177,7 @@ int test_cmd_write_fast_1chan(void) return 0; } - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } @@ -214,7 +214,7 @@ int test_cmd_write_fast_1chan(void) total += ret; if(verbose)printf("write %d %d\n",ret,total); } - + ret = comedi_internal_trigger(device, subdevice, 0); if(ret<0){ perror("E: comedi_inttrig"); @@ -323,11 +323,11 @@ char *tobinary(char *s,int bits,int n) { int bit=1<>=1) *t++=(bits&bit)?'1':'0'; *t=0; - + return s; } diff --git a/testing/cmd_2.c b/testing/cmd_2.c index 09142ec..77467c5 100644 --- a/testing/cmd_2.c +++ b/testing/cmd_2.c @@ -43,7 +43,7 @@ static int get_chunks_per_length(int length) int ret; int chunks=0; - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } diff --git a/testing/cmd_3.c b/testing/cmd_3.c index eba5ea0..4b0ae74 100644 --- a/testing/cmd_3.c +++ b/testing/cmd_3.c @@ -48,7 +48,7 @@ static int do_continuous(int multiplier) unsigned long total_secs = 0; struct timeval tv,start_tv; - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device,subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } diff --git a/testing/inttrig.c b/testing/inttrig.c index eacb36d..60aa862 100644 --- a/testing/inttrig.c +++ b/testing/inttrig.c @@ -59,7 +59,7 @@ int test_cmd_start_inttrig(void) return 0; } - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf(" not supported\n"); return 0; } diff --git a/testing/mmap.c b/testing/mmap.c index d59843c..f2ebebc 100644 --- a/testing/mmap.c +++ b/testing/mmap.c @@ -76,7 +76,7 @@ int test_mmap(void) return 0; } - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf("E: comedi_get_cmd_generic_timed failed\n"); return 0; } @@ -153,7 +153,7 @@ int test_mmap(void) printf("E: %p still mapped\n",adr); } } - + free(buf); return 0; diff --git a/testing/select.c b/testing/select.c index 1325a48..f4a67e0 100644 --- a/testing/select.c +++ b/testing/select.c @@ -35,7 +35,7 @@ int test_read_select(void) return 0; } - if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ + if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){ printf("E: comedi_get_cmd_generic_timed failed\n"); return 0; }