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

Subversion Repositories wb_vga

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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