Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
62 | f9daq | 1 | |
2 | #include <stdio.h> |
||
3 | #include "VmUsbStack_cvi.h" |
||
4 | |||
5 | #define MAXSTACKSIZE 1000 |
||
6 | long fStack[MAXSTACKSIZE]; |
||
7 | |||
8 | |||
9 | void VmUsbStackInit(){ |
||
10 | fStack[0]=1; |
||
11 | fStack[1]=0; |
||
12 | } |
||
13 | |||
14 | void VmUsbStackClear(){ |
||
15 | VmUsbStackInit(); |
||
16 | } |
||
17 | |||
18 | int VmUsbStackGet(int maxn, int *stack){ |
||
19 | int i; |
||
20 | for (i=0;i< fStack[0]+1;i++){ |
||
21 | if (i<maxn) stack[i]=fStack[i]; else return -1; |
||
22 | } |
||
23 | return fStack[0]; |
||
24 | } |
||
25 | |||
26 | |||
27 | void VmUsbStackAppend(int cmd, int addr ){ |
||
28 | int i= fStack[0]+1; |
||
29 | fStack[i] = (cmd & 0xFFFF); |
||
30 | fStack[i+1] = (cmd >> 16); |
||
31 | fStack[i+2] = addr&0xFFFF; |
||
32 | fStack[i+3] = (addr >> 16)& 0xFFFF; |
||
33 | fStack[0]+=4; |
||
34 | } |
||
35 | |||
36 | void VmUsbStackAppendData(int cmd, int addr , int data){ |
||
37 | int i=0; |
||
38 | VmUsbStackAppend( cmd, addr ); |
||
39 | i = fStack[0]+1; |
||
40 | fStack[i] = data & 0xFFFF; |
||
41 | fStack[i+1] = (data >> 16)&0xFFFF; |
||
42 | fStack[0]+=2; |
||
43 | } |
||
44 | |||
45 | void VmUsbStackConditionalRead(int adr_mod,int d16d32, int addr, int bmask){ |
||
46 | VmUsbStackAppend(CMD_READ| CMD_HD | adr_mod ,addr); |
||
47 | VmUsbStackAppendData(CMD_READ| CMD_HD | CMD_HM |adr_mod, d16d32 |addr,bmask); |
||
48 | } |
||
49 | |||
50 | void VmUsbStackMultiRead(int adr_mod,int d16d32, int baseaddr, int n, int increment){ |
||
51 | int i; |
||
52 | for (i=0;i<n;i++) VmUsbStackAppend( adr_mod | CMD_READ, d16d32 +baseaddr + i*increment); |
||
53 | } |
||
54 | void VmUsbStackMultiWrite(int adr_mod,int d16d32,int baseaddr, int n, int increment, int data){ |
||
55 | int i; |
||
56 | for (i=0;i<n;i++) VmUsbStackAppendData( adr_mod | CMD_WRITE,d16d32 + baseaddr+i*increment, data); |
||
57 | } |
||
58 | |||
59 | void VmUsbStackPrint(){ |
||
60 | int i; |
||
61 | for (i=0; i < fStack[0]+1;i++) printf("0x%04x\n",fStack[i]); |
||
62 | printf("size of stack %d __________________________________\n",fStack[0]+1); |
||
63 | } |
||
64 | |||
65 | #ifdef MAIN |
||
66 | #include "CAENV965_DEF.h" |
||
67 | #include <utility.h> |
||
68 | #define CAEN_V965 0x340000 |
||
69 | |||
70 | int main(){ |
||
71 | |||
72 | int st[1000]; |
||
73 | int nb, i; |
||
74 | // INIT stackdata |
||
75 | int geo=1,fPedestal=255; |
||
76 | VmUsbStackInit(); |
||
77 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_CRN, 0x0); |
||
78 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_GEO, geo); |
||
79 | VmUsbStackMultiWrite( CMD_A24, CMD_D32, CAEN_V965 + CAENV965_THM, 32, 0x02,0x0); // threshold/kill for 32 channels, 2*i addr increment |
||
80 | VmUsbStackWriteA24D32( CAEN_V965 + CAENV965_BS1, 0x80 ); // soft reset |
||
81 | VmUsbStackWriteA24D32( CAEN_V965 + CAENV965_BC1, 0x80 ); // soft reset |
||
82 | VmUsbStackWriteA24D32( CAEN_V965 + CAENV965_PED, fPedestal ); // pedestal |
||
83 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_BS2,0x5000); |
||
84 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_BS2,0x4); // clear module |
||
85 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_BC2,0x4); |
||
86 | VmUsbStackPrint(); |
||
87 | |||
88 | // READOUT stackdata |
||
89 | VmUsbStackInit(); |
||
90 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_BS2,0x4); // clear module |
||
91 | VmUsbStackWriteA24D32(CAEN_V965 + CAENV965_BC2,0x4); |
||
92 | VmUsbStackConditionalRead(CMD_A24, CMD_D32,CAEN_V965 + CAENV965_SR1,0x1); // TRG wait : loop until bit 0 is on |
||
93 | VmUsbStackConditionalRead(CMD_A24, CMD_D32,CAEN_V965 + CAENV965_OB ,0x4000000) ; // loop until bit 26 is on, read data |
||
94 | VmUsbStackMarker(0xFAFB); |
||
95 | VmUsbStackPrint(); |
||
96 | |||
97 | |||
98 | nb= VmUsbStackGet(1000,st); |
||
99 | 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] ); |
||
100 | Delay(10); |
||
101 | return 0; |
||
102 | } |
||
103 | #endif |