MIDAS
Loading...
Searching...
No Matches
ybos_simfe.c File Reference
#include <stdio.h>
#include "midas.h"
#include "msystem.h"
#include "ybos.h"
#include "mcstd.h"
#include "esone.h"
Include dependency graph for ybos_simfe.c:

Go to the source code of this file.

Macros

#define CRATE   1
 
#define LAM_SLOT   1
 

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_trigger_event (char *pevent, INT off)
 
INT read_scaler_event (char *pevent, INT off)
 Scaler event readout.
 
INT files_dump (char *pevent, INT off)
 
INT poll_event (INT source, INT count, BOOL test)
 Polling routine for events.
 
INT interrupt_configure (INT cmd, INT source[], PTYPE adr)
 

Variables

INT poll_val = 10
 
INT tr1 = 16
 
INT tr2 = 200
 
charfrontend_name = "YbosFE"
 The frontend name (client name) as seen by other MIDAS clients.
 
charfrontend_file_name = __FILE__
 The frontend file name, don't change it.
 
BOOL frontend_call_loop = FALSE
 frontend_loop is called periodically if this variable is TRUE
 
INT display_period = 3000
 a frontend status page is displayed with this frequency in ms
 
INT max_event_size = 10000
 maximum event size produced by this frontend
 
INT event_buffer_size = 10 * 10000
 buffer size to hold events
 
INT gbl_run_number
 
EQUIPMENT equipment []
 Main structure for midas equipment.
 

Macro Definition Documentation

◆ CRATE

#define CRATE   1

Definition at line 30 of file ybos_simfe.c.

◆ LAM_SLOT

#define LAM_SLOT   1

Definition at line 31 of file ybos_simfe.c.

Function Documentation

◆ 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 177 of file ybos_simfe.c.

178{
179 int ext, q;
180 unsigned long d;
181 /* put here clear scalers etc. */
183
184 cdreg(&ext, 1, 2, 3, 4);
185 cfsa(16, ext, &d, &q);
186 return SUCCESS;
187}
EXTERNAL INLINE void cfsa(const int f, const int ext, unsigned long *d, int *q)
EXTERNAL INLINE void cdreg(int *ext, const int b, const int c, const int n, const int a)
#define SUCCESS
Definition mcstd.h:54
static std::string q(const char *s)
INT run_number[2]
Definition mana.cxx:246
double d
Definition system.cxx:1311
INT gbl_run_number
Definition ybos_simfe.c:63
Here is the call graph for this function:

◆ 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 191 of file ybos_simfe.c.

192{
193 return SUCCESS;
194}

◆ files_dump()

INT files_dump ( char pevent,
INT  off 
)

Definition at line 322 of file ybos_simfe.c.

323{
324 feodb_file_dump(equipment, "File", pevent, gbl_run_number, "trigger");
325
326 /* return 0 because I handle the "event send" by myself */
327 return 0;
328}
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
EQUIPMENT equipment[]
Main structure for midas equipment.
Definition ybos_simfe.c:68
Here is the call graph for this function:

◆ 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 169 of file ybos_simfe.c.

170{
171 cam_exit();
172 return SUCCESS;
173}
EXTERNAL void EXPRT cam_exit(void)
Here is the call graph for this function:

◆ 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 160 of file ybos_simfe.c.

161{
162 /* put here hardware initialization */
163 cam_init();
164 return SUCCESS;
165}
EXTERNAL int EXPRT cam_init(void)
Here is the call graph for this function:
Here is the caller 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 212 of file ybos_simfe.c.

213{
214 /* if frontend_call_loop is true, this routine gets called when
215 the frontend is idle or between every event */
216 return SUCCESS;
217}

◆ interrupt_configure()

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

Definition at line 246 of file ybos_simfe.c.

247{
248 switch (cmd) {
251 break;
254 break;
256 cam_interrupt_attach(CRATE, LAM_SLOT, (void (*)(void)) adr);
257 break;
260 break;
261 }
262 return SUCCESS;
263}
#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
EXTERNAL void EXPRT cam_interrupt_disable(const int c)
EXTERNAL void EXPRT cam_interrupt_enable(const int c)
EXTERNAL void EXPRT cam_interrupt_attach(const int c, const int n, void(*isr)(void))
EXTERNAL void EXPRT cam_interrupt_detach(const int c, const int n)
#define LAM_SLOT
Definition ybos_simfe.c:31
#define CRATE
Definition ybos_simfe.c:30
Here is the call graph for this function:

