-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestbench.v
More file actions
69 lines (60 loc) · 1.23 KB
/
testbench.v
File metadata and controls
69 lines (60 loc) · 1.23 KB
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
module testbench();
reg [7:0] data = 0;
reg [7:0] prev_data = 0; // Accounting for the delay in UART
reg clk = 0;
reg enable = 0;
wire Tx_busy;
wire rdy;
wire [7:0] Rx_data;
wire loopback;
reg ready_clr = 0;
wire TX2;
wire [7:0] LEDR;
wire rxen, txen;
wire ready;
uart uart1(
.DATA_IN(data),
.WR_EN(enable),
.CLK(clk),
.TX(loopback),
.TX_BUSY(Tx_busy),
.RX(loopback),
.READY(ready),
.READY_CLR(ready_clr),
.DATA_OUT(Rx_data),
.LEDR(LEDR),
.TX2(TX2),
.rxen(rxen),
.txen(txen)
);
initial begin
$dumpfile("uart.vcd");
$dumpvars(0, testbench);
enable <= 1'b1;
#2 enable <= 1'b0;
end
always begin
#1 clk = ~clk;
end
always @(posedge ready)
begin
#2 ready_clr <= 1;
#2 ready_clr <= 0;
if (Rx_data != prev_data)
begin
$display("FAIL: rx data %x does not match tx %x", Rx_data, prev_data);
$finish;
end
else
begin
if (Rx_data == 8'h2)
begin //Check if received data is 11111111
$display("SUCCESS: all bytes verified");
end
prev_data <= data;
data <= data + 1'b1;
enable <= 1'b1;
#2 enable <= 1'b0;
end
end
endmodule