1 #include "GroupInterface.h"
2 #include "FunctionalInterface.h"
3 #include "GroupBlock.h"
5 GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,_direction,_purpose,"inherited","") {
6 if (! _owner->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE));
9 // force clock and reset to boolean width type instead of inherited
10 if ((purpose == Clock) || (purpose == Reset)) {
13 clkIfaceType = InheritedName;
16 bool GroupInterface::isGroupInterface() {
20 AbstractInterface *GroupInterface::clone() {
21 GroupInterface *inter = new GroupInterface(owner,name,direction, purpose);
22 inter->setWidth(width);
26 int GroupInterface::getWidth() {
33 if (type == Boolean) {
36 else if (type == Inherited) {
37 // must search from which iface it is connected.
38 ConnectedInterface* fromIface = connectedFrom;
39 while ((fromIface != NULL) && (fromIface->getType() == Inherited)) {
40 fromIface = fromIface->getConnectedFrom();
42 if (fromIface == NULL) return -1;
43 w = fromIface->getWidth();
48 bool GroupInterface::canConnectTo(AbstractInterface *iface, bool testClock) {
51 necessary conditions :
52 - iface type must be functional or group interface
53 - iface->connectedFrom must be NULL
56 1 - this is owned by the parent group of the block (group or func) that owns iface
57 1.1 - this is input and iface is input
59 2 - this is owned by a group that has the same parent as the block (group or func) that owns iface
60 2.1 - this is an output, iface is an input of the group
62 3 - this is owned by a group and iface by its parent group
63 2.1 - this is an output, iface is an output of the group
66 NB: testClock is useless since a group interface has always a clkIfaceType inherited.
67 Thus, it is always possible
72 if (iface->isReferenceInterface()) return false;
73 ConnectedInterface* connIface = AI_TO_CON(iface);
74 if (connIface->getConnectedFrom() != NULL) return false;
76 if (this->getOwner() == iface->getOwner()->getParent()) {
77 if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true;
78 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
81 else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) {
82 if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true;
83 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
85 else if (this->getOwner()->getParent() == iface->getOwner()) {
86 if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true;
87 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
92 int dom1 = -1,dom2 = -2;
94 dom1 = getClockDomain();
95 dom2 = iface->getClockDomain();
98 cerr << qPrintable(e.getMessage()) << endl;
102 cout << "cannot connect interface that are in different clock domains" << endl;
112 bool GroupInterface::canConnectFrom(AbstractInterface *iface, bool testClock) {
115 necessary conditions :
116 - iface type must be functional or group interface
117 - this->connectedFrom must be NULL
120 1 - this is owned by the parent group of the block (group or func) that owns iface
121 1.1 - this is output and iface is output
123 2 - this is owned by a group that has the same parent as the block (group or func) that owns iface
124 2.1 - this is an input, iface is an output of the group
126 3 - this is owned by a group and iface by its parent group
127 2.1 - this is an input, iface is an input of the group
129 4 - this is owned by top group and iface is an output of a source block
133 if (iface->isReferenceInterface()) return false;
134 if (getConnectedFrom() != NULL) return false;
136 if (this->getOwner() == iface->getOwner()->getParent()) {
137 if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true;
138 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
141 else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) {
142 if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true;
143 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
145 else if (this->getOwner()->getParent() == iface->getOwner()) {
146 if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true;
147 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true;
149 else if ((getOwner()->isTopGroupBlock()) && (iface->getOwner()->isStimuliBlock())) {
150 if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true;
155 int dom1 = -1,dom2 = -2;
157 dom1 = getClockDomain();
158 dom2 = iface->getClockDomain();
161 cerr << qPrintable(e.getMessage()) << endl;
165 cout << "cannot connect interface that are in different clock domains" << endl;
175 int GroupInterface::getClockDomain() throw(Exception) {
177 /* For clk/rst interfaces, the clock domain can be deduced
178 from the interface name.
179 Otherwise, we can search backward/forward for a functional
180 interface. Since a group interface cannot exist if it is not
181 connected to and/or from a functional interface (either directly
182 or through a sequence of subgroups) there is at least such a functional
186 if ((purpose == Clock) || (purpose == Reset)) {
187 QString domName = name;
190 idClock = domName.toInt(&ok);
191 if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this));
194 // start by searching backward
195 ConnectedInterface* connFrom = connectedFrom;
196 while ((connFrom != NULL) && (connFrom->isGroupInterface())) {
197 connFrom = connFrom->getConnectedFrom();
199 if (connFrom != NULL) {
200 idClock = connFrom->getClockDomain();
204 QList<ConnectedInterface*> lstIfaces = getForwardFunctionalInterfaces(this);
205 if (lstIfaces.isEmpty()) throw(Exception(IFACE_INVALID_CLKFREQ,this));
206 foreach(ConnectedInterface* iface, lstIfaces) {
207 // test if all ifaces are in the same clock domain
209 idClock = iface->getClockDomain();
211 else if (idClock != iface->getClockDomain()) throw(Exception(IFACE_INVALID_CLKFREQ,this));
219 QList<ConnectedInterface*> GroupInterface::getForwardFunctionalInterfaces(GroupInterface* groupIface) {
220 QList<ConnectedInterface*> lstIfaces;
221 foreach(ConnectedInterface* iface, groupIface->getConnectedTo()) {
222 if (iface->isFunctionalInterface()) {
223 lstIfaces.append(iface);
225 else if (iface->isGroupInterface()) {
226 lstIfaces.append(getForwardFunctionalInterfaces(AI_TO_GRP(iface)));
232 void GroupInterface::connectionsValidation(QStack<AbstractInterface*> *interfacetoValidate, QList<AbstractInterface*> *validatedInterfaces) throw(Exception) {
233 cout << "group interface connection validation" << endl;