naps.util package

Submodules

naps.util.amaranth_misc module

naps.util.amaranth_misc.assert_is_pot(x)
naps.util.amaranth_misc.connect_leds(m, platform, signal, upper_bits=True)
naps.util.amaranth_misc.delay_by(signal, cycles, m)
naps.util.amaranth_misc.ends_with(signal, *patterns)
naps.util.amaranth_misc.fake_differential(v)
naps.util.amaranth_misc.iterator_with_if_elif(iterator: Iterable, module: Module) Iterator

A helper to build a priority encoder using If / Elif constructs :param iterator: the iterator contaianing all the elements :param module: the module from which m.If and m.Elif are sourced

naps.util.amaranth_misc.log2(x)
naps.util.amaranth_misc.max_error_freq(real_freq, requested_freq, max_error_percent=1)
naps.util.amaranth_misc.nAbsDifference(a, b)
naps.util.amaranth_misc.nAll(seq)
naps.util.amaranth_misc.nAny(seq)
naps.util.amaranth_misc.nAvrg(*values)
naps.util.amaranth_misc.nMax(a, b)
naps.util.amaranth_misc.nMin(a, b)
naps.util.amaranth_misc.with_reset(m, signal, exclusive=False)

naps.util.amaranth_misc_test module

class naps.util.amaranth_misc_test.TestNMigenMisc(methodName='runTest')

Bases: TestCase

test_ends_with()
test_is_pot()
test_log2()
test_nAbsDifference()
test_nAll()
test_nAny()
test_nMax()
test_nMin()

naps.util.amaranth_private module

naps.util.draw_hierarchy module

naps.util.draw_hierarchy.hierarchy_to_dot(e: Elaboratable, plat=None, **kwargs)

naps.util.env module

naps.util.env.naps_getenv(name, default=None)

naps.util.formal module

class naps.util.formal.FormalPlatform

Bases: object

naps.util.formal.assert_formal(spec, mode='bmc', depth=1, submodules=())

naps.util.past module

naps.util.past.Changed(m, expr: Signal, domain='sync', clocks=0)
naps.util.past.Fell(m, expr: Signal, domain='sync', clocks=0)
naps.util.past.NewHere(m)
naps.util.past.Rose(m, expr: Signal, domain='sync', clocks=0)
naps.util.past.Sample(m, signal: Signal, clocks=1, domain='sync')

naps.util.plot_util module

naps.util.process module

class naps.util.process.Process(m: Module, name, to)

Bases: object

Processes are a utility to ease the writing of sequential steps in a FSM that are seperated by “locks”. Each lock takes at least one cycle to complete and may be time or event driven. The code between the locks is run in parallel.

naps.util.process.process_block(function)

A decorator that helps writing blocks that are parts of processes. See delay() for a minimal example of how to use this

naps.util.process.process_delay(*args, **kwargs)
naps.util.process.process_write_to_stream(*args, **kwargs)

naps.util.process_test module

class naps.util.process_test.TestProcess(methodName='runTest')

Bases: TestCase

test_basic()

naps.util.py_serialize module

naps.util.py_serialize.is_py_serializable(obj)
naps.util.py_serialize.py_serialize(obj)

naps.util.python_misc module

naps.util.python_misc.camel_to_snake(name)
naps.util.python_misc.decimal_range(start, stop, step)

naps.util.sim module

class naps.util.sim.FakeResource(name, handed_out_resources)

Bases: ValueCastable

as_value()

Convert :py:`self` to a value-like object.

This method is called by the Amaranth language to convert :py:`self` to a concrete Value. It will usually return a Value object, but it may also return another value-like object to delegate its functionality.

This method must be idempotent: when called twice on the same object, the result must be exactly the same.

This method may also be called by code that is not a part of the Amaranth language.

Returns

Any other object recognized by Value.cast().

Raises

Exception

When the conversion cannot be done. This exception must be propagated by callers, either directly or as a cause of another exception.

It is recommended that, in cases where this method raises an exception, the shape() method also raises an exception.

shape()

Compute the shape of :py:`self`.

This method is not called by the Amaranth language itself; whenever it needs to discover the shape of a value-castable object, it calls self.as_value().shape(). However, that method must return a Shape, and ValueCastable subclasses may have a richer representation of their shape provided by an instance of a ShapeCastable subclass. This method may return such a representation.

This method must be idempotent: when called twice on the same object, the result must be exactly the same.

The following condition must hold:

Shape.cast(self.shape()) == Value.cast(self).shape()

Returns

A shape-like object.

Raises

Exception

When the conversion cannot be done. This exception must be propagated by callers, either directly or as a cause of another exception.

It is recommended that, in cases where this method raises an exception, the as_value() method also raises an exception.

class naps.util.sim.InputIo(shape=None)

Bases: object

class naps.util.sim.OutputIo(shape=None)

Bases: object

class naps.util.sim.SimDdr(*args, src_loc_at=0, **kwargs)

Bases: Elaboratable

elaborate(platform)
class naps.util.sim.SimPlatform(filename=None)

Bases: object

add_file(name, contents)
add_process(generator, domain=None)
add_sim_clock(domain_name, frequency, phase=0)
command_templates = []
prepare(top_fragment, name='top', *args, **kwargs)
request(name, number=0, *args, **kwargs)
sim(dut, testbench=None, traces=(), engine='pysim')
class naps.util.sim.TristateDdrIo(shape=None)

Bases: object

class naps.util.sim.TristateIo(shape=None)

Bases: object

naps.util.sim.do_nothing(length=10)
naps.util.sim.pulse(signal, length=1, after=0)
naps.util.sim.resolve(expr)

Resolves a nMigen expression that can be constantly evaluated to an integer

naps.util.sim.wait_for(expr, timeout=100, must_clock=True)

naps.util.size_estimation module

naps.util.size_estimation.get_module_sizes(module, *args, **kwargs)
naps.util.size_estimation.print_module_sizes(module, *args, **kwargs)

naps.util.timer module

naps.util.timer.end_task()
naps.util.timer.print_summary_at_end()
naps.util.timer.print_task_timing(current_task, elapsed)
naps.util.timer.start_task(name)

naps.util.yosys module

naps.util.yosys.get_verilog_module_ports(verilog_paths, module_name)

Get the ports of a verilog module via yosys

Parameters:
  • verilog_paths

  • module_name

Returns:

the verilog as a string

naps.util.yosys.parse_yosys_json(verilog_paths)
naps.util.yosys.yosys_script(commands)

Executes a yosys script

Parameters:

commands – a list of commands to run

Returns:

the stdout of yosys

Module contents