mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 07:19:28 -05:00
Extract BasebandThread, ThreadBase to separate files.
This commit is contained in:
parent
2808efac4c
commit
e998014e57
@ -129,6 +129,7 @@ CPPSRC = main.cpp \
|
|||||||
gpdma.cpp \
|
gpdma.cpp \
|
||||||
baseband_dma.cpp \
|
baseband_dma.cpp \
|
||||||
portapack_shared_memory.cpp \
|
portapack_shared_memory.cpp \
|
||||||
|
baseband_thread.cpp \
|
||||||
baseband_processor.cpp \
|
baseband_processor.cpp \
|
||||||
channel_decimator.cpp \
|
channel_decimator.cpp \
|
||||||
dsp_decimate.cpp \
|
dsp_decimate.cpp \
|
||||||
|
122
firmware/baseband/baseband_thread.cpp
Normal file
122
firmware/baseband/baseband_thread.cpp
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
#include "baseband_stats_collector.hpp"
|
||||||
|
#include "baseband_dma.hpp"
|
||||||
|
|
||||||
|
#include "rssi.hpp"
|
||||||
|
#include "i2s.hpp"
|
||||||
|
|
||||||
|
#include "proc_am_audio.hpp"
|
||||||
|
#include "proc_nfm_audio.hpp"
|
||||||
|
#include "proc_wfm_audio.hpp"
|
||||||
|
#include "proc_ais.hpp"
|
||||||
|
#include "proc_wideband_spectrum.hpp"
|
||||||
|
#include "proc_tpms.hpp"
|
||||||
|
#include "proc_ert.hpp"
|
||||||
|
|
||||||
|
#include "portapack_shared_memory.hpp"
|
||||||
|
|
||||||
|
Thread* BasebandThread::start(const tprio_t priority) {
|
||||||
|
return chThdCreateStatic(wa, sizeof(wa),
|
||||||
|
priority, ThreadBase::fn,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasebandThread::set_configuration(const BasebandConfiguration& new_configuration) {
|
||||||
|
if( new_configuration.mode != baseband_configuration.mode ) {
|
||||||
|
disable();
|
||||||
|
|
||||||
|
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
||||||
|
auto old_p = baseband_processor;
|
||||||
|
baseband_processor = nullptr;
|
||||||
|
delete old_p;
|
||||||
|
|
||||||
|
baseband_processor = create_processor(new_configuration.mode);
|
||||||
|
|
||||||
|
enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
baseband_configuration = new_configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasebandThread::run() {
|
||||||
|
BasebandStatsCollector stats {
|
||||||
|
chSysGetIdleThread(),
|
||||||
|
thread_main,
|
||||||
|
thread_rssi,
|
||||||
|
chThdSelf()
|
||||||
|
};
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
// TODO: Place correct sampling rate into buffer returned here:
|
||||||
|
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
|
||||||
|
buffer_c8_t buffer {
|
||||||
|
buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate
|
||||||
|
};
|
||||||
|
|
||||||
|
if( baseband_processor ) {
|
||||||
|
baseband_processor->execute(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.process(buffer,
|
||||||
|
[](const BasebandStatistics& statistics) {
|
||||||
|
const BasebandStatisticsMessage message { statistics };
|
||||||
|
shared_memory.application_queue.push(message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BasebandProcessor* BasebandThread::create_processor(const int32_t mode) {
|
||||||
|
switch(mode) {
|
||||||
|
case 0: return new NarrowbandAMAudio();
|
||||||
|
case 1: return new NarrowbandFMAudio();
|
||||||
|
case 2: return new WidebandFMAudio();
|
||||||
|
case 3: return new AISProcessor();
|
||||||
|
case 4: return new WidebandSpectrum();
|
||||||
|
case 5: return new TPMSProcessor();
|
||||||
|
case 6: return new ERTProcessor();
|
||||||
|
default: return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasebandThread::disable() {
|
||||||
|
if( baseband_processor ) {
|
||||||
|
i2s::i2s0::tx_mute();
|
||||||
|
baseband::dma::disable();
|
||||||
|
rf::rssi::stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BasebandThread::enable() {
|
||||||
|
if( baseband_processor ) {
|
||||||
|
if( direction() == baseband::Direction::Receive ) {
|
||||||
|
rf::rssi::start();
|
||||||
|
}
|
||||||
|
baseband::dma::enable(direction());
|
||||||
|
}
|
||||||
|
}
|
64
firmware/baseband/baseband_thread.hpp
Normal file
64
firmware/baseband/baseband_thread.hpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __BASEBAND_THREAD_H__
|
||||||
|
#define __BASEBAND_THREAD_H__
|
||||||
|
|
||||||
|
#include "thread_base.hpp"
|
||||||
|
#include "message.hpp"
|
||||||
|
#include "baseband_processor.hpp"
|
||||||
|
|
||||||
|
#include <ch.h>
|
||||||
|
|
||||||
|
class BasebandThread : public ThreadBase {
|
||||||
|
public:
|
||||||
|
BasebandThread(
|
||||||
|
) : ThreadBase { "baseband" }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread* start(const tprio_t priority);
|
||||||
|
|
||||||
|
void set_configuration(const BasebandConfiguration& new_configuration);
|
||||||
|
|
||||||
|
// This getter should die, it's just here to leak information to code that
|
||||||
|
// isn't in the right place to begin with.
|
||||||
|
baseband::Direction direction() const {
|
||||||
|
return baseband::Direction::Receive;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread* thread_main { nullptr };
|
||||||
|
Thread* thread_rssi { nullptr };
|
||||||
|
BasebandProcessor* baseband_processor { nullptr };
|
||||||
|
BasebandConfiguration baseband_configuration;
|
||||||
|
|
||||||
|
private:
|
||||||
|
WORKING_AREA(wa, 2048);
|
||||||
|
|
||||||
|
void run() override;
|
||||||
|
|
||||||
|
BasebandProcessor* create_processor(const int32_t mode);
|
||||||
|
|
||||||
|
void disable();
|
||||||
|
void enable();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif/*__BASEBAND_THREAD_H__*/
|
@ -40,17 +40,10 @@
|
|||||||
|
|
||||||
#include "touch_dma.hpp"
|
#include "touch_dma.hpp"
|
||||||
|
|
||||||
#include "baseband_stats_collector.hpp"
|
|
||||||
#include "rssi_stats_collector.hpp"
|
#include "rssi_stats_collector.hpp"
|
||||||
|
|
||||||
|
#include "baseband_thread.hpp"
|
||||||
#include "baseband_processor.hpp"
|
#include "baseband_processor.hpp"
|
||||||
#include "proc_am_audio.hpp"
|
|
||||||
#include "proc_nfm_audio.hpp"
|
|
||||||
#include "proc_wfm_audio.hpp"
|
|
||||||
#include "proc_ais.hpp"
|
|
||||||
#include "proc_wideband_spectrum.hpp"
|
|
||||||
#include "proc_tpms.hpp"
|
|
||||||
#include "proc_ert.hpp"
|
|
||||||
|
|
||||||
#include "message_queue.hpp"
|
#include "message_queue.hpp"
|
||||||
|
|
||||||
@ -67,128 +60,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
class ThreadBase {
|
|
||||||
public:
|
|
||||||
constexpr ThreadBase(
|
|
||||||
const char* const name
|
|
||||||
) : name { name }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static msg_t fn(void* arg) {
|
|
||||||
auto obj = static_cast<ThreadBase*>(arg);
|
|
||||||
chRegSetThreadName(obj->name);
|
|
||||||
obj->run();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void run() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const char* const name;
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto direction = baseband::Direction::Receive;
|
|
||||||
|
|
||||||
class BasebandThread : public ThreadBase {
|
|
||||||
public:
|
|
||||||
BasebandThread(
|
|
||||||
) : ThreadBase { "baseband" }
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread* start(const tprio_t priority) {
|
|
||||||
return chThdCreateStatic(wa, sizeof(wa),
|
|
||||||
priority, ThreadBase::fn,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_configuration(const BasebandConfiguration& new_configuration) {
|
|
||||||
if( new_configuration.mode != baseband_configuration.mode ) {
|
|
||||||
disable();
|
|
||||||
|
|
||||||
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
|
||||||
auto old_p = baseband_processor;
|
|
||||||
baseband_processor = nullptr;
|
|
||||||
delete old_p;
|
|
||||||
|
|
||||||
baseband_processor = create_processor(new_configuration.mode);
|
|
||||||
|
|
||||||
enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
baseband_configuration = new_configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread* thread_main { nullptr };
|
|
||||||
Thread* thread_rssi { nullptr };
|
|
||||||
BasebandProcessor* baseband_processor { nullptr };
|
|
||||||
BasebandConfiguration baseband_configuration;
|
|
||||||
|
|
||||||
private:
|
|
||||||
WORKING_AREA(wa, 2048);
|
|
||||||
|
|
||||||
void run() override {
|
|
||||||
BasebandStatsCollector stats {
|
|
||||||
chSysGetIdleThread(),
|
|
||||||
thread_main,
|
|
||||||
thread_rssi,
|
|
||||||
chThdSelf()
|
|
||||||
};
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
// TODO: Place correct sampling rate into buffer returned here:
|
|
||||||
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
|
|
||||||
buffer_c8_t buffer {
|
|
||||||
buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate
|
|
||||||
};
|
|
||||||
|
|
||||||
if( baseband_processor ) {
|
|
||||||
baseband_processor->execute(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
stats.process(buffer,
|
|
||||||
[](const BasebandStatistics& statistics) {
|
|
||||||
const BasebandStatisticsMessage message { statistics };
|
|
||||||
shared_memory.application_queue.push(message);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BasebandProcessor* create_processor(const int32_t mode) {
|
|
||||||
switch(mode) {
|
|
||||||
case 0: return new NarrowbandAMAudio();
|
|
||||||
case 1: return new NarrowbandFMAudio();
|
|
||||||
case 2: return new WidebandFMAudio();
|
|
||||||
case 3: return new AISProcessor();
|
|
||||||
case 4: return new WidebandSpectrum();
|
|
||||||
case 5: return new TPMSProcessor();
|
|
||||||
case 6: return new ERTProcessor();
|
|
||||||
default: return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void disable() {
|
|
||||||
if( baseband_processor ) {
|
|
||||||
i2s::i2s0::tx_mute();
|
|
||||||
baseband::dma::disable();
|
|
||||||
rf::rssi::stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void enable() {
|
|
||||||
if( baseband_processor ) {
|
|
||||||
if( direction == baseband::Direction::Receive ) {
|
|
||||||
rf::rssi::start();
|
|
||||||
}
|
|
||||||
baseband::dma::enable(direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class RSSIThread : public ThreadBase {
|
class RSSIThread : public ThreadBase {
|
||||||
public:
|
public:
|
||||||
RSSIThread(
|
RSSIThread(
|
||||||
@ -379,7 +250,7 @@ int main(void) {
|
|||||||
|
|
||||||
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
||||||
|
|
||||||
if( direction == baseband::Direction::Receive ) {
|
if( baseband_thread.direction() == baseband::Direction::Receive ) {
|
||||||
rf::rssi::dma::allocate(4, 400);
|
rf::rssi::dma::allocate(4, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +261,7 @@ int main(void) {
|
|||||||
new std::array<baseband::sample_t, 8192>();
|
new std::array<baseband::sample_t, 8192>();
|
||||||
baseband::dma::configure(
|
baseband::dma::configure(
|
||||||
baseband_buffer->data(),
|
baseband_buffer->data(),
|
||||||
direction
|
baseband_thread.direction()
|
||||||
);
|
);
|
||||||
//baseband::dma::allocate(4, 2048);
|
//baseband::dma::allocate(4, 2048);
|
||||||
|
|
||||||
|
49
firmware/baseband/thread_base.hpp
Normal file
49
firmware/baseband/thread_base.hpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __THREAD_BASE_H__
|
||||||
|
#define __THREAD_BASE_H__
|
||||||
|
|
||||||
|
#include <ch.h>
|
||||||
|
|
||||||
|
class ThreadBase {
|
||||||
|
public:
|
||||||
|
constexpr ThreadBase(
|
||||||
|
const char* const name
|
||||||
|
) : name { name }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static msg_t fn(void* arg) {
|
||||||
|
auto obj = static_cast<ThreadBase*>(arg);
|
||||||
|
chRegSetThreadName(obj->name);
|
||||||
|
obj->run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void run() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* const name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif/*__THREAD_BASE_H__*/
|
Loading…
Reference in New Issue
Block a user