1 #include "ArithmeticEvaluator.h"
\r
2 #include "FunctionalInterface.h"
\r
3 #include "ReferenceInterface.h"
\r
4 #include "GroupInterface.h"
\r
5 #include "FunctionalBlock.h"
\r
6 #include "GroupBlock.h"
\r
8 FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterface *_reference) throw(Exception) : ConnectedInterface(_owner) {
\r
10 if (_owner == NULL) throw(Exception(BLOCK_NULL));
\r
11 if (_reference == NULL) throw(Exception(IFACE_NULL));
\r
13 if (! _owner->isFunctionalBlock()) throw(Exception(BLOCK_INVALID_TYPE));
\r
14 if (! _reference->isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
\r
16 reference = _reference;
\r
18 name = reference->getName();
\r
19 type = reference->getType();
\r
20 endianess = reference->getEndianess();
\r
21 width = reference->getWidthString();
\r
22 direction = reference->getDirection();
\r
23 purpose = reference->getPurpose();
\r
24 connectedFrom = NULL;
\r
27 bool FunctionalInterface::isFunctionalInterface() {
\r
31 int FunctionalInterface::getInterfaceMultiplicity() {
\r
35 FunctionalInterface* iface = NULL;
\r
37 if (direction == AbstractInterface::Input) {
\r
38 QList<AbstractInterface *> inputs = owner->getInputs();
\r
39 for(i=0;i<inputs.size();i++) {
\r
40 iface = AI_TO_FUN(inputs.at(i));
\r
41 if (iface->getReference() == reference) {
\r
46 else if (direction == AbstractInterface::Output) {
\r
47 QList<AbstractInterface *> outputs = owner->getOutputs();
\r
48 for(i=0;i<outputs.size();i++) {
\r
49 iface = AI_TO_FUN(outputs.at(i));
\r
50 if (iface->getReference() == reference) {
\r
55 else if (direction == AbstractInterface::InOut) {
\r
56 QList<AbstractInterface *> bidirs = owner->getBidirs();
\r
57 for(i=0;i<bidirs.size();i++) {
\r
58 iface = AI_TO_FUN(bidirs.at(i));
\r
59 if (iface->getReference() == reference) {
\r
64 if (ifaceCount == 0) {
\r
67 else if ( reference->getMultiplicity() == -1) {
\r
70 else if ( ifaceCount < reference->getMultiplicity()) {
\r
76 AbstractInterface *FunctionalInterface::clone() {
\r
77 int id = getInterfaceMultiplicity();
\r
78 if (id < 0) return NULL;
\r
79 FunctionalInterface *inter = new FunctionalInterface(owner, reference);
\r
80 inter->setWidth(width);
\r
81 inter->setName(reference->getName()+"_"+QString::number(id+1));
\r
85 bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {
\r
88 necessary conditions :
\r
89 - this is an output or in/out interface
\r
90 - iface type must be functional or group interface
\r
91 - iface->connectedFrom must be NULL
\r
93 valid "normal" cases:
\r
94 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
95 1.1 - this is output and iface is input
\r
96 1.2 - both are inout
\r
97 2 - iface is owned by the parent group of the block that owns this
\r
98 2.1 - this is an output, iface is an output of the group
\r
99 2.2 - both are inout
\r
100 3 - this is owned by a source block and iface is owned by the top group
\r
102 special case : clk/reset from clkrstgen can connect to stimuli clk/reset
\r
105 if (direction == Input) return false;
\r
106 if (iface->isReferenceInterface()) return false;
\r
107 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
108 if (connIface->getConnectedFrom() != NULL) return false;
\r
110 if ((getOwner()->getName().startsWith("clkrstgen")) && (iface->getOwner()->isStimuliBlock())) {
\r
111 if ((direction == Output) && (iface->getDirection() == Input)) {
\r
112 if ((purpose == AbstractInterface::Clock) && (iface->getPurpose() == AbstractInterface::Clock)) return true;
\r
113 else if ((purpose == AbstractInterface::Reset) && (iface->getPurpose() == AbstractInterface::Reset)) return true;
\r
117 // first case: interface of blocks within the same group
\r
118 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
120 if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
\r
121 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
\r
123 // second case: iface = interface of the group that contains owner of this
\r
124 else if (getOwner()->getParent() == iface->getOwner()) {
\r
125 if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
\r
126 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
\r
128 else if ((getOwner()->isStimuliBlock()) && (iface->getOwner()->isTopGroupBlock())) {
\r
129 if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
\r
136 bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {
\r
139 necessary conditions :
\r
140 - this is an input or in/out interface
\r
141 - iface type must be functional or group interface
\r
142 - this connectedFrom must be NULL
\r
145 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
146 1.1 - this is input and iface is output
\r
147 1.2 - both are inout
\r
148 2 - iface is owned by the parent group of the block that owns this
\r
149 2.1 - this is an input, iface is an input of the group
\r
150 2.2 - both are inout
\r
152 special case : clk/reset of stimuli can connect from clk/reset of clkrstgen
\r
154 if (direction == Output) return false;
\r
155 if (iface->isReferenceInterface()) return false;
\r
156 if (connectedFrom != NULL) return false;
\r
159 if ((iface->getOwner()->getName().startsWith("clkrstgen")) && (getOwner()->isStimuliBlock())) {
\r
160 if ((direction == Input) && (iface->getDirection() == Output)) {
\r
161 if ((purpose == AbstractInterface::Clock) && (iface->getPurpose() == AbstractInterface::Clock)) return true;
\r
162 else if ((purpose == AbstractInterface::Reset) && (iface->getPurpose() == AbstractInterface::Reset)) return true;
\r
166 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
168 if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
\r
169 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
\r
171 else if (getOwner()->getParent() == iface->getOwner()) {
\r
172 if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
\r
173 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
\r
179 int FunctionalInterface::getClockDomain() throw(Exception) {
\r
183 FunctionalInterface* iface = NULL;
\r
184 if (clkIfaceType == ClockName) {
\r
185 iface = AI_TO_FUN(getClockIface());
\r
187 else if ((direction == Input) && (purpose == Clock)) {
\r
191 if ( iface != NULL) {
\r
193 // if iface is a functional interface, it is connected to clkrstgen_X (in top group) or to ext_clk_X (in subgroup)
\r
194 ConnectedInterface* connFrom = iface->getConnectedFrom();
\r
195 if (connFrom == NULL) throw(Exception(IFACE_INVALID_CLKFREQ,this));
\r
197 if (connFrom->getOwner()->isFunctionalBlock()) {
\r
198 QString name = connFrom->getOwner()->getName();
\r
199 cout << "conn from clkrstgen: searching for clkdomain in " << qPrintable(name) << endl;
\r
202 idClock = name.toInt(&ok);
\r
203 if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this));
\r
206 QString name = connFrom->getName();
\r
207 cout << "conn from group: searching for clkdomain in " << qPrintable(name) << endl;
\r
210 idClock = name.toInt(&ok);
\r
211 if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this));
\r
219 void FunctionalInterface::connectionsValidation(QStack<AbstractInterface *> *interfacetoValidate, QList<AbstractInterface *> *validatedInterfaces) throw(Exception) {
\r
222 //inputs interfaces
\r
223 double widthInput, widthOutput;
\r
224 if(getDirection() == AbstractInterface::Input){
\r
225 widthInput = getDoubleWidth();
\r
226 widthOutput = getConnectedFrom()->getDoubleWidth();
\r
227 if(widthInput != widthOutput){
\r
228 throw new Exception(WIDTHS_NOT_EQUALS);
\r
230 foreach(AbstractInterface *inter, getOwner()->getOutputs()){
\r
231 if(inter->isConnectedTo()){
\r
232 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
233 interfacetoValidate->push(inter);
\r
238 //outputs interfaces
\r
239 else if(getDirection() == AbstractInterface::Output){
\r
240 widthOutput = getDoubleWidth();
\r
241 foreach(AbstractInterface *inter, getConnectedTo()){
\r
242 widthInput = inter->getDoubleWidth();
\r
243 if(widthInput != widthOutput){
\r
244 throw new Exception(WIDTHS_NOT_EQUALS);
\r
247 foreach(AbstractInterface *inter, getConnectedTo()){
\r
248 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
249 interfacetoValidate->push(inter);
\r
253 else if(getDirection() == AbstractInterface::InOut){
\r