aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/mem01
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-02-18 18:44:42 +0100
committerTristan Gingold <tgingold@free.fr>2020-02-18 18:45:07 +0100
commit393612fc52586d8eb8372f0ce3f05c162cfccfe2 (patch)
tree9a3f06bd59ba01c80b8012b1e3e52e7a4aa516d9 /testsuite/synth/mem01
parent3689e0eb1d8b4a9689afa6f76187f1ecdc5ec458 (diff)
downloadghdl-393612fc52586d8eb8372f0ce3f05c162cfccfe2.tar.gz
ghdl-393612fc52586d8eb8372f0ce3f05c162cfccfe2.tar.bz2
ghdl-393612fc52586d8eb8372f0ce3f05c162cfccfe2.zip
testsuite/synth: merge ram01 to mem01, add NOTES.txt
Diffstat (limited to 'testsuite/synth/mem01')
-rw-r--r--testsuite/synth/mem01/NOTES.txt9
-rw-r--r--testsuite/synth/mem01/sram01.vhdl29
-rw-r--r--testsuite/synth/mem01/srom01.vhdl28
-rw-r--r--testsuite/synth/mem01/tb_sram01.vhdl43
-rw-r--r--testsuite/synth/mem01/tb_srom01.vhdl38
-rwxr-xr-xtestsuite/synth/mem01/testsuite.sh2
6 files changed, 148 insertions, 1 deletions
diff --git a/testsuite/synth/mem01/NOTES.txt b/testsuite/synth/mem01/NOTES.txt
new file mode 100644
index 000000000..84edd5041
--- /dev/null
+++ b/testsuite/synth/mem01/NOTES.txt
@@ -0,0 +1,9 @@
+Tests for RAMs
+--------------
+
+rom1: asynchronous ROM
+srom01: Read (initialized ROM).
+sram01: Read+Write (at the same address).
+dpram1: Read+Write (using signals, without enables)
+dpram2: Read+Write (using a variable, without enables)
+dpram3: Read+Write (like dpram2 but downto)
diff --git a/testsuite/synth/mem01/sram01.vhdl b/testsuite/synth/mem01/sram01.vhdl
new file mode 100644
index 000000000..b4bfd0d2e
--- /dev/null
+++ b/testsuite/synth/mem01/sram01.vhdl
@@ -0,0 +1,29 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity sram01 is
+ port (
+ clk_i : std_logic;
+ addr_i : std_logic_vector(3 downto 0);
+ data_i : std_logic_vector(7 downto 0);
+ data_o : out std_logic_vector(7 downto 0);
+ wen_i : std_logic);
+end sram01;
+
+architecture behav of sram01 is
+begin
+ process (clk_i, addr_i)
+ type mem_type is array (0 to 15) of std_logic_vector (7 downto 0);
+ variable mem : mem_type;
+ variable addr : natural range mem_type'range;
+ begin
+ if rising_edge(clk_i) then
+ addr := to_integer (unsigned (addr_i));
+ data_o <= mem (addr);
+ if wen_i = '1' then
+ mem (addr) := data_i;
+ end if;
+ end if;
+ end process;
+end behav;
diff --git a/testsuite/synth/mem01/srom01.vhdl b/testsuite/synth/mem01/srom01.vhdl
new file mode 100644
index 000000000..1d8e70b64
--- /dev/null
+++ b/testsuite/synth/mem01/srom01.vhdl
@@ -0,0 +1,28 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+
+entity srom01 is
+ port (
+ clk_i : std_logic;
+ addr_i : std_logic_vector(3 downto 0);
+ data_o : out std_logic_vector(7 downto 0));
+end srom01;
+
+architecture behav of srom01 is
+begin
+ process (clk_i, addr_i)
+ type mem_type is array (0 to 15) of std_logic_vector (7 downto 0);
+ constant mem : mem_type := (
+ x"f0", x"e1", x"d2", x"c3",
+ x"b4", x"a5", x"96", x"87",
+ x"78", x"69", x"5a", x"4b",
+ x"3c", x"2d", x"1e", x"0f");
+ variable addr : natural range mem_type'range;
+ begin
+ if rising_edge(clk_i) then
+ addr := to_integer (unsigned (addr_i));
+ data_o <= mem (addr);
+ end if;
+ end process;
+end behav;
diff --git a/testsuite/synth/mem01/tb_sram01.vhdl b/testsuite/synth/mem01/tb_sram01.vhdl
new file mode 100644
index 000000000..6fa0a7106
--- /dev/null
+++ b/testsuite/synth/mem01/tb_sram01.vhdl
@@ -0,0 +1,43 @@
+entity tb_sram01 is
+end tb_sram01;
+
+library ieee;
+use ieee.std_logic_1164.all;
+
+architecture behav of tb_sram01 is
+ signal addr : std_logic_vector(3 downto 0);
+ signal rdat : std_logic_vector(7 downto 0);
+ signal wdat : std_logic_vector(7 downto 0);
+ signal wen : std_logic;
+ signal clk : std_logic;
+begin
+ dut: entity work.sram01
+ port map (clk_i => clk, addr_i => addr, data_i => wdat, data_o => rdat,
+ wen_i => wen);
+
+ process
+ procedure pulse is
+ begin
+ clk <= '0';
+ wait for 1 ns;
+ clk <= '1';
+ wait for 1 ns;
+ end pulse;
+ begin
+ addr <= "0000";
+ wdat <= x"01";
+ wen <= '1';
+ pulse;
+
+ addr <= "0001";
+ wdat <= x"02";
+ pulse;
+
+ addr <= "0000";
+ wen <= '0';
+ pulse;
+ assert rdat = x"01" severity failure;
+
+ wait;
+ end process;
+end behav;
diff --git a/testsuite/synth/mem01/tb_srom01.vhdl b/testsuite/synth/mem01/tb_srom01.vhdl
new file mode 100644
index 000000000..530423a67
--- /dev/null
+++ b/testsuite/synth/mem01/tb_srom01.vhdl
@@ -0,0 +1,38 @@
+entity tb_srom01 is
+end tb_srom01;
+
+library ieee;
+use ieee.std_logic_1164.all;
+
+architecture behav of tb_srom01 is
+ signal addr : std_logic_vector(3 downto 0);
+ signal rdat : std_logic_vector(7 downto 0);
+ signal clk : std_logic;
+begin
+ dut: entity work.srom01
+ port map (clk_i => clk, addr_i => addr, data_o => rdat);
+
+ process
+ procedure pulse is
+ begin
+ clk <= '0';
+ wait for 1 ns;
+ clk <= '1';
+ wait for 1 ns;
+ end pulse;
+ begin
+ addr <= "0000";
+ pulse;
+ assert rdat = x"f0" severity failure;
+
+ addr <= "0001";
+ pulse;
+ assert rdat = x"e1" severity failure;
+
+ addr <= "0100";
+ pulse;
+ assert rdat = x"b4" severity failure;
+
+ wait;
+ end process;
+end behav;
diff --git a/testsuite/synth/mem01/testsuite.sh b/testsuite/synth/mem01/testsuite.sh
index 8d0b840a5..073c69ea4 100755
--- a/testsuite/synth/mem01/testsuite.sh
+++ b/testsuite/synth/mem01/testsuite.sh
@@ -2,7 +2,7 @@
. ../../testenv.sh
-for t in rom1 dpram1 dpram2 dpram3; do
+for t in rom1 srom01 sram01 dpram1 dpram2 dpram3; do
analyze $t.vhdl tb_$t.vhdl
elab_simulate tb_$t
clean