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.

85 lines
2.3 KiB

  1. import logging
  2. from cocotb.triggers import FallingEdge, RisingEdge, Timer, ReadOnly
  3. class Vai:
  4. """VAI base class"""
  5. def __init__(self, clock, data, valid, accept, *args, **kwargs):
  6. self._version = "0.0.1"
  7. self.log = logging.getLogger(f"cocotb.{data._path}")
  8. self._data = data
  9. self._valid = valid
  10. self._accept = accept
  11. self._clock = clock
  12. self._clkedge = RisingEdge(self._clock)
  13. class VaiDriver(Vai):
  14. """Valid-Accept Driver"""
  15. def __init__(self, clock, data, valid, accept, *args, **kwargs):
  16. super().__init__(clock, data, valid, accept, *args, **kwargs)
  17. self.log.info("Valid-accept driver")
  18. self.log.info(" cocotbext-vai version %s", self._version)
  19. self.log.info(" Copyright (c) 2022 Torsten Meissner")
  20. # Drive input defaults (setimmediatevalue to avoid x asserts)
  21. self._data.setimmediatevalue(0)
  22. self._valid.setimmediatevalue(0)
  23. async def send(self, data, sync=True):
  24. if sync:
  25. await self._clkedge
  26. self.log.info("Sending data: %s", hex(data))
  27. self._valid.value = 1
  28. self._data.value = data
  29. while True:
  30. await ReadOnly()
  31. if self._accept.value:
  32. break
  33. await self._clkedge
  34. await self._clkedge
  35. self._valid.value = 0
  36. class VaiReceiver(Vai):
  37. """Valid-Accept Receiver"""
  38. def __init__(self, clock, data, valid, accept, *args, **kwargs):
  39. super().__init__(clock, data, valid, accept, *args, **kwargs)
  40. self.log.info("Valid-accept receiver")
  41. self.log.info(" cocotbext-vai version %s", self._version)
  42. self.log.info(" Copyright (c) 2022 Torsten Meissner")
  43. # Drive input defaults (setimmediatevalue to avoid x asserts)
  44. self._accept.setimmediatevalue(0)
  45. async def receive(self, sync=True):
  46. if sync:
  47. await self._clkedge
  48. while True:
  49. await ReadOnly()
  50. if self._valid.value:
  51. break
  52. await self._clkedge
  53. await self._clkedge
  54. self._accept.value = 1
  55. _rec = self._data.value
  56. self.log.info("Received data: %s", hex(_rec))
  57. await self._clkedge
  58. self._accept.value = 0
  59. return _rec