Rev 100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 100 | Rev 122 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | #include <stdlib.h> |
2 | #include <stdlib.h> |
3 | #include <stdio.h> |
3 | #include <stdio.h> |
4 | #include <stdint.h> |
4 | #include <stdint.h> |
5 | 5 | ||
6 | #include <CAENVMElib.h> |
6 | #include <CAENVMElib.h> |
7 | #include <CAENVMEoslib.h> |
7 | #include <CAENVMEoslib.h> |
8 | #include <CAENVMEtypes.h> |
8 | #include <CAENVMEtypes.h> |
9 | 9 | ||
Line 19... | Line 19... | ||
19 | 19 | ||
20 | int32_t CAEN_udev; |
20 | int32_t CAEN_udev; |
21 | 21 | ||
22 | int VMEerrors; |
22 | int VMEerrors; |
23 | 23 | ||
24 | int CAEN_VME_start (char* serial) |
24 | int CAEN_VME_start (char* serial) { |
25 | { |
- | |
26 | 25 | ||
27 | CVErrorCodes result = CAENVME_Init( cvV1718 , 0 , 0 , &CAEN_udev); |
26 | CVErrorCodes result = CAENVME_Init( cvV1718 , 0 , 0 , &CAEN_udev); |
28 | if (result != cvSuccess) { |
27 | if (result != cvSuccess) { |
29 | printf("CAEN1718 Init %s\n", CAENVME_DecodeError(result)); |
28 | printf("CAEN1718 Init %s\n", CAENVME_DecodeError(result)); |
30 | printf(" Check usb cable, usb udev permissions and restart! Exiting .....\n"); |
29 | printf(" Check usb cable, usb udev permissions and restart! Exiting .....\n"); |
31 | return (-1); |
30 | return (-1); |
32 | } |
31 | } |
33 | if (serial == NULL) serial = (char *) malloc(100*sizeof(char)); |
32 | if (serial == NULL) serial = (char *) malloc(100*sizeof(char)); |
34 | CAENVME_BoardFWRelease(CAEN_udev, serial); |
33 | CAENVME_BoardFWRelease(CAEN_udev, serial); |
- | 34 | ||
- | 35 | return result; |
|
- | 36 | } |
|
- | 37 | ||
- | 38 | ||
- | 39 | short CAEN_VME_read(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) { |
|
- | 40 | ||
- | 41 | CVErrorCodes result; |
|
- | 42 | int ncount=0; |
|
- | 43 | while (1) { |
|
- | 44 | result = CAENVME_ReadCycle(Handle, Address, Data, AM, DW ); |
|
- | 45 | if (result !=cvSuccess ) { |
|
- | 46 | VMEerrors++; |
|
- | 47 | 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)); |
|
- | 48 | ncount++; |
|
- | 49 | if (ncount==10) return (result); |
|
- | 50 | } else break; |
|
35 | 51 | } |
|
36 | return result; |
52 | return result; |
37 | } |
53 | } |
38 | 54 | ||
39 | - | ||
40 | short CAEN_VME_read(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
- | |
41 | { |
- | |
42 | - | ||
43 | CVErrorCodes result; |
- | |
44 | int ncount=0; |
- | |
45 | while (1){ |
- | |
46 | result = CAENVME_ReadCycle(Handle, Address, Data, AM, DW ); |
- | |
47 | if (result !=cvSuccess ) { |
- | |
48 | VMEerrors++; |
- | |
49 | 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)); |
- | |
50 | ncount++; |
- | |
51 | if (ncount==10) return (result); |
- | |
52 | } else break; |
- | |
53 | } |
- | |
54 | return result; |
- | |
55 | } |
- | |
56 | - | ||
57 | int CAEN_VME_BltRead(long Handle, unsigned long Address, void *Data, int size, CVAddressModifier AM, CVDataWidth DW) |
55 | int CAEN_VME_BltRead(long Handle, unsigned long Address, void *Data, int size, CVAddressModifier AM, CVDataWidth DW) { |
58 | { |
- | |
59 | int count=0; |
56 | int count=0; |
60 | CVErrorCodes result; |
57 | CVErrorCodes result; |
61 | int ncount=0; |
58 | int ncount=0; |
62 | 59 | ||
63 | while (1){ |
60 | while (1) { |
64 | 61 | ||
65 | result = CAENVME_BLTReadCycle(Handle, Address, Data, size, AM, DW , &count); |
62 | result = CAENVME_BLTReadCycle(Handle, Address, Data, size, AM, DW , &count); |
66 | if (result !=cvSuccess ) { |
63 | if (result !=cvSuccess ) { |
67 |
|
64 | VMEerrors++; |
68 |
|
65 | 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); |
69 |
|
66 | ncount++; |
70 |
|
67 | if (ncount==10) return (result); |
71 | } else break; |
68 | } else break; |
72 | } |
69 | } |
73 | return count; |
70 | return count; |
74 | } |
71 | } |
75 | 72 | ||
76 | short CAEN_VME_write(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) |
73 | short CAEN_VME_write(long Handle, unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) { |
77 | { |
- | |
78 | 74 | ||
79 | CVErrorCodes result; |
75 | CVErrorCodes result; |
80 | int ncount=0; |
76 | int ncount=0; |
81 | while |
77 | while (1) { |
82 | 78 | ||
83 | result = CAENVME_WriteCycle(Handle, Address, Data, AM, DW ); |
79 | result = CAENVME_WriteCycle(Handle, Address, Data, AM, DW ); |
84 | if (result !=cvSuccess ) { |
80 | if (result !=cvSuccess ) { |
85 | VMEerrors++; |
81 | VMEerrors++; |
86 | 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)); |
82 | 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)); |
87 | if (ncount==10) return (result); |
83 | if (ncount==10) return (result); |
88 | } else break; |
84 | } else break; |
89 | } |
85 | } |
90 | return result; |
86 | return result; |
91 | } |
87 | } |
92 | 88 | ||
93 | 89 | ||
94 | 90 | ||
95 | 91 | ||
96 | uint32_t *WStackAddrs = NULL; |
92 | uint32_t *WStackAddrs = NULL; |
97 | uint32_t *WStackBuffer; |
93 | uint32_t *WStackBuffer; |
98 | unsigned short WStackNCycles; |
94 | unsigned short WStackNCycles; |
99 | unsigned short WStackMaxCycles=100; |
95 | unsigned short WStackMaxCycles=100; |
100 | CVAddressModifier *WStackAMs; |
96 | CVAddressModifier *WStackAMs; |
101 | CVDataWidth *WStackDWs; |
97 | CVDataWidth *WStackDWs; |
102 | CVErrorCodes *WStackECs; |
98 | CVErrorCodes *WStackECs; |
103 | 99 | ||
104 | 100 | ||
105 | uint32_t *RStackAddrs =NULL; |
101 | uint32_t *RStackAddrs =NULL; |
106 | unsigned short RStackNCycles; |
102 | unsigned short RStackNCycles; |
107 | unsigned short RStackMaxCycles=1000; |
103 | unsigned short RStackMaxCycles=1000; |
108 | CVAddressModifier *RStackAMs; |
104 | CVAddressModifier *RStackAMs; |
109 | CVDataWidth *RStackDWs; |
105 | CVDataWidth *RStackDWs; |
110 | CVErrorCodes *RStackECs; |
106 | CVErrorCodes *RStackECs; |
111 | 107 | ||
112 | 108 | ||
113 | 109 | ||
114 | short CAEN_VME_appendread(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
110 | short CAEN_VME_appendread(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) { |
115 | if (RStackNCycles<RStackMaxCycles){ |
111 | if (RStackNCycles<RStackMaxCycles) { |
116 | RStackAddrs[RStackNCycles] = Address; |
112 | RStackAddrs[RStackNCycles] = Address; |
117 | RStackAMs[RStackNCycles] = AM; |
113 | RStackAMs[RStackNCycles] = AM; |
118 | RStackDWs[RStackNCycles] = DW; |
114 | RStackDWs[RStackNCycles] = DW; |
119 | //int i=RStackNCycles; |
115 | //int i=RStackNCycles; |
120 | //printf("AppendRead %d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X \n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i]); |
116 | //printf("AppendRead %d ADDR= 0x%0X AM= 0x%0X DW= 0x%0X \n", i,RStackAddrs[i],RStackAMs[i], RStackDWs[i]); |
121 | RStackNCycles++; |
117 | RStackNCycles++; |
122 | } else { |
118 | } else { |
123 | printf("Increase DataBuffer RStackMaxCycles =%d\n", RStackMaxCycles); |
119 | printf("Increase DataBuffer RStackMaxCycles =%d\n", RStackMaxCycles); |
124 | } |
120 | } |
125 | return RStackNCycles; |
121 | return RStackNCycles; |
126 | } |
122 | } |
127 | 123 | ||
128 | short CAEN_VME_appendwrite(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW){ |
124 | short CAEN_VME_appendwrite(unsigned long Address, void *Data, CVAddressModifier AM, CVDataWidth DW) { |
129 | if (WStackNCycles<WStackMaxCycles){ |
125 | if (WStackNCycles<WStackMaxCycles) { |
130 | WStackAddrs[WStackNCycles] = Address; |
126 | WStackAddrs[WStackNCycles] = Address; |
131 | WStackBuffer[WStackNCycles] = *((uint32_t *) Data); |
127 | WStackBuffer[WStackNCycles] = *((uint32_t *) Data); |
132 | WStackAMs[WStackNCycles] = AM; |
128 | WStackAMs[WStackNCycles] = AM; |
133 | WStackDWs[WStackNCycles] = DW; |
129 | WStackDWs[WStackNCycles] = DW; |
134 | WStackNCycles++; |
130 | WStackNCycles++; |
Line 136... | Line 132... | ||
136 | printf("Increase DataBuffer WStackMaxCycles =%d\n", WStackMaxCycles); |
132 | printf("Increase DataBuffer WStackMaxCycles =%d\n", WStackMaxCycles); |
137 | } |
133 | } |
138 | return 0; |
134 | return 0; |
139 | } |
135 | } |
140 | 136 | ||
141 | short CAEN_VME_MultiReadReset(){ |
137 | short CAEN_VME_MultiReadReset() { |
142 | RStackNCycles=0; |
138 | RStackNCycles=0; |
143 | if (RStackAddrs!=NULL) return 0; |
139 | if (RStackAddrs!=NULL) return 0; |
144 | RStackAddrs = (uint32_t *) malloc( RStackMaxCycles*sizeof(uint32_t)); |
140 | RStackAddrs = (uint32_t *) malloc( RStackMaxCycles*sizeof(uint32_t)); |
145 | 141 | ||
146 | RStackAMs = (CVAddressModifier *) malloc(RStackMaxCycles*sizeof(CVAddressModifier)); |
142 | RStackAMs = (CVAddressModifier *) malloc(RStackMaxCycles*sizeof(CVAddressModifier)); |
147 | RStackDWs = (CVDataWidth *) malloc(RStackMaxCycles*sizeof(CVDataWidth)); |
143 | RStackDWs = (CVDataWidth *) malloc(RStackMaxCycles*sizeof(CVDataWidth)); |
148 | RStackECs = (CVErrorCodes *) malloc(RStackMaxCycles*sizeof(CVErrorCodes)); |
144 | RStackECs = (CVErrorCodes *) malloc(RStackMaxCycles*sizeof(CVErrorCodes)); |
149 | 145 | ||
150 | return 0; |
146 | return 0; |
151 | } |
147 | } |
152 | 148 | ||
153 | short CAEN_VME_MultiWriteReset(){ |
149 | short CAEN_VME_MultiWriteReset() { |
154 | WStackNCycles=0; |
150 | WStackNCycles=0; |
155 | if (WStackAddrs!=NULL) return 0; |
151 | if (WStackAddrs!=NULL) return 0; |
156 | WStackBuffer = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
152 | WStackBuffer = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
157 | WStackAddrs = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
153 | WStackAddrs = (uint32_t *) malloc( WStackMaxCycles*sizeof(uint32_t)); |
158 | WStackAMs = (CVAddressModifier *) malloc(WStackMaxCycles*sizeof(CVAddressModifier)); |
154 | WStackAMs = (CVAddressModifier *) malloc(WStackMaxCycles*sizeof(CVAddressModifier)); |
159 | WStackDWs = (CVDataWidth *) malloc(WStackMaxCycles*sizeof(CVDataWidth)); |
155 | WStackDWs = (CVDataWidth *) malloc(WStackMaxCycles*sizeof(CVDataWidth)); |
160 | WStackECs = (CVErrorCodes *) malloc(WStackMaxCycles*sizeof(CVErrorCodes)); |
156 | WStackECs = (CVErrorCodes *) malloc(WStackMaxCycles*sizeof(CVErrorCodes)); |
161 | 157 | ||
162 | return 0; |
158 | return 0; |
163 | } |
159 | } |
164 | 160 | ||
165 | short CAEN_VME_MultiReadExecute(long Handle, uint32_t * Data){ |
161 | short CAEN_VME_MultiReadExecute(long Handle, uint32_t * Data) { |
166 | //printf("len=%d\n",RStackNCycles); |
162 | //printf("len=%d\n",RStackNCycles); |
167 | int i=0; |
163 | int i=0; |
168 | CVErrorCodes result =CAENVME_MultiRead(Handle, RStackAddrs, Data, RStackNCycles, RStackAMs, RStackDWs, RStackECs); |
164 | CVErrorCodes result =CAENVME_MultiRead(Handle, RStackAddrs, Data, RStackNCycles, RStackAMs, RStackDWs, RStackECs); |
169 | if (result !=cvSuccess ) { |
165 | if (result !=cvSuccess ) { |
170 | VMEerrors++; |
166 | VMEerrors++; |
171 | printf("CAENVME_MultiRead at 0x%0X failed! err=%s RStackNCycles=%d\n", RStackAddrs[0], CAENVME_DecodeError(result), RStackNCycles); |
167 | printf("CAENVME_MultiRead at 0x%0X failed! err=%s RStackNCycles=%d\n", RStackAddrs[0], CAENVME_DecodeError(result), RStackNCycles); |
172 | for |
168 | for (i=0; i<RStackNCycles; i++) { |
173 | 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]) ); |
169 | 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]) ); |
174 | } |
170 | } |
175 | exit(result); |
171 | exit(result); |
176 | } |
172 | } |
177 | return RStackNCycles; |
173 | return RStackNCycles; |
178 | } |
174 | } |
179 | 175 | ||
180 | short CAEN_VME_MultiWriteExecute(long Handle){ |
176 | short CAEN_VME_MultiWriteExecute(long Handle) { |
181 | int i=0; |
177 | int i=0; |
182 | CVErrorCodes result =CAENVME_MultiWrite(Handle, WStackAddrs, WStackBuffer, WStackNCycles, WStackAMs, WStackDWs, WStackECs); |
178 | CVErrorCodes result =CAENVME_MultiWrite(Handle, WStackAddrs, WStackBuffer, WStackNCycles, WStackAMs, WStackDWs, WStackECs); |
183 | if (result !=cvSuccess ) { |
179 | if (result !=cvSuccess ) { |
184 | printf("CAENVME_MultiWrite at 0x%0X failed! err=%s WStackNCycles=%d\n", WStackAddrs[0], CAENVME_DecodeError(result), WStackNCycles); |
180 | printf("CAENVME_MultiWrite at 0x%0X failed! err=%s WStackNCycles=%d\n", WStackAddrs[0], CAENVME_DecodeError(result), WStackNCycles); |
185 | 181 | ||
186 | for |
182 | for (i=0; i<WStackNCycles; i++) { |
187 | if (WStackECs[i]!=cvSuccess ) |
183 | if (WStackECs[i]!=cvSuccess ) |
188 | 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]) ); |
184 | 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]) ); |
189 | } |
185 | } |
190 | exit(result); |
186 | exit(result); |
191 | } |
187 | } |
192 | return WStackNCycles; |
188 | return WStackNCycles; |
193 | } |
189 | } |
194 | 190 | ||
195 | 191 | ||
196 | short __stdcall CAEN_VME_R( uint16_t AddressModifier, uint16_t DataWidth, uint32_t VME_Address, uint32_t *Data){ |
192 | short __stdcall CAEN_VME_R( uint16_t AddressModifier, uint16_t DataWidth, uint32_t VME_Address, uint32_t *Data) { |
197 |
|
193 | return CAEN_VME_read( CAEN_udev, VME_Address, (void *)Data, (CVAddressModifier) AddressModifier, (CVDataWidth) DataWidth); |
198 | } |
194 | } |
199 | 195 | ||
200 | short __stdcall CAEN_VME_W( uint16_t AddressModifier, uint16_t DataWidth, uint32_t VME_Address, uint32_t Data){ |
196 | short __stdcall CAEN_VME_W( uint16_t AddressModifier, uint16_t DataWidth, uint32_t VME_Address, uint32_t Data) { |
201 |
|
197 | return CAEN_VME_write( CAEN_udev, VME_Address, &Data, (CVAddressModifier) AddressModifier, (CVDataWidth) DataWidth); |
202 | } |
198 | } |
203 | 199 | ||
204 | short __stdcall CAEN_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data){ |
200 | short __stdcall CAEN_VME_MW( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t Data) { |
205 | 201 | ||
206 | return CAEN_VME_appendwrite( VME_Address, &Data ,(CVAddressModifier) AM , (CVDataWidth) DW) ; |
202 | return CAEN_VME_appendwrite( VME_Address, &Data ,(CVAddressModifier) AM , (CVDataWidth) DW) ; |
207 | 203 | ||
208 | } |
204 | } |
209 | short __stdcall CAEN_VME_MWRST( void ){ |
205 | short __stdcall CAEN_VME_MWRST( void ) { |
210 | 206 | ||
211 | return CAEN_VME_MultiWriteReset(); |
207 | return CAEN_VME_MultiWriteReset(); |
212 | 208 | ||
213 | } |
209 | } |
214 | short __stdcall CAEN_VME_MWEXEC( void ){ |
210 | short __stdcall CAEN_VME_MWEXEC( void ) { |
215 | 211 | ||
216 | return CAEN_VME_MultiWriteExecute(CAEN_udev); |
212 | return CAEN_VME_MultiWriteExecute(CAEN_udev); |
217 | 213 | ||
218 | } |
214 | } |
219 | 215 | ||
220 | short __stdcall CAEN_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data){ |
216 | short __stdcall CAEN_VME_MR( uint16_t AM, uint16_t DW, uint32_t VME_Address, uint32_t *Data) { |
221 | 217 | ||
222 | return CAEN_VME_appendread( VME_Address, Data ,(CVAddressModifier) AM , (CVDataWidth) DW) ; |
218 | return CAEN_VME_appendread( VME_Address, Data ,(CVAddressModifier) AM , (CVDataWidth) DW) ; |
223 | 219 | ||
224 | } |
220 | } |
225 | short __stdcall CAEN_VME_MRRST( void ){ |
221 | short __stdcall CAEN_VME_MRRST( void ) { |
226 | 222 | ||
227 | return CAEN_VME_MultiReadReset(); |
223 | return CAEN_VME_MultiReadReset(); |
228 | 224 | ||
229 | } |
225 | } |
230 | short __stdcall CAEN_VME_MREXEC( uint32_t *Data ){ |
226 | short __stdcall CAEN_VME_MREXEC( uint32_t *Data ) { |
231 | return CAEN_VME_MultiReadExecute(CAEN_udev, Data); |
227 | return CAEN_VME_MultiReadExecute(CAEN_udev, Data); |
232 | 228 | ||
233 | 229 | ||
234 | } |
230 | } |
235 | 231 | ||
236 | 232 |