From 4d55a9ca2ca796a47cb358a02a88776c95e3c5ba Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Tue, 7 May 2002 01:32:57 +0000 Subject: [PATCH] Added dummy support for cb_pcidas64 boards that does nothing so far. Slowly getting rid of global variables as I go. --- comedi_calibrate/Makefile | 4 +- comedi_calibrate/calib.h | 18 +++- comedi_calibrate/cb.c | 151 ++++++++++++++++++++++++++++ comedi_calibrate/comedi_calibrate.c | 67 ++++++------ comedi_calibrate/ni.c | 114 ++++++++++++--------- 5 files changed, 267 insertions(+), 87 deletions(-) create mode 100644 comedi_calibrate/cb.c diff --git a/comedi_calibrate/Makefile b/comedi_calibrate/Makefile index 49c0aee..390f6bf 100644 --- a/comedi_calibrate/Makefile +++ b/comedi_calibrate/Makefile @@ -6,8 +6,8 @@ CFLAGS += -I../include LDFLAGS += -L../lib/ -lcomedi -lm -BINS=comedi_calibrate -objs = comedi_calibrate.o ni.o +BINS = comedi_calibrate +objs = comedi_calibrate.o ni.o cb.o all: $(BINS) diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 48a0b7c..b85f9f1 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -45,6 +45,16 @@ typedef struct{ double target; }observable; +typedef struct calibration_setup_struct calibration_setup; +struct calibration_setup_struct { + int status; + observable *observables; + unsigned int n_observables; + caldac *caldacs; + unsigned int n_caldacs; + int (*do_cal) ( calibration_setup *setup ); +}; + extern caldac caldacs[N_CALDACS]; extern int n_caldacs; @@ -79,18 +89,20 @@ void observe(void); void preobserve(int obs); void observable_dependence(int obs); void measure_observable(int obs); -void reset_caldacs(void); +void reset_caldacs( const calibration_setup *setup); /* drivers */ extern char ni_id[]; +extern char cb_id[]; -int ni_setup(void); +int ni_setup( calibration_setup*, const char *device_name ); +int cb_setup( calibration_setup*, const char *device_name ); /* low level */ void set_target(int obs,double target); -void update_caldac(int i); +void update_caldac( caldac ); void setup_caldacs(void); void postgain_cal(int obs1, int obs2, int dac); void cal1(int obs, int dac); diff --git a/comedi_calibrate/cb.c b/comedi_calibrate/cb.c new file mode 100644 index 0000000..720cebc --- /dev/null +++ b/comedi_calibrate/cb.c @@ -0,0 +1,151 @@ +/*************************************************************************** + cb.c - calibration support for some Measurement computing boards. + Based on ni.c by David Schleef. + ------------------- + + begin : Sat Apr 27 2002 + copyright : (C) 2002 by Frank Mori Hess + email : fmhess@users.sourceforge.net + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "calib.h" + + +char cb_id[] = "$Id$"; + +struct board_struct{ + char *name; + int status; + int (*setup)( calibration_setup *setup ); +}; + +int cb_setup_board(void); +void cb_setup_observables(void); + +int setup_cb_pci_64xx( calibration_setup *setup ); +int setup_cb_pci_60xx( calibration_setup *setup ); +int setup_cb_pci_4020( calibration_setup *setup ); + +int cal_cb_pci_64xx( calibration_setup *setup ); +int cal_cb_pci_60xx( calibration_setup *setup ); +int cal_cb_pci_4020( calibration_setup *setup ); + +int init_observables_64xx( calibration_setup *setup ); +int init_observables_60xx( calibration_setup *setup ); +int init_observables_4020( calibration_setup *setup ); + +static struct board_struct boards[]={ + { "pci-das6402/16", STATUS_DONE, setup_cb_pci_64xx }, + { "pci-das6402/12", STATUS_GUESS, setup_cb_pci_64xx }, + { "pci-das64/m1/16", STATUS_GUESS, setup_cb_pci_64xx }, + { "pci-das64/m2/16", STATUS_GUESS, setup_cb_pci_64xx }, + { "pci-das64/m3/16", STATUS_GUESS, setup_cb_pci_64xx }, + { "pci-das6025", STATUS_DONE, setup_cb_pci_60xx }, + { "pci-das6034", STATUS_GUESS, setup_cb_pci_60xx }, + { "pci-das6035", STATUS_GUESS, setup_cb_pci_60xx }, + { "pci-das4020/12", STATUS_DONE, setup_cb_pci_4020 }, +}; + +static const int num_boards = ( sizeof(boards) / sizeof(boards[0]) ); + +enum { + cb_zero_offset_low = 0, + cb_zero_offset_high, + cb_reference_low, + cb_unip_offset_low, + cb_ao0_zero_offset, + cb_ao0_reference, + cb_ao1_zero_offset, + cb_ao1_reference, +}; + +int cb_setup( calibration_setup *setup, const char *device_name ) +{ + unsigned int i; + + for( i = 0; i < num_boards; i++ ) + { + if( !strcmp( devicename, boards[i].name ) ) + { + return boards[i].setup( setup ); + break; + } + } + + return 0; +} + +int setup_cb_pci_64xx( calibration_setup *setup ) +{ + init_observables_64xx( setup ); + setup->do_cal = cal_cb_pci_64xx; + return 0; +} + +int setup_cb_pci_60xx( calibration_setup *setup ) +{ + init_observables_60xx( setup ); + setup->do_cal = cal_cb_pci_60xx; + return 0; +} + +int setup_cb_pci_4020( calibration_setup *setup ) +{ + init_observables_4020( setup ); + setup->do_cal = cal_cb_pci_60xx; + return 0; +} + +int init_observables_64xx( calibration_setup *setup ) +{ + return 0; +} + +int init_observables_60xx( calibration_setup *setup ) +{ + return 0; +} + +int init_observables_4020( calibration_setup *setup ) +{ + return 0; +} + +int cal_cb_pci_64xx( calibration_setup *setup ) +{ + return 0; +} + +int cal_cb_pci_60xx( calibration_setup *setup ) +{ + return 0; +} + +int cal_cb_pci_4020( calibration_setup *setup ) +{ + return 0; +} + diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 4872537..76a3c39 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -61,13 +61,14 @@ int verbose = 0; struct board_struct{ char *name; char *id; - int (*setup)(void); + int (*setup)( calibration_setup *setup, const char *device_name ); }; struct board_struct drivers[] = { { "ni_pcimio", ni_id, ni_setup }, { "ni_atmio", ni_id, ni_setup }, { "ni_mio_cs", ni_id, ni_setup }, + { "cb_pcidas64", cb_id, cb_setup }, }; #define n_drivers (sizeof(drivers)/sizeof(drivers[0])) @@ -104,7 +105,7 @@ int main(int argc, char *argv[]) struct board_struct *this_board; int index; int device_status = STATUS_UNKNOWN; - + calibration_setup setup; fn = "/dev/comedi0"; while (1) { @@ -160,7 +161,9 @@ int main(int argc, char *argv[]) return 1; ok: - device_status = this_board->setup(); + memset( &setup, 0, sizeof( setup ) ); + this_board->setup( &setup, devicename ); + device_status = setup.status; if(device_statusn_caldacs; i++){ + setup->caldacs[i].current = setup->caldacs[i].maxdata / 2; + update_caldac( setup->caldacs[i] ); } } -void update_caldac(int i) +void update_caldac( caldac dac ) { int ret; - - DPRINT(4,"update %d %d %d\n",caldacs[i].subdev,caldacs[i].chan,caldacs[i].current); - if(caldacs[i].current<0){ - DPRINT(1,"caldac set out of range (%d<0)\n",caldacs[i].current); - caldacs[i].current=0; + + DPRINT(4,"update %d %d %d\n", dac.subdev, dac.chan, dac.current); + if( dac.current < 0 ){ + DPRINT(1,"caldac set out of range (%d<0)\n", dac.current); + dac.current = 0; } - if(caldacs[i].current>caldacs[i].maxdata){ + if( dac.current > dac.maxdata ){ DPRINT(1,"caldac set out of range (%d>%d)\n", - caldacs[i].current,caldacs[i].maxdata); - caldacs[i].current=caldacs[i].maxdata; + dac.current, dac.maxdata); + dac.current = dac.maxdata; } - ret = comedi_data_write(dev,caldacs[i].subdev,caldacs[i].chan,0,0, - caldacs[i].current); - if(ret<0)perror("update_caldac()"); + ret = comedi_data_write(dev, dac.subdev, dac.chan, 0, 0, + dac.current); + if(ret < 0) perror("update_caldac()"); } #if 0 @@ -525,7 +528,7 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; caldacs[cdac].current=0; - update_caldac(cdac); + update_caldac( caldacs[cdac] ); usleep(100000); new_sv_measure(&sv); @@ -533,7 +536,7 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) sum_err=0; for(i=0;i*stepyerr=sum_err/sum_err_count; l->dx=step; @@ -603,7 +606,7 @@ double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; caldacs[cdac].current=0; - update_caldac(cdac); + update_caldac( caldacs[cdac] ); usleep(100000); new_sv_measure(&sv); @@ -611,7 +614,7 @@ double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) sum_err=0; for(i=0;iyerr=sum_err/sum_err_count; l->dx=1; diff --git a/comedi_calibrate/ni.c b/comedi_calibrate/ni.c index f7bd2b9..2797d61 100644 --- a/comedi_calibrate/ni.c +++ b/comedi_calibrate/ni.c @@ -41,29 +41,29 @@ char ni_id[] = "$Id$"; struct board_struct{ char *name; int status; - void (*cal)(void); + int (*cal)( calibration_setup *setup); }; -int ni_setup_board(void); +int ni_setup_board( calibration_setup *setup , const char *device_name ); void ni_setup_observables(void); -void cal_ni_at_mio_16e_2(void); -void cal_ni_daqcard_ai_16xe_50(void); -void cal_ni_at_mio_16e_1(void); -void cal_ni_pci_mio_16e_1(void); -void cal_ni_pci_6025e(void); -void cal_ni_pci_6035e(void); -void cal_ni_pci_6071e(void); -void cal_ni_pxi_6071e(void); -void cal_ni_at_mio_16e_10(void); -void cal_ni_pci_mio_16xe_50(void); -void cal_ni_pci_6023e(void); -void cal_ni_pci_6024e(void); -void cal_ni_at_mio_16xe_50(void); -void cal_ni_pci_mio_16xe_10(void); -void cal_ni_pci_6052e(void); - -struct board_struct boards[]={ +int cal_ni_at_mio_16e_2(calibration_setup *setup); +int cal_ni_daqcard_ai_16xe_50(calibration_setup *setup); +int cal_ni_at_mio_16e_1(calibration_setup *setup); +int cal_ni_pci_mio_16e_1(calibration_setup *setup); +int cal_ni_pci_6025e(calibration_setup *setup); +int cal_ni_pci_6035e(calibration_setup *setup); +int cal_ni_pci_6071e(calibration_setup *setup); +int cal_ni_pxi_6071e(calibration_setup *setup); +int cal_ni_at_mio_16e_10(calibration_setup *setup); +int cal_ni_pci_mio_16xe_50(calibration_setup *setup); +int cal_ni_pci_6023e(calibration_setup *setup); +int cal_ni_pci_6024e(calibration_setup *setup); +int cal_ni_at_mio_16xe_50(calibration_setup *setup); +int cal_ni_pci_mio_16xe_10(calibration_setup *setup); +int cal_ni_pci_6052e(calibration_setup *setup); + +static struct board_struct boards[]={ { "at-mio-16e-2", STATUS_DONE, cal_ni_at_mio_16e_2 }, { "DAQCard-ai-16xe-50", STATUS_DONE, cal_ni_daqcard_ai_16xe_50 }, { "at-mio-16xe-50", STATUS_SOME, cal_ni_at_mio_16xe_50 }, @@ -117,31 +117,31 @@ enum { ni_ao1_reference, }; -int ni_setup(void) +int ni_setup( calibration_setup *setup , const char *device_name ) { - int status; - - status = ni_setup_board(); + ni_setup_board( setup, device_name ); + setup->observables = observables; + setup->n_observables = n_observables; + setup->caldacs = caldacs; + setup->n_caldacs = n_caldacs; ni_setup_observables(); setup_caldacs(); - return status; + return 0; } -int ni_setup_board(void) +int ni_setup_board( calibration_setup *setup, const char *device_name ) { int i; - int device_status = STATUS_UNKNOWN; - for(i=0;istatus = boards[i].status; + setup->do_cal = boards[i].cal; break; } } - //do_cal = cal_ni_unknown; - return device_status; + return 0; } void ni_setup_observables(void) @@ -267,7 +267,7 @@ void ni_setup_observables(void) } } -void cal_ni_at_mio_16e_2(void) +int cal_ni_at_mio_16e_2(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); cal1(ni_zero_offset_high,0); @@ -279,6 +279,7 @@ void cal_ni_at_mio_16e_2(void) cal1(ni_ao1_zero_offset,8); cal1(ni_ao1_reference,9); } + return 0; } /* @@ -307,32 +308,34 @@ void cal_ni_at_mio_16e_2(void) * caldac[2] gain=7.8670(11)e-5 V/bit S_min=903.291 dof=254 * caldac[8] gain=2.7732(74)e-7 V/bit S_min=415.399 dof=254 */ -void cal_ni_daqcard_ai_16xe_50(void) +int cal_ni_daqcard_ai_16xe_50(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); cal1(ni_zero_offset_high,8); cal1(ni_reference_low,0); cal1_fine(ni_reference_low,0); cal1(ni_reference_low,1); + return 0; } -void cal_ni_at_mio_16xe_50(void) +int cal_ni_at_mio_16xe_50(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); cal1(ni_zero_offset_high,8); cal1(ni_reference_low,0); cal1_fine(ni_reference_low,0); cal1(ni_reference_low,1); - + if(do_output){ cal1(ni_ao0_zero_offset,6); cal1(ni_ao0_reference,4); cal1(ni_ao1_zero_offset,7); cal1(ni_ao1_reference,5); } + return 0; } -void cal_ni_pci_mio_16xe_10(void) +int cal_ni_pci_mio_16xe_10(calibration_setup *setup) { postgain_cal(ni_zero_offset_low, ni_zero_offset_high, 2); postgain_cal(ni_zero_offset_low, ni_zero_offset_high, 3); @@ -346,14 +349,15 @@ void cal_ni_pci_mio_16xe_10(void) cal1(ni_ao1_zero_offset,7); cal1(ni_ao1_reference,5); } + return 0; } -void cal_ni_at_mio_16e_1(void) +int cal_ni_at_mio_16e_1(calibration_setup *setup) { - cal_ni_at_mio_16e_2(); + return cal_ni_at_mio_16e_2( setup ); } -void cal_ni_pci_mio_16e_1(void) +int cal_ni_pci_mio_16e_1(calibration_setup *setup) { //cal_ni_at_mio_16e_2(); @@ -369,9 +373,10 @@ void cal_ni_pci_mio_16e_1(void) //cal1(ni_ao1_zero_offset,7); /* linearity? */ cal1(ni_ao1_reference,9); } + return 0; } -void cal_ni_pci_6035e(void) +int cal_ni_pci_6035e(calibration_setup *setup) { // 6035e (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); @@ -380,9 +385,10 @@ void cal_ni_pci_6035e(void) if(do_output){ // unknown } + return 0; } -void cal_ni_pci_6071e(void) +int cal_ni_pci_6071e(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); cal1(ni_zero_offset_high,0); @@ -396,9 +402,10 @@ void cal_ni_pci_6071e(void) //cal1(ni_ao1_zero_offset,7); /* linearity? */ cal1(ni_ao1_reference,9); } + return 0; } -void cal_ni_pxi_6071e(void) +int cal_ni_pxi_6071e(calibration_setup *setup) { // 6071e (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); @@ -407,9 +414,10 @@ void cal_ni_pxi_6071e(void) if(do_output){ // unknown } + return 0; } -void cal_ni_at_mio_16e_10(void) +int cal_ni_at_mio_16e_10(calibration_setup *setup) { // 16e-10 (old) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); @@ -423,25 +431,27 @@ void cal_ni_at_mio_16e_10(void) cal1(ni_ao1_zero_offset,8); // guess cal1(ni_ao1_reference,9); // guess } + return 0; } -void cal_ni_pci_mio_16xe_50(void) +int cal_ni_pci_mio_16xe_50(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); cal1(ni_zero_offset_high,8); cal1(ni_reference_low,0); cal1_fine(ni_reference_low,0); cal1(ni_reference_low,1); - + if(do_output){ cal1(ni_ao0_zero_offset,6); cal1(ni_ao0_reference,4); cal1(ni_ao1_zero_offset,7); cal1(ni_ao1_reference,5); } + return 0; } -void cal_ni_pci_6023e(void) +int cal_ni_pci_6023e(calibration_setup *setup) { /* There seems to be a bug in the driver that doesn't allow * access to caldac 10, and possibly others. */ @@ -449,9 +459,10 @@ void cal_ni_pci_6023e(void) //cal1(ni_zero_offset_high,10); //cal1(ni_zero_offset_high,0); cal1(ni_reference_low,3); + return 0; } -void cal_ni_pci_6024e(void) +int cal_ni_pci_6024e(calibration_setup *setup) { /* There seems to be a bug in the driver that doesn't allow * access to caldac 10, and possibly others. */ @@ -467,9 +478,10 @@ void cal_ni_pci_6024e(void) //cal1(ni_ao1_zero_offset,7); // nonlinearity? //cal1(ni_ao1_reference,9); } + return 0; } -void cal_ni_pci_6025e(void) +int cal_ni_pci_6025e(calibration_setup *setup) { postgain_cal(ni_zero_offset_low,ni_zero_offset_high,4); // was 1 //cal1(ni_zero_offset_high,XXX); // was 10 @@ -483,9 +495,10 @@ void cal_ni_pci_6025e(void) //cal1(ni_ao1_zero_offset,1); // nonlinearity was 7 cal1(ni_ao1_reference,5); // was 9 } + return 0; } -void cal_ni_pci_6052e(void) +int cal_ni_pci_6052e(calibration_setup *setup) { /* * This board has noisy caldacs @@ -539,6 +552,7 @@ void cal_ni_pci_6052e(void) cal1(ni_ao1_reference,12+9); cal1(ni_ao1_reference,12+5); } + return 0; } double ni_get_reference(int lsb_loc,int msb_loc) -- 2.26.2