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.

50 lines
1.4 KiB

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