Examples of using cocotb for functional verification of VHDL designs with GHDL.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. import logging
  2. import random
  3. import cocotb
  4. from Uart import UartDriver, UartReceiver
  5. from Vai import VaiDriver, VaiReceiver
  6. from cocotb.clock import Clock
  7. from cocotb.triggers import FallingEdge, RisingEdge, Timer, ReadOnly
  8. # Reset coroutine
  9. async def reset_dut(reset_n, duration_ns):
  10. reset_n.value = 0
  11. await Timer(duration_ns, units="ns")
  12. reset_n.value = 1
  13. @cocotb.test()
  14. async def test_uarttx(dut):
  15. """ First simple test """
  16. clkedge = RisingEdge(dut.clk_i)
  17. # Connect reset
  18. reset_n = dut.reset_n_i
  19. # Instantiate VAI driver
  20. vai_driver = VaiDriver(dut.clk_i, dut.data_i, dut.valid_i, dut.accept_o)
  21. # Instantiate UART receiver
  22. uart_receiver = UartReceiver(dut.tx_o, dut.clk_i, 10, 8, True);
  23. # Drive input defaults (setimmediatevalue to avoid x asserts)
  24. dut.data_i.setimmediatevalue(0)
  25. dut.valid_i.setimmediatevalue(0)
  26. clock = Clock(dut.clk_i, 10, units="ns") # Create a 10 ns period clock
  27. cocotb.start_soon(clock.start()) # Start the clock
  28. # Execution will block until reset_dut has completed
  29. await reset_dut(reset_n, 100)
  30. dut._log.info("Released reset")
  31. # Test 10 UART transmissions
  32. for i in range(10):
  33. await Timer(100, units="ns")
  34. val = random.randint(0, 255)
  35. await vai_driver.send(val)
  36. rec = await uart_receiver.receive();
  37. assert rec == val, "UART sent data was incorrect on the {}th cycle".format(i)