DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AddressTable_IO.cpp
Go to the documentation of this file.
2#include <fstream>
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
10uint32_t AddressTable::Read(uint16_t address){
11 return io->Read(address);
12}
13uint32_t AddressTable::ReadWithRetry(uint16_t address){
14 return io->ReadWithRetry(address);
15}
16
17
18void AddressTable::Write(uint16_t address, uint32_t data){
19 io->Write(address,data);
20}
21void AddressTable::WriteWithRetry(uint16_t address, uint32_t data){
22 io->WriteWithRetry(address,data);
23}
24
25void AddressTable::Write(uint16_t address, std::vector<uint32_t> const & values){
26 io->Write(address,values);
27}
28void AddressTable::Write(uint16_t address,uint32_t const * values, size_t word_count){
29 io->Write(address,values,word_count);
30}
31
32
33uint32_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
50uint32_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
67void 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
88void 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
110void AddressTable::Write(std::string registerName,std::vector<uint32_t> const & values){
111 Write(registerName,values.data(),values.size());
112}
113void 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
void Write(uint16_t, uint32_t)
uint32_t ReadWithRetry(uint16_t)
void WriteWithRetry(uint16_t, uint32_t)
uint32_t Read(uint16_t)
std::map< std::string, Item * > nameItemMap
uint16_t address
uint32_t mask
uint8_t offset