DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
wibmod
src
WIB1
AddressTable_IO.cpp
Go to the documentation of this file.
1
#include "
wibmod/WIB1/AddressTable.hh
"
2
#include <fstream>
3
#include "
wibmod/WIB1/AddressTableException.hh
"
4
#include <boost/tokenizer.hpp>
//tokenizer
5
#include <stdlib.h>
//strtoul & getenv
6
#include <boost/regex.hpp>
//regex
7
#include <boost/algorithm/string/case_conv.hpp>
//to_upper
8
9
10
uint32_t
AddressTable::Read
(uint16_t address){
11
return
io
->Read(address);
12
}
13
uint32_t
AddressTable::ReadWithRetry
(uint16_t address){
14
return
io
->ReadWithRetry(address);
15
}
16
17
18
void
AddressTable::Write
(uint16_t address, uint32_t data){
19
io
->Write(address,data);
20
}
21
void
AddressTable::WriteWithRetry
(uint16_t address, uint32_t data){
22
io
->WriteWithRetry(address,data);
23
}
24
25
void
AddressTable::Write
(uint16_t address, std::vector<uint32_t>
const
& values){
26
io
->Write(address,values);
27
}
28
void
AddressTable::Write
(uint16_t address,uint32_t
const
* values,
size_t
word_count){
29
io
->Write(address,values,word_count);
30
}
31
32
33
uint32_t
AddressTable::Read
(std::string registerName){
34
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
35
if
(itNameItem ==
nameItemMap
.end()){
36
BUException::INVALID_NAME e;
37
e.Append(
"Can't find item with name \""
);
38
e.Append(registerName.c_str());
39
e.Append(
"\""
);
40
throw
e;
41
}
42
Item
* item = itNameItem->second;
43
uint32_t val =
io
->Read(item->
address
);
44
val &= (item->
mask
);
45
val >>= item->
offset
;
46
47
return
val;
48
}
49
50
uint32_t
AddressTable::ReadWithRetry
(std::string registerName){
51
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
52
if
(itNameItem ==
nameItemMap
.end()){
53
BUException::INVALID_NAME e;
54
e.Append(
"Can't find item with name \""
);
55
e.Append(registerName.c_str());
56
e.Append(
"\""
);
57
throw
e;
58
}
59
Item
* item = itNameItem->second;
60
uint32_t val =
io
->ReadWithRetry(item->
address
);
61
val &= (item->
mask
);
62
val >>= item->
offset
;
63
64
return
val;
65
}
66
67
void
AddressTable::Write
(std::string registerName,uint32_t val){
68
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
69
if
(itNameItem ==
nameItemMap
.end()){
70
BUException::INVALID_NAME e;
71
e.Append(
"Can't find item with name \""
);
72
e.Append(registerName.c_str());
73
e.Append(
"\""
);
74
throw
e;
75
}
76
Item
* item = itNameItem->second;
77
//Check if this entry controls all the bits
78
uint32_t buildingVal =0;
79
if
(item->
mask
!= 0xFFFFFFFF){
80
//Since there are bits this register we don't control, we need to see what they currently are
81
buildingVal =
io
->Read(item->
address
);
82
buildingVal &= ~(item->
mask
);
83
}
84
buildingVal |= (item->
mask
& (val << item->
offset
));
85
io
->Write(item->
address
,buildingVal);
86
}
87
88
void
AddressTable::WriteWithRetry
(std::string registerName,uint32_t val){
89
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
90
if
(itNameItem ==
nameItemMap
.end()){
91
BUException::INVALID_NAME e;
92
e.Append(
"Can't find item with name \""
);
93
e.Append(registerName.c_str());
94
e.Append(
"\""
);
95
throw
e;
96
}
97
Item
* item = itNameItem->second;
98
//Check if this entry controls all the bits
99
uint32_t buildingVal =0;
100
if
(item->
mask
!= 0xFFFFFFFF){
101
//Since there are bits this register we don't control, we need to see what they currently are
102
buildingVal =
io
->ReadWithRetry(item->
address
);
103
buildingVal &= ~(item->
mask
);
104
}
105
buildingVal |= (item->
mask
& (val << item->
offset
));
106
io
->WriteWithRetry(item->
address
,buildingVal);
107
}
108
109
110
void
AddressTable::Write
(std::string registerName,std::vector<uint32_t>
const
& values){
111
Write
(registerName,values.data(),values.size());
112
}
113
void
AddressTable::Write
(std::string registerName,uint32_t
const
* values,
size_t
word_count){
114
std::map<std::string,Item *>::iterator itNameItem =
nameItemMap
.find(registerName);
115
if
(itNameItem ==
nameItemMap
.end()){
116
BUException::INVALID_NAME e;
117
e.Append(
"Can't find item with name \""
);
118
e.Append(registerName.c_str());
119
e.Append(
"\""
);
120
throw
e;
121
}
122
Item
* item = itNameItem->second;
123
//Check if this entry controls all the bits
124
if
(item->
mask
!= 0xFFFFFFFF){
125
BUException::BAD_BLOCK_WRITE e;
126
e.Append(
"Mask is not 0xFFFFFFFF\n"
);
127
throw
e;
128
}
129
io
->Write(item->
address
,values,word_count);
130
}
131
AddressTableException.hh
AddressTable.hh
AddressTable::Write
void Write(uint16_t, uint32_t)
Definition
AddressTable_IO.cpp:18
AddressTable::io
BNL_UDP * io
Definition
AddressTable.hh:68
AddressTable::ReadWithRetry
uint32_t ReadWithRetry(uint16_t)
Definition
AddressTable_IO.cpp:13
AddressTable::WriteWithRetry
void WriteWithRetry(uint16_t, uint32_t)
Definition
AddressTable_IO.cpp:21
AddressTable::Read
uint32_t Read(uint16_t)
Definition
AddressTable_IO.cpp:10
AddressTable::nameItemMap
std::map< std::string, Item * > nameItemMap
Definition
AddressTable.hh:66
Item
Definition
AddressTable.hh:14
Item::address
uint16_t address
Definition
AddressTable.hh:18
Item::mask
uint32_t mask
Definition
AddressTable.hh:19
Item::offset
uint8_t offset
Definition
AddressTable.hh:20
Generated on
for DUNE-DAQ by
1.17.0