Subversion Repositories f9daq

Rev

Rev 100 | Rev 136 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 100 Rev 125
Line 63... Line 63...
63
short __stdcall VME_BLT_read_32(usb_dev_handle *hdev, short Address_Modifier, int count, 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);
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);
65
short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
66
 
66
 
67
 
67
 
68
void _VI_FUNC WIENER_VMUSB_load (const char* module_path)
68
void _VI_FUNC WIENER_VMUSB_load (const char* module_path) {
69
{
-
 
70
  if (module_path == NULL) {
69
  if (module_path == NULL) {
71
    DLLHandle = LoadLibrary("libxxusb.dll");
70
    DLLHandle = LoadLibrary("libxxusb.dll");
72
  } else {
71
  } else {
73
    DLLHandle = LoadLibrary(module_path);
72
    DLLHandle = LoadLibrary(module_path);
74
  }
73
  }
75
  if (!DLLHandle) {
74
  if (!DLLHandle) {
76
       printf ("\n\nFailed to Open libxxusb.dll \n");  
75
    printf ("\n\nFailed to Open libxxusb.dll  \n");
77
       return;
76
    return;
78
  }
77
  }
79
  if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
78
  if (!(xxusb_register_read_Ptr = (void *) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
80
  if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
79
  if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
81
  if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
80
  if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
82
  if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
81
  if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
Line 103... Line 102...
103
  if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) exit(1);
102
  if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) exit(1);
104
  if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) exit(1);
103
  if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) exit(1);
105
  if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1);
104
  if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1);
106
}
105
}
107
 
106
 
108
void _VI_FUNC WIENER_VMUSB_open (const char *serial)
107
void _VI_FUNC WIENER_VMUSB_open (const char *serial) {
109
{
-
 
110
       
108
 
111
  xxusb_device_type devices[100];
109
  xxusb_device_type devices[100];
112
  struct usb_device *dev;
110
  struct usb_device *dev;
113
  if (serial != NULL)
111
  if (serial != NULL)
114
        WUSB_udev = xxusb_serial_open((char *) serial);
112
    WUSB_udev = xxusb_serial_open((char *) serial);
115
  else  {
113
  else  {
116
  //Find XX_USB devices and open the first one found
114
    //Find XX_USB devices and open the first one found
117
    xxusb_devices_find(devices);
115
    xxusb_devices_find(devices);
118
    dev = devices[0].usbdev;
116
    dev = devices[0].usbdev;
119
    WUSB_udev = xxusb_device_open(dev);
117
    WUSB_udev = xxusb_device_open(dev);
120
  }  
118
  }
121
  // Make sure VM_USB opened OK
119
  // Make sure VM_USB opened OK
122
  if(!WUSB_udev) {
120
  if(!WUSB_udev) {
123
    printf ("\n\nFailed to Open VM_USB \n\n");
121
    printf ("\n\nFailed to Open VM_USB \n\n");
124
    return ;
122
    return ;
125
  } else {
123
  } else {
126
    printf("VM-USB Device open.!\n");
124
    printf("VM-USB Device open.!\n");
127
  }  
-
 
128
 
-
 
129
 
125
  }
130
}
126
 
131
 
127
 
132
void _VI_FUNC WIENER_VMUSB_close (void)
-
 
133
{
-
 
134
  if (WUSB_udev) xxusb_device_close(WUSB_udev);
-
 
135
}
-
 
136
 
-
 
137
 
-
 
138
uint32_t fStack[MAXSTACKSIZE];
-
 
139
uint32_t fStackSize;
-
 
140
 
-
 
141
int WIENER_VMUSB_StackInit(){
-
 
142
        fStack[0]=1;
-
 
143
        fStackSize=1;
-
 
144
   return fStack[0];
-
 
145
}
-
 
146
 
-
 
147
void WIENER_VMUSB_StackClear(){
-
 
148
        WIENER_VMUSB_StackInit();
-
 
149
}
128
}
150
 
129
 
-
 
