Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit e18e284

Browse files
committed
add draft for i2c drvier implementation
Signed-off-by: Niklas Eiling <[email protected]>
1 parent da97253 commit e18e284

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

Diff for: include/villas/fpga/ips/i2c.hpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* I2C driver
2+
*
3+
* Author: Niklas Eiling <[email protected]>
4+
* SPDX-FileCopyrightText: 2023 Niklas Eiling <[email protected]>
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#pragma once
9+
10+
#include <fmt/ostream.h>
11+
#include <villas/config.hpp>
12+
#include <villas/exceptions.hpp>
13+
#include <villas/fpga/node.hpp>
14+
#include <villas/memory.hpp>
15+
#include <xilinx/xiic.h>
16+
17+
namespace villas {
18+
namespace fpga {
19+
namespace ip {
20+
21+
class I2c : public Node {
22+
public:
23+
friend class I2cFactory;
24+
25+
virtual ~I2c();
26+
virtual bool init() override;
27+
bool reset() override;
28+
bool write(std::list<u8> &data);
29+
bool read(std::list<u8> &data, size_t max_read);
30+
31+
private:
32+
static constexpr char registerMemory[] = "Reg";
33+
34+
XIic xIic;
35+
XIic_Config xConfig;
36+
37+
std::mutex hwLock;
38+
39+
bool configDone = false;
40+
41+
class I2cFactory : NodeFactory {
42+
43+
public:
44+
virtual std::string getName() const { return "i2c"; }
45+
46+
virtual std::string getDescription() const {
47+
return "Xilinx's AXI4 iic IP";
48+
}
49+
50+
private:
51+
virtual Vlnv getCompatibleVlnv() const {
52+
return Vlnv("xilinx.com:ip:axi_iic:");
53+
}
54+
55+
// Create a concrete IP instance
56+
Core *make() const { return new Dma; };
57+
58+
protected:
59+
virtual void parse(Core &ip, json_t *json) override;
60+
61+
virtual void configurePollingMode(Core &ip, PollingMode mode) override {
62+
dynamic_cast<Dma &>(ip).polling = (mode == POLL);
63+
}
64+
};
65+
66+
} // namespace ip
67+
} // namespace fpga
68+
} // namespace villas
69+
70+
#ifndef FMT_LEGACY_OSTREAM_FORMATTER
71+
template <>
72+
class fmt::formatter<villas::fpga::ip::I2c> : public fmt::ostream_formatter {};
73+
#endif

Diff for: lib/ips/i2c.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* I2C driver
2+
*
3+
* Author: Niklas Eiling <[email protected]>
4+
* SPDX-FileCopyrightText: 2023 Niklas Eiling <[email protected]>
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <sstream>
9+
#include <string>
10+
11+
#include <xilinx/xiic.h>
12+
13+
#include <villas/fpga/ips/i2c.hpp>
14+
#include <villas/fpga/ips/intc.hpp>
15+
16+
using namespace villas::fpga::ip;
17+
18+
I2c::I2c() : Node("i2c") {}
19+
20+
I2c::~I2c() {}
21+
22+
bool I2c::init() override {}
23+
24+
bool I2c::reset() override {}
25+
26+
bool I2c::write(std::list<u8> &data) {}
27+
28+
bool I2c::read(std::list<u8> &data, size_t max_read) {}
29+
30+
void I2cFactory::parse(Core &ip, json_t *cfg) {
31+
NodeFactory::parse(ip, cfg);
32+
33+
auto &i2c = dynamic_cast<I2c &>(ip);
34+
35+
int i2c_frequency = 0;
36+
37+
json_error_t err;
38+
int ret = json_unpack_ex(
39+
cfg, &err, 0, "{ s: { s?: i, s?: i, s?: i, s?: i, s?: i} }", "parameters",
40+
"c_iic_freq", &i2c_frequency, "c_ten_bit_adr", &i2c.xConfig.Has10BitAddr,
41+
"c_gpo_width", &i2c.xConfig.GpOutWidth, "component_name",
42+
&i2c.xConfig.Name, "c_baseaddr", &i2c.xConfig.BaseAddress);
43+
if (ret != 0)
44+
throw ConfigError(cfg, err, "", "Failed to parse DMA configuration");
45+
46+
dma.configDone = true;
47+
}
48+
49+
static I2cFactory f;

Diff for: thirdparty/libxil

Submodule libxil updated 151 files

0 commit comments

Comments
 (0)