MIDAS
Loading...
Searching...
No Matches
mantrigfe.c
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: mantrigfe.c
4 Created by: Stefan Ritt
5
6 Contents: Experiment specific readout code (user part) of
7 Midas frontend. This example demonstrantes
8 the implementation of the manual trigger of
9 a periodic event in this case.
10
11 $Id:$
12
13\********************************************************************/
14
15#include <stdio.h>
16#include <stdlib.h>
17#include "midas.h"
18#include "mcstd.h"
19#include "experim.h"
20
21/* make frontend functions callable from the C framework */
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/*-- Globals -------------------------------------------------------*/
27
28/* The frontend name (client name) as seen by other MIDAS clients */
29 char *frontend_name = "mantrigfe";
30/* The frontend file name, don't change it */
31 char *frontend_file_name = __FILE__;
32
33/* frontend_loop is called periodically if this variable is TRUE */
35
36/* a frontend status page is displayed with this frequency in ms */
38
39/* maximum event size produced by this frontend */
41
42/* maximum event size for fragmented events (EQ_FRAGMENTED) */
43 INT max_event_size_frag = 5 * 1024 * 1024;
44
45/* buffer size to hold events */
46 INT event_buffer_size = 10 * 10000;
47
48/* number of channels */
49#define N_ADC 4
50#define N_TDC 8
51#define N_SCLR 4
52
53/* CAMAC crate and slots */
54#define CRATE 0
55#define SLOT_IO 23
56#define SLOT_ADC 1
57#define SLOT_TDC 2
58#define SLOT_SCLR 3
59
60/*-- Function declarations -----------------------------------------*/
61
64 INT begin_of_run(INT run_number, char *error);
65 INT end_of_run(INT run_number, char *error);
66 INT pause_run(INT run_number, char *error);
67 INT resume_run(INT run_number, char *error);
69
70 INT read_mantrig_event(char *pevent, INT off);
71
72/*-- Bank definitions ----------------------------------------------*/
73
74 ADC0_BANK_STR(adc0_bank_str);
75
77 {"ADC0", TID_STRUCT, sizeof(ADC0_BANK), adc0_bank_str}
78 ,
79 {"TDC0", TID_WORD, N_TDC, NULL}
80 ,
81
82 {""}
83 ,
84 };
85
87 {"SCLR", TID_DWORD, N_ADC, NULL}
88 ,
89 {""}
90 ,
91 };
92
93/*-- Equipment list ------------------------------------------------*/
94
95#undef USE_INT
96
98 {"mantrig", /* equipment name */
99 2, 0, /* event ID, trigger mask */
100 "SYSTEM", /* event buffer */
101 EQ_PERIODIC | EQ_MANUAL_TRIG, /* equipment type */
102 0, /* event source */
103 "MIDAS", /* format */
104 TRUE, /* enabled */
105 RO_RUNNING | RO_TRANSITIONS | /* read when running and on transitions */
106 RO_ODB, /* and update ODB */
107 30000, /* read every 30 sec */
108 0, /* stop run after this event limit */
109 0, /* number of sub events */
110 0, /* log history */
111 "", "", "",
112 read_mantrig_event, /* readout routine */
113 NULL, NULL,
114 scaler_bank_list, /* bank list */
115 }
116 ,
117
118 {""}
119 };
120
121#ifdef __cplusplus
122}
123#endif
124/********************************************************************\
125 Callback routines for system transitions
126
127 These routines are called whenever a system transition like start/
128 stop of a run occurs. The routines are called on the following
129 occations:
130
131 frontend_init: When the frontend program is started. This routine
132 should initialize the hardware.
133
134 frontend_exit: When the frontend program is shut down. Can be used
135 to releas any locked resources like memory, commu-
136 nications ports etc.
137
138 begin_of_run: When a new run is started. Clear scalers, open
139 rungates, etc.
140
141 end_of_run: Called on a request to stop a run. Can send
142 end-of-run event and close run gates.
143
144 pause_run: When a run is paused. Should disable trigger events.
145
146 resume_run: When a run is resumed. Should enable trigger events.
147
148 \********************************************************************//*-- Frontend Init -------------------------------------------------*/
150{
151 /* hardware initialization */
152
153 cam_init();
156
157 /* enable LAM in IO unit */
158 camc(CRATE, SLOT_IO, 0, 26);
159
160 /* enable LAM in crate controller */
162
163 /* reset external LAM Flip-Flop */
164 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
165 camo(CRATE, SLOT_IO, 1, 16, 0);
166
167 return SUCCESS;
168}
169
170/*-- Frontend Exit -------------------------------------------------*/
171
173{
174 return SUCCESS;
175}
176
177/*-- Begin of Run --------------------------------------------------*/
178
180{
181 /* put here clear scalers etc. */
182
183 return SUCCESS;
184}
185
186/*-- End of Run ----------------------------------------------------*/
187
189{
190 return SUCCESS;
191}
192
193/*-- Pause Run -----------------------------------------------------*/
194
196{
197 return SUCCESS;
198}
199
200/*-- Resuem Run ----------------------------------------------------*/
201
203{
204 return SUCCESS;
205}
206
207/*-- Frontend Loop -------------------------------------------------*/
208
210{
211 /* if frontend_call_loop is true, this routine gets called when
212 the frontend is idle or once between every event */
213 return SUCCESS;
214}
215
216/*------------------------------------------------------------------*/
217
218/********************************************************************\
219
220 Readout routines for different events
221
222\********************************************************************/
223
224/*-- Trigger event routines ----------------------------------------*/
225
227/* Polling routine for events. Returns TRUE if event
228 is available. If test equals TRUE, don't return. The test
229 flag is used to time the polling */
230{
231 int i;
232 DWORD lam;
233
234 for (i = 0; i < count; i++) {
235 cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
236
237 if (lam & LAM_SOURCE_STATION(source))
238 if (!test)
239 return lam;
240 }
241
242 return 0;
243}
244
245/*-- Interrupt configuration ---------------------------------------*/
246
248{
249 switch (cmd) {
251 break;
253 break;
255 break;
257 break;
258 }
259 return SUCCESS;
260}
261
262
263/*-- mantrig event --------------------------------------------------*/
264
265INT read_mantrig_event(char *pevent, INT off)
266{
267 DWORD *pdata, a;
268
269 /* init bank structure */
270 bk_init(pevent);
271
272 /* create SCLR bank */
273 bk_create(pevent, "SCLR", TID_DWORD, &pdata);
274
275 /* read scaler bank */
276 for (a = 0; a < N_SCLR; a++)
277 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
278
279 bk_close(pevent, pdata);
280
281 return bk_size(pevent);
282}
#define FALSE
Definition cfortran.h:309
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
#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 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 int DWORD
Definition mcstd.h:51
#define SUCCESS
Definition mcstd.h:54
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define TID_WORD
Definition midas.h:332
#define TID_STRUCT
Definition midas.h:348
#define EQ_MANUAL_TRIG
Definition midas.h:419
#define RO_TRANSITIONS
Definition midas.h:434
#define RO_RUNNING
Definition midas.h:426
#define TID_DWORD
Definition midas.h:336
INT run_number[2]
Definition mana.cxx:246
BOOL frontend_call_loop
Definition mantrigfe.c:34
#define SLOT_SCLR
Definition mantrigfe.c:58
INT read_mantrig_event(char *pevent, INT off)
Definition mantrigfe.c:265
INT max_event_size
Definition mantrigfe.c:40
INT frontend_exit()
Frontend exit.
Definition mantrigfe.c:172
INT frontend_init()
Frontend initialization.
Definition mantrigfe.c:149
INT event_buffer_size
Definition mantrigfe.c:46
INT max_event_size_frag
Definition mantrigfe.c:43
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition mantrigfe.c:247
BANK_LIST trigger_bank_list[]
Definition mantrigfe.c:76
#define N_TDC
Definition mantrigfe.c:50
ADC0_BANK_STR(adc0_bank_str)
#define SLOT_IO
Definition mantrigfe.c:55
INT poll_event(INT source, INT count, BOOL test)
Definition mantrigfe.c:226
EQUIPMENT equipment[]
Definition mantrigfe.c:97
INT display_period
Definition mantrigfe.c:37
char * frontend_name
Definition mantrigfe.c:29
char * frontend_file_name
Definition mantrigfe.c:31
#define N_SCLR
Definition mantrigfe.c:51
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition mantrigfe.c:179
#define CRATE
Definition mantrigfe.c:54
INT frontend_loop()
Frontend loop.
Definition mantrigfe.c:209
INT end_of_run(INT run_number, char *error)
End of Run.
Definition mantrigfe.c:188
#define N_ADC
Definition mantrigfe.c:49
BANK_LIST scaler_bank_list[]
Definition mantrigfe.c:86
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 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