Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 80 → Rev 82

/cvi/instr/WUSBVME_DLL/wusbvme_dll.c
1,19 → 1,23
#include "wusbvme_dll.h"
 
usb_dev_handle *udev;
 
usb_dev_handle *WUSB_udev;
 
static HINSTANCE DLLHandle;
 
void _VI_FUNC WUSBVME_load (char* module_path)
void _VI_FUNC WIENER_VMUSB_load (char* module_path)
{
if (module_path == NULL)
DLLHandle = LoadLibrary("libxxusb.dll");
else
DLLHandle = LoadLibrary(module_path);
if (!DLLHandle) return;
if (!(xxusb_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_read"))) exit(1);
if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) exit(1);
if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) exit(1);
if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) exit(1);
if (!(xxusb_longstack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_longstack_execute"))) exit(1);
if (!(xxusb_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_write"))) exit(1);
if (!(xxusb_usbfifo_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_usbfifo_read"))) exit(1);
if (!(xxusb_bulk_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_read"))) exit(1);
38,13 → 42,203
if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1);
}
 
void _VI_FUNC WUSBVME_open (char *serial)
void _VI_FUNC WIENER_VMUSB_open (char *serial)
{
xxusb_device_type devices[100];
struct usb_device *dev;
if (serial != NULL)
udev = xxusb_serial_open(serial);
WUSB_udev = xxusb_serial_open(serial);
else {
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
WUSB_udev = xxusb_device_open(dev);
}
// Make sure VM_USB opened OK
if(!WUSB_udev) {
printf ("\n\nFailed to Open VM_USB \n\n");
return ;
} else {
printf("VM-USB Device open.!\n");
}
}
 
void _VI_FUNC WUSBVME_close (void)
void _VI_FUNC WIENER_VMUSB_close (void)
{
if (udev) xxusb_device_close(udev);
if (WUSB_udev) xxusb_device_close(WUSB_udev);
}
 
 
uint16_t fStack[MAXSTACKSIZE];
 
 
int WIENER_VMUSB_StackInit(){
fStack[0]=1;
fStack[1]=0;
return fStack[0];
}
 
void WIENER_VMUSB_StackClear(){
WIENER_VMUSB_StackInit();
}
 
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack){
int i;
for (i=0;i< fStack[0]+1;i++){
if (i<maxn) stack[i]=fStack[i]; else return -1;
}
return fStack[0]+1;
}
 
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack){
int i;
for (i=0;i< fStack[0]+1;i++){
if (i<maxn) stack[i]=fStack[i]; else return -1;
}
return fStack[0]+1;
}
 
 
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ){
int i= fStack[0]+1;
if (i+4 >= MAXSTACKSIZE) {
fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", i+4);
return -1;
}
fStack[i] = (cmd & 0xFFFF);
fStack[i+1] = (cmd >> 16);
fStack[i+2] = addr&0xFFFF;
fStack[i+3] = (addr >> 16)& 0xFFFF;
fStack[0]+=4;
return fStack[0];
}
 
int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data){
int i=0;
WIENER_VMUSB_StackAppend( cmd, addr );
i = fStack[0]+1;
if (i+2 >= MAXSTACKSIZE) {
fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", i+4);
return -1;
}
fStack[i] = data & 0xFFFF;
fStack[i+1] = (data >> 16)&0xFFFF;
fStack[0]+=2;
return fStack[0];
}
 
void WIENER_VMUSB_StackConditionalRead(int adr_mod,int d16d32, uint32_t addr,uint32_t bmask){
WIENER_VMUSB_StackAppend(CMD_READ| CMD_HD | adr_mod ,addr);
WIENER_VMUSB_StackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask);
}
 
void WIENER_VMUSB_StackMultiRead(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment){
int i;
for (i=0;i<n;i++) WIENER_VMUSB_StackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment);
}
void WIENER_VMUSB_StackMultiWrite(int adr_mod,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data){
int i;
for (i=0;i<n;i++) WIENER_VMUSB_StackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data);
}
 
