OpenASIP  2.0
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 
44 using 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  */
62 }
63 
64 
65 /**
66  * Executes the command.
67  *
68  * @return true, if the command was succesfully executed, false otherwise.
69  */
70 bool
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())
100  socket_->setDirection(Socket::INPUT);
101  else
102  socket_->setDirection(Socket::OUTPUT);
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')
112  socket_->setDirection(Socket::OUTPUT);
113  else
114  socket_->setDirection(Socket::INPUT);
115  }
116  }
117  // HERE.
118  } catch (Exception& e) {
119  return false;
120  }
121  }
122 
123  return true;
124 }
OperationPool::operation
Operation & operation(const char *name)
Definition: OperationPool.cc:99
SocketBusConnCmd::Do
virtual bool Do()
Definition: SocketBusConnCmd.cc:71
TTAMachine::Socket::port
Port * port(int index) const
Definition: Socket.cc:266
TTAMachine::Socket::portCount
int portCount() const
TTAMachine::HWOperation
Definition: HWOperation.hh:52
TTAMachine::Segment
Definition: Segment.hh:54
SocketBusConnCmd.hh
TTAMachine::Socket::direction
Direction direction() const
SocketBusConnCmd::SocketBusConnCmd
SocketBusConnCmd(TTAMachine::Socket *socket, TTAMachine::Segment *segment)
Definition: SocketBusConnCmd.cc:52
TTAMachine::RFPort
Definition: RFPort.hh:45
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::HWOperation::io
int io(const FUPort &port) const
Definition: HWOperation.cc:364
TTAMachine::Socket::attachBus
void attachBus(Segment &bus)
Definition: Socket.cc:166
HWOperation.hh
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
Application.hh
TTAMachine::HWOperation::isBound
bool isBound(const FUPort &port) const
Definition: HWOperation.cc:338
TTAMachine::Socket
Definition: Socket.hh:53
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
Operation.hh
Exception
Definition: Exception.hh:54
SocketBusConnCmd::socket_
TTAMachine::Socket * socket_
Socket to connect.
Definition: SocketBusConnCmd.hh:53
TTAMachine::Socket::setDirection
void setDirection(Direction direction)
Definition: Socket.cc:130
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
Operation
Definition: Operation.hh:59
TTAMachine::Socket::detachBus
void detachBus(Segment &bus)
Definition: Socket.cc:213
ComponentCommand
Definition: ComponentCommand.hh:46
Operand.hh
Operation::operand
virtual Operand & operand(int id) const
Definition: Operation.cc:541
SocketBusConnCmd::segment_
TTAMachine::Segment * segment_
Bus segment to connect.
Definition: SocketBusConnCmd.hh:55
Operation::isNull
bool isNull() const
FUPort.hh
UNKNOWN
@ UNKNOWN
Definition: MemoryGenerator.hh:58
RFPort.hh
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
OperationPool
Definition: OperationPool.hh:52
TTAMachine
Definition: Assembler.hh:48
Operand::isInput
virtual bool isInput() const
Definition: Operand.cc:145
OperationPool.hh
SocketBusConnCmd::~SocketBusConnCmd
virtual ~SocketBusConnCmd()
Definition: SocketBusConnCmd.cc:61
FunctionUnit.hh