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:
Jared Boone 2016-04-23 15:07:44 -07:00
parent 67eb62ec12
commit d5e21ce972
12 changed files with 82 additions and 29 deletions

View File

@ -37,21 +37,28 @@ using namespace hackrf::one;
class StreamOutput { class StreamOutput {
public: public:
StreamOutput( StreamOutput() {
) : fifo { reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK) } shared_memory.baseband_queue.push_and_wait(
{ CaptureConfigMessage { &config }
);
}
~StreamOutput() {
shared_memory.baseband_queue.push_and_wait(
CaptureConfigMessage { nullptr }
);
} }
size_t available() { size_t available() {
return fifo->len(); return config.fifo->len();
} }
size_t read(void* const data, const size_t length) { 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: private:
FIFO<uint8_t>* const fifo; CaptureConfig config;
}; };
class CaptureThread { class CaptureThread {
@ -66,21 +73,25 @@ public:
} }
~CaptureThread() { ~CaptureThread() {
chThdTerminate(thread); const auto thread_tmp = thread;
chEvtSignal(thread, EVT_FIFO_HIGHWATER);
const auto success = chThdWait(thread);
if( !success ) { if( thread_tmp ) {
led_tx.on(); 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() { static void check_fifo_isr() {
if( (shared_memory.FIFO_HACK != nullptr) && (thread != nullptr) ) { // TODO: Prevent over-signalling by transmitting a set of
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK); // flags from the baseband core.
if( fifo->len() >= write_size ) { if( thread ) {
chEvtSignalI(thread, EVT_FIFO_HIGHWATER); chEvtSignalI(thread, EVT_FIFO_HIGHWATER);
}
} }
} }

View File

@ -255,6 +255,4 @@ void EventDispatcher::init_message_queues() {
new (&shared_memory.application_queue) MessageQueue( new (&shared_memory.application_queue) MessageQueue(
shared_memory.application_queue_data, SharedMemory::application_queue_k shared_memory.application_queue_data, SharedMemory::application_queue_k
); );
shared_memory.FIFO_HACK = nullptr;
} }

View File

@ -63,6 +63,10 @@ void NarrowbandAMAudio::on_message(const Message* const message) {
configure(*reinterpret_cast<const AMConfigureMessage*>(message)); configure(*reinterpret_cast<const AMConfigureMessage*>(message));
break; break;
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
break;
default: default:
break; break;
} }
@ -93,3 +97,11 @@ void NarrowbandAMAudio::configure(const AMConfigureMessage& message) {
configured = true; 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);
}
}

View File

@ -72,6 +72,7 @@ private:
bool configured { false }; bool configured { false };
void configure(const AMConfigureMessage& message); void configure(const AMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message);
buffer_f32_t demodulate(const buffer_c16_t& channel); buffer_f32_t demodulate(const buffer_c16_t& channel);
}; };

View File

@ -44,8 +44,6 @@ CaptureProcessor::CaptureProcessor() {
spectrum_samples = 0; spectrum_samples = 0;
channel_spectrum.set_decimation_factor(1); channel_spectrum.set_decimation_factor(1);
stream = std::make_unique<StreamInput>(15);
} }
void CaptureProcessor::execute(const buffer_c8_t& buffer) { 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); channel_spectrum.on_message(message);
break; break;
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
break;
default: default:
break; break;
} }
} }
void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
if( message.config ) {
stream = std::make_unique<StreamInput>(15, *message.config);
} else {
stream.reset();
}
}

View File

@ -61,6 +61,8 @@ private:
SpectrumCollector channel_spectrum; SpectrumCollector channel_spectrum;
size_t spectrum_interval_samples = 0; size_t spectrum_interval_samples = 0;
size_t spectrum_samples = 0; size_t spectrum_samples = 0;
void capture_config(const CaptureConfigMessage& message);
}; };
#endif/*__PROC_CAPTURE_HPP__*/ #endif/*__PROC_CAPTURE_HPP__*/

View File

@ -53,6 +53,10 @@ void NarrowbandFMAudio::on_message(const Message* const message) {
configure(*reinterpret_cast<const NBFMConfigureMessage*>(message)); configure(*reinterpret_cast<const NBFMConfigureMessage*>(message));
break; break;
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
break;
default: default:
break; break;
} }
@ -81,3 +85,11 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) {
configured = true; 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);
}
}

View File

@ -66,6 +66,7 @@ private:
bool configured { false }; bool configured { false };
void configure(const NBFMConfigureMessage& message); void configure(const NBFMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message);
}; };
#endif/*__PROC_NFM_AUDIO_H__*/ #endif/*__PROC_NFM_AUDIO_H__*/

View File

@ -81,6 +81,10 @@ void WidebandFMAudio::on_message(const Message* const message) {
configure(*reinterpret_cast<const WFMConfigureMessage*>(message)); configure(*reinterpret_cast<const WFMConfigureMessage*>(message));
break; break;
case Message::ID::CaptureConfig:
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
break;
default: default:
break; break;
} }
@ -110,3 +114,11 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
configured = true; 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);
}
}

View File

@ -68,6 +68,7 @@ private:
bool configured { false }; bool configured { false };
void configure(const WFMConfigureMessage& message); void configure(const WFMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message);
}; };
#endif/*__PROC_WFM_AUDIO_H__*/ #endif/*__PROC_WFM_AUDIO_H__*/

View File

@ -32,18 +32,12 @@
class StreamInput { class StreamInput {
public: public:
StreamInput(const size_t K) : StreamInput(const size_t K, CaptureConfig& config) :
K { K }, K { K },
data { std::make_unique<uint8_t[]>(1UL << K) }, data { std::make_unique<uint8_t[]>(1UL << K) },
fifo { data.get(), K } fifo { data.get(), K }
{ {
// TODO: Send stream creation message. config.fifo = &fifo;
shared_memory.FIFO_HACK = &fifo;
}
~StreamInput() {
// TODO: Send stream distruction message.
shared_memory.FIFO_HACK = nullptr;
} }
size_t write(const void* const data, const size_t length) { size_t write(const void* const data, const size_t length) {

View File

@ -40,7 +40,6 @@ struct SharedMemory {
uint8_t baseband_queue_data[1 << baseband_queue_k]; uint8_t baseband_queue_data[1 << baseband_queue_k];
MessageQueue application_queue; MessageQueue application_queue;
uint8_t application_queue_data[1 << application_queue_k]; uint8_t application_queue_data[1 << application_queue_k];
void* FIFO_HACK;
// TODO: M0 should directly configure and control DMA channel that is // TODO: M0 should directly configure and control DMA channel that is
// acquiring ADC samples. // acquiring ADC samples.