Created
June 28, 2021 22:08
-
-
Save olofk/e91fba2572396f55525f8814f05fb33d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module corescore_emitter_uart | |
#( | |
parameter clk_freq_hz = 0, | |
parameter baud_rate = 57600) | |
( | |
input wire i_clk, | |
input wire i_rst, | |
input wire [7:0] i_data, | |
input wire i_valid, | |
output reg o_ready, | |
output wire o_uart_tx); | |
localparam START_VALUE = clk_freq_hz/baud_rate; | |
localparam WIDTH = $clog2(START_VALUE); | |
reg [WIDTH:0] cnt; | |
reg [9:0] data; | |
assign o_uart_tx = data[0] | !(|data); | |
always @(posedge i_clk) begin | |
if (cnt[WIDTH] & !(|data)) | |
o_ready <= 1'b1; | |
else if (i_valid & o_ready) | |
o_ready <= 1'b0; | |
if (o_ready | cnt[WIDTH]) | |
cnt <= {1'b0,START_VALUE[WIDTH-1:0]}; | |
else | |
cnt <= cnt-1; | |
if (cnt[WIDTH]) | |
data <= {1'b0, data[9:1]}; | |
else if (i_valid & o_ready) | |
data <= {1'b1, i_data, 1'b0}; | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Olof,
I've modified the not a bit:
Do you think that is OK?