Rev 52 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 52 | Rev 69 | ||
---|---|---|---|
1 | 1 | ||
2 | #include <stdlib.h> |
2 | #include <stdlib.h> |
3 | #include <stdio.h> |
3 | #include <stdio.h> |
4 | #include <CAENVMElib.h> |
4 | #include <CAENVMElib.h> |
5 | #include <CAENVMElib.h> |
5 | #include <CAENVMElib.h> |
6 | #include <CAENVMEoslib.h> |
6 | #include <CAENVMEoslib.h> |
7 | #include <CAENVMEtypes.h> |
7 | #include <CAENVMEtypes.h> |
8 | 8 | ||
9 | 9 | ||
10 | int32_t udev; |
10 | int32_t udev; |
11 | 11 | ||
12 |
|
12 | int VMEerrors; |
13 | 13 | ||
14 | int VME_start (char* serial) |
14 | int VME_start (char* serial) |
15 | { |
15 | { |
16 | 16 | ||
17 | CVErrorCodes result = CAENVME_Init( cvV1718 , 0 , 0 , &udev); |
17 | CVErrorCodes result = CAENVME_Init( cvV1718 , 0 , 0 , &udev); |
18 | if (result != cvSuccess) { |
18 | if (result != cvSuccess) { |
19 | printf("CAEN1718 Init %s\n", CAENVME_DecodeError(result)); |
19 | printf("CAEN1718 Init %s\n", CAENVME_DecodeError(result)); |
20 | printf(" Check usb cable, usb udev permissions and restart! Exiting .....\n"); |
20 | printf(" Check usb cable, usb udev permissions and restart! Exiting .....\n"); |
21 | exit(-1); |
21 | exit(-1); |
22 | } |
22 | } |
23 | if (serial == NULL) serial = malloc(100*sizeof(char)); |
23 | if (serial == NULL) serial = malloc(100*sizeof(char)); |
24 | CAENVME_BoardFWRelease(udev, serial); |
24 | CAENVME_BoardFWRelease(udev, serial); |
25 | 25 | ||
26 | return result; |
26 | return result; |
27 | } |
27 | } |
28 | 28 | ||
29 | 29 | ||
30 | int VME_read(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
30 | int VME_read(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
31 | { |
31 | { |
32 | 32 | ||
33 | CVErrorCodes result; |
33 | CVErrorCodes result; |
34 | int ncount=0; |
34 | int ncount=0; |
35 | while (1){ |
35 | while (1){ |
36 | result = CAENVME_ReadCycle(Handle, Address, Data, AM, DW ); |
36 | result = CAENVME_ReadCycle(Handle, Address, Data, AM, DW ); |
37 | if (result !=cvSuccess ) { |
37 | if (result !=cvSuccess ) { |
38 | VMEerrors++; |
38 | VMEerrors++; |
39 | printf("%d CAENVME_ReadCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s\n", ncount,Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result)); |
39 | printf("%d CAENVME_ReadCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s\n", ncount,Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result)); |
40 | ncount++; |
40 | ncount++; |
41 | if (ncount==10) exit(result); |
41 | if (ncount==10) exit(result); |
42 | } else break; |
42 | } else break; |
43 | } |
43 | } |
44 | return result; |
44 | return result; |
45 | } |
45 | } |
46 | 46 | ||
47 | int VME_BltRead(long Handle, unsigned long Address, void *Data, int size, CVAddressModifier AM, CVDataWidth DW) |
47 | int VME_BltRead(long Handle, unsigned long Address, void *Data, int size, CVAddressModifier AM, CVDataWidth DW) |
48 | { |
48 | { |
49 | int count=0; |
49 | int count=0; |
50 | CVErrorCodes result; |
50 | CVErrorCodes result; |
51 | int ncount=0; |
51 | int ncount=0; |
52 | 52 | ||
53 | while (1){ |
53 | while (1){ |
54 | 54 | ||
55 | result = CAENVME_BLTReadCycle(Handle, Address, Data, size, AM, DW , &count); |
55 | result = CAENVME_BLTReadCycle(Handle, Address, Data, size, AM, DW , &count); |
56 | if (result !=cvSuccess ) { |
56 | if (result !=cvSuccess ) { |
57 | VMEerrors++; |
57 | VMEerrors++; |
58 | printf("%d CAENVME_BLTReadCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s count=%d\n", ncount,Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result),count); |
58 | printf("%d CAENVME_BLTReadCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s count=%d\n", ncount,Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result),count); |
59 | ncount++; |
59 | ncount++; |
60 | if (ncount==10) exit(result); |
60 | if (ncount==10) exit(result); |
61 | } else break; |
61 | } else break; |
62 | } |
62 | } |
63 | return count; |
63 | return count; |
64 | } |
64 | } |
65 | 65 | ||
66 | int VME_write(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
66 | int VME_write(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
67 | { |
67 | { |
68 | 68 | ||
69 | CVErrorCodes result; |
69 | CVErrorCodes result; |
70 | int ncount=0; |
70 | int ncount=0; |
71 | while (1){ |
71 | while (1){ |
72 | result = CAENVME_WriteCycle(Handle, Address, Data, AM, DW ); |
72 | result = CAENVME_WriteCycle(Handle, Address, Data, AM, DW ); |
73 | if (result !=cvSuccess ) { |
73 | if (result !=cvSuccess ) { |
74 | VMEerrors++; |
74 | VMEerrors++; |
75 | printf("CAENVME_WriteCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s\n", Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result)); |
75 | printf("CAENVME_WriteCycle at 0x%0lX failed! data=0x%0X AM= 0x%0X DW= 0x%0X err=%s\n", Address, *((uint32_t *) Data),AM,DW, CAENVME_DecodeError(result)); |
76 | if (ncount==10) exit(result); |
76 | if (ncount==10) exit(result); |
77 | } else break; |
77 | } else break; |
78 | } |
78 | } |
79 | return result; |
79 | return result; |
80 | } |
80 | } |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | uint32_t *WStackAddrs = NULL; |
85 | uint32_t *WStackAddrs = NULL; |
86 | uint32_t *WStackBuffer; |
86 | uint32_t *WStackBuffer; |
87 | int WStackNCycles; |
87 | int WStackNCycles; |
88 | int WStackMaxCycles=100000; |
88 | int WStackMaxCycles=100000; |
89 | CVAddressModifier *WStackAMs; |
89 | CVAddressModifier *WStackAMs; |
90 | CVDataWidth *WStackDWs; |
90 | CVDataWidth *WStackDWs; |
91 | CVErrorCodes *WStackECs; |
91 | CVErrorCodes *WStackECs; |
92 | 92 | ||
93 | 93 | ||
94 | uint32_t *RStackAddrs =NULL; |
94 | uint32_t *RStackAddrs =NULL; |
95 | int RStackNCycles; |
95 | int RStackNCycles; |
96 | int RStackMaxCycles=100000; |
96 | int RStackMaxCycles=100000; |
97 | CVAddressModifier *RStackAMs; |
97 | CVAddressModifier *RStackAMs; |
98 | CVDataWidth *RStackDWs; |
98 | CVDataWidth *RStackDWs; |
99 | CVErrorCodes *RStackECs; |
99 | CVErrorCodes *RStackECs; |
100 | 100 | ||
101 | 101 | ||
102 | 102 | ||
103 | int VME_appendread(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
103 | int VME_appendread(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
104 | if (RStackNCycles<RStackMaxCycles){ |
104 | if (RStackNCycles<RStackMaxCycles){ |
105 | RStackAddrs[RStackNCycles] = Address; |
105 | RStackAddrs[RStackNCycles] = Address; |
106 | RStackAMs[RStackNCycles] = AM; |
106 | RStackAMs[RStackNCycles] = AM; |
107 | RStackDWs[RStackNCycles] = DW; |
107 | RStackDWs[RStackNCycles] = DW; |
108 | //int i=RStackNCycles; |
108 | //int i=RStackNCycles; |
109 | //printf("AppendRead %d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X \n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i]); |
109 | //printf("AppendRead %d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X \n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i]); |
110 | RStackNCycles++; |
110 | RStackNCycles++; |
111 | } else { |
111 | } else { |
112 | printf("Increase DataBuffer RStackMaxCycles =%d\n", RStackMaxCycles); |
112 | printf("Increase DataBuffer RStackMaxCycles =%d\n", RStackMaxCycles); |
113 | } |
113 | } |
114 | return RStackNCycles; |
114 | return RStackNCycles; |
115 | } |
115 | } |
116 | 116 | ||
117 | int VME_appendwrite(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
117 | int VME_appendwrite(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
118 | if (WStackNCycles<WStackMaxCycles){ |
118 | if (WStackNCycles<WStackMaxCycles){ |
119 | WStackAddrs[WStackNCycles] = Address; |
119 | WStackAddrs[WStackNCycles] = Address; |
120 | WStackBuffer[WStackNCycles] = *((uint32_t *) Data); |
120 | WStackBuffer[WStackNCycles] = *((uint32_t *) Data); |
121 | WStackAMs[WStackNCycles] = AM; |
121 | WStackAMs[WStackNCycles] = AM; |
122 | WStackDWs[WStackNCycles] = DW; |
122 | WStackDWs[WStackNCycles] = DW; |
123 | WStackNCycles++; |
123 | WStackNCycles++; |
124 | } else { |
124 | } else { |
125 | printf("Increase DataBuffer WStackMaxCycles =%d\n", WStackMaxCycles); |
125 | printf("Increase DataBuffer WStackMaxCycles =%d\n", WStackMaxCycles); |
126 | } |
126 | } |
127 | return 0; |
127 | return 0; |
128 | } |
128 | } |
129 | 129 | ||
130 | int VME_MultiReadReset(){ |
130 | int VME_MultiReadReset(){ |
131 | RStackNCycles=0; |
131 | RStackNCycles=0; |
132 | if (RStackAddrs!=NULL) return 0; |
132 | if (RStackAddrs!=NULL) return 0; |
133 | RStackAddrs = (uint32_t *) malloc( RStackMaxCycles*sizeof(uint32_t)); |
133 | RStackAddrs = (uint32_t *) malloc( RStackMaxCycles*sizeof(uint32_t)); |
134 | 134 | ||
135 | RStackAMs = (CVAddressModifier *) malloc(RStackMaxCycles*sizeof(CVAddressModifier)); |
135 | RStackAMs = (CVAddressModifier *) malloc(RStackMaxCycles*sizeof(CVAddressModifier)); |
136 | RStackDWs = (CVDataWidth *) malloc(RStackMaxCycles*sizeof(CVDataWidth)); |
136 | RStackDWs = (CVDataWidth *) malloc(RStackMaxCycles*sizeof(CVDataWidth)); |
137 | RStackECs = (CVErrorCodes *) malloc(RStackMaxCycles*sizeof(CVErrorCodes)); |
137 | RStackECs = (CVErrorCodes *) malloc(RStackMaxCycles*sizeof(CVErrorCodes)); |
138 | 138 | ||
139 | return 0; |
139 | return 0; |
140 | } |
140 | } |
141 | 141 | ||
142 | int VME_MultiWriteReset(){ |
142 | int VME_MultiWriteReset(){ |
143 | WStackNCycles=0; |
143 | WStackNCycles=0; |
144 | if (WStackAddrs!=NULL) return 0; |
144 | if (WStackAddrs!=NULL) return 0; |
145 | WStackBuffer = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
145 | WStackBuffer = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
146 | WStackAddrs = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
146 | WStackAddrs = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
147 | WStackAMs = (CVAddressModifier *) malloc(WStackMaxCycles*sizeof(CVAddressModifier)); |
147 | WStackAMs = (CVAddressModifier *) malloc(WStackMaxCycles*sizeof(CVAddressModifier)); |
148 | WStackDWs = (CVDataWidth *) malloc(WStackMaxCycles*sizeof(CVDataWidth)); |
148 | WStackDWs = (CVDataWidth *) malloc(WStackMaxCycles*sizeof(CVDataWidth)); |
149 | WStackECs = (CVErrorCodes *) malloc(WStackMaxCycles*sizeof(CVErrorCodes)); |
149 | WStackECs = (CVErrorCodes *) malloc(WStackMaxCycles*sizeof(CVErrorCodes)); |
150 | 150 | ||
151 | return 0; |
151 | return 0; |
152 | } |
152 | } |
153 | 153 | ||
154 | int VME_MultiReadExecute(long Handle, uint32_t * Data){ |
154 | int VME_MultiReadExecute(long Handle, uint32_t * Data){ |
155 | //printf("len=%d\n",RStackNCycles); |
155 | //printf("len=%d\n",RStackNCycles); |
156 | int i=0; |
156 | int i=0; |
157 | CVErrorCodes result =CAENVME_MultiRead(Handle, RStackAddrs, Data, RStackNCycles, RStackAMs, RStackDWs, RStackECs); |
157 | CVErrorCodes result =CAENVME_MultiRead(Handle, RStackAddrs, Data, RStackNCycles, RStackAMs, RStackDWs, RStackECs); |
158 | if (result !=cvSuccess ) { |
158 | if (result !=cvSuccess ) { |
159 | VMEerrors++; |
159 | VMEerrors++; |
160 | printf("CAENVME_MultiRead at 0x%0X failed! err=%s RStackNCycles=%d\n", RStackAddrs[0], CAENVME_DecodeError(result), RStackNCycles); |
160 | printf("CAENVME_MultiRead at 0x%0X failed! err=%s RStackNCycles=%d\n", RStackAddrs[0], CAENVME_DecodeError(result), RStackNCycles); |
161 | for (i=0;i<RStackNCycles;i++){ |
161 | for (i=0;i<RStackNCycles;i++){ |
162 | if (RStackECs[i]!=cvSuccess ) printf("%d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X failed! err=%s\n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i], CAENVME_DecodeError(RStackECs[i]) ); |
162 | if (RStackECs[i]!=cvSuccess ) printf("%d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X failed! err=%s\n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i], CAENVME_DecodeError(RStackECs[i]) ); |
163 | } |
163 | } |
164 | exit(result); |
164 | exit(result); |
165 | } |
165 | } |
166 | return RStackNCycles; |
166 | return RStackNCycles; |
167 | } |
167 | } |
168 | 168 | ||
169 | int VME_MultiWriteExecute(long Handle){ |
169 | int VME_MultiWriteExecute(long Handle){ |
170 | int i=0; |
170 | int i=0; |
171 | CVErrorCodes result =CAENVME_MultiWrite(Handle, WStackAddrs, WStackBuffer, WStackNCycles, WStackAMs, WStackDWs, WStackECs); |
171 | CVErrorCodes result =CAENVME_MultiWrite(Handle, WStackAddrs, WStackBuffer, WStackNCycles, WStackAMs, WStackDWs, WStackECs); |
172 | if (result !=cvSuccess ) { |
172 | if (result !=cvSuccess ) { |
173 | printf("CAENVME_MultiWrite at 0x%0X failed! err=%s WStackNCycles=%d\n", WStackAddrs[0], CAENVME_DecodeError(result), WStackNCycles); |
173 | printf("CAENVME_MultiWrite at 0x%0X failed! err=%s WStackNCycles=%d\n", WStackAddrs[0], CAENVME_DecodeError(result), WStackNCycles); |
174 | 174 | ||
175 | for (i=0;i<WStackNCycles;i++){ |
175 | for (i=0;i<WStackNCycles;i++){ |
176 | if (WStackECs[i]!=cvSuccess ) |
176 | if (WStackECs[i]!=cvSuccess ) |
177 | printf("%d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X data= 0x%0X failed! err=%s\n", i,WStackAddrs[i],WStackAMs[i], WStackDWs[i], WStackBuffer[i], CAENVME_DecodeError(WStackECs[i]) ); |
177 | printf("%d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X data= 0x%0X failed! err=%s\n", i,WStackAddrs[i],WStackAMs[i], WStackDWs[i], WStackBuffer[i], CAENVME_DecodeError(WStackECs[i]) ); |
178 | } |
178 | } |
179 | exit(result); |
179 | exit(result); |
180 | } |
180 | } |
181 | return WStackNCycles; |
181 | return WStackNCycles; |
182 | } |
182 | } |
183 | 183 | ||
184 | 184 | ||
185 | 185 | ||
186 | 186 | ||
187 | 187 | ||
188 | 188 |