Jelajahi Sumber

Рефакторинг

Anatoliy Chigirinskiy 1 tahun lalu
induk
melakukan
9da7ee4d2c
2 mengubah file dengan 24 tambahan dan 54 penghapusan
  1. 23 53
      Devices/lmx2594.c
  2. 1 1
      Devices/tmsgheaders.h

+ 23 - 53
Devices/lmx2594.c

@@ -122,7 +122,6 @@ uint32_t lmx2594regs[LMX_COUNT] = {
         0x00251C
 };
 
-
 void auto_cal(void *bar1) {
     lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_R0_FCAL);
     lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | LMX2594_R0_FCAL_EN;
@@ -148,7 +147,6 @@ void lmx2594_init(void *bar1) {
     *ptr = InitLMX2594Header;
     // Init data
     for (int i = 0; i < LMX_COUNT; i++) {
-        uint32_t *ptr = bar1 + LMX_BASE_ADDR;
         *ptr = lmx2594regs[i];
     }
     usleep(10);
@@ -166,7 +164,7 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
      if (lmx_freq <= 12500e6) {
         if (N < 28){
             N= 28;
-        };
+        }
     }
     else if (lmx_freq > 12500e6) {
         if (N <32) {
@@ -258,11 +256,6 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
     }
     vco_cap_ctrl_strt = round(c_core_min - (c_core_min - c_core_max) * (lmx_freq - f_coremin) / (f_coremax - f_coremin));
     vco_daciset_strt = round(a_core_min + (a_core_min - a_core_max) * (lmx_freq - f_coremin) / (f_coremax - f_coremin));
-    
-    // printf("VCO_CORE = %d\n", vco_core);
-    // printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
-    // printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
-
     //Set the VCO_CORE 
     lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
     lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] | (vco_core << BITP_LMX2594_R20_VCO_SEL);
@@ -277,12 +270,10 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
     if (lmx_freq <= 12500e6) {
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x1 << BITP_LMX2594_R37_PFD_DLY_SEL);
-        printf("PFD_DLY_SEL = %d\n", 1);
     }
     else if (lmx_freq > 12500e6) {
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
         lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x2 << BITP_LMX2594_R37_PFD_DLY_SEL);
-        printf("PFD_DLY_SEL = %d\n", 2);
     };
     int cal_clk_div;
     //SET the FCAL_HPFD_ADJ
@@ -301,7 +292,7 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
     else if (f_pd > 200e6) {
         lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_RO_FCAL_HPFD_ADJ);
         lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] | ENUM_LMX2594_R0_FCAL_HPFD_ADJ_MORE200MHZ;
-    };
+    }
     // SET the CAL_CLK_DIV value 
     if (f_pd <= 200e6 ) {
         lmx2594regs[112-R1_ADDR] = lmx2594regs[112-R1_ADDR] & (~BITM_LMX2594_R1_CAL_CLK_DIV);
@@ -334,7 +325,7 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
     // Clear the SEG1_EN bit
     lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
     // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
-    lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
+    // Removed unnecessary commented-out LMX_HEADER definition
     lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_VCO;
        // Program the FCAL_EN bit
     lmx2594regs[112-FCAL_ADDR] = lmx2594regs[112-FCAL_ADDR] & (~BITM_LMX2594_R0_FCAL);   
@@ -363,21 +354,7 @@ int lmx_freq_set_main_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
         uint32_t *data_ptr = bar1 + LMX_BASE_ADDR;
         *data_ptr = lmx_change_freq_regs[i];
     }
-    // char filename[100];
-    // sprintf(filename, "%f.txt", lmx_freq);
-    // FILE * f = fopen(filename, "w");
-    // for (int i = 0; i < sizeof(lmx2594regs) / 4; i++) {
-    //     fprintf(f, "0x%08X\n", lmx2594regs[i]);
-    // }
-    // fclose(f);
-
-    // printf("N_div = %f\n", N_div);
-    // printf("N = %d\n", N);
-    // printf("f_vco = %f\n", lmx_freq);
-    // printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
-
     return 0;
