OpenASIP 2.2
Loading...
Searching...
No Matches
QuartusProjectGenerator.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 QuartusProjectGenerator.hh
26 *
27 * Declaration of QuartusProjectGenerator class.
28 *
29 * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <vector>
34#include <iostream>
35#include <fstream>
36#include "Exception.hh"
37#include "FileSystem.hh"
39#include "PlatformIntegrator.hh"
40#include "StringTools.hh"
42using std::ofstream;
43using std::endl;
45
47 TCEString coreEntity,
48 const PlatformIntegrator* integrator):
49 ProjectFileGenerator(coreEntity, integrator) {
50}
51
54
55void
64
65
66void
68
69 TCEString qpfFileName = toplevelEntity() + ".qpf";
70 ofstream qpfFile;
71 qpfFile.open(qpfFileName.c_str());
72 if (!qpfFile) {
73 TCEString msg = "Couldn't open file " + qpfFileName + " for writing";
74 IOException exc(__FILE__, __LINE__, "QuartusProjectGenerator", msg);
75 throw exc;
76 }
77 qpfFile
78 << "# Generated by QuartusProject Generator" << endl << endl
79 << "QUARTUS_VERSION = \"8.0\"" << endl << endl
80 << "PROJECT_REVISION = \"" << toplevelEntity() << "\"" << endl;
81 qpfFile.close();
82}
83
84
85void
87
88 TCEString qsfFileName = toplevelEntity() + ".qsf";
89 ofstream qsfFile;
90 qsfFile.open(qsfFileName.c_str());
91 if (!qsfFile) {
92 TCEString msg = "Couldn't open file " + qsfFileName + " for writing";
93 IOException exc(__FILE__, __LINE__, "QuartusProjectGenerator", msg);
94 throw exc;
95 }
96
97 TCEString deviceFamily = integrator()->deviceFamily();
98 TCEString deviceName = integrator()->deviceName();
99 int fmax = integrator()->targetClockFrequency();
100 qsfFile
101 << "# Generated by QuartusProjectGenerator" << endl << endl
102 << "set_global_assignment -name FAMILY \"" << deviceFamily << "\""
103 << endl
104 << "set_global_assignment -name DEVICE " << deviceName << endl
105 << "set_global_assignment -name TOP_LEVEL_ENTITY " << toplevelEntity()
106 << endl
107 << "set_global_assignment -name ORIGINAL_QUARTUS_VERSION 8.0" << endl
108 << "set_global_assignment -name LAST_QUARTUS_VERSION 8.0" << endl
109 << "set_global_assignment -name USE_GENERATED_PHYSICAL_CONSTRAINTS "
110 << "OFF -section_id eda_palace" << endl
111 << "set_global_assignment -name USE_CONFIGURATION_DEVICE ON" << endl
112 << "set_global_assignment -name RESERVE_ALL_UNUSED_PINS \"AS "
113 << "INPUT TRI-STATED\"" << endl
114 << "set_global_assignment -name FMAX_REQUIREMENT \"" << fmax
115 << " MHz\"" << endl;
116
117 for (unsigned int i = 0; i < hdlFileList().size(); i++) {
118 qsfFile << "set_global_assignment -name VHDL_FILE \""
119 << hdlFileList().at(i) << "\"" << endl;
120 }
121
122 for (unsigned int i = 0; i < memInitFileList().size(); i++) {
123 if (StringTools::endsWith(memInitFileList().at(i), ".mif")) {
124 qsfFile << "set_global_assignment -name MIF_FILE \""
125 << memInitFileList().at(i) << "\"" << endl;
126 } else if (StringTools::endsWith(memInitFileList().at(i), ".hex")) {
127 qsfFile << "set_global_assignment -name HEX_FILE \""
128 << memInitFileList().at(i) << "\"" << endl;
129 }
130 }
131
132 for (int i = 0; i < signalMappingCount(); i++) {
133 const SignalMapping* mapping = signalMapping(i);
134 qsfFile << "set_location_assignment " << mapping->first
135 << " -to " << mapping->second << endl;
136 }
137 qsfFile.close();
138}
139
140
141void
143
144 TCEString exportCommand = "";
145 TCEString alteraLibPath =
147 "ALTERA_LIBRARY_PATH");
148
149 if (alteraLibPath != "") {
150 exportCommand << "export LD_LIBRARY_PATH=" << alteraLibPath << "\n";
151 }
152
153
154 TCEString synthesisScript = "quartus_synthesize.sh";
155 ofstream synthesis;
156 synthesis.open(synthesisScript.c_str());
157 if (!synthesis) {
158 TCEString msg =
159 "Couldn't open file " + synthesisScript + " for writing";
160 IOException exc(__FILE__, __LINE__, "QuartusProjectGenerator", msg);
161 throw exc;
162 }
163 synthesis
164 << "#!/bin/bash" << endl
165 << "# Generated by QuartusProjectGenerator of TCE" << endl << endl
166 << exportCommand
167 << "quartus_sh --flow compile " << toplevelEntity() << endl;
168 synthesis.close();
169 FileSystem::setFileExecutable(synthesisScript);
170
171 TCEString programmingScript = "quartus_program_fpga.sh";
172 ofstream programming;
173 programming.open(programmingScript.c_str());
174 if (!programming) {
175 TCEString msg = "Couldn't open file " + programmingScript
176 + " for writing";
177 IOException exc(__FILE__, __LINE__, "QuartusProjectGenerator", msg);
178 throw exc;
179 }
180 programming
181 << "#!/bin/bash" << endl
182 << "# Generated by QuartusProjectGenerator of TCE" << endl << endl
183 << exportCommand
184 << "quartus_pgm -c USB-Blaster -m JTAG -o p\\;"
185 << toplevelEntity() << ".sof" << endl << endl;
186 programming.close();
187 FileSystem::setFileExecutable(programmingScript);
188}
static std::string environmentVariable(const std::string &variable)
static bool setFileExecutable(const std::string fileName)
TCEString deviceName() const
virtual int targetClockFrequency() const
virtual TCEString deviceFamily() const =0
const PlatformIntegrator * integrator() const
const std::vector< TCEString > & hdlFileList() const
const std::vector< TCEString > & memInitFileList() const
const PlatInt::SignalMapping * signalMapping(int index) const
TCEString toplevelEntity() const
QuartusProjectGenerator(TCEString toplevelEntity, const PlatformIntegrator *integrator)
static bool endsWith(const std::string &source, const std::string &searchString)
std::pair< TCEString, TCEString > SignalMapping