Signal
Signal and Port Handling.
A Signal is a module internal signal. A Port is a module interface signal with a direction IN, OUT or INOUT.
Simple Types
Usage:
>>> from tabulate import tabulate
>>> import ucdp as u
>>> u.Signal(u.UintType(6), "sig_s")
Signal(UintType(6), 'sig_s')
>>> u.Port(u.UintType(6), "port_i")
Port(UintType(6), 'port_i', direction=IN)
>>> u.Port(u.UintType(6), "port_o")
Port(UintType(6), 'port_o', direction=OUT)
Complex Types
Also complex types can simply be used:
>>> class AType(u.AStructType):
... def _build(self) -> None:
... self._add("req", u.BitType())
... self._add("data", u.ArrayType(u.UintType(16), 5))
... self._add("ack", u.BitType(), u.BWD)
>>> class MType(u.AEnumType):
... keytype: u.AScalarType = u.UintType(2)
... def _build(self) -> None:
... self._add(0, "Linear")
... self._add(1, "Cyclic")
>>> class BType(u.AStructType):
... def _build(self) -> None:
... self._add("foo", AType())
... self._add("mode", MType())
... self._add("bar", u.ArrayType(AType(), 3), u.BWD)
Resolving Types
These types are automatically resolved by iterating over the port:
>>> sig = u.Signal(BType(), "sig_s")
>>> for item in sig:
... print(repr(item))
Signal(BType(), 'sig_s')
Signal(AType(), 'sig_foo_s')
Signal(BitType(), 'sig_foo_req_s')
Signal(ArrayType(UintType(16), 5), 'sig_foo_data_s')
Signal(BitType(), 'sig_foo_ack_s', direction=BWD)
Signal(MType(), 'sig_mode_s')
Signal(ArrayType(AType(), 3), 'sig_bar_s', direction=BWD)
Signal(ArrayType(BitType(), 3), 'sig_bar_ack_s')
Signal(ArrayType(ArrayType(UintType(16), 5), 3), 'sig_bar_data_s', direction=BWD)
Signal(ArrayType(BitType(), 3), 'sig_bar_req_s', direction=BWD)
>>> inp = u.Port(BType(), "inp_i")
>>> for item in inp:
... print(repr(item))
Port(BType(), 'inp_i', direction=IN)
Port(AType(), 'inp_foo_i', direction=IN)
Port(BitType(), 'inp_foo_req_i', direction=IN)
Port(ArrayType(UintType(16), 5), 'inp_foo_data_i', direction=IN)
Port(BitType(), 'inp_foo_ack_o', direction=OUT)
Port(MType(), 'inp_mode_i', direction=IN)
Port(ArrayType(AType(), 3), 'inp_bar_o', direction=OUT)
Port(ArrayType(BitType(), 3), 'inp_bar_ack_i', direction=IN)
Port(ArrayType(ArrayType(UintType(16), 5), 3), 'inp_bar_data_o', direction=OUT)
Port(ArrayType(BitType(), 3), 'inp_bar_req_o', direction=OUT)
BaseSignal
Bases: Ident
Base Class for All Signals (Port, Signal).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ |
BaseType
|
Type. |
required |
name |
str
|
Name. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
AOrientation
|
Direction. |
doc |
AOrientation
|
Documentation Container |
ifdef |
AOrientation
|
IFDEF encapsulation |
Signal
Bases: BaseSignal
Module Internal Signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ |
BaseType
|
Type. |
required |
name |
str
|
Name. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
Direction. |
|
doc |
Documentation Container |
|
ifdef |
IFDEF encapsulation |
Signal Examples
Examples.
>>> import ucdp as u
>>> count = u.Signal(u.UintType(6), "count_s")
>>> count
Signal(UintType(6), 'count_s')
>>> count.type_
UintType(6)
>>> count.name
'count_s'
>>> count.basename
'count'
>>> count.suffix
'_s'
>>> count.direction
FWD
>>> count.ifdef
Note
Signal names should end with '_r' or '_s', but must not.
Port
Bases: BaseSignal
Module Port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_ |
BaseType
|
Type. |
required |
name |
str
|
Name. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
Direction
|
Direction. |
doc |
Direction
|
Documentation Container |
ifdef |
Direction
|
IFDEF encapsulation |
Port Examples
Examples.
>>> import ucdp as u
>>> count = u.Port(u.UintType(6), "count_i")
>>> count
Port(UintType(6), 'count_i', direction=IN)
>>> count.type_
UintType(6)
>>> count.name
'count_i'
>>> count.basename
'count'
>>> count.suffix
'_i'
>>> count.ifdef
Direction
The port direction is automatically determined from the name or needs to be specified explicitly:
>>> u.Port(u.UintType(6), "count_i").direction
IN
>>> u.Port(u.UintType(6), "count_o").direction
OUT
>>> u.Port(u.UintType(6), "count_io").direction
INOUT
>>> u.Port(u.UintType(6), "count").direction
Traceback (most recent call last):
...
ValueError: 'direction' is required (could not be retrieved from name 'count').
>>> u.Port(u.UintType(6), "count", direction=u.OUT).direction
OUT