Skip to content

Commit

Permalink
tb: Defer sim termination until UART transfer is complete (#67)
Browse files Browse the repository at this point in the history
Wait until the current byte has been transmitted before terminating the
simulation. This is bound by the UART baud period x bauds per byte.

Signed-off-by: Nils Wistoff <[email protected]>
  • Loading branch information
niwis committed Sep 6, 2023
1 parent 6c314fa commit 7a2d040
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions target/sim/src/tb_cheshire_soc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module tb_cheshire_soc;
fix.vip.jtag_wait_for_eoc(exit_code);
end

// Wait for the UART to finish reading the current byte
wait (fix.vip.uart_reading_byte == 0);

$finish;
end

Expand Down
10 changes: 7 additions & 3 deletions target/sim/src/vip_cheshire_soc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,19 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
byte_bt uart_boot_byte;
logic uart_boot_ena;
logic uart_boot_eoc;
logic uart_reading_byte;

initial begin
uart_rx = 1;
uart_boot_eoc = 0;
uart_boot_ena = 0;
uart_rx = 1;
uart_boot_eoc = 0;
uart_boot_ena = 0;
uart_reading_byte = 0;
end

task automatic uart_read_byte(output byte_bt bite);
// Start bit
@(negedge uart_tx);
uart_reading_byte = 1;
#(UartBaudPeriod/2);
// 8-bit byte
for (int i = 0; i < 8; i++) begin
Expand All @@ -356,6 +359,7 @@ module vip_cheshire_soc import cheshire_pkg::*; #(
end
// Stop bit
#UartBaudPeriod;
uart_reading_byte=0;
endtask

task automatic uart_write_byte(input byte_bt bite);
Expand Down

0 comments on commit 7a2d040

Please sign in to comment.