MIDAS
Loading...
Searching...
No Matches
deferredfe.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "midas.h"
#include "mcstd.h"
#include "experim.h"
Include dependency graph for deferredfe.c:

Go to the source code of this file.

Macros

#define N_ADC   4
 
#define N_TDC   8
 
#define N_SCLR   4
 
#define CRATE   0
 
#define SLOT_IO   23
 
#define SLOT_ADC   1
 
#define SLOT_TDC   2
 
#define SLOT_SCLR   3
 

Functions

INT frontend_init ()
 Frontend initialization.
 
INT frontend_exit ()
 Frontend exit.
 
INT begin_of_run (INT run_number, char *error)
 Begin of Run.
 
INT end_of_run (INT run_number, char *error)
 End of Run.
 
INT pause_run (INT run_number, char *error)
 Pause Run.
 
INT resume_run (INT run_number, char *error)
 Resume Run.
 
INT frontend_loop ()
 Frontend loop.
 
INT read_deferred_event (char *pevent, INT off)
 
 ADC0_BANK_STR (adc0_bank_str)
 
BOOL wait_end_cycle (int transition, BOOL first)
 
INT poll_event (INT source, INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source, PTYPE adr)
 

Variables

charfrontend_name = "deferredfe"
 
charfrontend_file_name = __FILE__
 
BOOL frontend_call_loop = FALSE
 
INT display_period = 000
 
INT max_event_size = 10000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT event_buffer_size = 10 * 10000
 
BANK_LIST trigger_bank_list []
 
BANK_LIST scaler_bank_list []
 
EQUIPMENT equipment []
 
int pseudo_delay = 0
 
BOOL transition_PS_requested = FALSE
 
BOOL end_of_mcs_cycle = FALSE
 

Macro Definition Documentation

◆ CRATE

#define CRATE   0

Definition at line 54 of file deferredfe.c.

◆ N_ADC

#define N_ADC   4

Definition at line 49 of file deferredfe.c.

◆ N_SCLR

#define N_SCLR   4

Definition at line 51 of file deferredfe.c.

◆ N_TDC

#define N_TDC   8

Definition at line 50 of file deferredfe.c.

◆ SLOT_ADC

#define SLOT_ADC   1

Definition at line 56 of file deferredfe.c.

◆ SLOT_IO

#define SLOT_IO   23

Definition at line 55 of file deferredfe.c.

◆ SLOT_SCLR

#define SLOT_SCLR   3

Definition at line 58 of file deferredfe.c.

◆ SLOT_TDC

#define SLOT_TDC   2

Definition at line 57 of file deferredfe.c.

Function Documentation

◆ ADC0_BANK_STR()

ADC0_BANK_STR ( adc0_bank_str  )

◆ begin_of_run()

INT begin_of_run ( INT  run_number,
char error 
)

Begin of Run.

Called every run start transition. Set equipment status in ODB, start acquisition on the modules.

Parameters
[in]run_numberNumber of the run being started
[out]errorCan be used to write a message string to midas.log

Definition at line 229 of file deferredfe.c.

230{
231 /* put here clear scalers etc. */
232 pseudo_delay = 0;
233 return SUCCESS;
234}
int pseudo_delay
Definition deferredfe.c:163
#define SUCCESS
Definition mcstd.h:54

◆ end_of_run()

INT end_of_run ( INT  run_number,
char error 
)

End of Run.

Called every stop run transition. Set equipment status in ODB, stop acquisition on the modules.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log

Definition at line 238 of file deferredfe.c.

239{
240 return SUCCESS;
241}

◆ frontend_exit()

INT frontend_exit ( void  )

Frontend exit.

Runs at frontend shutdown. Disconnect hardware and set equipment status in ODB

Returns
Midas status code

Definition at line 222 of file deferredfe.c.

223{
224 return SUCCESS;
225}

◆ frontend_init()

INT frontend_init ( void  )

Frontend initialization.

Runs once at application startup. We initialize the hardware and optical interfaces and set the equipment status in ODB. We also lock the frontend to once physical cpu core.

Returns
Midas status code

Definition at line 191 of file deferredfe.c.

