Persist tuned frequency.

w00t!
This commit is contained in:
Jared Boone 2015-08-04 10:31:03 -07:00
parent 4870f0015b
commit d855336985
4 changed files with 22 additions and 4 deletions

View file

@ -47,12 +47,17 @@ struct range_t {
}
};
using tuned_frequency_range_t = range_t<rf::Frequency>;
constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max };
constexpr rf::Frequency tuned_frequency_reset_value { 858750000 };
using ppb_range_t = range_t<ppb_t>;
constexpr ppb_range_t ppb_range { -99000, 99000 };
constexpr ppb_t ppb_reset_value { 0 };
/* struct must pack the same way on M4 and M0 cores. */
struct data_t {
int64_t tuned_frequency;
int32_t correction_ppb;
};
@ -60,6 +65,15 @@ static_assert(sizeof(data_t) <= 0x100, "Persistent memory structure too large fo
static data_t* const data = reinterpret_cast<data_t*>(LPC_BACKUP_REG_BASE);
rf::Frequency tuned_frequency() {
tuned_frequency_range.reset_if_outside(data->tuned_frequency, tuned_frequency_reset_value);
return data->tuned_frequency;
}
void set_tuned_frequency(const rf::Frequency new_value) {
data->tuned_frequency = tuned_frequency_range.clip(new_value);
}
ppb_t correction_ppb() {
ppb_range.reset_if_outside(data->correction_ppb, ppb_reset_value);
return data->correction_ppb;