OpenASIP 2.2
Loading...
Searching...
No Matches
TestBenchBlock.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 TestBenchBlock.cc
26 *
27 * Implementation of TestBenchBlock 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 "TestBenchBlock.hh"
35
37
38#include "Machine.hh"
39#include "MachineInfo.hh"
40
42#include "FileSystem.hh"
43#include "Environment.hh"
44#include "Conversion.hh"
45
46namespace ProGe {
47
48/**
49 * Construct The test bench for the core TTA processor.
50 *
51 * The test bench creation is limited to TTAs with one address space for
52 * instruction and address spaces for data shared by one LSU at most.
53 *
54 * @param context The context for deriving necessary information about the
55 * core.
56 * @param coreBlock The DUT for test bench
57 * @exception Thrown if the test bench can not be created.
58 */
60 const ProGeContext& context, const BaseNetlistBlock& coreBlock)
61 : BaseNetlistBlock("testbench", ""), context_(context), proc_(nullptr) {
62 using namespace TTAMachine;
63
64 std::map<std::string, unsigned> ASUserCounts;
65 std::map<std::string, unsigned> lockFUCounts;
66
67 for (auto fu : MachineInfo::findLockUnits(context.adf())) {
68 if (fu->hasAddressSpace()) {
69 lockFUCounts[fu->addressSpace()->name()]++;
70 }
71 }
72
73 for (auto fu : context.adf().functionUnitNavigator()) {
74 if (fu->hasAddressSpace()) {
75 ASUserCounts[fu->addressSpace()->name()]++;
76 }
77 }
78
79 for (auto asUserCount : ASUserCounts) {
80 unsigned LSUCount(asUserCount.second);
81
82 if (lockFUCounts.count(asUserCount.first) > 0) {
83 LSUCount -= lockFUCounts[asUserCount.first];
84 }
85
86 if (LSUCount > 1) {
88 "Can not create test bench for TTA address spaces shared by "
89 "multiple LSUs.");
90 }
91 }
92 try {
93 proc_ = new ProcessorWrapperBlock(context, coreBlock);
94 } catch (Exception& e) {
96 }
97}
98
101
102void
103TestBenchBlock::write(const Path& targetBaseDir, HDL targetLang) const {
104 // Check language compatibility //
105 if (targetLang != VHDL) {
106 THROW_EXCEPTION(NotAvailable, "Only VHDL is supported.");
107 }
108
110
111 instantiator.replacePlaceholder("dut-entity", proc_->moduleName());
112
113 if (context_.idf().icDecoderParameterValue("debugger") == "external") {
114 instantiator.replacePlaceholder("proc-entity-db-signals",
115 "db_pc_start : in std_logic_vector(IMEMADDRWIDTH-1 downto 0);\n"
116 "db_tta_nreset : in std_logic;\n"
117 "db_lockrq : in std_logic;");
118
119 instantiator.replacePlaceholder("proc-instance-db-signals",
120 "db_pc_start => (others => '0'),\n"
121 "db_tta_nreset => '1',\n"
122 "db_lockrq => '0',");
123 }
124
125 FileSystem::createDirectory(targetBaseDir / std::string("tb"));
126
127 Path progeDataDir(Environment::dataDirPath("ProGe"));
128 instantiator.instantiateTemplateFile(
129 progeDataDir / std::string("tb") / std::string("testbench.vhdl.tmpl"),
130 targetBaseDir / std::string("tb") / std::string("testbench.vhdl"));
131 instantiator.instantiateTemplateFile(
132 progeDataDir / std::string("tb") / std::string("clkgen.vhdl"),
133 targetBaseDir / std::string("tb") / std::string("clkgen.vhdl"));
134
135 proc_->write(targetBaseDir, targetLang);
136}
137
138} /* namespace ProGe */
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition Exception.hh:39
static std::string dataDirPath(const std::string &prog)
std::string errorMessage() const
Definition Exception.cc:123
static bool createDirectory(const std::string &path)
void instantiateTemplateFile(const std::string &templateFile, const std::string &dstFile)
void replacePlaceholder(const std::string &key, const std::string &replacer, bool append=false)
std::string icDecoderParameterValue(const std::string &name) const
static std::vector< const TTAMachine::FunctionUnit * > findLockUnits(const TTAMachine::Machine &machine)
const std::string & moduleName() const
const std::string & coreEntityName() const
const IDF::MachineImplementation & idf() const
const TTAMachine::Machine & adf() const
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
ProcessorWrapperBlock * proc_
The block that wraps the processor and instantiates memories for the GCU and LSUs.
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
const ProGeContext & context_
The ProGe context for additional information.
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
Definition FUGen.hh:54
HDL
HDLs supported by ProGe.
Definition ProGeTypes.hh:40
@ VHDL
VHDL.
Definition ProGeTypes.hh:41