Move FIFO and write size to CaptureConfig structure.

Now configured from baseband, where write size and appropriate FIFO size is known.
This commit is contained in:
Jared Boone 2016-04-26 22:26:30 -07:00
parent 01fc6b9bc9
commit 91ee2dbb67
13 changed files with 71 additions and 32 deletions

View file

@ -37,13 +37,19 @@ using namespace hackrf::one;
class StreamOutput {
public:
StreamOutput() {
StreamOutput(
const size_t write_size_log2,
const size_t buffer_count_log2
) : config { write_size_log2, buffer_count_log2 }
{
shared_memory.baseband_queue.push_and_wait(
CaptureConfigMessage { &config }
);
fifo = config.fifo;
}
~StreamOutput() {
fifo = nullptr;
shared_memory.baseband_queue.push_and_wait(
CaptureConfigMessage { nullptr }
);
@ -57,6 +63,8 @@ public:
return config.fifo->out(reinterpret_cast<uint8_t*>(data), length);
}
static FIFO<uint8_t>* fifo;
private:
CaptureConfig config;
};
@ -64,9 +72,13 @@ private:
class CaptureThread {
public:
CaptureThread(
std::string file_path
) : file_path { std::move(file_path) },
write_buffer { std::make_unique<std::array<uint8_t, write_size>>() }
std::string file_path,
size_t write_size_log2,
size_t buffer_count_log2
) : write_size_log2 { write_size_log2 },
write_size { 1U << write_size_log2 },
buffer_count_log2 { buffer_count_log2 },
file_path { std::move(file_path) }
{
// Need significant stack for FATFS
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, CaptureThread::static_fn, this);
@ -90,16 +102,17 @@ public:
static void check_fifo_isr() {
// TODO: Prevent over-signalling by transmitting a set of
// flags from the baseband core.
if( thread ) {
const auto fifo = StreamOutput::fifo;
if( fifo ) {
chEvtSignalI(thread, EVT_MASK_CAPTURE_THREAD);
}
}
private:
static constexpr size_t write_size = 16384;
const size_t write_size_log2;
const size_t write_size;
const size_t buffer_count_log2;
const std::string file_path;
std::unique_ptr<std::array<uint8_t, write_size>> write_buffer;
File file;
static Thread* thread;
@ -113,12 +126,17 @@ private:
return false;
}
StreamOutput stream;
const auto write_buffer = std::make_unique<uint8_t[]>(write_size);
if( !write_buffer ) {
return false;
}
StreamOutput stream { write_size_log2, buffer_count_log2 };
while( !chThdShouldTerminate() ) {
chEvtWaitAny(EVT_MASK_CAPTURE_THREAD);
while( stream.available() >= write_buffer->size() ) {
while( stream.available() >= write_size ) {
if( !transfer(stream, write_buffer.get()) ) {
return false;
}
@ -128,14 +146,14 @@ private:
return true;
}
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {
bool transfer(StreamOutput& stream, uint8_t* const write_buffer) {
bool success = false;
led_usb.on();
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
if( bytes_to_write == write_buffer->size() ) {
if( file.write(write_buffer->data(), write_buffer->size()) ) {
const auto bytes_to_write = stream.read(write_buffer, write_size);
if( bytes_to_write == write_size ) {
if( file.write(write_buffer, write_size) ) {
success = true;
}
}