intel / rohd

The Rapid Open Hardware Development (ROHD) framework is a framework for describing and verifying hardware in the Dart programming language.
https://intel.github.io/rohd-website
BSD 3-Clause "New" or "Revised" License
370 stars 65 forks source link

Rohme interop #471

Closed AdamRose66 closed 6 months ago

AdamRose66 commented 6 months ago

Description & Motivation

Allow immediate scheduling of an action within the same delta cycle

This is a Rohme inspired enhancement to enable things like external IO inside
a non Future timer callback.
        var publisher = publish(loops, Duration(milliseconds: 250));

        Simulator simulator = Simulator(clockPeriod: SimDuration(picoseconds: 10));

        simulator.run((simulator) async {
          Future.delayed(tickTime(5), () async {
            expect(simulator.elapsedTicks, 5);

            await simulator.immediate(() => subscribe(publisher) );

            expect(simulator.elapsedTicks, 5);
          });

          Future.delayed(tickTime(10), () async {
            expect(simulator.elapsedTicks, 10);
          });
        });

        await simulator.elapse(SimDuration(picoseconds: 1000));
The Rohme call simulator.immediate( action ) is a thinish wrapper around the new
Rohd call Simulator.registerImmediateAction( action ) [ It just wraps a Completer
around the underlying action ].

This preserves the ability to do things like
     simulator.run((simulator) async {
        Future.delayed( tickTime(10) , () async {
          a();
          await Future.delayed( tickTime( 10 ) );
          b();
        });
        Future.delayed( tickTime(11) , () async {
          c();
          await Future.delayed( tickTime( 10 ) );
          d();
        });
      });
in Rohme, but also provide the ability to do "genuinely asynchronous" communication in zero
simulation time.

Testing

Two new tests in simulator_test.dart

Backwards-compatibility

All tests still pass, and this is a new API, so no backward compatibility issues anticipated.

Documentation

Code is documented in line.

AdamRose66 commented 6 months ago

For some reason this has created some merge conflicts, and I don't think I can resolve them since I don't have write access to the Rohd repo. To resolve the conflicts, just accept all the rohme_interop changes.