◆ 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 198 of file ybos_simfe.c.

199{
200 return SUCCESS;
201}

◆ poll_event()

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

Polling routine for events.

Parameters
[in]sourceEvent source (LAM/IRQ)
[in]countLoop count for event polling timeout
[in]testflag used to time the polling
Returns
1 if event is available, 0 if done polling (no event). If test equals TRUE, don't return.

Definition at line 229 of file ybos_simfe.c.

230{
231 INT i;
232
233 for (i = 0; i < count; i++) {
234 /* read the LAM register of the Crate controller to find out if
235 ANY station has raised the LAM line.
236 */
237
238 if (rand() % 10000 < poll_val) /* Ignore LAM if not LAM_STATION */
239 if (!test)
240 return TRUE;
241 }
242 return FALSE;
243}
#define FALSE
Definition cfortran.h:309
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
program test
Definition miniana.f:6
INT poll_val
Definition ybos_simfe.c:32
Here is the call graph for this function:

◆ read_scaler_event()

INT read_scaler_event ( char pevent,
INT  off 
)

Scaler event readout.

Placeholder.

Scaler event readout routine. Not used in this example.

Parameters
[in]peventPointer to event buffer
[in]offCaller info (unused here), see mfe.c
Returns
Size of the event

Definition at line 304 of file ybos_simfe.c.

305{
306 DWORD i;
307 DWORD *pbkdat;
308
309 ybk_init((DWORD *) pevent);
310
311 /* collect user hardware data */
312 /*---- USER Stuff ----*/
313 ybk_create((DWORD *) pevent, "SCAL", I4_BKTYPE, (DWORD *) (&pbkdat));
314 for (i = 0; i < 16; i++)
315 *pbkdat++ = (DWORD) (0xff + i) & 0xFFF;
316 ybk_close((DWORD *) pevent, pbkdat);
317
318 return (ybk_size((DWORD *) pevent));
319}
unsigned int DWORD
Definition mcstd.h:51
Here is the call graph for this function:

◆ read_trigger_event()

INT read_trigger_event ( char pevent,
INT  off 
)

Definition at line 267 of file ybos_simfe.c.

268{
269 INT i, j;
270 double *pbkdat;
271 ybk_init((DWORD *) pevent);
272
273 j = rand() % 100;
274 if (j < tr1)
275 j = tr1;
276 else if (j > tr2)
277 j = tr2;
278 ybk_create((DWORD *) pevent, "ADC0", I4_BKTYPE, (DWORD *) (&pbkdat));
279 for (i = 0; i < j; i++)
280 *((DWORD *) pbkdat)++ = i & 0xFFF;
281 ybk_close((DWORD *) pevent, pbkdat);
282
283 ybk_create((DWORD *) pevent, "TDC0", I2_BKTYPE, (DWORD *) (&pbkdat));
284 for (i = 0; i < 16; i++)
285 *((WORD *) pbkdat)++ = (WORD) (0x10 + i) & 0xFFFF;
286 ybk_close((DWORD *) pevent, pbkdat);
287
288 ybk_create_chaos((DWORD *) pevent, "OTHR", I2_BKTYPE, (DWORD *) (&pbkdat));
289 for (i = 0; i < 16; i++)
290 *((WORD *) pbkdat)++ = (WORD) (0x20 + i + 1) & 0xFFFF;
292
293 ybk_create((DWORD *) pevent, "EFGH", D8_BKTYPE, (DWORD *) (&pbkdat));
294 for (i = 0; i < 6; i++)
295 *pbkdat++ = (double) i + 10.;
296 ybk_close((DWORD *) pevent, pbkdat);
297 /* END OF EVENT */
298
299 return (ybk_size((DWORD *) pevent));
300}
unsigned short int WORD
Definition mcstd.h:49
INT j
Definition odbhist.cxx:40
INT tr2
Definition ybos_simfe.c:33
INT tr1
Definition ybos_simfe.c:33
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 205 of file ybos_simfe.c.

