Fletchgen
The Fletcher Design Generator
bus.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 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "fletchgen/basic_types.h"
25 
26 namespace fletchgen {
27 
28 using cerata::Instance;
29 using cerata::Component;
30 using cerata::Port;
31 using cerata::intl;
32 using cerata::Object;
33 
34 // Bus channel constructs.
35 PARAM_DECL_FACTORY(bus_addr_width, 64)
36 PARAM_DECL_FACTORY(bus_data_width, 512)
37 PARAM_DECL_FACTORY(bus_len_width, 8)
38 PARAM_DECL_FACTORY(bus_burst_step_len, 4)
39 PARAM_DECL_FACTORY(bus_burst_max_len, 16)
40 
42 enum class BusFunction {
43  READ,
44  WRITE
45 };
46 
48 struct BusDim {
49  uint32_t aw = 64;
50  uint32_t dw = 512;
51  uint32_t lw = 8;
52  uint32_t bs = 1;
53  uint32_t bm = 16;
54 
56  static BusDim FromString(const std::string &str, BusDim default_to);
57 
59  [[nodiscard]] std::string ToString() const;
61  [[nodiscard]] std::string ToName() const;
62 };
63 
65 bool operator==(const BusDim &lhs, const BusDim &rhs);
66 
68 struct BusDimParams {
70  explicit BusDimParams(cerata::Graph *parent, BusDim dim = BusDim{}, const std::string &prefix = "");
72  explicit BusDimParams(const std::shared_ptr<cerata::Graph> &parent,
73  BusDim spec = BusDim{},
74  const std::string &prefix = "")
75  : BusDimParams(parent.get(), spec, prefix) {}
79  std::shared_ptr<Node> aw;
80  std::shared_ptr<Node> dw;
81  std::shared_ptr<Node> lw;
82  std::shared_ptr<Node> bs;
83  std::shared_ptr<Node> bm;
84 
86  [[nodiscard]] std::vector<std::shared_ptr<Object>> all() const;
87 };
88 
90 struct BusSpecParams {
96  [[nodiscard]] std::string ToName() const;
97 };
98 
100 struct BusSpec {
102  BusSpec() = default;
104  explicit BusSpec(const BusSpecParams &params) : dim(params.dim.plain), func(params.func) {}
110  [[nodiscard]] std::string ToName() const;
111 };
112 
114 bool operator==(const BusSpec &lhs, const BusSpec &rhs);
115 
117 std::shared_ptr<Type> bus_read(const std::shared_ptr<Node> &addr_width,
118  const std::shared_ptr<Node> &data_width,
119  const std::shared_ptr<Node> &len_width);
120 
122 std::shared_ptr<Type> bus_write(const std::shared_ptr<Node> &addr_width,
123  const std::shared_ptr<Node> &data_width,
124  const std::shared_ptr<Node> &len_width);
125 
127 std::shared_ptr<Type> bus(const BusSpecParams &param);
128 
130 struct BusPort : public Port {
132  BusPort(const std::string &name,
133  Port::Dir dir,
134  const BusSpecParams &params,
135  std::shared_ptr<ClockDomain> domain = bus_cd())
136  : Port(name, bus(params), dir, std::move(domain)), spec_(params) {}
137 
140 
142  std::shared_ptr<Object> Copy() const override;
143 };
145 std::shared_ptr<BusPort> bus_port(const std::string &name, Port::Dir dir, const BusSpecParams &params);
147 std::shared_ptr<BusPort> bus_port(Port::Dir dir, const BusSpecParams &params);
148 
149 // TODO(johanpel): Perhaps generalize and build some sort of parameter struct/bundle in cerata for fast connection.
151 void ConnectBusParam(cerata::Graph *dst,
152  const std::string &prefix,
153  const BusDimParams &src,
154  cerata::NodeMap *rebinding);
155 
169 Component *bus_arbiter(BusFunction function);
170 
172 std::shared_ptr<Component> BusReadSerializer();
173 
175 std::shared_ptr<Component> BusWriteSerializer();
176 
177 } // namespace fletchgen
178 
179 
181 template<>
182 struct std::hash<fletchgen::BusSpec> {
184  size_t operator()(fletchgen::BusSpec const &spec) const noexcept {
185  auto str = spec.ToName();
186  return std::hash<std::string>()(str);
187  }
188 };
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
std::shared_ptr< Component > BusWriteSerializer()
Return a BusWriteSerializer component.
std::shared_ptr< Type > bus_write(const std::shared_ptr< Node > &addr_width, const std::shared_ptr< Node > &data_width, const std::shared_ptr< Node > &len_width)
Return a Cerata type for a Fletcher bus write interface.
Definition: bus.cc:61
std::shared_ptr< Type > bus_read(const std::shared_ptr< Node > &addr_width, const std::shared_ptr< Node > &data_width, const std::shared_ptr< Node > &len_width)
Return a Cerata type for a Fletcher bus read interface.
Definition: bus.cc:49
std::shared_ptr< Component > BusReadSerializer()
Return a BusReadSerializer component.
Definition: bus.cc:138
Component * bus_arbiter(BusFunction function)
Return a Cerata model of a BusArbiter.
Definition: bus.cc:82
std::shared_ptr< Type > bus(const BusSpecParams &spec)
Fletcher bus type with access mode conveyed through spec of params.
Definition: bus.cc:166
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,...
Definition: bus.cc:191
std::shared_ptr< ClockDomain > bus_cd()
Fletcher bus clock domain.
Definition: basic_types.cc:67
std::shared_ptr< BusPort > bus_port(const std::string &name, Port::Dir dir, const BusSpecParams &params)
Make a new port and return a shared pointer to it.
Definition: bus.cc:175
bool operator==(const BusSpec &lhs, const BusSpec &rhs)
Returns true if BusSpecs are equal.
Definition: bus.cc:162
BusFunction
Defines function of a bus interface (read/write).
Definition: bus.h:42
@ READ
Interface reads from memory.
@ WRITE
Interface writes to memory.
Holds bus interface dimensions.
Definition: bus.h:48
uint32_t dw
Data width.
Definition: bus.h:50
std::string ToString() const
Return a human-readable version of the bus dimensions.
Definition: bus.cc:254
std::string ToName() const
Return a shorter somewhat human-readable name for this BusDims, can be used for comparisons.
Definition: bus.cc:216
uint32_t lw
Len width.
Definition: bus.h:51
static BusDim FromString(const std::string &str, BusDim default_to)
Returns a BusDim from a string. See [common/cpp/include/fletcher/arrow-utils.h] for more info.
Definition: bus.cc:237
uint32_t bs
Burst step length.
Definition: bus.h:52
uint32_t aw
Address width.
Definition: bus.h:49
uint32_t bm
Burst max length.
Definition: bus.h:53
Holds bus parameters based on bus dimensions, that has actual nodes representing the dimensions.
Definition: bus.h:68
BusDim plain
Plain bus dimensions, not as nodes.
Definition: bus.h:77
BusDimParams(const std::shared_ptr< cerata::Graph > &parent, BusDim spec=BusDim{}, const std::string &prefix="")
Construct a new bunch of bus parameters based on a bus spec and function, and add them to a graph.
Definition: bus.h:72
std::shared_ptr< Node > aw
Value nodes.
Definition: bus.h:79
std::shared_ptr< Node > lw
Len width node.
Definition: bus.h:81
BusDimParams(cerata::Graph *parent, BusDim dim=BusDim{}, const std::string &prefix="")
Construct a new bunch of bus parameters based on a bus spec and function, and add them to a graph.
Definition: bus.cc:268
std::shared_ptr< Node > dw
Data width node.
Definition: bus.h:80
std::vector< std::shared_ptr< Object > > all() const
Return all parameters as an object vector.
Definition: bus.cc:264
std::shared_ptr< Node > bs
Burst step length node.
Definition: bus.h:82
std::shared_ptr< Node > bm
Burst max length node.
Definition: bus.h:83
A port derived from bus parameters.
Definition: bus.h:130
std::shared_ptr< Object > Copy() const override
Deep-copy the BusPort.
Definition: bus.cc:208
BusSpecParams spec_
The bus spec to which the type generics of the bus port are bound.
Definition: bus.h:139
BusPort(const std::string &name, Port::Dir dir, const BusSpecParams &params, std::shared_ptr< ClockDomain > domain=bus_cd())
Construct a new port based on a bus parameters..
Definition: bus.h:132
Holds bus dimensions and function, without instantiating Cerata nodes.
Definition: bus.h:100
BusSpec(const BusSpecParams &params)
BusSpec constructor.
Definition: bus.h:104
std::string ToName() const
Return a shorter somewhat human-readable name, can be used for comparisons.
Definition: bus.cc:277
BusDim dim
Bus dimensions.
Definition: bus.h:106
BusSpec()=default
Default BusSpec constructor.
BusFunction func
Bus function.
Definition: bus.h:108
Holds bus parameters and function based on bus dimensions, that has actual nodes representing the dim...
Definition: bus.h:90
std::string ToName() const
Return a shorter somewhat human-readable name, can be used for comparisons.
Definition: bus.cc:281
BusFunction func
Bus function.
Definition: bus.h:94
BusDimParams dim
Bus dimensions.
Definition: bus.h:92
size_t operator()(fletchgen::BusSpec const &spec) const noexcept
Hash a BusSpec.
Definition: bus.h:184