Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / vhdl_json / vhdl_files / 2-exportOK / forth-cpu / ram.vhd @ 2051e520

History | View | Annotate | Download (4.2 KB)

1
-------------------------------------------------------------------------------
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
--| enable signals. They are selected with a Chip Select (RamCS = SRAM,
18
--| FlashCS = Flash device). The Flash has an addition reset line (FlashRP).
19
--|
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
-------------------------------------------------------------------------------
26
library ieee,work;
27
use ieee.std_logic_1164.all;
28
use ieee.numeric_std.all;
29

    
30
entity ram_interface is
31
	port(
32
		clk:               in    std_ulogic;
33
		rst:               in    std_ulogic;
34

    
35
		mem_addr_16_1:     in    std_ulogic_vector(16 downto 1);
36
		mem_addr_16_1_we:  in    std_ulogic;
37
		mem_addr_26_17:    in    std_ulogic_vector(26 downto 17);
38
		mem_addr_26_17_we: in    std_ulogic;
39
		mem_control_i:     in    std_ulogic_vector(5 downto 0);
40
		mem_control_we:    in    std_ulogic;
41
		mem_data_i:        in    std_ulogic_vector(15 downto 0);
42
		mem_data_i_we:     in    std_ulogic;
43

    
44
		mem_data_o:        out   std_ulogic_vector(15 downto 0);
45

    
46
		RamCS:             out   std_ulogic := '1';
47

    
48
		MemOE:             out   std_ulogic := '0'; -- negative logic
49
		MemWR:             out   std_ulogic := '0'; -- negative logic
50
		MemAdv:            out   std_ulogic := '0'; -- negative logic
51
		MemWait:           out   std_ulogic := '0'; -- positive!
52

    
53
		FlashCS:           out   std_ulogic := '0';
54
		FlashRp:           out   std_ulogic := '1';
55
		MemAdr:            out   std_ulogic_vector(26 downto 1) := (others => '0');
56
		MemDB:             inout std_logic_vector(15 downto 0)  := (others => 'Z'));
57
end entity;
58

    
59
architecture rtl of ram_interface is
60
	signal mem_data_buf_i: std_ulogic_vector(mem_data_i'range)    := (others => '0');
61
	signal mem_control_o:  std_ulogic_vector(mem_control_i'range) := (others => '0');
62
	signal mem_we:         std_ulogic := '0';
63
	signal mem_oe:         std_ulogic := '0';
64
	signal mem_addr_low:   std_ulogic_vector(mem_addr_16_1'range)  := (others => '0');
65
	signal mem_addr_high:  std_ulogic_vector(mem_addr_26_17'range) := (others => '0');
66
begin
67
	MemAdr <= '0' & mem_addr_high & mem_addr_low(mem_addr_low'high downto mem_addr_low'low + 1);
68

    
69
	mem_addr_16_1_reg: entity work.reg
70
		generic map(N => mem_addr_16_1'length)
71
		port map(
72
			clk => clk,
73
			rst => rst,
74
			we  => mem_addr_16_1_we,
75
			di  => mem_addr_16_1,
76
			do  => mem_addr_low);
77

    
78
	mem_addr_26_17_reg: entity work.reg
79
		generic map(N => 10)
80
		port map(
81
			clk => clk,
82
			rst => rst,
83
			we  => mem_addr_26_17_we,
84
			di  => mem_addr_26_17,
85
			do  => mem_addr_high);
86

    
87
	mem_control_reg: entity work.reg
88
		generic map(N => 6)
89
		port map(
90
			clk => clk,
91
			rst => rst,
92
			we  => mem_control_we,
93
			di  => mem_control_i,
94
			do  => mem_control_o);
95

    
96
	mem_data_i_reg: entity work.reg
97
		generic map(N => mem_data_i'length)
98
		port map(
99
			clk => clk,
100
			rst => rst,
101
			we  => mem_data_i_we,
102
			di  => mem_data_i,
103
			do  => mem_data_buf_i);
104

    
105
	FlashCS    <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(0) = '1' else '1';
106
	RamCS      <= '0' when mem_control_o(5 downto 4) /= "00" and mem_control_o(1) = '1' else '1';
107
	MemWait    <= mem_control_o(2);
108
	FlashRp    <= '0' when mem_control_o(3) = '1' else '1';
109
	MemAdv     <= '0' when mem_oe = '1' or mem_we = '1' else '1';
110
	mem_oe     <= '1' when mem_control_o(5 downto 4) = "01"  else '0';
111
	mem_we     <= '1' when mem_control_o(5 downto 4) = "10"  else '0';
112

    
113
	MemOE      <= not mem_oe;
114
	MemWR      <= not mem_we;
115

    
116
	mem_data_o <= std_ulogic_vector(MemDB) when mem_oe = '1' else (others => '0');
117
	MemDB      <= std_logic_vector(mem_data_buf_i) when mem_we = '1' else (others => 'Z');
118

    
119
end architecture;
120

    
121