15 #include "fletchgen/mantle.h"
17 #include <cerata/api.h>
18 #include <fletcher/common.h>
26 #include "fletchgen/basic_types.h"
27 #include "fletchgen/bus.h"
28 #include "fletchgen/nucleus.h"
29 #include "fletchgen/axi4_lite.h"
30 #include "fletchgen/external.h"
41 const std::vector<std::shared_ptr<RecordBatch>> &recordbatches,
42 const std::shared_ptr<Nucleus> &
nucleus,
45 : Component(std::move(name)), bus_dim_(bus_dim) {
50 auto iw = index_width();
51 auto tw = tag_width();
58 std::shared_ptr<Port> bus_rd =
bus_port(
"rd_mst", Port::OUT, bus_rd_spec);
59 std::shared_ptr<Port> bus_wr =
bus_port(
"wr_mst", Port::OUT, bus_wr_spec);
62 auto bcr = port(
"bcd",
cr(), Port::Dir::IN,
bus_cd());
63 auto kcr = port(
"kcd",
cr(), Port::Dir::IN,
kernel_cd());
83 std::vector<BusPort *> rb_bus_ports;
85 for (
const auto &rb : recordbatches) {
87 auto rbi = Instantiate(rb.get());
91 rbi->prt(
"bcd") <<= bcr;
92 rbi->prt(
"kcd") <<= kcr;
94 rbi->par(
"INDEX_WIDTH")->SetValue(iw);
95 rbi->par(
"TAG_WIDTH")->SetValue(tw);
98 auto rbi_bus_ports = rbi->GetAll<
BusPort>();
99 rb_bus_ports.insert(rb_bus_ports.end(), rbi_bus_ports.begin(), rbi_bus_ports.end());
102 auto field_ports = rbi->GetAll<
FieldPort>();
104 for (
const auto &fp : field_ports) {
105 if (fp->function_ == FieldPort::Function::ARROW) {
107 auto prefix = rb->schema()->name() +
"_" + fp->
field_->name();
108 Connect(
nucleus_inst_->par(bus_addr_width(0, prefix)), par(bus_addr_width()));
113 if (fp->dir() == cerata::Term::Dir::OUT) {
118 }
else if (fp->function_ == FieldPort::Function::COMMAND) {
120 }
else if (fp->function_ == FieldPort::Function::UNLOCK) {
141 std::vector<BusSpec> bus_specs;
142 for (
const auto &bp : rb_bus_ports) {
143 bus_specs.push_back(
BusSpec(bp->spec_));
145 cerata::FilterDuplicates(&bus_specs);
148 std::unordered_map<BusSpec, Instance *> arb_map;
149 for (
const auto &b : bus_specs) {
150 auto prefix = b.ToName();
151 Instance *inst = Instantiate(
bus_arbiter(b.func), prefix +
"_inst");
154 inst->prt(
"bcd") <<= bcr;
160 Connect(bus_rd, inst->Get<Port>(
"mst"));
163 Connect(bus_wr, inst->Get<Port>(
"mst"));
170 for (
const auto &bp : rb_bus_ports) {
172 auto arb = arb_map[
BusSpec(bp->spec_)];
174 auto array = arb->prt_arr(
"bsv");
176 Connect(
array->Append(), bp);
180 auto ext = external();
182 auto pf = cerata::port(
"ext", ext.value(), Port::Dir::OUT);
189 std::shared_ptr<Mantle>
mantle(
const std::string &name,
190 const std::vector<std::shared_ptr<RecordBatch>> &recordbatches,
191 const std::shared_ptr<Nucleus> &
nucleus,
194 return std::make_shared<Mantle>(name, recordbatches,
nucleus, bus_spec, axi_spec);
std::vector< Instance * > recordbatch_instances_
The RecordBatch instances.
Mantle(std::string name, const std::vector< std::shared_ptr< RecordBatch >> &recordbatches, const std::shared_ptr< Nucleus > &nucleus, BusDim bus_dim, Axi4LiteSpec axi_spec)
Construct a Mantle based on a SchemaSet.
std::shared_ptr< Nucleus > nucleus() const
Return the kernel component of this Mantle.
Instance * nucleus_inst_
Shortcut to the instantiated Nucleus.
Contains all classes and functions related to Fletchgen.
std::shared_ptr< Mantle > mantle(const std::string &name, const std::vector< std::shared_ptr< RecordBatch >> &recordbatches, const std::shared_ptr< Nucleus > &nucleus, BusDim bus_spec, Axi4LiteSpec axi_spec)
Construct a Mantle and return a shared pointer to it.
std::shared_ptr< Nucleus > nucleus(const std::string &name, const std::vector< std::shared_ptr< RecordBatch >> &recordbatches, const std::shared_ptr< Kernel > &kernel, const std::shared_ptr< Component > &mmio, Axi4LiteSpec axi_spec)
Make an Nucleus component based on RecordBatch components. Returns a shared pointer to the new Nucleu...
std::shared_ptr< ClockDomain > kernel_cd()
Fletcher accelerator clock domain.
std::shared_ptr< Type > cr()
Fletcher clock/reset;.
Component * bus_arbiter(BusFunction function)
Return a Cerata model of a BusArbiter.
std::shared_ptr< Axi4LitePort > axi4_lite(Port::Dir dir, const std::shared_ptr< ClockDomain > &domain, Axi4LiteSpec spec)
Make a new AXI4-lite port, returning a shared pointer to it.
void ConnectBusParam(cerata::Graph *dst, const std::string &prefix, const BusDimParams &src, cerata::NodeMap *rebinding)
Find and connect all prefixed bus params on a graph to the supplied source params,...
Component * array(Mode mode)
Return a Cerata component model of an Array(Reader/Writer).
std::shared_ptr< ClockDomain > bus_cd()
Fletcher bus clock domain.
std::shared_ptr< BusPort > bus_port(const std::string &name, Port::Dir dir, const BusSpecParams ¶ms)
Make a new port and return a shared pointer to it.
@ READ
Interface reads from memory.
@ WRITE
Interface writes to memory.
AXI4-lite bus specification.
Holds bus interface dimensions.
Holds bus parameters based on bus dimensions, that has actual nodes representing the dimensions.
A port derived from bus parameters.
Holds bus dimensions and function, without instantiating Cerata nodes.
Holds bus parameters and function based on bus dimensions, that has actual nodes representing the dim...
A port derived from an Arrow field.
std::shared_ptr< arrow::Field > field_
The Arrow field this port was derived from.