-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from vkottler/dev/2.4.1
Initial output generation from SVD
- Loading branch information
Showing
29 changed files
with
527 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[settings] | ||
known_first_party=ifgen,vmklib | ||
skip=tests/data | ||
skip=tests/data,config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule config
updated
22 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
includes: | ||
- has_description.yaml | ||
- has_volatile.yaml | ||
- has_expected_size.yaml | ||
|
||
required: [name, type] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
properties: | ||
expected_size: | ||
type: integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
runtimepy>=2.1.1 | ||
vcorelib>=2.6.1 | ||
vcorelib>=3.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
A module implementing interfaces for processing a group of peripherals. | ||
""" | ||
|
||
# built-in | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
# third-party | ||
from vcorelib.io import ARBITER | ||
|
||
# internal | ||
from ifgen.svd.group.base import PeripheralGroup, peripheral_groups | ||
from ifgen.svd.group.fields import DEFAULT_STRUCT, StructMap, struct_fields | ||
from ifgen.svd.model.peripheral import Peripheral | ||
|
||
__all__ = ["PeripheralGroup", "peripheral_groups", "handle_group"] | ||
|
||
|
||
def struct_instance(peripheral: Peripheral) -> dict[str, Any]: | ||
"""Get struct instance data.""" | ||
|
||
return { | ||
"name": peripheral.name, | ||
"address": peripheral.raw_data["baseAddress"], | ||
} | ||
|
||
|
||
def struct_data(group: PeripheralGroup, structs: StructMap) -> dict[str, Any]: | ||
"""Get struct data for a peripheral group.""" | ||
|
||
data: dict[str, Any] = {} | ||
peripheral = group.root | ||
peripheral.handle_description(data) | ||
|
||
data["instances"] = [struct_instance(x) for x in group.peripherals] | ||
size, data["fields"] = struct_fields(peripheral.registers, structs) | ||
data["expected_size"] = size | ||
|
||
data.update(DEFAULT_STRUCT) | ||
return data | ||
|
||
|
||
def handle_group( | ||
output_dir: Path, group: PeripheralGroup, includes: set[Path] | ||
) -> None: | ||
"""Handle a peripheral group.""" | ||
|
||
output = output_dir.joinpath("include.yaml") | ||
includes.add(output) | ||
|
||
structs: StructMap = {} | ||
structs[group.root.base_name] = struct_data(group, structs) | ||
ARBITER.encode(output, {"structs": structs}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
A module implementing base interfaces for processing a group of peripherals. | ||
""" | ||
|
||
# built-in | ||
from dataclasses import dataclass | ||
from typing import Iterator | ||
|
||
# internal | ||
from ifgen.svd.model.peripheral import Peripheral | ||
|
||
|
||
@dataclass | ||
class PeripheralGroup: | ||
"""A container for peripherals that have the same register layout.""" | ||
|
||
root: Peripheral | ||
derivatives: list[Peripheral] | ||
|
||
@property | ||
def peripherals(self) -> Iterator[Peripheral]: | ||
"""Get all peripheral instances.""" | ||
yield self.root | ||
yield from self.derivatives | ||
|
||
|
||
def peripheral_groups( | ||
peripherals: dict[str, Peripheral] | ||
) -> dict[str, PeripheralGroup]: | ||
"""Organize peripherals into groups.""" | ||
|
||
result: dict[str, PeripheralGroup] = {} | ||
|
||
for name, peripheral in peripherals.items(): | ||
if name not in result and not peripheral.derived: | ||
# Validate this later. | ||
result[name] = PeripheralGroup(None, []) # type: ignore | ||
|
||
if peripheral.derived: | ||
result[peripheral.derived_elem.name].derivatives.append(peripheral) | ||
else: | ||
assert result[name].root is None, result[name].root | ||
result[name].root = peripheral | ||
|
||
# Validate groups. | ||
for name, group in result.items(): | ||
assert group.root is not None, (name, group) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
A module for generating configuration data for struct fields. | ||
""" | ||
|
||
# built-in | ||
from typing import Any | ||
|
||
# internal | ||
from ifgen.svd.model.peripheral import Cluster, Register, RegisterData | ||
|
||
StructMap = dict[str, Any] | ||
StructField = dict[str, Any] | ||
DEFAULT_STRUCT = {"stream": False, "codec": False} | ||
|
||
|
||
def handle_cluster( | ||
cluster: Cluster, structs: StructMap | ||
) -> tuple[int, StructField]: | ||
"""Handle a cluster element.""" | ||
|
||
# Register a struct for this cluster. Should we use a namespace for this? | ||
cluster_struct: dict[str, Any] = cluster.handle_description() | ||
size, cluster_struct["fields"] = struct_fields(cluster.children, structs) | ||
cluster_struct["expected_size"] = size | ||
cluster_struct.update(DEFAULT_STRUCT) | ||
|
||
# compute expected size? | ||
|
||
structs[cluster.name] = cluster_struct | ||
|
||
# This needs to be an array element somehow. Use a namespace? | ||
result: StructField = {"name": cluster.name, "expected_size": size} | ||
cluster.handle_description(result) | ||
return size, result | ||
|
||
|
||
def handle_register(register: Register) -> tuple[int, StructField]: | ||
"""Handle a register entry.""" | ||
|
||
# handle register is array + get size from peripheral if necessary | ||
size = register.size | ||
data = { | ||
"name": register.name, | ||
"type": register.c_type, | ||
"expected_size": size, | ||
} | ||
register.handle_description(data) | ||
return size, data | ||
|
||
|
||
def struct_fields( | ||
registers: RegisterData, structs: StructMap, size: int = None | ||
) -> tuple[int, list[StructField]]: | ||
"""Generate data for struct fields.""" | ||
|
||
fields = [] | ||
|
||
if size is None: | ||
size = 0 | ||
|
||
for item in registers: | ||
inst_size, field = ( | ||
handle_cluster(item, structs) | ||
if isinstance(item, Cluster) | ||
else handle_register(item) | ||
) | ||
fields.append(field) | ||
size += inst_size | ||
|
||
return size, fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.