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

Subversion Repositories mmu180

[/] [mmu180/] [trunk/] [vsourc/] [mmu180_Testbench.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 beattidp
/** @package zGlue
2
 
3
    @file mmu180_Testbench.v
4
 
5
    @brief Test Bench for Memory Management Unit to mimic Z180.
6
 
7
<BR>Simplified (2-clause) BSD License
8
 
9
Copyright (c) 2012, Douglas Beattie Jr.
10
All rights reserved.
11
 
12
Redistribution and use in source and hardware/binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
14
 
15
1. Redistributions of source code must retain the above copyright notice,
16
   this list of conditions and the following disclaimer.
17
 
18
2. Redistributions in hardware/binary form must reproduce the above
19
   copyright notice, this list of conditions and the following disclaimer in
20
   the documentation and/or other materials provided with the distribution.
21
 
22
THIS RTL SOURCE IS PROVIDED BY DOUGLAS BEATTIE JR. "AS IS" AND ANY
23
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
DISCLAIMED. IN NO EVENT SHALL DOUGLAS BEATTIE JR. BE LIABLE FOR ANY
26
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31
THIS RTL SOURCE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 
33
    Author: Douglas Beattie
34
    Created on: 4/20/2012 8:52:31 PM
35
        Last change: DBJR 4/26/2012 7:49:24 PM
36
*/
37
`timescale 1ns / 100ps
38
 
39
/* iverilog -o mytest ioport.v mmu180.v mmu180_Testbench.v */
40
/* vvp mytest */
41
 
42
module mmu180_Testbench;
43
    // Inputs
44
    reg RST;
45
    reg EN;
46
    reg IORQ;
47
    reg MREQ;
48
    reg PHI;
49
    reg RD;
50
    reg WR;
51
    reg [23:0] A_in; // address bus input
52
    wire [19:12] A_out; // address bus output
53
    wire [23:0] addr_out_all;
54
 
55
    assign addr_out_all = {A_in[23:20],A_out,A_in[11:0]};
56
 
57
    //reg /*inout*/ [7:0]  D; // data bus, di-directional
58
    wire  [7:0]  D; // data bus output
59
 
60
    reg [7:0] D_in;  // data bus input stimulus
61
 
62
    wire [7:0] D_out; // data bus observed output
63
 
64
    assign D_out = (! RD) ? D : 8'bz;
65
 
66
    assign D = (! WR) ? D_in : 8'bz;
67
 
68
`define CBR_IO_ADDR     16'h0038  // Common Bank Register
69
`define BBR_IO_ADDR     16'h0039  // Bank Base Register
70
`define CBAR_IO_ADDR    16'h003A  // Common/Bank Address Register
71
 
72
wire cbar_hinyb, cbar_lonyb;
73
 
74
/** ***************************************************************
75
    Read Port
76
 */
77
task read_port;
78
input [15:0] port_addr;
79
begin
80
    $display("Read port (0x%h)", port_addr);
81
    // Read back from port address
82
    #1 MREQ <= 1; #1 IORQ<=0;
83
    #3 RD<=0;
84
    #2 A_in<={8'h0, port_addr};
85
    wait (PHI==1'b0);
86
    //#100  PHI <= 0; // -----------------------------------
87
    wait (PHI==1'b1);
88
    //#350  PHI <= 0; // -----------------------------------
89
    #1  RD<=1;
90
    #1  IORQ<=1; #1 MREQ <= 1;
91
 
92
end
93
endtask
94
 
95
/** ***************************************************************
96
    Write Port
97
 */
98
task write_port;
99
input [15:0] port_addr;
100
input [7:0]  port_data;
101
begin
102
    $display("Write port (0x%h) <= 0x%h", port_addr, port_data);
103
    #1  MREQ <= 1; #1 IORQ<=0;
104
    #2  A_in<={8'h0, port_addr};
105
    wait (PHI==1'b0);
106
    //#100  PHI <= 0; // -----------------------------------
107
    #3  D_in <= port_data;
108
    #2  WR<=0;
109
    wait (PHI==1'b1);
110
    //#100  PHI <= 1; // -----------------------------------
111
    #1  WR<=1;
112
    #1  IORQ<=1; #1 MREQ <= 1;
113
end
114
endtask
115
 
116
/** ***************************************************************
117
    Insertion of one wait state, meant to be inserted after
118
        the first falling edge of PHI in each memory access cycle.
119
 */
120
task add_one_WAIT_state;
121
begin
122
    wait (PHI==1'b1); wait (PHI==1'b0);
123
end
124
endtask
125
 
126
/** ***************************************************************
127
    Memory Access
128
 */
129
task mem_access;
130
input [23:0] mem_addr;
131
begin
132
    #1  IORQ<=1; #1 MREQ <= 0;
133
    #3 RD<=0;
134
    #2  A_in<=mem_addr;
135
    wait (PHI==1'b0);
136
    add_one_WAIT_state();
137
    wait (PHI==1'b1);
138
    #1  RD<=1;
139
    #1  MREQ <= 1; #1 IORQ<=1;
140
end
141
endtask
142
 
143
/** ***************************************************************
144
    Default block of verification addresses, composite Memory Access
145
 */
146
task try_default_mem_values;
147
begin
148
    $display("Try Default Memory Values...");
149
    mem_access(24'h000100);
150
    mem_access(24'h001100);
151
    mem_access(24'h001500);
152
    mem_access(24'h003500);
153
    mem_access(24'h005122);
154
    mem_access(24'h00C155);
155
    mem_access(24'h02C155);
156
    mem_access(24'h00F155);
157
    mem_access(24'h01F155);
158
end
159
endtask
160
 
161
 
162
    // Instantiate the Unit Under Test (UUT)
163
    mmu180 uut (
164
        .reset_n(RST),
165
        .en(EN),
166
        .iorq_n(IORQ),
167
        .mreq_n(MREQ),
168
        .rd_n(RD),
169
        .wr_n(WR),
170
        .phi(PHI),
171
        .addr_in(A_in),
172
        .dq(D),
173
        .addr_out(A_out),
174
        .cbar_hinyb(cbar_hinyb),
175
        .cbar_lonyb(cbar_lonyb)
176
        );
177
 
178
/**  Clock runs continuously, 20ns period (50_MHz)
179
*/
180
always
181
  #10 PHI <= !PHI;  // 10ns half-cycle
182
 
183
 
184
initial begin
185
 
186
    A_in <= 24'h000000;
187
    D_in <= 8'h00;
188
    RST <= 0;
189
    EN <= 1;
190
    IORQ <= 1;
191
    MREQ <= 0;
192
    RD <= 1;
193
    WR <= 1;
194
    PHI <= 0;
195
 
196
    #5  RST <= 1;// PHI <= 1;
197
 
198
    $display("Initial Read default reset value of CBAR");
199
    read_port(`CBAR_IO_ADDR);
200
 
201
    $display("Write port to set up CBAR=0x%h", 8'hC4);
202
    write_port(`CBAR_IO_ADDR,8'hC4);
203
 
204
    $display("Read-back/verify CBAR");
205
    read_port(`CBAR_IO_ADDR);
206
 
207
    try_default_mem_values();
208
 
209
    $display("Write port to set up BBR=0x%h", 8'h55);
210
    write_port(`BBR_IO_ADDR,8'h55);
211
 
212
    $display("Read-back/verify BBR");
213
    read_port(`BBR_IO_ADDR);
214
 
215
    try_default_mem_values();
216
 
217
    $display("Write port to set up CBR=0x%h", 8'h77);
218
    write_port(`CBR_IO_ADDR,8'h77);
219
 
220
    $display("Read-back/verify CBR");
221
    read_port(`CBR_IO_ADDR);
222
 
223
 
224
    try_default_mem_values();
225
 
226
    $display("Disabled MREQ -- all addresses should be pass-through");
227
    // disable MREQ
228
    #1  MREQ <= 1; IORQ<=1;
229
    #1  A_in<=24'h003500; wait (PHI==1'b0); wait (PHI==1'b1);
230
    #1  A_in<=24'h005122; wait (PHI==1'b0); wait (PHI==1'b1);
231
    #1  A_in<=24'h00C155; wait (PHI==1'b0); wait (PHI==1'b1);
232
    #1  A_in<=24'h02C155; wait (PHI==1'b0); wait (PHI==1'b1);
233
    #1  A_in<=24'h00F155; wait (PHI==1'b0); wait (PHI==1'b1);
234
    #1  A_in<=24'h01F155; wait (PHI==1'b0); wait (PHI==1'b1);
235
 
236
 
237
//@TODO write to bogus address, then read all valid ports,
238
//      to verify the value was not accepted.
239
/*
240
    // Write to bogus port address
241
    #500  MREQ <= 1; IORQ<=0;
242
    #500  A_in<={8'h0, 16'h0037;
243
    #250  WR<=0; D_in <= 8'h33;
244
    #250  WR<=1;
245
    #250  IORQ<=1;
246
    #250  A<=0;
247
*/
248
 
249
    $finish;
250
end
251
 
252
initial begin
253
    // console dump, for verification
254
    $monitor("time=",$time,,
255
/*
256
    "RST=%b IORQ=%b MREQ=%b PHI=%b RD=%b WR=%b A_in=%h A_out=%h addr_out_all=%h D_in=%h D=%h D_out=%h cbar_hinyb=%b, cbar_lonyb=%b",
257
     RST,   IORQ,   MREQ,    PHI,  RD,   WR,   A_in,   A_out, addr_out_all,   D_in,   D, D_out, cbar_hinyb, cbar_lonyb);
258
*/  //omit PHI for cleaner output
259
    "RST=%b IORQ=%b MREQ=%b RD=%b WR=%b A_in=%h A_out=%h addr_out_all=%h D_in=%h D=%h D_out=%h cbar_hinyb=%b, cbar_lonyb=%b",
260
     RST,   IORQ,   MREQ,   RD,   WR,   A_in,   A_out, addr_out_all,   D_in,   D, D_out, cbar_hinyb, cbar_lonyb);
261
 
262
end
263
 
264
endmodule
265
 

powered by: WebSVN 2.1.0

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