-
Notifications
You must be signed in to change notification settings - Fork 18
/
complex_num_tb.v
128 lines (82 loc) · 2.54 KB
/
complex_num_tb.v
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
`define assert(signal, value) if ((signal) !== (value)) begin $display("ASSERTION FAILED in %m: signal != value"); $finish(1); end
`define POSEDGE #1 clk = 0; #1 clk = 1;
module test();
reg clk;
reg rst;
wire valid;
// Depth 16, width 32 RAM
wire [3:0] raddr;
wire [3:0] waddr;
wire [63:0] wdata;
wire [0:0] wen;
reg [3:0] debug_addr;
wire [63:0] debug_data;
reg [3:0] debug_write_addr;
reg [63:0] debug_write_data;
reg debug_write_en;
wire [63:0] rdata;
reg [63:0] expected;
initial begin
#1 expected = {32'd2 + 32'd7, 32'd8 + 32'd9};
#1 rst = 1;
#1 debug_write_en = 1;
#1 debug_write_addr = 0;
#1 debug_write_data = {32'd2, 32'd8};
`POSEDGE
#1 debug_write_en = 1;
#1 debug_write_addr = 1;
#1 debug_write_data = {32'd7, 32'd9};
`POSEDGE
#1 debug_write_en = 0;
#1 debug_addr = 3;
#1 clk = 0;
#1 rst = 1;
#1 clk = 1;
// In global state 0
#1 `assert(debug_data, 64'hxxxxxxxx)
#1 `assert(valid, 1'd0)
#1 rst = 0;
#1 clk = 0;
#1 clk = 1;
// In global state 1
#1 `assert(debug_data, 64'hxxxxxxxx)
#1 `assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
// In global state 2
#1 `assert(debug_data, 64'hxxxxxxxx)
#1 `assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
// In global state 3
`POSEDGE
#1 $display("debug_data = %b", debug_data);
// gs 4
`POSEDGE
// gs 5, done
#1 $display("debug_data = %b", debug_data);
#1 `assert(valid, 1'd1)
#1 `assert(debug_data, expected)
`POSEDGE
`POSEDGE
`POSEDGE
#1 clk = 0;
#1 clk = 1;
// #1 `assert(debug_data, expected)
#1 `assert(valid, 1'd1)
#1 $display("Passed");
end
RAM #(.WIDTH(64), .DEPTH(16)) mem(.clk(clk),
.rst(rst),
.raddr_0(raddr),
.rdata_0(rdata),
.wen_0(wen),
.wdata_0(wdata),
.waddr_0(waddr),
.debug_addr(debug_addr),
.debug_data(debug_data),
.debug_write_addr(debug_write_addr),
.debug_write_data(debug_write_data),
.debug_write_en(debug_write_en));
complex_num ss(.clk(clk), .rst(rst), .valid(valid), .ram_waddr_0(waddr), .ram_wdata_0(wdata), .ram_wen_0(wen), .ram_raddr_0(raddr), .ram_rdata_0(rdata));
endmodule