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 shoud 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-1516 | Compiler : GCC |
33 | Module name : hwdrv_apci1516.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
37 | Description : Hardware Layer Acces For APCI-1516 |
38 +-----------------------------------------------------------------------+
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
46 +----------+-----------+------------------------------------------------+
50 +----------------------------------------------------------------------------+
52 +----------------------------------------------------------------------------+
54 #include "hwdrv_apci1516.h"
57 +----------------------------------------------------------------------------+
58 | Function Name : int i_APCI1516_Read1DigitalInput |
59 | (struct comedi_device *dev,struct comedi_subdevice *s, |
60 | struct comedi_insn *insn,unsigned int *data) |
61 +----------------------------------------------------------------------------+
62 | Task : Return the status of the digital input |
63 +----------------------------------------------------------------------------+
64 | Input Parameters : struct comedi_device *dev : Driver handle |
65 | struct comedi_subdevice *s, :pointer to subdevice structure
66 struct comedi_insn *insn :pointer to insn structure |
67 | unsigned int *data : Data Pointer to read status |
68 +----------------------------------------------------------------------------+
69 | Output Parameters : -- |
70 +----------------------------------------------------------------------------+
71 | Return Value : TRUE : No error occur |
72 | : FALSE : Error occur. Return the error |
74 +----------------------------------------------------------------------------+
76 int i_APCI1516_Read1DigitalInput(struct comedi_device * dev, struct comedi_subdevice * s,
77 struct comedi_insn * insn, unsigned int * data)
79 unsigned int ui_TmpValue = 0;
80 unsigned int ui_Channel;
81 ui_Channel = CR_CHAN(insn->chanspec);
82 if (ui_Channel >= 0 && ui_Channel <= 7) {
83 ui_TmpValue = (unsigned int) inw(devpriv->iobase + APCI1516_DIGITAL_IP);
84 /* since only 1 channel reqd to bring it to last bit it is rotated */
85 /* 8 +(chan - 1) times then ANDed with 1 for last bit. */
86 *data = (ui_TmpValue >> ui_Channel) & 0x1;
87 } /* if(ui_Channel >= 0 && ui_Channel <=7) */
89 /* comedi_error(dev," \n chan spec wrong\n"); */
90 return -EINVAL; /* "sorry channel spec wrong " */
91 } /* else if(ui_Channel >= 0 && ui_Channel <=7) */
97 +----------------------------------------------------------------------------+
98 | Function Name : int i_APCI1516_ReadMoreDigitalInput |
99 | (struct comedi_device *dev,struct comedi_subdevice *s, |
100 | struct comedi_insn *insn,unsigned int *data) |
101 +----------------------------------------------------------------------------+
102 | Task : Return the status of the Requested digital inputs |
103 +----------------------------------------------------------------------------+
104 | Input Parameters : struct comedi_device *dev : Driver handle |
105 | struct comedi_subdevice *s, :pointer to subdevice structure
106 struct comedi_insn *insn :pointer to insn structure |
107 | unsigned int *data : Data Pointer to read status |
108 +----------------------------------------------------------------------------+
109 | Output Parameters : -- |
110 +----------------------------------------------------------------------------+
111 | Return Value : TRUE : No error occur |
112 | : FALSE : Error occur. Return the error |
114 +----------------------------------------------------------------------------+
117 int i_APCI1516_ReadMoreDigitalInput(struct comedi_device * dev, struct comedi_subdevice * s,
118 struct comedi_insn * insn, unsigned int * data)
121 unsigned int ui_PortValue = data[0];
122 unsigned int ui_Mask = 0;
123 unsigned int ui_NoOfChannels;
125 ui_NoOfChannels = CR_CHAN(insn->chanspec);
127 *data = (unsigned int) inw(devpriv->iobase + APCI1516_DIGITAL_IP);
128 switch (ui_NoOfChannels) {
131 *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
135 *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
141 printk("\nWrong parameters\n");
142 return -EINVAL; /* "sorry channel spec wrong " */
144 } /* switch(ui_NoOfChannels) */
150 +----------------------------------------------------------------------------+
151 | Function Name : int i_APCI1516_ConfigDigitalOutput (struct comedi_device *dev,
152 struct comedi_subdevice *s struct comedi_insn *insn,unsigned int *data) |
154 +----------------------------------------------------------------------------+
155 | Task : Configures The Digital Output Subdevice. |
156 +----------------------------------------------------------------------------+
157 | Input Parameters : struct comedi_device *dev : Driver handle |
158 | unsigned int *data : Data Pointer contains |
159 | configuration parameters as below |
160 | struct comedi_subdevice *s, :pointer to subdevice structure
161 struct comedi_insn *insn :pointer to insn structure |
162 | data[0] :1:Memory on |
166 +----------------------------------------------------------------------------+
167 | Output Parameters : -- |
168 +----------------------------------------------------------------------------+
169 | Return Value : TRUE : No error occur |
170 | : FALSE : Error occur. Return the error |
172 +----------------------------------------------------------------------------+
174 int i_APCI1516_ConfigDigitalOutput(struct comedi_device * dev, struct comedi_subdevice * s,
175 struct comedi_insn * insn, unsigned int * data)
177 devpriv->b_OutputMemoryStatus = data[0];
182 +----------------------------------------------------------------------------+
183 | Function Name : int i_APCI1516_WriteDigitalOutput |
184 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
185 unsigned int *data) |
186 +----------------------------------------------------------------------------+
187 | Task : Writes port value To the selected port |
188 +----------------------------------------------------------------------------+
189 | Input Parameters : struct comedi_device *dev : Driver handle |
190 | struct comedi_subdevice *s, :pointer to subdevice structure
191 struct comedi_insn *insn :pointer to insn structure |
192 | unsigned int *data : Data Pointer to read status |
193 +----------------------------------------------------------------------------+
194 | Output Parameters : -- |
195 +----------------------------------------------------------------------------+
196 | Return Value : TRUE : No error occur |
197 | : FALSE : Error occur. Return the error |
199 +----------------------------------------------------------------------------+
202 int i_APCI1516_WriteDigitalOutput(struct comedi_device * dev, struct comedi_subdevice * s,
203 struct comedi_insn * insn, unsigned int * data)
205 unsigned int ui_Temp, ui_Temp1;
206 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
208 printk("EL311003 : @=%x\n", devpriv->iobase + APCI1516_DIGITAL_OP);
210 if (devpriv->b_OutputMemoryStatus) {
211 ui_Temp = inw(devpriv->iobase + APCI1516_DIGITAL_OP);
213 } /* if(devpriv->b_OutputMemoryStatus ) */
216 } /* if(devpriv->b_OutputMemoryStatus ) */
219 data[0] = (data[0] << ui_NoOfChannel) | ui_Temp;
220 outw(data[0], devpriv->iobase + APCI1516_DIGITAL_OP);
222 printk("EL311003 : d=%d @=%x\n", data[0],
223 devpriv->iobase + APCI1516_DIGITAL_OP);
225 } /* if(data[1]==0) */
228 switch (ui_NoOfChannel) {
243 data[0] = data[0] | ui_Temp;
247 comedi_error(dev, " chan spec wrong");
248 return -EINVAL; /* "sorry channel spec wrong " */
250 } /* switch(ui_NoOfChannels) */
253 devpriv->iobase + APCI1516_DIGITAL_OP);
255 printk("EL311003 : d=%d @=%x\n", data[0],
256 devpriv->iobase + APCI1516_DIGITAL_OP);
257 } /* if(data[1]==1) */
259 printk("\nSpecified channel not supported\n");
260 } /* else if(data[1]==1) */
261 } /* elseif(data[1]==0) */
262 } /* if(data[3]==0) */
266 data[0] = ~data[0] & 0x1;
268 ui_Temp1 = ui_Temp1 << ui_NoOfChannel;
269 ui_Temp = ui_Temp | ui_Temp1;
270 data[0] = (data[0] << ui_NoOfChannel) ^ 0xff;
271 data[0] = data[0] & ui_Temp;
273 devpriv->iobase + APCI1516_DIGITAL_OP);
275 printk("EL311003 : d=%d @=%x\n", data[0],
276 devpriv->iobase + APCI1516_DIGITAL_OP);
278 } /* if(data[1]==0) */
281 switch (ui_NoOfChannel) {
284 data[0] = ~data[0] & 0x3;
287 ui_Temp1 << 2 * data[2];
288 ui_Temp = ui_Temp | ui_Temp1;
297 data[0] = ~data[0] & 0xf;
300 ui_Temp1 << 4 * data[2];
301 ui_Temp = ui_Temp | ui_Temp1;
315 return -EINVAL; /* "sorry channel spec wrong " */
317 } /* switch(ui_NoOfChannels) */
321 APCI1516_DIGITAL_OP);
323 printk("EL311003 : d=%d @=%x\n",
326 APCI1516_DIGITAL_OP);
327 } /* if(data[1]==1) */
329 printk("\nSpecified channel not supported\n");
330 } /* else if(data[1]==1) */
331 } /* elseif(data[1]==0) */
332 } /* if(data[3]==1); */
334 printk("\nSpecified functionality does not exist\n");
336 } /* if else data[3]==1) */
337 } /* if else data[3]==0) */
342 +----------------------------------------------------------------------------+
343 | Function Name : int i_APCI1516_ReadDigitalOutput |
344 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
345 unsigned int *data) |
346 +----------------------------------------------------------------------------+
347 | Task : Read value of the selected channel or port |
348 +----------------------------------------------------------------------------+
349 | Input Parameters : struct comedi_device *dev : Driver handle |
350 | struct comedi_subdevice *s, :pointer to subdevice structure
351 struct comedi_insn *insn :pointer to insn structure |
352 | unsigned int *data : Data Pointer to read status |
353 +----------------------------------------------------------------------------+
354 | Output Parameters : -- |
355 +----------------------------------------------------------------------------+
356 | Return Value : TRUE : No error occur |
357 | : FALSE : Error occur. Return the error |
359 +----------------------------------------------------------------------------+
362 int i_APCI1516_ReadDigitalOutput(struct comedi_device * dev, struct comedi_subdevice * s,
363 struct comedi_insn * insn, unsigned int * data)
366 unsigned int ui_Temp;
367 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
369 *data = inw(devpriv->iobase + APCI1516_DIGITAL_OP_RW);
371 *data = (*data >> ui_NoOfChannel) & 0x1;
372 } /* if(ui_Temp==0) */
375 switch (ui_NoOfChannel) {
378 *data = (*data >> (2 * data[1])) & 3;
382 *data = (*data >> (4 * data[1])) & 15;
389 comedi_error(dev, " chan spec wrong");
390 return -EINVAL; /* "sorry channel spec wrong " */
392 } /* switch(ui_NoOfChannels) */
393 } /* if(ui_Temp==1) */
395 printk("\nSpecified channel not supported \n");
396 } /* elseif(ui_Temp==1) */
397 } /* elseif(ui_Temp==0) */
402 +----------------------------------------------------------------------------+
403 | Function Name : int i_APCI1516_ConfigWatchdog(struct comedi_device *dev,
404 struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
406 +----------------------------------------------------------------------------+
407 | Task : Configures The Watchdog |
408 +----------------------------------------------------------------------------+
409 | Input Parameters : struct comedi_device *dev : Driver handle |
410 | struct comedi_subdevice *s, :pointer to subdevice structure
411 struct comedi_insn *insn :pointer to insn structure |
412 | unsigned int *data : Data Pointer to read status |
413 +----------------------------------------------------------------------------+
414 | Output Parameters : -- |
415 +----------------------------------------------------------------------------+
416 | Return Value : TRUE : No error occur |
417 | : FALSE : Error occur. Return the error |
419 +----------------------------------------------------------------------------+
422 int i_APCI1516_ConfigWatchdog(struct comedi_device * dev, struct comedi_subdevice * s,
423 struct comedi_insn * insn, unsigned int * data)
426 /* Disable the watchdog */
428 devpriv->i_IobaseAddon +
429 APCI1516_WATCHDOG_ENABLEDISABLE);
430 /* Loading the Reload value */
432 devpriv->i_IobaseAddon +
433 APCI1516_WATCHDOG_RELOAD_VALUE);
434 data[1] = data[1] >> 16;
436 devpriv->i_IobaseAddon +
437 APCI1516_WATCHDOG_RELOAD_VALUE + 2);
438 } /* if(data[0]==0) */
440 printk("\nThe input parameters are wrong\n");
442 } /* elseif(data[0]==0) */
448 +----------------------------------------------------------------------------+
449 | Function Name : int i_APCI1516_StartStopWriteWatchdog |
450 | (struct comedi_device *dev,struct comedi_subdevice *s,
451 struct comedi_insn *insn,unsigned int *data); |
452 +----------------------------------------------------------------------------+
453 | Task : Start / Stop The Watchdog |
454 +----------------------------------------------------------------------------+
455 | Input Parameters : struct comedi_device *dev : Driver handle |
456 | struct comedi_subdevice *s, :pointer to subdevice structure
457 struct comedi_insn *insn :pointer to insn structure |
458 | unsigned int *data : Data Pointer to read status |
459 +----------------------------------------------------------------------------+
460 | Output Parameters : -- |
461 +----------------------------------------------------------------------------+
462 | Return Value : TRUE : No error occur |
463 | : FALSE : Error occur. Return the error |
465 +----------------------------------------------------------------------------+
468 int i_APCI1516_StartStopWriteWatchdog(struct comedi_device * dev, struct comedi_subdevice * s,
469 struct comedi_insn * insn, unsigned int * data)
472 case 0: /* stop the watchdog */
473 outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_ENABLEDISABLE); /* disable the watchdog */
475 case 1: /* start the watchdog */
477 devpriv->i_IobaseAddon +
478 APCI1516_WATCHDOG_ENABLEDISABLE);
480 case 2: /* Software trigger */
482 devpriv->i_IobaseAddon +
483 APCI1516_WATCHDOG_ENABLEDISABLE);
486 printk("\nSpecified functionality does not exist\n");
488 } /* switch(data[0]) */
493 +----------------------------------------------------------------------------+
494 | Function Name : int i_APCI1516_ReadWatchdog |
495 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
496 unsigned int *data); |
497 +----------------------------------------------------------------------------+
498 | Task : Read The Watchdog |
499 +----------------------------------------------------------------------------+
500 | Input Parameters : struct comedi_device *dev : Driver handle |
501 | struct comedi_subdevice *s, :pointer to subdevice structure
502 struct comedi_insn *insn :pointer to insn structure |
503 | unsigned int *data : Data Pointer to read status |
504 +----------------------------------------------------------------------------+
505 | Output Parameters : -- |
506 +----------------------------------------------------------------------------+
507 | Return Value : TRUE : No error occur |
508 | : FALSE : Error occur. Return the error |
510 +----------------------------------------------------------------------------+
513 int i_APCI1516_ReadWatchdog(struct comedi_device * dev, struct comedi_subdevice * s,
514 struct comedi_insn * insn, unsigned int * data)
516 data[0] = inw(devpriv->i_IobaseAddon + APCI1516_WATCHDOG_STATUS) & 0x1;
521 +----------------------------------------------------------------------------+
522 | Function Name : int i_APCI1516_Reset(struct comedi_device *dev) | |
523 +----------------------------------------------------------------------------+
524 | Task :resets all the registers |
525 +----------------------------------------------------------------------------+
526 | Input Parameters : struct comedi_device *dev
527 +----------------------------------------------------------------------------+
528 | Output Parameters : -- |
529 +----------------------------------------------------------------------------+
532 +----------------------------------------------------------------------------+
535 int i_APCI1516_Reset(struct comedi_device * dev)
537 outw(0x0, devpriv->iobase + APCI1516_DIGITAL_OP); /* RESETS THE DIGITAL OUTPUTS */
538 outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_ENABLEDISABLE);
539 outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_RELOAD_VALUE);
540 outw(0x0, devpriv->i_IobaseAddon + APCI1516_WATCHDOG_RELOAD_VALUE + 2);