MIDAS
Loading...
Searching...
No Matches
feserial.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "midas.h"
#include "rs232.h"
#include "experim.h"
Include dependency graph for feserial.c:

Go to the source code of this file.

Functions

INT frontend_init ()
 Frontend initialization.
 
INT frontend_exit ()
 Frontend exit.
 
INT begin_of_run (INT run_number, char *error)
 Begin of Run.
 
INT end_of_run (INT run_number, char *error)
 End of Run.
 
INT pause_run (INT run_number, char *error)
 Pause Run.
 
INT resume_run (INT run_number, char *error)
 Resume Run.
 
INT frontend_loop ()
 Frontend loop.
 
INT read_trigger_event (char *pevent, INT off)
 
INT read_scaler_event (char *pevent, INT off)
 Scaler event readout.
 
INT poll_event (INT source, INT count, BOOL test)
 Polling routine for events.
 
INT interrupt_configure (INT cmd, INT source, POINTER_T adr)
 Interrupt configuration (not implemented)
 

Variables

charfrontend_name = "feSerial"
 The frontend name (client name) as seen by other MIDAS clients.
 
charfrontend_file_name = __FILE__
 The frontend file name, don't change it.
 
BOOL frontend_call_loop = FALSE
 frontend_loop is called periodically if this variable is TRUE
 
INT display_period = 3000
 a frontend status page is displayed with this frequency in ms
 
INT max_event_size = 10000
 maximum event size produced by this frontend
 
INT max_event_size_frag = 5 * 1024 * 1024
 maximum event size for fragmented events (EQ_FRAGMENTED)
 
INT event_buffer_size = 10 * 10000
 buffer size to hold events
 
void ** info
 
char strin [256]
 
HNDLE hDB
 main ODB handle
 
HNDLE hSet
 
EQUIPMENT equipment []
 Main structure for midas equipment.
 

Function Documentation

◆ begin_of_run()

INT begin_of_run ( INT  run_number,
char error 
)

Begin of Run.

Called every run start transition. Set equipment status in ODB, start acquisition on the modules.

Parameters
[in]run_numberNumber of the run being started
[out]errorCan be used to write a message string to midas.log

Definition at line 157 of file feserial.c.

158{
159 /* put here clear scalers etc. */
160 rs232(CMD_READ, info, strin, 256, 100);
161 return SUCCESS;
162}
void ** info
Definition feserial.c:47
char strin[256]
Definition feserial.c:48
#define CMD_READ
Definition midas.h:812
#define SUCCESS
Definition mcstd.h:54
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ end_of_run()

INT end_of_run ( INT  run_number,
char error 
)

End of Run.

Called every stop run transition. Set equipment status in ODB, stop acquisition on the modules.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log

Definition at line 166 of file feserial.c.

167{
168 return SUCCESS;
169}

◆ frontend_exit()

INT frontend_exit ( void  )

Frontend exit.

Runs at frontend shutdown. Disconnect hardware and set equipment status in ODB

Returns
Midas status code

Definition at line 149 of file feserial.c.

150{
152 return SUCCESS;
153}
#define CMD_EXIT
Definition midas.h:763
Here is the call graph for this function:

◆ frontend_init()

INT frontend_init ( void  )

Frontend initialization.

Runs once at application startup. We initialize the hardware and optical interfaces and set the equipment status in ODB. We also lock the frontend to once physical cpu core.

Returns
Midas status code

Definition at line 125 of file feserial.c.

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}
#define TRIGGER_SETTINGS_STR(_name)
Definition experim.h:166
HNDLE hSet
Definition feserial.c:49
HNDLE hDB
main ODB handle
Definition feserial.c:49
#define DB_SUCCESS
Definition midas.h:631
#define CMD_INIT
Definition midas.h:762
#define MINFO
Definition midas.h:560
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 INT
Definition midas.h:129
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:

◆ frontend_loop()

INT frontend_loop ( void  )

Frontend loop.

If frontend_call_loop is true, this routine gets called when the frontend is idle or once between every event.

Returns
Midas status code

Definition at line 187 of file feserial.c.

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}

◆ interrupt_configure()

INT interrupt_configure ( INT  cmd,
INT  source,
POINTER_T  adr 
)

Interrupt configuration (not implemented)

Routine for interrupt configuration if equipment is set in EQ_INTERRUPT mode. Not implemented right now, returns SUCCESS.

