4 Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
14 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.
16 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.
18 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 You should also find the complete GPL in the COPYING file accompanying this source code.
26 +-----------------------------------------------------------------------+
27 | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
28 +-----------------------------------------------------------------------+
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-------------------------------+---------------------------------------+
32 | Project : APCI-1032 | Compiler : GCC |
33 | Module name : hwdrv_apci1032.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
37 | Description : Hardware Layer Access For APCI-1032 |
38 +-----------------------------------------------------------------------+
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
46 +----------+-----------+------------------------------------------------+
49 /********* Definitions for APCI-1032 card *****/
51 #define APCI1032_ADDRESS_RANGE 20
52 /* DIGITAL INPUT DEFINE */
54 #define APCI1032_DIGITAL_IP 0
55 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE1 4
56 #define APCI1032_DIGITAL_IP_INTERRUPT_MODE2 8
57 #define APCI1032_DIGITAL_IP_IRQ 16
59 /* Digital Input IRQ Function Selection */
61 #define ADDIDATA_AND 1
63 /* Digital Input Interrupt Status */
64 #define APCI1032_DIGITAL_IP_INTERRUPT_STATUS 12
66 /* Digital Input Interrupt Enable Disable. */
67 #define APCI1032_DIGITAL_IP_INTERRUPT_ENABLE 0x4
68 #define APCI1032_DIGITAL_IP_INTERRUPT_DISABLE 0xfffffffb
70 /* ADDIDATA Enable Disable */
71 #define ADDIDATA_ENABLE 1
72 #define ADDIDATA_DISABLE 0
74 static unsigned int ui_InterruptStatus;
77 +----------------------------------------------------------------------------+
78 | Function Name : int i_APCI1032_ConfigDigitalInput |
79 | (struct comedi_device *dev,struct comedi_subdevice *s, |
80 | struct comedi_insn *insn,unsigned int *data) |
81 +----------------------------------------------------------------------------+
82 | Task : Configures the digital input Subdevice |
83 +----------------------------------------------------------------------------+
84 | Input Parameters : struct comedi_device *dev : Driver handle |
85 | unsigned int *data : Data Pointer contains |
86 | configuration parameters as below |
88 | data[0] : 1 Enable Digital Input Interrupt |
89 | 0 Disable Digital Input Interrupt |
90 | data[1] : 0 ADDIDATA Interrupt OR LOGIC |
91 | : 1 ADDIDATA Interrupt AND LOGIC |
92 | data[2] : Interrupt mask for the mode 1 |
93 | data[3] : Interrupt mask for the mode 2 |
95 +----------------------------------------------------------------------------+
96 | Output Parameters : -- |
97 +----------------------------------------------------------------------------+
98 | Return Value : TRUE : No error occur |
99 | : FALSE : Error occur. Return the error |
101 +----------------------------------------------------------------------------+
104 static int i_APCI1032_ConfigDigitalInput(struct comedi_device *dev,
105 struct comedi_subdevice *s,
106 struct comedi_insn *insn,
109 struct addi_private *devpriv = dev->private;
110 unsigned int ui_TmpValue;
111 unsigned int ul_Command1 = 0;
112 unsigned int ul_Command2 = 0;
114 devpriv->tsk_Current = current;
116 /*******************************/
117 /* Set the digital input logic */
118 /*******************************/
119 if (data[0] == ADDIDATA_ENABLE) {
120 ul_Command1 = ul_Command1 | data[2];
121 ul_Command2 = ul_Command2 | data[3];
123 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
125 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
126 if (data[1] == ADDIDATA_OR) {
127 outl(0x4, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
129 inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
130 } /* if (data[1] == ADDIDATA_OR) */
132 outl(0x6, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
133 /* else if(data[1] == ADDIDATA_OR) */
134 } /* if( data[0] == ADDIDATA_ENABLE) */
136 ul_Command1 = ul_Command1 & 0xFFFF0000;
137 ul_Command2 = ul_Command2 & 0xFFFF0000;
139 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1);
141 devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);
142 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
143 } /* else if ( data[0] == ADDIDATA_ENABLE) */
149 +----------------------------------------------------------------------------+
150 | Function Name : int i_APCI1032_Read1DigitalInput |
151 | (struct comedi_device *dev,struct comedi_subdevice *s, |
152 | struct comedi_insn *insn,unsigned int *data) |
153 +----------------------------------------------------------------------------+
154 | Task : Return the status of the digital input |
155 +----------------------------------------------------------------------------+
156 | Input Parameters : struct comedi_device *dev : Driver handle |
157 | unsigned int ui_Channel : Channel number to read |
158 | unsigned int *data : Data Pointer to read status |
159 +----------------------------------------------------------------------------+
160 | Output Parameters : -- |
161 +----------------------------------------------------------------------------+
162 | Return Value : TRUE : No error occur |
163 | : FALSE : Error occur. Return the error |
165 +----------------------------------------------------------------------------+
167 static int i_APCI1032_Read1DigitalInput(struct comedi_device *dev,
168 struct comedi_subdevice *s,
169 struct comedi_insn *insn,
172 struct addi_private *devpriv = dev->private;
173 unsigned int ui_TmpValue = 0;
174 unsigned int ui_Channel;
175 ui_Channel = CR_CHAN(insn->chanspec);
177 if (ui_Channel <= 31) {
178 ui_TmpValue = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
180 * since only 1 channel reqd to bring it to last bit it is rotated 8
181 * +(chan - 1) times then ANDed with 1 for last bit.
183 *data = (ui_TmpValue >> ui_Channel) & 0x1;
184 } /* if(ui_Channel >= 0 && ui_Channel <=31) */
186 /* comedi_error(dev," \n chan spec wrong\n"); */
187 return -EINVAL; /* "sorry channel spec wrong " */
188 } /* else if(ui_Channel >= 0 && ui_Channel <=31) */
193 +----------------------------------------------------------------------------+
194 | Function Name : int i_APCI1032_ReadMoreDigitalInput |
195 | (struct comedi_device *dev,struct comedi_subdevice *s, |
196 | struct comedi_insn *insn,unsigned int *data) |
197 +----------------------------------------------------------------------------+
198 | Task : Return the status of the Requested digital inputs |
199 +----------------------------------------------------------------------------+
200 | Input Parameters : struct comedi_device *dev : Driver handle |
201 | unsigned int ui_NoOfChannels : No Of Channels To be Read |
202 | unsigned int *data : Data Pointer to read status |
203 +----------------------------------------------------------------------------+
204 | Output Parameters : -- |
205 +----------------------------------------------------------------------------+
206 | Return Value : TRUE : No error occur |
207 | : FALSE : Error occur. Return the error |
209 +----------------------------------------------------------------------------+
212 static int i_APCI1032_ReadMoreDigitalInput(struct comedi_device *dev,
213 struct comedi_subdevice *s,
214 struct comedi_insn *insn,
217 struct addi_private *devpriv = dev->private;
218 unsigned int ui_PortValue = data[0];
219 unsigned int ui_Mask = 0;
220 unsigned int ui_NoOfChannels;
222 ui_NoOfChannels = CR_CHAN(insn->chanspec);
224 *data = (unsigned int) inl(devpriv->iobase + APCI1032_DIGITAL_IP);
225 switch (ui_NoOfChannels) {
228 *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
232 *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
236 *data = (*data >> (8 * ui_PortValue)) & ui_Mask;
240 *data = (*data >> (16 * ui_PortValue)) & ui_Mask;
245 /* comedi_error(dev," \nchan spec wrong\n"); */
246 return -EINVAL; /* "sorry channel spec wrong " */
248 } /* switch(ui_NoOfChannels) */
249 } /* if(data[1]==0) */
252 *data = ui_InterruptStatus;
254 } /* else if(data[1]==0) */
259 +----------------------------------------------------------------------------+
260 | Function Name : static void v_APCI1032_Interrupt |
261 | (int irq , void *d) |
262 +----------------------------------------------------------------------------+
263 | Task : Interrupt handler for the interruptible digital inputs |
264 +----------------------------------------------------------------------------+
265 | Input Parameters : int irq : irq number |
266 | void *d : void pointer |
267 +----------------------------------------------------------------------------+
268 | Output Parameters : -- |
269 +----------------------------------------------------------------------------+
270 | Return Value : TRUE : No error occur |
271 | : FALSE : Error occur. Return the error |
273 +----------------------------------------------------------------------------+
275 static void v_APCI1032_Interrupt(int irq, void *d)
277 struct comedi_device *dev = d;
278 struct addi_private *devpriv = dev->private;
279 unsigned int ui_Temp;
281 /* disable the interrupt */
282 ui_Temp = inl(devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
283 outl(ui_Temp & APCI1032_DIGITAL_IP_INTERRUPT_DISABLE,
284 devpriv->iobase + APCI1032_DIGITAL_IP_IRQ);
286 inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS);
287 ui_InterruptStatus = ui_InterruptStatus & 0X0000FFFF;
288 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
289 outl(ui_Temp, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); /* enable the interrupt */
294 +----------------------------------------------------------------------------+
295 | Function Name : int i_APCI1032_Reset(struct comedi_device *dev) | |
296 +----------------------------------------------------------------------------+
297 | Task :resets all the registers |
298 +----------------------------------------------------------------------------+
299 | Input Parameters : struct comedi_device *dev
300 +----------------------------------------------------------------------------+
301 | Output Parameters : -- |
302 +----------------------------------------------------------------------------+
305 +----------------------------------------------------------------------------+
308 static int i_APCI1032_Reset(struct comedi_device *dev)
310 struct addi_private *devpriv = dev->private;
312 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_IRQ); /* disable the interrupts */
313 inl(devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_STATUS); /* Reset the interrupt status register */
314 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE1); /* Disable the and/or interrupt */
315 outl(0x0, devpriv->iobase + APCI1032_DIGITAL_IP_INTERRUPT_MODE2);