2024-03-11 00:31:30 -04:00
|
|
|
from registers import *
|
|
|
|
|
|
|
|
class PicoRV32(Immutable):
|
|
|
|
def __init__(self, ram, params, ram_pi):
|
2024-03-11 21:13:23 -04:00
|
|
|
"""
|
|
|
|
:param ram: Instance of FlatArea containing the executable space
|
|
|
|
of the PicoRV32.
|
|
|
|
:param params: Instance of RegisterRegion. This register region
|
|
|
|
contains CPU register information, the enable/disable bit, etc.
|
|
|
|
:param ram_pi: Register that controls ram read/write access.
|
|
|
|
"""
|
2024-03-11 00:31:30 -04:00
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.ram = ram
|
|
|
|
self.ram_pi = ram_pi
|
|
|
|
self.params = params
|
|
|
|
|
|
|
|
self.make_immutable()
|
|
|
|
|
|
|
|
def load(self, filename, force=False):
|
2024-03-11 21:13:23 -04:00
|
|
|
""" Load file (as bytes) into PicoRV32.
|
|
|
|
:param filename: File to load.
|
|
|
|
:param force: If True, turn off the PicoRV32 even if it's running.
|
|
|
|
"""
|
2024-03-11 00:31:30 -04:00
|
|
|
if not force and self.params.enable == 1:
|
|
|
|
raise Exception("PicoRV32 RAM cannot be modified while running")
|
|
|
|
|
|
|
|
self.params.enable.v = 0
|
|
|
|
self.ram_pi.v = 0
|
|
|
|
with open(filename, 'rb') as f:
|
2024-03-11 21:13:23 -04:00
|
|
|
self.ram.mem8.load(f.read())
|
2024-03-11 00:31:30 -04:00
|
|
|
|
|
|
|
def enable(self):
|
2024-03-11 21:13:23 -04:00
|
|
|
""" Start the PicoRV32. """
|
2024-03-11 00:31:30 -04:00
|
|
|
self.ram_pi.v = 1
|
|
|
|
self.params.enable.v = 1
|
|
|
|
|
|
|
|
def dump(self):
|
2024-03-11 21:13:23 -04:00
|
|
|
""" Dump all status information about the PicoRV32. """
|
2024-03-11 00:31:30 -04:00
|
|
|
return self.params.dump()
|
|
|
|
|
|
|
|
def test_pico(pico, filename, cl_I):
|
|
|
|
pico.params.cl_I.v = cl_I
|
|
|
|
|
|
|
|
pico.load(filename, force=True)
|
|
|
|
pico.enable()
|
|
|
|
|
|
|
|
return pico.dump()
|