fix rounding error in bytes_per_scan() for dio subdevices, noted by
authorFrank Mori Hess <fmhess@speakeasy.net>
Tue, 25 Jan 2005 23:41:58 +0000 (23:41 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Tue, 25 Jan 2005 23:41:58 +0000 (23:41 +0000)
 Ian Abbott <abbotti@mev.co.uk>.  Also, round to nearest sampl_t or
 lsampl_t size, instead of nearest byte size.

comedi/drivers/comedi_fc.c

index fc0cedb89df2ce59dff4ae296c824da4f543b868..629c4b6c8593b650ca48bb79faff25ee5f87481f 100644 (file)
 
 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:
-                       return subd->async->cmd.chanlist_len / 8;
+                       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 subd->async->cmd.chanlist_len * bytes_per_sample( subd );
+       return num_samples * bytes_per_sample( subd );
 }
 
 static void increment_scan_progress( comedi_subdevice *subd, unsigned int num_bytes )