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