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

Subversion Repositories oks8

[/] [oks8/] [trunk/] [rtl/] [verilog/] [oks8_tb.v] - Blame information for rev 7

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

Line No. Rev Author Line
1 7 kongzilee
//                              -*- Mode: Verilog -*-
2
// Filename        : oks8_tb.v
3
// Description     : OKS8 CPU Simulation using model RAM/ROM
4
// Author          : Jian Li
5
// Created On      : Sat Jan 07 09:09:49 2006
6
// Last Modified By: .
7
// Last Modified On: .
8
// Update Count    : 0
9
// Status          : Unknown, Use with caution!
10
 
11
/*
12
 * Copyright (C) 2006 to Jian Li
13
 * Contact: kongzilee@yahoo.com.cn
14
 *
15
 * This source file may be used and distributed without restriction
16
 * provided that this copyright statement is not removed from the file
17
 * and that any derivative works contain the original copyright notice
18
 * and the associated disclaimer.
19
 *
20
 * THIS SOFTWARE IS PROVIDE "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
21
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
23
 * SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGE.
31
 */
32
 
33
`include "oks8_defines.v"
34
`include "oks8.v"
35
 
36
// synopsys translate_off
37
`timescale 1ns / 10ps
38
// synopsys translate_on
39
 
40
// =====================================================================
41
// OKS8 CPU SIMULATION
42
// This is only for simulation purposes. It can be used to simulate
43
// RTL and also Gate Level Netlist. 
44
//
45
// All ROM codes should be loaded from a file named "oks8sim.rom".
46
//
47
// =====================================================================
48
module oks8_tb ();
49
 
50
  parameter iw = `W_INST;
51
 
52
  reg clk_i, rst_i, int_i;
53
 
54
  wire clk_o;
55
  wire ien_o;
56
  wire den_o;
57
  wire we_o;
58
  wire rst_o;
59
  wire [15:0] add_o;
60
  wire [7:0] dat_i, dat_o;
61
 
62
  oks8  mcu0 (/*AUTOINST*/
63
        // Outputs
64
        .rst_o          (rst_o),
65
        .clk_o          (clk_o),
66
        .ien_o          (ien_o),
67
        .den_o          (den_o),
68
        .we_o           (we_o),
69
        .add_o          (add_o),
70
        .dat_o          (dat_o),
71
        // Inputs
72
        .rst_i          (rst_i),
73
        .clk_i          (clk_i),
74
        .int_i          (int_i),
75
        // Inputs
76
        .dat_i          (dat_i)
77
        );
78
 
79
  ex_mem imem(/*AUTOINST*/
80
        .clk            (clk_o),
81
        .address        (add_o[iw-1:0]),
82
        .en                     (ien_o),
83
        .we                     (we_o),
84
        .din            (dat_o),
85
        .dout           (dat_i)
86
        );
87
 
88
  ex_mem dmem(/*AUTOINST*/
89
        .clk            (clk_o),
90
        .address        (add_o[iw-1:0]),
91
        .en                     (den_o),
92
        .we                     (we_o),
93
        .din            (dat_o),
94
        .dout           (dat_i)
95
        );
96
 
97
//
98
// SIMULATED CLOCK & RESET
99
//
100
initial begin
101
 
102
  $readmemh("../../sw/oks8sim.rom",imem.mem);
103
 
104
  int_i = 0;
105
  clk_i = 0;
106
  rst_i = 1;
107
 
108
  $display ("time ", $time, " reset ON");
109
  $dumpfile("oks8sim.vcd");
110
  $dumpvars(1, clk_i, rst_i, int_i);
111
  $dumpvars(1, clk_o, rst_o);
112
  $dumpvars(1, add_o, dat_i, dat_o, ien_o, den_o, we_o);
113
  $dumpvars(1, mcu0.s$_clk, mcu0.p$_clk);
114
  $dumpvars(1, mcu0.pow0.idle, mcu0.pow0.stop);
115
  $dumpvars(1, mcu0.dc_final, mcu0.ex_final, mcu0.pc);
116
  $dumpvars(1, mcu0.s$_fen);
117
  $dumpvars(1, mcu0.d0.en_i, mcu0.d0.op, mcu0.d0.fin_o);
118
  $dumpvars(1, mcu0.ex0.en_i, mcu0.ex0.alu, mcu0.ex0.sts);
119
  $dumpvars(1, mcu0.ex0.r1, mcu0.ex0.r1_t, mcu0.ex0.r2, mcu0.ex0.r2_t, mcu0.ex0.r3);
120
  $dumpvars(1, mcu0.ex0.src_finish, mcu0.ex0.dst_finish, mcu0.ex0.ex_final);
121
  $dumpvars(1, mcu0.ex0.skp_o, mcu0.ex0.do_int_);
122
 
123
  $dumpon;
124
 
125
  #40 rst_i = 0;
126
  $display ("time ", $time, " reset OFF");
127
 
128
  #2000 int_i = 1;      // Simulate a interrupt
129
  #100 int_i = 0;
130
 
131
  #3000 rst_i = 0;
132
  $monitoroff;
133
  $display("time ", $time, " End of Bench");
134
  $stop;
135
 
136
end
137
 
138
  always clk_i = #5 ~clk_i;
139
 
140
endmodule       // oks8_tb
141
 
142
// =====================================================================
143
// SIMULATION RAM/ROM
144
// Provides 2K of RAM/ROM Space from 0000h
145
// =====================================================================
146
module ex_mem (/*AUTOARG*/
147
  // Inputs
148
  clk, address, en, we, din,
149
  // Outputs
150
  dout );
151
 
152
parameter ew = `W_INST;
153
parameter depth = 8192;
154
 
155
input                   clk;
156
input [ew-1:0]   address;
157
input                   en;
158
input                   we;
159
input [7:0]              din;
160
output [7:0]     dout;
161
 
162
reg [ew-1:0]     addr_r;
163
reg [7:0]                mem[0:depth-1];
164
 
165
always @(posedge clk)
166
   addr_r <= address;
167
 
168
assign dout = (en) ? mem[addr_r] : `DAT_Z;
169
 
170
always @(posedge clk)
171
   if (en && we) mem[address] <= din;
172
 
173
endmodule       // ex_mem
174
 
175
// =====================================================================

powered by: WebSVN 2.1.0

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