MIDAS
Loading...
Searching...
No Matches
ybos_simfe.c
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: ybos_simfe.c
4 Created by: Stefan Ritt/Pierre-A. Amaudruz
5
6 Contents: Experiment specific readout code (user part) of
7 Midas frontend. This example simulates a "trigger
8 event" and a "scaler event" which are filled with
9 random data. The trigger event is filled with
10 two banks (ADC0 and TDC0), the scaler event with
11 one bank (SCLR).
12
13 $Id:$
14
15\********************************************************************/
16
17#include <stdio.h>
18#include "midas.h"
19#include "msystem.h"
20#include "ybos.h"
21#include "mcstd.h"
22#include "esone.h"
23
24/* make frontend functions callable from the C framework */
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/*-- Globals -------------------------------------------------------*/
30#define CRATE 1
31#define LAM_SLOT 1
32 INT poll_val = 10; /* .1% */
33 INT tr1 = 16, tr2 = 200;
34/* The frontend name (client name) as seen by other MIDAS clients */
35 char *frontend_name = "YbosFE";
36/* The frontend file name, don't change it */
38
39/* frontend_loop is called periodically if this variable is TRUE */
41
42/* a frontend status page is displayed with this frequency in ms */
44
45/* maximum event size produced by this frontend */
47
48/* buffer size to hold events */
49 INT event_buffer_size = 10 * 10000;
50
51/*-- Function declarations -----------------------------------------*/
54 INT begin_of_run(INT run_number, char *error);
55 INT end_of_run(INT run_number, char *error);
56 INT pause_run(INT run_number, char *error);
57 INT resume_run(INT run_number, char *error);
59
60 INT read_trigger_event(char *pevent, INT off);
61 INT read_scaler_event(char *pevent, INT off);
62 INT files_dump(char *pevent, INT off);
64/*-- Equipment list ------------------------------------------------*/
65
66#undef USE_INT
67
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 };
131
132#ifdef __cplusplus
133}
134#endif
135/********************************************************************\
136 Callback routines for system transitions
137
138 These routines are called whenever a system transition like start/
139 stop of a run occurs. The routines are called on the following
140 occations:
141
142 frontend_init: When the frontend program is started. This routine
143 should initialize the hardware.
144
145 frontend_exit: When the frontend program is shut down. Can be used
146 to releas any locked resources like memory, commu-
147 nications ports etc.
148
149 begin_of_run: When a new run is started. Clear scalers, open
150 rungates, etc.
151
152 end_of_run: Called on a request to stop a run. Can send
153 end-of-run event and close run gates.
154
155 pause_run: When a run is paused. Should disable trigger events.
156
157 resume_run: When a run is resumed. Should enable trigger events.
158
159 \********************************************************************//*-- Frontend Init -------------------------------------------------*/
161{
162 /* put here hardware initialization */
163 cam_init();
164 return SUCCESS;
165}
166
167/*-- Frontend Exit -------------------------------------------------*/
168
170{
171 cam_exit();
172 return SUCCESS;
173}
174
175/*-- Begin of Run --------------------------------------------------*/
176
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}
188
189/*-- End of Run ----------------------------------------------------*/
190
192{
193 return SUCCESS;
194}
195
196/*-- Pause Run -----------------------------------------------------*/
197
199{
200 return SUCCESS;
201}
202
203/*-- Resuem Run ----------------------------------------------------*/
204
206{
207 return SUCCESS;
208}
209
210/*-- Frontend Loop -------------------------------------------------*/
211
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}
218
219/*------------------------------------------------------------------*/
220
221/********************************************************************\
222
223 Readout routines for different events
224
225\********************************************************************/
226
227/*-- Trigger event routines ----------------------------------------*/
228
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}
244
245/*-- Interrupt configuration for trigger event ---------------------*/
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}
264
265/*-- Event readout -------------------------------------------------*/
266
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}
301
302/*-- Scaler event --------------------------------------------------*/
303
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}
320
321/*-- File event -------------------------------------------------*/
322INT files_dump(char *pevent, INT off)
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}
#define FALSE
Definition cfortran.h:309
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 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 int EXPRT cam_init(void)
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_exit(void)
EXTERNAL void EXPRT cam_interrupt_detach(const int c, const int n)
unsigned short int WORD
Definition mcstd.h:49
unsigned int DWORD
Definition mcstd.h:51
#define SUCCESS
Definition mcstd.h:54
#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
static std::string q(const char *s)
INT run_number[2]
Definition mana.cxx:246
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define PTYPE
Definition midas.h:170
#define TRUE
Definition midas.h:182
#define resume_run
#define pause_run
program test
Definition miniana.f:6
INT j
Definition odbhist.cxx:40
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
double d
Definition system.cxx:1311
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition ybos_simfe.c:40
INT tr2
Definition ybos_simfe.c:33
INT poll_val
Definition ybos_simfe.c:32
INT max_event_size
maximum event size produced by this frontend
Definition ybos_simfe.c:46
INT frontend_exit()
Frontend exit.
Definition ybos_simfe.c:169
INT files_dump(char *pevent, INT off)
Definition ybos_simfe.c:322
#define LAM_SLOT
Definition ybos_simfe.c:31
INT frontend_init()
Frontend initialization.
Definition ybos_simfe.c:160
INT event_buffer_size
buffer size to hold events
Definition ybos_simfe.c:49
INT poll_event(INT source, INT count, BOOL test)
Polling routine for events.
Definition ybos_simfe.c:229
INT read_trigger_event(char *pevent, INT off)
Definition ybos_simfe.c:267
INT interrupt_configure(INT cmd, INT source[], PTYPE adr)
Definition ybos_simfe.c:246
EQUIPMENT equipment[]
Main structure for midas equipment.
Definition ybos_simfe.c:68
INT tr1
Definition ybos_simfe.c:33
INT display_period
a frontend status page is displayed with this frequency in ms
Definition ybos_simfe.c:43
char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
Definition ybos_simfe.c:35
char * frontend_file_name
The frontend file name, don't change it.
Definition ybos_simfe.c:37
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition ybos_simfe.c:177
#define CRATE
Definition ybos_simfe.c:30
INT frontend_loop()
Frontend loop.
Definition ybos_simfe.c:212
INT end_of_run(INT run_number, char *error)
End of Run.
Definition ybos_simfe.c:191
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition ybos_simfe.c:304
INT gbl_run_number
Definition ybos_simfe.c:63