2015-12-10 18:53:54 -05: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 "baseband_thread.hpp"
|
|
|
|
|
|
|
|
#include "dsp_types.hpp"
|
|
|
|
|
2015-12-10 19:32:00 -05:00
|
|
|
#include "baseband.hpp"
|
2016-01-10 13:23:39 -05:00
|
|
|
#include "baseband_sgpio.hpp"
|
2015-12-10 18:53:54 -05:00
|
|
|
#include "baseband_dma.hpp"
|
|
|
|
|
|
|
|
#include "rssi.hpp"
|
|
|
|
#include "i2s.hpp"
|
2016-05-10 14:02:42 -04:00
|
|
|
using namespace lpc43xx;
|
2015-12-10 18:53:54 -05:00
|
|
|
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
2015-12-10 19:32:00 -05:00
|
|
|
#include <array>
|
|
|
|
|
2016-01-10 13:23:39 -05:00
|
|
|
static baseband::SGPIO baseband_sgpio;
|
|
|
|
|
2016-01-02 13:57:47 -05:00
|
|
|
WORKING_AREA(baseband_thread_wa, 4096);
|
2015-12-11 00:01:44 -05:00
|
|
|
|
2016-06-24 18:34:49 -04:00
|
|
|
Thread* BasebandThread::thread = nullptr;
|
|
|
|
|
2016-06-25 13:57:16 -04:00
|
|
|
BasebandThread::BasebandThread(
|
|
|
|
uint32_t sampling_rate,
|
|
|
|
BasebandProcessor* const baseband_processor,
|
2016-08-10 13:36:03 -04:00
|
|
|
const tprio_t priority,
|
|
|
|
baseband::Direction direction
|
2016-06-25 13:57:16 -04:00
|
|
|
) : baseband_processor { baseband_processor },
|
2016-08-10 13:36:03 -04:00
|
|
|
sampling_rate { sampling_rate },
|
|
|
|
_direction { direction }
|
2016-06-25 13:57:16 -04:00
|
|
|
{
|
2016-06-24 18:34:49 -04:00
|
|
|
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
|
2015-12-10 18:53:54 -05:00
|
|
|
priority, ThreadBase::fn,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:34:49 -04:00
|
|
|
BasebandThread::~BasebandThread() {
|
2016-06-24 18:46:53 -04:00
|
|
|
chThdTerminate(thread);
|
|
|
|
chThdWait(thread);
|
|
|
|
thread = nullptr;
|
2016-06-24 18:34:49 -04:00
|
|
|
}
|
|
|
|
|
2015-12-10 18:53:54 -05:00
|
|
|
void BasebandThread::run() {
|
2016-01-10 13:23:39 -05:00
|
|
|
baseband_sgpio.init();
|
2015-12-10 19:32:00 -05:00
|
|
|
baseband::dma::init();
|
|
|
|
|
2016-02-23 23:21:32 -05:00
|
|
|
const auto baseband_buffer = std::make_unique<std::array<baseband::sample_t, 8192>>();
|
2015-12-10 19:32:00 -05:00
|
|
|
baseband::dma::configure(
|
|
|
|
baseband_buffer->data(),
|
|
|
|
direction()
|
|
|
|
);
|
|
|
|
//baseband::dma::allocate(4, 2048);
|
|
|
|
|
2016-06-25 13:53:16 -04:00
|
|
|
baseband_sgpio.configure(direction());
|
|
|
|
baseband::dma::enable(direction());
|
|
|
|
baseband_sgpio.streaming_enable();
|
|
|
|
|
2016-06-24 18:34:49 -04:00
|
|
|
while( !chThdShouldTerminate() ) {
|
2015-12-10 18:53:54 -05:00
|
|
|
// TODO: Place correct sampling rate into buffer returned here:
|
2016-08-10 13:34:14 -04:00
|
|
|
const auto buffer_tmp = baseband::dma::wait_for_buffer();
|
2016-01-09 15:20:57 -05:00
|
|
|
if( buffer_tmp ) {
|
|
|
|
buffer_c8_t buffer {
|
2016-06-25 13:57:16 -04:00
|
|
|
buffer_tmp.p, buffer_tmp.count, sampling_rate
|
2016-01-09 15:20:57 -05:00
|
|
|
};
|
2015-12-10 18:53:54 -05:00
|
|
|
|
2016-01-09 15:20:57 -05:00
|
|
|
if( baseband_processor ) {
|
|
|
|
baseband_processor->execute(buffer);
|
2015-12-10 18:53:54 -05:00
|
|
|
}
|
2016-01-09 15:20:57 -05:00
|
|
|
}
|
2015-12-10 18:53:54 -05:00
|
|
|
}
|
2016-06-25 13:53:16 -04:00
|
|
|
|
|
|
|
i2s::i2s0::tx_mute();
|
|
|
|
baseband::dma::disable();
|
|
|
|
baseband_sgpio.streaming_disable();
|
2015-12-10 18:53:54 -05:00
|
|
|
}
|