Skip to main content

Sequential Logic

Project description

Sequential Logic

SeqiLog (pronounced seh-kwi-log) is a Python library for logic design and verification.

Read the docs! (WIP)

Documentation Status

Features

SeqiLog provides building blocks to simulate hardware at the register transfer level (RTL) of abstraction:

  • Hierarchical, parameterized Module design element
  • Four-state bits multidimensional array data type
  • Discrete event simulation using async / await syntax

SeqiLog is declarative. To the extent possible, the designer should only need to know what components to declare, not how they interact with the task scheduling algorithm.

SeqiLog is strict. Functions should raise exceptions when arguments have inconsistent types. Uninitialized or metastable state should always propagate pessimistically.

The API is an experiment in how to create a Pythonic meta-HDL. It is currently a work in progress. Expect breaking changes from time to time.

Example

The following code implements a D flip flop (DFF) with the D input connected to the inverted Q output.

from bvwx import Vec
from vcd import VCDWriter
from seqlogic import Module, run, sleep


async def drv_clock(y):
    """Positive clock w/ no phase shift, period T=2, 50% duty cycle."""
    while True:
        y.next = "1b1"
        await sleep(1)
        y.next = "1b0"
        await sleep(1)


async def drv_reset(y):
    """Positive reset asserting from T=[1..2]"""
    y.next = "1b0"
    await sleep(1)
    y.next = "1b1"
    await sleep(1)
    y.next = "1b0"


class Top(Module):
    """Data flip flop (DFF) Example"""

    def build(self):
        clk = self.logic(name="clk", dtype=Vec[1])
        rst = self.logic(name="rst", dtype=Vec[1])
        q = self.logic(name="q", dtype=Vec[1])
        d = self.logic(name="d", dtype=Vec[1])

        # d = NOT(q)
        self.expr(d, ~q)

        # DFF w/ async positive (active high) reset, reset to 0
        self.dff(q, d, clk, rst=rst, rval="1b0")

        # Clock/Reset
        self.drv(drv_clock, clk)
        self.drv(drv_reset, rst)


# Run simulation w/ VCD dump enabled
with (
    open("dff.vcd", "w") as f,
    VCDWriter(f, timescale="1ns") as vcdw,
):
    top = Top(name="top")
    top.dump_vcd(vcdw, ".*")
    run(top.main(), ticks=20)

Use GTKWave or Surfer to view the VCD wave dump. It should look this this:

T (ns)   0  1  2  3  4  5  6  7  8  9 ...
---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

clk      /‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\__/‾‾\

rst      ___/‾‾\___________________________________________________

q        XXXX________/‾‾‾‾‾\_____/‾‾‾‾‾\_____/‾‾‾‾‾\_____/‾‾‾‾‾\___

d        XXXX‾‾‾‾‾‾‾‾\_____/‾‾‾‾‾\_____/‾‾‾‾‾\_____/‾‾‾‾‾\_____/‾‾‾

---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

See the ipynb and tests directories for more examples.

Installing

SeqiLog is available on PyPI:

$ pip install seqlogic

It supports Python 3.12+.

Developing

SeqiLog's repository is on GitHub:

$ git clone https://github.com/cjdrake/seqlogic.git

Runtime dependencies are listed in requirements.txt. Development dependencies are listed in requirements-dev.txt.

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

seqlogic-0.53.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

seqlogic-0.53.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file seqlogic-0.53.0.tar.gz.

File metadata

  • Download URL: seqlogic-0.53.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for seqlogic-0.53.0.tar.gz
Algorithm Hash digest
SHA256 f1d790cb4b24984a3123e838c8113feb2f5d3f1f43cc222de1ce5026b05f54f5
MD5 63304b861880a2b8ce0bc2d41401aed5
BLAKE2b-256 8f582a8da5434bd32968f4432df2b49f902070b3647226fd30400961c4c2117f

See more details on using hashes here.

File details

Details for the file seqlogic-0.53.0-py3-none-any.whl.

File metadata

  • Download URL: seqlogic-0.53.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for seqlogic-0.53.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2ca62c7c613f1700d2a810713351732560e698d0849e11901d92cde3733ad9e
MD5 19364e459c3e64a9d00c8293888f5fa4
BLAKE2b-256 46077008bd8d41af6b3f12550d6a64cb66ae80a84cd5a778b9d02d48de3ad65a

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