Subversion Repositories f9daq

Rev

Rev 92 | Rev 125 | Go to most recent revision | Show entire file | Ignore 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 "wusbvme_dll.h"
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
   else
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);
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);
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 140... Line 201...
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);
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 VME_D32: nb=  VME_read_32(WUSB_udev, AM,VME_Address,Data); break;
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
}