X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/bc5d59217a24b25c1b913bec4a41dd026d02720c..e0eaffd44fc9733bc230a803c80d8d5efd0faca6:/Graph.cpp?ds=sidebyside diff --git a/Graph.cpp b/Graph.cpp index d0c11cc..2b43baa 100644 --- a/Graph.cpp +++ b/Graph.cpp @@ -3,6 +3,8 @@ #include "ReferenceBlock.h" #include "FunctionalBlock.h" #include "SpecialBlock.h" +#include "BlockParameter.h" +#include "ConnectedInterface.h" Graph::Graph() { topGroup = NULL; @@ -275,6 +277,7 @@ void Graph::generateTestbench(const QString &projectName, const QString &benchFi out << "use IEEE.numeric_std.all;" << endl; out << "entity " << projectName << "_tb is" << endl; out << "end entity " << projectName << "_tb;" << endl << endl; + out << "architecture " << projectName << "_tb_1 of " << projectName << "_tb is" << endl << endl; out << " component clock_gen" << endl; @@ -287,7 +290,238 @@ void Graph::generateTestbench(const QString &projectName, const QString &benchFi out << " end component;" << endl << endl; topGroup->generateComponent(out,false); + foreach(FunctionalBlock* block, stimulis) { + block->generateComponent(out,false); + } + + out << " ----------------------------" << endl; + out << " -- SIGNALS" << endl; + out << " ----------------------------" << endl << endl; + + out << " -- signals to reset stimulis" << endl; + foreach(FunctionalBlock* block, stimulis) { + out << " signal reset_" << block->getName() << " : std_logic;" << endl; + } + out << endl; + + out << " -- signals for external clocks/reset" << endl; + for(int i=0;igetName() << endl; + QList listInputs = block->getInputs(); + foreach(AbstractInterface* iface, listInputs) { + if (iface->getPurpose() == AbstractInterface::Data) { + out << " signal " << iface->toVHDL(AbstractInterface::Signal,0) << endl; + } + } + } + catch(Exception e) { + throw(e); + } + try { + out << " -- signals from output ports of " << block->getName() << endl; + QList listOutputs = block->getOutputs(); + foreach(AbstractInterface* iface, listOutputs) { + if ((iface->getPurpose() == AbstractInterface::Data)||(iface->getPurpose() == AbstractInterface::Control)) { + out << " signal " << iface->toVHDL(AbstractInterface::Signal,0) << endl; + } + } + } + catch(Exception e) { + throw(e); + } + out << endl; + } + out << endl; + + // signals out of top group + try { + out << " -- signals from output ports of " << topGroup->getName() << endl; + QList listOutputs = topGroup->getOutputs(); + foreach(AbstractInterface* iface, listOutputs) { + if ((iface->getPurpose() == AbstractInterface::Data)||(iface->getPurpose() == AbstractInterface::Control)) { + out << " signal " << iface->toVHDL(AbstractInterface::Signal,0) << endl; + } + } + } + catch(Exception e) { + throw(e); + } + out << endl; + + // signals out of top group + try { + out << " -- signals from inout ports of " << topGroup->getName() << endl; + QList listBidirs = topGroup->getBidirs(); + foreach(AbstractInterface* iface, listBidirs) { + if (iface->getPurpose() == AbstractInterface::Data) { + out << " signal " << iface->toVHDL(AbstractInterface::Signal,0) << endl; + } + } + } + catch(Exception e) { + throw(e); + } + out << endl; + + out << "begin" << endl; + // for now assign all external resets to fixed 0 because of clkrstgen in top group + for(int i=0;i " << halfPer << " ns" << endl; + out << " )" << endl; + out << " port map (" << endl; + out << " phase => ext_clk_" << i << endl; + out << " );" << endl << endl; + } + // generate instances of stimulis + foreach(FunctionalBlock* block, stimulis) { + try { + out << " " << block->getName() << "_1 : " << block->getName() << endl; + + QList listGenerics = block->getGenericParameters(); + QList listInputs = block->getInputs(); + QList listOutputs = block->getOutputs(); + + if (!listGenerics.isEmpty()) { + out << " generic map (" << endl; + int i; + for(i=0;itoVHDL(BlockParameter::Instance, BlockParameter::NoComma) << "," << endl; + } + out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Instance,BlockParameter::NoComma) << endl; + out << " )" << endl; + } + + out << " port map (" << endl; + QString portMap = ""; + + for(int i=0;igetPurpose() == AbstractInterface::Data) || (connIface->getPurpose() == AbstractInterface::Control)) { + portMap += " " + connIface->getName() + " => " + connIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n"; + } + else if (connIface->getPurpose() == AbstractInterface::Clock) { + // get the "fake" clkrstgen from which it is connected + ConnectedInterface* fromIface = connIface->getConnectedFrom(); + QString clkrstName = fromIface->getOwner()->getName(); + clkrstName.remove(0,10); + portMap += " " + connIface->getName() + " => ext_clk_" + clkrstName + ",\n"; + } + else if (connIface->getPurpose() == AbstractInterface::Reset) { + portMap += " " + connIface->getName() + " => reset_" + block->getName()+",\n"; + } + } + for(int i=0;igetName() + " => " + connIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n"; + } + portMap.chop(2); + out << portMap << endl; + + + out << " );" << endl; + } + catch(Exception e) { + throw(e); + } + out << endl; + } + out << endl; + // generate instance of top group + try { + out << " " << topGroup->getName() << "_1 : " << topGroup->getName() << endl; + + QList listGenerics = topGroup->getGenericParameters(); + QList listInputs = topGroup->getInputs(); + QList listOutputs = topGroup->getOutputs(); + QList listBidirs = topGroup->getBidirs(); + + if (!listGenerics.isEmpty()) { + out << " generic map (" << endl; + int i; + for(i=0;itoVHDL(BlockParameter::Instance, BlockParameter::NoComma) << "," << endl; + } + out << " " << listGenerics.at(i)->toVHDL(BlockParameter::Instance,BlockParameter::NoComma) << endl; + out << " )" << endl; + } + + out << " port map (" << endl; + QString portMap = ""; + + for(int i=0;igetPurpose() == AbstractInterface::Data) || (connIface->getPurpose() == AbstractInterface::Control)) { + ConnectedInterface* fromIface = connIface->getConnectedFrom(); + portMap += " " + connIface->getName() + " => " + fromIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n"; + } + else if ( (connIface->getPurpose() == AbstractInterface::Clock) || (connIface->getPurpose() == AbstractInterface::Reset)) { + portMap += " " + connIface->getName() + " => " + connIface->getName() + ",\n"; + } + } + for(int i=0;igetName() + " => " + connIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n"; + } + for(int i=0;igetName() + " => " + connIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n"; + } + portMap.chop(2); + out << portMap << endl; + + + out << " );" << endl; + } + catch(Exception e) { + throw(e); + } + out << endl; + + // generate process for stimulis + foreach(FunctionalBlock* block, stimulis) { + // getting the start input + AbstractInterface* startIface = block->getIfaceFromName("start"); + if (startIface == NULL) continue; + double per = 1000.0/startIface->getClockFrequency(); + QString startName = block->getName()+"_start"; + out << " from_" << block->getName() << " : process" << endl; + out << " variable pclk : time := " << per << " ns;" << endl; + out << " begin" << endl; + out << " reset_" << block->getName() << " <= '0';" << endl; + out << " " << startName << " <= '0';" << endl; + out << " wait for 2*pclk;" << endl; + out << " reset_" << block->getName() << " <= '1';" << endl; + out << " wait for 1*pclk;" << endl; + out << " reset_" << block->getName() << " <= '0';" << endl; + out << " wait for 5*pclk;" << endl; + out << " " << startName << " <= '1';" << endl; + out << " wait for pclk;" << endl; + out << " " << startName << " <= '0';" << endl << endl; + out << " wait for 100000 us;" << endl; + out << " end process from_" << block->getName() << ";" << endl; + } + out << "end architecture " << projectName << "_tb_1;" << endl; vhdlBench.close(); }