-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart_system_tb.sv
More file actions
75 lines (62 loc) · 1.45 KB
/
uart_system_tb.sv
File metadata and controls
75 lines (62 loc) · 1.45 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
70
71
72
73
74
75
module uart_system_tb();
timeunit 1ns;
timeprecision 1ps;
localparam CLK_PERIOD = 20;
logic clk;
initial begin
clk <= 0;
forever begin
#(CLK_PERIOD/2);
clk <= ~clk;
end
end
localparam DATA_WIDTH = 8;
localparam BAUD_RATE = 19200;
localparam BAUD_TIME_PERIOD = 10**9 / BAUD_RATE;
logic rstN,txByteStart,rx;
logic [DATA_WIDTH-1:0]byteForTx;
logic tx,tx_ready,rx_ready,rx_new_byte_indicate;
logic [DATA_WIDTH-1:0]byteFromRx;
uart_system #(.DATA_WIDTH(DATA_WIDTH), .BAUD_RATE(BAUD_RATE)) dut(.*);
///////// initial reset
initial begin
@(posedge clk);
rstN <= 1'b0;
@(posedge clk);
rstN <= 1'b1;
end
///////// Trasmitter test
initial begin
#(CLK_PERIOD*2); // to initialize
repeat(10) begin
@(posedge clk);
wait(tx_ready);
@(posedge clk);
byteForTx = $urandom();
txByteStart = 1'b1;
@(posedge clk);
txByteStart = 1'b0;
end
@(posedge clk);
wait(tx_ready);
$stop;
end
///////// Receier test
initial begin
#(CLK_PERIOD*2); // to initialize
repeat(10) begin
@(posedge clk); //starting delimiter
rx <= 1'b0;
#(BAUD_TIME_PERIOD);
for (int i=0;i<DATA_WIDTH;i++) begin:data //data
@(posedge clk);
rx = $urandom();
#(BAUD_TIME_PERIOD);
end
@(posedge clk); // end delimiter
rx <= 1'b1;
#(BAUD_TIME_PERIOD);
end
$stop;
end
endmodule:uart_system_tb