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
63 bool AbstractBlock::isGeneratorBlock() {
\r
64 if (getDataInputs().size() > 0) return false;
\r
69 void AbstractBlock::addParameter(BlockParameter *param) {
\r
70 params.append(param);
\r
74 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
75 foreach(BlockParameter* p, params) {
\r
76 if (p->getName() == name) return p;
\r
81 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
82 if(inter->getDirection() == AbstractInterface::Input){
\r
83 inputs.append(inter);
\r
84 } else if(inter->getDirection() == AbstractInterface::Output){
\r
85 outputs.append(inter);
\r
86 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
87 bidirs.append(inter);
\r
91 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
92 /* CAUTION: no check is done about the connection state of this interface
\r
93 Thus, if it is still connected to/from, there will be a crash
\r
95 if(inter->getDirection() == AbstractInterface::Input){
\r
96 inputs.removeAll(inter);
\r
97 } else if(inter->getDirection() == AbstractInterface::Output){
\r
98 outputs.removeAll(inter);
\r
99 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
100 bidirs.removeAll(inter);
\r
105 void AbstractBlock::removeAllInterfaces() {
\r
107 foreach(AbstractInterface* iface, inputs) {
\r
110 foreach(AbstractInterface* iface, outputs) {
\r
113 foreach(AbstractInterface* iface, bidirs) {
\r
122 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
124 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
126 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
128 while (!ok && value.isEmpty())
\r
130 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
131 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
133 param->setValue(value);
\r
136 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
137 QList<AbstractInterface *> list;
\r
138 bool selIn = false;
\r
139 bool selOut = false;
\r
140 bool selInOut = false;
\r
142 if (direction == AbstractInterface::AnyDirection) {
\r
147 else if (direction == AbstractInterface::Input) {
\r
150 else if (direction == AbstractInterface::Output) {
\r
153 else if (direction == AbstractInterface::InOut) {
\r
157 foreach(AbstractInterface* iface, inputs) {
\r
158 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
162 foreach(AbstractInterface* iface, outputs) {
\r
163 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
167 foreach(AbstractInterface* iface, bidirs) {
\r
168 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
174 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
175 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
178 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
179 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
182 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
183 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
186 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
187 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
190 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
192 foreach(AbstractInterface* iface, inputs) {
\r
193 if (iface->getName() == name) return iface;
\r
195 foreach(AbstractInterface* iface, outputs) {
\r
196 if (iface->getName() == name) return iface;
\r
198 foreach(AbstractInterface* iface, bidirs) {
\r
199 if (iface->getName() == name) return iface;
\r
204 bool AbstractBlock::isWBConfigurable() {
\r
206 foreach(BlockParameter* p, params) {
\r
207 if (p->isWishboneParameter()) return true;
\r
212 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
213 QList<BlockParameter *> lst;
\r
214 foreach(BlockParameter* p, params) {
\r
215 if (p->isUserParameter()) lst.append(p);
\r
220 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
221 QList<BlockParameter *> lst;
\r
222 foreach(BlockParameter* p, params) {
\r
223 if (p->isGenericParameter()) lst.append(p);
\r
228 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
229 QList<BlockParameter *> lst;
\r
230 foreach(BlockParameter* p, params) {
\r
231 if (p->isPortParameter()) lst.append(p);
\r
236 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
237 QList<BlockParameter *> lst;
\r
238 foreach(BlockParameter* p, params) {
\r
239 if (p->isWishboneParameter()) lst.append(p);
\r
246 void AbstractBlock::connectClkReset() throw(Exception) {
\r
248 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
250 cout << "connecting clk/rst for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
252 QList<AbstractInterface* > lstClk = getInterfaces(AbstractInterface::Input,AbstractInterface::Clock);
\r
253 QList<AbstractInterface* > lstRst = getInterfaces(AbstractInterface::Input,AbstractInterface::Reset);
\r
255 if ((lstClk.isEmpty()) || (lstRst.isEmpty())) {
\r
256 throw(Exception(IFACE_GROUP_NOCLKRST,this));
\r
259 ConnectedInterface* toClk = AI_TO_CON(lstClk.at(0));
\r
260 ConnectedInterface* toRst = AI_TO_CON(lstRst.at(0));
\r
262 ConnectedInterface* fromClk = NULL;
\r
263 ConnectedInterface* fromRst = NULL;
\r
265 if (parentBlock->isTop()) {
\r
266 AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName("clkrstgen");
\r
267 if (clkrstgen == NULL) {
\r
268 throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));
\r
271 fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));
\r
272 fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));
\r
276 fromClk = AI_TO_CON(parentBlock->getIfaceFromName("clk"));
\r
277 fromRst = AI_TO_CON(parentBlock->getIfaceFromName("reset"));
\r
279 if ((fromClk == NULL) || (fromRst == NULL)) {
\r
280 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
283 fromClk->connectTo(toClk);
\r
284 fromRst->connectTo(toRst);
\r