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

📄 cb_pcimdda.c

📁 rtlinux-3.2-pre3.tar.bz2 rtlinux3.2-pre3的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    comedi/drivers/cb_pcimdda.c    Computer Boards PCIM-DDA06-16 Comedi driver    Author: Calin Culianu <calin@ajvar.org>        COMEDI - Linux Control and Measurement Device Interface    Copyright (C) 2000 David A. Schleef <ds@schleef.org>    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: cb_pcimdda.oDescription: A driver for this relatively new and uniquely designed boardDevices: [Computer Boards] PCIM-DDA06-16 (cb_pcimdda)Author: Calin Culianu <calin@ajvar.org>Updated: Thu, 20 Jun 2002 16:19:41 -0500Status: worksAll features of the PCIM-DDA06-16 board are supported.  This boardhas 6 16-bit AO channels, and the usual 8255 DIO setup.  (24 channels, configurable in banks of 8 and 4, etc.).  This board does not support commands.The board has a peculiar way of specifying AO gain/range settings -- You have1 jumper bank on the card, which either makes all 6 AO channels either5 Volt unipolar, 5V bipolar, 10 Volt unipolar or 10V bipolar.   Since there is absolutely _no_ way to tell in software how this jumper is set(well, at least according  to the rather thin spec. from Measurement Computing that comes with the board), the driver assumes the jumper is at its factory default setting of +/-5V.Also of note is the fact that this board features another jumper, whosestate is also completely invisible to software.  It toggles two possible AOoutput modes on the board:  - Update Mode: Writing to an AO channel instantaneously updates the actual    signal output by the DAC on the board (this is the factory default).  - Simultaneous XFER Mode: Writing to an AO channel has no effect until    you read from any one of the AO channels.  This is useful for loading    all 6 AO values, and then reading from any one of the AO channels on the     device to instantly update all 6 AO values in unison.  Useful for some    control apps, I would assume?  If your jumper is in this setting, then you     need to issue your comedi_data_write()s to load all the values you want,    then issue one comedi_data_read() on any channel on the AO subdevice    to initiate the simultaneous XFER. Configuration Options:  [0] PCI bus (optional) (unimplemented)  [1] PCI slot (optional) (unimplemented)  [2] analog output range jumper setting      0 == +/- 5 V      1 == +/- 10 V*//*    This is a driver for the Computer Boards PCIM-DDA06-16 Analog Output    card.  This board has a unique register layout and as such probably     deserves its own driver file.      It is theoretically possible to integrate this board into the cb_pcidda    file, but since that isn't my code, I didn't want to significantly    modify that file to support this board (I thought it impolite to do so).    At any rate, if you feel ambitious, please feel free to take    the code out of this file and combine it with a more unified driver    file.    I would like to thank Timothy Curry <Timothy.Curry@rdec.redstone.army.mil>    for lending me a board so that I could write this driver.    -Calin Culianu <calin@ajvar.org> */#include <linux/comedidev.h>#include <linux/pci.h>#include "8255.h"/* device ids of the cards we support -- currently only 1 card supported */#define PCI_ID_PCIM_DDA06_16 0x0053/* * This is straight from skel.c -- I did this in case this source file * will someday support more than 1 board... */typedef struct board_struct {    char *name;    unsigned short device_id;    int ao_chans;    int ao_bits;	int dio_chans;    int dio_method;    int dio_offset; /* how many bytes into the BADR are the DIO ports */    int regs_badrindex; /* IO Region for the control, analog output,                            and DIO registers */    int reg_sz;     /* number of bytes of registers in io region */} board;enum DIO_METHODS {  DIO_NONE = 0,  DIO_8255,  DIO_INTERNAL /* unimplemented */};static board boards[] = {    {        name:		"cb_pcimdda06-16",        device_id:       PCI_ID_PCIM_DDA06_16,        ao_chans:	 6,        ao_bits:         16,        dio_chans:	 24,        dio_method:      DIO_8255,        dio_offset:      12,         regs_badrindex:  3,        reg_sz:          16,    }};/* * Useful for shorthand access to the particular board structure */#define thisboard    ((board *)dev->board_ptr)/* Number of boards in boards[] */#define N_BOARDS	(sizeof(boards) / sizeof(board))#define REG_SZ (thisboard->reg_sz)#define REGS_BADRINDEX (thisboard->regs_badrindex)/* This is used by modprobe to translate PCI IDs to drivers.  Should * only be used for PCI and ISA-PnP devices *//* Please add your PCI vendor ID to comedidev.h, and it will be forwarded * upstream. */static struct pci_device_id pci_table[] __devinitdata = {  { PCI_VENDOR_ID_COMPUTERBOARDS, PCI_ID_PCIM_DDA06_16, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },  { 0 }};MODULE_DEVICE_TABLE(pci, pci_table);/* this structure is for data unique to this hardware driver.  If   several hardware drivers keep similar information in this structure,   feel free to suggest moving the variable to the comedi_device struct.  */typedef struct {        int registers; /* set by probe */        int dio_registers;        char  attached_to_8255; /* boolean */        char  attached_successfully; /* boolean */  /* would be useful for a PCI device */        struct pci_dev *pci_dev;#define MAX_AO_READBACK_CHANNELS 6      /* Used for AO readback */       lsampl_t ao_readback[MAX_AO_READBACK_CHANNELS];    } private;/* * most drivers define the following macro to make it easy to * access the private structure. */#define devpriv ((private *)dev->private)/* * The comedi_driver structure tells the Comedi core module * which functions to call to configure/deconfigure (attach/detach) * the board, and also about the kernel module that contains * the device code. */static int attach(comedi_device *dev,comedi_devconfig *it);static int detach(comedi_device *dev);static comedi_driver cb_pcimdda_driver = {	driver_name:	"cb_pcimdda",	module:		THIS_MODULE,	attach:		attach,	detach:		detach,};MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");             MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "                   "series.  Currently only supports PCIM-DDA06-16 (which "                   "also happens to be the only board in this series. :) ) "); MODULE_LICENSE("GPL");COMEDI_INITCLEANUP_NOMODULE(cb_pcimdda_driver);static int ao_winsn(comedi_device *dev, comedi_subdevice *s,                     comedi_insn *insn,lsampl_t *data);static int ao_rinsn(comedi_device *dev, comedi_subdevice *s,                     comedi_insn *insn,lsampl_t *data);/*---------------------------------------------------------------------------  HELPER FUNCTION DECLARATIONS -----------------------------------------------------------------------------*//* returns a maxdata value for a given n_bits */static inline lsampl_t figure_out_maxdata(int bits);/*  *  Probes for a supported device. * *  Prerequisite: private be allocated already inside dev *    *  If the device is found, it returns 0 and has the following side effects: * *  o  assigns a struct pci_dev * to dev->private->pci_dev  *  o  assigns a struct board * to dev->board_ptr *  o  sets dev->private->registers *  o  sets dev->private->dio_registers * *  Otherwise, returns a -errno on error */static int probe(comedi_device *dev, const comedi_devconfig *it);/*---------------------------------------------------------------------------  FUNCTION DEFINITIONS-----------------------------------------------------------------------------*//* * Attach is called by the Comedi core to configure the driver * for a particular board.  If you specified a board_name array * in the driver structure, dev->board_ptr contains that * address. */static int attach(comedi_device *dev,comedi_devconfig *it){	comedi_subdevice *s;	int err;    /* * Allocate the private structure area.  alloc_private() is a * convenient macro defined in comedidev.h. * if this function fails (returns negative) then the private area is * kfree'd by comedi */	if (alloc_private(dev,sizeof(private))<0)

⌨️ 快捷键说明

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