Parameters
[in]cmdCommand for interrupt events (see midas.h)
[in]sourceEquipment index number
[in]adrInterrupt routine (see mfe.c)
Returns
Midas status code

Definition at line 224 of file feserial.c.

225{
226 switch (cmd) {
228 break;
230 break;
232 break;
234 break;
235 }
236 return SUCCESS;
237}
#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

◆ pause_run()

INT pause_run ( INT  run_number,
char error 
)

Pause Run.

Called every pause run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 173 of file feserial.c.

174{
175 return SUCCESS;
176}

◆ poll_event()

INT poll_event ( INT  source,
INT  count,
BOOL  test 
)

Polling routine for events.

Parameters
[in]sourceEvent source (LAM/IRQ)
[in]countLoop count for event polling timeout
[in]testflag used to time the polling
Returns
1 if event is available, 0 if done polling (no event). If test equals TRUE, don't return.

Definition at line 204 of file feserial.c.

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}
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
program test
Definition miniana.f:6
Here is the call graph for this function:

◆ read_scaler_event()

INT read_scaler_event ( char pevent,
INT  off 
)

Scaler event readout.

Placeholder.

Scaler event readout routine. Not used in this example.

Parameters
[in]peventPointer to event buffer
[in]offCaller info (unused here), see mfe.c
Returns
Size of the event

Definition at line 295 of file ebfe.cxx.

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}
#define SLOT_SCLR
Definition ebfe.cxx:63
char Sclx[5]
Definition ebfe.cxx:51
#define N_SCLR
Definition ebfe.cxx:56
#define CRATE
Definition ebfe.cxx:59
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
EXTERNAL void EXPRT cam24i(const int c, const int n, const int a, const int f, DWORD *d)
unsigned int DWORD
Definition mcstd.h:51
#define TID_DWORD
Definition midas.h:336

◆ read_trigger_event()

INT read_trigger_event ( char pevent,
INT  off 
)

Definition at line 241 of file feserial.c.

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}
#define CMD_GETS
Definition midas.h:814
unsigned short int WORD
Definition mcstd.h:49
#define TID_WORD
Definition midas.h:332
INT j
Definition odbhist.cxx:40
Here is the call graph for this function:

◆ resume_run()

INT resume_run ( INT  run_number,
char error 
)

Resume Run.

Called every resume run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 180 of file feserial.c.

181{
182 return SUCCESS;
183}

Variable Documentation

◆ display_period

INT display_period = 3000

a frontend status page is displayed with this frequency in ms

Definition at line 37 of file feserial.c.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"Trigger",
{1, 0,
"SYSTEM",
LAM_SOURCE(0, 0xFFFFFF),
"MIDAS",
TRUE,
500,
0,
0,
0,
"", "", "",},
},
{""}
}
INT read_trigger_event(char *pevent, INT off)
Definition feserial.c:241
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define RO_RUNNING
Definition midas.h:426
#define LAM_SOURCE(c, s)
Definition midas.h:469
#define TRUE
Definition midas.h:182

Main structure for midas equipment.

Definition at line 68 of file feserial.c.

68 {
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};
#define EQ_INTERRUPT
Definition midas.h:416

◆ event_buffer_size

INT event_buffer_size = 10 * 10000

buffer size to hold events

Definition at line 46 of file feserial.c.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

frontend_loop is called periodically if this variable is TRUE

Definition at line 34 of file feserial.c.

◆ frontend_file_name

char* frontend_file_name = __FILE__

The frontend file name, don't change it.

Definition at line 31 of file feserial.c.

◆ frontend_name

char* frontend_name = "feSerial"

The frontend name (client name) as seen by other MIDAS clients.

Definition at line 29 of file feserial.c.

◆ hDB

HNDLE hDB

main ODB handle

Definition at line 49 of file feserial.c.

◆ hSet

HNDLE hSet

Definition at line 49 of file feserial.c.

◆ info

void** info

Definition at line 47 of file feserial.c.

◆ max_event_size

INT max_event_size = 10000

maximum event size produced by this frontend

Definition at line 40 of file feserial.c.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

maximum event size for fragmented events (EQ_FRAGMENTED)

Definition at line 43 of file feserial.c.

◆ strin

char strin[256]

Definition at line 48 of file feserial.c.