Fifo.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using NativeLibraryLoader;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.Http.Headers;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace NIFPGA
  10. {
  11. public abstract class FPGABase
  12. {
  13. protected private FPGASession _Session;
  14. internal FPGABase(FPGASession session)
  15. {
  16. _Session = session;
  17. }
  18. }
  19. public abstract class Fifo : FPGABase
  20. {
  21. private NiFpga_HostBufferType _HostBufferType;
  22. private uint _BytesPerElement;
  23. internal Fifo(FPGASession session,uint fifosession) : base(session)
  24. {
  25. FifoSession= fifosession;
  26. if (_Session.Session == 0) return;
  27. int value = 0;
  28. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyI32>()(_Session.Session, fifosession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferType, ref value));
  29. _HostBufferType = (NiFpga_HostBufferType)value;
  30. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyU32>()(_Session.Session, fifosession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_BytesPerElement, ref _BytesPerElement));
  31. }
  32. public string Name { get; init; } = string.Empty;
  33. private uint GetHostBufferAllocationGranularity()
  34. {
  35. uint value = 0;
  36. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyU32>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferAllocationGranularity, ref value));
  37. return value;
  38. }
  39. private void SetHostBufferAllocationGranularity(uint value)
  40. {
  41. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_SetFifoPropertyU32>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferAllocationGranularity, value));
  42. }
  43. public uint HostBufferAllocationGranularity
  44. {
  45. get=>GetHostBufferAllocationGranularity();set=>SetHostBufferAllocationGranularity(value);
  46. }
  47. private ulong GetHostBufferSize()
  48. {
  49. ulong value = 0;
  50. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyU64>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferSize, ref value));
  51. return value;
  52. }
  53. private void SetHostBufferSize(ulong value)
  54. {
  55. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_SetFifoPropertyU64>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferSize, value));
  56. }
  57. private ulong GetHostBufferMirrorSize()
  58. {
  59. ulong value = 0;
  60. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyU64>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferMirrorSize, ref value));
  61. return value;
  62. }
  63. private void SetHostBufferMirrorSize(ulong value)
  64. {
  65. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_SetFifoPropertyU64>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferMirrorSize, value));
  66. }
  67. public ulong HostBufferSize { get => GetHostBufferSize(); set => SetHostBufferSize(value); }
  68. public ulong HostBufferMirrorSize { get=>GetHostBufferMirrorSize(); set=>SetHostBufferMirrorSize(value); }
  69. public UInt32 FifoSession { get; }
  70. public NiFpga_FifoFlowControl FifoFlowControl { get=>GetFlowControl(); set=>SetFlowControl(value); }
  71. public NiFpga_HostBufferType HostBufferType => _HostBufferType;
  72. public uint BytesPerElement => _BytesPerElement;
  73. private NiFpga_FifoFlowControl GetFlowControl()
  74. {
  75. int value = 0;
  76. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_GetFifoPropertyI32>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl, ref value));
  77. return (NiFpga_FifoFlowControl)value;
  78. }
  79. private void SetFlowControl(NiFpga_FifoFlowControl flowControl)
  80. {
  81. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_SetFifoPropertyI32>()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl, (int)flowControl));
  82. }
  83. public void Start()
  84. {
  85. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_StartFifo>()(_Session.Session, FifoSession));
  86. }
  87. public void Stop()
  88. {
  89. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_StopFifo>()(_Session.Session, FifoSession));
  90. }
  91. public void Unreserve()
  92. {
  93. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_UnreserveFifo>()(_Session.Session, FifoSession));
  94. }
  95. public void CommitConfiguration()
  96. {
  97. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_CommitFifoConfiguration>()(_Session.Session, FifoSession));
  98. }
  99. public override string ToString()
  100. {
  101. return Name;
  102. }
  103. }
  104. }