OpenASIP  2.0
VhdlRomGenerator.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 VhdlRomGenerator.hh
26  *
27  * Implementation of VhdlRomGenerator class.
28  *
29  * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <iostream>
34 #include <fstream>
35 #include <sstream>
36 #include <vector>
37 #include "Exception.hh"
38 #include "StringTools.hh"
39 #include "FileSystem.hh"
40 #include "MemoryGenerator.hh"
41 #include "VhdlRomGenerator.hh"
42 #include "PlatformIntegrator.hh"
43 #include "NetlistBlock.hh"
44 #include "NetlistPort.hh"
45 #include "HDLPort.hh"
46 using std::endl;
48 using ProGe::NetlistPort;
49 
51  int memMauWidth,
52  int widthInMaus,
53  int addrWidth,
54  TCEString initFile,
55  const PlatformIntegrator* integrator,
56  std::ostream& warningStream,
57  std::ostream& errorStream):
58  MemoryGenerator(memMauWidth, widthInMaus, addrWidth, initFile,
59  integrator, warningStream, errorStream) {
60 
61  addPort("clk", new HDLPort("clock", "1", ProGe::BIT, ProGe::IN, false, 1));
62  addPort("imem_addr", new HDLPort("addr", "addrw", ProGe::BIT_VECTOR,
63  ProGe::IN, false, memoryAddrWidth()));
64 
65  addPort("imem_en_x", new HDLPort("en_x", "1", ProGe::BIT,
66  ProGe::IN, false, 1));
67 
68  addPort("imem_data", new HDLPort("dataout", "instrw", ProGe::BIT_VECTOR,
69  ProGe::OUT, false, memoryTotalWidth()));
70 
71  HDLPort* busyToGnd = new HDLPort("wait", "1", ProGe::BIT, ProGe::OUT,
72  false, 1);
74  addPort("busy", busyToGnd);
75 
76  ProGe::Parameter addr("addrw", "integer", "IMEMADDRWIDTH");
77  ProGe::Parameter data("instrw", "integer", "IMEMMAUWIDTH*IMEMWIDTHINMAUS");
78 
79  addParameter(addr);
80  addParameter(data);
81 }
82 
84 }
85 
86 
87 bool
89  return true;
90 }
91 
92 
93 std::vector<TCEString>
95 
96  TCEString outputFile =
98  << ".vhd";
99 
100  std::ofstream file;
101  file.open(outputFile.c_str());
102  if (!file) {
103  TCEString msg = "Couldn't open file " + outputFile + " for writing";
104  IOException exc(__FILE__, __LINE__, "VhdlRomGenerator", msg);
105  throw exc;
106  }
107 
108  TCEString indentL1 = StringTools::indent(1);
109  TCEString indentL2 = StringTools::indent(2);
110  std::ostringstream stream;
111  stream
112  << "library ieee;" << endl
113  << "use ieee.std_logic_1164.all;" << endl
114  << "use ieee.std_logic_arith.all;" << endl
115  << "use work." << imagePackageName() << ".all;" << endl << endl
116  << "entity " << moduleName() << " is" << endl << endl
117  << indentL1 << "generic (" << endl
118  << indentL2 << "addrw : integer := 10;" << endl
119  << indentL2 << "instrw : integer := 100);" << endl
120  << indentL1 << "port (" << endl
121  << indentL2 << "clock : in std_logic;" << endl
122  << indentL2 << "en_x : in std_logic; -- not used" << endl
123  << indentL2 << "addr : in std_logic_vector(addrw-1 downto 0);"
124  << endl << indentL2
125  << "dataout : out std_logic_vector(instrw-1 downto 0));" << endl
126  << "end " << moduleName() << ";" << endl << endl;
127 
128  stream
129  << "architecture rtl of " << moduleName() << " is" << endl << endl
130  << indentL1
131  << "subtype imem_index is integer range 0 to imem_array'length-1;"
132  << endl
133  << indentL1 << "constant imem : std_logic_imem_matrix"
134  << "(0 to imem_array'length-1) := imem_array;" << endl
135  << indentL1 << "signal en_x_dummy : std_logic;" << endl << endl
136  << "begin --rtl" << endl << endl
137  << indentL1 << "process" << endl
138  << indentL2 << "variable imem_line : imem_index;" << endl
139  << indentL1 << "begin -- process" << endl
140  << indentL2 << "wait until clock'event and clock='1';" << endl
141  << indentL2 << "imem_line := conv_integer(unsigned(addr));" << endl
142  << indentL2 << "dataout <= imem(imem_line);" << endl
143  << indentL1 << "end process;" << endl << endl
144  << indentL1 << "en_x_dummy <= en_x; -- dummy connection" << endl
145  << endl << "end rtl;" << endl;
146 
147  file << stream.str();
148  file.close();
149 
150  std::vector<TCEString> componentFiles;
151  componentFiles.push_back(outputFile);
152  componentFiles.push_back(initializationFile());
153  return componentFiles;
154 }
155 
156 
157 TCEString
159 
160  return ttaCoreName() + "_rom_array_comp";
161 }
162 
163 
164 TCEString
165 VhdlRomGenerator::instanceName(int coreId, int memIndex) const {
166 
167  TCEString iname("imem_array_instance_");
168  return iname << memoryIndexString(coreId, memIndex);
169 }
170 
171 TCEString
173 
174  return ttaCoreName() + "_imem_image";
175 }
ProGe::StaticSignal::GND
@ GND
All port signals set to low.
Definition: NetlistPort.hh:50
FileSystem.hh
ProGe::NetlistBlock
Definition: NetlistBlock.hh:61
MemoryGenerator::initializationFile
TCEString initializationFile() const
Definition: MemoryGenerator.cc:219
MemoryGenerator::addPort
void addPort(const TCEString &name, HDLPort *port)
Definition: MemoryGenerator.cc:294
Exception.hh
HDLPort
Definition: PlatformIntegrator/HDLPort.hh:48
ProGe::BIT_VECTOR
@ BIT_VECTOR
Several bits.
Definition: ProGeTypes.hh:48
MemoryGenerator.hh
MemoryGenerator::ttaCoreName
TCEString ttaCoreName() const
Definition: MemoryGenerator.cc:319
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
VhdlRomGenerator::~VhdlRomGenerator
virtual ~VhdlRomGenerator()
Definition: VhdlRomGenerator.cc:83
MemoryGenerator::memoryIndexString
TCEString memoryIndexString(int coreId, int memIndex) const
Definition: MemoryGenerator.cc:383
StringTools.hh
VhdlRomGenerator::generateComponentFile
virtual std::vector< TCEString > generateComponentFile(TCEString outputPath)
Definition: VhdlRomGenerator.cc:94
ProGe::Parameter
Definition: Parameter.hh:62
NetlistPort.hh
NetlistBlock.hh
VhdlRomGenerator::moduleName
virtual TCEString moduleName() const
Definition: VhdlRomGenerator.cc:158
HDLPort.hh
ProGe::BIT
@ BIT
One bit.
Definition: ProGeTypes.hh:47
VhdlRomGenerator.hh
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
ProGe::OUT
@ OUT
Output port.
Definition: ProGeTypes.hh:54
VhdlRomGenerator::instanceName
virtual TCEString instanceName(int coreId, int memIndex) const
Definition: VhdlRomGenerator.cc:165
VhdlRomGenerator::imagePackageName
TCEString imagePackageName() const
Definition: VhdlRomGenerator.cc:172
HDLPort::setToStatic
void setToStatic(ProGe::StaticSignal value)
Definition: HDLPort.cc:145
TCEString
Definition: TCEString.hh:53
PlatformIntegrator.hh
MemoryGenerator::addParameter
void addParameter(const ProGe::Parameter &add)
Definition: MemoryGenerator.cc:313
VhdlRomGenerator::generatesComponentHdlFile
virtual bool generatesComponentHdlFile() const
Definition: VhdlRomGenerator.cc:88
ProGe::NetlistPort
Definition: NetlistPort.hh:70
PlatformIntegrator
Definition: PlatformIntegrator.hh:65
IOException
Definition: Exception.hh:130
MemoryGenerator::memoryTotalWidth
int memoryTotalWidth() const
Definition: MemoryGenerator.cc:193
MemoryGenerator::memoryAddrWidth
int memoryAddrWidth() const
Definition: MemoryGenerator.cc:212
VhdlRomGenerator::VhdlRomGenerator
VhdlRomGenerator(int memMauWidth, int widthInMaus, int addrWidth, TCEString initFile, const PlatformIntegrator *integrator, std::ostream &warningStream, std::ostream &errorStream)
Definition: VhdlRomGenerator.cc:50
ProGe::IN
@ IN
Input port.
Definition: ProGeTypes.hh:53
MemoryGenerator
Definition: MemoryGenerator.hh:85