avl-apb 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
avl_apb-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [avl@projectapheleia.net]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
avl_apb-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,193 @@
1
+ Metadata-Version: 2.3
2
+ Name: avl-apb
3
+ Version: 0.1.0
4
+ Summary: Apheleia Verification Library - AMBA Advanced Peripheral Bus verification component.
5
+ License: MIT License
6
+
7
+ Copyright (c) [2025] [avl@projectapheleia.net]
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ Author: avl
27
+ Author-email: avl@projectapheleia.net
28
+ Maintainer: avl
29
+ Maintainer-email: avl@projectapheleia.net
30
+ Requires-Python: >=3.10
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Programming Language :: Python
33
+ Provides-Extra: dev
34
+ Requires-Dist: avl-core (>=0.2.1)
35
+ Requires-Dist: black (>=22.3.0) ; extra == "dev"
36
+ Requires-Dist: matplotlib (>=3.10.0)
37
+ Requires-Dist: mypy (>=0.910) ; extra == "dev"
38
+ Requires-Dist: pytest (>=7.0) ; extra == "dev"
39
+ Requires-Dist: ruff (>=0.11.0) ; extra == "dev"
40
+ Requires-Dist: sphinx (>=8.1.3) ; extra == "dev"
41
+ Requires-Dist: sphinx_rtd_theme (>=3.0.2) ; extra == "dev"
42
+ Description-Content-Type: text/markdown
43
+
44
+ # AVL-APB - Apheleia Verification Library AMBA APB Verification Component
45
+
46
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
47
+ [![Python](https://img.shields.io/badge/Python-3.7%2B-blue)](https://www.python.org/)
48
+
49
+
50
+ AVL-APB has been developed by experienced, industry professional verification engineers to provide a simple, \
51
+ extensible verification component for the [AMBA APB Bus](https://developer.arm.com/documentation/ihi0024/latest/) \
52
+ developed in [Python](https://www.python.org/) and the [AVL](https://avl-core.readthedocs.io/en/latest/index.html) library.
53
+
54
+ AVL is built on the [CocoTB](https://docs.cocotb.org/en/stable/) framework, but aims to combine the best elements of \
55
+ [UVM](https://accellera.org/community/uvm) in a more engineer friendly and efficient way.
56
+
57
+
58
+ ## Protocol Features
59
+
60
+ | Version | Signal Name | Description | Driven By |
61
+ |---------|-------------|-------------|-----------|
62
+ | APB2 | PCLK | APB clock signal; all APB transfers are synchronized to this clock. | Requester |
63
+ | APB2 | PRESETn | Asynchronous active-low reset for the APB interface. | Requester |
64
+ | APB2 | PADDR | Address bus; specifies the register address for the transfer. | Requester |
65
+ | APB2 | PSELx | Slave select; one per slave. High when the slave is selected. | Requester |
66
+ | APB2 | PENABLE | Indicates the second and subsequent cycles of an APB transfer. | Requester |
67
+ | APB2 | PWRITE | Write control signal; high for write, low for read. | Requester |
68
+ | APB2 | PWDATA | Write data bus from master to slave. | Requester |
69
+ | APB2 | PRDATA | Read data bus from slave to master. | Completer |
70
+ | APB3 | PREADY | Optional signal; indicates the slave is ready to complete the transfer. | Completer |
71
+ | APB3 | PSLVERR | Optional signal; indicates an error condition on the transfer. | Completer |
72
+ | APB4 | PPROT | Optional protection control signals for privilege, security, and instruction/data access. | Requester |
73
+ | APB4 | PSTRB | Optional byte lane strobe signals for write operations. | Requester |
74
+ | APB5 | PNSE | Optional signal; indicates whether the transfer is secure or non-secure. | Requester |
75
+ | APB5 | PWAKEUP | Optional wakeup signal from slave to master for low-power operation. | Completer |
76
+ | APB5 | PAUSER | Optional signal; specifies the user ID associated with the transfer for secure systems. | Requester |
77
+ | APB5 | PRUSER | Optional user-defined read data channel sideband signals. | Completer |
78
+ | APB5 | PWUSER | Optional user-defined write data channel sideband signals. | Requester |
79
+ | APB5 | PBUSER | Optional user-defined byte strobe channel sideband signals. | Requester |
80
+
81
+ ## Component Features
82
+
83
+ - All protocol features supported
84
+ - Simple RTL interface to interact with HDL and define parameter and configuration options
85
+ - Requester sequence, sequencer and driver with easy to control rate limiter and wakeup control
86
+ - Completer driver with vanilla, random and memory response patterns
87
+ - Monitor
88
+ - Bandwidth monitor generating bus activity plots over user defined windows during simulation
89
+ - Functional coverage including performance measurements
90
+ - Searchable trace file generation
91
+
92
+ ---
93
+
94
+ ## 📦 Installation
95
+
96
+ ### Using `pip`
97
+ ```sh
98
+ # Standard build
99
+ pip install avl-core
100
+
101
+ # Development build
102
+ pip install avl-core[dev]
103
+ ```
104
+
105
+ ### Install from Source
106
+ ```sh
107
+ git clone https://github.com/projectapheleia/avl.git
108
+ cd avl
109
+
110
+ # Standard build
111
+ pip install .
112
+
113
+ # Development build
114
+ pip install .[dev]
115
+ ```
116
+
117
+ Alternatively if you want to create a [virtual environment](https://docs.python.org/3/library/venv.html) rather than install globally a script is provided. This will install, with edit privileges to local virtual environment.
118
+
119
+ This script assumes you have [Graphviz](https://graphviz.org/download/) and appropriate simulator installed, so all examples and documentation will build out of the box.
120
+
121
+
122
+ ```sh
123
+ git clone https://github.com/projectapheleia/avl-apb.git
124
+ cd avl-apb
125
+ source avl-apb.sh
126
+ ```
127
+
128
+ ## 📖 Documentation
129
+
130
+ In order to build the documentation you must have installed the development build.
131
+
132
+ ### Build from Source
133
+ ```sh
134
+ cd docs
135
+ make html
136
+ <browser> build/html/index.html
137
+ ```
138
+ ## 🏃 Examples
139
+
140
+ In order to run all the examples you must have installed the development build.
141
+
142
+ To run all examples:
143
+
144
+ ```sh
145
+ cd examples
146
+
147
+ # To run
148
+ make -j 8 sim
149
+
150
+ # To clean
151
+ make -j 8 clean
152
+ ```
153
+
154
+ To run an individual example:
155
+
156
+ ```sh
157
+ cd examples/THE EXAMPLE YOU WANT
158
+
159
+ # To run
160
+ make sim
161
+
162
+ # To clean
163
+ make clean
164
+ ```
165
+
166
+ The examples use the [CocoTB Makefile](https://docs.cocotb.org/en/stable/building.html) and default to [Verilator](https://www.veripool.org/verilator/) with all waveforms generated. This can be modified using the standard CocoTB build system.
167
+
168
+ ---
169
+
170
+
171
+ ## 🧹 Code Style & Linting
172
+
173
+ This project uses [**Ruff**](https://docs.astral.sh/ruff/) for linting and formatting.
174
+
175
+ Check code for issues:
176
+
177
+ ```sh
178
+ ruff check .
179
+ ```
180
+
181
+ Automatically fix common issues:
182
+
183
+ ```sh
184
+ ruff check . --fix
185
+ ```
186
+
187
+
188
+
189
+ ## 📧 Contact
190
+
191
+ - Email: avl@projectapheleia.net
192
+ - GitHub: [projectapheleia](https://github.com/projectapheleia)
193
+
@@ -0,0 +1,149 @@
1
+ # AVL-APB - Apheleia Verification Library AMBA APB Verification Component
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
+ [![Python](https://img.shields.io/badge/Python-3.7%2B-blue)](https://www.python.org/)
5
+
6
+
7
+ AVL-APB has been developed by experienced, industry professional verification engineers to provide a simple, \
8
+ extensible verification component for the [AMBA APB Bus](https://developer.arm.com/documentation/ihi0024/latest/) \
9
+ developed in [Python](https://www.python.org/) and the [AVL](https://avl-core.readthedocs.io/en/latest/index.html) library.
10
+
11
+ AVL is built on the [CocoTB](https://docs.cocotb.org/en/stable/) framework, but aims to combine the best elements of \
12
+ [UVM](https://accellera.org/community/uvm) in a more engineer friendly and efficient way.
13
+
14
+
15
+ ## Protocol Features
16
+
17
+ | Version | Signal Name | Description | Driven By |
18
+ |---------|-------------|-------------|-----------|
19
+ | APB2 | PCLK | APB clock signal; all APB transfers are synchronized to this clock. | Requester |
20
+ | APB2 | PRESETn | Asynchronous active-low reset for the APB interface. | Requester |
21
+ | APB2 | PADDR | Address bus; specifies the register address for the transfer. | Requester |
22
+ | APB2 | PSELx | Slave select; one per slave. High when the slave is selected. | Requester |
23
+ | APB2 | PENABLE | Indicates the second and subsequent cycles of an APB transfer. | Requester |
24
+ | APB2 | PWRITE | Write control signal; high for write, low for read. | Requester |
25
+ | APB2 | PWDATA | Write data bus from master to slave. | Requester |
26
+ | APB2 | PRDATA | Read data bus from slave to master. | Completer |
27
+ | APB3 | PREADY | Optional signal; indicates the slave is ready to complete the transfer. | Completer |
28
+ | APB3 | PSLVERR | Optional signal; indicates an error condition on the transfer. | Completer |
29
+ | APB4 | PPROT | Optional protection control signals for privilege, security, and instruction/data access. | Requester |
30
+ | APB4 | PSTRB | Optional byte lane strobe signals for write operations. | Requester |
31
+ | APB5 | PNSE | Optional signal; indicates whether the transfer is secure or non-secure. | Requester |
32
+ | APB5 | PWAKEUP | Optional wakeup signal from slave to master for low-power operation. | Completer |
33
+ | APB5 | PAUSER | Optional signal; specifies the user ID associated with the transfer for secure systems. | Requester |
34
+ | APB5 | PRUSER | Optional user-defined read data channel sideband signals. | Completer |
35
+ | APB5 | PWUSER | Optional user-defined write data channel sideband signals. | Requester |
36
+ | APB5 | PBUSER | Optional user-defined byte strobe channel sideband signals. | Requester |
37
+
38
+ ## Component Features
39
+
40
+ - All protocol features supported
41
+ - Simple RTL interface to interact with HDL and define parameter and configuration options
42
+ - Requester sequence, sequencer and driver with easy to control rate limiter and wakeup control
43
+ - Completer driver with vanilla, random and memory response patterns
44
+ - Monitor
45
+ - Bandwidth monitor generating bus activity plots over user defined windows during simulation
46
+ - Functional coverage including performance measurements
47
+ - Searchable trace file generation
48
+
49
+ ---
50
+
51
+ ## 📦 Installation
52
+
53
+ ### Using `pip`
54
+ ```sh
55
+ # Standard build
56
+ pip install avl-core
57
+
58
+ # Development build
59
+ pip install avl-core[dev]
60
+ ```
61
+
62
+ ### Install from Source
63
+ ```sh
64
+ git clone https://github.com/projectapheleia/avl.git
65
+ cd avl
66
+
67
+ # Standard build
68
+ pip install .
69
+
70
+ # Development build
71
+ pip install .[dev]
72
+ ```
73
+
74
+ Alternatively if you want to create a [virtual environment](https://docs.python.org/3/library/venv.html) rather than install globally a script is provided. This will install, with edit privileges to local virtual environment.
75
+
76
+ This script assumes you have [Graphviz](https://graphviz.org/download/) and appropriate simulator installed, so all examples and documentation will build out of the box.
77
+
78
+
79
+ ```sh
80
+ git clone https://github.com/projectapheleia/avl-apb.git
81
+ cd avl-apb
82
+ source avl-apb.sh
83
+ ```
84
+
85
+ ## 📖 Documentation
86
+
87
+ In order to build the documentation you must have installed the development build.
88
+
89
+ ### Build from Source
90
+ ```sh
91
+ cd docs
92
+ make html
93
+ <browser> build/html/index.html
94
+ ```
95
+ ## 🏃 Examples
96
+
97
+ In order to run all the examples you must have installed the development build.
98
+
99
+ To run all examples:
100
+
101
+ ```sh
102
+ cd examples
103
+
104
+ # To run
105
+ make -j 8 sim
106
+
107
+ # To clean
108
+ make -j 8 clean
109
+ ```
110
+
111
+ To run an individual example:
112
+
113
+ ```sh
114
+ cd examples/THE EXAMPLE YOU WANT
115
+
116
+ # To run
117
+ make sim
118
+
119
+ # To clean
120
+ make clean
121
+ ```
122
+
123
+ The examples use the [CocoTB Makefile](https://docs.cocotb.org/en/stable/building.html) and default to [Verilator](https://www.veripool.org/verilator/) with all waveforms generated. This can be modified using the standard CocoTB build system.
124
+
125
+ ---
126
+
127
+
128
+ ## 🧹 Code Style & Linting
129
+
130
+ This project uses [**Ruff**](https://docs.astral.sh/ruff/) for linting and formatting.
131
+
132
+ Check code for issues:
133
+
134
+ ```sh
135
+ ruff check .
136
+ ```
137
+
138
+ Automatically fix common issues:
139
+
140
+ ```sh
141
+ ruff check . --fix
142
+ ```
143
+
144
+
145
+
146
+ ## 📧 Contact
147
+
148
+ - Email: avl@projectapheleia.net
149
+ - GitHub: [projectapheleia](https://github.com/projectapheleia)
@@ -0,0 +1,26 @@
1
+ from ._agent import Agent
2
+ from ._agent_cfg import AgentCfg
3
+ from ._bandwidth import Bandwidth
4
+ from ._cdriver import CplDriver, CplMemoryDriver, CplRandomDriver
5
+ from ._coverage import Coverage
6
+ from ._item import SequenceItem
7
+ from ._monitor import Monitor
8
+ from ._rdriver import ReqDriver
9
+ from ._rsequence import ReqSequence
10
+
11
+ # Add version
12
+ __version__: str = "0.1.0"
13
+
14
+ __all__ = [
15
+ "Agent",
16
+ "AgentCfg",
17
+ "Bandwidth",
18
+ "CplDriver",
19
+ "CplMemoryDriver",
20
+ "CplRandomDriver",
21
+ "Coverage",
22
+ "SequenceItem",
23
+ "Monitor",
24
+ "ReqDriver",
25
+ "ReqSequence",
26
+ ]
@@ -0,0 +1,105 @@
1
+ # Copyright 2025 Apheleia
2
+ #
3
+ # Description:
4
+ # Apheleia Verification Library Agent
5
+
6
+ import avl
7
+ from cocotb.handle import HierarchyObject
8
+ from cocotb.triggers import NextTimeStep, RisingEdge
9
+
10
+ from ._agent_cfg import AgentCfg
11
+ from ._bandwidth import Bandwidth
12
+ from ._cdriver import CplDriver
13
+ from ._coverage import Coverage
14
+ from ._interface import Interface
15
+ from ._monitor import Monitor
16
+ from ._rdriver import ReqDriver
17
+ from ._rsequence import ReqSequence
18
+
19
+
20
+ class Agent(avl.Agent):
21
+ def __init__(self, name: str, parent: avl.Component) -> None:
22
+ """
23
+ Initialize the avl-apb Agent
24
+
25
+ :param name: Name of the agent instance
26
+ :type name: str
27
+ :param parent: Parent component
28
+ :type parent: Component
29
+ """
30
+ super().__init__(name, parent)
31
+
32
+ # Create configuration and export to children
33
+ self.cfg = avl.Factory.get_variable(f"{self.get_full_name()}.cfg", AgentCfg("cfg", self))
34
+ avl.Factory.set_variable(f"{self.get_full_name()}.*.cfg", self.cfg)
35
+
36
+ # Bind HDL to establish parameters and configuration
37
+ self._bind_(avl.Factory.get_variable(f"{self.get_full_name()}.hdl", None))
38
+
39
+ # Create sequencer and driver if requester is enabled
40
+ if self.cfg.has_requester:
41
+ self.rsqr = avl.Sequencer("rsqr", self)
42
+ self.rseq = ReqSequence("rseq",self.rsqr)
43
+ self.rdrv = ReqDriver("rdrv", self)
44
+ self.rsqr.seq_item_export.connect(self.rdrv.seq_item_port)
45
+
46
+ if self.cfg.num_completer > 1:
47
+ self.cdrv = []
48
+ for i in range(self.cfg.num_completer):
49
+ avl.Factory.set_variable(f"{self.get_full_name()}.cdrv_{i}.idx", i)
50
+ self.cdrv.append(CplDriver(f"cdrv_{i}", self))
51
+ elif self.cfg.num_completer == 1:
52
+ self.cdrv = CplDriver("cdrv", self)
53
+
54
+ # Create monitor if enabled
55
+ if self.cfg.has_monitor:
56
+ self.monitor = Monitor("monitor", self)
57
+
58
+ if self.cfg.has_coverage:
59
+ self.coverage = Coverage("coverage", self)
60
+ self.monitor.item_export.connect(self.coverage.item_port)
61
+
62
+ if self.cfg.has_bandwidth:
63
+ self.bandwidth = Bandwidth("bandwidth", self)
64
+ self.monitor.item_export.connect(self.bandwidth.item_port)
65
+
66
+ if self.cfg.has_trace:
67
+ self.trace = avl.Trace("trace", self)
68
+ self.monitor.item_export.connect(self.trace.item_port)
69
+
70
+ def _bind_(self, hdl) -> None:
71
+ """
72
+ Bind the agent to a hardware description language (HDL) interface.
73
+ This method is used to associate the agent with a specific HDL interface,
74
+ allowing it to interact with the hardware model.
75
+
76
+ :param hdl: The HDL interface to bind to the agent
77
+ :type hdl: HierarchyObject
78
+ :raises TypeError: If `hdl` is not an instance of HierarchyObject
79
+ """
80
+ if not isinstance(hdl, HierarchyObject):
81
+ raise TypeError(f"Expected HierarchyObject, got {type(hdl)}")
82
+
83
+ # Assign Interface
84
+ self.i_f = Interface(hdl)
85
+ avl.Factory.set_variable(f"{self.get_full_name()}.*.i_f", self.i_f)
86
+
87
+ async def run_phase(self) -> None:
88
+ """
89
+ Run the agent's phase. This method is called to start the agent's operation.
90
+ It initializes the agent and starts the requester and completer if they are active.
91
+ """
92
+
93
+ self.raise_objection()
94
+ await NextTimeStep()
95
+
96
+ if self.cfg.has_requester:
97
+ await self.rseq.start()
98
+
99
+ # Run-off
100
+ for _ in range(10):
101
+ await RisingEdge(self.i_f.pclk)
102
+
103
+ self.drop_objection()
104
+
105
+ __all__ = ["Agent"]
@@ -0,0 +1,36 @@
1
+ # Copyright 2025 Apheleia
2
+ #
3
+ # Description:
4
+ # Apheleia Verification Library Agent Configuration
5
+
6
+ import avl
7
+
8
+
9
+ class AgentCfg(avl.Object):
10
+
11
+ def __init__(self, name: str, parent: avl.Component) -> None:
12
+ """
13
+ Initialize the avl-apb Agent Configuration
14
+
15
+ :param name: Name of the agent instance
16
+ :type name: str
17
+ :param parent: Parent component
18
+ :type parent: Component
19
+ """
20
+ super().__init__(name, parent)
21
+
22
+ # Agent Attributes
23
+ self.has_requester = avl.Factory.get_variable(f"{self.get_full_name()}.has_requester", False)
24
+ """Has Requester Driver"""
25
+ self.num_completer = avl.Factory.get_variable(f"{self.get_full_name()}.num_completer", 0)
26
+ """Number Completer Driver"""
27
+ self.has_monitor = avl.Factory.get_variable(f"{self.get_full_name()}.has_monitor", False)
28
+ """Has Monitor Driver"""
29
+ self.has_coverage = avl.Factory.get_variable(f"{self.get_full_name()}.has_coverage", False)
30
+ """Has Functional Coverage"""
31
+ self.has_bandwidth = avl.Factory.get_variable(f"{self.get_full_name()}.has_bandwidth", False)
32
+ """Has Bandwidth Monitor"""
33
+ self.has_trace = avl.Factory.get_variable(f"{self.get_full_name()}.has_trace", False)
34
+ """Has Trace Generator"""
35
+
36
+ __all__ = ["AgentCfg"]
@@ -0,0 +1,94 @@
1
+ # Copyright 2025 Apheleia
2
+ #
3
+ # Description:
4
+ # Apheleia Verification Library Bandwidth Monitor
5
+
6
+ import avl
7
+ import cocotb
8
+ import matplotlib.pyplot as plt
9
+ import numpy as np
10
+ from cocotb.triggers import Timer
11
+ from cocotb.utils import get_sim_time
12
+
13
+
14
+ class Bandwidth(avl.Component):
15
+
16
+ def __init__(self, name: str, parent: avl.Component) -> None:
17
+ """
18
+ Initialize Bandwidth Monitor
19
+
20
+ Class contains variable window_ns which defines the time window in nanoseconds. This
21
+ is configurable via the factory.
22
+
23
+ :param name: Name of the bandwidth monitor.
24
+ :type name: str
25
+ :param parent: Parent component.
26
+ :type parent: Component
27
+ """
28
+ super().__init__(name, parent)
29
+ self.i_f = avl.Factory.get_variable(f"{self.get_full_name()}.i_f", None)
30
+
31
+ self.window_ns = avl.Factory.get_variable(f"{self.get_full_name()}.window_ns", 1000)
32
+ """ Rolling ime window in nanoseconds for bandwidth calculation. Default is 1000 ns. """
33
+
34
+ self.item_port = avl.List()
35
+ self.bandwidth = {}
36
+
37
+ async def run_phase(self) -> None:
38
+ """
39
+ Run phase for the coverage component.
40
+
41
+ """
42
+ async def counter():
43
+ while True:
44
+ self.item = await self.item_port.blocking_get()
45
+
46
+ incr = self.i_f.PSTRB_WIDTH
47
+ if self.item.get("pwrite"):
48
+ pstrb = self.item.get("pstrb", None)
49
+ if pstrb is not None:
50
+ incr = bin(pstrb).count("1")
51
+ self.bandwidth[t] += incr
52
+
53
+ cocotb.start_soon(counter())
54
+
55
+ while True:
56
+ t = get_sim_time(units="ns")
57
+ self.bandwidth[t] = 0
58
+
59
+ self.raise_objection()
60
+ await Timer(self.window_ns, units="ns")
61
+ self.drop_objection()
62
+
63
+ async def report_phase(self) -> None:
64
+ """
65
+ Report phase for the bandwidth component.
66
+
67
+ Generate plot of bytes on bus over time windows
68
+
69
+ """
70
+ times = list(self.bandwidth.keys())
71
+ counts = list(self.bandwidth.values())
72
+
73
+ if len(times) > 1:
74
+ # For unevenly spaced data, calculate individual widths
75
+ # This uses the minimum spacing to avoid overlapping bars
76
+ spacings = np.diff(times)
77
+ bar_width = np.min(spacings)
78
+ else:
79
+ # For single bar, use a default width
80
+ bar_width = 1
81
+
82
+ # Create plot
83
+ plt.figure(figsize=(8, 4))
84
+ plt.bar(times, counts, width=bar_width, align='center')
85
+ plt.title("Bus Bandwidth (Bytes over Time)")
86
+ plt.xlabel("Time (ns)")
87
+ plt.ylabel("Byte Count")
88
+ plt.grid(True)
89
+
90
+ # Export to PNG
91
+ plt.savefig(f"{self.get_full_name()}.png")
92
+ plt.close()
93
+
94
+ __all__ = ["Bandwidth"]