Bitfile.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using FxpConvert.Common;
  7. namespace NIFPGA.lvbitx
  8. {
  9. public class Bitfile
  10. {
  11. public static List<Datatype> Datatypes { get; } = Enum.GetValues(typeof(Datatype)).Cast<Datatype>().ToList();
  12. public string FilePath { get; set; } = string.Empty;
  13. public string BitfileVersion { get; set; } =string.Empty;
  14. public string SignatureRegister { get; set; } = string.Empty;
  15. public string SignatureGuids { get; set; } = string.Empty;
  16. public string SignatureNames { get; set; } = string.Empty;
  17. public string BitstreamVersion { get; set; } = string.Empty;
  18. public string BitstreamMD5 { get; set; } = string.Empty;
  19. public VI VI { get; } = new VI();
  20. public Project Project { get; } = new Project();
  21. }
  22. public class VI
  23. {
  24. public string Name { get; set; } = string.Empty;
  25. public List<Register> Registers { get; } = new List<Register>();
  26. }
  27. public class Register
  28. {
  29. /// <summary>
  30. /// 寄存器名字
  31. /// </summary>
  32. public string Name { get; set; } = string.Empty;
  33. public Boolean Hidden { get; set; }
  34. /// <summary>
  35. /// <see cref="true"/>为读
  36. /// <see cref="false"/>为写
  37. /// </summary>
  38. public Boolean Indicator { get; set; }
  39. /// <summary>
  40. /// 数据类型
  41. /// </summary>
  42. public Datatype Datatype { get; set; }
  43. public string FlattenedType { get; set; } = string.Empty;
  44. /// <summary>
  45. /// 寄存器地址
  46. /// </summary>
  47. public uint Offset { get; set; }
  48. public uint SizeInBits { get; set; }
  49. public uint Class { get; set; }
  50. public bool Internal { get; set; }
  51. public uint ID { get; set; }
  52. public bool Bidirectional { get; set; }
  53. public bool Synchronous { get; set; }
  54. public string MechanicalAction { get; set; }=string.Empty;
  55. public bool AccessMayTimeout { get; set; }
  56. public bool RegisterNode { get; set; }
  57. public NiFpga_FxpTypeInfo FxpTypeInfo;
  58. public uint Size { get; set; }
  59. public Datatype ArrayValueType { get; set; }
  60. public override string ToString() => Name;
  61. }
  62. public class Project
  63. {
  64. public string TargetClass { get; set; }= string.Empty;
  65. public bool AutoRunWhenDownloaded { get; set; }
  66. public uint BaseAddressOnDevice { get; set; }
  67. public List<DMA> DMA { get; } = new List<DMA>();
  68. }
  69. public class DMA
  70. {
  71. public string Name { get; set; } = string.Empty;
  72. public string BaseAddressTag { get; set; } = string.Empty;
  73. public uint ControlSet { get; set; }
  74. public Datatype Datatype { get; set; }
  75. public NiFpga_FxpTypeInfo FxpTypeInfo;
  76. public string Direction { get; set; } = string.Empty;
  77. public string Implementation { get; set; } = string.Empty;
  78. public int Number { get; set; }
  79. public UInt32 NumberOfElements { get; set; }
  80. public Boolean UserVisible { get; set; }
  81. public override string ToString() => Name;
  82. }
  83. public enum Datatype
  84. {
  85. [DataType("Boolean")]
  86. Boolean,
  87. [DataType("I8","EnumI8")]
  88. Int8,
  89. [DataType("U8","EnumU8")]
  90. Uint8,
  91. [DataType("I16","EnumI16")]
  92. Int16,
  93. [DataType("U16","EnumU16")]
  94. Uint16,
  95. [DataType("I32","EnumI32")]
  96. Int32,
  97. [DataType("U32","EnumU32")]
  98. Uint32,
  99. [DataType("I64","EnumI64")]
  100. Int64,
  101. [DataType("U64","EnumU64")]
  102. Uint64,
  103. [DataType("SGL")]
  104. Float,
  105. [DataType("DBL")]
  106. Double,
  107. [DataType("FXP")]
  108. FXP,
  109. [DataType("Array")]
  110. Array,
  111. }
  112. [AttributeUsage(AttributeTargets.Field)]
  113. internal class DataTypeAttribute:Attribute
  114. {
  115. private List<string> names = new List<string>();
  116. public IReadOnlyList<string> Name => names.AsReadOnly();
  117. public DataTypeAttribute(params string[] name)
  118. {
  119. if (name == null || name.Length == 0) return;
  120. names.AddRange(name);
  121. }
  122. }
  123. }