@@ -333,6 +333,14 @@ void sys_clock_samplerate(const airspy_sys_samplerate_t* const pt_airspy_sys_sam
333333 }
334334}
335335
336+ /* Return corrected xtal_freq */
337+ uint32_t sys_calib_r820t (uint32_t xtal_freq , int32_t correction_ppb )
338+ {
339+ const int invppb = 1000000000 ;
340+ xtal_freq += ((int64_t )xtal_freq * (int64_t )correction_ppb + invppb / 2 ) / invppb ;
341+ return xtal_freq ;
342+ }
343+
336344/*
337345Configure PLL1 to min speed (48MHz) => see cpu_clock_pll1_low_speed() .
338346Configure PLL0USB @480MHz for USB0.
@@ -348,7 +356,6 @@ void sys_clock_init(void)
348356 uint16_t nb_struct_u16 ;
349357 airspy_calib_t airspy_calib = { 0 };
350358 airspy_calib_t * airspy_calib_flash ;
351- airspy_calib_si5351c_reg_val_t * airspy_calib_flash_data_si5351c ;
352359
353360 /* After boot the CPU runs at 96 MHz */
354361 /* cpu runs from: IRC (12MHz) >> PLL M = 24, FCCO @ 288 MHz direct mode >> IDIVC = 4 >> 96 MHz */
@@ -468,26 +475,14 @@ void sys_clock_init(void)
468475 /* CLKIN Loss Of Signal (LOS) ? */
469476 if (si5351c_read [1 ] == SI5351C_REG0_CLKIN_LOS )
470477 {
471- /* Check calibration */
478+ /* Apply SI5351C configuration */
479+ si5351c_airspy_config (& airspy_conf -> si5351c_config [AIRSPY_SI5351C_CONFIG_XTAL ]);
480+
481+ /* Check calibration is valid / enabled */
472482 if (airspy_calib .header == AIRSPY_FLASH_CALIB_HEADER )
473483 {
474- int i ;
475- uint8_t reg ;
476- uint8_t val ;
477-
478- airspy_calib_flash_data_si5351c = (airspy_calib_si5351c_reg_val_t * )((ROMFLASH_BASE_ADDR + AIRSPY_FLASH_CALIB_OFFSET ) + sizeof (airspy_calib_t ));
479- for (i = 0 ; i < AIRSPY_FLASH_CALIB_SI5351C_REG_VAL_MAX ; i ++ )
480- {
481- reg = airspy_calib_flash_data_si5351c [i ].reg ;
482- val = airspy_calib_flash_data_si5351c [i ].val ;
483- if ( (reg == 0 ) && (val == 0 ) )
484- break ;
485-
486- airspy_conf -> si5351c_config [AIRSPY_SI5351C_CONFIG_XTAL ].conf [reg ] = val ;
487- }
484+ airspy_conf -> r820t_conf_rw .xtal_freq = sys_calib_r820t (airspy_conf -> r820t_conf_rw .xtal_freq , airspy_calib .correction_ppb );
488485 }
489- /* Apply SI5351C configuration */
490- si5351c_airspy_config (& airspy_conf -> si5351c_config [AIRSPY_SI5351C_CONFIG_XTAL ]);
491486 }else
492487 {
493488 si5351c_airspy_config (& airspy_conf -> si5351c_config [AIRSPY_SI5351C_CONFIG_CLKIN ]);
@@ -503,11 +498,10 @@ void sys_clock_init(void)
503498 si5351c_read [3 ] = si5351c_read_single (0 );
504499 }else
505500 {
506- /* Check calibration */
501+ /* Check calibration is valid / enabled */
507502 if (airspy_calib .header == AIRSPY_FLASH_CALIB_HEADER )
508503 {
509- const int invppb = 1000000000 ;
510- airspy_conf -> r820t_conf_rw .xtal_freq += ((int64_t )airspy_conf -> r820t_conf_rw .xtal_freq * (int64_t )airspy_calib .correction_ppb + invppb / 2 ) / invppb ;
504+ airspy_conf -> r820t_conf_rw .xtal_freq = sys_calib_r820t (airspy_conf -> r820t_conf_rw .xtal_freq , airspy_calib .correction_ppb );
511505 }
512506 }
513507
0 commit comments