Irq.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using static NIFPGA.Interop;
  8. namespace NIFPGA
  9. {
  10. public class Irq
  11. {
  12. private FPGASession _Session;
  13. private IntPtr _Handle = IntPtr.Zero;
  14. internal Irq(FPGASession session)
  15. {
  16. _Session = session;
  17. }
  18. public void Reserve()
  19. {
  20. if (_Handle != IntPtr.Zero) return;
  21. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReserveIrqContext>()(_Session.Session, ref _Handle));
  22. }
  23. public IrqResult WaitOnIrqs(NiFpga_Irq irq,uint timeout)
  24. {
  25. if(_Handle == IntPtr.Zero)
  26. {
  27. throw new Exception($"Need Call {nameof(Reserve)}");
  28. }
  29. IrqResult result = new IrqResult(timeout, irq);
  30. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WaitOnIrqs>()(_Session.Session, _Handle, irq, timeout, ref result.IrqsAsserted, ref result.IsTimeOut));
  31. return result;
  32. }
  33. public void WaitOnIrqs(ref IrqResult result)
  34. {
  35. if (_Handle == IntPtr.Zero)
  36. {
  37. throw new Exception($"Need Call {nameof(Reserve)}");
  38. }
  39. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WaitOnIrqs>()(_Session.Session, _Handle, result.Irqs, result.TimeOut, ref result.IrqsAsserted, ref result.IsTimeOut));
  40. result.IsAcknowledge = false;
  41. }
  42. public void AcknowledgeIrqs(ref IrqResult result)
  43. {
  44. if (result.IsAcknowledge) return;
  45. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_AcknowledgeIrqs>()(_Session.Session, result.Irqs));
  46. result.IsAcknowledge = true;
  47. }
  48. public void Unreserve()
  49. {
  50. if (_Handle != IntPtr.Zero) return;
  51. _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_UnreserveIrqContext>()(_Session.Session, _Handle));
  52. _Handle = IntPtr.Zero;
  53. }
  54. }
  55. public struct IrqResult
  56. {
  57. public IrqResult(uint timeOut, NiFpga_Irq irqs)
  58. {
  59. TimeOut = timeOut;
  60. Irqs = irqs;
  61. }
  62. public uint TimeOut;
  63. public Boolean IsTimeOut;
  64. public uint IrqsAsserted;
  65. public NiFpga_Irq Irqs;
  66. public bool IsAcknowledge;
  67. }
  68. }