⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daqboard2000.c

📁 rtlinux-3.2-pre3.tar.bz2 rtlinux3.2-pre3的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   comedi/drivers/daqboard2000.c   hardware driver for IOtech DAQboard/2000   COMEDI - Linux Control and Measurement Device Interface   Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>   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.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//*Driver: daqboard2000.oDescription: IOTech DAQBoard/2000Author: Anders Blomdell <anders.blomdell@control.lth.se>Status: worksDevices: [IOTech] DAQBoard/2000 (daqboard2000)Much of the functionality of this driver was determined from readingthe source code for the Windows driver.The FPGA on the board requires initialization code, which can eitherbe compiled into the driver or loaded by comedi_config using the -ioption.  The latter is recommended, in order to save a bit of kernelmemory.Configuration options:    none*//*   This card was obviously never intended to leave the Windows world,    since it lacked all kind of hardware documentation (except for cable    pinouts, plug and pray has something to catch up with yet).    With some help from our swedish distributor, we got the Windows sourcecode    for the card, and here are the findings so far.   1. A good document that describes the PCI interface chip is found at:      http://plx.plxtech.com/download/9080/databook/9080db-106.pdf        2. The initialization done so far is:        a. program the FPGA (windows code sans a lot of error messages)	b.    3. Analog out seems to work OK with DAC's disabled, if DAC's are enabled,       you have to output values to all enabled DAC's until result appears, I      guess that it has something to do with pacer clocks, but the source       gives me no clues. I'll keep it simple so far.   4. Analog in.         Each channel in the scanlist seems to be controlled by four	control words:        Word0:          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+          ! | | | ! | | | ! | | | ! | | | !          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+        Word1:          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+          ! | | | ! | | | ! | | | ! | | | !          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+	   |             |       | | | | |           +------+------+       | | | | +-- Digital input (??)		  |		 | | | +---- 10 us settling time		  |		 | | +------ Suspend acquisition (last to scan)		  |		 | +-------- Simultaneous sample and hold		  |		 +---------- Signed data format		  +------------------------- Correction offset low			               Word2:          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+          ! | | | ! | | | ! | | | ! | | | !          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+           |     | |     | | | | | |     |           +-----+ +--+--+ +++ +++ +--+--+              |       |     |   |     +----- Expansion channel	      |       |     |   +----------- Expansion gain              |       |     +--------------- Channel (low)	      |       +--------------------- Correction offset high	      +----------------------------- Correction gain low        Word3:          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+          ! | | | ! | | | ! | | | ! | | | !          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+           |             | | | |   | | | |           +------+------+ | | +-+-+ | | +-- Low bank enable                  |        | |   |   | +---- High bank enable                  |        | |   |   +------ Hi/low select		  |    	   | |   +---------- Gain (1,?,2,4,8,16,32,64)		  |    	   | +-------------- differential/single ended		  |    	   +---------------- Unipolar		  +------------------------- Correction gain high           999. The card seems to have an incredible amount of capabilities, but        trying to reverse engineer them from the Windows source is beyond my	patience.    */#include <linux/comedidev.h>#include <linux/delay.h>#include <linux/pci.h>#include "8255.h"#define DAQBOARD2000_SUBSYSTEM_IDS2 	0x00021616 /* Daqboard/2000 - 2 Dacs */#define DAQBOARD2000_SUBSYSTEM_IDS4 	0x00041616 /* Daqboard/2000 - 4 Dacs */#define DAQBOARD2000_DAQ_SIZE 		0x1002#define DAQBOARD2000_PLX_SIZE 		0x100// Initialization bits for the Serial EEPROM Control Register#define DAQBOARD2000_SECRProgPinHi      0x8001767e#define DAQBOARD2000_SECRProgPinLo      0x8000767e#define DAQBOARD2000_SECRLocalBusHi     0xc000767e#define DAQBOARD2000_SECRLocalBusLo     0x8000767e#define DAQBOARD2000_SECRReloadHi       0xa000767e#define DAQBOARD2000_SECRReloadLo       0x8000767e// SECR status bits#define DAQBOARD2000_EEPROM_PRESENT     0x10000000// CPLD status bits#define DAQBOARD2000_CPLD_INIT 		0x0002#define DAQBOARD2000_CPLD_DONE 		0x0004// Available rangesstatic comedi_lrange range_daqboard2000_ai = { 13, {  RANGE(-10, 10),  RANGE(-5, 5),  RANGE(-2.5, 2.5),  RANGE(-1.25, 1.25),  RANGE(-0.625, 0.625),  RANGE(-0.3125, 0.3125),  RANGE(-0.156, 0.156),  RANGE(0, 10),  RANGE(0, 5),  RANGE(0, 2.5),  RANGE(0, 1.25),  RANGE(0, 0.625),  RANGE(0, 0.3125)}};static comedi_lrange range_daqboard2000_ao = { 1, {  RANGE(-10, 10)}};typedef struct daqboard2000_hw {  volatile u16  acqControl;               // 0x00  volatile u16  acqScanListFIFO;          // 0x02  volatile u32  acqPacerClockDivLow;      // 0x04  volatile u16  acqScanCounter;           // 0x08  volatile u16  acqPacerClockDivHigh;     // 0x0a  volatile u16  acqTriggerCount;          // 0x0c  volatile u16  fill2;                    // 0x0e  volatile u16  acqResultsFIFO;           // 0x10  volatile u16  fill3;                    // 0x12  volatile u16  acqResultsShadow;         // 0x14  volatile u16  fill4;                    // 0x16  volatile u16  acqAdcResult;             // 0x18  volatile u16  fill5;                    // 0x1a  volatile u16  dacScanCounter;           // 0x1c  volatile u16  fill6;                    // 0x1e  volatile u16  dacControl;               // 0x20  volatile u16  fill7;                    // 0x22  volatile s16  dacFIFO;                  // 0x24  volatile u16  fill8[2];                 // 0x26  volatile u16  dacPacerClockDiv;         // 0x2a  volatile u16  refDacs;                  // 0x2c  volatile u16  fill9;                    // 0x2e  volatile u16  dioControl;               // 0x30  volatile s16  dioP3hsioData;            // 0x32  volatile u16  dioP3Control;             // 0x34  volatile u16  calEepromControl;         // 0x36  volatile s16  dacSetting[4];            // 0x38  volatile s16  dioP2ExpansionIO8Bit[32]; // 0x40  volatile u16  ctrTmrControl;            // 0x80  volatile u16  fill10[3];                // 0x82  volatile s16  ctrInput[4];              // 0x88  volatile u16  fill11[8];                // 0x90  volatile u16  timerDivisor[2];          // 0xa0  volatile u16  fill12[6];                // 0xa4  volatile u16  dmaControl;               // 0xb0  volatile u16  trigControl;              // 0xb2  volatile u16  fill13[2];                // 0xb4  volatile u16  calEeprom;                // 0xb8  volatile u16  acqDigitalMark;           // 0xba  volatile u16  trigDacs;                 // 0xbc  volatile u16  fill14;                   // 0xbe  volatile s16  dioP2ExpansionIO16Bit[32];// 0xc0} daqboard2000_hw;/* Scan Sequencer programming */#define DAQBOARD2000_SeqStartScanList            0x0011#define DAQBOARD2000_SeqStopScanList             0x0010// Prepare for acquisition#define DAQBOARD2000_AcqResetScanListFifo        0x0004#define DAQBOARD2000_AcqResetResultsFifo         0x0002#define DAQBOARD2000_AcqResetConfigPipe          0x0001// Acqusition status bits#define DAQBOARD2000_AcqResultsFIFOMore1Sample   0x0001#define DAQBOARD2000_AcqResultsFIFOHasValidData  0x0002#define DAQBOARD2000_AcqResultsFIFOOverrun       0x0004#define DAQBOARD2000_AcqLogicScanning            0x0008#define DAQBOARD2000_AcqConfigPipeFull           0x0010#define DAQBOARD2000_AcqScanListFIFOEmpty        0x0020#define DAQBOARD2000_AcqAdcNotReady              0x0040#define DAQBOARD2000_ArbitrationFailure          0x0080#define DAQBOARD2000_AcqPacerOverrun             0x0100#define DAQBOARD2000_DacPacerOverrun             0x0200#define DAQBOARD2000_AcqHardwareError            0x01c0// Scan Sequencer programming#define DAQBOARD2000_SeqStartScanList            0x0011#define DAQBOARD2000_SeqStopScanList             0x0010/* Pacer Clock Control */#define DAQBOARD2000_AdcPacerInternal            0x0030#define DAQBOARD2000_AdcPacerExternal            0x0032#define DAQBOARD2000_AdcPacerEnable              0x0031#define DAQBOARD2000_AdcPacerEnableDacPacer      0x0034#define DAQBOARD2000_AdcPacerDisable             0x0030#define DAQBOARD2000_AdcPacerNormalMode          0x0060#define DAQBOARD2000_AdcPacerCompatibilityMode   0x0061#define DAQBOARD2000_AdcPacerInternalOutEnable   0x0008#define DAQBOARD2000_AdcPacerExternalRising      0x0100// DAC status#define DAQBOARD2000_DacFull                     0x0001#define DAQBOARD2000_RefBusy                     0x0002#define DAQBOARD2000_TrgBusy                     0x0004#define DAQBOARD2000_CalBusy                     0x0008#define DAQBOARD2000_Dac0Busy                    0x0010#define DAQBOARD2000_Dac1Busy                    0x0020#define DAQBOARD2000_Dac2Busy                    0x0040#define DAQBOARD2000_Dac3Busy                    0x0080// DAC control#define DAQBOARD2000_Dac0Enable                  0x0021#define DAQBOARD2000_Dac1Enable                  0x0031#define DAQBOARD2000_Dac2Enable                  0x0041#define DAQBOARD2000_Dac3Enable                  0x0051#define DAQBOARD2000_DacEnableBit                0x0001#define DAQBOARD2000_Dac0Disable                 0x0020#define DAQBOARD2000_Dac1Disable                 0x0030#define DAQBOARD2000_Dac2Disable                 0x0040#define DAQBOARD2000_Dac3Disable                 0x0050#define DAQBOARD2000_DacResetFifo                0x0004#define DAQBOARD2000_DacPatternDisable           0x0060#define DAQBOARD2000_DacPatternEnable            0x0061#define DAQBOARD2000_DacSelectSignedData         0x0002#define DAQBOARD2000_DacSelectUnsignedData       0x0000/* Trigger Control */#define DAQBOARD2000_TrigAnalog                  0x0000#define DAQBOARD2000_TrigTTL                     0x0010#define DAQBOARD2000_TrigTransHiLo               0x0004#define DAQBOARD2000_TrigTransLoHi               0x0000#define DAQBOARD2000_TrigAbove                   0x0000#define DAQBOARD2000_TrigBelow                   0x0004#define DAQBOARD2000_TrigLevelSense              0x0002#define DAQBOARD2000_TrigEdgeSense               0x0000#define DAQBOARD2000_TrigEnable                  0x0001#define DAQBOARD2000_TrigDisable                 0x0000// Reference Dac Selection#define DAQBOARD2000_PosRefDacSelect             0x0100#define DAQBOARD2000_NegRefDacSelect             0x0000static int daqboard2000_attach(comedi_device *dev,comedi_devconfig *it);static int daqboard2000_detach(comedi_device *dev);static comedi_driver driver_daqboard2000 = {  driver_name:	"daqboard2000",  module:	THIS_MODULE,  attach:	daqboard2000_attach,  detach:	daqboard2000_detach,};typedef struct {	char *name;	int id;}boardtype;static boardtype boardtypes[]={	{ "ids2", DAQBOARD2000_SUBSYSTEM_IDS2 },	{ "ids4", DAQBOARD2000_SUBSYSTEM_IDS4 },};#define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype))#define this_board ((boardtype *)dev->board_ptr)static struct pci_device_id daqboard2000_pci_table[] __devinitdata = {	{ 0x1616, 0x0409, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },	{ 0 }};MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table);typedef struct {  enum {    card_daqboard_2000  } card;  void *daq;  void *plx;  lsampl_t ao_readback[2];} daqboard2000_private;#define devpriv ((daqboard2000_private*)dev->private)static void writeAcqScanListEntry(comedi_device *dev, u16 entry){  daqboard2000_hw *fpga = devpriv->daq;  comedi_udelay(4);  fpga->acqScanListFIFO = entry & 0x00ff;  comedi_udelay(4);  fpga->acqScanListFIFO = (entry >> 8) & 0x00ff;}static void setup_sampling(comedi_device *dev, int chan, int gain){  u16 word0, word1, word2, word3;  /* Channel 0-7 diff, channel 8-23 single ended */  word0 = 0;  word1 = 0x0004; /* Last scan */  word2 = (chan<<6) & 0x00c0;  switch (chan / 4) {     case 0: word3 = 0x0001; break;    case 1: word3 = 0x0002; break;    case 2: word3 = 0x0005; break;    case 3: word3 = 0x0006; break;    case 4: word3 = 0x0041; break;    case 5: word3 = 0x0042; break;    default: word3 = 0; break;  }/*  dev->eeprom.correctionDACSE[i][j][k].offset = 0x800;  dev->eeprom.correctionDACSE[i][j][k].gain = 0xc00;*/  /* These should be read from EEPROM */  word2 |= 0x0800;  word3 |= 0xc000;  /*  printk("%d %4.4x %4.4x %4.4x %4.4x\n", chan, word0, word1, word2, word3);*/  writeAcqScanListEntry(dev, word0);  writeAcqScanListEntry(dev, word1);  writeAcqScanListEntry(dev, word2);  writeAcqScanListEntry(dev, word3);}static int daqboard2000_ai_insn_read(comedi_device *dev, comedi_subdevice *s,	comedi_insn *insn, lsampl_t *data){  int i;  daqboard2000_hw *fpga = devpriv->daq;  int gain, chan, timeout;  /* Could these two be merged? */  fpga->acqControl = DAQBOARD2000_AcqResetScanListFifo;  fpga->acqControl = DAQBOARD2000_AcqResetResultsFifo | DAQBOARD2000_AcqResetConfigPipe;  gain = CR_RANGE(insn->chanspec);  chan = CR_CHAN(insn->chanspec);		  /* This doesn't look efficient.  I decided to take the conservative   * approach when I did the insn conversion.  Perhaps it would be   * better to have broken it completely, then someone would have been   * forced to fix it.  --ds */  for(i=0;i<insn->n;i++){    setup_sampling(dev, chan, gain);    /* Enable reading from the scanlist FIFO */    fpga->acqControl = DAQBOARD2000_SeqStartScanList;    for (timeout = 0 ; timeout < 20 ; timeout++) {      if (fpga->acqControl & DAQBOARD2000_AcqConfigPipeFull) { break; }      //comedi_udelay(2);    }    fpga->acqControl = DAQBOARD2000_AdcPacerEnable;    for (timeout = 0 ; timeout < 20 ; timeout++) {      if (fpga->acqControl & DAQBOARD2000_AcqLogicScanning) { break; }      //comedi_udelay(2);    }    for (timeout = 0 ; timeout < 20 ; timeout++) {      if (fpga->acqControl & DAQBOARD2000_AcqResultsFIFOHasValidData) { break;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -