-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadV513.cpp
More file actions
114 lines (94 loc) · 3.09 KB
/
readV513.cpp
File metadata and controls
114 lines (94 loc) · 3.09 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
107
108
109
110
111
112
113
114
#include <iostream>
#include <ctime>
#include "myV513.h"
// v513 xio(0xa00000,"/V2718/cvA24_U_DATA/1");
// v513 xio(0xa00000,"/V2718/cvA24_U_DATA/1");
v513 xio(0xa00000,"/V2718/cvA24_U_DATA/0"); // Desy setup // roberto 15.06.2021
using namespace std;
#define SLEEP1000ns 1000 // for sleeping 1000 ns
#define NSLEEPT 1000
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 );
}
#define DAQ_VETO 11 // channel 11
#define TRIGGER_UNLOCK 10 // channel 10
#define SCALER_RESET 9 // channel 9
#define PEDESTAL_VETO 8 // channel 8
inline bool isT1T2Trig() { return (xio.readInputRegister() & 1<<7); }
inline bool isHWBusy() { return (xio.readInputRegister() & 1<<4); }
inline bool isInSpill() { return (xio.readInputRegister() & 1<<2); }
inline bool isPedTrig() { return (xio.readInputRegister() & 1<<1); }
inline bool isPhysTrig() { return (xio.readInputRegister() & 1<<0); }
inline void resetTrig() { nsleep(SLEEP1000ns); xio.setOutputBit( TRIGGER_UNLOCK ); nsleep(SLEEP1000ns); xio.clearOutputBit( TRIGGER_UNLOCK ); }
inline void enableTriggers() { xio.clearOutputBit( DAQ_VETO ) ; }
inline void disableTriggers() { xio.setOutputBit( DAQ_VETO ); }
inline void enablePedestal() { xio.clearOutputBit( PEDESTAL_VETO ); }
int initV513( )
{
uint16_t w;
xio.read16phys(0xFE, &w);
cout << hex << " V513 FE " << w << endl;
nsleep(NSLEEPT);
xio.read16phys(0xFC, &w);
cout << hex << " V513 FC " << w << endl;
nsleep(NSLEEPT);
xio.read16phys(0xFA, &w);
cout << hex << " V513 FA " << w << endl;
nsleep(NSLEEPT);
w=0;
xio.write16phys(0x48, w);
nsleep(NSLEEPT);
xio.write16phys(0x46, w);
nsleep(NSLEEPT);
xio.write16phys(0x42, w);
nsleep(NSLEEPT);
xio.reset();
nsleep(NSLEEPT);
xio.read16phys(0x04, &w);
cout << hex << " V513 0x4 " << w << endl;
nsleep(NSLEEPT);
for (int i=0; i<8; i++)
{
int reg = 0x10+i*2;
xio.setChannelInput(i);
nsleep(NSLEEPT);
xio.read16phys(reg, &w);
cout << hex << " V513 input ch " << i << " reg " << reg << " " << w << endl;
nsleep(NSLEEPT);
}
for (int i=8; i<16; i++)
{
int reg = 0x10+i*2;
xio.setChannelOutput(i);
nsleep(NSLEEPT);
xio.read16phys(reg, &w);
cout << hex << " V513 output ch " << i << " reg " << reg << " " << w << endl;
nsleep(NSLEEPT);
}
disableTriggers();
return 0;
}
int32_t main( int32_t , char** )
{
uint16_t z;
initV513();
enableTriggers();
enablePedestal();
for (unsigned int i=0; ; i++)
{
xio.read16phys(0x04, &z);
//if(i%100 == 0)
cout << hex << " V513 0x4 " << z << " isT1T2Trig: " << isT1T2Trig() << " - isPhysTrig: " << isPhysTrig() << " - isPedTrig: " << isPedTrig() << " - isInSpill " << isInSpill() << " - isHWBusy " << isHWBusy() << endl;
if (isPedTrig() | isPhysTrig()) resetTrig();
//nsleep(10000000);
sleep(1);
} while(1);
return 0;
}