192{
193 // register for deferred transition
196
197
198 /* hardware initialization */
199
200 cam_init();
203
204 /* enable LAM in IO unit */
205 camc(CRATE, SLOT_IO, 0, 26);
206
207 /* enable LAM in crate controller */
209
210 /* reset external LAM Flip-Flop */
211 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
212 camo(CRATE, SLOT_IO, 1, 16, 0);
213
214 /* print message and return FE_ERR_HW if frontend should not be started */
215
216
217 return SUCCESS;
218}
BOOL wait_end_cycle(int transition, BOOL first)
Definition deferredfe.c:168
#define SLOT_IO
Definition deferredfe.c:55
#define CRATE
Definition deferredfe.c:54
INT cm_register_deferred_transition(INT transition, BOOL(*func)(INT, BOOL))
Definition midas.cxx:3837
EXTERNAL void EXPRT cam_lam_enable(const int c, const int n)
EXTERNAL int EXPRT cam_init(void)
EXTERNAL void EXPRT camo(const int c, const int n, const int a, const int f, WORD d)
EXTERNAL void EXPRT cam_crate_clear(const int c)
EXTERNAL void EXPRT camc(const int c, const int n, const int a, const int f)
EXTERNAL void EXPRT cam_crate_zinit(const int c)
#define TR_PAUSE
Definition midas.h:407
#define TR_STOP
Definition midas.h:406
Here is the call graph for this function:

◆ frontend_loop()

INT frontend_loop ( void  )

Frontend loop.

If frontend_call_loop is true, this routine gets called when the frontend is idle or once between every event.

Returns
Midas status code

Definition at line 259 of file deferredfe.c.

260{
261 /* if frontend_call_loop is true, this routine gets called when
262 the frontend is idle or once between every event */
263 return SUCCESS;
264}

◆ interrupt_configure()

INT interrupt_configure ( INT  cmd,
INT  source,
PTYPE  adr 
)

Definition at line 297 of file deferredfe.c.

298{
299 switch (cmd) {
301 break;
303 break;
305 break;
307 break;
308 }
309 return SUCCESS;
310}
#define CMD_INTERRUPT_ATTACH
Definition midas.h:822
#define CMD_INTERRUPT_DISABLE
Definition midas.h:821
#define CMD_INTERRUPT_ENABLE
Definition midas.h:820
#define CMD_INTERRUPT_DETACH
Definition midas.h:823

◆ pause_run()

INT pause_run ( INT  run_number,
char error 
)

Pause Run.

Called every pause run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 245 of file deferredfe.c.

246{
247 return SUCCESS;
248}

◆ poll_event()

INT poll_event ( INT  source,
INT  count,
BOOL  test 
)

Definition at line 276 of file deferredfe.c.

280{
281 int i;
282 DWORD lam;
283
284 for (i = 0; i < count; i++) {
286
287 if (lam & LAM_SOURCE_STATION(source))
288 if (!test)
289 return lam;
290 }
291
292 return 0;
293}
EXTERNAL void cam_lam_read(const int c, DWORD *lam)
unsigned int DWORD
Definition mcstd.h:51
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
#define LAM_SOURCE_STATION(s)
Definition midas.h:487
#define LAM_SOURCE_CRATE(c)
Definition midas.h:481
program test
Definition miniana.f:6
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ read_deferred_event()

INT read_deferred_event ( char pevent,
INT  off 
)

Definition at line 313 of file deferredfe.c.

314{
315 DWORD *pdata, a;
316
317 /* init bank structure */
318 bk_init(pevent);
319
320
321 /* create SCLR bank */
322 bk_create(pevent, "SCLR", TID_DWORD, &pdata);
323
324 /* read scaler bank */
325 for (a = 0; a < N_SCLR; a++)
326 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
327
328 bk_close(pevent, pdata);
329
331 // transition acknowledged, but...
332 // carry on until hardware condition satisfied
333 // ...
334 if (pseudo_delay++ < 3) {
335 // Ignore transition
336 printf("Transition ignored, ");
337 } else {
338 // Time to do transition
339 printf("End of cycle... perform transition\n");
341 }
342 }
343 printf("Event ID:%d - Event#: %d\n", EVENT_ID(pevent), SERIAL_NUMBER(pevent));
344 return bk_size(pevent);
345}
#define SLOT_SCLR
Definition deferredfe.c:58
BOOL transition_PS_requested
Definition deferredfe.c:164
BOOL end_of_mcs_cycle
Definition deferredfe.c:165
#define N_SCLR
Definition deferredfe.c:51
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
INT bk_size(const void *event)
Definition midas.cxx:16495
EXTERNAL void EXPRT cam24i(const int c, const int n, const int a, const int f, DWORD *d)
#define TID_DWORD
Definition midas.h:336
#define TRUE
Definition midas.h:182
#define SERIAL_NUMBER(e)
Definition midas.h:880
#define EVENT_ID(e)
Definition midas.h:873
Here is the call graph for this function:

