1 |
3 |
howe.r.j.8 |
-------------------------------------------------------------------------------
|
2 |
|
|
--| @file ram.vhd
|
3 |
|
|
--| @brief Bus Interface to Nexys3 on board memory devices
|
4 |
|
|
--| @author Richard James Howe
|
5 |
|
|
--| @copyright Copyright 2017 Richard James Howe.
|
6 |
|
|
--| @license MIT
|
7 |
|
|
--| @email howe.r.j.89@gmail.com
|
8 |
|
|
--|
|
9 |
|
|
--| This component is for interfacing with the two memory devices available
|
10 |
|
|
--| on the Nexys3 board.
|
11 |
|
|
--|
|
12 |
|
|
--| The devices are:
|
13 |
|
|
--| - PC28F128P33BF60 (Non-Volatile Flash with a CSI Interface)
|
14 |
|
|
--| - MT45W1MW16BDGB (SRAM)
|
15 |
|
|
--|
|
16 |
|
|
--| They both share the same data, address lines, output enable, and write
|
17 |
5 |
howe.r.j.8 |
--| enable signals. They are selected with a Chip Select (ram_cs = SRAM,
|
18 |
|
|
--| flash_cs = Flash device). The Flash has an addition reset line (flash_rp).
|
19 |
3 |
howe.r.j.8 |
--|
|
20 |
|
|
--| This interface is very simple, it does not bother with timing and
|
21 |
|
|
--| only has minimal logic and state, it is up to the consumer of this
|
22 |
|
|
--| module to implement the bus timing - which in this case is a Soft CPU
|
23 |
|
|
--| Core.
|
24 |
|
|
--|
|
25 |
5 |
howe.r.j.8 |
--| Many improvements could be made, we could do a lot more in the hardware,
|
26 |
|
|
--| even going as far as to implement most of the Common Flash Interface (but
|
27 |
|
|
--| that would be better placed in a controlling module), but it is not
|
28 |
|
|
--| necessary. We will Keep It Simple.
|
29 |
|
|
--|
|
30 |
3 |
howe.r.j.8 |
-------------------------------------------------------------------------------
|
31 |
5 |
howe.r.j.8 |
library ieee, work;
|
32 |
3 |
howe.r.j.8 |
use ieee.std_logic_1164.all;
|
33 |
5 |
howe.r.j.8 |
use work.util.common_generics;
|
34 |
3 |
howe.r.j.8 |
|
35 |
|
|
entity ram_interface is
|
36 |
5 |
howe.r.j.8 |
generic (g: common_generics);
|
37 |
3 |
howe.r.j.8 |
port(
|
38 |
|
|
clk: in std_ulogic;
|
39 |
|
|
rst: in std_ulogic;
|
40 |
|
|
|
41 |
5 |
howe.r.j.8 |
mem_addr_16_1: in std_ulogic_vector(16 downto 2);
|
42 |
3 |
howe.r.j.8 |
mem_addr_16_1_we: in std_ulogic;
|
43 |
|
|
mem_addr_26_17: in std_ulogic_vector(26 downto 17);
|
44 |
|
|
mem_addr_26_17_we: in std_ulogic;
|
45 |
|
|
mem_control_i: in std_ulogic_vector(5 downto 0);
|
46 |
|
|
mem_control_we: in std_ulogic;
|
47 |
|
|
mem_data_i: in std_ulogic_vector(15 downto 0);
|
48 |
|
|
mem_data_i_we: in std_ulogic;
|
49 |
|
|
|
50 |
|
|
mem_data_o: out std_ulogic_vector(15 downto 0);
|
51 |
|
|
|
52 |
5 |
howe.r.j.8 |
ram_cs: out std_ulogic := '1';
|
53 |
3 |
howe.r.j.8 |
|
54 |
5 |
howe.r.j.8 |
mem_oe: out std_ulogic := '0'; -- negative logic
|
55 |
|
|
mem_wr: out std_ulogic := '0'; -- negative logic
|
56 |
|
|
mem_adv: out std_ulogic := '0'; -- negative logic
|
57 |
|
|
mem_wait: out std_ulogic := '0'; -- positive!
|
58 |
3 |
howe.r.j.8 |
|
59 |
5 |
howe.r.j.8 |
flash_cs: out std_ulogic := '0';
|
60 |
|
|
flash_rp: out std_ulogic := '1';
|
61 |
|
|
mem_addr: out std_ulogic_vector(26 downto 1) := (others => '0');
|
62 |
|
|
mem_data: inout std_logic_vector(15 downto 0) := (others => 'Z'));
|
63 |
3 |
howe.r.j.8 |
end entity;
|
64 |
|
|
|
65 |
|
|
architecture rtl of ram_interface is
|
66 |
5 |
howe.r.j.8 |
signal mem_data_buf_i: std_ulogic_vector(mem_data_i'range) := (others => '0');
|
67 |
|
|
signal mem_control_o: std_ulogic_vector(mem_control_i'range) := (others => '0');
|
68 |
|
|
signal mem_we: std_ulogic := '0';
|
69 |
|
|
signal mem_oe_internal: std_ulogic := '0';
|
70 |
|
|
signal mem_addr_low: std_ulogic_vector(mem_addr_16_1'range) := (others => '0');
|
71 |
|
|
signal mem_addr_high: std_ulogic_vector(mem_addr_26_17'range) := (others => '0');
|
72 |
3 |
howe.r.j.8 |
begin
|
73 |
5 |
howe.r.j.8 |
mem_addr <= '0' & mem_addr_high & mem_addr_low;
|
74 |
3 |
howe.r.j.8 |
|
75 |
|
|
mem_addr_16_1_reg: entity work.reg
|
76 |
5 |
howe.r.j.8 |
generic map(g => g, N => mem_addr_16_1'length)
|
77 |
3 |
howe.r.j.8 |
port map(
|
78 |
|
|
clk => clk,
|
79 |
|
|
rst => rst,
|
80 |
|
|
we => mem_addr_16_1_we,
|
81 |
|
|
di => mem_addr_16_1,
|
82 |
|
|
do => mem_addr_low);
|
83 |
|
|
|
84 |
|
|
mem_addr_26_17_reg: entity work.reg
|
85 |
5 |
howe.r.j.8 |
generic map(g => g, N => mem_addr_26_17'length)
|
86 |
3 |
howe.r.j.8 |
port map(
|
87 |
|
|
clk => clk,
|
88 |
|
|
rst => rst,
|
89 |
|
|
we => mem_addr_26_17_we,
|
90 |
|
|
di => mem_addr_26_17,
|
91 |
|
|
do => mem_addr_high);
|
92 |
|
|
|
93 |
|
|
mem_control_reg: entity work.reg
|
94 |
5 |
howe.r.j.8 |
generic map(g => g, N => mem_control_i'length)
|
95 |
3 |
howe.r.j.8 |
port map(
|
96 |
|
|
clk => clk,
|
97 |
|
|
rst => rst,
|
98 |
|
|
we => mem_control_we,
|
99 |
|
|
di => mem_control_i,
|
100 |
|
|
do => mem_control_o);
|
101 |
|
|
|
102 |
|
|
mem_data_i_reg: entity work.reg
|
103 |
5 |
howe.r.j.8 |
generic map(g => g, N => mem_data_i'length)
|
104 |
3 |
howe.r.j.8 |
port map(
|
105 |
|
|
clk => clk,
|
106 |
|
|
rst => rst,
|
107 |
|
|
we => mem_data_i_we,
|
108 |
|
|
di => mem_data_i,
|
109 |
|
|
do => mem_data_buf_i);
|
110 |
|
|
|
111 |
5 |
howe.r.j.8 |
flash_cs <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(0) = '1' else '1' after g.delay;
|
112 |
|
|
ram_cs <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(1) = '1' else '1' after g.delay;
|
113 |
|
|
mem_wait <= mem_control_o(2);
|
114 |
|
|
flash_rp <= '0' when mem_control_o(3) = '1' else '1' after g.delay;
|
115 |
|
|
mem_adv <= '0' when mem_oe_internal = '1' or mem_we = '1' else '1' after g.delay;
|
116 |
|
|
mem_oe_internal <= '1' when mem_control_o(5 downto 4) = "01" else '0' after g.delay;
|
117 |
|
|
mem_we <= '1' when mem_control_o(5 downto 4) = "10" else '0' after g.delay;
|
118 |
3 |
howe.r.j.8 |
|
119 |
5 |
howe.r.j.8 |
mem_oe <= not mem_oe_internal after g.delay;
|
120 |
|
|
mem_wr <= not mem_we after g.delay;
|
121 |
3 |
howe.r.j.8 |
|
122 |
5 |
howe.r.j.8 |
mem_data_o <= std_ulogic_vector(mem_data) when mem_oe_internal = '1' else (others => '0') after g.delay;
|
123 |
|
|
mem_data <= std_logic_vector(mem_data_buf_i) when mem_we = '1' else (others => 'Z') after g.delay;
|
124 |
3 |
howe.r.j.8 |
|
125 |
|
|
end architecture;
|