41
41
#define PCI171X_AD_DATA_REG 0x00 /* R: A/D data */
42
42
#define PCI171X_SOFTTRG_REG 0x00 /* W: soft trigger for A/D */
43
43
#define PCI171X_RANGE_REG 0x02 /* W: A/D gain/range register */
44
+ #define PCI171X_RANGE_DIFF BIT(5)
45
+ #define PCI171X_RANGE_UNI BIT(4)
46
+ #define PCI171X_RANGE_GAIN (x ) (((x) & 0x7) << 0)
44
47
#define PCI171X_MUX_REG 0x04 /* W: A/D multiplexor control */
45
48
#define PCI171X_STATUS_REG 0x06 /* R: status register */
46
49
#define PCI171X_STATUS_IRQ BIT(11) /* 1=IRQ occurred */
63
66
#define PCI171X_DO_REG 0x10 /* W: digital outputs */
64
67
#define PCI171X_TIMER_BASE 0x18 /* R/W: 8254 timer */
65
68
66
- static const struct comedi_lrange range_pci1710_3 = {
69
+ static const struct comedi_lrange pci1710_ai_range = {
67
70
9 , {
68
- BIP_RANGE (5 ),
69
- BIP_RANGE (2.5 ),
70
- BIP_RANGE (1.25 ),
71
- BIP_RANGE (0.625 ),
72
- BIP_RANGE (10 ),
73
- UNI_RANGE (10 ),
74
- UNI_RANGE (5 ),
75
- UNI_RANGE (2.5 ),
76
- UNI_RANGE (1.25 )
71
+ BIP_RANGE (5 ), /* gain 1 (0x00) */
72
+ BIP_RANGE (2.5 ), /* gain 2 (0x01) */
73
+ BIP_RANGE (1.25 ), /* gain 4 (0x02) */
74
+ BIP_RANGE (0.625 ), /* gain 8 (0x03) */
75
+ BIP_RANGE (10 ), /* gain 0.5 (0x04) */
76
+ UNI_RANGE (10 ), /* gain 1 (0x00 | UNI) */
77
+ UNI_RANGE (5 ), /* gain 2 (0x01 | UNI) */
78
+ UNI_RANGE (2.5 ), /* gain 4 (0x02 | UNI) */
79
+ UNI_RANGE (1.25 ) /* gain 8 (0x03 | UNI) */
77
80
}
78
81
};
79
82
80
- static const char range_codes_pci1710_3 [] = { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 ,
81
- 0x10 , 0x11 , 0x12 , 0x13 };
82
-
83
- static const struct comedi_lrange range_pci1710hg = {
83
+ static const struct comedi_lrange pci1710hg_ai_range = {
84
84
12 , {
85
- BIP_RANGE (5 ),
86
- BIP_RANGE (0.5 ),
87
- BIP_RANGE (0.05 ),
88
- BIP_RANGE (0.005 ),
89
- BIP_RANGE (10 ),
90
- BIP_RANGE (1 ),
91
- BIP_RANGE (0.1 ),
92
- BIP_RANGE (0.01 ),
93
- UNI_RANGE (10 ),
94
- UNI_RANGE (1 ),
95
- UNI_RANGE (0.1 ),
96
- UNI_RANGE (0.01 )
85
+ BIP_RANGE (5 ), /* gain 1 (0x00) */
86
+ BIP_RANGE (0.5 ), /* gain 10 (0x01) */
87
+ BIP_RANGE (0.05 ), /* gain 100 (0x02) */
88
+ BIP_RANGE (0.005 ), /* gain 1000 (0x03) */
89
+ BIP_RANGE (10 ), /* gain 0.5 (0x04) */
90
+ BIP_RANGE (1 ), /* gain 5 (0x05) */
91
+ BIP_RANGE (0.1 ), /* gain 50 (0x06) */
92
+ BIP_RANGE (0.01 ), /* gain 500 (0x07) */
93
+ UNI_RANGE (10 ), /* gain 1 (0x00 | UNI) */
94
+ UNI_RANGE (1 ), /* gain 10 (0x01 | UNI) */
95
+ UNI_RANGE (0.1 ), /* gain 100 (0x02 | UNI) */
96
+ UNI_RANGE (0.01 ) /* gain 1000 (0x03 | UNI) */
97
97
}
98
98
};
99
99
100
- static const char range_codes_pci1710hg [] = { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 ,
101
- 0x05 , 0x06 , 0x07 , 0x10 , 0x11 ,
102
- 0x12 , 0x13 };
103
-
104
- static const struct comedi_lrange range_pci17x1 = {
100
+ static const struct comedi_lrange pci1711_ai_range = {
105
101
5 , {
106
- BIP_RANGE (10 ),
107
- BIP_RANGE (5 ),
108
- BIP_RANGE (2.5 ),
109
- BIP_RANGE (1.25 ),
110
- BIP_RANGE (0.625 )
102
+ BIP_RANGE (10 ), /* gain 1 (0x00) */
103
+ BIP_RANGE (5 ), /* gain 2 (0x01) */
104
+ BIP_RANGE (2.5 ), /* gain 4 (0x02) */
105
+ BIP_RANGE (1.25 ), /* gain 8 (0x03) */
106
+ BIP_RANGE (0.625 ) /* gain 16 (0x04) */
111
107
}
112
108
};
113
109
114
- static const char range_codes_pci17x1 [] = { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 };
115
-
116
110
static const struct comedi_lrange pci171x_ao_range = {
117
111
2 , {
118
112
UNI_RANGE (5 ),
@@ -132,7 +126,6 @@ struct boardtype {
132
126
const char * name ; /* board name */
133
127
int n_aichan ; /* num of A/D chans */
134
128
const struct comedi_lrange * rangelist_ai ; /* rangelist for A/D */
135
- const char * rangecode_ai ; /* range codes for programming */
136
129
unsigned int is_pci1713 :1 ;
137
130
unsigned int has_large_fifo :1 ; /* 4K or 1K FIFO */
138
131
unsigned int has_diff_ai :1 ;
@@ -144,8 +137,7 @@ static const struct boardtype boardtypes[] = {
144
137
[BOARD_PCI1710 ] = {
145
138
.name = "pci1710" ,
146
139
.n_aichan = 16 ,
147
- .rangelist_ai = & range_pci1710_3 ,
148
- .rangecode_ai = range_codes_pci1710_3 ,
140
+ .rangelist_ai = & pci1710_ai_range ,
149
141
.has_large_fifo = 1 ,
150
142
.has_diff_ai = 1 ,
151
143
.has_ao = 1 ,
@@ -154,8 +146,7 @@ static const struct boardtype boardtypes[] = {
154
146
[BOARD_PCI1710HG ] = {
155
147
.name = "pci1710hg" ,
156
148
.n_aichan = 16 ,
157
- .rangelist_ai = & range_pci1710hg ,
158
- .rangecode_ai = range_codes_pci1710hg ,
149
+ .rangelist_ai = & pci1710hg_ai_range ,
159
150
.has_large_fifo = 1 ,
160
151
.has_diff_ai = 1 ,
161
152
.has_ao = 1 ,
@@ -164,25 +155,22 @@ static const struct boardtype boardtypes[] = {
164
155
[BOARD_PCI1711 ] = {
165
156
.name = "pci1711" ,
166
157
.n_aichan = 16 ,
167
- .rangelist_ai = & range_pci17x1 ,
168
- .rangecode_ai = range_codes_pci17x1 ,
158
+ .rangelist_ai = & pci1711_ai_range ,
169
159
.has_ao = 1 ,
170
160
.has_di_do = 1 ,
171
161
},
172
162
[BOARD_PCI1713 ] = {
173
163
.name = "pci1713" ,
174
164
.n_aichan = 32 ,
175
- .rangelist_ai = & range_pci1710_3 ,
176
- .rangecode_ai = range_codes_pci1710_3 ,
165
+ .rangelist_ai = & pci1710_ai_range ,
177
166
.is_pci1713 = 1 ,
178
167
.has_large_fifo = 1 ,
179
168
.has_diff_ai = 1 ,
180
169
},
181
170
[BOARD_PCI1731 ] = {
182
171
.name = "pci1731" ,
183
172
.n_aichan = 16 ,
184
- .rangelist_ai = & range_pci17x1 ,
185
- .rangecode_ai = range_codes_pci17x1 ,
173
+ .rangelist_ai = & pci1711_ai_range ,
186
174
.has_di_do = 1 ,
187
175
},
188
176
};
@@ -196,6 +184,7 @@ struct pci1710_private {
196
184
unsigned int act_chanlist [32 ]; /* list of scanned channel */
197
185
unsigned char saved_seglen ; /* len of the non-repeating chanlist */
198
186
unsigned char da_ranges ; /* copy of D/A outpit range register */
187
+ unsigned char unipolar_gain ; /* adjust for unipolar gain codes */
199
188
};
200
189
201
190
static int pci171x_ai_check_chanlist (struct comedi_device * dev ,
@@ -270,7 +259,6 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev,
270
259
unsigned int n_chan ,
271
260
unsigned int seglen )
272
261
{
273
- const struct boardtype * board = dev -> board_ptr ;
274
262
struct pci1710_private * devpriv = dev -> private ;
275
263
unsigned int first_chan = CR_CHAN (chanlist [0 ]);
276
264
unsigned int last_chan = CR_CHAN (chanlist [seglen - 1 ]);
@@ -280,11 +268,15 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev,
280
268
unsigned int chan = CR_CHAN (chanlist [i ]);
281
269
unsigned int range = CR_RANGE (chanlist [i ]);
282
270
unsigned int aref = CR_AREF (chanlist [i ]);
283
- unsigned int rangeval ;
271
+ unsigned int rangeval = 0 ;
284
272
285
- rangeval = board -> rangecode_ai [range ];
286
273
if (aref == AREF_DIFF )
287
- rangeval |= 0x0020 ;
274
+ rangeval |= PCI171X_RANGE_DIFF ;
275
+ if (comedi_range_is_unipolar (s , range )) {
276
+ rangeval |= PCI171X_RANGE_UNI ;
277
+ range -= devpriv -> unipolar_gain ;
278
+ }
279
+ rangeval |= PCI171X_RANGE_GAIN (range );
288
280
289
281
/* select channel and set range */
290
282
outw (chan | (chan << 8 ), dev -> iobase + PCI171X_MUX_REG );
@@ -758,6 +750,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
758
750
struct pci1710_private * devpriv ;
759
751
struct comedi_subdevice * s ;
760
752
int ret , subdev , n_subdevices ;
753
+ int i ;
761
754
762
755
if (context < ARRAY_SIZE (boardtypes ))
763
756
board = & boardtypes [context ];
@@ -823,6 +816,15 @@ static int pci1710_auto_attach(struct comedi_device *dev,
823
816
s -> do_cmd = pci171x_ai_cmd ;
824
817
s -> cancel = pci171x_ai_cancel ;
825
818
}
819
+
820
+ /* find the value needed to adjust for unipolar gain codes */
821
+ for (i = 0 ; i < s -> range_table -> length ; i ++ ) {
822
+ if (comedi_range_is_unipolar (s , i )) {
823
+ devpriv -> unipolar_gain = i ;
824
+ break ;
825
+ }
826
+ }
827
+
826
828
subdev ++ ;
827
829
}
828
830
0 commit comments