1
0
forked from tanchou/Verilog

Refactor UART FIFO implementation: update top-level module and integrate RX/TX FIFO functionality

This commit is contained in:
Gamenight77
2025-05-07 09:46:43 +02:00
parent 86d4f5ddd2
commit abef18227c
8 changed files with 75 additions and 62 deletions

View File

@@ -1,65 +1,79 @@
module top_uart_loopback (
module top_uart_loopback_fifo (
input wire clk, // 27 MHz
input wire rx,
output wire tx,
output reg [5:0] leds
);
wire rx_received;
wire [7:0] rx_data;
reg [7:0] tx_data;
reg tx_enable;
wire tx_ready;
// === UART TX ===
reg [7:0] wr_data;
reg wr_en;
wire tx_fifo_full;
wire [7:0] rd_data;
reg rd_en;
wire data_available;
initial begin
leds = 6'b000000; // Initialiser les LEDs à 0
leds = 6'b111111; // Initialiser les LEDs à 0
end
// === UART RX ===
uart_rx uart_rx_inst (
uart_rx_fifo uart_rx_inst (
.clk(clk),
.rst_p(1'b0),
.rx_pin(rx),
.rx_received(rx_received),
.rx_enable(1'b1),
.rx_data(rx_data)
.rd_data(rd_data),
.rd_en(rd_en),
.data_available(data_available)
);
// === UART TX ===
uart_tx uart_tx_inst (
uart_tx_fifo uart_tx_inst (
.clk(clk),
.rst_p(1'b0),
.data(tx_data),
.tx_enable(tx_enable),
.tx_ready(tx_ready),
.tx(tx)
.wr_en(wr_en),
.wr_data(wr_data),
.fifo_full(tx_fifo_full),
.tx_pin(tx)
);
// === FSM pour déclencher la transmission ===
localparam IDLE = 0, SEND = 1;
reg state = IDLE;
localparam IDLE = 0, PREP_READ = 1, READ = 2, WRITE = 3;
reg [1:0] state = IDLE;
always @(posedge clk) begin
// Par défaut
wr_en <= 0;
rd_en <= 0;
// Debug visuel
leds[5] <= rx;
leds[4] <= tx;
leds[3] <= data_available;
leds[2] <= ~fifo_full;
case (state)
IDLE: begin
tx_enable <= 0;
if (rx_received && tx_ready) begin
tx_data <= rx_data;
tx_enable <= 1;
state <= SEND;
leds[0] <= 1;
leds[5:1] <= 0;
if (data_available && !fifo_full) begin
rd_en <= 1; // Mettre rd_en à 1 maintenant
state <= PREP_READ;
end
end
SEND: begin
tx_enable <= 0;
state <= IDLE;
PREP_READ: begin
rd_en <= 1;
state <= READ;
end
leds[0] <= 0; // LED 0 allumée pour indiquer la réception
leds[1] <= 1; // LED 1 éteinte pour indiquer l'attente de transmission
READ: begin
rd_en <= 0;
wr_data <= rd_data;
state <= WRITE;
end
WRITE: begin
wr_en <= 1;
state <= IDLE;
end
endcase
end

View File

@@ -5,7 +5,7 @@ module uart_rx_fifo #(
)(
input clk,
input rd_en,
output reg [7:0] rd_data,
output reg [7:0] rd_data,
input rx_pin,
output data_available
);