2015-08-28 18:50:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "transmitter_model.hpp"
|
|
|
|
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
rf::Frequency TransmitterModel::tuning_frequency() const {
|
|
|
|
return persistent_memory::tuned_frequency();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_tuning_frequency(rf::Frequency f) {
|
|
|
|
persistent_memory::set_tuned_frequency(f);
|
|
|
|
update_tuning_frequency();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransmitterModel::rf_amp() const {
|
|
|
|
return rf_amp_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_rf_amp(bool enabled) {
|
|
|
|
rf_amp_ = enabled;
|
|
|
|
update_rf_amp();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t TransmitterModel::lna() const {
|
|
|
|
return lna_gain_db_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_lna(int32_t v_db) {
|
|
|
|
lna_gain_db_ = v_db;
|
|
|
|
update_lna();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TransmitterModel::baseband_bandwidth() const {
|
|
|
|
return baseband_bandwidth_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_baseband_bandwidth(uint32_t v) {
|
|
|
|
baseband_bandwidth_ = v;
|
|
|
|
update_baseband_bandwidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t TransmitterModel::vga() const {
|
|
|
|
return vga_gain_db_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_vga(int32_t v_db) {
|
|
|
|
vga_gain_db_ = v_db;
|
|
|
|
update_vga();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TransmitterModel::sampling_rate() const {
|
|
|
|
return baseband_configuration.sampling_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::enable() {
|
2016-02-04 09:27:53 +00:00
|
|
|
enabled_ = true;
|
2015-08-28 18:50:42 +00:00
|
|
|
radio::set_direction(rf::Direction::Transmit);
|
|
|
|
update_tuning_frequency();
|
|
|
|
update_rf_amp();
|
|
|
|
update_lna();
|
|
|
|
update_vga();
|
|
|
|
update_baseband_bandwidth();
|
|
|
|
update_baseband_configuration();
|
|
|
|
}
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
void TransmitterModel::baseband_disable() {
|
|
|
|
shared_memory.baseband_queue.push_and_wait(
|
|
|
|
BasebandConfigurationMessage {
|
|
|
|
.configuration = { },
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
2016-02-04 09:27:53 +00:00
|
|
|
);
|
|
|
|
}
|
2015-08-28 18:50:42 +00:00
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
void TransmitterModel::disable() {
|
|
|
|
enabled_ = false;
|
|
|
|
baseband_disable();
|
|
|
|
|
|
|
|
// TODO: Responsibility for enabling/disabling the radio is muddy.
|
|
|
|
// Some happens in ReceiverModel, some inside radio namespace.
|
2015-08-28 18:50:42 +00:00
|
|
|
radio::disable();
|
|
|
|
}
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
uint32_t TransmitterModel::baseband_oversampling() const {
|
|
|
|
// TODO: Rename decimation_factor.
|
|
|
|
return baseband_configuration.decimation_factor;
|
|
|
|
}
|
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
int32_t TransmitterModel::tuning_offset() {
|
|
|
|
return -(sampling_rate() / 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_tuning_frequency() {
|
|
|
|
radio::set_tuning_frequency(tuning_frequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_rf_amp() {
|
|
|
|
radio::set_rf_amp(rf_amp_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_lna() {
|
|
|
|
radio::set_lna_gain(lna_gain_db_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_baseband_bandwidth() {
|
|
|
|
radio::set_baseband_filter_bandwidth(baseband_bandwidth_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_vga() {
|
|
|
|
radio::set_vga_gain(vga_gain_db_);
|
|
|
|
}
|
|
|
|
|
2016-02-04 09:27:53 +00:00
|
|
|
uint32_t TransmitterModel::modulation() const {
|
|
|
|
return baseband_configuration.mode;
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 10:47:46 +00:00
|
|
|
void TransmitterModel::set_baseband_configuration(const BasebandConfiguration config) {
|
|
|
|
baseband_configuration = config;
|
|
|
|
update_baseband_configuration();
|
|
|
|
}
|
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
void TransmitterModel::update_baseband_configuration() {
|
2016-02-04 09:27:53 +00:00
|
|
|
// TODO: Move more low-level radio control stuff to M4. It'll enable tighter
|
|
|
|
// synchronization for things like wideband (sweeping) spectrum analysis, and
|
|
|
|
// protocols that need quick RX/TX turn-around.
|
|
|
|
|
|
|
|
// Disabling baseband while changing sampling rates seems like a good idea...
|
|
|
|
baseband_disable();
|
2015-11-18 21:01:48 +00:00
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
clock_manager.set_sampling_frequency(sampling_rate() * baseband_oversampling());
|
|
|
|
update_tuning_frequency();
|
|
|
|
radio::set_baseband_decimation_by(baseband_oversampling());
|
|
|
|
|
|
|
|
BasebandConfigurationMessage message { baseband_configuration };
|
2015-11-18 21:01:48 +00:00
|
|
|
shared_memory.baseband_queue.push(message);
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
2016-01-05 10:47:46 +00:00
|
|
|
|