Rev 136 | Rev 139 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 136 | Rev 138 | ||
---|---|---|---|
1 | #ifdef LINUX |
1 | #ifdef LINUX |
2 | #include <dlfcn.h> |
2 | #include <dlfcn.h> |
3 | #define LoadLibrary(x) dlopen( (x), RTLD_NOW ); |
3 | #define LoadLibrary(x) dlopen( (x), RTLD_NOW ); |
4 | #define GetProcAddress(x,y) dlsym((x),(y)) |
4 | #define GetProcAddress(x,y) dlsym((x),(y)) |
5 | #define __stdcall |
5 | #define __stdcall |
6 | #define UCHAR unsigned char |
6 | #define UCHAR unsigned char |
7 | #define HINSTANCE void * |
7 | #define HINSTANCE void * |
8 | #define _VI_FUNC |
8 | #define _VI_FUNC |
9 | #include <stdlib.h> |
9 | #include <stdlib.h> |
10 | #include <stdio.h> |
10 | #include <stdio.h> |
11 | #include <stdint.h> |
11 | #include <stdint.h> |
12 | #include <string.h> |
12 | #include <string.h> |
13 | #endif |
13 | #endif |
14 | 14 | ||
15 | #include "wusbvme_dll.h" |
15 | #include "wusbvme_dll.h" |
16 | 16 | ||
17 | usb_dev_handle *WUSB_udev; |
17 | usb_dev_handle *WUSB_udev; |
18 | 18 | ||
19 | static HINSTANCE DLLHandle; |
19 | static HINSTANCE DLLHandle; |
20 | 20 | ||
21 | 21 | ||
22 | short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data); |
22 | short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data); |
23 | 23 | ||
24 | short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data); |
24 | short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data); |
25 | 25 | ||
26 | short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data); |
26 | short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data); |
27 | short __stdcall WIENER_VMUSB_VME_MWRST( void ); |
27 | short __stdcall WIENER_VMUSB_VME_MWRST( void ); |
28 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ); |
28 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ); |
29 | 29 | ||
30 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data); |
30 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data); |
31 | short __stdcall WIENER_VMUSB_VME_MRRST( void ); |
31 | short __stdcall WIENER_VMUSB_VME_MRRST( void ); |
32 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ); |
32 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ); |
33 | 33 | ||
- | 34 | ||
- | 35 | #ifdef XXDLL |
|
34 | 36 | ||
35 | short __stdcall xxusb_register_read(usb_dev_handle *hDev, short RegAddr, long *RegData); |
37 | short __stdcall xxusb_register_read(usb_dev_handle *hDev, short RegAddr, long *RegData); |
36 | short __stdcall xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData); |
38 | short __stdcall xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData); |
37 | short __stdcall xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData); |
39 | short __stdcall xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData); |
38 | short __stdcall xxusb_stack_execute(usb_dev_handle *hDev, long *StackData); |
40 | short __stdcall xxusb_stack_execute(usb_dev_handle *hDev, long *StackData); |
39 | short __stdcall xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout); |
41 | short __stdcall xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout); |
40 | short __stdcall xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData); |
42 | short __stdcall xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData); |
41 | short __stdcall xxusb_usbfifo_read(usb_dev_handle *hDev, long *DataBuffer, short lDataLen, int timeout); |
43 | short __stdcall xxusb_usbfifo_read(usb_dev_handle *hDev, long *DataBuffer, short lDataLen, int timeout); |
42 | short __stdcall xxusb_bulk_read(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout); |
44 | short __stdcall xxusb_bulk_read(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout); |
43 | short __stdcall xxusb_bulk_write(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout); |
45 | short __stdcall xxusb_bulk_write(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout); |
44 | short __stdcall xxusb_reset_toggle(usb_dev_handle *hDev); |
46 | short __stdcall xxusb_reset_toggle(usb_dev_handle *hDev); |
45 | 47 | ||
46 | short __stdcall xxusb_devices_find(xxusb_device_type *xxusbDev); |
48 | short __stdcall xxusb_devices_find(xxusb_device_type *xxusbDev); |
47 | short __stdcall xxusb_device_close(usb_dev_handle *hDev); |
49 | short __stdcall xxusb_device_close(usb_dev_handle *hDev); |
48 | usb_dev_handle* __stdcall xxusb_device_open(struct usb_device *dev); |
50 | usb_dev_handle* __stdcall xxusb_device_open(struct usb_device *dev); |
49 | short __stdcall xxusb_flash_program(usb_dev_handle *hDev, char *config, short nsect); |
51 | short __stdcall xxusb_flash_program(usb_dev_handle *hDev, char *config, short nsect); |
50 | short __stdcall xxusb_flashblock_program(usb_dev_handle *hDev, UCHAR *config); |
52 | short __stdcall xxusb_flashblock_program(usb_dev_handle *hDev, UCHAR *config); |
51 | usb_dev_handle* __stdcall xxusb_serial_open(char *SerialString); |
53 | usb_dev_handle* __stdcall xxusb_serial_open(char *SerialString); |
52 | 54 | ||
53 | short __stdcall VME_register_write(usb_dev_handle *hdev, long VME_Address, long Data); |
55 | short __stdcall VME_register_write(usb_dev_handle *hdev, long VME_Address, long Data); |
54 | short __stdcall VME_register_read(usb_dev_handle *hdev, long VME_Address, long *Data); |
56 | short __stdcall VME_register_read(usb_dev_handle *hdev, long VME_Address, long *Data); |
55 | short __stdcall VME_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch); |
57 | short __stdcall VME_LED_settings(usb_dev_handle *hdev, int LED, int code, int invert, int latch); |
56 | 58 | ||
57 | short __stdcall VME_DGG(usb_dev_handle *hdev, unsigned short channel, unsigned short trigger,unsigned short output, long delay, unsigned short gate, unsigned short invert, unsigned short latch); |
59 | short __stdcall VME_DGG(usb_dev_handle *hdev, unsigned short channel, unsigned short trigger,unsigned short output, long delay, unsigned short gate, unsigned short invert, unsigned short latch); |
58 | 60 | ||
59 | short __stdcall VME_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch); |
61 | short __stdcall VME_Output_settings(usb_dev_handle *hdev, int Channel, int code, int invert, int latch); |
60 | 62 | ||
61 | short __stdcall VME_read_16(usb_dev_handle *hdev,short Address_Modifier, long VME_Address, long *Data); |
63 | short __stdcall VME_read_16(usb_dev_handle *hdev,short Address_Modifier, long VME_Address, long *Data); |
62 | short __stdcall VME_read_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long *Data); |
64 | short __stdcall VME_read_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long *Data); |
63 | short __stdcall VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, long VME_Address, long Data[]); |
65 | short __stdcall VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, long VME_Address, long Data[]); |
64 | short __stdcall VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data); |
66 | short __stdcall VME_write_16(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data); |
65 | short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data); |
67 | short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data); |
66 | 68 | ||
67 | 69 | ||
68 | void _VI_FUNC WIENER_VMUSB_load (const char* module_path) { |
70 | void _VI_FUNC WIENER_VMUSB_load (const char* module_path) { |
69 | if (module_path == NULL) { |
71 | if (module_path == NULL) { |
70 | DLLHandle = LoadLibrary("libxxusb.dll"); |
72 | DLLHandle = LoadLibrary("c:\\Windows\\system32\\libxxusb.dll"); |
71 | } else { |
73 | } else { |
72 | DLLHandle = LoadLibrary(module_path); |
74 | DLLHandle = LoadLibrary(module_path); |
73 | } |
75 | } |
74 | if (!DLLHandle) { |
76 | if (!DLLHandle) { |
75 | printf ("\n\nFailed to Open libxxusb.dll \n"); |
77 | printf ("\n\nFailed to Open libxxusb.dll \n"); |
- | 78 | printf("LastError 0x%x\n",GetLastError() ); |
|
76 | return; |
79 | return; |
77 | } |
80 | } |
78 | if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1); |
81 | if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1); |
79 | if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1); |
82 | if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1); |
80 | if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1); |
83 | if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1); |
81 | if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1); |
84 | if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1); |
82 | if (!(xxusb_longstack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_longstack_execute"))) exit(1); |
85 | if (!(xxusb_longstack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_longstack_execute"))) exit(1); |
83 | if (!(xxusb_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_write"))) exit(1); |
86 | if (!(xxusb_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_write"))) exit(1); |
84 | if (!(xxusb_usbfifo_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_usbfifo_read"))) exit(1); |
87 | if (!(xxusb_usbfifo_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_usbfifo_read"))) exit(1); |
85 | if (!(xxusb_bulk_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_read"))) exit(1); |
88 | if (!(xxusb_bulk_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_read"))) exit(1); |
86 | if (!(xxusb_bulk_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_write"))) exit(1); |
89 | if (!(xxusb_bulk_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_write"))) exit(1); |
87 | if (!(xxusb_reset_toggle_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_reset_toggle"))) exit(1); |
90 | if (!(xxusb_reset_toggle_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_reset_toggle"))) exit(1); |
88 | 91 | ||
89 | if (!(xxusb_devices_find_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_devices_find"))) exit(1); |
92 | if (!(xxusb_devices_find_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_devices_find"))) exit(1); |
90 | if (!(xxusb_device_close_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_close"))) exit(1); |
93 | if (!(xxusb_device_close_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_close"))) exit(1); |
91 | if (!(xxusb_device_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_open"))) exit(1); |
94 | if (!(xxusb_device_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_open"))) exit(1); |
92 | if (!(xxusb_flash_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flash_program"))) exit(1); |
95 | if (!(xxusb_flash_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flash_program"))) exit(1); |
93 | if (!(xxusb_flashblock_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flashblock_program"))) exit(1); |
96 | if (!(xxusb_flashblock_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flashblock_program"))) exit(1); |
94 | if (!(xxusb_serial_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_serial_open"))) exit(1); |
97 | if (!(xxusb_serial_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_serial_open"))) exit(1); |
95 | if (!(VME_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_write"))) exit(1); |
98 | if (!(VME_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_write"))) exit(1); |
96 | if (!(VME_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_read"))) exit(1); |
99 | if (!(VME_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_read"))) exit(1); |
97 | if (!(VME_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_LED_settings"))) exit(1); |
100 | if (!(VME_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_LED_settings"))) exit(1); |
98 | if (!(VME_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"VME_DGG"))) exit(1); |
101 | if (!(VME_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"VME_DGG"))) exit(1); |
99 | if (!(VME_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_Output_settings"))) exit(1); |
102 | if (!(VME_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_Output_settings"))) exit(1); |
100 | if (!(VME_read_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_16"))) exit(1); |
103 | if (!(VME_read_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_16"))) exit(1); |
101 | if (!(VME_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_32"))) exit(1); |
104 | if (!(VME_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_32"))) exit(1); |
102 | if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) exit(1); |
105 | if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) exit(1); |
103 | if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) exit(1); |
106 | if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) exit(1); |
104 | if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1); |
107 | if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1); |
105 | } |
108 | } |
- | 109 | ||
- | 110 | #else |
|
- | 111 | ||
- | 112 | void _VI_FUNC WIENER_VMUSB_load (const char* module_path) { |
|
- | 113 | ||
- | 114 | } |
|
- | 115 | #endif |
|
106 | 116 | ||
107 | void _VI_FUNC WIENER_VMUSB_open (const char *serial) { |
117 | void _VI_FUNC WIENER_VMUSB_open (const char *serial) { |
108 | 118 | ||
109 | xxusb_device_type devices[100]; |
119 | xxusb_device_type devices[100]; |
110 | struct usb_device *dev; |
120 | struct usb_device *dev; |
111 | if (serial != NULL) |
121 | if (serial != NULL) |
112 | WUSB_udev = xxusb_serial_open((char *) serial); |
122 | WUSB_udev = xxusb_serial_open((char *) serial); |
113 | else { |
123 | else { |
114 | //Find XX_USB devices and open the first one found |
124 | //Find XX_USB devices and open the first one found |
115 | xxusb_devices_find(devices); |
125 | xxusb_devices_find(devices); |
116 | dev = devices[0].usbdev; |
126 | dev = devices[0].usbdev; |
117 | WUSB_udev = xxusb_device_open(dev); |
127 | WUSB_udev = xxusb_device_open(dev); |
118 | } |
128 | } |
119 | // Make sure VM_USB opened OK |
129 | // Make sure VM_USB opened OK |
120 | if(!WUSB_udev) { |
130 | if(!WUSB_udev) { |
121 | printf ("\n\nFailed to Open VM_USB \n\n"); |
131 | printf ("\n\nFailed to Open VM_USB \n\n"); |
122 | return ; |
132 | return ; |
123 | } else { |
133 | } else { |
124 | printf("VM-USB Device open.!\n"); |
134 | printf("VM-USB Device open.!\n"); |
125 | } |
135 | } |
126 | 136 | ||
127 | 137 | ||
128 | } |
138 | } |
129 | 139 | ||
130 | void _VI_FUNC WIENER_VMUSB_close (void) { |
140 | void _VI_FUNC WIENER_VMUSB_close (void) { |
131 | if (WUSB_udev) xxusb_device_close(WUSB_udev); |
141 | if (WUSB_udev) xxusb_device_close(WUSB_udev); |
132 | } |
142 | } |
133 | 143 | ||
134 | 144 | ||
135 | uint32_t fStack[MAXSTACKSIZE]; |
145 | uint32_t fStack[MAXSTACKSIZE]; |
136 | uint32_t fStackSize; |
146 | uint32_t fStackSize; |
137 | 147 | ||
138 | int WIENER_VMUSB_StackInit() { |
148 | int WIENER_VMUSB_StackInit() { |
139 | fStack[0]=1; |
149 | fStack[0]=1; |
140 | fStackSize=1; |
150 | fStackSize=1; |
141 | return fStack[0]; |
151 | return fStack[0]; |
142 | } |
152 | } |
143 | 153 | ||
144 | void WIENER_VMUSB_StackClear() { |
154 | void WIENER_VMUSB_StackClear() { |
145 | WIENER_VMUSB_StackInit(); |
155 | WIENER_VMUSB_StackInit(); |
146 | } |
156 | } |
147 | 157 | ||
148 | int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack) { |
158 | int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack) { |
149 | int i; |
159 | int i; |
150 | uint16_t * u16Stack = (uint16_t *) fStack; |
160 | uint16_t * u16Stack = (uint16_t *) fStack; |
151 | for (i=0; i< fStackSize*2; i++) { |
161 | for (i=0; i< fStackSize*2; i++) { |
152 | if (i<maxn) stack[i]=u16Stack[i]; |
162 | if (i<maxn) stack[i]=u16Stack[i]; |
153 | else return -1; |
163 | else return -1; |
154 | } |
164 | } |
155 | return fStackSize*2; |
165 | return fStackSize*2; |
156 | } |
166 | } |
157 | 167 | ||
158 | int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack) { |
168 | int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack) { |
159 | int i; |
169 | int i; |
160 | uint16_t * u16Stack = (uint16_t *) fStack; |
170 | uint16_t * u16Stack = (uint16_t *) fStack; |
161 | for (i=0; i< fStackSize*2; i++) { |
171 | for (i=0; i< fStackSize*2; i++) { |
162 | if (i<maxn) stack[i]=u16Stack[i]; |
172 | if (i<maxn) stack[i]=u16Stack[i]; |
163 | else return -1; |
173 | else return -1; |
164 | } |
174 | } |
165 | return fStackSize*2; |
175 | return fStackSize*2; |
166 | } |
176 | } |
167 | 177 | ||
168 | 178 | ||
169 | int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ) { |
179 | int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ) { |
170 | if (fStackSize+2 >= MAXSTACKSIZE) { |
180 | if (fStackSize+2 >= MAXSTACKSIZE) { |
171 | fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2); |
181 | fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2); |
172 | return -1; |
182 | return -1; |
173 | } |
183 | } |
174 | fStack[fStackSize ++] = cmd; |
184 | fStack[fStackSize ++] = cmd; |
175 | fStack[fStackSize ++] = addr; |
185 | fStack[fStackSize ++] = addr; |
176 | fStack[0]+=4; |
186 | fStack[0]+=4; |
177 | return fStack[0]; |
187 | return fStack[0]; |
178 | } |
188 | } |
179 | 189 | ||
180 | int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data) { |
190 | int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data) { |
181 | 191 | ||
182 | WIENER_VMUSB_StackAppend( cmd, addr ); |
192 | WIENER_VMUSB_StackAppend( cmd, addr ); |
183 | 193 | ||
184 | if (fStackSize+1 >= MAXSTACKSIZE) { |
194 | if (fStackSize+1 >= MAXSTACKSIZE) { |
185 | fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1); |
195 | fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1); |
186 | return -1; |
196 | return -1; |
187 | } |
197 | } |
188 | fStack[fStackSize++] = data; |
198 | fStack[fStackSize++] = data; |
189 | fStack[0]+=2; |
199 | fStack[0]+=2; |
190 | return fStack[0]; |
200 | return fStack[0]; |
191 | } |
201 | } |
192 | 202 | ||
193 | void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask) { |
203 | void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask) { |
194 | WIENER_VMUSB_StackAppend(CMD_READ| CMD_HD | adr_mod ,addr); |
204 | WIENER_VMUSB_StackAppend(CMD_READ| CMD_HD | adr_mod ,addr); |
195 | WIENER_VMUSB_StackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask); |
205 | WIENER_VMUSB_StackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask); |
196 | } |
206 | } |
197 | 207 | ||
198 | void WIENER_VMUSB_StackMultiRead(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment) { |
208 | void WIENER_VMUSB_StackMultiRead(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment) { |
199 | int i; |
209 | int i; |
200 | for (i=0; i<n; i++) WIENER_VMUSB_StackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment); |
210 | for (i=0; i<n; i++) WIENER_VMUSB_StackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment); |
201 | } |
211 | } |
202 | void WIENER_VMUSB_StackMultiWrite(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data) { |
212 | void WIENER_VMUSB_StackMultiWrite(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data) { |
203 | int i; |
213 | int i; |
204 | for (i=0; i<n; i++) WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data); |
214 | for (i=0; i<n; i++) WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data); |
205 | } |
215 | } |
206 | 216 | ||
207 | void WIENER_VMUSB_StackPrint() { |
217 | void WIENER_VMUSB_StackPrint() { |
208 | uint16_t * u16Stack = (uint16_t *) fStack; |
218 | uint16_t * u16Stack = (uint16_t *) fStack; |
209 | uint32_t i; |
219 | uint32_t i; |
210 | for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]); |
220 | for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]); |
211 | printf("size of stack %d __________________________________\n",fStackSize*2-1); |
221 | printf("size of stack %d __________________________________\n",fStackSize*2-1); |
212 | } |
222 | } |
213 | 223 | ||
214 | 224 | ||
215 | char wusbcc_stack[MAXSTACKSIZE*4]; |
225 | char wusbcc_stack[MAXSTACKSIZE*4]; |
216 | 226 | ||
217 | 227 | ||
218 | int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) { |
228 | int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) { |
219 | int i, nb=0; |
229 | int i, nb=0; |
220 | if (!dev) { |
230 | if (!dev) { |
221 | printf("WUSBXX_stack_execute device not open\n"); |
231 | printf("WUSBXX_stack_execute device not open\n"); |
222 | return -1; |
232 | return -1; |
223 | } |
233 | } |
224 | uint16_t * exstack = (uint16_t *) wusbcc_stack; |
234 | uint16_t * exstack = (uint16_t *) wusbcc_stack; |
225 | exstack[0]=0; |
235 | exstack[0]=0; |
226 | nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] ); |
236 | nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] ); |
227 | //printf("WUSBXX_stack_execute stack size %d\n", nb); |
237 | //printf("WUSBXX_stack_execute stack size %d\n", nb); |
228 | //WIENER_VMUSB_StackPrint(); |
238 | //WIENER_VMUSB_StackPrint(); |
229 | nb = xxusb_longstack_execute (dev, exstack, nb, 1000); |
239 | nb = xxusb_longstack_execute (dev, exstack, nb, 1000); |
230 | //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0 |
240 | //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0 |
231 | //printf("WUSBXX_stack_execute return size %d\n", nb); |
241 | //printf("WUSBXX_stack_execute return size %d\n", nb); |
232 | if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
242 | if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
233 | if (stack!=NULL) for ( i=0; i<nb; i++) stack[i]=wusbcc_stack[i]; |
243 | if (stack!=NULL) for ( i=0; i<nb; i++) stack[i]=wusbcc_stack[i]; |
234 | return nb/sizeof(uint32_t); |
244 | return nb/sizeof(uint32_t); |
235 | } |
245 | } |
236 | 246 | ||
237 | 247 | ||
238 | 248 | ||
239 | #ifndef VME_D32 |
249 | #ifndef VME_D32 |
240 | 250 | ||
241 | #define VME_D8 0x1 |
251 | #define VME_D8 0x1 |
242 | #define VME_D16 0x2 |
252 | #define VME_D16 0x2 |
243 | #define VME_D32 0x4 |
253 | #define VME_D32 0x4 |
244 | #endif |
254 | #endif |
245 | 255 | ||
246 | 256 | ||
247 | short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) { |
257 | short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) { |
248 | int nb=0; |
258 | int nb=0; |
249 | if (!WUSB_udev) return -222; |
259 | if (!WUSB_udev) return -222; |
250 | 260 | ||
251 | switch (DW) { |
261 | switch (DW) { |
252 | case VME_D16: |
262 | case VME_D16: |
253 | nb= VME_read_16(WUSB_udev, AM,VME_Address,(long int *) Data); |
263 | nb= VME_read_16(WUSB_udev, AM,VME_Address,(long int *) Data); |
254 | break; |
264 | break; |
255 | case VME_D32: |
265 | case VME_D32: |
256 | nb= VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data); |
266 | nb= VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data); |
257 | break; |
267 | break; |
258 | default: |
268 | default: |
259 | return 0; |
269 | return 0; |
260 | } |
270 | } |
261 | //printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data); |
271 | //printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data); |
262 | if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
272 | if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
263 | 273 | ||
264 | return (short)nb; |
274 | return (short)nb; |
265 | } |
275 | } |
266 | 276 | ||
267 | short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) { |
277 | short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) { |
268 | int nb=0; |
278 | int nb=0; |
269 | if (!WUSB_udev) return -222; |
279 | if (!WUSB_udev) return -222; |
270 | // printf("W 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, Data); |
280 | // printf("W 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, Data); |
271 | switch (DW) { |
281 | switch (DW) { |
272 | case VME_D16: |
282 | case VME_D16: |
273 | nb= VME_write_16(WUSB_udev, AM,VME_Address,Data); |
283 | nb= VME_write_16(WUSB_udev, AM,VME_Address,Data); |
274 | break; |
284 | break; |
275 | case VME_D32: |
285 | case VME_D32: |
276 | nb= VME_write_32(WUSB_udev, AM,VME_Address,Data); |
286 | nb= VME_write_32(WUSB_udev, AM,VME_Address,Data); |
277 | break; |
287 | break; |
278 | default: |
288 | default: |
279 | return 0; |
289 | return 0; |
280 | } |
290 | } |
281 | if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
291 | if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) ); |
282 | 292 | ||
283 | return (short)nb; |
293 | return (short)nb; |
284 | } |
294 | } |
285 | 295 | ||
286 | short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) { |
296 | short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) { |
287 | switch (DW) { |
297 | switch (DW) { |
288 | case VME_D16: |
298 | case VME_D16: |
289 | return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D16 , Data); |
299 | return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D16 , Data); |
290 | case VME_D32: |
300 | case VME_D32: |
291 | return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D32 , Data); |
301 | return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D32 , Data); |
292 | default: |
302 | default: |
293 | return 0; |
303 | return 0; |
294 | } |
304 | } |
295 | return 0; |
305 | return 0; |
296 | } |
306 | } |
297 | short __stdcall WIENER_VMUSB_VME_MWRST( void ) { |
307 | short __stdcall WIENER_VMUSB_VME_MWRST( void ) { |
298 | WIENER_VMUSB_StackInit(); |
308 | WIENER_VMUSB_StackInit(); |
299 | return 0; |
309 | return 0; |
300 | } |
310 | } |
301 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ) { |
311 | short __stdcall WIENER_VMUSB_VME_MWEXEC( void ) { |
302 | return (short) WUSBXX_stack_execute (WUSB_udev, NULL); |
312 | return (short) WUSBXX_stack_execute (WUSB_udev, NULL); |
303 | } |
313 | } |
304 | 314 | ||
305 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) { |
315 | short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) { |
306 | switch (DW) { |
316 | switch (DW) { |
307 | case VME_D16: |
317 | case VME_D16: |
308 | return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 ); |
318 | return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 ); |
309 | case VME_D32: |
319 | case VME_D32: |
310 | return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 ); |
320 | return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 ); |
311 | default: |
321 | default: |
312 | return 0; |
322 | return 0; |
313 | } |
323 | } |
314 | return 0; |
324 | return 0; |
315 | } |
325 | } |
316 | short __stdcall WIENER_VMUSB_VME_MRRST( void ) { |
326 | short __stdcall WIENER_VMUSB_VME_MRRST( void ) { |
317 | WIENER_VMUSB_StackInit(); |
327 | WIENER_VMUSB_StackInit(); |
318 | return 0; |
328 | return 0; |
319 | } |
329 | } |
320 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ) { |
330 | short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ) { |
321 | return (short) WUSBXX_stack_execute (WUSB_udev,(char *) Data); |
331 | return (short) WUSBXX_stack_execute (WUSB_udev,(char *) Data); |
322 | } |
332 | } |
323 | 333 |