2026-04-16 16:51:05 +08:00
|
|
|
from typing import List
|
|
|
|
|
from ctypes import c_uint64, c_uint32, c_uint8
|
|
|
|
|
from enum import IntEnum
|
|
|
|
|
|
2026-07-02 17:16:18 +08:00
|
|
|
import UniTAP.libs.lib_tsi.tsi_types as ci
|
2026-04-16 16:51:05 +08:00
|
|
|
from UniTAP.libs.lib_tsi.tsi_io import DeviceIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MemoryManager:
|
|
|
|
|
class MemoryOwner(IntEnum):
|
|
|
|
|
MO_PatternGenerator = 0
|
|
|
|
|
MO_AudioGenerator = 1
|
|
|
|
|
MO_Events = 2
|
|
|
|
|
|
|
|
|
|
MAX_BLOCK_COUNT = 4
|
|
|
|
|
|
2026-07-02 17:16:18 +08:00
|
|
|
DEFAULT_MEMOTY_ALLOCATION = [534600704, 534600704, 2048]
|
2026-04-16 16:51:05 +08:00
|
|
|
RESERVED_MEMORY_BYTES = 8192 * (5120 + 1) * 4 + 0x80000
|
|
|
|
|
|
|
|
|
|
def __init__(self, io: DeviceIO):
|
|
|
|
|
self.__io = io
|
|
|
|
|
|
|
|
|
|
def get_total_memory(self) -> int:
|
2026-07-02 17:16:18 +08:00
|
|
|
result = self.__io.get(ci.TSI_R_MEMORY_SIZE, c_uint64)[1]
|
2026-04-16 16:51:05 +08:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def set_memory_layout(self, layout: List[int]):
|
2026-07-02 17:16:18 +08:00
|
|
|
self.__io.set(ci.TSI_MEMORY_LAYOUT, layout, c_uint64, data_count=len(layout))
|
2026-04-16 16:51:05 +08:00
|
|
|
|
|
|
|
|
def get_memory_layout(self) -> List[int]:
|
2026-07-02 17:16:18 +08:00
|
|
|
return list(self.__io.get(ci.TSI_MEMORY_LAYOUT, c_uint64, self.MAX_BLOCK_COUNT)[1])
|
2026-04-16 16:51:05 +08:00
|
|
|
|
|
|
|
|
def set_memory_block_index(self, index: MemoryOwner):
|
2026-07-02 17:16:18 +08:00
|
|
|
self.__io.set(ci.TSI_MEMORY_BLOCK_INDEX, index.value)
|
2026-04-16 16:51:05 +08:00
|
|
|
|
|
|
|
|
def make_default(self):
|
2026-07-02 17:16:18 +08:00
|
|
|
self.__io.set(ci.TSI_MEMORY_LAYOUT, self.DEFAULT_MEMOTY_ALLOCATION, c_uint64,
|
2026-04-16 16:51:05 +08:00
|
|
|
data_count=len(self.DEFAULT_MEMOTY_ALLOCATION))
|
|
|
|
|
|
|
|
|
|
def reset(self):
|
2026-07-02 17:16:18 +08:00
|
|
|
self.__io.set(ci.TSI_MEMORY_RESET_W, 0)
|
2026-04-16 16:51:05 +08:00
|
|
|
|
|
|
|
|
def memory_write(self, data, size):
|
2026-07-02 17:16:18 +08:00
|
|
|
self.__io.set(ci.TSI_MEMORY_WRITE_W, bytearray(data), data_type=c_uint8, data_count=size)
|