Integration guide

Register Interfaces

Connect your Livt components to software through memory-mapped registers.

Software often controls hardware by reading and writing registers at known addresses. A write may configure a threshold or start an operation; a read may return status or the result of a calculation. Those addresses, bit layouts, and behaviours form a contract between the component and its consumers.

HxS stands for Hardware × Software: the “H” represents hardware, the “S” represents software, and the “x” marks where they meet. HxS is a language for describing registers and address maps, giving hardware and software a shared definition of their interface.

Livt integrates HxS so you can describe that contract beside the fields and functions that implement it. Annotations define the register map, and the build generates the interface logic that connects it to the selected bus. You can also bind a component to an existing HxS description when the register map is already defined. This page follows one AXI4-Lite example from source through bus-level tests and generated output.

Prepare your project

In the Livt Project view, right-click your project’s Dependencies node and choose Add a Package…. Search for Livt.Bus and select the version you intend to use. The package supplies the bus contracts and test masters used below; the HxS annotations are imported separately from Livt.HxS. See Packages and Dependencies for the package-selection and synchronisation workflow.

Create src/DeviceControl.lvt for the component and tests/DeviceControlTest.lvt for its tests. The following manifest shows the configuration for a standalone example. Keep the dependency version selected by the package picker in place of the placeholder, and adapt the project and test settings if you are adding the example to an existing project.

toml
[project]
name = "RegisterDemo"
component = "DeviceControl"
path = "src"
outdir = "out"

[tests]
path = "tests"
components = ["DeviceControlTest"]

[dependencies]
"Livt.Bus" = "<selected-version>"

Create your first register interface

Our example has three registers: a stored threshold, an enable command, and a calculation that accepts a value and returns a result. Put the following complete component in src/DeviceControl.lvt:

livt
using Livt.HxS
using Livt.Bus.Axi4Lite

@Interface(BusType="AXI4Lite")
component DeviceControl
{
    @Register(Id="Threshold", Offset=0)
    threshold: uint

    public enabled: logic

    new(bus: flip IAxi4Lite32Master)
    {
        threshold = 0 as uint
        enabled = 0b0
    }

    @Register(Id="Enable", Offset=4)
    public fn Enable()
    {
        enabled = 0b1
    }

    @Register(Id="Transform", Offset=8)
    @Data(Id="Result", Position=0)
    public fn Transform(@Data(Id="Value", Position=0) value: uint) uint
    {
        return (value * (2 as uint)) + (1 as uint)
    }
}

@Interface selects the bus protocol, and @Register binds a field or function to a register. HxS supplies a default block and a 32-bit data layout. A bare @Register can derive its ID from the source member and use the next aligned offset. Here we spell out IDs and offsets so the address table and tests remain easy to follow as the example grows.

The constructor exposes the bus connection through flip IAxi4Lite32Master. The interface describes signals from the master’s perspective; flip reverses their directions so DeviceControl receives requests and supplies responses as the target. Passing a compatible test master into this constructor connects the test to the same bus boundary used by a parent design.

AddressRegisterWriteRead
0x00ThresholdStore a 32-bit unsigned value in bits 31–0.Return the current threshold, initially zero.
0x04EnableInvoke Enable(); the function takes no data parameter.No application read result is defined by this command.
0x08TransformPass bits 31–0 to Transform(value).Return the most recent completed result in bits 31–0.

These addresses are relative to the component’s bus address space. A system that maps the peripheral at a higher base address adds that base when software accesses it. Writing five to 0x08 calculates 5 × 2 + 1, so the subsequent read should return eleven. The unannotated enabled field is observable through the Livt API but is not another register in this map.

DeviceControl source in VS Code beside RegisterDemo and its installed Livt.Bus dependency.
Keep the register definitions beside their implementation.

Test the interface through the bus

A direct call to device.Transform(5) can check the arithmetic, but it does not check address decoding, register data packing, or bus handshakes. The transaction test below exercises those connections. Put it in tests/DeviceControlTest.lvt:

livt
using Livt.Bus.Axi4Lite.Testing

@Test
component DeviceControlTest
{
    master: Axi4LiteTestMaster32
    device: DeviceControl

    new()
    {
        master = new Axi4LiteTestMaster32()
        device = new DeviceControl(master)
    }

    @Test
    fn ConfiguresDevice()
    {
        master.SetTimeoutTicks(200)
        master.Verify32(0x00, 0 as uint)
        master.Write32(0x00, 7 as uint)
        master.Verify32(0x00, 7 as uint)
        master.Write32(0x04, 1 as uint)
        assert device.enabled == 0b1
    }

    @Test
    fn ReadsCompletedResult()
    {
        master.SetTimeoutTicks(200)
        master.Write32(0x08, 5 as uint)
        master.Verify32(0x08, 11 as uint)
        master.Verify32(0x08, 11 as uint)
    }
}

Axi4LiteTestMaster32 implements the fixed-width IAxi4Lite32Master contract used by the component. The fixture constructs the master and passes it into the device. Each test sets a transaction timeout so a missing response produces a failure rather than an unlimited wait. Write32 performs a write and checks successful completion; Verify32 reads, checks the response, and compares the returned word with the expected value.

