DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
WIB1
WIB_SI5342.cpp
Go to the documentation of this file.
1
#include "
wibmod/WIB1/WIB.hh
"
2
#include "
wibmod/WIB1/WIBException.hh
"
3
#include <fstream>
4
#include <unistd.h>
//usleep
5
6
#define SI5342_CONFIG_FILENAME "FELIX_SI5342.txt"
7
8
void
WIB::WriteDAQ_SI5342
(uint16_t address,uint32_t value,uint8_t byte_count){
9
WriteI2C
(
"DAQ.SI5342.I2C"
,address,value,byte_count);
10
}
11
uint32_t
WIB::ReadDAQ_SI5342
(uint16_t address,uint8_t byte_count){
12
return
ReadI2C
(
"DAQ.SI5342.I2C"
,address,byte_count);
13
}
14
15
16
void
WIB::ResetSi5342
(){
17
Write
(
"DAQ.SI5342.RESET"
,0x1);
18
Write
(
"DAQ.SI5342.RESET"
,0x0);
19
usleep(100000);
20
}
21
22
void
WIB::SetDAQ_SI5342Page
(uint8_t page){
23
WriteDAQ_SI5342
(0x1,page,1);
24
}
25
26
uint8_t
WIB::GetDAQ_SI5342Page
(){
27
return
uint8_t(
ReadDAQ_SI5342
(0x1,1)&0xFF);
28
}
29
30
uint8_t
WIB::GetDAQ_SI5342AddressPage
(uint16_t address){
31
return
uint8_t((address >> 8)&0xFF);
32
}
33
34
void
WIB::LoadConfigDAQ_SI5342
(std::string
const
& fileName){
35
std::ifstream confFile(fileName.c_str());
36
BUException::WIB_BAD_ARGS badFile;
37
38
if
(confFile.fail()){
39
//Failed to topen filename, add it to the exception
40
badFile.Append(
"Bad SI5342 config file name:"
);
41
badFile.Append(fileName.c_str());
42
43
//Try the default
44
if
(getenv(
"WIBMOD_SHARE"
) != NULL){
45
std::string envBasedFileName=getenv(
"WIBMOD_SHARE"
);
46
envBasedFileName+=
"/config/WIB1/config/"
;
47
envBasedFileName+=
SI5342_CONFIG_FILENAME
;
48
confFile.open(envBasedFileName.c_str());
49
if
(confFile.fail()){
50
badFile.Append(
"Bad env based filename:"
);
51
badFile.Append(envBasedFileName.c_str());
52
}
53
}
54
}
55
56
if
(confFile.fail()){
57
//We are still failing to open our file
58
throw
badFile;
59
}
60
61
//Make sure the chip isn't in reset
62
if
(
Read
(
"DAQ.SI5342.RESET"
) != 0){
63
Write
(
"DAQ.SI5342.RESET"
,0x0);
64
usleep(50000);
65
}
66
67
//Reset the I2C firmware
68
Write
(
"DAQ.SI5342.I2C.RESET"
,1);
69
70
std::vector<std::pair<uint16_t,uint8_t> > writes;
71
while
(!confFile.eof()){
72
std::string line;
73
std::getline(confFile,line);
74
if
(line.size() == 0){
75
continue
;
76
}
else
if
(line[0] ==
'#'
){
77
continue
;
78
}
else
if
(line[0] ==
'A'
){
79
continue
;
80
}
else
{
81
if
( line.find(
','
) == std::string::npos ){
82
printf(
"Skipping bad line: \"%s\"\n"
,line.c_str());
83
continue
;
84
}
85
uint16_t address = strtoul(line.substr(0,line.find(
','
)).c_str(),NULL,16);
86
uint8_t data = strtoul(line.substr(line.find(
','
)+1).c_str(),NULL,16);
87
writes.push_back(std::pair<uint16_t,uint8_t>(address,data));
88
}
89
}
90
91
//Disable the SI5342 output
92
Write
(
"DAQ.SI5342.ENABLE"
,0x0);
93
94
uint8_t page =
GetDAQ_SI5342Page
();
95
unsigned
int
percentDone = 0;
96
97
98
printf(
"\n[==================================================]\n"
);
99
fprintf(stderr,
" "
);
100
for
(
size_t
iWrite = 0; iWrite < writes.size();iWrite++){
101
102
if
(page !=
GetDAQ_SI5342AddressPage
(writes[iWrite].first)){
103
page =
GetDAQ_SI5342AddressPage
(writes[iWrite].first);
104
SetDAQ_SI5342Page
(page);
105
usleep(100000);
106
}
107
108
109
if
(iWrite == 3){
110
usleep(300000);
111
}
112
113
114
uint8_t address = writes[iWrite].first & 0xFF;
115
uint32_t data = (writes[iWrite].second) & 0xFF;
116
uint8_t iData = 1;
117
118
for
(
size_t
iTries = 10; iTries > 0;iTries--){
119
try
{
120
WriteDAQ_SI5342
(address ,data,iData);
121
}
catch
(BUException::WIB_ERROR & e){
122
//Reset the I2C firmware
123
Write
(
"DAQ.SI5342.I2C.RESET"
,1);
124
if
(iTries == 1){
125
e.Append(
"\nTried 3 times\n"
);
126
throw
;
127
}
128
}
129
}
130
if
((100*iWrite)/writes.size() > percentDone){
131
fprintf(stderr,
"#"
);
132
percentDone+=2;
133
}
134
}
135
printf(
"\n"
);
136
137
}
138
139
void
WIB::SelectSI5342
(uint64_t input,
bool
enable
){
140
Write
(
"DAQ.SI5342.INPUT_SELECT"
, input);
141
Write
(
"DAQ.SI5342.ENABLE"
, uint64_t(
enable
));
142
}
WIBException.hh
WIB.hh
SI5342_CONFIG_FILENAME
#define SI5342_CONFIG_FILENAME
Definition
WIB_SI5342.cpp:6
WIBBase::WriteI2C
void WriteI2C(std::string const &base_address, uint16_t I2C_address, uint32_t data, uint8_t byte_count=4, bool ignore_error=false)
Definition
WIBBase.cpp:69
WIBBase::Read
uint32_t Read(uint16_t address)
Definition
WIBBase.cpp:119
WIBBase::ReadI2C
uint32_t ReadI2C(std::string const &base_address, uint16_t I2C_aaddress, uint8_t byte_count=4)
Definition
WIBBase.cpp:39
WIBBase::Write
void Write(uint16_t address, uint32_t value)
Definition
WIBBase.cpp:132
WIB::ReadDAQ_SI5342
uint32_t ReadDAQ_SI5342(uint16_t address, uint8_t byte_count=4)
Definition
WIB_SI5342.cpp:11
WIB::GetDAQ_SI5342Page
uint8_t GetDAQ_SI5342Page()
Definition
WIB_SI5342.cpp:26
WIB::SelectSI5342
void SelectSI5342(uint64_t input, bool enable)
Definition
WIB_SI5342.cpp:139
WIB::GetDAQ_SI5342AddressPage
uint8_t GetDAQ_SI5342AddressPage(uint16_t address)
Definition
WIB_SI5342.cpp:30
WIB::WriteDAQ_SI5342
void WriteDAQ_SI5342(uint16_t address, uint32_t value, uint8_t byte_count=4)
Definition
WIB_SI5342.cpp:8
WIB::ResetSi5342
void ResetSi5342()
Definition
WIB_SI5342.cpp:16
WIB::LoadConfigDAQ_SI5342
void LoadConfigDAQ_SI5342(std::string const &fileName)
Definition
WIB_SI5342.cpp:34
WIB::SetDAQ_SI5342Page
void SetDAQ_SI5342Page(uint8_t page)
Definition
WIB_SI5342.cpp:22
enable
Definition
enable.py:1
Generated on
for DUNE-DAQ by
1.17.0