Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 125 → Rev 124

/cvi/instr/WUSBVME_DLL/wusbvme_dll.c
65,7 → 65,8
short __stdcall VME_write_32(usb_dev_handle *hdev, short Address_Modifier, long VME_Address, long Data);
 
 
void _VI_FUNC WIENER_VMUSB_load (const char* module_path) {
void _VI_FUNC WIENER_VMUSB_load (const char* module_path)
{
if (module_path == NULL) {
DLLHandle = LoadLibrary("libxxusb.dll");
} else {
72,8 → 73,8
DLLHandle = LoadLibrary(module_path);
}
if (!DLLHandle) {
printf ("\n\nFailed to Open libxxusb.dll \n");
return;
printf ("\n\nFailed to Open libxxusb.dll \n");
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);
104,18 → 105,19
if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) exit(1);
}
 
void _VI_FUNC WIENER_VMUSB_open (const char *serial) {
 
void _VI_FUNC WIENER_VMUSB_open (const char *serial)
{
xxusb_device_type devices[100];
struct usb_device *dev;
if (serial != NULL)
WUSB_udev = xxusb_serial_open((char *) serial);
WUSB_udev = xxusb_serial_open((char *) serial);
else {
//Find XX_USB devices and open the first one found
//Find XX_USB devices and open the first one found
xxusb_devices_find(devices);
dev = devices[0].usbdev;
WUSB_udev = xxusb_device_open(dev);
}
WUSB_udev = xxusb_device_open(dev);
}
// Make sure VM_USB opened OK
if(!WUSB_udev) {
printf ("\n\nFailed to Open VM_USB \n\n");
122,51 → 124,50
return ;
} else {
printf("VM-USB Device open.!\n");
}
 
 
}
}
 
