How to use the cocotb.fork 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 im-tomu / valentyusb / sim / test-dummyusb.py View on Github external
def __init__(self, dut):
        self.dut = dut
        self.csrs = dict()
        with open("csr.csv", newline='') as csr_csv_file:
            csr_csv = csv.reader(csr_csv_file)
            # csr_register format: csr_register, name, address, size, rw/ro
            for row in csr_csv:
                if row[0] == 'csr_register':
                    self.csrs[row[1]] = int(row[2], base=0)
        cocotb.fork(Clock(dut.clk48, 20800, 'ps').start())
        self.wb = WishboneMaster(dut, "wishbone", dut.clk12, timeout=20)

        # Set the signal "test_name" to match this test
        import inspect
        tn = cocotb.binary.BinaryValue(value=None, n_bits=4096)
        tn.buff = inspect.stack()[1][3]
        self.dut.test_name = tn
github cocotb / cocotb / tests / test_cases / test_avalon_stream / test_avalon_stream.py View on Github external
def initialise(self):
        self.dut.reset <= 0
        cocotb.fork(Clock(self.dut.clk, 10).start())
        for _ in range(3):
            yield self.clkedge
        self.dut.reset <= 1
        yield self.clkedge
github cocotb / cocotb / tests / test_cases / test_cocotb / test_edge_triggers.py View on Github external
def test_clock_cycles(dut):
    """
    Test the ClockCycles Trigger
    """

    clk = dut.clk

    clk_gen = cocotb.fork(Clock(clk, 100).start())

    yield RisingEdge(clk)

    dut._log.info("After one edge")

    yield ClockCycles(clk, 10)

    dut._log.info("After 10 edges")
github cocotb / cocotb / tests / test_cases / issue_348 / issue_348.py View on Github external
def start(self):
        clock_edges = 10

        cocotb.fork(clock_gen(self.signal, clock_edges))
        first = cocotb.fork(self.signal_mon(self.signal, 0, self.edge_type))
        second = cocotb.fork(self.signal_mon(self.signal, 1, self.edge_type))

        yield Timer(10000)

        for mon in self.monitor_edges:
            if not mon:
                raise TestFailure("Monitor saw nothing")
github cocotb / cocotb / tests / test_cases / test_iteration_verilog / test_iteration_es.py View on Github external
def dual_iteration(dut):
    loop_one = cocotb.fork(iteration_loop(dut))
    loop_two = cocotb.fork(iteration_loop(dut))

    yield [loop_one.join(), loop_two.join()]
github cocotb / cocotb / tests / test_cases / test_cocotb / test_scheduler.py View on Github external
def test_kill_twice(dut):
    """
    Test that killing a coroutine that has already been killed does not crash
    """
    clk_gen = cocotb.fork(Clock(dut.clk, 100).start())
    yield Timer(1)
    clk_gen.kill()
    yield Timer(1)
    clk_gen.kill()
github cocotb / cocotb / cocotb / monitors / wishbone.py View on Github external
self._datGen            = self.defaultGen0()
        if datGen is not None:
            self._datGen        = datGen
        self._ackGen            = self.defaultGen1()        
        if ackGen is not None:
            self._ackGen        = ackGen    
        self._waitAckGen        = self.defaultGen0()
        if waitAckGen is not None:
            self._waitAckGen    = waitAckGen 
        self._waitStallGen      = self.defaultTupleGen()
        if waitStallGen is not None:
            self._waitStallGen  = self.bitSeqGen(waitStallGen)
            
        Wishbone.__init__(self, *args, **kwargs)
        cocotb.fork(self._stall())
        cocotb.fork(self._clk_cycle_counter())
        cocotb.fork(self._ack())
        self.log.info("Wishbone Slave created")
github cocotb / cocotb / cocotb / drivers / ad9361.py View on Github external
def ad9361_tx_to_rx_loopback(self):
        """Create loopback from ``tx`` to ``rx``.

        Forks a coroutine doing the actual task.
        """
        cocotb.fork(self._ad9361_tx_to_rx_loopback())
github CospanDesign / nysa / nysa / host / sim / sim_host.py View on Github external
self.timeout                          = 1000
        self.response                         = Array('B')

        self.dut.rst                          <= 0
        self.dut.ih_reset                     <= 0

        self.dut.in_ready                     <= 0
        self.dut.in_command                   <= 0
        self.dut.in_address                   <= 0
        self.dut.in_data                      <= 0
        self.dut.in_data_count                <= 0
        gd = GenSDB()
        self.callbacks = {}
        self.rom = gd.gen_rom(self.dev_dict, user_paths = self.user_paths, debug = False)

        cocotb.fork(Clock(dut.clk, period).start())
        cocotb.fork(self.interrupt_interface())