ConfiguresDevice checks the initial threshold, writes and reads back a new value, and sends the enable command through its register. ReadsCompletedResult submits a calculation and reads the completed result twice. The repeated read checks that observing the result does not consume it.

Save the files, open Livt Tests or VS Code’s Test Explorer, and run DeviceControlTest. Both tests should pass. Open Show Livt Test Output to follow the build and simulation stages; see Testing for the complete test-run workflow.

DeviceControlTest passing in VS Code with register-write and repeated-read checks beside the Livt Tests output.
Both bus tests pass against the generated register interface.

Investigate a register failure

To see a readback mismatch, temporarily change the first expected result in ReadsCompletedResult from eleven to twelve and rerun it. The master still reads eleven, so the comparison fails. Inspect the failure details and the transaction that produced them, then restore the expectation and run both tests again.

Failed register readback test in VS Code showing an expected value of 12 and an actual value of 11.
The comparison shows 32-bit binary values: the expected value ends in 1100 (twelve), while the actual value ends in 1011 (eleven).

For an unexpected value, check the address, data width, bit positions, and whether the operation has reached the completion point promised by its contract. A timeout calls for a different investigation: check the bus connection, clock/reset state, and whether the target responds. The assertion may be located inside the test master, so use the calling test and the reported value to identify the relevant transaction.

A layout or binding diagnostic happens before those transactions run. Inspect the Problems view for overlapping addresses, incompatible bus types, or IDs that do not match an external HxS description. Fix the map or connection rather than increasing the timeout to compensate.

Choose how registers behave

Use a function when accessing the register should perform an action. The parameterless Enable() function is a command trigger: a write invokes it, and the written word supplies no function argument. A function with parameters receives values from the write layout. A parameterless function with a return value can provide a value when the register is read, making it useful for computed status.

A function with both parameters and a return value, such as Transform, combines a write-triggered operation with readable result data. Its write and read layouts are separate, which is why Value and Result can both begin at bit zero. The latest completed result remains readable until another invocation completes. The example checks sequential transactions; it does not establish a throughput or latency guarantee for overlapping requests.

Distinguish the function’s completion from any longer activity it starts. If a command merely enqueues work, completion of that command does not mean that a peripheral has finished the work. Expose and test a suitable status or completion indication for the application’s actual contract. The acceptance and completion discussion explains how to test that distinction.

Use fields for configuration and status

A stored field is a concise choice when a register simply holds configuration. In the example, bus writes update threshold, and reads return its current value. Use directed fields for input or output contracts and check their generated access behaviour: input-directed fields map to write-facing data, while output-directed fields expose read-facing data.

Add @Data when you need an explicit field ID, position, description, or access behaviour. When a write carries several function parameters, assign their positions deliberately and document the packed word. For example, two bytes at positions zero and eight occupy bits 7–0 and 15–8. Treat the write layout and read layout separately, and test the packing through bus transactions.

Define a stable register map

Automatic placement is convenient while exploring a design: HxS creates a default block and assigns registers aligned offsets in source order. Once software depends on the map, give the registers stable IDs and explicit locations. Otherwise, adding or reordering a member can change an address that a consumer already uses. An ID provides a stable name for the contract; it does not by itself fix the register’s address.

Use @Block to group registers into address regions. BaseAddress locates the block, Alignment controls automatic placement, and Size can bound the region. A register’s Offset is relative to its selected block, while Address is absolute within the interface. For example, a block at 0x100 with a register offset of 0x08 places that register at 0x108.

The layout checks IDs, block references, alignment, overlap, block bounds, and address width. Registers without an explicit address continue to use automatic placement within their block. Review the generated map after a layout change and update the bus tests and consuming software together.

Leave room for future fields

Use @Reserved to describe unused bit ranges in a register. A field occupying bits 7–0 can leave bits 15–8 reserved for future expansion, for example. Reserved bits belong to the public contract too: document their access behaviour and test the defined read and write behaviour instead of relying on an accidental implementation result. Keep data positions and reserved ranges non-overlapping.

Describe values and reset behaviour

Name and Description provide information for people and generated descriptions, while Id identifies the object used by bindings. Use @Enum and @Value to describe named encodings, such as Off, Idle, and Run. These names make the register contract easier to understand; they do not replace tests of how the component responds to the encoded values.

@Reset records reset information for a data or enum binding. Keep it consistent with the component’s actual initialisation and reset behaviour. If the documented reset mode is Idle with value one, initialise the corresponding stored field accordingly and verify its first bus read. Also test reset assertion and release when that is part of the interface’s requirements; metadata alone is not evidence that the implemented reset sequence behaves as intended.

Inspect the generated interface

After a successful build or test run, expand Generated Outputs in the Livt Project view to inspect the generated HDL. To inspect the register description, use Go to File to open Global.DeviceControl.hxs. With the example’s default debug profile, it is written to out/debug/hxs/Global.DeviceControl.hxs. It shows the interface, block, register offsets, and data behaviour derived from the annotations. The output also contains generated VHDL for the register interface and the Livt component.

