Subversion Repositories f9daq

Rev

Rev 78 | Rev 124 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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