void WIENER_VMUSB_StackPrint(){
uint32_t i;
for (i=0; i < fStack[0]+1;i++) printf("0x%04x\n",fStack[i]);
printf("size of stack %d __________________________________\n",fStack[0]+1);
}
 
 
char wusbcc_stack[MAXSTACKSIZE*4];
 
 
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack){
int i, nb=0;
if (!dev) return -1;
uint16_t * exstack = (uint16_t *) wusbcc_stack;
exstack[0]=0;
nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] );
//printf("WUSBXX_stack_execute stack size %d ", nb);
//WIENER_VMUSB_StackPrint();
nb = xxusb_longstack_execute (dev, exstack, nb, 1000);
 
if (nb<0 ) printf("%s line:%d err=%d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
if (stack!=NULL) for ( i=0;i<nb;i++) stack[i]=wusbcc_stack[i];
return nb/sizeof(uint32_t);
}
 
 
 
#ifndef VME_D32
 
#define VME_D8 0x1
#define VME_D16 0x2
#define VME_D32 0x4
#endif
 
 
short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){
int nb=0;
if (!WUSB_udev) return -222;
switch (DW){
case VME_D16: nb= VME_read_16(WUSB_udev, AM,VME_Address,Data); break;
case VME_D32: nb= VME_read_32(WUSB_udev, AM,VME_Address,Data); break;
default: return 0;
}
//printf("R 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, *Data);
if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
 
return nb;
}
 
short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
int nb=0;
if (!WUSB_udev) return -222;
// printf("W 0x%02x 0x%02x 0x%08x %x\n", AM , DW, VME_Address, Data);
switch (DW){
case VME_D16: nb= VME_write_16(WUSB_udev, AM,VME_Address,Data); break;
case VME_D32: nb= VME_write_32(WUSB_udev, AM,VME_Address,Data); break;
default: return 0;
}
if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
 
return nb;
}
 
short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){
switch (DW){
case VME_D16: return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D16 , Data);
case VME_D32: return (short) WIENER_VMUSB_StackAppendData(CMD_WRITE | AM , VME_Address | CMD_D32 , Data);
default: return 0;
}
return 0;
}
short __stdcall WIENER_VMUSB_VME_MWRST( void ){
WIENER_VMUSB_StackInit();
return 0;
}
short __stdcall WIENER_VMUSB_VME_MWEXEC( void ){
WUSBXX_stack_execute (WUSB_udev, NULL);
return 0;
}
 
short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){
switch (DW){
case VME_D16: return (short) WIENER_VMUSB_StackAppendData(CMD_READ | AM , VME_Address | CMD_D16 , *Data);
case VME_D32: return (short) WIENER_VMUSB_StackAppendData(CMD_READ | AM , VME_Address | CMD_D32 , *Data);
default: return 0;
}
return 0;
}
short __stdcall WIENER_VMUSB_VME_MRRST( void ){
WIENER_VMUSB_StackInit();
return 0;
}
short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ){
WUSBXX_stack_execute (WUSB_udev,(char *) Data);
return 0;
}
/cvi/instr/WUSBVME_DLL/wusbvme_dll.h
9,27 → 9,83
#include "usb.h"
#include "xxusb_dll.h"
 
extern usb_dev_handle *udev;
 
void _VI_FUNC WUSBVME_load (char *module_path);
void _VI_FUNC WUSBVME_open (char *serial);
void _VI_FUNC WUSBVME_close (void);
#define CMD_WRITE 0x000
#define CMD_READ 0x100
#define CMD_A24 0x039
#define CMD_A32 0x009
#define CMD_HM 0x80000
#define CMD_HD 0x20000
#define CMD_MRK 0x2000
#define CMD_DLY 0x8000
#define CMD_BLT 0xFF000000
 
