transactron package
Subpackages
- transactron.cmd package
- transactron.core package
- Submodules
- transactron.core.body module
- transactron.core.context module
- transactron.core.interface module
- transactron.core.keys module
- transactron.core.manager module
- transactron.core.method module
- transactron.core.schedulers module
- transactron.core.sugar module
- transactron.core.tmodule module
- transactron.core.transaction module
- transactron.core.transaction_base module
- Module contents
- transactron.evlog package
- Submodules
- transactron.evlog.consumer module
- transactron.evlog.emit module
- transactron.evlog.event module
- transactron.evlog.log module
- transactron.evlog.sampler module
- transactron.evlog.schema module
- Module contents
- transactron.lib package
- Submodules
- transactron.lib.adapters module
- transactron.lib.allocators module
- transactron.lib.basicio module
- transactron.lib.connectors module
- transactron.lib.dependencies module
- transactron.lib.fifo module
- transactron.lib.metrics module
- transactron.lib.pipeline module
- transactron.lib.reqres module
- transactron.lib.simultaneous module
- transactron.lib.stack module
- transactron.lib.storage module
- transactron.lib.stream module
- transactron.lib.transformers module
- Module contents
- transactron.testing package
- Submodules
- transactron.testing.evlog module
- transactron.testing.functions module
- transactron.testing.input_generation module
- transactron.testing.logging module
- transactron.testing.method_mock module
- transactron.testing.profiler module
- transactron.testing.reqres module
- transactron.testing.simulator module
- transactron.testing.test_case module
TestCaseWithSimulatorBaseTestCaseWithSimulatorBase.ctx_testing_env()TestCaseWithSimulatorBase.ctx_testing_env_next()TestCaseWithSimulatorBase.dependency_managerTestCaseWithSimulatorBase.random_wait()TestCaseWithSimulatorBase.random_wait_geom()TestCaseWithSimulatorBase.run_simulation()TestCaseWithSimulatorBase.tick()TestCaseWithSimulatorBase.wrap_testing_env()TestCaseWithSimulatorBase.wrap_testing_env_next()
- transactron.testing.test_case_pytest module
- transactron.testing.test_circuit module
- transactron.testing.testbenchio module
CallTriggerTestbenchIOTestbenchIO.__init__()TestbenchIO.call()TestbenchIO.call_do()TestbenchIO.call_init()TestbenchIO.call_result()TestbenchIO.call_try()TestbenchIO.disable()TestbenchIO.doneTestbenchIO.enable()TestbenchIO.get_call_result()TestbenchIO.get_done()TestbenchIO.get_outputs()TestbenchIO.outputsTestbenchIO.sample_outputs()TestbenchIO.sample_outputs_done()TestbenchIO.sample_outputs_until_done()TestbenchIO.set_enable()TestbenchIO.set_inputs()
- transactron.testing.tick_count module
- Module contents
CallTriggerMethodMockProcessContextPysimSimulatorRequestResponseTestbenchIOSimpleTestCircuitSimulatorContextTestCaseWithSimulatorBaseTestCaseWithSimulatorBase.ctx_testing_env()TestCaseWithSimulatorBase.ctx_testing_env_next()TestCaseWithSimulatorBase.dependency_managerTestCaseWithSimulatorBase.random_wait()TestCaseWithSimulatorBase.random_wait_geom()TestCaseWithSimulatorBase.run_simulation()TestCaseWithSimulatorBase.tick()TestCaseWithSimulatorBase.wrap_testing_env()TestCaseWithSimulatorBase.wrap_testing_env_next()
TestbenchContextTestbenchIOTestbenchIO.__init__()TestbenchIO.call()TestbenchIO.call_do()TestbenchIO.call_init()TestbenchIO.call_result()TestbenchIO.call_try()TestbenchIO.disable()TestbenchIO.doneTestbenchIO.enable()TestbenchIO.get_call_result()TestbenchIO.get_done()TestbenchIO.get_outputs()TestbenchIO.outputsTestbenchIO.sample_outputs()TestbenchIO.sample_outputs_done()TestbenchIO.sample_outputs_until_done()TestbenchIO.set_enable()TestbenchIO.set_inputs()
call_request_response()data_const_to_dict()data_layout()def_method_mock()def_request_response_mock()
- transactron.utils package
- Subpackages
- transactron.utils.amaranth_ext package
- Submodules
- transactron.utils.amaranth_ext.coding module
- transactron.utils.amaranth_ext.component_interface module
- transactron.utils.amaranth_ext.data module
- transactron.utils.amaranth_ext.elaboratables module
- transactron.utils.amaranth_ext.functions module
- transactron.utils.amaranth_ext.memory module
- transactron.utils.amaranth_ext.option module
- transactron.utils.amaranth_ext.shifter module
- Module contents
- transactron.utils.amaranth_ext package
- Submodules
- transactron.utils.assign module
- transactron.utils.data_repr module
- transactron.utils.debug_signals module
- transactron.utils.depcache module
- transactron.utils.dependencies module
- transactron.utils.gen module
GeneratedLogGenerationInfoGenerationInfo.__init__()GenerationInfo.decode()GenerationInfo.encode()GenerationInfo.evlogGenerationInfo.from_dict()GenerationInfo.from_json()GenerationInfo.logsGenerationInfo.method_signals_locationGenerationInfo.metrics_locationGenerationInfo.profile_dataGenerationInfo.schema()GenerationInfo.to_dict()GenerationInfo.to_json()GenerationInfo.transaction_signals_location
MetricLocationgenerate_verilog()
- transactron.utils.gen_hacks module
- transactron.utils.idgen module
- transactron.utils.logging module
HardwareLoggerHardwareLogger.__init__()HardwareLogger.assertion()HardwareLogger.debug()HardwareLogger.error()HardwareLogger.info()HardwareLogger.log()HardwareLogger.top_assertion()HardwareLogger.top_debug()HardwareLogger.top_error()HardwareLogger.top_info()HardwareLogger.top_log()HardwareLogger.top_warning()HardwareLogger.warning()
LogChunkInfoLogKeyLogLevelLogRecordLogRecordInfoassertion()get_log_records()get_trigger_bit()top_assertion()
- transactron.utils.transactron_helpers module
NestedCollectionUniformObjectasync_mock_def_helper()dataclass_asdict()def_helper()extend_layout()from_method_layout()get_caller_class_name()get_src_loc()is_nested_collection()local_src_loc()longest_common_prefix()make_layout()method_def_helper()mock_def_helper()nested_collection_items()silence_mustuse()
- transactron.utils.typing module
- Module contents
- Subpackages
Submodules
transactron.graph module
Utilities for extracting dependency graphs from Amaranth designs.
- class transactron.graph.Direction
Bases:
IntFlag- IN = 1
- INOUT = 3
- NONE = 0
- OUT = 2
- __new__(value)
transactron.profiler module
- class transactron.profiler.MethodSamples
Bases:
objectRuntime value of method control signals in a given clock cycle.
- Attributes:
- run: bool
The value of the method’s
runsignal.
- class transactron.profiler.Profile
Bases:
objectTransactron execution profile.
Can be saved by the simulator, and then restored by an analysis tool. In the profile data structure, methods and transactions are referred to by their unique ID numbers.
- Attributes:
- transactions_and_methodsdict[int, ProfileInfo]
Information about transactions and methods indexed by ID numbers.
- cycleslist[CycleProfile]
Profile information for each cycle of the simulation.
- __init__(transactions_and_methods: dict[int, ~transactron.profiler.ProfileInfo]=<factory>, cycles: list[CycleProfile] = <factory>) None
- analyze_methods(recursive=False) list[RunStatNode]
- analyze_transactions(recursive=False) list[RunStatNode]
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
- classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
- to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: int | str | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
- transactions_and_methods: dict[int, ProfileInfo]
- class transactron.profiler.ProfileData
Bases:
objectInformation about transactions and methods from the transaction manager.
This data is required for transaction profile generation in simulators. Transactions and methods are referred to by their unique ID numbers.
- Attributes:
- transactions_and_methods: dict[int, ProfileInfo]
Information about individual transactions and methods.
- method_parents: dict[int, list[int]]
Lists the callers (transactions and methods) for each method. Key is method ID.
- transactions_by_method: dict[int, list[int]]
Lists which transactions are calling each method. Key is method ID.
- transaction_conflicts: dict[int, list[int]]
List which other transactions conflict with each transaction.
- __init__(transactions_and_methods: dict[int, ProfileInfo], method_parents: dict[int, list[int]], transactions_by_method: dict[int, list[int]], transaction_conflicts: dict[int, list[int]]) None
- static make(transaction_manager: TransactionManager)
- transactions_and_methods: dict[int, ProfileInfo]
- class transactron.profiler.ProfileInfo
Bases:
objectInformation about transactions and methods.
In Profile, transactions and methods are referred to by their unique ID numbers.
- Attributes:
- namestr
The name.
- src_locSrcLoc
Source location.
- is_transactionbool
If true, this object describes a transaction; if false, a method.
- classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
- classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
- class transactron.profiler.ProfileSamples
Bases:
objectRuntime values of all transaction and method control signals.
- Attributes:
- transactions: dict[int, TransactionSamples]
Runtime values of transaction control signals for each transaction.
- methods: dict[int, MethodSamples]
Runtime values of method control signals for each method.
- __init__(transactions: dict[int, ~transactron.profiler.TransactionSamples]=<factory>, methods: dict[int, ~transactron.profiler.MethodSamples]=<factory>) None
- methods: dict[int, MethodSamples]
- transactions: dict[int, TransactionSamples]
- class transactron.profiler.RunStat
Bases:
objectCollected statistics about a transaction or method.
- Attributes:
- namestr
The name.
- src_locSrcLoc
Source location.
- lockedint
For methods: the number of cycles this method was locked because of a disabled call (a call under a false condition). For transactions: the number of cycles this transaction was ready to run, but did not run because a conflicting transaction has run instead.
- static make(info: ProfileInfo)
- class transactron.profiler.RunStatNode
Bases:
objectA statistics tree. Summarizes call graph information.
- Attributes:
- statRunStat
Statistics.
- callersdict[int, RunStatNode]
Statistics for the method callers. For transactions, this is empty.
- callers: dict[int, RunStatNode]
- static make(info: ProfileInfo)
- class transactron.profiler.TransactionSamples
Bases:
objectRuntime value of transaction control signals in a given clock cycle.
- Attributes:
- ready: bool
The value of the transaction’s
readysignal.- runnable: bool
The value of the transaction’s
runnablesignal.- run: bool
The value of the transaction’s
runsignal.
transactron.tracing module
Utilities for extracting dependencies from Amaranth.
- class transactron.tracing.TracingFragment
Bases:
Fragment- static get(obj: HasElaborate, platform) TracingFragment
Code of this function is based on Amaranth, which originally loses all information. It was too difficult to hook into, so this has to be a near-exact copy.
Relevant copyrights apply.
- prepare(*args, **kwargs) TracingFragment
- class transactron.tracing.TracingFragmentTransformer
Bases:
FragmentTransformer- on_fragment(fragment)
- class transactron.tracing.TracingInstance
Bases:
Instance,TracingFragment- get(platform) TracingFragment
Code of this function is based on Amaranth, which originally loses all information. It was too difficult to hook into, so this has to be a near-exact copy.
Relevant copyrights apply.
Module contents
- class transactron.AssignType
Bases:
Enum- ALL = 4
- COMMON = 1
- LHS = 2
- RHS = 3
- class transactron.Method
Bases:
TransactionBase[Transaction | Method]Transactional method.
A Method serves to interface a module with external Transactions or Methods. It can be called by at most once in a given clock cycle. When a given Method is called by multiple Transactions (either directly, or indirectly via another Method) simultaneously, at most one of them is run by the TransactionManager, and the rest of them must wait. (Non-exclusive methods are an exception to this behavior.) Calling a Method always takes a single clock cycle.
Data is combinationally transferred between to and from Methods using Amaranth structures (View with a StructLayout). The transfer can take place in both directions at the same time: from the called Method to the caller (data_out) and from the caller to the called Method (data_in).
A module which defines a Method should use body or def_method to describe the method’s effect on the module state.
- Attributes:
- name: str
Name of this Method.
- ready: Signal, in
Signals that the method is ready to run in the current cycle. Typically defined by calling body.
- run: Signal, out
Signals that the method is called in the current cycle by some Transaction. Defined by the TransactionManager.
- data_in: MethodStruct, out
Contains the data passed to the Method by the caller (a Transaction or another Method).
- data_out: MethodStruct, in
Contains the data passed from the Method to the caller (a Transaction or another Method). Typically defined by calling body.
- __init__(*, name: str | None = None, i: MethodLayout = (), o: MethodLayout = (), src_loc: int | tuple[str, int] = 0)
- Parameters:
- name: str or None
Name hint for this Method. If None (default) the name is inferred from the variable name this Method is assigned to.
- i: method layout
The format of data_in.
- o: method layout
The format of data_out.
- src_loc: int | SrcLoc
How many stack frames deep the source location is taken from. Alternatively, the source location to use instead of the default.
- body(m: ~transactron.core.tmodule.TModule, *, ready: ~amaranth.hdl._ast.Value | int | ~enum.Enum | ~amaranth.hdl._ast.ValueCastable = (const 1'd1), out: ~amaranth.hdl._ast.Value | int | ~enum.Enum | ~amaranth.hdl._ast.ValueCastable = (const 0'd0), **kwargs: ~typing.Unpack[~transactron.core.body.BodyParams]) Iterator[View[StructLayout]]
Define method body
The body context manager can be used to define the actions performed by a Method when it’s run. Each assignment added to a domain under body is guarded by the run signal. Combinational assignments which do not need to be guarded by run can be added to m.d.av_comb or m.d.top_comb instead of m.d.comb. Method calls can be performed under body.
- Parameters:
- mTModule
Module in which operations on signals should be executed, body uses the combinational domain only.
- readySignal, in
Signal to indicate if the method is ready to be run. By default it is Const(1), so the method is always ready. Assigned combinationially to the ready attribute.
- outValue, in
Data generated by the Method, which will be passed to the caller (a Transaction or another Method). Assigned combinationally to the data_out attribute.
- validate_arguments: Optional[Callable[…, ValueLike]]
Function that takes input arguments used to call the method and checks whether the method can be called with those arguments. It instantiates a combinational circuit for each method caller. By default, there is no function, so all arguments are accepted.
- combiner: (Module, Sequence[MethodStruct], Value) -> AssignArg
If nonexclusive is true, the combiner function combines the arguments from multiple calls to this method into a single argument, which is passed to the method body. The third argument is a bit vector, whose n-th bit is 1 if the n-th call is active in a given cycle.
- nonexclusive: bool
If true, the method is non-exclusive: it can be called by multiple transactions in the same clock cycle. If such a situation happens, the method still is executed only once, and each of the callers receive its output. Nonexclusive methods cannot have inputs.
- single_caller: bool
If true, this method is intended to be called from a single transaction. An error will be thrown if called from multiple transactions.
- Returns:
- data_inStructLayout, out
Data passed from the caller (a Transaction or another Method) to this Method.
Examples
m = Module() my_sum_method = Method(i = Layout([("arg1",8),("arg2",8)])) sum = Signal(16) with my_sum_method.body(m, out = sum) as data_in: m.d.comb += sum.eq(data_in.arg1 + data_in.arg2)
- debug_signals() DebugBundle
- property layout_in
- property layout_out
- static like(other: Method, *, name: str | None = None) Method
Constructs a new Method based on another.
The returned Method has the same input/output data layouts as the other Method.
- Parameters:
- otherMethod
The Method which serves as a blueprint for the new Method.
- namestr, optional
Name of the new Method.
- Returns:
- Method
The freshly constructed Method.
- provide(method: Method)
Provide method definition using another method.
The calls to this method will be forwarded to method. Input and output data layouts of this method and method must match.
- Parameters:
- methodMethod
Definition of method will be provided to this method.
- type transactron.MethodLayout = StructLayout | LayoutIterable
- class transactron.Methods
-
- __init__(count: int, **kwargs)
- debug_signals() DebugBundle
- property layout_in
- property layout_out
- class transactron.Priority
Bases:
Enum- LEFT = 2
Left transaction/method is prioritized over the right one.
- RIGHT = 3
Right transaction/method is prioritized over the left one.
- UNDEFINED = 1
Conflicting transactions/methods don’t have a priority order.
- class transactron.TModule
Bases:
ModuleLike,ElaboratableExtended Amaranth module for use with transactions.
It includes three different combinational domains:
comb domain, works like the comb domain in plain Amaranth modules. Statements in comb are guarded by every condition, including AvoidedIf. This means they are guarded by transaction and method bodies: they don’t execute if the given transaction/method is not run.
av_comb is guarded by all conditions except AvoidedIf. This means they are not guarded by transaction and method bodies. This allows to reduce the amount of useless multplexers due to transaction use, while still allowing the use of conditions in transaction/method bodies.
top_comb is unguarded: statements added to this domain always execute. It can be used to reduce combinational path length due to multplexers while keeping related combinational and synchronous statements together.
- AvoidedIf(cond: Value | int | Enum | ValueCastable)
- Case(*patterns: str | Value | int | Enum | ValueCastable)
- Default()
- Elif(cond)
- Else()
- If(cond: Value | int | Enum | ValueCastable)
- State(name: str)
- Switch(test: Value | int | Enum | ValueCastable)
- __init__()
- property ctrl_path
- property next: NoReturn
- class transactron.Transaction
Bases:
TransactionBase[Transaction | Method]Transaction.
A Transaction represents a task which needs to be regularly done. Execution of a Transaction always lasts a single clock cycle. A Transaction signals readiness for execution by setting the ready signal. If the conditions for its execution are met, it can be run by the TransactionManager.
A Transaction can, as part of its execution, call a number of Methods. A Transaction can be run only if every Method it calls is ready.
A Transaction cannot execute concurrently with another, conflicting Transaction. Conflicts between Transactions are either explicit or implicit. An explicit conflict is added using the add_conflict method. Implicit conflicts arise between pairs of Transactions which use the same Method.
A module which defines a Transaction should use body to describe used methods and the transaction’s effect on the module state. The used methods should be called inside the body’s with block.
- Attributes:
- name: str
Name of this Transaction.
- ready: Signal, in
Signals that the transaction wants to run. If omitted, the transaction is always ready. Defined in the constructor.
- runnable: Signal, out
Signals that all used methods are ready.
- run: Signal, out
Signals that the transaction is run by the TransactionManager.
- __init__(*, name: str | None = None, src_loc: int | tuple[str, int] = 0)
- Parameters:
- name: str or None
Name hint for this Transaction. If None (default) the name is inferred from the variable name this Transaction is assigned to. If the Transaction was not assigned, the name is inferred from the class name where the Transaction was constructed.
- src_loc: int | SrcLoc
How many stack frames deep the source location is taken from. Alternatively, the source location to use instead of the default.
- always_body(m: TModule, log: HardwareLogger | None = None, *, ready: Value | int | Enum | ValueCastable = (const 1'd1)) Iterator[Transaction]
- body(m: TModule, *, ready: Value | int | Enum | ValueCastable = (const 1'd1)) Iterator[Transaction]
Defines the Transaction body.
This context manager allows to conveniently define the actions performed by a Transaction when it’s running. Each assignment added to a domain under body is guarded by the run signal. Combinational assignments which do not need to be guarded by run can be added to m.d.top_comb or m.d.av_comb instead of m.d.comb. Method calls can be performed under body.
- Parameters:
- m: TModule
The module where the Transaction is defined.
- ready: Signal
Indicates that the Transaction wants to be executed. By default it is Const(1), so it wants to be executed in every clock cycle.
- debug_signals() DebugBundle
- class transactron.TransactronContextComponent
Bases:
TransactronContextElaboratable,ComponentTop-level component for Transactron projects.
The TransactronContextComponent is a wrapper on Component classes, which adds Transactron support for the wrapped class. The use case is to wrap a top-level module of the project, and pass the wrapped module for simulation, HDL generation or synthesis. The ports of the wrapped component are forwarded to the wrapper.
It extends the functionality of TransactronContextComponent.
- __init__(component: AbstractComponent, dependency_manager: DependencyManager | None = None, transaction_manager: TransactionManager | None = None)
- Parameters:
- component: Component
The Component which should be wrapped to add support for transactions and methods.
- dependency_manager: DependencyManager, optional
The DependencyManager to use inside the transaction component. If omitted, a new one is created.
- transaction_manager: TransactionManager, optional
The TransactionManager to use inside the transaction component. If omitted, a new one is created.
- class transactron.TransactronContextElaboratable
Bases:
ElaboratableTop-level Elaboratable for Transactron projects.
TransactronContextElaboratable is used as wrapper on Elaboratable classes, which adds support for transactions. It creates a TransactionManager which will handle transaction scheduling and can be used in definition of Methods and Transactions. The TransactionManager is stored in a DependencyManager.
- __init__(elaboratable: HasElaborate, dependency_manager: DependencyManager | None = None, transaction_manager: TransactionManager | None = None)
- Parameters:
- elaboratable: HasElaborate
The Elaboratable which should be wrapped to add support for transactions and methods.
- dependency_manager: DependencyManager, optional
The DependencyManager to use inside the transaction module. If omitted, a new one is created.
- transaction_manager: TransactionManager, optional
The TransactionManager to use inside the transaction module. If omitted, a new one is created.
- context() DependencyContext
- transactron.assertion(m: ModuleLike, value: Value | int | Enum | ValueCastable, format: str, *args: Value | int | Enum | ValueCastable, name: str = 'global', src_loc: int | tuple[str, int] = 0, **kwargs: Value | int | Enum | ValueCastable)
Define an assertion.
This is a short form, for use in generic code. For general use, see HardwareLogger.assertion.
- transactron.assign(lhs: AssignArg, rhs: AssignArg, *, fields: AssignFields = AssignType.RHS, lhs_strict=False, rhs_strict=False) Iterable[Assign]
Safe structured assignment.
This function recursively generates assignment statements for field-containing structures. This includes: Amaranth Views using StructLayout, Python dicts. In case of mismatching fields or bit widths, error is raised.
When both lhs and rhs are field-containing, assign generates assignment statements according to the value of the field parameter. If either of lhs or rhs is not field-containing, assign checks for the same bit width and generates a single assignment statement.
The bit width check is performed if:
Any of lhs or rhs is a View.
Both lhs and rhs have an explicitly defined shape (e.g. are a Signal, a field of a View).
- Parameters:
- lhsView or Value-castable or dict
View, signal or dict being assigned.
- rhsView or Value-castable or dict
View, signal or dict containing assigned values.
- fieldsAssignType or Iterable or Mapping, optional
Determines which fields will be assigned. Possible values:
- AssignType.COMMON
Only fields common to lhs and rhs are assigned.
- AssignType.LHS
All fields in lhs are assigned. If one of them is not present in rhs, an exception is raised.
- AssignType.RHS
All fields in rhs are assigned. If one of them is not present in lhs, an exception is raised.
- AssignType.ALL
Assume that both structures have the same layouts. All fields present in lhs or rhs are assigned.
- Mapping
Keys are field names, values follow the format for fields.
- Iterable
Items are field names. For subfields, AssignType.ALL is assumed.
- Returns:
- Iterable[Assign]
Generated assignment statements.
- Raises:
- ValueError
If the assignment can’t be safely performed.
- transactron.condition(m: TModule, *, nonblocking: bool = False, priority: bool = False)
Conditions using simultaneous transactions.
This context manager allows to easily define conditions utilizing nested transactions and the simultaneous transactions mechanism. It is similar to Amaranth’s If, but allows to call different and possibly overlapping method sets in each branch. Each of the branches is defined using a separate nested transaction.
Inside the condition body, branches can be added, which are guarded by Boolean conditions. A branch is considered for execution if its condition is true and the called methods can be run. A catch-all, default branch can be added, which can be executed only if none of the other branches execute. The condition of the default branch is the negated alternative of all the other conditions.
- Parameters:
- mTModule
A module where the condition is defined.
- nonblockingbool
States that the condition should not block the containing method or transaction from running, even when none of the branch conditions is true. In case of a blocking method call, the containing method or transaction is still blocked.
- prioritybool
States that when conditions are not mutually exclusive and multiple branches could be executed, the first one will be selected. This influences the scheduling order of generated transactions.
Examples
with condition(m) as branch: with branch(cond1): ... with branch(cond2): ... with branch(): # default, optional ...
- transactron.def_method(m: ~transactron.core.tmodule.TModule, method: ~transactron.core.method.Method, ready: ~amaranth.hdl._ast.Value | int | ~enum.Enum | ~amaranth.hdl._ast.ValueCastable = (const 1'd1), **kwargs: ~typing.Unpack[~transactron.core.body.BodyParams])
Define a method.
This decorator allows to define transactional methods in an elegant way using Python’s def syntax. Internally, def_method uses Method.body.
The decorated function should take keyword arguments corresponding to the fields of the method’s input layout. The **kwargs syntax is supported. Alternatively, it can take one argument named arg, which will be a structure with input signals.
The returned value can be either a structure with the method’s output layout or a dictionary of outputs.
- Parameters:
- m: TModule
Module in which operations on signals should be executed.
- method: Method
The method whose body is going to be defined.
- ready: Signal
Signal to indicate if the method is ready to be run. By default it is Const(1), so the method is always ready. Assigned combinationally to the ready attribute.
- **kwargs: BodyParams
For details, see Method.body.
Examples
m = Module() my_sum_method = Method(i=[("arg1",8),("arg2",8)], o=[("res",8)]) @def_method(m, my_sum_method) def _(arg1, arg2): return arg1 + arg2
Alternative syntax (keyword args in dictionary):
@def_method(m, my_sum_method) def _(**args): return args["arg1"] + args["arg2"]
Alternative syntax (arg structure):
@def_method(m, my_sum_method) def _(arg): return {"res": arg.arg1 + arg.arg2}
- transactron.def_methods(m: ~transactron.core.tmodule.TModule, methods: ~collections.abc.Sequence[~transactron.core.method.Method], ready: ~collections.abc.Callable[[int], ~amaranth.hdl._ast.Value | int | ~enum.Enum | ~amaranth.hdl._ast.ValueCastable] = <function <lambda>>, **kwargs: ~typing.Unpack[~transactron.core.body.BodyParams])
Decorator for defining similar methods
This decorator is a wrapper over def_method, which allows you to easily define multiple similar methods in a loop.
The function over which this decorator is applied, should always expect at least one argument, as the index of the method will be passed as the first argument to the function.
This is a syntax sugar equivalent to:
for i in range(len(my_methods)): @def_method(m, my_methods[i]) def _(arg): ...
- Parameters:
- m: TModule
Module in which operations on signals should be executed.
- methods: Sequence[Method]
The methods whose body is going to be defined.
- ready: Callable[[int], Value]
A Callable that takes the index in the form of an int of the currently defined method and produces a Value describing whether the method is ready to be run. When omitted, each defined method is always ready. Assigned combinationally to the ready attribute.
- **kwargs: BodyParams
For details, see Method.body.
Examples
Define three methods with the same body:
m = TModule() my_sum_methods = [Method(i=[("arg1",8),("arg2",8)], o=[("res",8)]) for _ in range(3)] @def_methods(m, my_sum_methods) def _(_, arg1, arg2): return arg1 + arg2
Define three methods with different bodies parametrized with the index of the method:
m = TModule() my_sum_methods = [Method(i=[("arg1",8),("arg2",8)], o=[("res",8)]) for _ in range(3)] @def_methods(m, my_sum_methods) def _(index : int, arg1, arg2): return arg1 + arg2 + index
Define three methods with different ready signals:
@def_methods(m, my_filter_read_methods, ready_list=lambda i: fifo.head == i) def _(_): return fifo.read(m)