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

Subversion Repositories wb2axip

[/] [wb2axip/] [trunk/] [bench/] [cpp/] [aximemsim.cpp] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    aximemsim.cpp
4
//
5
// Project:     Pipelined Wishbone to AXI converter
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14 16 dgisselq
// Copyright (C) 2016-2018, Gisselquist Technology, LLC
15 8 dgisselq
//
16 16 dgisselq
// This file is part of the pipelined Wishbone to AXI converter project, a
17
// project that contains multiple bus bridging designs and formal bus property
18
// sets.
19 8 dgisselq
//
20 16 dgisselq
// The bus bridge designs and property sets are free RTL designs: you can
21
// redistribute them and/or modify any of them under the terms of the GNU
22
// Lesser General Public License as published by the Free Software Foundation,
23
// either version 3 of the License, or (at your option) any later version.
24 8 dgisselq
//
25 16 dgisselq
// The bus bridge designs and property sets are distributed in the hope that
26
// they will be useful, but WITHOUT ANY WARRANTY; without even the implied
27
// warranty of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
// GNU Lesser General Public License for more details.
29
//
30
// You should have received a copy of the GNU Lesser General Public License
31
// along with these designs.  (It's in the $(ROOT)/doc directory.  Run make
32
// with no target there if the PDF file isn't present.)  If not, see
33 8 dgisselq
// <http://www.gnu.org/licenses/> for a copy.
34
//
35 16 dgisselq
// License:     LGPL, v3, as defined and found on www.gnu.org,
36
//              http://www.gnu.org/licenses/lgpl.html
37 8 dgisselq
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
#include <stdio.h>
42
 
43
#include "aximemsim.h"
44
 
45
class   ADRFIFO {
46
        typedef {
47
                int id; unsigned addr;
48
        } ADRFIFOELEMENT;
49
        int     m_head, m_tail, m_len;
50
        int     *m_mem;
51
public:
52
        ADRFIFO(int ln) {
53
                m_mem = new ADRFIFOELEMENT[ln];
54
                m_head = m_tail = 0;
55
                m_len = ln;
56
        }
57
 
58
        void    push(int id, unsigned addr) {
59
                int nhead = m_head + 1;
60
                if (nhead >= m_len)
61
                        nhead = 0;
62
                assert(nhead != m_tail);
63
                m_mem[m_head].id   = id;
64
                m_mem[m_head].addr = addr;
65
                m_head = nhead;
66
        }
67
 
68
        bool    full(void) {
69
                int nhead = m_head + 1;
70
                if (nhead >= m_len)
71
                        nhead = 0;
72
                return (nhead == m_tail);
73
        }
74
 
75
        bool    valid(void) {
76
                return (m_head != m_tail);
77
        }
78
 
79
        int     id(void)        { return m_mem[m_tail].id; }
80
        int     addr(void)      { return m_mem[m_tail].addr; }
81
        int     pop(void)       {
82
                if (m_tail == m_head)
83
                        return;
84
                m_tail++;
85
                if (m_tail >= m_len)
86
                        m_tail = 0;
87
        }
88
};
89
 
90
class   DATFIFO {
91
        typedef {
92
                unsigned data[4];
93
                int     strb;
94
        } DATAFIFOELEMENT;
95
        int     m_head, m_tail, m_len;
96
        int     *m_mem;
97
public:
98
        DATAFIFO(int ln) {
99
                m_mem = new DATAFIFOELEMENT[ln];
100
                m_head = m_tail = 0;
101
                m_len = ln;
102
        }
103
 
104
        void    push(int strb, unsigned dat0, unsigned dat1,
105
                        unsigned dat, unsigned dat3) {
106
                int nhead = m_head + 1;
107
                if (nhead >= m_len)
108
                        nhead = 0;
109
                assert(nhead != m_tail);
110
                m_mem[m_head].strb   = id;
111
                m_mem[m_head].data[0] = dat0;
112
                m_mem[m_head].data[1] = dat1;
113
                m_mem[m_head].data[2] = dat2;
114
                m_mem[m_head].data[3] = dat3;
115
                m_head = nhead;
116
        }
117
 
118
        bool    full(void) {
119
                int nhead = m_head + 1;
120
                if (nhead >= m_len)
121
                        nhead = 0;
122
                return (nhead == m_tail);
123
        }
124
 
125
        bool    valid(void) {
126
                return (m_head != m_tail);
127
        }
128
 
129
        int     strb(void)      { return m_mem[m_tail].strb; }
130
        unsigned *data(void)    { return &m_mem[m_tail].data[0]; }
131
        int     pop(void)       {
132
                if (m_tail == m_head)
133
                        return;
134
                m_tail++;
135
                if (m_tail >= m_len)
136
                        m_tail = 0;
137
        }
138
};
139
 