130
void _VI_FUNC WIENER_VMUSB_close (void) {
-
 
131
  if (WUSB_udev) xxusb_device_close(WUSB_udev);
-
 
132
}
-
 
133
 
-
 
134
 
-
 
135
uint32_t fStack[MAXSTACKSIZE];
-
 
136
uint32_t fStackSize;
-
 
137
 
-
 
138
int WIENER_VMUSB_StackInit() {
-
 
139
  fStack[0]=1;
-
 
140
  fStackSize=1;
-
 
141
  return fStack[0];
-
 
142
}
-
 
143
 
-
 
144
void WIENER_VMUSB_StackClear() {
-
 
145
  WIENER_VMUSB_StackInit();
-
 
146
}
-
 
147
 
151
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack){
148
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack) {
152
  int i;
149
  int i;
153
  uint16_t * u16Stack = (uint16_t *) fStack;
150
  uint16_t * u16Stack = (uint16_t *) fStack;
154
  for (i=0;i< fStackSize*2;i++){
151
  for (i=0; i< fStackSize*2; i++) {
155
                        if (i<maxn) stack[i]=u16Stack[i]; else return -1;
152
    if (i<maxn) stack[i]=u16Stack[i];
-
 
153
    else return -1;
156
  }
154
  }
157
  return fStackSize*2;
155
  return fStackSize*2;
158
}
156
}
159
 
157
 
160
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack){
158
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack) {
161
  int i;
159
  int i;
162
  uint16_t * u16Stack = (uint16_t *) fStack;
160
  uint16_t * u16Stack = (uint16_t *) fStack;
163
  for (i=0;i< fStackSize*2;i++){
161
  for (i=0; i< fStackSize*2; i++) {
164
                        if (i<maxn) stack[i]=u16Stack[i]; else return -1;
162
    if (i<maxn) stack[i]=u16Stack[i];
-
 
163
    else return -1;
165
  }
164
  }
166
  return fStackSize*2;
165
  return fStackSize*2;
167
}
166
}
168
 
167
 
169
 
168
 
170
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ){
169
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ) {
171
  if (fStackSize+2 >= MAXSTACKSIZE) {
170
  if (fStackSize+2 >= MAXSTACKSIZE) {
172
    fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2);
171
    fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2);
173
    return -1;
172
    return -1;
174
  }
173
  }
175
  fStack[fStackSize ++]   = cmd;
174
  fStack[fStackSize ++]   = cmd;
176
  fStack[fStackSize ++]   = addr;
175
  fStack[fStackSize ++]   = addr;
177
  fStack[0]+=4;
176
  fStack[0]+=4;
178
  return fStack[0];
177
  return fStack[0];
179
}
178
}
180
 
179
 
181
int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data){
180
int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data) {
182
       
181
 
183
  WIENER_VMUSB_StackAppend( cmd, addr );
182
  WIENER_VMUSB_StackAppend( cmd, addr );
184
 
183
 
185
  if (fStackSize+1 >= MAXSTACKSIZE) {
184
  if (fStackSize+1 >= MAXSTACKSIZE) {
186
    fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1);
185
    fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1);
187
    return -1;
186
    return -1;
188
  }
187
  }
189
  fStack[fStackSize++]  =  data;
188
  fStack[fStackSize++]  =  data;
190
  fStack[0]+=2;
189
  fStack[0]+=2;
191
  return fStack[0];
190
  return fStack[0];
192
}
191
}
193
 
192
 
194
void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask){
193
void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask) {
195
        WIENER_VMUSB_StackAppend(CMD_READ| CMD_HD | adr_mod ,addr);
194
  WIENER_VMUSB_StackAppend(CMD_READ| CMD_HD | adr_mod ,addr);
196
        WIENER_VMUSB_StackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask);
195
  WIENER_VMUSB_StackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask);
197
}
196
}
198
 
197
 
