How to use the cocotb.scheduler.add function in cocotb

To help you get started, we’ve selected a few cocotb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cocotb / cocotb / tests / test_cases / test_cocotb / test_scheduler.py View on Github external
def test_coroutine_kill(dut):
    """Test that killing a coroutine causes pending routine continue"""
    global test_flag
    clk_gen = cocotb.scheduler.add(clock_gen(dut.clk))
    yield Timer(100)
    clk_gen_two = cocotb.fork(clock_yield(clk_gen))
    yield Timer(100)
    clk_gen.kill()
    if test_flag is not False:
        raise TestFailure
    yield Timer(1000)
    if test_flag is not True:
        raise TestFailure
github cocotb / cocotb / tests / test_cases / test_cocotb / test_generator_coroutines.py View on Github external
def test_yield_list(dut):
    """Example of yielding on a list of triggers"""
    clock = dut.clk
    cocotb.scheduler.add(clock_gen(clock))
    yield [Timer(1000), Timer(2000)]

    yield Timer(10000)
github cocotb / cocotb / cocotb / monitors / __init__.py View on Github external
def __init__(self, callback=None, event=None):
        self._event = event
        self._wait_event = Event()
        self._recvQ = deque()
        self._callbacks = []
        self.stats = MonitorStatistics()

        # Sub-classes may already set up logging
        if not hasattr(self, "log"):
            self.log = SimLog("cocotb.monitor.%s" % (type(self).__qualname__))

        if callback is not None:
            self.add_callback(callback)

        # Create an independent coroutine which can receive stuff
        self._thread = cocotb.scheduler.add(self._monitor_recv())
github cocotb / cocotb / examples / comb_seq / issue12.py View on Github external
# convenience
    clock = dut.clk
    ready = dut.stream_in_ready
    dout_comb = dut.stream_out_data_comb
    dout_regd = dut.stream_out_data_registered

    clock <= 0

    dut.stream_out_ready <= 0

    real_clock = Clock(clock, 1000)
    yield Timer(1000)

    # kick off the coroutines
    rdys = cocotb.scheduler.add(ready_fiddler(dut.clk, dut.stream_out_ready))
    drvr = cocotb.scheduler.add(driver(dut.clk, dut.stream_in_ready, dut.stream_in_data))

    yield Timer(1000)
    real_clock.start(12)

    expected_comb = 0
    expected_regd = 0
    failed = 0

    for clock_tick in range(6):
        yield RisingEdge(dut.clk)
        yield ReadOnly()
        if ready.value.value: expected_comb += 1
        dut.log.info("ready: %s\tdout_comb: %d\tdout_regd: %d" % (ready.value.value, dout_comb.value.value, dout_regd.value.value))
        if dout_comb.value.value != expected_comb:
            dut.log.error("Expected dout_comb to be %d but got %d" % (expected_comb, dout_comb.value.value))
            failed += 1
github cocotb / cocotb / examples / demo / demo.py View on Github external
"""This is an example test"""
    dut.log.info("Example test got DUT:" + str(dut))

    yield Timer(10000)

    clk = dut.clock
    enable = dut.enable
    reset = dut.reset
    count = dut.counter_out

    dut.log.info(str(clk))

    cgen = cocotb.scheduler.add(clock_generator(clk))
    yield reset_dut(clk, reset, enable)
    dut.log.info("Reset DUT complete, continuing test...")
    cmon = cocotb.scheduler.add(clock_monitor(clk, count))

    dut.log.info("Blocking test until the clock generator finishes...")
    yield cgen.join()

    sync = Event()
    cocotb.scheduler.add(waiting_coroutine(sync))
    yield Timer(10000)
    dut.log.info("Waking up the waiting coroutine with an event...")
    sync.set()
    yield Timer(10000)


    result = yield Timer(1000000)
    dut.log.warning("test complete!")
github cocotb / cocotb / examples / plusargs / demo.py View on Github external
yield Timer(10000)

    clk = dut.clock
    enable = dut.enable
    reset = dut.reset
    count = dut.counter_out

    dut.log.info(str(clk))

    for name in cocotb.plusargs:
        print name, cocotb.plusargs[name]

    cgen = cocotb.scheduler.add(clock_generator(clk))
    yield reset_dut(clk, reset, enable)
    dut.log.info("Reset DUT complete, continuing test...")
    cmon = cocotb.scheduler.add(clock_monitor(clk, count))

    dut.log.info("Blocking test until the clock generator finishes...")
    yield cgen.join()

    sync = Event()
    cocotb.scheduler.add(waiting_coroutine(sync))
    yield Timer(10000)
    dut.log.info("Waking up the waiting coroutine with an event...")
    sync.set()
    yield Timer(10000)


    result = yield Timer(1000000)
    dut.log.warning("test complete!")
github cocotb / cocotb / examples / comb_seq / issue12.py View on Github external
# convenience
    clock = dut.clk
    ready = dut.stream_in_ready
    dout_comb = dut.stream_out_data_comb
    dout_regd = dut.stream_out_data_registered

    clock <= 0

    dut.stream_out_ready <= 0

    real_clock = Clock(clock, 1000)
    yield Timer(1000)

    # kick off the coroutines
    rdys = cocotb.scheduler.add(ready_fiddler(dut.clk, dut.stream_out_ready))
    drvr = cocotb.scheduler.add(driver(dut.clk, dut.stream_in_ready, dut.stream_in_data))

    yield Timer(1000)
    real_clock.start(12)

    expected_comb = 0
    expected_regd = 0
    failed = 0

    for clock_tick in range(6):
        yield RisingEdge(dut.clk)
        yield ReadOnly()
        if ready.value.value: expected_comb += 1
        dut.log.info("ready: %s\tdout_comb: %d\tdout_regd: %d" % (ready.value.value, dout_comb.value.value, dout_regd.value.value))
        if dout_comb.value.value != expected_comb:
            dut.log.error("Expected dout_comb to be %d but got %d" % (expected_comb, dout_comb.value.value))
github cocotb / cocotb / cocotb / drivers / __init__.py View on Github external
def __init__(self):
        """Constructor for a driver instance."""
        self._pending = Event(name="Driver._pending")
        self._sendQ = deque()

        # Sub-classes may already set up logging
        if not hasattr(self, "log"):
            self.log = SimLog("cocotb.driver.%s" % (type(self).__qualname__))

        # Create an independent coroutine which can send stuff
        self._thread = cocotb.scheduler.add(self._send_thread())