MIDAS
Loading...
Searching...
No Matches
tinyfe.c
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: tinyfe.c
4 Created by: Stefan Ritt
5
6 Contents: Experiment specific readout code (user part) of
7 Midas frontend. This example demonstrate the
8 implementation of the sub-events packing.
9
10 $Id:$
11
12\********************************************************************/
13
14#include <stdio.h>
15#include <stdlib.h>
16#include "midas.h"
17#include "msystem.h"
18#include "mcstd.h"
19
20/* make frontend functions callable from the C framework */
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*-- Globals -------------------------------------------------------*/
26/* The frontend name (client name) as seen by other MIDAS clients */
27 char *frontend_name = "tinyfe";
28
29/* The frontend file name, don't change it */
30 char *frontend_file_name = __FILE__;
31
32/* frontend_loop is called periodically if this variable is TRUE */
34
35/* a frontend status page is displayed with this frequency in ms */
37
38/* maximum event size produced by this frontend */
40
41/* maximum event size for fragmented events (EQ_FRAGMENTED) */
42 INT max_event_size_frag = 5 * 1024 * 1024;
43
44/* buffer size to hold events */
45 INT event_buffer_size = 10 * 10000;
46
47
48/* MY HV structure */
50
51/*-- Function declarations -----------------------------------------*/
52
55 INT begin_of_run(INT run_number, char *error);
56 INT end_of_run(INT run_number, char *error);
57 INT pause_run(INT run_number, char *error);
58 INT resume_run(INT run_number, char *error);
60 INT read_tiny_event(char *pevent, INT off);
61/*-- Equipment list ------------------------------------------------*/
62
63#undef USE_INT
64
66
67 {"Tiny", /* equipment name */
68 3, 0, /* event ID, trigger mask */
69 "SYSTEM", /* event buffer */
70 EQ_POLLED, /* equipment type */
71 1, /* event source */
72 "MIDAS", /* format */
73 TRUE, /* enabled */
74 RO_RUNNING, /* read when running and on transitions */
75 500, /* poll 500ms */
76 0, /* stop run after this event limit */
77 10, /* number of sub events */
78 0, /* log history */
79 "", "", "",
80 read_tiny_event, /* readout routine */
81 NULL, NULL, /* keep null */
82 NULL, /* init string */
83 },
84
85 {""}
86 };
87
88#ifdef __cplusplus
89}
90#endif
91/********************************************************************\
92 Callback routines for system transitions
93
94 These routines are called whenever a system transition like start/
95 stop of a run occurs. The routines are called on the following
96 occations:
97
98 frontend_init: When the frontend program is started. This routine
99 should initialize the hardware.
100
101 frontend_exit: When the frontend program is shut down. Can be used
102 to releas any locked resources like memory, commu-
103 nications ports etc.
104
105 begin_of_run: When a new run is started. Clear scalers, open
106 rungates, etc.
107
108 end_of_run: Called on a request to stop a run. Can send
109 end-of-run event and close run gates.
110
111 pause_run: When a run is paused. Should disable trigger events.
112
113 resume_run: When a run is resumed. Should enable trigger events.
114
115 \********************************************************************//*-- Frontend Init -------------------------------------------------*/
117{
118 return SUCCESS;
119}
120
121/*-- Frontend Exit -------------------------------------------------*/
122
124{
125 return SUCCESS;
126}
127
128/*-- Begin of Run --------------------------------------------------*/
129
131{
132 return SUCCESS;
133}
134
135/*-- End of Run ----------------------------------------------------*/
136
138{
139 return SUCCESS;
140}
141
142/*-- Pause Run -----------------------------------------------------*/
143
145{
146 return SUCCESS;
147}
148
149/*-- Resuem Run ----------------------------------------------------*/
150
152{
153 return SUCCESS;
154}
155
156/*-- Frontend Loop -------------------------------------------------*/
158{
159 return SUCCESS;
160}
161
162/*------------------------------------------------------------------*/
163
164/********************************************************************\
165
166 Readout routines for different events
167
168\********************************************************************/
169
170/*-- Trigger event routines ----------------------------------------*/
171
173/* Polling routine for events. Returns TRUE if event
174 is available. If test equals TRUE, don't return. The test
175 flag is used to time the polling */
176{
177 int i;
178 DWORD lam;
179
180 for (i = 0; i < count; i++) {
181 cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
182
183// To force a LAM independently of the driver.
184 lam = 1;
185 if (lam & LAM_SOURCE_STATION(source))
186 if (!test)
187 return lam;
188 }
189
190 return 0;
191}
192
193/*-- Interrupt configuration ---------------------------------------*/
194
196{
197 switch (cmd) {
199 break;
201 break;
203 break;
205 break;
206 }
207 return SUCCESS;
208}
209
210
211/*-- Tiny event --------------------------------------------------*/
212#define NWORDS 3
213
215{
216 static WORD *pdata = NULL;
217 static WORD sub_counter = 0;
218 // Super event structure
219 if (offset == 0) { // FIRST event of the Super event
220 bk_init(pevent);
221 bk_create(pevent, "SUPR", TID_WORD, &pdata);
222 sub_counter = 1;
223 } else if (offset == -1) { // CLOSE Super event
224 bk_close(pevent, pdata);
225 return bk_size(pevent);
226 }
227 // READ event
228 *pdata++ = 0xB0E;
229 *pdata++ = sub_counter++;
230 *pdata++ = 0xE0E;
231
232 if (offset == 0) {
233 // Compute the proper event length on the FIRST event in the Super Event
234 // NWORDS correspond to the !! NWORDS WORD above !!
235 // sizeof(BANK_HEADER) + sizeof(BANK) will make the 16 bytes header
236 // sizeof(WORD) is defined by the TID_WORD in bk_create()
237 return NWORDS * sizeof(WORD) + sizeof(BANK_HEADER) + sizeof(BANK);
238 } else {
239 // Return the data section size only
240 // sizeof(WORD) is defined by the TID_WORD in bk_create()
241 return NWORDS * sizeof(WORD);
242 }
243}
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 cam_lam_read(const int c, DWORD *lam)
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 TID_WORD
Definition midas.h:332
#define RO_RUNNING
Definition midas.h:426
INT run_number[2]
Definition mana.cxx:246
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
static int offset
Definition mgd.cxx:1500
INT HNDLE
Definition midas.h:132
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
Definition midas.h:1215
BOOL frontend_call_loop
Definition tinyfe.c:33
INT max_event_size
Definition tinyfe.c:39
INT frontend_exit()
Frontend exit.
Definition tinyfe.c:123
INT frontend_init()
Frontend initialization.
Definition tinyfe.c:116
#define NWORDS
Definition tinyfe.c:212
INT event_buffer_size
Definition tinyfe.c:45
INT read_tiny_event(char *pevent, INT off)
Definition tinyfe.c:214
INT max_event_size_frag
Definition tinyfe.c:42
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition tinyfe.c:195
HNDLE hKey
Definition tinyfe.c:49
INT poll_event(INT source, INT count, BOOL test)
Definition tinyfe.c:172
EQUIPMENT equipment[]
Definition tinyfe.c:65
HNDLE hDB
main ODB handle
Definition tinyfe.c:49
INT display_period
Definition tinyfe.c:36
char * frontend_name
Definition tinyfe.c:27
char * frontend_file_name
Definition tinyfe.c:30
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition tinyfe.c:130
INT frontend_loop()
Frontend loop.
Definition tinyfe.c:157
INT end_of_run(INT run_number, char *error)
End of Run.
Definition tinyfe.c:137