OpenASIP  2.0
SOPCInterface.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 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 SOPCInterface.cc
26  *
27  * Implementation of SOPCInterface class.
28  *
29  * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <cassert>
34 #include "SOPCInterface.hh"
35 #include "Conversion.hh"
36 using std::vector;
37 using std::map;
38 using std::endl;
39 
41  "add_interface";
43  "set_interface_property";
45  "add_interface_port";
47  "ASSOCIATED_CLOCK";
48 
49 const TCEString SOPCInterface::SOPC_CLOCK_INT_NAME = "clock_reset";
51 
52 const TCEString SOPCInterface::SOPC_EXPORT_INT_NAME = "conduit_interface";
55 
56 const TCEString SOPCInterface::SOPC_MASTER_INT_NAME = "avalon_master";
57 const TCEString SOPCInterface::SOPC_MASTER_INT_DECLR = "avalon start";
58 
59 const TCEString SOPCInterface::SOPC_IRQ_RECV_INT_NAME = "interrupt_recv";
60 const TCEString SOPCInterface::SOPC_IRQ_RECV_INT_DECLR = "interrupt start";
61 
62 const TCEString SOPCInterface::SOPC_INPUT = "Input";
63 const TCEString SOPCInterface::SOPC_OUTPUT = "Output";
64 const TCEString SOPCInterface::SOPC_BIDIR = "Bidir";
65 
67  name_(name), declaration_(declaration) {
68 }
69 
71 }
72 
74  const TCEString& propertyName,
75  const TCEString& propertyValue) {
76 
77  properties_[propertyName] = propertyValue;
78 }
79 
80 
82  const TCEString& propertyName,
83  int propertyValue) {
84 
85  TCEString convertedValue = Conversion::toString(propertyValue);
86  setProperty(propertyName, convertedValue);
87 }
88 
89 void
91  const TCEString& hdlName, const TCEString& interfaceName,
92  ProGe::Direction direction, int width) {
93  SOPCPort port = {hdlName, interfaceName, direction, width};
94  ports_.push_back(port);
95 }
96 
99 
100  return name_;
101 }
102 
103 bool
105 
106  return !ports_.empty();
107 }
108 
109 void
110 SOPCInterface::writeInterface(std::ostream& stream) const {
111 
112  stream
113  << "# " << name_ << endl
114  << SOPC_ADD_INTERFACE << " " << name_ << " " << declaration_ << endl;
115  writeProperties(stream);
116  writePorts(stream);
117  stream << endl;
118 }
119 
122 
123  return &properties_;
124 }
125 
128 
129  return &ports_;
130 }
131 
132 
133 void
134 SOPCInterface::writeProperties(std::ostream& stream) const {
135 
136  PropertyMap::const_iterator iter = properties_.begin();
137  while (iter != properties_.end()) {
138  stream
139  << SOPC_SET_INT_PROPERTY << " " << name_ << " " << iter->first
140  << " " << iter->second << endl;
141  iter++;
142  }
143 }
144 
145 
146 void
147 SOPCInterface::writePorts(std::ostream& stream) const {
148 
149  for (unsigned int i = 0; i < ports_.size(); i++) {
150  stream
151  << SOPC_ADD_INT_PORT << " " << name_ << " "
152  << ports_.at(i).hdlName << " " << ports_.at(i).interfaceName
153  << " ";
154  if (ports_.at(i).direction == ProGe::IN) {
155  stream << SOPC_INPUT << " ";
156  } else if (ports_.at(i).direction == ProGe::OUT) {
157  stream << SOPC_OUTPUT << " ";
158  } else if (ports_.at(i).direction == ProGe::BIDIR) {
159  stream << SOPC_BIDIR << " ";
160  } else {
161  assert(false && "Invalid port direction");
162  }
163  stream << ports_.at(i).width << endl;
164  }
165 }
SOPCInterface::properties
const PropertyMap * properties() const
Definition: SOPCInterface.cc:121
SOPCInterface::~SOPCInterface
virtual ~SOPCInterface()
Definition: SOPCInterface.cc:70
SOPCInterface::hasPorts
bool hasPorts() const
Definition: SOPCInterface.cc:104
SOPCInterface::setProperty
void setProperty(const TCEString &propertyName, const TCEString &propertyValue)
Definition: SOPCInterface.cc:73
SOPCInterface::SOPCPort
Definition: SOPCInterface.hh:91
SOPCInterface::SOPC_ADD_INT_PORT
static const TCEString SOPC_ADD_INT_PORT
Definition: SOPCInterface.hh:69
SOPCInterface::SOPC_ASSOCIATED_CLOCK
static const TCEString SOPC_ASSOCIATED_CLOCK
Definition: SOPCInterface.hh:70
SOPCInterface::PortList
std::vector< SOPCPort > PortList
Definition: SOPCInterface.hh:99
SOPCInterface::SOPC_CLOCK_INT_DECLR
static const TCEString SOPC_CLOCK_INT_DECLR
Definition: SOPCInterface.hh:76
SOPCInterface::SOPC_IRQ_RECV_INT_NAME
static const TCEString SOPC_IRQ_RECV_INT_NAME
Definition: SOPCInterface.hh:82
ProGe::BIDIR
@ BIDIR
Bidirectional port.
Definition: ProGeTypes.hh:55
SOPCInterface::declaration_
TCEString declaration_
Definition: SOPCInterface.hh:115
SOPCInterface.hh
SOPCInterface::writeInterface
virtual void writeInterface(std::ostream &stream) const
Definition: SOPCInterface.cc:110
Conversion::toString
static std::string toString(const T &source)
SOPCInterface::SOPC_ADD_INTERFACE
static const TCEString SOPC_ADD_INTERFACE
Definition: SOPCInterface.hh:67
assert
#define assert(condition)
Definition: Application.hh:86
SOPCInterface::SOPC_EXPORT_NAME
static const TCEString SOPC_EXPORT_NAME
Definition: SOPCInterface.hh:80
SOPCInterface::writePorts
void writePorts(std::ostream &stream) const
Definition: SOPCInterface.cc:147
Conversion.hh
SOPCInterface::setPort
void setPort(const TCEString &hdlName, const TCEString &interfaceName, ProGe::Direction direction, int width)
Definition: SOPCInterface.cc:90
SOPCInterface::SOPC_MASTER_INT_DECLR
static const TCEString SOPC_MASTER_INT_DECLR
Definition: SOPCInterface.hh:73
SOPCInterface::name
TCEString name() const
Definition: SOPCInterface.cc:98
SOPCInterface::ports
const PortList * ports() const
Definition: SOPCInterface.cc:127
SOPCInterface::SOPC_IRQ_RECV_INT_DECLR
static const TCEString SOPC_IRQ_RECV_INT_DECLR
Definition: SOPCInterface.hh:83
SOPCInterface::SOPC_BIDIR
static const TCEString SOPC_BIDIR
Definition: SOPCInterface.hh:87
SOPCInterface::SOPC_EXPORT_INT_NAME
static const TCEString SOPC_EXPORT_INT_NAME
Definition: SOPCInterface.hh:78
SOPCInterface::SOPC_SET_INT_PROPERTY
static const TCEString SOPC_SET_INT_PROPERTY
Definition: SOPCInterface.hh:68
SOPCInterface::SOPC_MASTER_INT_NAME
static const TCEString SOPC_MASTER_INT_NAME
Definition: SOPCInterface.hh:72
SOPCInterface::SOPCInterface
SOPCInterface()
ProGe::OUT
@ OUT
Output port.
Definition: ProGeTypes.hh:54
SOPCInterface::SOPC_OUTPUT
static const TCEString SOPC_OUTPUT
Definition: SOPCInterface.hh:86
SOPCInterface::ports_
PortList ports_
Definition: SOPCInterface.hh:117
SOPCInterface::SOPC_CLOCK_INT_NAME
static const TCEString SOPC_CLOCK_INT_NAME
Definition: SOPCInterface.hh:75
SOPCInterface::SOPC_EXPORT_INT_DECLR
static const TCEString SOPC_EXPORT_INT_DECLR
Definition: SOPCInterface.hh:79
TCEString
Definition: TCEString.hh:53
SOPCInterface::SOPC_INPUT
static const TCEString SOPC_INPUT
Definition: SOPCInterface.hh:85
SOPCInterface::PropertyMap
std::map< TCEString, TCEString > PropertyMap
Definition: SOPCInterface.hh:98
SOPCInterface::properties_
PropertyMap properties_
Definition: SOPCInterface.hh:116
SOPCInterface::name_
TCEString name_
Definition: SOPCInterface.hh:114
SOPCInterface::writeProperties
void writeProperties(std::ostream &stream) const
Definition: SOPCInterface.cc:134
ProGe::Direction
Direction
Direction of the port.
Definition: ProGeTypes.hh:52
ProGe::IN
@ IN
Input port.
Definition: ProGeTypes.hh:53