OpenCores
URL https://opencores.org/ocsvn/nocmodel/nocmodel/trunk

Subversion Repositories nocmodel

[/] [nocmodel/] [trunk/] [nocmodel/] [basicmodels/] [intercon_model.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dargor
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
#
5
# Intercon models
6
#  * Dual P2P Wishbone model
7
#  * Single Bus Wishbone model
8
#
9
# Author:  Oscar Diaz
10
# Version: 0.1
11
# Date:    11-03-2011
12
 
13
#
14
# This code is free software; you can redistribute it and/or
15
# modify it under the terms of the GNU Lesser General Public
16
# License as published by the Free Software Foundation; either
17
# version 2.1 of the License, or (at your option) any later version.
18
#
19
# This code is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22
# Lesser General Public License for more details.
23
#
24
# You should have received a copy of the GNU Lesser General Public
25
# License along with this library; if not, write to the
26
# Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
27
# Boston, MA  02111-1307  USA
28
#
29
 
30
#
31
# Changelog:
32
#
33
# 11-03-2011 : (OD) initial release
34
#
35
 
36
"""
37
Basic Wishbone intercon models
38
"""
39
 
40
from nocmodel import *
41
 
42
class dualwb_intercon(intercon):
43
    """
44
    Wishbone dual P2P intercon model
45
 
46
    This intercon defines two bidirectional Wishbone P2P ports.
47
    """
48
    intercon_type = "dualwb"
49
    complement = None
50
    sideinfo = ""
51
 
52
    def __init__(self, **kwargs):
53
        intercon.__init__(self, **kwargs)
54
 
55
        # attributes: data_width (default 32 bits)
56
        if not hasattr(self, "data_width"):
57
            setattr(self, "data_width", 32)
58
        # addr_width (default 0, don't use address signal)
59
        if not hasattr(self, "addr_width"):
60
            setattr(self, "addr_width", 0)
61
 
62
        self.intercon_type = "dualwb"
63
#        self.complement = None
64
#        self.sideinfo = ""
65
 
66
        # build the intercon structure
67
        # Common signals
68
        #self.signals["rst_i"]
69
        #self.signals["clk_i"]
70
        # Master part
71
        # discard m_dat_i, m_we_o, m_sel_o, m_rty_i, m_lock_o
72
        # optional m_adr_o
73
        self.signals["m_dat_o"] = {"width": self.data_width, "direction": "out", "signal_obj": None, "description": "Master data output"}
74
        if self.addr_width > 0:
75
            self.signals["m_adr_o"] = {"width": self.addr_width, "direction": "out", "signal_obj": None, "description": "Master address output"}
76
        self.signals["m_stb_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master strobe"}
77
        self.signals["m_cyc_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master cycle"}
78
        self.signals["m_lflit_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master last flit flag"}
79
        self.signals["m_ack_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master acknowledge"}
80
        self.signals["m_stall_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master stall"}
81
        self.signals["m_err_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master error"}
82
        # Slave part
83
        # discard s_adr_i, s_dat_o, s_we_i, s_sel_i, s_rty_o, s_lock_i
84
        self.signals["s_dat_i"] = {"width": self.data_width, "direction": "in", "signal_obj": None, "description": "Slave data input"}
85
        if self.addr_width > 0:
86
            self.signals["s_adr_i"] = {"width": self.addr_width, "direction": "in", "signal_obj": None, "description": "Slave address input"}
87
        self.signals["s_stb_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave strobe"}
88
        self.signals["s_cyc_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave cycle"}
89
        self.signals["s_lflit_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave last flit flag"}
90
        self.signals["s_ack_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave acknowledge"}
91
        self.signals["s_stall_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave stall"}
92
        self.signals["s_err_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave error"}
93
 
94
    def get_complement_signal(self, signalname):
95
        """
96
        Get the signal name that should be connected to this signal when
97
        connecting two intercon.
98
 
99
        Arguments:
100
        * signalname: signal name of this intercon
101
 
102
        Return: a string with the name of a signal from a complementary intercon.
103
        """
104
        if signalname not in self.signals:
105
            raise KeyError("Signal '%s' not found" % signalname)
106
        mchange = {"m": "s", "s": "m"}
107
        dchange = {"i": "o", "o": "i"}
108
        return mchange[signalname[0]] + signalname[1:-1] + dchange[signalname[-1]]
109
 
110
class slavewb_intercon():
111
    pass
112
 
113
class masterwb_intercon(intercon):
114
    """
115
    Wishbone single bus master intercon model
116
 
117
    This intercon defines a simple master Wishbone bus.
118
    """
119
    intercon_type = "masterwb"
120
    complement = slavewb_intercon
121
    sideinfo = "master"
122
 
123
    def __init__(self, **kwargs):
124
        intercon.__init__(self, **kwargs)
125
 
126
        # attributes: data_width (default 32 bits)
127
        if not hasattr(self, "data_width"):
128
            setattr(self, "data_width", 32)
129
        # addr_width (default 16 bits)
130
        if not hasattr(self, "addr_width"):
131
            setattr(self, "addr_width", 16)
132
 
133
        self.intercon_type = "masterwb"
134
#        self.complement = slavewb_intercon
135
#        self.sideinfo = "master"
136
 
137
        # build the intercon structure
138
        self.signals["rst_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Reset input"}
139
        self.signals["clk_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Clock input"}
140
 
141
        # discard m_sel_o, m_rty_i, m_lock_o
142
        self.signals["m_adr_o"] = {"width": self.addr_width, "direction": "out", "signal_obj": None, "description": "Master address output"}
143
        self.signals["m_dat_i"] = {"width": self.data_width, "direction": "in", "signal_obj": None, "description": "Master data input"}
144
        self.signals["m_dat_o"] = {"width": self.data_width, "direction": "out", "signal_obj": None, "description": "Master data output"}
145
        self.signals["m_we_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master write enable"}
146
        self.signals["m_stb_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master strobe"}
147
        self.signals["m_cyc_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Master cycle"}
148
        self.signals["m_ack_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master acknowledge"}
149
        self.signals["m_stall_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master stall"}
150
        self.signals["m_err_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master error"}
151
        self.signals["m_irq_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Master IRQ"}
152
 
153
    def get_complement_signal(self, signalname):
154
        """
155
        Get the signal name that should be connected to this signal when
156
        connecting two intercon.
157
 
158
        Arguments:
159
        * signalname: signal name of this intercon
160
 
161
        Return: a string with the name of a signal from a complementary intercon.
162
        """
163
        if signalname not in self.signals:
164
            raise KeyError("Signal '%s' not found" % signalname)
165
        mchange = {"m": "s", "s": "m"}
166
        dchange = {"i": "o", "o": "i"}
167
        if signalname == "rst_i" or signalname == "clk_i":
168
            # special signals. Return None
169
            return None
170
        else:
171
            return mchange[signalname[0]] + signalname[1:-1] + dchange[signalname[-1]]
172
 
173
class slavewb_intercon(intercon):
174
    """
175
    Wishbone single bus slave intercon model
176
 
177
    This intercon defines a simple slave Wishbone bus.
178
    """
179
    intercon_type = "slavewb"
180
    complement = masterwb_intercon
181
    sideinfo = "slave"
182
 
183
    def __init__(self, **kwargs):
184
        intercon.__init__(self, **kwargs)
185
 
186
        # attributes: data_width (default 32 bits)
187
        if not hasattr(self, "data_width"):
188
            setattr(self, "data_width", 32)
189
        # addr_width (default 16 bits)
190
        if not hasattr(self, "addr_width"):
191
            setattr(self, "addr_width", 16)
192
 
193
        self.intercon_type = "slavewb"
194
#        self.complement = masterwb_intercon
195
#        self.sideinfo = "slave"
196
 
197
        # build the intercon structure
198
        self.signals["rst_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Reset input"}
199
        self.signals["clk_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Clock input"}
200
 
201
        # discard s_sel_o, s_rty_i, s_lock_o
202
        self.signals["s_adr_i"] = {"width": self.addr_width, "direction": "in", "signal_obj": None, "description": "Slave address output"}
203
        self.signals["s_dat_o"] = {"width": self.data_width, "direction": "out", "signal_obj": None, "description": "Slave data input"}
204
        self.signals["s_dat_i"] = {"width": self.data_width, "direction": "in", "signal_obj": None, "description": "Slave data output"}
205
        self.signals["s_we_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave write enable"}
206
        self.signals["s_stb_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave strobe"}
207
        self.signals["s_cyc_i"] = {"width": 1, "direction": "in", "signal_obj": None, "description": "Slave cycle"}
208
        self.signals["s_ack_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave acknowledge"}
209
        self.signals["s_stall_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave stall"}
210
        self.signals["s_err_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave error"}
211
        self.signals["s_irq_o"] = {"width": 1, "direction": "out", "signal_obj": None, "description": "Slave IRQ"}
212
 
213
    def get_complement_signal(self, signalname):
214
        """
215
        Get the signal name that should be connected to this signal when
216
        connecting two intercon.
217
 
218
        Arguments:
219
        * signalname: signal name of this intercon
220
 
221
        Return: a string with the name of a signal from a complementary intercon.
222
        """
223
        if signalname not in self.signals:
224
            raise KeyError("Signal '%s' not found" % signalname)
225
        mchange = {"m": "s", "s": "m"}
226
        dchange = {"i": "o", "o": "i"}
227
        if signalname == "rst_i" or signalname == "clk_i":
228
            # special signals. Return None
229
            return None
230
        else:
231
            return mchange[signalname[0]] + signalname[1:-1] + dchange[signalname[-1]]

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.