void _VI_FUNC WIENER_VMUSB_close (void) {
void _VI_FUNC WIENER_VMUSB_close (void)
{
if (WUSB_udev) xxusb_device_close(WUSB_udev);
}
 
 
uint32_t fStack[MAXSTACKSIZE];
uint32_t fStackSize;
uint32_t fStackSize;
 
int WIENER_VMUSB_StackInit() {
fStack[0]=1;
fStackSize=1;
return fStack[0];
int WIENER_VMUSB_StackInit(){
fStack[0]=1;
fStackSize=1;
return fStack[0];
}
 
void WIENER_VMUSB_StackClear() {
WIENER_VMUSB_StackInit();
void WIENER_VMUSB_StackClear(){
WIENER_VMUSB_StackInit();
}
 
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack) {
int WIENER_VMUSB_StackGetUInt16(int maxn, uint16_t *stack){
int i;
uint16_t * u16Stack = (uint16_t *) fStack;
for (i=0; i< fStackSize*2; i++) {
if (i<maxn) stack[i]=u16Stack[i];
else return -1;
uint16_t * u16Stack = (uint16_t *) fStack;
for (i=0;i< fStackSize*2;i++){
if (i<maxn) stack[i]=u16Stack[i]; else return -1;
}
return fStackSize*2;
}
 
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack) {
int WIENER_VMUSB_StackGetUInt32(int maxn, uint32_t *stack){
int i;
uint16_t * u16Stack = (uint16_t *) fStack;
for (i=0; i< fStackSize*2; i++) {
if (i<maxn) stack[i]=u16Stack[i];
else return -1;
for (i=0;i< fStackSize*2;i++){
if (i<maxn) stack[i]=u16Stack[i]; else return -1;
}
return fStackSize*2;
}
 
 
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ) {
int WIENER_VMUSB_StackAppend(int cmd, uint32_t addr ){
if (fStackSize+2 >= MAXSTACKSIZE) {
fprintf(stderr,"WIENER_VMUSB_StackAppend Maximum stack size reached! Increase....%d\n", fStackSize+2);
return -1;
177,10 → 178,10
return fStack[0];
}
 
int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data) {
 
int WIENER_VMUSB_StackAppendData(int cmd,uint32_t addr ,uint32_t data){
WIENER_VMUSB_StackAppend( cmd, addr );
 
if (fStackSize+1 >= MAXSTACKSIZE) {
fprintf(stderr,"WIENER_VMUSB_StackAppendData Maximum stack size reached! Increase....%d\n", fStackSize+1);
return -1;
190,25 → 191,25
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_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_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_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() {
uint16_t * u16Stack = (uint16_t *) fStack;
uint32_t i;
for (i=0; i < fStackSize*2; i++) printf("0x%04x\n",u16Stack[i]);
printf("size of stack %d __________________________________\n",fStackSize*2-1);
void WIENER_VMUSB_StackPrint(){
uint16_t * u16Stack = (uint16_t *) fStack;
uint32_t i;
for (i=0; i < fStackSize*2;i++) printf("0x%04x\n",u16Stack[i]);
printf("size of stack %d __________________________________\n",fStackSize*2-1);
}
 
 
215,12 → 216,12
char wusbcc_stack[MAXSTACKSIZE*4];
 
 
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack) {
int _VI_FUNC WUSBXX_stack_execute (usb_dev_handle * dev, char * stack){
int i, nb=0;
if (!dev) {
printf("WUSBXX_stack_execute device not open\n");
printf("WUSBXX_stack_execute device not open\n");
return -1;
}
}
uint16_t * exstack = (uint16_t *) wusbcc_stack;
exstack[0]=0;
nb = WIENER_VMUSB_StackGetUInt16(MAXSTACKSIZE, &exstack[1] );
228,9 → 229,9
//WIENER_VMUSB_StackPrint();
nb = xxusb_longstack_execute (dev, exstack, nb, 1000);
//DataBuffer(0 - (ReturnValue/2-1)) - (unsigned short)array of returned data when ReturnValue>0
//printf("WUSBXX_stack_execute return size %d\n", nb);
//printf("WUSBXX_stack_execute return size %d\n", nb);
if (nb<0 ) printf("xxusb_longstack_execute %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];
if (stack!=NULL) for ( i=0;i<nb;i++) stack[i]=wusbcc_stack[i];
return nb/sizeof(uint32_t);
}
 
244,79 → 245,63
#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,(long int *) Data);
break;
case VME_D32:
nb= VME_read_32(WUSB_udev, AM,VME_Address,(long int *)Data);
break;
default:
return 0;
}
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,(long int *) Data); break;
case VME_D32: nb= VME_read_32(WUSB_udev, AM,VME_Address,(long int *)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) );
if (nb<0) printf("%s %d %d %s\n",__FILE__,__LINE__,nb, strerror(-nb) );
 
return 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) );
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;
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_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_MWRST( void ){
WIENER_VMUSB_StackInit();
return 0;
}
short __stdcall WIENER_VMUSB_VME_MWEXEC( void ) {
return WUSBXX_stack_execute (WUSB_udev, NULL);
short __stdcall WIENER_VMUSB_VME_MWEXEC( void ){
return WUSBXX_stack_execute (WUSB_udev, NULL);
}
 
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_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 );
case VME_D32:
return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 );
default:
return 0;
}
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_StackAppend(CMD_READ | AM , VME_Address | CMD_D16 );
case VME_D32: return (short) WIENER_VMUSB_StackAppend(CMD_READ | AM , VME_Address | CMD_D32 );
default: return 0;
}
return 0;
}
short __stdcall WIENER_VMUSB_VME_MRRST( void ) {
WIENER_VMUSB_StackInit();
return 0;
short __stdcall WIENER_VMUSB_VME_MRRST( void ){
WIENER_VMUSB_StackInit();
return 0;
}
short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ) {
return WUSBXX_stack_execute (WUSB_udev,(char *) Data);
short __stdcall WIENER_VMUSB_VME_MREXEC( uint32_t *Data ){
return WUSBXX_stack_execute (WUSB_udev,(char *) Data);
}