Subversion Repositories f9daq

Rev

Rev 23 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23 f9daq 1
//-------------------------------------------------------------------------
2
// WINNT driver for PCICC32 interface from ARW Elektronik, Germany --------
3
// all around recognition and basic services of VMEMM
4
//
5
// (c) 2000-2002 ARW Elektronik
6
//
7
// this source code is published under GPL (Open Source). You can use, redistrubute and 
8
// modify it unless this header   is not modified or deleted. No warranty is given that 
9
// this software will work like expected.
10
// This product is not authorized for use as critical component in life support systems
11
// wihout the express written approval of ARW Elektronik Germany.
12
//
13
// Please announce changes and hints to ARW Elektronik
14
//
15
// what                                            who          when
16
// started from pcivme_v.c                         AR           02.07.2000
17
// changed making procedure (only VCC > 6.0)       AR           30.05.2002
18
//
19
 
20
//-------------------------------------------------------------------------
21
// INCLUDES
22
//
23
#include <ntddk.h>
24
#include <pcicc32_drv.h>
25
#include <pcicc32_v.h>
26
#include <pcicc32_local.h>  // all around the pciada interface
27
 
28
#ifndef WORD                            // don't touch include files of WIN95 driver
29
#define WORD USHORT
30
#endif
31
 
32
#ifndef DWORD
33
#define DWORD ULONG
34
#endif
35
 
36
//------------------------------------------------------------------------
37
// PROTOTYPES
38
//
39
 
40
//------------------------------------------------------------------------
41
// GLOBALS
42
//
43
 
44
//------------------------------------------------------------------------
45
// FUNCTIONS
46
//
47
 
48
//------------------------------------------------------------------------
49
// test connection to VMEMM devices without disturbing anything 
50
//
51
//---------------------------------------------------------------------
52
// checks a connection with a small test pattern
53
//
54
NTSTATUS TestConnection(PCIADA *pciada)
55
{
56
        USHORT *pwADRH = (USHORT *)_WORD_NAF(pciada->pvVirtIfr, 30, 1, 0);
57
        USHORT *pwADRL = (USHORT *)_WORD_NAF(pciada->pvVirtIfr, 30, 0, 0);
58
        int i;
59
        USHORT wRet;
60
    USHORT wADRHContent;
61
    USHORT wADRLContent;
62
 
63
 
64
        KdPrint(("TestConnection()\n"));
65
 
66
        wADRHContent = READ_REGISTER_USHORT(pwADRH);    // save previous content
67
        wADRLContent = READ_REGISTER_USHORT(pwADRL);
68
 
69
        for (i = 0; i < 10000; i++)
70
        {
71
                WRITE_REGISTER_USHORT(pwADRH, 0x5555);
72
                WRITE_REGISTER_USHORT(pwADRL, 0xAAAA);
73
                wRet = READ_REGISTER_USHORT(pwADRH);
74
                if (wRet != 0x5555) return STATUS_UNSUCCESSFUL;
75
 
76
                WRITE_REGISTER_USHORT(pwADRH, 0xAAAA);
77
                WRITE_REGISTER_USHORT(pwADRL, 0x5555);
78
                wRet = READ_REGISTER_USHORT(pwADRH);
79
                if (wRet != 0xAAAA) return STATUS_UNSUCCESSFUL;
80
 
81
                WRITE_REGISTER_USHORT(pwADRH, 0x0000);
82
                WRITE_REGISTER_USHORT(pwADRL, 0xFFFF);
83
                wRet = READ_REGISTER_USHORT(pwADRH);
84
                if (wRet != 0x0000) return STATUS_UNSUCCESSFUL;
85
 
86
                WRITE_REGISTER_USHORT(pwADRH, 0xFFFF);
87
                WRITE_REGISTER_USHORT(pwADRL, 0x0000);
88
                wRet = READ_REGISTER_USHORT(pwADRH);
89
                if (wRet != 0xFFFF) return STATUS_UNSUCCESSFUL;
90
        }
91
 
92
        WRITE_REGISTER_USHORT(pwADRH, wADRHContent);    // restore previous content
93
        WRITE_REGISTER_USHORT(pwADRL, wADRLContent);
94
 
95
        KdPrint(("TestConnection() OK.\n"));
96
 
97
        return STATUS_SUCCESS;
98
}
99
 
