Fletchgen
The Fletcher Design Generator
axi4_lite.cc
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "fletchgen/axi4_lite.h"
16 
17 #include <cerata/api.h>
18 
19 #include "fletchgen/utils.h"
20 
21 namespace fletchgen {
22 
23 using cerata::record;
24 using cerata::field;
25 using cerata::stream;
26 using cerata::vector;
27 using cerata::Object;
28 
29 std::shared_ptr<Type> axi4_lite_type(Axi4LiteSpec spec) {
30  auto axi_typename = spec.ToAxiTypeName();
31  auto opt_existing_axi_typename = cerata::default_type_pool()->Get(axi_typename);
32  if (opt_existing_axi_typename) {
33  // AXI-lite type already exists in type pool, just return that.
34  return opt_existing_axi_typename.value()->shared_from_this();
35  } else {
36  auto new_axi_lite_type = record(axi_typename, {
37  NoSep(field("aw", stream("addr", vector(spec.addr_width)))),
38  NoSep(field("w", stream(record({field("data", vector(spec.data_width)),
39  field("strb", vector(spec.data_width / 8))})))),
40  NoSep(field("b", stream("resp", vector(2)))->Reverse()),
41  NoSep(field("ar", stream("addr", vector(spec.addr_width)))),
42  NoSep(field("r", stream(record({field("data", vector(spec.data_width)),
43  field("resp", vector(2))})))->Reverse())
44  });
45  cerata::default_type_pool()->Add(new_axi_lite_type);
46  return new_axi_lite_type;
47  }
48 }
49 
50 std::string Axi4LiteSpec::ToString() const {
51  std::stringstream str;
52  str << "MmioSpec[";
53  str << "addr:" << addr_width;
54  str << ", dat:" << data_width;
55  str << "]";
56  return str.str();
57 }
58 
59 std::string Axi4LiteSpec::ToAxiTypeName() const {
60  std::stringstream str;
61  str << "MMIO";
62  str << "_A" << addr_width;
63  str << "_D" << data_width;
64  return str.str();
65 }
66 
67 std::shared_ptr<Axi4LitePort> axi4_lite(Port::Dir dir, const std::shared_ptr<ClockDomain> &domain, Axi4LiteSpec spec) {
68  return std::make_shared<Axi4LitePort>(dir, spec, "mmio", domain);
69 }
70 
71 Axi4LitePort::Axi4LitePort(Port::Dir dir, Axi4LiteSpec spec, std::string name, std::shared_ptr<ClockDomain> domain) :
72  Port(std::move(name), axi4_lite_type(spec), dir, std::move(domain)), spec_(spec) {}
73 
74 std::shared_ptr<Object> Axi4LitePort::Copy() const {
75  return axi4_lite(dir_, domain_, spec_);
76 }
77 } // namespace fletchgen
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
std::shared_ptr< Type > axi4_lite_type(Axi4LiteSpec spec)
AXI4-lite port type.
Definition: axi4_lite.cc:29
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.
Definition: axi4_lite.cc:67
Axi4LitePort(Port::Dir dir, Axi4LiteSpec spec, std::string name="mmio", std::shared_ptr< ClockDomain > domain=cerata::default_domain())
Construct a new MmioPort.
Definition: axi4_lite.cc:71
Axi4LiteSpec spec_
The specification this port was derived from.
Definition: axi4_lite.h:51
std::shared_ptr< Object > Copy() const override
Make a copy of this AXI4-lite port.
Definition: axi4_lite.cc:74
AXI4-lite bus specification.
Definition: axi4_lite.h:29
std::string ToString() const
Return a human-readable representation of this Axi4LiteSpec.
Definition: axi4_lite.cc:50
std::string ToAxiTypeName() const
Return a Cerata type name based on this Axi4LiteSpec.
Definition: axi4_lite.cc:59
size_t data_width
The data width.
Definition: axi4_lite.h:37
size_t addr_width
The address width.
Definition: axi4_lite.h:39