Skip to main content

A VUnit package providing JSON parsing and querying capabilities for VHDL.

Project description

vunit-json-for-vhdl

A VUnit package providing JSON parsing and querying capabilities for VHDL.

Overview

vunit-json-for-vhdl is based on the JSON-for-VHDL project which provides the core VHDL functionality to operate on JSON data structures. In addition, vunit-json-for-vhdl provides integration support for exchanging JSON data between the VUnit Python run script and the simulator, using string generics as the transport mechanism. This makes it straightforward to pass structured configuration data from Python into VHDL testbenches.

Installation

pip install vunit-json-for-vhdl

Basic Example

For more in-depth examples of the VHDL part, see the JSON-for-VHDL project.

Below is an example of how the VUnit run script can pass JSON data structures to the testbench.

from vunit import VUnit

# By importing vunit_json_for_vhdl, we get access to the Python helper
# functions of the project. This is not necessary if all you need
# are the VHDL parts.
import vunit_json_for_vhdl

vu = VUnit.from_argv()
vu.add_vhdl_builtins()

# Add the VHDL parts
vu.add_component("vunit-json-for-vhdl")

# By grouping all testbench configurations in a dictionary, we keep the
# testbench generic declaration short and there is no need to update it
# when adding new configurations.
tb_cfg = dict(image_size=(384, 216), enable_compression=True)

# Converting the testbench configuration dictionary into JSON would
# result in the following string:
#
# '{"image_size": [384, 216], "enable_compression": true}'
#
# All the special characters become a problem when passing the string
# as a generic to the simulator. Different simulators have different
# limitations on the allowed characters in generics and how they are
# escaped. To avoid these issues, we need a simpler hexadecimal string
# representation of the JSON string.
tb_cfg_str = vunit_json_for_vhdl.to_str(tb_cfg)

# The configuration generic is passed to the testbench in the normal way,
# for example:
my_lib = vu.add_library("my_lib")
my_lib.add_source_files(path / to / my / source / files / "*.vhd")
my_tb = my_lib.entity("my_tb")
my_tb.set_generic("tb_cfg", tb_cfg_str)

vu.main()

Below is an example of how the VHDL testbench can extract the individual fields of the JSON data structure.

library vunit_lib;
context vunit_lib.vunit_context;

library json;
context json.json_ctx;

entity my_tb is
  generic (
    runner_cfg : string;
    tb_cfg   : string
  );
end entity;

architecture tb of my_tb is
begin
  test_runner: process is
    constant tb_cfg_json : T_JSON := jsonLoad(tb_cfg);
    constant image_size : integer_vector :=
      jsonGetIntegerArray(tb_cfg_json, "image_size");
    constant enable_compression : boolean :=
      jsonGetBoolean(tb_cfg_json, "enable_compression");
  begin
    test_runner_setup(runner, runner_cfg);

    for i in 0 to image_size'length-1 loop
      info(
        "Image size [" & to_string(i) & "]: " &
        to_string(image_size(i))
      );
    end loop;
    info("Enable compression: " & to_string(enable_compression));

    test_runner_cleanup(runner);
  end process;
end architecture;

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vunit_json_for_vhdl-0.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vunit_json_for_vhdl-0.1.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file vunit_json_for_vhdl-0.1.0.tar.gz.

File metadata

  • Download URL: vunit_json_for_vhdl-0.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for vunit_json_for_vhdl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0726d1660a1f99b608b45b499505dd0e4a4498fc71a0e7cba3637a140b76c1e8
MD5 5b4d8d852407d165b7bd96780f6b2fb2
BLAKE2b-256 0c2b23295c3c6c75adb639e0a3660e92f8cc9d7bff11142c1e385009ecad9d3d

See more details on using hashes here.

File details

Details for the file vunit_json_for_vhdl-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vunit_json_for_vhdl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8e31c6ef0ecf0293d1422d766cc02d221fe2aafa79fbc6e45143e8c97b20f73
MD5 c8592bac704ba4233187cf77ee5a4571
BLAKE2b-256 d0a968bf9228a13f2cdf82119f1e38a6ff9f9d22e3995df1ae45616e6fb848cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page