100
//------------------------------------------------------------------------
101
// scan VMEMM devices without disturbing anything 
102
//
103
NTSTATUS PCICC32ScanCC32(PDEVICE_OBJECT deviceObj)
104
{
105
        int i;
106
        int nPCIADAs = ((DEVICE_EXT*)(deviceObj->DeviceExtension))->nPCIADAs;
107
        PCIADA           *pciada;
108
        USHORT           wCntrl;
109
        USHORT                   wIntCSR;
110
        USHORT                   wModuleStatus;
111
 
112
        KdPrint(("PCICC32ScanCC32(nPCIADAs = %d)\n", nPCIADAs));
113
 
114
    for (i = 0; i < nPCIADAs; i++)
115
    {
116
                pciada = &((DEVICE_EXT*)(deviceObj->DeviceExtension))->pciada[i];
117
 
118
                wCntrl  = READ_REGISTER_USHORT(pciada->pwCntrl);   // save it for later use
119
        wIntCSR = READ_REGISTER_USHORT(pciada->pwIntCSR);
120
 
121
                KdPrint(("wCntrl = 0x%04x, wIntCSR = 0x%04x\n", wCntrl, wIntCSR));
122
 
123
                WRITE_REGISTER_USHORT(pciada->pwCntrl, INHIBIT_CC32);  // switch off before open
124
                WRITE_REGISTER_USHORT(pciada->pwIntCSR, DISABLE_PCIADA_IRQS);
125
                WRITE_REGISTER_USHORT(pciada->pwCntrl, RELEASE_CC32);  // open it for test
126
 
127
                if (wCntrl & 0x0800)
128
                {
129
                        if (TestConnection(pciada) == STATUS_SUCCESS)
130
                        {      
131
                                wModuleStatus  = READ_REGISTER_USHORT(pciada->pvVirtIfr);
132
 
133
                                pciada->bConnected              = TRUE;
134
 
135
                                // interpret the content
136
                                pciada->wModuleNumber   = (wModuleStatus & MASK_MODNR)   >> 4;
137
                                pciada->wFPGAVersion    = (wModuleStatus & MASK_FPGA)    >> 8;
138
                                pciada->wModuleType             = (wModuleStatus & MASK_MODTYPE) >> 12;
139
 
140
                                KdPrint(("PCIADA %d <-> CC32 %d\n", i, pciada->wModuleNumber));
141
                        }
142
                        else
143
                                pciada->wModuleNumber = 0xFFFF;  // not recognized, take it out
144
                }
145
                else
146
                        pciada->wModuleNumber = 0xFFFF;  // not recognized, take it out
147
 
148
                if (pciada->wModuleNumber != 0xFFFF)
149
                  WRITE_REGISTER_USHORT(pciada->pwCntrl,  wCntrl);   // restore state
150
                else
151
                  WRITE_REGISTER_USHORT(pciada->pwCntrl,  INHIBIT_CC32);  
152
 
153
                WRITE_REGISTER_USHORT(pciada->pwIntCSR, wIntCSR);    // restore interrupt masks
154
    }
155
 
156
        return STATUS_SUCCESS;
157
}
158
 
159
 
160
//------------------------------------------------------------------------
161
// deinit all PCIADAs in a passive state 
162
//
163
NTSTATUS PCICC32DeInitPCIADAs(PDEVICE_OBJECT deviceObj)
164
{
165
        int              i;
166
        DEVICE_EXT       *pDevExt = (DEVICE_EXT*)deviceObj->DeviceExtension;
167
        int                              nPCIADAs = pDevExt->nPCIADAs;
168
        PCIADA           *pciada;
169
 
170
        KdPrint(("PCICC32DeInitPCIADAs()\n"));
171
 
172
        // dis connect the interrupts to service routines
173
        for (i = 0; i < nPCIADAs; i++)
174
        {
175
                pciada = &pDevExt->pciada[i];
176
 
177
                WRITE_REGISTER_USHORT(pciada->pwCntrl,  INHIBIT_CC32);
178
                // this is the same as globalInterruptDisable(pciada);
179
                WRITE_REGISTER_USHORT(pciada->pwIntCSR, DISABLE_PCIADA_IRQS);
180
        }
181
 
182
        return STATUS_SUCCESS;
183
}
184
 
185
//------------------------------------------------------------------------
186
// switches pciada on or off 
187
//
188
void enableCC32(PCIADA *pciada)
189
{
190
        WRITE_REGISTER_USHORT(pciada->pwCntrl,  RELEASE_CC32);
191
}
192
 
193
void disableCC32(PCIADA *pciada)
194
{
195
        WRITE_REGISTER_USHORT(pciada->pwCntrl,  INHIBIT_CC32);
196
}