litex/milkymist/identifier/__init__.py

31 lines
943 B
Python
Raw Normal View History

import re
2012-05-16 19:41:41 -04:00
from migen.fhdl.structure import *
from migen.fhdl.module import Module
2012-05-16 19:41:41 -04:00
from migen.bank.description import *
def encode_version(version):
match = re.match("(\d+)\.(\d+)(\.(\d+))?(rc(\d+))?", version, re.IGNORECASE)
r = (int(match.group(1)) << 12) | (int(match.group(2)) << 8)
subminor = match.group(4)
rc = match.group(6)
if subminor:
r |= int(subminor) << 4
if rc:
r |= int(rc)
return r
class Identifier(Module, AutoReg):
def __init__(self, sysid, version, frequency):
2012-05-16 19:41:41 -04:00
self._r_sysid = RegisterField("sysid", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
self._r_version = RegisterField("version", 16, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
2012-05-22 07:23:44 -04:00
self._r_frequency = RegisterField("frequency", 32, access_bus=READ_ONLY, access_dev=WRITE_ONLY)
2012-05-16 19:41:41 -04:00
###
self.comb += [
self._r_sysid.field.w.eq(sysid),
self._r_version.field.w.eq(encode_version(version)),
self._r_frequency.field.w.eq(frequency)
2012-05-16 19:41:41 -04:00
]