aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue635/ram.vhdl
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-08-16 21:53:33 +0200
committerTristan Gingold <tgingold@free.fr>2018-08-16 21:53:33 +0200
commit3bf65cc57427fdd683ac91bf76696cb7275eddad (patch)
treeb41124063e1226fcd16e1486219af1fc0a714df1 /testsuite/gna/issue635/ram.vhdl
parent35647707bf3035ec4135207ec72f0b4e2daba0db (diff)
downloadghdl-3bf65cc57427fdd683ac91bf76696cb7275eddad.tar.gz
ghdl-3bf65cc57427fdd683ac91bf76696cb7275eddad.tar.bz2
ghdl-3bf65cc57427fdd683ac91bf76696cb7275eddad.zip
Add testcase for #635
Diffstat (limited to 'testsuite/gna/issue635/ram.vhdl')
-rw-r--r--testsuite/gna/issue635/ram.vhdl47
1 files changed, 47 insertions, 0 deletions
diff --git a/testsuite/gna/issue635/ram.vhdl b/testsuite/gna/issue635/ram.vhdl
new file mode 100644
index 000000000..e28225673
--- /dev/null
+++ b/testsuite/gna/issue635/ram.vhdl
@@ -0,0 +1,47 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity Ram is
+ generic
+ (
+ addressWidth : in positive;
+ busWidth : in positive;
+ size : in positive
+ );
+ port
+ (
+ clk : in std_logic;
+ address : in unsigned(addressWidth - 1 downto 0);
+ writeEnable : in std_logic;
+ dataIn : in std_logic_vector(busWidth - 1 downto 0);
+ dataOut : out std_logic_vector(busWidth - 1 downto 0)
+ );
+end Ram;
+
+architecture Behavioral of Ram is
+ constant alignment : positive := busWidth / 8;
+ constant ramSize : positive := size / alignment;
+
+ type RamType is array(natural range <>) of std_logic_vector(busWidth - 1 downto 0);
+ subtype RamRange is natural range 0 to ramSize;
+
+ signal ram : RamType(RamRange);
+begin
+ process(clk)
+ variable index : RamRange;
+ begin
+ if (rising_edge(clk))
+ then
+ index := to_integer(address) / alignment;
+
+ if (writeEnable = '1')
+ then
+ ram(index) <= dataIn;
+ end if;
+
+ dataOut <= ram(index);
+ end if;
+ end process;
+end Behavioral;
+