MIDAS
Loading...
Searching...
No Matches
fevme.cxx File Reference
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
#include <assert.h>
#include "midas.h"
#include "mvmestd.h"
#include "vme/v792.h"
#include "v895.h"
#include "vme/v1190B.h"
Include dependency graph for fevme.cxx:

Go to the source code of this file.

Macros

#define HAVE_V792
 
#define HAVE_V895
 
#define HAVE_V1190B
 

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_event (char *pevent, INT off)
 
int mvme_read16 (int addr)
 
int mvme_read32 (int addr)
 
void encodeU32 (char *pdata, uint32_t value)
 
uint32_t odbReadUint32 (const char *name, int index, uint32_t defaultValue=0)
 
int enable_trigger ()
 
int disable_trigger ()
 
INT init_vme_modules ()
 
INT poll_event (INT source, INT count, BOOL test)
 Polling routine for events.
 
INT interrupt_configure (INT cmd, INT source, PTYPE adr)
 
int read_v792 (int base, const char *bname, char *pevent, int nchan)
 
int read_tdc (int base, char *pevent)
 

Variables

charfrontend_name = "fevme"
 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 = 000
 a frontend status page is displayed with this frequency in ms
 
INT max_event_size = 100*1024
 maximum event size produced by this frontend
 
INT max_event_size_frag = 1024*1024
 maximum event size for fragmented events (EQ_FRAGMENTED)
 
INT event_buffer_size = 200*1024
 buffer size to hold events
 
INT run_state
 
HNDLE hDB
 main ODB handle
 
EQUIPMENT equipment []
 Main structure for midas equipment.
 
MVME_INTERFACEgVme = 0
 
int gVmeioBase = 0x780000
 
int gAdcBase = 0x110000
 
int gDisBase [] = { 0xE00000, 0 }
 
int gTdcBase = 0xf10000
 
int gVF48base = 0xa00000
 
static int gHaveRun = 0
 

Macro Definition Documentation

◆ HAVE_V1190B

#define HAVE_V1190B

Definition at line 24 of file fevme.cxx.

◆ HAVE_V792

#define HAVE_V792

Definition at line 22 of file fevme.cxx.

◆ HAVE_V895

#define HAVE_V895

Definition at line 23 of file fevme.cxx.

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 284 of file fevme.cxx.

285{
286 gHaveRun = 1;
287 printf("begin run %d\n",run_number);
288
290
292 return SUCCESS;
293}
INT init_vme_modules()
Definition fevme.cxx:202
int enable_trigger()
Definition fevme.cxx:185
static int gHaveRun
Definition fevme.cxx:268
#define SUCCESS
Definition mcstd.h:54
INT run_number[2]
Definition mana.cxx:246
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:

◆ disable_trigger()

int disable_trigger ( )

Definition at line 194 of file fevme.cxx.

195{
196#ifdef HAVE_VMEIO
198#endif
199 return 0;
200}
MVME_INTERFACE * gVme
Definition fevme.cxx:142
int gVmeioBase
Definition fevme.cxx:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable_trigger()

int enable_trigger ( )

Definition at line 185 of file fevme.cxx.

186{
187#ifdef HAVE_VMEIO
189#endif
190 return 0;
191}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeU32()

void encodeU32 ( char pdata,
uint32_t  value 
)

Definition at line 162 of file fevme.cxx.

163{
164 pdata[0] = (value&0x000000FF)>>0;
165 pdata[1] = (value&0x0000FF00)>>8;
166 pdata[2] = (value&0x00FF0000)>>16;
167 pdata[3] = (value&0xFF000000)>>24;
168}
double value[100]
Definition odbhist.cxx:42
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 296 of file fevme.cxx.

297{
298 static bool gInsideEndRun = false;
299
300 if (gInsideEndRun)
301 {
302 printf("breaking recursive end_of_run()\n");
303 return SUCCESS;
304 }
305
306 gInsideEndRun = true;
307
308 gHaveRun = 0;
309 printf("end run %d\n",run_number);
311
312 gInsideEndRun = false;
313
314 return SUCCESS;
315}
int disable_trigger()
Definition fevme.cxx:194
Here is the call graph for this function:

◆ 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 272 of file fevme.cxx.

273{
274 gHaveRun = 0;
276
278
279 return SUCCESS;
280}
int EXPRT mvme_close(MVME_INTERFACE *vme)
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 251 of file fevme.cxx.

