From d78e7b8d3d8c6e85ea04aefd61cbf2bd6d628322 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Wed, 6 Mar 2024 19:57:10 +0100 Subject: [PATCH 01/15] Added management of system interrupts while waiting for client connection --- src/vs_server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vs_server.c b/src/vs_server.c index eb1667a..c68e1c2 100644 --- a/src/vs_server.c +++ b/src/vs_server.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "vs_logging.h" #include "vs_server.h" @@ -100,6 +101,7 @@ int vs_server_accept(int fd_socket, char *hostname, const size_t len, int fd_conn_socket = -1; struct hostent *host_info; uint32_t addr; + int selval; /* Use select mechanism uniquely to easily implement a timeout - The vs_server_accept function will keep being blocking until it times out.*/ @@ -108,7 +110,9 @@ int vs_server_accept(int fd_socket, char *hostname, const size_t len, FD_SET(fd_socket, &set); /* If a client attempts a connection, accept it */ - int selval = select(FD_SETSIZE, &set, NULL, NULL, p_timeout); + do + selval = select(FD_SETSIZE, &set, NULL, NULL, p_timeout); + while (0 > selval && EINTR == errno); if (0 > selval) { vs_log_mod_perror("vs_server", ""); goto error; From 944e5839dcc45a4ac5d74771d8029ce12d0f36b9 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Wed, 6 Mar 2024 22:01:44 +0100 Subject: [PATCH 02/15] Added management of multiple trials with delay in client connect method --- examples/hello_world/test_hello_world.py | 3 --- examples/spi_master/test_spi_master.py | 3 --- python/test/test_verisocks.py | 10 ++------ python/verisocks/verisocks.py | 31 +++++++++++++++++++++--- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/hello_world/test_hello_world.py b/examples/hello_world/test_hello_world.py index e1c0a01..c2cdb88 100644 --- a/examples/hello_world/test_hello_world.py +++ b/examples/hello_world/test_hello_world.py @@ -1,7 +1,6 @@ from verisocks.verisocks import Verisocks from verisocks.utils import setup_sim, find_free_port import socket -import time import pytest import logging import os.path @@ -11,7 +10,6 @@ PORT = find_free_port() VS_TIMEOUT = 10 LIBVPI = "../../build/verisocks.vpi" -CONNECT_DELAY = 0.1 def setup_test(): @@ -24,7 +22,6 @@ def setup_test(): f"-DVS_TIMEOUT={VS_TIMEOUT}" ] ) - time.sleep(CONNECT_DELAY) @pytest.fixture diff --git a/examples/spi_master/test_spi_master.py b/examples/spi_master/test_spi_master.py index 3bc5c5c..c5124ae 100644 --- a/examples/spi_master/test_spi_master.py +++ b/examples/spi_master/test_spi_master.py @@ -1,7 +1,6 @@ from verisocks.verisocks import Verisocks from verisocks.utils import setup_sim, find_free_port import os.path -import time import logging import pytest import socket @@ -12,7 +11,6 @@ HOST = socket.gethostbyname("localhost") PORT = find_free_port() LIBVPI = "../../build/verisocks.vpi" # Relative path to this file! -CONNECT_DELAY = 0.01 VS_TIMEOUT = 10 SRC = ["spi_master.v", "spi_slave.v", "spi_master_tb.v"] @@ -29,7 +27,6 @@ def setup_test(): "-DDUMP_FILE=\"spi_master_tb.fst\"" ] ) - time.sleep(CONNECT_DELAY) def send_spi(vs, tx_buffer): diff --git a/python/test/test_verisocks.py b/python/test/test_verisocks.py index f048d62..d78c49a 100644 --- a/python/test/test_verisocks.py +++ b/python/test/test_verisocks.py @@ -1,7 +1,6 @@ from verisocks.verisocks import Verisocks, VerisocksError import subprocess import os.path -import time import shutil import pytest import logging @@ -17,7 +16,6 @@ # Parameters HOST = socket.gethostbyname("localhost") LIBVPI = "../../build/verisocks.vpi" # Relative path to this file! -CONNECT_DELAY = 0.1 VS_TIMEOUT = 2 @@ -81,10 +79,6 @@ def setup_iverilog(port, src_file): pop = subprocess.Popen( cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) print(f"Launched Icarus with PID {pop.pid}") - # Some delay is required for Icarus to launch the Verisocks server before - # being able to connect - Please adjust CONNECT_DELAY if required. - - time.sleep(CONNECT_DELAY) return pop @@ -105,9 +99,9 @@ def test_already_connected(vs, caplog): def test_connect_error(): """Tests trying to connect to a non-running server""" port = find_free_port() - with pytest.raises(ConnectionRefusedError): + with pytest.raises(ConnectionError): vs = Verisocks(HOST, port) - vs.connect() + vs.connect(trials=1) vs.close() diff --git a/python/verisocks/verisocks.py b/python/verisocks/verisocks.py index 347c321..a60e3e8 100644 --- a/python/verisocks/verisocks.py +++ b/python/verisocks/verisocks.py @@ -3,6 +3,7 @@ import struct import json from enum import Enum, auto +from time import sleep class VsRxState(Enum): @@ -72,16 +73,38 @@ def __init__(self, host="127.0.0.1", port=5100, timeout=120.0): self._tx_buffer = b"" self._tx_msg_len = [] - def connect(self): + def connect(self, trials=10, delay=0.05): """Connect to server socket. If the client is already connected to a server socket, nothing happens. + Otherwise, the client attempts to connect to the server as defined by + the address and port provided to the class constructor. The method will + apply a delay prior each connection trial and will retry a number of + times if unsuccessful. + + Args: + trials (int): Maximum number of connection trials + delay (float): Delay to be applied prior each connection trial + + Raises: + ConnectionError if all the successive connection trials are + unsucessful """ if not self._connected: logging.info(f"Attempting connection to {self.address}") - self.sock.connect(self.address) - logging.info("Socket connected") - self._connected = True + trial = 0 + while trial < trials: + try: + sleep(delay) + self.sock.connect(self.address) + logging.info(f"Socket connected after {trial + 1} trials") + self._connected = True + break + except ConnectionError: + trial += 1 + if trial >= trials: + raise ConnectionError( + f"Connection unsucessful after {trial} trials") else: logging.info("Socket already connected") From 3488d71a557595d538a2e77c61c5b44963d184ef Mon Sep 17 00:00:00 2001 From: jchabloz Date: Wed, 6 Mar 2024 22:04:03 +0100 Subject: [PATCH 03/15] Python module version to 1.1.1-dev --- python/verisocks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/verisocks/__init__.py b/python/verisocks/__init__.py index 18199b9..964a098 100644 --- a/python/verisocks/__init__.py +++ b/python/verisocks/__init__.py @@ -1,4 +1,4 @@ """Verisocks Python client API """ -__version__ = "1.1.0" +__version__ = "1.1.1-dev" From 168b9aca61ef7b04de2c701ef41f4a482ee88c3b Mon Sep 17 00:00:00 2001 From: jchabloz Date: Wed, 6 Mar 2024 22:04:48 +0100 Subject: [PATCH 04/15] Updated docs (1.1.1-dev) --- docs/conf.py | 4 ++-- docs/src/release_notes.rst | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index cf2e362..2bebda3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,8 +9,8 @@ project = 'Verisocks' copyright = '2023, Jérémie Chabloz' author = 'Jérémie Chabloz' -version = '1.1.0' -release = '1.1.0' +version = '1.1.1-dev' +release = '1.1.1' # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/src/release_notes.rst b/docs/src/release_notes.rst index f6178a3..00986d0 100644 --- a/docs/src/release_notes.rst +++ b/docs/src/release_notes.rst @@ -8,6 +8,14 @@ Releases of documentation and code are using the same version numbers. The version numbering system follows the `semantic versioning `_ principles. +1.1.1 - Ongoing +*************** + +* Modified :py:meth:`Verisocks.connect() + ` method to include multiple, delayed + connection trials. Examples and test have been simplified accordingly. +* Added correct management of system call interrupts while waiting on client + connection in the server code. 1.1.0 - 2024-02-07 ****************** From 2b9af548bc7af11ac0057f10d8905ebf5916ca2e Mon Sep 17 00:00:00 2001 From: jchabloz Date: Wed, 6 Mar 2024 22:11:09 +0100 Subject: [PATCH 05/15] Corrected docstrings for correct autodoc formatting --- python/verisocks/verisocks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/verisocks/verisocks.py b/python/verisocks/verisocks.py index a60e3e8..380baeb 100644 --- a/python/verisocks/verisocks.py +++ b/python/verisocks/verisocks.py @@ -87,8 +87,8 @@ def connect(self, trials=10, delay=0.05): delay (float): Delay to be applied prior each connection trial Raises: - ConnectionError if all the successive connection trials are - unsucessful + ConnectionError: All the successive connection trials have been + unsucessful """ if not self._connected: logging.info(f"Attempting connection to {self.address}") @@ -116,8 +116,8 @@ def _read(self, timeout=None): base value as defined within the class constructor applies. Raises: - ConnectionError if no data is received (most likely the socket is - closed). + ConnectionError: no data is received (most likely the socket is + closed). """ if timeout: self.sock.settimeout(timeout) @@ -136,8 +136,8 @@ def _write(self, num_bytes, num_trials=10): num_bytes (int): Number of bytes to send Raises: - ConnectionError if no data is written (most likely the socket is - closed). + ConnectionError: no data is written (most likely the socket is + closed). """ sent = 0 trials = 0 From c20f4065113e263073a35ae1f9f2f17a7abf96c3 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Fri, 8 Mar 2024 23:03:13 +0100 Subject: [PATCH 06/15] Added docs target --- Makefile.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 03a98ae..64ee0db 100644 --- a/Makefile.in +++ b/Makefile.in @@ -7,6 +7,7 @@ BUILDDIR = build INCDIRS += $(SRCDIR)/include INCDIRS += $(SRCDIR)/cjson LIBVPI = $(BUILDDIR)/verisocks.vpi +DOCSDIR = docs CC = @CC@ CFLAGS = @CFLAGS@ @@ -45,7 +46,10 @@ $(BUILDDIR)/%.o: %.c @mkdir -p $(BUILDDIR) $(CC) -o $@ -c $(CFLAGS) $< -.PHONY: clean all +.PHONY: clean all docs + +docs: + $(MAKE) -C $(DOCSDIR) html clean: -$(RM) $(OBJS) From d5a9967fc14f2c5f474db0bea6d08877d658b963 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Fri, 8 Mar 2024 23:04:09 +0100 Subject: [PATCH 07/15] Added connect_trials and connect_delay arguments to constructor --- python/verisocks/verisocks.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/python/verisocks/verisocks.py b/python/verisocks/verisocks.py index 380baeb..4e7e76e 100644 --- a/python/verisocks/verisocks.py +++ b/python/verisocks/verisocks.py @@ -37,6 +37,16 @@ class Verisocks: port (int): Server port number, default=5100 timeout (float): Socket timeout (base value), in seconds (default=120) + connect_trials (int): Number of consecutive connections to be attempted + when the method + :py:meth:`connect()` is + being used. This value can be overriden by the method's own + ``trials`` argument. + connect_delay (float): Delay to be applied before attempting a new + connection trial when the method + :py:meth:`connect()` is + being used. This value can be overriden by the method's own + ``delay`` argument. Note: For certain methods, a specific timeout value can be passed as @@ -48,7 +58,8 @@ class Verisocks: PRE_HDR_LEN = 2 # Pre-header length in bytes READ_BUFFER_LEN = 4096 - def __init__(self, host="127.0.0.1", port=5100, timeout=120.0): + def __init__(self, host="127.0.0.1", port=5100, timeout=120.0, + connect_trials=10, connect_delay=0.05): """Verisocks class constructor """ # Connection address and status @@ -60,6 +71,8 @@ def __init__(self, host="127.0.0.1", port=5100, timeout=120.0): if timeout: self._timeout = timeout self.sock.settimeout(timeout) + self.connect_trials = connect_trials + self.connect_delay = connect_delay # RX variables self._rx_buffer = b"" @@ -73,7 +86,7 @@ def __init__(self, host="127.0.0.1", port=5100, timeout=120.0): self._tx_buffer = b"" self._tx_msg_len = [] - def connect(self, trials=10, delay=0.05): + def connect(self, trials=None, delay=None): """Connect to server socket. If the client is already connected to a server socket, nothing happens. @@ -83,24 +96,34 @@ def connect(self, trials=10, delay=0.05): times if unsuccessful. Args: - trials (int): Maximum number of connection trials - delay (float): Delay to be applied prior each connection trial + trials (int): Maximum number of connection trials to be attempted. + If None, the value of the ``connect_trials`` argument passed to + the constructor is being used. + delay (float): Delay to be applied prior each connection trial. If + None, the value of the ``connect_delay`` argument passed to the + constructor is being used. Raises: ConnectionError: All the successive connection trials have been unsucessful """ + + if trials is None: + trials = self.connect_trials + if delay is None: + delay = self.connect_delay + if not self._connected: logging.info(f"Attempting connection to {self.address}") trial = 0 while trial < trials: try: - sleep(delay) self.sock.connect(self.address) logging.info(f"Socket connected after {trial + 1} trials") self._connected = True break except ConnectionError: + sleep(delay) trial += 1 if trial >= trials: raise ConnectionError( From f5c80157ffef8371acb93880cf6f344a7b805275 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Fri, 8 Mar 2024 23:04:53 +0100 Subject: [PATCH 08/15] Updated docs - Alternative simulators + misc --- docs/src/intro.rst | 32 ++++++++++++++++++++++++-------- docs/src/release_notes.rst | 12 ++++++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/docs/src/intro.rst b/docs/src/intro.rst index 6c79e17..897b88c 100644 --- a/docs/src/intro.rst +++ b/docs/src/intro.rst @@ -21,7 +21,7 @@ to trying and compile Verisocks: packaged version provided with your favorite distro. * GCC C or C++ compiler -.. note:: +.. note:: Older GCC versions will most likely complain about the variadic macros used for logging purposes. These warnings can normally be safely ignored... @@ -68,6 +68,11 @@ not to impact your system's Python packages. pip install /python +.. note:: + + The main advantage of Verisock's socket interface is its versatility. The + Python client provided with the code can serve as a reference implementation + that can easily be replicated in any language with an API for TCP sockets. Run the examples ---------------- @@ -138,12 +143,23 @@ have to typically be: variable rising edge), * etc... -.. note:: +.. _sec_alternative_simulators: + +Alternative simulators +********************** - Note that while the Verisocks PLI application has been developed targeting - specifically Icarus as a verilog simulator, there is no known reason that - it would not be working as well with any other simulator that is supporting - the VPI interface standard, including mainstream commercial simulators. I - will gladly accept any contribution that may confirm or infirm this - statement... +While the Verisocks PLI application has been developed targeting specifically +Icarus as a verilog simulator, there is no known reason that it would not be +working as well with any other simulator that is supporting the VPI normative +interface (as defined in `IEEE Std 1364 +`_ and `IEEE Std 1800 +`_), including mainstream +commercial simulators. +.. note:: + I will gladly accept any contribution to test Verisocks with other + simulators. + As of now, I have only successfully tested it with Cadence's XCelium 64 + 29.03. As soon as I get more material, I will make a short tutorial for it. + My next target will be Tachyon's CVC. If anybody is able to test it with + QuestaSim... diff --git a/docs/src/release_notes.rst b/docs/src/release_notes.rst index 00986d0..84d03f2 100644 --- a/docs/src/release_notes.rst +++ b/docs/src/release_notes.rst @@ -11,11 +11,15 @@ version numbering system follows the `semantic versioning 1.1.1 - Ongoing *************** -* Modified :py:meth:`Verisocks.connect() - ` method to include multiple, delayed - connection trials. Examples and test have been simplified accordingly. +* Modified :py:class:`Verisocks` constructor and + :py:meth:`Verisocks.connect() ` method + to include arguments for multiple, delayed connection trials. Examples and + test have been simplified accordingly. * Added correct management of system call interrupts while waiting on client - connection in the server code. + connection in the server code (see + https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html + for details). +* Added section :ref:`sec_alternative_simulators`. 1.1.0 - 2024-02-07 ****************** From 4389ff496993fe33bd460398ee61f37f81743765 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Fri, 8 Mar 2024 23:08:38 +0100 Subject: [PATCH 09/15] Changed version to 1.2.0 instead of 1.1.1 --- docs/conf.py | 4 ++-- docs/src/release_notes.rst | 2 +- python/verisocks/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 2bebda3..bc1c984 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,8 +9,8 @@ project = 'Verisocks' copyright = '2023, Jérémie Chabloz' author = 'Jérémie Chabloz' -version = '1.1.1-dev' -release = '1.1.1' +version = '1.2.0-dev' +release = '1.2.0' # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/src/release_notes.rst b/docs/src/release_notes.rst index 84d03f2..48351dd 100644 --- a/docs/src/release_notes.rst +++ b/docs/src/release_notes.rst @@ -8,7 +8,7 @@ Releases of documentation and code are using the same version numbers. The version numbering system follows the `semantic versioning `_ principles. -1.1.1 - Ongoing +1.2.0 - Ongoing *************** * Modified :py:class:`Verisocks` constructor and diff --git a/python/verisocks/__init__.py b/python/verisocks/__init__.py index 964a098..6d1126e 100644 --- a/python/verisocks/__init__.py +++ b/python/verisocks/__init__.py @@ -1,4 +1,4 @@ """Verisocks Python client API """ -__version__ = "1.1.1-dev" +__version__ = "1.2.0-dev" From 5f450cf7b15f6e5f9f0a86daabfa502b03dcd5d4 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 9 Mar 2024 15:47:30 +0100 Subject: [PATCH 10/15] Corrected args order in docstring and refactored setup_sim() function --- python/verisocks/utils.py | 42 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/python/verisocks/utils.py b/python/verisocks/utils.py index 8da9826..82d2a6d 100644 --- a/python/verisocks/utils.py +++ b/python/verisocks/utils.py @@ -29,6 +29,32 @@ def _format_path(cwd, path): return os.path.abspath(os.path.join(cwd, path)) +def run_setup_cmds(elab_cmd, sim_cmd, capture_output=True): + """ + Args: + capture_output (bool): Defines if stdout and stderr output + are "captured" (i.e. not visible). + + Returns: + subprocess.Popen + """ + + if elab_cmd: + subprocess.check_call(elab_cmd) + + if capture_output: + pop = subprocess.Popen( + sim_cmd, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) + else: + pop = subprocess.Popen(sim_cmd) + + logging.info(f"Launched Icarus with PID {pop.pid}") + return pop + + def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, vvp_logpath="vvp.log", ivl_exec=None, ivl_args=None, vvp_exec=None, vvp_args=None, vvp_postargs=None, @@ -37,11 +63,11 @@ def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, and launching the simulation with :code:`vvp`. Args: - cwd (str): Reference path to be used for all paths provided as relative - paths. vpi_libpath (str): Path to the compiled Verisocks VPI library. src_files (str): Paths to all (verilog) source files to use for the simulation. All files have to be added as separate arguments. + cwd (str): Reference path to be used for all paths provided as relative + paths. vvp_filepath (str): Path to the elaborated VVP file (iverilog output). If None (default), "sim.vvp" will be used. vvp_logpath (str): Path to a simulation logfile. Default="vvp.log". If @@ -95,7 +121,6 @@ def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, *ivl_args, *src_file_paths ] - subprocess.check_call(ivl_cmd) # Simulation with vvp if vvp_exec: @@ -121,14 +146,5 @@ def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, *vvp_postargs ] - if capture_output: - pop = subprocess.Popen( - vvp_cmd, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL - ) - else: - pop = subprocess.Popen(vvp_cmd) - - logging.info(f"Launched Icarus with PID {pop.pid}") + pop = run_setup_cmds(ivl_cmd, vvp_cmd, capture_output) return pop From b1b1c2d0906af2f1b7e9990307cab801a9198f9d Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 9 Mar 2024 17:38:43 +0100 Subject: [PATCH 11/15] Updated docstring --- python/verisocks/utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/verisocks/utils.py b/python/verisocks/utils.py index 82d2a6d..fe91e41 100644 --- a/python/verisocks/utils.py +++ b/python/verisocks/utils.py @@ -30,8 +30,18 @@ def _format_path(cwd, path): def run_setup_cmds(elab_cmd, sim_cmd, capture_output=True): - """ + """Run simulation setup commands. + + This command is e.g. used by :py:meth:`setup_sim` with elaboration and + simulation commands formatted according to the provided arguments. + Args: + elab_cmd (list): Elaboration command. It has to be provided as a list + of command and arguments (see subprocess documentation). If None, + this step is skipped. + sim_cmd (list): Simulation command. It has to be provided as a list + of command and arguments (see subprocess documentation). This + command is mandatory and cannot be None. capture_output (bool): Defines if stdout and stderr output are "captured" (i.e. not visible). @@ -42,6 +52,9 @@ def run_setup_cmds(elab_cmd, sim_cmd, capture_output=True): if elab_cmd: subprocess.check_call(elab_cmd) + if sim_cmd is None: + raise ValueError("Simulation command and arguments is mandatory") + if capture_output: pop = subprocess.Popen( sim_cmd, From 76906d304f00a8a2688ea944ab563c19c7531984 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 16 Mar 2024 02:00:28 +0100 Subject: [PATCH 12/15] Renamed method verisocks.utils.setup_sim_run() --- docs/src/release_notes.rst | 2 ++ python/verisocks/utils.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/src/release_notes.rst b/docs/src/release_notes.rst index 48351dd..93de144 100644 --- a/docs/src/release_notes.rst +++ b/docs/src/release_notes.rst @@ -20,6 +20,8 @@ version numbering system follows the `semantic versioning https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html for details). * Added section :ref:`sec_alternative_simulators`. +* Added method :py:meth:`verisocks.utils.setup_sim_run` to simplify foreseen + support for alternative simulators. 1.1.0 - 2024-02-07 ****************** diff --git a/python/verisocks/utils.py b/python/verisocks/utils.py index fe91e41..e151b15 100644 --- a/python/verisocks/utils.py +++ b/python/verisocks/utils.py @@ -29,7 +29,7 @@ def _format_path(cwd, path): return os.path.abspath(os.path.join(cwd, path)) -def run_setup_cmds(elab_cmd, sim_cmd, capture_output=True): +def setup_sim_run(elab_cmd, sim_cmd, capture_output=True): """Run simulation setup commands. This command is e.g. used by :py:meth:`setup_sim` with elaboration and @@ -73,7 +73,8 @@ def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, vvp_exec=None, vvp_args=None, vvp_postargs=None, capture_output=True): """Set up Icarus simulation by elaborating the design with :code:`iverilog` - and launching the simulation with :code:`vvp`. + and launching the simulation with :code:`vvp`. Uses + :py:meth:`setup_sim_run` to run the concatenated commands and arguments. Args: vpi_libpath (str): Path to the compiled Verisocks VPI library. @@ -159,5 +160,5 @@ def setup_sim(vpi_libpath, *src_files, cwd=".", vvp_filepath=None, *vvp_postargs ] - pop = run_setup_cmds(ivl_cmd, vvp_cmd, capture_output) + pop = setup_sim_run(ivl_cmd, vvp_cmd, capture_output) return pop From fded6b0c022a9e9fa573cb0f1adfc2d26d069bd0 Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 16 Mar 2024 02:03:59 +0100 Subject: [PATCH 13/15] Updated .gitignore for default generated paths when using CVC or Verilator --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 486597c..5a71c5b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ tags Makefile include/vpi_config.h *.fst +obj_dir/ +cvcsim # autoconf files config.status From 50bbf120020c72b1a3924f0f6567a0aed08b61ae Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 16 Mar 2024 02:04:23 +0100 Subject: [PATCH 14/15] Improved against Verilator linting --- examples/spi_master/spi_master.v | 45 +++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/examples/spi_master/spi_master.v b/examples/spi_master/spi_master.v index a0e51d6..c409f00 100644 --- a/examples/spi_master/spi_master.v +++ b/examples/spi_master/spi_master.v @@ -42,12 +42,12 @@ module spi_master(cs_b, mosi, miso, sclk); reg cs_b, mosi, sclk; reg [7:0] tx_buffer [6:0]; reg [7:0] rx_buffer [7:0]; - reg [7:0] tx_crc, rx_crc; + reg [7:0] rx_crc; reg [255:0] ascii_cmd_id; reg [255:0] ascii_ret_id; reg rx_crc_error; - event start_transaction; - event end_transaction; + event start_transaction; + event end_transaction; integer transaction_counter; /************************************************************************** @@ -128,8 +128,8 @@ module spi_master(cs_b, mosi, miso, sclk); begin if (tx_mask[7] == 0) begin rx_crc_error = 1'b0; - crc = 8'hff; //Initialize CRC with correct seed - rx_crc = 8'hff; + crc = CRC_SEED; //Initialize CRC with correct seed + rx_crc = CRC_SEED; end for (i = 0; i < 7; i = i + 1) begin if (tx_mask[7 - i] == 0) begin @@ -159,12 +159,44 @@ module spi_master(cs_b, mosi, miso, sclk); end endtask + task init_tx_buffer; + integer i; + begin + for (i=0; i < 7; i = i + 1) begin + tx_buffer[i] = 8'd0; + end + end + endtask + /************************************************************************** Hook for Verisocks to trigger task execution using a named event **************************************************************************/ always @(start_transaction) spi_transmit_buffer(8'd0); + /************************************************************************** + Hook for Verilator - A public task (as declared using the verilator public + comment is used here. It could also have been exported as a DPI method, + which would make it also compatible with other simulators, however, passing + arguments gets more complex. Another alternative would have been to declare + the start_transaction and tx_buffer variables as public (I tested, this + works fine), but such a task makes for a better, more readable, + encapsulation. + **************************************************************************/ + `ifdef VERILATOR + task trigger_transaction; + /*verilator public*/ + input [7:0] tx_val [6:0]; + integer i; + begin + for (i=0; i < 7; i = i + 1) begin + tx_buffer[i] = tx_val[i]; + end + ->start_transaction; + end + endtask + `endif + /************************************************************************** Initial **************************************************************************/ @@ -175,7 +207,8 @@ module spi_master(cs_b, mosi, miso, sclk); ascii_cmd_id = "N/A"; ascii_ret_id = "N/A"; rx_crc_error = 1'b0; - transaction_counter = 1'b0; + transaction_counter = 0; + init_tx_buffer(); end endmodule From 33047318f5420c030c987c3169e0f12a3da14cdb Mon Sep 17 00:00:00 2001 From: jchabloz Date: Sat, 16 Mar 2024 02:07:05 +0100 Subject: [PATCH 15/15] Ready for release 1.2.0 --- docs/conf.py | 2 +- docs/src/release_notes.rst | 4 ++-- python/verisocks/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index bc1c984..587085b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,7 @@ project = 'Verisocks' copyright = '2023, Jérémie Chabloz' author = 'Jérémie Chabloz' -version = '1.2.0-dev' +version = '1.2.0' release = '1.2.0' # -- General configuration --------------------------------------------------- diff --git a/docs/src/release_notes.rst b/docs/src/release_notes.rst index 93de144..beb46ac 100644 --- a/docs/src/release_notes.rst +++ b/docs/src/release_notes.rst @@ -8,8 +8,8 @@ Releases of documentation and code are using the same version numbers. The version numbering system follows the `semantic versioning `_ principles. -1.2.0 - Ongoing -*************** +1.2.0 - 2024-03-16 +****************** * Modified :py:class:`Verisocks` constructor and :py:meth:`Verisocks.connect() ` method diff --git a/python/verisocks/__init__.py b/python/verisocks/__init__.py index 6d1126e..6c14252 100644 --- a/python/verisocks/__init__.py +++ b/python/verisocks/__init__.py @@ -1,4 +1,4 @@ """Verisocks Python client API """ -__version__ = "1.2.0-dev" +__version__ = "1.2.0"