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

Subversion Repositories rs232_with_buffer_and_wb

[/] [rs232_with_buffer_and_wb/] [trunk/] [bench/] [wb_pack.vhd] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 TobiasJ
--
2
--
3
--  This file is a part of JOP, the Java Optimized Processor
4
--
5
--  Copyright (C) 2001-2008, Martin Schoeberl (martin@jopdesign.com)
6
--
7
--  This program is free software: you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation, either version 3 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
 
21
 
22
--
23
--
24
--      Package for Wishbone defines and testbench procedures
25
--
26
--      31012013 - TNJ - Adopted the package for testing the WB interface
27
--      31012013 - TNJ - Added wb_naive_connect to make interface easier
28
--      
29
--
30
 
31
library std;
32
use std.textio.all;
33
 
34
library ieee;
35
use ieee.std_logic_1164.all;
36
use ieee.numeric_std.all;
37
 
38
package wb_pack is
39
 
40
        constant TIMEOUT : integer := 10;
41
        constant M_DATA_SIZE : integer := 8;
42
        constant M_ADDR_SIZE : integer := 8;
43
        constant S_DATA_SIZE : integer := 8;
44
        constant S_ADDR_SIZE : integer := 8;
45
 
46
--
47
--      type definitions for the memory WISHBONE interface
48
--
49
 
50
        -- 21 bits as example for the SRAM/Flash/NAND interface
51
        constant MEM_ADDR_SIZE : integer := 21;
52
 
53
        type wb_mem_out_type is record
54
                dat : std_logic_vector(31 downto 0);
55
                adr : std_logic_vector(MEM_ADDR_SIZE-1 downto 0);
56
                we  : std_logic;
57
                cyc : std_logic;
58
                sel : std_logic_vector(3 downto 0);
59
                stb : std_logic;
60
        end record;
61
        type wb_mem_in_type is record
62
                dat : std_logic_vector(31 downto 0);
63
                ack : std_logic;
64
        end record;
65
 
66
--
67
--      type definitions for the IO WISHBONE interface
68
--
69
 
70
        type wb_slave_in_type is record
71
                dat_i : std_logic_vector(S_DATA_SIZE-1 downto 0);
72
                adr_i : std_logic_vector(S_ADDR_SIZE-1 downto 0);
73
                we_i  : std_logic;
74
                cyc_i : std_logic;
75
                stb_i : std_logic;
76
        end record;
77
        type wb_slave_out_type is record
78
                dat_o : std_logic_vector(S_DATA_SIZE-1 downto 0);
79
                ack_o : std_logic;
80
        end record;
81
 
82
        type wb_master_out_type is record
83
                dat_o : std_logic_vector(M_DATA_SIZE-1 downto 0);
84
                adr_o : std_logic_vector(M_ADDR_SIZE-1 downto 0);
85
                we_o  : std_logic;
86
                cyc_o : std_logic;
87
                stb_o : std_logic;
88
        end record;
89
        type wb_master_in_type is record
90
                dat_i : std_logic_vector(M_DATA_SIZE-1 downto 0);
91
                ack_i : std_logic;
92
        end record;
93
 
94
        procedure wb_connect(
95
                signal m_in     : out wb_master_in_type;
96
                signal m_out : in wb_master_out_type;
97
                signal s_in     : out wb_slave_in_type;
98
                signal s_out : in wb_slave_out_type);
99 49 TobiasJ
 
100
        procedure wb_reset(
101
                signal clk              : in    std_logic;
102
                signal m_out    : out   wb_master_out_type);
103 48 TobiasJ
 
104
        procedure wb_naive_connect(
105 49 TobiasJ
                signal s_cyc_i  : out   std_logic;
106
                signal s_stb_i  : out   std_logic;
107
                signal s_ack_o  : in    std_logic;
108
                signal s_we_i   : out   std_logic;
109
                signal s_adr_i  : out   std_logic_vector(S_ADDR_SIZE-1 downto 0);
110
                signal s_dat_i  : out   std_logic_vector(S_DATA_SIZE-1 downto 0);
111
                signal s_dat_o  : in    std_logic_vector(S_DATA_SIZE-1 downto 0);
112
                signal m_in             : out   wb_master_in_type;
113
                signal m_out    : in    wb_master_out_type);
