OpenASIP 2.2
Loading...
Searching...
No Matches
SOPCBuilderFileGenerator.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2010 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 SOPCBuilderFileGenerator.cc
26 *
27 * Implementation of SOPCBuilderFileGenerator class.
28 *
29 * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <fstream>
34#include <cassert>
36#include "PlatformIntegrator.hh"
37#include "NetlistBlock.hh"
38#include "NetlistPort.hh"
39#include "Exception.hh"
40#include "FileSystem.hh"
42#include "MapTools.hh"
43using std::ofstream;
44using std::vector;
45using std::map;
46using std::endl;
47
48
51 "_hw.tcl";
53 "set_module_property";
55 "add_file";
62 "std.standard.all ieee.std_logic_1164.all ieee.std_logic_arith.all "
63 "work.globals.all work.util.all work.imem_mau.all";
65 "dev_family_g";
66
67
68
69
71 TCEString toplevelEntity,
72 const PlatformIntegrator* integrator):
73 ProjectFileGenerator(toplevelEntity, integrator),
74 clock_(new SOPCInterface(
75 SOPCInterface::SOPC_CLOCK_INT_NAME,
76 SOPCInterface::SOPC_CLOCK_INT_DECLR)),
77 export_(new SOPCInterface(
78 SOPCInterface::SOPC_EXPORT_INT_NAME,
79 SOPCInterface::SOPC_EXPORT_INT_DECLR)) {
80
81 clock_->setProperty("ptfSchematicName", "\"\"");
84
87}
88
89
91
92 if (clock_ != NULL) {
93 delete clock_;
94 }
95 if (export_ != NULL) {
96 delete export_;
97 }
99}
100
101
102void
104
105 int masterInterfaces = countAvalonMMMasters();
106 if (masterInterfaces == 0) {
107 TCEString msg = "Couldn't find any Avalon MM Master interfaces.";
108 InvalidData exc(__FILE__, __LINE__, "SOPCBuilderFileGenerator", msg);
109 throw exc;
110 }
111
113
115 ofstream output;
116 output.open(outputFileName.c_str());
117 if (!output) {
118 TCEString msg =
119 "Couldn't open file " + outputFileName + " for writing";
120 IOException exc(__FILE__, __LINE__, "SOPCBuilderFileGenerator", msg);
121 throw exc;
122 }
123
124 output << "# Generated by SOPCBuilderGenerator" << endl << endl;
125 writeModuleProperties(output);
126
127 writeGenerics(output);
128
129 writeFileList(output);
130
131 writeInterfaces(output);
132
133 output.close();
134}
135
136
137/**
138 * Counts how many Avalon MM Master interfaces toplevel netlis block has.
139 *
140 * Avalon MM interface is recognised by the address port. Address signal in
141 * first of the 2 mandatory signals in Avalon MM interface. Direction of the
142 * address port determines whether it belongs to a master or slave interface.
143 *
144 * @return Number of found Avalon MM Master interfaces
145 */
146int
148
150 TCEString addressPortName =
152 int found = 0;
153 for (size_t i = 0; i < top.portCount(); i++) {
154 TCEString portName = top.port(i).name();
155 if (portName.find(addressPortName) != TCEString::npos) {
156 if (top.port(i).direction() == ProGe::OUT) {
157 found++;
158 }
159 }
160 }
161 return found;
162}
163
164
165void
167
169 stream
170 << "# Module properties" << endl
171 << property << " NAME " << toplevelEntity() << endl
172 << property << " VERSION 1.0" << endl
173 << property << " GROUP \"" << SOPC_DEFAULT_GROUP << "\"" << endl
174 << property << " DISPLAY_NAME " << toplevelEntity() << endl
175 << property << " LIBRARIES {" << SOPC_DEFAULT_VHDL_LIBS;
176
177 if (integrator()->toplevelBlock().netlist().parameterCount() > 0) {
178 stream << " work." << toplevelEntity() << "_params.all";
179 }
180 stream << "}" << endl;
181
182 TCEString toplevelFile =
184 stream
185 << property << " TOP_LEVEL_HDL_FILE " << toplevelFile << endl
186 << property << " TOP_LEVEL_HDL_MODULE " << toplevelEntity() << endl
187 << property << " INSTANTIATE_IN_SYSTEM_MODULE true" << endl
188 << property << " EDITABLE false" << endl
189 << property << " SIMULATION_MODEL_IN_VERILOG false" << endl
190 << property << " SIMULATION_MODEL_IN_VHDL false" << endl
191 << property << " SIMULATION_MODEL_HAS_TULIPS false" << endl
192 << property << " SIMULATION_MODEL_IS_OBFUSCATED false" << endl
193 << endl;
194}
195
196
197void
199
201 if (top.parameterCount() == 0) {
202 return;
203 }
204 stream << "# toplevel parameters" << endl;
205 for (size_t i = 0; i < top.parameterCount(); i++) {
206 TCEString line;
207 line << "add_parameter " << top.parameter(i).name() << " ";
208 if (top.parameter(i).type().lower() == "string") {
209 line << "STRING ";
210 if (!top.parameter(i).value().startsWith("\"")) line << "\"";
211 line << top.parameter(i).value();
212 if (!top.parameter(i).value().endsWith("\"")) line << "\"";
213 } else if (top.parameter(i).type().lower() == "integer") {
214 line << "INTEGER " << top.parameter(i).value();
215 } else {
216 // unknown type, ignore
217 continue;
218 }
219 stream << line << endl;
220 if (top.parameter(i).name().lower() == PI_DEVICE_FAMILY_GENERIC) {
221 stream << "set_parameter_property " << PI_DEVICE_FAMILY_GENERIC
222 << " DISPLAY_NAME \"Device family (change if necessary)\""
223 << endl;
224 }
225 }
226 stream << endl;
227}
228
229void
231
232 stream << "# module hdl files" << endl;
233 for (unsigned int i = 0; i < hdlFileList().size(); i++) {
234 stream << SOPC_ADD_FILE << " " << hdlFileList().at(i)
235 << " {SYNTHESIS SIMULATION}" << endl;
236 }
237 for (unsigned int i = 0; i < memInitFileList().size(); i++) {
238 stream << SOPC_ADD_FILE << " " << memInitFileList().at(i)
239 << " {SYNTHESIS SIMULATION}" << endl;
240 }
241 stream << endl;
242}
243
244
245void
247
249 for (size_t i = 0; i < top.portCount(); i++) {
250 TCEString portName = top.port(i).name();
251
252 bool needToExport = true;
253 if (portName == TTA_CLOCK_NAME || portName == TTA_RESET_NAME) {
254 continue;
255 } else if (portName.find(HDB_AVALON_PREFIX) != TCEString::npos) {
256 needToExport = !handleAvalonSignal(top.port(i));
257 }
258
259 if (needToExport) {
260 exportSignal(top.port(i));
261 }
262 }
263}
264
265
266bool
268 const ProGe::NetlistPort& port) {
269
271
272 if (fuName.empty()) {
273 TCEString msg = "Failed to extract FU name from: " + port.name();
274 InvalidData exc(__FILE__, __LINE__, "SOPCBuilderFileGenerator", msg);
275 throw exc;
276 }
277
278 if (!MapTools::containsKey(masters_ ,fuName)) {
279 TCEString interfaceName =
282 masters_[fuName] = new AvalonMMMasterInterface(
283 interfaceName, declr, HDB_AVALON_PREFIX, *clock_);
284 }
285
286 AvalonMMMasterInterface* master = getMaster(fuName);
287 bool isAvalonPort = false;
288 if (!master->isValidPort(port)) {
289 isAvalonPort = false;
290 } else {
291 master->addPort(port);
292 isAvalonPort = true;
293 }
294 return isAvalonPort;
295}
296
297
298void
300
301 int width = 32;
302 if (port.realWidthAvailable()) {
303 width = port.realWidth();
304 }
306 export_->setPort(port.name(), intPortName, port.direction(), width);
307}
308
309
310void
311SOPCBuilderFileGenerator::writeInterfaces(std::ostream& stream) const {
312
313 clock_->writeInterface(stream);
314
315 std::map<TCEString, AvalonMMMasterInterface*>::const_iterator iter =
316 masters_.begin();
317 while (iter != masters_.end()) {
318 AvalonMMMasterInterface* master = iter->second;
319 if (master->hasPorts()) {
320 master->writeInterface(stream);
321 }
322 iter++;
323 }
324 if (export_->hasPorts()) {
325 export_->writeInterface(stream);
326 }
327}
328
329
330
331
332
335
336 std::map<TCEString, AvalonMMMasterInterface*>::iterator iter =
337 masters_.find(fuName);
338
339 assert(iter != masters_.end());
340 return iter->second;
341}
#define assert(condition)
static std::string outputFileName(const std::string &adfFile)
Definition CreateBEM.cc:77
virtual void writeInterface(std::ostream &stream) const
static const TCEString AVALON_MM_ADDRESS
void addPort(const ProGe::NetlistPort &port)
bool isValidPort(const ProGe::NetlistPort &port) const
static void deleteAllValues(MapType &aMap)
static bool containsKey(const MapType &aMap, const KeyType &aKey)
const ProGe::NetlistBlock & toplevelBlock() const
TCEString outputFilePath(TCEString fileName, bool absolute=false) const
virtual size_t parameterCount() const
virtual const Parameter & parameter(const std::string &name) const
virtual NetlistPort * port(const std::string &portName, bool partialMatch=true)
virtual size_t portCount() const
bool realWidthAvailable() const
Direction direction() const
std::string name() const
int realWidth() const
const TCEString & value() const
Definition Parameter.cc:143
const TCEString & type() const
Definition Parameter.cc:138
const TCEString & name() const
Definition Parameter.cc:133
const PlatformIntegrator * integrator() const
const std::vector< TCEString > & hdlFileList() const
TCEString extractFUName(const TCEString &port, const TCEString &delimiter) const
const std::vector< TCEString > & memInitFileList() const
TCEString toplevelEntity() const
bool handleAvalonSignal(const ProGe::NetlistPort &port)
AvalonMMMasterInterface * getMaster(const TCEString &fuName)
SOPCBuilderFileGenerator(TCEString toplevelEntity, const PlatformIntegrator *integrator)
static const TCEString SOPC_ADD_FILE
std::map< TCEString, AvalonMMMasterInterface * > masters_
static const TCEString TTA_RESET_NAME
void writeFileList(std::ostream &stream)
static const TCEString SOPC_COMPONENT_FILE_TYPE
static const TCEString SOPC_CLOCK_NAME
static const TCEString HDB_AVALON_PREFIX
static const TCEString SOPC_DEFAULT_VHDL_LIBS
void writeGenerics(std::ostream &stream)
void writeInterfaces(std::ostream &stream) const
static const TCEString SOPC_DEFAULT_GROUP
static const TCEString PI_DEVICE_FAMILY_GENERIC
void writeModuleProperties(std::ostream &stream)
static const TCEString TTA_CLOCK_NAME
static const TCEString SOPC_SET_MODULE_PROPERTY
static const TCEString SOPC_RESET_NAME
void exportSignal(const ProGe::NetlistPort &port)
TCEString name() const
static const TCEString SOPC_MASTER_INT_NAME
void setPort(const TCEString &hdlName, const TCEString &interfaceName, ProGe::Direction direction, int width)
static const TCEString SOPC_MASTER_INT_DECLR
static const TCEString SOPC_ASSOCIATED_CLOCK
virtual void writeInterface(std::ostream &stream) const
void setProperty(const TCEString &propertyName, const TCEString &propertyValue)
bool hasPorts() const
static const TCEString SOPC_EXPORT_NAME
TCEString lower() const
Definition TCEString.cc:78
bool startsWith(const std::string &str) const
bool endsWith(const std::string &str) const
@ OUT
Output port.
Definition ProGeTypes.hh:54
@ IN
Input port.
Definition ProGeTypes.hh:53