199
void WIENER_VMUSB_StackMultiRead(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment){
198
void WIENER_VMUSB_StackMultiRead(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment) {
200
        int i;
199
  int i;
201
        for (i=0;i<n;i++) WIENER_VMUSB_StackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment);
200
  for (i=0; i<n; i++) WIENER_VMUSB_StackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment);
202
}
201
}
203
void WIENER_VMUSB_StackMultiWrite(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data){
202
void WIENER_VMUSB_StackMultiWrite(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data) {
204
        int i;
203
  int i;
205
        for (i=0;i<n;i++)  WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data);
204
  for (i=0; i<n; i++)  WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data);
206
}
205
}
207
 
206
 
208
void WIENER_VMUSB_StackPrint(){
207
void WIENER_VMUSB_StackPrint() {
209
   uint16_t * u16Stack = (uint16_t *) fStack;  
208
  uint16_t * u16Stack = (uint16_t *) fStack;
210
   uint32_t i;
209
  uint32_t i;
211
   for (i=0; i < fStackSize*2;i++) printf("0x%04x\n",u16Stack[i]);
210
  for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]);
212
   printf("size of stack %d __________________________________\n",fStackSize*2-1);
211
  printf("size of stack %d __________________________________\n",fStackSize*2-1);
213
}
212
}
214
 
213
 
215
 
214
 
216
char wusbcc_stack[MAXSTACKSIZE*4];
215
char wusbcc_stack[MAXSTACKSIZE*4];
217
 
-
 
218
 
216
 
-
 
217
 
219
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack){
218
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) {
220
  int i, nb=0;
219
  int i, nb=0;
221
  if (!dev) {
220
  if (!dev) {
222
        printf("WUSBXX_stack_execute device not open\n");  
221
    printf("WUSBXX_stack_execute device not open\n");
223
    return -1;
222
    return -1;
224
  }      
223
  }
225
  uint16_t * exstack = (uint16_t *) wusbcc_stack;
224
  uint16_t * exstack = (uint16_t *) wusbcc_stack;
226
  exstack[0]=0;
225
  exstack[0]=0;
227
  nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] );
226
  nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] );
228
  //printf("WUSBXX_stack_execute stack size %d\n", nb);
227
  //printf("WUSBXX_stack_execute stack size %d\n", nb);
229
  //WIENER_VMUSB_StackPrint();
228
  //WIENER_VMUSB_StackPrint();
230
  nb = xxusb_longstack_execute (dev,  exstack, nb, 1000);
229
  nb = xxusb_longstack_execute (dev,  exstack, nb, 1000);
231
  //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0
230
  //DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0
232
  //printf("WUSBXX_stack_execute return size %d\n", nb);         
231
  //printf("WUSBXX_stack_execute return size %d\n", nb);
233
  if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
232
  if (nb<0 ) printf("xxusb_longstack_execute %s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
234
  if (stack!=NULL) for ( i=0;i<nb;i++) stack[i]=wusbcc_stack[i];
233
  if (stack!=NULL) for ( i=0; i<nb; i++) stack[i]=wusbcc_stack[i];
235
  return nb/sizeof(uint32_t);
234
  return nb/sizeof(uint32_t);
236
}
235
}
237
 
236
 
238
 
237
 
239
 
238
 
Line 243... Line 242...
243
#define VME_D16 0x2
242
#define VME_D16 0x2
244
#define VME_D32 0x4
243
#define VME_D32 0x4
245
#endif
244
#endif
246
 
245
 
247
 
246
 
248
short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW,  uint32_t VME_Address, uint32_t *Data){
247
short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW,  uint32_t VME_Address, uint32_t *Data) {
249
        int nb=0;
248
  int nb=0;
250
        if (!WUSB_udev) return -222;
249
  if (!WUSB_udev) return -222;
251
       
250
 
252
    switch (DW){
251
  switch (DW) {
-
 
252
    case VME_D16:
253
        case VME_D16: nb=  VME_read_16(WUSB_udev, AM,VME_Address,(long int *) Data);  break;
253
      nb=  VME_read_16(WUSB_udev, AM,VME_Address,(long int *) Data);
-
 
254
      break;
-
 
255
    case VME_D32:
254
        case VME_D32: nb=  VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data); break;
256
      nb=  VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data);
-
 
257
      break;
-
 
258
    default:
255
        default: return 0;
259
      return 0;
256
    }
