@@ -514,37 +514,42 @@ void pinI2C2Task(void *pvParameters)
514514
515515void beginTCXO (TwoWire *i2cBus)
516516{
517- if (i2cBus == nullptr )
517+ if (! i2cBus)
518518 reportFatalError (" Illegal TCXO i2cBus" );
519519
520- if (!myTCXO.begin (*i2cBus, SFE_GNSSDO_OSC_SIT5358)) // Initialize the SiT5358
521- return ;
522-
523- myTCXO.setBaseFrequencyHz (10000000.0 ); // Pass the oscillator base frequency into the driver
524-
525- systemPrint (" TCXO base frequency set to " );
526- systemPrint (myTCXO.getBaseFrequencyHz ());
527- systemPrintln (" Hz" );
528-
529- myTCXO.setPullRangeControl (SiT5358_PULL_RANGE_6ppm25); // Set the pull range control to 6.25ppm
530-
531- systemPrint (" TCXO pull range control set to " );
532- systemPrintln (myTCXO.getPullRangeControlText (myTCXO.getPullRangeControl ()));
520+ // In order of priority: use STP3593LF or SiT5811 if present
521+ if (presentSTP3593LF)
522+ {
523+ myTCXO = (GNSSDO_TCXO *) new GNSSDO_STP3593LF ();
533524
534- myTCXO.setMaxFrequencyChangePPB (3.0 ); // Set the maximum frequency change in PPB
525+ if (!myTCXO->begin (*i2cBus, SFE_GNSSDO_OSC_STP3593LF))
526+ return ;
527+
528+ systemPrintln (" Using STP3593LF OCXO" );
529+ }
530+ else if (presentSIT5811)
531+ {
532+ myTCXO = (GNSSDO_TCXO *) new GNSSDO_SIT5811 ();
535533
536- systemPrint (" TCXO maximum frequency change set to " );
537- systemPrint (myTCXO.getMaxFrequencyChangePPB ());
538- systemPrintln (" PPB" );
534+ if (!myTCXO->begin (*i2cBus, SFE_GNSSDO_OSC_SIT5811))
535+ return ;
539536
540- myTCXO.setFrequencyControlWord (settings.tcxoControl );
537+ systemPrintln (" Using SiT5811 OCXO" );
538+ }
539+ else if (presentSIT5358)
540+ {
541+ myTCXO = (GNSSDO_TCXO *) new GNSSDO_SIT5358 ();
541542
542- systemPrint ( " TCXO frequency control word set to " );
543- systemPrintln (myTCXO. getFrequencyControlWord ()) ;
543+ if (!myTCXO-> begin (*i2cBus, SFE_GNSSDO_OSC_SIT5358))
544+ return ;
544545
545- systemPrint (" TCXO frequency is " );
546- systemPrint (myTCXO.getFrequencyHz (), 6 );
547- systemPrintln (" Hz" );
546+ systemPrintln (" Using SiT5358 TCXO" );
547+ }
548+ else
549+ {
550+ // No TCXO present!
551+ return ;
552+ }
548553
549554 online.tcxo = true ;
550555}
@@ -554,10 +559,29 @@ void updateTCXO()
554559{
555560 if (online.tcxo )
556561 {
557- myTCXO.setFrequencyByBiasMillis (tcxoClockBias_ms, settings.Pk , settings.Ik );
562+ myTCXO->setFrequencyByBiasMillis (tcxoClockBias_ms, settings.Pk , settings.Ik );
563+ }
564+ }
565+
566+ // This function tells the TCXO to save its control value - if supported
567+ void saveTCXO ()
568+ {
569+ if (online.tcxo )
570+ {
571+ myTCXO->saveFrequencyControlValue ();
558572 }
559573}
560574
575+ int64_t getFrequencyControlWord ()
576+ {
577+ if (online.tcxo )
578+ {
579+ return myTCXO->getFrequencyControlWord ();
580+ }
581+
582+ return 0 ;
583+ }
584+
561585// This function updates the tcxoClockBias_ms used to discipline the TCXO frequency
562586// updateTCXOClockBias is only called by STATE_GNSS_FINETIME when gnssPVTUpdated was true
563587// So we know that gnssClockBias_ms is valid
0 commit comments