forked from nathaliafab/Projeto_IH_RISC-V
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tb_top.sv
63 lines (50 loc) · 1.35 KB
/
tb_top.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
`timescale 1ns / 1ps
module tb_top;
//clock and reset signal declaration
logic tb_clk, reset;
logic [31:0] tb_WB_Data;
logic [4:0] reg_num;
logic [31:0] reg_data;
logic reg_write_sig;
logic wr;
logic rd;
logic [8:0] addr;
logic [31:0] wr_data;
logic [31:0] rd_data;
localparam CLKPERIOD = 10;
localparam CLKDELAY = CLKPERIOD / 2;
localparam NUM_CYCLES = 50;
riscv riscV (
.clk(tb_clk),
.reset(reset),
.WB_Data(tb_WB_Data),
.reg_num(reg_num),
.reg_data(reg_data),
.reg_write_sig(reg_write_sig),
.wr(wr),
.rd(rd),
.addr(addr),
.wr_data(wr_data),
.rd_data(rd_data)
);
initial begin
tb_clk = 0;
reset = 1;
#(CLKPERIOD);
reset = 0;
#(CLKPERIOD * NUM_CYCLES);
$stop;
end
always @(posedge tb_clk) begin : REGISTER
if (reg_write_sig)
$display($time, ": Register [%d] written with value: [%X] | [%d]\n", reg_num, reg_data, $signed(reg_data));
end : REGISTER
always @(posedge tb_clk) begin : MEMORY
if (wr && ~rd)
$display($time, ": Memory [%d] written with value: [%X] | [%d]\n", addr, wr_data, $signed(wr_data));
else if (rd && ~wr)
$display($time, ": Memory [%d] read with value: [%X] | [%d]\n", addr, rd_data, $signed(rd_data));
end : MEMORY
//clock generator
always #(CLKDELAY) tb_clk = ~tb_clk;
endmodule