using NativeLibraryLoader; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.Http.Headers; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace NIFPGA { public abstract class FPGABase { protected private FPGASession _Session; internal FPGABase(FPGASession session) { _Session = session; } } public abstract class Fifo : FPGABase { private NiFpga_HostBufferType _HostBufferType; private uint _BytesPerElement; internal Fifo(FPGASession session,uint fifosession) : base(session) { FifoSession= fifosession; if (_Session.Session == 0) return; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, fifosession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferType, ref Unsafe.As(ref _HostBufferType))); _Session.CheckResult(_Session.GetDelegate()(_Session.Session, fifosession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_BytesPerElement, ref _BytesPerElement)); } public void GetDmaBuffer(ref nint ptr) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBuffer, ref ptr)); } public ulong ElementsCurrentlyAcquired =>GetElementsCurrentlyAcquired(); private ulong GetElementsCurrentlyAcquired() { ulong value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_ElementsCurrentlyAcquired, ref value)); return value; } public string Name { get; init; } = string.Empty; private uint GetHostBufferAllocationGranularity() { uint value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferAllocationGranularity, ref value)); return value; } private void SetHostBufferAllocationGranularity(uint value) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferAllocationGranularity, value)); } public uint HostBufferAllocationGranularity { get=>GetHostBufferAllocationGranularity();set=>SetHostBufferAllocationGranularity(value); } private ulong GetHostBufferSize() { ulong value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferSize, ref value)); return value; } private void SetHostBufferSize(ulong value) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferSize, value)); } private ulong GetHostBufferMirrorSize() { ulong value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferMirrorSize, ref value)); return value; } private void SetHostBufferMirrorSize(ulong value) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_HostBufferMirrorSize, value)); } public ulong HostBufferSize { get => GetHostBufferSize(); set => SetHostBufferSize(value); } public ulong HostBufferMirrorSize { get=>GetHostBufferMirrorSize(); set=>SetHostBufferMirrorSize(value); } public UInt32 FifoSession { get; } public NiFpga_FifoFlowControl FifoFlowControl { get=>GetFlowControl(); set=>SetFlowControl(value); } public NiFpga_HostBufferType HostBufferType => _HostBufferType; public uint BytesPerElement => _BytesPerElement; private NiFpga_FifoFlowControl GetFlowControl() { int value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl, ref value)); return (NiFpga_FifoFlowControl)value; } private void SetFlowControl(NiFpga_FifoFlowControl flowControl) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl, (int)flowControl)); } public void Start() { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession)); } public void Stop() { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession)); } public void Unreserve() { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession)); } public void CommitConfiguration() { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession)); } public override string ToString() { return Name; } } }