Fixed some calculations of number of bytes per scan when doing
authorFrank Mori Hess <fmhess@speakeasy.net>
Fri, 24 Aug 2007 18:44:38 +0000 (18:44 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Fri, 24 Aug 2007 18:44:38 +0000 (18:44 +0000)
digital io commands.

comedi/drivers/comedi_fc.c
comedi/drivers/comedi_fc.h
comedi/drivers/mite.c

index 712f05b96de7500d8d33f5ac2d0566c26c55503e..e38b05d7058ecc4073be9ad0b93ef27a42ed1bb9 100644 (file)
 
 #include "comedi_fc.h"
 
-static inline unsigned int bytes_per_scan( comedi_subdevice *subd )
-{
-       int num_samples;
-       int bits_per_sample;
-
-       switch( subd->type )
-       {
-               case COMEDI_SUBD_DI:
-               case COMEDI_SUBD_DO:
-               case COMEDI_SUBD_DIO:
-                       bits_per_sample = 8 * bytes_per_sample(subd);
-                       num_samples = (subd->async->cmd.chanlist_len + bits_per_sample - 1) / bits_per_sample;
-                       break;
-               default:
-                       num_samples = subd->async->cmd.chanlist_len;
-                       break;
-       }
-       return num_samples * bytes_per_sample( subd );
-}
-
 static void increment_scan_progress( comedi_subdevice *subd, unsigned int num_bytes )
 {
        comedi_async *async = subd->async;
-       unsigned int scan_length = bytes_per_scan( subd );
+       unsigned int scan_length = cfc_bytes_per_scan(subd);
 
        async->scan_progress += num_bytes;
        if( async->scan_progress >= scan_length )
index e001ecca439c8364a0524cbd3103878b9128d50d..5763a9fa9dc1979b87a5b5169f0577818d55a827 100644 (file)
@@ -50,4 +50,24 @@ extern unsigned int cfc_read_array_from_buffer( comedi_subdevice *subd, void *da
 
 extern unsigned int cfc_handle_events( comedi_device *dev, comedi_subdevice *subd );
 
+inline unsigned int cfc_bytes_per_scan(comedi_subdevice *subd)
+{
+       int num_samples;
+       int bits_per_sample;
+
+       switch(subd->type)
+       {
+               case COMEDI_SUBD_DI:
+               case COMEDI_SUBD_DO:
+               case COMEDI_SUBD_DIO:
+                       bits_per_sample = 8 * bytes_per_sample(subd);
+                       num_samples = (subd->async->cmd.chanlist_len + bits_per_sample - 1) / bits_per_sample;
+                       break;
+               default:
+                       num_samples = subd->async->cmd.chanlist_len;
+                       break;
+       }
+       return num_samples * bytes_per_sample(subd);
+}
+
 #endif /* _COMEDI_FC_H */
index fa542f50d79b81c9e696ff04a401a7dfb017f073..870db3391bd3867eb5ae810e30f314c6e93e714d 100644 (file)
 
 //#define USE_KMALLOC
 
+#include "mite.h"
+
+#include "comedi_fc.h"
 #include <linux/comedidev.h>
 
 #include <linux/pci.h>
 #include <asm/system.h>
 
-#include "mite.h"
 
 #define PCI_MITE_SIZE          4096
 #define PCI_DAQ_SIZE           4096
@@ -518,7 +520,7 @@ int mite_sync_input_dma(struct mite_channel *mite_chan, comedi_async *async)
 {
        int count;
        unsigned int nbytes, old_alloc_count;
-       unsigned int bytes_per_scan = bytes_per_sample(async->subdevice) * async->cmd.chanlist_len;
+       const unsigned bytes_per_scan = cfc_bytes_per_scan(async->subdevice);
 
        old_alloc_count = async->buf_write_alloc_count;
        // write alloc as much as we can
@@ -556,8 +558,7 @@ int mite_sync_output_dma(struct mite_channel *mite_chan, comedi_async *async)
        int count;
        u32 nbytes_ub, nbytes_lb;
        unsigned int old_alloc_count;
-       u32 stop_count = async->cmd.stop_arg * bytes_per_sample(async->subdevice) *
-               async->cmd.chanlist_len;        //FIXME will be wrong for digital commands
+       u32 stop_count = async->cmd.stop_arg * cfc_bytes_per_scan(async->subdevice);
 
        old_alloc_count = async->buf_read_alloc_count;
        // read alloc as much as we can