Repository navigation
Expand file tree
/
Copy pathtb_RISCV_SSRAM.vhd
More file actions
138 lines (111 loc) · 3.52 KB
/
Copy pathtb_RISCV_SSRAM.vhd
File metadata and controls
138 lines (111 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use WORK.constants.all;
use WORK.functions.all;
use ieee.numeric_std.all;
entity tb_RISCV is
end tb_RISCV;
architecture Behavioral of tb_RISCV is
component RISCV is
PORT(CLK: IN std_logic;
RST: IN std_logic;
from_DRAM_data: IN std_logic_vector(data_size-1 downto 0); --data coming from the DRAM
IRAM_data: IN std_logic_vector(data_size-1 downto 0); --data coming from the IRAM
DRAM_addr: OUT std_logic_vector(31 downto 0); --DRAM address
IRAM_addr: OUT std_logic_vector(9 downto 0); --IRAM address
to_DRAM_data: OUT std_logic_vector(data_size-1 downto 0); --data sent to the DRAM
DRAM_EN: OUT std_logic; --enable DRAM
DRAM_LnS: OUT std_logic --LOADnotSTORE for DRAM
);
end component;
component IRAM_wrapper is
port (
Clk : in std_logic;
Rst : in std_logic;
Addr : in std_logic_vector(9 downto 0);
Dout : out std_logic_vector(31 downto 0)
);
end component;
component DRAM_wrapper is
port (
Clk : in std_logic;
Rst : in std_logic;
Enable : in std_logic;
RnW : in std_logic;
Addr : in std_logic_vector(31 downto 0);
Din : in std_logic_vector(31 downto 0);
Dout : out std_logic_vector(31 downto 0)
);
end component ;
signal s_CLK: std_logic:= '0';
signal s_RST, s_SRAM_rst: std_logic;
signal s_DRAM_LnS: std_logic;
signal s_DRAM_EN: std_logic;
signal DRAM_EN_RST: std_logic;
signal s_IRAM_addr: std_logic_vector(9 downto 0);
signal s_instr,s_instr_enc,s_instr_dec: std_logic_vector(IR_size-1 downto 0);
signal s_data_out: std_logic_vector(data_size-1 downto 0);
signal s_DRAM_addr: std_logic_vector(31 downto 0);
signal s_DRAM_data_in: std_logic_vector(data_size-1 downto 0);
signal s_from_DRAM_data:std_logic_vector(data_size-1 downto 0);
subtype NKEYS is natural range 0 to 15;
type KEY_ARRAY is array(NKEYS) of std_logic_vector(31 downto 0); -- size of data per address
constant key_mem : KEY_ARRAY := (x"47db4e3a",
x"1ccc40d1",
x"3250d4d8",
x"38d2f928",
x"247c3b51",
x"12882f7c",
x"48228dc8",
x"6eadcab0",
x"729c8701",
x"1d8b01f0",
x"00000000",
x"00000000",
x"00000000",
x"00000000",
x"00000000",
x"00000000");
begin
s_clk <= not s_clk after 1 ns;
s_rst <= '1','0' after 1 ns, '1' after 86 ns;
s_SRAM_rst <= '1', '0' after 86 ns;
DRAM_EN_RST <= s_SRAM_rst when (s_rst = '0' )else
s_DRAM_EN;
RISCV_test: RISCV
port map(clk =>s_clk,
rst =>s_rst,
from_DRAM_data =>s_from_DRAM_data,
IRAM_data =>s_instr_dec,
DRAM_addr =>s_DRAM_addr,
IRAM_addr =>s_IRAM_addr,
to_DRAM_data =>s_DRAM_data_in,
DRAM_EN =>s_DRAM_EN,
DRAM_LnS =>s_DRAM_LnS
);
decription : process(s_instr_enc,s_IRAM_addr)
variable key : std_logic_vector(31 downto 0) ;
begin
key := key_mem(to_integer(unsigned(s_IRAM_addr(7 downto 4)))); -- the 2 LSBs are discarded for division by 4 and other 2 bits are discarted because we increment by 4
for i in 0 to 31 loop
s_instr_dec(i) <= key(i) xor s_instr_enc(i);
end loop;
end process decription;
instr_mem: IRAM_wrapper
port map(
Clk => s_clk,
Rst => s_RST,
Addr => s_IRAM_addr,
Dout => s_instr_enc
);
mmem: DRAM_wrapper
port map(
Clk => s_CLK,
RST => s_RST,
Enable => DRAM_EN_RST,
RnW => s_DRAM_LnS,
Addr => s_DRAM_addr,
Din => s_DRAM_data_in,
Dout => s_from_DRAM_data
);
end Behavioral;