2 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
7 * Tel: +19(0)7223/9493-0
8 * Fax: +49(0)7223/9493-92
9 * http://www.addi-data.com
12 * This program is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at your option) any later
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 /* Card Specific information */
25 #define APCI1500_ADDRESS_RANGE 4
27 /* DIGITAL INPUT-OUTPUT DEFINE */
29 #define APCI1500_DIGITAL_OP 2
30 #define APCI1500_DIGITAL_IP 0
31 #define APCI1500_AND 2
33 #define APCI1500_OR_PRIORITY 6
34 #define APCI1500_CLK_SELECT 0
38 #define APCI1500_COUNTER 0x20
39 #define APCI1500_TIMER 0
40 #define APCI1500_WATCHDOG 0
41 #define APCI1500_SINGLE 0
42 #define APCI1500_CONTINUOUS 0x80
43 #define APCI1500_DISABLE 0
44 #define APCI1500_ENABLE 1
45 #define APCI1500_SOFTWARE_TRIGGER 0x4
46 #define APCI1500_HARDWARE_TRIGGER 0x10
47 #define APCI1500_SOFTWARE_GATE 0
48 #define APCI1500_HARDWARE_GATE 0x8
54 * Zillog I/O enumeration
57 APCI1500_Z8536_PORT_C,
58 APCI1500_Z8536_PORT_B,
59 APCI1500_Z8536_PORT_A,
60 APCI1500_Z8536_CONTROL_REGISTER
64 * Z8536 CIO Internal Address
67 APCI1500_RW_MASTER_INTERRUPT_CONTROL,
68 APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
69 APCI1500_RW_PORT_A_INTERRUPT_CONTROL,
70 APCI1500_RW_PORT_B_INTERRUPT_CONTROL,
71 APCI1500_RW_TIMER_COUNTER_INTERRUPT_VECTOR,
72 APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,
73 APCI1500_RW_PORT_C_DATA_DIRECTION,
74 APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,
76 APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
77 APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
78 APCI1500_RW_CPT_TMR1_CMD_STATUS,
79 APCI1500_RW_CPT_TMR2_CMD_STATUS,
80 APCI1500_RW_CPT_TMR3_CMD_STATUS,
81 APCI1500_RW_PORT_A_DATA,
82 APCI1500_RW_PORT_B_DATA,
83 APCI1500_RW_PORT_C_DATA,
85 APCI1500_R_CPT_TMR1_VALUE_HIGH,
86 APCI1500_R_CPT_TMR1_VALUE_LOW,
87 APCI1500_R_CPT_TMR2_VALUE_HIGH,
88 APCI1500_R_CPT_TMR2_VALUE_LOW,
89 APCI1500_R_CPT_TMR3_VALUE_HIGH,
90 APCI1500_R_CPT_TMR3_VALUE_LOW,
91 APCI1500_RW_CPT_TMR1_TIME_CST_HIGH,
92 APCI1500_RW_CPT_TMR1_TIME_CST_LOW,
93 APCI1500_RW_CPT_TMR2_TIME_CST_HIGH,
94 APCI1500_RW_CPT_TMR2_TIME_CST_LOW,
95 APCI1500_RW_CPT_TMR3_TIME_CST_HIGH,
96 APCI1500_RW_CPT_TMR3_TIME_CST_LOW,
97 APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION,
98 APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION,
99 APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION,
100 APCI1500_R_CURRENT_VECTOR,
102 APCI1500_RW_PORT_A_SPECIFICATION,
103 APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION,
104 APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY,
105 APCI1500_RW_PORT_A_DATA_DIRECTION,
106 APCI1500_RW_PORT_A_SPECIAL_IO_CONTROL,
107 APCI1500_RW_PORT_A_PATTERN_POLARITY,
108 APCI1500_RW_PORT_A_PATTERN_TRANSITION,
109 APCI1500_RW_PORT_A_PATTERN_MASK,
111 APCI1500_RW_PORT_B_SPECIFICATION,
112 APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,
113 APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,
114 APCI1500_RW_PORT_B_DATA_DIRECTION,
115 APCI1500_RW_PORT_B_SPECIAL_IO_CONTROL,
116 APCI1500_RW_PORT_B_PATTERN_POLARITY,
117 APCI1500_RW_PORT_B_PATTERN_TRANSITION,
118 APCI1500_RW_PORT_B_PATTERN_MASK
121 static int i_TimerCounter1Init;
122 static int i_TimerCounter2Init;
123 static int i_WatchdogCounter3Init;
124 static int i_Event1Status, i_Event2Status;
125 static int i_TimerCounterWatchdogInterrupt;
126 static int i_Logic, i_CounterLogic;
127 static int i_InterruptMask;
128 static int i_InputChannel;
129 static int i_TimerCounter1Enabled, i_TimerCounter2Enabled,
130 i_WatchdogCounter3Enabled;
133 * An event can be generated for each port. The first event is related to the
134 * first 8 channels (port 1) and the second to the following 6 channels (port 2)
135 * An interrupt is generated when one or both events have occurred.
137 * data[0] Number of the input port on which the event will take place (1 or 2)
138 * data[1] The event logic for port 1 has three possibilities:
139 * APCI1500_AND This logic links the inputs with an AND logic.
140 * APCI1500_OR This logic links the inputs with a OR logic.
141 * APCI1500_OR_PRIORITY This logic links the inputs with a priority OR
142 * logic. Input 1 has the highest priority level
143 * and input 8 the smallest.
144 * For the second port the user has 1 possibility:
145 * APCI1500_OR This logic links the inputs with a polarity OR logic
146 * data[2] These 8-character word for port1 and 6-character word for port 2
147 * give the mask of the event. Each place gives the state of the input
148 * channels and can have one of these six characters
149 * 0 This input must be on 0
150 * 1 This input must be on 1
151 * 2 This input reacts to a falling edge
152 * 3 This input reacts to a rising edge
153 * 4 This input reacts to both edges
154 * 5 This input is not used for event
156 static int apci1500_di_config(struct comedi_device *dev,
157 struct comedi_subdevice *s,
158 struct comedi_insn *insn,
161 struct addi_private *devpriv = dev->private;
162 int i_PatternPolarity = 0, i_PatternTransition = 0, i_PatternMask = 0;
163 int i_MaxChannel = 0, i_Count = 0, i_EventMask = 0;
164 int i_PatternTransitionCount = 0, i_RegValue;
167 /* Selects the master interrupt control register */
168 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
169 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
170 /* Disables the main interrupt on the board */
171 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
175 } /* if (data[0] == 1) */
179 } /* if(data[0]==2) */
181 dev_warn(dev->hw_dev,
182 "The specified port event does not exist\n");
184 } /* else if(data[0]==2) */
185 } /* else if (data[0] == 1) */
188 data[1] = APCI1500_AND;
191 data[1] = APCI1500_OR;
194 data[1] = APCI1500_OR_PRIORITY;
197 dev_warn(dev->hw_dev,
198 "The specified interrupt logic does not exist\n");
200 } /* switch(data[1]); */
203 for (i_Count = i_MaxChannel, i = 0; i_Count > 0; i_Count--, i++) {
204 i_EventMask = data[2 + i];
205 switch (i_EventMask) {
208 i_PatternMask | (1 << (i_MaxChannel - i_Count));
212 i_PatternMask | (1 << (i_MaxChannel - i_Count));
214 i_PatternPolarity | (1 << (i_MaxChannel -
219 i_PatternMask | (1 << (i_MaxChannel - i_Count));
220 i_PatternTransition =
221 i_PatternTransition | (1 << (i_MaxChannel -
226 i_PatternMask | (1 << (i_MaxChannel - i_Count));
228 i_PatternPolarity | (1 << (i_MaxChannel -
230 i_PatternTransition =
231 i_PatternTransition | (1 << (i_MaxChannel -
235 i_PatternTransition =
236 i_PatternTransition | (1 << (i_MaxChannel -
242 dev_warn(dev->hw_dev,
243 "The option indicated in the event mask does not exist\n");
245 } /* switch(i_EventMask) */
246 } /* for (i_Count = i_MaxChannel; i_Count >0;i_Count --) */
249 /* Test the interrupt logic */
251 if (data[1] == APCI1500_AND ||
252 data[1] == APCI1500_OR ||
253 data[1] == APCI1500_OR_PRIORITY) {
254 /* Tests if a transition was declared */
255 /* for a OR PRIORITY logic */
257 if (data[1] == APCI1500_OR_PRIORITY
258 && i_PatternTransition != 0) {
259 dev_warn(dev->hw_dev,
260 "Transition error on an OR PRIORITY logic\n");
262 } /* if (data[1]== APCI1500_OR_PRIORITY && i_PatternTransition != 0) */
264 /* Tests if more than one transition */
265 /* was declared for an AND logic */
267 if (data[1] == APCI1500_AND) {
268 for (i_Count = 0; i_Count < 8; i_Count++) {
269 i_PatternTransitionCount =
270 i_PatternTransitionCount +
271 ((i_PatternTransition >>
274 } /* for (i_Count = 0; i_Count < 8; i_Count++) */
276 if (i_PatternTransitionCount > 1) {
277 dev_warn(dev->hw_dev,
278 "Transition error on an AND logic\n");
280 } /* if (i_PatternTransitionCount > 1) */
281 } /* if (data[1]== APCI1500_AND) */
283 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
284 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
286 APCI1500_Z8536_CONTROL_REGISTER);
290 APCI1500_Z8536_CONTROL_REGISTER);
291 /* Selects the polarity register of port 1 */
292 outb(APCI1500_RW_PORT_A_PATTERN_POLARITY,
294 APCI1500_Z8536_CONTROL_REGISTER);
295 outb(i_PatternPolarity,
297 APCI1500_Z8536_CONTROL_REGISTER);
299 /* Selects the pattern mask register of */
301 outb(APCI1500_RW_PORT_A_PATTERN_MASK,
303 APCI1500_Z8536_CONTROL_REGISTER);
306 APCI1500_Z8536_CONTROL_REGISTER);
307 /* Selects the pattern transition register */
309 outb(APCI1500_RW_PORT_A_PATTERN_TRANSITION,
311 APCI1500_Z8536_CONTROL_REGISTER);
312 outb(i_PatternTransition,
314 APCI1500_Z8536_CONTROL_REGISTER);
316 /* Selects the mode specification mask */
317 /* register of port 1 */
318 outb(APCI1500_RW_PORT_A_SPECIFICATION,
320 APCI1500_Z8536_CONTROL_REGISTER);
322 inb(devpriv->iobase +
323 APCI1500_Z8536_CONTROL_REGISTER);
325 /* Selects the mode specification mask */
326 /* register of port 1 */
327 outb(APCI1500_RW_PORT_A_SPECIFICATION,
329 APCI1500_Z8536_CONTROL_REGISTER);
331 /* Port A new mode */
333 i_RegValue = (i_RegValue & 0xF9) | data[1] | 0x9;
336 APCI1500_Z8536_CONTROL_REGISTER);
340 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
342 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
344 APCI1500_Z8536_CONTROL_REGISTER);
348 APCI1500_Z8536_CONTROL_REGISTER);
350 } /* if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) */
352 dev_warn(dev->hw_dev,
353 "The choice for interrupt logic does not exist\n");
355 } /* else }// if(data[1]==APCI1500_AND||data[1]==APCI1500_OR||data[1]==APCI1500_OR_PRIORITY) */
356 } /* if (data[0]== 1) */
358 /* Test if event setting for port 2 */
361 /* Test the event logic */
363 if (data[1] == APCI1500_OR) {
364 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
365 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
367 APCI1500_Z8536_CONTROL_REGISTER);
371 APCI1500_Z8536_CONTROL_REGISTER);
372 /* Selects the mode specification mask */
373 /* register of port B */
374 outb(APCI1500_RW_PORT_B_SPECIFICATION,
376 APCI1500_Z8536_CONTROL_REGISTER);
378 inb(devpriv->iobase +
379 APCI1500_Z8536_CONTROL_REGISTER);
381 /* Selects the mode specification mask */
382 /* register of port B */
383 outb(APCI1500_RW_PORT_B_SPECIFICATION,
385 APCI1500_Z8536_CONTROL_REGISTER);
386 i_RegValue = i_RegValue & 0xF9;
389 APCI1500_Z8536_CONTROL_REGISTER);
391 /* Selects error channels 1 and 2 */
393 i_PatternMask = (i_PatternMask | 0xC0);
394 i_PatternPolarity = (i_PatternPolarity | 0xC0);
395 i_PatternTransition = (i_PatternTransition | 0xC0);
397 /* Selects the polarity register of port 2 */
398 outb(APCI1500_RW_PORT_B_PATTERN_POLARITY,
400 APCI1500_Z8536_CONTROL_REGISTER);
401 outb(i_PatternPolarity,
403 APCI1500_Z8536_CONTROL_REGISTER);
404 /* Selects the pattern transition register */
406 outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION,
408 APCI1500_Z8536_CONTROL_REGISTER);
409 outb(i_PatternTransition,
411 APCI1500_Z8536_CONTROL_REGISTER);
412 /* Selects the pattern Mask register */
415 outb(APCI1500_RW_PORT_B_PATTERN_MASK,
417 APCI1500_Z8536_CONTROL_REGISTER);
420 APCI1500_Z8536_CONTROL_REGISTER);
422 /* Selects the mode specification mask */
423 /* register of port 2 */
424 outb(APCI1500_RW_PORT_B_SPECIFICATION,
426 APCI1500_Z8536_CONTROL_REGISTER);
428 inb(devpriv->iobase +
429 APCI1500_Z8536_CONTROL_REGISTER);
430 /* Selects the mode specification mask */
431 /* register of port 2 */
432 outb(APCI1500_RW_PORT_B_SPECIFICATION,
434 APCI1500_Z8536_CONTROL_REGISTER);
435 i_RegValue = (i_RegValue & 0xF9) | 4;
438 APCI1500_Z8536_CONTROL_REGISTER);
441 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
443 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
445 APCI1500_Z8536_CONTROL_REGISTER);
450 APCI1500_Z8536_CONTROL_REGISTER);
451 } /* if (data[1] == APCI1500_OR) */
453 dev_warn(dev->hw_dev,
454 "The choice for interrupt logic does not exist\n");
456 } /* elseif (data[1] == APCI1500_OR) */
457 } /* if(data[0]==2) */
463 * Allows or disallows a port event
465 * data[0] 0 = Start input event, 1 = Stop input event
466 * data[1] Number of port (1 or 2)
468 static int apci1500_di_write(struct comedi_device *dev,
469 struct comedi_subdevice *s,
470 struct comedi_insn *insn,
473 struct addi_private *devpriv = dev->private;
474 int i_Event1InterruptStatus = 0, i_Event2InterruptStatus =
479 /* Tests the port number */
481 if (data[1] == 1 || data[1] == 2) {
482 /* Test if port 1 selected */
485 /* Test if event initialised */
486 if (i_Event1Status == 1) {
487 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
488 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
492 APCI1500_Z8536_CONTROL_REGISTER);
493 /* Selects the command and status register of */
495 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
496 /* Allows the pattern interrupt */
499 APCI1500_Z8536_CONTROL_REGISTER);
500 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
501 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
505 APCI1500_Z8536_CONTROL_REGISTER);
506 i_Event1InterruptStatus = 1;
507 outb(APCI1500_RW_PORT_A_SPECIFICATION,
509 APCI1500_Z8536_CONTROL_REGISTER);
511 inb(devpriv->iobase +
512 APCI1500_Z8536_CONTROL_REGISTER);
514 /* Selects the master interrupt control register */
515 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
516 /* Authorizes the main interrupt on the board */
519 APCI1500_Z8536_CONTROL_REGISTER);
521 } /* if(i_Event1Status==1) */
523 dev_warn(dev->hw_dev,
524 "Event 1 not initialised\n");
526 } /* else if(i_Event1Status==1) */
527 } /* if (data[1]==1) */
530 if (i_Event2Status == 1) {
531 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
532 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
536 APCI1500_Z8536_CONTROL_REGISTER);
537 /* Selects the command and status register of */
539 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
540 /* Allows the pattern interrupt */
543 APCI1500_Z8536_CONTROL_REGISTER);
544 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
545 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
549 APCI1500_Z8536_CONTROL_REGISTER);
551 /* Selects the master interrupt control register */
552 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
553 /* Authorizes the main interrupt on the board */
556 APCI1500_Z8536_CONTROL_REGISTER);
557 i_Event2InterruptStatus = 1;
558 } /* if(i_Event2Status==1) */
560 dev_warn(dev->hw_dev,
561 "Event 2 not initialised\n");
563 } /* else if(i_Event2Status==1) */
564 } /* if(data[1]==2) */
565 } /* if (data[1] == 1 || data[0] == 2) */
567 dev_warn(dev->hw_dev,
568 "The port parameter is in error\n");
570 } /* else if (data[1] == 1 || data[0] == 2) */
575 /* Tests the port number */
577 if (data[1] == 1 || data[1] == 2) {
578 /* Test if port 1 selected */
581 /* Test if event initialised */
582 if (i_Event1Status == 1) {
583 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
584 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
588 APCI1500_Z8536_CONTROL_REGISTER);
589 /* Selects the command and status register of */
591 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
592 /* Inhibits the pattern interrupt */
595 APCI1500_Z8536_CONTROL_REGISTER);
596 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
597 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
601 APCI1500_Z8536_CONTROL_REGISTER);
602 i_Event1InterruptStatus = 0;
603 } /* if(i_Event1Status==1) */
605 dev_warn(dev->hw_dev,
606 "Event 1 not initialised\n");
608 } /* else if(i_Event1Status==1) */
609 } /* if (data[1]==1) */
611 /* Test if event initialised */
612 if (i_Event2Status == 1) {
613 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
614 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
618 APCI1500_Z8536_CONTROL_REGISTER);
619 /* Selects the command and status register of */
621 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
622 /* Inhibits the pattern interrupt */
625 APCI1500_Z8536_CONTROL_REGISTER);
626 /* Selects the APCI1500_RW_MASTER_CONFIGURATION_CONTROL register */
627 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
631 APCI1500_Z8536_CONTROL_REGISTER);
632 i_Event2InterruptStatus = 0;
633 } /* if(i_Event2Status==1) */
635 dev_warn(dev->hw_dev,
636 "Event 2 not initialised\n");
638 } /* else if(i_Event2Status==1) */
639 } /* if(data[1]==2) */
641 } /* if (data[1] == 1 || data[1] == 2) */
643 dev_warn(dev->hw_dev,
644 "The port parameter is in error\n");
646 } /* else if (data[1] == 1 || data[1] == 2) */
649 dev_warn(dev->hw_dev,
650 "The option of START/STOP logic does not exist\n");
652 } /* switch(data[0]) */
658 * Return the status of the digital input
660 static int apci1500_di_read(struct comedi_device *dev,
661 struct comedi_subdevice *s,
662 struct comedi_insn *insn,
665 struct addi_private *devpriv = dev->private;
669 i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
670 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
671 i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
672 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
673 outb(1, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
674 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
676 /* Selects the master configuration control register */
677 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
678 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
679 outb(0xF4, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
681 /* Selects the mode specification register of port A */
682 outb(APCI1500_RW_PORT_A_SPECIFICATION,
683 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
684 outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
686 /* Selects the data path polarity register of port A */
687 outb(APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY,
688 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
689 /* High level of port A means 1 */
690 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
692 /* Selects the data direction register of port A */
693 outb(APCI1500_RW_PORT_A_DATA_DIRECTION,
694 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
695 /* All bits used as inputs */
696 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
697 /* Selects the command and status register of port A */
698 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
699 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
700 /* Deletes IP and IUS */
701 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
702 /* Selects the command and status register of port A */
703 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
704 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
705 /* Deactivates the interrupt management of port A: */
706 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
707 /* Selects the handshake specification register of port A */
708 outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION,
709 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
710 /* Deletes the register */
711 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
713 /* Selects the mode specification register of port B */
714 outb(APCI1500_RW_PORT_B_SPECIFICATION,
715 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
716 outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
717 /* Selects the data path polarity register of port B */
718 outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,
719 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
720 /* A high level of port B means 1 */
721 outb(0x7F, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
722 /* Selects the data direction register of port B */
723 outb(APCI1500_RW_PORT_B_DATA_DIRECTION,
724 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
725 /* All bits used as inputs */
726 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
727 /* Selects the command and status register of port B */
728 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
729 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
730 /* Deletes IP and IUS */
731 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
732 /* Selects the command and status register of port B */
733 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
734 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
735 /* Deactivates the interrupt management of port B: */
736 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
737 /* Selects the handshake specification register of port B */
738 outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,
739 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
740 /* Deletes the register */
741 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
743 /* Selects the data path polarity register of port C */
744 outb(APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,
745 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
746 /* High level of port C means 1 */
747 outb(0x9, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
748 /* Selects the data direction register of port C */
749 outb(APCI1500_RW_PORT_C_DATA_DIRECTION,
750 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
751 /* All bits used as inputs except channel 1 */
752 outb(0x0E, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
753 /* Selects the special IO register of port C */
754 outb(APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,
755 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
757 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
758 /* Selects the command and status register of timer 1 */
759 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
760 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
761 /* Deletes IP and IUS */
762 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
763 /* Selects the command and status register of timer 1 */
764 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
765 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
766 /* Deactivates the interrupt management of timer 1 */
767 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
768 /* Selects the command and status register of timer 2 */
769 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
770 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
771 /* Deletes IP and IUS */
772 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
773 /* Selects the command and status register of timer 2 */
774 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
775 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
776 /* Deactivates Timer 2 interrupt management: */
777 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
778 /* Selects the command and status register of timer 3 */
779 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
780 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
781 /* Deletes IP and IUS */
782 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
783 /* Selects the command and status register of Timer 3 */
784 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
785 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
786 /* Deactivates interrupt management of timer 3: */
787 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
788 /* Selects the master interrupt control register */
789 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
790 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
791 /* Deletes all interrupts */
792 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
796 static int apci1500_di_insn_bits(struct comedi_device *dev,
797 struct comedi_subdevice *s,
798 struct comedi_insn *insn,
801 struct addi_private *devpriv = dev->private;
803 data[1] = inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP);
809 * Configures the digital output memory and the digital output error interrupt
811 * data[1] 1 = Enable the voltage error interrupt
812 * 2 = Disable the voltage error interrupt
814 static int apci1500_do_config(struct comedi_device *dev,
815 struct comedi_subdevice *s,
816 struct comedi_insn *insn,
819 struct addi_private *devpriv = dev->private;
821 devpriv->b_OutputMemoryStatus = data[0];
826 * Writes port value to the selected port
828 static int apci1500_do_write(struct comedi_device *dev,
829 struct comedi_subdevice *s,
830 struct comedi_insn *insn,
833 struct addi_private *devpriv = dev->private;
834 static unsigned int ui_Temp;
835 unsigned int ui_Temp1;
836 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
838 if (!devpriv->b_OutputMemoryStatus) {
841 } /* if(!devpriv->b_OutputMemoryStatus ) */
844 data[0] = (data[0] << ui_NoOfChannel) | ui_Temp;
846 devpriv->i_IobaseAddon + APCI1500_DIGITAL_OP);
847 } /* if(data[1]==0) */
850 switch (ui_NoOfChannel) {
871 data[0] = data[0] | ui_Temp;
875 comedi_error(dev, " chan spec wrong");
876 return -EINVAL; /* "sorry channel spec wrong " */
878 } /* switch(ui_NoOfChannels) */
881 devpriv->i_IobaseAddon +
882 APCI1500_DIGITAL_OP);
883 } /* if(data[1]==1) */
885 dev_warn(dev->hw_dev,
886 "Specified channel not supported\n");
888 } /* else if(data[1]==1) */
889 } /* elseif(data[1]==0) */
890 } /* if(data[3]==0) */
894 data[0] = ~data[0] & 0x1;
896 ui_Temp1 = ui_Temp1 << ui_NoOfChannel;
897 ui_Temp = ui_Temp | ui_Temp1;
899 (data[0] << ui_NoOfChannel) ^
901 data[0] = data[0] & ui_Temp;
903 devpriv->i_IobaseAddon +
904 APCI1500_DIGITAL_OP);
905 } /* if(data[1]==0) */
908 switch (ui_NoOfChannel) {
911 data[0] = ~data[0] & 0x3;
914 ui_Temp1 << 2 * data[2];
915 ui_Temp = ui_Temp | ui_Temp1;
920 0xffffffff) & ui_Temp;
924 data[0] = ~data[0] & 0xf;
927 ui_Temp1 << 4 * data[2];
928 ui_Temp = ui_Temp | ui_Temp1;
933 0xffffffff) & ui_Temp;
937 data[0] = ~data[0] & 0xff;
940 ui_Temp1 << 8 * data[2];
941 ui_Temp = ui_Temp | ui_Temp1;
946 0xffffffff) & ui_Temp;
955 return -EINVAL; /* "sorry channel spec wrong " */
957 } /* switch(ui_NoOfChannels) */
960 devpriv->i_IobaseAddon +
961 APCI1500_DIGITAL_OP);
962 } /* if(data[1]==1) */
964 dev_warn(dev->hw_dev,
965 "Specified channel not supported\n");
967 } /* else if(data[1]==1) */
968 } /* elseif(data[1]==0) */
969 } /* if(data[3]==1); */
971 dev_warn(dev->hw_dev,
972 "Specified functionality does not exist\n");
974 } /* if else data[3]==1) */
975 } /* if else data[3]==0) */
981 * Configures The Watchdog
983 * data[0] 0 = APCI1500_115_KHZ, 1 = APCI1500_3_6_KHZ, 2 = APCI1500_1_8_KHZ
984 * data[1] 0 = Counter1/Timer1, 1 = Counter2/Timer2, 2 = Counter3/Watchdog
985 * data[2] 0 = Counter, 1 = Timer/Watchdog
986 * data[3] This parameter has two meanings. If the counter/timer is used as
987 * a counter the limit value of the counter is given. If the counter/timer
988 * is used as a timer, the divider factor for the output is given.
989 * data[4] 0 = APCI1500_CONTINUOUS, 1 = APCI1500_SINGLE
990 * data[5] 0 = Software Trigger, 1 = Hardware Trigger
991 * data[6] 0 = Software gate, 1 = Hardware gate
992 * data[7] 0 = Interrupt Disable, 1 = Interrupt Enable
994 static int apci1500_timer_config(struct comedi_device *dev,
995 struct comedi_subdevice *s,
996 struct comedi_insn *insn,
999 struct addi_private *devpriv = dev->private;
1000 int i_TimerCounterMode, i_MasterConfiguration;
1002 devpriv->tsk_Current = current;
1004 /* Selection of the input clock */
1005 if (data[0] == 0 || data[0] == 1 || data[0] == 2) {
1006 outw(data[0], devpriv->i_IobaseAddon + APCI1500_CLK_SELECT);
1007 } /* if(data[0]==0||data[0]==1||data[0]==2) */
1010 dev_warn(dev->hw_dev,
1011 "The option for input clock selection does not exist\n");
1013 } /* if(data[0]!=3) */
1014 } /* elseif(data[0]==0||data[0]==1||data[0]==2) */
1015 /* Select the counter/timer */
1018 /* selecting counter or timer */
1021 data[2] = APCI1500_COUNTER;
1024 data[2] = APCI1500_TIMER;
1027 dev_warn(dev->hw_dev,
1028 "This choice is not a timer nor a counter\n");
1030 } /* switch(data[2]) */
1032 /* Selecting single or continuous mode */
1035 data[4] = APCI1500_CONTINUOUS;
1038 data[4] = APCI1500_SINGLE;
1041 dev_warn(dev->hw_dev,
1042 "This option for single/continuous mode does not exist\n");
1044 } /* switch(data[4]) */
1046 i_TimerCounterMode = data[2] | data[4] | 7;
1047 /* Test the reload value */
1049 if ((data[3] >= 0) && (data[3] <= 65535)) {
1050 if (data[7] == APCI1500_ENABLE
1051 || data[7] == APCI1500_DISABLE) {
1053 /* Selects the mode register of timer/counter 1 */
1054 outb(APCI1500_RW_CPT_TMR1_MODE_SPECIFICATION,
1056 APCI1500_Z8536_CONTROL_REGISTER);
1057 /* Writes the new mode */
1058 outb(i_TimerCounterMode,
1060 APCI1500_Z8536_CONTROL_REGISTER);
1062 /* Selects the constant register of timer/counter 1 */
1064 outb(APCI1500_RW_CPT_TMR1_TIME_CST_LOW,
1066 APCI1500_Z8536_CONTROL_REGISTER);
1068 /* Writes the low value */
1072 APCI1500_Z8536_CONTROL_REGISTER);
1074 /* Selects the constant register of timer/counter 1 */
1076 outb(APCI1500_RW_CPT_TMR1_TIME_CST_HIGH,
1078 APCI1500_Z8536_CONTROL_REGISTER);
1080 /* Writes the high value */
1082 data[3] = data[3] >> 8;
1085 APCI1500_Z8536_CONTROL_REGISTER);
1087 /* Selects the master configuration register */
1089 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1091 APCI1500_Z8536_CONTROL_REGISTER);
1093 /* Reads the register */
1095 i_MasterConfiguration =
1096 inb(devpriv->iobase +
1097 APCI1500_Z8536_CONTROL_REGISTER);
1099 /* Enables timer/counter 1 and triggers timer/counter 1 */
1101 i_MasterConfiguration =
1102 i_MasterConfiguration | 0x40;
1104 /* Selects the master configuration register */
1105 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1107 APCI1500_Z8536_CONTROL_REGISTER);
1109 /* Writes the new configuration */
1110 outb(i_MasterConfiguration,
1112 APCI1500_Z8536_CONTROL_REGISTER);
1113 /* Selects the commands register of */
1114 /* timer/counter 1 */
1116 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1118 APCI1500_Z8536_CONTROL_REGISTER);
1120 /* Disable timer/counter 1 */
1124 APCI1500_Z8536_CONTROL_REGISTER);
1125 /* Selects the commands register of */
1126 /* timer/counter 1 */
1127 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1129 APCI1500_Z8536_CONTROL_REGISTER);
1131 /* Trigger timer/counter 1 */
1134 APCI1500_Z8536_CONTROL_REGISTER);
1135 } /* if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1137 dev_warn(dev->hw_dev,
1138 "Error in selection of interrupt enable or disable\n");
1140 } /* elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1141 } /* if ((data[3]>= 0) && (data[3] <= 65535)) */
1143 dev_warn(dev->hw_dev,
1144 "Error in selection of reload value\n");
1146 } /* else if ((data[3]>= 0) && (data[3] <= 65535)) */
1147 i_TimerCounterWatchdogInterrupt = data[7];
1148 i_TimerCounter1Init = 1;
1151 case COUNTER2: /* selecting counter or timer */
1154 data[2] = APCI1500_COUNTER;
1157 data[2] = APCI1500_TIMER;
1160 dev_warn(dev->hw_dev,
1161 "This choice is not a timer nor a counter\n");
1163 } /* switch(data[2]) */
1165 /* Selecting single or continuous mode */
1168 data[4] = APCI1500_CONTINUOUS;
1171 data[4] = APCI1500_SINGLE;
1174 dev_warn(dev->hw_dev,
1175 "This option for single/continuous mode does not exist\n");
1177 } /* switch(data[4]) */
1179 /* Selecting software or hardware trigger */
1182 data[5] = APCI1500_SOFTWARE_TRIGGER;
1185 data[5] = APCI1500_HARDWARE_TRIGGER;
1188 dev_warn(dev->hw_dev,
1189 "This choice for software or hardware trigger does not exist\n");
1191 } /* switch(data[5]) */
1193 /* Selecting software or hardware gate */
1196 data[6] = APCI1500_SOFTWARE_GATE;
1199 data[6] = APCI1500_HARDWARE_GATE;
1202 dev_warn(dev->hw_dev,
1203 "This choice for software or hardware gate does not exist\n");
1205 } /* switch(data[6]) */
1207 i_TimerCounterMode = data[2] | data[4] | data[5] | data[6] | 7;
1209 /* Test the reload value */
1211 if ((data[3] >= 0) && (data[3] <= 65535)) {
1212 if (data[7] == APCI1500_ENABLE
1213 || data[7] == APCI1500_DISABLE) {
1215 /* Selects the mode register of timer/counter 2 */
1216 outb(APCI1500_RW_CPT_TMR2_MODE_SPECIFICATION,
1218 APCI1500_Z8536_CONTROL_REGISTER);
1219 /* Writes the new mode */
1220 outb(i_TimerCounterMode,
1222 APCI1500_Z8536_CONTROL_REGISTER);
1224 /* Selects the constant register of timer/counter 2 */
1226 outb(APCI1500_RW_CPT_TMR2_TIME_CST_LOW,
1228 APCI1500_Z8536_CONTROL_REGISTER);
1230 /* Writes the low value */
1234 APCI1500_Z8536_CONTROL_REGISTER);
1236 /* Selects the constant register of timer/counter 2 */
1238 outb(APCI1500_RW_CPT_TMR2_TIME_CST_HIGH,
1240 APCI1500_Z8536_CONTROL_REGISTER);
1242 /* Writes the high value */
1244 data[3] = data[3] >> 8;
1247 APCI1500_Z8536_CONTROL_REGISTER);
1249 /* Selects the master configuration register */
1251 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1253 APCI1500_Z8536_CONTROL_REGISTER);
1255 /* Reads the register */
1257 i_MasterConfiguration =
1258 inb(devpriv->iobase +
1259 APCI1500_Z8536_CONTROL_REGISTER);
1261 /* Enables timer/counter 2 and triggers timer/counter 2 */
1263 i_MasterConfiguration =
1264 i_MasterConfiguration | 0x20;
1266 /* Selects the master configuration register */
1267 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1269 APCI1500_Z8536_CONTROL_REGISTER);
1271 /* Writes the new configuration */
1272 outb(i_MasterConfiguration,
1274 APCI1500_Z8536_CONTROL_REGISTER);
1275 /* Selects the commands register of */
1276 /* timer/counter 2 */
1278 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1280 APCI1500_Z8536_CONTROL_REGISTER);
1282 /* Disable timer/counter 2 */
1286 APCI1500_Z8536_CONTROL_REGISTER);
1287 /* Selects the commands register of */
1288 /* timer/counter 2 */
1289 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1291 APCI1500_Z8536_CONTROL_REGISTER);
1293 /* Trigger timer/counter 1 */
1296 APCI1500_Z8536_CONTROL_REGISTER);
1297 } /* if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1299 dev_warn(dev->hw_dev,
1300 "Error in selection of interrupt enable or disable\n");
1302 } /* elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1303 } /* if ((data[3]>= 0) && (data[3] <= 65535)) */
1305 dev_warn(dev->hw_dev,
1306 "Error in selection of reload value\n");
1308 } /* else if ((data[3]>= 0) && (data[3] <= 65535)) */
1309 i_TimerCounterWatchdogInterrupt = data[7];
1310 i_TimerCounter2Init = 1;
1313 case COUNTER3: /* selecting counter or watchdog */
1316 data[2] = APCI1500_COUNTER;
1319 data[2] = APCI1500_WATCHDOG;
1322 dev_warn(dev->hw_dev,
1323 "This choice is not a watchdog nor a counter\n");
1325 } /* switch(data[2]) */
1327 /* Selecting single or continuous mode */
1330 data[4] = APCI1500_CONTINUOUS;
1333 data[4] = APCI1500_SINGLE;
1336 dev_warn(dev->hw_dev,
1337 "This option for single/continuous mode does not exist\n");
1339 } /* switch(data[4]) */
1341 /* Selecting software or hardware gate */
1344 data[6] = APCI1500_SOFTWARE_GATE;
1347 data[6] = APCI1500_HARDWARE_GATE;
1350 dev_warn(dev->hw_dev,
1351 "This choice for software or hardware gate does not exist\n");
1353 } /* switch(data[6]) */
1355 /* Test if used for watchdog */
1357 if (data[2] == APCI1500_WATCHDOG) {
1358 /* - Enables the output line */
1359 /* - Enables retrigger */
1360 /* - Pulses output */
1361 i_TimerCounterMode = data[2] | data[4] | 0x54;
1362 } /* if (data[2] == APCI1500_WATCHDOG) */
1364 i_TimerCounterMode = data[2] | data[4] | data[6] | 7;
1365 } /* elseif (data[2] == APCI1500_WATCHDOG) */
1366 /* Test the reload value */
1368 if ((data[3] >= 0) && (data[3] <= 65535)) {
1369 if (data[7] == APCI1500_ENABLE
1370 || data[7] == APCI1500_DISABLE) {
1372 /* Selects the mode register of watchdog/counter 3 */
1373 outb(APCI1500_RW_CPT_TMR3_MODE_SPECIFICATION,
1375 APCI1500_Z8536_CONTROL_REGISTER);
1376 /* Writes the new mode */
1377 outb(i_TimerCounterMode,
1379 APCI1500_Z8536_CONTROL_REGISTER);
1381 /* Selects the constant register of watchdog/counter 3 */
1383 outb(APCI1500_RW_CPT_TMR3_TIME_CST_LOW,
1385 APCI1500_Z8536_CONTROL_REGISTER);
1387 /* Writes the low value */
1391 APCI1500_Z8536_CONTROL_REGISTER);
1393 /* Selects the constant register of watchdog/counter 3 */
1395 outb(APCI1500_RW_CPT_TMR3_TIME_CST_HIGH,
1397 APCI1500_Z8536_CONTROL_REGISTER);
1399 /* Writes the high value */
1401 data[3] = data[3] >> 8;
1404 APCI1500_Z8536_CONTROL_REGISTER);
1406 /* Selects the master configuration register */
1408 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1410 APCI1500_Z8536_CONTROL_REGISTER);
1412 /* Reads the register */
1414 i_MasterConfiguration =
1415 inb(devpriv->iobase +
1416 APCI1500_Z8536_CONTROL_REGISTER);
1418 /* Enables watchdog/counter 3 and triggers watchdog/counter 3 */
1420 i_MasterConfiguration =
1421 i_MasterConfiguration | 0x10;
1423 /* Selects the master configuration register */
1424 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
1426 APCI1500_Z8536_CONTROL_REGISTER);
1428 /* Writes the new configuration */
1429 outb(i_MasterConfiguration,
1431 APCI1500_Z8536_CONTROL_REGISTER);
1433 /* Test if COUNTER */
1434 if (data[2] == APCI1500_COUNTER) {
1436 /* Selects the command register of */
1437 /* watchdog/counter 3 */
1438 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1440 APCI1500_Z8536_CONTROL_REGISTER);
1441 /* Disable the watchdog/counter 3 and starts it */
1444 APCI1500_Z8536_CONTROL_REGISTER);
1446 /* Selects the command register of */
1447 /* watchdog/counter 3 */
1449 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1451 APCI1500_Z8536_CONTROL_REGISTER);
1452 /* Trigger the watchdog/counter 3 and starts it */
1455 APCI1500_Z8536_CONTROL_REGISTER);
1457 } /* elseif(data[2]==APCI1500_COUNTER) */
1459 } /* if(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1461 dev_warn(dev->hw_dev,
1462 "Error in selection of interrupt enable or disable\n");
1464 } /* elseif(data[7]== APCI1500_ENABLE ||data[7]== APCI1500_DISABLE) */
1465 } /* if ((data[3]>= 0) && (data[3] <= 65535)) */
1467 dev_warn(dev->hw_dev,
1468 "Error in selection of reload value\n");
1470 } /* else if ((data[3]>= 0) && (data[3] <= 65535)) */
1471 i_TimerCounterWatchdogInterrupt = data[7];
1472 i_WatchdogCounter3Init = 1;
1476 dev_warn(dev->hw_dev,
1477 "The specified counter/timer option does not exist\n");
1479 } /* switch(data[1]) */
1480 i_CounterLogic = data[2];
1485 * Start / Stop or trigger the timer counter or Watchdog
1487 * data[0] 0 = Counter1/Timer1, 1 = Counter2/Timer2, 2 = Counter3/Watchdog
1488 * data[1] 0 = Start, 1 = Stop, 2 = Trigger
1489 * data[2] 0 = Counter, 1 = Timer/Watchdog
1491 static int apci1500_timer_write(struct comedi_device *dev,
1492 struct comedi_subdevice *s,
1493 struct comedi_insn *insn,
1496 struct addi_private *devpriv = dev->private;
1497 int i_CommandAndStatusValue;
1503 if (i_TimerCounter1Init == 1) {
1504 if (i_TimerCounterWatchdogInterrupt == 1) {
1505 i_CommandAndStatusValue = 0xC4; /* Enable the interrupt */
1506 } /* if(i_TimerCounterWatchdogInterrupt==1) */
1508 i_CommandAndStatusValue = 0xE4; /* disable the interrupt */
1509 } /* elseif(i_TimerCounterWatchdogInterrupt==1) */
1510 /* Starts timer/counter 1 */
1511 i_TimerCounter1Enabled = 1;
1512 /* Selects the commands and status register */
1513 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1515 APCI1500_Z8536_CONTROL_REGISTER);
1516 outb(i_CommandAndStatusValue,
1518 APCI1500_Z8536_CONTROL_REGISTER);
1519 } /* if( i_TimerCounter1Init==1) */
1521 dev_warn(dev->hw_dev,
1522 "Counter/Timer1 not configured\n");
1529 /* Stop timer/counter 1 */
1531 /* Selects the commands and status register */
1532 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1534 APCI1500_Z8536_CONTROL_REGISTER);
1537 APCI1500_Z8536_CONTROL_REGISTER);
1538 i_TimerCounter1Enabled = 0;
1542 if (i_TimerCounter1Init == 1) {
1543 if (i_TimerCounter1Enabled == 1) {
1544 /* Set Trigger and gate */
1546 i_CommandAndStatusValue = 0x6;
1547 } /* if( i_TimerCounter1Enabled==1) */
1551 i_CommandAndStatusValue = 0x2;
1552 } /* elseif(i_TimerCounter1Enabled==1) */
1554 /* Selects the commands and status register */
1555 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1557 APCI1500_Z8536_CONTROL_REGISTER);
1558 outb(i_CommandAndStatusValue,
1560 APCI1500_Z8536_CONTROL_REGISTER);
1561 } /* if( i_TimerCounter1Init==1) */
1563 dev_warn(dev->hw_dev,
1564 "Counter/Timer1 not configured\n");
1570 dev_warn(dev->hw_dev,
1571 "The specified option for start/stop/trigger does not exist\n");
1573 } /* switch(data[1]) */
1579 if (i_TimerCounter2Init == 1) {
1580 if (i_TimerCounterWatchdogInterrupt == 1) {
1581 i_CommandAndStatusValue = 0xC4; /* Enable the interrupt */
1582 } /* if(i_TimerCounterWatchdogInterrupt==1) */
1584 i_CommandAndStatusValue = 0xE4; /* disable the interrupt */
1585 } /* elseif(i_TimerCounterWatchdogInterrupt==1) */
1586 /* Starts timer/counter 2 */
1587 i_TimerCounter2Enabled = 1;
1588 /* Selects the commands and status register */
1589 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1591 APCI1500_Z8536_CONTROL_REGISTER);
1592 outb(i_CommandAndStatusValue,
1594 APCI1500_Z8536_CONTROL_REGISTER);
1595 } /* if( i_TimerCounter2Init==1) */
1597 dev_warn(dev->hw_dev,
1598 "Counter/Timer2 not configured\n");
1605 /* Stop timer/counter 2 */
1607 /* Selects the commands and status register */
1608 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1610 APCI1500_Z8536_CONTROL_REGISTER);
1613 APCI1500_Z8536_CONTROL_REGISTER);
1614 i_TimerCounter2Enabled = 0;
1617 if (i_TimerCounter2Init == 1) {
1618 if (i_TimerCounter2Enabled == 1) {
1619 /* Set Trigger and gate */
1621 i_CommandAndStatusValue = 0x6;
1622 } /* if( i_TimerCounter2Enabled==1) */
1626 i_CommandAndStatusValue = 0x2;
1627 } /* elseif(i_TimerCounter2Enabled==1) */
1629 /* Selects the commands and status register */
1630 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1632 APCI1500_Z8536_CONTROL_REGISTER);
1633 outb(i_CommandAndStatusValue,
1635 APCI1500_Z8536_CONTROL_REGISTER);
1636 } /* if( i_TimerCounter2Init==1) */
1638 dev_warn(dev->hw_dev,
1639 "Counter/Timer2 not configured\n");
1644 dev_warn(dev->hw_dev,
1645 "The specified option for start/stop/trigger does not exist\n");
1647 } /* switch(data[1]) */
1652 if (i_WatchdogCounter3Init == 1) {
1654 if (i_TimerCounterWatchdogInterrupt == 1) {
1655 i_CommandAndStatusValue = 0xC4; /* Enable the interrupt */
1656 } /* if(i_TimerCounterWatchdogInterrupt==1) */
1658 i_CommandAndStatusValue = 0xE4; /* disable the interrupt */
1659 } /* elseif(i_TimerCounterWatchdogInterrupt==1) */
1660 /* Starts Watchdog/counter 3 */
1661 i_WatchdogCounter3Enabled = 1;
1662 /* Selects the commands and status register */
1663 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1665 APCI1500_Z8536_CONTROL_REGISTER);
1666 outb(i_CommandAndStatusValue,
1668 APCI1500_Z8536_CONTROL_REGISTER);
1670 } /* if( i_WatchdogCounter3init==1) */
1672 dev_warn(dev->hw_dev,
1673 "Watchdog/Counter3 not configured\n");
1680 /* Stop Watchdog/counter 3 */
1682 /* Selects the commands and status register */
1683 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1685 APCI1500_Z8536_CONTROL_REGISTER);
1688 APCI1500_Z8536_CONTROL_REGISTER);
1689 i_WatchdogCounter3Enabled = 0;
1694 case 0: /* triggering counter 3 */
1695 if (i_WatchdogCounter3Init == 1) {
1696 if (i_WatchdogCounter3Enabled == 1) {
1697 /* Set Trigger and gate */
1699 i_CommandAndStatusValue = 0x6;
1700 } /* if( i_WatchdogCounter3Enabled==1) */
1704 i_CommandAndStatusValue = 0x2;
1705 } /* elseif(i_WatchdogCounter3Enabled==1) */
1707 /* Selects the commands and status register */
1708 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1710 APCI1500_Z8536_CONTROL_REGISTER);
1711 outb(i_CommandAndStatusValue,
1713 APCI1500_Z8536_CONTROL_REGISTER);
1714 } /* if( i_WatchdogCounter3Init==1) */
1716 dev_warn(dev->hw_dev,
1717 "Counter3 not configured\n");
1722 /* triggering Watchdog 3 */
1723 if (i_WatchdogCounter3Init == 1) {
1725 /* Selects the commands and status register */
1726 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1728 APCI1500_Z8536_CONTROL_REGISTER);
1731 APCI1500_Z8536_CONTROL_REGISTER);
1732 } /* if( i_WatchdogCounter3Init==1) */
1734 dev_warn(dev->hw_dev,
1735 "Watchdog 3 not configured\n");
1740 dev_warn(dev->hw_dev,
1741 "Wrong choice of watchdog/counter3\n");
1743 } /* switch(data[2]) */
1746 dev_warn(dev->hw_dev,
1747 "The specified option for start/stop/trigger does not exist\n");
1749 } /* switch(data[1]) */
1752 dev_warn(dev->hw_dev,
1753 "The specified choice for counter/watchdog/timer does not exist\n");
1755 } /* switch(data[0]) */
1762 * data[0] 0 = Counter1/Timer1, 1 = Counter2/Timer2, 2 = Counter3/Watchdog
1764 static int apci1500_timer_bits(struct comedi_device *dev,
1765 struct comedi_subdevice *s,
1766 struct comedi_insn *insn,
1769 struct addi_private *devpriv = dev->private;
1770 int i_CommandAndStatusValue;
1774 /* Read counter/timer1 */
1775 if (i_TimerCounter1Init == 1) {
1776 if (i_TimerCounter1Enabled == 1) {
1777 /* Set RCC and gate */
1779 i_CommandAndStatusValue = 0xC;
1780 } /* if( i_TimerCounter1Init==1) */
1784 i_CommandAndStatusValue = 0x8;
1785 } /* elseif(i_TimerCounter1Init==1) */
1787 /* Selects the commands and status register */
1788 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
1790 APCI1500_Z8536_CONTROL_REGISTER);
1791 outb(i_CommandAndStatusValue,
1793 APCI1500_Z8536_CONTROL_REGISTER);
1795 /* Selects the counter register (high) */
1796 outb(APCI1500_R_CPT_TMR1_VALUE_HIGH,
1798 APCI1500_Z8536_CONTROL_REGISTER);
1800 inb(devpriv->iobase +
1801 APCI1500_Z8536_CONTROL_REGISTER);
1802 data[0] = data[0] << 8;
1803 data[0] = data[0] & 0xff00;
1804 outb(APCI1500_R_CPT_TMR1_VALUE_LOW,
1806 APCI1500_Z8536_CONTROL_REGISTER);
1808 data[0] | inb(devpriv->iobase +
1809 APCI1500_Z8536_CONTROL_REGISTER);
1810 } /* if( i_TimerCounter1Init==1) */
1812 dev_warn(dev->hw_dev,
1813 "Timer/Counter1 not configured\n");
1815 } /* elseif( i_TimerCounter1Init==1) */
1818 /* Read counter/timer2 */
1819 if (i_TimerCounter2Init == 1) {
1820 if (i_TimerCounter2Enabled == 1) {
1821 /* Set RCC and gate */
1823 i_CommandAndStatusValue = 0xC;
1824 } /* if( i_TimerCounter2Init==1) */
1828 i_CommandAndStatusValue = 0x8;
1829 } /* elseif(i_TimerCounter2Init==1) */
1831 /* Selects the commands and status register */
1832 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
1834 APCI1500_Z8536_CONTROL_REGISTER);
1835 outb(i_CommandAndStatusValue,
1837 APCI1500_Z8536_CONTROL_REGISTER);
1839 /* Selects the counter register (high) */
1840 outb(APCI1500_R_CPT_TMR2_VALUE_HIGH,
1842 APCI1500_Z8536_CONTROL_REGISTER);
1844 inb(devpriv->iobase +
1845 APCI1500_Z8536_CONTROL_REGISTER);
1846 data[0] = data[0] << 8;
1847 data[0] = data[0] & 0xff00;
1848 outb(APCI1500_R_CPT_TMR2_VALUE_LOW,
1850 APCI1500_Z8536_CONTROL_REGISTER);
1852 data[0] | inb(devpriv->iobase +
1853 APCI1500_Z8536_CONTROL_REGISTER);
1854 } /* if( i_TimerCounter2Init==1) */
1856 dev_warn(dev->hw_dev,
1857 "Timer/Counter2 not configured\n");
1859 } /* elseif( i_TimerCounter2Init==1) */
1862 /* Read counter/watchdog2 */
1863 if (i_WatchdogCounter3Init == 1) {
1864 if (i_WatchdogCounter3Enabled == 1) {
1865 /* Set RCC and gate */
1867 i_CommandAndStatusValue = 0xC;
1868 } /* if( i_TimerCounter2Init==1) */
1872 i_CommandAndStatusValue = 0x8;
1873 } /* elseif(i_WatchdogCounter3Init==1) */
1875 /* Selects the commands and status register */
1876 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
1878 APCI1500_Z8536_CONTROL_REGISTER);
1879 outb(i_CommandAndStatusValue,
1881 APCI1500_Z8536_CONTROL_REGISTER);
1883 /* Selects the counter register (high) */
1884 outb(APCI1500_R_CPT_TMR3_VALUE_HIGH,
1886 APCI1500_Z8536_CONTROL_REGISTER);
1888 inb(devpriv->iobase +
1889 APCI1500_Z8536_CONTROL_REGISTER);
1890 data[0] = data[0] << 8;
1891 data[0] = data[0] & 0xff00;
1892 outb(APCI1500_R_CPT_TMR3_VALUE_LOW,
1894 APCI1500_Z8536_CONTROL_REGISTER);
1896 data[0] | inb(devpriv->iobase +
1897 APCI1500_Z8536_CONTROL_REGISTER);
1898 } /* if( i_WatchdogCounter3Init==1) */
1900 dev_warn(dev->hw_dev,
1901 "WatchdogCounter3 not configured\n");
1903 } /* elseif( i_WatchdogCounter3Init==1) */
1906 dev_warn(dev->hw_dev,
1907 "The choice of timer/counter/watchdog does not exist\n");
1909 } /* switch(data[0]) */
1915 * Read the interrupt mask
1917 * data[0] The interrupt mask value
1918 * data[1] Channel Number
1920 static int apci1500_timer_read(struct comedi_device *dev,
1921 struct comedi_subdevice *s,
1922 struct comedi_insn *insn,
1925 data[0] = i_InterruptMask;
1926 data[1] = i_InputChannel;
1927 i_InterruptMask = 0;
1932 * Configures the interrupt registers
1934 static int apci1500_do_bits(struct comedi_device *dev,
1935 struct comedi_subdevice *s,
1936 struct comedi_insn *insn,
1939 struct addi_private *devpriv = dev->private;
1940 unsigned int ui_Status;
1944 devpriv->tsk_Current = current;
1945 outl(0x0, devpriv->i_IobaseAmcc + 0x38);
1948 } /* if(data[0]==1) */
1952 } /* if{data[0]==0) */
1954 dev_warn(dev->hw_dev,
1955 "The parameter passed to driver is in error for enabling the voltage interrupt\n");
1957 } /* else if(data[0]==0) */
1958 } /* elseif(data[0]==1) */
1960 /* Selects the mode specification register of port B */
1961 outb(APCI1500_RW_PORT_B_SPECIFICATION,
1962 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1963 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1964 outb(APCI1500_RW_PORT_B_SPECIFICATION,
1965 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1966 /* Writes the new configuration (APCI1500_OR) */
1967 i_RegValue = (i_RegValue & 0xF9) | APCI1500_OR;
1969 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1970 /* Selects the command and status register of port B */
1971 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
1972 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1973 /* Authorises the interrupt on the board */
1974 outb(0xC0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1975 /* Selects the pattern polarity register of port B */
1976 outb(APCI1500_RW_PORT_B_PATTERN_POLARITY,
1977 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1978 outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1979 /* Selects the pattern transition register of port B */
1980 outb(APCI1500_RW_PORT_B_PATTERN_TRANSITION,
1981 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1982 outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1983 /* Selects the pattern mask register of port B */
1984 outb(APCI1500_RW_PORT_B_PATTERN_MASK,
1985 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1986 outb(i_Constant, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1988 /* Selects the command and status register of port A */
1989 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
1990 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1991 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1992 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
1993 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1994 /* Deletes the interrupt of port A */
1996 i_RegValue = (i_RegValue & 0x0F) | 0x20;
1997 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
1998 /* Selects the command and status register of port B */
1999 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2000 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2001 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2002 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2003 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2004 /* Deletes the interrupt of port B */
2006 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2007 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2009 /* Selects the command and status register of timer 1 */
2010 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2011 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2012 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2013 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2014 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2015 /* Deletes the interrupt of timer 1 */
2017 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2018 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2020 /* Selects the command and status register of timer 2 */
2021 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2022 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2023 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2024 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2025 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2026 /* Deletes the interrupt of timer 2 */
2028 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2029 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2031 /* Selects the command and status register of timer 3 */
2032 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2033 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2034 i_RegValue = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2035 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2036 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2037 /* Deletes the interrupt of timer 3 */
2039 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2040 outb(i_RegValue, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2042 /* Selects the master interrupt control register */
2043 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
2044 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2045 /* Authorizes the main interrupt on the board */
2046 outb(0xD0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2048 /* Enables the PCI interrupt */
2049 outl(0x3000, devpriv->i_IobaseAmcc + 0x38);
2050 ui_Status = inl(devpriv->i_IobaseAmcc + 0x10);
2051 ui_Status = inl(devpriv->i_IobaseAmcc + 0x38);
2052 outl(0x23000, devpriv->i_IobaseAmcc + 0x38);
2057 static void apci1500_interrupt(int irq, void *d)
2060 struct comedi_device *dev = d;
2061 struct addi_private *devpriv = dev->private;
2062 unsigned int ui_InterruptStatus = 0;
2064 i_InterruptMask = 0;
2066 /* Read the board interrupt status */
2067 ui_InterruptStatus = inl(devpriv->i_IobaseAmcc + 0x38);
2069 /* Test if board generated a interrupt */
2070 if ((ui_InterruptStatus & 0x800000) == 0x800000) {
2071 /* Disable all Interrupt */
2072 /* Selects the master interrupt control register */
2073 /* outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); */
2074 /* Disables the main interrupt on the board */
2075 /* outb(0x00,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); */
2077 /* Selects the command and status register of port A */
2078 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
2079 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2081 inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2082 if ((i_RegValue & 0x60) == 0x60) {
2083 /* Selects the command and status register of port A */
2084 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
2086 APCI1500_Z8536_CONTROL_REGISTER);
2087 /* Deletes the interrupt of port A */
2088 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2091 APCI1500_Z8536_CONTROL_REGISTER);
2092 i_InterruptMask = i_InterruptMask | 1;
2093 if (i_Logic == APCI1500_OR_PRIORITY) {
2094 outb(APCI1500_RW_PORT_A_SPECIFICATION,
2096 APCI1500_Z8536_CONTROL_REGISTER);
2098 inb(devpriv->iobase +
2099 APCI1500_Z8536_CONTROL_REGISTER);
2101 /* Selects the interrupt vector register of port A */
2102 outb(APCI1500_RW_PORT_A_INTERRUPT_CONTROL,
2104 APCI1500_Z8536_CONTROL_REGISTER);
2106 inb(devpriv->iobase +
2107 APCI1500_Z8536_CONTROL_REGISTER);
2109 i_InputChannel = 1 + (i_RegValue >> 1);
2111 } /* if(i_Logic==APCI1500_OR_PRIORITY) */
2114 } /* elseif(i_Logic==APCI1500_OR_PRIORITY) */
2115 } /* if ((i_RegValue & 0x60) == 0x60) */
2117 /* Selects the command and status register of port B */
2118 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2119 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2121 inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2122 if ((i_RegValue & 0x60) == 0x60) {
2123 /* Selects the command and status register of port B */
2124 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2126 APCI1500_Z8536_CONTROL_REGISTER);
2127 /* Deletes the interrupt of port B */
2128 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2131 APCI1500_Z8536_CONTROL_REGISTER);
2134 inb((unsigned int) devpriv->iobase +
2135 APCI1500_Z8536_PORT_B);
2137 i_RegValue = i_RegValue & 0xC0;
2138 /* Tests if this is an external error */
2141 /* Disable the interrupt */
2142 /* Selects the command and status register of port B */
2143 outl(0x0, devpriv->i_IobaseAmcc + 0x38);
2145 if (i_RegValue & 0x80) {
2147 i_InterruptMask | 0x40;
2148 } /* if (i_RegValue & 0x80) */
2150 if (i_RegValue & 0x40) {
2152 i_InterruptMask | 0x80;
2153 } /* if (i_RegValue & 0x40) */
2154 } /* if (i_RegValue) */
2156 i_InterruptMask = i_InterruptMask | 2;
2157 } /* if (i_RegValue) */
2158 } /* if ((i_RegValue & 0x60) == 0x60) */
2160 /* Selects the command and status register of timer 1 */
2161 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2162 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2164 inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2165 if ((i_RegValue & 0x60) == 0x60) {
2166 /* Selects the command and status register of timer 1 */
2167 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2169 APCI1500_Z8536_CONTROL_REGISTER);
2170 /* Deletes the interrupt of timer 1 */
2171 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2174 APCI1500_Z8536_CONTROL_REGISTER);
2175 i_InterruptMask = i_InterruptMask | 4;
2176 } /* if ((i_RegValue & 0x60) == 0x60) */
2177 /* Selects the command and status register of timer 2 */
2178 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2179 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2181 inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2182 if ((i_RegValue & 0x60) == 0x60) {
2183 /* Selects the command and status register of timer 2 */
2184 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2186 APCI1500_Z8536_CONTROL_REGISTER);
2187 /* Deletes the interrupt of timer 2 */
2188 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2191 APCI1500_Z8536_CONTROL_REGISTER);
2192 i_InterruptMask = i_InterruptMask | 8;
2193 } /* if ((i_RegValue & 0x60) == 0x60) */
2195 /* Selects the command and status register of timer 3 */
2196 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2197 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2199 inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2200 if ((i_RegValue & 0x60) == 0x60) {
2201 /* Selects the command and status register of timer 3 */
2202 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2204 APCI1500_Z8536_CONTROL_REGISTER);
2205 /* Deletes the interrupt of timer 3 */
2206 i_RegValue = (i_RegValue & 0x0F) | 0x20;
2209 APCI1500_Z8536_CONTROL_REGISTER);
2210 if (i_CounterLogic == APCI1500_COUNTER) {
2211 i_InterruptMask = i_InterruptMask | 0x10;
2212 } /* if(i_CounterLogic==APCI1500_COUNTER) */
2214 i_InterruptMask = i_InterruptMask | 0x20;
2216 } /* if ((i_RegValue & 0x60) == 0x60) */
2218 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
2219 /* Enable all Interrupts */
2221 /* Selects the master interrupt control register */
2222 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
2223 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2224 /* Authorizes the main interrupt on the board */
2225 outb(0xD0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2226 } /* if ((ui_InterruptStatus & 0x800000) == 0x800000) */
2228 dev_warn(dev->hw_dev,
2229 "Interrupt from unknown source\n");
2231 } /* else if ((ui_InterruptStatus & 0x800000) == 0x800000) */
2235 static int apci1500_reset(struct comedi_device *dev)
2237 struct addi_private *devpriv = dev->private;
2238 int i_DummyRead = 0;
2240 i_TimerCounter1Init = 0;
2241 i_TimerCounter2Init = 0;
2242 i_WatchdogCounter3Init = 0;
2245 i_TimerCounterWatchdogInterrupt = 0;
2248 i_InterruptMask = 0;
2250 i_TimerCounter1Enabled = 0;
2251 i_TimerCounter2Enabled = 0;
2252 i_WatchdogCounter3Enabled = 0;
2254 /* Software reset */
2255 i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2256 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2257 i_DummyRead = inb(devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2258 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2259 outb(1, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2260 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2262 /* Selects the master configuration control register */
2263 outb(APCI1500_RW_MASTER_CONFIGURATION_CONTROL,
2264 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2265 outb(0xF4, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2267 /* Selects the mode specification register of port A */
2268 outb(APCI1500_RW_PORT_A_SPECIFICATION,
2269 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2270 outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2272 /* Selects the data path polarity register of port A */
2273 outb(APCI1500_RW_PORT_A_DATA_PCITCH_POLARITY,
2274 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2275 /* High level of port A means 1 */
2276 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2278 /* Selects the data direction register of port A */
2279 outb(APCI1500_RW_PORT_A_DATA_DIRECTION,
2280 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2281 /* All bits used as inputs */
2282 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2283 /* Selects the command and status register of port A */
2284 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
2285 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2286 /* Deletes IP and IUS */
2287 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2288 /* Selects the command and status register of port A */
2289 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
2290 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2291 /* Deactivates the interrupt management of port A: */
2292 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2293 /* Selects the handshake specification register of port A */
2294 outb(APCI1500_RW_PORT_A_HANDSHAKE_SPECIFICATION,
2295 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2296 /* Deletes the register */
2297 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2299 /* Selects the mode specification register of port B */
2300 outb(APCI1500_RW_PORT_B_SPECIFICATION,
2301 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2302 outb(0x10, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2303 /* Selects the data path polarity register of port B */
2304 outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,
2305 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2306 /* A high level of port B means 1 */
2307 outb(0x7F, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2308 /* Selects the data direction register of port B */
2309 outb(APCI1500_RW_PORT_B_DATA_DIRECTION,
2310 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2311 /* All bits used as inputs */
2312 outb(0xFF, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2313 /* Selects the command and status register of port B */
2314 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2315 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2316 /* Deletes IP and IUS */
2317 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2318 /* Selects the command and status register of port B */
2319 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2320 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2321 /* Deactivates the interrupt management of port B: */
2322 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2323 /* Selects the handshake specification register of port B */
2324 outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,
2325 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2326 /* Deletes the register */
2327 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2329 /* Selects the data path polarity register of port C */
2330 outb(APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,
2331 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2332 /* High level of port C means 1 */
2333 outb(0x9, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2334 /* Selects the data direction register of port C */
2335 outb(APCI1500_RW_PORT_C_DATA_DIRECTION,
2336 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2337 /* All bits used as inputs except channel 1 */
2338 outb(0x0E, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2339 /* Selects the special IO register of port C */
2340 outb(APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,
2341 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2343 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2344 /* Selects the command and status register of timer 1 */
2345 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2346 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2347 /* Deletes IP and IUS */
2348 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2349 /* Selects the command and status register of timer 1 */
2350 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2351 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2352 /* Deactivates the interrupt management of timer 1 */
2353 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2354 /* Selects the command and status register of timer 2 */
2355 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2356 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2357 /* Deletes IP and IUS */
2358 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2359 /* Selects the command and status register of timer 2 */
2360 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2361 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2362 /* Deactivates Timer 2 interrupt management: */
2363 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2364 /* Selects the command and status register of timer 3 */
2365 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2366 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2367 /* Deletes IP and IUS */
2368 outb(0x20, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2369 /* Selects the command and status register of Timer 3 */
2370 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2371 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2372 /* Deactivates interrupt management of timer 3: */
2373 outb(0xE0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2374 /* Selects the master interrupt control register */
2375 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
2376 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2377 /* Deletes all interrupts */
2378 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2379 /* reset all the digital outputs */
2380 outw(0x0, devpriv->i_IobaseAddon + APCI1500_DIGITAL_OP);
2381 /* Disable the board interrupt */
2382 /* Selects the master interrupt control register */
2383 outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,
2384 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2385 /* Deactivates all interrupts */
2386 outb(0, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2387 /* Selects the command and status register of port A */
2388 outb(APCI1500_RW_PORT_A_COMMAND_AND_STATUS,
2389 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2390 /* Deactivates all interrupts */
2391 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2392 /* Selects the command and status register of port B */
2393 outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,
2394 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2395 /* Deactivates all interrupts */
2396 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2397 /* Selects the command and status register of timer 1 */
2398 outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,
2399 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2400 /* Deactivates all interrupts */
2401 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2402 /* Selects the command and status register of timer 2 */
2403 outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,
2404 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2405 /* Deactivates all interrupts */
2406 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2407 /* Selects the command and status register of timer 3*/
2408 outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,
2409 devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);
2410 /* Deactivates all interrupts */
2411 outb(0x00, devpriv->iobase + APCI1500_Z8536_CONTROL_REGISTER);