From 10d4172d5c63b054a0035b1714fbbfa6cbfa4f5b Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 22 Jan 2016 23:24:20 -0800 Subject: [PATCH] RF antenna bias voltage control API. --- firmware/application/radio.cpp | 6 ++++++ firmware/application/radio.hpp | 1 + firmware/application/receiver_model.cpp | 14 ++++++++++++++ firmware/application/receiver_model.hpp | 5 +++++ firmware/application/rffc507x.cpp | 12 ++++++++++++ firmware/application/rffc507x.hpp | 3 ++- 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index cdaced34..b58222c5 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -152,7 +152,13 @@ void set_baseband_decimation_by(const size_t n) { baseband_cpld.set_decimation_by(n); } +void set_antenna_bias(const bool on) { + /* Pull MOSFET gate low to turn on antenna bias. */ + first_if.set_gpo1(on ? 0 : 1); +} + void disable() { + set_antenna_bias(false); baseband_codec.set_mode(max5864::Mode::Shutdown); second_if.set_mode(max2837::Mode::Standby); first_if.disable(); diff --git a/firmware/application/radio.hpp b/firmware/application/radio.hpp index 0513c17c..715fd0d5 100644 --- a/firmware/application/radio.hpp +++ b/firmware/application/radio.hpp @@ -42,6 +42,7 @@ void set_vga_gain(const int_fast8_t db); void set_sampling_frequency(const uint32_t frequency); void set_baseband_filter_bandwidth(const uint32_t bandwidth_minimum); void set_baseband_decimation_by(const size_t n); +void set_antenna_bias(const bool on); void disable(); diff --git a/firmware/application/receiver_model.cpp b/firmware/application/receiver_model.cpp index 0162632d..944ba4c1 100644 --- a/firmware/application/receiver_model.cpp +++ b/firmware/application/receiver_model.cpp @@ -52,6 +52,15 @@ void ReceiverModel::set_reference_ppm_correction(int32_t v) { clock_manager.set_reference_ppb(v * 1000); } +bool ReceiverModel::antenna_bias() const { + return antenna_bias_; +} + +void ReceiverModel::set_antenna_bias(bool enabled) { + antenna_bias_ = enabled; + update_antenna_bias(); +} + bool ReceiverModel::rf_amp() const { return rf_amp_; } @@ -113,6 +122,7 @@ uint32_t ReceiverModel::baseband_oversampling() const { void ReceiverModel::enable() { radio::set_direction(rf::Direction::Receive); update_tuning_frequency(); + update_antenna_bias(); update_rf_amp(); update_lna(); update_vga(); @@ -148,6 +158,10 @@ void ReceiverModel::update_tuning_frequency() { radio::set_tuning_frequency(persistent_memory::tuned_frequency() + tuning_offset()); } +void ReceiverModel::update_antenna_bias() { + radio::set_antenna_bias(antenna_bias_); +} + void ReceiverModel::update_rf_amp() { radio::set_rf_amp(rf_amp_); } diff --git a/firmware/application/receiver_model.hpp b/firmware/application/receiver_model.hpp index aeeac7e4..e13d76cb 100644 --- a/firmware/application/receiver_model.hpp +++ b/firmware/application/receiver_model.hpp @@ -58,6 +58,9 @@ public: int32_t reference_ppm_correction() const; void set_reference_ppm_correction(int32_t v); + bool antenna_bias() const; + void set_antenna_bias(bool enabled); + bool rf_amp() const; void set_rf_amp(bool enabled); @@ -87,6 +90,7 @@ public: private: rf::Frequency frequency_step_ { 25000 }; bool rf_amp_ { false }; + bool antenna_bias_ { false }; int32_t lna_gain_db_ { 32 }; uint32_t baseband_bandwidth_ { max2837::filter::bandwidth_minimum }; int32_t vga_gain_db_ { 32 }; @@ -101,6 +105,7 @@ private: int32_t tuning_offset(); void update_tuning_frequency(); + void update_antenna_bias(); void update_rf_amp(); void update_lna(); void update_baseband_bandwidth(); diff --git a/firmware/application/rffc507x.cpp b/firmware/application/rffc507x.cpp index b001aee4..6d466ea0 100644 --- a/firmware/application/rffc507x.cpp +++ b/firmware/application/rffc507x.cpp @@ -262,6 +262,18 @@ void RFFC507x::set_frequency(const rf::Frequency lo_frequency) { flush(); } +void RFFC507x::set_gpo1(const bool new_value) { + if( new_value ) { + _map.r.gpo.p2gpo |= 1; + _map.r.gpo.p1gpo |= 1; + } else { + _map.r.gpo.p2gpo &= ~1; + _map.r.gpo.p1gpo &= ~1; + } + + flush_one(Register::GPO); +} + spi::reg_t RFFC507x::readback(const Readback readback) { /* TODO: This clobbers the rest of the DEV_CTRL register * Time to implement bitfields for registers. diff --git a/firmware/application/rffc507x.hpp b/firmware/application/rffc507x.hpp index 4850f147..016f0f11 100644 --- a/firmware/application/rffc507x.hpp +++ b/firmware/application/rffc507x.hpp @@ -808,7 +808,8 @@ public: void set_mixer_current(const uint8_t value); void set_frequency(const rf::Frequency lo_frequency); - + void set_gpo1(const bool new_value); + reg_t read(const address_t reg_num); private: