-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathahb_bus.py
89 lines (74 loc) · 2.34 KB
/
ahb_bus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : ahb_bus.py
# License : MIT license <Check LICENSE>
# Author : Anderson I. da Silva (aignacio) <[email protected]>
# Date : 08.10.2023
# Last Modified Date: 12.11.2023
from cocotb_bus.drivers import Bus
from cocotb.handle import SimHandleBase
from typing import Any
class AHBBus(Bus):
_signals = [
"haddr",
"hsize",
"htrans",
"hwdata",
"hrdata",
"hwrite",
"hready",
"hresp",
]
_optional_signals = [
"hburst",
"hmastlock",
"hprot",
"hnonsec",
"hexcl",
"hmaster",
"hexokay",
"hsel",
"hready_in",
]
def __init__(
self, entity: SimHandleBase = None, prefix: str = None, **kwargs: Any
) -> None:
name = prefix if prefix is not None else entity._name + "_ahb_bus"
# Handle default signals or signals overrided at an upper level
if "signals" not in kwargs:
kwargs["signals"] = self._signals
else:
entity._log.info(f"AHB ({name}) master use provided signals mapping")
# Handle default optional_signals or optional_signals overrided at an upper level
if "optional_signals" not in kwargs:
kwargs["optional_signals"] = self._optional_signals
else:
entity._log.info(
f"AHB ({name}) master use provided optional_signals mapping"
)
super().__init__(entity, prefix, **kwargs)
self.entity = entity
self.name = name
self._data_width = len(self.hwdata)
self._addr_width = len(self.haddr)
@property
def data_width(self):
return self._data_width
@property
def addr_width(self):
return self._addr_width
@property
def hsel_exist(self):
return True if "hsel" in self._signals else False
@property
def hready_in_exist(self):
return True if "hready_in" in self._signals else False
@property
def hburst_exist(self):
return True if "hburst" in self._signals else False
@classmethod
def from_entity(cls, entity, **kwargs):
return cls(entity, **kwargs)
@classmethod
def from_prefix(cls, entity, prefix, **kwargs):
return cls(entity, prefix, **kwargs)