1
0
forked from tanchou/Verilog
Files
Verilog_Louis/Semaine_4/UART/tests/verilog/tb_uart_tx.v

77 lines
1.8 KiB
Coq
Raw Normal View History

2025-05-02 15:51:18 +02:00
`timescale 1ns/1ps
module tb_uart_tx;
reg clk = 0;
reg tx_enable = 0;
reg [7:0] data_in = 8'h00;
reg [7:0] data_out;
2025-05-02 15:51:18 +02:00
wire tx;
reg tx_ready;
wire rx_recieved;
2025-05-02 15:51:18 +02:00
always #18.5 clk = ~clk;
2025-05-05 09:51:23 +02:00
other_uart_rx rx_instance(
.clk(clk),
.rx_pin(tx), // tx is connected to rx for testing
.rst_n(1'b1),
.rx_data(data_out),
.rx_data_valid(rx_recieved),
.rx_data_ready(1'b1)
);
2025-05-02 15:51:18 +02:00
uart_tx #(
.CLK_FREQ(27_000_000),
.BAUD_RATE(115_200)
)tx_instance (
.clk(clk),
.tx_enable(tx_enable),
.tx_ready(tx_ready),
.data(data_in),
2025-05-02 15:51:18 +02:00
.tx(tx),
.rst_p(1'b0)
2025-05-02 15:51:18 +02:00
);
initial begin
$dumpfile("runs/uart_tx.vcd");
2025-05-02 15:51:18 +02:00
$dumpvars(0, tb_uart_tx);
2025-05-05 09:51:23 +02:00
$display("======== Start UART TX test =========");
2025-05-02 15:51:18 +02:00
#100;
data_in <= 8'd234; // 234
tx_enable <= 1;
wait(tx_ready == 1'b0);
tx_enable <= 0;
2025-05-02 15:51:18 +02:00
// Attendre
wait (rx_recieved == 1'b1); // Attendre que le signal de reception soit actif
$display("Data received: %d", data_out); // Afficher la valeur recu
$display("Data expected: %d", data_in); // Afficher la valeur envoyee
2025-05-02 15:51:18 +02:00
#1000;
wait(tx_ready == 1'b1); // Attendre que le signal de reception soit actif
data_in <= 8'd202; // 202
tx_enable <= 1;
wait(tx_ready == 1'b0);
tx_enable <= 0;
// Attendre
wait (rx_recieved == 1'b1); // Attendre que le signal de reception soit actif
2025-05-02 15:51:18 +02:00
$display("Data received: %d", data_out); // Afficher la valeur recu
$display("Data expected: %d", data_in); // Afficher la valeur envoyee
2025-05-02 15:51:18 +02:00
2025-05-05 09:51:23 +02:00
$display("======== END UART TX test =========");
2025-05-02 15:51:18 +02:00
#1000;
$stop;
end
endmodule