forth-cpu

Форк
0
/
ram.vhd 
125 строк · 4.7 Кб
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 (ram_cs = SRAM,
18
--| flash_cs = Flash device). The Flash has an addition reset line (flash_rp).
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
--| 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
-------------------------------------------------------------------------------
31
library ieee, work;
32
use ieee.std_logic_1164.all;
33
use work.util.common_generics;
34

35
entity ram_interface is
36
	generic (g: common_generics);
37
	port(
38
		clk:               in    std_ulogic;
39
		rst:               in    std_ulogic;
40

41
		mem_addr_16_1:     in    std_ulogic_vector(16 downto 2);
42
		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
		ram_cs:            out   std_ulogic := '1';
53

54
		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

59
		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
end entity;
64

65
architecture rtl of ram_interface is
66
	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
begin
73
	mem_addr <= '0' & mem_addr_high & mem_addr_low;
74

75
	mem_addr_16_1_reg: entity work.reg
76
		generic map(g => g, N => mem_addr_16_1'length)
77
		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
		generic map(g => g, N => mem_addr_26_17'length)
86
		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
		generic map(g => g, N => mem_control_i'length)
95
		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
		generic map(g => g, N => mem_data_i'length)
104
		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
	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

119
	mem_oe   <= not mem_oe_internal after g.delay;
120
	mem_wr   <= not mem_we after g.delay;
121

122
	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

125
end architecture;
126

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.