aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Matyas <matyas@codasip.com>2020-01-22 08:50:36 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2020-02-15 15:32:53 +0000
commit4882acef80d179628e31ee94e931f8fc2ac2698e (patch)
treed474f1ab2973e58885788e6eff4b3289286cf8b8
parente8c747048fed28edf1900df56e8ffd5ba77b221e (diff)
jtag_vpi: added an option to stop simulation on exit
Command CMD_STOP_SIMU had been defined in jtag_vpi for a long time (since the beginning?) but has not been utilized until now. Its purpose is to signal to the jtag_vpi server (i.e. the RTL simulation software) that the simulation shall be stopped. This commit adds a TCL configuration command that selects whether CMD_STOP_SIMU will be sent to the jtag_vpi server when OpenOCD is about to exit. This functionality is off by default to maintain identical behavior as in previous OpenOCD versions, unless the user enables it explicitly. Change-Id: If3894af6efa61038ccf6c9191f664e2128f2ef11 Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/5407 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/jtag/drivers/jtag_vpi.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c
index e5124b5b..a5a95a5a 100644
--- a/src/jtag/drivers/jtag_vpi.c
+++ b/src/jtag/drivers/jtag_vpi.c
@@ -49,11 +49,15 @@
#define CMD_SCAN_CHAIN_FLIP_TMS 3
#define CMD_STOP_SIMU 4
-int server_port = SERVER_PORT;
-char *server_address;
+/* jtag_vpi server port and address to connect to */
+static int server_port = SERVER_PORT;
+static char *server_address;
-int sockfd;
-struct sockaddr_in serv_addr;
+/* Send CMD_STOP_SIMU to server when OpenOCD exits? */
+static bool stop_sim_on_exit;
+
+static int sockfd;
+static struct sockaddr_in serv_addr;
/* One jtag_vpi "packet" as sent over a TCP channel. */
struct vpi_cmd {
@@ -576,10 +580,28 @@ static int jtag_vpi_init(void)
return ERROR_OK;
}
+static int jtag_vpi_stop_simulation(void)
+{
+ struct vpi_cmd cmd;
+ memset(&cmd, 0, sizeof(struct vpi_cmd));
+ cmd.length = 0;
+ cmd.nb_bits = 0;
+ cmd.cmd = CMD_STOP_SIMU;
+ return jtag_vpi_send_cmd(&cmd);
+}
+
static int jtag_vpi_quit(void)
{
+ if (stop_sim_on_exit) {
+ if (jtag_vpi_stop_simulation() != ERROR_OK)
+ LOG_WARNING("jtag_vpi: failed to send \"stop simulation\" command");
+ }
+ if (close_socket(sockfd) != 0) {
+ LOG_WARNING("jtag_vpi: could not close jtag_vpi client socket");
+ log_socket_error("jtag_vpi");
+ }
free(server_address);
- return close_socket(sockfd);
+ return ERROR_OK;
}
COMMAND_HANDLER(jtag_vpi_set_port)
@@ -609,6 +631,17 @@ COMMAND_HANDLER(jtag_vpi_set_address)
return ERROR_OK;
}
+COMMAND_HANDLER(jtag_vpi_stop_sim_on_exit_handler)
+{
+ if (CMD_ARGC != 1) {
+ LOG_ERROR("jtag_vpi_stop_sim_on_exit expects 1 argument (on|off)");
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ } else {
+ COMMAND_PARSE_ON_OFF(CMD_ARGV[0], stop_sim_on_exit);
+ }
+ return ERROR_OK;
+}
+
static const struct command_registration jtag_vpi_command_handlers[] = {
{
.name = "jtag_vpi_set_port",
@@ -624,6 +657,14 @@ static const struct command_registration jtag_vpi_command_handlers[] = {
.help = "set the address of the VPI server",
.usage = "ipv4_addr",
},
+ {
+ .name = "jtag_vpi_stop_sim_on_exit",
+ .handler = &jtag_vpi_stop_sim_on_exit_handler,
+ .mode = COMMAND_CONFIG,
+ .help = "Configure if simulation stop command shall be sent "
+ "before OpenOCD exits (default: off)",
+ .usage = "<on|off>",
+ },
COMMAND_REGISTRATION_DONE
};