Change caldac code to be slightly less confusing
authorDavid Schleef <ds@schleef.org>
Wed, 6 Feb 2002 20:41:21 +0000 (20:41 +0000)
committerDavid Schleef <ds@schleef.org>
Wed, 6 Feb 2002 20:41:21 +0000 (20:41 +0000)
comedi/drivers/ni_atmio.c
comedi/drivers/ni_mio_common.c
comedi/drivers/ni_mio_cs.c
comedi/drivers/ni_pcimio.c
comedi/drivers/ni_stc.h

index 1dccaf4c15b9a3dfbdab0c51687d1ca23864f67f..99c9776e217d58a6d1685bd818866f5417fb9a94 100644 (file)
@@ -108,9 +108,6 @@ External triggering is supported for some events.  The channel index
 
 #define NI_SIZE 0x20
 
-static struct caldac_struct *type1[]={&caldac_mb88341,NULL,NULL};
-static struct caldac_struct *type2[]={&caldac_dac8800,&caldac_dac8043,NULL};
-
 #define MAX_N_CALDACS 12
 
 static ni_board ni_boards[]={
@@ -127,7 +124,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
                has_8255:       0,
-               caldac:         type1,
+               caldac:         {mb88341},
        },
        {       device_id:      25,
                name:           "at-mio-16e-2",
@@ -142,7 +139,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
                has_8255:       0,
-               caldac:         type1,
+               caldac:         {mb88341},
        },
        {       device_id:      36,
                name:           "at-mio-16e-10",
@@ -156,7 +153,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type1,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      37,
@@ -171,7 +168,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type1,
+               caldac:         {mb88341},
                has_8255:       1,
        },
        {       device_id:      38,
@@ -187,7 +184,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
                has_8255:       0,
-               caldac:         type1,
+               caldac:         {mb88341},
        },
        {       device_id:      39,
                name:           "at-mio-16xe-50",
@@ -201,7 +198,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    0,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
                has_8255:       0,
        },
        {       device_id:      50,
@@ -216,7 +213,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,      /* unknown */
                ao_unipolar:    0,      /* unknown */
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
                has_8255:       0,
        },
        {       device_id:      51,
@@ -232,7 +229,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  0,
                aorangelkup:    0,
                ao_unipolar:    0,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
                has_8255:       0,
        }
 };
