diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-11-01 18:34:59 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-11-01 18:34:59 +0100 |
commit | c4cdce922e246bdd41a8f405bc28846333385aba (patch) | |
tree | cf872eb110fa8131e7543d045e41d4aa8dee7a40 /testsuite/synth | |
parent | 150a5c6e886cb5a5e5da3194f02481781fba027b (diff) | |
download | ghdl-c4cdce922e246bdd41a8f405bc28846333385aba.tar.gz ghdl-c4cdce922e246bdd41a8f405bc28846333385aba.tar.bz2 ghdl-c4cdce922e246bdd41a8f405bc28846333385aba.zip |
testsuite/synth: add a test for previous commit.
Diffstat (limited to 'testsuite/synth')
-rw-r--r-- | testsuite/synth/mem2d01/memmux04.vhdl | 39 | ||||
-rw-r--r-- | testsuite/synth/mem2d01/tb_memmux04.vhdl | 83 | ||||
-rwxr-xr-x | testsuite/synth/mem2d01/testsuite.sh | 2 |
3 files changed, 123 insertions, 1 deletions
diff --git a/testsuite/synth/mem2d01/memmux04.vhdl b/testsuite/synth/mem2d01/memmux04.vhdl new file mode 100644 index 000000000..63f998f80 --- /dev/null +++ b/testsuite/synth/mem2d01/memmux04.vhdl @@ -0,0 +1,39 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity memmux04 is + port ( + wen : std_logic; + waddr : std_logic_vector (3 downto 0); + wdat : std_logic_vector (31 downto 0); + raddr : std_logic_vector (3 downto 0); + rsel : std_logic_vector (1 downto 0); + rdat : out std_logic_vector(7 downto 0); + clk : std_logic); +end memmux04; + +architecture rtl of memmux04 is +begin + process (clk) + is + type mem_type is array(0 to 15) of std_logic_vector(31 downto 0); + variable mem : mem_type; + variable ad : natural range 0 to 15; + variable sd : natural range 0 to 3; + variable w : std_logic_vector (31 downto 0); + begin + if rising_edge(clk) then + -- Read + ad := to_integer(unsigned(raddr)); + w := mem (ad); + sd := to_integer(unsigned(rsel)); + rdat <= w (sd*8 + 7 downto sd*8); + + ad := to_integer(unsigned(waddr)); + if wen = '1' then + mem (ad) := wdat; + end if; + end if; + end process; +end rtl; diff --git a/testsuite/synth/mem2d01/tb_memmux04.vhdl b/testsuite/synth/mem2d01/tb_memmux04.vhdl new file mode 100644 index 000000000..276de2460 --- /dev/null +++ b/testsuite/synth/mem2d01/tb_memmux04.vhdl @@ -0,0 +1,83 @@ +entity tb_memmux04 is +end tb_memmux04; + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +architecture behav of tb_memmux04 is + signal wen : std_logic; + signal waddr : std_logic_vector (3 downto 0); + signal wdat : std_logic_vector (31 downto 0); + signal raddr : std_logic_vector (3 downto 0); + signal rsel : std_logic_vector (1 downto 0); + signal rdat : std_logic_vector (7 downto 0); + signal clk : std_logic; +begin + dut : entity work.memmux04 + port map ( + wen => wen, + waddr => waddr, + wdat => wdat, + raddr => raddr, + rsel => rsel, + rdat => rdat, + clk => clk); + + process + procedure pulse is + begin + clk <= '0'; + wait for 1 ns; + clk <= '1'; + wait for 1 ns; + end pulse; + + variable v : std_logic_vector(3 downto 0); + variable s : std_logic_vector(1 downto 0); + begin + wen <= '1'; + waddr <= x"0"; + wdat <= x"0123_5670"; + pulse; + + wen <= '1'; + waddr <= x"1"; + wdat <= x"1234_6781"; + raddr <= x"0"; + rsel <= "00"; + pulse; + assert rdat = x"70" severity failure; + + -- Fill the memory. + for i in 0 to 15 loop + wen <= '1'; + v := std_logic_vector (to_unsigned (i, 4)); + waddr <= v; + wdat (3 downto 0) <= v; + wdat (7 downto 4) <= x"0"; + wdat (11 downto 8) <= v; + wdat (15 downto 12) <= x"1"; + wdat (19 downto 16) <= v; + wdat (23 downto 20) <= x"2"; + wdat (27 downto 24) <= v; + wdat (31 downto 28) <= x"3"; + pulse; + end loop; + + -- Check the memory. + wen <= '0'; + for i in 0 to 15 loop + v := std_logic_vector (to_unsigned (i, 4)); + raddr <= v; + for j in 0 to 3 loop + s := std_logic_vector (to_unsigned (j, 2)); + rsel <= s; + pulse; + assert rdat (3 downto 0) = v severity failure; + assert rdat (5 downto 4) = s severity failure; + end loop; + end loop; + wait; + end process; +end behav; diff --git a/testsuite/synth/mem2d01/testsuite.sh b/testsuite/synth/mem2d01/testsuite.sh index 3f49885dd..e885729f1 100755 --- a/testsuite/synth/mem2d01/testsuite.sh +++ b/testsuite/synth/mem2d01/testsuite.sh @@ -2,7 +2,7 @@ . ../../testenv.sh -for t in dpram1r dpram2r dpram2w; do +for t in dpram1r dpram2r dpram2w memmux04; do analyze $t.vhdl tb_$t.vhdl elab_simulate tb_$t clean |