#define VME_START(NODE) WUSBVME_load(NULL);WUSBVME_open((NODE));
#define VME_STOP() WUSBVME_close()
#define CMD_D16 1
#define CMD_D32 0
 
 
#define MAXSTACKSIZE 100000
 
int WIENER_VMUSB_StackInit();
void WIENER_VMUSB_StackClear();
 
 
#define WIENER_VMUSB_StackReadA24D16( ADDR, DATA ) WIENER_VMUSB_StackAppend(CMD_READ | CMD_A24 , CMD_D16 | (ADDR) )
#define WIENER_VMUSB_StackReadA24D32( ADDR, DATA ) WIENER_VMUSB_StackAppend(CMD_READ | CMD_A24 , CMD_D32 | (ADDR) )
#define WIENER_VMUSB_StackReadA32D16( ADDR, DATA ) WIENER_VMUSB_StackAppend(CMD_READ | CMD_A32 , CMD_D16 | (ADDR) )
#define WIENER_VMUSB_StackReadA32D32( ADDR, DATA ) WIENER_VMUSB_StackAppend(CMD_READ | CMD_A32 , CMD_D32 | (ADDR) )
 
#define WIENER_VMUSB_StackWriteA24D16( ADDR, DATA) WIENER_VMUSB_StackAppendData(CMD_WRITE | CMD_A24,CMD_D16 | (ADDR), (DATA))
#define WIENER_VMUSB_StackWriteA24D32( ADDR, DATA) WIENER_VMUSB_StackAppendData(CMD_WRITE | CMD_A24,CMD_D32 | (ADDR), (DATA))
#define WIENER_VMUSB_StackWriteA32D16( ADDR, DATA) WIENER_VMUSB_StackAppendData(CMD_WRITE | CMD_A32,CMD_D16 | (ADDR), (DATA))
#define WIENER_VMUSB_StackWriteA32D32( ADDR, DATA) WIENER_VMUSB_StackAppendData(CMD_WRITE | CMD_A32,CMD_D32 | (ADDR), (DATA))
 
#define WIENER_VMUSB_StackMarker(MRK) WIENER_VMUSB_StackAppend(CMD_MRK, (MRK))
 
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr);
int WIENER_VMUSB_StackAppendData(int cmd, uint32_t addr, uint32_t data);
 
void WIENER_VMUSB_StackConditionalRead(int am ,int d16d32,uint32_t addr, uint32_t data);
void WIENER_VMUSB_StackMultiRead(int addr_modifier,int d16d32, uint32_t baseaddr, int n,uint32_t increment);
void WIENER_VMUSB_StackMultiWrite(int addr_modifier,int d16d32,uint32_t baseaddr, int n, uint32_t increment, uint32_t data);
 
int WIENER_VMUSB_StackGetUint32(int maxn, uint32_t *stack);
int WIENER_VMUSB_StackGetUint16(int maxn, uint16_t *stack);
void WIENER_VMUSB_StackPrint();
 
 
void _VI_FUNC WIENER_VMUSB_load (char *module_path);
void _VI_FUNC WIENER_VMUSB_open (char *serial);
void _VI_FUNC WIENER_VMUSB_close (void);
 
