Skip to content

Commit a56adfd

Browse files
committed
Unified calibration for AirSpy NOS R0/R2 and AirSpy Mini (do not use anymore SI5351C for calibration)
1 parent ca23852 commit a56adfd

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

common/airspy_calib.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,15 @@ extern "C"
2929

3030
#define AIRSPY_FLASH_CALIB_OFFSET (0x20000) /* After 128KB (Reserved for Firmware + 64KB Spare) */
3131
#define AIRSPY_FLASH_CALIB_HEADER (0xCA1B0001)
32-
#define AIRSPY_FLASH_CALIB_SI5351C_REG_VAL_MAX (32)
3332

3433
/* For each configuration the index corresponds to uint32_t */
3534
typedef struct
3635
{
3736
uint32_t header; /* Shall be equal to AIRSPY_FLASH_CALIB_HEADER */
3837
uint32_t timestamp; /* Epoch Unix Time Stamp */
3938
int32_t correction_ppb;
40-
/* SI5351C 8bits reg/val pairs until both reg/val = 0 (end of config) see airspy_calib_si5351c_reg_val_t */
4139
} airspy_calib_t;
4240

43-
typedef struct
44-
{
45-
uint8_t reg; /* Register Number */
46-
uint8_t val; /* Value */
47-
} airspy_calib_si5351c_reg_val_t;
48-
4941
#ifdef __cplusplus
5042
}
5143
#endif

common/airspy_core.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/*
337345
Configure PLL1 to min speed (48MHz) => see cpu_clock_pll1_low_speed() .
338346
Configure 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

Comments
 (0)