1 |
42 |
lmaarsen |
--------------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- Ethernet Switch on Configurable Logic IP Core ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the ESoCL project ----
|
6 |
|
|
---- http://www.opencores.org/cores/esoc/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description: see design description ESoCL_dd_71022001.pdf ----
|
9 |
|
|
---- ----
|
10 |
|
|
---- To Do: see roadmap description ESoCL_dd_71022001.pdf ----
|
11 |
|
|
---- and/or release bulleting ESoCL_rb_71022001.pdf ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- Author(s): L.Maarsen ----
|
14 |
|
|
---- Bert Maarsen, lmaarsen@opencores.org ----
|
15 |
|
|
---- ----
|
16 |
|
|
--------------------------------------------------------------------------------
|
17 |
|
|
---- ----
|
18 |
|
|
---- Copyright (C) 2009 Authors and OPENCORES.ORG ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- This source file may be used and distributed without ----
|
21 |
|
|
---- restriction provided that this copyright statement is not ----
|
22 |
|
|
---- removed from the file and that any derivative work contains ----
|
23 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
24 |
|
|
---- ----
|
25 |
|
|
---- This source file is free software; you can redistribute it ----
|
26 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
27 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
28 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
29 |
|
|
---- later version. ----
|
30 |
|
|
---- ----
|
31 |
|
|
---- This source is distributed in the hope that it will be ----
|
32 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
33 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
34 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
35 |
|
|
---- details. ----
|
36 |
|
|
---- ----
|
37 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
38 |
|
|
---- Public License along with this source; if not, download it ----
|
39 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
40 |
|
|
---- ----
|
41 |
|
|
--------------------------------------------------------------------------------
|
42 |
|
|
-- Object : Entity work.esoc_bus_arbiter
|
43 |
|
|
-- Last modified : Mon Apr 14 12:48:27 2014.
|
44 |
|
|
--------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
library ieee, std, work;
|
49 |
|
|
use ieee.std_logic_1164.all;
|
50 |
|
|
use std.textio.all;
|
51 |
|
|
use ieee.numeric_std.all;
|
52 |
|
|
use work.package_esoc_configuration.all;
|
53 |
|
|
|
54 |
|
|
entity esoc_bus_arbiter is
|
55 |
|
|
generic(
|
56 |
|
|
id : integer := 0);
|
57 |
|
|
port(
|
58 |
|
|
bus_eof : in std_logic;
|
59 |
|
|
bus_gnt_rd : out std_logic_vector(esoc_port_count-1 downto 0);
|
60 |
|
|
bus_gnt_wr : out std_logic_vector(esoc_port_count-1 downto 0);
|
61 |
|
|
bus_req : in std_logic_vector(esoc_port_count-1 downto 0);
|
62 |
|
|
bus_sof : in std_logic;
|
63 |
|
|
clk_bus : in std_logic;
|
64 |
|
|
clk_control : in std_logic;
|
65 |
|
|
ctrl_address : in std_logic_vector(15 downto 0);
|
66 |
|
|
ctrl_rd : in std_logic;
|
67 |
|
|
ctrl_rddata : out std_logic_vector(31 downto 0);
|
68 |
|
|
ctrl_wait : out std_logic;
|
69 |
|
|
ctrl_wr : in std_logic;
|
70 |
|
|
ctrl_wrdata : in std_logic_vector(31 downto 0);
|
71 |
|
|
reset : in std_logic);
|
72 |
|
|
end entity esoc_bus_arbiter;
|
73 |
|
|
|
74 |
|
|
--------------------------------------------------------------------------------
|
75 |
|
|
-- Object : Architecture work.esoc_bus_arbiter.esoc_bus_arbiter
|
76 |
|
|
-- Last modified : Mon Apr 14 12:48:27 2014.
|
77 |
|
|
--------------------------------------------------------------------------------
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
---------------------------------------------------------------------------------------------------------------
|
81 |
|
|
-- architecture and declarations
|
82 |
|
|
---------------------------------------------------------------------------------------------------------------
|
83 |
|
|
architecture esoc_bus_arbiter of esoc_bus_arbiter is
|
84 |
|
|
|
85 |
|
|
---------------------------------------------------------------------------------------------------------------
|
86 |
|
|
-- registers
|
87 |
|
|
---------------------------------------------------------------------------------------------------------------
|
88 |
|
|
constant reg_arb_port_disable_add: integer := 7;
|
89 |
|
|
signal reg_arb_port_disable_dat: std_logic_vector(31 downto 0);
|
90 |
|
|
constant reg_arb_port_disable_rst: std_logic_vector(31 downto 0) := X"00000000";
|
91 |
|
|
|
92 |
|
|
constant reg_arb_port_weight_add: integer := 0;
|
93 |
|
|
signal reg_arb_port_weight_dat: std_logic_vector(31 downto 0);
|
94 |
|
|
constant reg_arb_port_weight_rst: std_logic_vector(31 downto 0) := X"00000000";
|
95 |
|
|
---------------------------------------------------------------------------------------------------------------
|
96 |
|
|
-- signals
|
97 |
|
|
---------------------------------------------------------------------------------------------------------------
|
98 |
|
|
signal port_select: integer range esoc_port_count-1 downto 0;
|
99 |
|
|
signal port_request: std_logic;
|
100 |
|
|
signal port_request_weight: std_logic_vector(1 downto 0);
|
101 |
|
|
|
102 |
|
|
type states_data_bus is (idle, wait_sof, wait_eof);
|
103 |
|
|
signal state_data_bus: states_data_bus;
|
104 |
|
|
|
105 |
|
|
signal ctrl_rddata_i: std_logic_vector(ctrl_rddata'high downto 0);
|
106 |
|
|
signal ctrl_wait_i: std_logic;
|
107 |
|
|
signal ctrl_bus_enable: std_logic;
|
108 |
|
|
|
109 |
|
|
begin
|
110 |
|
|
|
111 |
|
|
--=============================================================================================================
|
112 |
|
|
-- Process : process data bus access request, use weight factor for each port and approve access
|
113 |
|
|
-- Description :
|
114 |
|
|
--=============================================================================================================
|
115 |
|
|
req_scan: process(clk_bus, reset)
|
116 |
|
|
begin
|
117 |
|
|
if reset = '1' then
|
118 |
|
|
port_select <= 0;
|
119 |
|
|
port_request <= '0';
|
120 |
|
|
port_request_weight <= (others => '0');
|
121 |
|
|
bus_gnt_wr <= (others => '0');
|
122 |
|
|
bus_gnt_rd <= (others => '0');
|
123 |
|
|
state_data_bus <= idle;
|
124 |
|
|
|
125 |
|
|
elsif clk_bus'event and clk_bus = '1' then
|
126 |
|
|
-- scan request outputs from all ESOC ports, if asserted wait for free data bus
|
127 |
|
|
if bus_req(port_select) = '1' and reg_arb_port_disable_dat(port_select) = '0' then
|
128 |
|
|
port_request <= '1';
|
129 |
|
|
|
130 |
|
|
-- request output deasserted, current weight factor zero? determine next port to check, use weight factor of current port
|
131 |
|
|
else
|
132 |
|
|
port_request <= '0';
|
133 |
|
|
|
134 |
|
|
-- check weight of processed port, scan port again or go to next port with appropriate weight?
|
135 |
|
|
if to_integer(unsigned(port_request_weight)) = 0 then
|
136 |
|
|
if port_select = esoc_port_count-1 then
|
137 |
|
|
port_select <= 0;
|
138 |
|
|
port_request_weight <= reg_arb_port_weight_dat(1) & reg_arb_port_weight_dat(0);
|
139 |
|
|
else
|
140 |
|
|
port_select <= port_select + 1;
|
141 |
|
|
port_request_weight <= reg_arb_port_weight_dat(2*(port_select+1)+1) & reg_arb_port_weight_dat(2*(port_select+1));
|
142 |
|
|
end if;
|
143 |
|
|
|
144 |
|
|
-- weight not 0, do not proceed with next port, but decrease weight of actual port
|
145 |
|
|
else
|
146 |
|
|
port_request_weight <= std_logic_vector(to_unsigned(to_integer(unsigned(port_request_weight))-1,2));
|
147 |
|
|
end if;
|
148 |
|
|
end if;
|
149 |
|
|
|
150 |
|
|
-- monitor the data bus state and control the scan process
|
151 |
|
|
case state_data_bus is
|
152 |
|
|
when idle => -- if there is a bus request, give a write grant to selected port, a read grant to all other ports and wait for SOF and EOF
|
153 |
|
|
if port_request = '1' then
|
154 |
|
|
bus_gnt_wr(port_select) <= '1';
|
155 |
|
|
bus_gnt_rd <= (others => '1');
|
156 |
|
|
state_data_bus <= wait_sof;
|
157 |
|
|
end if;
|
158 |
|
|
|
159 |
|
|
when wait_sof => -- wait for start of packet, no further actions required yet (future)
|
160 |
|
|
if bus_sof = '1' then
|
161 |
|
|
state_data_bus <= wait_eof;
|
162 |
|
|
end if;
|
163 |
|
|
|
164 |
|
|
when wait_eof => -- End of packet detect? Terminate and go back to idle.
|
165 |
|
|
if bus_eof = '1' then
|
166 |
|
|
bus_gnt_wr <= (others => '0');
|
167 |
|
|
bus_gnt_rd <= (others => '0');
|
168 |
|
|
state_data_bus <= idle;
|
169 |
|
|
end if;
|
170 |
|
|
|
171 |
|
|
when others => state_data_bus <= idle;
|
172 |
|
|
end case;
|
173 |
|
|
end if;
|
174 |
|
|
end process;
|
175 |
|
|
|
176 |
|
|
--=============================================================================================================
|
177 |
|
|
-- Process : access registers when addressed or provide data from other units to the readdata bus
|
178 |
|
|
-- Description :
|
179 |
|
|
--=============================================================================================================
|
180 |
|
|
registers: process(clk_control, reset)
|
181 |
|
|
begin
|
182 |
|
|
if reset = '1' then
|
183 |
|
|
-- all ports have weight 1 after reset
|
184 |
|
|
reg_arb_port_disable_dat <= reg_arb_port_disable_rst;
|
185 |
|
|
reg_arb_port_weight_dat <= reg_arb_port_weight_rst;
|
186 |
|
|
ctrl_rddata_i <= (others => '0');
|
187 |
|
|
ctrl_wait_i <= '1';
|
188 |
|
|
ctrl_bus_enable <= '0';
|
189 |
|
|
|
190 |
|
|
elsif clk_control'event and clk_control = '1' then
|
191 |
|
|
ctrl_wait_i <= '1';
|
192 |
|
|
ctrl_bus_enable <= '0';
|
193 |
|
|
|
194 |
|
|
-- continu if memory space of this entity is addressed
|
195 |
|
|
if to_integer(unsigned(ctrl_address)) >= (esoc_bus_arbiter_base + (id * esoc_bus_arbiter_size)) and to_integer(unsigned(ctrl_address)) < (esoc_bus_arbiter_base + (id * esoc_bus_arbiter_size) + esoc_bus_arbiter_size) then
|
196 |
|
|
ctrl_bus_enable <= '1';
|
197 |
|
|
|
198 |
|
|
--
|
199 |
|
|
-- READ CYCLE started, unit addressed?
|
200 |
|
|
--
|
201 |
|
|
if ctrl_rd = '1' then
|
202 |
|
|
-- Check register address and provide data when addressed
|
203 |
|
|
case to_integer(unsigned(ctrl_address))- esoc_bus_arbiter_base - (id * esoc_bus_arbiter_size) is
|
204 |
|
|
when reg_arb_port_disable_add => ctrl_rddata_i <= reg_arb_port_disable_dat;
|
205 |
|
|
ctrl_wait_i <= '0';
|
206 |
|
|
|
207 |
|
|
when reg_arb_port_weight_add => ctrl_rddata_i <= reg_arb_port_weight_dat;
|
208 |
|
|
ctrl_wait_i <= '0';
|
209 |
|
|
|
210 |
|
|
when others => NULL;
|
211 |
|
|
end case;
|
212 |
|
|
|
213 |
|
|
--
|
214 |
|
|
-- WRITE CYCLE started, unit addressed?
|
215 |
|
|
--
|
216 |
|
|
elsif ctrl_wr = '1' then
|
217 |
|
|
-- Check address and accept data when addressed
|
218 |
|
|
case to_integer(unsigned(ctrl_address))- esoc_bus_arbiter_base - (id * esoc_bus_arbiter_size) is
|
219 |
|
|
when reg_arb_port_disable_add => reg_arb_port_disable_dat <= ctrl_wrdata;
|
220 |
|
|
ctrl_wait_i <= '0';
|
221 |
|
|
|
222 |
|
|
when reg_arb_port_weight_add => reg_arb_port_weight_dat <= ctrl_wrdata;
|
223 |
|
|
ctrl_wait_i <= '0';
|
224 |
|
|
|
225 |
|
|
when others => NULL;
|
226 |
|
|
end case;
|
227 |
|
|
end if;
|
228 |
|
|
end if;
|
229 |
|
|
end if;
|
230 |
|
|
end process;
|
231 |
|
|
|
232 |
|
|
-- Create tristate outputs
|
233 |
|
|
ctrl_wait <= ctrl_wait_i when ctrl_bus_enable = '1' else 'Z';
|
234 |
|
|
ctrl_rddata <= ctrl_rddata_i when ctrl_bus_enable = '1' else (others => 'Z');
|
235 |
|
|
|
236 |
|
|
end architecture esoc_bus_arbiter ; -- of esoc_bus_arbiter
|