Line 12... |
Line 12... |
--| The devices are:
|
--| The devices are:
|
--| - PC28F128P33BF60 (Non-Volatile Flash with a CSI Interface)
|
--| - PC28F128P33BF60 (Non-Volatile Flash with a CSI Interface)
|
--| - MT45W1MW16BDGB (SRAM)
|
--| - MT45W1MW16BDGB (SRAM)
|
--|
|
--|
|
--| They both share the same data, address lines, output enable, and write
|
--| They both share the same data, address lines, output enable, and write
|
--| enable signals. They are selected with a Chip Select (RamCS = SRAM,
|
--| enable signals. They are selected with a Chip Select (ram_cs = SRAM,
|
--| FlashCS = Flash device). The Flash has an addition reset line (FlashRP).
|
--| flash_cs = Flash device). The Flash has an addition reset line (flash_rp).
|
--|
|
--|
|
--| This interface is very simple, it does not bother with timing and
|
--| This interface is very simple, it does not bother with timing and
|
--| only has minimal logic and state, it is up to the consumer of this
|
--| only has minimal logic and state, it is up to the consumer of this
|
--| module to implement the bus timing - which in this case is a Soft CPU
|
--| module to implement the bus timing - which in this case is a Soft CPU
|
--| Core.
|
--| Core.
|
--|
|
--|
|
|
--| Many improvements could be made, we could do a lot more in the hardware,
|
|
--| even going as far as to implement most of the Common Flash Interface (but
|
|
--| that would be better placed in a controlling module), but it is not
|
|
--| necessary. We will Keep It Simple.
|
|
--|
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
library ieee,work;
|
library ieee,work;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use work.util.common_generics;
|
|
|
entity ram_interface is
|
entity ram_interface is
|
|
generic (g: common_generics);
|
port(
|
port(
|
clk: in std_ulogic;
|
clk: in std_ulogic;
|
rst: in std_ulogic;
|
rst: in std_ulogic;
|
|
|
mem_addr_16_1: in std_ulogic_vector(16 downto 1);
|
mem_addr_16_1: in std_ulogic_vector(16 downto 2);
|
mem_addr_16_1_we: in std_ulogic;
|
mem_addr_16_1_we: in std_ulogic;
|
mem_addr_26_17: in std_ulogic_vector(26 downto 17);
|
mem_addr_26_17: in std_ulogic_vector(26 downto 17);
|
mem_addr_26_17_we: in std_ulogic;
|
mem_addr_26_17_we: in std_ulogic;
|
mem_control_i: in std_ulogic_vector(5 downto 0);
|
mem_control_i: in std_ulogic_vector(5 downto 0);
|
mem_control_we: in std_ulogic;
|
mem_control_we: in std_ulogic;
|
mem_data_i: in std_ulogic_vector(15 downto 0);
|
mem_data_i: in std_ulogic_vector(15 downto 0);
|
mem_data_i_we: in std_ulogic;
|
mem_data_i_we: in std_ulogic;
|
|
|
mem_data_o: out std_ulogic_vector(15 downto 0);
|
mem_data_o: out std_ulogic_vector(15 downto 0);
|
|
|
RamCS: out std_ulogic := '1';
|
ram_cs: out std_ulogic := '1';
|
|
|
MemOE: out std_ulogic := '0'; -- negative logic
|
mem_oe: out std_ulogic := '0'; -- negative logic
|
MemWR: out std_ulogic := '0'; -- negative logic
|
mem_wr: out std_ulogic := '0'; -- negative logic
|
MemAdv: out std_ulogic := '0'; -- negative logic
|
mem_adv: out std_ulogic := '0'; -- negative logic
|
MemWait: out std_ulogic := '0'; -- positive!
|
mem_wait: out std_ulogic := '0'; -- positive!
|
|
|
FlashCS: out std_ulogic := '0';
|
flash_cs: out std_ulogic := '0';
|
FlashRp: out std_ulogic := '1';
|
flash_rp: out std_ulogic := '1';
|
MemAdr: out std_ulogic_vector(26 downto 1) := (others => '0');
|
mem_addr: out std_ulogic_vector(26 downto 1) := (others => '0');
|
MemDB: inout std_logic_vector(15 downto 0) := (others => 'Z'));
|
mem_data: inout std_logic_vector(15 downto 0) := (others => 'Z'));
|
end entity;
|
end entity;
|
|
|
architecture rtl of ram_interface is
|
architecture rtl of ram_interface is
|
signal mem_data_buf_i: std_ulogic_vector(mem_data_i'range) := (others => '0');
|
signal mem_data_buf_i: std_ulogic_vector(mem_data_i'range) := (others => '0');
|
signal mem_control_o: std_ulogic_vector(mem_control_i'range) := (others => '0');
|
signal mem_control_o: std_ulogic_vector(mem_control_i'range) := (others => '0');
|
signal mem_we: std_ulogic := '0';
|
signal mem_we: std_ulogic := '0';
|
signal mem_oe: std_ulogic := '0';
|
signal mem_oe_internal: std_ulogic := '0';
|
signal mem_addr_low: std_ulogic_vector(mem_addr_16_1'range) := (others => '0');
|
signal mem_addr_low: std_ulogic_vector(mem_addr_16_1'range) := (others => '0');
|
signal mem_addr_high: std_ulogic_vector(mem_addr_26_17'range) := (others => '0');
|
signal mem_addr_high: std_ulogic_vector(mem_addr_26_17'range) := (others => '0');
|
begin
|
begin
|
MemAdr <= '0' & mem_addr_high & mem_addr_low(mem_addr_low'high downto mem_addr_low'low + 1);
|
mem_addr <= '0' & mem_addr_high & mem_addr_low;
|
|
|
mem_addr_16_1_reg: entity work.reg
|
mem_addr_16_1_reg: entity work.reg
|
generic map(N => mem_addr_16_1'length)
|
generic map(g => g, N => mem_addr_16_1'length)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
we => mem_addr_16_1_we,
|
we => mem_addr_16_1_we,
|
di => mem_addr_16_1,
|
di => mem_addr_16_1,
|
do => mem_addr_low);
|
do => mem_addr_low);
|
|
|
mem_addr_26_17_reg: entity work.reg
|
mem_addr_26_17_reg: entity work.reg
|
generic map(N => 10)
|
generic map(g => g, N => mem_addr_26_17'length)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
we => mem_addr_26_17_we,
|
we => mem_addr_26_17_we,
|
di => mem_addr_26_17,
|
di => mem_addr_26_17,
|
do => mem_addr_high);
|
do => mem_addr_high);
|
|
|
mem_control_reg: entity work.reg
|
mem_control_reg: entity work.reg
|
generic map(N => 6)
|
generic map(g => g, N => mem_control_i'length)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
we => mem_control_we,
|
we => mem_control_we,
|
di => mem_control_i,
|
di => mem_control_i,
|
do => mem_control_o);
|
do => mem_control_o);
|
|
|
mem_data_i_reg: entity work.reg
|
mem_data_i_reg: entity work.reg
|
generic map(N => mem_data_i'length)
|
generic map(g => g, N => mem_data_i'length)
|
port map(
|
port map(
|
clk => clk,
|
clk => clk,
|
rst => rst,
|
rst => rst,
|
we => mem_data_i_we,
|
we => mem_data_i_we,
|
di => mem_data_i,
|
di => mem_data_i,
|
do => mem_data_buf_i);
|
do => mem_data_buf_i);
|
|
|
FlashCS <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(0) = '1' else '1';
|
flash_cs <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(0) = '1' else '1' after g.delay;
|
RamCS <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(1) = '1' else '1';
|
ram_cs <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(1) = '1' else '1' after g.delay;
|
MemWait <= mem_control_o(2);
|
mem_wait <= mem_control_o(2);
|
FlashRp <= '0' when mem_control_o(3) = '1' else '1';
|
flash_rp <= '0' when mem_control_o(3) = '1' else '1' after g.delay;
|
MemAdv <= '0' when mem_oe = '1' or mem_we = '1' else '1';
|
mem_adv <= '0' when mem_oe_internal = '1' or mem_we = '1' else '1' after g.delay;
|
mem_oe <= '1' when mem_control_o(5 downto 4) = "01" else '0';
|
mem_oe_internal <= '1' when mem_control_o(5 downto 4) = "01" else '0' after g.delay;
|
mem_we <= '1' when mem_control_o(5 downto 4) = "10" else '0';
|
mem_we <= '1' when mem_control_o(5 downto 4) = "10" else '0' after g.delay;
|
|
|
MemOE <= not mem_oe;
|
mem_oe <= not mem_oe_internal after g.delay;
|
MemWR <= not mem_we;
|
mem_wr <= not mem_we after g.delay;
|
|
|
mem_data_o <= std_ulogic_vector(MemDB) when mem_oe = '1' else (others => '0');
|
mem_data_o <= std_ulogic_vector(mem_data) when mem_oe_internal = '1' else (others => '0') after g.delay;
|
MemDB <= std_logic_vector(mem_data_buf_i) when mem_we = '1' else (others => 'Z');
|
mem_data <= std_logic_vector(mem_data_buf_i) when mem_we = '1' else (others => 'Z') after g.delay;
|
|
|
end architecture;
|
end architecture;
|
|
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|