OpenASIP 2.2
Loading...
Searching...
No Matches
SocketBusConnCmd.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file SocketBusConnCmd.cc
26 *
27 * Definition of SocketBusConnCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2019
31 * @note rating: red
32 */
33
34#include "Application.hh"
35#include "SocketBusConnCmd.hh"
36#include "FUPort.hh"
37#include "RFPort.hh"
38#include "FunctionUnit.hh"
39#include "HWOperation.hh"
40#include "OperationPool.hh"
41#include "Operation.hh"
42#include "Operand.hh"
43
44using namespace TTAMachine;
45
46/**
47 * The Constructor.
48 *
49 * @param segment Segment to connect/disconnect.
50 * @param socket Socket to connect/disconnect.
51 */
54 socket_(socket), segment_(segment) {
55}
56
57
58/**
59 * The Destructor.
60 */
63
64
65/**
66 * Executes the command.
67 *
68 * @return true, if the command was succesfully executed, false otherwise.
69 */
70bool
72
74 try {
76 } catch (Exception& e) {
77 return false;
78 }
79 } else {
80 try {
81 // If there was no direction before for this socket, let's
82 // try to figure out a better guess for it after connected
83 // to a port.
84 bool resetDirection =
87
88 if (resetDirection && socket_->portCount() > 0) {
89 if (FUPort *port = dynamic_cast<FUPort*>(socket_->port(0))) {
91 dynamic_cast<FunctionUnit*>(port->parentUnit());
92 for (int i = 0; i < FUnit->operationCount(); ++i) {
93 HWOperation* hwOp = FUnit->operation(i);
94 if (!hwOp->isBound(*port)) continue;
95 int operandId = hwOp->io(*port);
96 OperationPool opPool;
97 Operation& osalOp = opPool.operation(hwOp->name().c_str());
98 if (osalOp.isNull()) break;
99 if (osalOp.operand(operandId).isInput())
101 else
103 break;
104 }
105 } else if (RFPort* port =
106 dynamic_cast<RFPort*>(socket_->port(0))) {
107 // RF ports have no other direction clue but the naming, which
108 // is often 'rd' or 'wr'. rd is for a port that is _used for_
109 // reading data (thus OUTPUT). This is probably a better guess
110 // than always assuming one or another.
111 if (port->name().size() > 0 && port->name()[0] == 'r')
113 else
115 }
116 }
117 // HERE.
118 } catch (Exception& e) {
119 return false;
120 }
121 }
122
123 return true;
124}
virtual bool isInput() const
Definition Operand.cc:145
Operation & operation(const char *name)
bool isNull() const
virtual Operand & operand(int id) const
Definition Operation.cc:541
virtual bool Do()
virtual ~SocketBusConnCmd()
TTAMachine::Socket * socket_
Socket to connect.
SocketBusConnCmd(TTAMachine::Socket *socket, TTAMachine::Segment *segment)
TTAMachine::Segment * segment_
Bus segment to connect.
virtual HWOperation * operation(const std::string &name) const
virtual int operationCount() const
int io(const FUPort &port) const
const std::string & name() const
bool isBound(const FUPort &port) const
void setDirection(Direction direction)
Definition Socket.cc:130
@ OUTPUT
Data goes from port to bus.
Definition Socket.hh:60
@ INPUT
Data goes from bus to port.
Definition Socket.hh:59
@ UNKNOWN
Unknown direction.
Definition Socket.hh:61
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331
void detachBus(Segment &bus)
Definition Socket.cc:213
Direction direction() const
Port * port(int index) const
Definition Socket.cc:266
void attachBus(Segment &bus)
Definition Socket.cc:166
int portCount() const