Skip to content

Transactions

Forastero expects drivers and monitors to consume or produce a standard form of transaction that is based on Python's dataclasses library. A custom base class (BaseTransaction) is provided that helps Forastero interact with these components.

For example, a transaction for driving requests on an address mapped interface to a memory may look something like the following:

tb/mapped/transaction.py
import dataclasses
from enum import IntEnum, auto

from forastero import BaseTransaction

class MappedAccess(IntEnum):
    READ  = auto()
    WRITE = auto()

@dataclasses.dataclass(kw_only=True)
class MappedRequest(BaseTransaction):
    address : int = 0
    access  : MappedAccess = MappedAccess.READ
    data    : int = 0

The MappedRequest transaction is decorated by dataclass to mark it as a dataclass object (see the Python documentation for more details), but importantly also inherits from BaseTransaction. This base class provides a standard entry called timestamp that is used to capture when the transaction was submitted to or captured from the design, it is excluded from comparisons and exists primarily for debug.


forastero.transaction.BaseTransaction dataclass

Base transaction object type

Parameters:

Name Type Description Default
timestamp int

The time at which the event occurred

lambda: get_sim_time(units='ns')()
_f_event Enum | None

Forastero event type to trigger on

None
_c_event Event | None

The cocotb Event to trigger when _f_event is reached

None

format(field, value)

Subclasses of BaseTransaction may override this to format different fields however they prefer.

Parameters:

Name Type Description Default
field str

Name of the field to format

required
value Any

Value to format

required

Returns:

Type Description
str

A string of the formatted value

tabulate(other=None)

Tabulate the fields of this transaction, optionally comparing against the fields of another object of this same type. When comparison is performed, mismatches are flagged in a separate column.

Parameters:

Name Type Description Default
other Optional[BaseTransaction]

Optional transaction to compare against

None

Returns:

Type Description
str

String of tabulated data