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_uartrx(dut):
  16. """ First simple test """
  17. clkedge = RisingEdge(dut.clk_i)
  18. # Connect reset
  19. reset_n = dut.reset_n_i
  20. # Instantiate UART driver
  21. uart_driver = UartDriver(dut.rx_i, dut.clk_i, 10, 8, True);
  22. # Instantiate VAI receiver
  23. vai_receiver = VaiReceiver(dut.clk_i, dut.data_o, dut.valid_o, dut.accept_i)
  24. # Drive input defaults (setimmediatevalue to avoid x asserts)
  25. dut.rx_i.setimmediatevalue(1)
  26. dut.accept_i.setimmediatevalue(0)
  27. clock = Clock(dut.clk_i, 10, units="ns") # Create a 1 us 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 uart_driver.send(val)
  38. rec = await vai_receiver.receive();
  39. assert rec == val, "UART received data was incorrect on the {}th cycle".format(i)