-
 }
 
 int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd) {
@@ -399,70 +376,71 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd)
 
     // minimum N_div value is 28 and Vco frequency can't be less than 7.5 GHz
     if (f_vco < 7.5e9) {
-        if (vco_div > 2 && vco_div <= 4)
+        if (vco_div > 2 && vco_div <= 4) {
             chan_div = 4;  // 4
             f_vco = lmx_freq * chan_div;
-        if (vco_div > 4 && vco_div <= 6) {
+        }
+        else if (vco_div > 4 && vco_div <= 6) {
             chan_div = 6;  // 6
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 6 && vco_div <= 8) {
+        else if (vco_div > 6 && vco_div <= 8) {
             chan_div = 8;  // 8
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 8 && vco_div <= 12) {
+        else if (vco_div > 8 && vco_div <= 12) {
             chan_div = 12;  // 12
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 12 && vco_div <= 16) {
+        else if (vco_div > 12 && vco_div <= 16) {
             chan_div = 16;  // 16
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 16 && vco_div <= 24) {
+        else if (vco_div > 16 && vco_div <= 24) {
             chan_div = 24;  // 24
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 24 && vco_div <= 32) {
+        else if (vco_div > 24 && vco_div <= 32) {
             chan_div = 32;  // 32
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 32 && vco_div <= 48) {
+        else if (vco_div > 32 && vco_div <= 48) {
             chan_div = 48;  // 48
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 48 && vco_div <= 64) {
+        else if (vco_div > 48 && vco_div <= 64) {
             chan_div = 64;  // 64
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 64 && vco_div <= 72) {
+        else if (vco_div > 64 && vco_div <= 72) {
             chan_div = 72;  // 72
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 72 && vco_div <= 96) {
+        else if (vco_div > 72 && vco_div <= 96) {
             chan_div = 96;  // 96
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 96 && vco_div <= 128) {
+        else if (vco_div > 96 && vco_div <= 128) {
             chan_div = 128;  // 128
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 128 && vco_div <= 192) {
+        else if (vco_div > 128 && vco_div <= 192) {
             chan_div = 192;  // 192
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 192 && vco_div <= 256) {
+        else if (vco_div > 192 && vco_div <= 256) {
             chan_div = 256;  // 256
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 256 && vco_div <= 384) {
+        else if (vco_div > 256 && vco_div <= 384) {
             chan_div = 384;  // 384
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 384 && vco_div <= 512) {
+        else if (vco_div > 384 && vco_div <= 512) {
             chan_div = 512;  // 512
             f_vco = lmx_freq * chan_div;
         }
-        if (vco_div > 512 && vco_div <= 768) {
+        else if (vco_div > 512 && vco_div <= 768) {
             chan_div = 768;  // 768
             f_vco = lmx_freq * chan_div;
         }
@@ -522,7 +500,8 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd)
                 ch_div_reg = 17;
                 break;
         }
-    } else {
+    }
+    else {
         ch_div_reg = 0;
         f_vco = lmx_freq * 2;
     }
@@ -614,10 +593,6 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd)
         vco_core = 4;
         vco_cap_ctrl_strt = 1;
     }
-    //  printf("VCO_CORE = %d\n", vco_core);
-    //  printf("VCO_CAP_CTRL_STR = %d\n", vco_cap_ctrl_strt);
-    //  printf("VCO_DACISET_STR = %d\n", vco_daciset_strt);
-
     // Calibration assist 
     //Set the VCO_CORE 
     lmx2594regs[112 - VCO_SEL] = lmx2594regs[112 - VCO_SEL] & (~BITM_LMX2594_R20_VCO_SEL);
@@ -721,8 +696,6 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd)
         lmx2594regs[112 - FCAL_ADDR]
     };
 
-    // Create a header for the LMX2594 with the appropriate number of words
-    // uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
     // Create a header for the LMX2594 with the appropriate number of words MOSI 4
     uint32_t LMX_HEADER = ((0x1<< 23) | ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 1);
     uint32_t *ptr = bar1 + LMX_BASE_ADDR;
@@ -747,7 +720,6 @@ int lmx_freq_set_out_of_band_int_mode(void *bar1, double lmx_freq, double f_pd)
     return 0;
 }
 
-
 double lmx_lower_bond_set (double freq, double f_pd) {
     double f_max2870 = 4e9;
 
@@ -774,9 +746,7 @@ double lmx_get_freq(double freq) {
     }
 }
 
-
 int lmx_freq_set(void *bar1, double freq,double f_pd) {
-
     // Set the 4 Mosi mode
     usleep(1);
     uint32_t cfg_reg = get_cfg_reg();

+ 1 - 1
Devices/tmsgheaders.h

@@ -289,7 +289,7 @@
 // Macros to set register parameter
 #define SET_REGISTER_PARAM( REGISTER, BITM, BITP, PARAMETER )\
 			REGISTER &= ~BITM;\
-			REGISTER |= (PARAMETER << BITP);
+			REGISTER |= PARAMETER;
 
 #define     CFG_REG_ADDR            0x08