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

Subversion Repositories steelcore

[/] [soc/] [bench/] [tb_ram.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
//////////////////////////////////////////////////////////////////////////////////
2
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com) 
3
// 
4
// Create Date: 05.07.2020 00:20:31
5
// Module Name: tb_ram
6
// Project Name: Steel SoC 
7
// Description: RAM memory array testbench 
8
// 
9
// Dependencies: ram.v
10
// 
11
// Version 0.01
12
// 
13
//////////////////////////////////////////////////////////////////////////////////
14
 
15
/*********************************************************************************
16
 
17
MIT License
18
 
19
Copyright (c) 2020 Rafael de Oliveira Calçada
20
 
21
Permission is hereby granted, free of charge, to any person obtaining a copy
22
of this software and associated documentation files (the "Software"), to deal
23
in the Software without restriction, including without limitation the rights
24
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
copies of the Software, and to permit persons to whom the Software is
26
furnished to do so, subject to the following conditions:
27
 
28
The above copyright notice and this permission notice shall be included in all
29
copies or substantial portions of the Software.
30
 
31
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
SOFTWARE.
38
 
39
********************************************************************************/
40
 
41
`timescale 1ns / 1ps
42
 
43
module tb_ram();
44
 
45
    reg CLK;
46
    reg [10:0] ADDRA;
47
    reg [10:0] ADDRB;
48
    reg [31:0] DINA;
49
    reg [3:0] WEA;
50
    wire [31:0] DOUTA;
51
    wire [31:0] DOUTB;
52
 
53
    ram dut(
54
        .CLK(CLK),
55
        .ADDRA(ADDRA),
56
        .ADDRB(ADDRB),
57
        .DINA(DINA),
58
        .WEA(WEA),
59
        .DOUTA(DOUTA),
60
        .DOUTB(DOUTB)
61
    );
62
 
63
    always
64
    begin
65
        #10 CLK = !CLK;
66
    end
67
 
68
    integer i;
69
 
70
    initial
71
    begin
72
 
73
        $display("Testing RAM by showing its data...");
74
 
75
        CLK = 1'b0;
76
        WEA = 4'b0;
77
        DINA = 32'b0;
78
        #20;
79
        for(i = 0; i < 2048; i = i+1)
80
        begin
81
            ADDRA = i[10:0];
82
            ADDRB = i[10:0];
83
            #20;
84
            $display("Port A - %d: %h", ADDRA, DOUTA);
85
            $display("Port B - %d: %h", ADDRB, DOUTB);
86
        end
87
 
88
        $display("RAM end.");
89
 
90
        $display("Writting word...");
91
 
92
        WEA = 4'b1111;
93
        DINA = 32'hFFFFFFFF;
94
        ADDRA = 10'b0000001010;
95
        #20;
96
 
97
        if(DOUTA != 32'hFFFFFFFF)
98
        begin
99
            $display("FAIL. Check the results.");
100
            $stop;
101
        end
102
 
103
        $display("Writting halfword (upper)...");
104
 
105
        WEA = 4'b1100;
106
        DINA = 32'hEEEEEEEE;
107
        ADDRA = 10'b0000001010;
108
        #20;
109
 
110
        if(DOUTA != 32'hEEEEFFFF)
111
        begin
112
            $display("FAIL. Check the results.");
113
            $stop;
114
        end
115
 
116
        $display("Writting halfword (lower)...");
117
 
118
        WEA = 4'b0011;
119
        DINA = 32'hDDDDDDDD;
120
        ADDRA = 10'b0000001010;
121
        #20;
122
 
123
        if(DOUTA != 32'hEEEEDDDD)
124
        begin
125
            $display("FAIL. Check the results.");
126
            $stop;
127
        end
128
 
129
        $display("Writting byte (msb)...");
130
 
131
        WEA = 4'b1000;
132
        DINA = 32'hCCCCCCCC;
133
        ADDRA = 10'b0000001010;
134
        #20;
135
 
136
        if(DOUTA != 32'hCCEEDDDD)
137
        begin
138
            $display("FAIL. Check the results.");
139
            $stop;
140
        end
141
 
142
        $display("Writting byte (2 msb)...");
143
 
144
        WEA = 4'b0100;
145
        DINA = 32'hBBBBBBBB;
146
        ADDRA = 10'b0000001010;
147
        #20;
148
 
149
        if(DOUTA != 32'hCCBBDDDD)
150
        begin
151
            $display("FAIL. Check the results.");
152
            $stop;
153
        end
154
 
155
        $display("Writting byte (3 msb)...");
156
 
157
        WEA = 4'b0010;
158
        DINA = 32'hAAAAAAAA;
159
        ADDRA = 10'b0000001010;
160
        #20;
161
 
162
        if(DOUTA != 32'hCCBBAADD)
163
        begin
164
            $display("FAIL. Check the results.");
165
            $stop;
166
        end
167
 
168
        $display("Writting byte (4 msb)...");
169
 
170
        WEA = 4'b0001;
171
        DINA = 32'h99999999;
172
        ADDRA = 10'b0000001010;
173
        #20;
174
 
175
        if(DOUTA != 32'hCCBBAA99)
176
        begin
177
            $display("FAIL. Check the results.");
178
            $stop;
179
        end
180
 
181
        $display("RAM seems to work.");
182
 
183
    end
184
 
185
endmodule

powered by: WebSVN 2.1.0

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