OpenASIP  2.0
ProcessorWrapperBlock.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * @file ProcessorWrapperBlock.cc
26  *
27  * Implementation/Declaration of ProcessorWrapperBlock class.
28  *
29  * Created on: 7.9.2015
30  * @author Henry Linjam�ki 2015 (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "ProcessorWrapperBlock.hh"
35 
36 #include "Netlist.hh"
37 #include "NetlistTools.hh"
38 #include "NetlistFactories.hh"
39 #include "NetlistPort.hh"
40 #include "NetlistPortGroup.hh"
41 #include "SinglePortSSRAMBlock.hh"
43 #include "GlobalPackage.hh"
44 #include "MemoryBusInterface.hh"
45 
46 #include "FileSystem.hh"
47 #include "MathTools.hh"
48 #include "ControlUnit.hh"
49 #include "InverterBlock.hh"
50 
51 namespace ProGe {
52 
54  const ProGeContext& context, const BaseNetlistBlock& processorBlock)
55  : BaseNetlistBlock("proc", ""),
56  context_(context),
57  coreBlock_(processorBlock.shallowCopy()) {
58  assert(processorBlock.portCount() > 0);
59  assert(coreBlock_->portCount() > 0);
60 
61  // Wrapper interface //
64  NetlistPort* coreLocked = new OutPort("locked", "1");
65  addPort(coreLocked);
66 
67  // Instantiate core //
69 
70  // Memory instantiations and connections //
71  for (size_t i = 0; i < coreBlock_->portGroupCount(); i++) {
72  const NetlistPortGroup& portGrp = coreBlock_->portGroup(i);
73  SignalGroupType type = portGrp.assignedSignalGroup().type();
75  addInstructionMemory(portGrp);
76  } else if (type == SignalGroupType::BITMASKED_SRAM_PORT) {
77  auto dmemIf = dynamic_cast<const MemoryBusInterface*>(&portGrp);
78  assert(dmemIf != nullptr);
79  addDataMemory(*dmemIf);
80  } else if (type == SignalGroupType::BYTEMASKED_SRAM_PORT) {
81  auto dmemIf = dynamic_cast<const MemoryBusInterface*>(&portGrp);
82  assert(dmemIf != nullptr);
83  addDataMemory2(*dmemIf);
84  }
85  }
86 
87  connectClocks();
88  connectResets();
89  connectLockStatus(*coreLocked);
90 
91  // Package holding instruction bus constants
92  std::set<std::string> procPackages{context.globalPackage().name()};
93 
94  // Other packages possibly holding constants used in core ports.
95  for (size_t i = 0; i < processorBlock.packageCount(); i++) {
96  procPackages.insert(processorBlock.package(i));
97  }
98 
99  for (auto packageStr : procPackages) {
100  addPackage(packageStr);
101  }
102 
103  addPackage(context.coreEntityName() + "_params");
104 
105  // Handle unknown ports
107 }
108 
110 
111 void
113  const Path& targetBaseDir, HDL targetLang) const {
114  BaseNetlistBlock::writeSelf(targetBaseDir / "tb", targetLang);
115  BaseNetlistBlock::write(targetBaseDir, targetLang);
116 }
117 
118 void
120  const NetlistPortGroup& coreImemPort) {
121  using SigT = SignalType;
122  bool isRISCV = context_.adf().isRISCVMachine();
123 
124  const int imemWidthInMaus = (context_.adf().isRISCVMachine()) ? 4 : 1;
125  const int unusedBits = std::ceil(std::log2(imemWidthInMaus));
126 
127  std::string addrWidth = context_.globalPackage().fetchBlockAddressWidth();
128  if (isRISCV) {
129  const int unusedBits = std::ceil(std::log2(imemWidthInMaus));
130  addrWidth = context_.globalPackage().fetchBlockAddressWidth() + "-" +
131  std::to_string(unusedBits);
132  }
133 
136  "tb/imem_init.img", true);
137  addSubBlock(imemBlock, "imem0");
138  // todo: use core id instead of counter value.
139  std::string accessTrace = std::string("core") +
141  "_imem_access_trace.dump";
142  imemBlock->setAccessTraceFile(accessTrace);
143 
144  if (isRISCV) {
145  // With RISC-V the two lower bits are unused
146  const int realAddrWidth = MathTools::requiredBits(
148  netlist().connect(
149  imemBlock->memoryPort(), coreImemPort,
150  {{SigT::READ_DATA, SigT::FETCHBLOCK},
151  {SigT::READ_WRITE_REQUEST, SigT::READ_REQUEST}});
152  netlist().connect(
153  imemBlock->memoryPort().portBySignal(SigT::ADDRESS),
154  coreImemPort.portBySignal(SigT::ADDRESS), 0, unusedBits,
155  realAddrWidth - unusedBits);
156  } else {
157  netlist().connect(
158  imemBlock->memoryPort(), coreImemPort,
159  {{SigT::ADDRESS, SigT::ADDRESS},
160  {SigT::READ_DATA, SigT::FETCHBLOCK},
161  {SigT::READ_WRITE_REQUEST, SigT::READ_REQUEST}});
162  }
163 
164  imemBlock->memoryPort()
165  .portBySignal(SigT::WRITE_BITMASK)
166  .setToStatic(StaticSignal::VCC);
167  imemBlock->memoryPort()
168  .portBySignal(SigT::WRITEMODE)
169  .setToStatic(StaticSignal::VCC);
170  imemBlock->memoryPort()
171  .portBySignal(SigT::WRITE_DATA)
172  .setToStatic(StaticSignal::GND);
173  coreImemPort.portBySignal(SigT::READ_REQUEST_READY)
174  .setToStatic(StaticSignal::GND); // Active low
175 }
176 
177 void
178 ProcessorWrapperBlock::addDataMemory(const MemoryBusInterface& coreDmemPort) {
179  using SigT = SignalType;
180 
181  const NetlistPort& addrPort = coreDmemPort.portBySignal(SigT::ADDRESS);
182  const NetlistPort& dataPort = coreDmemPort.portBySignal(SigT::WRITE_DATA);
183 
185  addrPort.widthFormula(), dataPort.widthFormula(),
186  TCEString("tb/dmem_") + coreDmemPort.addressSpace() + "_init.img",
187  /* isForSmulation = */ true);
188  addSubBlock(dmemBlock, TCEString("dmem_") + coreDmemPort.addressSpace());
189 
190  if (!netlist().connect(dmemBlock->memoryPort(), coreDmemPort)) {
193  "Could not connect two port groups together.");
194  }
195 }
196 
197 void
198 ProcessorWrapperBlock::addDataMemory2(
199  const MemoryBusInterface& coreDmemPort) {
200  using SigT = SignalType;
201 
202  const NetlistPort& addrPort = coreDmemPort.portBySignal(SigT::AADDR);
203  const NetlistPort& dataPort = coreDmemPort.portBySignal(SigT::RDATA);
204 
205  SinglePortByteMaskSSRAMBlock* dmemBlock =
207  addrPort.widthFormula(), dataPort.widthFormula(),
208  TCEString("tb/dmem_") + coreDmemPort.addressSpace() + "_init.img",
209  /* isForSmulation = */ true);
210  addSubBlock(dmemBlock, TCEString("dmem_") + coreDmemPort.addressSpace());
211 
212  if (!netlist().connect(dmemBlock->memoryPort(), coreDmemPort)) {
215  "Could not connect two port groups together.");
216  }
217 }
218 
219 void
220 ProcessorWrapperBlock::connectLockStatus(
221  const NetlistPort& topLockStatusPort) {
222  assert(
223  coreBlock_->port("locked") != nullptr &&
224  "Could not found lock status port.");
225  if (!netlist().connect(*coreBlock_->port("locked"), topLockStatusPort)) {
228  "Could not connect \"locked\" signal to the toplevel");
229  }
230 }
231 
232 /**
233  * Handles unconnected ports of the top-level TTA processor by connecting
234  * them to the toplevel
235  */
236 void
237 ProcessorWrapperBlock::handleUnconnectedPorts() {
238  for (size_t i = 0; i < coreBlock_->portCount(); i++) {
239  const NetlistPort& port =
240  ((const BaseNetlistBlock*)coreBlock_)->port(i);
241  if (!netlist().isPortConnected(port) && !port.hasStaticValue()) {
242  NetlistPort* topPort = port.clone();
243  addPort(topPort);
244  netlist().connect(*topPort, port);
245  }
246  }
247 }
248 
249 } /* namespace ProGe */
ProGe::BaseNetlistBlock::addPort
NetlistPort * addPort(NetlistPort *port)
Definition: BaseNetlistBlock.cc:467
ProGe::BaseNetlistBlock
Definition: BaseNetlistBlock.hh:59
Netlist.hh
Path
Definition: FileSystem.hh:197
ProGe::BaseNetlistBlock::addSubBlock
void addSubBlock(BaseNetlistBlock *subBlock, const std::string &instanceName="")
Definition: BaseNetlistBlock.cc:405
ProGe::GlobalPackage::fetchBlockDataWidth
const std::string fetchBlockDataWidth() const
Definition: GlobalPackage.cc:65
ProGe::ProcessorWrapperBlock::context_
const ProGeContext & context_
Definition: ProcessorWrapperBlock.hh:74
FileSystem.hh
NetlistFactories.hh
ProGe::SignalGroupType::BYTEMASKED_SRAM_PORT
@ BYTEMASKED_SRAM_PORT
Signal group type for one port SRAM having read and write capability and bitmask for writing with sep...
ProGe::ProcessorWrapperBlock::connectLockStatus
void connectLockStatus(const NetlistPort &topPCInitPort)
Definition: ProcessorWrapperBlock.cc:220
ProGe::BaseNetlistBlock::writeSelf
virtual void writeSelf(const Path &targetBaseDir, HDL targetLang=VHDL) const
Definition: BaseNetlistBlock.cc:625
TTAMachine::Machine::isRISCVMachine
bool isRISCVMachine() const
Definition: Machine.cc:1063
ProGe::ProGeContext::adf
const TTAMachine::Machine & adf() const
Definition: ProGeContext.cc:57
ProGe::PortFactory::resetPort
static NetlistPort * resetPort(Direction direction=IN)
Definition: NetlistFactories.cc:209
ProGe::SinglePortSSRAMBlock
Definition: SinglePortSSRAMBlock.hh:46
ProGe::ProcessorWrapperBlock::addInstructionMemory
void addInstructionMemory(const NetlistPortGroup &)
Definition: ProcessorWrapperBlock.cc:119
ProcessorWrapperBlock.hh
ProGe::NetlistPort::widthFormula
std::string widthFormula() const
Definition: NetlistPort.cc:316
ProGe::BaseNetlistBlock::connectClocks
void connectClocks()
Definition: BaseNetlistBlock.cc:722
MemoryBusInterface.hh
ProGe::BaseNetlistBlock::package
virtual const std::string & package(size_t idx) const
Definition: BaseNetlistBlock.cc:699
TTAMachine::FunctionUnit::addressSpace
virtual AddressSpace * addressSpace() const
Definition: FunctionUnit.cc:580
ProGe::ProcessorWrapperBlock::coreBlock_
BaseNetlistBlock * coreBlock_
The target TTA processor.
Definition: ProcessorWrapperBlock.hh:76
ProGe::BaseNetlistBlock::netlist
virtual const Netlist & netlist() const
Definition: BaseNetlistBlock.cc:348
ProGe::ProcessorWrapperBlock::addDataMemory2
void addDataMemory2(const MemoryBusInterface &)
Definition: ProcessorWrapperBlock.cc:198
SinglePortSSRAMBlock.hh
Conversion::toString
static std::string toString(const T &source)
ProGe::ProcessorWrapperBlock::~ProcessorWrapperBlock
virtual ~ProcessorWrapperBlock()
Definition: ProcessorWrapperBlock.cc:109
ProGe::Netlist::connect
bool connect(const NetlistPort &port1, const NetlistPort &port2, int port1FirstBit, int port2FirstBit, int width=1)
Definition: Netlist.cc:83
ProGe::SignalGroupType::INSTRUCTION_LINE
@ INSTRUCTION_LINE
Signal group type for serial TTA instruction bus.
ProGe::BaseNetlistBlock::portGroupCount
virtual size_t portGroupCount() const
Definition: BaseNetlistBlock.cc:327
NetlistPortGroup.hh
assert
#define assert(condition)
Definition: Application.hh:86
ProGe::SinglePortSSRAMBlock::memoryPort
const NetlistPortGroup & memoryPort() const
Definition: SinglePortSSRAMBlock.cc:97
ProGe::NetlistPortGroup
Definition: NetlistPortGroup.hh:53
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
NetlistTools.hh
THROW_EXCEPTION
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition: Exception.hh:39
NetlistPort.hh
ProGe::MemoryBusInterface
Definition: MemoryBusInterface.hh:46
ProGe::BaseNetlistBlock::portCount
virtual size_t portCount() const
Definition: BaseNetlistBlock.cc:248
ProGe::BaseNetlistBlock::packageCount
virtual size_t packageCount() const
Definition: BaseNetlistBlock.cc:694
ProGe::BaseNetlistBlock::addPackage
void addPackage(const std::string &packageName)
Definition: BaseNetlistBlock.cc:687
ProGe::SinglePortByteMaskSSRAMBlock::memoryPort
const NetlistPortGroup & memoryPort() const
Definition: SinglePortByteMaskSSRAMBlock.cc:103
ProGe::ProGeContext::globalPackage
const GlobalPackage & globalPackage() const
Definition: ProGeContext.cc:87
ProGe::ProcessorWrapperBlock::ProcessorWrapperBlock
ProcessorWrapperBlock()=delete
ProGe::ProcessorWrapperBlock::addDataMemory
void addDataMemory(const MemoryBusInterface &)
Definition: ProcessorWrapperBlock.cc:178
ProGe::ProcessorWrapperBlock::imemCount_
unsigned imemCount_
Definition: ProcessorWrapperBlock.hh:77
MathTools::requiredBits
static int requiredBits(unsigned long int number)
ProGe::BaseNetlistBlock::portGroup
virtual const NetlistPortGroup & portGroup(size_t index) const
Definition: BaseNetlistBlock.cc:332
ProGe::SignalGroupType::BITMASKED_SRAM_PORT
@ BITMASKED_SRAM_PORT
Signal group type for one port SRAM having read and write capability and bitmask for writing.
ProGe::ProGeContext::coreEntityName
const std::string & coreEntityName() const
Definition: ProGeContext.cc:77
InverterBlock.hh
ProGe::NetlistPort::clone
virtual NetlistPort * clone(bool asMirrored=false) const
Definition: NetlistPort.cc:258
SinglePortByteMaskSSRAMBlock.hh
ProGe::NetlistPortGroup::assignedSignalGroup
SignalGroup assignedSignalGroup() const
Definition: NetlistPortGroup.cc:160
ProGe::PortFactory::clockPort
static NetlistPort * clockPort(Direction direction=IN)
Definition: NetlistFactories.cc:200
ProGe::SignalType
SignalType
Definition: SignalTypes.hh:42
ProGe::BaseNetlistBlock::connectResets
void connectResets()
Definition: BaseNetlistBlock.cc:743
ProGe::GlobalPackage::fetchBlockAddressWidth
const std::string fetchBlockAddressWidth() const
Definition: GlobalPackage.cc:56
ProGe::MemoryBusInterface::addressSpace
TCEString addressSpace() const
Definition: MemoryBusInterface.cc:67
ProGe::ProcessorWrapperBlock::write
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
Definition: ProcessorWrapperBlock.cc:112
GlobalPackage.hh
ProGe
Definition: FUGen.hh:54
ProGe::ProcessorWrapperBlock::handleUnconnectedPorts
void handleUnconnectedPorts()
Definition: ProcessorWrapperBlock.cc:237
ProGe::NetlistPort::hasStaticValue
bool hasStaticValue() const
Definition: NetlistPort.cc:423
TCEString
Definition: TCEString.hh:53
ControlUnit.hh
ProGe::NetlistPortGroup::portBySignal
const NetlistPort & portBySignal(SignalType type) const
Definition: NetlistPortGroup.cc:111
ProGe::HDL
HDL
HDLs supported by ProGe.
Definition: ProGeTypes.hh:40
ProGe::NetlistPort
Definition: NetlistPort.hh:70
IllegalConnectivity
Definition: Exception.hh:473
ProGe::GlobalPackage::name
const std::string name() const
Definition: GlobalPackage.cc:47
MathTools.hh
ProGe::ProGeContext
Definition: ProGeContext.hh:60
ProGe::SignalGroup::type
SignalGroupType type() const
Definition: SignalGroup.cc:43
ProGe::SignalGroupType
SignalGroupType
Definition: SignalGroupTypes.hh:43
TTAMachine::AddressSpace::end
virtual ULongWord end() const
Definition: AddressSpace.cc:177
ProGe::OutPort
Convenience class for output ports.
Definition: NetlistPort.hh:158
ProGe::SinglePortByteMaskSSRAMBlock
Definition: SinglePortByteMaskSSRAMBlock.hh:46
ProGe::BaseNetlistBlock::write
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
Definition: BaseNetlistBlock.cc:614
ProGe::SinglePortSSRAMBlock::setAccessTraceFile
void setAccessTraceFile(const std::string filename)
Definition: SinglePortSSRAMBlock.cc:91