140
AXIMEMSIM::AXIMEMSIM(unsigned abits) {
141
        // abits is the number of bits in a memory address, referencing 8-bit
142
        // bytes, therefore we can size our memory properly.
143
        assert(abits>2);
144
        m_len = (1<<(abits-2));
145
        m_mask= m_len-1;
146
        m_mem = new unsigned[(1<<(abits-2))];
147
 
148
        memset(m_mem, 0, sizeof(unsigned)<<(abits-2));
149
}
150
 
151
void AXIMEMSIM::apply(AXIBUS &bus) {
152
        // First, let's validate our inputs ..., and queue up our outputs
153
        bus.ar.ready = (!m_readfifo.full());
154
        bus.aw.ready = (!m_writefifo.full());
155
        bus.w.ready  = (!m_wdata.full());
156
        if (bus.r.ready)
157
                bus.r.valid = false;
158
        if (bus.b.ready)
159
                bus.b.valid = false;
160
 
161
        if ((bus.ar.ready)&&(!m_readfifo.full())) {
162
                assert(bus.ar.len  == 0);
163
                assert(bus.ar.size  == 5);
164
                assert(bus.ar.burst == 1);
165
                assert(bus.ar.lock  == 0);
166
                assert(bus.ar.cache == 2);
167
                assert(bus.ar.prot  == 2);
168
                assert(bus.ar.qos   == 0);
169
 
170
                m_readfifo.push(bus.ar.id, bus.ar.addr);
171
        }
172
 
173
        if ((bus.aw.ready)&&(!m_writefifo.full())) {
174
                assert(bus.aw.len   == 0);
175
                assert(bus.aw.size  == 5);
176
                assert(bus.aw.burst == 1);
177
                assert(bus.aw.lock  == 0);
178
                assert(bus.aw.cache == 2);
179
                assert(bus.aw.prot  == 2);
180
                assert(bus.aw.qos   == 0);
181
 
182
                m_awfifo.push(bus.aw.id, bus.aw.addr);
183
        }
184
 
185
        if ((bus.w.ready)&&(!m_writedata.full())) {
186
                m_writefifo.push(bus.aw.strb, bus.aw.data[0], bus.aw.data[1],
187
                        bus.aw.data[2], bus.aw.data[3]);
188
 
189
        if (m_respfifo[m_now].valid) {
190
                if (m_respfifo[m_now].read) {
191
                        if ((!bus.r.valid)||(bus.r.ready)) {
192
                                bus.r.data[0] = m_respfifo[m_now].data[0];
193
                                bus.r.data[1] = m_respfifo[m_now].data[1];
194
                                bus.r.data[2] = m_respfifo[m_now].data[2];
195
                                bus.r.data[3] = m_respfifo[m_now].data[3];
196
                                bus.r.valid = true;
197
                                m_now++;
198
                        }
199
                } else if ((!bus.b.valid)||(bus.b.ready)) {
200
                        bus.b.resp = m_respfifo[m_now].resp;
201
                        bus.b.id = m_respfifo[m_now].id;
202
                        bus.b.valid = true;
203
                        m_now++;
204
                }
205
        }
206
}
207
 

powered by: WebSVN 2.1.0

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