63 #include "../comedidev.h"
68 #define PCI_VENDOR_ID_DT 0x1116
78 static const struct comedi_lrange range_dt3000_ai_pgl = { 4, {
103 .adrange = &range_dt3000_ai,
108 {.name =
"dt3001-pgl",
112 .adrange = &range_dt3000_ai_pgl,
121 .adrange = &range_dt3000_ai,
130 .adrange = &range_dt3000_ai,
135 {.name =
"dt3003-pgl",
139 .adrange = &range_dt3000_ai_pgl,
148 .adrange = &range_dt3000_ai,
157 .adrange = &range_dt3000_ai,
164 #define this_board ((const struct dt3k_boardtype *)dev->board_ptr)
166 #define DT3000_SIZE (4*0x1000)
170 #define DPR_DAC_buffer (4*0x000)
171 #define DPR_ADC_buffer (4*0x800)
172 #define DPR_Command (4*0xfd3)
173 #define DPR_SubSys (4*0xfd3)
174 #define DPR_Encode (4*0xfd4)
175 #define DPR_Params(a) (4*(0xfd5+(a)))
176 #define DPR_Tick_Reg_Lo (4*0xff5)
177 #define DPR_Tick_Reg_Hi (4*0xff6)
178 #define DPR_DA_Buf_Front (4*0xff7)
179 #define DPR_DA_Buf_Rear (4*0xff8)
180 #define DPR_AD_Buf_Front (4*0xff9)
181 #define DPR_AD_Buf_Rear (4*0xffa)
182 #define DPR_Int_Mask (4*0xffb)
183 #define DPR_Intr_Flag (4*0xffc)
184 #define DPR_Response_Mbx (4*0xffe)
185 #define DPR_Command_Mbx (4*0xfff)
187 #define AI_FIFO_DEPTH 2003
188 #define AO_FIFO_DEPTH 2048
192 #define CMD_GETBRDINFO 0
194 #define CMD_GETCONFIG 2
197 #define CMD_READSINGLE 5
198 #define CMD_WRITESINGLE 6
199 #define CMD_CALCCLOCK 7
200 #define CMD_READEVENTS 8
201 #define CMD_WRITECTCTRL 16
202 #define CMD_READCTCTRL 17
203 #define CMD_WRITECT 18
204 #define CMD_READCT 19
205 #define CMD_WRITEDATA 32
206 #define CMD_READDATA 33
207 #define CMD_WRITEIO 34
208 #define CMD_READIO 35
209 #define CMD_WRITECODE 36
210 #define CMD_READCODE 37
211 #define CMD_EXECUTE 38
222 #define DT3000_CMDONE 0x80
223 #define DT3000_CTDONE 0x40
224 #define DT3000_DAHWERR 0x20
225 #define DT3000_DASWERR 0x10
226 #define DT3000_DAEMPTY 0x08
227 #define DT3000_ADHWERR 0x04
228 #define DT3000_ADSWERR 0x02
229 #define DT3000_ADFULL 0x01
231 #define DT3000_COMPLETION_MASK 0xff00
232 #define DT3000_COMMAND_MASK 0x00ff
233 #define DT3000_NOTPROCESSED 0x0000
234 #define DT3000_NOERROR 0x5500
235 #define DT3000_ERROR 0xaa00
236 #define DT3000_NOTSUPPORTED 0xff00
238 #define DT3000_EXTERNAL_CLOCK 1
239 #define DT3000_RISING_EDGE 2
241 #define TMODE_MASK 0x1c
243 #define DT3000_AD_TRIG_INTERNAL (0<<2)
244 #define DT3000_AD_TRIG_EXTERNAL (1<<2)
245 #define DT3000_AD_RETRIG_INTERNAL (2<<2)
246 #define DT3000_AD_RETRIG_EXTERNAL (3<<2)
247 #define DT3000_AD_EXTRETRIG (4<<2)
249 #define DT3000_CHANNEL_MODE_SE 0
250 #define DT3000_CHANNEL_MODE_DI 1
260 #define devpriv ((struct dt3k_private *)dev->private)
264 static int dt3k_ns_to_timer(
unsigned int timer_base,
unsigned int *
arg,
265 unsigned int round_mode);
269 static void debug_intr_flags(
unsigned int flags);
281 for (i = 0; i <
TIMEOUT; i++) {
297 unsigned int subsys,
unsigned int chan,
310 static void dt3k_writesingle(
struct comedi_device *dev,
unsigned int subsys,
311 unsigned int chan,
unsigned int data)
322 static int debug_n_ints;
338 debug_intr_flags(status);
342 dt3k_ai_empty_fifo(dev, s);
350 if (debug_n_ints >= 10) {
351 dt3k_ai_cancel(dev, s);
360 static char *intr_flags[] = {
361 "AdFull",
"AdSwError",
"AdHwError",
"DaEmpty",
362 "DaSwError",
"DaHwError",
"CtDone",
"CmDone",
365 static void debug_intr_flags(
unsigned int flags)
369 for (i = 0; i < 8; i++) {
370 if (flags & (1 << i))
387 count = front -
devpriv->ai_front;
395 for (i = 0; i <
count; i++) {
516 static int dt3k_ns_to_timer(
unsigned int timer_base,
unsigned int *nanosec,
517 unsigned int round_mode)
524 for (prescale = 0; prescale < 16; prescale++) {
525 base = timer_base * (prescale + 1);
526 switch (round_mode) {
529 divider = (*nanosec + base / 2) / base;
532 divider = (*nanosec) / base;
535 divider = (*nanosec) / base;
538 if (divider < 65536) {
539 *nanosec = divider * base;
540 return (prescale << 16) | (divider);
545 base = timer_base * (1 <<
prescale);
547 *nanosec = divider * base;
548 return (prescale << 16) | (divider);
555 unsigned int chan,
range, aref;
556 unsigned int divider;
557 unsigned int tscandiv;
566 writew((range << 6) | chan,
635 unsigned int chan,
gain, aref;
642 for (i = 0; i < insn->
n; i++)
643 data[i] = dt3k_readsingle(dev,
SUBS_AI, chan, gain);
655 for (i = 0; i < insn->
n; i++) {
656 dt3k_writesingle(dev,
SUBS_AO, chan, data[i]);
657 devpriv->ao_readback[chan] = data[
i];
671 for (i = 0; i < insn->
n; i++)
672 data[i] =
devpriv->ao_readback[chan];
719 dt3k_dio_config(dev, mask);
729 s->
state &= ~data[0];
730 s->
state |= data[1] & data[0];
733 data[1] = dt3k_readsingle(dev,
SUBS_DIN, 0, 0);
745 for (i = 0; i < insn->
n; i++) {
768 if (bus != pcidev->
bus->number ||
774 for (i = 0; i <
ARRAY_SIZE(dt3k_boardtypes); i++) {
782 "No supported board found! (req. bus %d, slot %d)\n",
800 pcidev = dt3000_find_pci_dev(dev, it);
803 comedi_set_hw_dev(dev, &pcidev->
dev);
842 s->
cancel = dt3k_ai_cancel;
887 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
903 .driver_name =
"dt3000",
905 .attach = dt3000_attach,
906 .detach = dt3000_detach,
932 static struct pci_driver dt3000_pci_driver = {
934 .id_table = dt3000_pci_table,
935 .probe = dt3000_pci_probe,