File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -749,10 +749,18 @@ def reset(self):
749
749
self .critical = not self .background
750
750
self .waits_on = None
751
751
self .coroutine = self .constructor (self .context )
752
+ self .first_await = True
752
753
753
754
def run (self ):
754
755
try :
755
756
self .waits_on = self .coroutine .send (None )
757
+ # Special case to make combination logic replacement work correctly: ensure that
758
+ # a process looping over `changed()` always gets awakened at least once at time 0,
759
+ # to see the initial values.
760
+ if self .first_await and self .waits_on .initial_eligible ():
761
+ self .waits_on .compute_result ()
762
+ self .waits_on = self .coroutine .send (None )
763
+ self .first_await = False
756
764
except StopIteration :
757
765
self .critical = False
758
766
self .waits_on = None
Original file line number Diff line number Diff line change @@ -555,7 +555,7 @@ def activate(self):
555
555
else :
556
556
self ._broken = True
557
557
558
- def run (self ):
558
+ def compute_result (self ):
559
559
result = []
560
560
for trigger in self ._combination ._triggers :
561
561
if isinstance (trigger , (SampleTrigger , ChangedTrigger )):
@@ -570,12 +570,20 @@ def run(self):
570
570
assert False # :nocov:
571
571
self ._result = tuple (result )
572
572
573
+ def run (self ):
574
+ self .compute_result ()
573
575
self ._combination ._process .runnable = True
574
576
self ._combination ._process .waits_on = None
575
577
self ._triggers_hit .clear ()
576
578
for waker , interval_fs in self ._delay_wakers .items ():
577
579
self ._engine .state .set_delay_waker (interval_fs , waker )
578
580
581
+ def initial_eligible (self ):
582
+ return not self ._oneshot and any (
583
+ isinstance (trigger , ChangedTrigger )
584
+ for trigger in self ._combination ._triggers
585
+ )
586
+
579
587
def __await__ (self ):
580
588
self ._result = None
581
589
if self ._broken :
Original file line number Diff line number Diff line change @@ -1506,6 +1506,22 @@ def test_comb_clock_conflict(self):
1506
1506
r"^Clock signal is already driven by combinational logic$" ):
1507
1507
sim .add_clock (1e-6 )
1508
1508
1509
+ def test_initial (self ):
1510
+ a = Signal (4 , init = 3 )
1511
+ m = Module ()
1512
+ sim = Simulator (m )
1513
+ fired = 0
1514
+
1515
+ async def process (ctx ):
1516
+ nonlocal fired
1517
+ async for val_a , in ctx .changed (a ):
1518
+ self .assertEqual (val_a , 3 )
1519
+ fired += 1
1520
+
1521
+ sim .add_process (process )
1522
+ sim .run ()
1523
+ self .assertEqual (fired , 1 )
1524
+
1509
1525
def test_sample (self ):
1510
1526
m = Module ()
1511
1527
m .domains .sync = cd_sync = ClockDomain ()
You can’t perform that action at this time.
0 commit comments