Fixes #125.
super().__init__(src_loc_at=src_loc_at)
if not isinstance(domain, str):
raise TypeError("Clock domain name must be a string, not '{!r}'".format(domain))
+ if domain == "comb":
+ raise ValueError("Domain '{}' does not have a clock".format(domain))
self.domain = domain
def shape(self):
super().__init__(src_loc_at=src_loc_at)
if not isinstance(domain, str):
raise TypeError("Clock domain name must be a string, not '{!r}'".format(domain))
+ if domain == "comb":
+ raise ValueError("Domain '{}' does not have a reset".format(domain))
self.domain = domain
self.allow_reset_less = allow_reset_less
raise ValueError("Clock domain name must be specified explicitly")
if name.startswith("cd_"):
name = name[3:]
+ if name == "comb":
+ raise ValueError("Domain '{}' may not be clocked".format(name))
self.name = name
self.clk = Signal(name=self._name_for(name, "clk"), src_loc_at=1)
@contextmanager
def FSM(self, reset=None, domain="sync", name="fsm"):
self._check_context("FSM", context=None)
+ if domain == "comb":
+ raise ValueError("FSM may not be driven by the '{}' domain".format(domain))
fsm_data = self._set_ctrl("FSM", {
"name": name,
"signal": Signal(name="{}_state".format(name), src_loc_at=2),
def __init__(self, domain_map):
if isinstance(domain_map, str):
domain_map = {"sync": domain_map}
+ for src, dst in domain_map.items():
+ if src == "comb":
+ raise ValueError("Domain '{}' may not be renamed".format(src))
+ if dst == "comb":
+ raise ValueError("Domain '{}' may not be renamed to '{}'".format(src, dst))
self.domain_map = OrderedDict(domain_map)
def on_ClockSignal(self, value):
s1 = ClockSignal()
self.assertEqual(repr(s1), "(clk sync)")
+ def test_wrong_name_comb(self):
+ with self.assertRaises(ValueError,
+ msg="Domain 'comb' does not have a clock"):
+ ClockSignal("comb")
+
class ResetSignalTestCase(FHDLTestCase):
def test_domain(self):
s1 = ResetSignal()
self.assertEqual(repr(s1), "(rst sync)")
+ def test_wrong_name_comb(self):
+ with self.assertRaises(ValueError,
+ msg="Domain 'comb' does not have a reset"):
+ ResetSignal("comb")
+
class MockUserValue(UserValue):
def __init__(self, lowered):
sync.rename("pix")
self.assertEqual(sync.name, "pix")
self.assertEqual(sync.clk.name, "pix_clk")
+
+ def test_wrong_name_comb(self):
+ with self.assertRaises(ValueError,
+ msg="Domain 'comb' may not be clocked"):
+ comb = ClockDomain()
()
""")
+ def test_FSM_wrong_domain(self):
+ m = Module()
+ with self.assertRaises(ValueError,
+ msg="FSM may not be driven by the 'comb' domain"):
+ with m.FSM(domain="comb"):
+ pass
+
def test_FSM_wrong_redefined(self):
m = Module()
with m.FSM():
"pix": cd_pix,
})
+ def test_rename_wrong_to_comb(self):
+ with self.assertRaises(ValueError,
+ msg="Domain 'sync' may not be renamed to 'comb'"):
+ DomainRenamer("comb")
+
+ def test_rename_wrong_from_comb(self):
+ with self.assertRaises(ValueError,
+ msg="Domain 'comb' may not be renamed"):
+ DomainRenamer({"comb": "sync"})
+
class DomainLowererTestCase(FHDLTestCase):
def setUp(self):