2011-12-16 15:30:14 -05:00
|
|
|
from migen.fhdl.structure import *
|
2011-12-05 11:43:56 -05:00
|
|
|
|
|
|
|
class Register:
|
2011-12-17 18:28:04 -05:00
|
|
|
def __init__(self, name, raw=None):
|
2011-12-05 11:43:56 -05:00
|
|
|
self.name = name
|
2011-12-17 18:28:04 -05:00
|
|
|
self.raw = raw
|
|
|
|
if raw is not None:
|
|
|
|
self.dev_re = Signal(name=name + "_re")
|
|
|
|
self.dev_r = Signal(raw, name + "_r")
|
|
|
|
self.dev_w = Signal(raw, name + "_w")
|
|
|
|
else:
|
|
|
|
self.fields = []
|
2011-12-05 11:43:56 -05:00
|
|
|
|
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)
|