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

Subversion Repositories wb_tk

[/] [wb_tk/] [trunk/] [wb_async_slave.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 tantos
--
2
--  Wishbone bus toolkit.
3
--
4
--  (c) Copyright Andras Tantos <andras_tantos@yahoo.com> 2001/03/31
5
--  This code is distributed under the terms and conditions of the GNU General Public Lince.
6
--
7
--
8
-- ELEMENTS:
9
--   wb_async_slave: Wishbone bus to async (SRAM-like) bus slave bridge.
10
 
11
-------------------------------------------------------------------------------
12
--
13
--  wb_async_slave
14
--
15
-------------------------------------------------------------------------------
16
 
17
library IEEE;
18
use IEEE.std_logic_1164.all;
19 6 tantos
use IEEE.STD_LOGIC_UNSIGNED.all;
20 4 tantos
 
21
library wb_tk;
22
use wb_tk.technology.all;
23
 
24
entity wb_async_slave is
25
        generic (
26 6 tantos
                dat_width: positive := 16;
27
                adr_width: positive := 20
28 4 tantos
        );
29
        port (
30
                clk_i: in std_logic;
31
                rst_i: in std_logic := '0';
32 6 tantos
 
33 4 tantos
                -- interface for wait-state generator state-machine
34
                wait_state: in std_logic_vector (3 downto 0);
35
 
36
                -- interface to wishbone master device
37 6 tantos
                adr_i: in std_logic_vector (adr_width-1 downto 0);
38
                sel_i: in std_logic_vector ((adr_width/8)-1 downto 0);
39
                dat_i: in std_logic_vector (dat_width-1 downto 0);
40
                dat_o: out std_logic_vector (dat_width-1 downto 0);
41
                dat_oi: in std_logic_vector (dat_width-1 downto 0) := (others => '-');
42 4 tantos
                we_i: in std_logic;
43
                stb_i: in std_logic;
44
                ack_o: out std_logic := '0';
45
                ack_oi: in std_logic := '-';
46 6 tantos
 
47 4 tantos
                -- interface to async slave
48 6 tantos
                a_data: inout std_logic_vector (dat_width-1 downto 0) := (others => 'Z');
49
                a_addr: out std_logic_vector (adr_width-1 downto 0) := (others => 'U');
50 4 tantos
                a_rdn: out std_logic := '1';
51
                a_wrn: out std_logic := '1';
52
                a_cen: out std_logic := '1';
53
                -- byte-enable signals
54 6 tantos
                a_byen: out std_logic_vector ((dat_width/8)-1 downto 0)
55 4 tantos
        );
56
end wb_async_slave;
57
 
58
architecture wb_async_slave of wb_async_slave is
59
        -- multiplexed access signals to memory
60
        signal i_ack: std_logic;
61
        signal sm_ack: std_logic;
62
 
63
        type states is (sm_idle, sm_wait, sm_deact);
64
        signal state: states;
65
        signal cnt: std_logic_vector(3 downto 0);
66
begin
67
        ack_o <= (stb_i and i_ack) or (not stb_i and ack_oi);
68
        dat_o_gen: for i in dat_o'RANGE generate
69 6 tantos
                dat_o(i) <= (stb_i and a_data(i)) or (not stb_i and dat_oi(i));
70 4 tantos
        end generate;
71 6 tantos
 
72 4 tantos
        -- For 0WS operation i_ack is an async signal otherwise it's a sync one.
73 6 tantos
        i_ack_gen: process
74 4 tantos
        begin
75
                wait on sm_ack, stb_i, wait_state, state;
76
                if (wait_state = "0000") then
77
                        case (state) is
78
                                when sm_deact => i_ack <= '0';
79
                                when others => i_ack <= stb_i;
80
                        end case;
81
                else
82
                        i_ack <= sm_ack;
83
                end if;
84
        end process;
85 6 tantos
 
86 4 tantos
        -- SRAM signal-handler process
87 6 tantos
        sram_signals: process
88 4 tantos
        begin
89
                wait on state,we_i,a_data,adr_i,rst_i, stb_i, sel_i, dat_i;
90
                if (rst_i = '1') then
91
                        a_wrn <= '1';
92
                        a_rdn <= '1';
93
                        a_cen <= '1';
94
                        a_addr <= (others => '-');
95
                        a_data <= (others => 'Z');
96 6 tantos
                        a_byen <= (others => '1');
97 4 tantos
                else
98
                        case (state) is
99
                                when sm_deact =>
100
                                        a_wrn <= '1';
101
                                        a_rdn <= '1';
102
                                        a_cen <= '1';
103
                                        a_addr <= (others => '-');
104
                                        a_data <= (others => 'Z');
105 6 tantos
                                        a_byen <= (others => '1');
106 4 tantos
                                when others =>
107
                                        a_addr <= adr_i;
108
                                        a_rdn <= not (not we_i and stb_i);
109
                                        a_wrn <= not (we_i and stb_i);
110
                                        a_cen <= not stb_i;
111 6 tantos
                                        a_byen <= not sel_i;
112
                                        if (we_i = '1') then
113
                                                a_data <= dat_i;
114 4 tantos
                                        else
115
                                                a_data <= (others => 'Z');
116
                                        end if;
117
                        end case;
118
                end if;
119
        end process;
120
 
121
        -- Aysnc access state-machine.
122 6 tantos
        async_sm: process
123 4 tantos
--              variable cnt: std_logic_vector(3 downto 0) := "0000";
124
--              variable state: states := init;
125
        begin
126
                wait until clk_i'EVENT and clk_i = '1';
127
                if (rst_i = '1') then
128
                        state <= sm_idle;
129
                        cnt <= ((0) => '1', others => '0');
130
                        sm_ack <= '0';
131
                else
132
                        case (state) is
133
                                when sm_idle =>
134
                                        -- Check if anyone needs access to the memory.
135
                                        -- it's rdy signal will already be pulled low, so we only have to start the access
136
                                        if (stb_i = '1') then
137
                                                case wait_state is
138
                                                        when "0000" =>
139
                                                                sm_ack <= '1';
140
                                                                state <= sm_deact;
141
                                                        when "0001" =>
142
                                                                sm_ack <= '1';
143
                                                                cnt <= "0001";
144
                                                                state <= sm_wait;
145
                                                        when others =>
146
                                                                sm_ack <= '0';
147
                                                                cnt <= "0001";
148
                                                                state <= sm_wait;
149
                                                end case;
150
                                        end if;
151
                                when sm_wait =>
152
                                        if (cnt = wait_state) then
153
                                                -- wait cycle completed.
154
                                                state <= sm_deact;
155
                                                sm_ack <= '0';
156
                                                cnt <= "0000";
157
                                        else
158 6 tantos
                                                if (cnt+"1" = wait_state) then
159 4 tantos
                                                        sm_ack <= '1';
160
                                                else
161
                                                        sm_ack <= '0';
162
                                                end if;
163 6 tantos
                                                cnt <=cnt+"1";
164 4 tantos
                                        end if;
165
                                when sm_deact =>
166
                                        if (stb_i = '1') then
167
                                                case wait_state is
168
                                                        when "0000" =>
169
                                                                cnt <= "0000";
170
                                                                sm_ack <= '0';
171
                                                                state <= sm_wait;
172
                                                        when others =>
173
                                                                sm_ack <= '0';
174
                                                                cnt <= "0000";
175
                                                                state <= sm_wait;
176
                                                end case;
177
                                        else
178
                                                sm_ack <= '0';
179
                                                state <= sm_idle;
180
                                        end if;
181
                        end case;
182
                end if;
183
        end process;
184
end wb_async_slave;
185
 

powered by: WebSVN 2.1.0

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