#include <ProtocolAxi4Lite.hpp>
|
| MappedFile (const std::string &aPath, size_t aLength, int aProtFlags=PROT_WRITE) |
|
| ~MappedFile () |
|
const std::string & | getPath () const |
|
void | setPath (const std::string &aPath) |
|
void | setLength (size_t) |
|
void | open () |
| Open bus file and map it to memory.
|
|
void | close () |
| Unmap and close file.
|
|
void | createBuffer (const size_t aNrBytes) |
| Create a local buffer.
|
|
void | read (const uint32_t aAddr, const uint32_t aNrWords, std::vector< uint32_t > &aValues) |
|
void | write (const uint32_t aAddr, const std::vector< uint32_t > &aValues) |
|
void | write (const uint32_t aAddr, const uint8_t *const aPtr, const size_t aNrBytes) |
|
void | write (const uint32_t aAddr, const std::vector< std::pair< const uint8_t *, size_t > > &aData) |
|
bool | haveLock () const |
|
void | lock () |
|
void | unlock () |
|
Definition at line 97 of file ProtocolAxi4Lite.hpp.
◆ MappedFile()
uhallibs::Axi4Lite::MappedFile::MappedFile |
( |
const std::string & | aPath, |
|
|
size_t | aLength, |
|
|
int | aProtFlags = PROT_WRITE ) |
◆ ~MappedFile()
uhallibs::Axi4Lite::MappedFile::~MappedFile |
( |
| ) |
|
◆ close()
void uhallibs::Axi4Lite::MappedFile::close |
( |
| ) |
|
Unmap and close file.
Definition at line 55 of file ProtocolAxi4Lite.cpp.
55 {
58
64 if (rc == -1)
65 log (uhal::Error(),
"Failed to close file ", uhal::Quote(
mPath),
"; errno=", uhal::Integer(errno),
", meaning ", uhal::Quote (
strerror(errno)));
66 }
67}
const std::string strerror(int error)
Convert C error number to string.
◆ createBuffer()
void uhallibs::Axi4Lite::MappedFile::createBuffer |
( |
const size_t | aNrBytes | ) |
|
Create a local buffer.
Definition at line 70 of file ProtocolAxi4Lite.cpp.
70 {
73 return;
74 else {
78 }
79 }
80
81 posix_memalign((
void**)&
mBuffer, 4096 , aNrBytes + 4096);
83 exception::Axi4LiteCommunicationError lExc;
84 log(lExc,
"Failed to allocate ", Integer(aNrBytes + 4096),
85 " bytes in Axi4Lite::MappedFile::createBuffer");
86 throw lExc;
87 }
88
90}
◆ getPath()
const std::string & uhallibs::Axi4Lite::MappedFile::getPath |
( |
| ) |
const |
◆ haveLock()
bool uhallibs::Axi4Lite::MappedFile::haveLock |
( |
| ) |
const |
◆ lock()
void uhallibs::Axi4Lite::MappedFile::lock |
( |
| ) |
|
Definition at line 150 of file ProtocolAxi4Lite.cpp.
150 {
151 if (flock(
mFd, LOCK_EX) == -1) {
152 ipc::exception::MutexError lExc;
153 log(lExc,
"Failed to lock device file ", uhal::Quote(
mPath),
154 "; errno=", Integer(errno),
", meaning ", uhal::Quote(
strerror(errno)));
155 throw lExc;
156 }
158}
◆ open()
void uhallibs::Axi4Lite::MappedFile::open |
( |
| ) |
|
Open bus file and map it to memory.
Definition at line 43 of file ProtocolAxi4Lite.cpp.
43 {
44 if (
mBar !=
nullptr)
return;
45
48 return;
49 }
50
52 mBar = (lBar == MAP_FAILED ? nullptr : (uint32_t*)lBar);
53}
void open()
Open bus file and map it to memory.
◆ read()
void uhallibs::Axi4Lite::MappedFile::read |
( |
const uint32_t | aAddr, |
|
|
const uint32_t | aNrWords, |
|
|
std::vector< uint32_t > & | aValues ) |
Definition at line 92 of file ProtocolAxi4Lite.cpp.
93 {
95
96 for (size_t i(0); i < aNrWords; ++i) {
97 aValues.push_back(le32toh(
mBar[aAddr + i]));
98 }
99}
◆ setLength()
void uhallibs::Axi4Lite::MappedFile::setLength |
( |
size_t | aLength | ) |
|
◆ setPath()
void uhallibs::Axi4Lite::MappedFile::setPath |
( |
const std::string & | aPath | ) |
|
◆ unlock()
void uhallibs::Axi4Lite::MappedFile::unlock |
( |
| ) |
|
Definition at line 160 of file ProtocolAxi4Lite.cpp.
160 {
161 if (flock(
mFd, LOCK_UN) == -1) {
162 log(uhal::Warning(),
"Failed to unlock device file ", uhal::Quote(
mPath),
163 "; errno=", Integer(errno),
", meaning ", uhal::Quote(
strerror(errno)));
164 } else
166}
◆ write() [1/3]
void uhallibs::Axi4Lite::MappedFile::write |
( |
const uint32_t | aAddr, |
|
|
const std::vector< std::pair< const uint8_t *, size_t > > & | aData ) |
Definition at line 119 of file ProtocolAxi4Lite.cpp.
120 {
122
123 size_t lNrBytes = 0;
124 for (size_t i = 0; i < aData.size(); i++) lNrBytes += aData.at(i).second;
125
126 assert((lNrBytes % 4) == 0);
127 size_t lNrWords = lNrBytes/4;
128
130
131 size_t k(0);
132 for (size_t i = 0; i < aData.size(); ++i) {
133 for (size_t j = 0; j < aData.at(i).second; ++j) {
134 mBuffer[k] = aData.at(i).first[j];
135 ++k;
136 }
137 }
138
139 auto mBuffer32b =
reinterpret_cast<const uint32_t*
>(
mBuffer);
140
141 for (size_t i(0); i<lNrWords; ++i) {
142 mBar[aAddr + i] = htole32(mBuffer32b[i]);
143 }
144
145
146}
void createBuffer(const size_t aNrBytes)
Create a local buffer.
◆ write() [2/3]
void uhallibs::Axi4Lite::MappedFile::write |
( |
const uint32_t | aAddr, |
|
|
const std::vector< uint32_t > & | aValues ) |
Definition at line 101 of file ProtocolAxi4Lite.cpp.
101 {
102 write(aAddr,
reinterpret_cast<const uint8_t*
>(aValues.data()),
103 4 * aValues.size());
104}
void write(const uint32_t aAddr, const std::vector< uint32_t > &aValues)
◆ write() [3/3]
void uhallibs::Axi4Lite::MappedFile::write |
( |
const uint32_t | aAddr, |
|
|
const uint8_t *const | aPtr, |
|
|
const size_t | aNrBytes ) |
Definition at line 106 of file ProtocolAxi4Lite.cpp.
107 {
109
110 assert((aNrBytes % 4) == 0);
111 uint32_t lNrWordsData = aNrBytes / 4;
112
113 auto lPtr32 = reinterpret_cast<const uint32_t*>(aPtr);
114 for (size_t i(0); i < lNrWordsData; ++i) {
115 mBar[aAddr + i] = lPtr32[i];
116 }
117}
◆ mBar
uint32_t* uhallibs::Axi4Lite::MappedFile::mBar |
|
private |
◆ mBuffer
char* uhallibs::Axi4Lite::MappedFile::mBuffer |
|
private |
◆ mBufferSize
size_t uhallibs::Axi4Lite::MappedFile::mBufferSize |
|
private |
◆ mFd
int uhallibs::Axi4Lite::MappedFile::mFd |
|
private |
◆ mLength
size_t uhallibs::Axi4Lite::MappedFile::mLength |
|
private |
◆ mLocked
bool uhallibs::Axi4Lite::MappedFile::mLocked |
|
private |
◆ mPath
std::string uhallibs::Axi4Lite::MappedFile::mPath |
|
private |
◆ mProtFlags
int uhallibs::Axi4Lite::MappedFile::mProtFlags |
|
private |
The documentation for this class was generated from the following files: