Irq.cs 2.4 KB

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