From: Frank Mori Hess Date: Fri, 24 Aug 2007 18:44:38 +0000 (+0000) Subject: Fixed some calculations of number of bytes per scan when doing X-Git-Tag: r0_7_75~38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64f3722ec527d761b15aeb7920f9241d3c867367;p=comedi.git Fixed some calculations of number of bytes per scan when doing digital io commands. --- diff --git a/comedi/drivers/comedi_fc.c b/comedi/drivers/comedi_fc.c index 712f05b9..e38b05d7 100644 --- a/comedi/drivers/comedi_fc.c +++ b/comedi/drivers/comedi_fc.c @@ -28,30 +28,10 @@ #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 ) diff --git a/comedi/drivers/comedi_fc.h b/comedi/drivers/comedi_fc.h index e001ecca..5763a9fa 100644 --- a/comedi/drivers/comedi_fc.h +++ b/comedi/drivers/comedi_fc.h @@ -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 */ diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index fa542f50..870db339 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -50,12 +50,14 @@ //#define USE_KMALLOC +#include "mite.h" + +#include "comedi_fc.h" #include #include #include -#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