Merge branch 'divider' of https://github.com/paulusmack/microwatt
[microwatt.git] / wishbone_arbiter.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3
4 library work;
5 use work.wishbone_types.all;
6
7 -- TODO: Use an array of master/slaves with parametric size
8 entity wishbone_arbiter is
9 port (clk : in std_ulogic;
10 rst : in std_ulogic;
11
12 wb1_in : in wishbone_master_out;
13 wb1_out : out wishbone_slave_out;
14
15 wb2_in : in wishbone_master_out;
16 wb2_out : out wishbone_slave_out;
17
18 wb3_in : in wishbone_master_out;
19 wb3_out : out wishbone_slave_out;
20
21 wb_out : out wishbone_master_out;
22 wb_in : in wishbone_slave_out
23 );
24 end wishbone_arbiter;
25
26 architecture behave of wishbone_arbiter is
27 type wishbone_arbiter_state_t is (IDLE, WB1_BUSY, WB2_BUSY, WB3_BUSY);
28 signal state : wishbone_arbiter_state_t := IDLE;
29 begin
30
31 wishbone_muxes: process(state, wb_in, wb1_in, wb2_in, wb3_in)
32 begin
33 -- Requests from masters are fully muxed
34 wb_out <= wb1_in when state = WB1_BUSY else
35 wb2_in when state = WB2_BUSY else
36 wb3_in when state = WB3_BUSY else
37 wishbone_master_out_init;
38
39 -- Responses from slave don't need to mux the data bus
40 wb1_out.dat <= wb_in.dat;
41 wb2_out.dat <= wb_in.dat;
42 wb3_out.dat <= wb_in.dat;
43 wb1_out.ack <= wb_in.ack when state = WB1_BUSY else '0';
44 wb2_out.ack <= wb_in.ack when state = WB2_BUSY else '0';
45 wb3_out.ack <= wb_in.ack when state = WB3_BUSY else '0';
46 end process;
47
48 wishbone_arbiter_process: process(clk)
49 begin
50 if rising_edge(clk) then
51 if rst = '1' then
52 state <= IDLE;
53 else
54 case state is
55 when IDLE =>
56 if wb1_in.cyc = '1' then
57 state <= WB1_BUSY;
58 elsif wb2_in.cyc = '1' then
59 state <= WB2_BUSY;
60 elsif wb3_in.cyc = '1' then
61 state <= WB3_BUSY;
62 end if;
63 when WB1_BUSY =>
64 if wb1_in.cyc = '0' then
65 state <= IDLE;
66 end if;
67 when WB2_BUSY =>
68 if wb2_in.cyc = '0' then
69 state <= IDLE;
70 end if;
71 when WB3_BUSY =>
72 if wb3_in.cyc = '0' then
73 state <= IDLE;
74 end if;
75 end case;
76 end if;
77 end if;
78 end process;
79 end behave;