MIDAS
Loading...
Searching...
No Matches
ebfe.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: ebfe.c
4 Created by: Stefan Ritt / Pierre-Andre Amaudruz
5
6 Contents: Frontend code for mevb example.
7 Source code taken from the frontend.c example.
8 Modification of:
9 *frontend_name
10 Trigger eqp name : Trigger1
11 Scaler eqp name : Scaler1
12 Trigger eqp buffer name : BUF1
13 Added cm_yield(10) in the poll_event()
14 data rate reduction.
15
16 Simplified the event generator and should be linked
17 with the camacnul driver for the mevb example.
18 But nothing prevent to generate real event using
19 proper driver.
20
21 $Id$
22
23\********************************************************************/
24
25#include <stdio.h>
26#include <stdlib.h>
27#include "midas.h"
28#include "mcstd.h"
29
30/*-- Globals -------------------------------------------------------*/
31
32 /* The frontend name (client name) as seen by other MIDAS clients */
33 const char *frontend_name = "ebfe";
34 /* The frontend file name, don't change it */
35 const char *frontend_file_name = __FILE__;
36
37 /* frontend_loop is called periodically if this variable is TRUE */
39
40 /* a frontend status page is displayed with this frequency in ms */
42
43 /* maximum event size produced by this frontend */
46
47 /* buffer size to hold events */
49
50 /* bank name list */
51 char Adcx[5], Tdcx[5], Sclx[5];
52
53/* number of channels */
54#define N_ADC 8
55#define N_TDC 8
56#define N_SCLR 8
57
58/* CAMAC crate and slots */
59#define CRATE 0
60#define SLOT_IO 23
61#define SLOT_ADC 1
62#define SLOT_TDC 2
63#define SLOT_SCLR 3
64
65/*-- Function declarations -----------------------------------------*/
66
69 INT begin_of_run(INT run_number, char *error);
70 INT end_of_run(INT run_number, char *error);
71 INT pause_run(INT run_number, char *error);
72 INT resume_run(INT run_number, char *error);
74
75 INT read_trigger_event(char *pevent, INT off);
76 INT read_scaler_event(char *pevent, INT off);
77 extern INT get_frontend_index();
78
79/*-- Equipment list ------------------------------------------------*/
80
81#undef USE_INT
83
85
86 {"Eqp%0d", /* equipment name */
87 {2, 0, /* event ID, trigger mask */
88 "BUF%0d", /* event buffer */
89#ifdef USE_INT
90 EQ_INTERRUPT, /* equipment type */
91#else
92 EQ_POLLED | EQ_EB, /* equipment type */
93#endif
94 LAM_SOURCE(0, 0xFFFFFF), /* event source crate 0, all stations */
95 "MIDAS", /* format */
96 TRUE, /* enabled */
97 RO_RUNNING | /* read only when running */
98 RO_ODB, /* and update ODB */
99 500, /* poll for 500ms */
100 0, /* stop run after this event limit */
101 0, /* number of sub events */
102 0, /* don't log history */
103 "", "", "",},
104 read_trigger_event, /* readout routine */
105 },
106 {""}
107 };
108
109/********************************************************************\
110 Callback routines for system transitions
111
112 These routines are called whenever a system transition like start/
113 stop of a run occurs. The routines are called on the following
114 occations:
115
116 frontend_init: When the frontend program is started. This routine
117 should initialize the hardware.
118
119 frontend_exit: When the frontend program is shut down. Can be used
120 to releas any locked resources like memory, commu-
121 nications ports etc.
122
123 begin_of_run: When a new run is started. Clear scalers, open
124 rungates, etc.
125
126 end_of_run: Called on a request to stop a run. Can send
127 end-of-run event and close run gates.
128
129 pause_run: When a run is paused. Should disable trigger events.
130
131 resume_run: When a run is resumed. Should enable trigger events.
132\********************************************************************/
134{
135 /* Compose expected bank name under Ebuilder */
136 sprintf(Adcx, "AD%02d", get_frontend_index());
137 sprintf(Tdcx, "TC%02d", get_frontend_index());
138 sprintf(Sclx, "SC%02d", get_frontend_index());
139
140 /* hardware initialization */
141
142 cam_init();
145
146 /* enable LAM in IO unit */
147 camc(CRATE, SLOT_IO, 0, 26);
148
149 /* enable LAM in crate controller */
151
152 /* reset external LAM Flip-Flop */
153 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
154 camo(CRATE, SLOT_IO, 1, 16, 0);
155
156 /* print message and return FE_ERR_HW if frontend should not be started */
157
158 return SUCCESS;
159}
160
161/*-- Frontend Exit -------------------------------------------------*/
163{
164 return SUCCESS;
165}
166
167/*-- Begin of Run --------------------------------------------------*/
169{
170 /* put here clear scalers etc. */
171
172 return SUCCESS;
173}
174
175/*-- End of Run ----------------------------------------------------*/
177{
178 return SUCCESS;
179}
180
181/*-- Pause Run -----------------------------------------------------*/
183{
184 return SUCCESS;
185}
186
187/*-- Resume Run ----------------------------------------------------*/
189{
190 return SUCCESS;
191}
192
193/*-- Frontend Loop -------------------------------------------------*/
195{
196 /* if frontend_call_loop is true, this routine gets called when
197 the frontend is idle or once between every event */
198 cm_yield(100);
199 return SUCCESS;
200}
201
202/*------------------------------------------------------------------*/
203/********************************************************************\
204
205Readout routines for different events
206
207\********************************************************************/
208
209/*-- Trigger event routines ----------------------------------------*/
210
212/* Polling routine for events. Returns TRUE if event
213is available. If test equals TRUE, don't return. The test
214flag is used to time the polling */
215{
216 int i;
217 DWORD lam;
218
219 for (i = 0; i < count; i++) {
220 cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
221 cm_yield(10);
222 if (lam & LAM_SOURCE_STATION(source))
223 if (!test)
224 return lam;
225 }
226
227 return 0;
228}
229
230/*-- Interrupt configuration ---------------------------------------*/
231
233{
234 switch (cmd) {
236 break;
238 break;
240 break;
242 break;
243 }
244 return SUCCESS;
245}
246
247/*-- Event readout -------------------------------------------------*/
248
249INT read_trigger_event(char *pevent, INT off)
250{
251 WORD *pdata, a;
252
253 /* init bank structure */
254 bk_init(pevent);
255
256 /* create ADC bank */
257 bk_create(pevent, Adcx, TID_WORD, (void**)&pdata);
258
259 /* read ADC bank */
260 for (a = 0; a < N_ADC; a++)
261 *pdata++ = a + 10;
262
263 /* clear ADC */
264 camc(CRATE, SLOT_ADC, 0, 9);
265
266 bk_close(pevent, pdata);
267
268 /* create TDC bank */
269 bk_create(pevent, Tdcx, TID_WORD, (void**)&pdata);
270
271 /* read TDC bank */
272 for (a = 0; a < N_TDC; a++)
273 *pdata++ = a + 20;
274
275 /* clear TDC */
276 camc(CRATE, SLOT_TDC, 0, 9);
277
278 bk_close(pevent, pdata);
279
280 /* clear IO unit LAM */
281 camc(CRATE, SLOT_IO, 0, 10);
282
283 /* clear LAM in crate controller */
285
286 /* reset external LAM Flip-Flop */
287 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
288 camo(CRATE, SLOT_IO, 1, 16, 0);
289
290 return bk_size(pevent);
291}
292
293/*-- Scaler event --------------------------------------------------*/
294
295INT read_scaler_event(char *pevent, INT off)
296{
297 DWORD *pdata, a;
298
299 /* init bank structure */
300 bk_init(pevent);
301
302 /* create SCLR bank */
303 bk_create(pevent, Sclx, TID_DWORD, (void**)&pdata);
304
305 /* read scaler bank */
306 for (a = 0; a < N_SCLR; a++)
307 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
308
309 bk_close(pevent, pdata);
310
311 return bk_size(pevent);
312}
BOOL frontend_call_loop
Definition ebfe.cxx:38
INT get_frontend_index()
Definition mfe.cxx:2391
const char * frontend_file_name
Definition ebfe.cxx:35
#define SLOT_SCLR
Definition ebfe.cxx:63
INT max_event_size
Definition ebfe.cxx:44
INT frontend_exit()
Frontend exit.
Definition ebfe.cxx:162
char Sclx[5]
Definition ebfe.cxx:51
INT frontend_init()
Frontend initialization.
Definition ebfe.cxx:133
INT event_buffer_size
Definition ebfe.cxx:48
INT max_event_size_frag
Definition ebfe.cxx:45
INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
Definition ebfe.cxx:232
#define SLOT_ADC
Definition ebfe.cxx:61
BOOL equipment_common_overwrite
Definition ebfe.cxx:82
#define N_TDC
Definition ebfe.cxx:55
char Tdcx[5]
Definition ebfe.cxx:51
#define SLOT_IO
Definition ebfe.cxx:60
INT poll_event(INT source, INT count, BOOL test)
Definition ebfe.cxx:211
#define SLOT_TDC
Definition ebfe.cxx:62
INT read_trigger_event(char *pevent, INT off)
Definition ebfe.cxx:249
EQUIPMENT equipment[]
Definition ebfe.cxx:84
const char * frontend_name
Definition ebfe.cxx:33
INT display_period
Definition ebfe.cxx:41
#define N_SCLR
Definition ebfe.cxx:56
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition ebfe.cxx:168
#define CRATE
Definition ebfe.cxx:59
INT frontend_loop()
Frontend loop.
Definition ebfe.cxx:194
INT end_of_run(INT run_number, char *error)
End of Run.
Definition ebfe.cxx:176
#define N_ADC
Definition ebfe.cxx:54
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition ebfe.cxx:295
char Adcx[5]
Definition ebfe.cxx: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
INT cm_yield(INT millisec)
Definition midas.cxx:5642
#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_lam_enable(const int c, const int n)
EXTERNAL int EXPRT cam_init(void)
EXTERNAL void EXPRT cam_lam_clear(const int c, const int n)
EXTERNAL void EXPRT cam24i(const int c, const int n, const int a, const int f, DWORD *d)
EXTERNAL void cam_lam_read(const int c, DWORD *lam)
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)
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 EQ_EB
Definition midas.h:421
#define RO_ODB
Definition midas.h:438
#define TID_WORD
Definition midas.h:332
#define EQ_INTERRUPT
Definition midas.h:416
#define RO_RUNNING
Definition midas.h:426
#define TID_DWORD
Definition midas.h:336
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 LAM_SOURCE(c, s)
Definition midas.h:469
#define TRUE
Definition midas.h:182
#define POINTER_T
Definition midas.h:166
#define LAM_SOURCE_STATION(s)
Definition midas.h:487
#define LAM_SOURCE_CRATE(c)
Definition midas.h:481
#define resume_run
#define pause_run
program test
Definition miniana.f:6