Skip to main content

Python-native Register Abstraction Layer (RAL) for cocotb with a data-driven runtime architecture

Project description

cocotbext-ral

A Python-native Register Abstraction Layer (RAL) for cocotb.

cocotbext-ral provides UVM-like register modeling, access-type-aware prediction, and automated checking -- all in pure Python, designed for cocotb hardware verification.

Features

  • Runtime-backed architecture with clean separation of register spec vs mutable state
  • Full access-type coverage: RW, RO, WO, W1C, W1S, RCLR, RSET
  • Smart volatile inference: RO, RCLR, RSET fields default to volatile (overridable)
  • Safe field writes that reject unsafe read-modify-write sequences
  • Backdoor resolution that scales to replicated blocks and chiplets
  • Transaction logging with detailed per-transaction file output
  • Pure-Python core -- model, predictor, and policies work without cocotb

Architecture

RegisterModel (spec)
        |
    RuntimeState (per-instance mutable state)
        |
RuntimePredictor + AccessPolicy
        |
RuntimeRAL -> SafeRuntimeRAL -> IntegratedRuntimeRAL
                                       |          |
                                  Backdoor    Transaction Log

Installation

pip install cocotbext-ral

Optional extras:

pip install cocotbext-ral[cocotb]   # cocotb + cocotbext-axi
pip install cocotbext-ral[rdl]      # SystemRDL compiler
pip install cocotbext-ral[all]      # Everything

Quick start

With cocotb simulation

import cocotb
from cocotbext.axi import AxiLiteMaster, AxiLiteBus
from cocotbext.ral import IntegratedRuntimeRAL
from cocotbext.ral.adapters import load_json

@cocotb.test()
async def test_registers(dut):
    model = load_json("registers.json")

    ral = IntegratedRuntimeRAL("my_ip", model, dut_handle=dut, txn_log=True)
    master = AxiLiteMaster(AxiLiteBus.from_prefix(dut, "s_axil"), dut.clk, dut.rst)
    ral.attach_master(master, protocol="axil", interface="dut.s_axil")

    # Write and read with automatic prediction checking
    await ral.write("CTRL", 0x01)
    val = await ral.read("CTRL")

    # Field-level access with RMW safety
    await ral.write_field("CTRL", "enable", 1)
    en = await ral.read_field("CTRL", "enable")

    # Check results
    ral.raise_on_errors()
    ral.close_txn_log()

Standalone (no cocotb)

The core model, predictor, and policy layers have zero dependencies:

from cocotbext.ral import RegisterModel, Register, RegisterField, SwAccess
from cocotbext.ral.runtime_predictor import RuntimePredictor

model = RegisterModel("my_ip")
reg = Register("CTRL", address=0x0, size_bits=32, fields=[
    RegisterField("enable", lsb=0, msb=0, reset_value=0, sw_access=SwAccess.RW),
    RegisterField("irq", lsb=8, msb=15, reset_value=0xFF, sw_access=SwAccess.W1C),
])
model.add_register(reg, hierarchical_name="block.CTRL")

pred = RuntimePredictor(model)
pred.predict_write(0x0, 0x01)
result = pred.predict_read(0x0, 0x01)
assert result.passed

API classes

Class Description
IntegratedRuntimeRAL Recommended. Runtime state + RMW safety + backdoor + transaction log
SafeRuntimeRAL Runtime state + RMW safety checks
RuntimeRAL Runtime state-backed prediction
RuntimePredictor Standalone prediction engine (no cocotb needed)
RuntimeState Per-instance mutable register state
AccessPolicy Per-field read/write behavior
TransactionLogger Detailed file-based transaction logging
BackdoorResolver HDL path resolution (base, Prefix, Mapping variants)
RegisterModel Structural register specification

Register loading

from cocotbext.ral.adapters import load_json, load_rdl

model = load_json("registers.json")                        # RDL-generated JSON
model = load_rdl("regs.rdl", top_name="my_ip", incdir=[])  # SystemRDL source

Access types

SwAccess Write behavior Read behavior Volatile by default
RW Update value Check prediction No
RO Ignored Not checked Yes
WO Update value Not checked No
W1C Clear written-1 bits Check prediction No
W1S Set written-1 bits Check prediction No
RCLR Ignored Clears to 0 after read Yes
RSET Ignored Sets to all-1s after read Yes

Aliases: WOCLR=W1C, WOSET=W1S, RC=RCLR, RS=RSET

Transaction logging

Enable detailed per-transaction file output:

# Default filename (register_txns.log)
ral = IntegratedRuntimeRAL("ip", model, txn_log=True)

# Custom path
ral = IntegratedRuntimeRAL("ip", model, txn_log="my_regs.log")

# Phase annotations
ral.set_txn_phase("Phase 1: Reset value check")
await ral.write(addr, value)

# Summary and close
ral.close_txn_log()

Each transaction entry includes: model path, address, data, protocol, interface HDL path, status (PASS/FAIL/SKIP), mirror state, per-field breakdown, and RMW safety assessment.

Testing

pip install -e .[dev]
pytest

146 tests covering: register model (including search / group helpers), runtime predictor (all access types), access policies, RMW safety, backdoor resolvers, runtime state, volatile policy, debug helpers, checker, JSON loader, transaction logger, and RuntimeRAL construction / reset / check-toggle helpers.

Documentation

Read in this order:

  1. Quick Start -- 10-step walkthrough covering all access types and the common flows.
  2. Architecture -- layer-by-layer design and the rationale behind each decision.
  3. API reference (pick what you need):
    • Core Model -- RegisterModel, Register, RegisterField, SwAccess.
    • Runtime API -- IntegratedRuntimeRAL, SafeRuntimeRAL, mirror update modes, RMW logging, search / bulk APIs.
    • Integration and Loaders -- JSON/RDL loaders, backdoor resolvers, transaction logging.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocotbext_ral-0.5.4.tar.gz (49.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cocotbext_ral-0.5.4-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file cocotbext_ral-0.5.4.tar.gz.

File metadata

  • Download URL: cocotbext_ral-0.5.4.tar.gz
  • Upload date:
  • Size: 49.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cocotbext_ral-0.5.4.tar.gz
Algorithm Hash digest
SHA256 c3ad09751f429e2d4a9e7d05388079283f2c5133c16445aebff94b775246aa0e
MD5 44eea91c6d10b72cb6dbd7be682eeeab
BLAKE2b-256 3f7e5b560a7aa220e3de3273b1621abe8fa6e5430a8d2f8a5acebba34b8e2dcf

See more details on using hashes here.

File details

Details for the file cocotbext_ral-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: cocotbext_ral-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 42.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cocotbext_ral-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 367907972511d5c81ba021fc75e9c2bb88dae4a419ca8149faf72ff58e540c57
MD5 f622217dc766e251237e68b5da0567b3
BLAKE2b-256 de1b0a495cc48fdd77d8964df7affd27e39e7b06cc14628e90e22ca89a281b7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page