-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbram.vhd
74 lines (61 loc) · 1.7 KB
/
bram.vhd
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
library IEEE;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_1164.ALL;
use work.ram.ALL;
use std.textio.all;
ENTITY BRAM IS
PORT(
WEN_A : IN STD_LOGIC;
EN_A : IN STD_LOGIC;
CLK_A : IN STD_LOGIC;
ADDR_W_A : IN INTEGER;
ADDR_R_A : IN INTEGER;
DIN_A : IN STD_LOGIC_VECTOR( 7 DOWNTO 0);
D_A : OUT STD_LOGIC_VECTOR( 7 DOWNTO 0);
WEN_B : IN STD_LOGIC;
EN_B : IN STD_LOGIC;
CLK_B : IN STD_LOGIC;
ADDR_W_B : IN INTEGER;
ADDR_R_B : IN INTEGER;
DIN_B : IN STD_LOGIC_VECTOR( 7 DOWNTO 0);
D_B : OUT STD_LOGIC_VECTOR( 7 DOWNTO 0)
);
END ENTITY;
ARCHITECTURE r of BRAM is
impure function init_my_ram (file1, file2 : string) return ram_type is
FILE f1, f2 : TEXT;
variable m : ram_type;
variable inline : line;
variable dataread1 : REAL;
begin
file_open(f1, file1, read_mode);
file_open(f2, file2, read_mode);
for i in 0 to 3686399 loop
readline(f1, inline);
read( inline, dataread1 );
m(i) := STD_LOGIC_VECTOR(to_unsigned(INTEGER(dataread1),8));
end loop;
for i in 3686400 to 7372799 loop
readline(f2, inline);
read( inline, dataread1 );
m(i) := STD_LOGIC_VECTOR(to_unsigned(INTEGER(dataread1),8));
end loop;
file_close(f1);
file_close(f2);
return m;
end init_my_ram;
SIGNAL ram_block : ram_type := init_my_ram( "./mat1.dat", "./mat2.dat");
BEGIN
PROCESS( CLK_A ) BEGIN
IF( WEN_A = '1') THEN
ram_block( ADDR_W_A) <= DIN_A;
END IF;
D_A <= ram_block( ADDR_R_A);
END PROCESS;
PROCESS(CLK_B ) BEGIN
IF( WEN_B = '1') THEN
ram_block( ADDR_W_B) <= DIN_B;
END IF;
D_B <= ram_block( ADDR_R_B);
END PROCESS;
END r;