◆ resume_run()

INT resume_run ( INT  run_number,
char error 
)

Resume Run.

Called every resume run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 252 of file deferredfe.c.

253{
254 return SUCCESS;
255}

◆ wait_end_cycle()

BOOL wait_end_cycle ( int  transition,
BOOL  first 
)

Definition at line 168 of file deferredfe.c.

169{
170 // Get there after every
171 if (first) {
172 // Get there as soon as transition is requested
174 printf("Transition requested...\n");
175 // Defer the transition now
176 return FALSE;
177 }
178 // Check user flag
179 if (end_of_mcs_cycle) {
180 // User flag set, ready to perform deferred transition now
183 return TRUE;
184 } else {
185 // User not ready for transition, defers it...
186 return FALSE;
187 }
188}
#define FALSE
Definition cfortran.h:309
Here is the caller graph for this function:

Variable Documentation

◆ display_period

INT display_period = 000

Definition at line 37 of file deferredfe.c.

◆ end_of_mcs_cycle

BOOL end_of_mcs_cycle = FALSE

Definition at line 165 of file deferredfe.c.

◆ equipment

EQUIPMENT equipment[]

Definition at line 97 of file deferredfe.c.

97 {
98
99 {"Deferred", /* equipment name */
100 2, 0, /* event ID, trigger mask */
101 "SYSTEM", /* event buffer */
102 EQ_PERIODIC, /* equipment type */
103 0, /* event source */
104 "MIDAS", /* format */
105 TRUE, /* enabled */
106 RO_RUNNING | /* read when running */
107 RO_ODB, /* and update ODB */
108 2000, /* read every 2 sec */
109 0, /* stop run after this event limit */
110 0, /* number of sub events */
111 0, /* log history */
112 "", "", "",
113 read_deferred_event, /* readout routine */
114 NULL, NULL,
115 NULL, /* bank list */
116 }
117 ,
118
119 {"Junk", /* equipment name */
120 2, 0, /* event ID, trigger mask */
121 "SYSTEM", /* event buffer */
122 EQ_PERIODIC, /* equipment type */
123 0, /* event source */
124 "MIDAS", /* format */
125 TRUE, /* enabled */
126 RO_RUNNING | /* read when running */
127 RO_ODB, /* and update ODB */
128 2000, /* read every 2 sec */
129 }
130 ,
131
132 {""}
133 };
INT read_deferred_event(char *pevent, INT off)
Definition deferredfe.c:313
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define RO_RUNNING
Definition midas.h:426

◆ event_buffer_size

INT event_buffer_size = 10 * 10000

Definition at line 46 of file deferredfe.c.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

Definition at line 34 of file deferredfe.c.

◆ frontend_file_name

char* frontend_file_name = __FILE__

Definition at line 31 of file deferredfe.c.

◆ frontend_name

char* frontend_name = "deferredfe"

Definition at line 29 of file deferredfe.c.

◆ max_event_size

INT max_event_size = 10000

Definition at line 40 of file deferredfe.c.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 43 of file deferredfe.c.

◆ pseudo_delay

int pseudo_delay = 0

Definition at line 163 of file deferredfe.c.

◆ scaler_bank_list

BANK_LIST scaler_bank_list[]
Initial value:
= {
{"SCLR", TID_DWORD, N_ADC, NULL}
,
{""}
,
}
#define N_ADC
Definition deferredfe.c:49

Definition at line 86 of file deferredfe.c.

86 {
87 {"SCLR", TID_DWORD, N_ADC, NULL}
88 ,
89 {""}
90 ,
91 };

◆ transition_PS_requested

BOOL transition_PS_requested = FALSE

Definition at line 164 of file deferredfe.c.

◆ trigger_bank_list

BANK_LIST trigger_bank_list[]
Initial value:
= {
{"ADC0", TID_STRUCT, sizeof(ADC0_BANK), adc0_bank_str}
,
{"TDC0", TID_WORD, N_TDC, NULL}
,
{""}
,
}
#define N_TDC
Definition deferredfe.c:50
#define TID_WORD
Definition midas.h:332
#define TID_STRUCT
Definition midas.h:348

Definition at line 76 of file deferredfe.c.

76 {
77 {"ADC0", TID_STRUCT, sizeof(ADC0_BANK), adc0_bank_str}
78 ,
79 {"TDC0", TID_WORD, N_TDC, NULL}
80 ,
81
82 {""}
83 ,
84 };