Configuration
Configuration.
AConfig
Bases: LightObject
Configuration Container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
Configuration name, used as suffix of the generated module. |
''
|
A configuration is nothing more than a receipe how to assemble a module:
- if a specific option should be built-in or not
- how many instances or which instances should be created
A configuration MUST have at least a name.
Due to the frozen instance approach, configurations have to be implemented
via u.field().
AConfig Examples
Create a Config.
>>> import ucdp as u
>>> class MyConfig(u.AConfig):
...
... base_addr: u.Hex # required without default
... ram_size: u.Bytes
... rom_size: u.Bytes|None = None
... feature: bool = False
To create 1st variant
>>> variant0 = MyConfig(name='variant0', base_addr=4*1024, ram_size='16kB')
>>> variant0
MyConfig('variant0', base_addr=Hex('0x1000'), ram_size=Bytes('16 KB'))
>>> variant0.base_addr
Hex('0x1000')
>>> variant0.ram_size
Bytes('16 KB')
>>> variant0.rom_size
>>> variant0.feature
False
>>> variant0.hash
'7f16ca5fadcb6e3d'
To create 2nd variant
>>> for name, value in variant0:
... name, value
('name', 'variant0')
('base_addr', Hex('0x1000'))
('ram_size', Bytes('16 KB'))
('rom_size', None)
('feature', False)
>>> variant1 = MyConfig('variant1', base_addr=8*1024, rom_size="2KB", ram_size="4KB", feature=True)
>>> variant1
MyConfig('variant1', base_addr=Hex('0x2000'), ram_size=Bytes('4 KB'), rom_size=Bytes('2 KB'), feature=True)
>>> variant1.base_addr
Hex('0x2000')
>>> variant1.ram_size
Bytes('4 KB')
>>> variant1.rom_size
Bytes('2 KB')
>>> variant1.feature
True
>>> variant1.hash
'89a81c4c7760e3d3'
To create another variant based on an existing:
>>> variant2 = variant1.new(name='variant2', rom_size='8KB')
>>> variant2
MyConfig('variant2', base_addr=Hex('0x2000'), ram_size=Bytes('4 KB'), rom_size=Bytes('8 KB'), feature=True)
>>> variant2.base_addr
Hex('0x2000')
>>> variant2.ram_size
Bytes('4 KB')
>>> variant2.rom_size
Bytes('8 KB')
>>> variant2.feature
True
>>> variant2.hash
'17714da763ff4d59'
Todo
- fix name type
AVersionConfig
Bases: AConfig
Version Configuration Container.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Title. |
version |
str
|
Version |
timestamp |
datetime
|
Timestamp |
AVersionConfig Examples
Create a Config.
>>> import ucdp as u
>>> import datetime
>>> class MyVersionConfig(u.AVersionConfig):
... mem_baseaddr: u.Hex
>>> version = MyVersionConfig(
... 'my',
... title="Title",
... version="1.2.3",
... timestamp=datetime.datetime(2020, 10, 17, 23, 42),
... mem_baseaddr=0x12340000
... )
>>> version.name
'my'
>>> version.title
'Title'
>>> version.timestamp
datetime.datetime(2020, 10, 17, 23, 42)
>>> version.mem_baseaddr
Hex('0x12340000')
>>> version.hash
'872899af38feb238'
>>> for name, value in version:
... name, value
('name', 'my')
('title', 'Title')
('version', '1.2.3')
('timestamp', datetime.datetime(2020, 10, 17, 23, 42))
('mem_baseaddr', Hex('0x12340000'))
Title, version and timestamp do not affect the hash
title = "Title" version = "Version" timestamp0 = datetime.datetime(2020, 10, 17, 23, 42) timestamp1 = datetime.datetime(2020, 10, 17, 23, 43) MyVersionConfig(mem_baseaddr=0x12340000, title=title, version=version, timestamp=timestamp0).hash 'b022b2a8ae767ed8' MyVersionConfig(mem_baseaddr=0x12340000, title=title, version=version, timestamp=timestamp1).hash 'b022b2a8ae767ed8'