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
  5. from Vai import VaiReceiver
  6. from cocotb.clock import Clock
  7. from cocotb.triggers import RisingEdge, Timer
  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_uartrx(dut):
  15. """ First simple test """
  16. clkedge = RisingEdge(dut.clk_i)
  17. # Connect reset
  18. reset_n = dut.reset_n_i
  19. # Instantiate UART driver
  20. uart_driver = UartDriver(dut.rx_i, dut.clk_i, 10, 8, True);
  21. # Instantiate VAI receiver
  22. vai_receiver = VaiReceiver(dut.clk_i, dut.data_o, dut.valid_o, dut.accept_i)
  23. # Drive input defaults (setimmediatevalue to avoid x asserts)
  24. dut.rx_i.setimmediatevalue(1)
  25. dut.accept_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 uart_driver.send(val)
  36. rec = await vai_receiver.receive();
  37. assert rec == val, "UART received data was incorrect on the {}th cycle".format(i)