#define WIENER_VMUSB_VME_START(NODE) WIENER_VMUSB_load(NULL);WIENER_VMUSB_open((NODE));
#define WIENER_VMUSB_VME_STOP() WIENER_VMUSB_close()
//#define VME_RESET() WIENVME_reset()
//#define VME_A24D8_R(VME,DATA) WIENVME_read8(hHandle24, 1, (VME), (DATA))
#define VME_A24D16_R(VME,DATA) VME_read_16(udev, Std_NoPriv_Data, (VME), (DATA))
#define VME_A24D32_R(VME,DATA) VME_read_32(udev, Std_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A24D16_R(VME,DATA) VME_read_16(WUSB_udev, Std_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A24D32_R(VME,DATA) VME_read_32(WUSB_udev, Std_NoPriv_Data, (VME), (DATA))
//#define VME_A24D8_W(VME,DATA) WIENVME_write8(hHandle24, 1, (VME), (DATA))
#define VME_A24D16_W(VME,DATA) VME_write_16(udev, Std_NoPriv_Data, (VME), (DATA))
#define VME_A24D32_W(VME,DATA) VME_write_32(udev, Std_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A24D16_W(VME,DATA) VME_write_16(WUSB_udev, Std_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A24D32_W(VME,DATA) VME_write_32(WUSB_udev, Std_NoPriv_Data, (VME), (DATA))
//#define VME_A32D8_R(VME,DATA) WIENVME_read8(hHandle32, 1, (VME), (DATA))
#define VME_A32D16_R(VME,DATA) VME_read_16(udev, Ext_NoPriv_Data, (VME), (DATA))
#define VME_A32D32_R(VME,DATA) VME_read_32(udev, Ext_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A32D16_R(VME,DATA) VME_read_16(WUSB_udev, Ext_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A32D32_R(VME,DATA) VME_read_32(WUSB_udev, Ext_NoPriv_Data, (VME), (DATA))
//#define VME_A32D8_W(VME,DATA) WIENVME_write8(hHandle32, 1, (VME), (DATA))
#define VME_A32D16_W(VME,DATA) VME_write_16(udev, Ext_NoPriv_Data, (VME), (DATA))
#define VME_A32D32_W(VME,DATA) VME_write_32(udev, Ext_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A32D16_W(VME,DATA) VME_write_16(WUSB_udev, Ext_NoPriv_Data, (VME), (DATA))
#define WIENER_VMUSB_VME_A32D32_W(VME,DATA) VME_write_32(WUSB_udev, Ext_NoPriv_Data, (VME), (DATA))
 
 
short __stdcall WIENER_VMUSB_VME_R( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data);
 
short __stdcall WIENER_VMUSB_VME_W( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data);
 
short __stdcall WIENER_VMUSB_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data);
short __stdcall WIENER_VMUSB_VME_MWRST( void );
short __stdcall WIENER_VMUSB_VME_MWEXEC( void );
 
short __stdcall WIENER_VMUSB_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data);
short __stdcall WIENER_VMUSB_VME_MRRST( void );
short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data );
 
#endif
 
/cvi/instr/WUSBVME_DLL/xxusb_dll.h
29,6 → 29,7
#define xxusb_stack_read (*xxusb_stack_read_Ptr)
#define xxusb_stack_write (*xxusb_stack_write_Ptr)
#define xxusb_stack_execute (*xxusb_stack_execute_Ptr)
#define xxusb_longstack_execute (*xxusb_longstack_execute_Ptr)
#define xxusb_register_write (*xxusb_register_write_Ptr)
#define xxusb_usbfifo_read (*xxusb_usbfifo_read_Ptr)
#define xxusb_bulk_read (*xxusb_bulk_read_Ptr)
57,6 → 58,7
short __stdcall xxusb_stack_read(usb_dev_handle *hDev, short StackAddr, long *StackData);
short __stdcall xxusb_stack_write(usb_dev_handle *hDev, short StackAddr, long *StackData);
short __stdcall xxusb_stack_execute(usb_dev_handle *hDev, long *StackData);
short __stdcall xxusb_longstack_execute(usb_dev_handle *hDev, void *DataBuffer, int lDataLen, int timeout);
short __stdcall xxusb_register_write(usb_dev_handle *hDev, short RegAddr, long RegData);
short __stdcall xxusb_usbfifo_read(usb_dev_handle *hDev, long *DataBuffer, short lDataLen, int timeout);
short __stdcall xxusb_bulk_read(usb_dev_handle *hDev, char *DataBuffer, short lDataLen, int timeout);