4 Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data-com
14 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 You shoud also find the complete GPL in the COPYING file accompanying this source code.
26 +-----------------------------------------------------------------------+
27 | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier |
28 +-----------------------------------------------------------------------+
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-----------------------------------------------------------------------+
32 | Project : ADDI-DATA | Compiler : GCC |
33 | Modulname : addi_common.h | Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-----------------------------------------------------------------------+
37 | Description : ADDI COMMON Header File |
38 +-----------------------------------------------------------------------+
41 //including header files
43 #include <linux/kernel.h>
44 #include <linux/module.h>
45 #include <linux/sched.h>
47 //#include <linux/malloc.h>
48 #include <linux/slab.h>
49 #include <linux/errno.h>
50 #include <linux/ioport.h>
51 #include <linux/delay.h>
52 #include <linux/interrupt.h>
53 #include <linux/timex.h>
54 #include <linux/timer.h>
55 #include <linux/pci.h>
57 #include "../../comedidev.h"
58 #include "addi_amcc_s5933.h"
59 #include <linux/kmod.h>
60 #include <asm/uaccess.h>
65 // variable type definition
67 typedef void VOID
, *PVOID
;
68 typedef char CHAR
, *PCHAR
;
69 typedef const CHAR
*PCSTR
;
70 typedef unsigned char BYTE
, *PBYTE
;
71 typedef short SHORT
, *PSHORT
;
72 typedef unsigned short USHORT
, *PUSHORT
;
73 typedef unsigned short WORD
, *PWORD
;
74 typedef int INT
, *PINT
;;
75 typedef unsigned int UINT
, *PUINT
;
76 typedef int LONG
, *PLONG
; /* 32-bit */
77 typedef unsigned int ULONG
, *PULONG
; /* 32-bit */
78 typedef unsigned int DWORD
, *PDWORD
; /* 32-bit */
79 typedef unsigned long ULONG_PTR
;
81 typedef const comedi_lrange
*PCRANGE
;
82 #define LOBYTE(W) (BYTE )((W)&0xFF)
83 #define HIBYTE(W) (BYTE )(((W)>>8)&0xFF)
84 #define MAKEWORD(H,L) (USHORT )((L)|( (H)<<8) )
85 #define LOWORD(W) (USHORT )((W)&0xFFFF)
86 #define HIWORD(W) (USHORT )(((W)>>16)&0xFFFF)
87 #define MAKEDWORD(H,L) (UINT )((L)|( (H)<<16) )
90 #define ADDI_DISABLE 0
91 #define APCI1710_SAVE_INTERRUPT 1
93 #define ADDIDATA_EEPROM 1
94 #define ADDIDATA_NO_EEPROM 0
95 #define ADDIDATA_93C76 "93C76"
96 #define ADDIDATA_S5920 "S5920"
97 #define ADDIDATA_S5933 "S5933"
98 #define ADDIDATA_9054 "9054"
100 //ADDIDATA Enable Disable
101 #define ADDIDATA_ENABLE 1
102 #define ADDIDATA_DISABLE 0
105 // structure for the boardtype
108 PCSTR pc_DriverName
; // driver name
109 INT i_VendorId
; //PCI vendor a device ID of card
113 INT i_IorangeBase2
; // base 2 range
114 INT i_IorangeBase3
; // base 3 range
115 INT i_PCIEeprom
; // eeprom present or not
116 PCHAR pc_EepromChip
; // type of chip
117 INT i_NbrAiChannel
; // num of A/D chans
118 INT i_NbrAiChannelDiff
; // num of A/D chans in diff mode
119 INT i_AiChannelList
; // len of chanlist
120 INT i_NbrAoChannel
; // num of D/A chans
121 INT i_AiMaxdata
; // resolution of A/D
122 INT i_AoMaxdata
; // resolution of D/A
123 PCRANGE pr_AiRangelist
; // rangelist for A/D
124 PCRANGE pr_AoRangelist
; // rangelist for D/A
126 INT i_NbrDiChannel
; // Number of DI channels
127 INT i_NbrDoChannel
; // Number of DO channels
128 INT i_DoMaxdata
; // data to set all chanels high
130 INT i_NbrTTLChannel
; // Number of TTL channels
131 PCRANGE pr_TTLRangelist
; // rangelist for TTL
133 INT i_Dma
; // dma present or not
134 INT i_Timer
; // timer subdevice present or not
135 BYTE b_AvailableConvertUnit
;
136 UINT ui_MinAcquisitiontimeNs
; // Minimum Acquisition in Nano secs
137 UINT ui_MinDelaytimeNs
; // Minimum Delay in Nano secs
139 // interrupt and reset
140 void (*v_hwdrv_Interrupt
) (int irq
, void *d
);
141 int (*i_hwdrv_Reset
) (comedi_device
* dev
);
143 //Subdevice functions
146 int (*i_hwdrv_InsnConfigAnalogInput
) (comedi_device
* dev
,
147 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
148 int (*i_hwdrv_InsnReadAnalogInput
) (comedi_device
* dev
,
149 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
150 int (*i_hwdrv_InsnWriteAnalogInput
) (comedi_device
* dev
,
151 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
152 int (*i_hwdrv_InsnBitsAnalogInput
) (comedi_device
* dev
,
153 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
154 int (*i_hwdrv_CommandTestAnalogInput
) (comedi_device
* dev
,
155 comedi_subdevice
* s
, comedi_cmd
* cmd
);
156 int (*i_hwdrv_CommandAnalogInput
) (comedi_device
* dev
,
157 comedi_subdevice
* s
);
158 int (*i_hwdrv_CancelAnalogInput
) (comedi_device
* dev
,
159 comedi_subdevice
* s
);
162 int (*i_hwdrv_InsnConfigAnalogOutput
) (comedi_device
* dev
,
163 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
164 int (*i_hwdrv_InsnWriteAnalogOutput
) (comedi_device
* dev
,
165 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
166 int (*i_hwdrv_InsnBitsAnalogOutput
) (comedi_device
* dev
,
167 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
170 int (*i_hwdrv_InsnConfigDigitalInput
) (comedi_device
* dev
,
171 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
172 int (*i_hwdrv_InsnReadDigitalInput
) (comedi_device
* dev
,
173 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
174 int (*i_hwdrv_InsnWriteDigitalInput
) (comedi_device
* dev
,
175 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
176 int (*i_hwdrv_InsnBitsDigitalInput
) (comedi_device
* dev
,
177 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
180 int (*i_hwdrv_InsnConfigDigitalOutput
) (comedi_device
* dev
,
181 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
182 int (*i_hwdrv_InsnWriteDigitalOutput
) (comedi_device
* dev
,
183 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
184 int (*i_hwdrv_InsnBitsDigitalOutput
) (comedi_device
* dev
,
185 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
186 int (*i_hwdrv_InsnReadDigitalOutput
) (comedi_device
* dev
,
187 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
190 int (*i_hwdrv_InsnConfigTimer
) (comedi_device
* dev
,
191 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
192 int (*i_hwdrv_InsnWriteTimer
) (comedi_device
* dev
,
193 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
194 int (*i_hwdrv_InsnReadTimer
) (comedi_device
* dev
, comedi_subdevice
* s
,
195 comedi_insn
* insn
, lsampl_t
* data
);
196 int (*i_hwdrv_InsnBitsTimer
) (comedi_device
* dev
, comedi_subdevice
* s
,
197 comedi_insn
* insn
, lsampl_t
* data
);
200 int (*i_hwdr_ConfigInitTTLIO
) (comedi_device
* dev
,
201 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
202 int (*i_hwdr_ReadTTLIOBits
) (comedi_device
* dev
, comedi_subdevice
* s
,
203 comedi_insn
* insn
, lsampl_t
* data
);
204 int (*i_hwdr_ReadTTLIOAllPortValue
) (comedi_device
* dev
,
205 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
206 int (*i_hwdr_WriteTTLIOChlOnOff
) (comedi_device
* dev
,
207 comedi_subdevice
* s
, comedi_insn
* insn
, lsampl_t
* data
);
210 //MODULE INFO STRUCTURE
213 /*****************************/
214 /* Incremental counter infos */
215 /*****************************/
220 BYTE b_ModeRegister1
;
221 BYTE b_ModeRegister2
;
222 BYTE b_ModeRegister3
;
223 BYTE b_ModeRegister4
;
224 } s_ByteModeRegister
;
225 DWORD dw_ModeRegister1_2_3_4
;
229 unsigned int b_IndexInit
:1;
230 unsigned int b_CounterInit
:1;
231 unsigned int b_ReferenceInit
:1;
232 unsigned int b_IndexInterruptOccur
:1;
233 unsigned int b_CompareLogicInit
:1;
234 unsigned int b_FrequencyMeasurementInit
:1;
235 unsigned int b_FrequencyMeasurementEnable
:1;
238 } s_SiemensCounterInfo
;
246 BYTE b_PositionTurnLength
;
247 BYTE b_TurnCptLength
;
257 BYTE b_PortConfiguration
[4];
260 /*********************/
261 /* Digital I/O infos */
262 /*********************/
268 BYTE b_OutputMemoryEnabled
;
269 DWORD dw_OutputMemory
;
272 /*********************/
273 /* 82X54 timer infos */
274 /*********************/
279 BYTE b_InputClockSelection
;
280 BYTE b_InputClockLevel
;
282 BYTE b_HardwareGateLevel
;
283 DWORD dw_ConfigurationWord
;
284 } s_82X54TimerInfo
[3];
285 BYTE b_InterruptMask
;
288 /*********************/
289 /* Chronometer infos */
290 /*********************/
294 BYTE b_InterruptMask
;
295 BYTE b_PCIInputClock
;
298 double d_TimingInterval
;
300 } s_ChronoModuleInfo
;
302 /***********************/
303 /* Pulse encoder infos */
304 /***********************/
308 BYTE b_PulseEncoderInit
;
309 } s_PulseEncoderInfo
[4];
310 DWORD dw_SetRegister
;
311 DWORD dw_ControlRegister
;
312 DWORD dw_StatusRegister
;
313 } s_PulseEncoderModuleInfo
;
315 /********************/
316 /* Tor conter infos */
317 /********************/
321 BYTE b_TorCounterInit
;
323 BYTE b_InterruptEnable
;
324 double d_TimingInterval
;
325 ULONG ul_RealTimingInterval
;
326 } s_TorCounterInfo
[2];
327 BYTE b_PCIInputClock
;
328 } s_TorCounterModuleInfo
;
338 BYTE b_InterruptEnable
;
341 ULONG ul_RealLowTiming
;
342 ULONG ul_RealHighTiming
;
344 BYTE b_ClockSelection
;
358 BYTE b_ClockSelection
;
359 double d_TimingInterval
;
372 BYTE b_CDAReadFIFOOverflow
;
376 // Private structure for the addi_apci3120 driver
381 INT i_IobaseAmcc
; // base+size for AMCC chip
382 INT i_IobaseAddon
; //addon base address
383 INT i_IobaseReserved
;
385 struct pcilst_struct
*amcc
; // ptr too AMCC data
386 BYTE allocated
; // we have blocked card
387 BYTE b_ValidDriver
; // driver is ok
388 BYTE b_AiContinuous
; // we do unlimited AI
389 BYTE b_AiInitialisation
;
390 UINT ui_AiActualScan
; //how many scans we finished
391 UINT ui_AiBufferPtr
; // data buffer ptr in samples
392 UINT ui_AiNbrofChannels
; // how many channels is measured
393 UINT ui_AiScanLength
; // Length of actual scanlist
394 UINT ui_AiActualScanPosition
; // position in actual scan
395 PUINT pui_AiChannelList
; // actual chanlist
396 UINT ui_AiChannelList
[32]; // actual chanlist
397 BYTE b_AiChannelConfiguration
[32]; // actual chanlist
398 UINT ui_AiReadData
[32];
399 DWORD dw_AiInitialised
;
400 UINT ui_AiTimer0
; //Timer Constant for Timer0
401 UINT ui_AiTimer1
; //Timer constant for Timer1
403 UINT ui_AiDataLength
;
404 sampl_t
*AiData
; // Pointer to sample data
405 UINT ui_AiNbrofScans
; // number of scans to do
406 USHORT us_UseDma
; // To use Dma or not
407 BYTE b_DmaDoubleBuffer
; // we can use double buffering
408 UINT ui_DmaActualBuffer
; // which buffer is used now
409 //*UPDATE-0.7.57->0.7.68
410 //ULONG ul_DmaBufferVirtual[2];// pointers to begin of DMA buffer
411 sampl_t
*ul_DmaBufferVirtual
[2]; // pointers to begin of DMA buffer
412 ULONG ul_DmaBufferHw
[2]; // hw address of DMA buff
413 UINT ui_DmaBufferSize
[2]; // size of dma buffer in bytes
414 UINT ui_DmaBufferUsesize
[2]; // which size we may now used for transfer
415 UINT ui_DmaBufferSamples
[2]; // size in samples
416 UINT ui_DmaBufferPages
[2]; // number of pages in buffer
417 BYTE b_DigitalOutputRegister
; // Digital Output Register
418 BYTE b_OutputMemoryStatus
;
419 BYTE b_AnalogInputChannelNbr
; // Analog input channel Nbr
420 BYTE b_AnalogOutputChannelNbr
; // Analog input Output Nbr
421 BYTE b_TimerSelectMode
; // Contain data written at iobase + 0C
422 BYTE b_ModeSelectRegister
; // Contain data written at iobase + 0E
423 USHORT us_OutputRegister
; // Contain data written at iobase + 0
424 BYTE b_InterruptState
;
425 BYTE b_TimerInit
; // Specify if InitTimerWatchdog was load
426 BYTE b_TimerStarted
; // Specify if timer 2 is running or not
427 BYTE b_Timer2Mode
; // Specify the timer 2 mode
428 BYTE b_Timer2Interrupt
; //Timer2 interrupt enable or disable
429 BYTE b_AiCyclicAcquisition
; // indicate cyclic acquisition
430 BYTE b_InterruptMode
; // eoc eos or dma
431 BYTE b_EocEosInterrupt
; // Enable disable eoc eos interrupt
432 UINT ui_EocEosConversionTime
;
433 BYTE b_EocEosConversionTimeBase
;
435 BYTE b_ExttrigEnable
; // To enable or disable external trigger
437 struct task_struct
*tsk_Current
; // Pointer to the current process
438 boardtype
*ps_BoardInfo
;
440 // Hardware board infos for 1710
443 UINT ui_Address
; // Board address
444 UINT ui_FlashAddress
;
445 BYTE b_InterruptNbr
; // Board interrupt number
446 BYTE b_SlotNumber
; // PCI slot number
448 DWORD dw_MolduleConfiguration
[4]; // Module configuration
451 /*******************/
452 /* Interrupt infos */
453 /*******************/
456 ULONG ul_InterruptOccur
; /* 0 : No interrupt occur */
457 /* > 0 : Interrupt occur */
458 UINT ui_Read
; /* Read FIFO */
459 UINT ui_Write
; /* Write FIFO */
461 BYTE b_OldModuleMask
;
462 ULONG ul_OldInterruptMask
; /* Interrupt mask */
463 ULONG ul_OldCounterLatchValue
; /* Interrupt counter value */
464 } s_FIFOInterruptParameters
[APCI1710_SAVE_INTERRUPT
];
465 } s_InterruptParameters
;
467 str_ModuleInfo s_ModuleInfo
[4];
468 ULONG ul_TTLPortConfiguration
[10];
472 static unsigned short pci_list_builded
= 0; /* set to 1 when list of card is known */
474 //Function declarations
476 static int i_ADDI_Attach(comedi_device
* dev
, comedi_devconfig
* it
);
477 static int i_ADDI_Detach(comedi_device
* dev
);
478 static int i_ADDI_Reset(comedi_device
* dev
);
480 static irqreturn_t
v_ADDI_Interrupt(int irq
, void *d PT_REGS_ARG
);
481 static int i_ADDIDATA_InsnReadEeprom(comedi_device
* dev
, comedi_subdevice
* s
,
482 comedi_insn
* insn
, lsampl_t
* data
);