2011-12-16 15:30:14 -05:00
|
|
|
from migen.fhdl.structure import *
|
2011-12-05 11:43:56 -05:00
|
|
|
|
|
|
|
class Register:
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.fields = []
|
|
|
|
|
2011-12-16 10:02:55 -05:00
|
|
|
def add_field(self, f):
|
2011-12-05 11:43:56 -05:00
|
|
|
self.fields.append(f)
|
|
|
|
|
|
|
|
(READ_ONLY, WRITE_ONLY, READ_WRITE) = range(3)
|
|
|
|
|
|
|
|
class Field:
|
|
|
|
def __init__(self, parent, name, size=1, access_bus=READ_WRITE, access_dev=READ_ONLY, reset=0):
|
|
|
|
self.parent = parent
|
|
|
|
self.name = name
|
|
|
|
self.size = size
|
|
|
|
self.access_bus = access_bus
|
|
|
|
self.access_dev = access_dev
|
|
|
|
self.reset = reset
|
|
|
|
fullname = parent.name + "_" + name
|
2011-12-16 15:30:14 -05:00
|
|
|
self.storage = Signal(BV(self.size), fullname)
|
2011-12-05 11:43:56 -05:00
|
|
|
if self.access_dev == READ_ONLY or self.access_dev == READ_WRITE:
|
2011-12-16 15:30:14 -05:00
|
|
|
self.dev_r = Signal(BV(self.size), fullname + "_r")
|
2011-12-05 11:43:56 -05:00
|
|
|
if self.access_dev == WRITE_ONLY or self.access_dev == READ_WRITE:
|
2011-12-16 15:30:14 -05:00
|
|
|
self.dev_w = Signal(BV(self.size), fullname + "_w")
|
|
|
|
self.dev_we = Signal(name=fullname + "_we")
|
|
|
|
self.parent.add_field(self)
|