Blame |
Last modification |
View Log
| RSS feed
#include <stdio.h>
#include "VmUsbStack_cvi.h"
#define MAXSTACKSIZE 1000
long fStack
[MAXSTACKSIZE
];
void VmUsbStackInit
(){
fStack
[0]=1;
fStack
[1]=0;
}
void VmUsbStackClear
(){
VmUsbStackInit
();
}
int VmUsbStackGet
(int maxn
, int *stack
){
int i
;
for (i
=0;i
< fStack
[0]+1;i
++){
if (i
<maxn
) stack
[i
]=fStack
[i
]; else return -1;
}
return fStack
[0];
}
void VmUsbStackAppend
(int cmd
, int addr
){
int i
= fStack
[0]+1;
fStack
[i
] = (cmd
& 0xFFFF);
fStack
[i
+1] = (cmd
>> 16);
fStack
[i
+2] = addr
&0xFFFF;
fStack
[i
+3] = (addr
>> 16)& 0xFFFF;
fStack
[0]+=4;
}
void VmUsbStackAppendData
(int cmd
, int addr
, int data
){
int i
=0;
VmUsbStackAppend
( cmd
, addr
);
i
= fStack
[0]+1;
fStack
[i
] = data
& 0xFFFF;
fStack
[i
+1] = (data
>> 16)&0xFFFF;
fStack
[0]+=2;
}
void VmUsbStackConditionalRead
(int adr_mod
,int d16d32
, int addr
, int bmask
){
VmUsbStackAppend
(CMD_READ
| CMD_HD
| adr_mod
,addr
);
VmUsbStackAppendData
(CMD_READ
| CMD_HD
| CMD_HM
|adr_mod
, d16d32
|addr
,bmask
);
}
void VmUsbStackMultiRead
(int adr_mod
,int d16d32
, int baseaddr
, int n
, int increment
){
int i
;
for (i
=0;i
<n
;i
++) VmUsbStackAppend
( adr_mod
| CMD_READ
, d16d32
+baseaddr
+ i
*increment
);
}
void VmUsbStackMultiWrite
(int adr_mod
,int d16d32
,int baseaddr
, int n
, int increment
, int data
){
int i
;
for (i
=0;i
<n
;i
++) VmUsbStackAppendData
( adr_mod
| CMD_WRITE
,d16d32
+ baseaddr
+i
*increment
, data
);
}
void VmUsbStackPrint
(){
int i
;
for (i
=0; i
< fStack
[0]+1;i
++) printf("0x%04x\n",fStack
[i
]);
printf("size of stack %d __________________________________\n",fStack
[0]+1);
}
#ifdef MAIN
#include "CAENV965_DEF.h"
#include <utility.h>
#define CAEN_V965 0x340000
int main
(){
int st
[1000];
int nb
, i
;
// INIT stackdata
int geo
=1,fPedestal
=255;
VmUsbStackInit
();
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_CRN
, 0x0);
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_GEO
, geo
);
VmUsbStackMultiWrite
( CMD_A24
, CMD_D32
, CAEN_V965
+ CAENV965_THM
, 32, 0x02,0x0); // threshold/kill for 32 channels, 2*i addr increment
VmUsbStackWriteA24D32
( CAEN_V965
+ CAENV965_BS1
, 0x80 ); // soft reset
VmUsbStackWriteA24D32
( CAEN_V965
+ CAENV965_BC1
, 0x80 ); // soft reset
VmUsbStackWriteA24D32
( CAEN_V965
+ CAENV965_PED
, fPedestal
); // pedestal
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_BS2
,0x5000);
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_BS2
,0x4); // clear module
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_BC2
,0x4);
VmUsbStackPrint
();
// READOUT stackdata
VmUsbStackInit
();
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_BS2
,0x4); // clear module
VmUsbStackWriteA24D32
(CAEN_V965
+ CAENV965_BC2
,0x4);
VmUsbStackConditionalRead
(CMD_A24
, CMD_D32
,CAEN_V965
+ CAENV965_SR1
,0x1); // TRG wait : loop until bit 0 is on
VmUsbStackConditionalRead
(CMD_A24
, CMD_D32
,CAEN_V965
+ CAENV965_OB
,0x4000000) ; // loop until bit 26 is on, read data
VmUsbStackMarker
(0xFAFB);
VmUsbStackPrint
();
nb
= VmUsbStackGet
(1000,st
);
for (i
=0;i
<nb
;i
++) if (st
[i
]!=fStack
[i
]) printf("error i=%d 0x%04x 0x%04x \n",i
,st
[i
],fStack
[i
] );
Delay
(10);
return 0;
}
#endif