Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
162bfd4
Remove unnecessary python 3.8 bakward compatibility support
krcb197 Nov 5, 2025
a2ff8f3
move int field test to a function to reduced code
krcb197 Nov 8, 2025
5f8e7ea
Update the version number
krcb197 Nov 8, 2025
70c8d0a
Resolve typing issues
krcb197 Nov 8, 2025
6679b86
Fix missing tab in template
krcb197 Nov 8, 2025
20e9498
Merge pull request #237 from krcb197/234-optimised-test_int_field_rea…
krcb197 Nov 9, 2025
3ace243
Optimise the `test_enum_field_read_and_write`
krcb197 Nov 9, 2025
c81851a
Resttucture the test library with a shared base class between async a…
krcb197 Nov 9, 2025
b40d01c
Fixed a bug with the async __single_int_field_read_test
krcb197 Nov 9, 2025
b4b5e1e
Fixed a bug with the async __single_int_field_read_test
krcb197 Nov 9, 2025
6537501
Optimised the `test_field_properties` by merging it to main field tests
krcb197 Nov 9, 2025
97840ac
Reduced the number of combinations tested in the test_export->TestExp…
krcb197 Nov 9, 2025
c1eb69d
Reduced the number of combinations tested in the test_export->TestExp…
krcb197 Nov 9, 2025
c9f53de
Merge remote-tracking branch 'origin/240-optimised-test_field_propert…
krcb197 Nov 9, 2025
97fac0d
Resolved some basic linting issues
krcb197 Nov 9, 2025
ba9e469
Fixed the check for whether the value is in the enumeration or not
krcb197 Nov 9, 2025
00c072e
Fixed the typing on the call to `_single_enum_field_read_and_write_test`
krcb197 Nov 9, 2025
9bffafd
Fixed the typing on the call to `_single_enum_field_read_and_write_test`
krcb197 Nov 9, 2025
c29e520
Merge pull request #239 from krcb197/238-optimised-test_enum_field_re…
krcb197 Nov 9, 2025
aeabb17
Merge pull request #242 from krcb197/240-optimised-test_field_properties
krcb197 Nov 9, 2025
53da9a1
Optimised `test_register_read_and_write`
krcb197 Nov 10, 2025
0b1fbed
Increased release candiate version in preparation for next pre-release
krcb197 Nov 10, 2025
213a3b1
Merge branch 'release/3.0.0' of https://github.com/krcb197/PeakRDL-py…
krcb197 Nov 10, 2025
53dcdd8
resolving merge issued from release\3.0.0 branch update
krcb197 Nov 10, 2025
ee1add3
Optimise `test_register_properties`
krcb197 Nov 10, 2025
d0857d1
Optimise `test_register_properties`
krcb197 Nov 10, 2025
bea3687
Merge remote-tracking branch 'origin/243-optimised-test_register_read…
krcb197 Nov 10, 2025
28bcb03
Fixed a merge bug reg_value
krcb197 Nov 10, 2025
39c8adb
Simplified the field property checks
krcb197 Nov 11, 2025
1fca0a9
Fix linting issues
krcb197 Nov 11, 2025
63b489f
Optimise `def test_register_read_fields`
krcb197 Nov 12, 2025
9974d1c
Moved await to the correct place
krcb197 Nov 12, 2025
77837a7
Optimise `test_register_read_context_manager`
krcb197 Nov 13, 2025
511a490
remove the `skip_write` from register `single_read_modify_write`
krcb197 Nov 13, 2025
8c1995f
clean up bugs from previous implementations
krcb197 Nov 13, 2025
c559267
Fix the unit tests that failed due to the withdrawal of skip_write
krcb197 Nov 14, 2025
d34e6c5
Tidy up the file
krcb197 Nov 14, 2025
08aa752
Added some sleeps to see if it helps the CI problem
krcb197 Nov 15, 2025
4518a63
optimise `test_register_write_context_manager`
krcb197 Nov 15, 2025
676dd0c
Remove `test_register_write_context_manager` from the automatically g…
krcb197 Nov 15, 2025
bb1e905
Optimise `test_register_write_fields`
krcb197 Nov 15, 2025
a65db0e
Merge pull request #248 from krcb197/243-optimised-test_register_read…
krcb197 Nov 15, 2025
b58c6c8
Change the test classes over to using the simulator rather than the d…
krcb197 Nov 15, 2025
63adeae
Moved the simulator register test into the test library and merged it…
krcb197 Nov 15, 2025
67ebadc
Up revision the version number for the simulator test optimisation
krcb197 Nov 15, 2025
39cb67b
Simplify the simulation register test
krcb197 Nov 16, 2025
8b2d6f2
Optimise the field simulator tests by merging them into the main regi…
krcb197 Nov 16, 2025
197f6e3
Fix a bug with address maps that don't have memories
krcb197 Nov 16, 2025
273dcee
Added a missing await
krcb197 Nov 16, 2025
06a126c
Move the hashing method inside the generated tests to reduce the numb…
krcb197 Nov 16, 2025
658baf4
Merge pull request #254 from krcb197/244-autogenerated-simulator-test…
krcb197 Nov 16, 2025
6e44995
Merge remote-tracking branch 'origin/release/3.0.0' into release/3.0.0
krcb197 Nov 16, 2025
b44670d
Optimise the `test_name_property` and `test_desc` into a single test
krcb197 Nov 17, 2025
d3d475d
Revise the version number
krcb197 Nov 17, 2025
204d2f8
Annotate return type for test method
krcb197 Nov 17, 2025
7263799
Merge pull request #259 from krcb197/257-merge-test_name_property-and…
krcb197 Nov 18, 2025
acb3fef
Reduce the console output from generate_and_test.py
krcb197 Nov 21, 2025
783cfc7
Merge remote-tracking branch 'origin/release/3.0.0' into release/3.0.0
krcb197 Nov 21, 2025
e226407
Merge branch 'main' of https://github.com/krcb197/PeakRDL-python into…
krcb197 Nov 21, 2025
17b5b76
Correct the license message in the file docstring
krcb197 Nov 21, 2025
46c856d
Change the documentation to use `sphinx-book-theme` which which is mu…
krcb197 Nov 22, 2025
60fbdd2
Simplify the `test_inst_name` test and update the revision to rc5
krcb197 Nov 22, 2025
6b63fef
Merge pull request #264 from krcb197/263-change-the-documentation-to-…
krcb197 Nov 22, 2025
c0b47ac
Move all the field interator tests into the single register test
krcb197 Nov 22, 2025
a418d4c
Merge pull request #265 from krcb197/256-optimise-test_inst_name
krcb197 Nov 22, 2025
1fd0758
Test for memory, register and section iterators
krcb197 Nov 22, 2025
fc07406
Fixed a bug with the parent typing of write only registers
krcb197 Nov 27, 2025
5ca8112
Optimise the remaining traversal interator checks
krcb197 Nov 27, 2025
999f1a0
Linting cleanups
krcb197 Nov 27, 2025
7c1d488
Merge branch 'release/3.0.0' of https://github.com/krcb197/PeakRDL-py…
krcb197 Nov 27, 2025
d9d2263
Merge pull request #266 from krcb197/258-optimise-test_traversal_iter…
krcb197 Nov 27, 2025
6a06a58
Revise version number
krcb197 Nov 28, 2025
f3cda7d
Update to the iterator test:
krcb197 Nov 28, 2025
63cbede
Remove old jinja template logic checking for pre-3.8
krcb197 Nov 28, 2025
12ea6d8
Merge pull request #269 from krcb197/258-optimise-test_traversal_iter…
krcb197 Nov 28, 2025
19d9320
Merge pull request #271 from krcb197/270-remove-old-checks-on-pre-pyt…
krcb197 Nov 29, 2025
7767e1a
Move all the memory read/write testing into the test library
krcb197 Nov 29, 2025
1a9c1b9
Fix some bugs from the previus commit
krcb197 Nov 29, 2025
211c829
Added checks for illegal values
krcb197 Nov 29, 2025
7166ce3
Added checks for illegal values
krcb197 Nov 29, 2025
a612cba
Line length fixes
krcb197 Nov 29, 2025
f579dee
Fix the illegal range checks to check lower value too
krcb197 Nov 29, 2025
10d5923
Change the typecode for 16-bit memory width to `H` and correct the er…
krcb197 Nov 30, 2025
73c681a
Add min/max value checking to the memory write
krcb197 Nov 30, 2025
f1b6a97
Move all the simulator memory tests into the `lib_test`
krcb197 Nov 30, 2025
814e323
Put in tests for the `addrmap` and `regfile`, then remove the individ…
krcb197 Nov 30, 2025
354a367
Fix bug with import of simulator test class
krcb197 Nov 30, 2025
7993fab
Fix bug with import of simulator test class
krcb197 Nov 30, 2025
cc05bbb
Remove the typecode checking in non-legacy mode
krcb197 Nov 30, 2025
38644f9
Merge fixes
krcb197 Nov 30, 2025
6460979
Fix issue with the testing of parent addrmap and error in the regfile…
krcb197 Nov 30, 2025
bfe6107
Handle the case where the hardware array sizes are larger than needed.
krcb197 Nov 30, 2025
ae02f37
Handle the case where the hardware array sizes are larger than needed.
krcb197 Nov 30, 2025
eccbaf4
Move the bad attribute test inside the library
krcb197 Nov 30, 2025
d9759ee
Merge pull request #273 from krcb197/267-make-a-generalised-memory-te…
krcb197 Dec 1, 2025
5c020fa
Merge the `test_name_map` into the iterator test
krcb197 Dec 1, 2025
690c264
Merge branch 'release/3.0.0' of https://github.com/krcb197/PeakRDL-py…
krcb197 Dec 1, 2025
6f08aca
Merge pull request #275 from krcb197/268-further-optimise-the-propert…
krcb197 Dec 2, 2025
3154d9f
Optimise the `test_field_encoding_properties` by inclduing within the…
krcb197 Dec 3, 2025
f4eee76
Fix a problem with the legacy enum type not generating the correct te…
krcb197 Dec 3, 2025
cefaf9a
Merge pull request #277 from krcb197/276-optimise-test_field_encoding…
krcb197 Dec 3, 2025
307c5d5
Remove the `decode_read_value` and `encode_write_value` public API. c…
krcb197 Dec 9, 2025
acb8a4e
Merge pull request #279 from krcb197/184-deprecate-decode_read_value-…
krcb197 Dec 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .github/workflows/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,42 @@ jobs:
run: |

