mirror of
https://github.com/openhwgroup/cva6.git
synced 2025-04-20 12:17:19 -04:00
Fix uart time precision problem
This commit is contained in:
parent
26fde6e49e
commit
23b7740d74
1 changed files with 18 additions and 29 deletions
|
@ -14,15 +14,15 @@
|
|||
// A string is printed to the console as soon as a '\n' character is found
|
||||
|
||||
interface uart_bus #(
|
||||
parameter BAUD_RATE = 115200,
|
||||
parameter PARITY_EN = 0
|
||||
parameter int unsigned BAUD_RATE = 115200,
|
||||
parameter int unsigned PARITY_EN = 0
|
||||
)(
|
||||
input logic rx,
|
||||
output logic tx,
|
||||
input logic rx_en
|
||||
);
|
||||
|
||||
localparam BIT_PERIOD = (1000000000/BAUD_RATE*1000);
|
||||
localparam time BIT_PERIOD = (1000000000 / BAUD_RATE) * 1ns;
|
||||
|
||||
logic [7:0] character;
|
||||
logic [256*8-1:0] stringa;
|
||||
|
@ -30,35 +30,28 @@ interface uart_bus #(
|
|||
integer charnum;
|
||||
integer file;
|
||||
|
||||
initial
|
||||
begin
|
||||
initial begin
|
||||
tx = 1'bZ;
|
||||
file = $fopen("stdout/uart", "w");
|
||||
end
|
||||
|
||||
always
|
||||
begin
|
||||
if (rx_en)
|
||||
begin
|
||||
always begin
|
||||
if (rx_en) begin
|
||||
@(negedge rx);
|
||||
#(BIT_PERIOD/2) ;
|
||||
for (int i=0;i<=7;i++)
|
||||
begin
|
||||
#(BIT_PERIOD/2);
|
||||
for (int i = 0; i <= 7; i++) begin
|
||||
#BIT_PERIOD character[i] = rx;
|
||||
end
|
||||
|
||||
if(PARITY_EN == 1)
|
||||
begin
|
||||
if (PARITY_EN == 1) begin
|
||||
// check parity
|
||||
#BIT_PERIOD parity = rx;
|
||||
|
||||
for (int i=7;i>=0;i--)
|
||||
begin
|
||||
for (int i=7;i>=0;i--) begin
|
||||
parity = character[i] ^ parity;
|
||||
end
|
||||
|
||||
if(parity == 1'b1)
|
||||
begin
|
||||
if (parity == 1'b1) begin
|
||||
$display("Parity error detected");
|
||||
end
|
||||
end
|
||||
|
@ -68,24 +61,20 @@ interface uart_bus #(
|
|||
|
||||
$fwrite(file, "%c", character);
|
||||
stringa[(255-charnum)*8 +: 8] = character;
|
||||
if (character == 8'h0A || charnum == 254) // line feed or max. chars reached
|
||||
begin
|
||||
if (character == 8'h0A)
|
||||
if (character == 8'h0A || charnum == 254) begin // line feed or max. chars reached
|
||||
if (character == 8'h0A) begin
|
||||
stringa[(255-charnum)*8 +: 8] = 8'h0; // null terminate string, replace line feed
|
||||
else
|
||||
end else begin
|
||||
stringa[(255-charnum-1)*8 +: 8] = 8'h0; // null terminate string
|
||||
end
|
||||
|
||||
$write("RX string: %s\n",stringa);
|
||||
$write("[UART]: %s\n", stringa);
|
||||
charnum = 0;
|
||||
stringa = "";
|
||||
end
|
||||
else
|
||||
begin
|
||||
end else begin
|
||||
charnum = charnum + 1;
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
end else begin
|
||||
charnum = 0;
|
||||
stringa = "";
|
||||
#10;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue