Clock reference: Return enum for selected clock source.

This commit is contained in:
Jared Boone
2019-03-20 14:38:18 -07:00
parent 2531d486f9
commit 891eaa9e62
2 changed files with 11 additions and 3 deletions

View File

@ -716,7 +716,7 @@ void cpu_clock_init(void)
#endif
}
void activate_best_clock_source(void)
clock_source_t activate_best_clock_source(void)
{
#ifdef HACKRF_ONE
/* Ensure PortaPack reference oscillator is off while checking for external clock input. */
@ -728,6 +728,7 @@ void activate_best_clock_source(void)
/* Check for external clock input. */
if (si5351c_clkin_signal_valid(&clock_gen)) {
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_CLKIN);
return CLOCK_SOURCE_EXTERNAL;
} else {
#ifdef HACKRF_ONE
/* Enable PortaPack reference oscillator (if present), and check for valid clock. */
@ -736,7 +737,7 @@ void activate_best_clock_source(void)
delay(510000); /* loop iterations @ 204MHz for >10ms for oscillator to enable. */
if (si5351c_clkin_signal_valid(&clock_gen)) {
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_CLKIN);
return;
return CLOCK_SOURCE_PORTAPACK;
} else {
portapack_reference_oscillator(false);
}
@ -744,6 +745,7 @@ void activate_best_clock_source(void)
#endif
/* No external or PortaPack clock was found. Use HackRF Si5351C crystal. */
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_XTAL);
return CLOCK_SOURCE_HACKRF;
}
}

View File

@ -264,6 +264,12 @@ typedef enum {
HW_SYNC_MODE_ON = 1,
} hw_sync_mode_t;
typedef enum {
CLOCK_SOURCE_HACKRF = 0,
CLOCK_SOURCE_EXTERNAL = 1,
CLOCK_SOURCE_PORTAPACK = 2,
} clock_source_t;
void delay(uint32_t duration);
/* TODO: Hide these configurations */
@ -294,7 +300,7 @@ bool sample_rate_frac_set(uint32_t rate_num, uint32_t rate_denom);
bool sample_rate_set(const uint32_t sampling_rate_hz);
bool baseband_filter_bandwidth_set(const uint32_t bandwidth_hz);
void activate_best_clock_source(void);
clock_source_t activate_best_clock_source(void);
#if (defined HACKRF_ONE || defined RAD1O)
void enable_rf_power(void);