252{
253 int status;
254
257
258 status = mvme_open(&gVme,0);
260
262
264
265 return status;
266}
int EXPRT mvme_open(MVME_INTERFACE **vme, int idx)
int EXPRT mvme_set_am(MVME_INTERFACE *vme, int am)
#define MVME_AM_A24_ND
Definition mvmestd.h:120
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 334 of file fevme.cxx.

335{
336 /* if frontend_call_loop is true, this routine gets called when
337 the frontend is idle or once between every event */
338 return SUCCESS;
339}

◆ init_vme_modules()

INT init_vme_modules ( )

Definition at line 202 of file fevme.cxx.

203{
204#ifdef HAVE_VMEIO
207 printf("VMEIO at 0x%x CSR is 0x%x\n",gVmeioBase,vmeio_CsrRead(gVme,gVmeioBase));
208#endif
209
210#ifdef HAVE_V792
213#endif
214
215#ifdef HAVE_V895
216 for (int i=0; gDisBase[i] != 0; i++)
217 {
219
220 v895_writeReg16(gVme,gDisBase[i],0x40,255); // width 0-7
221 v895_writeReg16(gVme,gDisBase[i],0x42,255); // width 8-15
222 v895_writeReg16(gVme,gDisBase[i],0x48,56); // majority
223 v895_writeReg16(gVme,gDisBase[i],0x4A,0xFFFF); // enable all channels
224 //v895_writeReg8(gVme,gDisBase[i],0x4A,0x0000); // enable all channels
225 for (int j=0; j<16; j++)
226 {
227 int thr_mV = 12;
228 v895_writeReg16(gVme,gDisBase[i],j*2,thr_mV); // threshold in mV
229 }
230 //v895_TestPulse(gVme,gDisBase[i]); // fire test pulse
231
232 //v895_writeReg16(gVme,gDisBase[i],0*2,250); // threshold in mV
233 }
234#endif
235
236#ifdef HAVE_V1190B
239#endif
240
241#ifdef HAVE_VF48
243 printf("VF48 at 0x%x CSR is 0x%x\n",gVF48base,VF48_CsrRead(gVme,gVF48base));
244#endif
245
246 return SUCCESS;
247}
int gVF48base
Definition fevme.cxx:148
int gDisBase[]
Definition fevme.cxx:146
int gAdcBase
Definition fevme.cxx:145
int gTdcBase
Definition fevme.cxx:147
INT i
Definition mdump.cxx:32
INT j
Definition odbhist.cxx:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ interrupt_configure()

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

Definition at line 382 of file fevme.cxx.

383{
384 switch (cmd) {
386 break;
388 break;
390 break;
392 break;
393 }
394 return SUCCESS;
395}
#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

◆ mvme_read16()

int mvme_read16 ( int  addr)

Definition at line 150 of file fevme.cxx.

151{
153 return mvme_read_value(gVme, addr);
154}
unsigned int EXPRT mvme_read_value(MVME_INTERFACE *vme, mvme_addr_t vme_addr)
int EXPRT mvme_set_dmode(MVME_INTERFACE *vme, int dmode)
#define MVME_DMODE_D16
Definition mvmestd.h:81
char addr[128]
Definition mcnaf.cxx:104
Here is the call graph for this function:

◆ mvme_read32()

int mvme_read32 ( int  addr)

Definition at line 156 of file fevme.cxx.

157{
159 return mvme_read_value(gVme, addr);
160}
#define MVME_DMODE_D32
Definition mvmestd.h:82
Here is the call graph for this function:

◆ odbReadUint32()

uint32_t TMidasOnline::odbReadUint32 ( const char name,
int  index,
uint32_t  defaultValue = 0 
)

Definition at line 170 of file fevme.cxx.

171{
172 int status;
173 uint32_t value = 0;
174 int size = 4;
175 HNDLE hkey;
177 if (status != SUCCESS)
178 {
179 cm_msg (MERROR,frontend_name,"Cannot read \'%s\'[%d] from odb, status %d",name,index,status);
180 return defaultValue;
181 }
182 return value;
183}
HNDLE hDB
main ODB handle
Definition mana.cxx:207
char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
Definition fevme.cxx:52
#define MERROR
Definition midas.h:559
#define TID_DWORD
Definition midas.h:336
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
INT index
Definition mana.cxx:271
INT HNDLE
Definition midas.h:132
#define name(x)
Definition midas_macro.h:24
Here is the call graph for this function:

◆ 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 318 of file fevme.cxx.

319{
320 gHaveRun = 0;
322 return SUCCESS;
323}
Here is the call graph for this function:

