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

Subversion Repositories m65c02

[/] [m65c02/] [trunk/] [Sim/] [tb_M65C02.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright 2012-2013 by Michael A. Morris, dba M. A. Morris & Associates
4
//
5
//  All rights reserved. The source code contained herein is publicly released
6
//  under the terms and conditions of the GNU Lesser Public License. No part of
7
//  this source code may be reproduced or transmitted in any form or by any
8
//  means, electronic or mechanical, including photocopying, recording, or any
9
//  information storage and retrieval system in violation of the license under
10
//  which the source code is released.
11
//
12
//  The source code contained herein is free; it may be redistributed and/or 
13
//  modified in accordance with the terms of the GNU Lesser General Public
14
//  License as published by the Free Software Foundation; either version 2.1 of
15
//  the GNU Lesser General Public License, or any later version.
16
//
17
//  The source code contained herein is freely released WITHOUT ANY WARRANTY;
18
//  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
//  PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
20
//  more details.)
21
//
22
//  A copy of the GNU Lesser General Public License should have been received
23
//  along with the source code contained herein; if not, a copy can be obtained
24
//  by writing to:
25
//
26
//  Free Software Foundation, Inc.
27
//  51 Franklin Street, Fifth Floor
28
//  Boston, MA  02110-1301 USA
29
//
30
//  Further, no use of this source code is permitted in any form or means
31
//  without inclusion of this banner prominently in any derived works. 
32
//
33
//  Michael A. Morris
34
//  Huntsville, AL
35
//
36
///////////////////////////////////////////////////////////////////////////////
37
 
38
`timescale 1ns / 1ps
39
 
40
////////////////////////////////////////////////////////////////////////////////
41
// Company:         M. A. Morris & Associates
42
// Engineer:        Michael A. Morris
43
//
44
// Create Date:     15:34:45 02/22/2013
45
// Design Name:     M65C02
46
// Module Name:     C:/XProjects/ISE10.1i/M65C02/tb_M65C02.v
47
// Project Name:    M65C02
48
// Target Device:   Xilinx Spartan-3A FPGA - XC3S50A-4VQ100
49
// Tool versions:   ISE 10.1i SP3  
50
//
51
// Description: 
52
//
53
// Verilog Test Fixture created by ISE for module: M65C02
54
//
55
// Dependencies:
56
// 
57
// Revision:
58
//
59
//  0.01    13B22   MAM     File Created
60
//
61
//  1.00    14B24   MAM     Initial release
62
//
63
//  1.10    13B26   MAM     Changed to support M65C02 with internal 2kB Boot ROM    
64
//
65
// Additional Comments:
66
// 
67
////////////////////////////////////////////////////////////////////////////////
68
 
69
module tb_M65C02;
70
 
71
parameter pRAM_AddrWidth = 14;
72
parameter pSim_Loop      = 16'h0400;
73
 
74
// UUT Signal Declarations
75
 
76
reg     nRst;
77
tri1    nRstO;
78
 
79
reg     ClkIn;
80
 
81
wire    Phi1O;
82
wire    Phi2O;
83
 
84
tri1    nSO;
85
tri1    nNMI;
86
tri1    nIRQ;
87
tri1    nVP;
88
 
89
reg     BE_In;
90
tri1    Rdy;
91
tri0    Sync;
92
tri1    nML;
93
wire    nWait;
94
 
95
tri1    [3:0] nCE;
96
tri1    RnW;
97
tri1    nOE;
98
tri1    nWr;
99
tri1    [ 3:0] XA;
100
tri1    [15:0] A;
101
tri1    [ 7:0] DB;
102
 
103
wire    [4:0] LED;
104
 
105
//  Define simulation variables
106
 
107
reg     Sim_nSO, Sim_nNMI, Sim_nIRQ;
108
reg     [ 7:0] TestNum;
109
reg     [17:0] chkdad, chkadd;
110
 
111
integer cycle_cnt = 0;
112
integer instr_cnt = 0;
113
 
114
integer Loop_Start = 0;
115
 
116
integer Hist_File = 0;          // File handle for instruction histogram
117
 
118
reg     [31:0] Hist [255:0];    // Instruction Histogram array
119
reg     [31:0] val;             // Instruction Histogram variable
120
reg     [31:0] i, j;            // loop counters
121
 
122
// Instantiate the Unit Under Test (UUT)
123
 
124
M65C02  #(
125 3 MichaelA
            .pBootROM_File("Src/M65C02_Tst5.txt")
126 2 MichaelA
        ) uut (
127
            .nRst(nRst),
128
            .nRstO(nRstO),
129
 
130
            .ClkIn(ClkIn),
131
 
132
            .Phi1O(Phi1O),
133
            .Phi2O(Phi2O),
134
 
135
            .nNMI(nNMI),
136
            .nIRQ(nIRQ),
137
            .nVP(nVP),
138
 
139
            .BE_In(BE_In),
140
            .Sync(Sync),
141
            .nML(nML),
142
 
143
            .nCE(nCE),
144
            .RnW(RnW),
145
            .nOE(nOE),
146 3 MichaelA
            .nWE(nWr),
147 2 MichaelA
            .Rdy(Rdy),
148
            .XA(XA),
149
            .A(A),
150
            .DB(DB),
151
 
152
            .nWP_In(1'b0),
153
 
154 3 MichaelA
            .nWait(nWait),
155
 
156
            .LED(LED)
157 2 MichaelA
 
158 3 MichaelA
//            .LED(LED),
159
//            
160
//            .nSel(nSel), 
161
//            .SCk(SCk), 
162
//            .MOSI(MOSI), 
163
//            .MISO(MISO)
164 2 MichaelA
        );
165
 
166
//  Instantiate RAM Module
167
 
168
wire    [7:0] RAM_DO;
169
reg     RAM_WE;
170
 
171
M65C02_RAM  #(
172
                .pAddrSize(pRAM_AddrWidth),
173
                .pDataSize(8),
174 3 MichaelA
                .pFileName("Src/65C02_FT.txt")
175 2 MichaelA
            ) RAM (
176
                .Clk(~Phi2O),
177
//                .Ext(1'b1),     // 4 cycle memory
178
//                .ZP(1'b0),
179
//                .Ext(1'b0),     // 2 cycle memory
180
//                .ZP(1'b0),
181
                .Ext(1'b0),     // 1 cycle memory
182
                .ZP(1'b1),
183
                .WE(RAM_WE),
184
                .AI(A[(pRAM_AddrWidth - 1):0]),
185
                .DI(DB),
186
                .DO(RAM_DO)
187
            );
188
 
189
initial begin
190
    // Initialize Inputs
191
    nRst     = 0;
192
    ClkIn    = 1;
193
    Sim_nSO  = 0;
194
    Sim_nNMI = 0;
195
    Sim_nIRQ = 0;
196
    BE_In    = 1;
197
    TestNum  = 0;
198
    chkdad   = 0;
199
    chkadd   = 0;
200
 
201
    // Intialize Simulation Time Format
202
 
203
    $timeformat (-9, 3, " ns", 12);
204
 
205
    //  Initialize Instruction Execution Histogram array
206
 
207
    for(cycle_cnt = 0; cycle_cnt < 256; cycle_cnt = cycle_cnt + 1)
208
        Hist[cycle_cnt] = 0;
209
    cycle_cnt = 0;
210
 
211
    Hist_File = $fopen("M65C02_Hist_File.txt", "w");
212
 
213
    // Wait 100 ns for global reset to finish
214
 
215
    #101 nRst = 1;
216
 
217
    // Start the Simulation Loop
218
 
219
    wait(A == pSim_Loop);
220
    @(posedge Phi1O);
221
 
222
    // Test WAI w/ IRQ_Mask set
223
 
224
    fork
225
        begin
226
            @(negedge nWait);
227
            for(i = 0; i < 4; i = i + 1) @(posedge Phi1O);
228
            Sim_nIRQ = 1;
229
            @(posedge nWait);
230
            @(posedge Phi1O) Sim_nIRQ = 0;
231
        end
232
 
233
        begin
234
            while(1) begin
235
                @(posedge Phi1O);
236
                if(A == pSim_Loop) begin
237
                    @(posedge Phi1O);
238
                    @(posedge Phi1O);
239
                    @(posedge Phi1O);
240 3 MichaelA
 
241
                    $display("\n\tTest Loop Complete\n");
242
                    $display("\tEnd of Simulation-Looping to Start detected\n");
243
                    $display("\t\tSuccess - All enabled tests passed.\n");
244
 
245
                    $fclose(Hist_File);
246
 
247 2 MichaelA
                    $stop;
248
                end
249
            end
250
        end
251
    join
252
end
253
 
254
////////////////////////////////////////////////////////////////////////////////
255
//
256
//  Clocks
257
//
258
 
259
//always #20.000 ClkIn = ~ClkIn;
260
//always #27.127 ClkIn = ~ClkIn;
261
always #33.908 ClkIn = ~ClkIn;
262
//always #12.500 ClkIn = ~ClkIn;
263
 
264
////////////////////////////////////////////////////////////////////////////////
265
//
266
//  Test Structures
267
//
268
 
269
always @(posedge nWr)
270
begin
271
    TestNum = ((A == 16'h0200) ? DB : TestNum);
272
end
273
 
274
always @(posedge nOE)
275
begin
276
    chkdad = ((A == 16'h3405) ? (chkdad + 1) : chkdad);
277
end
278
 
279
always @(posedge nOE)
280
begin
281
    chkadd = ((A == 16'h354E) ? (chkadd + 1) : chkadd);
282
end
283
 
284
//  Connect ROM/RAM to M65C02 memory bus
285
 
286
always @(*) RAM_WE <= Phi2O & ~A[15] & ~nWr;
287
 
288
assign DB = ((~nOE) ? RAM_DO : {8{1'bZ}});
289
 
290
//  Generate Simulate nIRQ signal based on writes by test program to address
291
//      0xFFF8 (assert nIRQ) or 0xFFF9 (deassert nIRQ)
292
 
293
always @(posedge nWr or negedge nRstO)
294
begin
295
    if(~nRstO)
296
        Sim_nIRQ <= 0;
297
    else
298
        Sim_nIRQ <= ((A[15:1] == 15'b1111_1111_1111_100) ? ~A[0] : Sim_nIRQ);
299
end
300
 
301
//  Drive nSO, nNMI, and nIRQ using simulation controlled signals
302
 
303
assign nSO  = ((Sim_nSO)  ? 0 : 1'bZ);
304
assign nNMI = ((Sim_nNMI) ? 0 : 1'bZ);
305
assign nIRQ = ((Sim_nIRQ) ? 0 : 1'bZ);
306
 
307
//  Count number of cycles and the number of instructions between between
308
//      0x0210 and the repeat at 0x0210 
309
 
310
always @(posedge uut.ClkGen.Clk)
311
begin
312
    if((uut.ClkGen.Rst | ~uut.ClkGen.nRst))
313
        cycle_cnt = 0;
314 3 MichaelA
    else if(Phi1O & uut.Rdy)
315 2 MichaelA
        cycle_cnt = ((A == 16'h0400) ? 1 : (cycle_cnt + 1));
316
end
317
 
318
always @(posedge uut.ClkGen.Clk)
319
begin
320
    if((uut.ClkGen.Rst | ~uut.ClkGen.nRst))
321
        instr_cnt = 0;
322 3 MichaelA
    else if(Sync & Phi1O & uut.Rdy)
323 2 MichaelA
        instr_cnt = ((A == 16'h0400) ? 1 : (instr_cnt + 1));
324
end
325
 
326
//  Perform Instruction Histogramming for coverage puposes
327
 
328
always @(posedge uut.ClkGen.Clk)
329
begin
330
    if(~(uut.ClkGen.Rst | ~uut.ClkGen.nRst)) begin
331 3 MichaelA
        if(uut.Rdy & uut.uP.CE_IR) begin
332
            if((A == pSim_Loop)) begin
333 2 MichaelA
                if((Loop_Start == 1)) begin
334 3 MichaelA
                    for(i = 0; i < 16; i = i + 1) begin     // lower nibble
335
                        for(j = 0; j < 16; j = j + 1) begin // upper nibble
336 2 MichaelA
                            val = Hist[(j * 16) + i];
337
                            Hist[(j * 16) + i] = 0;
338 3 MichaelA
                            if((j == 0) || (j == 8))
339
                                $fwrite(Hist_File, "\n%h : %d", (j*16)+i, val);
340 2 MichaelA
                            else
341 3 MichaelA
                                $fwrite(Hist_File, " %d", val);
342 2 MichaelA
                        end
343 3 MichaelA
                    end
344 2 MichaelA
                end else begin
345
                    Loop_Start = 1;
346
                end
347
            end
348 3 MichaelA
            val             = Hist[uut.uP.DI];
349
            Hist[uut.uP.DI] = val + 1;
350
        end
351 2 MichaelA
    end
352
end
353
 
354
endmodule
355
 

powered by: WebSVN 2.1.0

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