29 lines
No EOL
841 B
Python
29 lines
No EOL
841 B
Python
from abc import ABC, abstractmethod
|
|
|
|
from typing_extensions import override
|
|
|
|
class FlashChip(ABC):
|
|
@abstractmethod
|
|
def write(self, vaddr: int, value: int, access: int) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def read(self, vaddr: int, access: int) -> int:
|
|
return 0
|
|
|
|
class OpenBus(FlashChip):
|
|
@override
|
|
def write(self, vaddr: int, value: int, access: int) -> None:
|
|
pass
|
|
|
|
@override
|
|
def read(self, vaddr: int, access: int) -> int:
|
|
return vaddr & ((2 ** (access * 8)) - 1) # pyright: ignore[reportAny]
|
|
class DebugPort(FlashChip):
|
|
@override
|
|
def write(self, vaddr: int, value: int, access: int) -> None:
|
|
print(chr(value), end="")
|
|
|
|
@override
|
|
def read(self, vaddr: int, access: int) -> int:
|
|
return vaddr & ((2 ** (access * 8)) - 1) # pyright: ignore[reportAny] |