Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
APCI1710_Ttl.c
Go to the documentation of this file.
1 
24 /*
25 
26  +-----------------------------------------------------------------------+
27  | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
28  +-----------------------------------------------------------------------+
29  | Tel : +49 (0) 7223/9493-0 | email : [email protected] |
30  | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31  +-----------------------------------------------------------------------+
32  | Project : API APCI1710 | Compiler : gcc |
33  | Module name : TTL.C | Version : 2.96 |
34  +-------------------------------+---------------------------------------+
35  | Project manager: Eric Stolz | Date : 02/12/2002 |
36  +-----------------------------------------------------------------------+
37  | Description : APCI-1710 TTL I/O module |
38  | |
39  | |
40  +-----------------------------------------------------------------------+
41  | UPDATES |
42  +-----------------------------------------------------------------------+
43  | Date | Author | Description of updates |
44  +----------+-----------+------------------------------------------------+
45  | 13/05/98 | S. Weber | TTL digital input / output implementation |
46  |----------|-----------|------------------------------------------------|
47  | 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 |
48  | | | available |
49  +-----------------------------------------------------------------------+
50  | | | |
51  | | | |
52  +-----------------------------------------------------------------------+
53 */
54 
55 /*
56 +----------------------------------------------------------------------------+
57 | Included files |
58 +----------------------------------------------------------------------------+
59 */
60 
61 #include "APCI1710_Ttl.h"
62 
63 /*
64 +----------------------------------------------------------------------------+
65 | Function Name : _INT_ i_APCI1710_InitTTLIODirection |
66 | (unsigned char_ b_BoardHandle, |
67 | unsigned char_ b_ModulNbr, |
68 | unsigned char_ b_PortAMode, |
69 | unsigned char_ b_PortBMode, |
70 | unsigned char_ b_PortCMode, |
71 | unsigned char_ b_PortDMode) |
72 +----------------------------------------------------------------------------+
73 | Task APCI1710_TTL_INIT (using defaults) : Configure the TTL I/O operating mode from selected |
74 | module (b_ModulNbr). You must calling this function be|
75 | for you call any other function witch access of TTL. |
76  APCI1710_TTL_INITDIRECTION(user inputs for direction)
77 
78 +----------------------------------------------------------------------------+
79 | Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710|
80 | unsigned char_ b_ModulNbr : Module number to |
81 | configure (0 to 3)
82  b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
83  b_InitType = (unsigned char) data[0];
84  b_PortAMode = (unsigned char) data[1];
85  b_PortBMode = (unsigned char) data[2];
86  b_PortCMode = (unsigned char) data[3];
87  b_PortDMode = (unsigned char) data[4];|
88 +----------------------------------------------------------------------------+
89 | Output Parameters : - |
90 +----------------------------------------------------------------------------+
91 | Return Value : 0: No error |
92 | -1: The handle parameter of the board is wrong |
93 | -2: The module parameter is wrong |
94 | -3: The module is not a TTL module |
95 | -4: Function not available for this version |
96 | -5: Port A mode selection is wrong |
97 | -6: Port B mode selection is wrong |
98 | -7: Port C mode selection is wrong |
99 | -8: Port D mode selection is wrong |
100 +----------------------------------------------------------------------------+
101 */
102 
104  struct comedi_insn *insn, unsigned int *data)
105 {
106  int i_ReturnValue = 0;
107  unsigned char b_ModulNbr;
108  unsigned char b_InitType;
109  unsigned char b_PortAMode;
110  unsigned char b_PortBMode;
111  unsigned char b_PortCMode;
112  unsigned char b_PortDMode;
113 
114  b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
115  b_InitType = (unsigned char) data[0];
116  i_ReturnValue = insn->n;
117 
118  /**************************/
119  /* Test the module number */
120  /**************************/
121 
122  if (b_ModulNbr < 4) {
123  /**************************/
124  /* Test if TTL I/O module */
125  /**************************/
126 
127  if ((devpriv->s_BoardInfos.
128  dw_MolduleConfiguration[b_ModulNbr] &
129  0xFFFF0000UL) == APCI1710_TTL_IO) {
130  switch (b_InitType) {
131  case APCI1710_TTL_INIT:
132 
133  devpriv->s_ModuleInfo[b_ModulNbr].
134  s_TTLIOInfo.b_TTLInit = 1;
135 
136  /***************************/
137  /* Set TTL port A to input */
138  /***************************/
139 
140  devpriv->s_ModuleInfo[b_ModulNbr].
141  s_TTLIOInfo.b_PortConfiguration[0] = 0;
142 
143  /***************************/
144  /* Set TTL port B to input */
145  /***************************/
146 
147  devpriv->s_ModuleInfo[b_ModulNbr].
148  s_TTLIOInfo.b_PortConfiguration[1] = 0;
149 
150  /***************************/
151  /* Set TTL port C to input */
152  /***************************/
153 
154  devpriv->s_ModuleInfo[b_ModulNbr].
155  s_TTLIOInfo.b_PortConfiguration[2] = 0;
156 
157  /****************************/
158  /* Set TTL port D to output */
159  /****************************/
160 
161  devpriv->s_ModuleInfo[b_ModulNbr].
162  s_TTLIOInfo.b_PortConfiguration[3] = 1;
163 
164  /*************************/
165  /* Set the configuration */
166  /*************************/
167 
168  outl(0x8,
169  devpriv->s_BoardInfos.ui_Address + 20 +
170  (64 * b_ModulNbr));
171  break;
172 
174 
175  b_PortAMode = (unsigned char) data[1];
176  b_PortBMode = (unsigned char) data[2];
177  b_PortCMode = (unsigned char) data[3];
178  b_PortDMode = (unsigned char) data[4];
179 
180  /********************/
181  /* Test the version */
182  /********************/
183 
184  if ((devpriv->s_BoardInfos.
185  dw_MolduleConfiguration
186  [b_ModulNbr] & 0xFFFF) >=
187  0x3230) {
188  /************************/
189  /* Test the port A mode */
190  /************************/
191 
192  if ((b_PortAMode == 0)
193  || (b_PortAMode == 1)) {
194  /************************/
195  /* Test the port B mode */
196  /************************/
197 
198  if ((b_PortBMode == 0)
199  || (b_PortBMode == 1)) {
200  /************************/
201  /* Test the port C mode */
202  /************************/
203 
204  if ((b_PortCMode == 0)
205  || (b_PortCMode
206  == 1)) {
207  /************************/
208  /* Test the port D mode */
209  /************************/
210 
211  if ((b_PortDMode == 0) || (b_PortDMode == 1)) {
212  devpriv->
213  s_ModuleInfo
214  [b_ModulNbr].
215  s_TTLIOInfo.
216  b_TTLInit
217  =
218  1;
219 
220  /***********************/
221  /* Set TTL port A mode */
222  /***********************/
223 
224  devpriv->
225  s_ModuleInfo
226  [b_ModulNbr].
227  s_TTLIOInfo.
228  b_PortConfiguration
229  [0]
230  =
231  b_PortAMode;
232 
233  /***********************/
234  /* Set TTL port B mode */
235  /***********************/
236 
237  devpriv->
238  s_ModuleInfo
239  [b_ModulNbr].
240  s_TTLIOInfo.
241  b_PortConfiguration
242  [1]
243  =
244  b_PortBMode;
245 
246  /***********************/
247  /* Set TTL port C mode */
248  /***********************/
249 
250  devpriv->
251  s_ModuleInfo
252  [b_ModulNbr].
253  s_TTLIOInfo.
254  b_PortConfiguration
255  [2]
256  =
257  b_PortCMode;
258 
259  /***********************/
260  /* Set TTL port D mode */
261  /***********************/
262 
263  devpriv->
264  s_ModuleInfo
265  [b_ModulNbr].
266  s_TTLIOInfo.
267  b_PortConfiguration
268  [3]
269  =
270  b_PortDMode;
271 
272  /*************************/
273  /* Set the configuration */
274  /*************************/
275 
276  outl((b_PortAMode << 0) | (b_PortBMode << 1) | (b_PortCMode << 2) | (b_PortDMode << 3), devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr));
277  } else {
278  /**********************************/
279  /* Port D mode selection is wrong */
280  /**********************************/
281 
282  DPRINTK("Port D mode selection is wrong\n");
283  i_ReturnValue
284  =
285  -8;
286  }
287  } else {
288  /**********************************/
289  /* Port C mode selection is wrong */
290  /**********************************/
291 
292  DPRINTK("Port C mode selection is wrong\n");
293  i_ReturnValue =
294  -7;
295  }
296  } else {
297  /**********************************/
298  /* Port B mode selection is wrong */
299  /**********************************/
300 
301  DPRINTK("Port B mode selection is wrong\n");
302  i_ReturnValue = -6;
303  }
304  } else {
305  /**********************************/
306  /* Port A mode selection is wrong */
307  /**********************************/
308 
309  DPRINTK("Port A mode selection is wrong\n");
310  i_ReturnValue = -5;
311  }
312  } else {
313  /*******************************************/
314  /* Function not available for this version */
315  /*******************************************/
316 
317  DPRINTK("Function not available for this version\n");
318  i_ReturnValue = -4;
319  }
320  break;
321 
322  DPRINTK("\n");
323  default:
324  printk("Bad Config Type\n");
325  } /* switch end */
326  } else {
327  /**********************************/
328  /* The module is not a TTL module */
329  /**********************************/
330 
331  DPRINTK("The module is not a TTL module\n");
332  i_ReturnValue = -3;
333  }
334  } else {
335  /***********************/
336  /* Module number error */
337  /***********************/
338 
339  DPRINTK("Module number error\n");
340  i_ReturnValue = -2;
341  }
342 
343  return i_ReturnValue;
344 }
345 
346 /*
347 +----------------------------------------------------------------------------+
348 | INPUT FUNCTIONS |
349 +----------------------------------------------------------------------------+
350 */
351 
352 /*
353 +----------------------------------------------------------------------------+
354 | Function Name : _INT_ i_APCI1710_ReadTTLIOChannelValue |
355 | (unsigned char_ b_BoardHandle, |
356 | unsigned char_ b_ModulNbr, |
357 | unsigned char_ b_SelectedPort, |
358 | unsigned char_ b_InputChannel, |
359 | unsigned char *_ pb_ChannelStatus) |
360 +----------------------------------------------------------------------------+
361 | Task : Read the status from selected TTL digital input |
362 | (b_InputChannel)
363 +----------------------------------------------------------------------------+
364 | Task : Read the status from digital input port |
365 | (b_SelectedPort) from selected TTL module (b_ModulNbr) |
366 +----------------------------------------------------------------------------+
367 
368 +----------------------------------------------------------------------------+
369 | Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710|
370 | unsigned char_ b_ModulNbr : Module number to |
371 | configure (0 to 7) |
372 | unsigned char_ b_SelectedPort, : Selection from TTL I/O |
373 | port (0 to 2) |
374 | 0 : Port A selection |
375 | 1 : Port B selection |
376 | 2 : Port C selection |
377 | 3 : Port D selection |
378 | unsigned char_ b_InputChannel : Selection from digital |
379 | input ( 0 to 2)
380 APCI1710_TTL_READCHANNEL
381  b_ModulNbr = CR_AREF(insn->chanspec);
382  b_SelectedPort= CR_RANGE(insn->chanspec);
383  b_InputChannel= CR_CHAN(insn->chanspec);
384  b_ReadType = (unsigned char) data[0];
385 
386  APCI1710_TTL_READPORT|
387  b_ModulNbr = CR_AREF(insn->chanspec);
388  b_SelectedPort= CR_RANGE(insn->chanspec);
389  b_ReadType = (unsigned char) data[0];
390 
391 +----------------------------------------------------------------------------+
392 | Output Parameters : data[0]
393 
394  unsigned char *_ pb_ChannelStatus : Digital input channel |
395 | status |
396 | 0 : Channle is not active|
397 | 1 : Channle is active |
398 +----------------------------------------------------------------------------+
399 | Return Value : 0: No error |
400 | -1: The handle parameter of the board is wrong |
401 | -2: The module parameter is wrong |
402 | -3: The module is not a TTL module |
403 | -4: The selected TTL input port is wrong |
404 | -5: The selected TTL digital input is wrong |
405 | -6: TTL I/O not initialised |
406 +----------------------------------------------------------------------------+
407 */
408 
410  struct comedi_insn *insn, unsigned int *data)
411 {
412  int i_ReturnValue = 0;
413  unsigned int dw_StatusReg;
414  unsigned char b_ModulNbr;
415  unsigned char b_SelectedPort;
416  unsigned char b_InputChannel;
417  unsigned char b_ReadType;
418  unsigned char *pb_ChannelStatus;
419  unsigned char *pb_PortValue;
420 
421  i_ReturnValue = insn->n;
422  b_ReadType = (unsigned char) data[0];
423  b_ModulNbr = CR_AREF(insn->chanspec);
424  b_SelectedPort = CR_RANGE(insn->chanspec);
425  b_InputChannel = CR_CHAN(insn->chanspec);
426 
427  /**************************/
428  /* Test the module number */
429  /**************************/
430 
431  if (b_ModulNbr < 4) {
432  /**************************/
433  /* Test if TTL I/O module */
434  /**************************/
435 
436  if ((devpriv->s_BoardInfos.
437  dw_MolduleConfiguration[b_ModulNbr] &
438  0xFFFF0000UL) == APCI1710_TTL_IO) {
439  switch (b_ReadType) {
440 
442  pb_ChannelStatus = (unsigned char *) &data[0];
443  /********************************/
444  /* Test the TTL I/O port number */
445  /********************************/
446 
447  if (((b_SelectedPort <= 2)
448  && ((devpriv->s_BoardInfos.
449  dw_MolduleConfiguration
450  [b_ModulNbr] &
451  0xFFFF) ==
452  0x3130))
453  || ((b_SelectedPort <= 3)
454  && ((devpriv->s_BoardInfos.
455  dw_MolduleConfiguration
456  [b_ModulNbr] &
457  0xFFFF) >=
458  0x3230))) {
459  /******************************************/
460  /* Test the digital imnput channel number */
461  /******************************************/
462 
463  if (((b_InputChannel <= 7)
464  && (b_SelectedPort < 3))
465  || ((b_InputChannel <= 1)
466  && (b_SelectedPort ==
467  3))) {
468  /******************************************/
469  /* Test if the TTL I/O module initialised */
470  /******************************************/
471 
472  if (devpriv->
473  s_ModuleInfo
474  [b_ModulNbr].
475  s_TTLIOInfo.b_TTLInit ==
476  1) {
477  /***********************************/
478  /* Test if TTL port used for input */
479  /***********************************/
480 
481  if (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) == 0x3130) || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) {
482  /**************************/
483  /* Read all digital input */
484  /**************************/
485 
486  dw_StatusReg =
487  inl
488  (devpriv->
489  s_BoardInfos.
490  ui_Address
491  +
492  (64 * b_ModulNbr));
493 
494  *pb_ChannelStatus
495  =
496  (unsigned char) (
497  (dw_StatusReg
498  >>
499  (8 * b_SelectedPort)) >> b_InputChannel) & 1;
500  } else {
501  /*******************************/
502  /* Selected TTL I/O port error */
503  /*******************************/
504 
505  DPRINTK("Selected TTL I/O port error\n");
506  i_ReturnValue =
507  -4;
508  }
509  } else {
510  /***************************/
511  /* TTL I/O not initialised */
512  /***************************/
513 
514  DPRINTK("TTL I/O not initialised\n");
515  i_ReturnValue = -6;
516  }
517  } else {
518  /********************************/
519  /* Selected digital input error */
520  /********************************/
521 
522  DPRINTK("Selected digital input error\n");
523  i_ReturnValue = -5;
524  }
525  } else {
526  /*******************************/
527  /* Selected TTL I/O port error */
528  /*******************************/
529 
530  DPRINTK("Selected TTL I/O port error\n");
531  i_ReturnValue = -4;
532  }
533  break;
534 
536  pb_PortValue = (unsigned char *) &data[0];
537  /********************************/
538  /* Test the TTL I/O port number */
539  /********************************/
540 
541  if (((b_SelectedPort <= 2)
542  && ((devpriv->s_BoardInfos.
543  dw_MolduleConfiguration
544  [b_ModulNbr] &
545  0xFFFF) ==
546  0x3130))
547  || ((b_SelectedPort <= 3)
548  && ((devpriv->s_BoardInfos.
549  dw_MolduleConfiguration
550  [b_ModulNbr] &
551  0xFFFF) >=
552  0x3230))) {
553  /******************************************/
554  /* Test if the TTL I/O module initialised */
555  /******************************************/
556 
557  if (devpriv->s_ModuleInfo[b_ModulNbr].
558  s_TTLIOInfo.b_TTLInit == 1) {
559  /***********************************/
560  /* Test if TTL port used for input */
561  /***********************************/
562 
563  if (((devpriv->s_BoardInfos.
564  dw_MolduleConfiguration
565  [b_ModulNbr]
566  &
567  0xFFFF)
568  == 0x3130)
569  || (((devpriv->s_BoardInfos.dw_MolduleConfiguration[b_ModulNbr] & 0xFFFF) >= 0x3230) && (devpriv->s_ModuleInfo[b_ModulNbr].s_TTLIOInfo.b_PortConfiguration[b_SelectedPort] == 0))) {
570  /**************************/
571  /* Read all digital input */
572  /**************************/
573 
574  dw_StatusReg =
575  inl(devpriv->
576  s_BoardInfos.
577  ui_Address +
578  (64 * b_ModulNbr));
579 
580  *pb_PortValue =
581  (unsigned char) (
582  (dw_StatusReg >>
583  (8 * b_SelectedPort)) & 0xFF);
584  } else {
585  /*******************************/
586  /* Selected TTL I/O port error */
587  /*******************************/
588 
589  DPRINTK("Selected TTL I/O port error\n");
590  i_ReturnValue = -4;
591  }
592  } else {
593  /***************************/
594  /* TTL I/O not initialised */
595  /***************************/
596 
597  DPRINTK("TTL I/O not initialised\n");
598  i_ReturnValue = -5;
599  }
600  } else {
601  /*******************************/
602  /* Selected TTL I/O port error */
603  /*******************************/
604 
605  DPRINTK("Selected TTL I/O port error\n");
606  i_ReturnValue = -4;
607  }
608  break;
609 
610  default:
611  printk("Bad ReadType\n");
612 
613  } /* End Switch */
614  } else {
615  /**********************************/
616  /* The module is not a TTL module */
617  /**********************************/
618 
619  DPRINTK("The module is not a TTL module\n");
620  i_ReturnValue = -3;
621  }
622  } else {
623  /***********************/
624  /* Module number error */
625  /***********************/
626 
627  DPRINTK("Module number error\n");
628  i_ReturnValue = -2;
629  }
630 
631  return i_ReturnValue;
632 }
633 
634 /*
635 +----------------------------------------------------------------------------+
636 | Function Name : int i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device
637 *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
638 +----------------------------------------------------------------------------+
639 | Task : Read the status from all digital input ports |
640 | (port A, port B and port C) from selected TTL |
641 | module (b_ModulNbr) |
642 +----------------------------------------------------------------------------+
643 | Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710|
644 | unsigned char_ b_ModulNbr : Module number to |
645 | configure (0 to 3) |
646 +----------------------------------------------------------------------------+
647 | Output Parameters : PULONG_ pul_PortValue : Digital TTL inputs port |
648 | status |
649 +----------------------------------------------------------------------------+
650 | Return Value : 0: No error |
651 | -1: The handle parameter of the board is wrong |
652 | -2: The module parameter is wrong |
653 | -3: The module is not a TTL module |
654 | -4: TTL I/O not initialised |
655 +----------------------------------------------------------------------------+
656 */
657 
659  struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
660 {
661  int i_ReturnValue = 0;
662  unsigned int dw_StatusReg;
663  unsigned char b_ModulNbr;
664  unsigned int *pul_PortValue;
665 
666  b_ModulNbr = (unsigned char) CR_AREF(insn->chanspec);
667  i_ReturnValue = insn->n;
668  pul_PortValue = (unsigned int *) &data[0];
669 
670  /**************************/
671  /* Test the module number */
672  /**************************/
673 
674  if (b_ModulNbr < 4) {
675  /**************************/
676  /* Test if TTL I/O module */
677  /**************************/
678 
679  if ((devpriv->s_BoardInfos.
680  dw_MolduleConfiguration[b_ModulNbr] &
681  0xFFFF0000UL) == APCI1710_TTL_IO) {
682  /******************************************/
683  /* Test if the TTL I/O module initialised */
684  /******************************************/
685 
686  if (devpriv->
687  s_ModuleInfo[b_ModulNbr].
688  s_TTLIOInfo.b_TTLInit == 1) {
689  /**************************/
690  /* Read all digital input */
691  /**************************/
692 
693  dw_StatusReg = inl(devpriv->s_BoardInfos.
694  ui_Address + (64 * b_ModulNbr));
695 
696  /**********************/
697  /* Test if TTL Rev1.0 */
698  /**********************/
699 
700  if ((devpriv->s_BoardInfos.
701  dw_MolduleConfiguration
702  [b_ModulNbr] & 0xFFFF) ==
703  0x3130) {
704  *pul_PortValue =
705  dw_StatusReg & 0xFFFFFFUL;
706  } else {
707  /**************************************/
708  /* Test if port A not used for output */
709  /**************************************/
710 
711  if (devpriv->s_ModuleInfo[b_ModulNbr].
712  s_TTLIOInfo.
713  b_PortConfiguration[0] == 1) {
714  *pul_PortValue =
715  dw_StatusReg &
716  0x3FFFF00UL;
717  }
718 
719  /**************************************/
720  /* Test if port B not used for output */
721  /**************************************/
722 
723  if (devpriv->
724  s_ModuleInfo[b_ModulNbr].
725  s_TTLIOInfo.
726  b_PortConfiguration[1] == 1) {
727  *pul_PortValue =
728  dw_StatusReg &
729  0x3FF00FFUL;
730  }
731 
732  /**************************************/
733  /* Test if port C not used for output */
734  /**************************************/
735 
736  if (devpriv->
737  s_ModuleInfo[b_ModulNbr].
738  s_TTLIOInfo.
739  b_PortConfiguration[2] == 1) {
740  *pul_PortValue =
741  dw_StatusReg &
742  0x300FFFFUL;
743  }
744 
745  /**************************************/
746  /* Test if port D not used for output */
747  /**************************************/
748 
749  if (devpriv->
750  s_ModuleInfo[b_ModulNbr].
751  s_TTLIOInfo.
752  b_PortConfiguration[3] == 1) {
753  *pul_PortValue =
754  dw_StatusReg &
755  0xFFFFFFUL;
756  }
757  }
758  } else {
759  /***************************/
760  /* TTL I/O not initialised */
761  /***************************/
762  DPRINTK("TTL I/O not initialised\n");
763  i_ReturnValue = -5;
764  }
765  } else {
766  /**********************************/
767  /* The module is not a TTL module */
768  /**********************************/
769  DPRINTK("The module is not a TTL module\n");
770  i_ReturnValue = -3;
771  }
772  } else {
773  /***********************/
774  /* Module number error */
775  /***********************/
776  DPRINTK("Module number error\n");
777  i_ReturnValue = -2;
778  }
779 
780  return i_ReturnValue;
781 }
782 
783 /*
784 +----------------------------------------------------------------------------+
785 | OUTPUT FUNCTIONS |
786 +----------------------------------------------------------------------------+
787 */
788 
789 /*
790 +----------------------------------------------------------------------------+
791 | Function Name : _INT_ i_APCI1710_SetTTLIOChlOn |
792 | (unsigned char_ b_BoardHandle, |
793 | unsigned char_ b_ModulNbr, |
794 | unsigned char_ b_OutputChannel)
795 int i_APCI1710_InsnWriteSetTTLIOChlOnOff(struct comedi_device *dev,struct comedi_subdevice *s,
796  struct comedi_insn *insn,unsigned int *data) |
797 +----------------------------------------------------------------------------+
798 | Task : Sets or resets the output witch has been passed with the |
799 | parameter b_Channel. Setting an output means setting |
800 | an ouput high. |
801 +----------------------------------------------------------------------------+
802 | Input Parameters : unsigned char_ b_BoardHandle : Handle of board APCI-1710 |
803 | unsigned char_ b_ModulNbr : Selected module number (0 to 3)|
804 | unsigned char_ b_OutputChannel : Selection from digital output |
805 | channel (0 or 1) |
806 | 0 : PD0 |
807 | 1 : PD1 |
808 | 2 to 9 : PA |
809 | 10 to 17: PB |
810 | 18 to 25: PC |
811 
812  b_ModulNbr = CR_AREF(insn->chanspec);
813  b_OutputChannel= CR_CHAN(insn->chanspec);
814  ui_State = data[0]; /* ON or OFF */
815 +----------------------------------------------------------------------------+
816 | Output Parameters : - |
817 +----------------------------------------------------------------------------+
818 | Return Value : 0: No error |
819 | -1: The handle parameter of the board is wrong |
820 | -2: The module parameter is wrong |
821 | -3: The module is not a TTL I/O module |
822 | -4: The selected digital output is wrong |
823 | -5: TTL I/O not initialised see function |
824 | " i_APCI1710_InitTTLIO"
825 +----------------------------------------------------------------------------+
826 */
827 
829  struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
830 {
831  int i_ReturnValue = 0;
832  unsigned int dw_StatusReg = 0;
833  unsigned char b_ModulNbr;
834  unsigned char b_OutputChannel;
835  unsigned int ui_State;
836 
837  i_ReturnValue = insn->n;
838  b_ModulNbr = CR_AREF(insn->chanspec);
839  b_OutputChannel = CR_CHAN(insn->chanspec);
840  ui_State = data[0]; /* ON or OFF */
841 
842  /**************************/
843  /* Test the module number */
844  /**************************/
845 
846  if (b_ModulNbr < 4) {
847  /**************************/
848  /* Test if TTL I/O module */
849  /**************************/
850 
851  if ((devpriv->s_BoardInfos.
852  dw_MolduleConfiguration[b_ModulNbr] &
853  0xFFFF0000UL) == APCI1710_TTL_IO) {
854  /******************************************/
855  /* Test if the TTL I/O module initialised */
856  /******************************************/
857 
858  if (devpriv->s_ModuleInfo[b_ModulNbr].
859  s_TTLIOInfo.b_TTLInit == 1) {
860  /***********************************/
861  /* Test the TTL I/O channel number */
862  /***********************************/
863 
864  if (((b_OutputChannel <= 1)
865  && ((devpriv->s_BoardInfos.
866  dw_MolduleConfiguration
867  [b_ModulNbr] &
868  0xFFFF) ==
869  0x3130))
870  || ((b_OutputChannel <= 25)
871  && ((devpriv->s_BoardInfos.
872  dw_MolduleConfiguration
873  [b_ModulNbr] &
874  0xFFFF) >=
875  0x3230))) {
876  /****************************************************/
877  /* Test if the selected channel is a output channel */
878  /****************************************************/
879 
880  if (((b_OutputChannel <= 1)
881  && (devpriv->
882  s_ModuleInfo
883  [b_ModulNbr].
884  s_TTLIOInfo.
885  b_PortConfiguration
886  [3] == 1))
887  || ((b_OutputChannel >= 2)
888  && (b_OutputChannel <=
889  9)
890  && (devpriv->
891  s_ModuleInfo
892  [b_ModulNbr].
893  s_TTLIOInfo.
894  b_PortConfiguration
895  [0] == 1))
896  || ((b_OutputChannel >= 10)
897  && (b_OutputChannel <=
898  17)
899  && (devpriv->
900  s_ModuleInfo
901  [b_ModulNbr].
902  s_TTLIOInfo.
903  b_PortConfiguration
904  [1] == 1))
905  || ((b_OutputChannel >= 18)
906  && (b_OutputChannel <=
907  25)
908  && (devpriv->
909  s_ModuleInfo
910  [b_ModulNbr].
911  s_TTLIOInfo.
912  b_PortConfiguration
913  [2] == 1))) {
914  /************************/
915  /* Test if PD0 selected */
916  /************************/
917 
918  if (b_OutputChannel == 0) {
919 
920  outl(ui_State,
921  devpriv->
922  s_BoardInfos.
923  ui_Address +
924  (64 * b_ModulNbr));
925  } else {
926  /************************/
927  /* Test if PD1 selected */
928  /************************/
929 
930  if (b_OutputChannel ==
931  1) {
932 
933  outl(ui_State,
934  devpriv->
935  s_BoardInfos.
936  ui_Address
937  + 4 +
938  (64 * b_ModulNbr));
939  } else {
940  b_OutputChannel
941  =
942  b_OutputChannel
943  - 2;
944 
945  /********************/
946  /* Read all channel */
947  /********************/
948 
949  dw_StatusReg =
950  inl
951  (devpriv->
952  s_BoardInfos.
953  ui_Address
954  +
955  (64 * b_ModulNbr));
956  if (ui_State) /* ON */
957  {
958  dw_StatusReg
959  =
960  (dw_StatusReg
961  >>
962  ((b_OutputChannel / 8) * 8)) & 0xFF;
963  dw_StatusReg
964  =
965  dw_StatusReg
966  |
967  (1
968  <<
969  (b_OutputChannel
970  %
971  8));
972  } else /* Off */
973  {
974  dw_StatusReg
975  =
976  (dw_StatusReg
977  >>
978  ((b_OutputChannel / 8) * 8)) & 0xFF;
979  dw_StatusReg
980  =
981  dw_StatusReg
982  &
983  (0xFF
984  -
985  (1 << (b_OutputChannel % 8)));
986 
987  }
988 
989  /****************************/
990  /* Set the new output value */
991  /****************************/
992 
993  outl(dw_StatusReg, devpriv->s_BoardInfos.ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr));
994  }
995  }
996  } else {
997  /************************************/
998  /* The selected TTL output is wrong */
999  /************************************/
1000 
1001  DPRINTK(" The selected TTL output is wrong\n");
1002  i_ReturnValue = -4;
1003  }
1004  } else {
1005  /************************************/
1006  /* The selected TTL output is wrong */
1007  /************************************/
1008 
1009  DPRINTK("The selected TTL output is wrong\n");
1010  i_ReturnValue = -4;
1011  }
1012  } else {
1013  /***************************/
1014  /* TTL I/O not initialised */
1015  /***************************/
1016 
1017  DPRINTK("TTL I/O not initialised\n");
1018  i_ReturnValue = -5;
1019  }
1020  } else {
1021  /**************************************/
1022  /* The module is not a TTL I/O module */
1023  /**************************************/
1024 
1025  DPRINTK("The module is not a TTL I/O module\n");
1026  i_ReturnValue = -3;
1027  }
1028  } else {
1029  /***********************/
1030  /* Module number error */
1031  /***********************/
1032 
1033  DPRINTK("Module number error\n");
1034  i_ReturnValue = -2;
1035  }
1036 
1037  return i_ReturnValue;
1038 }