114 48 TobiasJ
 
115
        procedure wb_write(
116
                signal clk : in std_logic;
117
                constant addr : in natural;
118
                constant data : in natural;
119
                signal wb_in    : in wb_master_in_type;
120
                signal wb_out : out wb_master_out_type);
121
 
122
        procedure wb_read(
123
                signal clk : in std_logic;
124
                constant addr : in natural;
125
                variable data : out natural;
126
                signal wb_in    : in wb_master_in_type;
127
                signal wb_out : out wb_master_out_type);
128 49 TobiasJ
 
129
        procedure wb_confirme_write(
130
                signal clk              : in    std_logic;
131
                constant addr   : in    natural;
132
                constant data   : in    natural;
133
                signal wb_in    : in    wb_master_in_type;
134
                signal wb_out   : out   wb_master_out_type);
135 48 TobiasJ
 
136
end wb_pack;
137
 
138
package body wb_pack is
139
 
140
        procedure wb_connect(
141
                signal m_in     : out wb_master_in_type;
142
                signal m_out : in wb_master_out_type;
143
                signal s_in     : out wb_slave_in_type;
144
                signal s_out : in wb_slave_out_type) is
145
 
146
        begin
147
 
148 49 TobiasJ
                s_in.dat_i <= m_out.dat_o(S_DATA_SIZE-1 downto 0);
149 48 TobiasJ
                s_in.we_i <= m_out.we_o;
150
                s_in.adr_i <= m_out.adr_o(S_ADDR_SIZE-1 downto 0);
151
                s_in.cyc_i <= m_out.cyc_o;
152
                s_in.stb_i <= m_out.stb_o;
153
 
154
                m_in.dat_i <= s_out.dat_o;
155
                m_in.ack_i <= s_out.ack_o;
156
 
157
        end;
158 49 TobiasJ
 
159
        procedure wb_reset(
160
                signal clk              : in std_logic;
161
                signal m_out    : out wb_master_out_type) is
162
        begin
163
                wait until rising_edge(clk);
164
                m_out.dat_o <= (others => '0');
165
                m_out.adr_o     <= (others => '0');
166
                m_out.we_o      <= '0';
167
                m_out.cyc_o     <= '0';
168
                m_out.stb_o     <= '0';
169
        end;
170
 
171
        procedure wb_naive_connect(
172
                signal s_cyc_i  : out   std_logic;
173
                signal s_stb_i  : out   std_logic;
174
                signal s_ack_o  : in    std_logic;
175
                signal s_we_i   : out   std_logic;
176
                signal s_adr_i  : out   std_logic_vector(S_ADDR_SIZE-1 downto 0);
177
                signal s_dat_i  : out   std_logic_vector(S_DATA_SIZE-1 downto 0);
178
                signal s_dat_o  : in    std_logic_vector(S_DATA_SIZE-1 downto 0);
179
                signal m_in             : out   wb_master_in_type;
180
                signal m_out    : in    wb_master_out_type) is
181
 
182
        begin
183
 
184
                s_cyc_i         <= m_out.cyc_o;
185
                s_stb_i         <= m_out.stb_o;
186
                s_we_i          <= m_out.we_o;
187
                s_adr_i         <= m_out.adr_o;
188
                s_dat_i         <= m_out.dat_o;
189
 
190
                m_in.dat_i      <= s_dat_o;
191
                m_in.ack_i      <= s_ack_o;
192
 
193
        end;
194
 
195 48 TobiasJ
 
196
        procedure wb_write(
197
                signal clk : in std_logic;
198
                constant addr : in natural;
199
                constant data : in natural;
200
                signal wb_in    : in wb_master_in_type;
201
                signal wb_out : out wb_master_out_type) is
202
 
203
                variable txt : line;
204
 
205
        begin
206
 
207
                -- start cycle on positive edge
