Skip to main content

A behavioral hardware simulator

Project description

SimuHW

Overview

SimuHW is a behavioral hardware simulator provided as a Python module.

Python 3.11 or later is required.

The GitHub page is https://github.com/arithy/simuhw.

Installation

Release Version

You can install the release version by the following command.

$ python -m pip install simuhw

Development Version

You can install the development version by the following commands.

$ cd simuhw   # the repository root directory
$ make req
$ make clean
$ make dist
$ python -m pip install --no-index --find-links=./dist simuhw

Usage

Concept

  • Word: a chunk of bits being transferred by wires.
  • Device: a hardware element such as a wire, switching devices, and memory devices.
  • Channel: a wire to transfer words.
  • Memory: a memory device to memorize words associated with specific addresses.
  • Port: an endpoint provided by a device to input or output words.
  • Probe: an entity to record word values with the respective times, whenever the value of the word passing through a specific port or stored at a specific address in a memory changes.

Import of Module

To use SimuHW, import simuhw module. An example is shown below.

import simuhw as hw

Simulation of Hardware Devices

  1. Create instances of the derived classes of Device class. As of version 0.3.0, the following device classes are available.

    An example is shown below.

    width: int = 16  # Word size in bits
    source: hw.Source = hw.Source(width, [
        (b'\x00\x01', 0.0e-9),
        (b'\xc1\x85', 3.0e-9),
        (b'\xd3\xbb', 6.0e-9),
        (b'\xf2\x3a', 10.0e-9)
    ])
    drain: hw.Drain = hw.Drain(width)
    
  2. Connect the output ports to the input ports of the device class instances. An example is shown below.

    source.port_o.connect(drain.port_i)
    
  3. Create instances of ChannelProbe class or MemoryProbe class. ChannelProbe class instances can be added to input ports or output ports, and MemoryProbe class instances can be added to instances of the derived classes of Memory class. An example is shown below.

    probe: hw.ChannelProbe = hw.ChannelProbe('out', width)
    
  4. Add the probes to the ports or the memory. An example is shown below.

    drain.port_i.add_probe(probe)
    
  5. Create an instances of LogicAnalyzer class. An example is shown below.

    la: hw.LogicAnalyzer = hw.LogicAnalyzer()
    
  6. Add the probes to the logic analyzer. An example is shown below.

    la.add_probe(probe)
    
  7. Create an instance of Simulator class. An example is shown below.

    sim: hw.Simulator = hw.Simulator([source, drain])
    
  8. Start the simulation. An example is shown below.

    sim.start()
    
  9. Save the word value change timings recorded in the probes to a VCD file. An example is shown below.

    with open('test.vcd', mode='w') as file:
        la.save_as_vcd(file)
    
  10. View the VCD file using a waveform viewer such as GTKWave.

The whole source code of the example above is shown below.

import simuhw as hw

width: int = 16  # Word size in bits
source: hw.Source = hw.Source(width, [
    (b'\x00\x01', 0.0e-9),
    (b'\xc1\x85', 3.0e-9),
    (b'\xd3\xbb', 6.0e-9),
    (b'\xf2\x3a', 10.0e-9)
])
drain: hw.Drain = hw.Drain(width)
source.port_o.connect(drain.port_i)
probe: hw.ChannelProbe = hw.ChannelProbe('out', width)
drain.port_i.add_probe(probe)
la: hw.LogicAnalyzer = hw.LogicAnalyzer()
la.add_probe(probe)
sim: hw.Simulator = hw.Simulator([source, drain])
sim.start()
with open('test.vcd', mode='w') as file:
    la.save_as_vcd(file)

This example simulates a Source device and a Drain device which are connected directly, and saves word value change timings at the input port of the Drain device to the file test.vcd.

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

simuhw-0.7.2.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

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

simuhw-0.7.2-py3-none-any.whl (120.0 kB view details)

Uploaded Python 3

File details

Details for the file simuhw-0.7.2.tar.gz.

File metadata

  • Download URL: simuhw-0.7.2.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for simuhw-0.7.2.tar.gz
Algorithm Hash digest
SHA256 19567d45d48aba0cc113f6a8f6f9f5e529c546778c9f3f2437cd0b1c32e1dfbb
MD5 6fa44343069c2d541551cf89cf6b6357
BLAKE2b-256 52f5d01beb1c25262d50a61d28acea56ca29a7112eccf08b93cddf67ff9318c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for simuhw-0.7.2.tar.gz:

Publisher: release.yml on arithy/simuhw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simuhw-0.7.2-py3-none-any.whl.

File metadata

  • Download URL: simuhw-0.7.2-py3-none-any.whl
  • Upload date:
  • Size: 120.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for simuhw-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 330dab9d78d1912e56192af26cf83cefef77a977209025a8a6c41974b3ab5ea1
MD5 8b2429655c508579017e7e56bf5ada62
BLAKE2b-256 115ff1a82e3ab340e2599534e56641abd1c886f7fd6fb227aa3efe86f1c84a39

See more details on using hashes here.

Provenance

The following attestation bundles were made for simuhw-0.7.2-py3-none-any.whl:

Publisher: release.yml on arithy/simuhw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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