forked from ZiyangYE/General-Slow-DDR3-Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb.v
144 lines (115 loc) · 2.27 KB
/
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
`timescale 1ns / 1ps
module tb;
reg clk;
wire inv_clk = ~clk;
reg resetn;
//ddr interface
wire [13:0] addr;
wire [2:0] bank;
wire cs;
wire cas;
wire ras;
wire we;
wire clk_p;
wire clk_n;
wire cke;
wire odt;
wire rst_n;
wire [1:0] dm;
wire [15:0] dq;
wire [1:0] dqs_p;
wire [1:0] dqs_n;
//user interface
wire rd_valid;
reg rd_rdy;
wire [15:0] rd_payload;
wire wr_rdy;
reg wr_valid;
wire [15:0] wr_payload;
wire [26:0] address;
wire init_fin;
//counter
reg [15:0] rdwr_cnt;
assign address = {11'd0,rdwr_cnt};
assign wr_payload = rdwr_cnt;
initial begin
clk=0;
resetn=0;
//init user interface
rd_rdy=0;
wr_valid=0;
rdwr_cnt=0;
#10
resetn=1;
//wait unitl init finish
@(init_fin)
wr_valid=1;
//write 32768*16bits
@(rdwr_cnt==32768)
wr_valid=0;
rdwr_cnt=0;
rd_rdy=1;
//read 32768*16bits
@(rdwr_cnt==32768)
rd_rdy=0;
$display("\n\n----------Test Passed----------\n");
$finish();
end
always@(posedge clk)begin
if(wr_rdy || rd_valid)
rdwr_cnt<=rdwr_cnt+1;
if(rd_valid && rdwr_cnt!=rd_payload)begin
$display("\n----------Read Data Error----------");
$display("The read payload is %d, it shoube be %d\n",rd_payload,rdwr_cnt);
$finish();
end
end
always begin
#5 clk=~clk; //5ns period, sys clk is 100MHz
end
ddr3 ddr_module(
.rst_n(rst_n),
.ck(clk_p),
.ck_n(clk_n),
.cke(cke),
.cs_n(cs),
.ras_n(ras),
.cas_n(cas),
.we_n(we),
.dm_tdqs(dm),
.ba(bank),
.addr(addr),
.dq(dq),
.dqs(dqs_p),
.dqs_n(dqs_n),
.odt(odt)
);
slowDDR3 ddr_interface(
.inv_clk(inv_clk),
.phyIO_address(addr),
.phyIO_bank(bank),
.phyIO_cs(cs),
.phyIO_cas(cas),
.phyIO_ras(ras),
.phyIO_we(we),
.phyIO_clk_p(clk_p),
.phyIO_clk_n(clk_n),
.phyIO_cke(cke),
.phyIO_odt(odt),
.phyIO_rst_n(rst_n),
.phyIO_dm(dm),
.phyIO_dq(dq),
.phyIO_dqs_p(dqs_p),
.phyIO_dqs_n(dqs_n),
.sysIO_dataRd_valid(rd_valid),
.sysIO_dataRd_ready(rd_rdy),
.sysIO_dataRd_payload(rd_payload),
.sysIO_dataWr_ready(wr_rdy),
.sysIO_dataWr_valid(wr_valid),
.sysIO_dataWr_payload(wr_payload),
.sysIO_address(address),
.sysIO_initFin(init_fin),
.clk(clk),
.resetn(resetn)
);
endmodule