2015-07-08 11:39:24 -04: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 "rssi.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "adc.hpp"
|
|
|
|
#include "rssi_dma.hpp"
|
|
|
|
#include "utility.hpp"
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
using namespace lpc43xx;
|
|
|
|
|
|
|
|
#include "hackrf_hal.hpp"
|
|
|
|
using namespace hackrf::one;
|
|
|
|
|
|
|
|
#include "portapack_adc.hpp"
|
|
|
|
|
|
|
|
namespace rf {
|
|
|
|
namespace rssi {
|
|
|
|
|
2015-07-08 19:00:18 -04:00
|
|
|
constexpr uint8_t adc1_sel = (1 << portapack::adc1_rssi_input);
|
2015-07-08 18:48:20 -04:00
|
|
|
const auto adc1_interrupt_mask = flp2(adc1_sel);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
constexpr adc::CR adc1_cr {
|
|
|
|
.sel = adc1_sel,
|
|
|
|
.clkdiv = 49, /* 400kHz sample rate, 2.5us/sample @ 200MHz PCLK */
|
|
|
|
.resolution = 9, /* Ten clocks */
|
|
|
|
.edge = 0,
|
|
|
|
};
|
|
|
|
constexpr adc::Config adc1_config {
|
|
|
|
.cr = adc1_cr,
|
|
|
|
};
|
|
|
|
|
|
|
|
void init() {
|
2017-01-05 20:10:00 -05:00
|
|
|
adc1::clock_enable();
|
|
|
|
adc1::interrupts_disable();
|
|
|
|
adc1::power_up(adc1_config);
|
|
|
|
adc1::interrupts_enable(adc1_interrupt_mask);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
dma::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void start() {
|
|
|
|
dma::enable();
|
2017-01-05 20:10:00 -05:00
|
|
|
adc1::start_burst();
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void stop() {
|
|
|
|
dma::disable();
|
2017-01-05 20:10:00 -05:00
|
|
|
adc1::stop_burst();
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace rssi */
|
|
|
|
} /* namespace rf */
|