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