Skip to content

Commit

Permalink
Update lowrisc_ip to lowRISC/opentitan@a78922f14a
Browse files Browse the repository at this point in the history
Update code from upstream repository
https://github.com/lowRISC/opentitan to revision
a78922f14a8cc20c7ee569f322a04626f2ac6127

Signed-off-by: Marno van der Maas <[email protected]>
  • Loading branch information
marnovandermaas committed Dec 10, 2024
1 parent f804cc5 commit 4adc54e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vendor/lowrisc_ip.lock.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
upstream:
{
url: https://github.com/lowRISC/opentitan
rev: 4fe1b8dd1a09af9dbc242434481ae031955dfd85
rev: a78922f14a8cc20c7ee569f322a04626f2ac6127
}
}
21 changes: 19 additions & 2 deletions vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
#include <string.h>
#include <unistd.h>

#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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions vendor/lowrisc_ip/dv/dpi/uartdpi/uartdpi.sv
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4adc54e

Please sign in to comment.