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

Annotation of /quicklook/dataToXML/Data/compilationInfo/src/INFN/ALM_Alarm_INFN.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Apr 25 09:00:20 2006 UTC (19 years, 2 months ago) by kusanagi
Branch point for: MAIN
File MIME type: text/plain
Initial revision

1 kusanagi 1.1 /****************************************************************************
2     * F i l e D a t a
3     * $Id: ALM_Alarm_INFN.c,v 1.24 2005/03/13 18:10:23 sebastiani Exp $
4     * $Revision: 1.24 $
5     * $Date: 2005/03/13 18:10:23 $
6     * $RCSfile: ALM_Alarm_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: ALM_Alarm_INFN.c,v $
17     * Revision 1.24 2005/03/13 18:10:23 sebastiani
18     * fix:correct logging khb_reg
19     *
20     * Revision 1.23 2005/03/06 14:54:46 sebastiani
21     * version running on 06 03 2005
22     *
23     * Revision 1.22 2005/02/22 18:09:25 sebastiani
24     * various bugfixes
25     *
26     * Revision 1.21 2005/02/21 14:26:01 sebastiani
27     * TSB bugfixes.
28     *
29     * Revision 1.20 2005/01/10 14:02:12 faber
30     * TRG,AC_1,AC_2,TOF Error Handler reviewed
31     *
32     * Revision 1.19 2005/01/07 15:41:51 sebastiani
33     * fix alarm precedure
34     * add exp 64 delay patch
35     * removed unused sleep
36     *
37     * Revision 1.18 2004/12/20 14:02:04 faber
38     * @LOG entry introduced in all ALM_WriteLog occurrences
39     *
40     * Revision 1.17 2004/12/15 09:12:50 sebastiani
41     * maks contruction well defined in
42     * ALM_FE_Acquisition_Check
43     *
44     * Revision 1.16 2004/12/02 10:43:38 sebastiani
45     * fix AC
46     * fix CAL
47     * fix HK BUFTYPE
48     *
49     * Revision 1.15 2004/11/30 11:51:53 faber
50     * AC+AC2 software moved into AC_1 AC_2
51     * new calibration and initialization for AC
52     * first version,never run
53     *
54     * Revision 1.14 2004/11/19 15:14:52 sebastiani
55     * PRH_EXTERN_{VAR,ARR,TABLE} removed and put them on the autogenerated parameter heeader file
56     *
57     * Revision 1.13 2004/10/18 15:09:24 faber
58     * *** empty log message ***
59     *
60     * Revision 1.12 2004/10/04 13:59:05 alfarano
61     * fixed some return code in run manager
62     *
63     * Revision 1.11 2004/10/01 11:13:21 sebastiani
64     * TIMEOUT S4 calib fix
65     *
66     * Revision 1.10 2004/10/01 08:48:10 sebastiani
67     * TRD alarma renamed TRD_S4 - S4 Alarm renamed S4_POWER
68     * Callback function into DAQ_SendCmd2PIFWaitDAQReply_internal
69     *
70     * Revision 1.9 2004/09/22 15:54:54 alfarano
71     * S4 functions
72     *
73     * Revision 1.8 2004/09/13 14:16:53 faber
74     * ErrorHandler for TOF/TRG + Test function TOF/TRG
75     *
76     * Revision 1.7 2004/08/31 09:08:35 sebastiani
77     * fix warning
78     *
79     * Revision 1.6 2004/08/27 13:30:39 alfarano
80     * cvs header
81     *
82     * Revision 1.1 2003/10/03 16:12:26 faber
83     * *** empty log message ***
84     *
85     *
86     *****************************************************************************/
87     /*============================= Include File ================================*/
88     #include <src/INFN/LU_SourceFileID_INFN.h>
89     #define __FILEID__ _ALM_Alarm_INFN__c
90    
91     #include <src/INFN/PRH_ParamHandler_INFN.h>
92     #include <src/INFN/LU_LogUtility_INFN.h>
93     #include <src/INFN/PRH_ParamHandler_INFN_auto.h>
94     LU_DECL_MASK();
95    
96     #include <src/INFN/DAQ_IDAQ_INFN.h>
97     #include <src/INFN/CM_Common_INFN.h>
98     #include <src/INFN/KHB_Driver_INFN.h>
99     #include <src/INFN/CH_CommandHandler_INFN.h>
100     #include <src/INFN/HK_Manager_INFN.h>
101     #include <src/INFN/HB_HKBuffer_INFN.h>
102     #include <src/INFN/ALM_Alarm_INFN.h>
103     #include <src/INFN/MH_ModeHandler_INFN.h>
104     #include <src/INFN/CAL_Calorimeter_INFN.h>
105     #include <src/INFN/TRK_Tracker_INFN.h>
106     #include <src/INFN/TRD_TransRadDetector_INFN.h>
107     #include <src/INFN/S4_INFN.h>
108     #include <src/INFN/AC_Anticoincidence_INFN.h>
109     #include <src/INFN/TRG_Trigger_INFN.h>
110     #include <src/INFN/TOF_TimeOfFlight_INFN.h>
111     #include <src/INFN/SCM_Manager_INFN.h>
112    
113     /*============================ Global define ================================*/
114    
115    
116    
117    
118    
119    
120     UINT16 ALM_FE_Acquisition_Check()
121     {
122     status_code status;
123     UINT16 mask = KHB_STS_ALARM_IDAQ | KHB_STS_ALARM_TRG;
124     UINT16 status_reg;
125    
126     if(PRH_VAR_TOF_OK)
127     mask|=KHB_STS_ALARM_TOF;
128    
129     if (PRH_VAR_AC_1_OK)
130     mask|=KHB_STS_ALARM_AC_1;
131    
132     if(PRH_VAR_AC_2_OK)
133     mask|=KHB_STS_ALARM_S4_ADC_AC_2;
134    
135     if (PRH_VAR_CAL_OK)
136     mask|=KHB_STS_ALARM_CALO;
137    
138     if (PRH_VAR_TRK_OK)
139     mask|=KHB_STS_ALARM_TRK;
140    
141     if(PRH_VAR_S4_OK && (PRH_VAR_S4_WORKING || PRH_VAR_S4_ATTEMPT ))
142     mask |= KHB_STS_ALARM_S4_ADC_AC_2 | KHB_STS_ALARM_S4_FE;
143    
144     mask &= PRH_VAR_MASK_ACQ_ALARM;
145    
146     status = HK_ReadKHBStatusRegister(&status_reg);
147    
148     if (status/* == CM_RC_KHB_ERROR*/)
149     status_reg = ALM_KHB_INVALID_REGISTER;
150    
151     status_reg &=mask;
152     PRH_VAR_GOM_DURING_ALARM = MH_GetGOM();
153     return status_reg;
154     }
155    
156     status_code ALM_FE_Alarm_Check(UINT16 loc_mask,ALM_VAR_ID trace_id) {
157     return ALM_FE_Alarm_Check_general(loc_mask,trace_id,KHB_ALARM_MASK_ALL);
158     }
159    
160     status_code ALM_FE_Alarm_Check_general(UINT16 loc_mask,ALM_VAR_ID trace_id,UINT32 alarm_mask)
161     {
162     UINT16 status_reg;
163     status_code status;
164    
165     status = HK_ReadKHBStatusRegister(&status_reg);
166    
167     if (status == CM_RC_KHB_ERROR)
168     {
169     /*@LOG ALM_FE_Alarm_Check: error reading KHB status register */
170     ALM_WriteLog(ALM_KHB_REGISTER,status_reg);
171     status_reg = ALM_KHB_INVALID_REGISTER;
172     }
173    
174     status_reg &= ((KHB_STS_ALARM_IDAQ | loc_mask) & PRH_VAR_MASK_ACQ_ALARM);
175    
176     if (status_reg)
177     {
178     PRH_VAR_GOM_DURING_ALARM = MH_GetGOM();
179     /*@LOG ALM_FE_Alarm_Check: KHB - trace */
180     ALM_WriteLog(ALM_TRACE_ID,trace_id);
181     status = ALM_FE_AlarmAction_general(status_reg,alarm_mask);
182     }
183     else
184     status = CM_RC_SUCCESSFUL;
185     return(status);
186     }
187    
188     status_code ALM_FE_AlarmAction(UINT16 khb_reg) {
189     return ALM_FE_AlarmAction_general(khb_reg,KHB_ALARM_MASK_ALL);
190     }
191    
192     status_code ALM_FE_AlarmAction_general(UINT16 khb_reg,UINT32 alarm_mask)
193     {
194     status_code status=CM_RC_SUCCESSFUL;
195     int n;
196     UINT16 idaq_status;
197     BOOL idaq_ok = FALSE;
198     BOOL do_power_off_on = FALSE;
199     BOOL do_reset = FALSE;
200     BYTE old_pkt_type;
201     UINT32 khb_alarm;
202     /*@LOG Alarm Action ALM_KHB_REGISTER - khb_status_reg */
203     ALM_WriteLog(ALM_KHB_REGISTER,khb_reg);
204    
205     if (khb_reg & KHB_STS_ALARM_IDAQ)
206     {
207     n=0;
208     do
209     {
210     status = DAQ_ReadStatusWord(&idaq_status);
211    
212     if (status == CM_RC_KHB_ERROR)
213     {
214     /*@LOG Error reading IDAQ Status Word - status */
215     ALM_WriteLog(ALM_KHB_REGISTER,status);
216     idaq_status = ALM_KHB_INVALID_REGISTER;
217     break;
218     }
219    
220     idaq_ok = ((idaq_status & DAQ_IDAQ_OK) != DAQ_IDAQ_OK);
221     n++;
222     } while ((n < 3) && !idaq_ok);
223     /*@LOG idaq_status register (trace) */
224     ALM_WriteLog(ALM_IDAQ_REGISTER,idaq_status);
225    
226     if (!idaq_ok || status)
227     {
228     status = CM_RC_DO_RESET_IF_ALM;
229     return(status);
230     }
231    
232     if (!(
233     ((idaq_status & (
234     (1<<DAQ_SW_CMD_ERR) |
235     (1<<DAQ_SW_IF_ERR) |
236     (1<<DAQ_SW_ETO) |
237     (1<<DAQ_SW_ATO)
238     )) == (1<<DAQ_SW_ATO)
239     )
240     &&
241     (khb_reg & KHB_STS_ALARM_ALL_FE)
242     )
243     )
244     {
245     status = CM_RC_DO_RESET_IF_ALM;
246     return status;
247     }
248     }
249    
250    
251     if (khb_reg & KHB_STS_ALARM_TRG) {
252     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_TRG_ALARM);
253     status = TRG_Error_Handler();
254     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
255     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
256    
257     PM_pi_SetPktType(old_pkt_type);
258     }
259    
260     if ((khb_reg & KHB_STS_ALARM_AC_1)) {
261     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_AC_1_ALARM);
262     status = AC_Error_Handler(DAQ_FE_AC_1);
263     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
264     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
265     PM_pi_SetPktType(old_pkt_type);
266     }
267    
268     if ((khb_reg & KHB_STS_ALARM_S4_ADC_AC_2 ))
269     {
270     status = HK_ReadKHBAlarmRegister(&khb_alarm);
271    
272     if(status != CM_RC_SUCCESSFUL)
273     return CM_RC_DO_POWER_OFF_ON;
274    
275     khb_alarm &= alarm_mask;
276    
277     if((khb_alarm & KHB_ALARM_AC_2) && PRH_VAR_AC_2_OK){
278     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_AC_2_ALARM);
279     status = AC_Error_Handler(DAQ_FE_AC_2);
280     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
281     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
282     PM_pi_SetPktType(old_pkt_type);
283     }
284    
285     if((khb_alarm & KHB_ALARM_S4_ADC) && PRH_VAR_S4_OK) {
286     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_S4_ALARM);
287     status = S4_Error_Handler();
288     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
289     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
290     PM_pi_SetPktType(old_pkt_type);
291     }
292    
293     }
294    
295     if (khb_reg & KHB_STS_ALARM_S4_FE) {
296     PRH_VAR_S4_WORKING = 0;
297     /*@LOG S4_FE alarm: dont use S4 - khb_reg */
298     LU_INFN_LOG(LU_WARNING|LU_HA,LU_MASK(__FILEID__),__FILEID__,__LINE__,khb_reg);
299     }
300    
301     if ((khb_reg & KHB_STS_ALARM_TOF)) {
302     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_TOF_ALARM);
303     status = TOF_Error_Handler();
304     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
305     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
306    
307     PM_pi_SetPktType(old_pkt_type);
308     }
309    
310     if ((khb_reg & KHB_STS_ALARM_CALO)) {
311     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_CAL_ALARM);
312    
313     status = CAL_Error_Handler();
314     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
315     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
316    
317     PM_pi_SetPktType(old_pkt_type);
318     }
319    
320     if ((khb_reg & KHB_STS_ALARM_TRK)) {
321     old_pkt_type=PM_pi_SetPktType(HB_PKTTYPE_TRK_ALARM);
322    
323     status = TRK_Error_Handler();
324     do_power_off_on |= status == CM_RC_DO_POWER_OFF_ON;
325     do_reset |= status == CM_RC_DO_RESET_IF_ALM;
326    
327     PM_pi_SetPktType(old_pkt_type);
328     }
329     if(do_power_off_on)
330     return CM_RC_DO_POWER_OFF_ON;
331     if(do_reset)
332     return CM_RC_DO_RESET_IF_ALM;
333    
334     return CM_RC_SUCCESSFUL;
335     }
336    
337     status_code ALM_Eto_Reset()
338     {
339     UINT16 status_reg,n,idaq_status;
340     status_code status;
341     BOOL idaq_ok;
342    
343     status = HK_ReadKHBStatusRegister(&status_reg);
344    
345     if (status == CM_RC_KHB_ERROR)
346     {
347     /*@LOG ALM_Eto_Reset(): KHB Status Register reading error - status_reg */
348     ALM_WriteLog(ALM_KHB_REGISTER,status_reg);
349     status_reg = ALM_KHB_INVALID_REGISTER;
350     }
351     /*@LOG ALM_Eto_Reset(): KHB Status Register - status_reg */
352     ALM_WriteLog(ALM_KHB_REGISTER,status_reg);
353    
354     n=0;
355     do
356     {
357     status = DAQ_ReadStatusWord(&idaq_status);
358    
359     if (status == CM_RC_KHB_ERROR)
360     {
361     /*@LOG ALM_Eto_Reset(): error reading IDAQ status word - status */
362     ALM_WriteLog(ALM_KHB_REGISTER,status);
363     idaq_status = ALM_KHB_INVALID_REGISTER;
364     break;
365     }
366     idaq_ok = ((idaq_status & DAQ_IDAQ_OK) != DAQ_IDAQ_OK);
367     n++;
368     } while ((n < 3) && !idaq_ok);
369     /*@LOG ALM_Eto_Reset(): idaq_status */
370     ALM_WriteLog(ALM_IDAQ_REGISTER,idaq_status);
371    
372     return(CM_RC_DO_RESET_IF_ALM);
373     }
374    
375     status_code ALM_Eto_Acquisition()
376     {
377     UINT16 status_reg,n,idaq_status;
378     status_code status=CM_RC_DO_RESET_IF_ALM;
379     BOOL idaq_ok;
380    
381     n=0;
382     do
383     {
384     status = DAQ_ReadStatusWord(&idaq_status);
385    
386     if (status == CM_RC_KHB_ERROR)
387     {
388     /*@LOG ALM_Eto_Reset(): error reading IDAQ status word - status */
389     ALM_WriteLog(ALM_KHB_REGISTER,status);
390     idaq_status = ALM_KHB_INVALID_REGISTER;
391     break;
392     }
393    
394     idaq_ok = ((idaq_status & DAQ_IDAQ_OK) != DAQ_IDAQ_OK);
395    
396     n++;
397     } while ((n < 3) && !idaq_ok);
398     /*@LOG ALM_Eto_Reset(): idaq_status */
399     ALM_WriteLog(ALM_IDAQ_REGISTER,idaq_status);
400    
401     if(!idaq_ok || status)
402     status = CM_RC_DO_RESET_IF_ALM;
403     else
404     {
405     if ((idaq_status & 0x1109) != 0x9)
406     status = CM_RC_DO_RESET_IF_ALM;
407     else
408     {
409     if (++PRH_VAR_TRIG > PRH_VAR_NTRIG)
410     status = CM_RC_DO_POWER_OFF_ON;
411     else
412     status = CM_RC_DO_INIT;
413     }
414     }
415     return(status);
416     }

  ViewVC Help
Powered by ViewVC 1.1.23