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;
8 use unisim.vcomponents.all;
11 use work.lx_rocon_pkg.all;
13 -- lx_rocon_top - wires the modules with the outside world
15 -- ======================================================
16 -- MASTER CPU EXTERNAL MEMORY BUS
17 -- ======================================================
19 -- Master cpu memory bus has the following wires:
21 -- - address[15..0] The address
22 -- - data_in[31..0] The data coming to bus
23 -- - data_out[31..0] The data coming from bus, multiplexed
24 -- - rd Read enable, active LOW
25 -- - bls[3..0] Write enable for respective bytes, active LOW
26 -- In some cases, only WR is used
27 -- - ta Transaction acknowledge (latches data out), active LOW, multiplexed
29 -- ======================================================
30 -- TUMBL EXTERNAL MEMORY BUS
31 -- ======================================================
33 entity lx_rocon_top is
37 --clk_cpu : in std_logic;
38 clk_50m : in std_logic;
40 cs0_xc : in std_logic;
43 bls : in std_logic_vector(3 downto 0);
44 address : in std_logic_vector(15 downto 0);
45 data : inout std_logic_vector(31 downto 0);
47 irc1_a : in std_logic;
48 irc1_b : in std_logic;
49 irc1_index : in std_logic;
50 irc1_mark : in std_logic;
52 irc2_a : in std_logic;
53 irc2_b : in std_logic;
54 irc2_index : in std_logic;
55 irc2_mark : in std_logic;
57 irc3_a : in std_logic;
58 irc3_b : in std_logic;
59 irc3_index : in std_logic;
60 irc3_mark : in std_logic;
62 irc4_a : in std_logic;
63 irc4_b : in std_logic;
64 irc4_index : in std_logic;
65 irc4_mark : in std_logic;
71 architecture Behavioral of lx_rocon_top is
74 signal reset_s : std_logic;
75 signal neg_init_s : std_logic;
77 signal clk_100m_s : std_logic;
78 signal clk_100m_fb_s : std_logic;
79 signal clk_100m_locked_s : std_logic;
80 -- Peripherals on the memory bus
81 signal tumbl_out_s : std_logic_vector(31 downto 0);
82 signal tumbl_ta_s : std_logic;
83 signal tumbl_ce_s : std_logic;
85 signal irc_reg_out_s : std_logic_vector(31 downto 0);
86 signal irc_reg_ta_s : std_logic;
87 signal irc_reg_ce_s : std_logic;
89 signal calib_out_s : std_logic_vector(31 downto 0);
90 signal calib_ta_s : std_logic;
91 signal calib_ce_s : std_logic;
92 -- Signals for external bus transmission
93 signal data_i_s : std_logic_vector(31 downto 0);
94 signal data_o_s : std_logic_vector(31 downto 0);
95 -- Signals for internal transaction
96 signal last_address_s : std_logic_vector(15 downto 0);
97 signal last_rd_s : std_logic;
98 signal last_bls_s : std_logic_vector(3 downto 0);
101 -- Broadcast rd only till ta (transaction acknowledge)
102 -- is received, then latch the data till the state of
103 -- rd or address changes
105 -- Data latching is synchronous - it's purpose is to
106 -- provide stable data for CPU on the bus on high rise
107 -- of trans. ack signal
108 signal rd_f_s : std_logic; -- Filtered RD
109 signal rd_d_s : std_logic; -- D over RD
110 signal i_ta_s : std_logic; -- Internal bus TA (active 1)
111 signal i_rd_s : std_logic; -- Internal bus RD (active 1)
113 signal data_read_s : std_logic_vector(31 downto 0); -- Latched read data
115 signal acked_s : std_logic;
118 signal bls_f_s : std_logic_vector(3 downto 0); -- Filtered BLS
119 signal bls_d_s : std_logic_vector(3 downto 0); -- D over BLS
120 signal i_bls_s : std_logic_vector(3 downto 0); -- Internal BLS (active 1)
122 signal data_write_s : std_logic_vector(31 downto 0); -- Data broadcasted to write
127 clk_100m_dcm_sp : DCM_SP
133 clkin_divide_by_2 => false,
134 clkin_period => 20.0, -- 50 MHz
135 clkout_phase_shift => "NONE",
136 clk_feedback => "1X",
137 deskew_adjust => "SYSTEM_SYNCHRONOUS",
138 dfs_frequency_mode => "LOW",
139 dll_frequency_mode => "LOW",
141 duty_cycle_correction => true,
142 factory_jf => X"c080",
144 startup_wait => false
148 clk0 => clk_100m_fb_s,
157 locked => clk_100m_locked_s,
160 clkfb => clk_100m_fb_s,
170 memory_bus_irc: bus_irc
175 address_i => address(3 downto 0),
176 ce_i => irc_reg_ce_s,
177 data_i => data_i_s(0),
178 data_o => irc_reg_out_s,
181 ta_o => irc_reg_ta_s,
185 irc1_index_i => irc1_index,
186 irc1_mark_i => irc1_mark,
190 irc2_index_i => irc2_index,
191 irc2_mark_i => irc2_mark,
195 irc3_index_i => irc3_index,
196 irc3_mark_i => irc3_mark,
200 irc4_index_i => irc4_index,
201 irc4_mark_i => irc4_mark
205 memory_bus_tumbl: bus_tumbl
208 clk_100m_i => clk_100m_s,
209 clk_50m_i => clk_50m,
210 reset_100m_i => reset_s,
211 ce_100m_i => tumbl_ce_s,
212 ta_100m_o => tumbl_ta_s,
214 bls_100m_i => i_bls_s,
215 address_100m_i => address(11 downto 0),
216 data_100m_i => data_i_s,
217 data_100m_o => tumbl_out_s,
220 XMEMB_50m_i.clken => '1',
221 XMEMB_50m_i.data => (others => '1'),
222 XMEMB_50m_i.int => '0',
223 XMEMB_sel_50m_o => open
227 memory_bus_calibration: bus_calibration
233 address_i => address(1 downto 0),
238 data_o => calib_out_s
242 --bls_f <= bls when bls = bls_d else "1111";
243 bls_f_s(0) <= bls(0) when bls(0) = bls_d_s(0) else '1';
244 bls_f_s(1) <= bls(2) when bls(2) = bls_d_s(2) else '1';
245 bls_f_s(2) <= bls(2) when bls(2) = bls_d_s(2) else '1';
246 bls_f_s(3) <= bls(3) when bls(3) = bls_d_s(3) else '1';
247 rd_f_s <= rd when rd = rd_d_s else '1';
254 if clk_100m_s = '1' and clk_100m_s'event then
256 -- Set every signal to inactive state here
261 i_bls_s <= (others => '0');
262 data_i_s <= (others => 'X');
264 -- Check if we have chip select
265 if reset_s = '1' then
268 data_read_s <= (others => '0');
269 elsif cs0_xc = '0' then
271 -- Memory Map (16-bit address @ 32-bit each)
273 -- Each address is seen as 32-bit entry now
274 -- 0x0000 - 0x0FFF: Tumbl
275 -- 0x8000 - 0x800F: IRC registers
276 -- 0xFFFC - 0xFFFF: Calibration
278 if address < "0001000000000000" then -- Tumbl
280 i_ta_s <= tumbl_ta_s;
281 data_o_s <= tumbl_out_s;
282 elsif address(15 downto 4) = "100000000000" then -- IRC
284 i_ta_s <= irc_reg_ta_s;
285 data_o_s <= irc_reg_out_s;
286 elsif address(15 downto 2) = "11111111111111" then -- Calibration
288 i_ta_s <= calib_ta_s;
289 data_o_s <= calib_out_s;
294 if last_rd_s = '1' or last_address_s /= address then
295 -- Getting something new
296 -- Set internal RD to active and reset ack and latched data
299 -- Data latching - synchronous
300 data_read_s <= (others => 'X');
301 elsif i_rd_s = '1' and acked_s = '0' and i_ta_s = '1' then
302 -- Got acknowledge, latch data
304 data_read_s <= data_o_s;
305 elsif acked_s = '0' then
306 -- Ongoing read, keep the signal active
308 data_read_s <= (others => 'X');
311 last_address_s <= address;
313 -- Not reading, anything goes
314 data_read_s <= (others => 'X');
320 if bls_f_s /= "1111" then
322 if last_bls_s /= bls_f_s or last_address_s /= address then
323 -- Broadcast BLS for once cycle to write the data
324 i_bls_s <= not bls_f_s;
325 data_i_s <= data_write_s;
328 last_address_s <= address;
331 last_bls_s <= bls_f_s;
335 -- Set last read / bls to '1' if CS0 is not asserted
337 last_bls_s <= (others => '1');
349 -- If RD and BLS is not high, we must keep DATA at high impedance
350 -- or the FPGA collides with SDRAM (damaging each other)
352 process(cs0_xc, rd, data, data_read_s)
355 -- CS0 / RD / BLS are active LOW
356 if cs0_xc = '0' and rd = '0' then
360 data <= (others => 'Z');
363 data_write_s <= data;
369 process(init, clk_100m_locked_s)
372 -- TODO: Proper reset (lacks filter and propagation with ack as we use PLL)
373 neg_init_s <= not init;
374 reset_s <= (not init) or (not clk_100m_locked_s);