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

Subversion Repositories wb_vga

[/] [wb_vga/] [trunk/] [wb_tk/] [wb_arbiter.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_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
 
28
                -- 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
 
39
                -- 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
 
58
                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
 
70
        signal e_state: states;
71
begin
72
        mux_signal <= i_mux_signal;
73
 
74
        sm: process is
75
                variable state: states;
76
        begin
77
                wait on a_cyc_i, b_cyc_i, priority, rst_i;
78
                if (rst_i = '1') then
79
                        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
 
122
        signal_mux: process is
123
        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
                        ena:  in STD_LOGIC := '1';
157
                        clr:  in STD_LOGIC := '0';
158
                        pre:  in STD_LOGIC := '0';
159
                                q  :  out STD_LOGIC
160
                );
161
        end component;
162
 
163
        signal i_mux_signal: std_logic;
164
 
165
        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
 
171
        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
begin
175
        mux_signal <= i_mux_signal;
176
 
177
        idle_s <= not (a_cyc_i or b_cyc_i);
178
 
179
        aa_clr <= rst_i or not a_cyc_i;
180
        aa_clk <= a_cyc_i;
181
        aa_ena <= not b_cyc_i and priority;
182
        aa_pre <= (a_cyc_i and not priority and not ba_s) or (a_cyc_i and not b_cyc_i);
183
        aa_ff: d_ff port map (
184
                d => '1',
185
                clk => aa_clk,
186
                ena => aa_ena,
187
                clr => aa_clr,
188
                pre => aa_pre,
189
                q => aa_s
190
        );
191
 
192
        ba_clr <= rst_i or not b_cyc_i;
193
        ba_clk <= b_cyc_i;
194
        ba_ena <= not a_cyc_i and not priority;
195
        ba_pre <= (b_cyc_i and priority and not aa_s) or (b_cyc_i and not a_cyc_i);
196
        ba_ff: d_ff port map (
197
                d => '1',
198
                clk => ba_clk,
199
                ena => ba_ena,
200
                clr => ba_clr,
201
                pre => ba_pre,
202
                q => ba_s
203
        );
204
 
205
        i_mux_signal <= (priority and idle_s) or ba_s;
206
 
207
        signal_mux: process is
208
        begin
209
                wait on a_we_i, a_stb_i, a_ack_oi, a_err_oi, a_rty_oi, a_cyc_i,
210
                                b_we_i, b_stb_i, b_ack_oi, b_err_oi, b_rty_oi, b_cyc_i,
211
                                s_ack_i, s_err_i, s_rty_i, i_mux_signal;
212
                if (i_mux_signal = '0') then
213
                        s_we_o <= a_we_i;
214
                        s_stb_o <= a_stb_i;
215
                        s_cyc_o <= a_cyc_i;
216
                        a_ack_o <= (a_stb_i and s_ack_i) or (not a_stb_i and a_ack_oi);
217
                        a_err_o <= (a_stb_i and s_err_i) or (not a_stb_i and a_err_oi);
218
                        a_rty_o <= (a_stb_i and s_rty_i) or (not a_stb_i and a_rty_oi);
219
                        b_ack_o <= (b_stb_i and '0') or (not b_stb_i and b_ack_oi);
220
                        b_err_o <= (b_stb_i and '0') or (not b_stb_i and b_err_oi);
221
                        b_rty_o <= (b_stb_i and '0') or (not b_stb_i and b_rty_oi);
222
                else
223
                        s_we_o <= b_we_i;
224
                        s_stb_o <= b_stb_i;
225
                        s_cyc_o <= b_cyc_i;
226
                        b_ack_o <= (b_stb_i and s_ack_i) or (not b_stb_i and b_ack_oi);
227
                        b_err_o <= (b_stb_i and s_err_i) or (not b_stb_i and b_err_oi);
228
                        b_rty_o <= (b_stb_i and s_rty_i) or (not b_stb_i and b_rty_oi);
229
                        a_ack_o <= (a_stb_i and '0') or (not a_stb_i and a_ack_oi);
230
                        a_err_o <= (a_stb_i and '0') or (not a_stb_i and a_err_oi);
231
                        a_rty_o <= (a_stb_i and '0') or (not a_stb_i and a_rty_oi);
232
                end if;
233
        end process;
234
 
235
        gen_e_state: process is
236
        begin
237
                wait on idle_s,aa_s,ba_s;
238
                   if (idle_s = '1' and ba_s = '0' and aa_s = '0') then e_state <= idle;
239
                elsif (idle_s = '0' and ba_s = '1' and aa_s = '0') then e_state <= aa;
240
                elsif (idle_s = '0' and ba_s = '0' and aa_s = '1') then e_state <= ba;
241
                else                                                    e_state <= XX;
242
                end if;
243
        end process;
244
end FPGA;
245
 

powered by: WebSVN 2.1.0

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