OpenCores
URL https://opencores.org/ocsvn/tinycpu/tinycpu/trunk

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [testbench/] [memory_tb.vhd] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 earlz
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
 
5
ENTITY memory_tb IS
6
END memory_tb;
7
 
8
ARCHITECTURE behavior OF memory_tb IS
9
 
10
-- Component Declaration for the Unit Under Test (UUT)
11
 
12
  component memory
13
    port(
14 18 earlz
      Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
15
      WriteWord: in std_logic; --if set, will write a full 16-bit word instead of a byte. Address must be aligned to 16-bit address. (bottom bit must be 0)
16
      WriteEnable: in std_logic;
17 4 earlz
      Clock: in std_logic;
18
      DataIn: in std_logic_vector(15 downto 0);
19 18 earlz
      DataOut: out std_logic_vector(15 downto 0)
20 4 earlz
    );
21
  end component;
22
 
23
 
24
  --Inputs
25
  signal Address: std_logic_vector(15 downto 0) := (others => '0');
26 18 earlz
  signal WriteWord: std_logic := '0';
27
  signal WriteEnable: std_logic := '0';
28 4 earlz
  signal DataIn: std_logic_vector(15 downto 0) := (others => '0');
29
 
30
  --Outputs
31
  signal DataOut: std_logic_vector(15 downto 0);
32
 
33
  signal Clock: std_logic;
34
  constant clock_period : time := 10 ns;
35
 
36
BEGIN
37
 
38
  -- Instantiate the Unit Under Test (UUT)
39
  uut: memory PORT MAP (
40
    Address => Address,
41 18 earlz
    WriteWord => WriteWord,
42
    WriteEnable => WriteEnable,
43 4 earlz
    Clock => Clock,
44
    DataIn => DataIn,
45 18 earlz
    DataOut => DataOut
46 4 earlz
  );
47
 
48
  -- Clock process definitions
49
  clock_process :process
50
  begin
51
    Clock <= '0';
52
    wait for clock_period/2;
53
    Clock <= '1';
54
    wait for clock_period/2;
55
  end process;
56
 
57
 
58
  -- Stimulus process
59
  stim_proc: process
60
    variable err_cnt: integer :=0;
61
  begin
62 18 earlz
    wait for 50 ns;
63 4 earlz
 
64
 
65 18 earlz
    Address <= x"0000";
66
    WriteWord <= '1';
67
    WriteEnable <='1';
68
    DataIn <= x"1234";
69 4 earlz
    wait for 10 ns;
70 18 earlz
    WriteWord <= '0';
71
    WriteEnable <= '0';
72 4 earlz
    wait for 10 ns;
73 18 earlz
    assert (DataOut = x"1234") report "Basic storage failure" severity error;
74
 
75
    Address <= x"0022";
76
    WriteWord <= '1';
77
    WriteEnable <= '1';
78
    DataIn <= x"5215";
79 4 earlz
    wait for 10 ns;
80 18 earlz
    assert (DataOut = x"1234") report "no-change block ram failure" severity error;
81
    WriteWord <= '0';
82
    WriteEnable <= '0';
83
    Address <= x"0000";
84 4 earlz
    wait for 10 ns;
85 18 earlz
    assert( DataOut = x"1234") report "Memory retention failure" severity error;
86
    Address <= x"0022";
87 4 earlz
    wait for 10 ns;
88 18 earlz
    assert( DataOut = x"5215") report "memory timing is too slow" severity error;
89 4 earlz
 
90 18 earlz
    Address <= x"0010";
91
    WriteWord <= '1';
92
    WriteEnable <= '1';
93
    DataIn <= x"1234";
94 4 earlz
    wait for 10 ns;
95 18 earlz
    WriteWord <= '0';
96
    WriteEnable <= '0';
97
    Address <= x"0011";
98 4 earlz
    wait for 10 ns;
99 18 earlz
    assert (DataOut = x"0012") report "unaligned 8-bit memory read is wrong" severity error;
100
    WriteWord <='0';
101
    WriteEnable <= '1';
102
    DataIn <= x"0056";
103 4 earlz
    wait for 10 ns;
104 18 earlz
    WriteEnable <= '0';
105 4 earlz
    wait for 10 ns;
106 18 earlz
    assert (DataOut = x"0056") report "unaligned 8 bit memory write and then read is wrong" severity error;
107
    Address <= x"0010";
108 4 earlz
    wait for 10 ns;
109 18 earlz
    assert (DataOut = x"5634") report "aligned memory read after unaligned write is wrong" severity error;
110
    WriteEnable <= '1';
111
    DataIn <= x"0078";
112
    wait for 10 ns;
113
    WriteEnable <= '0';
114
    wait for 10 ns;
115
    assert (DataOut = x"5678") report "aligned 8-bit memory write is wrong" severity error;
116 4 earlz
 
117
   assert false
118
   report "Testbench of memory completed successfully!"
119
   severity note;
120
 
121
    wait;
122
 
123
    -- insert stimulus here 
124
 
125
    wait;
126
  end process;
127
 
128
 
129
END;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.