lmx2594.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. #include "lmx2594.h"
  2. const uint32_t lmx2594_rst[2] = {
  3. 0x00251e,
  4. 0x00251c
  5. };
  6. uint32_t lmx2594regs[LMX_COUNT] = {
  7. 0x700000,
  8. 0x6F0000,
  9. 0x6E0000,
  10. 0x6D0000,
  11. 0x6C0000,
  12. 0x6B0000,
  13. 0x6A0000,
  14. 0x690021,
  15. 0x680000,
  16. 0x670000,
  17. 0x660000,
  18. 0x650011,
  19. 0x640000,
  20. 0x630000,
  21. 0x620000,
  22. 0x610888,
  23. 0x600000,
  24. 0x5F0000,
  25. 0x5E0000,
  26. 0x5D0000,
  27. 0x5C0000,
  28. 0x5B0000,
  29. 0x5A0000,
  30. 0x590000,
  31. 0x580000,
  32. 0x570000,
  33. 0x560000,
  34. 0x550000,
  35. 0x540000,
  36. 0x530000,
  37. 0x520000,
  38. 0x510000,
  39. 0x500000,
  40. 0x4F0000,
  41. 0x4E0105,
  42. 0x4D0000,
  43. 0x4C000C,
  44. 0x4B0C40,
  45. 0x4A0000,
  46. 0x49003F,
  47. 0x480001,
  48. 0x470081,
  49. 0x46C350,
  50. 0x450000,
  51. 0x4403E8,
  52. 0x430000,
  53. 0x4201F4,
  54. 0x410000,
  55. 0x401388,
  56. 0x3F0000,
  57. 0x3E0322,
  58. 0x3D00A8,
  59. 0x3C03E8,
  60. 0x3B0001,
  61. 0x3A9001,
  62. 0x390020,
  63. 0x380000,
  64. 0x370000,
  65. 0x360000,
  66. 0x350000,
  67. 0x340820,
  68. 0x330080,
  69. 0x320000,
  70. 0x314180,
  71. 0x300300,
  72. 0x2F0300,
  73. 0x2E07FD,
  74. 0x2DC8DF,
  75. 0x2C1F20,
  76. 0x2B0000,
  77. 0x2A0000,
  78. 0x290000,
  79. 0x280000,
  80. 0x2703E8,
  81. 0x260000,
  82. 0x250104,
  83. 0x240032,
  84. 0x230004,
  85. 0x220000,
  86. 0x211E21,
  87. 0x200393,
  88. 0x1F43EC,
  89. 0x1E318C,
  90. 0x1D318C,
  91. 0x1C0488,
  92. 0x1B0002,
  93. 0x1A0DB0,
  94. 0x190C2B,
  95. 0x18071A,
  96. 0x17007C,
  97. 0x160001,
  98. 0x150401,
  99. 0x14D848,
  100. 0x1327B7,
  101. 0x120064,
  102. 0x11012C,
  103. 0x100080,
  104. 0x0F064F,
  105. 0x0E1E70,
  106. 0x0D4000,
  107. 0x0C5001,
  108. 0x0B0018,
  109. 0x0A10D8,
  110. 0x090604,
  111. 0x082000,
  112. 0x0740B2,
  113. 0x06C802,
  114. 0x0500C8,
  115. 0x041443,
  116. 0x030642,
  117. 0x020500,
  118. 0x01080B,
  119. 0x00251C
  120. };
  121. void lmx2594_init(void *bar1) {
  122. // Header for LMX Reset
  123. uint32_t *ptr_rst = bar1 + LMX_BASE_ADDR;
  124. *ptr_rst = LMX2594_RST_HEADER;
  125. // Reset Data
  126. for (int m = 0; m < 2; m++) {
  127. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  128. *ptr = lmx2594_rst[m];
  129. }
  130. // Header for init data
  131. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  132. *ptr = InitLMX2594Header;
  133. // Init data
  134. for (int i = 0; i < LMX_COUNT; i++) {
  135. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  136. *ptr = lmx2594regs[i];
  137. }
  138. }
  139. /*-------------------------LMX2594 Frequency Set-------------------------*/
  140. int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
  141. double N_div;
  142. N_div = freq / f_pd;
  143. // divide whole part and fractional part
  144. uint32_t N = (uint32_t) N_div;
  145. // In frac part there is separate denominator and numerator
  146. // If frac part is 0 then the denominator is 1000 and numerator is 0
  147. uint32_t frac_n = (uint32_t) ((N_div - N) * 524287);
  148. uint32_t frac_d = 524287;
  149. // If frac part is 0 then the denominator is 1000 and numerator is 0
  150. if (frac_n == 0) {
  151. frac_n = 0;
  152. frac_d = 524287;
  153. }
  154. // Recommended sequnce for changin freq
  155. // 1. Change the N-div value
  156. // 2. Change the PLL numerator and denominator
  157. // 3. Program FCAL_EN bit
  158. // Clear the required parts of the register
  159. lmx2594regs[112-MASH_ORDER] = lmx2594regs[112-MASH_ORDER] & (~BITM_LMX2594_R44_MASH_ORDER);
  160. // Set the MASH_ORDER to 3
  161. lmx2594regs[112-MASH_ORDER] = lmx2594regs[112-MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
  162. // Set PF_DLY_SEL to 3
  163. if (freq <= 10e9) {
  164. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  165. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
  166. printf("PFD_DLY_SEL = %d\n", 3);
  167. }
  168. else if (freq > 10e9) {
  169. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  170. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
  171. printf("PFD_DLY_SEL = %d\n", 4);
  172. }
  173. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] &(~0xFFFF);
  174. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] | (N >> 16);
  175. //CLear the lower 16 bits of the register
  176. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] & (~0xFFFF);
  177. // Next 16 bits of the register
  178. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] | (N & 0xFFFF);
  179. // Clear the upper 16 bits of the register lmx2594regs[PLL_NUM_S]
  180. lmx2594regs[112-PLL_NUM_S] = lmx2594regs[112-PLL_NUM_S] & (~0xFFFF);
  181. lmx2594regs[112-PLL_NUM_S] = lmx2594regs[112-PLL_NUM_S] | (frac_n >> 16);
  182. // Clear the lower 16 bits of the register lmx2594regs[PLL_NUM_M]
  183. lmx2594regs[112-PLL_NUM_M] = lmx2594regs[112-PLL_NUM_M] & (~0xFFFF);
  184. // Next 16 bits of the numerator
  185. lmx2594regs[112-PLL_NUM_M] = lmx2594regs[112-PLL_NUM_M] | (frac_n & 0xFFFF);
  186. // Clear the upper 16 bits of the register lmx2594regs[PLL_DEN_S]
  187. lmx2594regs[112-PLL_DEN_S] = lmx2594regs[112-PLL_DEN_S] & (~0xFFFF);
  188. // most significant 16 bits of the denominator
  189. lmx2594regs[112-PLL_DEN_S] = lmx2594regs[112-PLL_DEN_S] | (frac_d >> 16);
  190. // Clear the lower 16 bits of the register lmx2594regs[PLL_DEN_M]
  191. lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] & (~0xFFFF);
  192. // Next 16 bits of the denominator
  193. lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] | (frac_d & 0xFFFF);
  194. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  195. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
  196. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  197. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  198. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_VCO;
  199. // Program the FCAL_EN bit
  200. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  201. // Show the all the upper 16 bits of the register lmx2594regs[PLL_N_S]
  202. // Determine which regs are changed and send only those
  203. uint32_t lmx_change_freq_regs[] = {
  204. lmx2594regs[112-MASH_ORDER],
  205. lmx2594regs[112-PFD_DLY_SEL],
  206. lmx2594regs[112-PLL_N_S],
  207. lmx2594regs[112-PLL_N_M],
  208. lmx2594regs[112-PLL_DEN_S],
  209. lmx2594regs[112-PLL_DEN_M],
  210. lmx2594regs[112-PLL_NUM_S],
  211. lmx2594regs[112-PLL_NUM_M],
  212. lmx2594regs[112 - CHDIV],
  213. lmx2594regs[112 - CHDIV_DIV2],
  214. lmx2594regs[112-OUTA_MUX],
  215. lmx2594regs[112-FCAL_ADDR]
  216. };
  217. // Create a header for the LMX2594 with the appropriate number of words
  218. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs)/4) << 1) | 1);
  219. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  220. *ptr = LMX_HEADER;
  221. for (int i = 0; i < sizeof(lmx_change_freq_regs)/4; i++) {
  222. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  223. *data_ptr = lmx_change_freq_regs[i];
  224. }
  225. usleep(1);
  226. printf("N_div = %f\n", N_div);
  227. printf("f_vco = %f\n", freq);
  228. printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
  229. printf("N = %d\n", N);
  230. printf("frac_n = %d\n", frac_n);
  231. printf("frac_d = %d\n", frac_d);
  232. return 0;
  233. }
  234. int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
  235. double f_vco = 2 * freq;
  236. int chan_div = 2;
  237. uint8_t ch_div_reg = 0; // 2
  238. double vco_div = 7.5e9 / freq;
  239. double N_div;
  240. // minimum N_div value is 28 and Vco frequency can't be less than 7.5 GHz
  241. if (f_vco < 7.5e9) {
  242. if (vco_div > 2 && vco_div <= 4)
  243. chan_div = 4; // 4
  244. f_vco = freq * chan_div;
  245. if (vco_div > 4 && vco_div <= 6) {
  246. chan_div = 6; // 6
  247. f_vco = freq * chan_div;
  248. }
  249. if (vco_div > 6 && vco_div <= 8) {
  250. chan_div = 8; // 8
  251. f_vco = freq * chan_div;
  252. }
  253. if (vco_div > 8 && vco_div <= 12) {
  254. chan_div = 12; // 12
  255. f_vco = freq * chan_div;
  256. }
  257. if (vco_div > 12 && vco_div <= 16) {
  258. chan_div = 16; // 16
  259. f_vco = freq * chan_div;
  260. }
  261. if (vco_div > 16 && vco_div <= 24) {
  262. chan_div = 24; // 24
  263. f_vco = freq * chan_div;
  264. }
  265. if (vco_div > 24 && vco_div <= 32) {
  266. chan_div = 32; // 32
  267. f_vco = freq * chan_div;
  268. }
  269. if (vco_div > 32 && vco_div <= 48) {
  270. chan_div = 48; // 48
  271. f_vco = freq * chan_div;
  272. }
  273. if (vco_div > 48 && vco_div <= 64) {
  274. chan_div = 64; // 64
  275. f_vco = freq * chan_div;
  276. }
  277. if (vco_div > 64 && vco_div <= 72) {
  278. chan_div = 72; // 72
  279. f_vco = freq * chan_div;
  280. }
  281. if (vco_div > 72 && vco_div <= 96) {
  282. chan_div = 96; // 96
  283. f_vco = freq * chan_div;
  284. }
  285. if (vco_div > 96 && vco_div <= 128) {
  286. chan_div = 128; // 128
  287. f_vco = freq * chan_div;
  288. }
  289. if (vco_div > 128 && vco_div <= 192) {
  290. chan_div = 192; // 192
  291. f_vco = freq * chan_div;
  292. }
  293. if (vco_div > 192 && vco_div <= 256) {
  294. chan_div = 256; // 256
  295. f_vco = freq * chan_div;
  296. }
  297. if (vco_div > 256 && vco_div <= 384) {
  298. chan_div = 384; // 384
  299. f_vco = freq * chan_div;
  300. }
  301. if (vco_div > 384 && vco_div <= 512) {
  302. chan_div = 512; // 512
  303. f_vco = freq * chan_div;
  304. }
  305. if (vco_div > 512 && vco_div <= 768) {
  306. chan_div = 768; // 768
  307. f_vco = freq * chan_div;
  308. }
  309. switch (chan_div) {
  310. case 2:
  311. ch_div_reg = 0;
  312. break;
  313. case 4:
  314. ch_div_reg = 1;
  315. break;
  316. case 6:
  317. ch_div_reg = 2;
  318. break;
  319. case 8:
  320. ch_div_reg = 3;
  321. break;
  322. case 12:
  323. ch_div_reg = 4;
  324. break;
  325. case 16:
  326. ch_div_reg = 5;
  327. break;
  328. case 24:
  329. ch_div_reg = 6;
  330. break;
  331. case 32:
  332. ch_div_reg = 7;
  333. break;
  334. case 48:
  335. ch_div_reg = 8;
  336. break;
  337. case 64:
  338. ch_div_reg = 9;
  339. break;
  340. case 72:
  341. ch_div_reg = 10;
  342. break;
  343. case 96:
  344. ch_div_reg = 11;
  345. break;
  346. case 128:
  347. ch_div_reg = 12;
  348. break;
  349. case 192:
  350. ch_div_reg = 13;
  351. break;
  352. case 256:
  353. ch_div_reg = 14;
  354. break;
  355. case 384:
  356. ch_div_reg = 15;
  357. break;
  358. case 512:
  359. ch_div_reg = 16;
  360. break;
  361. case 768:
  362. ch_div_reg = 17;
  363. break;
  364. }
  365. } else {
  366. ch_div_reg = 0;
  367. f_vco = freq * 2;
  368. }
  369. N_div = f_vco / f_pd;
  370. // divide whole part and fractional part
  371. uint32_t N = (uint32_t) N_div;
  372. uint32_t frac_n = (uint32_t) ((N_div - N) * 524287);
  373. uint32_t frac_d = 524287;
  374. // If frac part is 0 then the denominator is 1000 and numerator is 0
  375. if (frac_n == 0) {
  376. frac_n = 0;
  377. frac_d = 524287;
  378. }
  379. // Partial assist for the calibration
  380. lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] & (~BITM_LMX2594_R44_MASH_ORDER);
  381. // Set the MASH_ORDER to 3
  382. lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
  383. // Set PF_DLY_SEL to appropriate value
  384. if (f_vco <=10e9){
  385. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  386. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
  387. printf("PFD_DLY_SEL = %d\n", 3);
  388. }
  389. else if (f_vco > 10e9) {
  390. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  391. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
  392. printf("PFD_DLY_SEL = %d\n", 4);
  393. }
  394. lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] & (~0xFFFF);
  395. lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] | (N >> 16);
  396. //CLear the lower 16 bits of the register
  397. lmx2594regs[112 - PLL_N_M] = lmx2594regs[112 - PLL_N_M] & (~0xFFFF);
  398. // Next 16 bits of the register
  399. lmx2594regs[112 - PLL_N_M] = lmx2594regs[112 - PLL_N_M] | (N & 0xFFFF);
  400. // Clear the upper 16 bits of the register lmx2594regs[PLL_NUM_S]
  401. lmx2594regs[112 - PLL_NUM_S] = lmx2594regs[112 - PLL_NUM_S] & (~0xFFFF);
  402. lmx2594regs[112 - PLL_NUM_S] = lmx2594regs[112 - PLL_NUM_S] | (frac_n >> 16);
  403. // Clear the lower 16 bits of the register lmx2594regs[PLL_NUM_M]
  404. lmx2594regs[112 - PLL_NUM_M] = lmx2594regs[112 - PLL_NUM_M] & (~0xFFFF);
  405. // Next 16 bits of the numerator
  406. lmx2594regs[112 - PLL_NUM_M] = lmx2594regs[112 - PLL_NUM_M] | (frac_n & 0xFFFF);
  407. // Clear the upper 16 bits of the register lmx2594regs[PLL_DEN_S]
  408. lmx2594regs[112 - PLL_DEN_S] = lmx2594regs[112 - PLL_DEN_S] & (~0xFFFF);
  409. // most significant 16 bits of the denominator
  410. lmx2594regs[112 - PLL_DEN_S] = lmx2594regs[112 - PLL_DEN_S] | (frac_d >> 16);
  411. // Clear the lower 16 bits of the register lmx2594regs[PLL_DEN_M]
  412. lmx2594regs[112 - PLL_DEN_M] = lmx2594regs[112 - PLL_DEN_M] & (~0xFFFF);
  413. // Next 16 bits of the denominator
  414. lmx2594regs[112 - PLL_DEN_M] = lmx2594regs[112 - PLL_DEN_M] | (frac_d & 0xFFFF);
  415. // Program the CHDIV value
  416. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
  417. // Set the CHDIV value with the starting position BITP_LMX2594_R75_CHDIV
  418. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] | (ch_div_reg << BITP_LMX2594_R75_CHDIV);
  419. // If the ch_div > 2 then set the SEG1_EN bit
  420. if (chan_div > 2) {
  421. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  422. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] | (ENUM_LMX2594_R31_CHDIV_DIV2_EN);
  423. }
  424. else {
  425. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  426. }
  427. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  428. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  429. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_CH_DIV;
  430. // Program the FCAL_EN bit
  431. lmx2594regs[112 - FCAL_ADDR] = lmx2594regs[112 - FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  432. uint32_t lmx_change_freq_regs[] = {
  433. lmx2594regs[112-MASH_ORDER],
  434. lmx2594regs[112-PFD_DLY_SEL],
  435. lmx2594regs[112 - PLL_N_S],
  436. lmx2594regs[112 - PLL_N_M],
  437. lmx2594regs[112 - PLL_DEN_S],
  438. lmx2594regs[112 - PLL_DEN_M],
  439. lmx2594regs[112 - PLL_NUM_S],
  440. lmx2594regs[112 - PLL_NUM_M],
  441. lmx2594regs[112 - CHDIV],
  442. lmx2594regs[112 - CHDIV_DIV2],
  443. lmx2594regs[112 - OUTA_MUX],
  444. lmx2594regs[112 - FCAL_ADDR]
  445. };
  446. // Create a header for the LMX2594 with the appropriate number of words
  447. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
  448. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  449. *ptr = LMX_HEADER;
  450. // Send the data
  451. for (int i = 0; i < sizeof(lmx_change_freq_regs) / 4; i++) {
  452. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  453. *data_ptr = lmx_change_freq_regs[i];
  454. }
  455. usleep(1);
  456. printf("N_div = %f\n", N_div);
  457. printf("f_vco = %f\n", f_vco);
  458. printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
  459. printf("N = %d\n", N);
  460. printf("frac_n = %d\n", frac_n);
  461. printf("frac_d = %d\n", frac_d);
  462. printf("chan_div = %d\n", chan_div);
  463. printf("chan_div_reg = %d\n", ch_div_reg);
  464. return 0;
  465. }
  466. int lmx_freq_set(void *bar1, double freq) {
  467. double f_pd = 200e6;
  468. double N_div = 0;
  469. if (freq < 10e6 || freq > 15e9) {
  470. printf("Frequency range is 10 MHz to 15 GHz\n");
  471. return -1;
  472. }
  473. // if the frequency is in the main band - 7.5 GHz to 15 GHz
  474. if (freq >= 7.5e9 && freq <= 15e9) {
  475. lmx_freq_set_main_band(bar1, freq, f_pd);
  476. }
  477. else if (freq < 7.5e9) {
  478. lmx_freq_set_out_of_band(bar1, freq, f_pd);
  479. }
  480. return 0;
  481. }
  482. uint32_t lmx_ld_status(void *bar1) {
  483. uint32_t *read_ptr = (uint32_t *)(bar1 + LMX_LD_STATUS_ADDR);
  484. uint32_t read_value = *read_ptr;
  485. return read_value;
  486. }