From b5682290c26d4a7d10ba34abaa10f09e4520e3dc Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Tue, 9 Jan 2024 17:06:23 +0100 Subject: [PATCH] I2c: use Switch::selfTest to check i2c bus Signed-off-by: Niklas Eiling --- fpga/include/villas/fpga/ips/i2c.hpp | 1 + fpga/lib/ips/i2c.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/fpga/include/villas/fpga/ips/i2c.hpp b/fpga/include/villas/fpga/ips/i2c.hpp index d342b4cc8..132e88f9e 100644 --- a/fpga/include/villas/fpga/ips/i2c.hpp +++ b/fpga/include/villas/fpga/ips/i2c.hpp @@ -32,6 +32,7 @@ public: I2c(); virtual ~I2c(); virtual bool init() override; + virtual bool check() override; virtual bool reset() override; bool write(u8 address, std::vector &data); bool read(u8 address, std::vector &data, size_t max_read); diff --git a/fpga/lib/ips/i2c.cpp b/fpga/lib/ips/i2c.cpp index 186c96f89..577700ac8 100644 --- a/fpga/lib/ips/i2c.cpp +++ b/fpga/lib/ips/i2c.cpp @@ -60,6 +60,13 @@ bool I2c::init() { return true; } +bool I2c::check() { + if (!initDone) { + throw RuntimeError("I2C not initialized"); + } + return getSwitch().selfTest(); +} + bool I2c::reset() { // we cannot lock here because this may be called in a destructor XIic_Reset(&xIic);