-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcomplex_ram.vhd
67 lines (56 loc) · 1.83 KB
/
complex_ram.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
library ieee;
library work;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
use work.fft_types.all;
-- read delay is 2 cycles
entity complexram is
generic(dataBits: integer := 8;
-- real depth is 2^depth_order
depthOrder: integer := 9);
port(rdclk,wrclk: in std_logic;
-- read side; synchronous to rdclk
rdaddr: in unsigned(depthOrder-1 downto 0);
rddata: out complex;
--write side; synchronous to wrclk
wren: in std_logic;
wraddr: in unsigned(depthOrder-1 downto 0);
wrdata: in complex
);
end entity;
architecture a of complexRam is
constant width: integer := dataBits*2;
constant depth: integer := 2**depthOrder;
--ram
type ram1t is array(depth-1 downto 0) of
std_logic_vector(width-1 downto 0);
signal ram1: ram1t; -- := (others=>(others=>'0'));
signal rdaddr1: unsigned(depthOrder-1 downto 0);
signal wrdata1: std_logic_vector(width-1 downto 0);
signal tmpdata: std_logic_vector(width-1 downto 0);
signal tmpdata1,tmpdata2: signed(dataBits-1 downto 0);
begin
--inferred ram
rdaddr1 <= rdaddr; -- when rising_edge(rdclk);
-- TODO: we are assuming this infers a register on the address side (rather than output side);
-- this is true on xilinx but we should verify it on other vendor tools as well.
process(rdclk)
begin
if(rising_edge(rdclk)) then
tmpdata <= ram1(to_integer(rdaddr1));
end if;
end process;
tmpdata1 <= signed(tmpdata(dataBits-1 downto 0)) when rising_edge(rdclk);
tmpdata2 <= signed(tmpdata(width-1 downto dataBits)) when rising_edge(rdclk);
rddata <= to_complex(tmpdata1,tmpdata2);
wrdata1 <= std_logic_vector(complex_im(wrdata, dataBits))
& std_logic_vector(complex_re(wrdata, dataBits));
process(wrclk)
begin
if(rising_edge(wrclk)) then
if(wren='1') then
ram1(to_integer(wraddr)) <= wrdata1;
end if;
end if;
end process;
end a;