mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
add draft for i2c drvier implementation
Signed-off-by: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
This commit is contained in:
parent
ba71f6384f
commit
d61337023e
3 changed files with 123 additions and 1 deletions
73
fpga/include/villas/fpga/ips/i2c.hpp
Normal file
73
fpga/include/villas/fpga/ips/i2c.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* I2C driver
|
||||
*
|
||||
* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
||||
* SPDX-FileCopyrightText: 2023 Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
#include <villas/config.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/fpga/node.hpp>
|
||||
#include <villas/memory.hpp>
|
||||
#include <xilinx/xiic.h>
|
||||
|
||||
namespace villas {
|
||||
namespace fpga {
|
||||
namespace ip {
|
||||
|
||||
class I2c : public Node {
|
||||
public:
|
||||
friend class I2cFactory;
|
||||
|
||||
virtual ~I2c();
|
||||
virtual bool init() override;
|
||||
bool reset() override;
|
||||
bool write(std::list<u8> &data);
|
||||
bool read(std::list<u8> &data, size_t max_read);
|
||||
|
||||
private:
|
||||
static constexpr char registerMemory[] = "Reg";
|
||||
|
||||
XIic xIic;
|
||||
XIic_Config xConfig;
|
||||
|
||||
std::mutex hwLock;
|
||||
|
||||
bool configDone = false;
|
||||
|
||||
class I2cFactory : NodeFactory {
|
||||
|
||||
public:
|
||||
virtual std::string getName() const { return "i2c"; }
|
||||
|
||||
virtual std::string getDescription() const {
|
||||
return "Xilinx's AXI4 iic IP";
|
||||
}
|
||||
|
||||
private:
|
||||
virtual Vlnv getCompatibleVlnv() const {
|
||||
return Vlnv("xilinx.com:ip:axi_iic:");
|
||||
}
|
||||
|
||||
// Create a concrete IP instance
|
||||
Core *make() const { return new Dma; };
|
||||
|
||||
protected:
|
||||
virtual void parse(Core &ip, json_t *json) override;
|
||||
|
||||
virtual void configurePollingMode(Core &ip, PollingMode mode) override {
|
||||
dynamic_cast<Dma &>(ip).polling = (mode == POLL);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ip
|
||||
} // namespace fpga
|
||||
} // namespace villas
|
||||
|
||||
#ifndef FMT_LEGACY_OSTREAM_FORMATTER
|
||||
template <>
|
||||
class fmt::formatter<villas::fpga::ip::I2c> : public fmt::ostream_formatter {};
|
||||
#endif
|
49
fpga/lib/ips/i2c.cpp
Normal file
49
fpga/lib/ips/i2c.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* I2C driver
|
||||
*
|
||||
* Author: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
||||
* SPDX-FileCopyrightText: 2023 Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <xilinx/xiic.h>
|
||||
|
||||
#include <villas/fpga/ips/i2c.hpp>
|
||||
#include <villas/fpga/ips/intc.hpp>
|
||||
|
||||
using namespace villas::fpga::ip;
|
||||
|
||||
I2c::I2c() : Node("i2c") {}
|
||||
|
||||
I2c::~I2c() {}
|
||||
|
||||
bool I2c::init() override {}
|
||||
|
||||
bool I2c::reset() override {}
|
||||
|
||||
bool I2c::write(std::list<u8> &data) {}
|
||||
|
||||
bool I2c::read(std::list<u8> &data, size_t max_read) {}
|
||||
|
||||
void I2cFactory::parse(Core &ip, json_t *cfg) {
|
||||
NodeFactory::parse(ip, cfg);
|
||||
|
||||
auto &i2c = dynamic_cast<I2c &>(ip);
|
||||
|
||||
int i2c_frequency = 0;
|
||||
|
||||
json_error_t err;
|
||||
int ret = json_unpack_ex(
|
||||
cfg, &err, 0, "{ s: { s?: i, s?: i, s?: i, s?: i, s?: i} }", "parameters",
|
||||
"c_iic_freq", &i2c_frequency, "c_ten_bit_adr", &i2c.xConfig.Has10BitAddr,
|
||||
"c_gpo_width", &i2c.xConfig.GpOutWidth, "component_name",
|
||||
&i2c.xConfig.Name, "c_baseaddr", &i2c.xConfig.BaseAddress);
|
||||
if (ret != 0)
|
||||
throw ConfigError(cfg, err, "", "Failed to parse DMA configuration");
|
||||
|
||||
dma.configDone = true;
|
||||
}
|
||||
|
||||
static I2cFactory f;
|
2
fpga/thirdparty/libxil
vendored
2
fpga/thirdparty/libxil
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 60ce084ad9f440f807183b6626d7aa56005f25a7
|
||||
Subproject commit 0294cee460cb6e4c09881c90b9b255ba9d7a99b3
|
Loading…
Add table
Reference in a new issue