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

Subversion Repositories simpcon

[/] [simpcon/] [trunk/] [vhdl/] [wb_pack.vhd] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 martin
--
2
--
3
--      Package for Wishbone defines and testbench procedures
4
--
5
 
6
library std;
7
use std.textio.all;
8
 
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
 
13
package wb_pack is
14
 
15
        constant TIMEOUT : integer := 10;
16
        constant M_ADDR_SIZE : integer := 8;
17
        constant S_ADDR_SIZE : integer := 4;
18
 
19
 
20
--
21
--      type definitions for the memory WISHBONE interface
22
--
23
 
24
        -- 21 bits as example for the SRAM/Flash/NAND interface
25
        constant MEM_ADDR_SIZE : integer := 21;
26
 
27
        type wb_mem_out_type is record
28
                dat : std_logic_vector(31 downto 0);
29
                adr : std_logic_vector(MEM_ADDR_SIZE-1 downto 0);
30
                we  : std_logic;
31
                cyc : std_logic;
32
                sel : std_logic_vector(3 downto 0);
33
                stb : std_logic;
34
        end record;
35
        type wb_mem_in_type is record
36
                dat : std_logic_vector(31 downto 0);
37
                ack : std_logic;
38
        end record;
39
 
40
--
41
--      type definitions for the IO WISHBONE interface
42
--
43
 
44
        type wb_slave_in_type is record
45
                dat_i : std_logic_vector(31 downto 0);
46
                adr_i : std_logic_vector(S_ADDR_SIZE-1 downto 0);
47
                we_i  : std_logic;
48
                cyc_i : std_logic;
49
                stb_i : std_logic;
50
        end record;
51
        type wb_slave_out_type is record
52
                dat_o : std_logic_vector(31 downto 0);
53
                ack_o : std_logic;
54
        end record;
55
 
56
        type wb_master_out_type is record
57
                dat_o : std_logic_vector(31 downto 0);
58
                adr_o : std_logic_vector(M_ADDR_SIZE-1 downto 0);
59
                we_o  : std_logic;
60
                cyc_o : std_logic;
61
                stb_o : std_logic;
62
        end record;
63
        type wb_master_in_type is record
64
                dat_i : std_logic_vector(31 downto 0);
65
                ack_i : std_logic;
66
        end record;
67
 
68
        procedure wb_connect(
69
                signal m_in     : out wb_master_in_type;
70
                signal m_out : in wb_master_out_type;
71
                signal s_in     : out wb_slave_in_type;
72
                signal s_out : in wb_slave_out_type);
73
 
74
        procedure wb_write(
75
                signal clk : in std_logic;
76
                constant addr : in natural;
77
                constant data : in natural;
78
                signal wb_in    : in wb_master_in_type;
79
                signal wb_out : out wb_master_out_type);
80
 
81
        procedure wb_read(
82
                signal clk : in std_logic;
83
                constant addr : in natural;
84
                variable data : out natural;
85
                signal wb_in    : in wb_master_in_type;
86
                signal wb_out : out wb_master_out_type);
87
 
88
end wb_pack;
89
 
90
package body wb_pack is
91
 
92
        procedure wb_connect(
93
                signal m_in     : out wb_master_in_type;
94
                signal m_out : in wb_master_out_type;
95
                signal s_in     : out wb_slave_in_type;
96
                signal s_out : in wb_slave_out_type) is
97
 
98
        begin
99
 
100
                s_in.dat_i <= m_out.dat_o;
101
                s_in.we_i <= m_out.we_o;
102
                s_in.adr_i <= m_out.adr_o(S_ADDR_SIZE-1 downto 0);
103
                s_in.cyc_i <= m_out.cyc_o;
104
                s_in.stb_i <= m_out.stb_o;
105
 
106
                m_in.dat_i <= s_out.dat_o;
107
                m_in.ack_i <= s_out.ack_o;
108
 
109
        end;
110
 
111
        procedure wb_write(
112
                signal clk : in std_logic;
113
                constant addr : in natural;
114
                constant data : in natural;
115
                signal wb_in    : in wb_master_in_type;
116
                signal wb_out : out wb_master_out_type) is
117
 
118
                variable txt : line;
119
 
120
        begin
121
 
122
                -- start cycle on positive edge
123
                wait until rising_edge(clk);
124
                write(txt, now, right, 8);
125
                write(txt, string'(" wrote "));
126
                write(txt, data);
127
                write(txt, string'(" to addr. "));
128
                write(txt, addr);
129
 
130
                wb_out.dat_o <= std_logic_vector(to_unsigned(data, wb_out.dat_o'length));
131
                wb_out.adr_o <= std_logic_vector(to_unsigned(addr, wb_out.adr_o'length));
132
 
133
                wb_out.we_o <= '1';
134
                wb_out.cyc_o <= '1';
135
                wb_out.stb_o <= '1';
136
 
137
                -- wait for acknowledge
138
                wait until rising_edge(clk);
139
                if wb_in.ack_i /= '1' then
140
                        for i in 1 to TIMEOUT loop
141
                                wait until rising_edge(clk);
142
                                exit when wb_in.ack_i = '1';
143
                                if (i = TIMEOUT) then
144
                                        write (txt, string'("No acknowledge recevied!"));
145
                                end if;
146
                        end loop;
147
                end if;
148
 
149
                wb_out.dat_o <= (others => '0');
150
                wb_out.adr_o <= (others => '0');
151
                wb_out.we_o <= '0';
152
                wb_out.cyc_o <= '0';
153
                wb_out.stb_o <= '0';
154
 
155
                writeline(output, txt);
156
 
157
        end;
158
 
159
        procedure wb_read(
160
                signal clk : in std_logic;
161
                constant addr : in natural;
162
                variable data : out natural;
163
                signal wb_in    : in wb_master_in_type;
164
                signal wb_out : out wb_master_out_type) is
165
 
166
                variable txt : line;
167
                variable in_data : natural;
168
 
169
        begin
170
 
171
                -- start cycle on positive edge
172
                wait until rising_edge(clk);
173
                write(txt, now, right, 8);
174
                write(txt, string'(" read from addr. "));
175
                write(txt, addr);
176
                writeline(output, txt);
177
 
178
                wb_out.adr_o <= std_logic_vector(to_unsigned(addr, wb_out.adr_o'length));
179
                wb_out.dat_o <= (others => '0');
180
 
181
                wb_out.we_o <= '0';
182
                wb_out.cyc_o <= '1';
183
                wb_out.stb_o <= '1';
184
 
185
                -- wait for acknowledge
186
                wait until rising_edge(clk);
187
                if wb_in.ack_i /= '1' then
188
                        for i in 1 to TIMEOUT loop
189
                                wait until rising_edge(clk);
190
                                exit when wb_in.ack_i = '1';
191
                                if (i = TIMEOUT) then
192
                                        write (txt, string'("No acknowledge recevied!"));
193
                                end if;
194
                        end loop;
195
                end if;
196
 
197
                in_data := to_integer(unsigned(wb_in.dat_i));
198
                data := in_data;
199
 
200
                wb_out.adr_o <= (others => '0');
201
                wb_out.we_o <= '0';
202
                wb_out.cyc_o <= '0';
203
                wb_out.stb_o <= '0';
204
 
205
                write(txt, now, right, 8);
206
                write(txt, string'(" value: "));
207
                write(txt, in_data);
208
 
209
                writeline(output, txt);
210
 
211
        end;
212
 
213
 
214
end wb_pack;

powered by: WebSVN 2.1.0

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