Rev 92 | Rev 125 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 92 | Rev 100 | ||
|---|---|---|---|
| Line -... | Line 1... | ||
| - | 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 | return; |
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); |
| Line 42... | Line 103... | ||
| 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); |
| Line 187... | Line 248... | ||
| 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 | ||