-
Notifications
You must be signed in to change notification settings - Fork 1
/
testV2718daq.cpp
147 lines (115 loc) · 3.62 KB
/
testV2718daq.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#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 "myV2718.h" // CAEN V2718 VME Bridge class
using namespace std;
#define TRIGGER_MASK 3 // in 0, 1 -> 0 = PHYS TRIG, 1 = PED TRIG, 2 = IN SPILL
#define PEDESTAL_VETO 6 // out 0 -> PEDESTAL VETO
#define DAQ_VETO 7 // out 1 -> DAQ VETO
#define UNLOCK_PED_TRIGGER 8 // out 2 -> UNLOCK PEDESTAL TRIGGER
#define UNLOCK_PHYS_TRIGGER 9 // out 3 -> UNLOCK PHYSICS TRIGGER
#define SCALER_RESET 10 // out 4 -> SCALER RESET
void dlwait( string msg )
{
cout << "Press any key to continue ... " << msg;
getchar();
cout << endl;
}
const uint32_t ONEK = 1000;
const uint32_t ONEM = ONEK*ONEK;
const uint32_t ONEG = ONEK*ONEM;
void nsleep ( uint32_t ns )
{
uint32_t secs = ns / ONEG;
uint32_t nsrem = ns % ONEG;
struct timespec ndelay = { secs, nsrem };
nanosleep ( &ndelay, NULL );
}
void myusleep (uint32_t us )
{
uint32_t secs = us / ONEM;
uint32_t usrem = us % ONEM;
struct timespec ndelay = { secs, usrem*ONEK };
nanosleep ( &ndelay, NULL );
}
inline void enableTriggers( v2718& ioreg ) { ioreg.clearOutputBit( DAQ_VETO ); }
inline void disableTriggers( v2718& ioreg ) { ioreg.setOutputBit( DAQ_VETO ); }
inline void enablePedestals( v2718& ioreg ) { ioreg.clearOutputBit( PEDESTAL_VETO ); }
inline void disablePedestals( v2718& ioreg ) { ioreg.setOutputBit( PEDESTAL_VETO ); }
inline void resetScaler( v2718& ioreg )
{
ioreg.setOutputBit( SCALER_RESET );
ioreg.clearOutputBit( SCALER_RESET );
}
inline void unlockTrigger( v2718& ioreg )
{
ioreg.setOutputBit( UNLOCK_PED_TRIGGER );
ioreg.setOutputBit( UNLOCK_PHYS_TRIGGER );
ioreg.clearOutputBit( UNLOCK_PED_TRIGGER );
ioreg.clearOutputBit( UNLOCK_PHYS_TRIGGER );
}
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,"%s cntrl_c_handler: sig%d\n\n", stime, sig);
fprintf(stderr,"aborting run\n");
abort_run = true;
}
void sigusr1_handler ( int32_t sig )
{
time_t timestr = time(NULL);
char * stime = ctime(×tr);
stime[24] = 0;
fprintf(stderr,"%s sigusr1_handler: sig%d pause_run is %d\n\n", stime, sig, pause_run);
pause_run = not pause_run;
pause_run ? fprintf(stderr,"pausing run\n") : fprintf(stderr,"resuming run\n");
}
uint32_t initV2718 ( v2718 & v2718_m )
{
for ( int out = cvOutput0; out <= cvOutput4; out++ )
{
CVOutputSelect cvout = static_cast<CVOutputSelect>(out);
v2718_m.setOutputManual (cvout);
}
for ( int inp = cvInput0; inp <= cvInput1; inp++ )
{
CVInputSelect cvinp = static_cast<CVInputSelect>(inp);
v2718_m.setInput (cvinp);
}
disableTriggers( v2718_m );
disablePedestals( v2718_m );
}
int main( int argc, char** argv )
{
uint32_t trignum(0);
uint32_t Tcts[4] = { 0, 0, 0, 0 };
signal(SIGINT, cntrl_c_handler); // Control-C handler
signal(SIGUSR1, sigusr1_handler); // Control-USR1 handler
v2718 v2718_m("/V2718/cvA24_U_DATA/0"); // VME interface
v2718_m.print();
initV2718 ( v2718_m );
unlockTrigger ( v2718_m );
bool running (false);
bool in_spill (false);
while (1)
{
if (abort_run) exit_now = true;
if (exit_now) disableTriggers(v2718_0);
uint32_t z;
xio.readInputRegister (&z);
if (z == 0)
}
disableTriggers( v2718_m );
return 0;
}