260
  }
257
//printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data);
261
//printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data);
258
if (nb<0)  printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
262
  if (nb<0)  printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
259
 
263
 
260
return nb;
264
  return nb;
261
}
265
}
262
 
266
 
263
short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
267
short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) {
264
        int nb=0;
268
  int nb=0;
265
        if (!WUSB_udev) return -222;
269
  if (!WUSB_udev) return -222;
266
//      printf("W 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, Data);
270
//  printf("W 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, Data);
267
 switch (DW){
271
  switch (DW) {
-
 
272
    case VME_D16:
268
   case VME_D16: nb=    VME_write_16(WUSB_udev, AM,VME_Address,Data); break;
273
      nb=    VME_write_16(WUSB_udev, AM,VME_Address,Data);
-
 
274
      break;
-
 
275
    case VME_D32:
269
   case VME_D32: nb=    VME_write_32(WUSB_udev, AM,VME_Address,Data); break;
276
      nb=    VME_write_32(WUSB_udev, AM,VME_Address,Data);
-
 
277
      break;
-
 
278
    default:
270
   default: return 0;
279
      return 0;
271
}
280
  }
272
if (nb<0)  printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
281
  if (nb<0)  printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
273
 
282
 
274
return nb;
283
  return nb;
275
}
284
}
276
 
285
 
277
short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
286
short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) {
278
switch (DW){
287
  switch (DW) {
-
 
288
    case VME_D16:
279
   case VME_D16: return  (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D16 , Data);
289
      return  (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D16 , Data);
-
 
290
    case VME_D32:
280
   case VME_D32: return  (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D32 , Data);
291
      return  (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D32 , Data);
-
 
292
    default:
281
   default: return 0;
293
      return 0;
-
 
294
  }
-
 
295
  return 0;
282
}
296
}
-
 
297
short __stdcall WIENER_VMUSB_VME_MWRST( void ) {
-
 
298
  WIENER_VMUSB_StackInit();
283
return 0;
299
  return 0;
284
}
300
}
285
short __stdcall WIENER_VMUSB_VME_MWRST( void ){
-
 
286
  WIENER_VMUSB_StackInit();
-
 
287
return 0;
-
 
288
}
-
 
289
short __stdcall WIENER_VMUSB_VME_MWEXEC( void ){
301
short __stdcall WIENER_VMUSB_VME_MWEXEC( void ) {
290
 return WUSBXX_stack_execute (WUSB_udev, NULL);
302
  return WUSBXX_stack_execute (WUSB_udev, NULL);
291
}
303
}
292
 
304
 
293
short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){
305
short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) {
294
switch (DW){
306
  switch (DW) {
-
 
307
    case VME_D16:
295
   case VME_D16: return  (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 );
308
      return  (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 );
-
 
309
    case VME_D32:
296
   case VME_D32: return  (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 );
310
      return  (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 );
-
 
311
    default:
297
   default: return 0;
312
      return 0;
298
}
313
  }
299
return 0;      
314
  return 0;
300
}
315
}
301
short __stdcall WIENER_VMUSB_VME_MRRST( void ){
316
short __stdcall WIENER_VMUSB_VME_MRRST( void ) {
302
    WIENER_VMUSB_StackInit();
317
  WIENER_VMUSB_StackInit();
303
return 0;
318
  return 0;
304
}
319
}
305
short __stdcall WIENER_VMUSB_VME_MREXEC(  uint32_t *Data  ){
320
short __stdcall WIENER_VMUSB_VME_MREXEC(  uint32_t *Data  ) {
306
 return WUSBXX_stack_execute (WUSB_udev,(char *) Data);
321
  return WUSBXX_stack_execute (WUSB_udev,(char *) Data);
307
}
322
}