python -m generate_and_test --RDL_source_file tests/testcases/simulator_test.rdl --root_node simulator_test
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/simulator_test.rdl --root_node simulator_test --async
sleep 10

python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map --legacy_block_access
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map --legacy_enum_type
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map --copy_libraries
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map --hashing_mode PYTHONHASH
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/accelera-generic_example.rdl --root_node some_register_map --hashing_mode SHA256
sleep 10

python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp bool_property_to_include
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp bool_property_to_include enum_property_to_include
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp bool_property_to_include enum_property_to_include int_property_to_include
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp bool_property_to_include enum_property_to_include int_property_to_include str_property_to_include
sleep 10
python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp bool_property_to_include enum_property_to_include int_property_to_include str_property_to_include struct_property_to_include double_layer_struct_property_to_include
sleep 10

python -m generate_and_test --RDL_source_file tests/testcases/user_defined_properties.rdl --root_node user_defined_properties --udp_regex "bool_property_to_include|enum_property_to_include|int_property_to_include|str_property_to_include|struct_property_to_include|double_layer_struct_property_to_include"
sleep 10

python -m generate_and_test --RDL_source_file tests/testcases/reserved_elements.rdl --root_node reserved_elements --hide_regex "(?:[\w_\[\]]+\.)+RSVD"
sleep 10

