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-2200 | Compiler : GCC |
33 | Module name : hwdrv_apci2200.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
37 | Description : Hardware Layer Acces For APCI-2200 |
38 +-----------------------------------------------------------------------+
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
46 +----------+-----------+------------------------------------------------+
50 +----------------------------------------------------------------------------+
52 +----------------------------------------------------------------------------+
54 #include "hwdrv_apci2200.h"
57 +----------------------------------------------------------------------------+
58 | Function Name : int i_APCI2200_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_APCI2200_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 <= 7) {
83 ui_TmpValue = (unsigned int) inw(devpriv->iobase + APCI2200_DIGITAL_IP);
84 *data = (ui_TmpValue >> ui_Channel) & 0x1;
85 } /* if(ui_Channel >= 0 && ui_Channel <=7) */
87 printk("\nThe specified channel does not exist\n");
88 return -EINVAL; /* "sorry channel spec wrong " */
89 } /* else if(ui_Channel >= 0 && ui_Channel <=7) */
95 +----------------------------------------------------------------------------+
96 | Function Name : int i_APCI2200_ReadMoreDigitalInput |
97 | (struct comedi_device *dev,struct comedi_subdevice *s, |
98 | struct comedi_insn *insn,unsigned int *data) |
99 +----------------------------------------------------------------------------+
100 | Task : Return the status of the Requested digital inputs |
101 +----------------------------------------------------------------------------+
102 | Input Parameters : struct comedi_device *dev : Driver handle |
103 | struct comedi_subdevice *s, :pointer to subdevice structure
104 | struct comedi_insn *insn :pointer to insn structure |
105 | unsigned int *data : Data Pointer to read status |
106 +----------------------------------------------------------------------------+
107 | Output Parameters : -- |
108 +----------------------------------------------------------------------------+
109 | Return Value : TRUE : No error occur |
110 | : FALSE : Error occur. Return the error |
112 +----------------------------------------------------------------------------+
115 int i_APCI2200_ReadMoreDigitalInput(struct comedi_device *dev, struct comedi_subdevice *s,
116 struct comedi_insn *insn, unsigned int *data)
119 unsigned int ui_PortValue = data[0];
120 unsigned int ui_Mask = 0;
121 unsigned int ui_NoOfChannels;
123 ui_NoOfChannels = CR_CHAN(insn->chanspec);
125 *data = (unsigned int) inw(devpriv->iobase + APCI2200_DIGITAL_IP);
126 switch (ui_NoOfChannels) {
129 *data = (*data >> (2 * ui_PortValue)) & ui_Mask;
133 *data = (*data >> (4 * ui_PortValue)) & ui_Mask;
139 printk("\nWrong parameters\n");
140 return -EINVAL; /* "sorry channel spec wrong " */
142 } /* switch(ui_NoOfChannels) */
148 +----------------------------------------------------------------------------+
149 | Function Name : int i_APCI2200_ConfigDigitalOutput (struct comedi_device *dev,
150 | struct comedi_subdevice *s struct comedi_insn *insn,unsigned int *data) |
152 +----------------------------------------------------------------------------+
153 | Task : Configures The Digital Output Subdevice. |
154 +----------------------------------------------------------------------------+
155 | Input Parameters : struct comedi_device *dev : Driver handle |
156 | unsigned int *data : Data Pointer contains |
157 | configuration parameters as below |
158 | struct comedi_subdevice *s, :pointer to subdevice structure
159 | struct comedi_insn *insn :pointer to insn structure |
160 | data[0] :1:Memory on |
164 +----------------------------------------------------------------------------+
165 | Output Parameters : -- |
166 +----------------------------------------------------------------------------+
167 | Return Value : TRUE : No error occur |
168 | : FALSE : Error occur. Return the error |
170 +----------------------------------------------------------------------------+
172 int i_APCI2200_ConfigDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
173 struct comedi_insn *insn, unsigned int *data)
175 devpriv->b_OutputMemoryStatus = data[0];
180 +----------------------------------------------------------------------------+
181 | Function Name : int i_APCI2200_WriteDigitalOutput |
182 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
183 | unsigned int *data) |
184 +----------------------------------------------------------------------------+
185 | Task : Writes port value To the selected port |
186 +----------------------------------------------------------------------------+
187 | Input Parameters : struct comedi_device *dev : Driver handle |
188 | struct comedi_subdevice *s, :pointer to subdevice structure
189 | struct comedi_insn *insn :pointer to insn structure |
190 | unsigned int *data : Data Pointer to read status |
191 +----------------------------------------------------------------------------+
192 | Output Parameters : -- |
193 +----------------------------------------------------------------------------+
194 | Return Value : TRUE : No error occur |
195 | : FALSE : Error occur. Return the error |
197 +----------------------------------------------------------------------------+
200 int i_APCI2200_WriteDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
201 struct comedi_insn *insn, unsigned int *data)
203 unsigned int ui_Temp, ui_Temp1;
204 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
205 if (devpriv->b_OutputMemoryStatus) {
206 ui_Temp = inw(devpriv->iobase + APCI2200_DIGITAL_OP);
208 } /* if(devpriv->b_OutputMemoryStatus ) */
211 } /* if(devpriv->b_OutputMemoryStatus ) */
214 data[0] = (data[0] << ui_NoOfChannel) | ui_Temp;
215 outw(data[0], devpriv->iobase + APCI2200_DIGITAL_OP);
216 } /* if(data[1]==0) */
219 switch (ui_NoOfChannel) {
239 data[0] = data[0] | ui_Temp;
242 comedi_error(dev, " chan spec wrong");
243 return -EINVAL; /* "sorry channel spec wrong " */
245 } /* switch(ui_NoOfChannels) */
248 devpriv->iobase + APCI2200_DIGITAL_OP);
249 } /* if(data[1]==1) */
251 printk("\nSpecified channel not supported\n");
252 } /* else if(data[1]==1) */
253 } /* elseif(data[1]==0) */
254 } /* if(data[3]==0) */
258 data[0] = ~data[0] & 0x1;
260 ui_Temp1 = ui_Temp1 << ui_NoOfChannel;
261 ui_Temp = ui_Temp | ui_Temp1;
262 data[0] = (data[0] << ui_NoOfChannel) ^ 0xffff;
263 data[0] = data[0] & ui_Temp;
265 devpriv->iobase + APCI2200_DIGITAL_OP);
266 } /* if(data[1]==0) */
269 switch (ui_NoOfChannel) {
272 data[0] = ~data[0] & 0x3;
275 ui_Temp1 << 2 * data[2];
276 ui_Temp = ui_Temp | ui_Temp1;
285 data[0] = ~data[0] & 0xf;
288 ui_Temp1 << 4 * data[2];
289 ui_Temp = ui_Temp | ui_Temp1;
298 data[0] = ~data[0] & 0xff;
301 ui_Temp1 << 8 * data[2];
302 ui_Temp = ui_Temp | ui_Temp1;
315 return -EINVAL; /* "sorry channel spec wrong " */
317 } /* switch(ui_NoOfChannels) */
321 APCI2200_DIGITAL_OP);
322 } /* if(data[1]==1) */
324 printk("\nSpecified channel not supported\n");
325 } /* else if(data[1]==1) */
326 } /* elseif(data[1]==0) */
327 } /* if(data[3]==1); */
329 printk("\nSpecified functionality does not exist\n");
331 } /* if else data[3]==1) */
332 } /* if else data[3]==0) */
337 +----------------------------------------------------------------------------+
338 | Function Name : int i_APCI2200_ReadDigitalOutput |
339 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
340 | unsigned int *data) |
341 +----------------------------------------------------------------------------+
342 | Task : Read value of the selected channel or port |
343 +----------------------------------------------------------------------------+
344 | Input Parameters : struct comedi_device *dev : Driver handle |
345 | struct comedi_subdevice *s, :pointer to subdevice structure
346 | struct comedi_insn *insn :pointer to insn structure |
347 | unsigned int *data : Data Pointer to read status |
348 +----------------------------------------------------------------------------+
349 | Output Parameters : -- |
350 +----------------------------------------------------------------------------+
351 | Return Value : TRUE : No error occur |
352 | : FALSE : Error occur. Return the error |
354 +----------------------------------------------------------------------------+
357 int i_APCI2200_ReadDigitalOutput(struct comedi_device *dev, struct comedi_subdevice *s,
358 struct comedi_insn *insn, unsigned int *data)
361 unsigned int ui_Temp;
362 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
364 *data = inw(devpriv->iobase + APCI2200_DIGITAL_OP);
366 *data = (*data >> ui_NoOfChannel) & 0x1;
367 } /* if(ui_Temp==0) */
370 switch (ui_NoOfChannel) {
373 *data = (*data >> (2 * data[1])) & 3;
377 *data = (*data >> (4 * data[1])) & 15;
381 *data = (*data >> (8 * data[1])) & 255;
388 comedi_error(dev, " chan spec wrong");
389 return -EINVAL; /* "sorry channel spec wrong " */
391 } /* switch(ui_NoOfChannels) */
392 } /* if(ui_Temp==1) */
394 printk("\nSpecified channel not supported \n");
395 } /* elseif(ui_Temp==1) */
396 } /* elseif(ui_Temp==0) */
401 +----------------------------------------------------------------------------+
402 | Function Name : int i_APCI2200_ConfigWatchdog(struct comedi_device *dev,
403 | struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
405 +----------------------------------------------------------------------------+
406 | Task : Configures The Watchdog |
407 +----------------------------------------------------------------------------+
408 | Input Parameters : struct comedi_device *dev : Driver handle |
409 | struct comedi_subdevice *s, :pointer to subdevice structure
410 | struct comedi_insn *insn :pointer to insn structure |
411 | unsigned int *data : Data Pointer to read status |
412 +----------------------------------------------------------------------------+
413 | Output Parameters : -- |
414 +----------------------------------------------------------------------------+
415 | Return Value : TRUE : No error occur |
416 | : FALSE : Error occur. Return the error |
418 +----------------------------------------------------------------------------+
421 int i_APCI2200_ConfigWatchdog(struct comedi_device *dev, struct comedi_subdevice *s,
422 struct comedi_insn *insn, unsigned int *data)
425 /* Disable the watchdog */
427 devpriv->iobase + APCI2200_WATCHDOG +
428 APCI2200_WATCHDOG_ENABLEDISABLE);
429 /* Loading the Reload value */
431 devpriv->iobase + APCI2200_WATCHDOG +
432 APCI2200_WATCHDOG_RELOAD_VALUE);
433 data[1] = data[1] >> 16;
435 devpriv->iobase + APCI2200_WATCHDOG +
436 APCI2200_WATCHDOG_RELOAD_VALUE + 2);
437 } /* if(data[0]==0) */
439 printk("\nThe input parameters are wrong\n");
441 } /* elseif(data[0]==0) */
447 +----------------------------------------------------------------------------+
448 | Function Name : int i_APCI2200_StartStopWriteWatchdog |
449 | (struct comedi_device *dev,struct comedi_subdevice *s,
450 struct comedi_insn *insn,unsigned int *data); |
451 +----------------------------------------------------------------------------+
452 | Task : Start / Stop The Watchdog |
453 +----------------------------------------------------------------------------+
454 | Input Parameters : struct comedi_device *dev : Driver handle |
455 | struct comedi_subdevice *s, :pointer to subdevice structure
456 struct comedi_insn *insn :pointer to insn structure |
457 | unsigned int *data : Data Pointer to read status |
458 +----------------------------------------------------------------------------+
459 | Output Parameters : -- |
460 +----------------------------------------------------------------------------+
461 | Return Value : TRUE : No error occur |
462 | : FALSE : Error occur. Return the error |
464 +----------------------------------------------------------------------------+
467 int i_APCI2200_StartStopWriteWatchdog(struct comedi_device *dev, struct comedi_subdevice *s,
468 struct comedi_insn *insn, unsigned int *data)
471 case 0: /* stop the watchdog */
472 outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); /* disable the watchdog */
474 case 1: /* start the watchdog */
476 devpriv->iobase + APCI2200_WATCHDOG +
477 APCI2200_WATCHDOG_ENABLEDISABLE);
479 case 2: /* Software trigger */
481 devpriv->iobase + APCI2200_WATCHDOG +
482 APCI2200_WATCHDOG_ENABLEDISABLE);
485 printk("\nSpecified functionality does not exist\n");
487 } /* switch(data[0]) */
492 +----------------------------------------------------------------------------+
493 | Function Name : int i_APCI2200_ReadWatchdog |
494 | (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
495 | unsigned int *data); |
496 +----------------------------------------------------------------------------+
497 | Task : Read The Watchdog |
498 +----------------------------------------------------------------------------+
499 | Input Parameters : struct comedi_device *dev : Driver handle |
500 | struct comedi_subdevice *s, :pointer to subdevice structure
501 | struct comedi_insn *insn :pointer to insn structure |
502 | unsigned int *data : Data Pointer to read status |
503 +----------------------------------------------------------------------------+
504 | Output Parameters : -- |
505 +----------------------------------------------------------------------------+
506 | Return Value : TRUE : No error occur |
507 | : FALSE : Error occur. Return the error |
509 +----------------------------------------------------------------------------+
512 int i_APCI2200_ReadWatchdog(struct comedi_device *dev, struct comedi_subdevice *s,
513 struct comedi_insn *insn, unsigned int *data)
516 inw(devpriv->iobase + APCI2200_WATCHDOG +
517 APCI2200_WATCHDOG_STATUS) & 0x1;
522 +----------------------------------------------------------------------------+
523 | Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | |
524 +----------------------------------------------------------------------------+
525 | Task :resets all the registers |
526 +----------------------------------------------------------------------------+
527 | Input Parameters : struct comedi_device *dev
528 +----------------------------------------------------------------------------+
529 | Output Parameters : -- |
530 +----------------------------------------------------------------------------+
533 +----------------------------------------------------------------------------+
536 int i_APCI2200_Reset(struct comedi_device *dev)
538 outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); /* RESETS THE DIGITAL OUTPUTS */
540 devpriv->iobase + APCI2200_WATCHDOG +
541 APCI2200_WATCHDOG_ENABLEDISABLE);
543 devpriv->iobase + APCI2200_WATCHDOG +
544 APCI2200_WATCHDOG_RELOAD_VALUE);
546 devpriv->iobase + APCI2200_WATCHDOG +
547 APCI2200_WATCHDOG_RELOAD_VALUE + 2);