Skip to content

Commit

Permalink
uart: make tx fifo a parameterized option
Browse files Browse the repository at this point in the history
  • Loading branch information
osresearch committed Jun 20, 2019
1 parent 71d67d7 commit f9648b4
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions uart.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


`include "util.v"
`include "fifo.v"

module uart_tx(
input clk,
Expand Down Expand Up @@ -153,22 +154,68 @@ module uart(
);
// todo: rx/tx could share a single clock
parameter DIVISOR = 40; // must be divisible by 4 for rx clock
parameter FIFO = 0;
parameter FREESPACE = 1;

uart_rx #(.DIVISOR(DIVISOR/4)) rx(
.clk(clk),
.reset(reset),
// physical
.serial(serial_rxd),
// logical
.data_strobe(rxd_strobe),
.data(rxd),
);

generate
if(FIFO == 0) begin
wire [7:0] serial_txd_data = txd;
wire serial_txd_ready = txd_ready;
wire serial_txd_strobe = txd_strobe;
end else begin
reg serial_txd_strobe;
wire serial_txd_ready;
wire [7:0] serial_txd_data;

wire fifo_available;
fifo #(
.FREESPACE(FREESPACE),
.NUM(FIFO),
.WIDTH(8),
) tx_fifo(
.clk(clk),
.reset(reset),
// input side to logic
.space_available(txd_ready),
.write_data(txd),
.write_strobe(txd_strobe),
// output side to serial uart
.data_available(fifo_available),
.read_data(serial_txd_data),
.read_strobe(serial_txd_strobe),
);

always @(posedge clk) begin
if (fifo_available
&& serial_txd_ready
&& !serial_txd_strobe
&& !reset)
serial_txd_strobe <= 1;
else
serial_txd_strobe <= 0;
end
end
endgenerate

uart_tx #(.DIVISOR(DIVISOR)) tx(
.clk(clk),
.reset(reset),
// physical
.serial(serial_txd),
.data(txd),
.data_strobe(txd_strobe),
.ready(txd_ready),
// logical
.data(serial_txd_data),
.data_strobe(serial_txd_strobe),
.ready(serial_txd_ready),
);
endmodule

Expand Down

0 comments on commit f9648b4

Please sign in to comment.