DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
WIB1
WIB_DTS.cpp
Go to the documentation of this file.
1
#include "
wibmod/WIB1/WIB.hh
"
2
#include "
wibmod/Issues.hpp
"
3
#include "
wibmod/WIB1/WIBException.hh
"
4
#include "
ers/ers.hpp
"
5
6
#include <unistd.h>
7
8
#include <stdio.h>
9
#include <chrono>
10
11
12
void
WIB::InitializeDTS
(uint8_t PDTSsource,uint8_t clockSource, uint32_t PDTSAlignment_timeout){
13
//Disable the PDTS
14
WriteWithRetry
(
"DTS.PDTS_ENABLE"
,0x0);
15
16
//Disable SI5344 outputs (fixed by SI5344 config)
17
WriteWithRetry
(
"DTS.SI5344.ENABLE"
,0);
18
//Disable SI5344 (fixed by SI5344 config)
19
WriteWithRetry
(
"DTS.SI5344.RESET"
,1);
20
21
22
//Reset the I2C firmware
23
WriteWithRetry
(
"DTS.CDS.I2C.RESET"
,1);
24
25
26
if
(0 == clockSource){
27
printf(
"Using PDTS for DUNE timing.\n\nConfiguring clock and data separator\n"
);
28
//Bring up the CDS
29
float
frequency = 0;
30
try
{
31
frequency =
ConfigureDTSCDS
(PDTSsource);
32
}
catch
(
BUException::exBase
& e){
33
frequency = 0;
34
e.
Append
(
"Failed to communicate with the DTS CDS via I2C\n"
);
35
throw
;
36
}
37
uint32_t LOL =
Read
(
"DTS.CDS.LOL"
);
38
uint32_t LOS =
Read
(
"DTS.CDS.LOS"
);
39
printf(
"CDS frequency %f\n"
,frequency);
40
printf(
"CDS LOL=%d LOS=%d\n"
,LOL,LOS);
41
42
//Check for the correct frequency, not in LOS, and not in LOL
43
// if( (2.4136e+08 == frequency) &&
44
if
(LOL || LOS){
45
BUException::WIB_DTS_ERROR e;
46
e.
Append
(
"Failed to configure CDS chip\n"
);
47
throw
e;
48
}
49
}
else
{
50
printf(
"Using local OSC for DUNE timing\n"
);
51
}
52
//CDS is up
53
54
55
printf(
"\nConfiguring SI5344.\n"
);
56
57
//Set the SI5344 source
58
WriteWithRetry
(
"DTS.SI5344.INPUT_SELECT"
,clockSource);
59
//Configure Si5344 with default config file
60
//Do the I2C configuration
61
try
{
62
LoadConfigDTS_SI5344
(
""
);
63
}
catch
(
BUException::exBase
& e){
64
//Disable SI5344 outputs
65
WriteWithRetry
(
"DTS.SI5344.ENABLE"
,0);
66
//Disable SI5344
67
WriteWithRetry
(
"DTS.SI5344.RESET"
,1);
68
69
e.
Append
(
"Error in LoadConfigDTS_SI5344\n"
);
70
throw
;
71
}
72
73
usleep(100000);
74
75
//Check that SI5344 is locked on
76
if
(
ReadWithRetry
(
"DTS.SI5344.LOS"
) ||
77
ReadWithRetry
(
"DTS.SI5344.LOL"
)){
78
//Disable SI5344 outputs
79
WriteWithRetry
(
"DTS.SI5344.ENABLE"
,0);
80
//Disable SI5344
81
WriteWithRetry
(
"DTS.SI5344.RESET"
,1);
82
83
//Throw
84
BUException::WIB_DTS_ERROR e;
85
e.
Append
(
"Failed to configure the SI5344 chip correctly\n"
);
86
throw
e;
87
}
88
89
//Enable the clock for FPGA
90
WriteWithRetry
(
"DTS.SI5344.ENABLE"
,1);
91
usleep(100000);
92
93
char
const
*
const
PDTSStates[] = {
"W_RST"
,
94
"W_LINK"
,
95
"W_FREQ"
,
96
"W_ADJUST"
,
97
"W_ALIGN"
,
98
"W_LOCK"
,
99
"W_PHASE"
,
100
"W_RDY"
,
101
"RUN"
,
102
"0x9"
,
103
"0xA"
,
104
"0xB"
,
105
"ERR_R"
,
106
"ERR_T"
,
107
"ERR_P"
,
108
"0xF"
};
109
110
111
if
(0 == clockSource){
112
printf(
"\nSetup PDTS.\n"
);
113
bool
timeout_exists =
true
;
114
if
(PDTSAlignment_timeout == 0)
115
timeout_exists =
false
;
116
117
auto
start_time = std::chrono::high_resolution_clock::now();
118
bool
timed_out =
false
;
119
120
while
((timeout_exists ==
false
) || timed_out ==
false
) {
121
//Using PDTS, set that up.
122
usleep(500000);
123
WriteWithRetry
(
"DTS.PDTS_ENABLE"
,1);
124
usleep(500000);
//needed in new PDTS system to get to a good state before giving up and trying a new phase.
125
126
//See if we've locked
127
uint32_t pdts_state =
ReadWithRetry
(
"DTS.PDTS_STATE"
);
128
printf(
"PDTS state: %s (0x%01X)\n"
,PDTSStates[pdts_state&0xF],pdts_state);
129
if
((pdts_state < 0x6) || (pdts_state > 0x8)) {
130
WriteWithRetry
(
"DTS.PDTS_ENABLE"
,0);
131
//dynamic post-amble
132
Write
(
"DTS.SI5344.I2C.RESET"
,1);
133
SetDTS_SI5344Page
(0x0);
134
Write
(
"DTS.SI5344.I2C.RESET"
,1);
135
WriteDTS_SI5344
(0x1C,0x1,1);
136
}
137
else
if
(0x6 == pdts_state){
138
ers::info
(dunedaq::wibmod::WaitingForAlignment(
ERS_HERE
));
139
}
140
else
if
(0x7 == pdts_state){
141
ers::info
(dunedaq::wibmod::WaitingForTimestamp(
ERS_HERE
));
142
}
143
else
{
144
return
;
//0x8 == pdts_state
145
}
146
auto
now
= std::chrono::high_resolution_clock::now();
147
auto
duration =
now
- start_time;
148
if
( duration.count() > PDTSAlignment_timeout)
149
timed_out =
true
;
150
}
151
//If we get here something went wrong
152
Write
(
"DTS.SI5344.I2C.RESET"
,1);
153
SetDTS_SI5344Page
(0x0);
154
Write
(
"DTS.SI5344.I2C.RESET"
,1);
155
WriteDTS_SI5344
(0x1C,0x1,1);
156
157
BUException::WIB_DTS_ERROR e;
158
e.
Append
(
"Failed to configure the PDTS correctly within timeout\n"
);
159
throw
e;
160
}
161
}
162
163
void
WIB::StartSyncDTS
(){
164
WriteWithRetry
(
"DTS.CONVERT_CONTROL.HALT"
,0);
165
WriteWithRetry
(
"DTS.CONVERT_CONTROL.ENABLE"
,1);
166
WriteWithRetry
(
"DTS.CONVERT_CONTROL.START_SYNC"
,1);
167
}
168
169
void
WIB::PDTSInRunningState
(){
170
if
(
Read
(
"DTS.PDTS_STATE"
) != 0x8){
171
BUException::WIB_DTS_ERROR e;
172
e.Append(
"WIB is not in PDTS state RUN(0x8)\n"
);
173
throw
e;
174
}
175
}
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
WIBException.hh
WIB.hh
BUException::exBase
Definition
ExceptionBase.hh:47
BUException::exBase::Append
void Append(const char *buffer)
Definition
ExceptionBase.cpp:94
WIBBase::WriteWithRetry
void WriteWithRetry(uint16_t address, uint32_t value)
Definition
WIBBase.cpp:129
WIBBase::ReadWithRetry
uint32_t ReadWithRetry(uint16_t address)
Definition
WIBBase.cpp:116
WIBBase::Read
uint32_t Read(uint16_t address)
Definition
WIBBase.cpp:119
WIBBase::Write
void Write(uint16_t address, uint32_t value)
Definition
WIBBase.cpp:132
WIB::LoadConfigDTS_SI5344
void LoadConfigDTS_SI5344(std::string const &fileName)
Definition
WIB_SI5344.cpp:34
WIB::InitializeDTS
void InitializeDTS(uint8_t PDTSsource=0, uint8_t clockSource=0, uint32_t PDTSAlignment_timeout=0)
Definition
WIB_DTS.cpp:12
WIB::SetDTS_SI5344Page
void SetDTS_SI5344Page(uint8_t page)
Definition
WIB_SI5344.cpp:22
WIB::StartSyncDTS
void StartSyncDTS()
Definition
WIB_DTS.cpp:163
WIB::WriteDTS_SI5344
void WriteDTS_SI5344(uint16_t address, uint32_t value, uint8_t byte_count=4)
Definition
WIB_SI5344.cpp:8
WIB::ConfigureDTSCDS
float ConfigureDTSCDS(uint8_t source=0)
Definition
WIB_CDS.cpp:24
WIB::PDTSInRunningState
void PDTSInRunningState()
Definition
WIB_DTS.cpp:169
ers.hpp
now
static int64_t now()
Definition
kafka_opmon_consumer.cxx:44
ers::info
void info(const Issue &issue)
Definition
ers.hpp:106
Issues.hpp
Generated on
for DUNE-DAQ by
1.17.0