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

Subversion Repositories wb_tk

[/] [wb_tk/] [trunk/] [wb_arbiter.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_arbiter: two-way bus arbiter. Asyncronous logic ensures 0-ws operation on shared bus
10
 
11
-------------------------------------------------------------------------------
12
--
13
--  wb_arbiter
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_arbiter is
24
        port (
25
--              clk: in std_logic;
26
                rst_i: in std_logic := '0';
27 6 tantos
 
28 4 tantos
                -- interface to master device a
29
                a_we_i: in std_logic;
30
                a_stb_i: in std_logic;
31
                a_cyc_i: in std_logic;
32
                a_ack_o: out std_logic;
33
                a_ack_oi: in std_logic := '-';
34
                a_err_o: out std_logic;
35
                a_err_oi: in std_logic := '-';
36
                a_rty_o: out std_logic;
37
                a_rty_oi: in std_logic := '-';
38 6 tantos
 
39 4 tantos
                -- interface to master device b
40
                b_we_i: in std_logic;
41
                b_stb_i: in std_logic;
42
                b_cyc_i: in std_logic;
43
                b_ack_o: out std_logic;
44
                b_ack_oi: in std_logic := '-';
45
                b_err_o: out std_logic;
46
                b_err_oi: in std_logic := '-';
47
                b_rty_o: out std_logic;
48
                b_rty_oi: in std_logic := '-';
49
 
50
                -- interface to shared devices
51
                s_we_o: out std_logic;
52
                s_stb_o: out std_logic;
53
                s_cyc_o: out std_logic;
54
                s_ack_i: in std_logic;
55
                s_err_i: in std_logic := '-';
56
                s_rty_i: in std_logic := '-';
57 6 tantos
 
58 4 tantos
                mux_signal: out std_logic; -- 0: select A signals, 1: select B signals
59
 
60
                -- misc control lines
61
                priority: in std_logic -- 0: A have priority over B, 1: B have priority over A
62
        );
63
end wb_arbiter;
64
 
65
-- This acthitecture is a clean asyncron state-machine. However it cannot be mapped to FPGA architecture
66
architecture behaviour of wb_arbiter is
67
        type states is (idle,aa,ba);
68
        signal i_mux_signal: std_logic;
69 6 tantos
 
70 4 tantos
        signal e_state: states;
71
begin
72
        mux_signal <= i_mux_signal;
73 6 tantos
 
74
        sm: process
75 4 tantos
                variable state: states;
76
        begin
77
                wait on a_cyc_i, b_cyc_i, priority, rst_i;
78 6 tantos
                if (rst_i = '1') then
79 4 tantos
                        state := idle;
80
                        i_mux_signal <= priority;
81
                else
82
                        case (state) is
83
                                when idle =>
84
                                        if (a_cyc_i = '1' and (priority = '0' or b_cyc_i = '0')) then
85
                                                state := aa;
86
                                                i_mux_signal <= '0';
87
                                        elsif (b_cyc_i = '1' and (priority = '1' or a_cyc_i = '0')) then
88
                                                state := ba;
89
                                                i_mux_signal <= '1';
90
                                        else
91
                                                i_mux_signal <= priority;
92
                                        end if;
93
                                when aa =>
94
                                        if (a_cyc_i = '0') then
95
                                                if (b_cyc_i = '1') then
96
                                                        state := ba;
97
                                                        i_mux_signal <= '1';
98
                                                else
99
                                                        state := idle;
100
                                                        i_mux_signal <= priority;
101
                                                end if;
102
                                        else
103
                                                i_mux_signal <= '0';
104
                                        end if;
105
                                when ba =>
106
                                        if (b_cyc_i = '0') then
107
                                                if (a_cyc_i = '1') then
108
                                                        state := aa;
109
                                                        i_mux_signal <= '0';
110
                                                else
111
                                                        state := idle;
112
                                                        i_mux_signal <= priority;
113
                                                end if;
114
                                        else
115
                                                i_mux_signal <= '1';
116
                                        end if;
117
                        end case;
118
                end if;
119
                e_state <= state;
120
        end process;
121 6 tantos
 
122
        signal_mux: process
123 4 tantos
        begin
124
                wait on a_we_i, a_stb_i, a_ack_oi, a_err_oi, a_rty_oi, a_cyc_i,
125
                                b_we_i, b_stb_i, b_ack_oi, b_err_oi, b_rty_oi, b_cyc_i,
126
                                s_ack_i, s_err_i, s_rty_i, i_mux_signal;
127
                if (i_mux_signal = '0') then
128
                        s_we_o <= a_we_i;
129
                        s_stb_o <= a_stb_i;
130
                        s_cyc_o <= a_cyc_i;
131
                        a_ack_o <= (a_stb_i and s_ack_i) or (not a_stb_i and a_ack_oi);
132
                        a_err_o <= (a_stb_i and s_err_i) or (not a_stb_i and a_err_oi);
133
                        a_rty_o <= (a_stb_i and s_rty_i) or (not a_stb_i and a_rty_oi);
134
                        b_ack_o <= (b_stb_i and '0') or (not b_stb_i and b_ack_oi);
135
                        b_err_o <= (b_stb_i and '0') or (not b_stb_i and b_err_oi);
136
                        b_rty_o <= (b_stb_i and '0') or (not b_stb_i and b_rty_oi);
137
                else
138
                        s_we_o <= b_we_i;
139
                        s_stb_o <= b_stb_i;
140
                        s_cyc_o <= b_cyc_i;
141
                        b_ack_o <= (b_stb_i and s_ack_i) or (not b_stb_i and b_ack_oi);
142
                        b_err_o <= (b_stb_i and s_err_i) or (not b_stb_i and b_err_oi);
143
                        b_rty_o <= (b_stb_i and s_rty_i) or (not b_stb_i and b_rty_oi);
144
                        a_ack_o <= (a_stb_i and '0') or (not a_stb_i and a_ack_oi);
145
                        a_err_o <= (a_stb_i and '0') or (not a_stb_i and a_err_oi);
146
                        a_rty_o <= (a_stb_i and '0') or (not a_stb_i and a_rty_oi);
147
                end if;
148
        end process;
149
end behaviour;
150
 
151
-- This acthitecture is a more-or-less structural implementation. Fits for FPGA realization.
152
architecture FPGA of wb_arbiter is
153
        component d_ff
154
                port (  d  :  in STD_LOGIC;
155
                                clk:  in STD_LOGIC;
156 6 tantos
                                ena:  in STD_LOGIC := '1';
157
                                clr:  in STD_LOGIC := '0';
158
                                pre:  in STD_LOGIC := '0';
159 4 tantos
                                q  :  out STD_LOGIC
160
                );
161
        end component;
162 6 tantos
 
163 4 tantos
        signal i_mux_signal: std_logic;
164 6 tantos
 
165 4 tantos
        type states is (idle,aa,ba,XX);
166
        signal e_state: states;
167
 
168
        -- signals for a DFF in FPGA
169
        signal idle_s, aa_s, ba_s: std_logic;
170 6 tantos
 
171 4 tantos
        signal aa_clk, aa_ena, aa_clr, aa_pre: std_logic;
172
        signal ba_clk, ba_ena, ba_clr, ba_pre: std_logic;
173
 
174 6 tantos
        signal one: std_logic := '1';
175 4 tantos
begin
176 6 tantos
        one <= '1';
177 4 tantos
        mux_signal <= i_mux_signal;
178 6 tantos
 
179 4 tantos
        idle_s <= not (a_cyc_i or b_cyc_i);
180 6 tantos
 
181 4 tantos
        aa_clr <= rst_i or not a_cyc_i;
182
        aa_clk <= a_cyc_i;
183
        aa_ena <= not b_cyc_i and priority;
184
        aa_pre <= (a_cyc_i and not priority and not ba_s) or (a_cyc_i and not b_cyc_i);
185
        aa_ff: d_ff port map (
186 6 tantos
                d => one,
187 4 tantos
                clk => aa_clk,
188
                ena => aa_ena,
189
                clr => aa_clr,
190
                pre => aa_pre,
191
                q => aa_s
192
        );
193 6 tantos
 
194 4 tantos
        ba_clr <= rst_i or not b_cyc_i;
195
        ba_clk <= b_cyc_i;
196
        ba_ena <= not a_cyc_i and not priority;
197
        ba_pre <= (b_cyc_i and priority and not aa_s) or (b_cyc_i and not a_cyc_i);
198
        ba_ff: d_ff port map (
199 6 tantos
                d => one,
200 4 tantos
                clk => ba_clk,
201
                ena => ba_ena,
202
                clr => ba_clr,
203
                pre => ba_pre,
204
                q => ba_s
205
        );
206 6 tantos
 
207 4 tantos
        i_mux_signal <= (priority and idle_s) or ba_s;
208 6 tantos
 
209
        signal_mux: process
210 4 tantos
        begin
211
                wait on a_we_i, a_stb_i, a_ack_oi, a_err_oi, a_rty_oi, a_cyc_i,
212
                                b_we_i, b_stb_i, b_ack_oi, b_err_oi, b_rty_oi, b_cyc_i,
213
                                s_ack_i, s_err_i, s_rty_i, i_mux_signal;
214
                if (i_mux_signal = '0') then
215
                        s_we_o <= a_we_i;
216
                        s_stb_o <= a_stb_i;
217
                        s_cyc_o <= a_cyc_i;
218
                        a_ack_o <= (a_stb_i and s_ack_i) or (not a_stb_i and a_ack_oi);
219
                        a_err_o <= (a_stb_i and s_err_i) or (not a_stb_i and a_err_oi);
220
                        a_rty_o <= (a_stb_i and s_rty_i) or (not a_stb_i and a_rty_oi);
221
                        b_ack_o <= (b_stb_i and '0') or (not b_stb_i and b_ack_oi);
222
                        b_err_o <= (b_stb_i and '0') or (not b_stb_i and b_err_oi);
223
                        b_rty_o <= (b_stb_i and '0') or (not b_stb_i and b_rty_oi);
224
                else
225
                        s_we_o <= b_we_i;
226
                        s_stb_o <= b_stb_i;
227
                        s_cyc_o <= b_cyc_i;
228
                        b_ack_o <= (b_stb_i and s_ack_i) or (not b_stb_i and b_ack_oi);
229
                        b_err_o <= (b_stb_i and s_err_i) or (not b_stb_i and b_err_oi);
230
                        b_rty_o <= (b_stb_i and s_rty_i) or (not b_stb_i and b_rty_oi);
231
                        a_ack_o <= (a_stb_i and '0') or (not a_stb_i and a_ack_oi);
232
                        a_err_o <= (a_stb_i and '0') or (not a_stb_i and a_err_oi);
233
                        a_rty_o <= (a_stb_i and '0') or (not a_stb_i and a_rty_oi);
234
                end if;
235
        end process;
236 6 tantos
 
237
        gen_e_state: process
238 4 tantos
        begin
239
                wait on idle_s,aa_s,ba_s;
240
                   if (idle_s = '1' and ba_s = '0' and aa_s = '0') then e_state <= idle;
241
                elsif (idle_s = '0' and ba_s = '1' and aa_s = '0') then e_state <= aa;
242
                elsif (idle_s = '0' and ba_s = '0' and aa_s = '1') then e_state <= ba;
243
                else                                                    e_state <= XX;
244
                end if;
245
        end process;
246
end FPGA;
247
 

powered by: WebSVN 2.1.0

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