/[PAMELA software]/quicklook/dataToXML/Data/compilationInfo/src/INFN/AC_Anticoincidence_INFN.c
ViewVC logotype

Contents of /quicklook/dataToXML/Data/compilationInfo/src/INFN/AC_Anticoincidence_INFN.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Apr 25 09:00:20 2006 UTC (19 years, 2 months ago) by kusanagi
Branch: MAIN
CVS Tags: dataToXML1_02/01, dataToXML1_02/00, dataToXML1_03/00, dataToXML1_03/01, dataToXML1_00/00, firstRelease, dataToXML1_01/00, dataToXML1_03_02, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
These program extract in an XML format the info contained into the ROOT files generated by YODA from the PAMELA data. To visualize the XML files in a more human readable format a collection of XSL files are given in the Data subfolder.

1 /****************************************************************************
2 * F i l e D a t a
3 * $Id: AC_Anticoincidence_INFN.c,v 1.25 2005/02/22 18:09:25 sebastiani Exp $
4 * $Revision: 1.25 $
5 * $Date: 2005/02/22 18:09:25 $
6 * $RCSfile: AC_Anticoincidence_INFN.c,v $
7 *
8 ****************************************************************************
9 * S W D e v e l o p m e n t E n v i r o n m e n t
10 *
11 * $Author: sebastiani $
12 * :
13 ****************************************************************************
14 * U p d a t i n g
15
16 * $Log: AC_Anticoincidence_INFN.c,v $
17 * Revision 1.25 2005/02/22 18:09:25 sebastiani
18 * various bugfixes
19 *
20 * Revision 1.24 2005/02/19 10:19:00 sebastiani
21 * bugfix: HB_PKTTYPE_CALIB1_AC_1,HB_PKTTYPE_CALIB2_AC_2 error setting; optimization: LU_EXIT_IFERROR/RM_EXIT_IFERROR for space reducing
22 *
23 * Revision 1.23 2005/01/26 18:46:48 sebastiani
24 * new bug fixes for WS
25 *
26 * Revision 1.22 2005/01/10 14:02:12 faber
27 * TRG,AC_1,AC_2,TOF Error Handler reviewed
28 *
29 * Revision 1.21 2004/12/02 10:43:38 sebastiani
30 * fix AC
31 * fix CAL
32 * fix HK BUFTYPE
33 *
34 * Revision 1.20 2004/11/30 11:51:53 faber
35 * AC+AC2 software moved into AC_1 AC_2
36 * new calibration and initialization for AC
37 * first version,never run
38 *
39 * Revision 1.19 2004/11/19 15:14:52 sebastiani
40 * PRH_EXTERN_{VAR,ARR,TABLE} removed and put them on the autogenerated parameter heeader file
41 *
42 * Revision 1.18 2004/10/01 09:20:23 alfarano
43 * AC2 and little bug fix on S4 return code
44 *
45 * Revision 1.17 2004/09/28 15:10:51 alfarano
46 * little bug
47 *
48 * Revision 1.16 2004/09/17 15:52:00 faber
49 * fix command queue Cmd2Fe/Fe2Daq right invocation for Test funcion inf TOF and TRG
50 *
51 * Revision 1.15 2004/09/17 15:01:00 faber
52 * LU_INFN_LOG flags fixing
53 *
54 * Revision 1.14 2004/08/27 13:30:39 alfarano
55 * cvs header
56 *
57 * Revision 1.1 2003/10/03 16:12:26 faber
58 * *** empty log message ***
59 *
60 *
61 *****************************************************************************/
62 /*============================= Include File ================================*/
63
64
65 #include <src/INFN/LU_SourceFileID_INFN.h>
66 #define __FILEID__ _AC_Anticoincidence_INFN__c
67
68 #include <src/INFN/PRH_ParamHandler_INFN.h>
69 #include <src/INFN/LU_LogUtility_INFN.h>
70 #include <src/INFN/PRH_ParamHandler_INFN_auto.h>
71 LU_DECL_MASK();
72
73 #include <src/INFN/DAQ_IDAQ_INFN.h>
74 #include <src/INFN/CM_Common_INFN.h>
75 #include <src/INFN/AC_Anticoincidence_INFN.h>
76 #include <src/INFN/KHB_Driver_INFN.h>
77 #include <src/INFN/HK_Manager_INFN.h>
78 #include <src/INFN/HB_HKBuffer_INFN.h>
79 #include <src/INFN/PM_PamManager_INFN.h>
80 #include <src/INFN/CH_CommandHandler_INFN.h>
81 #include <src/INFN/ALM_Alarm_INFN.h>
82 #include <src/INFN/RM_RunManager_INFN.h>
83 /*============================ Global define ================================*/
84
85
86 /*============================== global types ==============================*/
87
88 #define AC_SKIP_HEADER SM_PKTHEADER_LEN
89
90 DAQ_DECLBUF(daq_reply,128*1024);
91
92 #define AC_1 0
93 #define AC_2 1
94
95 static DAQ_CMD_BUF AC_SEND_DSP_PROG1;
96 static DAQ_CMD_BUF AC_1_SEND_DSP_PROG2,AC_2_SEND_DSP_PROG2;
97 static DAQ_CMD_BUF AC_1_SET_DAQ,AC_2_SET_DAQ;
98
99 static DAQ_CMD_BUF AC_1_WRITE_REG,AC_2_WRITE_REG;
100
101 static DAQ_CMD_BUF AC_READ_DSP_MEM;
102
103 DAQ_DECLBUF(AC_TempPif0,AC_MAXTEMPBUFFER);
104
105 status_code AC_Init_ParamBuffers()
106 {
107 DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_SET_DAQ);
108 DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_SET_DAQ);
109
110 DAQ_INIT_BUF_FROM_PARAMBUF(AC_SEND_DSP_PROG1);
111
112 DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_SEND_DSP_PROG2);
113 DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_SEND_DSP_PROG2);
114
115 DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_SET_DAQ);
116 DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_SET_DAQ);
117
118 //DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_CALIB1);
119 //DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_CALIB1);
120
121 //DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_CALIB2);
122 //DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_CALIB2);
123
124 DAQ_INIT_BUF_FROM_PARAMBUF(AC_READ_DSP_MEM);
125 DAQ_INIT_BUF_FROM_PARAMBUF(AC_1_WRITE_REG);
126 DAQ_INIT_BUF_FROM_PARAMBUF(AC_2_WRITE_REG);
127
128 return CM_RC_SUCCESSFUL;
129 }
130
131 status_code AC_Init_ATOETO()
132 {
133 int i;
134 CH_PARAMBUF_SET_ATO_ETO(AC_1_SET_DAQ,0x1,0x4);
135 CH_PARAMBUF_SET_ATO_ETO(AC_2_SET_DAQ,0x1,0x4);
136
137 // CH_PARAMBUF_SET_ATO_ETO(AC_SEND_DSP_PROG2,0x1,0x9);
138 CH_PARAMBUF_SET_ATO_ETO(AC_READ_DSP_MEM,0x1,0x9);
139
140 CH_PARAMBUF_SET_ATO_ETO(AC_1_WRITE_REG,0x1,0x2);
141 CH_PARAMBUF_SET_ATO_ETO(AC_2_WRITE_REG,0x1,0x2);
142
143 CH_SetAtoEto(CH_AC_STATUS_RESET,1,2);
144 CH_SetAtoEto(CH_AC_RESET_DSP,1,2);
145 CH_SetAtoEto(CH_AC_CHANGE_MODE_CALIB,1,2);
146 CH_SetAtoEto(CH_AC_CHANGE_MODE_PHYS,1,2);
147 CH_SetAtoEto(CH_AC_READ_EVENT,1,3);
148 CH_SetAtoEto(CH_AC_COUNTER_RESET,1,2);
149 CH_SetAtoEto(CH_AC_READ_STATUS,1,2);
150
151 CH_PARAMBUF_SET_ATO_ETO(AC_SEND_DSP_PROG1,0x1,0x9);
152 CH_PARAMBUF_SET_ATO_ETO(AC_1_SEND_DSP_PROG2,0x1,0x9);
153 CH_PARAMBUF_SET_ATO_ETO(AC_2_SEND_DSP_PROG2,0x1,0x9);
154
155 }
156
157 status_code AC_Init()
158 {
159 DAQ_BUFFER_INIT(AC_TempPif0);
160 DAQ_BUFFER_INIT(daq_reply);
161
162 AC_Init_ParamBuffers();
163 AC_Init_ATOETO();
164
165 return CM_RC_SUCCESSFUL;
166 }
167
168
169
170
171 status_code AC_Initialization(DAQ_FE fe,
172 BYTE pkt_type,
173 DAQ_CMD_BUF *ac_set_daq,
174 DAQ_CMD_BUF *ac_write_reg,
175 PRH_VAR_TYPE *ac_on)
176 {
177
178 UINT16 loop=0;
179 DAQ_CMD_BUF* auto_buf;
180 int i;
181 BOOL check_ok;
182 status_code status;
183
184 *ac_on = 0;
185
186 RM_Set_AcqExitIfError_FILEID(__FILEID__);
187
188 DAQ_ResetPIF(DAQ_DEFAULT_ETO_TICS,DAQ_MAX_DTO_TICS,SM_DAQSETUP,pkt_type);
189
190 DAQ_Format_CMD_Empty(&AC_TempPif0);
191
192 DAQ_Format_Fe2Daq(&AC_TempPif0,ac_set_daq,fe);
193 DAQ_Format_Fe2Daq(&AC_TempPif0,ac_write_reg,fe);
194 CH_GetBuf(CH_AC_COUNTER_RESET,&auto_buf);
195 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,fe);
196 CH_GetBuf(CH_AC_STATUS_RESET,&auto_buf);
197 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,fe);
198
199 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP0,&AC_TempPif0);
200 RM_EXIT_IFERROR(status);
201
202 do
203 {
204 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP0,DAQ_STORE_MM,&daq_reply,DAQ_STORE_RAM);
205
206 if (daq_reply.len < AC_SKIP_HEADER + 4*2)
207 status = CM_RC_RUNTIMEOUT;
208
209 RM_EXIT_IFERROR(status);
210
211 check_ok =
212 (*(UINT16*)(&daq_reply.buf[AC_SKIP_HEADER +0]) == 0xFFFF) &&
213 (*(UINT16*)(&daq_reply.buf[AC_SKIP_HEADER +2]) == 0xFFFF) &&
214 (*(UINT16*)(&daq_reply.buf[AC_SKIP_HEADER +4]) == 0xFFFF) &&
215 (*(UINT16*)(&daq_reply.buf[AC_SKIP_HEADER +6]) == 0xFFFF);
216
217 loop++;
218 }
219 while ((loop < PRH_VAR_AC_LOOP) && !check_ok);
220
221 if (check_ok)
222 *ac_on = 1;
223 else
224 *ac_on = 0;
225
226 return status;
227 }
228
229
230 status_code AC_1_Initialization() {
231 return AC_Initialization(DAQ_FE_AC_1,
232 HB_PKTTYPE_AC_1_INIT,
233 &AC_1_SET_DAQ,
234 &AC_1_WRITE_REG,
235 &PRH_VAR_AC_1_ON);
236 }
237 status_code AC_2_Initialization() {
238 return AC_Initialization(DAQ_FE_AC_2,
239 HB_PKTTYPE_AC_2_INIT,
240 &AC_2_SET_DAQ,
241 &AC_2_WRITE_REG,
242 &PRH_VAR_AC_2_ON);
243 }
244
245 status_code AC_Calibration1()
246 {
247 status_code status = CM_RC_SUCCESSFUL;
248 DAQ_CMD_BUF* auto_buf;
249 UINT16 alarm_reg;
250 int i;
251 UINT16 ac_ok[2] = {PRH_VAR_AC_1_OK,PRH_VAR_AC_2_OK};
252 UINT16 ac_on[2] = {PRH_VAR_AC_1_ON,PRH_VAR_AC_2_ON};
253 DAQ_CMD_BUF *ac_send_dsp_prog2[2] = {&AC_1_SEND_DSP_PROG2,&AC_2_SEND_DSP_PROG2};
254 DAQ_CMD_BUF *ac_set_daq[2] = {&AC_1_SET_DAQ,&AC_2_SET_DAQ};
255 DAQ_FE ac_fe[2] = {DAQ_FE_AC_1,DAQ_FE_AC_2};
256 BYTE ac_pkttype[2] = {HB_PKTTYPE_CALIB1_AC_1,HB_PKTTYPE_CALIB1_AC_2};
257
258 RM_Set_AcqExitIfError_FILEID(__FILEID__);
259
260 DAQ_ResetPIF(DAQ_DEFAULT_ETO_TICS,DAQ_MAX_DTO_TICS,SM_DAQSETUP,HB_PKTTYPE_RSV_AC_CALIB1);
261
262 for(i=0;i<2;i++) {
263 if(ac_ok[i] && ac_on[i]) {
264 PM_pi_SetPktType(ac_pkttype[i]);
265
266 DAQ_Format_CMD_Empty(&AC_TempPif0);
267
268 CH_GetBuf(CH_AC_RESET_DSP,&auto_buf);
269 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,ac_fe[i]);
270
271 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP0,&AC_TempPif0);
272 RM_EXIT_IFERROR(status);
273
274 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP0,DAQ_NO_STORE_MM,&daq_reply,DAQ_STORE_RAM);
275 RM_EXIT_IFERROR(status);
276
277 DAQ_Format_CMD_Empty(&AC_TempPif0);
278 DAQ_Format_Fe2Daq(&AC_TempPif0,&AC_SEND_DSP_PROG1,ac_fe[i]);
279
280 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP0,&AC_TempPif0);
281 RM_EXIT_IFERROR(status);
282
283 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP0,DAQ_NO_STORE_MM,&daq_reply,DAQ_STORE_RAM);
284 RM_EXIT_IFERROR(status);
285
286 DAQ_Format_CMD_Empty(&AC_TempPif0);
287
288 DAQ_Format_Fe2Daq(&AC_TempPif0,ac_send_dsp_prog2[i],ac_fe[i]);
289 CH_GetBuf(CH_AC_CHANGE_MODE_CALIB,&auto_buf);
290 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,ac_fe[i]);
291
292 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP1,&AC_TempPif0);
293 RM_EXIT_IFERROR(status);
294
295 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP1,DAQ_NO_STORE_MM,&daq_reply,DAQ_STORE_RAM);
296 RM_EXIT_IFERROR(status);
297 }
298 }
299
300 status = RM_TaskSuspendUnlessSINT(2500);
301 RM_EXIT_IFERROR(status);
302
303 for(i=0;i<2;i++) {
304 if(ac_ok[i] && ac_on[i]) {
305 PM_pi_SetPktType(ac_pkttype[i]);
306
307 DAQ_Format_CMD_Empty(&AC_TempPif0);
308 DAQ_Format_Fe2Daq(&AC_TempPif0,ac_set_daq[i],ac_fe[i]);
309 CH_GetBuf(CH_AC_CHANGE_MODE_PHYS,&auto_buf);
310 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,ac_fe[i]);
311 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP2,&AC_TempPif0);
312 RM_EXIT_IFERROR(status);
313
314 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP2,DAQ_STORE_MM,&daq_reply,DAQ_NO_STORE_RAM);
315 RM_EXIT_IFERROR(status);
316 }
317 }
318 return status;
319 }
320
321
322 status_code AC_Calibration2()
323 {
324
325
326 status_code status = CM_RC_SUCCESSFUL;
327 DAQ_CMD_BUF* auto_buf;
328 UINT16 alarm_reg;
329 int i;
330 UINT16 ac_ok[2] = {PRH_VAR_AC_1_OK,PRH_VAR_AC_2_OK};
331 UINT16 ac_on[2] = {PRH_VAR_AC_1_ON,PRH_VAR_AC_2_ON};
332 DAQ_FE ac_fe[2] = {DAQ_FE_AC_1,DAQ_FE_AC_2};
333 BYTE ac_pkttype[2] = {HB_PKTTYPE_CALIB2_AC_1,HB_PKTTYPE_CALIB2_AC_2};
334
335 RM_Set_AcqExitIfError_FILEID(__FILEID__);
336
337 DAQ_ResetPIF(DAQ_DEFAULT_ETO_TICS,DAQ_MAX_DTO_TICS,SM_DAQSETUP,HB_PKTTYPE_RSV_AC_CALIB2);
338
339 for(i=0;i<2;i++) {
340 if(ac_ok[i] && ac_on[i]) {
341
342 PM_pi_SetPktType(ac_pkttype[i]);
343
344 DAQ_Format_CMD_Empty(&AC_TempPif0);
345 DAQ_Format_Fe2Daq(&AC_TempPif0,&AC_READ_DSP_MEM,ac_fe[i]);
346 CH_GetBuf(CH_AC_RESET_DSP,&auto_buf);
347 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,ac_fe[i]);
348
349 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP2,&AC_TempPif0);
350 RM_EXIT_IFERROR(status);
351
352 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP2,DAQ_STORE_MM,&daq_reply,DAQ_NO_STORE_RAM);
353 RM_EXIT_IFERROR(status);
354
355 if(i == AC_1)
356 status=AC_1_Initialization();
357 else
358 status=AC_2_Initialization();
359
360 RM_EXIT_IFERROR(status);
361
362 }
363 }
364
365 return status;
366 }
367
368 status_code AC_Error_Handler(DAQ_FE fe)
369 {
370 UINT32 AC_Count2 = 0;
371 DAQ_CMD_BUF *auto_buf;
372 status_code status;
373 BOOL do_power_off_on=FALSE;
374 BOOL do_reset=FALSE;
375
376 DAQ_Format_CMD_Empty(&AC_TempPif0);
377
378 CH_GetBuf(CH_AC_READ_STATUS,&auto_buf);
379 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,fe);
380
381
382 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP0,&AC_TempPif0);
383
384 if(status == CM_RC_SUCCESSFUL) {
385 do {
386 AC_Count2++;
387
388 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP0,DAQ_STORE_MM,&daq_reply,DAQ_STORE_RAM);
389 if(status != CM_RC_SUCCESSFUL)
390 return CM_RC_DO_RESET_IF_ALM;
391
392 do_reset = ((signed int)daq_reply.len) - AC_SKIP_HEADER < 4;
393
394 } while( do_reset && (AC_Count2 <= PRH_VAR_AC_LOOP2));
395
396 if(!do_reset)
397 do_power_off_on=
398 ( daq_reply.buf[AC_SKIP_HEADER+1] != 0xFF) ||
399 ( (daq_reply.buf[AC_SKIP_HEADER ] & 0x1) != 0x1) ;
400
401
402 DAQ_Format_CMD_Empty(&AC_TempPif0);
403
404 CH_GetBuf(CH_AC_STATUS_RESET,&auto_buf);
405 DAQ_Format_Fe2Daq(&AC_TempPif0,auto_buf,fe);
406
407 status = DAQ_StoreCmdQueue2PIF(SM_CALEXP1,&AC_TempPif0);
408 if(status != CM_RC_SUCCESSFUL)
409 return do_power_off_on ? CM_RC_DO_POWER_OFF_ON : CM_RC_DO_RESET_IF_ALM;
410
411 status = DAQ_SendCmd2PIFWaitDAQReply(SM_CALEXP1,DAQ_STORE_MM,&daq_reply,DAQ_NO_STORE_RAM);
412 if(status != CM_RC_SUCCESSFUL)
413 return do_power_off_on ? CM_RC_DO_POWER_OFF_ON : CM_RC_DO_RESET_IF_ALM;
414
415 if(!do_power_off_on && !do_reset)
416 if(fe == DAQ_FE_AC_2)
417 status = AC_2_Initialization();
418 else
419 status = AC_1_Initialization();
420
421 if(status != CM_RC_SUCCESSFUL || do_reset || do_power_off_on )
422 return do_power_off_on ? CM_RC_DO_POWER_OFF_ON : CM_RC_DO_RESET_IF_ALM;
423
424 }else
425 status = CM_RC_DO_RESET_IF_ALM;
426
427 return status;
428 }
429
430
431
432

  ViewVC Help
Powered by ViewVC 1.1.23