Subversion Repositories f9daq

Rev

Rev 100 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
78 f9daq 1
#include <ansi_c.h>
2
#include "wienvme_dll.h"
3
#include <utility.h>
4
 
5
//----------- DEFINES -----------------------------------------------------
6
#define DEVICENAME_NT "\\\\.\\PCIVME:\\VMEMMxx"     // a device name 'template' for WINNT
7
#define DEVICENAME_9X "\\\\.\\C:\\windows\\system\\VWIENVMED.vxd" // the same for WIN95/98
8
#define MODULE_NUMBER     1 // number of connected CC32 module
9
 
10
#define VMEinit (*vme_init)
11
static int VMEinit (const char*, unsigned short, unsigned char, int*);
12
#define VMEread (*vme_read)
13
static int VMEread (int, unsigned long, unsigned char, unsigned long, void*);
14
#define VMEwrite (*vme_write)
15
static int VMEwrite (int, unsigned long, unsigned char, unsigned long, void*);
16
#define VMEreset (*vme_reset)
17
static int VMEreset (int);
18
#define VMEclose (*vme_close)
19
static int VMEclose (int);
20
 
21
int hHandle24, hHandle32;
22
int VMEmodule;
23
 
24
void WIENVME_load (char* module_path)
25
{
26
  int stat;
27
 
28
  if (module_path == NULL)
29
    VMEmodule = LoadExternalModule
30
      ("c:\\home\\CVI\\instr\\WIENVME_DLL\\pcivme_ni.lib");
31
   else
32
    VMEmodule = LoadExternalModule (module_path);
33
 
34
  vme_init = GetExternalModuleAddr (VMEmodule, "VMEinit", &stat);
35
  vme_read = GetExternalModuleAddr (VMEmodule, "VMEread", &stat);
36
  vme_write = GetExternalModuleAddr (VMEmodule, "VMEwrite", &stat);
37
  vme_reset = GetExternalModuleAddr (VMEmodule, "VMEreset", &stat);
38
  vme_close = GetExternalModuleAddr (VMEmodule, "VMEclose", &stat);
39
 
40
  return;
41
}
42
 
43
int WIENVME_open (int* hHandle, unsigned char AddMod, char* device_name,
44
                 unsigned short module_number)
45
{
46
  int   result;
47
 
48
/* open a path to a device. */
49
  if (device_name == NULL)
50
    switch (GetCurrentPlatform ())
51
        {
52
        case 2:
53
        device_name = DEVICENAME_9X;
54
                break;
55
        case 3:
56
        device_name = DEVICENAME_NT;
57
                break;
58
        default:
59
 
60
                break;
61
        }
62
  result = VMEinit(device_name, module_number, AddMod, hHandle);
63
  if (result) {
64
    printf("Can't open interface \"%s\" to VMEMM-module \"%d\"!\n", DEVICENAME_NT, MODULE_NUMBER);
65
  }
66
  return(result);
67
}
68
 
69
int WIENVME_open24 (void)
70
{
71
  return (WIENVME_open (&hHandle24, Std_NoPriv_Data, NULL, 1));
72
}
73
 
74
int WIENVME_open32 (void)
75
{
76
  return (WIENVME_open (&hHandle32, Ext_NoPriv_Data, NULL, 1));
77
}
78
 
79
int WIENVME_start (char* module_path)
80
{
81
  WIENVME_load(module_path);
82
  WIENVME_open24();
83
  WIENVME_open32();
84
 
85
  return 0;
86
}
87
 
88
void WIENVME_unload ()
89
{
90
  UnloadExternalModule (VMEmodule);
91
  return;
92
}
93
 
94
int WIENVME_close (int hHandle)
95
{
96
  int result;
97
 
98
/* close the opened path */
99
  printf("hHandle %d\n",hHandle);
100
 
101
  result = VMEclose(hHandle);
102
  if (result) {
103
    printf("Can't close interface!\n");
104
  }
105
  return (result);
106
}
107
 
108
int WIENVME_close24 ()
109
{
110
  return (WIENVME_close (hHandle24));
111
}
112
 
113
int WIENVME_close32 ()
114
{
115
  return (WIENVME_close (hHandle32));
116
}
117
 
118
int WIENVME_stop ()
119
{
120
  WIENVME_close24();
121
  WIENVME_close32();
122
  WIENVME_unload();
123
 
124
  return 0;
125
}
126
 
127
int WIENVME_reset ()
128
{
129
  int result;
130
 
131
/* close the opened path */
132
  result = VMEreset(hHandle24);
133
  if (result) {
134
    printf("Can't reset interface!\n");
135
  }
136
  return (result);
137
}
138
 
139
int WIENVME_read8 (int hHandle, unsigned long n, unsigned long at, void* buff)
140
{
141
  int result;
142
 
143
/* D8 read */
144
  result = VMEread(hHandle, at, 1, n, buff);
145
  if (result) {
146
    printf("D8 read at 0x%X failed!\n", at);
147
  }
148
//  printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
149
  return (result);
150
}
151
 
