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 : API APCI1648 | Compiler : gcc |
33 | Module name : TTL.C | Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: S. Weber | Date : 25/05/2005 |
36 +-----------------------------------------------------------------------+
37 | Description : APCI-16XX TTL I/O module |
40 +-----------------------------------------------------------------------+
42 +-----------------------------------------------------------------------+
43 | Date | Author | Description of updates |
44 +----------+-----------+------------------------------------------------+
45 |25.05.2005| S.Weber | Creation |
47 +-----------------------------------------------------------------------+
51 +----------------------------------------------------------------------------+
53 +----------------------------------------------------------------------------+
56 #include "hwdrv_apci16xx.h"
59 +----------------------------------------------------------------------------+
60 | Function Name : int i_APCI16XX_InsnConfigInitTTLIO |
61 | (struct comedi_device *dev, |
62 | struct comedi_subdevice *s, |
63 | struct comedi_insn *insn, |
64 | unsigned int *data) |
65 +----------------------------------------------------------------------------+
66 | Task APCI16XX_TTL_INIT (using defaults) : |
67 | Configure the TTL I/O operating mode from all ports |
68 | You must calling this function be |
69 | for you call any other function witch access of TTL. |
70 | APCI16XX_TTL_INITDIRECTION(user inputs for direction) |
71 +----------------------------------------------------------------------------+
72 | Input Parameters : b_InitType = (unsigned char) data[0]; |
73 | b_Port0Mode = (unsigned char) data[1]; |
74 | b_Port1Mode = (unsigned char) data[2]; |
75 | b_Port2Mode = (unsigned char) data[3]; |
76 | b_Port3Mode = (unsigned char) data[4]; |
78 +----------------------------------------------------------------------------+
79 | Output Parameters : - |
80 +----------------------------------------------------------------------------+
81 | Return Value :>0: No error |
82 | -1: Port 0 mode selection is wrong |
83 | -2: Port 1 mode selection is wrong |
84 | -3: Port 2 mode selection is wrong |
85 | -4: Port 3 mode selection is wrong |
86 | -X: Port X-1 mode selection is wrong |
88 | -100 : Config command error |
89 | -101 : Data size error |
90 +----------------------------------------------------------------------------+
93 int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device * dev,
94 struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
96 int i_ReturnValue = insn->n;
97 unsigned char b_Command = 0;
98 unsigned char b_Cpt = 0;
99 unsigned char b_NumberOfPort =
100 (unsigned char) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
102 /************************/
103 /* Test the buffer size */
104 /************************/
107 /*******************/
108 /* Get the command */
109 /* **************** */
111 b_Command = (unsigned char) data[0];
113 /********************/
114 /* Test the command */
115 /********************/
117 if ((b_Command == APCI16XX_TTL_INIT) ||
118 (b_Command == APCI16XX_TTL_INITDIRECTION) ||
119 (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) {
120 /***************************************/
121 /* Test the initialisation buffer size */
122 /***************************************/
124 if ((b_Command == APCI16XX_TTL_INITDIRECTION)
125 && ((unsigned char) (insn->n - 1) != b_NumberOfPort)) {
126 /*******************/
127 /* Data size error */
128 /*******************/
130 printk("\nBuffer size error");
131 i_ReturnValue = -101;
134 if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY)
135 && ((unsigned char) (insn->n) != 2)) {
136 /*******************/
137 /* Data size error */
138 /*******************/
140 printk("\nBuffer size error");
141 i_ReturnValue = -101;
144 /************************/
145 /* Config command error */
146 /************************/
148 printk("\nCommand selection error");
149 i_ReturnValue = -100;
152 /*******************/
153 /* Data size error */
154 /*******************/
156 printk("\nBuffer size error");
157 i_ReturnValue = -101;
160 /**************************************************************************/
161 /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */
162 /**************************************************************************/
164 if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) {
165 memset(devpriv->ul_TTLPortConfiguration, 0,
166 sizeof(devpriv->ul_TTLPortConfiguration));
168 /*************************************/
169 /* Test the port direction selection */
170 /*************************************/
173 (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0);
175 /**********************/
176 /* Test the direction */
177 /**********************/
179 if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) {
180 /************************/
181 /* Port direction error */
182 /************************/
184 printk("\nPort %d direction selection error",
186 i_ReturnValue = -(int) b_Cpt;
189 /**************************/
190 /* Save the configuration */
191 /**************************/
193 devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] =
194 devpriv->ul_TTLPortConfiguration[(b_Cpt -
195 1) / 4] | (data[b_Cpt] << (8 * ((b_Cpt -
200 /**************************/
201 /* Test if no error occur */
202 /**************************/
204 if (i_ReturnValue >= 0) {
205 /***********************************/
206 /* Test if TTL port initilaisation */
207 /***********************************/
209 if ((b_Command == APCI16XX_TTL_INIT)
210 || (b_Command == APCI16XX_TTL_INITDIRECTION)) {
211 /******************************/
212 /* Set all port configuration */
213 /******************************/
215 for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt++) {
216 if ((b_Cpt % 4) == 0) {
217 /*************************/
218 /* Set the configuration */
219 /*************************/
222 ul_TTLPortConfiguration[b_Cpt /
224 devpriv->iobase + 32 + b_Cpt);
230 /************************************************/
231 /* Test if output memory initialisation command */
232 /************************************************/
234 if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) {
236 devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE;
238 devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
242 return (i_ReturnValue);
246 +----------------------------------------------------------------------------+
248 +----------------------------------------------------------------------------+
252 +----------------------------------------------------------------------------+
253 | Function Name : int i_APCI16XX_InsnBitsReadTTLIO |
254 | (struct comedi_device *dev, |
255 | struct comedi_subdevice *s, |
256 | struct comedi_insn *insn, |
257 | unsigned int *data) |
258 +----------------------------------------------------------------------------+
259 | Task : Read the status from selected TTL digital input |
261 +----------------------------------------------------------------------------+
262 | Task : Read the status from digital input port |
264 +----------------------------------------------------------------------------+
265 | Input Parameters : |
266 | APCI16XX_TTL_READCHANNEL |
267 | b_SelectedPort= CR_RANGE(insn->chanspec); |
268 | b_InputChannel= CR_CHAN(insn->chanspec); |
269 | b_ReadType = (unsigned char) data[0]; |
271 | APCI16XX_TTL_READPORT |
272 | b_SelectedPort= CR_RANGE(insn->chanspec); |
273 | b_ReadType = (unsigned char) data[0]; |
274 +----------------------------------------------------------------------------+
275 | Output Parameters : data[0] 0 : Channle is not active |
276 | 1 : Channle is active |
277 +----------------------------------------------------------------------------+
278 | Return Value : >0 : No error |
279 | -100 : Config command error |
280 | -101 : Data size error |
281 | -102 : The selected TTL input port is wrong |
282 | -103 : The selected TTL digital input is wrong |
283 +----------------------------------------------------------------------------+
286 int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device * dev,
287 struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
289 int i_ReturnValue = insn->n;
290 unsigned char b_Command = 0;
291 unsigned char b_NumberOfPort =
292 (unsigned char) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
293 unsigned char b_SelectedPort = CR_RANGE(insn->chanspec);
294 unsigned char b_InputChannel = CR_CHAN(insn->chanspec);
295 unsigned char *pb_Status;
296 unsigned int dw_Status;
298 /************************/
299 /* Test the buffer size */
300 /************************/
303 /*******************/
304 /* Get the command */
305 /* **************** */
307 b_Command = (unsigned char) data[0];
309 /********************/
310 /* Test the command */
311 /********************/
313 if ((b_Command == APCI16XX_TTL_READCHANNEL)
314 || (b_Command == APCI16XX_TTL_READPORT)) {
315 /**************************/
316 /* Test the selected port */
317 /**************************/
319 if (b_SelectedPort < b_NumberOfPort) {
320 /**********************/
321 /* Test if input port */
322 /**********************/
324 if (((devpriv->ul_TTLPortConfiguration
331 /***************************/
332 /* Test the channel number */
333 /***************************/
336 APCI16XX_TTL_READCHANNEL)
337 && (b_InputChannel > 7)) {
338 /*******************************************/
339 /* The selected TTL digital input is wrong */
340 /*******************************************/
342 printk("\nChannel selection error");
343 i_ReturnValue = -103;
346 /****************************************/
347 /* The selected TTL input port is wrong */
348 /****************************************/
350 printk("\nPort selection error");
351 i_ReturnValue = -102;
354 /****************************************/
355 /* The selected TTL input port is wrong */
356 /****************************************/
358 printk("\nPort selection error");
359 i_ReturnValue = -102;
362 /************************/
363 /* Config command error */
364 /************************/
366 printk("\nCommand selection error");
367 i_ReturnValue = -100;
370 /*******************/
371 /* Data size error */
372 /*******************/
374 printk("\nBuffer size error");
375 i_ReturnValue = -101;
378 /**************************/
379 /* Test if no error occur */
380 /**************************/
382 if (i_ReturnValue >= 0) {
383 pb_Status = (unsigned char *) & data[0];
385 /*******************************/
386 /* Get the digital inpu status */
387 /*******************************/
390 inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4));
391 dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF;
393 /***********************/
394 /* Save the port value */
395 /***********************/
397 *pb_Status = (unsigned char) dw_Status;
399 /***************************************/
400 /* Test if read channel status command */
401 /***************************************/
403 if (b_Command == APCI16XX_TTL_READCHANNEL) {
404 *pb_Status = (*pb_Status >> b_InputChannel) & 1;
408 return (i_ReturnValue);
412 +----------------------------------------------------------------------------+
413 | Function Name : int i_APCI16XX_InsnReadTTLIOAllPortValue |
414 | (struct comedi_device *dev, |
415 | struct comedi_subdevice *s, |
416 | struct comedi_insn *insn, |
417 | unsigned int *data) |
418 +----------------------------------------------------------------------------+
419 | Task : Read the status from all digital input ports |
420 +----------------------------------------------------------------------------+
421 | Input Parameters : - |
422 +----------------------------------------------------------------------------+
423 | Output Parameters : data[0] : Port 0 to 3 data |
424 | data[1] : Port 4 to 7 data |
426 +----------------------------------------------------------------------------+
427 | Return Value : 0: No error |
428 | -100 : Read command error |
429 | -101 : Data size error |
430 +----------------------------------------------------------------------------+
433 int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device * dev,
434 struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
436 unsigned char b_Command = (unsigned char) CR_AREF(insn->chanspec);
437 int i_ReturnValue = insn->n;
438 unsigned char b_Cpt = 0;
439 unsigned char b_NumberOfPort = 0;
440 unsigned int *pls_ReadData = data;
442 /********************/
443 /* Test the command */
444 /********************/
446 if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS)
447 || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) {
448 /**********************************/
449 /* Get the number of 32-Bit ports */
450 /**********************************/
453 (unsigned char) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 32);
454 if ((b_NumberOfPort * 32) <
455 devpriv->ps_BoardInfo->i_NbrTTLChannel) {
456 b_NumberOfPort = b_NumberOfPort + 1;
459 /************************/
460 /* Test the buffer size */
461 /************************/
463 if (insn->n >= b_NumberOfPort) {
464 if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) {
465 /**************************/
466 /* Read all digital input */
467 /**************************/
469 for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) {
470 /************************/
471 /* Read the 32-Bit port */
472 /************************/
474 pls_ReadData[b_Cpt] =
475 inl(devpriv->iobase + 8 +
478 /**************************************/
479 /* Mask all channels used als outputs */
480 /**************************************/
482 pls_ReadData[b_Cpt] =
483 pls_ReadData[b_Cpt] &
485 ul_TTLPortConfiguration[b_Cpt]);
488 /****************************/
489 /* Read all digital outputs */
490 /****************************/
492 for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) {
493 /************************/
494 /* Read the 32-Bit port */
495 /************************/
497 pls_ReadData[b_Cpt] =
498 inl(devpriv->iobase + 20 +
501 /**************************************/
502 /* Mask all channels used als outputs */
503 /**************************************/
505 pls_ReadData[b_Cpt] =
506 pls_ReadData[b_Cpt] & devpriv->
507 ul_TTLPortConfiguration[b_Cpt];
511 /*******************/
512 /* Data size error */
513 /*******************/
515 printk("\nBuffer size error");
516 i_ReturnValue = -101;
523 printk("\nCommand selection error");
524 i_ReturnValue = -100;
527 return (i_ReturnValue);
531 +----------------------------------------------------------------------------+
533 +----------------------------------------------------------------------------+
537 +----------------------------------------------------------------------------+
538 | Function Name : int i_APCI16XX_InsnBitsWriteTTLIO |
539 | (struct comedi_device *dev, |
540 | struct comedi_subdevice *s, |
541 | struct comedi_insn *insn, |
542 | unsigned int *data) |
543 +----------------------------------------------------------------------------+
544 | Task : Set the state from selected TTL digital output |
545 | (b_OutputChannel) |
546 +----------------------------------------------------------------------------+
547 | Task : Set the state from digital output port |
549 +----------------------------------------------------------------------------+
550 | Input Parameters : |
551 | APCI16XX_TTL_WRITECHANNEL_ON | APCI16XX_TTL_WRITECHANNEL_OFF |
552 | b_SelectedPort = CR_RANGE(insn->chanspec); |
553 | b_OutputChannel= CR_CHAN(insn->chanspec); |
554 | b_Command = (unsigned char) data[0]; |
556 | APCI16XX_TTL_WRITEPORT_ON | APCI16XX_TTL_WRITEPORT_OFF |
557 | b_SelectedPort = CR_RANGE(insn->chanspec); |
558 | b_Command = (unsigned char) data[0]; |
559 +----------------------------------------------------------------------------+
560 | Output Parameters : data[0] : TTL output port 0 to 3 data |
561 | data[1] : TTL output port 4 to 7 data |
563 +----------------------------------------------------------------------------+
564 | Return Value : >0 : No error |
565 | -100 : Command error |
566 | -101 : Data size error |
567 | -102 : The selected TTL output port is wrong |
568 | -103 : The selected TTL digital output is wrong |
569 | -104 : Output memory disabled |
570 +----------------------------------------------------------------------------+
573 int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device * dev,
574 struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
576 int i_ReturnValue = insn->n;
577 unsigned char b_Command = 0;
578 unsigned char b_NumberOfPort =
579 (unsigned char) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
580 unsigned char b_SelectedPort = CR_RANGE(insn->chanspec);
581 unsigned char b_OutputChannel = CR_CHAN(insn->chanspec);
582 unsigned int dw_Status = 0;
584 /************************/
585 /* Test the buffer size */
586 /************************/
589 /*******************/
590 /* Get the command */
591 /* **************** */
593 b_Command = (unsigned char) data[0];
595 /********************/
596 /* Test the command */
597 /********************/
599 if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) ||
600 (b_Command == APCI16XX_TTL_WRITEPORT_ON) ||
601 (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||
602 (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) {
603 /**************************/
604 /* Test the selected port */
605 /**************************/
607 if (b_SelectedPort < b_NumberOfPort) {
608 /***********************/
609 /* Test if output port */
610 /***********************/
612 if (((devpriv->ul_TTLPortConfiguration
619 /***************************/
620 /* Test the channel number */
621 /***************************/
623 if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) {
624 /********************************************/
625 /* The selected TTL digital output is wrong */
626 /********************************************/
628 printk("\nChannel selection error");
629 i_ReturnValue = -103;
632 if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) {
633 /********************************************/
634 /* The selected TTL digital output is wrong */
635 /********************************************/
637 printk("\nOutput memory disabled");
638 i_ReturnValue = -104;
641 /************************/
642 /* Test the buffer size */
643 /************************/
645 if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) {
646 /*******************/
647 /* Data size error */
648 /*******************/
650 printk("\nBuffer size error");
651 i_ReturnValue = -101;
654 /*****************************************/
655 /* The selected TTL output port is wrong */
656 /*****************************************/
658 printk("\nPort selection error %lX",
659 (unsigned long)devpriv->
660 ul_TTLPortConfiguration[0]);
661 i_ReturnValue = -102;
664 /****************************************/
665 /* The selected TTL output port is wrong */
666 /****************************************/
668 printk("\nPort selection error %d %d",
669 b_SelectedPort, b_NumberOfPort);
670 i_ReturnValue = -102;
673 /************************/
674 /* Config command error */
675 /************************/
677 printk("\nCommand selection error");
678 i_ReturnValue = -100;
681 /*******************/
682 /* Data size error */
683 /*******************/
685 printk("\nBuffer size error");
686 i_ReturnValue = -101;
689 /**************************/
690 /* Test if no error occur */
691 /**************************/
693 if (i_ReturnValue >= 0) {
694 /********************************/
695 /* Get the digital output state */
696 /********************************/
699 inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
701 /**********************************/
702 /* Test if output memory not used */
703 /**********************************/
705 if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) {
706 /*********************************/
707 /* Clear the selected port value */
708 /*********************************/
711 dw_Status & (0xFFFFFFFFUL -
712 (0xFFUL << (8 * (b_SelectedPort % 4))));
715 /******************************/
716 /* Test if setting channel ON */
717 /******************************/
719 if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) {
721 dw_Status | (1UL << ((8 * (b_SelectedPort %
722 4)) + b_OutputChannel));
725 /***************************/
726 /* Test if setting port ON */
727 /***************************/
729 if (b_Command == APCI16XX_TTL_WRITEPORT_ON) {
731 dw_Status | ((data[1] & 0xFF) << (8 *
732 (b_SelectedPort % 4)));
735 /*******************************/
736 /* Test if setting channel OFF */
737 /*******************************/
739 if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) {
741 dw_Status & (0xFFFFFFFFUL -
742 (1UL << ((8 * (b_SelectedPort % 4)) +
746 /****************************/
747 /* Test if setting port OFF */
748 /****************************/
750 if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) {
752 dw_Status & (0xFFFFFFFFUL -
753 ((data[1] & 0xFF) << (8 * (b_SelectedPort %
758 devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
761 return (i_ReturnValue);
765 +----------------------------------------------------------------------------+
766 | Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | +----------------------------------------------------------------------------+
767 | Task :resets all the registers |
768 +----------------------------------------------------------------------------+
769 | Input Parameters : struct comedi_device *dev |
770 +----------------------------------------------------------------------------+
771 | Output Parameters : - |
772 +----------------------------------------------------------------------------+
774 +----------------------------------------------------------------------------+
777 int i_APCI16XX_Reset(struct comedi_device * dev)