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