+ 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<clocks.size();i++) {
+ out << " ext_reset_" << i << " <= '0';" << endl;
+ }
+ out << endl;
+ // generate clock instances
+ for(int i=0;i<clocks.size();i++) {
+ double halfPer = 500.0/clocks.at(i);
+ out << " clock_" << i << " : clock_gen" << endl;
+ out << " generic map (" << endl;
+ out << " Tps => " << 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<BlockParameter*> listGenerics = block->getGenericParameters();
+ QList<AbstractInterface*> listInputs = block->getInputs();
+ QList<AbstractInterface*> listOutputs = block->getOutputs();
+
+ if (!listGenerics.isEmpty()) {
+ out << " generic map (" << endl;
+ int i;
+ for(i=0;i<listGenerics.size()-1;i++) {
+ out << " " << listGenerics.at(i)->toVHDL(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;i<listInputs.size();i++) {
+ ConnectedInterface* connIface = AI_TO_CON(listInputs.at(i));
+ if ( (connIface->getPurpose() == 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;i<listOutputs.size();i++) {
+ ConnectedInterface* connIface = AI_TO_CON(listOutputs.at(i));
+ portMap += " " + connIface->getName() + " => " + 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<BlockParameter*> listGenerics = topGroup->getGenericParameters();
+ QList<AbstractInterface*> listInputs = topGroup->getInputs();
+ QList<AbstractInterface*> listOutputs = topGroup->getOutputs();
+ QList<AbstractInterface*> listBidirs = topGroup->getBidirs();
+
+ if (!listGenerics.isEmpty()) {
+ out << " generic map (" << endl;
+ int i;
+ for(i=0;i<listGenerics.size()-1;i++) {
+ out << " " << listGenerics.at(i)->toVHDL(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;i<listInputs.size();i++) {
+ ConnectedInterface* connIface = AI_TO_CON(listInputs.at(i));
+ if ( (connIface->getPurpose() == 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;i<listOutputs.size();i++) {
+ ConnectedInterface* connIface = AI_TO_CON(listOutputs.at(i));
+ portMap += " " + connIface->getName() + " => " + connIface->toVHDL(AbstractInterface::Instance, AbstractInterface::NoComma) + ",\n";
+ }
+ for(int i=0;i<listBidirs.size();i++) {
+ ConnectedInterface* connIface = AI_TO_CON(listBidirs.at(i));
+ portMap += " " + connIface->getName() + " => " + 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();
+
+}
+
+QList<QString> Graph::getExternalResources() {
+ QList<QString> list = topGroup->getExternalResources();
+ return list;