2013-03-10 14:32:38 -04:00
|
|
|
import re
|
|
|
|
|
2012-05-16 19:41:41 -04:00
|
|
|
from migen.fhdl.structure import *
|
2013-03-10 14:32:38 -04:00
|
|
|
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
|
|
|
|
|
2013-03-30 12:28:15 -04:00
|
|
|
class Identifier(Module, AutoCSR):
|
2013-03-10 14:32:38 -04:00
|
|
|
def __init__(self, sysid, version, frequency):
|
2013-03-30 12:28:15 -04:00
|
|
|
self._r_sysid = CSRStatus(16)
|
|
|
|
self._r_version = CSRStatus(16)
|
|
|
|
self._r_frequency = CSRStatus(32)
|
2012-05-16 19:41:41 -04:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
###
|
|
|
|
|
|
|
|
self.comb += [
|
2013-03-30 12:28:15 -04:00
|
|
|
self._r_sysid.status.eq(sysid),
|
|
|
|
self._r_version.status.eq(encode_version(version)),
|
|
|
|
self._r_frequency.status.eq(frequency)
|
2012-05-16 19:41:41 -04:00
|
|
|
]
|