Skip to content

Commit

Permalink
fpga: remove exceptions from AxisCache
Browse files Browse the repository at this point in the history
Signed-off-by: Niklas Eiling <[email protected]>
  • Loading branch information
n-eiling committed Nov 13, 2024
1 parent 394e8a6 commit 9afee0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
8 changes: 4 additions & 4 deletions fpga/include/villas/fpga/ips/axis_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class AxisCache : public Node {
std::list<MemoryBlockName> getMemoryBlocks() const override {
return {registerMemory};
}
void setRegister(size_t reg, uint32_t value);
uint32_t getRegister(size_t reg);
void resetRegister(size_t reg);
void resetAllRegisters();
bool setRegister(size_t reg, uint32_t value);
bool getRegister(size_t reg, uint32_t &value);
bool resetRegister(size_t reg);
bool resetAllRegisters();
};

} // namespace ip
Expand Down
31 changes: 21 additions & 10 deletions fpga/lib/ips/axis_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ bool AxisCache::check() {
}

for (size_t i = 1; i < registerNum; i++) {
buf = getRegister(i);
if (!getRegister(i, buf)) {
logger->error("Failed to read register {}", i);
return false;
}
if (buf != 0x00FF00FF) {
logger->error("Register {}: 0x{:08x} != 0x{:08x}", i, buf, i);
return false;
Expand All @@ -46,7 +49,11 @@ bool AxisCache::check() {
resetAllRegisters();

for (size_t i = 0; i < registerNum; i++) {
logger->debug("Register {}: 0x{:08x}", i, getRegister(i));
if (!getRegister(i, buf)) {
logger->error("Failed to read register {}", i);
return false;
}
logger->debug("Register {}: 0x{:08x}", i, buf);
}

return true;
Expand All @@ -57,28 +64,32 @@ void AxisCache::invalidate() {
logger->info("invalidated AXIS cache.");
}

void AxisCache::setRegister(size_t reg, uint32_t value) {
bool AxisCache::setRegister(size_t reg, uint32_t value) {
if (reg >= registerNum) {
logger->error("Register index out of range: {}/{}", reg, registerNum);
throw std::out_of_range("Register index out of range");
return false;
}
Xil_Out32(getBaseAddr(registerMemory) + REGISTER_OUT(reg), value);
return true;
}

uint32_t AxisCache::getRegister(size_t reg) {
bool AxisCache::getRegister(size_t reg, uint32_t &value) {
if (reg >= registerNum) {
logger->error("Register index out of range: {}/{}", reg, registerNum);
throw std::out_of_range("Register index out of range");
return false;
}
return Xil_In32(getBaseAddr(registerMemory) + REGISTER_OUT(reg));
value = Xil_In32(getBaseAddr(registerMemory) + REGISTER_OUT(reg));
return true;
}

void AxisCache::resetRegister(size_t reg) { setRegister(reg, 0); }
bool AxisCache::resetRegister(size_t reg) { return setRegister(reg, 0); }

void AxisCache::resetAllRegisters() {
bool AxisCache::resetAllRegisters() {
bool result = true;
for (size_t i = 1; i < registerNum; i++) {
resetRegister(i);
result &= resetRegister(i);
}
return result;
}

AxisCache::~AxisCache() {}
Expand Down

0 comments on commit 9afee0b

Please sign in to comment.