-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaqReadout.cpp
More file actions
106 lines (87 loc) · 2.43 KB
/
daqReadout.cpp
File metadata and controls
106 lines (87 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cstdint>
#include <csignal>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sstream>
#include <iomanip>
#include "myModules.h" // VME Module Id.s
#include "daqcommon.h"
#include "daqSem.h"
#include "daqShm.h"
using namespace std;
uint32_t hereIam(0);
volatile bool abort_run(false);
volatile bool pause_run(false);
void cntrl_c_handler ( int32_t sig )
{
time_t timestr = time(NULL);
char * stime = ctime(×tr);
stime[24] = 0;
fprintf(stderr,"\n\n%s cntrl_c_handler: sig %d hereIam %d\n\n", stime, sig, hereIam);
fprintf(stderr,"aborting run\n\n");
abort_run = true;
}
void sigusr1_handler ( int32_t sig )
{
time_t timestr = time(NULL);
char * stime = ctime(×tr);
stime[24] = 0;
fprintf(stderr,"\n\n%s sigusr1_handler: sig %d hereIam %d pause_run is %d\n\n", stime, sig, hereIam, pause_run);
pause_run = not pause_run;
pause_run ? fprintf(stderr,"pausing run\n\n") : fprintf(stderr,"resuming run\n\n");
}
uint64_t xreadtime(0);
void readEvent() {}
void printEvent() {}
int main()
{
signal( SIGINT, cntrl_c_handler ); // Control-C handler
signal( SIGUSR1, sigusr1_handler ); // Control-USR1 handler
daqSem mySem (0x40, sModeSlave );
// initialise shared segment
daqShm mShm ( 0x10, mModeSlave );
volatile uint32_t* daqReadyToRun = mShm.daqReadyToRun();
*daqReadyToRun = 0;
volatile uint32_t* askDaqToRun = mShm.askDaqToRun();
*askDaqToRun = 0;
volatile uint32_t* fromDaq = mShm.fromDaq();
*fromDaq = 0;
volatile uint32_t* toDaq = mShm.toDaq();
*toDaq = 0;
volatile uint32_t* eventNr = mShm.eventNr();
*eventNr = 0;
volatile uint32_t* spillNr = mShm.spillNr();
*spillNr = 0;
volatile uint32_t* triggerMask = mShm.triggerMask();
*triggerMask = 0;
*daqReadyToRun = 1;
while (*askDaqToRun == 0) { x_usleep(1); }
do
{
if (*triggerMask == 0)
{
sched_yield();
}
else
{
readEvent();
printEvent();
(*fromDaq) ++;
cout << " *daqReadyToRun " << *daqReadyToRun
<< " *askDaqToRun " << *askDaqToRun
<< " *fromDaq " << *fromDaq
<< " *toDaq " << *toDaq
<< " *eventNr " << *eventNr
<< " *spillNr " << *spillNr
<< " *triggerMask " << *triggerMask << endl;
*triggerMask = 0;
}
}
while (*askDaqToRun == 1);
*daqReadyToRun = 0;
return 0;
}