DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AddressTable_IO.cpp
Go to the documentation of this file.
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
9uint32_t
10AddressTable::Read(uint16_t address)
11{
12 return io->Read(address);
13}
14uint32_t
16{
17 return io->ReadWithRetry(address);
18}
19
20void
21AddressTable::Write(uint16_t address, uint32_t data)
22{
23 io->Write(address, data);
24}
25void
26AddressTable::WriteWithRetry(uint16_t address, uint32_t data)
27{
28 io->WriteWithRetry(address, data);
29}
30
31void
32AddressTable::Write(uint16_t address, std::vector<uint32_t> const& values)
33{
34 io->Write(address, values);
35}
36void
37AddressTable::Write(uint16_t address, uint32_t const* values, size_t word_count)
38{
39 io->Write(address, values, word_count);
40}
41
42uint32_t
43AddressTable::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
61uint32_t
62AddressTable::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
80void
81AddressTable::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
103void
104AddressTable::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
126void
127AddressTable::Write(std::string registerName, std::vector<uint32_t> const& values)
128{
129 Write(registerName, values.data(), values.size());
130}
131void
132AddressTable::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}
void Write(uint16_t, uint32_t)
BNL_UDP * io
uint32_t ReadWithRetry(uint16_t)
void WriteWithRetry(uint16_t, uint32_t)
uint32_t Read(uint16_t)
std::map< std::string, Item * > nameItemMap
void Write(uint16_t address, uint32_t value)
Definition BNL_UDP.cpp:230
void WriteWithRetry(uint16_t address, uint32_t value, uint8_t retry_count=10)
Definition BNL_UDP.cpp:208
uint32_t ReadWithRetry(uint16_t address, uint8_t retry_count=10)
Definition BNL_UDP.cpp:388
uint32_t Read(uint16_t address)
Definition BNL_UDP.cpp:411
uint16_t address
uint32_t mask
uint8_t offset