208
                wait until rising_edge(clk);
209
                write(txt, now, right, 8);
210
                write(txt, string'(" wrote "));
211
                write(txt, data);
212
                write(txt, string'(" to addr. "));
213
                write(txt, addr);
214
 
215
                wb_out.dat_o <= std_logic_vector(to_unsigned(data, wb_out.dat_o'length));
216
                wb_out.adr_o <= std_logic_vector(to_unsigned(addr, wb_out.adr_o'length));
217
 
218
                wb_out.we_o <= '1';
219
                wb_out.cyc_o <= '1';
220
                wb_out.stb_o <= '1';
221
 
222
                -- wait for acknowledge
223
                wait until rising_edge(clk);
224
                if wb_in.ack_i /= '1' then
225
                        for i in 1 to TIMEOUT loop
226
                                wait until rising_edge(clk);
227
                                exit when wb_in.ack_i = '1';
228
                                if (i = TIMEOUT) then
229
                                        write (txt, string'("No acknowledge recevied!"));
230
                                end if;
231
                        end loop;
232
                end if;
233
 
234
                wb_out.dat_o <= (others => '0');
235
                wb_out.adr_o <= (others => '0');
236
                wb_out.we_o <= '0';
237
                wb_out.cyc_o <= '0';
238
                wb_out.stb_o <= '0';
239
 
240
                writeline(output, txt);
241
 
242
        end;
243
 
244
        procedure wb_read(
245
                signal clk : in std_logic;
246
                constant addr : in natural;
247
                variable data : out natural;
248
                signal wb_in    : in wb_master_in_type;
249
                signal wb_out : out wb_master_out_type) is
250
 
251
                variable txt : line;
252
                variable in_data : natural;
253
 
254
        begin
255
 
256
                -- start cycle on positive edge
257
                wait until rising_edge(clk);
258
                write(txt, now, right, 8);
259
                write(txt, string'(" read from addr. "));
260
                write(txt, addr);
261
                writeline(output, txt);
262
 
263
                wb_out.adr_o <= std_logic_vector(to_unsigned(addr, wb_out.adr_o'length));
264
                wb_out.dat_o <= (others => '0');
265
 
266
                wb_out.we_o <= '0';
267
                wb_out.cyc_o <= '1';
268
                wb_out.stb_o <= '1';
269
 
270
                -- wait for acknowledge
271
                wait until rising_edge(clk);
272
                if wb_in.ack_i /= '1' then
273
                        for i in 1 to TIMEOUT loop
274
                                wait until rising_edge(clk);
275
                                exit when wb_in.ack_i = '1';
276
                                if (i = TIMEOUT) then
277
                                        write (txt, string'("No acknowledge recevied!"));
278
                                end if;
279
                        end loop;
280
                end if;
281
 
282
                in_data := to_integer(unsigned(wb_in.dat_i));
283
                data := in_data;
284
 
285
                wb_out.adr_o <= (others => '0');
286
                wb_out.we_o <= '0';
287
                wb_out.cyc_o <= '0';
288
                wb_out.stb_o <= '0';
289
 
290
                write(txt, now, right, 8);
291
                write(txt, string'(" value: "));
292
                write(txt, in_data);
293
 
294
                writeline(output, txt);
295
 
296
        end;
297 49 TobiasJ
 
298
        procedure wb_confirme_write(
299
                signal clk              : in    std_logic;
300
                constant addr   : in    natural;
301
                constant data   : in    natural;
302
                signal wb_in    : in    wb_master_in_type;
303
                signal wb_out   : out   wb_master_out_type) is
304
 
305
                variable wb_data_read : natural;
306
        begin
307
 
308
                wb_write(clk, addr, data, wb_in, wb_out);
309
 
310
                wb_read(clk, addr, wb_data_read, wb_in, wb_out);
311
 
312
                assert wb_data_read = data
313
                        report "not the same written as read"
314
                                severity error;
315
 
316
        end;
317 48 TobiasJ
 
318
 
319
end wb_pack;

powered by: WebSVN 2.1.0

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