MIDAS
Loading...
Searching...
No Matches
feserial.c
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: feserial.c
4 Created by:
5 Contents: Experiment specific readout code (user part) of
6 Midas frontend. This example simulates a "trigger
7 event" and a "scaler event" which are filled with
8 CAMAC or random data. The trigger event is filled
9 with two banks (ADC0 and TDC0), the scaler event
10 with one bank (SCLR).
11
12 $Id$
13\********************************************************************/
14
15#include <stdio.h>
16#include <stdlib.h>
17#include "midas.h"
18#include "rs232.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 */
29char *frontend_name = "feSerial";
30/* The frontend file name, don't change it */
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) */
43INT max_event_size_frag = 5 * 1024 * 1024;
44
45/* buffer size to hold events */
47 void **info;
48char strin[256];
50/*-- Function declarations -----------------------------------------*/
51
54INT begin_of_run(INT run_number, char *error);
55INT end_of_run(INT run_number, char *error);
56INT pause_run(INT run_number, char *error);
57INT resume_run(INT run_number, char *error);
59
60INT read_trigger_event(char *pevent, INT off);
61INT read_scaler_event(char *pevent, INT off);
62
63
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_PERIODIC, /* equipment type */
77#endif
78 LAM_SOURCE(0, 0xFFFFFF), /* event source crate 0, all stations */
79 "MIDAS", /* format */
80 TRUE, /* enabled */
81 RO_RUNNING | /* read only when running */
82 RO_ODB, /* and update ODB */
83 500, /* poll for 500ms */
84 0, /* stop run after this event limit */
85 0, /* number of sub events */
86 0, /* don't log history */
87 "", "", "",},
88 read_trigger_event, /* readout routine */
89 },
90
91 {""}
92};
93
94#ifdef __cplusplus
95}
96#endif
97
98/********************************************************************\
99 Callback routines for system transitions
100
101 These routines are called whenever a system transition like start/
102 stop of a run occurs. The routines are called on the following
103 occations:
104
105 frontend_init: When the frontend program is started. This routine
106 should initialize the hardware.
107
108 frontend_exit: When the frontend program is shut down. Can be used
109 to releas any locked resources like memory, commu-
110 nications ports etc.
111
112 begin_of_run: When a new run is started. Clear scalers, open
113 rungates, etc.
114
115 end_of_run: Called on a request to stop a run. Can send
116 end-of-run event and close run gates.
117
118 pause_run: When a run is paused. Should disable trigger events.
119
120 resume_run: When a run is resumed. Should enable trigger events.
121\********************************************************************/
122
123/*-- Frontend Init -------------------------------------------------*/
124
126{
127 /* hardware initialization */
128 INT status;
129 char set_str[80];
130 /* Book Setting space */
132
133 /* Map /equipment/Trigger/settings for the sequencer */
134 sprintf(set_str, "/Equipment/Trigger/Settings");
137 if (status != DB_SUCCESS)
138 cm_msg(MINFO,"FE","Key %s not found", set_str);
139
140
142 /* print message and return FE_ERR_HW if frontend should not be started */
143
144 return SUCCESS;
145}
146
147/*-- Frontend Exit -------------------------------------------------*/
148
150{
152 return SUCCESS;
153}
154
155/*-- Begin of Run --------------------------------------------------*/
156
158{
159 /* put here clear scalers etc. */
160 rs232(CMD_READ, info, strin, 256, 100);
161 return SUCCESS;
162}
163
164/*-- End of Run ----------------------------------------------------*/
165
167{
168 return SUCCESS;
169}
170
171/*-- Pause Run -----------------------------------------------------*/
172
174{
175 return SUCCESS;
176}
177
178/*-- Resuem Run ----------------------------------------------------*/
179
181{
182 return SUCCESS;
183}
184
185/*-- Frontend Loop -------------------------------------------------*/
186
188{
189 /* if frontend_call_loop is true, this routine gets called when
190 the frontend is idle or once between every event */
191 return SUCCESS;
192}
193
194/*------------------------------------------------------------------*/
195
196/********************************************************************\
197
198 Readout routines for different events
199
200\********************************************************************/
201
202/*-- Trigger event routines ----------------------------------------*/
203
205/* Polling routine for events. Returns TRUE if event
206 is available. If test equals TRUE, don't return. The test
207 flag is used to time the polling */
208{
209 int i;
210
211 for (i = 0; i < count; i++) {
212// cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
213
214// if (lam & LAM_SOURCE_STATION(source))
215 if (!test)
216 return 1;
217 }
218
219 return 0;
220}
221
222/*-- Interrupt configuration ---------------------------------------*/
223
225{
226 switch (cmd) {
228 break;
230 break;
232 break;
234 break;
235 }
236 return SUCCESS;
237}
238
239/*-- Event readout -------------------------------------------------*/
240
242{
243 WORD *pdata, a;
244 INT j;
245
246 /* init bank structure */
247 bk_init(pevent);
248
249 /* create structured ADC0 bank */
250 bk_create(pevent, "ADC0", TID_WORD, &pdata);
251 /* Use following code to "simulate" data */
252 for (a = 0; a < 3; a++)
253 *pdata++ = rand() % 1024;
254 rs232(CMD_GETS, info, strin, 256, 0, 500);
255 for (j=0;j<256;j++) {
256 if (strin[j] != 0)
257 *pdata++ = strin[j];
258 }
259
260 bk_close(pevent, pdata);
261
262 /* create variable length TDC bank */
263 bk_create(pevent, "TDC0", TID_WORD, &pdata);
264 /* Use following code to "simulate" data */
265 for (a = 0; a < 3; a++)
266 *pdata++ = rand() % 1024;
267 bk_close(pevent, pdata);
268
269 return bk_size(pevent);
270}
271
#define FALSE
Definition cfortran.h:309
#define TRIGGER_SETTINGS_STR(_name)
Definition experim.h:166
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition feserial.c:34
INT max_event_size
maximum event size produced by this frontend
Definition feserial.c:40
INT frontend_exit()
Frontend exit.
Definition feserial.c:149
HNDLE hSet
Definition feserial.c:49
INT frontend_init()
Frontend initialization.
Definition feserial.c:125
INT event_buffer_size
buffer size to hold events
Definition feserial.c:46
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition feserial.c:43
INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
Interrupt configuration (not implemented)
Definition feserial.c:224
void ** info
Definition feserial.c:47
char strin[256]
Definition feserial.c:48
INT poll_event(INT source, INT count, BOOL test)
Polling routine for events.
Definition feserial.c:204
INT read_trigger_event(char *pevent, INT off)
Definition feserial.c:241
EQUIPMENT equipment[]
Main structure for midas equipment.
Definition feserial.c:68
HNDLE hDB
main ODB handle
Definition feserial.c:49
INT display_period
a frontend status page is displayed with this frequency in ms
Definition feserial.c:37
char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
Definition feserial.c:29
char * frontend_file_name
The frontend file name, don't change it.
Definition feserial.c:31
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition feserial.c:157
INT frontend_loop()
Frontend loop.
Definition feserial.c:187
INT end_of_run(INT run_number, char *error)
End of Run.
Definition feserial.c:166
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition ebfe.cxx:295
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 DB_SUCCESS
Definition midas.h:631
#define CMD_GETS
Definition midas.h:814
#define CMD_INIT
Definition midas.h:762
#define CMD_INTERRUPT_ATTACH
Definition midas.h:822
#define CMD_READ
Definition midas.h:812
#define CMD_INTERRUPT_DISABLE
Definition midas.h:821
#define CMD_INTERRUPT_ENABLE
Definition midas.h:820
#define CMD_EXIT
Definition midas.h:763
#define CMD_INTERRUPT_DETACH
Definition midas.h:823
unsigned short int WORD
Definition mcstd.h:49
#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 MINFO
Definition midas.h:560
#define EQ_INTERRUPT
Definition midas.h:416
#define RO_RUNNING
Definition midas.h:426
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
std::string strcomb1(const char **list)
Definition odb.cxx:598
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
INT run_number[2]
Definition mana.cxx:246
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
INT HNDLE
Definition midas.h:132
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 resume_run
#define pause_run
program test
Definition miniana.f:6
INT j
Definition odbhist.cxx:40
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24