Subversion Repositories f9daq

Rev

Rev 100 | Rev 135 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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