Fixed comedi_get_cmd_generic_timed() by adding a chanlist_len
authorFrank Mori Hess <fmhess@speakeasy.net>
Thu, 2 Aug 2007 19:46:44 +0000 (19:46 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Thu, 2 Aug 2007 19:46:44 +0000 (19:46 +0000)
parameter.  Old version is still available in library, thanks to the
magic of the version_script.

14 files changed:
demo/cmd.c
demo/info.c
demo/mmap.c
doc/funcref
include/comedilib.h
lib/cmd.c
lib/version_script
swig/comedi.i
testing/cmd_1.c
testing/cmd_2.c
testing/cmd_3.c
testing/inttrig.c
testing/mmap.c
testing/select.c

index 20d8b2d18f98e97941e6b24dca1112858a2294ca..adc046a6a9f0e1f39a5285aa0de46f01b1426ba5 100644 (file)
@@ -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;
index bffc71c50ae87fc2cc5f30df297b9a50f537417d..2ad0a9579b5997a8edfbe6bc93279243358c009b 100644 (file)
@@ -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",
index ca3534f0afe1e0c2286c0b24474f6ebc0ee3294b..55bf58df07f0a9ca61344d604a09aa5ba476f9cd 100644 (file)
@@ -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;
index e00fbba52f20c9ec9a69dcf2eee73f5ee05447e2..920aaad1a44c9d68995f42f8da00811de811b447 100644 (file)
@@ -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
index b6b1ab281515654fa325527c4e4aa6f1024cbc95..478da91b97a9909421d5fb298f45760721015498 100644 (file)
@@ -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);
index a08a1d1b4db413a7c4e550c9d2974d0d121bb99d..27fd4cc54e0b1d89f78ab6f7c2ae8b74230ef64a 100644 (file)
--- 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;
index fc40d3a6428d2f281dc28c5715d4f14fc7372ca7..357ec0cc2d2172ee57a59340a7f7559ce5699b60 100644 (file)
@@ -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;
index c1bba4463d81122b41cc17c30f48eff45fe159ed..3fd68efa9d345c9d1d872bdfff53646929f42d5c 100644 (file)
@@ -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);
index f43ee27023691f77ff13e0bd331406387a136aa0..8e28f49ef9064ac730a8cca42e91faa2ccaa491a 100644 (file)
@@ -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<<n;
        char *t=s;
-       
+
        for(;bit;bit>>=1)
                *t++=(bits&bit)?'1':'0';
        *t=0;
-       
+
        return s;
 }
 
index 09142ec42228ed43541d82655c8a7add8c219979..77467c57a850ebe040244b4df00194d8d4a559ac 100644 (file)
@@ -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;
        }
index eba5ea0e3216a7159152ea9410c67df7303c9e40..4b0ae744a499216ded6fb67082bc118b3563cf67 100644 (file)
@@ -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;
        }
index eacb36dab473ff5597c4013ffa0067cd6e99c519..60aa86238dcfe176befc0083a512556316ead72d 100644 (file)
@@ -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;
        }
index d59843c7a1721442293d98eb2bdcd8ad619ba35a..f2ebebc1abc58e112c77ee76d66e38718c8a2d8e 100644 (file)
@@ -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;
index 1325a4869c1c562621dba0b70f26affb8df402aa..f4a67e0afd9eca846cdbdcf6ed63b7b9c16cdcc7 100644 (file)
@@ -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;
        }