◆ 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 348 of file fevme.cxx.

352{
353 //printf("poll_event %d %d %d!\n",source,count,test);
354
355 for (int i=0 ; i<count ; i++)
356 {
358 //printf("source: 0x%x, lam: 0x%x\n", source, lam);
359
360 if (lam)
361 if (!test)
362 return TRUE;
363 }
364
365 return FALSE;
366
367#if 0
368 for (int i = 0; i < count; i++)
369 {
370 usleep(1000);
371 if (true)
372 if (!test)
374 }
375 return 1;
376
378#endif
379}
#define FALSE
Definition cfortran.h:309
double count
Definition mdump.cxx:33
#define TRUE
Definition midas.h:182
program test
Definition miniana.f:6
Here is the call graph for this function:

◆ read_event()

INT read_event ( char pevent,
INT  off 
)

Definition at line 550 of file fevme.cxx.

551{
552 //printf("read event!\n");
553
554 /* init bank structure */
555 bk_init32(pevent);
556
557#ifdef HAVE_V792
558 read_v792(gAdcBase,"ADC1",pevent,32);
559#endif
560#ifdef HAVE_V1190B
561 read_tdc(gTdcBase,pevent);
562#endif
563#ifdef HAVE_VF48
564 read_vf48(gVF48base,pevent);
565#endif
566
567 return bk_size(pevent);
568}
int read_v792(int base, const char *bname, char *pevent, int nchan)
Definition fevme.cxx:399
int read_tdc(int base, char *pevent)
Definition fevme.cxx:437
void bk_init32(void *event)
Definition midas.cxx:16469
INT bk_size(const void *event)
Definition midas.cxx:16495
Here is the call graph for this function:

◆ read_tdc()

int read_tdc ( int  base,
char pevent 
)

Definition at line 437 of file fevme.cxx.

438{
439 int time0 = 0;
440 int time1 = 0;
441 int time2 = 0;
442 int count;
443 const int kDataSize = 10000;
445 int* pdata32;
446
447 /* create TOPA bank */
448 bk_create(pevent, "TDCS", TID_INT, &pdata32);
449
450 //while (count <
451 count = v1190_DataRead(gVme, base, data, 10000);
452
453 if (count > 0)
454 {
455#if 0
456 if (count > 1000)
457 printf("reading TDC got %d words\n",count);
458
459 printf("reading TDC got %d words\n",count);
460#endif
461 for (int i=0; i<count; i++)
462 {
463 int code = 0x1F&(data[i]>>27);
464
465 if (data[i] == 0)
466 continue;
467
468 switch (code)
469 {
470 case 0:
471 {
472 int edge = 0x1&(data[i]>>26);
473 int chan = 0x3F&(data[i]>>19);
474 int time = 0x3FFFF&data[i];
475#if 0
476 printf("tdc %3d: 0x%08x, code 0x%02x, edge %d, chan %2d, time %6d\n",
477 i,
478 data[i],
479 code,
480 edge,
481 chan,
482 time);
483#endif
484 if ((chan==0) && (time0==0))
485 time0 = time;
486 if ((chan==1) && (time0!=0) && (time1==0) && (time>time0))
487 time1 = time;
488 if ((chan==2) && (time0!=0) && (time2==0) && (time>time0))
489 time2 = time;
490 }
491 break;
492 //case 0x18:
493 //break;
494 default:
495#if 0
496 printf("tdc %3d: 0x%08x, code 0x%02x\n",i,data[i],code);
497#endif
498 break;
499 }
500 }
501
502#if 0
503 if (time1 && time2)
504 printf("time %8d %8d %8d, diff %8d\n",time0,time1,time2,time1-time2);
505#endif
506 }
507
508 int xdata = time1-time2;
509 if (xdata < -10000)
510 xdata = 0;
511 else if (xdata > 10000)
512 xdata = 0;
513
514#if 0
515 if (xdata == 0)
516 printf("count %d, time %8d %8d %8d, diff %8d\n",count,time0,time1,time2,xdata);
517#endif
518
519 *pdata32++ = xdata;
520
521 bk_close(pevent, pdata32);
522
524
525 return 0;
526}
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
unsigned int DWORD
Definition mcstd.h:51
#define TID_INT
Definition midas.h:338
void * data
Definition mana.cxx:268
static te_expr * base(state *s)
Definition tinyexpr.c:357
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_v792()

int read_v792 ( int  base,
const char bname,
char pevent,
int  nchan 
)