index fe3bb480c68f8368a1d53f885c9ba6479fdf1f19..4e923b23bc10bc6239fe1d8b694dbb689cfe4947 100644 (file)
@@ -2200,9 +2200,7 @@ static int ni_calib_insn_read(comedi_device *dev,comedi_subdevice *s,
 static int pack_mb88341(int addr,int val,int *bitstring);
 static int pack_dac8800(int addr,int val,int *bitstring);
 static int pack_dac8043(int addr,int val,int *bitstring);
-#ifdef PCIMIO
 static int pack_ad8522(int addr,int val,int *bitstring);
-#endif
 
 struct caldac_struct{
        int n_chans;
@@ -2210,13 +2208,12 @@ struct caldac_struct{
        int (*packbits)(int,int,int *);
 };
 
-static struct caldac_struct caldac_mb88341={ 12, 8, pack_mb88341 };
-static struct caldac_struct caldac_dac8800={ 8, 8, pack_dac8800 };
-static struct caldac_struct caldac_dac8043={ 1, 12, pack_dac8043 };
-#ifdef PCIMIO
-static struct caldac_struct caldac_ad8522={ 2, 12, pack_ad8522 };
-#endif
-
+static struct caldac_struct caldacs[] = {
+       [mb88341] = { 12, 8, pack_mb88341 },
+       [dac8800] = { 8, 8, pack_dac8800 },
+       [dac8043] = { 1, 12, pack_dac8043 },
+       [ad8522]  = { 2, 12, pack_ad8522 },
+};
 
 static void caldac_setup(comedi_device *dev,comedi_subdevice *s)
 {
@@ -2225,13 +2222,16 @@ static void caldac_setup(comedi_device *dev,comedi_subdevice *s)
        int n_chans=0;
        int n_bits;
        int diffbits=0;
+       int type;
        
-       if(!boardtype.caldac[0])return;
-       n_bits=boardtype.caldac[0]->n_bits;
+       type = boardtype.caldac[0];
+       if(type==caldac_none)return;
+       n_bits=caldacs[type].n_bits;
        for(i=0;i<3;i++){
-               if(!boardtype.caldac[i])break;
-               if(boardtype.caldac[i]->n_bits!=n_bits)diffbits=1;
-               n_chans+=boardtype.caldac[i]->n_chans;
+               type = boardtype.caldac[i];
+               if(type==caldac_none)break;
+               if(caldacs[type].n_bits!=n_bits)diffbits=1;
+               n_chans+=caldacs[type].n_chans;
        }
        n_dacs=i;
        s->n_chan=n_chans;
@@ -2245,30 +2245,37 @@ static void caldac_setup(comedi_device *dev,comedi_subdevice *s)
                s->maxdata_list=devpriv->caldac_maxdata_list;
                chan=0;
                for(i=0;i<n_dacs;i++){
-                       for(j=0;j<boardtype.caldac[i]->n_chans;j++){
+                       type = boardtype.caldac[i];
+                       for(j=0;j<caldacs[type].n_chans;j++){
                                s->maxdata_list[chan]=
-                                       (1<<boardtype.caldac[i]->n_bits)-1;
+                                       (1<<caldacs[type].n_bits)-1;
                                chan++;
                        }
                }
        }else{
-               s->maxdata=(1<<boardtype.caldac[0]->n_bits)-1;
+               type = boardtype.caldac[0];
+               s->maxdata=(1<<caldacs[type].n_bits)-1;
        }
 }
 
 static void ni_write_caldac(comedi_device *dev,int addr,int val)
 {
-       int loadbit=0,bits=0,bit,bitstring=0;
+       unsigned int loadbit=0,bits=0,bit,bitstring=0;
        int i;
+       int type;
        
+       //printk("ni_write_caldac: chan=%d val=%d\n",addr,val);
+
        for(i=0;i<3;i++){
-               if(!boardtype.caldac[i])return;
-               if(addr<boardtype.caldac[i]->n_chans){
-                       bits=boardtype.caldac[i]->packbits(addr,val,&bitstring);
+               type = boardtype.caldac[i];
+               if(type==caldac_none)break;
+               if(addr<caldacs[type].n_chans){
+                       bits=caldacs[type].packbits(addr,val,&bitstring);
                        loadbit=SerDacLd(i);
+                       //printk("caldac: using i=%d addr=%d %x\n",i,addr,bitstring);
                        break;
                }
-               addr-=boardtype.caldac[i]->n_chans;
+               addr-=caldacs[type].n_chans;
        }
 
        for(bit=1<<(bits-1);bit;bit>>=1){
@@ -2313,13 +2320,11 @@ static int pack_dac8043(int addr,int val,int *bitstring)
        return 12;
 }
        
-#ifdef PCIMIO
 static int pack_ad8522(int addr,int val,int *bitstring)
 {
        *bitstring=(val&0xfff)|(addr ? 0xc000:0xa000);
        return 16;
 }
-#endif
 
 
 
index f73cf7d246aea4989b73c646a5ad45384412b56e..2d673a13ed2d1ec976791ef7f4b40c98181e9dae 100644 (file)
@@ -73,9 +73,6 @@ See the notes in the ni_atmio.o driver.
 
 #define NI_SIZE 0x20
 
-static struct caldac_struct *type1[]={&caldac_mb88341,NULL,NULL};
-static struct caldac_struct *type2[]={&caldac_dac8800,&caldac_dac8043,NULL};
-
 #define MAX_N_CALDACS 12
 
 static ni_board ni_boards[]={
@@ -92,7 +89,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  0,
                ao_unipolar:    0,
                has_8255:       0,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
        },
        {       device_id:      0x010c,
                name:           "DAQCard-ai-16e-4",
@@ -107,7 +104,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  0,
                ao_unipolar:    0,
                has_8255:       0,
-               caldac:         type1, /* or ad8804 */
+               caldac:         {mb88341}, /* or ad8804 */
        },
        {       device_id:      0x02c4,
                name:           "DAQCard-6062E",
@@ -122,7 +119,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  2048,
                ao_unipolar:    0,
                has_8255:       0,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
        },
        {       device_id:      0x075e,
                name:           "DAQCard-6024E", /* specs incorrect! */
@@ -137,7 +134,7 @@ static ni_board ni_boards[]={
                ao_fifo_depth:  0,
                ao_unipolar:    0,
                has_8255:       0,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043},
        },
 };
 
index 98901113fcdcf8344ada72eea552b9ad7539c22d..1d4b31441df88bbe3f523a82a0b4ccd883c5f785 100644 (file)
@@ -109,11 +109,6 @@ DMA is halfway completed, but not yet operational.
 #define PCIMIO 1
 #undef ATMIO
 
-static struct caldac_struct *type1[]={&caldac_dac8800,&caldac_dac8043,NULL};
-static struct caldac_struct *type2[]={&caldac_dac8800,&caldac_dac8043,&caldac_ad8522};
-static struct caldac_struct *type3[]={&caldac_mb88341,NULL,NULL};
-static struct caldac_struct *type4[]={&caldac_mb88341,&caldac_mb88341,&caldac_ad8522};
-
 #define MAX_N_CALDACS (16+16+2)
 
 #define NI_VENDOR_ID 0x1093
@@ -162,7 +157,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    0,
-               caldac:         type1,
+               caldac:         {dac8800,dac8043},
                has_8255:       0,
        },
        {       device_id:      0x1170,
@@ -177,7 +172,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
        {       device_id:      0x11d0,
@@ -192,7 +187,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
 
@@ -208,7 +203,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x1190,
@@ -223,7 +218,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  512,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x11c0,
@@ -238,7 +233,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  512,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
 
@@ -254,7 +249,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
        {       device_id:      0x1270,
@@ -269,7 +264,7 @@ static ni_board ni_boards[]={
                aobits:         0,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
        {       device_id:      0x1340,
@@ -284,7 +279,7 @@ static ni_board ni_boards[]={
                aobits:         0,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
        {       device_id:      0x1350,
@@ -299,7 +294,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x2a60,
@@ -313,7 +308,7 @@ static ni_board ni_boards[]={
                n_aochan:       0,
                aobits:         0,
                ao_unipolar:    0,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x2a70,
@@ -328,7 +323,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x2a80,
@@ -343,7 +338,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       1,
        },
        {       device_id:      0x2ab0,
@@ -358,7 +353,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    1,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       1,
        },
 
@@ -374,7 +369,7 @@ static ni_board ni_boards[]={
                aobits:         0,
                ao_fifo_depth:  0,
                ao_unipolar:    0,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x2c80,
@@ -389,7 +384,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_fifo_depth:  0,
                ao_unipolar:    0,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
        {       device_id:      0x18b0,
@@ -404,9 +399,9 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    1,
                ao_fifo_depth:  2048,
-               caldac:         type4,
+               caldac:         {mb88341,mb88341,ad8522},
        },
-       {       device_id:      0x14e0,         /* unknown */
+       {       device_id:      0x14e0,
                name:           "pci-6110e",
                n_adchan:       4, 
                adbits:         12,
@@ -417,9 +412,9 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    0,
                ao_fifo_depth:  2048,
-               caldac:         type4,          /* XXX */
+               caldac:         {mb88341,mb88341,ad8522},/* XXX */
        },
-       {       device_id:      0x14f0,         /* unknown */
+       {       device_id:      0x14f0,
                name:           "pci-6111e",
                n_adchan:       2,
                adbits:         12,
@@ -431,7 +426,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  2048,
-               caldac:         type4,          /* XXX */
+               caldac:         {mb88341,mb88341,ad8522},/* XXX */
        },
        {       device_id:      0x1880,
                name:           "pci-6711",
@@ -445,7 +440,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  8192,
-               caldac:         type4,          /* XXX */
+               caldac:         {mb88341,mb88341,ad8522},/* XXX */
        },
        {       device_id:      0x1870,
                name:           "pci-6713",
@@ -459,7 +454,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
-               caldac:         type4,          /* XXX */
+               caldac:         {mb88341,mb88341,ad8522},/* XXX */
        },
         {       device_id:      0x15b0,
                 name:           "pxi-6071e",
@@ -473,7 +468,7 @@ static ni_board ni_boards[]={
                 aobits:         12,
                 ao_fifo_depth:  2048,
                 ao_unipolar:    1,
-                caldac:         type3,
+               caldac:         {mb88341},
                 has_8255:       0,
         },
 
@@ -489,7 +484,7 @@ static ni_board ni_boards[]={
                 aobits:         12,
                 ao_fifo_depth:  2048,
                 ao_unipolar:    1,
-                caldac:         type3,
+               caldac:         {mb88341},
                 has_8255:       0,
         },
        {       device_id:      0x18c0,
@@ -504,7 +499,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    1,
                ao_fifo_depth:  2048,
-               caldac:         type4,
+               caldac:         {mb88341,mb88341,ad8522},
        },
        {       device_id:      0x1580,
                name:           "pxi-6031e",
@@ -518,7 +513,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_fifo_depth:  2048,
                ao_unipolar:    1,
-               caldac:         type2,
+               caldac:         {dac8800,dac8043,ad8522},
        },
        {       device_id:      0x2890,
                name:           "pci-6036e",
@@ -532,7 +527,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_fifo_depth:  0,
                ao_unipolar:    0,
-               caldac:         type3,
+               caldac:         {mb88341},
                has_8255:       0,
        },
 };
index 8615711f6036b4ab08b432b145d4ee5dcb706880..914ef73467ad9e180654caed7f2d47a171018daa 100644 (file)
 */
 
 enum{ ai_gain_16=0, ai_gain_8, ai_gain_14, ai_gain_4, ai_gain_611x };
-extern struct caldac_struct caldac_mb88341,
-       caldac_dac8800,
-       caldac_dac8043,
-       caldac_ad8522;
+enum caldac_enum { caldac_none=0, mb88341, dac8800, dac8043, ad8522 };
 
 typedef struct ni_board_struct{
        int device_id;
@@ -597,7 +594,7 @@ typedef struct ni_board_struct{
 
        int has_analog_trig : 1;
 
-       struct caldac_struct **caldac;
+       enum caldac_enum caldac[3];
 }ni_board;
 
 static ni_board ni_boards[];