mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-12 23:53:38 +00:00
Take processor as argument to BasebandThread.
Remove lots of dependency on specific processors. Reduce state by removing processor switching from BasebandThread.
This commit is contained in:
parent
bb32ef5321
commit
74c8429f75
@ -31,15 +31,6 @@
|
|||||||
#include "i2s.hpp"
|
#include "i2s.hpp"
|
||||||
using namespace lpc43xx;
|
using namespace lpc43xx;
|
||||||
|
|
||||||
#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 "proc_capture.hpp"
|
|
||||||
|
|
||||||
#include "portapack_shared_memory.hpp"
|
#include "portapack_shared_memory.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
@ -50,7 +41,13 @@ WORKING_AREA(baseband_thread_wa, 4096);
|
|||||||
|
|
||||||
Thread* BasebandThread::thread = nullptr;
|
Thread* BasebandThread::thread = nullptr;
|
||||||
|
|
||||||
BasebandThread::BasebandThread(const tprio_t priority) {
|
BasebandThread::BasebandThread(
|
||||||
|
uint32_t sampling_rate,
|
||||||
|
BasebandProcessor* const baseband_processor,
|
||||||
|
const tprio_t priority
|
||||||
|
) : baseband_processor { baseband_processor },
|
||||||
|
sampling_rate { sampling_rate }
|
||||||
|
{
|
||||||
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
|
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa),
|
||||||
priority, ThreadBase::fn,
|
priority, ThreadBase::fn,
|
||||||
this
|
this
|
||||||
@ -63,33 +60,6 @@ BasebandThread::~BasebandThread() {
|
|||||||
thread = nullptr;
|
thread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
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::on_message(const Message* const message) {
|
|
||||||
if( message->id == Message::ID::BasebandConfiguration ) {
|
|
||||||
set_configuration(reinterpret_cast<const BasebandConfigurationMessage*>(message)->configuration);
|
|
||||||
} else {
|
|
||||||
if( baseband_processor ) {
|
|
||||||
baseband_processor->on_message(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BasebandThread::run() {
|
void BasebandThread::run() {
|
||||||
baseband_sgpio.init();
|
baseband_sgpio.init();
|
||||||
baseband::dma::init();
|
baseband::dma::init();
|
||||||
@ -110,7 +80,7 @@ void BasebandThread::run() {
|
|||||||
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
|
const auto buffer_tmp = baseband::dma::wait_for_rx_buffer();
|
||||||
if( buffer_tmp ) {
|
if( buffer_tmp ) {
|
||||||
buffer_c8_t buffer {
|
buffer_c8_t buffer {
|
||||||
buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate
|
buffer_tmp.p, buffer_tmp.count, sampling_rate
|
||||||
};
|
};
|
||||||
|
|
||||||
if( baseband_processor ) {
|
if( baseband_processor ) {
|
||||||
@ -123,17 +93,3 @@ void BasebandThread::run() {
|
|||||||
baseband::dma::disable();
|
baseband::dma::disable();
|
||||||
baseband_sgpio.streaming_disable();
|
baseband_sgpio.streaming_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
case 7: return new CaptureProcessor();
|
|
||||||
default: return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -30,10 +30,12 @@
|
|||||||
|
|
||||||
class BasebandThread : public ThreadBase {
|
class BasebandThread : public ThreadBase {
|
||||||
public:
|
public:
|
||||||
BasebandThread(const tprio_t priority);
|
BasebandThread(
|
||||||
|
uint32_t sampling_rate,
|
||||||
|
BasebandProcessor* const baseband_processor,
|
||||||
|
const tprio_t priority
|
||||||
|
);
|
||||||
~BasebandThread();
|
~BasebandThread();
|
||||||
|
|
||||||
void on_message(const Message* const message);
|
|
||||||
|
|
||||||
// This getter should die, it's just here to leak information to code that
|
// This getter should die, it's just here to leak information to code that
|
||||||
// isn't in the right place to begin with.
|
// isn't in the right place to begin with.
|
||||||
@ -45,14 +47,9 @@ private:
|
|||||||
static Thread* thread;
|
static Thread* thread;
|
||||||
|
|
||||||
BasebandProcessor* baseband_processor { nullptr };
|
BasebandProcessor* baseband_processor { nullptr };
|
||||||
|
uint32_t sampling_rate;
|
||||||
BasebandConfiguration baseband_configuration;
|
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
BasebandProcessor* create_processor(const int32_t mode);
|
|
||||||
|
|
||||||
void set_configuration(const BasebandConfiguration& new_configuration);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif/*__BASEBAND_THREAD_H__*/
|
#endif/*__BASEBAND_THREAD_H__*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user