mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Use CaptureConfig to share state between cores.
Remove awful FIFO_HACK. TODO: Lots of repeated code... TODO: Capture thread is signalled too frequently.
This commit is contained in:
parent
67eb62ec12
commit
d5e21ce972
@ -37,21 +37,28 @@ using namespace hackrf::one;
|
||||
|
||||
class StreamOutput {
|
||||
public:
|
||||
StreamOutput(
|
||||
) : fifo { reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK) }
|
||||
{
|
||||
StreamOutput() {
|
||||
shared_memory.baseband_queue.push_and_wait(
|
||||
CaptureConfigMessage { &config }
|
||||
);
|
||||
}
|
||||
|
||||
~StreamOutput() {
|
||||
shared_memory.baseband_queue.push_and_wait(
|
||||
CaptureConfigMessage { nullptr }
|
||||
);
|
||||
}
|
||||
|
||||
size_t available() {
|
||||
return fifo->len();
|
||||
return config.fifo->len();
|
||||
}
|
||||
|
||||
size_t read(void* const data, const size_t length) {
|
||||
return fifo->out(reinterpret_cast<uint8_t*>(data), length);
|
||||
return config.fifo->out(reinterpret_cast<uint8_t*>(data), length);
|
||||
}
|
||||
|
||||
private:
|
||||
FIFO<uint8_t>* const fifo;
|
||||
CaptureConfig config;
|
||||
};
|
||||
|
||||
class CaptureThread {
|
||||
@ -66,23 +73,27 @@ public:
|
||||
}
|
||||
|
||||
~CaptureThread() {
|
||||
chThdTerminate(thread);
|
||||
chEvtSignal(thread, EVT_FIFO_HIGHWATER);
|
||||
const auto success = chThdWait(thread);
|
||||
const auto thread_tmp = thread;
|
||||
|
||||
if( thread_tmp ) {
|
||||
thread = nullptr;
|
||||
chThdTerminate(thread_tmp);
|
||||
chEvtSignal(thread_tmp, EVT_FIFO_HIGHWATER);
|
||||
const auto success = chThdWait(thread_tmp);
|
||||
|
||||
if( !success ) {
|
||||
led_tx.on();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void check_fifo_isr() {
|
||||
if( (shared_memory.FIFO_HACK != nullptr) && (thread != nullptr) ) {
|
||||
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK);
|
||||
if( fifo->len() >= write_size ) {
|
||||
// TODO: Prevent over-signalling by transmitting a set of
|
||||
// flags from the baseband core.
|
||||
if( thread ) {
|
||||
chEvtSignalI(thread, EVT_FIFO_HIGHWATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr size_t write_size = 16384;
|
||||
|
@ -255,6 +255,4 @@ void EventDispatcher::init_message_queues() {
|
||||
new (&shared_memory.application_queue) MessageQueue(
|
||||
shared_memory.application_queue_data, SharedMemory::application_queue_k
|
||||
);
|
||||
|
||||
shared_memory.FIFO_HACK = nullptr;
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ void NarrowbandAMAudio::on_message(const Message* const message) {
|
||||
configure(*reinterpret_cast<const AMConfigureMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -93,3 +97,11 @@ void NarrowbandAMAudio::configure(const AMConfigureMessage& message) {
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(14, *message.config));
|
||||
} else {
|
||||
audio_output.set_stream(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ private:
|
||||
|
||||
bool configured { false };
|
||||
void configure(const AMConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
|
||||
buffer_f32_t demodulate(const buffer_c16_t& channel);
|
||||
};
|
||||
|
@ -44,8 +44,6 @@ CaptureProcessor::CaptureProcessor() {
|
||||
spectrum_samples = 0;
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);
|
||||
|
||||
stream = std::make_unique<StreamInput>(15);
|
||||
}
|
||||
|
||||
void CaptureProcessor::execute(const buffer_c8_t& buffer) {
|
||||
@ -76,7 +74,19 @@ void CaptureProcessor::on_message(const Message* const message) {
|
||||
channel_spectrum.on_message(message);
|
||||
break;
|
||||
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
stream = std::make_unique<StreamInput>(15, *message.config);
|
||||
} else {
|
||||
stream.reset();
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ private:
|
||||
SpectrumCollector channel_spectrum;
|
||||
size_t spectrum_interval_samples = 0;
|
||||
size_t spectrum_samples = 0;
|
||||
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
};
|
||||
|
||||
#endif/*__PROC_CAPTURE_HPP__*/
|
||||
|
@ -53,6 +53,10 @@ void NarrowbandFMAudio::on_message(const Message* const message) {
|
||||
configure(*reinterpret_cast<const NBFMConfigureMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -81,3 +85,11 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) {
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(14, *message.config));
|
||||
} else {
|
||||
audio_output.set_stream(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
|
||||
bool configured { false };
|
||||
void configure(const NBFMConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
};
|
||||
|
||||
#endif/*__PROC_NFM_AUDIO_H__*/
|
||||
|
@ -81,6 +81,10 @@ void WidebandFMAudio::on_message(const Message* const message) {
|
||||
configure(*reinterpret_cast<const WFMConfigureMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -110,3 +114,11 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(15, *message.config));
|
||||
} else {
|
||||
audio_output.set_stream(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ private:
|
||||
|
||||
bool configured { false };
|
||||
void configure(const WFMConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
};
|
||||
|
||||
#endif/*__PROC_WFM_AUDIO_H__*/
|
||||
|
@ -32,18 +32,12 @@
|
||||
|
||||
class StreamInput {
|
||||
public:
|
||||
StreamInput(const size_t K) :
|
||||
StreamInput(const size_t K, CaptureConfig& config) :
|
||||
K { K },
|
||||
data { std::make_unique<uint8_t[]>(1UL << K) },
|
||||
fifo { data.get(), K }
|
||||
{
|
||||
// TODO: Send stream creation message.
|
||||
shared_memory.FIFO_HACK = &fifo;
|
||||
}
|
||||
|
||||
~StreamInput() {
|
||||
// TODO: Send stream distruction message.
|
||||
shared_memory.FIFO_HACK = nullptr;
|
||||
config.fifo = &fifo;
|
||||
}
|
||||
|
||||
size_t write(const void* const data, const size_t length) {
|
||||
|
@ -40,7 +40,6 @@ struct SharedMemory {
|
||||
uint8_t baseband_queue_data[1 << baseband_queue_k];
|
||||
MessageQueue application_queue;
|
||||
uint8_t application_queue_data[1 << application_queue_k];
|
||||
void* FIFO_HACK;
|
||||
|
||||
// TODO: M0 should directly configure and control DMA channel that is
|
||||
// acquiring ADC samples.
|
||||
|
Loading…
Reference in New Issue
Block a user