Added support for various m-series ao ranges.
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 21 Dec 2005 03:04:52 +0000 (03:04 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 21 Dec 2005 03:04:52 +0000 (03:04 +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 cc24fad3c279dab1beb2ba7d7b5f50cf460d11d1..684342ebf8c6bfba58b66ba67f431220c3a30706 100644 (file)
@@ -128,6 +128,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                has_8255:       0,
                caldac:         {mb88341},
@@ -144,6 +145,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                has_8255:       0,
                caldac:         {mb88341},
@@ -160,6 +162,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -176,6 +179,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804_debug},
                has_8255:       1,
@@ -192,6 +196,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                has_8255:       0,
                caldac:         {ad8804_debug},
@@ -208,6 +213,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {dac8800,dac8043},
                has_8255:       0,
@@ -224,6 +230,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
@@ -240,7 +247,6 @@ static ni_board ni_boards[]={
                n_aochan:       0,
                aobits:         0,
                ao_fifo_depth:  0,
-               aorangelkup:    0,
                ao_unipolar:    0,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
index 00501795f754be5e7fd598e7f3eae1adfa03cde2..0de835510230cf59589e9b93f3dd337d3659adcd 100644 (file)
@@ -149,7 +149,7 @@ static comedi_lrange range_ni_E_ai_611x={ 8, {
        RANGE( -0.5,    0.5     ),
        RANGE( -0.2,    0.2     ),
 }};
-static comedi_lrange range_ni_E_ai_622x={ 8, {
+static comedi_lrange range_ni_M_ai_622x={ 8, {
        RANGE(-10, 10),
        RANGE(-5, 5),
        RANGE(-1, 1),
@@ -172,7 +172,7 @@ static comedi_lrange *ni_range_lkup[]={
        &range_ni_E_ai_limited14,
        &range_ni_E_ai_bipolar4,
        &range_ni_E_ai_611x,
-       &range_ni_E_ai_622x
+       &range_ni_M_ai_622x
 };
 
 
@@ -2021,27 +2021,42 @@ static int ni_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s,
                range = CR_RANGE(chanspec[i]);
                if(boardtype.reg_type == ni_reg_m_series)
                {
+                       comedi_krange *krange = s->range_table->range + range;
+                       invert = 0;
                        conf = 0;
-                       if((range&1) == 0){
-                               conf |= MSeries_AO_Bipolar_Bit;
-                               invert = (1<<(boardtype.aobits-1));
-                       }else{
-                               invert = 0;
-                       }
-                       if(range&2)
-                       {
-                       //FIXME: don't know external ao reference bit for m series
-                               /*conf |= AO_Ext_Ref;*/
-                       }else
+                       switch(krange->max - krange->min)
                        {
-                               conf |= MSeries_AO_DAC_Reference_Internal_Bits;
+                       case 20000000:
+                               conf |= MSeries_AO_DAC_Reference_10V_Internal_Bits;
+                               ni_writeb(0, M_Offset_AO_Reference_Attenuation(chan));
+                               break;
+                       case 10000000:
+                               conf |= MSeries_AO_DAC_Reference_5V_Internal_Bits;
+                               ni_writeb(0, M_Offset_AO_Reference_Attenuation(chan));
+                               break;
+                       case 4000000:
+                               conf |= MSeries_AO_DAC_Reference_10V_Internal_Bits;
+                               ni_writeb(MSeries_Attenuate_x5_Bit, M_Offset_AO_Reference_Attenuation(chan));
+                               break;
+                       case 2000000:
+                               conf |= MSeries_AO_DAC_Reference_5V_Internal_Bits;
+                               ni_writeb(MSeries_Attenuate_x5_Bit, M_Offset_AO_Reference_Attenuation(chan));
+                               break;
+                       default:
+                               rt_printk("%s: bug! unhandled ao reference voltage\n", __FUNCTION__);
+                               break;
                        }
-                       if(CR_AREF(chanspec[i])==AREF_OTHER)
-                       {
-                       //FIXME: don't know code for unusual ao offset configurations
-                       }else
+                       switch(krange->max + krange->min)
                        {
-                               conf |= MSeries_AO_DAC_Offset_AO_Ground_Bits;
+                       case 0:
+                               conf |= MSeries_AO_DAC_Offset_0V_Bits;
+                               break;
+                       case 10000000:
+                               conf |= MSeries_AO_DAC_Offset_5V_Bits;
+                               break;
+                       default:
+                               rt_printk("%s: bug! unhandled ao offset voltage\n", __FUNCTION__);
+                               break;
                        }
                        ni_writeb(conf, M_Offset_AO_Config_Bank(chan));
                }else
@@ -2774,11 +2789,7 @@ static int ni_E_init(comedi_device *dev,comedi_devconfig *it)
                s->subdev_flags=SDF_WRITABLE|SDF_DEGLITCH|SDF_GROUND;
                s->n_chan=boardtype.n_aochan;
                s->maxdata=(1<<boardtype.aobits)-1;
-               if(boardtype.ao_unipolar){
-                       s->range_table=&range_ni_E_ao_ext;      /* XXX wrong for some boards */
-               }else{
-                       s->range_table=&range_bipolar10;
-               }
+               s->range_table = boardtype.ao_range_table;
                s->insn_read=ni_ao_insn_read;
                if(boardtype.reg_type & ni_reg_6xxx_mask){
                        s->insn_write=ni_ao_insn_write_671x;
index 06b4886efe87c3e2c4b893f2cb67002a53de11f9..6d2eb690582e148ee41eb7c1f9d8baa3c3c95406 100644 (file)
@@ -109,6 +109,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                has_8255:       0,
                caldac:         {ad8804_debug}, /* verified */
@@ -124,6 +125,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                has_8255:       0,
                caldac:         {ad8804_debug},
@@ -139,6 +141,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                has_8255:       0,
                caldac:         {ad8804_debug},
index a656eb14f43bb9798cd80d1f4103b80047c80b44..f0f654926e4c2d4f5060288af4a67e445012f844 100644 (file)
@@ -162,6 +162,33 @@ static struct pci_device_id ni_pci_table[] __devinitdata = {
 };
 MODULE_DEVICE_TABLE(pci, ni_pci_table);
 
+/* These are not all the possible ao ranges for 628x boards.
+ They can do OFFSET +- REFERENCE where OFFSET can be
+ 0V, 5V, APFI<0,1>, or AO<0...3> and RANGE can
+ be 10V, 5V, 2V, 1V, APFI<0,1>, AO<0...3>.  That's
+ 63 different possibilities.  An AO channel
+ can not act as it's own OFFSET or REFERENCE.
+*/
+static comedi_lrange range_ni_M_628x_ao = { 8, {
+       RANGE(-10, 10),
+       RANGE(-5, 5),
+       RANGE(-2, 2),
+       RANGE(-1, 1),
+       RANGE(-5, 15),
+       RANGE(0, 10),
+       RANGE(3, 7),
+       RANGE(4, 6),
+       RANGE_ext(-1, 1)
+}};
+static comedi_lrange range_ni_M_625x_ao = { 3, {
+       RANGE(-10, 10),
+       RANGE(-5, 5),
+       RANGE_ext(-1, 1)
+}};
+static comedi_lrange range_ni_M_622x_ao = { 1, {
+       RANGE(-10, 10),
+}};
+
 static ni_board ni_boards[]={
        {       device_id:      0x0162, // NI also says 0x1620.  typo?
                name:           "pci-mio-16xe-50",
@@ -174,6 +201,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {dac8800,dac8043},
                has_8255:       0,
@@ -189,6 +217,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
@@ -204,6 +233,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -219,6 +249,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
@@ -235,6 +266,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {mb88341},
                has_8255:       0,
@@ -252,6 +284,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  512,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804_debug}, // doc says mb88341
                has_8255:       0,
@@ -267,6 +300,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  512,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {mb88341},
                has_8255:       0,
@@ -283,6 +317,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
@@ -298,7 +333,7 @@ static ni_board ni_boards[]={
                n_aochan:       0,
                aobits:         0,
                ao_fifo_depth:  0,
-               ao_unipolar:    1,
+               ao_unipolar:    0,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
@@ -313,7 +348,7 @@ static ni_board ni_boards[]={
                n_aochan:       0,
                aobits:         0,
                ao_fifo_depth:  0,
-               ao_unipolar:    1,
+               ao_unipolar:    0,
                caldac:         {dac8800,dac8043,ad8522},
                has_8255:       0,
        },
@@ -328,6 +363,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -357,6 +393,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {ad8804}, /* manual is wrong */
                has_8255:       0,
@@ -372,6 +409,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {ad8804}, /* manual is wrong */
                has_8255:       1,
@@ -387,6 +425,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804}, /* manual is wrong */
                has_8255:       1,
@@ -418,6 +457,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -434,6 +474,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    1,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                caldac:         {ad8804_debug,ad8804_debug,ad8522}, /* manual is wrong */
        },
 #if 0
@@ -449,6 +490,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    1,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                caldac:         {ad8804,mb88341,ad8522}, /* manual is wrong */
        },
 #endif
@@ -463,6 +505,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                reg_type:       ni_reg_611x,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                ao_fifo_depth:  2048,
                caldac:         {ad8804,ad8804},
@@ -478,6 +521,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                reg_type:       ni_reg_611x,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                ao_fifo_depth:  2048,
                caldac:         {ad8804,ad8804},
@@ -526,6 +570,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  16384, /* data sheet says 8192, but fifo really holds 16384 samples */
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6711,
                caldac:         {ad8804_debug},
        },
@@ -536,6 +581,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6711,
                caldac:         {ad8804_debug},
        },
@@ -546,6 +592,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6713,
                caldac:         {ad8804_debug,ad8804_debug},
        },
@@ -556,6 +603,7 @@ static ni_board ni_boards[]={
                aobits:         12,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6713,
                caldac:         {ad8804_debug,ad8804_debug},
        },
@@ -566,6 +614,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    0,
                ao_fifo_depth:  8192,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6711,
                caldac:         {ad8804_debug},
        },
@@ -577,6 +626,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    0,
                ao_fifo_depth:  8192,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6711,
                caldac:         {ad8804_debug},
        },
@@ -588,6 +638,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6713,
                caldac:         {ad8804_debug,ad8804_debug},
        },
