Fix baseband thread init order bug for all procs. (#1293)

This commit is contained in:
Kyle Reed 2023-07-22 23:54:17 -07:00 committed by GitHub
parent 828eb67a52
commit 7bd370b5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 226 additions and 174 deletions

View File

@ -46,24 +46,34 @@ Thread* BasebandThread::thread = nullptr;
BasebandThread::BasebandThread( BasebandThread::BasebandThread(
uint32_t sampling_rate, uint32_t sampling_rate,
BasebandProcessor* const baseband_processor, BasebandProcessor* const baseband_processor,
const tprio_t priority, baseband::Direction direction,
baseband::Direction direction) bool auto_start,
: baseband_processor{baseband_processor}, tprio_t priority)
_direction{direction}, : baseband_processor_{baseband_processor},
sampling_rate{sampling_rate} { direction_{direction},
thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa), sampling_rate_{sampling_rate},
priority, ThreadBase::fn, priority_{priority} {
this); if (auto_start) start();
} }
BasebandThread::~BasebandThread() { BasebandThread::~BasebandThread() {
if (thread) {
chThdTerminate(thread); chThdTerminate(thread);
chThdWait(thread); chThdWait(thread);
thread = nullptr; thread = nullptr;
} }
}
void BasebandThread::start() {
if (!thread) {
thread = chThdCreateStatic(
baseband_thread_wa, sizeof(baseband_thread_wa),
priority_, ThreadBase::fn, this);
}
}
void BasebandThread::set_sampling_rate(uint32_t new_sampling_rate) { void BasebandThread::set_sampling_rate(uint32_t new_sampling_rate) {
sampling_rate = new_sampling_rate; sampling_rate_ = new_sampling_rate;
} }
void BasebandThread::run() { void BasebandThread::run() {
@ -71,9 +81,7 @@ void BasebandThread::run() {
baseband::dma::init(); baseband::dma::init();
const auto baseband_buffer = std::make_unique<std::array<baseband::sample_t, 8192>>(); const auto baseband_buffer = std::make_unique<std::array<baseband::sample_t, 8192>>();
baseband::dma::configure( baseband::dma::configure(baseband_buffer->data(), direction());
baseband_buffer->data(),
direction());
// baseband::dma::allocate(4, 2048); // baseband::dma::allocate(4, 2048);
baseband_sgpio.configure(direction()); baseband_sgpio.configure(direction());
@ -85,10 +93,10 @@ void BasebandThread::run() {
const auto buffer_tmp = baseband::dma::wait_for_buffer(); const auto buffer_tmp = baseband::dma::wait_for_buffer();
if (buffer_tmp) { if (buffer_tmp) {
buffer_c8_t buffer{ buffer_c8_t buffer{
buffer_tmp.p, buffer_tmp.count, sampling_rate}; buffer_tmp.p, buffer_tmp.count, sampling_rate_};
if (baseband_processor) { if (baseband_processor_) {
baseband_processor->execute(buffer); baseband_processor_->execute(buffer);
} }
} }
} }

View File

@ -28,13 +28,20 @@
#include <ch.h> #include <ch.h>
/* NB: Because ThreadBase threads start when then are initialized (by default),
* they should be the last members in a Processor class to ensure the rest of the
* members are fully initialized before data handling starts. If the Procressor
* needs to do additional initialization (in its ctor), set 'auto_start' to false
* and manually call 'start()' on the thread. */
class BasebandThread : public ThreadBase { class BasebandThread : public ThreadBase {
public: public:
BasebandThread( BasebandThread(
uint32_t sampling_rate, uint32_t sampling_rate,
BasebandProcessor* const baseband_processor, BasebandProcessor* const baseband_processor,
const tprio_t priority, baseband::Direction direction,
const baseband::Direction direction = baseband::Direction::Receive); bool auto_start = true,
tprio_t priority = (NORMALPRIO + 20));
~BasebandThread(); ~BasebandThread();
BasebandThread(const BasebandThread&) = delete; BasebandThread(const BasebandThread&) = delete;
@ -42,10 +49,12 @@ class BasebandThread : public ThreadBase {
BasebandThread& operator=(const BasebandThread&) = delete; BasebandThread& operator=(const BasebandThread&) = delete;
BasebandThread& operator=(BasebandThread&&) = delete; BasebandThread& operator=(BasebandThread&&) = delete;
void start() override;
// 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.
baseband::Direction direction() const { baseband::Direction direction() const {
return _direction; return direction_;
} }
void set_sampling_rate(uint32_t new_sampling_rate); void set_sampling_rate(uint32_t new_sampling_rate);
@ -53,9 +62,10 @@ class BasebandThread : public ThreadBase {
private: private:
static Thread* thread; static Thread* thread;
BasebandProcessor* baseband_processor{nullptr}; BasebandProcessor* baseband_processor_;
baseband::Direction _direction{baseband::Direction::Receive}; baseband::Direction direction_;
uint32_t sampling_rate{0}; uint32_t sampling_rate_;
const tprio_t priority_;
void run() override; void run() override;
}; };

View File

@ -32,6 +32,7 @@ ACARSProcessor::ACARSProcessor() {
decim_0.configure(taps_11k0_decim_0.taps, 33554432); decim_0.configure(taps_11k0_decim_0.taps, 33554432);
decim_1.configure(taps_11k0_decim_1.taps, 131072); decim_1.configure(taps_11k0_decim_1.taps, 131072);
packet.clear(); packet.clear();
baseband_thread.start();
} }
void ACARSProcessor::execute(const buffer_c8_t& buffer) { void ACARSProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -110,9 +110,6 @@ class ACARSProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 2457600; static constexpr size_t baseband_fs = 2457600;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -138,6 +135,11 @@ class ACARSProcessor : public BasebandProcessor {
};*/ };*/
baseband::Packet packet{}; baseband::Packet packet{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
void consume_symbol(const float symbol); void consume_symbol(const float symbol);
void payload_handler(const baseband::Packet& packet); void payload_handler(const baseband::Packet& packet);
}; };

View File

@ -36,15 +36,11 @@ using namespace adsb;
class ADSBRXProcessor : public BasebandProcessor { class ADSBRXProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 2000000; static constexpr size_t baseband_fs = 2000000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
ADSBFrame frame{}; ADSBFrame frame{};
bool configured{false}; bool configured{false};
uint32_t prev_mag{0}; uint32_t prev_mag{0};
@ -58,6 +54,10 @@ class ADSBRXProcessor : public BasebandProcessor {
uint32_t sample{0}; uint32_t sample{0};
int32_t re{}, im{}; int32_t re{}, im{};
int32_t amp{0}; int32_t amp{0};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
}; };
#endif #endif

View File

@ -29,14 +29,11 @@
class ADSBTXProcessor : public BasebandProcessor { class ADSBTXProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override; void on_message(const Message* const p) override;
private: private:
bool configured = false; bool configured = false;
BasebandThread baseband_thread{4000000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
const complex8_t am_lut[4] = { const complex8_t am_lut[4] = {
{127, 0}, {127, 0},
{0, 127}, {0, 127},
@ -48,6 +45,9 @@ class ADSBTXProcessor : public BasebandProcessor {
uint32_t phase{0}; uint32_t phase{0};
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{4000000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -32,14 +32,11 @@
class AFSKProcessor : public BasebandProcessor { class AFSKProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
bool configured = false; bool configured = false;
BasebandThread baseband_thread{AFSK_SAMPLERATE, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint32_t afsk_samples_per_bit{0}; uint32_t afsk_samples_per_bit{0};
uint32_t afsk_phase_inc_mark{0}; uint32_t afsk_phase_inc_mark{0};
uint32_t afsk_phase_inc_space{0}; uint32_t afsk_phase_inc_space{0};
@ -59,6 +56,9 @@ class AFSKProcessor : public BasebandProcessor {
int8_t re{0}, im{0}; int8_t re{0}, im{0};
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{AFSK_SAMPLERATE, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -38,7 +38,6 @@
class AFSKRxProcessor : public BasebandProcessor { class AFSKRxProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
@ -53,9 +52,6 @@ class AFSKRxProcessor : public BasebandProcessor {
RECEIVE RECEIVE
}; };
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -93,9 +89,13 @@ class AFSKRxProcessor : public BasebandProcessor {
bool trigger_word{}; bool trigger_word{};
bool triggered{}; bool triggered{};
void configure(const AFSKRxConfigureMessage& message);
AFSKDataMessage data_message{false, 0}; AFSKDataMessage data_message{false, 0};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const AFSKRxConfigureMessage& message);
}; };
#endif /*__PROC_TPMS_H__*/ #endif /*__PROC_TPMS_H__*/

View File

@ -30,6 +30,7 @@
AISProcessor::AISProcessor() { AISProcessor::AISProcessor() {
decim_0.configure(taps_11k0_decim_0.taps, 33554432); decim_0.configure(taps_11k0_decim_0.taps, 33554432);
decim_1.configure(taps_11k0_decim_1.taps, 131072); decim_1.configure(taps_11k0_decim_1.taps, 131072);
baseband_thread.start();
} }
void AISProcessor::execute(const buffer_c8_t& buffer) { void AISProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -51,9 +51,6 @@ class AISProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 2457600; static constexpr size_t baseband_fs = 2457600;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -77,6 +74,11 @@ class AISProcessor : public BasebandProcessor {
this->payload_handler(packet); this->payload_handler(packet);
}}; }};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
void consume_symbol(const float symbol); void consume_symbol(const float symbol);
void payload_handler(const baseband::Packet& packet); void payload_handler(const baseband::Packet& packet);
}; };

View File

@ -38,7 +38,6 @@
class NarrowbandAMAudio : public BasebandProcessor { class NarrowbandAMAudio : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
@ -46,9 +45,6 @@ class NarrowbandAMAudio : public BasebandProcessor {
static constexpr size_t decim_2_decimation_factor = 4; static constexpr size_t decim_2_decimation_factor = 4;
static constexpr size_t channel_filter_decimation_factor = 1; static constexpr size_t channel_filter_decimation_factor = 1;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -65,6 +61,7 @@ class NarrowbandAMAudio : public BasebandProcessor {
int32_t channel_filter_low_f = 0; int32_t channel_filter_low_f = 0;
int32_t channel_filter_high_f = 0; int32_t channel_filter_high_f = 0;
int32_t channel_filter_transition = 0; int32_t channel_filter_transition = 0;
bool configured{false};
bool modulation_ssb = false; bool modulation_ssb = false;
dsp::demodulate::AM demod_am{}; dsp::demodulate::AM demod_am{};
@ -74,7 +71,10 @@ class NarrowbandAMAudio : public BasebandProcessor {
SpectrumCollector channel_spectrum{}; SpectrumCollector channel_spectrum{};
bool configured{false}; /* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const AMConfigureMessage& message); void configure(const AMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message); void capture_config(const CaptureConfigMessage& message);

View File

@ -38,15 +38,11 @@
class WidebandFMAudio : public BasebandProcessor { class WidebandFMAudio : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 2000000; static constexpr size_t baseband_fs = 2000000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -55,8 +51,12 @@ class WidebandFMAudio : public BasebandProcessor {
AudioSpectrum audio_spectrum{}; AudioSpectrum audio_spectrum{};
TvCollector channel_spectrum{}; TvCollector channel_spectrum{};
std::array<complex16_t, 256> spectrum{}; std::array<complex16_t, 256> spectrum{};
bool configured{false}; bool configured{false};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const WFMConfigureMessage& message); void configure(const WFMConfigureMessage& message);
}; };

View File

@ -75,7 +75,6 @@ static uint16_t crc_ccitt_tab[256] = {
class APRSRxProcessor : public BasebandProcessor { class APRSRxProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
@ -90,9 +89,6 @@ class APRSRxProcessor : public BasebandProcessor {
IN_FRAME IN_FRAME
}; };
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -135,6 +131,10 @@ class APRSRxProcessor : public BasebandProcessor {
aprs::APRSPacket aprs_packet{}; aprs::APRSPacket aprs_packet{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const APRSRxConfigureMessage& message); void configure(const APRSRxConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message); void capture_config(const CaptureConfigMessage& message);
void parse_packet(); void parse_packet();

View File

@ -37,8 +37,6 @@ class AudioTXProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 1536000; static constexpr size_t baseband_fs = 1536000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit};
std::unique_ptr<StreamOutput> stream{}; std::unique_ptr<StreamOutput> stream{};
ToneGen tone_gen{}; ToneGen tone_gen{};
@ -61,6 +59,9 @@ class AudioTXProcessor : public BasebandProcessor {
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest}; RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -39,16 +39,12 @@
class BTLERxProcessor : public BasebandProcessor { class BTLERxProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 4000000; static constexpr size_t baseband_fs = 4000000;
static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2; static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -81,10 +77,13 @@ class BTLERxProcessor : public BasebandProcessor {
int RB_SIZE{1000}; int RB_SIZE{1000};
bool configured{false}; bool configured{false};
AFSKDataMessage data_message{false, 0};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const BTLERxConfigureMessage& message); void configure(const BTLERxConfigureMessage& message);
AFSKDataMessage data_message{false, 0};
}; };
#endif /*__PROC_BTLERX_H__*/ #endif /*__PROC_BTLERX_H__*/

View File

@ -31,13 +31,10 @@ CaptureProcessor::CaptureProcessor() {
decim_1.configure(taps_200k_decim_1.taps, 131072); decim_1.configure(taps_200k_decim_1.taps, 131072);
channel_spectrum.set_decimation_factor(1); channel_spectrum.set_decimation_factor(1);
ready = true; baseband_thread.start();
} }
void CaptureProcessor::execute(const buffer_c8_t& buffer) { void CaptureProcessor::execute(const buffer_c8_t& buffer) {
if (!ready)
return;
/* 2.4576MHz, 2048 samples */ /* 2.4576MHz, 2048 samples */
const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);

View File

@ -28,9 +28,7 @@
#include "rssi_thread.hpp" #include "rssi_thread.hpp"
#include "dsp_decimate.hpp" #include "dsp_decimate.hpp"
#include "spectrum_collector.hpp" #include "spectrum_collector.hpp"
#include "stream_input.hpp" #include "stream_input.hpp"
#include <array> #include <array>
@ -41,21 +39,12 @@ class CaptureProcessor : public BasebandProcessor {
CaptureProcessor(); CaptureProcessor();
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
// TODO: Repeated value needs to be transmitted from application side.
size_t baseband_fs = 3072000; size_t baseband_fs = 3072000;
static constexpr auto spectrum_rate_hz = 50.0f; static constexpr auto spectrum_rate_hz = 50.0f;
// HACK: BasebandThread starts immediately and starts sending data to members
// before they are initialized. This is a workaround to prevent uninit data problems.
bool ready = false;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -73,6 +62,11 @@ class CaptureProcessor : public BasebandProcessor {
size_t spectrum_interval_samples = 0; size_t spectrum_interval_samples = 0;
size_t spectrum_samples = 0; size_t spectrum_samples = 0;
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
void samplerate_config(const SamplerateConfigMessage& message); void samplerate_config(const SamplerateConfigMessage& message);
void capture_config(const CaptureConfigMessage& message); void capture_config(const CaptureConfigMessage& message);
}; };

View File

@ -67,9 +67,6 @@ class ERTProcessor : public BasebandProcessor {
const size_t samples_per_symbol = channel_sampling_rate / symbol_rate; const size_t samples_per_symbol = channel_sampling_rate / symbol_rate;
const float clock_recovery_rate = symbol_rate * 2; const float clock_recovery_rate = symbol_rate * 2;
BasebandThread baseband_thread{baseband_sampling_rate, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
clock_recovery::ClockRecovery<clock_recovery::FixedErrorFilter> clock_recovery{ clock_recovery::ClockRecovery<clock_recovery::FixedErrorFilter> clock_recovery{
clock_recovery_rate, clock_recovery_rate,
symbol_rate, symbol_rate,
@ -116,6 +113,10 @@ class ERTProcessor : public BasebandProcessor {
float offset_i{0.0f}; float offset_i{0.0f};
float offset_q{0.0f}; float offset_q{0.0f};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_sampling_rate, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
float abs(const complex8_t& v); float abs(const complex8_t& v);
}; };

View File

@ -29,14 +29,11 @@
class FSKProcessor : public BasebandProcessor { class FSKProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override; void on_message(const Message* const p) override;
private: private:
bool configured = false; bool configured = false;
BasebandThread baseband_thread{2280000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint32_t samples_per_bit{0}; uint32_t samples_per_bit{0};
uint32_t length{0}; uint32_t length{0};
@ -48,6 +45,9 @@ class FSKProcessor : public BasebandProcessor {
uint32_t phase{0}, sphase{0}; uint32_t phase{0}, sphase{0};
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{2280000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -29,7 +29,7 @@
#include "utility.hpp" #include "utility.hpp"
ReplayProcessor::ReplayProcessor() { GPSReplayProcessor::GPSReplayProcessor() {
channel_filter_low_f = taps_200k_decim_1.low_frequency_normalized * 1000000; channel_filter_low_f = taps_200k_decim_1.low_frequency_normalized * 1000000;
channel_filter_high_f = taps_200k_decim_1.high_frequency_normalized * 1000000; channel_filter_high_f = taps_200k_decim_1.high_frequency_normalized * 1000000;
channel_filter_transition = taps_200k_decim_1.transition_normalized * 1000000; channel_filter_transition = taps_200k_decim_1.transition_normalized * 1000000;
@ -39,9 +39,10 @@ ReplayProcessor::ReplayProcessor() {
channel_spectrum.set_decimation_factor(1); channel_spectrum.set_decimation_factor(1);
configured = false; configured = false;
baseband_thread.start();
} }
void ReplayProcessor::execute(const buffer_c8_t& buffer) { void GPSReplayProcessor::execute(const buffer_c8_t& buffer) {
/* 2.6MHz, 2048 samples */ /* 2.6MHz, 2048 samples */
if (!configured || !stream) return; if (!configured || !stream) return;
@ -75,7 +76,7 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
} }
} }
void ReplayProcessor::on_message(const Message* const message) { void GPSReplayProcessor::on_message(const Message* const message) {
switch (message->id) { switch (message->id) {
case Message::ID::UpdateSpectrum: case Message::ID::UpdateSpectrum:
case Message::ID::SpectrumStreamingConfig: case Message::ID::SpectrumStreamingConfig:
@ -102,13 +103,13 @@ void ReplayProcessor::on_message(const Message* const message) {
} }
} }
void ReplayProcessor::samplerate_config(const SamplerateConfigMessage& message) { void GPSReplayProcessor::samplerate_config(const SamplerateConfigMessage& message) {
baseband_fs = message.sample_rate; baseband_fs = message.sample_rate;
baseband_thread.set_sampling_rate(baseband_fs); baseband_thread.set_sampling_rate(baseband_fs);
spectrum_interval_samples = baseband_fs / spectrum_rate_hz; spectrum_interval_samples = baseband_fs / spectrum_rate_hz;
} }
void ReplayProcessor::replay_config(const ReplayConfigMessage& message) { void GPSReplayProcessor::replay_config(const ReplayConfigMessage& message) {
if (message.config) { if (message.config) {
stream = std::make_unique<StreamOutput>(message.config); stream = std::make_unique<StreamOutput>(message.config);
@ -120,7 +121,7 @@ void ReplayProcessor::replay_config(const ReplayConfigMessage& message) {
} }
int main() { int main() {
EventDispatcher event_dispatcher{std::make_unique<ReplayProcessor>()}; EventDispatcher event_dispatcher{std::make_unique<GPSReplayProcessor>()};
event_dispatcher.run(); event_dispatcher.run();
return 0; return 0;
} }

View File

@ -34,20 +34,17 @@
#include <array> #include <array>
#include <memory> #include <memory>
class ReplayProcessor : public BasebandProcessor { class GPSReplayProcessor : public BasebandProcessor {
public: public:
ReplayProcessor(); GPSReplayProcessor();
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
size_t baseband_fs = 3072000; size_t baseband_fs = 3072000;
static constexpr auto spectrum_rate_hz = 50.0f; static constexpr auto spectrum_rate_hz = 50.0f;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit};
std::array<complex8_t, 2048> iq{}; std::array<complex8_t, 2048> iq{};
const buffer_c8_t iq_buffer{ const buffer_c8_t iq_buffer{
iq.data(), iq.data(),
@ -72,6 +69,10 @@ class ReplayProcessor : public BasebandProcessor {
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest}; RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Transmit, /*auto_start*/ false};
}; };
#endif /*__PROC_GPS_SIM_HPP__*/ #endif /*__PROC_GPS_SIM_HPP__*/

View File

@ -33,14 +33,11 @@ using namespace jammer;
class JammerProcessor : public BasebandProcessor { class JammerProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
bool configured{false}; bool configured{false};
BasebandThread baseband_thread{3072000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
JammerChannel* jammer_channels{}; JammerChannel* jammer_channels{};
JammerType noise_type{}; JammerType noise_type{};
@ -54,6 +51,9 @@ class JammerProcessor : public BasebandProcessor {
int8_t sample{0}; int8_t sample{0};
int8_t re{0}, im{0}; int8_t re{0}, im{0};
RetuneMessage message{}; RetuneMessage message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{3072000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -32,7 +32,6 @@
class MicTXProcessor : public BasebandProcessor { class MicTXProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
@ -40,8 +39,6 @@ class MicTXProcessor : public BasebandProcessor {
bool configured{false}; bool configured{false};
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit};
int16_t audio_data[64]; int16_t audio_data[64];
buffer_s16_t audio_buffer{ buffer_s16_t audio_buffer{
audio_data, audio_data,
@ -74,6 +71,9 @@ class MicTXProcessor : public BasebandProcessor {
AudioLevelReportMessage level_message{}; AudioLevelReportMessage level_message{};
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -42,15 +42,11 @@
class NarrowbandFMAudio : public BasebandProcessor { class NarrowbandFMAudio : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 3072000; static constexpr size_t baseband_fs = 3072000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -97,12 +93,16 @@ class NarrowbandFMAudio : public BasebandProcessor {
static constexpr float ki = 1.0f / k; static constexpr float ki = 1.0f / k;
bool configured{false}; bool configured{false};
// RequestSignalMessage sig_message { RequestSignalMessage::Signal::Squelched };
CodedSquelchMessage ctcss_message{0};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void pitch_rssi_config(const PitchRSSIConfigureMessage& message); void pitch_rssi_config(const PitchRSSIConfigureMessage& message);
void configure(const NBFMConfigureMessage& message); void configure(const NBFMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message); void capture_config(const CaptureConfigMessage& message);
// RequestSignalMessage sig_message { RequestSignalMessage::Signal::Squelched };
CodedSquelchMessage ctcss_message{0};
}; };
#endif /*__PROC_NFM_AUDIO_H__*/ #endif /*__PROC_NFM_AUDIO_H__*/

View File

@ -31,7 +31,8 @@ class NOOPProcessor : public BasebandProcessor {
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
private: private:
BasebandThread baseband_thread{1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit}; /* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{1536000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -39,16 +39,12 @@
class NRFRxProcessor : public BasebandProcessor { class NRFRxProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 4000000; static constexpr size_t baseband_fs = 4000000;
static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2; static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -82,10 +78,13 @@ class NRFRxProcessor : public BasebandProcessor {
int RB_SIZE{1000}; int RB_SIZE{1000};
bool configured{false}; bool configured{false};
AFSKDataMessage data_message{false, 0};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const NRFRxConfigureMessage& message); void configure(const NRFRxConfigureMessage& message);
AFSKDataMessage data_message{false, 0};
}; };
#endif /*__PROC_NRFRX_H__*/ #endif /*__PROC_NRFRX_H__*/

View File

@ -29,14 +29,11 @@
class OOKProcessor : public BasebandProcessor { class OOKProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override; void on_message(const Message* const p) override;
private: private:
bool configured = false; bool configured = false;
BasebandThread baseband_thread{2280000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint32_t samples_per_bit{0}; uint32_t samples_per_bit{0};
uint8_t repeat{0}; uint8_t repeat{0};
uint32_t length{0}; uint32_t length{0};
@ -67,6 +64,9 @@ class OOKProcessor : public BasebandProcessor {
size_t scan_progress{0}; size_t scan_progress{0};
uint8_t scan_done{true}; uint8_t scan_done{true};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{2280000, this, baseband::Direction::Transmit};
size_t duval_algo_step(); size_t duval_algo_step();
void scan_process(const buffer_c8_t& buffer); void scan_process(const buffer_c8_t& buffer);
bool scan_init(unsigned int order); bool scan_init(unsigned int order);

View File

@ -129,7 +129,6 @@ class SmoothVals {
class POCSAGProcessor : public BasebandProcessor { class POCSAGProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
int OnDataFrame(int len, int baud); int OnDataFrame(int len, int baud);
@ -138,9 +137,6 @@ class POCSAGProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 3072000; static constexpr size_t baseband_fs = 3072000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -166,7 +162,6 @@ class POCSAGProcessor : public BasebandProcessor {
// ---------------------------------------- // ----------------------------------------
// Frame extractraction methods and members // Frame extractraction methods and members
// ---------------------------------------- // ----------------------------------------
private:
void initFrameExtraction(); void initFrameExtraction();
struct FIFOStruct { struct FIFOStruct {
unsigned long codeword; unsigned long codeword;
@ -219,6 +214,10 @@ class POCSAGProcessor : public BasebandProcessor {
bool m_gotSync{false}; bool m_gotSync{false};
int m_numCode{0}; int m_numCode{0};
bool m_inverted{false}; bool m_inverted{false};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
}; };
#endif /*__PROC_POCSAG_H__*/ #endif /*__PROC_POCSAG_H__*/

View File

@ -33,14 +33,11 @@
class RDSProcessor : public BasebandProcessor { class RDSProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
uint32_t* rdsdata{}; uint32_t* rdsdata{};
BasebandThread baseband_thread{2280000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint16_t message_length{0}; uint16_t message_length{0};
int8_t re{0}, im{0}; int8_t re{0}, im{0};
uint8_t mphase{0}, s{0}; uint8_t mphase{0}, s{0};
@ -132,6 +129,9 @@ class RDSProcessor : public BasebandProcessor {
0, -14, -27, -41, -53, -66, -77, -88, 0, -14, -27, -41, -53, -66, -77, -88,
-99, -109, -118, -126, -134, -141, -147, -152, -99, -109, -118, -126, -134, -141, -147, -152,
-157, -160, -163, -166, -167, -168, -168, -167}; -157, -160, -163, -166, -167, -168, -168, -167};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{2280000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -38,6 +38,7 @@ ReplayProcessor::ReplayProcessor() {
channel_spectrum.set_decimation_factor(1); channel_spectrum.set_decimation_factor(1);
configured = false; configured = false;
baseband_thread.start();
} }
void ReplayProcessor::execute(const buffer_c8_t& buffer) { void ReplayProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -38,15 +38,12 @@ class ReplayProcessor : public BasebandProcessor {
ReplayProcessor(); ReplayProcessor();
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
size_t baseband_fs = 3072000; size_t baseband_fs = 3072000;
static constexpr auto spectrum_rate_hz = 50.0f; static constexpr auto spectrum_rate_hz = 50.0f;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit};
std::array<complex16_t, 256> iq{}; std::array<complex16_t, 256> iq{};
const buffer_c16_t iq_buffer{ const buffer_c16_t iq_buffer{
iq.data(), iq.data(),
@ -71,6 +68,10 @@ class ReplayProcessor : public BasebandProcessor {
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest}; RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Transmit, /*auto_start*/ false};
}; };
#endif /*__PROC_REPLAY_HPP__*/ #endif /*__PROC_REPLAY_HPP__*/

View File

@ -30,14 +30,11 @@
class SigGenProcessor : public BasebandProcessor { class SigGenProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const msg) override; void on_message(const Message* const msg) override;
private: private:
bool configured{false}; bool configured{false};
BasebandThread baseband_thread{1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint32_t tone_delta{0}, fm_delta{}, tone_phase{0}; uint32_t tone_delta{0}, fm_delta{}, tone_phase{0};
uint8_t tone_shape{}; uint8_t tone_shape{};
uint32_t sample_count{0}; uint32_t sample_count{0};
@ -51,6 +48,9 @@ class SigGenProcessor : public BasebandProcessor {
// uint8_t lfsr { }, bit { }; // Finally not used lfsr of 8 bits , bit must be 8-bit to allow bit<<7 later in the code */ // uint8_t lfsr { }, bit { }; // Finally not used lfsr of 8 bits , bit must be 8-bit to allow bit<<7 later in the code */
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{1536000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -35,6 +35,7 @@ SondeProcessor::SondeProcessor() {
audio_output.configure(false); audio_output.configure(false);
tone_gen.configure(BEEP_BASE_FREQ, 1.0, ToneGen::tone_type::sine, AUDIO_SAMPLE_RATE); tone_gen.configure(BEEP_BASE_FREQ, 1.0, ToneGen::tone_type::sine, AUDIO_SAMPLE_RATE);
baseband_thread.start();
} }
void SondeProcessor::execute(const buffer_c8_t& buffer) { void SondeProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -131,9 +131,6 @@ class SondeProcessor : public BasebandProcessor {
ToneGen tone_gen{}; ToneGen tone_gen{};
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -179,6 +176,11 @@ class SondeProcessor : public BasebandProcessor {
shared_memory.application_queue.push(message); shared_memory.application_queue.push(message);
}}; }};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
void play_beep(); void play_beep();
void stop_beep(); void stop_beep();

View File

@ -33,7 +33,9 @@ class SpectrumPainterProcessor : public BasebandProcessor {
private: private:
bool configured{false}; bool configured{false};
BasebandThread baseband_thread{3072000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{3072000, this, baseband::Direction::Transmit};
Thread* thread{nullptr}; Thread* thread{nullptr};
protected: protected:

View File

@ -33,7 +33,6 @@ using namespace sstv;
class SSTVTXProcessor : public BasebandProcessor { class SSTVTXProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override; void on_message(const Message* const p) override;
private: private:
@ -56,8 +55,6 @@ class SSTVTXProcessor : public BasebandProcessor {
bool configured{false}; bool configured{false};
BasebandThread baseband_thread{3072000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
uint32_t vis_code_sequence[10]{}; uint32_t vis_code_sequence[10]{};
sstv_scanline scanline_buffer[2]{}; sstv_scanline scanline_buffer[2]{};
uint8_t buffer_flip{0}, substep{0}; uint8_t buffer_flip{0}, substep{0};
@ -76,6 +73,9 @@ class SSTVTXProcessor : public BasebandProcessor {
int8_t re{}, im{}; int8_t re{}, im{};
RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest}; RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{3072000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -29,6 +29,7 @@
TestProcessor::TestProcessor() { TestProcessor::TestProcessor() {
decim_0.configure(taps_11k0_decim_0.taps, 33554432); decim_0.configure(taps_11k0_decim_0.taps, 33554432);
decim_1.configure(taps_11k0_decim_1.taps, 131072); decim_1.configure(taps_11k0_decim_1.taps, 131072);
baseband_thread.start();
} }
void TestProcessor::execute(const buffer_c8_t& buffer) { void TestProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -52,9 +52,6 @@ class TestProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 2457600 * 2; static constexpr size_t baseband_fs = 2457600 * 2;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -80,6 +77,11 @@ class TestProcessor : public BasebandProcessor {
const TestAppPacketMessage message{packet}; const TestAppPacketMessage message{packet};
shared_memory.application_queue.push(message); shared_memory.application_queue.push(message);
}}; }};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
}; };
#endif /*__PROC_TEST_H__*/ #endif /*__PROC_TEST_H__*/

View File

@ -31,14 +31,11 @@
class TonesProcessor : public BasebandProcessor { class TonesProcessor : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const p) override; void on_message(const Message* const p) override;
private: private:
bool configured = false; bool configured = false;
BasebandThread baseband_thread{1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit};
std::array<int16_t, 32> audio{}; // 2048/64 std::array<int16_t, 32> audio{}; // 2048/64
const buffer_s16_t audio_buffer{ const buffer_s16_t audio_buffer{
(int16_t*)audio.data(), (int16_t*)audio.data(),
@ -63,6 +60,9 @@ class TonesProcessor : public BasebandProcessor {
TXProgressMessage txprogress_message{}; TXProgressMessage txprogress_message{};
AudioOutput audio_output{}; AudioOutput audio_output{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{1536000, this, baseband::Direction::Transmit};
}; };
#endif #endif

View File

@ -28,6 +28,7 @@
TPMSProcessor::TPMSProcessor() { TPMSProcessor::TPMSProcessor() {
decim_0.configure(taps_200k_decim_0.taps, 33554432); decim_0.configure(taps_200k_decim_0.taps, 33554432);
decim_1.configure(taps_200k_decim_1.taps, 131072); decim_1.configure(taps_200k_decim_1.taps, 131072);
baseband_thread.start();
} }
void TPMSProcessor::execute(const buffer_c8_t& buffer) { void TPMSProcessor::execute(const buffer_c8_t& buffer) {

View File

@ -74,9 +74,6 @@ class TPMSProcessor : public BasebandProcessor {
private: private:
static constexpr size_t baseband_fs = 2457600; static constexpr size_t baseband_fs = 2457600;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -141,6 +138,11 @@ class TPMSProcessor : public BasebandProcessor {
const TPMSPacketMessage message{tpms::SignalType::OOK_8k4_Schrader, packet}; const TPMSPacketMessage message{tpms::SignalType::OOK_8k4_Schrader, packet};
shared_memory.application_queue.push(message); shared_memory.application_queue.push(message);
}}; }};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};
}; };
#endif /*__PROC_TPMS_H__*/ #endif /*__PROC_TPMS_H__*/

View File

@ -38,16 +38,12 @@
class WidebandFMAudio : public BasebandProcessor { class WidebandFMAudio : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
static constexpr size_t baseband_fs = 3072000; static constexpr size_t baseband_fs = 3072000;
static constexpr auto spectrum_rate_hz = 50.0f; static constexpr auto spectrum_rate_hz = 50.0f;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive};
RSSIThread rssi_thread{NORMALPRIO + 10};
std::array<complex16_t, 512> dst{}; std::array<complex16_t, 512> dst{};
const buffer_c16_t dst_buffer{ const buffer_c16_t dst_buffer{
dst.data(), dst.data(),
@ -93,6 +89,11 @@ class WidebandFMAudio : public BasebandProcessor {
size_t spectrum_samples = 0; size_t spectrum_samples = 0;
bool configured{false}; bool configured{false};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
void configure(const WFMConfigureMessage& message); void configure(const WFMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message); void capture_config(const CaptureConfigMessage& message);
void post_message(const buffer_c16_t& data); void post_message(const buffer_c16_t& data);

View File

@ -37,22 +37,20 @@
class WidebandSpectrum : public BasebandProcessor { class WidebandSpectrum : public BasebandProcessor {
public: public:
void execute(const buffer_c8_t& buffer) override; void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override; void on_message(const Message* const message) override;
private: private:
bool configured = false; bool configured = false;
size_t baseband_fs = 20000000; size_t baseband_fs = 20000000;
BasebandThread baseband_thread{baseband_fs, this, NORMALPRIO + 20};
RSSIThread rssi_thread{NORMALPRIO + 10};
SpectrumCollector channel_spectrum{}; SpectrumCollector channel_spectrum{};
std::array<complex16_t, 256> spectrum{}; std::array<complex16_t, 256> spectrum{};
size_t phase = 0, trigger = 127; size_t phase = 0, trigger = 127;
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
RSSIThread rssi_thread{};
}; };
#endif /*__PROC_WIDEBAND_SPECTRUM_H__*/ #endif /*__PROC_WIDEBAND_SPECTRUM_H__*/

View File

@ -32,17 +32,26 @@ WORKING_AREA(rssi_thread_wa, 128);
Thread* RSSIThread::thread = nullptr; Thread* RSSIThread::thread = nullptr;
RSSIThread::RSSIThread(const tprio_t priority) { RSSIThread::RSSIThread(bool auto_start, tprio_t priority)
thread = chThdCreateStatic(rssi_thread_wa, sizeof(rssi_thread_wa), : priority_{priority} {
priority, ThreadBase::fn, if (auto_start) start();
this);
} }
RSSIThread::~RSSIThread() { RSSIThread::~RSSIThread() {
if (thread) {
chThdTerminate(thread); chThdTerminate(thread);
chThdWait(thread); chThdWait(thread);
thread = nullptr; thread = nullptr;
} }
}
void RSSIThread::start() {
if (!thread) {
thread = chThdCreateStatic(
rssi_thread_wa, sizeof(rssi_thread_wa),
priority_, ThreadBase::fn, this);
}
}
void RSSIThread::run() { void RSSIThread::run() {
rf::rssi::init(); rf::rssi::init();

View File

@ -25,20 +25,32 @@
#include "thread_base.hpp" #include "thread_base.hpp"
#include <ch.h> #include <ch.h>
#include <cstdint> #include <cstdint>
/* NB: Because ThreadBase threads start when then are initialized (by default),
* they should be the last members in a Processor class to ensure the rest of the
* members are fully initialized before data handling starts. If the Procressor
* needs to do additional initialization (in its ctor), set 'auto_start' to false
* and manually call 'start()' on the thread.
* This isn't as relevant for RSSIThread which is entirely self-contained, but
* it's good practice to keep all the thread-init together. */
class RSSIThread : public ThreadBase { class RSSIThread : public ThreadBase {
public: public:
RSSIThread(const tprio_t priority); RSSIThread(
bool auto_start = true,
tprio_t priority = (NORMALPRIO + 10));
~RSSIThread(); ~RSSIThread();
void start() override;
private: private:
void run() override; void run() override;
static Thread* thread; const tprio_t priority_;
const uint32_t sampling_rate{400000}; static Thread* thread;
static constexpr uint32_t sampling_rate{400000};
}; };
#endif /*__RSSI_THREAD_H__*/ #endif /*__RSSI_THREAD_H__*/

View File

@ -28,6 +28,8 @@ class ThreadBase {
public: public:
virtual ~ThreadBase() = default; virtual ~ThreadBase() = default;
virtual void start() = 0;
protected: protected:
static msg_t fn(void* arg) { static msg_t fn(void* arg) {
auto obj = static_cast<ThreadBase*>(arg); auto obj = static_cast<ThreadBase*>(arg);