Definition at line 399 of file fevme.cxx.

400{
401 int i;
402 int wcount = 0;
403 DWORD data[100];
404 int counter = 0;
405 WORD* pdata;
406
407 /* Event counter */
409
410 /* Read Event */
412
413 /* create ADCS bank */
414 bk_create(pevent, bname, TID_WORD, &pdata);
415
416 for (i=0; i<32; i++)
417 pdata[i] = 0;
418
419 for (i=0; i<wcount; i++)
420 {
421 uint32_t w = data[i];
422 if (((w>>24)&0x7) != 0) continue;
423 int chan = (w>>16)&0x1F;
424 int val = (w&0x1FFF);
425 pdata[chan] = val;
426 }
427
428 //printf("counter %6d, words: %3d, header: 0x%08x, ADC0: 0x%08x, ADC0,1,2: %6d %6d %6d\n",counter,wcount,data[0],pdata[0],pdata[0],pdata[1],pdata[2]);
429
430 pdata += nchan;
431 bk_close(pevent, pdata);
432
433 return wcount;
434}
unsigned short int WORD
Definition mcstd.h:49
#define TID_WORD
Definition midas.h:332
Here is the call graph for this function:
Here is the caller 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 326 of file fevme.cxx.

327{
328 gHaveRun = 1;
330 return SUCCESS;
331}
Here is the call graph for this function:

Variable Documentation

◆ display_period

INT display_period = 000

a frontend status page is displayed with this frequency in ms

Definition at line 60 of file fevme.cxx.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"Trigger",
"SYSTEM",
LAM_SOURCE(0, 0xFFFFFF),
"MIDAS",
TRUE,
500,
0,
0,
0,
"", "", "",}
,
NULL,
}
,
{""}
}
INT read_event(char *pevent, INT off)
Definition fevme.cxx:550
#define EQ_POLLED
Definition midas.h:415
#define TRIGGER_ALL
Definition midas.h:538
#define RO_RUNNING
Definition midas.h:426
#define LAM_SOURCE(c, s)
Definition midas.h:469

Main structure for midas equipment.

Definition at line 88 of file fevme.cxx.

88 {
89
90 {"Trigger", /* equipment name */
91 {1, TRIGGER_ALL, /* event ID, trigger mask */
92 "SYSTEM", /* event buffer */
93 EQ_POLLED, /* equipment type */
94 LAM_SOURCE(0, 0xFFFFFF), /* event source */
95 "MIDAS", /* format */
96 TRUE, /* enabled */
97 RO_RUNNING, /* read only when running */
98
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 ,
105 read_event, /* readout routine */
106 NULL, NULL,
107 NULL, /* bank list */
108 }
109 ,
110
111 {""}
112 };

◆ event_buffer_size

INT event_buffer_size = 200*1024

buffer size to hold events

Definition at line 69 of file fevme.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

frontend_loop is called periodically if this variable is TRUE

Definition at line 57 of file fevme.cxx.

◆ frontend_file_name

char* frontend_file_name = __FILE__

The frontend file name, don't change it.

Definition at line 54 of file fevme.cxx.

◆ frontend_name

char* frontend_name = "fevme"

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

Definition at line 52 of file fevme.cxx.

◆ gAdcBase

int gAdcBase = 0x110000

Definition at line 145 of file fevme.cxx.

◆ gDisBase

int gDisBase[] = { 0xE00000, 0 }

Definition at line 146 of file fevme.cxx.

146{ 0xE00000, 0 };

◆ gHaveRun

int gHaveRun = 0
static

Definition at line 268 of file fevme.cxx.

◆ gTdcBase

int gTdcBase = 0xf10000

Definition at line 147 of file fevme.cxx.

◆ gVF48base

int gVF48base = 0xa00000

Definition at line 148 of file fevme.cxx.

◆ gVme

MVME_INTERFACE* gVme = 0

Definition at line 142 of file fevme.cxx.

◆ gVmeioBase

int gVmeioBase = 0x780000

Definition at line 144 of file fevme.cxx.

◆ hDB

HNDLE hDB
extern

main ODB handle

Definition at line 207 of file mana.cxx.

◆ max_event_size

INT max_event_size = 100*1024

maximum event size produced by this frontend

Definition at line 63 of file fevme.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 1024*1024

maximum event size for fragmented events (EQ_FRAGMENTED)

Definition at line 66 of file fevme.cxx.

◆ run_state

INT run_state
extern

Definition at line 35 of file mfe.cxx.