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

Subversion Repositories tinycpu

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

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 37 earlz
      DataOut: out std_logic_vector(15 downto 0);
20
      Port0: inout std_logic_vector(7 downto 0)
21 4 earlz
    );
22
  end component;
23
 
24
 
25
  --Inputs
26
  signal Address: std_logic_vector(15 downto 0) := (others => '0');
27 18 earlz
  signal WriteWord: std_logic := '0';
28
  signal WriteEnable: std_logic := '0';
29 4 earlz
  signal DataIn: std_logic_vector(15 downto 0) := (others => '0');
30
 
31
  --Outputs
32
  signal DataOut: std_logic_vector(15 downto 0);
33
 
34 37 earlz
  --inouts
35
  signal Port0: std_logic_vector(7 downto 0);
36
 
37 4 earlz
  signal Clock: std_logic;
38
  constant clock_period : time := 10 ns;
39
 
40
BEGIN
41
 
42
  -- Instantiate the Unit Under Test (UUT)
43
  uut: memory PORT MAP (
44
    Address => Address,
45 18 earlz
    WriteWord => WriteWord,
46
    WriteEnable => WriteEnable,
47 4 earlz
    Clock => Clock,
48
    DataIn => DataIn,
49 37 earlz
    DataOut => DataOut,
50
    Port0 => Port0
51 4 earlz
  );
52
 
53
  -- Clock process definitions
54
  clock_process :process
55
  begin
56
    Clock <= '0';
57
    wait for clock_period/2;
58
    Clock <= '1';
59
    wait for clock_period/2;
60
  end process;
61
 
62
 
63
  -- Stimulus process
64
  stim_proc: process
65
    variable err_cnt: integer :=0;
66
  begin
67 18 earlz
    wait for 50 ns;
68 4 earlz
 
69
 
70 37 earlz
    Address <= x"0100";
71 18 earlz
    WriteWord <= '1';
72
    WriteEnable <='1';
73
    DataIn <= x"1234";
74 4 earlz
    wait for 10 ns;
75 18 earlz
    WriteWord <= '0';
76
    WriteEnable <= '0';
77 4 earlz
    wait for 10 ns;
78 18 earlz
    assert (DataOut = x"1234") report "Basic storage failure" severity error;
79
 
80 37 earlz
    Address <= x"0122";
81 18 earlz
    WriteWord <= '1';
82
    WriteEnable <= '1';
83
    DataIn <= x"5215";
84 4 earlz
    wait for 10 ns;
85 18 earlz
    assert (DataOut = x"1234") report "no-change block ram failure" severity error;
86
    WriteWord <= '0';
87
    WriteEnable <= '0';
88 37 earlz
    Address <= x"0100";
89 4 earlz
    wait for 10 ns;
90 18 earlz
    assert( DataOut = x"1234") report "Memory retention failure" severity error;
91 37 earlz
    Address <= x"0122";
92 4 earlz
    wait for 10 ns;
93 18 earlz
    assert( DataOut = x"5215") report "memory timing is too slow" severity error;
94 4 earlz
 
95 37 earlz
    Address <= x"0110";
96 18 earlz
    WriteWord <= '1';
97
    WriteEnable <= '1';
98
    DataIn <= x"1234";
99 4 earlz
    wait for 10 ns;
100 18 earlz
    WriteWord <= '0';
101
    WriteEnable <= '0';
102 37 earlz
    Address <= x"0111";
103 4 earlz
    wait for 10 ns;
104 18 earlz
    assert (DataOut = x"0012") report "unaligned 8-bit memory read is wrong" severity error;
105
    WriteWord <='0';
106
    WriteEnable <= '1';
107
    DataIn <= x"0056";
108 4 earlz
    wait for 10 ns;
109 18 earlz
    WriteEnable <= '0';
110 4 earlz
    wait for 10 ns;
111 18 earlz
    assert (DataOut = x"0056") report "unaligned 8 bit memory write and then read is wrong" severity error;
112 37 earlz
    Address <= x"0110";
113 4 earlz
    wait for 10 ns;
114 18 earlz
    assert (DataOut = x"5634") report "aligned memory read after unaligned write is wrong" severity error;
115
    WriteEnable <= '1';
116
    DataIn <= x"0078";
117
    wait for 10 ns;
118
    WriteEnable <= '0';
119
    wait for 10 ns;
120
    assert (DataOut = x"5678") report "aligned 8-bit memory write is wrong" severity error;
121 41 earlz
 
122
    Address <= x"0001";
123
    Port0 <= "ZZZZZZ1Z";
124
    WriteWord<='0';
125
    WriteEnable <= '1';
126
    DataIn <= x"0001";
127
    wait for 10 ns;
128
    WriteEnable <= '0';
129
    Address <= x"1234";
130
    wait for 20 ns;
131
    WriteEnable <= '1';
132
    Address <= x"0000";
133
    DataIn <= x"0001";
134
 
135
    wait for 10 ns;
136
    WriteEnable <= '0';
137
    assert(Port0(0)='1') report "port0 not right 1" severity error;
138
    wait for 10 ns;
139
    assert(DataOut(1)='1') report "port0 not right 2" severity error;
140 4 earlz
 
141 41 earlz
 
142
    wait for 10 ns;
143 37 earlz
    Address <= x"0001";
144
    WriteWord <= '0';
145
    WriteEnable <= '1';
146
    DataIn <= b"00000000_0011_1000";
147
    wait for 10 ns;
148
    Address <= x"0000";
149
    Port0 <= "10ZZZ101";
150
    DataIn <= x"00" & b"00_101_011";
151
    wait for 10 ns;
152
    WriteEnable <= '0';
153
    wait for 10 ns;
154
    assert(Port0 = "10101101") report "Memory mapped port does not work correctly" severity error;
155
    assert(DataOut = x"00" & "10101101") report "Memory read of mapped port does not work correctly" severity error;
156
 
157
 
158 4 earlz
   assert false
159
   report "Testbench of memory completed successfully!"
160
   severity note;
161
 
162
    wait;
163
 
164
    -- insert stimulus here 
165
 
166
    wait;
167
  end process;
168
 
169
 
170
END;

powered by: WebSVN 2.1.0

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