@@ -598,6 +649,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    0,
                ao_fifo_depth:  16384,
+               .ao_range_table = &range_bipolar10,
                reg_type:       ni_reg_6713,
                caldac:         {ad8804_debug,ad8804_debug},
        },
@@ -612,6 +664,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -627,6 +680,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         12,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {mb88341},
                has_8255:       0,
@@ -643,6 +697,7 @@ static ni_board ni_boards[]={
                aobits:         16,
                ao_unipolar:    1,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                caldac:         {mb88341,mb88341,ad8522},
        },
        {       device_id:      0x1580,
@@ -656,6 +711,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  2048,
+               .ao_range_table = &range_ni_E_ao_ext,
                ao_unipolar:    1,
                caldac:         {dac8800,dac8043,ad8522},
        },
@@ -670,6 +726,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  0,
+               .ao_range_table = &range_bipolar10,
                ao_unipolar:    0,
                caldac:         {ad8804_debug},
                has_8255:       0,
@@ -699,6 +756,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_622x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       1200,
@@ -715,6 +773,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_622x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       1200,
@@ -747,6 +806,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_622x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       1200,
@@ -763,6 +823,7 @@ static ni_board ni_boards[]={
                n_aochan:       4,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_622x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       1200,
@@ -794,6 +855,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_625x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       357,
@@ -825,6 +887,7 @@ static ni_board ni_boards[]={
                n_aochan:       4,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_625x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    0,
 //             ao_speed:       357,
@@ -856,6 +919,7 @@ static ni_board ni_boards[]={
                n_aochan:       2,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_628x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    1,
 //             ao_speed:       357,
@@ -887,6 +951,7 @@ static ni_board ni_boards[]={
                n_aochan:       4,
                aobits:         16,
                ao_fifo_depth:  8191,
+               .ao_range_table = &range_ni_M_628x_ao,
                reg_type:       ni_reg_m_series,
                ao_unipolar:    1,
 //             ao_speed:       357,
index 562d180e74fa3b6b3ecd96aa7e4f92028b7c9942..952f2ef74476943c5b7a6babc0be70e16b2c24d8 100644 (file)
@@ -770,6 +770,8 @@ enum ni_reg_type {
        ni_reg_m_series = 0x8
 };
 
+static comedi_lrange range_ni_E_ao_ext;
+
 enum m_series_register_offsets
 {
        M_Offset_CDIO_DMA_Select = 0x7, // write
@@ -994,8 +996,8 @@ typedef struct ni_board_struct{
        int aobits;
 
        int ao_fifo_depth;
-       int aorangelkup;
-
+       comedi_lrange *ao_range_table;
+       
        int reg_type;
 
        unsigned int ao_unipolar : 1;