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:
- Quick Start -- 10-step walkthrough covering all access types and the common flows.
- Architecture -- layer-by-layer design and the rationale behind each decision.
- 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.
- Core Model --
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cocotbext_ral-0.5.5.tar.gz.
File metadata
- Download URL: cocotbext_ral-0.5.5.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47554a6087462f9788c9ce55967d394bd31fbeac2a4693603d68e582c94153a6
|
|
| MD5 |
72fe5b1452d95bfd9e413ccbcd848d62
|
|
| BLAKE2b-256 |
ec7e6bacdbbeb3e5c48eac639ad614c1e260541ab882326797e8093092ea96d3
|
File details
Details for the file cocotbext_ral-0.5.5-py3-none-any.whl.
File metadata
- Download URL: cocotbext_ral-0.5.5-py3-none-any.whl
- Upload date:
- Size: 43.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
261c06189e2e81bc093454ccc503ab87cd8010ed9c261c8db2d224eb1998f4a2
|
|
| MD5 |
50d83bc9522908053785de1ceda811c1
|
|
| BLAKE2b-256 |
ebf3558e5437bc160aaffa3b290b26c8f8fa5cf84f22d1dcdaa60769b2c294bf
|