Advertisement
Guest User

HH's C function displaying gr-baz tuning ranges

a guest
May 26th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #define DEFAULT_CRYSTAL_FREQUENCY 28800000
  2.  
  3. // Osmocom
  4. #define FREQ_USE_THREE_PHASE_BELOW 350000000
  5. #define _GR_BAZ_VCO_BUG_ 0
  6.  
  7. // Gr-Baz
  8. //#define FREQ_USE_THREE_PHASE_BELOW 300000000
  9. //#define _GR_BAZ_VCO_BUG_ 1
  10.  
  11. void dump_pll_valid_range()
  12. {
  13.     uint32_t fosc = DEFAULT_CRYSTAL_FREQUENCY;
  14.     int i=0;
  15.     int three_phase = 0;
  16.     for (three_phase = 0; three_phase < 2; three_phase ++)
  17.     {
  18.     fprintf(stderr,
  19.         "%s phase.\n",
  20.         three_phase ? "Three (3)" : "Two (2)");
  21.    
  22.     for (i=0; i< ARRAY_SIZE(vco_r_table_3ph);i++)
  23.     {
  24.         int r = vco_r_table_3ph[i];
  25.         if (!three_phase)
  26.         r = r / 2;
  27.  
  28.         uint64_t fvco_min = E4K_FVCO_MIN / r;
  29.         uint64_t fvco_max = E4K_FVCO_MAX / r;
  30.  
  31.         if (three_phase && fvco_max >= FREQ_USE_THREE_PHASE_BELOW)
  32.         {
  33.         fvco_max = FREQ_USE_THREE_PHASE_BELOW - 1;
  34.         }
  35.  
  36.         if (!three_phase && fvco_min < FREQ_USE_THREE_PHASE_BELOW)
  37.         {
  38.         fvco_min = FREQ_USE_THREE_PHASE_BELOW;
  39.         }
  40.  
  41.         if (!three_phase && fvco_max < FREQ_USE_THREE_PHASE_BELOW)
  42.         {
  43.         /* Skip this entire R value, falling below the cut-off,
  44.          * performed the output for this frequency range
  45.          * when three_phase = 1 */
  46.         continue;
  47.         }
  48.  
  49.  
  50.         uint32_t z = fvco_min / fosc;
  51.  
  52.         if (!is_z_valid(z))
  53.         {
  54.         fprintf(stderr, "Range (r =%3d) unavailable, z too high (%u)\n", r, z);
  55.         continue;
  56.         }
  57.  
  58. #if _GR_BAZ_VCO_BUG_
  59.  
  60.         uint64_t fvco_z = z * fosc;
  61.  
  62.         uint64_t remainder = fvco_min - fvco_z;
  63.  
  64.         if (remainder)
  65.         {
  66.         if (!is_z_valid(z+1))
  67.         {
  68.             fprintf(stderr, "Range (r =%3d) empty, z+1 too high (%u)+1\n", r, z);
  69.             continue;
  70.         }
  71.    
  72.  
  73.         fvco_min = (z + 1) * fosc;
  74.         }
  75. #endif
  76.  
  77.         if (three_phase && fvco_min >= FREQ_USE_THREE_PHASE_BELOW)
  78.         {
  79.         /* Try next R value. */
  80.         continue;
  81.         }
  82.  
  83.        
  84.         fprintf(stderr,
  85.             "r =%3d: %20llu..%llu\n",
  86.             r,
  87.             fvco_min,
  88.             fvco_max);
  89.     }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement