mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-05-23 07:38:22 +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:
parent
01fc6b9bc9
commit
91ee2dbb67
@ -322,7 +322,7 @@ void AnalogAudioView::record_start() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
capture_thread = std::make_unique<CaptureThread>(filename);
|
capture_thread = std::make_unique<CaptureThread>(filename, 12, 2);
|
||||||
button_record.set_bitmap(&bitmap_stop);
|
button_record.set_bitmap(&bitmap_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void CaptureAppView::on_record() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
capture_thread = std::make_unique<CaptureThread>(filename);
|
capture_thread = std::make_unique<CaptureThread>(filename, 14, 1);
|
||||||
button_record.set_bitmap(&bitmap_stop);
|
button_record.set_bitmap(&bitmap_stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,5 @@
|
|||||||
|
|
||||||
#include "capture_thread.hpp"
|
#include "capture_thread.hpp"
|
||||||
|
|
||||||
|
FIFO<uint8_t>* StreamOutput::fifo = nullptr;
|
||||||
Thread* CaptureThread::thread = nullptr;
|
Thread* CaptureThread::thread = nullptr;
|
||||||
|
@ -37,13 +37,19 @@ using namespace hackrf::one;
|
|||||||
|
|
||||||
class StreamOutput {
|
class StreamOutput {
|
||||||
public:
|
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(
|
shared_memory.baseband_queue.push_and_wait(
|
||||||
CaptureConfigMessage { &config }
|
CaptureConfigMessage { &config }
|
||||||
);
|
);
|
||||||
|
fifo = config.fifo;
|
||||||
}
|
}
|
||||||
|
|
||||||
~StreamOutput() {
|
~StreamOutput() {
|
||||||
|
fifo = nullptr;
|
||||||
shared_memory.baseband_queue.push_and_wait(
|
shared_memory.baseband_queue.push_and_wait(
|
||||||
CaptureConfigMessage { nullptr }
|
CaptureConfigMessage { nullptr }
|
||||||
);
|
);
|
||||||
@ -57,6 +63,8 @@ public:
|
|||||||
return config.fifo->out(reinterpret_cast<uint8_t*>(data), length);
|
return config.fifo->out(reinterpret_cast<uint8_t*>(data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FIFO<uint8_t>* fifo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CaptureConfig config;
|
CaptureConfig config;
|
||||||
};
|
};
|
||||||
@ -64,9 +72,13 @@ private:
|
|||||||
class CaptureThread {
|
class CaptureThread {
|
||||||
public:
|
public:
|
||||||
CaptureThread(
|
CaptureThread(
|
||||||
std::string file_path
|
std::string file_path,
|
||||||
) : file_path { std::move(file_path) },
|
size_t write_size_log2,
|
||||||
write_buffer { std::make_unique<std::array<uint8_t, write_size>>() }
|
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
|
// Need significant stack for FATFS
|
||||||
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, CaptureThread::static_fn, this);
|
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, CaptureThread::static_fn, this);
|
||||||
@ -90,16 +102,17 @@ public:
|
|||||||
static void check_fifo_isr() {
|
static void check_fifo_isr() {
|
||||||
// TODO: Prevent over-signalling by transmitting a set of
|
// TODO: Prevent over-signalling by transmitting a set of
|
||||||
// flags from the baseband core.
|
// flags from the baseband core.
|
||||||
if( thread ) {
|
const auto fifo = StreamOutput::fifo;
|
||||||
|
if( fifo ) {
|
||||||
chEvtSignalI(thread, EVT_MASK_CAPTURE_THREAD);
|
chEvtSignalI(thread, EVT_MASK_CAPTURE_THREAD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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;
|
const std::string file_path;
|
||||||
std::unique_ptr<std::array<uint8_t, write_size>> write_buffer;
|
|
||||||
File file;
|
File file;
|
||||||
static Thread* thread;
|
static Thread* thread;
|
||||||
|
|
||||||
@ -113,12 +126,17 @@ private:
|
|||||||
return false;
|
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() ) {
|
while( !chThdShouldTerminate() ) {
|
||||||
chEvtWaitAny(EVT_MASK_CAPTURE_THREAD);
|
chEvtWaitAny(EVT_MASK_CAPTURE_THREAD);
|
||||||
|
|
||||||
while( stream.available() >= write_buffer->size() ) {
|
while( stream.available() >= write_size ) {
|
||||||
if( !transfer(stream, write_buffer.get()) ) {
|
if( !transfer(stream, write_buffer.get()) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -128,14 +146,14 @@ private:
|
|||||||
return true;
|
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;
|
bool success = false;
|
||||||
|
|
||||||
led_usb.on();
|
led_usb.on();
|
||||||
|
|
||||||
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
|
const auto bytes_to_write = stream.read(write_buffer, write_size);
|
||||||
if( bytes_to_write == write_buffer->size() ) {
|
if( bytes_to_write == write_size ) {
|
||||||
if( file.write(write_buffer->data(), write_buffer->size()) ) {
|
if( file.write(write_buffer, write_size) ) {
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "event_m0.hpp"
|
#include "event_m0.hpp"
|
||||||
|
|
||||||
#include "portapack.hpp"
|
#include "portapack.hpp"
|
||||||
#include "portapack_shared_memory.hpp"
|
|
||||||
|
|
||||||
#include "sd_card.hpp"
|
#include "sd_card.hpp"
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
|
|||||||
|
|
||||||
chSysLockFromIsr();
|
chSysLockFromIsr();
|
||||||
CaptureThread::check_fifo_isr();
|
CaptureThread::check_fifo_isr();
|
||||||
EventDispatcher::events_flag_isr(EVT_MASK_APPLICATION);
|
EventDispatcher::check_fifo_isr();
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
|
|
||||||
creg::m4txevent::clear();
|
creg::m4txevent::clear();
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "ui_painter.hpp"
|
#include "ui_painter.hpp"
|
||||||
|
|
||||||
#include "portapack.hpp"
|
#include "portapack.hpp"
|
||||||
|
#include "portapack_shared_memory.hpp"
|
||||||
|
|
||||||
#include "message.hpp"
|
#include "message.hpp"
|
||||||
|
|
||||||
@ -58,6 +59,12 @@ public:
|
|||||||
|
|
||||||
void set_display_sleep(const bool sleep);
|
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) {
|
static inline void events_flag(const eventmask_t events) {
|
||||||
if( thread_event_loop ) {
|
if( thread_event_loop ) {
|
||||||
chEvtSignal(thread_event_loop, events);
|
chEvtSignal(thread_event_loop, events);
|
||||||
|
@ -100,7 +100,7 @@ void NarrowbandAMAudio::configure(const AMConfigureMessage& message) {
|
|||||||
|
|
||||||
void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) {
|
void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||||
if( message.config ) {
|
if( message.config ) {
|
||||||
audio_output.set_stream(std::make_unique<StreamInput>(14, *message.config));
|
audio_output.set_stream(std::make_unique<StreamInput>(*message.config));
|
||||||
} else {
|
} else {
|
||||||
audio_output.set_stream(nullptr);
|
audio_output.set_stream(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ void CaptureProcessor::on_message(const Message* const message) {
|
|||||||
|
|
||||||
void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
|
void CaptureProcessor::capture_config(const CaptureConfigMessage& message) {
|
||||||
if( message.config ) {
|
if( message.config ) {
|
||||||
stream = std::make_unique<StreamInput>(15, *message.config);
|
stream = std::make_unique<StreamInput>(*message.config);
|
||||||
} else {
|
} else {
|
||||||
stream.reset();
|
stream.reset();
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) {
|
|||||||
|
|
||||||
void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||||
if( message.config ) {
|
if( message.config ) {
|
||||||
audio_output.set_stream(std::make_unique<StreamInput>(14, *message.config));
|
audio_output.set_stream(std::make_unique<StreamInput>(*message.config));
|
||||||
} else {
|
} else {
|
||||||
audio_output.set_stream(nullptr);
|
audio_output.set_stream(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
|
|||||||
|
|
||||||
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||||
if( message.config ) {
|
if( message.config ) {
|
||||||
audio_output.set_stream(std::make_unique<StreamInput>(15, *message.config));
|
audio_output.set_stream(std::make_unique<StreamInput>(*message.config));
|
||||||
} else {
|
} else {
|
||||||
audio_output.set_stream(nullptr);
|
audio_output.set_stream(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,21 @@
|
|||||||
#ifndef __STREAM_INPUT_H__
|
#ifndef __STREAM_INPUT_H__
|
||||||
#define __STREAM_INPUT_H__
|
#define __STREAM_INPUT_H__
|
||||||
|
|
||||||
#include "portapack_shared_memory.hpp"
|
#include "message.hpp"
|
||||||
|
|
||||||
#include "fifo.hpp"
|
#include "fifo.hpp"
|
||||||
|
|
||||||
|
#include "lpc43xx_cpp.hpp"
|
||||||
|
using namespace lpc43xx;
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class StreamInput {
|
class StreamInput {
|
||||||
public:
|
public:
|
||||||
StreamInput(const size_t K, CaptureConfig& config) :
|
StreamInput(CaptureConfig& config) :
|
||||||
K { K },
|
K { config.write_size_log2 + config.buffer_count_log2 },
|
||||||
|
event_bytes_mask { (1UL << config.write_size_log2) - 1 },
|
||||||
data { std::make_unique<uint8_t[]>(1UL << K) },
|
data { std::make_unique<uint8_t[]>(1UL << K) },
|
||||||
fifo { data.get(), K }
|
fifo { data.get(), K }
|
||||||
{
|
{
|
||||||
@ -58,7 +61,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const size_t K;
|
const size_t K;
|
||||||
const uint64_t event_bytes_mask = (1ULL << (K - 2)) - 1;
|
const uint64_t event_bytes_mask;
|
||||||
uint64_t bytes_written = 0;
|
uint64_t bytes_written = 0;
|
||||||
std::unique_ptr<uint8_t[]> data;
|
std::unique_ptr<uint8_t[]> data;
|
||||||
FIFO<uint8_t> fifo;
|
FIFO<uint8_t> fifo;
|
||||||
|
@ -411,7 +411,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CaptureConfig {
|
struct CaptureConfig {
|
||||||
FIFO<uint8_t>* fifo { nullptr };
|
const size_t write_size_log2;
|
||||||
|
const size_t buffer_count_log2;
|
||||||
|
FIFO<uint8_t>* fifo;
|
||||||
|
|
||||||
|
constexpr CaptureConfig(
|
||||||
|
const size_t write_size_log2,
|
||||||
|
const size_t buffer_count_log2
|
||||||
|
) : write_size_log2 { write_size_log2 },
|
||||||
|
buffer_count_log2 { buffer_count_log2 },
|
||||||
|
fifo { nullptr }
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CaptureConfigMessage : public Message {
|
class CaptureConfigMessage : public Message {
|
||||||
|
@ -70,6 +70,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_empty() const {
|
||||||
|
return fifo.is_empty();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FIFO<uint8_t> fifo;
|
FIFO<uint8_t> fifo;
|
||||||
Mutex mutex_write;
|
Mutex mutex_write;
|
||||||
@ -92,10 +96,6 @@ private:
|
|||||||
return fifo.len();
|
return fifo.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_empty() const {
|
|
||||||
return fifo.is_empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool push(const void* const buf, const size_t len) {
|
bool push(const void* const buf, const size_t len) {
|
||||||
chMtxLock(&mutex_write);
|
chMtxLock(&mutex_write);
|
||||||
const auto result = fifo.in_r(buf, len);
|
const auto result = fifo.in_r(buf, len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user