1 #include <AbstractBlock.h>
\r
2 #include <QInputDialog>
\r
3 #include <QMessageBox>
\r
4 #include "AbstractInterface.h"
\r
5 #include "BlockParameter.h"
\r
6 #include "Parameters.h"
\r
7 #include "GroupBlock.h"
\r
8 #include "ConnectedInterface.h"
\r
11 AbstractBlock::AbstractBlock() {
\r
17 AbstractBlock::AbstractBlock(const QString& _name) {
\r
18 name = Parameters::normalizeName(_name);
\r
23 AbstractBlock::~AbstractBlock() {
\r
25 removeAllInterfaces();
\r
27 foreach(BlockParameter* p, params) {
\r
33 void AbstractBlock::setName(const QString& str) {
\r
34 name = Parameters::normalizeName(str);
\r
37 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
41 bool AbstractBlock::isReferenceBlock() {
\r
45 bool AbstractBlock::isFunctionalBlock() {
\r
49 bool AbstractBlock::isGroupBlock() {
\r
53 bool AbstractBlock::isTopGroupBlock() {
\r
57 bool AbstractBlock::isSourceBlock() {
\r
60 /* NB: a generator is a block that has no data inputs
\r
61 * and has at least one data output.
\r
62 * By the way, blokcs that have no data input/output
\r
63 * (like clkrstgen) are not generators !
\r
65 bool AbstractBlock::isGeneratorBlock() {
\r
66 if (getDataInputs().size() > 0) return false;
\r
67 if (getDataOutputs().size() == 0) return false;
\r
71 void AbstractBlock::addParameter(BlockParameter *param) {
\r
72 params.append(param);
\r
76 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
77 foreach(BlockParameter* p, params) {
\r
78 if (p->getName() == name) return p;
\r
83 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
84 if(inter->getDirection() == AbstractInterface::Input){
\r
85 inputs.append(inter);
\r
86 } else if(inter->getDirection() == AbstractInterface::Output){
\r
87 outputs.append(inter);
\r
88 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
89 bidirs.append(inter);
\r
93 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
94 /* CAUTION: no check is done about the connection state of this interface
\r
95 Thus, if it is still connected to/from, there will be a crash
\r
97 if(inter->getDirection() == AbstractInterface::Input){
\r
98 inputs.removeAll(inter);
\r
99 } else if(inter->getDirection() == AbstractInterface::Output){
\r
100 outputs.removeAll(inter);
\r
101 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
102 bidirs.removeAll(inter);
\r
107 void AbstractBlock::removeAllInterfaces() {
\r
109 foreach(AbstractInterface* iface, inputs) {
\r
112 foreach(AbstractInterface* iface, outputs) {
\r
115 foreach(AbstractInterface* iface, bidirs) {
\r
124 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
126 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
128 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
130 while (!ok && value.isEmpty())
\r
132 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
133 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
135 param->setValue(value);
\r
138 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
139 QList<AbstractInterface *> list;
\r
140 bool selIn = false;
\r
141 bool selOut = false;
\r
142 bool selInOut = false;
\r
144 if (direction == AbstractInterface::AnyDirection) {
\r
149 else if (direction == AbstractInterface::Input) {
\r
152 else if (direction == AbstractInterface::Output) {
\r
155 else if (direction == AbstractInterface::InOut) {
\r
159 foreach(AbstractInterface* iface, inputs) {
\r
160 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
164 foreach(AbstractInterface* iface, outputs) {
\r
165 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
169 foreach(AbstractInterface* iface, bidirs) {
\r
170 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
176 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
177 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
180 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
181 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
184 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
185 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
188 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
189 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
192 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
194 foreach(AbstractInterface* iface, inputs) {
\r
195 if (iface->getName() == name) return iface;
\r
197 foreach(AbstractInterface* iface, outputs) {
\r
198 if (iface->getName() == name) return iface;
\r
200 foreach(AbstractInterface* iface, bidirs) {
\r
201 if (iface->getName() == name) return iface;
\r
206 bool AbstractBlock::isWBConfigurable() {
\r
208 foreach(BlockParameter* p, params) {
\r
209 if (p->isWishboneParameter()) return true;
\r
214 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
215 QList<BlockParameter *> lst;
\r
216 foreach(BlockParameter* p, params) {
\r
217 if (p->isUserParameter()) lst.append(p);
\r
222 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
223 QList<BlockParameter *> lst;
\r
224 foreach(BlockParameter* p, params) {
\r
225 if (p->isGenericParameter()) lst.append(p);
\r
230 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
231 QList<BlockParameter *> lst;
\r
232 foreach(BlockParameter* p, params) {
\r
233 if (p->isPortParameter()) lst.append(p);
\r
238 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
239 QList<BlockParameter *> lst;
\r
240 foreach(BlockParameter* p, params) {
\r
241 if (p->isWishboneParameter()) lst.append(p);
\r
248 void AbstractBlock::connectClkReset() throw(Exception) {
\r
250 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
252 cout << "connecting clk/rst for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
254 QList<AbstractInterface* > lstClk = getInterfaces(AbstractInterface::Input,AbstractInterface::Clock);
\r
255 QList<AbstractInterface* > lstRst = getInterfaces(AbstractInterface::Input,AbstractInterface::Reset);
\r
257 if ((lstClk.isEmpty()) || (lstRst.isEmpty())) {
\r
258 throw(Exception(IFACE_GROUP_NOCLKRST,this));
\r
261 ConnectedInterface* toClk = AI_TO_CON(lstClk.at(0));
\r
262 ConnectedInterface* toRst = AI_TO_CON(lstRst.at(0));
\r
264 ConnectedInterface* fromClk = NULL;
\r
265 ConnectedInterface* fromRst = NULL;
\r
267 if (parentBlock->isTop()) {
\r
268 AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName("clkrstgen");
\r
269 if (clkrstgen == NULL) {
\r
270 throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));
\r
273 fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));
\r
274 fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));
\r
278 fromClk = AI_TO_CON(parentBlock->getIfaceFromName("clk"));
\r
279 fromRst = AI_TO_CON(parentBlock->getIfaceFromName("reset"));
\r
281 if ((fromClk == NULL) || (fromRst == NULL)) {
\r
282 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
285 fromClk->connectTo(toClk);
\r
286 fromRst->connectTo(toRst);
\r