diff --git a/vendor/lowrisc_ip.lock.hjson b/vendor/lowrisc_ip.lock.hjson index 1b9322b19..e7529c5a0 100644 --- a/vendor/lowrisc_ip.lock.hjson +++ b/vendor/lowrisc_ip.lock.hjson @@ -9,6 +9,6 @@ upstream: { url: https://github.com/lowRISC/opentitan - rev: 4fe1b8dd1a09af9dbc242434481ae031955dfd85 + rev: a78922f14a8cc20c7ee569f322a04626f2ac6127 } } diff --git a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.c b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.c index f99b9da3c..97366a91d 100644 --- a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.c +++ b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.c @@ -19,9 +19,13 @@ #include #include +#define EXIT_MESSAGE_LENGTH (32) + // This keeps the necessary uart state. struct uartdpi_ctx { char ptyname[64]; + char exitstring[EXIT_MESSAGE_LENGTH]; + int exittracker; int host; int device; char tmp_read; @@ -84,6 +88,9 @@ void *uartdpi_create(const char *name, const char *log_file_path) { } } + ctx->exittracker = 0; + strncpy(ctx->exitstring, "Safe to exit simulator.\xd8\xaf\xfb\xa0\xc7\xe1\xa9\xd7", EXIT_MESSAGE_LENGTH); + return (void *)ctx; } @@ -123,11 +130,12 @@ char uartdpi_read(void *ctx_void) { return ctx->tmp_read; } -void uartdpi_write(void *ctx_void, char c) { +// Returns true when simulator should exit. +int uartdpi_write(void *ctx_void, char c) { int rv; struct uartdpi_ctx *ctx = (struct uartdpi_ctx *)ctx_void; if (ctx == NULL) { - return; + return 0; } rv = write(ctx->host, &c, 1); @@ -143,4 +151,13 @@ void uartdpi_write(void *ctx_void, char c) { fprintf(stderr, "UART: Write to log file failed: %s\n", strerror(errno)); } } + + if (c == ctx->exitstring[ctx->exittracker]) { + ctx->exittracker++; + } else { + ctx->exittracker = 0; + } + + // Don't require 0 to be sent at the end. + return ctx->exittracker == (EXIT_MESSAGE_LENGTH - 1); } diff --git a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.h b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.h index 638340789..5e1152c96 100644 --- a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.h +++ b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.h @@ -13,7 +13,7 @@ void *uartdpi_create(const char *name, const char *log_file_path); void uartdpi_close(void *ctx_void); int uartdpi_can_read(void *ctx_void); char uartdpi_read(void *ctx_void); -void uartdpi_write(void *ctx_void, char c); +int uartdpi_write(void *ctx_void, char c); #ifdef __cplusplus } // extern "C" diff --git a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.sv b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.sv index d476c5194..0d46e79e5 100644 --- a/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.sv +++ b/vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.sv @@ -33,7 +33,7 @@ module uartdpi #( int uartdpi_can_read(input chandle ctx); import "DPI-C" function - void uartdpi_write(input chandle ctx, int data); + int uartdpi_write(input chandle ctx, int data); chandle ctx; string log_file_path = DEFAULT_LOG_FILE; @@ -133,7 +133,10 @@ module uartdpi #( if (rxcyccount == CYCLES_PER_SYMBOL - 1) begin rxactive <= 0; if (rx_i) begin - uartdpi_write(ctx, rxsymbol); + if(uartdpi_write(ctx, rxsymbol)) begin + $display("Exiting the Sonata simulator because the magic UART string was seen."); + $exit; + end end end end