python -m generate_and_test --RDL_source_file tests/testcases/name_desc_all_levels.rdl --root_node name_desc_all_levels --skip_systemrdl_name_and_desc_properties
sleep 10

peakrdl_integration:
needs:
Expand Down Expand Up @@ -323,7 +339,6 @@ jobs:
matrix:
python-version: [3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
lib_copy: [true, false]
hashing_mode: ["PYTHONHASH", "SHA256"]

steps:
- uses: actions/checkout@v4
Expand All @@ -349,12 +364,12 @@ jobs:
- name: Generate testcases (lib_copy true)
if: matrix.lib_copy == true
run: |
python generate_testcases.py --copy_libraries --output testcase_output --hashing_mode ${{ matrix.hashing_mode }}
python generate_testcases.py --copy_libraries --output testcase_output

- name: Generate testcases (lib_copy false)
if: matrix.lib_copy == false
run: |
python generate_testcases.py --output testcase_output --hashing_mode ${{ matrix.hashing_mode }}
python generate_testcases.py --output testcase_output

- name: Static checks
run: |
Expand Down
11 changes: 10 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
html_theme = "sphinx_book_theme"

html_theme_options = {
"repository_url": "https://github.com/krcb197/PeakRDL-python",
"path_to_docs": "docs",
"use_download_button": False,
"use_source_button": True,
"use_repository_button": True,
"use_issues_button": True,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pygments-systemrdl
peakrdl-python
sphinx_rtd_theme
sphinx-book-theme
8 changes: 6 additions & 2 deletions generate_and_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#from coverage import Coverage

#from peakrdl_ipxact import IPXACTImporter
from peakrdl_ipxact import IPXACTImporter

sys.path.append('src')
from peakrdl_python import PythonExporter
Expand All @@ -46,6 +46,8 @@
CommandLineParser = argparse.ArgumentParser(description='Test the framework')
CommandLineParser.add_argument('--RDL_source_file', dest='root_RDL_file',
type=pathlib.Path, required=True)
CommandLineParser.add_argument('--RDL_additional_file', dest='additional_file_RDL_file',
type=pathlib.Path)
CommandLineParser.add_argument('--root_node', dest='root_node',
type=str, required=True)
CommandLineParser.add_argument('--output', dest='output_path',
Expand Down Expand Up @@ -195,13 +197,15 @@ def build_logging_cong(logfilepath:str):
else:
raise(RuntimeError('not a list'))

if CommandLineArgs.additional_file_RDL_file is not None:
rdlc.compile_file(CommandLineArgs.additional_file_RDL_file)
rdlc.compile_file(CommandLineArgs.root_RDL_file)
spec = rdlc.elaborate(top_def_name=CommandLineArgs.root_node).top

node_list = []
for node in spec.descendants(unroll=True):
node_list.append(node)
print(node.inst_name)
# print(node.inst_name)

# write out text file of all the nodes names, this can be used to debug regex issues
if CommandLineArgs.full_inst_file is not None:
Expand Down
23 changes: 8 additions & 15 deletions generate_testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@
'and debugging as multiple copies of the libraries can cause'
'confusion. Therefore by default this script does not copy '
'them over.')
CommandLineParser.add_argument('--hashing_mode',
dest='hashing_mode',
type=str,
choices=[item.name for item in NodeHashingMethod],
default='PYTHONHASH',
help='The method used to generate the hash of the node, in order to '
'deduplicate the register model. Set this to `SHA256` if '
'the python names need to stay consistent one export to the '
'next. However, this mode is slower')


def compile_rdl(infile: str,
incl_search_paths: Optional[List[str]] = None,
Expand Down Expand Up @@ -158,19 +148,22 @@ def generate(root: Node, outdir: str,
options = {
'asyncoutput': [True, False],
'legacy': [True, False],
'skip_systemrdl_name_and_desc_in_docstring': [True, False]
'skip_systemrdl_name_and_desc_in_docstring': [True, False],
'hashing': list(NodeHashingMethod)
}

for asyncoutput, legacy, skip_name_and_desc_in_docstring in product(
for asyncoutput, legacy, skip_name_and_desc_in_docstring, hashing_method in product(
options['asyncoutput'], options['legacy'],
options['skip_systemrdl_name_and_desc_in_docstring'] ):
options['skip_systemrdl_name_and_desc_in_docstring'],
options['hashing']):

# test cases that use the extended widths an not be tested in the non-legacy modes
if (testcase_name in ['extended_memories', 'extended_sizes_registers_array']) and \
(legacy is True):
continue

folder_parts = 'raw'
folder_parts = 'raw_'
folder_parts += hashing_method.name
if asyncoutput:
folder_parts += '_async'
if legacy:
Expand All @@ -184,7 +177,7 @@ def generate(root: Node, outdir: str,
legacy_enum_type=legacy,
copy_library=CommandLineArgs.copy_libraries,
skip_systemrdl_name_and_desc_in_docstring=skip_name_and_desc_in_docstring,
hashing_mode=NodeHashingMethod[CommandLineArgs.hashing_mode])
hashing_mode=hashing_method)

module_fqfn = output_path / folder_parts / '__init__.py'
with open(module_fqfn, 'w', encoding='utf-8') as fid:
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ dev = [
"mypy",
"pylint",
"coverage",
"peakrdl"
"peakrdl",
# needed for the documentation build
"sphinx-book-theme",
"pygments-systemrdl"

]
peakrdl = [
"peakrdl"
Expand Down
6 changes: 3 additions & 3 deletions src/peakrdl_python/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Copyright (C) 2021 - 2025

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
Expand All @@ -17,4 +17,4 @@

Variables that describes the peakrdl-python Package
"""
__version__ = "2.2.0"
__version__ = "3.0.0rc8"
7 changes: 7 additions & 0 deletions src/peakrdl_python/_deploy_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ class GeneratedPackage(PythonPackage):
Args:
include_tests (bool): include the tests package
"""
# pylint:disable=too-many-instance-attributes
template_lib_package = PythonPackage(Path(__file__).parent / 'lib')
template_sim_lib_package = PythonPackage(Path(__file__).parent / 'sim_lib')
template_lib_test_package = PythonPackage(Path(__file__).parent / 'lib_test')

def __init__(self, path: str, package_name: str, include_tests: bool, include_libraries: bool):
super().__init__(Path(path) / package_name)
Expand All @@ -169,6 +171,9 @@ def __init__(self, path: str, package_name: str, include_tests: bool, include_li
self.reg_model = _GeneratedRegModelPackage(self.child_path('reg_model'))

if include_tests:
if include_libraries:
self.lib_test = self.child_ref_package('lib_test',
self.template_lib_test_package)
self.tests = self.child_package('tests')

if include_libraries:
Expand Down Expand Up @@ -200,4 +205,6 @@ def create_empty_package(self, cleanup: bool) -> None:
if self._include_libraries:
self.lib.create_empty_package(cleanup=cleanup)
self.sim_lib.create_empty_package(cleanup=cleanup)
if self._include_tests:
self.lib_test.create_empty_package(cleanup=cleanup)
self.sim.create_empty_package(cleanup=cleanup)
6 changes: 4 additions & 2 deletions src/peakrdl_python/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
get_memory_max_entry_value_hex_string, get_memory_width_bytes, \
get_field_default_value, get_enum_values, get_properties_to_include, \
HideNodeCallback, hide_based_on_property, \
full_slice_accessor, ShowUDPCallback
full_slice_accessor, ShowUDPCallback, \
node_iterator_entry
from .unique_component_iterator import UniqueComponents
from .unique_component_iterator import PeakRDLPythonUniqueRegisterComponents
from .unique_component_iterator import PeakRDLPythonUniqueMemoryComponents
Expand Down Expand Up @@ -865,7 +866,8 @@ def is_reg_node(node: Node) -> TypeGuard[RegNode]:
'get_properties_to_include': get_properties_to_include,
'hide_node_func': hide_node_func,
'legacy_enum_type': legacy_enum_type,
'skip_systemrdl_name_and_desc_properties': skip_systemrdl_name_and_desc_properties
'skip_systemrdl_name_and_desc_properties': skip_systemrdl_name_and_desc_properties,
'node_iterator_entry': node_iterator_entry,
}

self.__stream_jinja_template(template_name="addrmap_tb.py.jinja",
Expand Down
4 changes: 4 additions & 0 deletions src/peakrdl_python/lib/async_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ async def _write(self, start_entry: int, data: Union[Array, list[int]]) -> None:
if not isinstance(data, (list, Array)):
raise TypeError(f'data should be an array.array got {type(data)}')

if (max(data) > self.max_entry_value) or (min(data) < 0):
raise ValueError('Data out of range for memory must be in the '
f'range 0 to {self.max_entry_value}')

if len(data) not in range(0, self.entries - start_entry + 1):
raise ValueError(f'data length must be in range 0 to {self.entries - start_entry:d} '
f'but got {len(data):d}')
Expand Down
14 changes: 3 additions & 11 deletions src/peakrdl_python/lib/async_register_and_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ def __init__(self, *,
# pylint: enable=too-many-arguments, duplicate-code

@asynccontextmanager
async def single_read_modify_write(self, verify: bool = False, skip_write: bool = False) -> \
AsyncGenerator[Self]:
async def single_read_modify_write(self, verify: bool = False) -> AsyncGenerator[Self]:
"""
Context manager to allow multiple field reads/write to be done with a single set of
field operations
Expand All @@ -361,11 +360,6 @@ async def single_read_modify_write(self, verify: bool = False, skip_write: bool
if self.__in_read_context_manager:
raise RuntimeError('using the `single_read_modify_write` context manager within the '
'single_read` is not permitted')

if skip_write is True:
warn('The `skip_write` argument will be removed in the future, use `single_read`'
' instead',
DeprecationWarning, stacklevel=2)
# pylint: enable=duplicate-code

self.__register_state = await self.read()
Expand All @@ -379,15 +373,13 @@ async def single_read_modify_write(self, verify: bool = False, skip_write: bool
finally:
self.__in_read_write_context_manager = False
# pylint: enable=duplicate-code
if not skip_write:
await self.write(self.__register_state, verify)
await self.write(self.__register_state, verify)

# clear the register states at the end of the context manager
self.__register_state = None

@asynccontextmanager
async def single_read(self) -> \
AsyncGenerator[Self]:
async def single_read(self) -> AsyncGenerator[Self]:
"""
Context manager to allow multiple field reads with a single register read
"""
Expand Down
45 changes: 0 additions & 45 deletions src/peakrdl_python/lib/base_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,28 +385,6 @@ class _FieldReadOnlyFramework(Field[FieldType], ABC):
"""
__slots__ : list[str] = []

def decode_read_value(self, value: int) -> FieldType:
"""
extracts the field value from a register value, by applying the bit
mask and shift needed

Args:
value: value to decode, normally read from a register

Returns:
field value

Warning:
This method will be removed from a future version, if you have a compelling use
case for it please add a comment to the #184 ticket

"""
# end users should not need access to the `decode_read_value` as the decoding is done
# for them, it felt like an anomaly that this was public, see #184
warnings.warn('decode_read_value will be made private in a future version',
DeprecationWarning, stacklevel=2)
return self._decode_read_value(value=value)

def _decode_read_value(self, value: int) -> FieldType:
"""
extracts the field value from a register value, by applying the bit
Expand Down Expand Up @@ -476,29 +454,6 @@ def _write_value_checks(self, value: int) -> None:
raise ValueError(f'value to be written to register must be less '
f'than or equal to {self.max_value:d}')


def encode_write_value(self, value: FieldType) -> int:
"""
Check that a value is legal for the field and then encode it in preparation to be written
to the register

Args:
value: field value

Returns:
value which can be applied to the register to update the field

Warning:
This method will be removed from a future version, if you have a compelling use
case for it please add a comment to the #184 ticket

"""
# end users should not need access to the `decode_read_value` as the decoding is done
# for them, it felt like an anomaly that this was public, see #184
warnings.warn('encode_write_value will be made private in a future version',
DeprecationWarning, stacklevel=2)
return self._encode_write_value(value=value)

def _encode_write_value(self, value: FieldType) -> int:
"""
Check that a value is legal for the field and then encode it in preparation to be written
Expand Down
18 changes: 18 additions & 0 deletions src/peakrdl_python/lib/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def width(self) -> int:
"""
return self.__memwidth

@property
def max_entry_value(self) -> int:
"""
maximum unsigned integer value that can be stored in a memory entry

For example:

* 8-bit memory width returns 0xFF (255)
* 16-bit memory width returns 0xFFFF (65535)
* 32-bit memory width returns 0xFFFF_FFFF (4294967295)

"""
return (2 ** self.width) - 1

@property
def width_in_bytes(self) -> int:
"""
Expand Down Expand Up @@ -505,6 +519,10 @@ def _write(self, start_entry: int, data: Union[Array, list[int]]) -> None:
if not isinstance(data, (Array, list)):
raise TypeError(f'data should be an List or array.array got {type(data)}')

if (max(data) > self.max_entry_value) or (min(data) < 0):
raise ValueError('Data out of range for memory must be in the '
f'range 0 to {self.max_entry_value}')

if len(data) not in range(0, self.entries - start_entry + 1):
raise ValueError(f'data length must be in range 0 to {self.entries - start_entry:d} '
f'but got {len(data):d}')
Expand Down
Loading