Fletchgen
The Fletcher Design Generator
axi4_lite.h
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 #pragma once
16 
17 #include <cerata/api.h>
18 #include <utility>
19 #include <memory>
20 #include <string>
21 
22 namespace fletchgen {
23 
24 using cerata::ClockDomain;
25 using cerata::Type;
26 using cerata::Port;
27 
29 struct Axi4LiteSpec {
30  explicit Axi4LiteSpec(size_t data_width = 32, size_t addr_width = 32, size_t offset = 0)
32  if (offset % (data_width / 8) != 0) {
33  throw std::runtime_error("Offset must be integer multiple of data width / 8.");
34  }
35  }
37  size_t data_width = 32;
39  size_t addr_width = 32;
41  size_t offset = 0;
43  [[nodiscard]] std::string ToString() const;
45  [[nodiscard]] std::string ToAxiTypeName() const;
46 };
47 
49 struct Axi4LitePort : public Port {
52 
54  Axi4LitePort(Port::Dir dir, Axi4LiteSpec spec, std::string name = "mmio",
55  std::shared_ptr<ClockDomain> domain = cerata::default_domain());
57  std::shared_ptr<Object> Copy() const override;
58 };
59 
61 std::shared_ptr<Type> axi4_lite_type(Axi4LiteSpec spec = Axi4LiteSpec());
62 
70 std::shared_ptr<Axi4LitePort> axi4_lite(Port::Dir dir,
71  const std::shared_ptr<ClockDomain> &domain = cerata::default_domain(),
72  Axi4LiteSpec spec = Axi4LiteSpec());
73 
74 } // 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
An AXI4-lite port derived from an AXI4-lite specification.
Definition: axi4_lite.h:49
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
size_t offset
The offset for all registers.
Definition: axi4_lite.h:41
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