152
int WIENVME_read16 (int hHandle, unsigned long n, unsigned long at, void* buff)
153
{
154
  int result;
155
 
156
/* D16 read */
157
  result = VMEread(hHandle, at, 2, n, buff);
158
  if (result) {
159
    printf("D16 read at 0x%X failed!\n", at);
160
  }
161
//  printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
162
  return (result);
163
}
164
 
165
int WIENVME_read32 (int hHandle, unsigned long n, unsigned long at, void* buff)
166
{
167
  int result;
168
 
169
/* D32 read */
170
  result = VMEread(hHandle, at, 4, n, buff);
171
  if (result) {
172
    printf("D32 read at 0x%X failed!\n", at);
173
  }
174
  //printf("0x%X, 0x%X, 0x%X, 0x%X\n", hHandle, at, n, * (unsigned short *) buff);
175
  return (result);
176
}
177
 
178
int WIENVME_write8 (int hHandle, unsigned long n, unsigned long at, void* buff)
179
{
180
  int result;
181
 
182
/* D8 write */
183
  result = VMEwrite(hHandle, at, 1, n, buff);
184
  if (result) {
185
    printf("D8 write at 0x%X failed!\n", at);
186
  }
187
  return (result);
188
}
189
 
190
int WIENVME_write16 (int hHandle, unsigned long n, unsigned long at, void* buff)
191
{
192
  int result;
193
 
194
/* D16 write */
195
  result = VMEwrite(hHandle, at, 2, n, buff);
196
  if (result) {
197
    printf("D16 write at 0x%X failed!\n", at);
198
  }
199
  return (result);
200
}
201
 
202
int WIENVME_write32 (int hHandle, unsigned long n, unsigned long at, void* buff)
203
{
204
  int result;
205
 
206
/* D32 write */
207
  result = VMEwrite(hHandle, at, 4, n, buff);
208
  if (result) {
209
    printf("D32 write at 0x%X failed!\n", at);
210
  }
211
  //printf("D32 write at 0x%X buff=0x%X\n", at,((int*) buff)[0]);
212
  return (result);
213
}
214
 
215
 
216
#ifndef VME_D32
217
 
218
#define VME_D8  0x1
219
#define VME_D16 0x2
220
#define VME_D32 0x4
221
#endif
222
 
223
short __stdcall WIENVME_VME_R( uint16_t AM, uint16_t DW,  uint32_t VME_Address, uint32_t *Data){
224
        int hHandle=0, nb=0;
225
        switch (AM){
226
                case Ext_NoPriv_Data: hHandle = hHandle32; break;
227
                case Std_NoPriv_Data: hHandle = hHandle24; break;
228
                default : return 0;
229
        }      
230
 
231
 
232
        switch (DW){
233
          case VME_D16: nb=  WIENVME_read16 (hHandle, 1, (unsigned long) VME_Address, (void*) Data)  ;  break;
234
      case VME_D32: nb=  WIENVME_read32 (hHandle, 1, (unsigned long) VME_Address, (void*) Data)  ; break;
235
 
236
      default: return 0;
237
    }
238
        return nb;
239
}      
240
 
241
short __stdcall WIENVME_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
242
                int hHandle=0, nb=0;
243
        switch (AM){
244
                case Ext_NoPriv_Data: hHandle = hHandle32; break;
245
                case Std_NoPriv_Data: hHandle = hHandle24; break;
246
                default : return 0;
247
        }      
248
 
249
 
250
        switch (DW){
251
          case VME_D16: nb=  WIENVME_write16 (hHandle, 1, (unsigned long) VME_Address, (void*) &Data)  ;  break;
252
      case VME_D32: nb=  WIENVME_write32 (hHandle, 1, (unsigned long) VME_Address, (void*) &Data)  ; break;
253
 
254
      default: return 0;
255
    }
256
        return nb;
257
}      
258
 
259
short __stdcall WIENVME_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
260
 
261
        return WIENVME_VME_W( AM, DW, VME_Address, Data);
262
}      
263
short __stdcall WIENVME_VME_MWRST( void ){
264
 
265
 
266
        return 0;
267
}      
268
short __stdcall WIENVME_VME_MWEXEC( void ){
269
 
270
 
271
        return 0;
272
}      
273
 
274
short __stdcall WIENVME_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){
275
 
276
 
277
        return WIENVME_VME_R( AM, DW, VME_Address, Data);  
278
}      
279
short __stdcall WIENVME_VME_MRRST( void ){
280
 
281
 
282
        return 0;
283
}      
284
short __stdcall WIENVME_VME_MREXEC(  uint32_t *Data  ){
285
 
286
 
287
        return 0;
288
}