lmx2594.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. #include "lmx2594.h"
  2. #include <math.h>
  3. const uint32_t lmx2594_rst[] = {
  4. 0x002516,
  5. 0x002514
  6. };
  7. uint32_t lmx2594regs[LMX_COUNT] = {
  8. 0x700000,
  9. 0x6F0000,
  10. 0x6E0000,
  11. 0x6D0000,
  12. 0x6C0000,
  13. 0x6B0000,
  14. 0x6A0000,
  15. 0x690021,
  16. 0x680000,
  17. 0x670000,
  18. 0x660000,
  19. 0x650011,
  20. 0x640000,
  21. 0x630000,
  22. 0x620000,
  23. 0x610888,
  24. 0x600000,
  25. 0x5F0000,
  26. 0x5E0000,
  27. 0x5D0000,
  28. 0x5C0000,
  29. 0x5B0000,
  30. 0x5A0000,
  31. 0x590000,
  32. 0x580000,
  33. 0x570000,
  34. 0x560000,
  35. 0x550000,
  36. 0x540000,
  37. 0x530000,
  38. 0x520000,
  39. 0x510000,
  40. 0x500000,
  41. 0x4F0000,
  42. 0x4E016F,
  43. 0x4D0000,
  44. 0x4C000C,
  45. 0x4B0800,
  46. 0x4A0000,
  47. 0x49003F,
  48. 0x480001,
  49. 0x470081,
  50. 0x46C350,
  51. 0x450000,
  52. 0x4403E8,
  53. 0x430000,
  54. 0x4201F4,
  55. 0x410000,
  56. 0x401388,
  57. 0x3F0000,
  58. 0x3E0322,
  59. 0x3D00A8,
  60. 0x3C03E8,
  61. 0x3B0001,
  62. 0x3A9001,
  63. 0x390020,
  64. 0x380000,
  65. 0x370000,
  66. 0x360000,
  67. 0x350000,
  68. 0x340820,
  69. 0x330080,
  70. 0x320000,
  71. 0x314180,
  72. 0x300300,
  73. 0x2F0300,
  74. 0x2E07FC,
  75. 0x2DC8DF,
  76. 0x2C1FA0,
  77. 0x2B0000,
  78. 0x2A0000,
  79. 0x290000,
  80. 0x280000,
  81. 0x2703E8,
  82. 0x260000,
  83. 0x250104,
  84. 0x240032,
  85. 0x230004,
  86. 0x220000,
  87. 0x211E21,
  88. 0x200393,
  89. 0x1F43EC,
  90. 0x1E318C,
  91. 0x1D318C,
  92. 0x1C0488,
  93. 0x1B0002,
  94. 0x1A0DB0,
  95. 0x190C2B,
  96. 0x18071A,
  97. 0x17007C,
  98. 0x160001,
  99. 0x150401,
  100. 0x14F848,
  101. 0x1327B7,
  102. 0x120064,
  103. 0x11012C,
  104. 0x100080,
  105. 0x0F064F,
  106. 0x0E1E40,
  107. 0x0D4000,
  108. 0x0C5001,
  109. 0x0B0018,
  110. 0x0A10D8,
  111. 0x090604,
  112. 0x082000,
  113. 0x0740B2,
  114. 0x06C802,
  115. 0x0500C8,
  116. 0x041243,
  117. 0x030642,
  118. 0x020500,
  119. 0x010808,
  120. 0x00251C
  121. };
  122. double lmx_freq; // Frequency of the LMX2594
  123. void lmx2594_init(void *bar1) {
  124. // Header for LMX Reset
  125. uint32_t *ptr_rst = bar1 + LMX_BASE_ADDR;
  126. *ptr_rst = LMX2594_RST_HEADER;
  127. // Reset Data
  128. for (int m = 0; m < (sizeof(lmx2594_rst))/4; m++) {
  129. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  130. *ptr = lmx2594_rst[m];
  131. }
  132. // Header for init data
  133. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  134. *ptr = InitLMX2594Header;
  135. // Init data
  136. for (int i = 0; i < LMX_COUNT; i++) {
  137. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  138. *ptr = lmx2594regs[i];
  139. }
  140. FILE * f = fopen("init.txt", "w");
  141. for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
  142. fprintf(f, "0x%08X\n", lmx2594regs[i]);
  143. }
  144. fclose(f);
  145. }
  146. /*-------------------------LMX2594 Frequency Set-------------------------*/
  147. int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
  148. double N_div;
  149. N_div = freq / f_pd;
  150. int vco_core;
  151. double f_coremin;
  152. double f_coremax;
  153. int c_core_min;
  154. int c_core_max;
  155. int a_core_min;
  156. int a_core_max;
  157. uint16_t vco_cap_ctrl_strt;
  158. uint16_t vco_daciset_strt;
  159. // divide whole part and fractional part
  160. uint32_t N = (uint32_t) N_div;
  161. // In frac part there is separate denominator and numerator
  162. // If frac part is 0 then the denominator is 1000 and numerator is 0
  163. uint32_t frac_n = (uint32_t) ((N_div - N) * (4294967295-1));
  164. uint32_t frac_d = 4294967295-1;
  165. // If frac part is 0 then the denominator is 1000 and numerator is 0
  166. if (frac_n == 0) {
  167. frac_n = 0;
  168. frac_d = 1000;
  169. }
  170. // Partial assist for the calibration
  171. //Determine a VCO core and other parameters
  172. if (freq >= 7500e6 && freq <= 8600e6) {
  173. vco_core = 1;
  174. f_coremin = 7500e6;
  175. f_coremax = 8600e6;
  176. c_core_min = 164;
  177. c_core_max = 12;
  178. a_core_min = 299;
  179. a_core_max = 240;
  180. }
  181. else if (freq > 8600e6 && freq < 9800e6) {
  182. vco_core = 2;
  183. f_coremin = 8600e6;
  184. f_coremax = 9800e6;
  185. c_core_min = 165;
  186. c_core_max = 16;
  187. a_core_min = 356;
  188. a_core_max = 247;
  189. }
  190. else if (freq >= 9800e6 && freq <= 10800e6) {
  191. vco_core = 3;
  192. f_coremin = 9800e6;
  193. f_coremax = 10800e6;
  194. c_core_min = 158;
  195. c_core_max = 19;
  196. a_core_min = 324;
  197. a_core_max = 224;
  198. }
  199. else if (freq > 10800e6 && freq <= 12000e6) {
  200. vco_core = 4;
  201. f_coremin = 10800e6;
  202. f_coremax = 12000e6;
  203. c_core_min = 140;
  204. c_core_max = 0;
  205. a_core_min = 383;
  206. a_core_max = 244;
  207. }
  208. else if (freq > 12000e6 && freq <= 12900e6) {
  209. vco_core = 5;
  210. f_coremin = 12000e6;
  211. f_coremax = 12900e6;
  212. c_core_min = 183;
  213. c_core_max = 36;
  214. a_core_min = 205;
  215. a_core_max = 146;
  216. }
  217. else if (freq > 12900e6 && freq <= 13900e6) {
  218. vco_core = 6;
  219. f_coremin = 12900e6;
  220. f_coremax = 13900e6;
  221. c_core_min = 155;
  222. c_core_max = 6;
  223. a_core_min = 242;
  224. a_core_max = 163;
  225. }
  226. else if (freq > 13900e6 && freq <= 15000e6) {
  227. vco_core = 7;
  228. f_coremin = 13900e6;
  229. f_coremax = 15000e6;
  230. c_core_min = 175;
  231. c_core_max = 19;
  232. a_core_min = 323;
  233. a_core_max = 244;
  234. };
  235. if (freq >=11900e6 && freq <=12100e6) {
  236. vco_daciset_strt = 300;
  237. vco_core = 4;
  238. vco_cap_ctrl_strt = 1;
  239. }
  240. vco_cap_ctrl_strt = round(c_core_min - (c_core_min - c_core_max) * (freq - f_coremin) / (f_coremax - f_coremin));
  241. vco_daciset_strt = round(a_core_min + (a_core_min - a_core_max) * (freq - f_coremin) / (f_coremax - f_coremin));
  242. printf("VCO_CORE = %d\n", vco_core);
  243. printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
  244. printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
  245. // Calibration assist
  246. //Set the VCO_CORE
  247. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
  248. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] | (vco_core << BITP_LMX2594_R20_VCO_SEL);
  249. // Set the VCO_CAP_CTRL
  250. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] & (~BITM_LMX2594_R78_VCO_CAP_CTRL_START);
  251. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] | (vco_cap_ctrl_strt << BITP_LMX2594_R78_VCO_CAP_CTRL_START);
  252. // Set the VCO_DACISET
  253. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] & (~BITM_LMX2594_R17_VCO_DACISET);
  254. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] | (vco_daciset_strt << BITP_LMX2594_R17_VCO_DACISET);
  255. // Recommended sequnce for changin freq
  256. // 1. Change the N-div value
  257. // 2. Change the PLL numerator and denominator
  258. // 3. Program FCAL_EN bit
  259. // Clear the required parts of the register
  260. lmx2594regs[112-MASH_ORDER] = lmx2594regs[112-MASH_ORDER] & (~BITM_LMX2594_R44_MASH_ORDER);
  261. // Set the MASH_ORDER to 3
  262. lmx2594regs[112-MASH_ORDER] = lmx2594regs[112-MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
  263. // Set PF_DLY_SEL to 3
  264. if (freq <= 10e9) {
  265. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  266. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
  267. printf("PFD_DLY_SEL = %d\n", 3);
  268. }
  269. else if (freq > 10e9) {
  270. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  271. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
  272. printf("PFD_DLY_SEL = %d\n", 4);
  273. }
  274. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] &(~0xFFFF);
  275. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] | (N >> 16);
  276. //CLear the lower 16 bits of the register
  277. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] & (~0xFFFF);
  278. // Next 16 bits of the register
  279. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] | (N & 0xFFFF);
  280. // Clear the upper 16 bits of the register lmx2594regs[PLL_NUM_S]
  281. lmx2594regs[112-PLL_NUM_S] = lmx2594regs[112-PLL_NUM_S] & (~0xFFFF);
  282. lmx2594regs[112-PLL_NUM_S] = lmx2594regs[112-PLL_NUM_S] | (frac_n >> 16);
  283. // Clear the lower 16 bits of the register lmx2594regs[PLL_NUM_M]
  284. lmx2594regs[112-PLL_NUM_M] = lmx2594regs[112-PLL_NUM_M] & (~0xFFFF);
  285. // Next 16 bits of the numerator
  286. lmx2594regs[112-PLL_NUM_M] = lmx2594regs[112-PLL_NUM_M] | (frac_n & 0xFFFF);
  287. // Clear the upper 16 bits of the register lmx2594regs[PLL_DEN_S]
  288. lmx2594regs[112-PLL_DEN_S] = lmx2594regs[112-PLL_DEN_S] & (~0xFFFF);
  289. // most significant 16 bits of the denominator
  290. lmx2594regs[112-PLL_DEN_S] = lmx2594regs[112-PLL_DEN_S] | (frac_d >> 16);
  291. // Clear the lower 16 bits of the register lmx2594regs[PLL_DEN_M]
  292. lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] & (~0xFFFF);
  293. // Next 16 bits of the denominator
  294. lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] | (frac_d & 0xFFFF);
  295. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  296. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
  297. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  298. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  299. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_VCO;
  300. // Program the FCAL_EN bit
  301. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  302. // Show the all the upper 16 bits of the register lmx2594regs[PLL_N_S]
  303. // Determine which regs are changed and send only those
  304. uint32_t lmx_change_freq_regs[] = {
  305. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
  306. lmx2594regs[112 - VCO_SEL],
  307. lmx2594regs[112 - CAP_CTRL_START],
  308. lmx2594regs[112 - VCO_DACISET],
  309. lmx2594regs[112-MASH_ORDER],
  310. lmx2594regs[112-PFD_DLY_SEL],
  311. lmx2594regs[112-PLL_N_S],
  312. lmx2594regs[112-PLL_N_M],
  313. lmx2594regs[112-PLL_DEN_S],
  314. lmx2594regs[112-PLL_DEN_M],
  315. lmx2594regs[112-PLL_NUM_S],
  316. lmx2594regs[112-PLL_NUM_M],
  317. lmx2594regs[112 - CHDIV],
  318. lmx2594regs[112 - CHDIV_DIV2],
  319. lmx2594regs[112-OUTA_MUX],
  320. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
  321. lmx2594regs[112-FCAL_ADDR]
  322. };
  323. // Create a header for the LMX2594 with the appropriate number of words
  324. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs)/4) << 1) | 1);
  325. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  326. *ptr = LMX_HEADER;
  327. for (int i = 0; i < sizeof(lmx_change_freq_regs)/4; i++) {
  328. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  329. *data_ptr = lmx_change_freq_regs[i];
  330. }
  331. char filename[100];
  332. sprintf(filename, "%f.txt", freq);
  333. FILE * f = fopen(filename, "w");
  334. for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
  335. fprintf(f, "0x%08X\n", lmx2594regs[i]);
  336. }
  337. fclose(f);
  338. printf("File has been written\n");
  339. printf("N_div = %f\n", N_div);
  340. printf("f_vco = %f\n", freq);
  341. printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
  342. printf("N = %d\n", N);
  343. printf("frac_n = %u\n", frac_n);
  344. printf("frac_d = %u\n", frac_d);
  345. }
  346. int lmx_freq_set_main_band_int_mode(void *bar1, double freq, double f_pd) {
  347. double N_div;
  348. printf("f_pd before = %f\n",f_pd);
  349. N_div = freq / f_pd;
  350. uint32_t N = (uint32_t) N_div;
  351. if (freq <= 12500e6) {
  352. if (N < 28){
  353. N= 28;
  354. };
  355. }
  356. else if (freq > 12500e6) {
  357. if (N <32) {
  358. N = 32;
  359. }
  360. };
  361. int vco_core;
  362. double f_coremin;
  363. double f_coremax;
  364. int c_core_min;
  365. int c_core_max;
  366. int a_core_min;
  367. int a_core_max;
  368. uint16_t vco_cap_ctrl_strt;
  369. uint16_t vco_daciset_strt;
  370. // Partial assist for the calibration
  371. //Determine a VCO core and other parameters
  372. if (freq >= 7500e6 && freq <= 8600e6) {
  373. vco_core = 1;
  374. f_coremin = 7500e6;
  375. f_coremax = 8600e6;
  376. c_core_min = 164;
  377. c_core_max = 12;
  378. a_core_min = 299;
  379. a_core_max = 240;
  380. }
  381. else if (freq > 8600e6 && freq < 9800e6) {
  382. vco_core = 2;
  383. f_coremin = 8600e6;
  384. f_coremax = 9800e6;
  385. c_core_min = 165;
  386. c_core_max = 16;
  387. a_core_min = 356;
  388. a_core_max = 247;
  389. }
  390. else if (freq >= 9800e6 && freq <= 10800e6) {
  391. vco_core = 3;
  392. f_coremin = 9800e6;
  393. f_coremax = 10800e6;
  394. c_core_min = 158;
  395. c_core_max = 19;
  396. a_core_min = 324;
  397. a_core_max = 224;
  398. }
  399. else if (freq > 10800e6 && freq <= 12000e6) {
  400. vco_core = 4;
  401. f_coremin = 10800e6;
  402. f_coremax = 12000e6;
  403. c_core_min = 140;
  404. c_core_max = 0;
  405. a_core_min = 383;
  406. a_core_max = 244;
  407. }
  408. else if (freq > 12000e6 && freq <= 12900e6) {
  409. vco_core = 5;
  410. f_coremin = 12000e6;
  411. f_coremax = 12900e6;
  412. c_core_min = 183;
  413. c_core_max = 36;
  414. a_core_min = 205;
  415. a_core_max = 146;
  416. }
  417. else if (freq > 12900e6 && freq <= 13900e6) {
  418. vco_core = 6;
  419. f_coremin = 12900e6;
  420. f_coremax = 13900e6;
  421. c_core_min = 155;
  422. c_core_max = 6;
  423. a_core_min = 242;
  424. a_core_max = 163;
  425. }
  426. else if (freq > 13900e6 && freq <= 15000e6) {
  427. vco_core = 7;
  428. f_coremin = 13900e6;
  429. f_coremax = 15000e6;
  430. c_core_min = 175;
  431. c_core_max = 19;
  432. a_core_min = 323;
  433. a_core_max = 244;
  434. };
  435. if (freq >=11900e6 && freq <=12100e6) {
  436. vco_daciset_strt = 300;
  437. vco_core = 4;
  438. vco_cap_ctrl_strt = 1;
  439. }
  440. vco_cap_ctrl_strt = round(c_core_min - (c_core_min - c_core_max) * (freq - f_coremin) / (f_coremax - f_coremin));
  441. vco_daciset_strt = round(a_core_min + (a_core_min - a_core_max) * (freq - f_coremin) / (f_coremax - f_coremin));
  442. printf("VCO_CORE = %d\n", vco_core);
  443. printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
  444. printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
  445. //Set the VCO_CORE
  446. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
  447. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] | (vco_core << BITP_LMX2594_R20_VCO_SEL);
  448. // Set the VCO_CAP_CTRL
  449. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] & (~BITM_LMX2594_R78_VCO_CAP_CTRL_START);
  450. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] | (vco_cap_ctrl_strt << BITP_LMX2594_R78_VCO_CAP_CTRL_START);
  451. // Set the VCO_DACISET
  452. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] & (~BITM_LMX2594_R17_VCO_DACISET);
  453. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] | (vco_daciset_strt << BITP_LMX2594_R17_VCO_DACISET);
  454. // Set the PF_DLY_SEL
  455. if (freq <= 12500e6) {
  456. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  457. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x1 << BITP_LMX2594_R37_PFD_DLY_SEL);
  458. printf("PFD_DLY_SEL = %d\n", 1);
  459. }
  460. else if (freq > 12500e6) {
  461. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  462. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x2 << BITP_LMX2594_R37_PFD_DLY_SEL);
  463. printf("PFD_DLY_SEL = %d\n", 2);
  464. };
  465. int cal_clk_div;
  466. //SET the FCAL_HPFD_ADJ
  467. if (f_pd <= 100e6) {
  468. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  469. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_LESS100MHZ;
  470. }
  471. else if (f_pd > 100e6 && f_pd <= 150e6) {
  472. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  473. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_100_150MHZ;
  474. }
  475. else if (f_pd > 150e6 && f_pd <= 200e6) {
  476. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  477. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_150_200MHZ;
  478. }
  479. else if (f_pd > 200e6) {
  480. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  481. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_MORE200MHZ;
  482. };
  483. // SET the CAL_CLK_DIV value
  484. if (f_pd <= 200e6 ) {
  485. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  486. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV1;
  487. cal_clk_div = 0;
  488. }
  489. else if (f_pd > 200e6 && f_pd <= 400e6) {
  490. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  491. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV2;
  492. cal_clk_div = 1;
  493. }
  494. else if (f_pd > 400e6 && f_pd < 800e6) {
  495. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  496. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV4;
  497. cal_clk_div = 2;
  498. };
  499. //Calculate the ACAL_CMP_DLY
  500. double Fsmclk = f_pd/(pow(2,cal_clk_div));
  501. uint8_t acal_cmp_dly = (uint8_t) ((uint64_t)round((Fsmclk)/10e6));
  502. //Set the ACAL_CMP_DLY value
  503. lmx2594regs[112-R4_ADDR] = lmx2594regs[112-R4_ADDR] &(~BITM_LMX2594_R4_ACAL_CMP_DLY);
  504. lmx2594regs[112-R4_ADDR] = lmx2594regs[112-R4_ADDR] | (acal_cmp_dly << BITP_LMX2594_R4_ACAL_CMP_DLY);
  505. // SET the N_DIV
  506. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] &(~0xFFFF);
  507. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] | (N >> 16);
  508. //CLear the lower 16 bits of the register
  509. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] & (~0xFFFF);
  510. // Next 16 bits of the register
  511. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] | (N & 0xFFFF);
  512. // Clear the SEG1_EN bit
  513. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  514. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  515. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  516. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_VCO;
  517. // Program the FCAL_EN bit
  518. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_R0_FCAL);
  519. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  520. uint32_t lmx_change_freq_regs[] = {
  521. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
  522. lmx2594regs[112 - VCO_SEL],
  523. lmx2594regs[112 - CAP_CTRL_START],
  524. lmx2594regs[112 - VCO_DACISET],
  525. lmx2594regs[112-PFD_DLY_SEL],
  526. lmx2594regs[112-R4_ADDR],
  527. lmx2594regs[112-R1_ADDR],
  528. lmx2594regs[112-CHDIV_DIV2],
  529. lmx2594regs[112-PLL_N_S],
  530. lmx2594regs[112-PLL_N_M],
  531. lmx2594regs[112 - OUTA_MUX],
  532. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
  533. lmx2594regs[112-FCAL_ADDR]
  534. };
  535. // Create a header for the LMX2594 with the appropriate number of words
  536. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs)/4) << 1) | 1);
  537. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  538. *ptr = LMX_HEADER;
  539. for (int i = 0; i < sizeof(lmx_change_freq_regs)/4; i++) {
  540. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  541. *data_ptr = lmx_change_freq_regs[i];
  542. }
  543. char filename[100];
  544. sprintf(filename, "%f.txt", freq);
  545. FILE * f = fopen(filename, "w");
  546. for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
  547. fprintf(f, "0x%08X\n", lmx2594regs[i]);
  548. }
  549. fclose(f);
  550. printf("N_div = %f\n", N_div);
  551. printf("N = %d\n", N);
  552. printf("f_vco = %f\n", freq);
  553. printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
  554. return 0;
  555. }
  556. int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
  557. if (freq >= 10e6 && freq <= 1000e6) {
  558. lmx_freq = lmx_lower_bond_set(freq, f_pd);
  559. }
  560. else {
  561. lmx_freq = freq;
  562. }
  563. double f_vco = 2 * lmx_freq;
  564. int chan_div = 2;
  565. uint8_t ch_div_reg = 0; // 2
  566. double vco_div = 7.5e9 / lmx_freq;
  567. double N_div;
  568. int vco_core;
  569. double f_coremin;
  570. double f_coremax;
  571. int c_core_min;
  572. int c_core_max;
  573. int a_core_min;
  574. int a_core_max;
  575. uint16_t vco_cap_ctrl_strt;
  576. uint16_t vco_daciset_strt;
  577. // minimum N_div value is 28 and Vco frequency can't be less than 7.5 GHz
  578. if (f_vco < 7.5e9) {
  579. if (vco_div > 2 && vco_div <= 4)
  580. chan_div = 4; // 4
  581. f_vco = lmx_freq * chan_div;
  582. if (vco_div > 4 && vco_div <= 6) {
  583. chan_div = 6; // 6
  584. f_vco = lmx_freq * chan_div;
  585. }
  586. if (vco_div > 6 && vco_div <= 8) {
  587. chan_div = 8; // 8
  588. f_vco = lmx_freq * chan_div;
  589. }
  590. if (vco_div > 8 && vco_div <= 12) {
  591. chan_div = 12; // 12
  592. f_vco = lmx_freq * chan_div;
  593. }
  594. if (vco_div > 12 && vco_div <= 16) {
  595. chan_div = 16; // 16
  596. f_vco = lmx_freq * chan_div;
  597. }
  598. if (vco_div > 16 && vco_div <= 24) {
  599. chan_div = 24; // 24
  600. f_vco = lmx_freq * chan_div;
  601. }
  602. if (vco_div > 24 && vco_div <= 32) {
  603. chan_div = 32; // 32
  604. f_vco = lmx_freq * chan_div;
  605. }
  606. if (vco_div > 32 && vco_div <= 48) {
  607. chan_div = 48; // 48
  608. f_vco = lmx_freq * chan_div;
  609. }
  610. if (vco_div > 48 && vco_div <= 64) {
  611. chan_div = 64; // 64
  612. f_vco = lmx_freq * chan_div;
  613. }
  614. if (vco_div > 64 && vco_div <= 72) {
  615. chan_div = 72; // 72
  616. f_vco = lmx_freq * chan_div;
  617. }
  618. if (vco_div > 72 && vco_div <= 96) {
  619. chan_div = 96; // 96
  620. f_vco = lmx_freq * chan_div;
  621. }
  622. if (vco_div > 96 && vco_div <= 128) {
  623. chan_div = 128; // 128
  624. f_vco = lmx_freq * chan_div;
  625. }
  626. if (vco_div > 128 && vco_div <= 192) {
  627. chan_div = 192; // 192
  628. f_vco = lmx_freq * chan_div;
  629. }
  630. if (vco_div > 192 && vco_div <= 256) {
  631. chan_div = 256; // 256
  632. f_vco = lmx_freq * chan_div;
  633. }
  634. if (vco_div > 256 && vco_div <= 384) {
  635. chan_div = 384; // 384
  636. f_vco = lmx_freq * chan_div;
  637. }
  638. if (vco_div > 384 && vco_div <= 512) {
  639. chan_div = 512; // 512
  640. f_vco = lmx_freq * chan_div;
  641. }
  642. if (vco_div > 512 && vco_div <= 768) {
  643. chan_div = 768; // 768
  644. f_vco = lmx_freq * chan_div;
  645. }
  646. switch (chan_div) {
  647. case 2:
  648. ch_div_reg = 0;
  649. break;
  650. case 4:
  651. ch_div_reg = 1;
  652. break;
  653. case 6:
  654. ch_div_reg = 2;
  655. break;
  656. case 8:
  657. ch_div_reg = 3;
  658. break;
  659. case 12:
  660. ch_div_reg = 4;
  661. break;
  662. case 16:
  663. ch_div_reg = 5;
  664. break;
  665. case 24:
  666. ch_div_reg = 6;
  667. break;
  668. case 32:
  669. ch_div_reg = 7;
  670. break;
  671. case 48:
  672. ch_div_reg = 8;
  673. break;
  674. case 64:
  675. ch_div_reg = 9;
  676. break;
  677. case 72:
  678. ch_div_reg = 10;
  679. break;
  680. case 96:
  681. ch_div_reg = 11;
  682. break;
  683. case 128:
  684. ch_div_reg = 12;
  685. break;
  686. case 192:
  687. ch_div_reg = 13;
  688. break;
  689. case 256:
  690. ch_div_reg = 14;
  691. break;
  692. case 384:
  693. ch_div_reg = 15;
  694. break;
  695. case 512:
  696. ch_div_reg = 16;
  697. break;
  698. case 768:
  699. ch_div_reg = 17;
  700. break;
  701. }
  702. } else {
  703. ch_div_reg = 0;
  704. f_vco = lmx_freq * 2;
  705. }
  706. N_div = f_vco / f_pd;
  707. // divide whole part and fractional part
  708. uint32_t N = (uint32_t) N_div;
  709. uint32_t frac_n = (uint32_t) ((N_div - N) * (4294967295-1));
  710. uint32_t frac_d = 4294967295-1;
  711. // If frac part is 0 then the denominator is 1000 and numerator is 0
  712. if (frac_n == 0) {
  713. frac_n = 0;
  714. frac_d = 1000;
  715. }
  716. // Partial assist for the calibration
  717. //Determine a VCO core and other parameters
  718. if (f_vco >= 7500e6 && f_vco <= 8600e6) {
  719. vco_core = 1;
  720. f_coremin = 7500e6;
  721. f_coremax = 8600e6;
  722. c_core_min = 164;
  723. c_core_max = 12;
  724. a_core_min = 299;
  725. a_core_max = 240;
  726. }
  727. else if (f_vco > 8600e6 && f_vco < 9800e6) {
  728. vco_core = 2;
  729. f_coremin = 8600e6;
  730. f_coremax = 9800e6;
  731. c_core_min = 165;
  732. c_core_max = 16;
  733. a_core_min = 356;
  734. a_core_max = 247;
  735. }
  736. else if (f_vco >= 9800e6 && f_vco <= 10800e6) {
  737. vco_core = 3;
  738. f_coremin = 9800e6;
  739. f_coremax = 10800e6;
  740. c_core_min = 158;
  741. c_core_max = 19;
  742. a_core_min = 324;
  743. a_core_max = 224;
  744. }
  745. else if (f_vco > 10800e6 && f_vco <= 12000e6) {
  746. vco_core = 4;
  747. f_coremin = 10800e6;
  748. f_coremax = 12000e6;
  749. c_core_min = 140;
  750. c_core_max = 0;
  751. a_core_min = 383;
  752. a_core_max = 244;
  753. }
  754. else if (f_vco > 12000e6 && f_vco <= 12900e6) {
  755. vco_core = 5;
  756. f_coremin = 12000e6;
  757. f_coremax = 12900e6;
  758. c_core_min = 183;
  759. c_core_max = 36;
  760. a_core_min = 205;
  761. a_core_max = 146;
  762. }
  763. else if (f_vco > 12900e6 && f_vco <= 13900e6) {
  764. vco_core = 6;
  765. f_coremin = 12900e6;
  766. f_coremax = 13900e6;
  767. c_core_min = 155;
  768. c_core_max = 6;
  769. a_core_min = 242;
  770. a_core_max = 163;
  771. }
  772. else if (f_vco > 13900e6 && f_vco <= 15000e6) {
  773. vco_core = 7;
  774. f_coremin = 13900e6;
  775. f_coremax = 15000e6;
  776. c_core_min = 175;
  777. c_core_max = 19;
  778. a_core_min = 323;
  779. a_core_max = 244;
  780. };
  781. vco_cap_ctrl_strt = round(c_core_min - (c_core_min - c_core_max) * (f_vco - f_coremin) / (f_coremax - f_coremin));
  782. vco_daciset_strt = round(a_core_min + (a_core_min - a_core_max) * (f_vco - f_coremin) / (f_coremax - f_coremin));
  783. if (f_vco >=11900e6 && f_vco <=12100e6) {
  784. vco_daciset_strt = 300;
  785. vco_core = 4;
  786. vco_cap_ctrl_strt = 1;
  787. }
  788. printf("VCO_CORE = %d\n", vco_core);
  789. printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
  790. printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
  791. // Calibration assist
  792. //Set the VCO_CORE
  793. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
  794. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] | (vco_core << BITP_LMX2594_R20_VCO_SEL);
  795. // Set the VCO_CAP_CTRL_START
  796. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] & (~BITM_LMX2594_R78_VCO_CAP_CTRL_START);
  797. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] | (vco_cap_ctrl_strt << BITP_LMX2594_R78_VCO_CAP_CTRL_START);
  798. // Set the VCO_DACISET
  799. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] & (~BITM_LMX2594_R17_VCO_DACISET);
  800. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] | (vco_daciset_strt << BITP_LMX2594_R17_VCO_DACISET);
  801. lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] & (~BITM_LMX2594_R44_MASH_ORDER);
  802. // Set the MASH_ORDER to 3
  803. lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
  804. // Set PF_DLY_SEL to appropriate value
  805. if (f_vco <=10e9){
  806. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  807. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
  808. printf("PFD_DLY_SEL = %d\n", 3);
  809. }
  810. else if (f_vco > 10e9) {
  811. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  812. lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
  813. printf("PFD_DLY_SEL = %d\n", 4);
  814. }
  815. lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] & (~0xFFFF);
  816. lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] | (N >> 16);
  817. //CLear the lower 16 bits of the register
  818. lmx2594regs[112 - PLL_N_M] = lmx2594regs[112 - PLL_N_M] & (~0xFFFF);
  819. // Next 16 bits of the register
  820. lmx2594regs[112 - PLL_N_M] = lmx2594regs[112 - PLL_N_M] | (N & 0xFFFF);
  821. // Clear the upper 16 bits of the register lmx2594regs[PLL_NUM_S]
  822. lmx2594regs[112 - PLL_NUM_S] = lmx2594regs[112 - PLL_NUM_S] & (~0xFFFF);
  823. lmx2594regs[112 - PLL_NUM_S] = lmx2594regs[112 - PLL_NUM_S] | (frac_n >> 16);
  824. // Clear the lower 16 bits of the register lmx2594regs[PLL_NUM_M]
  825. lmx2594regs[112 - PLL_NUM_M] = lmx2594regs[112 - PLL_NUM_M] & (~0xFFFF);
  826. // Next 16 bits of the numerator
  827. lmx2594regs[112 - PLL_NUM_M] = lmx2594regs[112 - PLL_NUM_M] | (frac_n & 0xFFFF);
  828. // Clear the upper 16 bits of the register lmx2594regs[PLL_DEN_S]
  829. lmx2594regs[112 - PLL_DEN_S] = lmx2594regs[112 - PLL_DEN_S] & (~0xFFFF);
  830. // most significant 16 bits of the denominator
  831. lmx2594regs[112 - PLL_DEN_S] = lmx2594regs[112 - PLL_DEN_S] | (frac_d >> 16);
  832. // Clear the lower 16 bits of the register lmx2594regs[PLL_DEN_M]
  833. lmx2594regs[112 - PLL_DEN_M] = lmx2594regs[112 - PLL_DEN_M] & (~0xFFFF);
  834. // Next 16 bits of the denominator
  835. lmx2594regs[112 - PLL_DEN_M] = lmx2594regs[112 - PLL_DEN_M] | (frac_d & 0xFFFF);
  836. // Program the CHDIV value
  837. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
  838. // Set the CHDIV value with the starting position BITP_LMX2594_R75_CHDIV
  839. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] | (ch_div_reg << BITP_LMX2594_R75_CHDIV);
  840. // If the ch_div > 2 then set the SEG1_EN bit
  841. if (chan_div > 2) {
  842. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  843. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] | (ENUM_LMX2594_R31_CHDIV_DIV2_EN);
  844. }
  845. else {
  846. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  847. }
  848. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  849. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  850. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_CH_DIV;
  851. // Program the FCAL_EN bit
  852. lmx2594regs[112 - FCAL_ADDR] = lmx2594regs[112 - FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  853. uint32_t lmx_change_freq_regs[] = {
  854. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
  855. lmx2594regs[112 - VCO_SEL],
  856. lmx2594regs[112 - CAP_CTRL_START],
  857. lmx2594regs[112 - VCO_DACISET],
  858. lmx2594regs[112-MASH_ORDER],
  859. lmx2594regs[112-PFD_DLY_SEL],
  860. lmx2594regs[112 - PLL_N_S],
  861. lmx2594regs[112 - PLL_N_M],
  862. lmx2594regs[112 - PLL_DEN_S],
  863. lmx2594regs[112 - PLL_DEN_M],
  864. lmx2594regs[112 - PLL_NUM_S],
  865. lmx2594regs[112 - PLL_NUM_M],
  866. lmx2594regs[112 - CHDIV],
  867. lmx2594regs[112 - CHDIV_DIV2],
  868. lmx2594regs[112 - OUTA_MUX],
  869. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
  870. lmx2594regs[112 - FCAL_ADDR]
  871. };
  872. // Create a header for the LMX2594 with the appropriate number of words
  873. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
  874. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  875. *ptr = LMX_HEADER;
  876. // Send the data
  877. for (int i = 0; i < sizeof(lmx_change_freq_regs) / 4; i++) {
  878. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  879. *data_ptr = lmx_change_freq_regs[i];
  880. }
  881. char filename[100];
  882. sprintf(filename, "%f.txt", freq);
  883. FILE * f = fopen(filename, "w");
  884. for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
  885. fprintf(f, "0x%08X\n", lmx2594regs[i]);
  886. }
  887. fclose(f);
  888. printf("N_div = %f\n", N_div);
  889. printf("f_vco = %f\n", f_vco);
  890. printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
  891. printf("N = %d\n", N);
  892. printf("frac_n = %u\n", frac_n);
  893. printf("frac_d = %u\n", frac_d);
  894. printf("chan_div = %d\n", chan_div);
  895. printf("chan_div_reg = %d\n", ch_div_reg);
  896. printf("LMX2594 Registers\n");
  897. return 0;
  898. }
  899. int lmx_freq_set_out_of_band_int_mode(void *bar1, double freq, double f_pd) {
  900. if (freq >= 10e6 && freq <= 1000e6) {
  901. lmx_freq = lmx_lower_bond_set(freq, f_pd);
  902. }
  903. else {
  904. lmx_freq = freq;
  905. }
  906. double f_vco = 2 * lmx_freq;
  907. int chan_div = 2;
  908. uint8_t ch_div_reg = 0; // 2
  909. double vco_div = 7.5e9 / lmx_freq;
  910. int vco_core;
  911. double f_coremin;
  912. double f_coremax;
  913. int c_core_min;
  914. int c_core_max;
  915. int a_core_min;
  916. int a_core_max;
  917. uint16_t vco_cap_ctrl_strt;
  918. uint16_t vco_daciset_strt;
  919. // minimum N_div value is 28 and Vco frequency can't be less than 7.5 GHz
  920. if (f_vco < 7.5e9) {
  921. if (vco_div > 2 && vco_div <= 4)
  922. chan_div = 4; // 4
  923. f_vco = lmx_freq * chan_div;
  924. if (vco_div > 4 && vco_div <= 6) {
  925. chan_div = 6; // 6
  926. f_vco = lmx_freq * chan_div;
  927. }
  928. if (vco_div > 6 && vco_div <= 8) {
  929. chan_div = 8; // 8
  930. f_vco = lmx_freq * chan_div;
  931. }
  932. if (vco_div > 8 && vco_div <= 12) {
  933. chan_div = 12; // 12
  934. f_vco = lmx_freq * chan_div;
  935. }
  936. if (vco_div > 12 && vco_div <= 16) {
  937. chan_div = 16; // 16
  938. f_vco = lmx_freq * chan_div;
  939. }
  940. if (vco_div > 16 && vco_div <= 24) {
  941. chan_div = 24; // 24
  942. f_vco = lmx_freq * chan_div;
  943. }
  944. if (vco_div > 24 && vco_div <= 32) {
  945. chan_div = 32; // 32
  946. f_vco = lmx_freq * chan_div;
  947. }
  948. if (vco_div > 32 && vco_div <= 48) {
  949. chan_div = 48; // 48
  950. f_vco = lmx_freq * chan_div;
  951. }
  952. if (vco_div > 48 && vco_div <= 64) {
  953. chan_div = 64; // 64
  954. f_vco = lmx_freq * chan_div;
  955. }
  956. if (vco_div > 64 && vco_div <= 72) {
  957. chan_div = 72; // 72
  958. f_vco = lmx_freq * chan_div;
  959. }
  960. if (vco_div > 72 && vco_div <= 96) {
  961. chan_div = 96; // 96
  962. f_vco = lmx_freq * chan_div;
  963. }
  964. if (vco_div > 96 && vco_div <= 128) {
  965. chan_div = 128; // 128
  966. f_vco = lmx_freq * chan_div;
  967. }
  968. if (vco_div > 128 && vco_div <= 192) {
  969. chan_div = 192; // 192
  970. f_vco = lmx_freq * chan_div;
  971. }
  972. if (vco_div > 192 && vco_div <= 256) {
  973. chan_div = 256; // 256
  974. f_vco = lmx_freq * chan_div;
  975. }
  976. if (vco_div > 256 && vco_div <= 384) {
  977. chan_div = 384; // 384
  978. f_vco = lmx_freq * chan_div;
  979. }
  980. if (vco_div > 384 && vco_div <= 512) {
  981. chan_div = 512; // 512
  982. f_vco = lmx_freq * chan_div;
  983. }
  984. if (vco_div > 512 && vco_div <= 768) {
  985. chan_div = 768; // 768
  986. f_vco = lmx_freq * chan_div;
  987. }
  988. switch (chan_div) {
  989. case 2:
  990. ch_div_reg = 0;
  991. break;
  992. case 4:
  993. ch_div_reg = 1;
  994. break;
  995. case 6:
  996. ch_div_reg = 2;
  997. break;
  998. case 8:
  999. ch_div_reg = 3;
  1000. break;
  1001. case 12:
  1002. ch_div_reg = 4;
  1003. break;
  1004. case 16:
  1005. ch_div_reg = 5;
  1006. break;
  1007. case 24:
  1008. ch_div_reg = 6;
  1009. break;
  1010. case 32:
  1011. ch_div_reg = 7;
  1012. break;
  1013. case 48:
  1014. ch_div_reg = 8;
  1015. break;
  1016. case 64:
  1017. ch_div_reg = 9;
  1018. break;
  1019. case 72:
  1020. ch_div_reg = 10;
  1021. break;
  1022. case 96:
  1023. ch_div_reg = 11;
  1024. break;
  1025. case 128:
  1026. ch_div_reg = 12;
  1027. break;
  1028. case 192:
  1029. ch_div_reg = 13;
  1030. break;
  1031. case 256:
  1032. ch_div_reg = 14;
  1033. break;
  1034. case 384:
  1035. ch_div_reg = 15;
  1036. break;
  1037. case 512:
  1038. ch_div_reg = 16;
  1039. break;
  1040. case 768:
  1041. ch_div_reg = 17;
  1042. break;
  1043. }
  1044. } else {
  1045. ch_div_reg = 0;
  1046. f_vco = lmx_freq * 2;
  1047. }
  1048. double N_div = f_vco / f_pd;
  1049. uint32_t N = (uint32_t) N_div;
  1050. if (f_vco <= 12500e6) {
  1051. if (N < 28){
  1052. N= 28;
  1053. };
  1054. }
  1055. else if (f_vco > 12500e6) {
  1056. if (N <32) {
  1057. N = 32;
  1058. }
  1059. };
  1060. // Partial assist for the calibration
  1061. //Determine a VCO core and other parameters
  1062. if (f_vco >= 7500e6 && f_vco <= 8600e6) {
  1063. vco_core = 1;
  1064. f_coremin = 7500e6;
  1065. f_coremax = 8600e6;
  1066. c_core_min = 164;
  1067. c_core_max = 12;
  1068. a_core_min = 299;
  1069. a_core_max = 240;
  1070. }
  1071. else if (f_vco > 8600e6 && f_vco < 9800e6) {
  1072. vco_core = 2;
  1073. f_coremin = 8600e6;
  1074. f_coremax = 9800e6;
  1075. c_core_min = 165;
  1076. c_core_max = 16;
  1077. a_core_min = 356;
  1078. a_core_max = 247;
  1079. }
  1080. else if (f_vco >= 9800e6 && f_vco <= 10800e6) {
  1081. vco_core = 3;
  1082. f_coremin = 9800e6;
  1083. f_coremax = 10800e6;
  1084. c_core_min = 158;
  1085. c_core_max = 19;
  1086. a_core_min = 324;
  1087. a_core_max = 224;
  1088. }
  1089. else if (f_vco > 10800e6 && f_vco <= 12000e6) {
  1090. vco_core = 4;
  1091. f_coremin = 10800e6;
  1092. f_coremax = 12000e6;
  1093. c_core_min = 140;
  1094. c_core_max = 0;
  1095. a_core_min = 383;
  1096. a_core_max = 244;
  1097. }
  1098. else if (f_vco > 12000e6 && f_vco <= 12900e6) {
  1099. vco_core = 5;
  1100. f_coremin = 12000e6;
  1101. f_coremax = 12900e6;
  1102. c_core_min = 183;
  1103. c_core_max = 36;
  1104. a_core_min = 205;
  1105. a_core_max = 146;
  1106. }
  1107. else if (f_vco > 12900e6 && f_vco <= 13900e6) {
  1108. vco_core = 6;
  1109. f_coremin = 12900e6;
  1110. f_coremax = 13900e6;
  1111. c_core_min = 155;
  1112. c_core_max = 6;
  1113. a_core_min = 242;
  1114. a_core_max = 163;
  1115. }
  1116. else if (f_vco > 13900e6 && f_vco <= 15000e6) {
  1117. vco_core = 7;
  1118. f_coremin = 13900e6;
  1119. f_coremax = 15000e6;
  1120. c_core_min = 175;
  1121. c_core_max = 19;
  1122. a_core_min = 323;
  1123. a_core_max = 244;
  1124. };
  1125. vco_cap_ctrl_strt = round(c_core_min - (c_core_min - c_core_max) * (f_vco - f_coremin) / (f_coremax - f_coremin));
  1126. vco_daciset_strt = round(a_core_min + (a_core_min - a_core_max) * (f_vco - f_coremin) / (f_coremax - f_coremin));
  1127. if (f_vco >=11900e6 && f_vco <=12100e6) {
  1128. vco_daciset_strt = 300;
  1129. vco_core = 4;
  1130. vco_cap_ctrl_strt = 1;
  1131. }
  1132. printf("VCO_CORE = %d\n", vco_core);
  1133. printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
  1134. printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
  1135. // Calibration assist
  1136. //Set the VCO_CORE
  1137. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
  1138. lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] | (vco_core << BITP_LMX2594_R20_VCO_SEL);
  1139. // Set the VCO_CAP_CTRL_START
  1140. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] & (~BITM_LMX2594_R78_VCO_CAP_CTRL_START);
  1141. lmx2594regs[112 - CAP_CTRL_START] = lmx2594regs[112 - CAP_CTRL_START] | (vco_cap_ctrl_strt << BITP_LMX2594_R78_VCO_CAP_CTRL_START);
  1142. // Set the VCO_DACISET
  1143. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] & (~BITM_LMX2594_R17_VCO_DACISET);
  1144. lmx2594regs[112 - VCO_DACISET] = lmx2594regs[112 - VCO_DACISET] | (vco_daciset_strt << BITP_LMX2594_R17_VCO_DACISET);
  1145. // Set the PFD_DLY_SEL to appropriate value
  1146. if (freq <= 12500e6) {
  1147. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  1148. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x1 << BITP_LMX2594_R37_PFD_DLY_SEL);
  1149. printf("PFD_DLY_SEL = %d\n", 1);
  1150. }
  1151. else if (freq > 12500e6) {
  1152. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
  1153. lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x2 << BITP_LMX2594_R37_PFD_DLY_SEL);
  1154. printf("PFD_DLY_SEL = %d\n", 2);
  1155. }
  1156. if (f_pd <= 100e6) {
  1157. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  1158. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_LESS100MHZ;
  1159. }
  1160. else if (f_pd > 100e6 && f_pd <= 150e6) {
  1161. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  1162. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_100_150MHZ;
  1163. }
  1164. else if (f_pd > 150e6 && f_pd <= 200e6) {
  1165. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  1166. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_150_200MHZ;
  1167. }
  1168. else if (f_pd > 200e6) {
  1169. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
  1170. lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_MORE200MHZ;
  1171. };
  1172. // SET the CAL_CLK_DIV value
  1173. int cal_clk_div;
  1174. if (f_pd <= 200e6 ) {
  1175. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  1176. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV1;
  1177. cal_clk_div =0;
  1178. }
  1179. else if (f_pd > 200e6 && f_pd <= 400e6) {
  1180. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  1181. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV2;
  1182. cal_clk_div =1;
  1183. }
  1184. else if (f_pd > 400e6 && f_pd < 800e6) {
  1185. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
  1186. lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] | ENUM_LMX2594_R1_CAL_CLK_DIV4;
  1187. cal_clk_div = 2;
  1188. };
  1189. //Calculate the ACAL_CMP_DLY
  1190. double Fsmclk = f_pd/(pow(2,cal_clk_div));
  1191. uint8_t acal_cmp_dly = (uint8_t) ((uint64_t)round((Fsmclk)/10e6));;
  1192. //Set the ACAL_CMP_DLY value
  1193. lmx2594regs[112-R4_ADDR] = lmx2594regs[112-R4_ADDR] &(~BITM_LMX2594_R4_ACAL_CMP_DLY);
  1194. lmx2594regs[112-R4_ADDR] = lmx2594regs[112-R4_ADDR] | (acal_cmp_dly << BITP_LMX2594_R4_ACAL_CMP_DLY);
  1195. // Set the N value
  1196. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] &(~0xFFFF);
  1197. lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] | (N >> 16);
  1198. //CLear the lower 16 bits of the register
  1199. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] & (~0xFFFF);
  1200. // Next 16 bits of the register
  1201. lmx2594regs[112-PLL_N_M] = lmx2594regs[112-PLL_N_M] | (N & 0xFFFF);
  1202. // Program the CHDIV value
  1203. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
  1204. // Set the CHDIV value with the starting position BITP_LMX2594_R75_CHDIV
  1205. lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] | (ch_div_reg << BITP_LMX2594_R75_CHDIV);
  1206. // If the ch_div > 2 then set the SEG1_EN bit
  1207. if (chan_div > 2) {
  1208. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  1209. lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] | (ENUM_LMX2594_R31_CHDIV_DIV2_EN);
  1210. }
  1211. else {
  1212. lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
  1213. }
  1214. // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
  1215. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
  1216. lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_CH_DIV;
  1217. // Program the FCAL_EN bit
  1218. lmx2594regs[112 - FCAL_ADDR] = lmx2594regs[112 - FCAL_ADDR] & (~LMX2594_R0_FCAL_EN);
  1219. lmx2594regs[112 - FCAL_ADDR] = lmx2594regs[112 - FCAL_ADDR] | (LMX2594_R0_FCAL_EN);
  1220. uint32_t lmx_change_freq_regs []={
  1221. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_TRISTATE,
  1222. lmx2594regs[112 - VCO_SEL],
  1223. lmx2594regs[112 - CAP_CTRL_START],
  1224. lmx2594regs[112 - VCO_DACISET],
  1225. lmx2594regs[112-PFD_DLY_SEL],
  1226. lmx2594regs[112-R4_ADDR],
  1227. lmx2594regs[112-R1_ADDR],
  1228. lmx2594regs[112 - PLL_N_S],
  1229. lmx2594regs[112 - PLL_N_M],
  1230. lmx2594regs[112 - CHDIV],
  1231. lmx2594regs[112 - CHDIV_DIV2],
  1232. lmx2594regs[112 - OUTA_MUX],
  1233. lmx2594regs[112-CPG_REG] = (lmx2594regs[112-CPG_REG] & (~BITM_LMX2594_R14_CPG)) | ENUM_LMX2594_R14_CPG_15ma,
  1234. lmx2594regs[112 - FCAL_ADDR]
  1235. };
  1236. // Create a header for the LMX2594 with the appropriate number of words
  1237. uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
  1238. uint32_t *ptr = bar1 + LMX_BASE_ADDR;
  1239. *ptr = LMX_HEADER;
  1240. // Send the data
  1241. for (int i = 0; i < sizeof(lmx_change_freq_regs) / 4; i++) {
  1242. uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
  1243. *data_ptr = lmx_change_freq_regs[i];
  1244. }
  1245. char filename[100];
  1246. sprintf(filename, "%f.txt", freq);
  1247. FILE * f = fopen(filename, "w");
  1248. for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
  1249. fprintf(f, "0x%08X\n", lmx2594regs[i]);
  1250. }
  1251. fclose(f);
  1252. printf("N_div = %f\n", N_div);
  1253. printf("f_vco = %f\n", f_vco);
  1254. printf("N = %d\n", N);
  1255. printf("chan_div = %d\n", chan_div);
  1256. printf("chan_div_reg = %d\n", ch_div_reg);
  1257. return 0;
  1258. }
  1259. double lmx_lower_bond_set (double freq, double f_pd) {
  1260. double f_max2870 = 4e9;
  1261. double lmx_req_freq = f_max2870-freq; // 4 GHz - freq
  1262. return lmx_req_freq;
  1263. }
  1264. int lmx_freq_set(void *bar1, double freq,double f_pd) {
  1265. // double f_pd = 175e6;
  1266. double N_div = 0;
  1267. if (freq < 10e6 || freq > 15e9) {
  1268. printf("Frequency range is 10 MHz to 15 GHz\n");
  1269. return -1;
  1270. }
  1271. // if the frequency is in the main band - 7.5 GHz to 15 GHz
  1272. if (freq >= 7.5e9 && freq <= 15e9) {
  1273. // lmx_freq_set_main_band(bar1, freq, f_pd);
  1274. lmx_freq_set_main_band_int_mode(bar1, freq, f_pd);
  1275. }
  1276. else if (freq < 7.5e9) {
  1277. // lmx_freq_set_out_of_band(bar1, freq, f_pd);
  1278. lmx_freq_set_out_of_band_int_mode(bar1, freq, f_pd);
  1279. }
  1280. // Switch the keys
  1281. key_switch(bar1, freq,lmx_freq);
  1282. return 0;
  1283. }
  1284. uint32_t lmx_ld_status(void *bar1) {
  1285. uint32_t *read_ptr = (uint32_t *)(bar1 + LMX_LD_STATUS_ADDR);
  1286. uint32_t read_value = *read_ptr;
  1287. return read_value;
  1288. }