tmsgheaders.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef DMADRIVER_TMSGHEADERS_H
  2. #define DMADRIVER_TMSGHEADERS_H
  3. #include <stdint.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. // Device IDs
  7. #define DeviceIdLmx2594 0x0
  8. #define DeviceIdDDS 0x1
  9. #define DeviceIdPot 0x2
  10. #define DeviceIdDac 0x3
  11. #define DeviceIdAtt 0x4
  12. #define DeviceIdShReg 0x5
  13. #define DeviceIdMax2870 0x6
  14. #define DeviceIdGpio1 0x7
  15. #define DeviceIdTemp 0x8
  16. #define DeviceIdGpio2 0x9
  17. // Init Word Numbers 1 MOSI
  18. #define Gpio1InitWordNum 2
  19. #define Gpio2InitWordNum 1
  20. #define PotWordInitNum 1
  21. #define DacWordInitNum 1
  22. #define AttWordInitNum 1
  23. #define ShRegWordInitNum 1
  24. #define Lmx2594InitWordNum 113
  25. #define DDSInitWordNum 37
  26. #define MaxInitWordNum 6
  27. #define TempSensWordNum 1
  28. // Bit Positions
  29. #define RF_SW1_BITP 0
  30. #define RF_SW2_BITP 1
  31. #define CTRL_AM_SW3_BITP 2
  32. #define DDS_SYNC_CTRL_FPGA_BITP 3
  33. #define DDS_RESET_FPGA_BITP 4
  34. #define DDS_SYNC_FPGA_BITP 5
  35. #define SW_CAP4_BITP 6
  36. #define AM_ALC_SW_BITP 7
  37. #define SW_CAP3_BITP 8
  38. #define SW_CAP2_BITP 9
  39. #define SW_CAP1_BITP 10
  40. #define AM_ALC_1_FIX_BITP 11
  41. #define PLL_VTUNE_CTRL_BITP 12
  42. #define PLL_SYNC_CTRL_BITP 13
  43. #define PLL_SYNC_BITP 14
  44. #define PLL_LOOP_CTRL_BITP 15
  45. #define DDS_X2_FPGA_BITP 16
  46. #define DDS_SAW2_FPGA_BITP 17
  47. #define REF_OFFSET_CTRL_FPGA_BITP 18
  48. #define GPIO_ADRF_V1_BITP 19
  49. #define GPIO_ADRF_V2_BITP 20
  50. #define DDS_SAW1_FPGA_BITP 21
  51. // Headers 1-MOSI
  52. #define LMX2594_RST_HEADER ((0 << 23) | (DeviceIdLmx2594 << 18) | (2 << 1) | 1)
  53. #define GPIO_INIT_HEADER ((0 << 23) | (DeviceIdGpio1 << 18) | (Gpio1InitWordNum << 1) | 1)
  54. #define InitGpio2Header ((0 << 23) | (DeviceIdGpio2 << 18) | (Gpio2InitWordNum << 1) | 1)
  55. #define TempSensHeader ((0 << 23) | (DeviceIdTemp << 18) | (TempSensWordNum << 1) | 1)
  56. #define InitLMX2594Header ((0 << 23) | (DeviceIdLmx2594 << 18) | (Lmx2594InitWordNum << 1) | 1)
  57. #define InitDDSHeader ((0 << 23) | (DeviceIdDDS << 18) | (DDSInitWordNum << 1) | 1)
  58. #define InitMAX2870Header ((0 << 23) | (DeviceIdMax2870 << 18) | (MaxInitWordNum << 1) | 1)
  59. #define InitPotHeader ((0 << 23) | (DeviceIdPot << 18) | (PotWordInitNum << 1) | 1)
  60. #define InitDacHeader ((0 << 23) | (DeviceIdDac << 18) | (DacWordInitNum << 1) | 1)
  61. #define InitAttHeader ((0 << 23) | (DeviceIdAtt << 18) | (AttWordInitNum << 1) | 1)
  62. #define InitShRegHeader ((0 << 23) | (DeviceIdShReg << 18) | (ShRegWordInitNum << 1) | 1)
  63. // Word Numbers 4-MOSI
  64. #define LMXWordNum 14
  65. #define DDSWordNum 4
  66. #define POTWordNum 2
  67. #define DACWordNum 1
  68. #define ATTWordNum 1
  69. #define ShRegWordNum 1
  70. #define MaxWordNum 2
  71. #define GPIOWordNum 1
  72. // Define bit values for GPIO Reg
  73. #define RF_SW1 0x0
  74. #define RF_SW2 0x0
  75. #define CTRL_AM_SW3 0x0
  76. #define DDS_SYNC_CTRL_FPGA 0x0
  77. #define DDS_RESET_FPGA 0x0
  78. #define DDS_SYNC_FPGA 0x0
  79. #define SW_CAP4 0x0
  80. #define AM_ALC_SW 0x1
  81. #define SW_CAP3 0x0
  82. #define SW_CAP2 0x0
  83. #define SW_CAP1 0x0
  84. #define AM_ALC_1_FIX 0x1
  85. #define PLL_VTUNE_CTRL 0x1
  86. #define PLL_SYNC_CTRL 0x0
  87. #define PLL_SYNC 0x0
  88. #define PLL_LOOP_CTRL 0x1
  89. #define DDS_X2_FPGA 0x0
  90. #define DDS_SAW2_FPGA 0x0
  91. #define REF_OFFSET_CTRL_FPGA 0x1
  92. #define GPIO_ADRF_V1 0x2
  93. #define GPIO_ADRF_V2 0x0
  94. #define DDS_SAW1_FPGA 0x0
  95. #define FPGA_AM_CTRL 0x0
  96. // Define values for Shift Reg
  97. #define SHIFT_REG_SW_RF 0x0
  98. #define SHIFT_REG_SW4_RF 0x0
  99. #define SHIFT_REG_GPIO_SW_015_RF 0x1
  100. #define SHIFT_REG_GPIO_SW_X2_RF 0x0
  101. #define SHIFT_REG_SW1_RF 0x1
  102. #define SHIFT_REG_SW_MIXER_RF 0x0
  103. #define SHIFT_REG_GPIO_SW_X2_RF_BITP 0
  104. #define SHIFT_REG_SW_RF_BITP 1
  105. #define SHIFT_REG_SW4_RF_BITP 2
  106. #define SHIFT_REG_GPIO_SW_015_RF_BITP 3
  107. #define SHIFT_REG_SW_MIXER_RF_BITP 4
  108. #define SHIFT_REG_SW1_RF_BITP 5
  109. #define SHIFT_REG_SW2_RF_BITP 6
  110. #define SHIFT_REG_SW3_RF_BITP 7
  111. #define SHIFT_REG ((SHIFT_REG_SW_RF << 1) | \
  112. (SHIFT_REG_SW4_RF<<2) | \
  113. (SHIFT_REG_GPIO_SW_015_RF<<3) | \
  114. (SHIFT_REG_GPIO_SW_X2_RF<<0) | \
  115. (SHIFT_REG_SW1_RF <<5) | \
  116. (SHIFT_REG_SW_MIXER_RF <<4))
  117. #define GPIO_REG ((FPGA_AM_CTRL << 22) | \
  118. (DDS_SAW1_FPGA << 21) | \
  119. (GPIO_ADRF_V2 << 20) | \
  120. (GPIO_ADRF_V1 << 19) | \
  121. (REF_OFFSET_CTRL_FPGA << 18) | \
  122. (DDS_SAW2_FPGA << 17) | \
  123. (DDS_X2_FPGA << 16) | \
  124. (PLL_LOOP_CTRL << 15) | \
  125. (PLL_SYNC << 14) | \
  126. (PLL_SYNC_CTRL << 13) | \
  127. (PLL_VTUNE_CTRL << 12) | \
  128. (AM_ALC_1_FIX << 11) | \
  129. (SW_CAP1 << 10) | \
  130. (SW_CAP2 << 9) | \
  131. (SW_CAP3 << 8) | \
  132. (AM_ALC_SW << 7) | \
  133. (SW_CAP4 << 6) | \
  134. (DDS_SYNC_FPGA << 5) | \
  135. (DDS_RESET_FPGA << 4) | \
  136. (DDS_SYNC_CTRL_FPGA << 3) | \
  137. (CTRL_AM_SW3 << 2) | \
  138. (RF_SW2 << 1) | \
  139. (RF_SW1 << 0))
  140. #define SET_REGISTER_PARAM( REGISTER, BITM, BITP, PARAMETER )\
  141. REGISTER &= ~BITM;\
  142. REGISTER |= (PARAMETER << BITP);
  143. #define CFG_REG_ADDR 0x08
  144. // Command Register
  145. #define CFG_REG_RST_FOR_FPGA_BITP 0
  146. #define CFG_REG_WIDTH_SPI_TMSG_BITP 1
  147. #define CFG_REG_MOD_CMD_REG_BITP 2
  148. #define CFG_REG_LR_GPIO_BITP 3
  149. #define CFG_REG_HR_GPIO_BITP 4
  150. #define CFG_REG_RST_FOR_FPGA_BITM (0x1 << CFG_REG_RST_FOR_FPGA_BITP)
  151. #define CFG_REG_WIDTH_SPI_TMSG_BITM (0x1 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  152. #define CFG_REG_MOD_CMD_REG_BITM (0x1 << CFG_REG_MOD_CMD_REG_BITP)
  153. #define CFG_REG_LR_GPIO_BITM (0x1 << CFG_REG_LR_GPIO_BITP)
  154. #define CFG_REG_HR_GPIO_BITM (0x1 << CFG_REG_HR_GPIO_BITP)
  155. #define CFG_REG_RST_FOR_FPGA_ON 0x1
  156. #define CFG_REG_RST_FOR_FPGA_OFF 0x0
  157. #define CFG_REG_WIDTH_SPI_TMSG_24_BIT (0x0 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  158. #define CFG_REG_WIDTH_SPI_TMSG_32_BIT (0x1 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  159. #define CFG_REG_MOD_0 (0x0 << CFG_REG_MOD_CMD_REG_BITP)
  160. #define CFG_REG_MOD_1 (0x1 << CFG_REG_MOD_CMD_REG_BITP)
  161. #define CFG_REG_LR_GPIO_0 (0x0 << CFG_REG_LR_GPIO_BITP)
  162. #define CFG_REG_LR_GPIO_1 (0x1 << CFG_REG_LR_GPIO_BITP)
  163. #define CFG_REG_HR_GPIO_0 (0x0 << CFG_REG_HR_GPIO_BITP)
  164. #define CFG_REG_HR_GPIO_1 (0x1 << CFG_REG_HR_GPIO_BITP)
  165. #define LMX_BASE_ADDR 0x04
  166. void rst_for_fpga(void *bar1);
  167. void shift_reg (void *bar1);
  168. void key_switch (void *bar1, double freq,double lmx_freq);
  169. uint32_t get_cfg_reg();
  170. void set_cfg_reg(uint32_t cfgRegToSet);
  171. #endif //DMADRIVER_TMSGHEADERS_H