Py4Hw User Guide> 1.5 Ports¶
Next: 1.6 Wires¶
All circuits have ports, either input or output.
Bidirectional ports are supported, but not recommended, in py4hw.
The InPort and OutPort classes have similar fields and methods.
| Field | Description |
|---|---|
| name | The name of the port |
| parent | The parent circuit (Logic derived object) containing the port |
| wire | The wire currently connected to the port |
| Field | Description |
|---|---|
| getFullPath | Returns the name (with the full path) of the port |
In [1]:
import py4hw
In [2]:
sys = py4hw.HWSystem()
a = sys.wire('a', 32)
reset = sys.wire('reset')
inc = sys.wire('inc', 1)
cnt = py4hw.Counter(sys, 'count', reset=reset, inc=inc, q=a)
In [3]:
py4hw.CircuitAnalysis.getAllPortNames(cnt)
Out[3]:
['reset', 'inc', 'q']
Input ports is just a list of InPort objects
In [4]:
cnt.inPorts
Out[4]:
[<py4hw.base.InPort at 0x17b02fa0950>, <py4hw.base.InPort at 0x17b031022d0>]
In [5]:
cnt.inPorts[0].__dict__
Out[5]:
{'name': 'reset',
'parent': <py4hw.logic.arithmetic.Counter at 0x17b03102150>,
'wire': <py4hw.base.Wire at 0x17b02d29350>}
Similarly, output ports is another list of OutPort objects
In [6]:
cnt.outPorts
Out[6]:
[<py4hw.base.OutPort at 0x17b03101fd0>]
In [7]:
cnt.outPorts[0].__dict__
Out[7]:
{'name': 'q',
'parent': <py4hw.logic.arithmetic.Counter at 0x17b03102150>,
'wire': <py4hw.base.Wire at 0x17b0276b110>}
Summary¶
- there are in, out, and inout ports
- ports are dynamically created
- ports have a name and are connected to a wire
In [ ]: