From 21d7877c2d39d46c6eb02085fcd48dfe95a9e98e Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Tue, 30 Apr 2002 22:56:30 +0000 Subject: [PATCH] Horrible hack to allow passing of CR flags through channel arguments. Made comedi_calibrate use comedi_data_read_n() from main library. Should be able to add computer boards support to comedi_calibrate soon now. --- comedi_calibrate/calib.h | 1 + comedi_calibrate/comedi_calibrate.c | 68 ++++++++++------------------- include/comedi.h | 2 + lib/data.c | 16 +++---- 4 files changed, 33 insertions(+), 54 deletions(-) diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 12a1764..48a0b7c 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -169,6 +169,7 @@ typedef struct{ int range; int subd; int chan; + int cr_flags; comedi_range *rng; diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 26208b1..4872537 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -257,7 +257,9 @@ void measure_observable(int obs) CR_RANGE(observables[obs].observe_insn.chanspec), CR_AREF(observables[obs].observe_insn.chanspec)); sv.order=7; - n=new_sv_measure(&sv); + // read internal calibration source and turn on dithering + sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; + n = new_sv_measure(&sv); sci_sprint_alt(s,sv.average,sv.error); DPRINT(0,"offset %s, target %g\n",s,observables[obs].target); @@ -519,6 +521,8 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) CR_CHAN(ad_chanspec), CR_RANGE(ad_chanspec), CR_AREF(ad_chanspec)); + // read internal calibration source and turn on dithering + sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; caldacs[cdac].current=0; update_caldac(cdac); @@ -595,6 +599,8 @@ double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) CR_CHAN(ad_chanspec), CR_RANGE(ad_chanspec), CR_AREF(ad_chanspec)); + // read internal calibration source and turn on dithering + sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; caldacs[cdac].current=0; update_caldac(cdac); @@ -725,6 +731,8 @@ double read_chan(int adc,int range) new_sv_init(&sv,dev,0,adc,range,AREF_OTHER); sv.order=7; + sv.cr_flags = CR_ALT_FILTER; + n=new_sv_measure(&sv); sci_sprint_alt(str,sv.average,sv.error); @@ -740,6 +748,9 @@ int read_chan2(char *s,int adc,int range) new_sv_init(&sv,dev,0,adc,range,AREF_OTHER); sv.order=7; + // turn on dithering + sv.cr_flags = CR_ALT_FILTER; + n=new_sv_measure(&sv); return sci_sprint_alt(s,sv.average,sv.error); @@ -779,35 +790,6 @@ int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int are return 0; } -int comedi_data_read_n(comedi_t *it,unsigned int subdev,unsigned int chan, - unsigned int range,unsigned int aref,lsampl_t *data,unsigned int n) -{ - comedi_insn insn; - int ret; - - if(n==0)return 0; - - insn.insn = INSN_READ; - insn.n = n; - insn.data = data; - insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,range,aref); - /* enable dithering */ - insn.chanspec |= (1<<26); - - ret = comedi_do_insn(it,&insn); - - if(ret>0)return n; - - printf("insn barfed: subdev=%d, chan=%d, range=%d, aref=%d, " - "n=%d, ret=%d, %s\n",subdev,chan,range,aref,n,ret, - strerror(errno)); - printf("please report this error\n"); - exit(1); - - return ret; -} - int new_sv_measure(new_sv_t *sv) { lsampl_t *data; @@ -824,14 +806,11 @@ int new_sv_measure(new_sv_t *sv) exit(1); } - for(i=0;isubd,sv->chan,sv->range, - sv->aref,data+i,n-i); - if(ret<0){ - printf("barf\n"); - goto out; - } - i+=ret; + ret = comedi_data_read_n(dev, sv->subd, sv->chan | sv->cr_flags, sv->range, + sv->aref, data, n); + if(ret<0){ + printf("barf\n"); + goto out; } s=0; @@ -869,14 +848,11 @@ int new_sv_measure_order(new_sv_t *sv,int order) exit(1); } - for(i=0;isubd,sv->chan,sv->range, - sv->aref,data+i,n-i); - if(ret<0){ - printf("barf order\n"); - goto out; - } - i+=ret; + ret = comedi_data_read_n(dev, sv->subd, sv->chan | sv->cr_flags, sv->range, + sv->aref, data, n); + if(ret<0){ + printf("barf order\n"); + goto out; } s=0; diff --git a/include/comedi.h b/include/comedi.h index 8ebb5eb..d1a8267 100644 --- a/include/comedi.h +++ b/include/comedi.h @@ -52,11 +52,13 @@ typedef unsigned short sampl_t; /* packs and unpacks a channel/range number */ #define CR_PACK(chan,rng,aref) ( (((aref)&0x3)<<24) | (((rng)&0xff)<<16) | ((chan)&0xffff) ) +#define CR_PACK_FLAGS(chan, range, aref, flags) (CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK)) #define CR_CHAN(a) ((a)&0xffff) #define CR_RANGE(a) (((a)>>16)&0xff) #define CR_AREF(a) (((a)>>24)&0x03) +#define CR_FLAGS_MASK 0xfc000000 #define CR_ALT_FILTER (1<<26) #define CR_DITHER CR_ALT_FILTER #define CR_DEGLITCH CR_ALT_FILTER diff --git a/lib/data.c b/lib/data.c index 0028fc4..68d97f4 100644 --- a/lib/data.c +++ b/lib/data.c @@ -86,7 +86,7 @@ int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne } static inline int comedi_internal_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, - unsigned int aref, lsampl_t *data, unsigned int n) + unsigned int aref, unsigned int flags, lsampl_t *data, unsigned int n) { subdevice *s; @@ -104,7 +104,7 @@ static inline int comedi_internal_data_read_n(comedi_t *it, unsigned int subdev, insn.n = n; insn.data = data; insn.subdev = subdev; - insn.chanspec = CR_PACK(chan,range,aref); + insn.chanspec = CR_PACK_FLAGS(chan,range,aref,flags); return comedi_do_insn(it,&insn); }else{ @@ -121,7 +121,7 @@ static inline int comedi_internal_data_read_n(comedi_t *it, unsigned int subdev, sampl_t sdata[n]; unsigned int i; - chan=CR_PACK(chan,range,aref); + chan=CR_PACK_FLAGS(chan,range,aref,flags); cmd.subdev=subdev; cmd.chanlist=&chan; @@ -158,7 +158,7 @@ int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, uns chunk_size = max_chunk_size; else chunk_size = n; - retval = comedi_internal_data_read_n( it, subdev, chan, range, aref, &data[sample_count], chunk_size); + retval = comedi_internal_data_read_n( it, subdev, chan, range, aref, chan, &data[sample_count], chunk_size); if( retval < 0 ) return retval; n -= chunk_size; sample_count += chunk_size; @@ -169,14 +169,14 @@ int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, uns int comedi_data_read(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, unsigned int aref, lsampl_t *data) { - return comedi_internal_data_read_n(it, subdev, chan, range, aref, data, 1); + return comedi_internal_data_read_n(it, subdev, chan, range, aref, chan, data, 1); } int comedi_data_read_hint(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range, unsigned int aref) { lsampl_t dummy_data; - return comedi_internal_data_read_n(it, subdev, chan, range, aref, &dummy_data, 0); + return comedi_internal_data_read_n(it, subdev, chan, range, aref, chan, &dummy_data, 0); } int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, @@ -200,7 +200,7 @@ int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int ch insn[0].n = 0; insn[0].data = data; insn[0].subdev = subdev; - insn[0].chanspec = CR_PACK( chan, range, aref ); + insn[0].chanspec = CR_PACK_FLAGS( chan, range, aref, chan ); // delay insn[1].insn = INSN_WAIT; insn[1].n = 1; @@ -210,7 +210,7 @@ int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int ch insn[2].n = 1; insn[2].data = data; insn[2].subdev = subdev; - insn[2].chanspec = CR_PACK( chan, range, aref ); + insn[2].chanspec = CR_PACK_FLAGS( chan, range, aref, chan ); ilist.insns = insn; ilist.n_insns = sizeof(insn) / sizeof(insn[0]); -- 2.26.2