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