Generated Outputs expanded in VS Code with Global.DeviceControl.hxs open, showing the generated block and register layout.
Review the generated HxS description to confirm the register layout produced by the source annotations.

Use these files to inspect the result, then change the authored Livt source or external HxS description when you need a correction. Edits made directly to generated output are lost on regeneration. Output paths depend on the project’s output directory and build profile.

Reuse an existing HxS description

If a register map is already maintained as an HxS file, keep that description as the contract and bind the Livt implementation to it. Set File on @Interface to a project-relative path and use the IDs defined by the file. For example, the interface annotation could be:

livt
@Interface(File="src/hxs/DeviceControl.hxs", Id="DeviceControlIfc")

The component’s register and data bindings must match the corresponding objects in that description. The path and interface ID above are illustrative: use the actual file and IDs from your contract. Keep the file with the package sources, such as under src/hxs, so it remains available through the normal build and package workflows. Select BusType explicitly for Avalon or Wishbone rather than relying on the AXI4-Lite default.

This approach lets a team reuse an established register map while implementing and testing its behaviour in Livt. A renamed ID or moved field is a contract change, so review the HxS file, Livt bindings, and transaction tests together. The HxS Objects reference explains the underlying register-map objects.

Extend the interface

Select between register views

Selectors are useful when a limited address region presents different views, such as banks of configuration. @Select declares a named selector on a field, and Selects associates it with a block, register, or delegated window. The default selector behaviour is read/write; specify Behaviour when a different access contract is required.

Explain to consumers how to choose the view before accessing it, and test each selected view as well as transitions between views. Keep ordinary registers unbanked when that meets the requirement: selectors add state to the access protocol that software and tests must respect.

Forward an address region

Use a delegated window when part of the address map belongs to another bus target, such as a memory or child peripheral. @Delegate reserves the region and binds it to a public bus endpoint. The endpoint’s type must match the selected bus protocol, and the parent design must connect it to the downstream target.

For a window starting at offset 0x20 with size 0x20 in a block based at zero, the reserved addresses are 0x20 through 0x3F. Check the first and last addresses, the downstream response, and the interaction with local registers. A declared window does not itself supply the downstream memory or peripheral.

Choose a bus contract

Choose the bus that matches the surrounding system. The component’s annotation, constructor contract, delegated endpoints, and test master must agree. The fixed-width contracts and matching transaction masters supplied by Livt.Bus include:

Bus typeContractTransaction master
AXI4LiteLivt.Bus.Axi4Lite.IAxi4Lite32MasterAxi4LiteTestMaster32
AvalonLivt.Bus.Avalon.IAvalon32MasterAvalonTestMaster32
WishboneLivt.Bus.Wishbone.IWishbone32MasterWishboneTestMaster32

Each test master is in the corresponding bus namespace’s Testing namespace. The example on this page uses AXI4-Lite; when changing protocol, rerun the interface tests with the matching master and check the new protocol’s response and timing behaviour.

Integrate and maintain the interface

Keep the bus constructor visible when reusing the component. A parent component can pass the same contract used by the test fixture, while internal Livt code can still call its ordinary fields and functions directly. Those direct accesses are useful within a design, but retain the bus-level tests to verify the interface that software and external masters observe.

Before exporting the design, run the transaction tests and review changes to IDs, addresses, bit positions, reset values, and access behaviour. Extend the suite as the map grows: cover boundary addresses, repeated commands and reads, byte enables, reserved bits, and any selected or delegated regions. For intentionally invalid accesses, test the defined error response using suitable lower-level transactions rather than a helper that requires a successful response.

HxS-annotated components use the normal Livt vendor workflow. In the Livt Project view, use the project’s Vendor node to choose and configure an integration. Continue with Hardware Integration for standalone projects, IP packaging, wrappers, and implementation checks. Keep the register map versioned with its implementation so software and hardware consumers can use a compatible contract.

Annotation reference

Annotation parameter names are case-sensitive. Use the defaults when they express the intended contract, and add explicit metadata or layout settings where consumers depend on them. The table below collects common parameters for reference; the HxS Objects guide describes the corresponding objects in more detail.

Annotation Applies to Common parameters
@Interface Component File, Id, Name, Description, BusDescription, BusType, AddressBusWidth, DataBusWidth
@Block Component Id, Name, Description, BaseAddress, Alignment, Size, Selects
@Register Field or function Id, Block, Name, Description, Offset, Address, Async, Selects
@Data Field, function, or parameter Id, Name, Description, Position, Behaviour
@Enum Field, function, or parameter Id, Name, Description, Position
@Value Enum-bound element Id, Name, Description, Value
@Reset Data or enum binding Id, Name, Description, Value
@Reserved Component Id, Register, Name, Description, Position, Width, Behaviour
@Select Field Id, Name, Description, Behaviour
@Delegate Public bus endpoint field Id, Block, Name, Description, Offset, Address, Size, Selects