2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5 use ieee.numeric_std.all;
7 -- lx_rocon_top - wires the modules with outside world
9 -- ======================================================
10 -- INTERNAL MEMORY BUS
11 -- ======================================================
13 -- Internal memory bus has the following wires:
15 -- - address[15..0] The address
16 -- - data_in[31..0] The data coming to bus
17 -- - data_out[31..0] The data coming from bus, multiplexed
18 -- - rd Read enable, active LOW
19 -- - bls[3..0] Write enable for respective bytes, active LOW
20 -- In some cases, only WR is used
21 -- - ta Transaction acknowledge (latches data out), active LOW, multiplexed
23 entity lx_rocon_top is
27 clk_cpu : in std_logic;
29 cs0_xc : in std_logic;
32 bls : in std_logic_vector(3 downto 0);
33 address : in std_logic_vector(15 downto 0);
34 data : inout std_logic_vector(31 downto 0);
36 irc1_a : in std_logic;
37 irc1_b : in std_logic;
38 irc1_index : in std_logic;
39 irc1_mark : in std_logic;
41 irc2_a : in std_logic;
42 irc2_b : in std_logic;
43 irc2_index : in std_logic;
44 irc2_mark : in std_logic;
46 irc3_a : in std_logic;
47 irc3_b : in std_logic;
48 irc3_index : in std_logic;
49 irc3_mark : in std_logic;
51 irc4_a : in std_logic;
52 irc4_b : in std_logic;
53 irc4_index : in std_logic;
54 irc4_mark : in std_logic;
60 architecture Behavioral of lx_rocon_top is
63 signal reset : std_logic;
65 -- Peripherals on the memory bus
66 signal bram_out : std_logic_vector(31 downto 0);
67 signal bram_ta : std_logic;
68 signal bram_ce : std_logic;
70 signal irc_reg_out : std_logic_vector(31 downto 0);
71 signal irc_reg_ta : std_logic;
72 signal irc_reg_ce : std_logic;
74 signal bcd_out : std_logic_vector(31 downto 0);
75 signal bcd_ta : std_logic;
76 signal bcd_ce : std_logic;
78 signal calib_out : std_logic_vector(31 downto 0);
79 signal calib_ta : std_logic;
80 signal calib_ce : std_logic;
82 -- Signals for external bus transmission
83 signal data_in_bus : std_logic_vector(31 downto 0);
84 signal data_out_bus : std_logic_vector(31 downto 0);
86 -- Signals for internal transaction
87 signal last_address : std_logic_vector(15 downto 0);
88 signal last_rd : std_logic;
89 signal last_bls : std_logic_vector(3 downto 0);
92 -- Broadcast rd only till ta (transaction acknowledge)
93 -- is received, then latch the data till the state of
94 -- rd or address changes
96 -- Data latching is synchronous - it's purpose is to
97 -- provide stable data for CPU on the bus on high rise
98 -- of trans. ack signal
99 signal i_ta : std_logic;
100 signal i_rd : std_logic;
101 signal data_read : std_logic_vector(31 downto 0);
102 signal acked : std_logic;
105 signal i_bls : std_logic_vector(3 downto 0);
106 signal data_write : std_logic_vector(31 downto 0);
112 reset : in std_logic;
114 address : in std_logic_vector(3 downto 0);
117 data_in : in std_logic;
118 data_out : out std_logic_vector(31 downto 0);
124 irc1_a : in std_logic;
125 irc1_b : in std_logic;
126 irc1_index : in std_logic;
127 irc1_mark : in std_logic;
129 irc2_a : in std_logic;
130 irc2_b : in std_logic;
131 irc2_index : in std_logic;
132 irc2_mark : in std_logic;
134 irc3_a : in std_logic;
135 irc3_b : in std_logic;
136 irc3_index : in std_logic;
137 irc3_mark : in std_logic;
139 irc4_a : in std_logic;
140 irc4_b : in std_logic;
141 irc4_index : in std_logic;
142 irc4_mark : in std_logic
146 component bus_control_bram
152 wea : in std_logic_vector(3 downto 0);
153 addra : in std_logic_vector(8 downto 0);
154 dina : in std_logic_vector(31 downto 0);
155 douta : out std_logic_vector(31 downto 0);
159 web : in std_logic_vector(3 downto 0);
160 addrb : in std_logic_vector(8 downto 0);
161 dinb : in std_logic_vector(31 downto 0);
162 doutb : out std_logic_vector(31 downto 0)
169 reset : in std_logic;
173 data_out : out std_logic_vector(31 downto 0);
179 component bus_calibration
183 reset : in std_logic;
185 address : in std_logic_vector(1 downto 0);
186 data_in : in std_logic_vector(31 downto 0);
187 data_out : out std_logic_vector(31 downto 0);
189 bls : in std_logic_vector(3 downto 0);
197 memory_bus_irc: bus_irc
202 address => address(3 downto 0),
204 data_in => data_in_bus(0),
205 data_out => irc_reg_out,
212 irc1_index => irc1_index,
213 irc1_mark => irc1_mark,
217 irc2_index => irc2_index,
218 irc2_mark => irc2_mark,
222 irc3_index => irc3_index,
223 irc3_mark => irc3_mark,
227 irc4_index => irc4_index,
228 irc4_mark => irc4_mark
231 -- Control BRAM interconnect (9 kib)
232 memory_bus_control_bram: bus_control_bram
239 addra => address(8 downto 0),
244 web => (others => '0'),
245 addrb => (others => '0'),
246 dinb => (others => '0'),
251 memory_bus_bcd: bus_bcd
264 memory_bus_calibration: bus_calibration
270 address => address(1 downto 0),
274 data_in => data_in_bus,
275 data_out => calib_out
279 memory_bus_update: process(clk_cpu)
282 if clk_cpu = '1' and clk_cpu'event then
284 -- Set every signal to inactive state here
290 i_bls <= (others => '1');
291 data_in_bus <= (others => 'X');
293 -- Check if we have chip select
296 -- Memory Map (16-bit address @ 32-bit each)
298 -- Each address is seen as 32-bit entry now
299 -- 0x0000 - 0x011F: Control dual-port BRAM
300 -- 0x8000 - 0x800F: IRC registers
301 -- 0xFFFB: 32-bit BCD
302 -- 0xFFFC - 0xFFFF: Calibration
304 if address < "0000000100100000" then -- Control BRAM
307 data_out_bus <= bram_out;
308 elsif address(15 downto 4) = "100000000000" then -- IRC
311 data_out_bus <= irc_reg_out;
312 elsif address = "1111111111111011" then -- BCD
315 data_out_bus <= bcd_out;
316 elsif address(15 downto 2) = "11111111111111" then -- Calibration
319 data_out_bus <= calib_out;
324 if last_rd = '1' or last_address /= address then
325 -- Getting something new
326 -- Set internal RD to active and reset ack and latched data
329 -- Data latching - synchronous
330 data_read <= (others => 'X');
331 elsif i_rd = '0' and acked = '0' and i_ta = '0' then
332 -- Got acknowledge, latch data
334 data_read <= data_out_bus;
335 elsif acked = '0' then
336 -- Ongoing read, keep the signal low
338 data_read <= (others => 'X');
341 last_address <= address;
343 -- Not reading, anything goes
344 data_read <= (others => 'X');
350 if bls /= "1111" then
351 if last_bls /= bls or last_address /= address then
352 -- Data are valid when BLS is active, broadcast it for one cycle
354 data_in_bus <= data_write;
357 last_address <= address;
364 -- Set last read / bls to '1' if CS0 is not asserted
366 last_bls <= (others => '1');
374 -- If RD and BLS is not high, we must keep DATA at high impedance
375 -- or the FPGA collides with SDRAM (damaging each other)
376 memory_bus_out: process(cs0_xc, rd, data, data_read)
379 -- CS0 / RD / BLS are active LOW
380 if cs0_xc = '0' and rd = '0' then
384 data <= (others => 'Z');
392 initialization: process(init)