OpenASIP 2.2
Loading...
Searching...
No Matches
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"
36using std::vector;
37using std::map;
38using std::endl;
39
41 "add_interface";
43 "set_interface_property";
45 "add_interface_port";
47 "ASSOCIATED_CLOCK";
48
51
52const TCEString SOPCInterface::SOPC_EXPORT_INT_NAME = "conduit_interface";
55
58
61
65
67 name_(name), declaration_(declaration) {
68}
69
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
89void
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
103bool
105
106 return !ports_.empty();
107}
108
109void
110SOPCInterface::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
133void
134SOPCInterface::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
146void
147SOPCInterface::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}
#define assert(condition)
static std::string toString(const T &source)
static const TCEString SOPC_IRQ_RECV_INT_DECLR
std::vector< SOPCPort > PortList
static const TCEString SOPC_OUTPUT
static const TCEString SOPC_INPUT
void writeProperties(std::ostream &stream) const
static const TCEString SOPC_CLOCK_INT_NAME
std::map< TCEString, TCEString > PropertyMap
TCEString name() const
static const TCEString SOPC_BIDIR
static const TCEString SOPC_ADD_INTERFACE
static const TCEString SOPC_EXPORT_INT_NAME
static const TCEString SOPC_IRQ_RECV_INT_NAME
const PortList * ports() const
static const TCEString SOPC_EXPORT_INT_DECLR
static const TCEString SOPC_MASTER_INT_NAME
void setPort(const TCEString &hdlName, const TCEString &interfaceName, ProGe::Direction direction, int width)
static const TCEString SOPC_MASTER_INT_DECLR
PropertyMap properties_
static const TCEString SOPC_ASSOCIATED_CLOCK
virtual void writeInterface(std::ostream &stream) const
void writePorts(std::ostream &stream) const
void setProperty(const TCEString &propertyName, const TCEString &propertyValue)
static const TCEString SOPC_SET_INT_PROPERTY
TCEString declaration_
bool hasPorts() const
static const TCEString SOPC_ADD_INT_PORT
const PropertyMap * properties() const
static const TCEString SOPC_EXPORT_NAME
virtual ~SOPCInterface()
static const TCEString SOPC_CLOCK_INT_DECLR
Direction
Direction of the port.
Definition ProGeTypes.hh:52
@ OUT
Output port.
Definition ProGeTypes.hh:54
@ IN
Input port.
Definition ProGeTypes.hh:53
@ BIDIR
Bidirectional port.
Definition ProGeTypes.hh:55