tmsgheaders.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // Headers 4-Mosi
  64. #define BITP_LMX2594_4MOSI_HEADER 12
  65. //Bit mask [15:12]
  66. #define BITM_LMX2594_4MOSI_HEADER (0xF << BITP_LMX2594_4MOSI_HEADER)
  67. #define BITP_DDS_4MOSI_HEADER 19
  68. //Bit mask [21:19]
  69. #define BITM_DDS_4MOSI_HEADER (0x7 << BITP_DDS_4MOSI_HEADER)
  70. // MAX2870
  71. #define BITP_MAX2870_4MOSI_HEADER 9
  72. //Bit mask [10:9]
  73. #define BITM_MAX2870_4MOSI_HEADER (0x3 << BITP_MAX2870_4MOSI_HEADER)
  74. //Shift Reg
  75. #define BITP_SHIFT_REG_4MOSI_HEADER 6
  76. //Bit mask [7:6]
  77. #define BITM_SHIFT_REG_4MOSI_HEADER (0x3 << BITP_SHIFT_REG_4MOSI_HEADER)
  78. // GPIO
  79. #define BITP_GPIO_4MOSI_HEADER 16
  80. //Bit mask [17:16]
  81. #define BITM_GPIO_4MOSI_HEADER (0x3 << BITP_GPIO_4MOSI_HEADER)
  82. // POT
  83. #define BITP_POT_4MOSI_HEADER 3
  84. //Bit mask [4:3]
  85. #define BITM_POT_4MOSI_HEADER (0x3 << BITP_POT_4MOSI_HEADER)
  86. // DAC
  87. #define BITP_DAC_4MOSI_HEADER 2
  88. //Bit mask [2:2]
  89. #define BITM_DAC_4MOSI_HEADER (0x1 << BITP_DAC_4MOSI_HEADER)
  90. // ATT
  91. #define BITP_ATT_4MOSI_HEADER 1
  92. //Bit mask [1:1]
  93. #define BITM_ATT_4MOSI_HEADER (0x1 << BITP_ATT_4MOSI_HEADER)
  94. // SpiMode
  95. #define BITP_SPIMODE_4MOSI_HEADER 23
  96. //Bit mask [23:23]
  97. #define BITM_SPIMODE_4MOSI_HEADER (0x1 << BITP_SPIMODE_4MOSI_HEADER)
  98. // SpiMode 1MOSI
  99. #define ENUM_SPIMODE_1MOSI (0x0 << BITP_SPIMODE_4MOSI_HEADER)
  100. // SpiMode 4MOSI
  101. #define ENUM_SPIMODE_4MOSI (0x1 << BITP_SPIMODE_4MOSI_HEADER)
  102. // Word Numbers 4-MOSI
  103. #define LMXWordNum 14
  104. #define DDSWordNum 4
  105. #define POTWordNum 2
  106. #define DACWordNum 1
  107. #define ATTWordNum 1
  108. #define ShRegWordNum 1
  109. #define MaxWordNum 2
  110. #define GPIOWordNum 1
  111. // Define bit values for GPIO Reg
  112. #define RF_SW1 0x0
  113. #define RF_SW2 0x0
  114. #define CTRL_AM_SW3 0x0
  115. #define DDS_SYNC_CTRL_FPGA 0x0
  116. #define DDS_RESET_FPGA 0x0
  117. #define DDS_SYNC_FPGA 0x0
  118. #define SW_CAP4 0x0
  119. #define AM_ALC_SW 0x1
  120. #define SW_CAP3 0x0
  121. #define SW_CAP2 0x0
  122. #define SW_CAP1 0x0
  123. #define AM_ALC_1_FIX 0x1
  124. #define PLL_VTUNE_CTRL 0x1
  125. #define PLL_SYNC_CTRL 0x0
  126. #define PLL_SYNC 0x0
  127. #define PLL_LOOP_CTRL 0x1
  128. #define DDS_X2_FPGA 0x0
  129. #define DDS_SAW2_FPGA 0x0
  130. #define REF_OFFSET_CTRL_FPGA 0x1
  131. #define GPIO_ADRF_V1 0x0
  132. #define GPIO_ADRF_V2 0x0
  133. #define DDS_SAW1_FPGA 0x0
  134. #define FPGA_AM_CTRL 0x0
  135. #define RF_SW1_BITP 0
  136. #define RF_SW2_BITP 1
  137. #define CTRL_AM_SW3_BITP 2
  138. #define DDS_SYNC_CTRL_FPGA_BITP 3
  139. #define DDS_RESET_FPGA_BITP 4
  140. #define DDS_SYNC_FPGA_BITP 5
  141. #define SW_CAP4_BITP 6
  142. #define AM_ALC_SW_BITP 7
  143. #define SW_CAP3_BITP 8
  144. #define SW_CAP2_BITP 9
  145. #define SW_CAP1_BITP 10
  146. #define AM_ALC_1_FIX_BITP 11
  147. #define PLL_VTUNE_CTRL_BITP 12
  148. #define PLL_SYNC_CTRL_BITP 13
  149. #define PLL_SYNC_BITP 14
  150. #define PLL_LOOP_CTRL_BITP 15
  151. #define DDS_X2_FPGA_BITP 16
  152. #define DDS_SAW2_FPGA_BITP 17
  153. #define REF_OFFSET_CTRL_FPGA_BITP 18
  154. #define GPIO_ADRF_V1_BITP 19
  155. #define GPIO_ADRF_V2_BITP 20
  156. #define DDS_SAW1_FPGA_BITP 21
  157. #define FPGA_AM_CTRL_BITP 22
  158. #define RF_SW1_BITM (0x1 << RF_SW1_BITP )
  159. #define RF_SW2_BITM (0x1 << RF_SW2_BITP )
  160. #define CTRL_AM_SW3_BITM (0x1 << CTRL_AM_SW3_BITP )
  161. #define DDS_SYNC_CTRL_FPGA_BITM (0x1 << DDS_SYNC_CTRL_FPGA_BITP )
  162. #define DDS_RESET_FPGA_BITM (0x1 << DDS_RESET_FPGA_BITP )
  163. #define DDS_SYNC_FPGA_BITM (0x1 << DDS_SYNC_FPGA_BITP )
  164. #define SW_CAP4_BITM (0x1 << SW_CAP4_BITP )
  165. #define AM_ALC_SW_BITM (0x1 << AM_ALC_SW_BITP )
  166. #define SW_CAP3_BITM (0x1 << SW_CAP3_BITP )
  167. #define SW_CAP2_BITM (0x1 << SW_CAP2_BITP )
  168. #define SW_CAP1_BITM (0x1 << SW_CAP1_BITP )
  169. #define AM_ALC_1_FIX_BITM (0x1 << AM_ALC_1_FIX_BITP )
  170. #define PLL_VTUNE_CTRL_BITM (0x1 << PLL_VTUNE_CTRL_BITP )
  171. #define PLL_SYNC_CTRL_BITM (0x1 << PLL_SYNC_CTRL_BITP )
  172. #define PLL_SYNC_BITM (0x1 << PLL_SYNC_BITP )
  173. #define PLL_LOOP_CTRL_BITM (0x1 << PLL_LOOP_CTRL_BITP )
  174. #define DDS_X2_FPGA_BITM (0x1 << DDS_X2_FPGA_BITP )
  175. #define DDS_SAW2_FPGA_BITM (0x1 << DDS_SAW2_FPGA_BITP )
  176. #define REF_OFFSET_CTRL_FPGA_BITM (0x1 << REF_OFFSET_CTRL_FPGA_BITP )
  177. #define GPIO_ADRF_V1_BITM (0x1 << GPIO_ADRF_V1_BITP )
  178. #define GPIO_ADRF_V2_BITM (0x1 << GPIO_ADRF_V2_BITP )
  179. #define DDS_SAW1_FPGA_BITM (0x1 << DDS_SAW1_FPGA_BITP )
  180. #define FPGA_AM_CTRL_BITM (0x1 << FPGA_AM_CTRL_BITP )
  181. #define RF_SW1_0 (0x0 << RF_SW1_BITP)
  182. #define RF_SW1_1 (0x1 << RF_SW1_BITP)
  183. #define RF_SW2_0 (0x0 << RF_SW2_BITP)
  184. #define RF_SW2_1 (0x1 << RF_SW2_BITP)
  185. #define CTRL_AM_SW3_0 (0x0 << CTRL_AM_SW3_BITP)
  186. #define CTRL_AM_SW3_1 (0x1 << CTRL_AM_SW3_BITP)
  187. #define DDS_SYNC_CTRL_FPGA_0 (0x0 << DDS_SYNC_CTRL_FPGA_BITP)
  188. #define DDS_SYNC_CTRL_FPGA_1 (0x1 << DDS_SYNC_CTRL_FPGA_BITP)
  189. #define DDS_RESET_FPGA_0 (0x0 << DDS_RESET_FPGA_BITP)
  190. #define DDS_RESET_FPGA_1 (0x1 << DDS_RESET_FPGA_BITP)
  191. #define DDS_SYNC_FPGA_0 (0x0 << DDS_SYNC_FPGA_BITP)
  192. #define DDS_SYNC_FPGA_1 (0x1 << DDS_SYNC_FPGA_BITP)
  193. #define SW_CAP4_0 (0x0 << SW_CAP4_BITP)
  194. #define SW_CAP4_1 (0x1 << SW_CAP4_BITP)
  195. #define AM_ALC_SW_0 (0x0 << AM_ALC_SW_BITP)
  196. #define AM_ALC_SW_1 (0x1 << AM_ALC_SW_BITP)
  197. #define SW_CAP3_0 (0x0 << SW_CAP3_BITP)
  198. #define SW_CAP3_1 (0x1 << SW_CAP3_BITP)
  199. #define SW_CAP2_0 (0x0 << SW_CAP2_BITP)
  200. #define SW_CAP2_1 (0x1 << SW_CAP2_BITP)
  201. #define SW_CAP1_0 (0x0 << SW_CAP1_BITP)
  202. #define SW_CAP1_1 (0x1 << SW_CAP1_BITP)
  203. #define AM_ALC_1_FIX_0 (0x0 << AM_ALC_1_FIX_BITP)
  204. #define AM_ALC_1_FIX_1 (0x1 << AM_ALC_1_FIX_BITP)
  205. #define PLL_VTUNE_CTRL_0 (0x0 << PLL_VTUNE_CTRL_BITP)
  206. #define PLL_VTUNE_CTRL_1 (0x1 << PLL_VTUNE_CTRL_BITP)
  207. #define PLL_SYNC_CTRL_0 (0x0 << PLL_SYNC_CTRL_BITP)
  208. #define PLL_SYNC_CTRL_1 (0x1 << PLL_SYNC_CTRL_BITP)
  209. #define PLL_SYNC_0 (0x0 << PLL_SYNC_BITP)
  210. #define PLL_SYNC_1 (0x1 << PLL_SYNC_BITP)
  211. #define PLL_LOOP_CTRL_0 (0x0 << PLL_LOOP_CTRL_BITP)
  212. #define PLL_LOOP_CTRL_1 (0x1 << PLL_LOOP_CTRL_BITP)
  213. #define DDS_X2_FPGA_0 (0x0 << DDS_X2_FPGA_BITP)
  214. #define DDS_X2_FPGA_1 (0x1 << DDS_X2_FPGA_BITP)
  215. #define DDS_SAW2_FPGA_0 (0x0 << DDS_SAW2_FPGA_BITP)
  216. #define DDS_SAW2_FPGA_1 (0x1 << DDS_SAW2_FPGA_BITP)
  217. #define REF_OFFSET_CTRL_FPGA_0 (0x0 << REF_OFFSET_CTRL_FPGA_BITP)
  218. #define REF_OFFSET_CTRL_FPGA_1 (0x1 << REF_OFFSET_CTRL_FPGA_BITP)
  219. #define GPIO_ADRF_V1_0 (0x0 << GPIO_ADRF_V1_BITP)
  220. #define GPIO_ADRF_V1_1 (0x1 << GPIO_ADRF_V1_BITP)
  221. #define GPIO_ADRF_V2_0 (0x0 << GPIO_ADRF_V2_BITP)
  222. #define GPIO_ADRF_V2_1 (0x1 << GPIO_ADRF_V2_BITP)
  223. #define DDS_SAW1_FPGA_0 (0x0 << DDS_SAW1_FPGA_BITP)
  224. #define DDS_SAW1_FPGA_1 (0x1 << DDS_SAW1_FPGA_BITP)
  225. #define FPGA_AM_CTRL_0 (0x0 << FPGA_AM_CTRL_BITP)
  226. #define FPGA_AM_CTRL_1 (0x1 << FPGA_AM_CTRL_BITP)
  227. // Define values for Shift Reg
  228. #define SHIFT_REG_SW_RF 0x0
  229. #define SHIFT_REG_SW4_RF 0x0
  230. #define SHIFT_REG_GPIO_SW_015_RF 0x1
  231. #define SHIFT_REG_GPIO_SW_X2_RF 0x0
  232. #define SHIFT_REG_SW1_RF 0x1
  233. #define SHIFT_REG_SW_MIXER_RF 0x0
  234. #define SHIFT_REG_GPIO_SW_X2_RF_BITP 0
  235. #define SHIFT_REG_SW_RF_BITP 1
  236. #define SHIFT_REG_SW4_RF_BITP 2
  237. #define SHIFT_REG_GPIO_SW_015_RF_BITP 3
  238. #define SHIFT_REG_SW_MIXER_RF_BITP 4
  239. #define SHIFT_REG_SW1_RF_BITP 5
  240. #define SHIFT_REG_SW2_RF_BITP 6
  241. #define SHIFT_REG_SW3_RF_BITP 7
  242. #define SHIFT_REG ((SHIFT_REG_SW_RF << 1) | \
  243. (SHIFT_REG_SW4_RF<<2) | \
  244. (SHIFT_REG_GPIO_SW_015_RF<<3) | \
  245. (SHIFT_REG_GPIO_SW_X2_RF<<0) | \
  246. (SHIFT_REG_SW1_RF <<5) | \
  247. (SHIFT_REG_SW_MIXER_RF <<4))
  248. #define GPIO_REG ((FPGA_AM_CTRL << 22) | \
  249. (DDS_SAW1_FPGA << 21) | \
  250. (GPIO_ADRF_V2 << 20) | \
  251. (GPIO_ADRF_V1 << 19) | \
  252. (REF_OFFSET_CTRL_FPGA << 18) | \
  253. (DDS_SAW2_FPGA << 17) | \
  254. (DDS_X2_FPGA << 16) | \
  255. (PLL_LOOP_CTRL << 15) | \
  256. (PLL_SYNC << 14) | \
  257. (PLL_SYNC_CTRL << 13) | \
  258. (PLL_VTUNE_CTRL << 12) | \
  259. (AM_ALC_1_FIX << 11) | \
  260. (SW_CAP1 << 10) | \
  261. (SW_CAP2 << 9) | \
  262. (SW_CAP3 << 8) | \
  263. (AM_ALC_SW << 7) | \
  264. (SW_CAP4 << 6) | \
  265. (DDS_SYNC_FPGA << 5) | \
  266. (DDS_RESET_FPGA << 4) | \
  267. (DDS_SYNC_CTRL_FPGA << 3) | \
  268. (CTRL_AM_SW3 << 2) | \
  269. (RF_SW2 << 1) | \
  270. (RF_SW1 << 0))
  271. // Macros to set register parameter
  272. #define SET_REGISTER_PARAM( REGISTER, BITM, BITP, PARAMETER )\
  273. REGISTER &= ~BITM;\
  274. REGISTER |= PARAMETER;
  275. #define CFG_REG_ADDR 0x08
  276. // Command Register
  277. #define CFG_REG_RST_FOR_FPGA_BITP 0
  278. #define CFG_REG_WIDTH_SPI_TMSG_BITP 1
  279. #define CFG_REG_MOD_CMD_REG_BITP 2
  280. #define CFG_REG_LR_GPIO_BITP 3
  281. #define CFG_REG_HR_GPIO_BITP 4
  282. #define CFG_REG_SPI_MODE_BITP 5
  283. #define CFG_REG_RST_FOR_FPGA_BITM (0x1 << CFG_REG_RST_FOR_FPGA_BITP)
  284. #define CFG_REG_WIDTH_SPI_TMSG_BITM (0x1 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  285. #define CFG_REG_MOD_CMD_REG_BITM (0x1 << CFG_REG_MOD_CMD_REG_BITP)
  286. #define CFG_REG_LR_GPIO_BITM (0x1 << CFG_REG_LR_GPIO_BITP)
  287. #define CFG_REG_HR_GPIO_BITM (0x1 << CFG_REG_HR_GPIO_BITP)
  288. #define CFG_REG_SPI_MODE_BITM (0x1 << CFG_REG_SPI_MODE_BITP)
  289. #define CFG_REG_RST_FOR_FPGA_ON 0x1
  290. #define CFG_REG_RST_FOR_FPGA_OFF 0x0
  291. #define CFG_REG_WIDTH_SPI_TMSG_24_BIT (0x0 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  292. #define CFG_REG_WIDTH_SPI_TMSG_32_BIT (0x1 << CFG_REG_WIDTH_SPI_TMSG_BITP)
  293. #define CFG_REG_MOD_0 (0x0 << CFG_REG_MOD_CMD_REG_BITP)
  294. #define CFG_REG_MOD_1 (0x1 << CFG_REG_MOD_CMD_REG_BITP)
  295. #define CFG_REG_LR_GPIO_0 (0x0 << CFG_REG_LR_GPIO_BITP)
  296. #define CFG_REG_LR_GPIO_1 (0x1 << CFG_REG_LR_GPIO_BITP)
  297. #define CFG_REG_HR_GPIO_0 (0x0 << CFG_REG_HR_GPIO_BITP)
  298. #define CFG_REG_HR_GPIO_1 (0x1 << CFG_REG_HR_GPIO_BITP)
  299. #define CFG_REG_SPI_MODE_1MOSI (0x0 << CFG_REG_SPI_MODE_BITP)
  300. #define CFG_REG_SPI_MODE_4MOSI (0x1 << CFG_REG_SPI_MODE_BITP)
  301. #define LMX_BASE_ADDR 0x04
  302. void rst_for_fpga(void *bar1);
  303. void shift_reg (void *bar1);
  304. void key_switch (void *bar1, double freq,double lmx_freq);
  305. uint32_t get_cfg_reg();
  306. void set_cfg_reg(uint32_t cfgRegToSet);
  307. #endif //DMADRIVER_TMSGHEADERS_H