206{
207 return SUCCESS;
208}

Variable Documentation

◆ display_period

INT display_period = 3000

a frontend status page is displayed with this frequency in ms

Definition at line 43 of file ybos_simfe.c.

◆ equipment

EQUIPMENT equipment[]

Main structure for midas equipment.

Definition at line 68 of file ybos_simfe.c.

68 {
69
70 {"Trigger", /* equipment name */
71 1, 0, /* event ID, trigger mask */
72 "SYSTEM", /* event buffer */
73#ifdef USE_INT
74 EQ_INTERRUPT, /* equipment type */
75#else
76 EQ_POLLED, /* equipment type */
77#endif
78 0, /* event source */
79 "YBOS", /* format */
80 TRUE, /* enabled */
81 RO_RUNNING, /* read only when running */
82 500, /* poll for 500ms */
83 0, /* stop run after this event limit */
84 0, /* number of sub event */
85 0, /* don't log history */
86 "", "", "",
87 read_trigger_event, /* readout routine */
88 NULL, /* keep null */
89 NULL /* init string */
90 },
91
92 {"Scaler", /* equipment name */
93 2, 0, /* event ID, trigger mask */
94 "SYSTEM", /* event buffer */
95 EQ_PERIODIC, /* equipment type */
96 0, /* event source */
97 "YBOS", /* format */
98 TRUE, /* enabled */
99 RO_RUNNING | RO_TRANSITIONS | /* read when running and on transitions */
100 RO_ODB, /* and update ODB */
101 10000, /* read every 10 sec */
102 0, /* stop run after this event limit */
103 0, /* number of sub event */
104 0, /* log history */
105 "", "", "",
106 read_scaler_event, /* readout routine */
107 NULL, /* keep null */
108 NULL /* init string */
109 },
110
111 {"File", /* equipment name */
112 7, 0x0000, /* event ID, mask */
113 "SYSTEM", /* event buffer */
114 EQ_PERIODIC, /* equipment type */
115 0, /* event source */
116 "YBOS", /* format */
117 FALSE, /* enabled */
118 RO_BOR, /* read only at BOR */
119 10000, /* read every 10 sec */
120 0, /* stop run after this event limit */
121 0, /* number of sub event */
122 0, /* don't log history */
123 "", "", "",
124 files_dump, /* file dump */
125 NULL, /* keep null */
126 NULL /* init string */
127 },
128
129 {""}
130 };
#define EQ_POLLED
Definition midas.h:415
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define RO_BOR
Definition midas.h:429
#define EQ_INTERRUPT
Definition midas.h:416
#define RO_TRANSITIONS
Definition midas.h:434
#define RO_RUNNING
Definition midas.h:426
INT files_dump(char *pevent, INT off)
Definition ybos_simfe.c:322
INT read_trigger_event(char *pevent, INT off)
Definition ybos_simfe.c:267
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition ybos_simfe.c:304

◆ event_buffer_size

INT event_buffer_size = 10 * 10000

buffer size to hold events

Definition at line 49 of file ybos_simfe.c.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

frontend_loop is called periodically if this variable is TRUE

Definition at line 40 of file ybos_simfe.c.

◆ frontend_file_name

char* frontend_file_name = __FILE__

The frontend file name, don't change it.

Definition at line 37 of file ybos_simfe.c.

◆ frontend_name

char* frontend_name = "YbosFE"

The frontend name (client name) as seen by other MIDAS clients.

Definition at line 35 of file ybos_simfe.c.

◆ gbl_run_number

INT gbl_run_number

Definition at line 63 of file ybos_simfe.c.

◆ max_event_size

INT max_event_size = 10000

maximum event size produced by this frontend

Definition at line 46 of file ybos_simfe.c.

◆ poll_val

INT poll_val = 10

Definition at line 32 of file ybos_simfe.c.

◆ tr1

INT tr1 = 16

Definition at line 33 of file ybos_simfe.c.

◆ tr2

INT tr2 = 200

Definition at line 33 of file ybos_simfe.c.