using NIFPGA.lvbitx; using System.Runtime.CompilerServices; namespace NIFPGA { public abstract class FPGABase { protected private FPGASession _Session; internal FPGABase(FPGASession session) { _Session = session; } } public abstract class Fifo : FPGABase { private protected DMA dma; private NiFpga_HostBufferType _HostBufferType; private uint _BytesPerElement; internal Fifo(FPGASession session,DMA dma) : base(session) { this.dma = dma; 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 => dma.Name; 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 => dma.ControlSet; public NiFpga_FifoFlowControl FifoFlowControl { get=>GetFlowControl(); set=>SetFlowControl(value); } public NiFpga_HostBufferType HostBufferType => _HostBufferType; public uint BytesPerElement => _BytesPerElement; private NiFpga_FifoFlowControl GetFlowControl() { NiFpga_FifoFlowControl value = 0; _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl, ref Unsafe.As(ref value))); return value; } private void SetFlowControl(NiFpga_FifoFlowControl flowControl) { _Session.CheckResult(_Session.GetDelegate()(_Session.Session, FifoSession, Interop.NiFpga_FifoProperty.NiFpga_FifoProperty_FlowControl,Unsafe.As(ref 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; } } }