Previous Page

Up One Level

Next Page

The MyHDL manual

Contents

Index

Previous: 3.1.1 Conditional instantiation Up: 3.1 Structural modeling Next: 3.1.3 Inferring the list


   
3.1.2 Arrays of instances

Python lists are easy to create. We can use them to model arrays of instances.

Suppose we have a top module that instantiates a single channel submodule, as follows:

def top(...):

 

    din = Signal(0)

    dout = Signal(0)

    clk = Signal(bool(0))

    reset = Signal(bool(0))

 

    channel_inst = channel(dout, din, clk, reset)

 

    return channel_inst

If we wanted to support an arbitrary number of channels, we can use lists of signals and a list of instances, as follows:

def top(..., n=8):

 

    din = [Signal(0) for i in range(n)]

    dout = [Signal(0) for i in range(n)]  ###

    clk = Signal(bool(0))

    reset = Signal(bool(0))

    channel_inst = [None for i in range(n)]

 

    for i in range(n):

        channel_inst[i] = channel(dout[i], din[i], clk, reset)

 

    return channel_inst


Previous Page

Up One Level

Next Page

The MyHDL manual

Contents

Index

Previous: 3.1.1 Conditional instantiation Up: 3.1 Structural modeling Next: 3.1.3 Inferring the list


Release 0.4, documentation updated on February 4, 2004.

About this document

1