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