mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-12-02 21:11:47 +00:00
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:
@@ -322,7 +322,7 @@ void AnalogAudioView::record_start() {
|
||||
return;
|
||||
}
|
||||
|
||||
capture_thread = std::make_unique<CaptureThread>(filename);
|
||||
capture_thread = std::make_unique<CaptureThread>(filename, 12, 2);
|
||||
button_record.set_bitmap(&bitmap_stop);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ void CaptureAppView::on_record() {
|
||||
return;
|
||||
}
|
||||
|
||||
capture_thread = std::make_unique<CaptureThread>(filename);
|
||||
capture_thread = std::make_unique<CaptureThread>(filename, 14, 1);
|
||||
button_record.set_bitmap(&bitmap_stop);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@
|
||||
|
||||
#include "capture_thread.hpp"
|
||||
|
||||
FIFO<uint8_t>* StreamOutput::fifo = nullptr;
|
||||
Thread* CaptureThread::thread = nullptr;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "event_m0.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "sd_card.hpp"
|
||||
|
||||
@@ -47,7 +46,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
|
||||
|
||||
chSysLockFromIsr();
|
||||
CaptureThread::check_fifo_isr();
|
||||
EventDispatcher::events_flag_isr(EVT_MASK_APPLICATION);
|
||||
EventDispatcher::check_fifo_isr();
|
||||
chSysUnlockFromIsr();
|
||||
|
||||
creg::m4txevent::clear();
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "ui_painter.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "message.hpp"
|
||||
|
||||
@@ -58,6 +59,12 @@ public:
|
||||
|
||||
void set_display_sleep(const bool sleep);
|
||||
|
||||
static inline void check_fifo_isr() {
|
||||
if( !shared_memory.application_queue.is_empty() ) {
|
||||
events_flag_isr(EVT_MASK_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void events_flag(const eventmask_t events) {
|
||||
if( thread_event_loop ) {
|
||||
chEvtSignal(thread_event_loop, events);
|
||||
|
||||
Reference in New Issue
Block a user