UHDL: Python Hardware Description for Humans.

Contents:

Installation

At the command line:

$ easy_install uhdl

Or, if you have virtualenvwrapper installed:

$ mkvirtualenv uhdl
$ pip install uhdl

Usage

To use Utilities for MyHDL in a project:

import uhdl

Developer Interface

Constructors

uhdl.randbits(n)[source]
uhdl.Sig(val=None, w=None, min=None, max=None)[source]
uhdl.create(n, constructor, *args, **kwargs)[source]

Helper function for constructing multiple objects with the same arguments.

Shorthand for [constructor(*args, **kwargs) for i in range(n)]

uhdl.Sigs(n, *args, **kwargs)[source]

Create multiple Signals cleanly.

Parameters:
  • n – number of signals to create.
  • *args – passed through to Sig()
  • **kwargs – passed through to Sig()
Returns:

[Sig(*args, **kwargs) for i in range(n)]

Simulation

class uhdl.HW(top, *args, **kwargs)[source]

A Hardware module.

Provides a uniform API for conversion and simulation of MyHDL Instances.

config

dict

Dictionary(CaselessDict) containing the default config.

Modifying this attribute will change the default argument values of the convert() and sim() methods.

convert(**kwargs)[source]

Converts the top function to another HDL

Note

VHDL conversion has not been implemented yet.

Parameters:
  • hdl (str, optional) – The target language. Defaults to ‘verilog’.
  • path (str, optional) – Destination folder. Defaults to current dir.
  • name (str, optional) – Top level instance name, and output file name. Defaults to self.top.__name__
  • tb (bool, optional) – Specifies whether a test bench should be created. Defaults to True.
  • trace (bool, optional) – Whether the testbench should dump all signal waveforms. Defaults to True.
  • timescale (str, optional) – Defaults to ‘1ns/1ps’
sim(**kwargs)[source]

Simulate the top function.

Parameters:
  • backend (str, optional) – Simulation runner. Available options are ‘myhdl’, ‘icarus’ and ‘modelsim’. Defaults to ‘myhdl’.
  • hdl (str) – Target HDL for conversion before simulation.
  • **kwargs – Optional arguments that convert() takes.
Returns:

Generator sequence if the backend is myhdl,

myhdl.Cosimulation object if the backend is a simulator.

Internals

uhdl.structures

Data structures(unrelated to hardware description) used internally by uhdl.

class uhdl.structures.CaselessDict(data=None, **kwargs)[source]

A case-insensitive dictionary.

All keys are expected to be strings. The structure converts the key to lower case before storing or retreiving objects.

uhdl.utils

Utility functions(unrelated to hardware desription) used within uhdl.

uhdl.utils.cd(path)[source]

Context manager which changes the current working directory

Parameters:path (str) – path to change directory to.
Usage:
with cd('path/to/somewhere'):
    #do something..
class uhdl.utils.classproperty(fget)[source]

Decorator which allows read only class properties

uhdl.utils.flatten(*args)[source]

Flattens arbitrarily nested iterators(Except strings)

Parameters:*args – objects and iterables.
Returns:list of all objects.

Changelog

Unreleased

  • Python 3 support
  • run has been split into a sim decorator and a run_sim function

(2013-10-27)

  • First public version. Not available on PyPI anymore because of various issues.

  • Features:
    • Constructors: bits, randbits, create, Sig, Sigs, Clock, Reset
    • Simulation: HW, run
    • math: clog2, roundup

Indices and tables