mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-22 06:29:31 -04:00
Formatted code (#1007)
* Updated style * Updated files * fixed new line * Updated spacing * File fix WIP * Updated to clang 13 * updated comment style * Removed old comment code
This commit is contained in:
parent
7aca7ce74d
commit
033c4e9a5b
599 changed files with 70746 additions and 66896 deletions
|
@ -26,101 +26,100 @@
|
|||
#include "buffer_exchange.hpp"
|
||||
|
||||
struct BasebandReplay {
|
||||
BasebandReplay(ReplayConfig* const config) {
|
||||
baseband::replay_start(config);
|
||||
}
|
||||
BasebandReplay(ReplayConfig* const config) {
|
||||
baseband::replay_start(config);
|
||||
}
|
||||
|
||||
~BasebandReplay() {
|
||||
baseband::replay_stop();
|
||||
}
|
||||
~BasebandReplay() {
|
||||
baseband::replay_stop();
|
||||
}
|
||||
};
|
||||
|
||||
// ReplayThread ///////////////////////////////////////////////////////////
|
||||
|
||||
ReplayThread::ReplayThread(
|
||||
std::unique_ptr<stream::Reader> reader,
|
||||
size_t read_size,
|
||||
size_t buffer_count,
|
||||
bool* ready_signal,
|
||||
std::function<void(uint32_t return_code)> terminate_callback
|
||||
) : config { read_size, buffer_count },
|
||||
reader { std::move(reader) },
|
||||
ready_sig { ready_signal },
|
||||
terminate_callback { std::move(terminate_callback) }
|
||||
{
|
||||
// Need significant stack for FATFS
|
||||
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, ReplayThread::static_fn, this);
|
||||
std::unique_ptr<stream::Reader> reader,
|
||||
size_t read_size,
|
||||
size_t buffer_count,
|
||||
bool* ready_signal,
|
||||
std::function<void(uint32_t return_code)> terminate_callback)
|
||||
: config{read_size, buffer_count},
|
||||
reader{std::move(reader)},
|
||||
ready_sig{ready_signal},
|
||||
terminate_callback{std::move(terminate_callback)} {
|
||||
// Need significant stack for FATFS
|
||||
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, ReplayThread::static_fn, this);
|
||||
}
|
||||
|
||||
ReplayThread::~ReplayThread() {
|
||||
if( thread ) {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
thread = nullptr;
|
||||
}
|
||||
if (thread) {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
msg_t ReplayThread::static_fn(void* arg) {
|
||||
auto obj = static_cast<ReplayThread*>(arg);
|
||||
const auto return_code = obj->run();
|
||||
if( obj->terminate_callback ) {
|
||||
obj->terminate_callback(return_code);
|
||||
}
|
||||
return 0;
|
||||
auto obj = static_cast<ReplayThread*>(arg);
|
||||
const auto return_code = obj->run();
|
||||
if (obj->terminate_callback) {
|
||||
obj->terminate_callback(return_code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t ReplayThread::run() {
|
||||
BasebandReplay replay { &config };
|
||||
BufferExchange buffers { &config };
|
||||
|
||||
StreamBuffer* prefill_buffer { nullptr };
|
||||
|
||||
// Wait for FIFOs to be allocated in baseband
|
||||
// Wait for ui_replay_view to tell us that the buffers are ready (awful :( )
|
||||
while (!(*ready_sig)) {
|
||||
chThdSleep(100);
|
||||
};
|
||||
|
||||
// While empty buffers fifo is not empty...
|
||||
while (!buffers.empty()) {
|
||||
prefill_buffer = buffers.get_prefill();
|
||||
|
||||
if (prefill_buffer == nullptr) {
|
||||
buffers.put_app(prefill_buffer);
|
||||
} else {
|
||||
size_t blocks = config.read_size / 512;
|
||||
|
||||
for (size_t c = 0; c < blocks; c++) {
|
||||
auto read_result = reader->read(&((uint8_t*)prefill_buffer->data())[c * 512], 512);
|
||||
if( read_result.is_error() ) {
|
||||
return READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
prefill_buffer->set_size(config.read_size);
|
||||
|
||||
buffers.put(prefill_buffer);
|
||||
}
|
||||
};
|
||||
|
||||
baseband::set_fifo_data(nullptr);
|
||||
BasebandReplay replay{&config};
|
||||
BufferExchange buffers{&config};
|
||||
|
||||
while( !chThdShouldTerminate() ) {
|
||||
auto buffer = buffers.get();
|
||||
|
||||
auto read_result = reader->read(buffer->data(), buffer->capacity());
|
||||
if( read_result.is_error() ) {
|
||||
return READ_ERROR;
|
||||
} else {
|
||||
if (read_result.value() == 0) {
|
||||
return END_OF_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->set_size(buffer->capacity());
|
||||
|
||||
buffers.put(buffer);
|
||||
}
|
||||
StreamBuffer* prefill_buffer{nullptr};
|
||||
|
||||
return TERMINATED;
|
||||
// Wait for FIFOs to be allocated in baseband
|
||||
// Wait for ui_replay_view to tell us that the buffers are ready (awful :( )
|
||||
while (!(*ready_sig)) {
|
||||
chThdSleep(100);
|
||||
};
|
||||
|
||||
// While empty buffers fifo is not empty...
|
||||
while (!buffers.empty()) {
|
||||
prefill_buffer = buffers.get_prefill();
|
||||
|
||||
if (prefill_buffer == nullptr) {
|
||||
buffers.put_app(prefill_buffer);
|
||||
} else {
|
||||
size_t blocks = config.read_size / 512;
|
||||
|
||||
for (size_t c = 0; c < blocks; c++) {
|
||||
auto read_result = reader->read(&((uint8_t*)prefill_buffer->data())[c * 512], 512);
|
||||
if (read_result.is_error()) {
|
||||
return READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
prefill_buffer->set_size(config.read_size);
|
||||
|
||||
buffers.put(prefill_buffer);
|
||||
}
|
||||
};
|
||||
|
||||
baseband::set_fifo_data(nullptr);
|
||||
|
||||
while (!chThdShouldTerminate()) {
|
||||
auto buffer = buffers.get();
|
||||
|
||||
auto read_result = reader->read(buffer->data(), buffer->capacity());
|
||||
if (read_result.is_error()) {
|
||||
return READ_ERROR;
|
||||
} else {
|
||||
if (read_result.value() == 0) {
|
||||
return END_OF_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->set_size(buffer->capacity());
|
||||
|
||||
buffers.put(buffer);
|
||||
}
|
||||
|
||||
return TERMINATED;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue