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